A tumblelog CMS built on AJAX, PHP and MySQL.

comments.php 7.1KB

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