A tumblelog CMS built on AJAX, PHP and MySQL.

comments.php 6.8KB

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