From 9c9ead2b082c82a28febfdd409551bc647c50ab3 Mon Sep 17 00:00:00 2001 From: Savetheinternet Date: Thu, 17 Mar 2011 16:52:43 +1100 Subject: Beta PM system --- mod.php | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 117 insertions(+), 2 deletions(-) (limited to 'mod.php') diff --git a/mod.php b/mod.php index 56c0e38a..ad3ee85d 100644 --- a/mod.php +++ b/mod.php @@ -146,6 +146,119 @@ 'mod'=>true ) ); + } elseif(preg_match('/^\/PM\/(\d+)$/', $query, $match)) { + $id = $match[1]; + + $query = prepare("SELECT `pms`.`id`, `time`, `sender`, `message`, `username` FROM `pms` LEFT JOIN `mods` ON `mods`.`id` = `sender` WHERE `pms`.`id` = :id AND `to` = :mod"); + $query->bindValue(':id', $id, PDO::PARAM_INT); + $query->bindValue(':mod', $mod['id'], PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + if(!$pm = $query->fetch()) { + // Mod doesn't exist + error($config['error']['404']); + } + + if(isset($_POST['delete'])) { + $query = prepare("DELETE FROM `pms` WHERE `id` = :id"); + $query->bindValue(':id', $id, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + header('Location: ?/', true, $config['redirect_http']); + } else { + $query = prepare("UPDATE `pms` SET `unread` = 0 WHERE `id` = :id"); + $query->bindValue(':id', $id, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + $body = '
' . + + '' . + + '' . + + '
From' . + ($mod['type'] >= $config['mod']['editusers'] ? + '' . htmlentities($pm['username']) . '' : + htmlentities($pm['username']) + ) . + '
Date ' . date($config['post_date'], $pm['time']) . '
Message ' . $pm['message'] . '
' . + + '

' . + + '
'; + + echo Element('page.html', Array( + 'index'=>$config['root'], + 'title'=>'Private message', + 'body'=>$body, + 'mod'=>true + ) + ); + } + } elseif(preg_match('/^\/new_PM\/(\d+)$/', $query, $match)) { + if($mod['type'] < $config['mod']['create_pm']) error($config['error']['noaccess']); + + $to = $match[1]; + + $query = prepare("SELECT `username`,`id` FROM `mods` WHERE `id` = :id"); + $query->bindValue(':id', $to, PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + if(!$to = $query->fetch()) { + // Mod doesn't exist + error($config['error']['404']); + } + + if(isset($_POST['message'])) { + // Post message + $message = $_POST['message']; + + if(empty($message)) + error($config['error']['tooshort_body']); + + markup($message); + + $query = prepare("INSERT INTO `pms` VALUES (NULL, :sender, :to, :message, :time, 1)"); + $query->bindValue(':sender', $mod['id'], PDO::PARAM_INT); + $query->bindValue(':to', $to['id'], PDO::PARAM_INT); + $query->bindValue(':message', $message); + $query->bindValue(':time', time(), PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + echo Element('page.html', Array( + 'index'=>$config['root'], + 'title'=>'PM sent', + 'body'=>'

Message sent successfully to ' . htmlentities($to['username']) . '.

', + 'mod'=>true + ) + ); + } else { + $body = '
' . + + '' . + + '' . + + '' . + + '
To' . + ($mod['type'] >= $config['mod']['editusers'] ? + '' . htmlentities($to['username']) . '' : + htmlentities($to['username']) + ) . + '
Message
' . + + '

' . + + '
'; + + echo Element('page.html', Array( + 'index'=>$config['root'], + 'title'=>'New PM for ' . htmlentities($to['username']), + 'body'=>$body + ,'mod'=>true + ) + ); + } } elseif(preg_match('/^\/users$/', $query)) { if($mod['type'] < $config['mod']['manageusers']) error($config['error']['noaccess']); @@ -185,8 +298,10 @@ ) . ($mod['type'] >= $config['mod']['editusers'] ? '[edit]' - : '' - ) . + : '' ) . + ($mod['type'] >= $config['mod']['create_pm'] ? + '[PM]' + : '' ) . ''; } -- cgit v1.3