A tumblelog CMS built on AJAX, PHP and MySQL.

comments.php 6.9KB

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