public function execute() { if (!$this->appSettings('show_comments', true)) { throw new waException(_ws("Page not found"), 404); } $this->comment_model = new blogCommentModel(); $this->blog_id = waRequest::param('blog_id', false, waRequest::TYPE_ARRAY_INT); $this->verify(); if ($this->getRequest()->method() == 'post') { $res = $this->addComment(); } else { $this->comment_id = waRequest::param('blog_id', false, waRequest::TYPE_ARRAY_INT); $res = true; } if (waRequest::get('json')) { if ($this->comment_id) { $this->displayComment(); } } else { if (!$res) { var_export($this->errors); exit; //handle error on non ajax } $url = blogPost::getUrl($this->post) . '#comment' . intval($this->parent_id ? $this->parent_id : $this->comment_id); $this->redirect($url); } }
public function commentValidate($comment) { $result = null; if (!$comment['contact_id'] && ($api_key = $this->getSettingValue('api_key')) && class_exists('Akismet')) { $url = wa()->getRouteUrl('blog', array(), true); $post_url = null; if (isset($comment['post_data'])) { $post_url = blogPost::getUrl($comment['post_data']); if (is_array($post_url)) { $post_url = array_shift($post_url); } } $akismet = new Akismet($url, $api_key); $akismet->setCommentAuthor($comment['name']); $akismet->setCommentAuthorEmail($comment['email']); //$akismet->setCommentAuthorURL($comment['site']); $akismet->setCommentContent($comment['text']); if ($post_url) { $akismet->setPermalink($post_url); } if ($akismet->isCommentSpam()) { $result = array('text' => _wp('According to Akismet.com, your comment very much looks like spam, thus will not be published. Please rewrite your comment. Sorry for the inconvenience.')); } } return $result; }
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() { $rss_author_tag = null; if ($blog_id = $this->getRequest()->param('blog_id')) { $rss_posts_number = max(1, $this->appSettings('rss_posts_number', 10)); $rss_author_tag = $this->appSettings('rss_author_tag'); $options = array(); $data = array(); switch ($rss_author_tag) { case 'blog': $blog_model = new blogBlogModel(); $data['blog'] = $blog_model->getByField(array('id' => $blog_id), 'id'); break; default: $data['blog'] = blogHelper::getAvailable(); break; } $options['params'] = true; $options['user'] = '******'; $post_model = new blogPostModel(); $posts = $post_model->search(array('blog_id' => $blog_id), $options, $data)->fetchSearchPage(1, $rss_posts_number); blogPhotosBridge::loadAlbums($posts); } else { $posts = array(); } $link = wa()->getRouteUrl('blog/frontend', array(), true); $rss_link = wa()->getRouteUrl('blog/frontend/rss', array(), true); $title = waRequest::param('rss_title') ? waRequest::param('rss_title') : wa()->accountName(); $this->view->assign('info', array('title' => $title, 'link' => $link, 'description' => '', 'language' => 'ru', 'pubDate' => date(DATE_RSS), 'lastBuildDate' => date(DATE_RSS), 'self' => $rss_link)); $this->view->assign('blog_name', $this->getResponse()->getTitle()); $this->view->assign('rss_author_tag', $rss_author_tag); if ($this->getConfig()->getOption('can_use_smarty')) { foreach ($posts as &$post) { try { $post['text'] = $this->view->fetch("string:{$post['text']}", $this->cache_id); } catch (SmartyException $ex) { $post['text'] = blogPost::handleTemplateException($ex, $post); } } unset($post); } foreach ($posts as &$post) { if (is_array($post['user']['email'])) { $post['user']['email'] = reset($post['user']['email']); } } unset($post); $this->view->assign('posts', $posts); $this->getResponse()->addHeader('Content-Type', 'application/rss+xml; charset=utf-8'); }
public function run($params = NULL) { $app_settings_model = new waAppSettingsModel(); $app_settings_model->set(array('blog', 'emailsubscription'), 'last_emailsubscription_cron_time', time()); $model = new blogEmailsubscriptionLogModel(); $row = $model->getByField('status', 0); if ($row) { $post_id = $row['post_id']; $post_model = new blogPostModel(); $post = $post_model->getById($post_id); $blog_model = new blogBlogModel(); $blog = $blog_model->getById($post['blog_id']); $subject = $blog['name'] . ': ' . $post['title']; $post_title = htmlspecialchars($post['title']); if ($blog['status'] == blogBlogModel::STATUS_PUBLIC) { $post_url = blogPost::getUrl($post); } else { $app_settings_model = new waAppSettingsModel(); $post_url = $app_settings_model->get(array('blog', 'emailsubscription'), 'backend_url', wa()->getRootUrl(true) . wa()->getConfig()->getBackendUrl()); $post_url .= "/blog/?module=post&id=" . $post_id; } $blog_name = htmlspecialchars($blog['name']); $body = '<html><body>' . sprintf(_wp("New post in the blog “%s”"), $blog_name) . ': <strong><a href="' . $post_url . '">' . $post_title . '</a></strong></body></html>'; $message = new waMailMessage(); $message->setEncoder(Swift_Encoding::getBase64Encoding()); $message->setSubject($subject); $message->setBody($body); $rows = $model->getByField(array('status' => 0, 'post_id' => $post_id), true); $message_count = 0; foreach ($rows as $row) { try { $message->setTo($row['email'], $row['name']); $status = $message->send() ? 1 : -1; $model->setStatus($row['id'], $status); if ($status) { $message_count++; } } catch (Exception $e) { $model->setStatus($row['id'], -1, $e->getMessage()); } } /** * Notify plugins about sending emailsubscripition * @event followup_send * @return void */ wa()->event('emailsubscription_send', $message_count); } }
public function execute() { if ($blog_id = (int) waRequest::post('id')) { blogHelper::checkRights($blog_id, true, blogRightConfig::RIGHT_FULL); $remove = waRequest::post('remove'); if ($remove == 'move') { $move_blog_id = waRequest::post('blog_id'); blogHelper::checkRights($move_blog_id, true, blogRightConfig::RIGHT_FULL); if ($move_blog_id != $blog_id) { blogPost::move($blog_id, $move_blog_id); } else { $this->redirect('?module=blog&action=settings&id=' . $blog_id); } } $blog_model = new blogBlogModel(); $blog_model->deleteById($blog_id); $this->log('blog_delete'); $this->redirect(wa()->getAppUrl()); } else { $this->redirect(wa()->getAppUrl()); } }
public function frontendExecute() { $post_slug = waRequest::param('post_url', false, waRequest::TYPE_STRING_TRIM); $storage = wa()->getStorage(); $post_model = new blogPostModel(); $show_comments = $this->appSettings('show_comments', true); $request_captcha = $show_comments && $this->appSettings('request_captcha', true); $require_authorization = $show_comments && $this->appSettings('require_authorization', false); $available = blogHelper::getAvailable(); // it's preview $hash = waRequest::get('preview'); $post = $post_model->search(array('url' => $post_slug, 'status' => $hash ? false : blogPostModel::STATUS_PUBLISHED), array('comments' => $show_comments ? array(50, 20) : false, 'params' => true, 'escape' => true), array('blog' => $available))->fetchSearchItem(); if (!$post) { throw new waException(_w('Post not found'), 404); } if ($post['status'] != blogPostModel::STATUS_PUBLISHED) { $hash = base64_decode($hash); list($hash, $user_id) = array(substr($hash, 0, 32), substr($hash, 32)); $options = array('contact_id' => $post['contact_id'], 'blog_id' => $post['blog_id'], 'post_id' => $post['id'], 'user_id' => $user_id); $preview_cached_options = $storage->read('preview'); $preview_cached_post_options = isset($preview_cached_options['post_id']) ? $preview_cached_options['post_id'] : null; if ($preview_cached_post_options && $preview_cached_post_options != $options) { $preview_cached_post_options = null; } if (!$preview_cached_post_options) { if ($hash == blogPostModel::getPreviewHash($options, false, false)) { $preview_cached_options['post_id'] = $preview_cached_post_options = $options; $storage->write('preview', $preview_cached_options); } } if (!$preview_cached_post_options) { throw new waException(_w('Post not found'), 404); } if (!$this->checkAuthorRightsToBlog($user_id, $post)) { throw new waException(_w('Post not found'), 404); } } $title = $this->getResponse()->getTitle(); if ($this->getRequest()->param('title_type', 'blog_post') == 'blog_post') { if ($title) { $this->getResponse()->setTitle($title . " » " . $post['title']); } elseif (isset($available[$post['blog_id']]) && ($title = $available[$post['blog_id']]['title'])) { $this->getResponse()->setTitle($title . " » " . $post['title']); } else { $this->getResponse()->setTitle($post['title']); } } else { $this->getResponse()->setTitle($post['title']); } $blog_id = (array) $this->getRequest()->param('blog_id'); if (!in_array($post['blog_id'], $blog_id)) { if ($this->getRequest()->param('blog_url_type') == 0) { if (isset($available[$post['blog_id']])) { $this->redirect($post['link'], 301); } } throw new waException(_w('Post not found'), 404); } $this->getRequest()->setParam('blog_id', $post['blog_id']); if (isset($post['comments']) && !empty($post['comments'])) { $depth = 1000; foreach ($post['comments'] as $key => $comment) { if ($comment['status'] == blogCommentModel::STATUS_DELETED) { if ($comment['depth'] < $depth) { $depth = $comment['depth']; } unset($post['comments'][$key]); continue; } if ($comment['depth'] > $depth) { unset($post['comments'][$key]); } else { $depth = 1000; } } } $errors = array(); $form = array(); if ($storage->read('errors') !== null) { $errors = $storage->read('errors'); $form = $storage->read('form'); $storage->remove('errors'); $storage->remove('form'); } $post['comment_link'] = blogPost::getUrl($post, 'comment'); $post['link'] = blogPost::getUrl($post); /** * Frontend post view page * UI hook allow extends frontend post view page * @event frontend_post * @param array[string]mixed $post * @param array[string]int $post['id'] * @param array[string]int $post['blog_id'] * @return array[string][string]string $return[%plugin_id%] * @return array[string][string]string $return[%plugin_id%]['footer'] */ $this->view->assign('frontend_post', wa()->event('frontend_post', $post)); $this->view->assign('errors', $errors); $this->view->assign('form', $form); $this->view->assign('show_comments', $show_comments); $this->view->assign('request_captcha', $request_captcha); $this->view->assign('require_authorization', $require_authorization); $this->view->assign('theme', waRequest::param('theme', 'default')); $app_url = wa()->getAppStaticUrl(); $root_url = wa()->getRootUrl(); $storage = wa()->getStorage(); $current_auth = $storage->read('auth_user_data'); $current_auth_source = $current_auth ? $current_auth['source'] : null; $this->view->assign('current_auth_source', $current_auth_source); $this->view->assign('current_auth', $current_auth, true); $adapters = wa()->getAuthAdapters(); $this->view->assign('auth_adapters', $adapters); $this->view->getHelper()->globals($this->getRequest()->param()); 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 static function getPureUrls($post) { if (isset($post['url'])) { unset($post['url']); } $urls = blogPost::getUrl($post); $replace = array_merge(explode(' ', date('Y n j')), (array) ''); $urls = str_replace(array('%year%', '%month%', '%day%', '%post_url%/'), $replace, $urls); return $urls; }
/** * Extend items by adding contact info into $rows[i]['user'] * Uses: * - $rows[i]['contact_id'] * - $rows[i]['name'] or $rows[i]['contact_name'] when contact is not found or its name is empty * - $rows[i]['auth_provider'] for default userpic URL * * @param array $rows * @param array $fields * @param bool $get_link pass true to get $rows[i]['user']['posts_link'] */ public static function extendUser(&$rows, $fields = array(), $get_link = false) { $default_fields = array('id', 'name', 'firstname', 'middlename', 'lastname'); $fields = array_unique(array_merge($fields, $default_fields)); // All contact ids $ids = array(); foreach ($rows as $row) { if ($row['contact_id']) { $ids[] = intval($row['contact_id']); } } $ids = array_unique($ids); // Fetch contacts using collection $collection = new waContactsCollection($ids); $contacts = $collection->getContacts(implode(',', $fields), 0, count($ids)); // Prepare data row to use as a placeholder when contact is not found $contact = new waContact(0); $contacts[0] = array('name' => ''); $photo_fields = array(); foreach ($fields as $field) { if (preg_match('@^photo_url_(\\d+)$@', $field, $matches)) { $photo_fields[] = $field; $contacts[0][$field] = $contact->getPhoto($matches[1], $matches[1]); } else { $contacts[0][$field] = $contact->get($field); } } // Format contact names foreach ($contacts as &$c) { $c['name'] = waContactNameField::formatName($c); } unset($c); // Add data as 'user' key to each row in $rows $app_static_url = wa()->getAppStaticUrl(); foreach ($rows as &$row) { $row['user'] = array(); $id = $row['contact_id'] = max(0, intval($row['contact_id'])); if (!isset($contacts[$id])) { $id = 0; } if (isset($contacts[$id])) { if (isset($row['url']) && $get_link && !isset($contacts[$id]['posts_link'])) { $contacts[$id]['posts_link'] = blogPost::getUrl($row, 'author'); } $row['user'] = $contacts[$id]; } if (!$id || !isset($contacts[$id])) { if (isset($row['name'])) { $row['user']['name'] = $row['name']; } elseif (isset($row['contact_name'])) { $row['user']['name'] = $row['contact_name']; } if (isset($row['auth_provider'])) { if ($row['auth_provider'] && $row['auth_provider'] != blogCommentModel::AUTH_GUEST) { $row['user']['photo_url'] = "{$app_static_url}img/{$row['auth_provider']}.png"; foreach ($photo_fields as $field) { $row['user'][$field] =& $row['user']['photo_url']; } } } } unset($row); } }
public function execute() { $blog_model = new blogBlogModel(); $blogs = $blog_model->getAvailable($this->getUser()); $stream = array('all_posts' => false); $title_suffix = ''; $search_options = array(); // native search if ($text = waRequest::get('text', '')) { $text = urldecode($text); $search_options['text'] = $text; $title_suffix = " / {$text}"; } // plugins' search if ($plugin = waRequest::get('search', false)) { $search_options["plugin"] = array(); if (is_array($plugin)) { foreach ($plugin as $plugin_id => $plugin_params) { $search_options["plugin"][$plugin_id] = $plugin_params; } } else { $search_options["plugin"][$plugin] = waRequest::get($plugin, true); } } if ($blog_id = max(0, waRequest::get('blog', null, waRequest::TYPE_INT))) { if (!isset($blogs[$blog_id])) { throw new waException(_w('Blog not found'), 404); } wa()->getStorage()->write('blog_last_id', $blog_id); $blog =& $blogs[$blog_id]; $stream['title'] = $blog['name']; $stream['link'] = $this->getUrl($blog); $stream['blog'] = $blog; $search_options['blog_id'] = $blog_id; } else { if (empty($search_options["plugin"])) { $stream['title'] = _w('All posts'); $stream['link'] = $this->getUrl(); $stream['all_posts'] = true; } else { $stream['title'] = ''; $stream['link'] = ''; } $stream['blog'] = null; $search_options['blog_id'] = array_keys($blogs); } $this->getResponse()->setTitle($stream['title'] . $title_suffix); $search = false; $page = max(1, waRequest::get('page', 1, waRequest::TYPE_INT)); $posts_per_page = max(1, intval($this->getConfig()->getOption('posts_per_page'))); $extend_options = array(); $extend_options['status'] = 'view'; $extend_options['author_link'] = false; $extend_options['rights'] = true; if (!$this->getRequest()->isMobile()) { $extend_options['text'] = 'cut'; } $post_model = new blogPostModel(); $posts = $post_model->search($search_options, $extend_options, array('blog' => $blogs))->fetchSearchPage($page, $posts_per_page); // Add photo albums to posts blogPhotosBridge::loadAlbums($posts); if ($page == 1) { $stream['title'] = $this->getResponse()->getTitle(); $this->chooseLayout(); $this->view->assign('search', $plugin ? urldecode(http_build_query(array('search' => $plugin))) : null); /** * Backend posts stream view page * UI hook allow extends backend posts view page * @event backend_stream * @param array[string]mixed $stream Array of stream properties * @param array[string]array $stream['blog'] Related blog data array or null * @param array[string]string $stream['title'] Stream title * @param array[string]string $stream['link'] Stream link * @return array[string][string]string $return['%plugin_id%']['menu'] Stream context menu html */ $this->view->assign('backend_stream', wa()->event('backend_stream', $stream, array('menu'))); } $posts_count = ($page - 1) * $posts_per_page + count($posts); $import_link = null; if ($posts_count <= 0 && !empty($stream['all_posts'])) { // When import plugin is installed, show its link on the welcome page $plugins = wa()->getConfig()->getPlugins(); if (!empty($plugins['import'])) { $import_link = wa()->getUrl() . '?module=plugins#/settings/custom/import/'; } } $this->view->assign('blogs', $blogs); $this->view->assign('blog_id', $blog_id); $this->view->assign('text', $text); $this->view->assign('stream', $stream); $this->view->assign('page', $page); $this->view->assign('pages', $post_model->pageCount()); $this->view->assign('posts_total_count', $post_model->searchCount()); $this->view->assign('posts_count', $posts_count); $this->view->assign('import_link', $import_link); $this->view->assign('posts_per_page', $posts_per_page); $this->view->assign('contact_rights', $this->getUser()->getRights('contacts', 'backend')); if ($this->getConfig()->getOption('can_use_smarty')) { foreach ($posts as &$post) { try { $post['text'] = $this->view->fetch("string:{$post['text']}", $this->cache_id); } catch (SmartyException $ex) { $post['text'] = blogPost::handleTemplateException($ex, $post); } } unset($post); } $this->view->assign('posts', $posts); }
/** * * Extend items by contact info * @param array $rows * @param array $fields * @param bool $get_link */ public static function extendUser(&$rows, $fields = array(), $get_link = false) { $default_fields = array('id', 'name'); $fields = array_unique(array_merge($fields, $default_fields)); $ids = array(); foreach ($rows as $row) { if ($row['contact_id']) { $ids[] = intval($row['contact_id']); } } $ids = array_unique($ids); $collection = new waContactsCollection($ids); $contacts = $collection->getContacts(implode(',', $fields), 0, count($ids)); $contact = new waContact(0); $contacts[0] = array('name' => ''); $photo_fields = array(); foreach ($fields as $field) { if (preg_match('@^photo_url_(\\d+)$@', $field, $matches)) { $photo_fields[] = $field; $contacts[0][$field] = $contact->getPhoto($matches[1], $matches[1]); } else { $contacts[0][$field] = $contact->get($field); } } $app_static_url = wa()->getAppStaticUrl(); foreach ($rows as &$row) { $row['user'] = array(); $id = $row['contact_id'] = max(0, intval($row['contact_id'])); if (!isset($contacts[$id])) { $id = 0; } if (isset($contacts[$id])) { if (isset($row['url']) && $get_link && !isset($contacts[$id]['posts_link'])) { $contacts[$id]['posts_link'] = blogPost::getUrl($row, 'author'); } $row['user'] = $contacts[$id]; } if (!$id || !isset($contacts[$id])) { if (isset($row['name'])) { $row['user']['name'] = $row['name']; } elseif (isset($row['contact_name'])) { $row['user']['name'] = $row['contact_name']; } if (isset($row['auth_provider'])) { if ($row['auth_provider'] && $row['auth_provider'] != blogCommentModel::AUTH_GUEST) { $row['user']['photo_url'] = "{$app_static_url}img/{$row['auth_provider']}.png"; foreach ($photo_fields as $field) { $row['user'][$field] =& $row['user']['photo_url']; } } } } unset($row); } }
private function save($post) { $options = array(); if (waRequest::post('transliterate', null)) { $options['transliterate'] = true; } $this->validate_messages = $this->post_model->validate($post, $options); if ($this->validate_messages) { $this->errors = $this->validate_messages; } else { $post['text_before_cut'] = null; $post['cut_link_label'] = null; $template = '<!--[\\s]*?more[\\s]*?(text[\\s]*?=[\\s]*?[\'"]([\\s\\S]*?)[\'"])*[\\s]*?-->'; $descriptor = preg_split("/{$template}/", $post['text'], 2, PREG_SPLIT_DELIM_CAPTURE); if ($descriptor) { if (count($descriptor) == 2) { $post['text_before_cut'] = blogPost::closeTags($descriptor[0]); } elseif (count($descriptor) > 2) { $post['text_before_cut'] = blogPost::closeTags($descriptor[0]); if (isset($descriptor[2])) { $post['cut_link_label'] = $descriptor[2]; } } } if ($post['id']) { $prev_post = $this->post_model->getFieldsById($post['id'], 'status'); if ($prev_post['status'] != blogPostModel::STATUS_PUBLISHED && $post['status'] == blogPostModel::STATUS_PUBLISHED) { $this->inline = false; } $this->post_model->updateItem($post['id'], $post); if ($prev_post['status'] != blogPostModel::STATUS_PUBLISHED && $post['status'] == blogPostModel::STATUS_PUBLISHED) { $this->log('post_publish', 1); } else { $this->log('post_edit', 1); } } else { $post['id'] = $this->post_model->updateItem(null, $post); $this->log('post_publish', 1); } $this->saveParams($post['id']); $this->clearViewCache($post['id'], $post['url']); if (!$this->inline) { if ($post['status'] != blogPostModel::STATUS_PUBLISHED) { $params = array('module' => 'post', 'action' => 'edit', 'id' => $post['id']); } elseif ($post['blog_status'] == blogBlogModel::STATUS_PUBLIC) { $params = array('blog' => $post['blog_id']); } else { $params = array('module' => 'post', 'id' => $post['id']); } $this->response['redirect'] = $this->getRedirectUrl($params); } else { $this->response['formatted_datetime'] = waDateTime::format('humandatetime', $post['datetime']); $this->response['id'] = $post['id']; $this->response['url'] = $post['url']; if ($post['status'] != blogPostModel::STATUS_PUBLISHED) { $options = array('contact_id' => $post['contact_id'], 'blog_id' => $post['blog_id'], 'post_id' => $post['id'], 'user_id' => wa()->getUser()->getId()); $preview_hash = blogPostModel::getPreviewHash($options); $this->response['preview_hash'] = base64_encode($preview_hash . $options['user_id']); $this->response['debug'] = $options; } } } }
public function execute() { if ($this->getRequest()->param('blog_id') === false) { throw new waException(_w('Blog not found'), 404); } $this->view->getHelper()->globals($this->getRequest()->param()); $posts_per_page = max(1, intval($this->getConfig()->getOption('posts_per_page'))); $post_model = new blogPostModel(); $options = array(); if (!$this->appSettings('show_comments', true)) { $options['comments'] = false; } $options['params'] = true; $options['text'] = 'cut'; $options['escape'] = true; $is_search = false; if (isset($this->search_params["search"])) { $plugin = $this->search_params["search"]; if (!isset($this->search_params["plugin"])) { $this->search_params["plugin"] = array(); } if (isset($this->search_params[$plugin])) { $this->search_params["plugin"][$plugin] = $this->search_params[$plugin]; $is_search = true; } } $query = $this->getRequest()->get('query', '', waRequest::TYPE_STRING_TRIM); if ($query) { $this->search_params['text'] = urldecode($query); $options['highlighted'] = true; } $blogs = blogHelper::getAvailable(); $posts = $post_model->search($this->search_params, $options, array('blog' => $blogs))->fetchSearchPage($this->page, $posts_per_page); $stream_title = false; if (isset($this->search_params['contact_id'])) { if (count($posts)) { reset($posts); $post = current($posts); $name = $post['user']['name']; $is_search = true; } else { if ($contact = blogHelper::getContactInfo($this->search_params['contact_id'])) { $name = htmlentities($contact['name'], ENT_QUOTES, 'utf-8'); $is_search = true; } else { throw new waException(_w('Blog not found'), 404); } } $stream_title = sprintf(_w('Posts by %s'), $name); $this->getResponse()->setTitle($stream_title); } elseif ($is_search) { $stream_title = $this->getResponse()->getTitle(); } elseif (isset($this->search_params['year'])) { $stream_title = ''; if (isset($this->search_params['day'])) { $stream_title .= intval($this->search_params['day']) . ' '; } if (isset($this->search_params['month'])) { $stream_title .= _ws(date("F", gmmktime(0, 0, 0, intval($this->search_params['month']), 1))) . ' '; } $stream_title .= $this->search_params['year'] . ' — ' . $this->getResponse()->getTitle(); $this->getResponse()->setTitle($stream_title); } else { if (!empty($this->search_params['text'])) { $stream_title = urldecode($this->search_params['text']); $this->getResponse()->setTitle($stream_title); $is_search = true; } } $this->view->assign('stream_title', $stream_title); $pages = $post_model->pageCount(); $url = wa()->getRouteUrl('blog/frontend', $this->search_params, true); if ($pages && $pages < $this->page) { $page = min($pages, $this->page); $redirect = $url . ($page > 1 ? "?page={$page}" : ''); $this->getResponse()->redirect($redirect, 302); } if ($layout = $this->getLayout()) { $links = array(); if ($pages > $this->page) { $page = $this->page + 1; $links['next'] = "{$url}?page={$page}"; } if ($this->page > 1) { $page = $this->page - 1; $links['prev'] = $url . ($page > 1 ? "?page={$page}" : ''); } $layout->assign('links', $links); if (!$is_search) { /* * @deprecated fix assigning sidebar_timeline for next version of blog * */ $layout->assign('sidebar_timeline', $post_model->getTimeline($this->search_params['blog_id'], $blogs, $this->search_params)); } if (isset($this->search_params['contact_id'])) { $layout->assign('action_info', array('search' => array('contact_id' => $this->search_params['contact_id']))); } $layout->assign('is_search', $is_search); } $this->view->assign('is_search', $is_search); $this->view->assign('page', $this->page); $this->view->assign('is_lazyloading', $this->is_lazyloading); $this->view->assign('pages', $pages); $this->view->assign('post_count', $post_model->searchCount()); $this->view->assign('show_comments', !isset($options['comments']) || $options['comments']); $this->view->assign('posts_per_page', $posts_per_page); $this->view->assign('blog_query', $query); /** * Backward compatibility with older themes * @deprecated */ $this->view->assign('is_concrete_blog', waRequest::param('blog_url') ? true : false); $this->view->assign('layout_type', $this->is_lazyloading ? 'lazyloading' : ($this->page > 1 ? 'page' : 'default')); if ($this->getConfig()->getOption('can_use_smarty')) { foreach ($posts as &$post) { try { $post['text'] = $this->view->fetch("string:{$post['text']}", $this->cache_id); } catch (SmartyException $ex) { $post['text'] = blogPost::handleTemplateException($ex, $post); } } unset($post); } $this->view->assign('posts', $posts); if ($this->cache_time && false) { $this->cache->set(array_keys($posts)); } }