A tumblelog CMS built on AJAX, PHP and MySQL.

comments.php 7.2KB

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