A tumblelog CMS built on AJAX, PHP and MySQL.

comments.class.php 3.8KB

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