A tumblelog CMS built on AJAX, PHP and MySQL.

comments.class.php 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. if (!defined('entry') || !entry) {
  3. die('Not a valid page');
  4. }
  5. /* ===========================
  6. gelato CMS - A PHP based tumblelog CMS
  7. development version
  8. http://www.gelatocms.com/
  9. gelato CMS is a free software licensed under the GPL 2.0
  10. Copyright (C) 2007 by Pedro Santana <pecesama at gmail dot com>
  11. =========================== */
  12. class comments
  13. {
  14. public $db;
  15. public $conf;
  16. public function __construct()
  17. {
  18. global $db;
  19. global $conf;
  20. $this->db = $db;
  21. $this->conf = $conf;
  22. }
  23. public function addComment($fieldsArray)
  24. {
  25. if ($this->db->insertarDeFormulario($this->conf->tablePrefix."comments", $fieldsArray)) {
  26. return true;
  27. } else {
  28. return false;
  29. }
  30. }
  31. public function generateCookie($fieldsArray)
  32. {
  33. $path = dirname(dirname($_SERVER['SCRIPT_NAME']."../"));
  34. setcookie("cookie_gel_user", $fieldsArray["username"], time() + 30000000, $path);
  35. setcookie("cookie_gel_email", $fieldsArray["email"], time() + 30000000, $path);
  36. setcookie("cookie_gel_web", $fieldsArray["web"], time() + 30000000, $path);
  37. }
  38. public function isSpam($fieldsArray)
  39. {
  40. if (preg_match("/^\d+$/", $fieldsArray["username"])) {
  41. return true;
  42. } elseif (trim($fieldsArray["content"]) == "") {
  43. return true;
  44. } elseif (preg_match("/^\d+$/", $fieldsArray["content"])) {
  45. return true;
  46. } elseif (strtolower($fieldsArray["content"]) == strtolower($fieldsArray["username"])) {
  47. return true;
  48. } elseif (preg_match("#^<strong>[^.]+\.\.\.</strong>#", $fieldsArray["content"])) {
  49. return true;
  50. } elseif (3 <= preg_match_all("/a href=/", strtolower($fieldsArray["content"]), $matches)) {
  51. return true;
  52. } elseif ($this->isBadWord($fieldsArray["content"])) {
  53. return true;
  54. } else {
  55. return false;
  56. }
  57. }
  58. public function isBadWord($str="")
  59. {
  60. $bads = array("puto", "viagra", "ringtones", "casino", "buy", "cheap", "order", "poker", "discount", "fuck", "cool", "site", "online", "very", "cholesterol", "milf", "sex", "sexo", "arredamento", "reddit", "sesso", "lesbico", "vzge", "angelcities", "porno", "holdem", "blackjack", "black-jack", "mortgage", "pharmacy", "loan", "refinance", "credit", "alberghi", "scarica", "hotel", "cellulare", "giochi", "gratis", "gif", "animata", "fantasy", "albergo", "blowjob", "delicio", "cosco", "dealerships");
  61. for ($i=0;$i<sizeof($bads);$i++) {
  62. if (eregi($bads[$i], $str)) {
  63. return true;
  64. }
  65. }
  66. return false;
  67. }
  68. public function getComments($idPost=null, $limit=null, $from=null, $spam=null)
  69. {
  70. if (isset($idPost)) {
  71. $this->db->ejecutarConsulta("select * from ".$this->conf->tablePrefix."comments WHERE id_post=".$idPost." AND spam=0 order by comment_date ASC");
  72. } else {
  73. if (isset($limit) && isset($from)) {
  74. $limit = " LIMIT $from, $limit";
  75. } else {
  76. "";
  77. }
  78. if (isset($spam)) {
  79. $sp = "1";
  80. } else {
  81. $sp = "0";
  82. }
  83. $this->db->ejecutarConsulta("select * from ".$this->conf->tablePrefix."comments WHERE spam=".$sp." order by comment_date ASC".$limit);
  84. }
  85. return $this->db->mid_consulta;
  86. }
  87. public function getComment($id="")
  88. {
  89. $this->db->ejecutarConsulta("select * from ".$this->conf->tablePrefix."comments WHERE id_comment=".$id);
  90. return $this->db->mid_consulta->fetch();
  91. }
  92. public function countComments($idPost=null)
  93. {
  94. if (isset($idPost)) {
  95. $this->db->ejecutarConsulta("select * from ".$this->conf->tablePrefix."comments WHERE id_post=".$idPost." AND spam=0");
  96. } else {
  97. $this->db->ejecutarConsulta("select * from ".$this->conf->tablePrefix."comments WHERE spam=0");
  98. }
  99. return $this->db->contarRegistros();
  100. }
  101. public function deleteComment($idComment)
  102. {
  103. if ($this->db->ejecutarConsulta("DELETE FROM ".$this->conf->tablePrefix."comments WHERE id_comment=".$idComment)) {
  104. return true;
  105. } else {
  106. return false;
  107. }
  108. }
  109. public function modifyComment($fieldsArray, $id_comment)
  110. {
  111. if ($this->db->modificarDeFormulario($this->conf->tablePrefix."comments", $fieldsArray, "id_comment=$id_comment")) {
  112. return true;
  113. } else {
  114. return false;
  115. }
  116. }
  117. }