public function execute() { $this->getResponse()->addHeader('Content-type', 'application/json'); if ($comment_id = $this->getRequest()->post('id', 0, waRequest::TYPE_INT)) { $comment_model = new blogCommentModel(); $comment = $comment_model->getById($comment_id); if (!$comment) { throw new waException(_w('Comment not found'), 404); } $post_model = new blogPostModel(); if (!($post = $post_model->getBlogPost(array('id' => $comment['post_id'], 'blog_id' => $comment['blog_id'])))) { throw new waException(_w('Post not found'), 404); } $user_id = $this->getUser()->getId(); $rights = blogHelper::checkRights($comment['blog_id'], $user_id, blogRightConfig::RIGHT_READ_WRITE); if ($rights == blogRightConfig::RIGHT_READ_WRITE && $user_id != $post['contact_id']) { throw new waRightsException(_w('Access denied'), 403); } $status = $this->getRequest()->post('status', blogCommentModel::STATUS_DELETED); if ($status != blogCommentModel::STATUS_DELETED) { $status = blogCommentModel::STATUS_PUBLISHED; } $changed = $comment_model->updateById($comment_id, array('status' => $status)); $count = $comment_model->getCount($comment['blog_id'], $comment['post_id']); if ($changed) { if ($status == blogCommentModel::STATUS_DELETED) { $this->log('comment_delete', 1); } else { $this->log('comment_restore', 1); } } $this->response = array('count_str' => $count . " " . _w('comment', 'comments', $count), 'status' => $status, 'changed' => $changed); } }
public function execute() { if ($target_blog = max(0, $this->getRequest()->post('blog', 0, waRequest::TYPE_INT))) { $blog_model = new blogBlogModel(); if ($blog = $blog_model->getById($target_blog)) { if ($ids = $this->getRequest()->post('id', null, waRequest::TYPE_ARRAY_INT)) { $post_model = new blogPostModel(); $comment_model = new blogCommentModel(); $this->response['moved'] = array(); foreach ($ids as $id) { try { //rights will checked for each record separately $post_model->updateItem($id, array('blog_id' => $target_blog)); $comment_model->updateByField('post_id', $id, array('blog_id' => $target_blog)); $this->response['moved'][$id] = $id; } catch (Exception $ex) { if (!isset($this->response['error'])) { $this->response['error'] = array(); } $this->response['error'][$id] = $ex->getMessage(); } } $this->response['style'] = $blog['color']; $blog_model->recalculate(); } } else { } } }
public function execute() { $id = $this->get('id', true); $comment_model = new blogCommentModel(); $comment = $comment_model->getById($id); if ($comment) { $this->response = $comment; } else { throw new waAPIException('invalid_param', 'Comment not found', 404); } }
static function move($blog_id, $move_blog_id) { if ($blog_id != $move_blog_id) { $post_model = new blogPostModel(); $post_model->updateByField('blog_id', $blog_id, array('blog_id' => $move_blog_id)); $comment_model = new blogCommentModel(); $comment_model->updateByField('blog_id', $blog_id, array('blog_id' => $move_blog_id)); $blog_model = new blogBlogModel(); $blog_model->recalculate(array($blog_id, $move_blog_id)); } }
/** * @param int[] $params Deleted contact_id * @see waEventHandler::execute() * @return void */ public function execute($params) { $contact_model = new waContactModel(); $contacts = $contact_model->getByField('id', $params, true); $post_model = new blogPostModel(); $comment_model = new blogCommentModel(); foreach ($contacts as $contact) { $data = array('contact_id' => 0, 'contact_name' => $contact['name']); $post_model->updateByField('contact_id', $contact['id'], $data); $data = array('contact_id' => 0, 'name' => $contact['name'], 'auth_provider' => null); $comment_model->updateByField('contact_id', $contact['id'], $data); } }
public function execute() { $contact_photo_size = 20; $comments_per_page = max(1, intval($this->getConfig()->getOption('comments_per_page'))); $page = max(1, waRequest::get('page', 1, waRequest::TYPE_INT)); $blog_models = new blogBlogModel(); $user = $this->getUser(); $blogs = blogHelper::getAvailable(); $comment_model = new blogCommentModel(); $offset = $comments_per_page * ($page - 1); $prepare_options = array('datetime' => blogActivity::getUserActivity()); $fields = array("photo_url_{$contact_photo_size}"); $blog_ids = array_keys($blogs); $comments = $comment_model->getList($offset, $comments_per_page, $blog_ids, $fields, $prepare_options); $comments_all_count = $comment_model->getCount($blog_ids, null, null, null, null, null); $post_ids = array(); foreach ($comments as $comment) { $post_ids[$comment['post_id']] = true; } //get related posts info $post_model = new blogPostModel(); $search_options = array('id' => array_keys($post_ids)); $extend_options = array('user' => false, 'link' => true, 'rights' => true, 'plugin' => false, 'comments' => false); $extend_data = array('blog' => $blogs); $posts = $post_model->search($search_options, $extend_options, $extend_data)->fetchSearchAll(false); $comments = blogCommentModel::extendRights($comments, $posts); $comments_count = ($page - 1) * $comments_per_page + count($comments); if ($page == 1) { $this->setLayout(new blogDefaultLayout()); $this->getResponse()->setTitle(_w('Comments')); } /** * Backend comments view page * UI hook allow extends backend comments view page * @event backend_comments * @param array[int][string]mixed $comments * @param array[int][string]int $comments[%id%][id] comment id * @return array[string][string]string $return[%plugin_id%]['toolbar'] Comment's toolbar html */ $this->view->assign('backend_comments', wa()->event('backend_comments', $comments)); $this->view->assign('comments', $comments); $this->view->assign('comments_count', $comments_count); $this->view->assign('comments_total_count', $comments_all_count); $this->view->assign('comments_per_page', $comments_per_page); $this->view->assign('pages', ceil($comments_all_count / $comments_per_page)); $this->view->assign('page', $page); $this->view->assign('contact_rights', $this->getUser()->getRights('contacts', 'backend')); $this->view->assign('current_contact_id', $user->getId()); $this->view->assign('current_contact', array('id' => $user->getId(), 'name' => $user->getName(), 'photo20' => $user->getPhoto($contact_photo_size))); }
/** * @param array $params deleted contact_id * @return array|void */ public function execute(&$params) { waLocale::loadByDomain('blog'); $post_model = new blogPostModel(); $comment_model = new blogCommentModel(); $links = array(); foreach ($params as $contact_id) { $links[$contact_id] = array(); if ($count = $post_model->countByField('contact_id', $contact_id)) { $links[$contact_id][] = array('role' => _wd('blog', 'Posts author'), 'links_number' => $count); } if ($count = $comment_model->countByField('contact_id', $contact_id)) { $links[$contact_id][] = array('role' => _wd('blog', 'Comments author'), 'links_number' => $count); } } return $links; }
public function execute() { $data = waRequest::post(); $exclude = array('left_key', 'right_key', 'type', 'full_url', 'parent_id'); foreach ($exclude as $k) { if (isset($data[$k])) { unset($data[$k]); } } // check required params $this->post('text', true); $post_id = $this->get('post_id', true); $post_model = new blogPostModel(); $post = $post_model->getBlogPost($post_id); if (!$post) { throw new waAPIException('invalid_param', 'Post not found', 404); } $parent_id = $this->post('parent_id'); $comment_model = new blogCommentModel(); if ($parent_id) { $parent = $comment_model->getById($parent_id); if (!$parent) { throw new waAPIException('invalid_param', 'Parent comment not found', 404); } } $contact_id = wa()->getUser()->getId(); // check rights try { blogHelper::checkRights($post['blog_id'], $contact_id, blogRightConfig::RIGHT_READ); } catch (waException $e) { throw new waAPIException('access_denied', 403); } // check comment mode if (!$post['comments_allowed']) { throw new waAPIException('invalid_param', "Isn't allowed comment to this post", 404); } $data = array_merge($data, array('blog_id' => $post['blog_id'], 'post_id' => $post_id, 'contact_id' => $contact_id, 'auth_provider' => blogCommentModel::AUTH_USER)); $messages = $comment_model->validate($data); if ($messages) { throw new waAPIException('invalid_param', 'Validate messages: ' . implode("\n", $messages), 404); } $id = $comment_model->add($data, $parent_id); $_GET['id'] = $id; $method = new blogPostCommentsGetInfoMethod(); $this->response = $method->getResponse(true); }
/** * @param int[] $params Deleted contact_id * @see waEventHandler::execute() * @return void */ public function execute(&$params) { $contact_model = new waContactModel(); $contacts = $contact_model->getByField('id', $params, true); $post_model = new blogPostModel(); $comment_model = new blogCommentModel(); foreach ($contacts as $contact) { $data = array('contact_id' => 0, 'contact_name' => $contact['name']); $post_model->updateByField('contact_id', $contact['id'], $data); $data = array('contact_id' => 0, 'name' => $contact['name'], 'auth_provider' => null); $comment_model->updateByField('contact_id', $contact['id'], $data); } /** * @event contacts_delete * @param array[] int $contact_ids array of contact's ID * @return void */ wa()->event(array('blog', 'contacts_delete'), $params); }
public function execute() { $comment_id = (int) waRequest::post('spam'); $comment_model = new blogCommentModel(); $comment = $comment_model->getById($comment_id); $this->response['status'] = null; if ($comment) { $comment_model->updateById($comment_id, array('akismet_spam' => 1, 'status' => blogCommentModel::STATUS_DELETED)); $this->response['status'] = blogCommentModel::STATUS_DELETED; $blog_plugin = wa()->getPlugin('akismet'); $akismet = new Akismet(wa()->getRouting()->getUrl('blog', array(), true), $blog_plugin->getSettingValue('api_key')); $akismet->setCommentAuthor($comment['name']); $akismet->setCommentAuthorEmail($comment['email']); $akismet->setCommentContent($comment['text']); if (!waSystemConfig::isDebug() && $blog_plugin->getSettingValue('send_spam')) { $akismet->submitSpam(); } } }
public function execute() { $post_id = max(0, waRequest::get('id', 0, waRequest::TYPE_INT)); if (!$post_id) { throw new waException(_w('Post not found'), 404); } $post_model = new blogPostModel(); $search_options = array('id' => $post_id); $extend_options = array('comments' => array(20), 'user' => array('photo_url_50'), 'status' => 'view'); $post = $post_model->search($search_options, $extend_options)->fetchSearchItem(); if (!$post) { throw new waException(_w('Post not found'), 404); } $post['rights'] = $this->getRights("blog.{$post['blog_id']}"); $posts = array(&$post); blogHelper::extendRights($posts, array(), $this->getUser()->getId()); blogPhotosBridge::loadAlbums($posts); if (isset($post['comments']) && $post['comments']) { $post['comments'] = blogCommentModel::extendRights($post['comments'], array($post_id => $post)); } $blog_model = new blogBlogModel(); $blog = $blog_model->getById($post['blog_id']); if ($blog['status'] != blogBlogModel::STATUS_PUBLIC || $post['status'] != blogPostModel::STATUS_PUBLISHED) { blogHelper::checkRights($post['blog_id'], true, blogRightConfig::RIGHT_READ); } $items = $blog_model->prepareView(array($blog)); $blog = array_shift($items); $this->setLayout(new blogDefaultLayout()); $this->getResponse()->setTitle($post['title']); /** * Backend post view page * UI hook allow extends post view page * @event backend_post * @param array[string]mixed $post Current page post item data * @param array[string]int $post['id'] Post ID * @param array[string]int $post['blog_id'] Post blog ID * @return array[string][string]string $backend_post['%plugin_id%']['footer'] Plugin %plugin_id% footer html */ $this->view->assign('backend_post', wa()->event('backend_post', $post, array('footer'))); $user = $this->getUser(); $this->view->assign('current_contact', array('id' => $user->getId(), 'name' => $user->getName(), 'photo20' => $user->getPhoto(20))); $this->view->assign('blog_id', $blog['id']); $this->view->assign('blog', $blog); $this->view->assign('contact_rights', $this->getUser()->getRights('contacts', 'backend')); if ($this->getConfig()->getOption('can_use_smarty')) { try { $post['text'] = $this->view->fetch("string:{$post['text']}", $this->cache_id); } catch (SmartyException $ex) { $post['text'] = blogPost::handleTemplateException($ex, $post); } } $this->view->assign('post', $post); }
public function execute() { $post_id = $this->get('post_id', true); $post_model = new blogPostModel(); $post = $post_model->getById($post_id); if (!$post) { throw new waAPIException('invalid_param', 'Post not found', 404); } $parent_id = waRequest::get('parent_comment_id'); $comment_model = new blogCommentModel(); $comments = $comment_model->getSubtree($post_id, $parent_id); $stack = array(); $result = array(); foreach ($comments as $r) { $r['comments'] = array(); // Number of stack items $l = count($stack); // Check if we're dealing with different levels while ($l > 0 && $stack[$l - 1]['depth'] >= $r['depth']) { array_pop($stack); $l--; } // Stack is empty (we are inspecting the root) if ($l == 0) { // Assigning the root node $i = count($result); $result[$i] = $r; $stack[] =& $result[$i]; } else { // Add node to parent $i = count($stack[$l - 1]['comments']); $stack[$l - 1]['comments'][$i] = $r; $stack[] =& $stack[$l - 1]['comments'][$i]; } } $this->response = $result; $this->response['_element'] = 'comment'; }
public function execute() { $id = $this->post('id', true); if (!is_array($id)) { if (strpos($id, ',') !== false) { $id = array_map('intval', explode(',', $id)); } else { $id = array($id); } } $user_id = wa()->getUser()->getId(); $comment_model = new blogCommentModel(); $post_model = new blogPostModel(); $comments = $comment_model->getByField('id', $id, 'id'); $post_ids = array(); foreach ($comments as $comment) { $post_ids[] = $comment['post_id']; } $post_ids = array_unique($post_ids); $posts = $post_model->getByField('id', $post_ids, 'id'); $available = array(); foreach ($comments as $comment) { try { $rights = blogHelper::checkRights($comment['blog_id'], $user_id, blogRightConfig::RIGHT_READ_WRITE); } catch (Exception $e) { continue; } if ($rights == blogRightConfig::RIGHT_READ_WRITE && $user_id != $posts[$comment['post_id']]['contact_id']) { continue; } if ($comment['status'] == blogCommentModel::STATUS_DELETED) { continue; } $available[] = $comment['id']; } $comment_model->updateById($available, array('status' => blogCommentModel::STATUS_DELETED)); $this->response = true; }
protected function getComments($search_options) { if (empty($search_options['post_id'])) { $search_options['post_id'] = null; } if (!isset($search_options['blog_id'])) { $search_options['blog_id'] = array_keys(blogHelper::getAvailable()); } else { if (is_numeric($search_options['blog_id'])) { $search_options['blog_id'] = array((int) $search_options['blog_id']); } else { if (!is_array($search_options['blog_id'])) { $search_options['blog_id'] = array(); } } } if (is_numeric($search_options['filter'])) { $search_options['filter'] = (int) $search_options['filter']; if (in_array($search_options['filter'], $search_options['blog_id'])) { $search_options['blog_id'] = array($search_options['filter']); } else { $search_options['blog_id'] = array(); } } else { if ($search_options['filter'] == 'myposts') { if (empty($search_options['blog_id'])) { $search_options['post_id'] = array(); } else { $post_model = new blogPostModel(); $search_options['post_id'] = array_keys($post_model->select('id')->where('contact_id=? AND blig_id IN (?)', array($this->getUser()->getId(), $search_options['blog_id']))->fetchAll('id')); } } } $search_options['approved'] = true; $comment_model = new blogCommentModel(); return $comment_model->getList($search_options, array("photo_url_20"), array('datetime' => blogActivity::getUserActivity())); }
private function displayComment() { $this->getResponse()->addHeader('Content-type', 'application/json'); if ($this->comment_id && ($comment = $this->comment_model->getById($this->comment_id))) { $count = $this->comment_model->getCount($comment['blog_id'], $comment['post_id']); $comments = $this->comment_model->prepareView(array($comment), array('photo_url_20'), array('user' => true, 'escape' => true)); $theme = waRequest::param('theme', 'default'); $theme_path = wa()->getDataPath('themes', true) . '/' . $theme; if (!file_exists($theme_path) || !file_exists($theme_path . '/theme.xml')) { $theme_path = wa()->getAppPath() . '/themes/' . $theme; } $template = 'file:comment.html'; $view = wa()->getView(array('template_dir' => $theme_path)); $view->assign('comment', array_shift($comments)); $this->response['template'] = $view->fetch($template); $this->response['count_str'] = $count . " " . _w('comment', 'comments', $count); $this->response['parent'] = $this->parent_id; } else { throw new waException(_w('Comment not found'), 404); } }
public function getComments($search_options, $fields, $prepare_options) { $comment_model = new blogCommentModel(); $post_ids = null; $blog_ids = $search_options['blog_id']; if (is_numeric($search_options['filter'])) { $k = array_search((int) $search_options['filter'], $blog_ids); if ($k !== false) { $blog_ids = $blog_ids[$k]; } else { $blog_ids = array(); } $search_options['blog_id'] = $blog_ids; } else { if ($search_options['filter'] == 'myposts') { $post_model = new blogPostModel(); $post_ids = array_keys($post_model->select('id')->where('contact_id=' . $this->getUser()->getId())->fetchAll('id')); $search_options['post_id'] = $post_ids; } } $counts = (array) $comment_model->getCount($blog_ids, $post_ids, null, null, null, null); return array('comments' => $comment_model->getList($search_options, $fields, $prepare_options), 'comments_all_count' => array_sum($counts)); }
public function onCount() { $full = !func_get_args(); $app = $this->getApplication(); $user = waSystem::getInstance()->getUser(); $user_id = $user->getId(); $type = explode(':', $user->getSettings($app, 'type_items_count')); $type = array_filter(array_map('trim', $type), 'strlen'); if (!$type) { $type = array('posts', 'comments_to_my_post', 'overdue'); } $activity_datetime = blogActivity::getUserActivity($user_id, false); $blogs = array_keys(blogHelper::getAvailable(false)); $counter = array(); $post_model = new blogPostModel(); if (in_array('posts', $type) && $full && $blogs) { $post_new_count = $post_model->getAddedPostCount($activity_datetime, $blogs); $post_new_count = array_sum($post_new_count); $counter['posts'] = $post_new_count; } else { $counter['posts'] = false; } if (in_array('comments', $type) && $full && $blogs) { $comment_model = new blogCommentModel(); $counter['comments'] = $comment_model->getCount($blogs, null, $activity_datetime, 0); } else { $counter['comments'] = false; } if (in_array('comments_to_my_post', $type) && $full && $blogs) { $comment_model = new blogCommentModel(); $counter['comments_to_my_post'] = $comment_model->getCount($blogs, null, $activity_datetime, 0, $user_id); } else { $counter['comments_to_my_post'] = false; } if (in_array('overdue', $type) && $blogs) { if (!isset($post_model)) { $post_model = new blogPostModel(); } $where = "status = '" . blogPostModel::STATUS_DEADLINE . "'"; $where .= " AND blog_id IN (" . implode(', ', $blogs) . ")"; $where .= " AND contact_id = {$user_id}"; $where .= " AND datetime <= '" . waDateTime::date("Y-m-d") . "'"; $count_overdue = $post_model->select("count(id)")->where($where)->fetchField(); $counter['overdue'] = $count_overdue ? $count_overdue : 0; } else { $counter['overdue'] = false; } $count = array_sum($counter); $url = $this->getBackendUrl(true) . $this->application . '/'; if ($count) { switch ($count) { case $counter['comments']: case $counter['comments_to_my_post']: $url .= '?module=comments'; break; case $counter['overdue']: $url .= '?action=calendar'; break; } } //debug //$counter['type'] = $type; //$counter['activity_datetime'] = $activity_datetime; //$counter['current_datetime'] = date("Y-m-d H:i:s",time()); //waLog::log('$counter = '.var_export($counter,true),"blog-counter-{$user_id}.log"); return array('count' => $count == 0 ? null : $count, 'url' => $url); }
/** * Delete records from table and related data * * @param $field * @param $value * @return bool */ public function deleteByField($field, $value = null) { if (is_array($field)) { $items = $this->getByField($field, $this->id); } else { $items = $this->getByField($field, $value, $this->id); } $res = false; if ($post_ids = array_keys($items)) { /** * @event post_predelete * @param array[] int $post_ids array of post's ID * @return void */ wa()->event('post_predelete', $post_ids); $res = parent::deleteByField('id', $post_ids); if ($res) { $comment_model = new blogCommentModel(); $comment_model->deleteByField('post_id', $post_ids); $params_model = new blogPostParamsModel(); $params_model->deleteByField('post_id', $post_ids); $blog_model = new blogBlogModel(); $blogs = array(); foreach ($items as $item) { $blogs[] = $item['blog_id']; } $blogs = array_unique($blogs); $blog_model->recalculate($blogs); /** * @event post_delete * @param array[] int $post_ids array of post's ID * @return void */ wa()->event('post_delete', $post_ids); } } return $res; }
private function importComments($post_id, $post) { static $commentors = array(); static $comment_model; if (version_compare($this->version, '2.7', '>=')) { try { if ($comments = $this->xmlrpc("wp.getComments", $post_id, $this->option('login'), $this->option('password'), array('post_id' => $post_id))) { if (!isset($comment_model)) { $comment_model = new blogCommentModel(); } $comment_map = array(); // new comment to the top $comments = array_reverse($comments); $emails = array(); foreach ($comments as $key => $comment) { $email = trim(strtolower($comment['author_email'])); if ($email && !isset($commentors[$email])) { $commentors[$email] = 0; $emails[] = $email; } else { if (!isset($commentors[$email])) { $commentors[$email] = 0; } } } $commentors = array_merge($commentors, $this->getContactByEmail($emails)); $comment_model->ping(); foreach ($comments as $key => $comment) { $email = trim(strtolower($comment['author_email'])); $this->log('comment ' . $key, self::LOG_DEBUG); $datetime = $comment['date_created_gmt']; $datetime = date("Y-m-d H:i:s", $datetime->timestamp); $parent = 0; if ($comment['parent'] && isset($comment_map[$comment['parent']])) { $parent = $comment_map[$comment['parent']]; } $contact_id = isset($commentors[$email]) ? $commentors[$email] : 0; $comment_data = array('post_id' => $post['id'], 'blog_id' => $post['blog_id'], 'contact_id' => $contact_id, 'text' => html_entity_decode(strip_tags($comment['content']), ENT_NOQUOTES, 'utf-8'), 'datetime' => $datetime, 'name' => html_entity_decode(trim($comment['author']), ENT_NOQUOTES, 'utf-8'), 'email' => $comment['author_email'], 'site' => $comment['author_url'], 'ip' => ip2long($comment['author_ip']), 'auth_provider' => $contact_id ? blogCommentModel::AUTH_USER : blogCommentModel::AUTH_GUEST, 'status' => $comment['status'] == 'approve' ? blogCommentModel::STATUS_PUBLISHED : blogCommentModel::STATUS_DELETED); $comment_id = $comment_model->add($comment_data, $parent); $comment_map[$comment['comment_id']] = $comment_id; } unset($comment_map); } } catch (waDbException $ex) { $this->log(__METHOD__ . ":\t" . $ex->getMessage() . "\nraw comment:\t" . var_export($comment, true) . "\nformatted comment:\t" . var_export($comment_data, true), self::LOG_WARNING); } catch (waException $ex) { if ($ex->getCode() == 401) { $this->log($ex->getMessage(), self::LOG_WARNING); } else { throw $ex; } } } }
/** * * Get comments for posts * @param array $posts */ public static function extendPostComments(&$posts) { $comment_model = new blogCommentModel(); $post_ids = array_keys($posts); $comment_count = $comment_model->getCount(null, $post_ids); $comment_new_count = $comment_model->getCount(null, $post_ids, blogActivity::getUserActivity()); foreach ($posts as $id => &$post) { $post['comment_count'] = isset($comment_count[$id]) ? $comment_count[$id] : 0; $post['comment_new_count'] = isset($comment_new_count[$id]) ? $comment_new_count[$id] : 0; unset($post); } }
public function comments($blog_id = null, $limit = 10) { $contact_photo_size = 20; $limit = max(1, intval($limit)); $blogs = blogHelper::getAvailable(true, $blog_id); $comment_model = new blogCommentModel(); $prepare_options = array('datetime' => blogActivity::getUserActivity()); $fields = array("photo_url_{$contact_photo_size}"); $blog_ids = array_keys($blogs); $comments = $comment_model->getList(0, $limit, $blog_ids, $fields); $post_ids = array(); foreach ($comments as $comment) { $post_ids[$comment['post_id']] = true; } //get related posts info $post_model = new blogPostModel(); $search_options = array('id' => array_keys($post_ids)); $extend_options = array('user' => false, 'link' => true, 'rights' => true, 'plugin' => false, 'comments' => false); $extend_data = array('blog' => $blogs); $posts = $post_model->search($search_options, $extend_options, $extend_data)->fetchSearchAll(false); $comments = blogCommentModel::extendRights($comments, $posts); self::escape($comments, array('*' => array('posts' => array('text' => true), 'plugins' => true))); return $comments; }
public function explainLogs($logs) { $logs = parent::explainLogs($logs); $app_url = wa()->getConfig()->getBackendUrl(true) . $this->application . '/'; $post_ids = array(); $comment_ids = array(); foreach ($logs as $l_id => $l) { if (in_array($l['action'], array('page_add', 'page_edit', 'page_move')) && isset($l['params_html'])) { $logs[$l_id]['params_html'] = str_replace('#/pages/', '?module=pages#/', $l['params_html']); } else { if ($l['action'] == 'post_edit' && version_compare(wa('webasyst')->getVersion(), '1.4.0.40888') >= 0) { // Removal of log records in activity is only supported since 1.4.0.40888, // but we don't want to raise requirements yet, so have to check for version here. // !!! TODO: should probably remove the check later and update requirements.php $logs[$l_id] = null; } else { if (in_array($l['action'], array('post_edit', 'post_publish', 'post_unpublish')) && $l['params']) { $post_ids[$l['params']] = 1; } else { if (in_array($l['action'], array('comment_add', 'comment_delete', 'comment_restore')) && $l['params']) { $comment_ids[$l['params']] = 1; } } } } } if ($comment_ids) { $comment_model = new blogCommentModel(); $comments = $comment_model->getById(array_keys($comment_ids)); foreach ($comments as $c) { $post_ids[$c['post_id']] = 1; } } if ($post_ids) { $post_model = new blogPostModel(); $posts = $post_model->getById(array_keys($post_ids)); } foreach ($logs as $l_id => $l) { if (!$l) { continue; } // Link to blog post in question $p = $c = null; if (in_array($l['action'], array('post_edit', 'post_publish', 'post_unpublish')) && isset($posts[$l['params']])) { $p = $posts[$l['params']]; } else { if (in_array($l['action'], array('comment_add', 'comment_delete', 'comment_restore')) && isset($comments[$l['params']])) { $c = $comments[$l['params']]; if (isset($posts[$c['post_id']])) { $p = $posts[$c['post_id']]; } } } if (!empty($p)) { if ($p['status'] == blogPostModel::STATUS_PUBLISHED) { $url = $app_url . '?module=post&id=' . $p['id']; } else { $url = $app_url . '?module=post&action=edit&id=' . $p['id']; } $logs[$l_id]['params_html'] = '<div class="activity-target"><a href="' . $url . '">' . htmlspecialchars($p['title']) . '</a></div>'; } if (!empty($c)) { $logs[$l_id]['params_html'] .= '<div class="activity-body"><p' . ($c['status'] == 'deleted' ? ' class="strike gray"' : '') . '>' . nl2br(htmlspecialchars(mb_substr($c['text'], 0, 512))) . '</p></div>'; } } return $logs; }
public function execute() { $this->post_id = max(0, $this->getRequest()->get('id', 0, waRequest::TYPE_INT)); $this->parent_id = max(0, $this->getRequest()->post('parent', 0, waRequest::TYPE_INT)); $comment_model = new blogCommentModel(); $post_model = new blogPostModel(); /** * * Parent comment data * @var array */ $parent = null; $stream = false; //find comment parent if ($this->parent_id && ($parent = $comment_model->getById($this->parent_id))) { if ($this->post_id && $this->post_id != $parent['post_id']) { throw new waRightsException(_w('Access denied')); } if (!$this->post_id) { $stream = true; } $this->post_id = $parent['post_id']; } else { $this->parent_id = 0; } //find post if (!$this->post_id || !($post = $post_model->getBlogPost($this->post_id))) { throw new waException(_w('Post not found'), 404); } $contact_id = $this->getUser()->getId(); #check rights $rights = blogHelper::checkRights($post['blog_id'], $contact_id, blogRightConfig::RIGHT_READ); //check comment mode if (!$post['comments_allowed']) { throw new waException(_w("Isn't allowed comment to this post")); } $comment = array('blog_id' => $post['blog_id'], 'post_id' => $this->post_id, 'contact_id' => $contact_id, 'text' => $this->getRequest()->post('text'), 'auth_provider' => blogCommentModel::AUTH_USER); $this->errors += $comment_model->validate($comment); if (count($this->errors) > 0) { return; } $id = $comment_model->add($comment, $this->parent_id); $this->logAction('comment_add', $id); $comment = $comment_model->getById($id); //$comment['new'] = false; $comment['parent'] = $this->parent_id; if ($stream) { $comment['parent_text'] = $parent ? $parent['text'] : null; $comment['parent_status'] = $parent ? $parent['status'] : null; } else { $count = $comment_model->getCount($post['blog_id'], $this->post_id); $this->response['count_str'] = $count . " " . _w('comment', 'comments', $count); } $comment['rights'] = $rights; $comment['post'] =& $post; $post['comments'] = $comment_model->prepareView(array($comment), array('photo_url_20')); blogHelper::extendRights($post['comments'], array(), $contact_id); if ($stream) { $posts = array($this->post_id => &$post); $blog_model = new blogBlogModel(); $extend_data = array('blog' => $blog_model->search(array('id' => $this->post_id))->fetchSearchAll()); $post_model->prepareView($posts, array('link' => true), $extend_data); } else { unset($comment['post']); } $view = wa()->getView(); $view->assign('post', $post); $view->assign('contact_rights', $this->getUser()->getRights('contacts', 'backend')); $template = $view->fetch('templates/actions/post/include.comments.html'); $this->getResponse()->addHeader('Content-type', 'application/json'); $this->response['template'] = $template; }
public function execute() { $this->user = $this->getUser(); $blog_id = waRequest::get('blog', null, 'int'); $post_id = waRequest::get('id', null, 'int'); $request = waRequest::get(); $module = waRequest::get('module'); $action = waRequest::get('action'); if (!$action) { $action = waRequest::get('module'); } $view_all_posts = waRequest::get('all', null) !== null || empty($request); $blog_model = new blogBlogModel(); $blogs = $blog_model->getAvailable($this->user, array(), null, array('new' => true, 'expire' => 1, 'link' => false)); $blog_ids = array_keys($blogs); $comment_model = new blogCommentModel(); $comment_count = $comment_model->getCount($blog_ids); $activity_datetime = blogActivity::getUserActivity(); $comment_new_count = $comment_model->getCount($blog_ids, null, $activity_datetime, 1); $post_count = 0; $new_post_count = 0; $writable_blogs = false; foreach ($blogs as $blog) { $post_count += $blog['qty']; if ($blog['rights'] >= blogRightConfig::RIGHT_READ_WRITE) { $writable_blogs = true; } if (isset($blog['new_post']) && $blog['new_post'] > 0) { $new_post_count += $blog['new_post']; } } if ($writable_blogs) { $post_model = new blogPostModel(); $search_options = array('status' => array(blogPostModel::STATUS_DRAFT, blogPostModel::STATUS_DEADLINE, blogPostModel::STATUS_SCHEDULED)); if (!$this->user->isAdmin($this->getApp())) { $search_options['contact_id'] = $this->user->getId(); } $search_options['sort'] = 'overdue'; $drafts = $post_model->search($search_options, array('status' => true, 'link' => false, 'plugin' => false, 'comments' => false), array('blog' => $blogs))->fetchSearchAll(false); $where = "status = '" . blogPostModel::STATUS_DEADLINE . "' AND datetime <= '" . waDateTime::date("Y-m-d") . "'"; if (!$this->getUser()->isAdmin($this->getApp())) { $where .= " AND contact_id = {$this->getUser()->getId()}"; $where .= " AND blog_id IN (" . implode(', ', array_keys($blogs)) . ")"; } $count_overdue = $post_model->select("count(id)")->where($where)->fetchField(); $count_overdue = $count_overdue ? $count_overdue : 0; } else { $drafts = false; $count_overdue = false; } /** * Extend backend sidebar * Add extra sidebar items (menu items, additional sections, system output) * @event backend_sidebar * @example #event handler example * public function sidebarAction() * { * $output = array(); * * #add external link into sidebar menu * $output['menu']='<li> * <a href="http://www.webasyst.com"> * http://www.webasyst.com * </a> * </li>'; * * #add section into sidebar menu * $output['section']=''; * * #add system link into sidebar menu * $output['system']=''; * * return $output; * } * @return array[string][string]string $return[%plugin_id%]['menu'] Single menu items * @return array[string][string]string $return[%plugin_id%]['section'] Sections menu items * @return array[string][string]string $return[%plugin_id%]['system'] Extra menu items */ $this->view->assign('backend_sidebar', wa()->event('backend_sidebar')); $this->view->assign('blog_id', $blog_id); $this->view->assign('blogs', $blogs); $this->view->assign('view_all_posts', $view_all_posts); $this->view->assign('action', $action); $this->view->assign('module', $module); $this->view->assign('post_id', $post_id); $this->view->assign('new_post', waRequest::get('action') == 'edit' && waRequest::get('id') == ''); $this->view->assign('drafts', $drafts); $this->view->assign('comment_count', $comment_count); $this->view->assign('comment_new_count', $comment_new_count); $this->view->assign('post_count', $post_count); $this->view->assign('new_post_count', $new_post_count); $this->view->assign('count_draft_overdue', $count_overdue); $this->view->assign('writable_blogs', $writable_blogs); }