A tumblelog CMS built on AJAX, PHP and MySQL.

comments.php 7.8KB

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