A tumblelog CMS built on AJAX, PHP and MySQL.

comments.php 8.2KB

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