A tumblelog CMS built on AJAX, PHP and MySQL.

comments.php 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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/mootools.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. <!--
  65. window.onload = function() {
  66. contenedor = new Fx.Style('divMessages', 'opacity', {duration: 5000, onComplete:
  67. function() {
  68. document.getElementById('divMessages').style.display="none";
  69. }
  70. });
  71. contenedor.custom(1,0);
  72. }
  73. -->
  74. </script>
  75. <style type="text/css" media="screen">
  76. @import "<?php echo $conf->urlGelato;?>/admin/css/style.css";
  77. </style>
  78. </head>
  79. <body>
  80. <div id="div-process" style="display:none;"><?=__("Processing request&hellip;");?></div>
  81. <div id="cont">
  82. <div id="head">
  83. <h1><a href="<?php echo $conf->urlGelato;?>/" title="gelato :: <?=__("home")?>">gelato cms</a></h1>
  84. <ul id="nav">
  85. <li><a href="<?php echo $conf->urlGelato;?>/" title="<?=__("Take me to the tumblelog")?>"><?=__("Back to the Tumblelog")?></a></li>
  86. </ul>
  87. </div>
  88. <div id="main">
  89. <div class="box">
  90. <ul class="menu manage">
  91. <h3><?=__("Manage comments")?></h3>
  92. <li><a href="index.php"><?=__("Posts")?></a></li>
  93. <li <?php if (isset($_GET["spam"])) { ?> class="selected" <?php } ?>><a href="comments.php?spam=true"><?=__("Spam")?></a></li>
  94. <li <?php if (!isset($_GET["spam"])) { ?> class="selected" <?php } ?> ><a href="comments.php"><?php echo ($isEdition) ? __("Edit") : __("List"); ?></a></li>
  95. </ul>
  96. <p>&nbsp;</p>
  97. <?php
  98. if (isset($_GET["deleted"])) {
  99. if ($_GET["deleted"]=="true") {
  100. echo "<div class=\"exito\" id=\"divMessages\">".__("The comment has been eliminated successfully.")."</div>";
  101. }
  102. if ($_GET["deleted"]=="false") {
  103. echo "<div class=\"error\" id=\"divMessages\">".__("The post has NOT been eliminated.")."</div>";
  104. }
  105. }
  106. if (isset($_GET["modified"])) {
  107. if ($_GET["modified"]=="true") {
  108. echo "<div class=\"exito\" id=\"divMessages\">".__("The comment has been modified successfully.")."</div>";
  109. }
  110. if ($_GET["modified"]=="false") {
  111. echo "<div class=\"error\" id=\"divMessages\">".__("The post has NOT been modified.")."</div>";
  112. }
  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->urlGelato."/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") { $sp = "1"; } else { $sp = null; }
  137. $rs = $comment->getComments(null, $limit, $from, $sp);
  138. if ($comment->contarRegistros()>0) {
  139. while($rowComment = mysql_fetch_array($rs)) {
  140. $commentAuthor = ($rowComment["web"]=="") ? $rowComment["username"]." | ".$rowComment["email"] : "<a href=\"".$rowComment["web"]."\" rel=\"external\">".$rowComment["username"]."</a> | ".$rowComment["email"];
  141. $input = array("{Permalink}", "{URL_Tumble}", "{Id_Comment}", "{Comment_Author}", "{Comment}");
  142. $output = array($conf->urlGelato."/index.php/post/".$rowComment["id_post"]."#comment-".$rowComment["id_comment"], $conf->urlGelato, $rowComment["id_comment"], $commentAuthor, $rowComment["content"]);
  143. $template->cargarPlantilla($input, $output, "template_comment");
  144. $template->mostrarPlantilla();
  145. }
  146. $p = new pagination;
  147. $p->items($comment->countComments());
  148. $p->limit($limit);
  149. $p->currentPage(isset($page_num) ? $page_num : 1);
  150. $p->show();
  151. }
  152. }
  153. ?>
  154. </div>
  155. <div class="footer-box">&nbsp;</div>
  156. </div>
  157. </div>
  158. <div id="foot">
  159. <a href="http://www.gelatocms.com/" title="gelato CMS">gelato CMS</a> :: PHP/MySQL Tumblelog Content Management System.
  160. </div>
  161. </div>
  162. </body>
  163. </html>
  164. <?php
  165. } else {
  166. header("Location: ".$conf->urlGelato."/login.php");
  167. }
  168. ?>