|
|
<?php
|
|
|
|
|
|
class Rant
|
|
|
{
|
|
|
public $id;
|
|
|
public $published;
|
|
|
public $status;
|
|
|
public $side;
|
|
|
public $author;
|
|
|
public $title;
|
|
|
public $body;
|
|
|
public $link;
|
|
|
public $imagetype;
|
|
|
public $imagetext;
|
|
|
}
|
|
|
|
|
|
function saverant($rant)
|
|
|
{
|
|
|
if ($rant->id)
|
|
|
return updaterant($rant);
|
|
|
else
|
|
|
return insertrant($rant);
|
|
|
}
|
|
|
|
|
|
function insertrant($rant)
|
|
|
{
|
|
|
global $dbConnection;
|
|
|
|
|
|
$sql = 'INSERT INTO rant (published, status, side, author, title, body, link, imagetype, imagetext) VALUES ' .
|
|
|
'(FROM_UNIXTIME(:published), :status, :side, :author, :title, :body, :link, :imagetype, :imagetext)';
|
|
|
$stmt = $dbConnection->prepare($sql);
|
|
|
|
|
|
$stmt->bindValue('published', (int)$rant->published);
|
|
|
$stmt->bindValue('status', $rant->status);
|
|
|
$stmt->bindValue('side', $rant->side);
|
|
|
$stmt->bindValue('author', (int)$rant->author);
|
|
|
$stmt->bindValue('title', trim($rant->title));
|
|
|
$stmt->bindValue('body', trim($rant->body));
|
|
|
$stmt->bindValue('link', trim($rant->link));
|
|
|
$stmt->bindValue('imagetype', $rant->imagetype);
|
|
|
$stmt->bindValue('imagetext', trim($rant->imagetext));
|
|
|
|
|
|
if ($stmt->execute())
|
|
|
{
|
|
|
//logthis( 'Saved changes to rant ' . $rant->id );
|
|
|
$rant->id = $dbConnection->lastInsertId();
|
|
|
|
|
|
adminlog("Rant " . $rant->id . " saved.", MTS_RANT, MTA_ADD);
|
|
|
|
|
|
if ($rant->status == "published")
|
|
|
{
|
|
|
adminlog("Rant " . $rant->id . " published.", MTS_RANT, MTA_ADD);
|
|
|
|
|
|
/*
|
|
|
$poster = get_userdatabyid($rant->author);
|
|
|
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 $dbConnection;
|
|
|
|
|
|
# First, check if it's published already
|
|
|
$sql = 'SELECT status FROM rant WHERE id = ?';
|
|
|
$stmt = $dbConnection->prepare($sql);
|
|
|
|
|
|
$stmt->bindValue(1, $rant->id);
|
|
|
|
|
|
$stmt->execute();
|
|
|
$status = $stmt->fetchColumn();
|
|
|
|
|
|
adminlog("Rant " . $rant->id . " updated.", MTS_RANT, MTA_UPDATE);
|
|
|
|
|
|
$sql = 'UPDATE rant SET published = FROM_UNIXTIME(:published), status = :status, side = :side, author = :author, ' .
|
|
|
'title = :title, body = :body, link = :link, imagetype = :imagetype, imagetext = :imagetext WHERE id = :id';
|
|
|
$stmt = $dbConnection->prepare($sql);
|
|
|
|
|
|
$stmt->bindValue('id', (int)$rant->id);
|
|
|
$stmt->bindValue('published', (int)$rant->published);
|
|
|
$stmt->bindValue('status', $rant->status);
|
|
|
$stmt->bindValue('side', $rant->side);
|
|
|
$stmt->bindValue('author', (int)$rant->author);
|
|
|
$stmt->bindValue('title', trim($rant->title));
|
|
|
$stmt->bindValue('body', trim($rant->body));
|
|
|
$stmt->bindValue('link', trim($rant->link));
|
|
|
$stmt->bindValue('imagetype', (int)$rant->imagetype);
|
|
|
$stmt->bindValue('imagetext', trim($rant->imagetext));
|
|
|
|
|
|
if ($status == "draft" && $rant->status == "published")
|
|
|
{
|
|
|
adminlog("Rant " . $rant->id . " published.", MTS_RANT, MTA_UPDATE);
|
|
|
|
|
|
/*
|
|
|
$poster = get_userdatabyid($rant->author);
|
|
|
twitterpost("New rant posted by ".$poster->name.": ".SITE_HOST.SITE_PATH."/rant/".$rant->id);
|
|
|
|
|
|
if($rant->author === 1) {
|
|
|
tumblrpost($rant->title, $rant->body);
|
|
|
}
|
|
|
*/
|
|
|
}
|
|
|
|
|
|
return $stmt->execute();
|
|
|
}
|
|
|
|
|
|
function deleterant($rantid)
|
|
|
{
|
|
|
if ( !(int)$rantid ) return false;
|
|
|
global $dbConnection;
|
|
|
|
|
|
$sql = 'DELETE FROM rant WHERE id = ?';
|
|
|
$stmt = $dbConnection->prepare($sql);
|
|
|
|
|
|
$stmt->bindValue(1, $rantid);
|
|
|
|
|
|
adminlog("Rant " . $rantid . " deleted.", MTS_RANT, MTA_DELETE);
|
|
|
return $stmt->execute();
|
|
|
}
|
|
|
|
|
|
function deleteattachment($id)
|
|
|
{
|
|
|
global $dbConnection;
|
|
|
|
|
|
// Remove attachment from filesystem
|
|
|
$file = SITE_PATH_ABS . '/' . get_rantattachment_filename($id);
|
|
|
unlink($file) or adminlog("Could not delete $file", MTS_RANT, MTA_DELETE, E_USER_WARNING);
|
|
|
|
|
|
// Remove from database
|
|
|
$sql = 'DELETE FROM rant_attachment WHERE id = ?';
|
|
|
$stmt = $dbConnection->prepare($sql);
|
|
|
|
|
|
$stmt->bindValue(1, $id);
|
|
|
|
|
|
$stmt->execute();
|
|
|
adminlog("Deleted attachment $id", MTS_RANT, MTA_DELETE);
|
|
|
}
|
|
|
|
|
|
function getrant($id)
|
|
|
{
|
|
|
global $dbConnection;
|
|
|
|
|
|
$sql = 'SELECT id, UNIX_TIMESTAMP(published) as published, status, side, author, title, body, link, imagetype, imagetext FROM rant WHERE id = ?';
|
|
|
$stmt = $dbConnection->prepare($sql);
|
|
|
|
|
|
$stmt->bindValue(1, (int)$id);
|
|
|
|
|
|
$stmt->execute();
|
|
|
return $stmt->fetch();
|
|
|
}
|
|
|
|
|
|
function get_rantimage_filename($rant)
|
|
|
{
|
|
|
global $dbConnection;
|
|
|
|
|
|
$sql = 'SELECT extension FROM media_t WHERE id = ?';
|
|
|
$stmt = $dbConnection->prepare($sql);
|
|
|
|
|
|
$stmt->bindValue(1, (int)$rant->imagetype);
|
|
|
|
|
|
$stmt->execute();
|
|
|
$ext = $stmt->fetchColumn(); // filename extension
|
|
|
|
|
|
return sprintf('%s/%04d.%s', SITE_RANT, (int)$rant->id, $ext);
|
|
|
}
|
|
|
|
|
|
function get_rantattachment_filename($id)
|
|
|
{
|
|
|
global $dbConnection;
|
|
|
|
|
|
$sql = 'SELECT extension FROM media_t JOIN rant_attachment ra ON ra.media = media_t.id WHERE ra.id = ?';
|
|
|
$stmt = $dbConnection->prepare($sql);
|
|
|
|
|
|
$stmt->bindValue(1, (int)$id);
|
|
|
|
|
|
$stmt->execute();
|
|
|
$ext = $stmt->fetchColumn(); // filename extension
|
|
|
|
|
|
return sprintf('%s/%d.%s', SITE_RANT_ATTACHMENT, (int)$id, $ext );
|
|
|
}
|
|
|
|
|
|
?>
|
|
|
|