Просмотр файла system/classes/comments.php

Размер файла: 3.68Kb
  1. <?php
  2. /**********************************
  3. * @package: PerfCMS *
  4. * @year: 2012 *
  5. * @author: Artas *
  6. * @link: http://perfcms.ru *
  7. **********************************/
  8. class Comments {
  9. protected $module;
  10. protected $module_id;
  11. protected $params;
  12. protected $ret;
  13. protected $mod;
  14. public function __construct($module = '', $module_id = '', $params = '', $ret='', $mod='') {
  15. if($module != '' && $module_id != '') {
  16. $this->module = $module;
  17. $this->module_id = abs(intval($module_id));
  18. $this->params = $params;
  19. $this->ret = $ret;
  20. $this->mod = $mod;
  21. }
  22. else {
  23. echo "<b>Undefined Comments module or comments parameter id!</b>\n<br/>
  24. Change string \$module and \$module_id\n";
  25. }
  26. }
  27. public function view() {
  28. global $db;
  29. global $user;
  30. global $ames;
  31. global $start;
  32. global $lang;
  33. global $tpl;
  34. global $settings;
  35. $comments_r = $db->query("SELECT * FROM `". $this->module ."_comms` WHERE `". $this->module ."_id` = '".$this->module_id ."' ". ($this->params != "" ? $this->params : NULL) ."")->rowCount();
  36. $pages = new Paginator($comments_r, $ames);
  37. if($comments_r == 0) {
  38. echo $tpl->div('menu', $lang->word('no_posts'));
  39. }
  40. else {
  41. $comments_q = $db->query("SELECT * FROM `". $this->module ."_comms` WHERE `". $this->module ."_id` = '".$this->module_id ."' ". ($this->params != "" ? $this->params : NULL) ." ORDER BY time DESC LIMIT $start, $ames");
  42. while($comments = $comments_q->fetch()) {
  43. echo '<div class="post">'. nick($comments['user_id']) . ($user['level'] >=5 || $comments['user_id'] == $user['id'] ? '<a href="/'. $this->module .'/delete_comment/'. abs(intval($_GET[$this->module .'_id'])) .'/?post_id='. $comments['id'] .'">'. img('delete.png') .'</a>' : NULL) .'<br/>
  44. '. output($comments['text']) .'<br/>
  45. <small>('.rtime($comments['time']).')</small></div>';
  46. }
  47. $pages->view('/'. $this->module .'/'. abs(intval($_GET[$this->module .'_id'])) .'/comments/?');
  48. }
  49. if($settings['fast_mess'] == 'yes') {
  50. $tpl->div('post', '<form action="/'.$this->module.'/add_comment/?act=create&amp;'. $this->module .'_id='. $this->module_id .'" method="post">
  51. <textarea name="text" rows="5" cols="26">'.(isset($_GET['reply_to']) ? '[b]'.tnick($_GET['reply_to']).'[/b], ' : NULL).'</textarea>
  52. <br/>
  53. <input type="submit" name="create" value="'. $lang->word('send') .'" /><br/>
  54. </form>');
  55. }
  56. }
  57. public function add($text) {
  58. global $db;
  59. global $user;
  60. if(!empty($text) && !empty($this->module_id)) {
  61. $text = substr(input($text), 0, 3000);
  62. $module_id = abs(intval($this->module_id));
  63. if($db->query("SELECT * FROM `". $this->module ."` WHERE `id` = '". $module_id ."' LIMIT 1")->rowCount() != 0) {
  64. $db->query("INSERT INTO `". (!empty($this->ret) ? $this->ret ."_comms`":$this->module."_comms`")." (`". (!empty($this->ret) ? $this->ret ."_id`":$this->module."_id`").", `text`, `time`, `user_id`) VALUES('".$module_id ."', '". $text ."', '". time() ."', '". $user['id'] ."')");
  65. // print_r($db->errorInfo());
  66. if(!empty($this->ret)) { $this->module = $this->ret; }
  67. header("Location: /". $this->module ."/".$module_id ."/comments");
  68. } else {
  69. header("Location: /". $this->module ."/".$module_id ."");
  70. }
  71. } else {
  72. header("Location: /". $this->module ."/".$module_id ."");
  73. }
  74. }
  75. public function delete($post_ids) {
  76. global $db;
  77. $post_id = abs(intval($post_ids));
  78. if(!empty($this->ret)) { $this->module = $this->ret; }
  79. $db->query("DELETE FROM `".$this->module."_comms` WHERE `id` = '". $post_id ."'");
  80. // print_r($db->errorInfo());
  81. header('Location: /'. $this->module .'/'. $this->module_id .'/comments/');
  82. }
  83. }