A tumblelog CMS built on AJAX, PHP and MySQL.

comments.class.php 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. if (!defined('entry') || !entry) {
  3. die('Not a valid page');
  4. }
  5. /* ===========================
  6. Sorbet CMS - A PHP based tumblelog CMS forked from Gelato CMS
  7. Sorbet CMS is a free software licensed under the GPL 3.0
  8. =========================== */
  9. class comments
  10. {
  11. public $db;
  12. public $conf;
  13. public function __construct()
  14. {
  15. global $db;
  16. global $conf;
  17. $this->db = $db;
  18. $this->conf = $conf;
  19. }
  20. public function addComment($fieldsArray)
  21. {
  22. if ($this->db->insertarDeFormulario($this->conf->tablePrefix."comments", $fieldsArray)) {
  23. return true;
  24. } else {
  25. return false;
  26. }
  27. }
  28. public function generateCookie($fieldsArray)
  29. {
  30. $path = dirname(dirname($_SERVER['SCRIPT_NAME']."../"));
  31. setcookie("cookie_sor_user", $fieldsArray["username"], time() + 30000000, $path);
  32. setcookie("cookie_sor_email", $fieldsArray["email"], time() + 30000000, $path);
  33. setcookie("cookie_sor_web", $fieldsArray["web"], time() + 30000000, $path);
  34. }
  35. public function isSpam($fieldsArray)
  36. {
  37. if (preg_match("/^\d+$/", $fieldsArray["username"])) {
  38. return true;
  39. } elseif (trim($fieldsArray["content"]) == "") {
  40. return true;
  41. } elseif (preg_match("/^\d+$/", $fieldsArray["content"])) {
  42. return true;
  43. } elseif (strtolower($fieldsArray["content"]) == strtolower($fieldsArray["username"])) {
  44. return true;
  45. } elseif (preg_match("#^<strong>[^.]+\.\.\.</strong>#", $fieldsArray["content"])) {
  46. return true;
  47. } elseif (3 <= preg_match_all("/a href=/", strtolower($fieldsArray["content"]), $matches)) {
  48. return true;
  49. } elseif ($this->isBadWord($fieldsArray["content"])) {
  50. return true;
  51. } else {
  52. return false;
  53. }
  54. }
  55. public function isBadWord($str="")
  56. {
  57. $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");
  58. for ($i=0;$i<sizeof($bads);$i++) {
  59. if (preg_match("/".$bads[$i]."/i", $str)) {
  60. return true;
  61. }
  62. }
  63. return false;
  64. }
  65. public function getComments($idPost=null, $limit=null, $from=null, $spam=null)
  66. {
  67. if (isset($idPost)) {
  68. $this->db->ejecutarConsulta("select * from ".$this->conf->tablePrefix."comments WHERE id_post=".$idPost." AND spam=0 order by comment_date ASC");
  69. } else {
  70. if (isset($limit) && isset($from)) {
  71. $limit = " LIMIT $from, $limit";
  72. } else {
  73. "";
  74. }
  75. if (isset($spam)) {
  76. $sp = "1";
  77. } else {
  78. $sp = "0";
  79. }
  80. $this->db->ejecutarConsulta("select * from ".$this->conf->tablePrefix."comments WHERE spam=".$sp." order by comment_date ASC".$limit);
  81. }
  82. return $this->db->mid_consulta;
  83. }
  84. public function getComment($id="")
  85. {
  86. $this->db->ejecutarConsulta("select * from ".$this->conf->tablePrefix."comments WHERE id_comment=".$id);
  87. return $this->db->mid_consulta->fetch();
  88. }
  89. public function countComments($idPost=null)
  90. {
  91. if (isset($idPost)) {
  92. $this->db->ejecutarConsulta("select * from ".$this->conf->tablePrefix."comments WHERE id_post=".$idPost." AND spam=0");
  93. } else {
  94. $this->db->ejecutarConsulta("select * from ".$this->conf->tablePrefix."comments WHERE spam=0");
  95. }
  96. return $this->db->contarRegistros();
  97. }
  98. public function deleteComment($idComment)
  99. {
  100. if ($this->db->ejecutarConsulta("DELETE FROM ".$this->conf->tablePrefix."comments WHERE id_comment=".$idComment)) {
  101. return true;
  102. } else {
  103. return false;
  104. }
  105. }
  106. public function modifyComment($fieldsArray, $id_comment)
  107. {
  108. if ($this->db->modificarDeFormulario($this->conf->tablePrefix."comments", $fieldsArray, "id_comment=$id_comment")) {
  109. return true;
  110. } else {
  111. return false;
  112. }
  113. }
  114. }