⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 comments.php

📁 CMS系统
💻 PHP
字号:
<?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 '<form method="post" action="comments.php">
        <input type="hidden" name="commentid"  value="'.$commentid.'" />
                <input type="hidden" name="action" value="updatecomment" />

        <table width="100%" border="0" cellpadding="5" cellspacing="0">
                <tr>
            <td class="tdrow2" width="15%"><b>Delete Comment:</b></td>
            <td class="tdrow3" width="75%" valign="top">
              <input type="checkbox" name="deletecomment"  value="1"> Delete this comment?
            </td>
        </tr>
                <tr>
          <td class="tdrow2" width="15%"><b>Plugin:</b></td>
          <td class="tdrow3" width="75%" valign="top">'.$comment['pluginname'].'
          </td>
        </tr>
                <tr>
          <td class="tdrow2" width="15%"><b>Item:</b></td>
          <td class="tdrow3" width="75%" valign="top">'.TranslateObjectID($comment['pluginid'], $comment['objectid']).'
          </td>
        </tr>
                <tr>
          <td class="tdrow2" width="15%"><b>User Name:</b></td>
          <td class="tdrow3" width="75%" valign="top">
            <input type="text" name="username" value="'.CleanFormValue($comment['username']).'" />
          </td>
        </tr>
        <tr>
          <td class="tdrow2" width="15%" valign="top"><b>Comment:</b></td>
          <td class="tdrow3" width="75%" valign="top">
            <textarea name="comment" cols="54" rows="5">'.$comment['comment'].'</textarea>
          </td>
        </tr>
        <tr>
          <td colspan="2" align="center" class="tdrow1">
            <input type="submit" value="Update Comment" />
                  </td>
        </tr>
        </table>
        </form>';
  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 '<table width="100%" border="0" cellpadding="5" cellspacing="0">
        <tr>
          <td class="tdrow1">Plugin</td>
          <td class="tdrow1">Comments</td>
        </tr>';

  while($comment = $DB->fetch_array($getcomments))
  {
    echo '<tr>
            <td class="tdrow2"><a href="comments.php?action=displaycomments&pluginid=' . $comment['pluginid']. '">' .$comment['pluginname'].'</a></td>
            <td class="tdrow3">'.$comment['count'].'</td>
          </tr>';
  }

  echo '</table>';

  EndSection();

}


// ######################### Instructions ##########################

function PrintInstructions()
{
  PrintSection('About Comments Manager');
  echo '<table width="100%" border="0" cellpadding="5" cellspacing="0">
        <tr>
          <td class="tdrow2">
          Various Subdreamer plugins allow users to leave comments. This tool allows you to edit and delete those comments as required.
          </td>
        </tr>
        </table>';
  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 '<form action="comments.php" method="POST">
        <input type="hidden" name="action" value="deletecomments" />

        <table width="100%" border="0" cellpadding="5" cellspacing="0">
        <tr>
          <td class="tdrow1">Comment</td>';
  if($pluginid == -1)
    echo '<td class="tdrow1">Plugin</td>';

  echo   '<td class="tdrow1">Item</td>
          <td class="tdrow1">Username</td>
          <td class="tdrow1">Date</td>
          <td class="tdrow1" width="150">Delete</td>
        </tr>';

  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 '<tr>
            <td class="tdrow2"><a href="comments.php?action=displaycomment&commentid=' . $comment['commentid']. '">' . $comment['comment'] . '</a></td>';

        if($pluginid == -1)
          echo '<td class="tdrow3">'.$comment['pluginname'].'</td>';

        echo   '<td class="tdrow2">'.TranslateObjectID($comment['pluginid'], $comment['objectid']).'</td>
            <td class="tdrow3">'.$comment['username'].'</td>
                        <td class="tdrow2">'.DisplayDate($comment['date']).'</td>
            <td class="tdrow3"><input type="checkbox" name="commentids[]" value="'.$comment['commentid'].'" /></td>
          </tr>';
  }

  echo '<tr>
          <td class="tdrow1" bgcolor="#FCFCFC" colspan="6" align="center">
           <input type="submit" value="Delete Comments" />
          </td>
        </tr>
        </table>

        </form>';

  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();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -