|
|
<?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
|
|
|
. '), "' . mysqli_real_escape_string($mtdb->link, $rant->status)
|
|
|
. '", "' . mysqli_real_escape_string($mtdb->link, $rant->side)
|
|
|
. '", "' . (int)$rant->author
|
|
|
. '", "' . 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 ) )
|
|
|
. '")';
|
|
|
|
|
|
if( $mtdb->query( $sql ) ) {
|
|
|
//logthis( 'Saved changes to rant ' . $rant->id );
|
|
|
$rant->id = mysqli_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 = mysqli_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 = "' . mysqli_real_escape_string($mtdb->link, $rant->status)
|
|
|
. '", side = "' . mysqli_real_escape_string($mtdb->link, $rant->side)
|
|
|
. '", author = ' . (int)$rant->author
|
|
|
. ', 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 ) )
|
|
|
. '", imagetype = ' . (int)$rant->imagetype
|
|
|
. ', imagetext = "' . mysqli_real_escape_string( $mtdb->link, 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 );
|
|
|
}
|
|
|
|
|
|
?>
|
|
|
|