Update more admin pages to use DBAL functions.
Update more admin pages to use DBAL functions.

File last commit:

089a8bc9edcb
3b807424bd87
Show More
rants.php
193 lines | 4.9 KiB | text/x-php | PhpLexer
Add most necessary files for admin interface.
r1 <?php
Update pages and rants to use DBAL.
r27 class Rant
{
public $id;
public $published;
public $status;
public $side;
public $author;
public $title;
public $body;
public $link;
public $imagetype;
public $imagetext;
Add most necessary files for admin interface.
r1 }
Update pages and rants to use DBAL.
r27 function saverant($rant)
{
if ($rant->id)
Add most necessary files for admin interface.
r1 return updaterant($rant);
else
return insertrant($rant);
}
Update pages and rants to use DBAL.
r27 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())
{
Add most necessary files for admin interface.
r1 //logthis( 'Saved changes to rant ' . $rant->id );
Update pages and rants to use DBAL.
r27 $rant->id = $dbConnection->lastInsertId();
Update include/*.php to use mysqli_* functions.
r4
Update pages and rants to use DBAL.
r27 adminlog("Rant " . $rant->id . " saved.", MTS_RANT, MTA_ADD);
Update include/*.php to use mysqli_* functions.
r4
Update pages and rants to use DBAL.
r27 if ($rant->status == "published")
Add most necessary files for admin interface.
r1 {
Update pages and rants to use DBAL.
r27 adminlog("Rant " . $rant->id . " published.", MTS_RANT, MTA_ADD);
/*
Add most necessary files for admin interface.
r1 $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);
}
Update pages and rants to use DBAL.
r27 */
Add most necessary files for admin interface.
r1 }
Update include/*.php to use mysqli_* functions.
r4
Add most necessary files for admin interface.
r1 return $rant->id;
}
Update pages and rants to use DBAL.
r27
Add most necessary files for admin interface.
r1 return false;
Update include/*.php to use mysqli_* functions.
r4 }
Add most necessary files for admin interface.
r1
Update pages and rants to use DBAL.
r27 function updaterant($rant)
{
Add most necessary files for admin interface.
r1 if ( !(int)$rant->id ) return false;
Update pages and rants to use DBAL.
r27 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")
Add most necessary files for admin interface.
r1 {
Update pages and rants to use DBAL.
r27 adminlog("Rant " . $rant->id . " published.", MTS_RANT, MTA_UPDATE);
/*
Add most necessary files for admin interface.
r1 $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);
}
Update pages and rants to use DBAL.
r27 */
Add most necessary files for admin interface.
r1 }
Update include/*.php to use mysqli_* functions.
r4
Update pages and rants to use DBAL.
r27 return $stmt->execute();
Add most necessary files for admin interface.
r1 }
Update pages and rants to use DBAL.
r27 function deleterant($rantid)
{
Add most necessary files for admin interface.
r1 if ( !(int)$rantid ) return false;
Update pages and rants to use DBAL.
r27 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();
Add most necessary files for admin interface.
r1 }
function deleteattachment($id)
{
Update pages and rants to use DBAL.
r27 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();
Add most necessary files for admin interface.
r1 adminlog("Deleted attachment $id", MTS_RANT, MTA_DELETE);
}
Update pages and rants to use DBAL.
r27 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();
Add most necessary files for admin interface.
r1 }
Update pages and rants to use DBAL.
r27 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);
Add most necessary files for admin interface.
r1 }
Update pages and rants to use DBAL.
r27 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 );
Add most necessary files for admin interface.
r1 }
?>