A tumblelog CMS built on AJAX, PHP and MySQL.

comments.php 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. if (!defined('entry')) {
  3. define('entry', true);
  4. }
  5. /* ===========================
  6. Sorbet CMS - A PHP based tumblelog CMS forked from Gelato CMS
  7. Sorbet CMS is a free software licensed under the GPL 3.0
  8. =========================== */
  9. ?>
  10. <?php
  11. require_once '../entry.php';
  12. global $user, $conf, $tumble;
  13. $comment = new comments();
  14. $template = new plantillas("admin");
  15. $isAdmin = $user->isAdmin();
  16. $isEdition = isset($_GET["edit"]);
  17. $commentId = ($isEdition) ? $_GET["edit"] : null;
  18. if (isset($_POST["btnAdd"])) {
  19. unset($_POST["btnAdd"]);
  20. $_POST["username"] = strip_tags($_POST["username"]);
  21. $_POST["email"] = strip_tags($_POST["email"]);
  22. $_POST["web"] = strip_tags($_POST["web"]);
  23. $_POST["content"] = util::removeBadTags($_POST["content"], true);
  24. if (isset($_POST["id_comment"])) {
  25. if ($isAdmin) {
  26. if ($comment->modifyComment($_POST, $_POST["id_comment"])) {
  27. header("Location: comments.php?modified=true");
  28. die();
  29. } else {
  30. header("Location: comments.php?modified=false");
  31. die();
  32. }
  33. }
  34. } else {
  35. $comment->generateCookie($_POST);
  36. $_POST["spam"] = ($comment->isSpam($_POST)) ? "1" : "0";
  37. $_POST["ip_user"] = $_SERVER["REMOTE_ADDR"];
  38. $strEnd=($conf->urlFriendly) ? "/" : "";
  39. if ($comment->addComment($_POST)) {
  40. header("Location: ".$conf->urlSorbet.($conf->urlFriendly?"/post/":"/index.php?post=").$_POST["id_post"].$strEnd);
  41. die();
  42. } else {
  43. header("Location: ".$conf->urlSorbet.($conf->urlFriendly?"/post/":"/index.php?post=").$_POST["id_post"].$strEnd);
  44. die();
  45. }
  46. }
  47. }
  48. if ($isAdmin) {
  49. if (isset($_GET["delete"])) {
  50. if ($comment->deleteComment($_GET['delete'])) {
  51. header("Location: comments.php?deleted=true");
  52. die();
  53. } else {
  54. header("Location: comments.php?deleted=false");
  55. die();
  56. }
  57. } ?>
  58. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  59. <html xmlns="http://www.w3.org/1999/xhtml">
  60. <head>
  61. <title>sorbet :: <?php echo __("comments")?></title>
  62. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  63. <meta name="generator" content="sorbet cms <?php echo util::version(); ?>" />
  64. <link rel="shortcut icon" href="<?php echo $conf->urlSorbet; ?>/images/favicon.ico" />
  65. <script language="javascript" type="text/javascript" src="<?php echo $conf->urlSorbet; ?>/admin/scripts/jquery.js"></script>
  66. <script language="javascript" type="text/javascript" src="<?php echo $conf->urlSorbet; ?>/admin/scripts/tools.js"></script>
  67. <script language="javascript" type="text/javascript">
  68. $(document).ready(function(){
  69. $("#divMessages").fadeOut(5000,function(){
  70. $("#divMessages").css({display:"none"});
  71. });
  72. });
  73. </script>
  74. <style type="text/css" media="screen">
  75. @import "<?php echo $conf->urlSorbet; ?>/admin/css/style.css";
  76. </style>
  77. </head>
  78. <body>
  79. <div id="div-process" style="display:none;"><?=__("Processing request&hellip;"); ?></div>
  80. <div id="cont">
  81. <div id="head">
  82. <h1><a href="<?php echo $conf->urlSorbet; ?>/admin/index.php" title="sorbet :: <?=__("home")?>">sorbet cms</a></h1>
  83. <ul id="nav">
  84. <li><a href="<?php echo $conf->urlSorbet; ?>/" title="<?=__("Take me to the tumblelog")?>"><?=__("Back to the Tumblelog")?></a></li>
  85. </ul>
  86. </div>
  87. <div id="main">
  88. <div class="box">
  89. <ul class="menu manage">
  90. <h3><?=__("Manage comments")?></h3>
  91. <li><a href="index.php"><?=__("Posts")?></a></li>
  92. <li <?php if (isset($_GET["spam"])) {
  93. ?> class="selected" <?php
  94. } ?>><a href="comments.php?spam=true"><?=__("Spam")?></a></li>
  95. <li <?php if (!isset($_GET["spam"])) {
  96. ?> class="selected" <?php
  97. } ?> ><a href="comments.php"><?php echo ($isEdition) ? __("Edit") : __("List"); ?></a></li>
  98. </ul>
  99. <p>&nbsp;</p>
  100. <?php
  101. if (isset($_GET["deleted"])) {
  102. if ($_GET["deleted"]=="true") {
  103. echo "<div class=\"exito\" id=\"divMessages\">".__("The comment has been eliminated successfully.")."</div>";
  104. }
  105. if ($_GET["deleted"]=="false") {
  106. echo "<div class=\"error\" id=\"divMessages\">".__("The post has NOT been eliminated.")."</div>";
  107. }
  108. }
  109. if (isset($_GET["modified"])) {
  110. if ($_GET["modified"]=="true") {
  111. echo "<div class=\"exito\" id=\"divMessages\">".__("The comment has been modified successfully.")."</div>";
  112. }
  113. if ($_GET["modified"]=="false") {
  114. echo "<div class=\"error\" id=\"divMessages\">".__("The post has NOT been modified.")."</div>";
  115. }
  116. } ?>
  117. <div class="tabla">
  118. <?php
  119. if ($isEdition) {
  120. $row = $comment->getComment($_GET["edit"]);
  121. $date = strtotime($row["comment_date"]);
  122. $input = array("{User}", "{Email}", "{Web}", "{Comment}", "{Id_Post}", "{Date_Added}", "{Id_Comment}", "{Form_Action}");
  123. $output = array($row["username"], $row["email"], $row["web"], $row["content"], $row["id_post"], $date, $row["id_comment"], $conf->urlSorbet."/admin/comments.php");
  124. $template->cargarPlantilla($input, $output, "template_comment_post");
  125. $template->mostrarPlantilla();
  126. } else {
  127. if (isset($_GET["page"]) && is_numeric($_GET["page"])) {
  128. $page_num = $_GET["page"];
  129. } else {
  130. $page_num = null;
  131. }
  132. $limit=$conf->postLimit;
  133. if (isset($page_num) && is_numeric($page_num) && $page_num>0) {
  134. $from = (($page_num-1) * $limit);
  135. } else {
  136. $from = 0;
  137. }
  138. if (isset($_GET["spam"]) && $_GET["spam"]=="true") {
  139. $sp = "1";
  140. } else {
  141. $sp = null;
  142. }
  143. $rs = $comment->getComments(null, $limit, $from, $sp);
  144. if ($db->contarRegistros()>0) {
  145. while ($rowComment = $rs->fetch()) {
  146. $commentAuthor = ($rowComment["web"]=="") ? $rowComment["username"]." | ".$rowComment["email"] : "<a href=\"".$rowComment["web"]."\" rel=\"external\">".$rowComment["username"]."</a> | ".$rowComment["email"];
  147. $input = array("{Permalink}", "{URL_Tumble}", "{Id_Comment}", "{Comment_Author}", "{Comment}");
  148. $output = array($conf->urlSorbet."/index.php/post/".$rowComment["id_post"]."#comment-".$rowComment["id_comment"], $conf->urlSorbet, $rowComment["id_comment"], $commentAuthor, $rowComment["content"]);
  149. $template->cargarPlantilla($input, $output, "template_comment");
  150. $template->mostrarPlantilla();
  151. }
  152. $p = new pagination;
  153. $p->items($comment->countComments());
  154. $p->limit($limit);
  155. $p->currentPage(isset($page_num) ? $page_num : 1);
  156. $p->show();
  157. }
  158. } ?>
  159. </div>
  160. <div class="footer-box">&nbsp;</div>
  161. </div>
  162. </div>
  163. <div id="foot">
  164. Sorbet CMS :: PHP Tumblelog Content Management System.
  165. </div>
  166. </div>
  167. </body>
  168. </html>
  169. <?php
  170. } else {
  171. header("Location: ".$conf->urlSorbet."/login.php");
  172. }
  173. ?>