rants.php
119 lines
| 3.9 KiB
| text/x-php
|
PhpLexer
/ include / rants.php
| r1 | <?php | |||
| class Rant { | ||||
| var $id, $published, $status, $side, $author, $title, $body, $link, $imagetype, $imagetext; | ||||
| } | ||||
| function saverant($rant) { | ||||
| if($rant->id) | ||||
| return updaterant($rant); | ||||
| else | ||||
| return insertrant($rant); | ||||
| } | ||||
| function insertrant($rant) { | ||||
| global $mtdb; | ||||
| $sql = 'INSERT INTO rant ( published, status, side, author, title, body, link, imagetype, imagetext ) VALUES ( FROM_UNIXTIME(' | ||||
| . (int)$rant->published | ||||
| . '), "' . mysql_real_escape_string($rant->status) | ||||
| . '", "' . mysql_real_escape_string($rant->side) | ||||
| . '", "' . (int)$rant->author | ||||
| . '", "' . mysql_real_escape_string( trim( $rant->title) ) | ||||
| . '", "' . mysql_real_escape_string( trim( $rant->body ) ) | ||||
| . '", "' . mysql_real_escape_string( trim( $rant->link ) ) | ||||
| . '", ' . mysql_real_escape_string($rant->imagetype) | ||||
| . ', "' . mysql_real_escape_string( trim( $rant->imagetext ) ) | ||||
| . '")'; | ||||
| if( $mtdb->query( $sql ) ) { | ||||
| //logthis( 'Saved changes to rant ' . $rant->id ); | ||||
| $rant->id = mysql_insert_id( $mtdb->link ); | ||||
| adminlog("Rant ".$rant->id." saved.", MTS_RANT, MTA_ADD); | ||||
| if($rant->status == "published") | ||||
| { | ||||
| $poster = get_userdatabyid($rant->author); | ||||
| adminlog("Rant ".$rant->id." published.", MTS_RANT, MTA_ADD); | ||||
| twitterpost("New rant posted by ".$poster->name.": ".SITE_HOST.SITE_PATH."/rant/".$rant->id); | ||||
| if($rant->author === 1) { | ||||
| tumblrpost($rant->title, $rant->body); | ||||
| } | ||||
| } | ||||
| return $rant->id; | ||||
| } | ||||
| return false; | ||||
| } | ||||
| function updaterant($rant) { | ||||
| if ( !(int)$rant->id ) return false; | ||||
| global $mtdb; | ||||
| #first, check if it's published already | ||||
| $qr = $mtdb->query("SELECT status FROM rant WHERE id = ".$rant->id); | ||||
| $row = mysql_fetch_row($qr); | ||||
| $status = $row[0]; | ||||
| adminlog("Rant ".$rant->id." updated.", MTS_RANT, MTA_UPDATE); | ||||
| $sql = 'UPDATE rant SET published=FROM_UNIXTIME(' . (int)$rant->published | ||||
| . '), status = "' . mysql_real_escape_string($rant->status) | ||||
| . '", side = "' . mysql_real_escape_string($rant->side) | ||||
| . '", author = ' . (int)$rant->author | ||||
| . ', title = "' . mysql_real_escape_string( trim($rant->title) ) | ||||
| . '", body = "' . mysql_real_escape_string( trim($rant->body ) ) | ||||
| . '", link = "' . mysql_real_escape_string( trim($rant->link ) ) | ||||
| . '", imagetype = ' . (int)$rant->imagetype | ||||
| . ', imagetext = "' . mysql_real_escape_string( trim($rant->imagetext) ) | ||||
| . '" WHERE id=' . (int)$rant->id; | ||||
| if($status == "draft" && $rant->status == "published") | ||||
| { | ||||
| $poster = get_userdatabyid($rant->author); | ||||
| adminlog("Rant ".$rant->id." published.", MTS_RANT, MTA_UPDATE); | ||||
| twitterpost("New rant posted by ".$poster->name.": ".SITE_HOST.SITE_PATH."/rant/".$rant->id); | ||||
| if($rant->author === 1) { | ||||
| tumblrpost($rant->title, $rant->body); | ||||
| } | ||||
| } | ||||
| return $mtdb->query( $sql ); | ||||
| } | ||||
| function deleterant($rantid) { | ||||
| if ( !(int)$rantid ) return false; | ||||
| global $mtdb; | ||||
| adminlog("Rant ".$rantid." deleted.", MTS_RANT, MTA_DELETE); | ||||
| return $mtdb->query( 'DELETE FROM rant WHERE id=' . $rantid ); | ||||
| } | ||||
| function deleteattachment($id) | ||||
| { | ||||
| global $mtdb; | ||||
| $file = SITE_PATH_ABS.'/'.get_rantattachment_filename($id); | ||||
| unlink( $file ) or adminlog("Could not delete $file", MTS_RANT, MTA_DELETE, E_USER_WARNING); | ||||
| $mtdb->query( 'DELETE FROM rant_attachment WHERE id = ' . $id ); | ||||
| adminlog("Deleted attachment $id", MTS_RANT, MTA_DELETE); | ||||
| } | ||||
| function getrant($id) { | ||||
| global $mtdb; | ||||
| return $mtdb->getRow( 'SELECT id, UNIX_TIMESTAMP(published) as published, status, side, author, title, body, link, imagetype, imagetext FROM rant WHERE id = '. (int)$id ); | ||||
| } | ||||
| function get_rantimage_filename( $rant ) { | ||||
| global $mtdb; | ||||
| $ext = $mtdb->getOne( 'SELECT extension FROM media_t WHERE id=' . (int)$rant->imagetype ); // filename extension | ||||
| return sprintf( '%s/%04d.%s',SITE_RANT, (int)$rant->id, $ext ); | ||||
| } | ||||
| function get_rantattachment_filename( $id ) { | ||||
| global $mtdb; | ||||
| $ext = $mtdb->getOne( 'SELECT extension FROM media_t JOIN rant_attachment ra ON ra.media = media_t.id WHERE ra.id=' . (int)$id ); // filename extension | ||||
| return sprintf( '%s/%d.%s',SITE_RANT_ATTACHMENT, (int)$id, $ext ); | ||||
| } | ||||
| ?> | ||||
