A tumblelog CMS built on AJAX, PHP and MySQL.

comments.class.php 3.9KB

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