A tumblelog CMS built on AJAX, PHP and MySQL.

comments.php 6.9KB

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