A tumblelog CMS built on AJAX, PHP and MySQL.

comments.class.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. if(!defined('entry') || !entry) die('Not a valid page');
  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. class comments {
  11. var $db;
  12. var $conf;
  13. function comments() {
  14. global $db;
  15. global $conf;
  16. $this->db = $db;
  17. $this->conf = $conf;
  18. }
  19. function addComment($fieldsArray) {
  20. if ($this->db->insertarDeFormulario($this->conf->tablePrefix."comments", $fieldsArray)) {
  21. return true;
  22. } else {
  23. return false;
  24. }
  25. }
  26. function generateCookie($fieldsArray) {
  27. $path = dirname(dirname($_SERVER['SCRIPT_NAME']."../"));
  28. setcookie("cookie_gel_user", $fieldsArray["username"], time() + 30000000, $path);
  29. setcookie("cookie_gel_email", $fieldsArray["email"], time() + 30000000, $path);
  30. setcookie("cookie_gel_web", $fieldsArray["web"], time() + 30000000, $path);
  31. }
  32. function isSpam($fieldsArray) {
  33. if (preg_match( "/^\d+$/", $fieldsArray["username"])) { return true; }
  34. elseif (trim($fieldsArray["content"]) == "") { return true; }
  35. elseif (preg_match( "/^\d+$/", $fieldsArray["content"])) { return true; }
  36. elseif (strtolower($fieldsArray["content"]) == strtolower($fieldsArray["username"])) { return true; }
  37. elseif (preg_match("#^<strong>[^.]+\.\.\.</strong>#", $fieldsArray["content"])) { return true; }
  38. elseif (3 <= preg_match_all("/a href=/", strtolower($fieldsArray["content"]), $matches)) { return true; }
  39. elseif ($this->isBadWord($fieldsArray["content"])) { return true; }
  40. else { return false; }
  41. }
  42. function isBadWord($str="") {
  43. $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");
  44. for($i=0;$i<sizeof($bads);$i++) {
  45. if(eregi($bads[$i],$str)) return true;
  46. }
  47. return false;
  48. }
  49. function getComments($idPost=null, $limit=null, $from=null, $spam=null) {
  50. if (isset($idPost)) {
  51. $this->db->ejecutarConsulta("select * from ".$this->conf->tablePrefix."comments WHERE id_post=".$idPost." AND spam=0 order by comment_date ASC");
  52. } else {
  53. if (isset($limit) && isset($from)) {
  54. $limit = " LIMIT $from, $limit";
  55. } else { ""; }
  56. if (isset($spam)) { $sp = "1"; } else { $sp = "0"; }
  57. $this->db->ejecutarConsulta("select * from ".$this->conf->tablePrefix."comments WHERE spam=".$sp." order by comment_date ASC".$limit);
  58. }
  59. return $this->db->mid_consulta;
  60. }
  61. function getComment($id="") {
  62. $this->db->ejecutarConsulta("select * from ".$this->conf->tablePrefix."comments WHERE id_comment=".$id);
  63. return mysql_fetch_array($this->db->mid_consulta);
  64. }
  65. function countComments($idPost=null) {
  66. if (isset($idPost)) {
  67. $this->db->ejecutarConsulta("select * from ".$this->conf->tablePrefix."comments WHERE id_post=".$idPost." AND spam=0");
  68. } else {
  69. $this->db->ejecutarConsulta("select * from ".$this->conf->tablePrefix."comments WHERE spam=0");
  70. }
  71. return $this->db->contarRegistros();
  72. }
  73. function deleteComment($idComment) {
  74. if ($this->db->ejecutarConsulta("DELETE FROM ".$this->conf->tablePrefix."comments WHERE id_comment=".$idComment)) {
  75. return true;
  76. } else {
  77. return false;
  78. }
  79. }
  80. function modifyComment($fieldsArray, $id_comment) {
  81. if ($this->db->modificarDeFormulario($this->conf->tablePrefix."comments", $fieldsArray, "id_comment=$id_comment")) {
  82. return true;
  83. } else {
  84. return false;
  85. }
  86. }
  87. }
  88. ?>