public function execute()
 {
     $blog_id = wa()->getRequest()->param('blog_url_type');
     if ($blog_id <= 0) {
         $blog_id = waRequest::request('blog_id', 0, 'int');
     }
     $this->setLayout(new blogFrontendLayout());
     // Get contact id and name as post author
     if (wa()->getUser()->get('is_user')) {
         $post_contact_id = wa()->getUser()->getId();
         $post_contact_name = wa()->getUser()->getName();
     } else {
         foreach (blogHelper::getAuthors($blog_id) as $post_contact_id => $post_contact_name) {
             break;
         }
     }
     // Prepare empty fake post data
     $post_model = new blogPostModel();
     $post = $post_model->prepareView(array(array('id' => 0, 'blog_id' => $blog_id, 'contact_id' => $post_contact_id, 'contact_name' => $post_contact_name, 'datetime' => date('Y-m-d H:i:s'), 'title' => '%replace-with-real-post-title%', 'status' => 'published', 'text' => '<div class="replace-with-real-post-text"></div>' . $this->getScripts(), 'comments_allowed' => 0) + $post_model->getEmptyRow()));
     $post = array_merge($post[0], array('comments' => array(), 'comment_link' => '', 'link' => ''));
     $this->getResponse()->setTitle(_w('Preview'));
     $this->getResponse()->setMeta('keywords', '');
     $this->getResponse()->setMeta('description', '');
     $current_auth = wa()->getStorage()->read('auth_user_data');
     $current_auth_source = $current_auth ? $current_auth['source'] : null;
     $this->view->assign(array('realtime_preview' => true, 'frontend_post' => array(), 'errors' => array(), 'form' => array(), 'show_comments' => false, 'request_captcha' => false, 'require_authorization' => false, 'theme' => waRequest::param('theme', 'default'), 'current_auth_source' => $current_auth_source, 'current_auth' => $current_auth, true, 'auth_adapters' => wa()->getAuthAdapters(), 'post' => $post));
 }
 public function postPublishAction($params)
 {
     $post_id = (int) $params['id'];
     $blog_id = (int) $params['blog_id'];
     // check rights for this blog at first and unsubscribe user if he hasn't
     $sql = "SELECT c.id FROM blog_emailsubscription s\n        JOIN wa_contact c ON s.contact_id = c.id\n        WHERE s.blog_id = " . $blog_id;
     $model = new waModel();
     $unsubscribe_contact_ids = array();
     foreach ($model->query($sql) as $row) {
         $rights = 1;
         try {
             $rights = blogHelper::checkRights($blog_id, $row['id'], blogRightConfig::RIGHT_READ);
         } catch (Exception $e) {
             $rights = 0;
         }
         if (!$rights) {
             $unsubscribe_contact_ids[] = $row['id'];
         }
     }
     if ($unsubscribe_contact_ids) {
         $em = new blogEmailsubscriptionModel();
         $em->deleteByField(array('contact_id' => $unsubscribe_contact_ids, 'blog_id' => $blog_id));
     }
     // add subscribers to queue
     $sql = "REPLACE INTO blog_emailsubscription_log (post_id, contact_id, name, email, datetime)\n                SELECT " . $post_id . ", c.id, c.name, e.email, '" . date('Y-m-d H:i:s') . "' FROM blog_emailsubscription s\n                JOIN wa_contact c ON s.contact_id = c.id\n                JOIN wa_contact_emails e ON c.id = e.contact_id AND e.sort = 0\n                WHERE s.blog_id = " . $blog_id;
     $model->exec($sql);
     // save backend url for cron
     $app_settings_model = new waAppSettingsModel();
     $app_settings_model->set(array($this->app_id, $this->id), 'backend_url', wa()->getRootUrl(true) . wa()->getConfig()->getBackendUrl());
 }
 public function genUniqueUrl($from)
 {
     static $time = 0;
     static $counter = 0;
     $from = preg_replace('/\\s+/', '-', $from);
     $url = blogHelper::transliterate($from);
     if (strlen($url) == 0) {
         $url = self::shortUuid();
     } else {
         $url = mb_substr($url, 0, $this->url_length);
     }
     $url = mb_strtolower($url);
     $pattern = mb_substr($this->escape($url, 'like'), 0, $this->url_length - 3) . '%';
     $sql = "SELECT url FROM {$this->table} WHERE url LIKE '{$pattern}' ORDER BY LENGTH(url)";
     $alike = $this->query($sql)->fetchAll('url');
     if (is_array($alike) && isset($alike[$url])) {
         $last = array_shift($alike);
         $counter = 1;
         do {
             $modifier = "-{$counter}";
             $length = mb_strlen($modifier);
             $url = mb_substr($last['url'], 0, $this->url_length - $length) . $modifier;
         } while ($counter++ < 99 && isset($alike[$url]));
         if (isset($alike[$url])) {
             $short_uuid = self::shortUuid();
             $length = mb_strlen($short_uuid);
             $url = mb_substr($last['url'], 0, $this->url_length - $length) . $short_uuid;
         }
     }
     return mb_strtolower($url);
 }
 public function execute()
 {
     $is_admin = $this->getUser()->isAdmin($this->getApp());
     $storage = $this->getStorage();
     if (waRequest::post('save')) {
         $this->save();
         $save_id = rand(10000, 99999);
         $storage->write('blog_setttings_save_id', $save_id);
         $this->redirect(array('module' => 'settings', 'save' => $save_id));
     }
     if ($is_admin) {
         $e_g = blogHelper::getAvailable();
         reset($e_g);
         $user = $this->getUser();
         $this->view->assign('e_g', current($e_g));
         $this->view->assign('user_name', $user['name']);
         // Checking if have saved now
         $save_id = $storage->read('blog_setttings_save_id');
     }
     // Checking if have saved now
     $save_id = $storage->read('blog_setttings_save_id');
     if ($save_id && $save_id == waRequest::get('save', 0)) {
         $storage->del('blog_setttings_save_id');
         $this->view->assign('saved', 1);
     }
     $this->getResponse()->setTitle(_w('Blog settings page'));
     $this->setLayout(new blogDefaultLayout());
     $this->view->assign('user_settings', $res = $this->getUserSettings());
     if ($is_admin) {
         $this->view->assign('backend_settings', $this->getFrontendSettings());
         $this->view->assign('routing_settings_url', blogHelper::getRouteSettingsUrl());
     }
 }
 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()
 {
     $id = $this->get('id', true);
     $post_model = new blogPostModel();
     $post = $post_model->getById($id);
     if (!$post) {
         throw new waAPIException('invalid_param', 'Post not found', 404);
     }
     //check rights
     if (blogHelper::checkRights($post['blog_id']) < blogRightConfig::RIGHT_FULL && $post['contact_id'] != wa()->getUser()->getId()) {
         throw new waAPIException('access_denied', 403);
     }
     $data = array_merge($post, waRequest::post());
     $blog_model = new blogBlogModel();
     $blogs = $blog_model->getAvailable();
     if (!isset($blogs[$data['blog_id']])) {
         throw new waAPIException('invalid_param', 'Blog not found', 404);
     }
     $blog = $blogs[$data['blog_id']];
     $data['blog_status'] = $blog['status'];
     $data['datetime'] = $this->formateDatetime($data['datetime']);
     $messages = $post_model->validate($data, array('transliterate' => true));
     if ($messages) {
         throw new waAPIException('invalid_param', 'Validate messages: ' . implode("\n", $messages), 404);
     }
     $post_model->updateItem($data['id'], $data);
     $_GET['id'] = $id;
     $method = new blogPostGetInfoMethod();
     $this->response = $method->getResponse(true);
 }
 public function prepareView($items, $fields = array(), $extend_options = array())
 {
     blogHelper::extendUser($items, $fields, !empty($extend_options['user']));
     $contact_id = wa()->getUser()->getId();
     if (isset($extend_options['datetime'])) {
         $blog_activity = blogActivity::getInstance();
         $viewed_comments = array();
         $expire = isset($extend_options['expire']) ? $extend_options['expire'] : false;
     }
     #data holders for plugin hooks
     foreach ($items as &$item) {
         $item['plugins'] = array('before' => array(), 'after' => array(), 'authorname_suffix' => array());
         $item['ip'] = long2ip($item['ip']);
         if (empty($item['name']) && !empty($item['user']['name'])) {
             $item['name'] = $item['user']['name'];
         }
         if (isset($extend_options['datetime'])) {
             if ($item['datetime'] > $extend_options['datetime'] && (!$contact_id || $contact_id != $item['contact_id'])) {
                 $item['new'] = $blog_activity->isNew("c.{$item['post_id']}", $item['id'], $expire);
                 if ($item['new'] == blogActivity::STATE_NEW) {
                     $viewed_comments[$item['post_id']][] = $item['id'];
                 } elseif (!$item['new']) {
                     unset($item['new']);
                 }
             }
         }
         if (!$item['auth_provider']) {
             if ($item['contact_id']) {
                 $item['auth_provider'] = blogCommentModel::AUTH_USER;
             } else {
                 $item['auth_provider'] = blogCommentModel::AUTH_GUEST;
             }
         }
         if (!empty($extend_options['escape'])) {
             $item['text'] = htmlspecialchars($item['text'], ENT_QUOTES, 'utf-8');
             $item['name'] = htmlspecialchars($item['name'], ENT_QUOTES, 'utf-8');
         }
         unset($item);
     }
     if (!empty($viewed_comments)) {
         foreach ($viewed_comments as $post_id => $ids) {
             $blog_activity->set("c.{$post_id}", $ids);
         }
     }
     /**
      * Prepare comments data
      * Extend each comment item via plugins data
      * @event prepare_comments_frontend
      * @event prepare_comments_backend
      * @param array[string]mixed $items
      * @param array[string]int $items[%id][id] Comment ID
      * @param array[string][string][string]string $item[plugins][before][%plugin_id%]
      * @param array[string][string][string]string $item[plugins][after][%plugin_id%]
      * @param array[string][string][string]string $item[plugins][authorname_suffix][%plugin_id%]
      * @return void
      */
     wa()->event('prepare_comments_' . wa()->getEnv(), $items);
     return $items;
 }
Beispiel #8
0
 static function getUrl($blog = null, $absolute = false)
 {
     $params = array();
     $blog_id = isset($blog['id']) ? $blog['id'] : null;
     if ($blog && isset($blog['url']) && $blog['url']) {
         $params['blog_url'] = $blog['url'];
     } elseif ($blog) {
         $params['blog_url'] = '%blog_url%';
     }
     return blogHelper::getUrl($blog_id, 'blog/frontend', $params, $absolute);
 }
 public function execute()
 {
     $post_title = waRequest::post('post_title', '', waRequest::TYPE_STRING_TRIM);
     $blog_id = waRequest::post('blog_id', 0, waRequest::TYPE_INT);
     $slug = waRequest::post('slug', '', waRequest::TYPE_STRING_TRIM);
     $blog_model = new blogBlogModel();
     $blog = $blog_model->getById($blog_id);
     if (!$blog) {
         throw new waException(_w("Can't find corresponding blog"));
     }
     $this->response['is_private_blog'] = $blog['status'] == blogBlogModel::STATUS_PRIVATE;
     $post_id = waRequest::post('post_id', 0, waRequest::TYPE_INT);
     $post_model = new blogPostModel();
     if ($post_id) {
         $post = $post_model->getById($post_id, array('text', 'text_before_cut'));
         if (!$post) {
             throw new waException(_w("Can't find corresponding post"));
         }
         if ($post['status'] != blogPostModel::STATUS_PUBLISHED) {
             $options = array('contact_id' => $post['contact_id'], 'blog_id' => $blog_id, 'post_id' => $post['id'], 'user_id' => wa()->getUser()->getId());
             $this->response['preview_hash'] = blogPostModel::getPreviewHash($options);
             $this->response['preview_hash'] = base64_encode($this->response['preview_hash'] . $options['user_id']);
         }
         $this->response['slug'] = $post['url'];
         $this->response['is_published'] = $post['status'] == blogPostModel::STATUS_PUBLISHED;
         $this->response['is_adding'] = false;
     } else {
         $post = array();
         $this->response['slug'] = $slug ? $slug : blogHelper::transliterate($post_title);
         $this->response['is_published'] = false;
         $this->response['is_adding'] = true;
     }
     $post['blog_id'] = $blog_id;
     $post['album_link_type'] = 'blog';
     $other_links = blogPostModel::getPureUrls($post);
     $this->response['link'] = array_shift($other_links);
     if (!$this->response['link']) {
         $this->response['is_private_blog'] = true;
     }
     $this->response['other_links'] = $other_links;
     foreach ($this->response as $k => &$item) {
         if (!$item || !is_string($item) && !is_array($item)) {
             continue;
         }
         if (is_array($item)) {
             $item = array_map('htmlspecialchars', $item, array_fill(0, count($item), ENT_QUOTES));
             continue;
         }
         $item = htmlspecialchars($item, ENT_QUOTES);
     }
     unset($item);
     $this->getResponse()->addHeader('Content-type', 'application/json');
 }
Beispiel #10
0
 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 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)));
 }
 protected function init()
 {
     $transport = ucfirst($this->getRequest()->post('blog_import_transport', '', waRequest::TYPE_STRING_TRIM));
     $class = "blogImportPlugin{$transport}Transport";
     if ($transport && class_exists($class)) {
         $plugin_namespace = $this->getApp() . '_import';
         $namespace = $plugin_namespace . '_' . strtolower($transport);
         $this->initPlugin();
         if ($post = $this->getRequest()->post($plugin_namespace)) {
             $this->plugin->setup($post);
             if ($this->plugin->validateSettings($this->errors)) {
                 $this->plugin->saveSettings();
             } else {
                 throw new waException(_wp('Invalid replace settings'));
             }
         }
         $settings = $this->plugin->getSettings();
         $blog_model = new blogBlogModel();
         if ($settings['blog'] && ($blog = $blog_model->getById($settings['blog']))) {
             $settings['blog_status'] = $blog['status'];
         } else {
             throw new waException(_wp("Target blog not found"));
         }
         $author_has_rights = false;
         try {
             if ($settings['contact']) {
                 $author_has_rights = blogHelper::checkRights($settings['blog'], $settings['contact']);
             }
         } catch (waRightsException $ex) {
             //do nothing
         }
         if (!$author_has_rights) {
             throw new waException(_wp("Author not found or has insufficient rights"));
         }
         $this->data['transport'] = new $class($settings);
         $this->data['blog'] = $this->plugin->getSettingValue('blog');
         $this->getTransport();
         $this->transport->setup($this->getRequest()->post($namespace, array()));
         if (!$this->transport->validate(true, $this->errors)) {
             throw new waException(_wp('Invalid settings'));
         }
         //$this->data['runtime_settings'] =$this->transport->get
         $this->data['posts'] = $this->transport->getPosts();
         $this->data['current'] = 0;
         $this->data['count'] = count($this->data['posts']);
     } else {
         throw new waException(sprintf(_wp("Transport type %s not found"), $transport));
     }
 }
Beispiel #14
0
 /**
  * @param array $items
  * @param array $options
  * @param array $extend_data
  * @return array
  */
 public function prepareView($items, $options = array(), $extend_data = array())
 {
     $extend_options = array_merge($this->extend_options, $options);
     $extend_data = array_merge($this->extend_data, (array) $extend_data);
     foreach ($items as &$item) {
         blogHelper::extendIcon($item);
         if (!isset($extend_options['link']) || $extend_options['link']) {
             $item['link'] = blogBlog::getUrl($item, true);
         }
         if (!empty($extend_options['escape'])) {
             $item['name'] = htmlspecialchars($item['name'], ENT_QUOTES, 'utf-8');
             $item['link'] = htmlspecialchars($item['link'], ENT_QUOTES, 'utf-8');
         }
         unset($item);
     }
     if (isset($options['new']) && $options['new']) {
         $post_model = new blogPostModel();
         $blog_activity = blogActivity::getInstance();
         $posts_update = $post_model->getAddedPostCount(blogActivity::getUserActivity(), array_keys($items), true);
         if ($posts_update) {
             foreach ($posts_update as $blog_id => $new) {
                 if (isset($items[$blog_id])) {
                     $items[$blog_id]['new_post'] = 0;
                     $post_ids = explode(':', $new);
                     foreach ($post_ids as $post_id) {
                         if ($blog_activity->isNew("b.{$blog_id}", $post_id, isset($options['expire']) ? $options['expire'] : null)) {
                             ++$items[$blog_id]['new_post'];
                         }
                     }
                     if (!$items[$blog_id]['new_post']) {
                         unset($items[$blog_id]['new_post']);
                     }
                 }
             }
         }
     }
     /**
      * Prepare blog data
      * Extend each blog item via plugins data
      * @event prepare_blogs_frontend
      * @event prepare_blogs_backend
      * @param array $items
      * @param int $items[]['id']
      * @return void
      */
     wa()->event('prepare_blogs_' . wa()->getEnv(), $items);
     return $items;
 }
 public function execute()
 {
     $id = $this->get('id', true);
     $post_model = new blogPostModel();
     $post = $post_model->search(array('id' => $id))->fetchSearchItem();
     if ($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);
         }
         $this->response = $post;
     } else {
         throw new waAPIException('invalid_param', 'Post not found', 404);
     }
 }
 public function execute()
 {
     $data = waRequest::post('data', null);
     if (!$data) {
         return;
     }
     foreach ($data as $name => $value) {
         if (in_array($name, $this->allowed_fields) === false) {
             throw new waException("Can't update post: editing of this field is denied");
         }
         if ($name == 'status') {
             if (in_array($value, array(blogPostModel::STATUS_DRAFT, blogPostModel::STATUS_DEADLINE, blogPostModel::STATUS_SCHEDULED, blogPostModel::STATUS_PUBLISHED)) === false) {
                 throw new waException("Can't change status: unknown value");
             }
         }
     }
     $post_id = waRequest::post('post_id', null, waRequest::TYPE_INT);
     $post_model = new blogPostModel();
     $post = null;
     if ($post_id) {
         $post = $post_model->getFieldsById($post_id, array('id', 'blog_id', 'contact_id', 'datetime'));
     }
     if (!$post) {
         throw new waException("Unknown post");
     }
     $contact = wa()->getUser();
     $contact_id = $contact->getId();
     $allow = blogHelper::checkRights($post['blog_id'], $contact_id, $contact_id != $post['contact_id'] ? blogRightConfig::RIGHT_FULL : blogRightConfig::RIGHT_READ_WRITE);
     if (!$allow) {
         throw new waException("Access denied");
     }
     if (!$post_model->updateById($post_id, $data)) {
         throw new waException("Error when updating data");
     }
     $post = array_merge($post, $data);
     if ($post['status'] == blogPostModel::STATUS_DEADLINE) {
         $user = wa()->getUser();
         $timezone = $user->getTimezone();
         $current_datetime = waDateTime::date("Y-m-d", null, $timezone);
         $datetime = waDateTime::date("Y-m-d", $post['datetime'], $timezone);
         if ($datetime <= $current_datetime) {
             $post['overdue'] = true;
         }
     }
     $this->response['post'] = $post;
 }
 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);
 }
 public function execute()
 {
     if (!wa()->getUser()->getRights('blog', blogRightConfig::RIGHT_ADD_BLOG, true)) {
         throw new waAPIException('access_denied', 403);
     }
     $data = waRequest::post();
     // check required param name
     $this->post('name', true);
     $data = array_merge($data, array('color' => 'b-white', 'icon' => 'blog', 'url' => blogHelper::transliterate($data['name'])));
     $blog_model = new blogBlogModel();
     $data['sort'] = (int) $blog_model->select('MAX(`sort`)')->fetchField() + 1;
     $blog_id = $blog_model->insert($data);
     wa()->getUser()->setRight('blog', "blog.{$blog_id}", blogRightConfig::RIGHT_FULL);
     // return info of the new blog
     $_GET['id'] = $blog_id;
     $method = new blogBlogGetInfoMethod();
     $this->response = $method->getResponse(true);
 }
 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 frontendSidebar($params)
    {
        $output = array();
        $category_id = isset($params['category']) ? $params['category'] : false;
        if ($categories = blogCategory::getAll()) {
            $output['sidebar'] = '<ul class="menu-v categories">';
            $wa = wa();
            foreach ($categories as $category) {
                blogHelper::extendIcon($category);
                $category['link'] = $wa->getRouteUrl('blog/frontend', array('category' => urlencode($category['url'])), true);
                $category['name'] = htmlentities($category['name'], ENT_QUOTES, 'utf-8');
                $selected = $category_id && $category_id == $category['url'] ? ' class="selected"' : '';
                $output['sidebar'] .= <<<HTML
<li{$selected}>
<a href="{$category['link']}" title="{$category['name']}">{$category['name']}</a>
</li>
HTML;
            }
            $output['sidebar'] .= '</ul>';
        }
        return $output;
    }
Beispiel #21
0
 public function execute()
 {
     $is_admin = $this->getUser()->isAdmin($this->getApp());
     $storage = $this->getStorage();
     if (waRequest::post('save')) {
         $this->save();
         $save_id = rand(10000, 99999);
         $storage->write('blog_setttings_save_id', $save_id);
         $this->redirect(array('module' => 'settings', 'save' => $save_id));
     }
     if ($is_admin) {
         $e_g = blogHelper::getAvailable();
         reset($e_g);
         $user = $this->getUser();
         $this->view->assign('e_g', current($e_g));
         $this->view->assign('user_email', $user->get('email', 'default'));
         // Checking if have saved now
         $save_id = $storage->read('blog_setttings_save_id');
     }
     // Checking if have saved now
     $save_id = $storage->read('blog_setttings_save_id');
     if ($save_id && $save_id == waRequest::get('save', 0)) {
         $storage->del('blog_setttings_save_id');
         $this->view->assign('saved', 1);
     }
     $this->getResponse()->setTitle(_w('Blog settings page'));
     $this->setLayout(new blogDefaultLayout());
     $this->view->assign('user_settings', $res = $this->getUserSettings());
     if ($is_admin) {
         $this->view->assign('backend_settings', $this->getFrontendSettings());
         // to mislead potential foes, apparently...
         $this->view->assign('routing_settings_url', blogHelper::getRouteSettingsUrl());
         $this->view->assign('photos_app_available', blogPhotosBridge::isAvailable());
     }
     $app_settings_model = new waAppSettingsModel();
     $this->view->assign('last_reminder_cron_time', $app_settings_model->get('blog', 'last_reminder_cron_time'));
     $this->view->assign('cron_command', 'php ' . wa()->getConfig()->getRootPath() . '/cli.php blog reminder');
 }
 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;
 }
    public function backendSidebar($params)
    {
        $output = array();
        $post_model = new blogPostModel();
        $blogs = blogHelper::getAvailable(false);
        $search_options = array('contact_id' => wa()->getUser()->getId(), 'status' => blogPostModel::STATUS_PUBLISHED, 'blog_id' => array_keys($blogs));
        $count = $post_model->countByField($search_options);
        $selected = '';
        if (waRequest::get('search') == $this->id) {
            $selected = ' class="selected"';
        }
        $img_url = wa()->getUser()->getPhoto(20);
        $title = _wp('Posts by me');
        $output['menu'] = <<<HTML
<li{$selected}>
\t<span class="count my_count">{$count}</span>
\t<a href="?search={$this->id}">
\t\t<i class="icon16 userpic20" style="background-image: url('{$img_url}');"></i>{$title}
\t</a>
</li>
HTML;
        return $output;
    }
 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()));
 }
Beispiel #25
0
<?php

//create first blog at install
try {
    $name = wa()->accountName();
    $blog = array('status' => blogBlogModel::STATUS_PUBLIC, 'name' => $name, 'icon' => 'blog', 'color' => 'b-white', 'url' => blogHelper::transliterate($name));
    $app = wa()->getApp();
    $blog_model = new blogBlogModel();
    if ($blog_model->countAll() == 0) {
        $blog_id = $blog_model->insert($blog);
        $user = wa()->getUser();
        if (!$user->isAdmin($app)) {
            $user->setRight($app, "blog.{$blog_id}", blogRightConfig::RIGHT_FULL);
        }
    }
} catch (Exception $e) {
    waLog::log($e->getMessage());
}
 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);
 }
Beispiel #27
0
 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);
 }
 /**
  * Validate data
  *
  * @param array &$data
  * @param array $options
  *
  * @return array messages or empty array
  */
 public function validate(&$data, $options = array())
 {
     $messages = array();
     if ($data['blog_status'] != blogBlogModel::STATUS_PRIVATE) {
         if (!empty($data['id'])) {
             $url_validator = new blogSlugValidator(array('id' => $data['id']));
         } else {
             if (!empty($options['transliterate']) && !$data['url']) {
                 if ($data['title']) {
                     $data['url'] = blogHelper::transliterate($data['title']);
                 } else {
                     $data['url'] = $this->genUniqueUrl('');
                 }
             }
             $url_validator = new blogSlugValidator();
         }
         $url_validator->setSubject(blogSlugValidator::SUBJECT_POST);
         if (!$url_validator->isValid($data['url'])) {
             $messages['url'] = current($url_validator->getErrors());
             if ($url_validator->isError(blogSlugValidator::ERROR_REQUIRED) && ($data['id'] || !$data['id'] && $data['status'] == blogPostModel::STATUS_DRAFT)) {
                 $url = $this->select('url')->where('id = i:id', array('id' => $data['id']))->fetchField('url');
                 $data['url'] = $url ? $url : $this->genUniqueUrl($data['title']);
                 unset($messages['url']);
                 if (!$url_validator->isValid($data['url'])) {
                     $messages['url'] = current($url_validator->getErrors());
                 }
             } elseif (!empty($options['make'])) {
                 $data['url'] = $this->genUniqueUrl($data['url']);
                 unset($messages['url']);
                 if (!$url_validator->isValid($data['url'])) {
                     $messages['url'] = current($url_validator->getErrors());
                 }
             }
         }
     } else {
         if (empty($data['id'])) {
             $data['url'] = $this->genUniqueUrl(empty($data['url']) ? $data['title'] : $data['url']);
         } else {
             $url = $this->select('url')->where('id = i:id', array('id' => $data['id']))->fetchField('url');
             $data['url'] = $url ? $url : $this->genUniqueUrl($data['title']);
         }
     }
     if (isset($data['datetime']) && !is_null($data['datetime'])) {
         if (!empty($options['datetime'])) {
             $formats = (array) $options['datetime'];
         } elseif (isset($options['datetime'])) {
             $formats = array();
         } elseif (strpos($data['datetime'], ':') !== false) {
             $formats = array('fulldatetime', 'datetime');
         } else {
             $formats = array('date');
         }
         if ($data['datetime'] != '') {
             $datetime = $data['datetime'];
             foreach ($formats as $format) {
                 try {
                     if ($datetime = waDateTime::parse($format, $data['datetime'])) {
                         break;
                     }
                 } catch (Exception $ex) {
                     $messages['datetime'] = _w('Incorrect format');
                     waLog::log($ex->getMessage());
                 }
             }
             if (preg_match('/^([\\d]{4})\\-([\\d]{1,2})\\-([\\d]{1,2})(\\s|$)/', $datetime, $matches)) {
                 if (!checkdate($matches[2], $matches[3], $matches[1])) {
                     $messages['datetime'] = _w('Incorrect format');
                 }
             }
             $data['datetime'] = $datetime;
         } else {
             if ($data['status'] != blogPostModel::STATUS_DRAFT) {
                 $data['datetime'] = false;
             }
         }
         if ($data['datetime'] === false) {
             $messages['datetime'] = _w('Incorrect format');
         }
     }
     /**
      * @event post_validate
      * @param array [string]mixed $data
      * @param array ['plugin']['%plugin_id%']mixed plugin data
      * @return array['%plugin_id%']['field']string error
      */
     $messages['plugin'] = wa()->event('post_validate', $data);
     if (empty($messages['plugin'])) {
         unset($messages['plugin']);
     }
     return $messages;
 }
 public function execute($plugin = null, $module = null, $action = null, $default = false)
 {
     if (!$plugin && $module == 'frontend') {
         try {
             if (!waRequest::param('page_id')) {
                 $request_url = parse_url($this->system->getRootUrl() . $this->system->getConfig()->getRequestUrl());
                 if (isset($request_url['path']) && $request_url['path'] && substr($request_url['path'], -1) != '/') {
                     $request_url['path'] .= '/';
                     $this->system->getResponse()->redirect(implode('', $request_url), 301);
                 }
             }
             #parse request URL
             $params = waRequest::param();
             #determine blog ID which are dependent on routing settings
             $blog_model = new blogBlogModel();
             $blogs = array();
             $params['blog_url_type'] = waRequest::param('blog_url_type', 0, waRequest::TYPE_INT);
             if (!($title = waRequest::param('title'))) {
                 $title = wa()->accountName();
             }
             $blog_url = waRequest::param('blog_url', '', waRequest::TYPE_STRING_TRIM);
             $main_page = false;
             if ($params['blog_url_type'] > 0) {
                 if ($blog = $blog_model->getByField(array('id' => $params['blog_url_type'], 'status' => blogBlogModel::STATUS_PUBLIC))) {
                     $blogs[] = $blog;
                     $main_page = true;
                 }
             } elseif (strlen($blog_url)) {
                 if ($blog = $blog_model->getBySlug($blog_url, true, array('id', 'name', 'url'))) {
                     $blogs[] = $blog;
                 }
             } else {
                 $blogs = blogHelper::getAvailable();
                 if (!isset($params['post_url'])) {
                     if (count($blogs) > 1 || $params['blog_url_type'] == 0) {
                         $main_page = true;
                     }
                 }
             }
             if ($blogs) {
                 if (count($blogs) == 1 && ($params['blog_url_type'] != 0 || strlen($blog_url))) {
                     $blog = reset($blogs);
                     $params['blog_id'] = intval($blog['id']);
                     $params['blog_url'] = $blog['url'];
                     if (!$main_page) {
                         $routing = wa()->getRouting();
                         if ($params['blog_id'] != $routing->getRouteParam('blog_url_type') || isset($params['post_url'])) {
                             $title = $blog['name'];
                         } elseif (!$title) {
                             $title = $blog['name'];
                         }
                     }
                 } else {
                     $params['blog_id'] = array_map('intval', array_keys($blogs));
                 }
             } else {
                 throw new waException(_w('Blog not found'), 404);
             }
             wa()->getResponse()->setTitle($title);
             if ($main_page) {
                 wa()->getResponse()->setMeta('keywords', waRequest::param('meta_keywords'));
                 wa()->getResponse()->setMeta('description', waRequest::param('meta_description'));
             }
             waRequest::setParam($params);
             parent::execute($plugin, $module, $action, $default);
         } catch (Exception $e) {
             waRequest::setParam('exception', $e);
             parent::execute(null, 'frontend', 'error');
         }
     } else {
         parent::execute($plugin, $module, $action, $default);
     }
 }
Beispiel #30
0
 static function getUrl($post, $type = 'post')
 {
     if ($type == 'post' && !empty($post['album_id']) && $post['album_link_type'] == 'photos') {
         wa('photos');
         if (empty($post['album']['full_url'])) {
             $album_full_url = photosCollection::frontendAlbumHashToUrl('album/' . $post['album_id']);
         } else {
             $album_full_url = $post['album']['full_url'];
         }
         $url = photosFrontendAlbum::getLink($album_full_url);
         if (wa()->getEnv() == 'backend') {
             return array($url);
         } else {
             return $url;
         }
     }
     static $blog_urls = array();
     $params = array();
     $fields = array('blog_url', 'year', 'month', 'day');
     foreach ($fields as $field) {
         if (isset($post[$field])) {
             $params[$field] = $post[$field];
         }
     }
     if (isset($post['id']) && $post['id'] && isset($post['url']) && $post['url']) {
         $params['post_url'] = $post['url'];
     } elseif ($type != 'timeline') {
         $params['post_url'] = '%post_url%';
     }
     $blog_id = null;
     if ($type != 'author') {
         if (isset($post['datetime']) && $post['datetime'] && ($time = date_parse($post['datetime']))) {
             $params['post_year'] = sprintf('%04d', $time['year']);
             $params['post_month'] = sprintf('%02d', $time['month']);
             $params['post_day'] = sprintf('%02d', $time['day']);
         } elseif ($type != 'timeline') {
             $params['post_year'] = '%year%';
             $params['post_month'] = '%month%';
             $params['post_day'] = '%day%';
         }
         if (!isset($params['blog_url']) && isset($post['blog_id'])) {
             $blog_id = $post['blog_id'];
             if (!isset($blog_urls[$blog_id])) {
                 $blog_urls[$blog_id] = false;
                 $blog_model = new blogBlogModel();
                 if ($blog_data = $blog_model->getById($blog_id)) {
                     if ($blog_data['status'] == blogBlogModel::STATUS_PUBLIC) {
                         if (strlen($blog_data['url'])) {
                             $blog_urls[$blog_id] = $blog_data['url'];
                         } else {
                             $blog_urls[$blog_id] = $blog_id;
                         }
                     }
                 }
             }
             $params['blog_url'] = $blog_urls[$blog_id];
         } elseif (isset($params['blog_url']) && isset($post['blog_id'])) {
             $blog_id = $post['blog_id'];
         }
     }
     $route = false;
     if (!isset($params['blog_url']) || $params['blog_url'] !== false) {
         switch ($type) {
             case 'comment':
                 $route = 'blog/frontend/comment';
                 break;
             case 'timeline':
                 $route = 'blog/frontend';
                 break;
             case 'author':
                 if ($params['contact_id'] = $post['contact_id']) {
                     $route = 'blog/frontend';
                 }
                 break;
             case 'post':
             default:
                 $route = 'blog/frontend/post';
                 break;
         }
     }
     return $route ? blogHelper::getUrl($blog_id, $route, $params) : array();
 }