public function Show($list = false) { global $user; if ($this->parent_obj === false) { return ''; } $sql_where = "`item_id`='" . $this->parent_obj->id() . "' AND `item_type`='" . $this->parent_obj->type() . "'"; $line = getDB()->fetchRow("SELECT COUNT(*) FROM `{$this->db}` WHERE " . $sql_where, false, 'num'); $comments_html = ''; $arrows_html = ''; $commentnum = (int) $line[0]; if ($commentnum) { $comm_pnum = $this->per_page; $comm_order = $this->revers ? 'ASC' : 'DESC'; $list_def = $this->revers ? ceil($commentnum / $comm_pnum) : 1; $list = $list <= 0 ? $list_def : (int) $list; $result = getDB()->ask("SELECT `id` FROM `{$this->db}` " . "WHERE " . $sql_where . " ORDER BY `time` " . $comm_order . " " . "LIMIT " . $comm_pnum * ($list - 1) . "," . $comm_pnum); while ($line = $result->fetch('num')) { $comments_item = new Comments_Item($line[0], $this->st_subdir); $comments_html .= $comments_item->Show($user); unset($comments_item); } $arrows_html = $this->arrowsGenerator($this->work_script, $list, $commentnum, $comm_pnum); } ob_start(); include $this->GetView('comments_container.html'); return ob_get_clean(); }
public function Delete() { global $user, $bd_names; if (empty($user) or !$user->getPermission('add_news') or !$this->Exist()) { return false; } $result = getDB()->ask("SELECT `id` FROM `{$bd_names['comments']}` " . "WHERE `item_id`='" . $this->id . "' AND `item_type` = '" . $this->type() . "'"); loadTool('comment.class.php'); while ($line = $result->fetch('num')) { $comments_item = new Comments_Item($line[0], false); $comments_item->Delete(); unset($comments_item); } getDB()->ask("DELETE FROM `{$bd_names['likes']}` " . "WHERE `item_id` = '" . $this->id . "' AND `item_type` = '" . $this->type() . "'"); return parent::Delete(); }
$item_id = Filter::input('item_id', 'post', 'int'); CaptchaCheck(3); if (empty($user) or !$comment or !$item_type or !$item_id) { aExit(1, lng('MESS_FAIL')); } loadTool('comment.class.php'); $comments_item = new Comments_Item(false, 'news/comments/'); $comments_item->aCreate($comment, $user, $item_id, $item_type); break; case 'del_com': $id = Filter::input('item_id', 'post', 'int'); if (empty($user) or !$id) { aExit(1); } loadTool('comment.class.php'); $comments_item = new Comments_Item($id); if (!$user->getPermission('adm_comm') and $comments_item->GetAuthorID() != $user->id()) { aExit(1); } if ($comments_item->Delete()) { aExit(0); } else { aExit(1); } break; case 'load_info': $id = Filter::input('id', 'post', 'int'); if (!$id) { aExit(1, 'Empty POST param ID'); } loadTool('profile.class.php');
public function Delete() { global $bd_users, $bd_names; if (!$this->id) { return false; } loadTool('catalog.class.php'); $this->deleteCloak(); $this->deleteSkin(); $this->deleteBuffer(); $result = getDB()->ask("SELECT `id` FROM `{$bd_names['comments']}` " . "WHERE `user_id`='{$this->id}'"); while ($line = $result->fetch('num')) { $comment_del = new Comments_Item($line[0]); $comment_del->Delete(); unset($comment_del); } getDB()->ask("DELETE FROM `{$this->db}` WHERE `{$bd_users['id']}`= '{$this->id}'"); $this->id = false; return true; }