A tumblelog CMS built on AJAX, PHP and MySQL.

comments.class.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /* ===========================
  3. gelato CMS - A PHP based tumblelog CMS
  4. development version
  5. http://www.gelatocms.com/
  6. gelato CMS is a free software licensed under the GPL 2.0
  7. Copyright (C) 2007 by Pedro Santana <pecesama at gmail dot com>
  8. =========================== */
  9. ?>
  10. <?php
  11. require_once("configuration.class.php");
  12. require_once("functions.php");
  13. class comments extends Conexion_Mysql {
  14. var $conf;
  15. function comments() {
  16. parent::Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
  17. $this->conf = new configuration();
  18. }
  19. function addComment($fieldsArray) {
  20. if ($this->insertarDeFormulario($this->conf->tablePrefix."comments", $fieldsArray)) {
  21. return true;
  22. } else {
  23. return false;
  24. }
  25. }
  26. function generateCookie($fieldsArray) {
  27. setcookie("cookie_gel_user", $fieldsArray["username"], time() + 30000000);
  28. setcookie("cookie_gel_email", $fieldsArray["email"], time() + 30000000);
  29. setcookie("cookie_gel_web", $fieldsArray["web"], time() + 30000000);
  30. }
  31. function isSpam($fieldsArray) {
  32. if (preg_match( "/^\d+$/", $fieldsArray["username"])) { return true; }
  33. elseif (trim($fieldsArray["content"]) == "") { return true; }
  34. elseif (preg_match( "/^\d+$/", $fieldsArray["content"])) { return true; }
  35. elseif (strtolower($fieldsArray["content"]) == strtolower($fieldsArray["username"])) { return true; }
  36. elseif (preg_match("#^<strong>[^.]+\.\.\.</strong>#", $fieldsArray["content"])) { return true; }
  37. elseif (3 <= preg_match_all("/a href=/", strtolower($fieldsArray["content"]), $matches)) { return true; }
  38. elseif ($this->isBadWord($fieldsArray["content"])) { return true; }
  39. else { return false; }
  40. }
  41. function isBadWord($str="") {
  42. $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");
  43. for($i=0;$i<sizeof($bads);$i++) {
  44. if(eregi($bads[$i],$str)) return true;
  45. }
  46. return false;
  47. }
  48. function getComments($idPost=null, $limit=null, $from=null, $spam=null) {
  49. if (isset($idPost)) {
  50. $this->ejecutarConsulta("select * from ".$this->conf->tablePrefix."comments WHERE id_post=".$idPost." AND spam=0 order by comment_date ASC");
  51. } else {
  52. if (isset($limit) && isset($from)) {
  53. $limit = " LIMIT $from, $limit";
  54. } else { ""; }
  55. if (isset($spam)) { $sp = "1"; } else { $sp = "0"; }
  56. $this->ejecutarConsulta("select * from ".$this->conf->tablePrefix."comments WHERE spam=".$sp." order by comment_date ASC".$limit);
  57. }
  58. return $this->mid_consulta;
  59. }
  60. function getComment($id="") {
  61. $this->ejecutarConsulta("select * from ".$this->conf->tablePrefix."comments WHERE id_comment=".$id);
  62. return mysql_fetch_array($this->mid_consulta);
  63. }
  64. function countComments($idPost=null) {
  65. if (isset($idPost)) {
  66. $this->ejecutarConsulta("select * from ".$this->conf->tablePrefix."comments WHERE id_post=".$idPost." AND spam=0");
  67. } else {
  68. $this->ejecutarConsulta("select * from ".$this->conf->tablePrefix."comments WHERE spam=0");
  69. }
  70. return $this->contarRegistros();
  71. }
  72. function deleteComment($idComment) {
  73. if ($this->ejecutarConsulta("DELETE FROM ".$this->conf->tablePrefix."comments WHERE id_comment=".$idComment)) {
  74. return true;
  75. } else {
  76. return false;
  77. }
  78. }
  79. function modifyComment($fieldsArray, $id_comment) {
  80. if ($this->modificarDeFormulario($this->conf->tablePrefix."comments", $fieldsArray, "id_comment=$id_comment")) {
  81. return true;
  82. } else {
  83. return false;
  84. }
  85. }
  86. }
  87. ?>