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 {
         }
     }
 }
Пример #2
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()
 {
     $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');
 }
 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);
     }
 }
 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));
     }
 }
Пример #6
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);
     }
 }
Пример #7
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);
     }
 }
Пример #8
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();
 }
Пример #9
0
 static function getUrl($post, $type = 'post')
 {
     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();
 }
 /**
  * Prepare for saving posted post and return it
  *
  * @return array prepared post
  *
  */
 private function getPreparedPost()
 {
     $post = array('id' => waRequest::post('post_id', null, waRequest::TYPE_INT), 'title' => substr(waRequest::post('title', '', waRequest::TYPE_STRING_TRIM), 0, 255), 'text' => waRequest::post('text'), 'blog_id' => waRequest::post('blog_id'), 'contact_id' => waRequest::post('contact_id'), 'datetime' => waRequest::post('datetime'), 'url' => waRequest::post('url', '', waRequest::TYPE_STRING_TRIM), 'draft' => waRequest::post('draft'), 'comments_allowed' => max(0, min(1, waRequest::post('comments_allowed', 0, waRequest::TYPE_INT))), 'public' => waRequest::post('public'), 'schedule_datetime' => waRequest::post('schedule_datetime'));
     $this->inline = waRequest::post('inline', false);
     if (waRequest::post('scheduled') && !empty($post['schedule_datetime'])) {
         $post['datetime'] = $post['schedule_datetime'];
     }
     if (!is_null($post['datetime'])) {
         $post['datetime'] = (array) $post['datetime'];
         if (count($post['datetime']) == 3) {
             $post['datetime'][1] = (int) $post['datetime'][1];
             $post['datetime'][2] = (int) $post['datetime'][2];
             $date_time = $post['datetime'][0] . ' ' . $post['datetime'][1] . ':' . $post['datetime'][2];
         } else {
             $date_time = implode(' ', $post['datetime']);
         }
         $post['datetime'] = $date_time;
     }
     if (waRequest::post('draft')) {
         $post['status'] = blogPostModel::STATUS_DRAFT;
         $this->operation = self::OPERATION_SAVE_DRAFT;
     } else {
         if (waRequest::post('deadline')) {
             if ($post['datetime']) {
                 $post['status'] = blogPostModel::STATUS_DEADLINE;
                 $this->operation = self::OPERATION_SET_DEADLINE;
             } else {
                 $post['status'] = blogPostModel::STATUS_DRAFT;
                 $this->operation = self::OPERATION_SAVE_DRAFT;
             }
         } else {
             if (waRequest::post('scheduled')) {
                 $post['status'] = blogPostModel::STATUS_SCHEDULED;
             } else {
                 if (waRequest::post('published')) {
                     $post['status'] = blogPostModel::STATUS_PUBLISHED;
                     $this->operation = self::OPERATION_PUBLISH;
                 } else {
                     if (waRequest::post('unpublish')) {
                         $post['status'] = blogPostModel::STATUS_DRAFT;
                         $this->operation = self::OPERATION_UNPUBLISH;
                     } else {
                         if ($post['id'] && waRequest::issetPost('delete')) {
                             $this->operation = self::OPERATION_DELETE;
                         } else {
                             if (waRequest::issetPost("schedule_cancel")) {
                                 $this->operation = self::OPERATION_CANCEL_SCHEDULE;
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!isset($post['status'])) {
         if ($post['id']) {
             $post['status'] = $this->post_model->select('status')->where('id = i:id', array('id' => $post['id']))->fetchField('status');
         } else {
             $post['status'] = blogPostModel::STATUS_DRAFT;
         }
     }
     $blog_model = new blogBlogModel();
     $blog = $blog_model->getById($post['blog_id']);
     $post['blog_status'] = $blog['status'];
     $post['plugin'] = (array) waRequest::post('plugin', null);
     foreach ($post['plugin'] as $k => &$plugin_data) {
         if (!is_array($plugin_data)) {
             $plugin_data = trim($plugin_data);
         }
     }
     return $post;
 }