rants.php
119 lines
| 4.1 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 | ||||
| r4 | . '), "' . mysqli_real_escape_string($mtdb->link, $rant->status) | |||
| . '", "' . mysqli_real_escape_string($mtdb->link, $rant->side) | ||||
| r1 | . '", "' . (int)$rant->author | |||
| r4 | . '", "' . mysqli_real_escape_string( $mtdb->link, trim( $rant->title) ) | |||
| . '", "' . mysqli_real_escape_string( $mtdb->link, trim( $rant->body ) ) | ||||
| . '", "' . mysqli_real_escape_string( $mtdb->link, trim( $rant->link ) ) | ||||
| . '", ' . mysqli_real_escape_string($mtdb->link, $rant->imagetype) | ||||
| . ', "' . mysqli_real_escape_string( $mtdb->link, trim( $rant->imagetext ) ) | ||||
| r1 | . '")'; | |||
| r4 | ||||
| r1 | if( $mtdb->query( $sql ) ) { | |||
| //logthis( 'Saved changes to rant ' . $rant->id ); | ||||
| r4 | $rant->id = mysqli_insert_id( $mtdb->link ); | |||
| r1 | adminlog("Rant ".$rant->id." saved.", MTS_RANT, MTA_ADD); | |||
| r4 | ||||
| r1 | 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); | ||||
| } | ||||
| } | ||||
| r4 | ||||
| r1 | return $rant->id; | |||
| } | ||||
| return false; | ||||
| r4 | } | |||
| r1 | ||||
| function updaterant($rant) { | ||||
| if ( !(int)$rant->id ) return false; | ||||
| global $mtdb; | ||||
| r4 | ||||
| r1 | #first, check if it's published already | |||
| $qr = $mtdb->query("SELECT status FROM rant WHERE id = ".$rant->id); | ||||
| r4 | $row = mysqli_fetch_row($qr); | |||
| r1 | $status = $row[0]; | |||
| r4 | ||||
| r1 | adminlog("Rant ".$rant->id." updated.", MTS_RANT, MTA_UPDATE); | |||
| r4 | ||||
| r1 | $sql = 'UPDATE rant SET published=FROM_UNIXTIME(' . (int)$rant->published | |||
| r4 | . '), status = "' . mysqli_real_escape_string($mtdb->link, $rant->status) | |||
| . '", side = "' . mysqli_real_escape_string($mtdb->link, $rant->side) | ||||
| r1 | . '", author = ' . (int)$rant->author | |||
| r4 | . ', title = "' . mysqli_real_escape_string( $mtdb->link, trim($rant->title) ) | |||
| . '", body = "' . mysqli_real_escape_string( $mtdb->link, trim($rant->body ) ) | ||||
| . '", link = "' . mysqli_real_escape_string( $mtdb->link, trim($rant->link ) ) | ||||
| r1 | . '", imagetype = ' . (int)$rant->imagetype | |||
| r4 | . ', imagetext = "' . mysqli_real_escape_string( $mtdb->link, trim($rant->imagetext) ) | |||
| r1 | . '" WHERE id=' . (int)$rant->id; | |||
| r4 | ||||
| r1 | 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); | ||||
| } | ||||
| } | ||||
| r4 | ||||
| r1 | 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 ); | ||||
| } | ||||
| ?> | ||||
