CMS系统
源代码在线查看: comments.php
define('MOD_ACCESS', true);
define('IN_ADMIN', true);
define('IN_SUBDREAMER', true);
$rootpath = "./../";
include($rootpath . 'includes/core.php');
PrintHeader('Comments Manager', 1);
function UpdateComment()
{
global $DB;
$commentid = $_POST['commentid'];
$comments = $_POST['comment'];
$username = $_POST['username'];
if($_POST['deletecomment'] == 1)
{
$DB->query("DELETE FROM " . TABLE_PREFIX . "comments WHERE commentid = '$commentid'");
}
else
{
$DB->query("UPDATE " . TABLE_PREFIX . "comments SET comment = '$comments',
username = '$username'
WHERE commentid = '$commentid'");
}
PrintRedirect('comments.php', 1);
}
function DeleteComments()
{
global $DB;
// get post vars
$commentids = $_POST['commentids'];
for($i = 0; $i < count($commentids); $i++)
{
$DB->query("DELETE FROM " . TABLE_PREFIX . "comments WHERE commentid = '".$commentids[$i]."'");
}
PrintRedirect('comments.php', 1);
}
function TranslateObjectID($pluginid, $objectid)
{
global $DB;
switch($pluginid)
{
case 2: // News
$title = $DB->query_first("SELECT title FROM " . TABLE_PREFIX . "p2_news WHERE articleid = $objectid");
$title = $title[0];
break;
case 13: // Download Manager
$title = $DB->query_first("SELECT title FROM " . TABLE_PREFIX . "p13_files WHERE fileid = $objectid");
$title = $title[0];
break;
case 17: // Image Gallery
$title = $DB->query_first("SELECT title FROM " . TABLE_PREFIX . "p17_images WHERE imageid = $objectid");
$title = $title[0];
break;
case 404: // Classified Ads
$title = $DB->query_first("SELECT title FROM " . TABLE_PREFIX . "p404_advert WHERE ad_id = $objectid");
$title = $title[0];
break;
default:
$title = 'Unknown (ID ' . $objectid . ')';
break;
}
return $title;
}
function DisplayComment($commentid)
{
global $DB, $rootpath, $userinfo;
$comment = $DB->query_first("SELECT *, p.name as pluginname FROM " . TABLE_PREFIX . "comments c
LEFT JOIN " . TABLE_PREFIX . "plugins p
ON p.pluginid = c.pluginid
WHERE commentid = '$commentid'");
PrintSection('Edit Comment');
echo '
Delete Comment:
Delete this comment?
Plugin:
'.$comment['pluginname'].'
Item:
'.TranslateObjectID($comment['pluginid'], $comment['objectid']).'
User Name:
Comment:
'.$comment['comment'].'
';
EndSection();
}
function DisplayPluginCounts()
{
global $DB;
$getcomments = $DB->query("SELECT p.pluginid, p.name AS pluginname, COUNT(*) As count FROM " . TABLE_PREFIX . "comments c
LEFT JOIN " . TABLE_PREFIX . "plugins p
ON p.pluginid = c.pluginid
GROUP BY p.pluginid
ORDER BY count DESC");
PrintSection('Comments By Plugin');
echo '
Plugin
Comments
';
while($comment = $DB->fetch_array($getcomments))
{
echo '
' .$comment['pluginname'].'
'.$comment['count'].'
';
}
echo '';
EndSection();
}
// ######################### Instructions ##########################
function PrintInstructions()
{
PrintSection('About Comments Manager');
echo '
Various Subdreamer plugins allow users to leave comments. This tool allows you to edit and delete those comments as required.
';
EndSection();
}
function DisplayComments($pluginid)
{
global $DB;
if($pluginid == -1)
{
// Latest Comments
$title = 'Latest Comments';
$getcomments = $DB->query("SELECT c.*, p.name AS pluginname FROM " . TABLE_PREFIX . "comments c
LEFT JOIN " . TABLE_PREFIX . "plugins p
ON p.pluginid = c.pluginid
ORDER BY date DESC LIMIT 0,10");
}
else
{
$title = $DB->query_first("SELECT name FROM " . TABLE_PREFIX . "plugins
WHERE pluginid = $pluginid");
$title = $title[0] . ' Comments';
$getcomments = $DB->query("SELECT * FROM " . TABLE_PREFIX . "comments
WHERE pluginid = '$pluginid'
ORDER BY date DESC");
}
PrintSection($title);
echo '
Comment';
if($pluginid == -1)
echo 'Plugin';
echo 'Item
Username
Date
Delete
';
while($comment = $DB->fetch_array($getcomments))
{
if(strlen($comment['comment']) == 0)
$comment['comment'] = '(None)';
else if(strlen($comment['comment']) > 20)
$comment['comment'] = substr($comment['comment'], 0, 20) . '...';
echo '
' . $comment['comment'] . '';
if($pluginid == -1)
echo ''.$comment['pluginname'].'';
echo ''.TranslateObjectID($comment['pluginid'], $comment['objectid']).'
'.$comment['username'].'
'.DisplayDate($comment['date']).'
';
}
echo '
';
EndSection();
}
// display the default page
function DisplayDefault()
{
global $DB;
global $pluginid;
PrintInstructions();
DisplayPluginCounts();
DisplayComments(-1);
}
$action = isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : '');
$commentid = is_numeric($_GET['commentid']) ? $_GET['commentid'] : 0;
$pluginid = is_numeric($_GET['pluginid']) ? $_GET['pluginid'] : 0;
// ############################# Select Function ############################
switch($action)
{
case 'displaycomment':
DisplayComment($commentid);
break;
case 'displaycomments':
DisplayComments($pluginid);
break;
case 'deletecomments':
DeleteComments();
break;
case 'updatecomment':
UpdateComment();
break;
default:
DisplayDefault();
}