public function execute()
 {
     $routes = $this->getRoutes();
     $app_id = wa()->getApp();
     $blog_model = new blogBlogModel();
     $post_model = new blogPostModel();
     $blogs = $blog_model->getAvailable(false, array('id', 'name', 'url'));
     foreach ($routes as $route) {
         $lastmod = null;
         $this->routing->setRoute($route);
         $default_blog_id = isset($route['blog_url_type']) ? (int) $route['blog_url_type'] : 0;
         $default_blog_id = max(0, $default_blog_id);
         $extend_options = array('datetime' => true);
         $extend_data = array('blog' => $blogs);
         foreach ($blogs as $blog_id => $blog) {
             if (!$default_blog_id || $blog_id == $default_blog_id) {
                 $search_options = array('blog_id' => $blog_id);
                 $posts = $post_model->search($search_options, $extend_options, $extend_data)->fetchSearchAll('id,title,url,datetime,blog_id');
                 foreach ($posts as $post) {
                     $post['blog_url'] = $blog['url'];
                     $post_lastmod = strtotime($post['datetime']);
                     $lastmod = max($lastmod, $post_lastmod);
                     if (!empty($post['comment_datetime'])) {
                         $post_lastmod = max($post_lastmod, strtotime($post['comment_datetime']));
                     }
                     $this->addUrl($post['link'], $post_lastmod);
                 }
             }
         }
         $this->addUrl(wa()->getRouteUrl($app_id . "/frontend", array(), true), $lastmod);
     }
 }
Ejemplo n.º 2
0
 public function execute()
 {
     $data = waRequest::post();
     // check required params
     $this->post('blog_id', true);
     $this->post('title', true);
     $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']];
     if ($blog['rights'] < blogRightConfig::RIGHT_READ_WRITE) {
         throw new waAPIException('access_denied', 403);
     }
     $data = array_merge($data, array('blog_status' => $blog['status'], 'url' => '', 'text' => '', 'status' => blogPostModel::STATUS_PUBLISHED));
     $post_model = new blogPostModel();
     $options = array();
     if (waRequest::post('transliterate', null)) {
         $options['transliterate'] = true;
     }
     $messages = $post_model->validate($data, array('transliterate' => true));
     if ($messages) {
         throw new waAPIException('invalid_param', 'Validate messages: ' . implode("\n", $messages), 404);
     }
     $id = $post_model->updateItem(null, $data);
     $_GET['id'] = $id;
     $method = new blogPostGetInfoMethod();
     $this->response = $method->getResponse(true);
 }
Ejemplo n.º 3
0
 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 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 {
         }
     }
 }
Ejemplo n.º 5
0
 public function execute()
 {
     $id = $this->get('id', true);
     $blog_model = new blogBlogModel();
     $blogs = $blog_model->getAvailable(wa()->getUser());
     if (isset($blogs[$id])) {
         $this->response = $blogs[$id];
     } else {
         throw new waAPIException('invalid_param', 'Blog not found', 404);
     }
 }
Ejemplo n.º 6
0
 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));
     }
 }
 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');
 }
Ejemplo n.º 8
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);
 }
Ejemplo n.º 9
0
 protected function getSettingsConfig()
 {
     $blogs = array();
     $blog_model = new blogBlogModel();
     $blogs[''] = _wp('All blogs');
     foreach ($blog_model->getAvailable(wa()->getUser()) as $b) {
         $blogs[$b['id']] = $b['name'];
     }
     $result = parent::getSettingsConfig();
     $result['blog_id']['options'] = $blogs;
     return $result;
 }
 public function execute()
 {
     if (!wa()->getUser()->isAdmin($this->getApp())) {
         $this->errors[] = _w('Access denied');
         return;
     }
     $blog_id = (int) waRequest::get('blog_id');
     $sort = (int) waRequest::get('sort');
     $blog_model = new blogBlogModel();
     $blog_model->sort($blog_id, $sort);
     $this->response = "ok";
     $this->getResponse()->addHeader('Content-type', 'application/json');
 }
 public function execute()
 {
     if ($ids = $this->getRequest()->post('id', null, waRequest::TYPE_ARRAY_INT)) {
         $post_model = new blogPostModel();
         $blog_model = new blogBlogModel();
         $blogs = $blog_model->getAvailable($this->getUser(), 'id');
         $options = array('id' => $ids, 'blog_id' => array_keys($blogs));
         $this->response['deleted'] = $post_model->deleteByField($options);
         $this->logAction('post_delete', implode(',', $ids));
     } else {
         $this->errors[] = 'empty request';
     }
 }
Ejemplo n.º 12
0
 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');
 }
 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));
     }
 }
 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);
     }
 }
Ejemplo n.º 15
0
 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);
         }
     }
     $post_model = new blogPostModel();
     $blog_model = new blogBlogModel();
     $blogs = $blog_model->getAvailable(wa()->getUser(), 'id');
     $post_model->deleteByField(array('id' => $id, 'blog_id' => array_keys($blogs)));
     $this->response = true;
 }
Ejemplo n.º 16
0
 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);
     }
 }
Ejemplo n.º 17
0
 public function execute()
 {
     $id = $this->get('id', true);
     if (!wa()->getUser()->getRights("blog.{$id}", true) < blogRightConfig::RIGHT_FULL) {
         throw new waAPIException('access_denied', 403);
     }
     $blog_model = new blogBlogModel();
     $blog = $blog_model->getById($id);
     if ($blog) {
         $data = waRequest::post();
         $blog_model->updateById($id, $data);
         $method = new blogBlogGetInfoMethod();
         $this->response = $method->getResponse(true);
     } else {
         throw new waAPIException('invalid_param', 'Blog not found', 404);
     }
 }
Ejemplo n.º 18
0
 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()
 {
     $routes = $this->getRoutes();
     $app_id = wa()->getApp();
     $blog_model = new blogBlogModel();
     $post_model = new blogPostModel();
     $page_model = new blogPageModel();
     $blogs = $blog_model->getAvailable(false, array('id', 'name', 'url'));
     $real_domain = $this->routing->getDomain(null, true, false);
     foreach ($routes as $route) {
         $lastmod = null;
         $this->routing->setRoute($route);
         $default_blog_id = isset($route['blog_url_type']) ? (int) $route['blog_url_type'] : 0;
         $default_blog_id = max(0, $default_blog_id);
         $extend_options = array('datetime' => true);
         $extend_data = array('blog' => $blogs);
         foreach ($blogs as $blog_id => $blog) {
             if (!$default_blog_id || $blog_id == $default_blog_id) {
                 $search_options = array('blog_id' => $blog_id);
                 $posts = $post_model->search($search_options, $extend_options, $extend_data)->fetchSearchAll('id,title,url,datetime,blog_id');
                 foreach ($posts as $post) {
                     $post['blog_url'] = $blog['url'];
                     $post_lastmod = strtotime($post['datetime']);
                     $lastmod = max($lastmod, $post_lastmod);
                     if (!empty($post['comment_datetime'])) {
                         $post_lastmod = max($post_lastmod, strtotime($post['comment_datetime']));
                     }
                     $this->addUrl($post['link'], $post_lastmod);
                 }
             }
         }
         // pages
         $main_url = wa()->getRouteUrl($app_id . "/frontend", array(), true, $real_domain);
         $domain = $this->routing->getDomain(null, true);
         $sql = "SELECT full_url, url, create_datetime, update_datetime FROM " . $page_model->getTableName() . '
                 WHERE status = 1 AND domain = s:domain AND route = s:route';
         $pages = $page_model->query($sql, array('domain' => $domain, 'route' => $route['url']))->fetchAll();
         foreach ($pages as $p) {
             $this->addUrl($main_url . $p['full_url'], $p['update_datetime'] ? $p['update_datetime'] : $p['create_datetime'], self::CHANGE_MONTHLY, 0.6);
         }
         $this->addUrl(wa()->getRouteUrl($app_id . "/frontend", array(), true, $real_domain), $lastmod, self::CHANGE_DAILY, 1.0);
     }
 }
Ejemplo n.º 20
0
 public function init()
 {
     $this->addItem(self::RIGHT_ADD_BLOG, _w('Can create new blogs'), 'checkbox');
     $this->addItem(self::RIGHT_PAGES, _ws('Can edit pages'), 'checkbox');
     $this->addItem(self::RIGHT_DESIGN, _ws('Can edit design'), 'checkbox');
     $blog_model = new blogBlogModel();
     $blogs = $blog_model->getAll();
     $items = array();
     foreach ($blogs as $blog) {
         $items[$blog['id']] = $blog['name'];
     }
     $options = array(self::RIGHT_NONE => _w('No access'), self::RIGHT_READ => _w('Read only'), self::RIGHT_READ_WRITE => _w('Read and publish new posts'), self::RIGHT_FULL => _w('Full access'));
     $control = array('items' => $items, 'position' => 'right', 'options' => $options);
     $this->addItem('blog', _w('Blog'), 'selectlist', $control);
     /**
      * @event rights.config
      * @param waRightConfig $this Rights setup object
      * @return void
      */
     wa()->event('rights.config', $this);
 }
 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());
     }
 }
Ejemplo n.º 22
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());
}
Ejemplo n.º 23
0
 /**
  * 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;
 }
 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;
 }
Ejemplo n.º 25
0
 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);
 }
Ejemplo n.º 26
0
 public function validate(&$data)
 {
     $messages = array();
     $new_route_setup = waRequest::post('new_route_setup', 0, waRequest::TYPE_INT);
     $route_enabled = waRequest::post('route_enabled', 0, waRequest::TYPE_INT);
     $no_settlement = $new_route_setup && !$route_enabled;
     if ($data['status'] != blogBlogModel::STATUS_PRIVATE && !$no_settlement) {
         if (isset($data['id'])) {
             $url_validator = new blogSlugValidator(array('id' => $data['id']));
         } else {
             $url_validator = new blogSlugValidator();
         }
         $url_validator->setSubject(blogSlugValidator::SUBJECT_BLOG);
         $name_validator = new waStringValidator(array('max_length' => 255, 'required' => true), array('required' => _w('Blog name must not be empty')));
         if (!$url_validator->isValid($data['url'])) {
             $messages['blog_url'] = current($url_validator->getErrors());
         }
         if (!$name_validator->isValid($data['name'])) {
             $messages['blog_name'] = current($name_validator->getErrors());
         }
     } else {
         $blog_model = new blogBlogModel();
         if (!$data['id']) {
             $data['url'] = $blog_model->genUniqueUrl($data['name']);
         } else {
             $url = $blog_model->select('url')->where('id = i:id', array('id' => $data['id']))->fetchField('url');
             $data['url'] = $url ? $url : $blog_model->genUniqueUrl($data['name']);
         }
     }
     /**
      * @event blog_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('blog_validate', $data);
     if (empty($messages['plugin'])) {
         unset($messages['plugin']);
     }
     return $messages;
 }
Ejemplo n.º 27
0
 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);
     }
 }
 public function validate(&$data)
 {
     $messages = array();
     $no_settlement = waRequest::post('no_settlement', 0, waRequest::TYPE_INT);
     if ($data['status'] != blogBlogModel::STATUS_PRIVATE && !$no_settlement) {
         if (isset($data['id'])) {
             $url_validator = new blogSlugValidator(array('id' => $data['id']));
         } else {
             $url_validator = new blogSlugValidator();
         }
         $url_validator->setSubject(blogSlugValidator::SUBJECT_BLOG);
         $name_validator = new waStringValidator(array('max_length' => 255, 'required' => true), array('required' => _w('Blog name must not be empty')));
         if (!$url_validator->isValid($data['url'])) {
             $messages['blog_url'] = current($url_validator->getErrors());
         }
         if (!$name_validator->isValid($data['name'])) {
             $messages['blog_name'] = current($name_validator->getErrors());
         }
     } else {
         $blog_model = new blogBlogModel();
         if (!$data['id']) {
             $data['url'] = $blog_model->genUniqueUrl($data['name']);
         } else {
             $url = $blog_model->select('url')->where('id = i:id', array('id' => $data['id']))->fetchField('url');
             $data['url'] = $url ? $url : $blog_model->genUniqueUrl($data['name']);
         }
     }
     return $messages;
 }
Ejemplo n.º 29
0
 /**
  *
  * @see blogBlog::getAvailable
  * @param bool $extended
  * @param int $blog_id
  * @return array
  */
 public static function getAvailable($extended = true, $blog_id = null)
 {
     static $blogs_cache = array();
     $extended = intval($extended) ? true : false;
     $backend = wa()->getEnv() == 'backend' ? true : false;
     if (!isset($blogs_cache[$extended])) {
         $blog_model = new blogBlogModel();
         $blogs = $blog_model->getAvailable($backend, $extended ? 'name,icon,color,id,url,status' : 'name,id,url', null, $extended);
         foreach ($blogs as $id => &$blog) {
             if ($extended) {
                 $blog['class'] = $blog['color'];
                 if (strpos($blog['icon'], '.')) {
                     $blog['style'] = "background-image: url('{$blog['icon']}'); background-repeat: no-repeat;";
                 } else {
                     $blog['class'] .= ($blog['class'] ? ' ' : '') . 'icon16 ' . $blog['icon'];
                 }
             }
             $blog['value'] = $id;
             $blog['title'] = $blog['name'];
             unset($blog);
         }
         $blogs_cache[$extended] = $blogs;
     } else {
         $blogs = $blogs_cache[$extended];
     }
     return $blog_id ? isset($blogs[$blog_id]) ? array($blog_id => $blogs[$blog_id]) : array() : $blogs;
 }
 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);
 }