Пример #1
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()
 {
     $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);
     }
 }
Пример #3
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);
 }
Пример #4
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);
     }
 }
 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 ($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';
     }
 }
Пример #7
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;
 }
 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);
     }
 }
Пример #9
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->setLayout(new blogDefaultLayout());
     $blog_id = (int) waRequest::get('blog');
     $blog_model = new blogBlogModel();
     if ($blog_id && $this->getRights("blog.{$blog_id}") < blogRightConfig::RIGHT_FULL || !$blog_id && !$this->getRights(blogRightConfig::RIGHT_ADD_BLOG)) {
         throw new waRightsException(_w('Access denied'));
     }
     // save settings (POST)
     $settings = waRequest::post('settings');
     $draft_data = array();
     if ($settings) {
         $settings['status'] = isset($settings['status']) ? blogBlogModel::STATUS_PUBLIC : blogBlogModel::STATUS_PRIVATE;
         $settings['name'] = trim($settings['name']);
         $settings['icon'] = !empty($settings['icon_url']) ? $settings['icon_url'] : $settings['icon'];
         if (isset($settings['qty'])) {
             unset($settings['qty']);
         }
         if (isset($settings['sort'])) {
             unset($settings['sort']);
         }
         $settings['id'] = $blog_id;
         $validate_massages = $this->validate($settings);
         if (!$validate_massages) {
             //TODO handle settings
             if ($blog_id) {
                 $blog_model->updateById($blog_id, $settings);
                 $this->log('blog_modify');
             } else {
                 $settings['sort'] = (int) $blog_model->select('MAX(`sort`)')->fetchField() + 1;
                 $blog_id = $blog_model->insert($settings);
                 $this->getUser()->setRight($this->getApp(), "blog.{$blog_id}", blogRightConfig::RIGHT_FULL);
                 $this->log('blog_add');
             }
             // refresh qty post in blogs
             $blog_model->recalculate($blog_id);
             $this->redirect(array('blog' => $blog_id));
         } else {
             $this->view->assign('messages', $validate_massages);
             $draft_data = $settings;
         }
     }
     $colors = $this->getConfig()->getColors();
     $icons = $this->getConfig()->getIcons();
     if ($blog_id) {
         if (!($blog = $blog_model->search(array('blog' => $blog_id), array('link' => false))->fetchSearchItem())) {
             throw new waException(_w('Blog not found'), 404);
         }
         $blog['other_settlements'] = blogBlogModel::getPureSettlements($blog);
         $blog['settlement'] = array_shift($blog['other_settlements']);
     } else {
         $blog = array('id' => false, 'name' => '', 'status' => blogBlogModel::STATUS_PUBLIC, 'icon' => current($icons), 'color' => current($colors), 'url' => false);
         $blogs = array($blog);
         $blogs = $blog_model->prepareView($blogs, array('link' => false));
         $blog = array_shift($blogs);
         $blog['other_settlements'] = blogBlogModel::getPureSettlements($blog);
         $blog['settlement'] = array_shift($blog['other_settlements']);
     }
     $this->getResponse()->setTitle($blog_id ? trim(sprintf(_w('%s settings'), $blog['name'])) : _w('New blog'));
     $blog = !$draft_data ? $blog : array_merge($blog, $draft_data);
     $posts_total_count = 0;
     if ($blog_id) {
         $post_model = new blogPostModel();
         $posts_total_count = $post_model->countByField('blog_id', $blog_id);
         if ($posts_total_count) {
             $blog_model = new blogBlogModel();
             $blogs = $blog_model->getAvailable($this->getUser());
             $this->view->assign('blogs', $blogs);
         }
     }
     /**
      * Backend blog settings
      * UI hook allow extends backend blog settings page
      * @event backend_blog_edit
      * @param array[string]mixed $blog Blog data
      * @param array['id']int $blog['id'] Blog ID
      * @return array[string][string]string $return['%plugin_id%']['settings'] Blog extra settings html fields
      */
     $this->view->assign('backend_blog_edit', wa()->event('backend_blog_edit', $blog));
     $this->view->assign('posts_total_count', $posts_total_count);
     $this->view->assign('blog_id', $blog_id);
     $this->view->assign('blog', $blog);
     $this->view->assign('colors', $colors);
     $this->view->assign('icons', $icons);
 }
 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);
 }
Пример #12
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);
 }
Пример #13
0
 public function execute()
 {
     $this->getResponse()->setTitle(_w('Calendar'));
     $this->setLayout(new blogDefaultLayout());
     $blog_model = new blogBlogModel();
     $post_model = new blogPostModel();
     $blogs = $blog_model->getAvailable($this->getUser());
     $timezone = wa()->getUser()->getTimezone();
     // Y-m-d -> 2011-01-01
     $month_date = waRequest::get("month");
     if (!$month_date) {
         $month_date = waDateTime::date("Y-m", null, $timezone);
     } elseif ($month_date <= "1970" || $month_date >= "2033" || !strtotime($month_date)) {
         $this->redirect("?action=calendar");
     }
     $month_date = strtotime($month_date);
     $days_count = date("t", $month_date);
     // Numeric representation of the day of the week
     $first_day = date("w", $month_date);
     $last_day = date("w", strtotime(date("Y-m-{$days_count}", $month_date)));
     // first day is 'Sunday'
     if (waLocale::getFirstDay() == 7) {
         $first_day += 1;
         $last_day += 1;
     }
     $first_day = $first_day == 0 ? 6 : $first_day - 1;
     $last_day = $last_day == 0 ? 0 : 7 - $last_day;
     $date_start = strtotime("-" . $first_day . " days", $month_date);
     $date_end = strtotime("+" . ($days_count + $last_day) . " days", $month_date);
     $search_options = array();
     $search_options['datetime'] = array(date("Y-m-d", $date_start), date("Y-m-d", $date_end));
     $search_options['blog_id'] = array_keys($blogs);
     $search_options['status'] = false;
     if (!$this->getUser()->isAdmin($this->getApp())) {
         $search_options['contact_id'] = $this->getUser()->getId();
     }
     $extend_options = array('status' => true, 'user' => false, 'rights' => true);
     $posts = $post_model->search($search_options, $extend_options, array('blog' => $blogs))->fetchSearchAll(false);
     $current_date_start = $date_start;
     $days = array();
     do {
         $week = (int) date("W", $current_date_start);
         $day = (int) date("w", $current_date_start);
         if (waLocale::getFirstDay() == 7 && $day == 0) {
             $week = (int) date("W", strtotime("+1 week", $current_date_start));
         }
         if (!isset($days[$week])) {
             $days[$week] = array();
         }
         $days[$week][$day] = array("date" => array('day' => date("j", $current_date_start), 'month' => date("n", $current_date_start), 'date' => date("Y-m-d", $current_date_start)), "posts" => array());
         $current_date_start = strtotime("+1 days", $current_date_start);
     } while ($date_end > $current_date_start);
     foreach ($posts as $post) {
         #post.datetime cast to user timezone
         $week = (int) waDateTime::date("W", $post['datetime'], $timezone);
         $day = (int) waDateTime::date("w", $post['datetime'], $timezone);
         $days[$week][$day]["posts"][] = $post;
     }
     $now_date = waDateTime::date("Y-m-d", null, $timezone);
     $where = '';
     $search = false;
     if ($this->getUser()->isAdmin($this->getApp())) {
         $search = true;
     } else {
         $writeable = array();
         $full = array();
         foreach ($blogs as $id => $blog) {
             if ($blog['rights'] >= blogRightConfig::RIGHT_FULL) {
                 $full[] = $id;
             } elseif ($blog['rights'] >= blogRightConfig::RIGHT_READ_WRITE) {
                 $writeable[] = $id;
             }
         }
         $contact_where = array();
         if ($full) {
             $contact_where[] = "blog_id IN (" . implode(', ', $full) . ")";
         }
         if ($writeable) {
             $contact_where[] .= "contact_id = {$this->getUser()->getId()} AND blog_id IN (" . implode(', ', $writeable) . ")";
         }
         if ($contact_where) {
             $search = true;
             $where .= ' AND ( (' . implode(') OR (', $contact_where) . ' ) )';
         }
     }
     if ($search) {
         $posts_overdue_prev = $post_model->select("COUNT(*) AS 'cnt'")->where("status = '" . blogPostModel::STATUS_DEADLINE . "' AND datetime < '" . date("Y-m-d", $date_start) . "' " . $where)->limit(1)->fetchField('cnt');
         $posts_overdue_next = $post_model->select("COUNT(*) AS 'cnt'")->where("status = '" . blogPostModel::STATUS_DEADLINE . "' AND datetime > '" . date("Y-m-d", $date_end) . "' AND datetime < '" . $now_date . "'" . $where)->limit(1)->fetchField('cnt');
         $prev_overdue = $posts_overdue_prev ? true : false;
         $next_overdue = $posts_overdue_next ? true : false;
     } else {
         $prev_overdue = false;
         $next_overdue = false;
     }
     $months = array(1 => _ws('January'), 2 => _ws('February'), 3 => _ws('March'), 4 => _ws('April'), 5 => _ws('May'), 6 => _ws('June'), 7 => _ws('July'), 8 => _ws('August'), 9 => _ws('September'), 10 => _ws('October'), 11 => _ws('November'), 12 => _ws('December'));
     $current_year = date('Y', $month_date);
     $current_month = date('Y', $month_date);
     $boundaries = $post_model->select("MIN(datetime) as min, MAX(datetime) as max")->fetch();
     if ($boundaries) {
         $years = range(min(date('Y', strtotime($boundaries['min'])), $current_year), max(date('Y', strtotime($boundaries['max'])), $current_year, date('Y')));
     } else {
         $now_year = date('Y');
         $years = range(min($current_year, $now_year), max($current_year, $now_year));
     }
     $this->view->assign("prev_overdue", $prev_overdue);
     $this->view->assign("next_overdue", $next_overdue);
     $this->view->assign("allow_add", $search);
     $this->view->assign("days", $days);
     $this->view->assign("week_first_sunday", waLocale::getFirstDay() == 7);
     $this->view->assign("current_month", date("n", $month_date));
     $this->view->assign("current_year", date("Y", $month_date));
     $this->view->assign("prev_month", date("Y-m", strtotime("-1 month", $month_date)));
     $this->view->assign("next_month", date("Y-m", strtotime("+1 month", $month_date)));
     $this->view->assign("years", $years);
     $this->view->assign("months", $months);
     // cast to user timezone
     $this->view->assign("today", waDateTime::date("j", null, $timezone));
     $this->view->assign("today_month", waDateTime::date("n", null, $timezone));
     $this->nocache();
 }
 public function execute()
 {
     $post_id = waRequest::get('id', null, waRequest::TYPE_INT);
     $blog_model = new blogBlogModel();
     $blogs = $blog_model->getAvailable();
     if (!$blogs) {
         $this->setTemplate('BlogNotFound');
         return;
     }
     $blogs = $blog_model->prepareView($blogs);
     if ($post_id) {
         // edit post
         $post_model = new blogPostModel();
         $post = $post_model->getById($post_id);
         if (!$post) {
             throw new waException(_w('Post not found'), 404);
         }
         //check rights
         if (blogHelper::checkRights($post['blog_id']) < blogRightConfig::RIGHT_FULL && $post['contact_id'] != $this->getUser()->getId()) {
             throw new waRightsException(_w('Access denied'));
         }
         $post['datetime'] = $post['datetime'] >= 1971 ? $post['datetime'] : '';
         $blog_id = $post['blog_id'];
         $blog = $blogs[$blog_id];
         $title = trim(sprintf(_w('Editing post %s'), $post['title']));
     } else {
         // add post
         $date = waRequest::get('date', '');
         $blog = $this->getAllowedBlog($blogs, wa()->getStorage()->read('blog_last_id'));
         if (!$blog) {
             throw new waRightsException(_w('Access denied'));
         }
         $blog_id = $blog['id'];
         $post = array('title' => $this->getRequest()->post('title', '', waRequest::TYPE_STRING_TRIM), 'text' => $this->getRequest()->post('text', '', waRequest::TYPE_STRING_TRIM), 'continued_text' => null, 'categories' => array(), 'contact_id' => wa()->getUser()->getId(), 'url' => '', 'blog_id' => $blog_id, 'comments_allowed' => true);
         $post['id'] = '';
         $post['status'] = $date ? blogPostModel::STATUS_DEADLINE : blogPostModel::STATUS_DRAFT;
         $post['datetime'] = '';
         $post['meta_title'] = null;
         $post['meta_keywords'] = null;
         $post['meta_description'] = null;
         $title = _w('Adding new post');
     }
     $all_links = blogPostModel::getPureUrls($post);
     $post['other_links'] = $all_links;
     $post['link'] = array_shift($post['other_links']);
     $post['remaining_time'] = null;
     if ($post['status'] == blogPostModel::STATUS_SCHEDULED && $post['datetime']) {
         $post['remaining_time'] = $this->calculateRemainingTime($post['datetime']);
     }
     if ($blog['rights'] >= blogRightConfig::RIGHT_FULL) {
         $users = blogHelper::getAuthors($post['blog_id']);
     } else {
         $user = $this->getUser();
         $users = array($user->getId() => $user->getName());
     }
     // preview hash for all type of drafts
     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());
         $preview_hash = blogPostModel::getPreviewHash($options);
         $this->view->assign('preview_hash', base64_encode($preview_hash . $options['user_id']));
     }
     $this->view->assign('no_settlements', empty($all_links) ? true : false);
     $this->view->assign('params', $this->getPostParams($post['id']));
     $this->view->assign('blog', $blog);
     $this->view->assign('users', $users);
     $this->view->assign('blogs', $blogs);
     $allow_change_blog = 0;
     foreach ($blogs as $blog_item) {
         if ($blog_item['rights'] >= blogRightConfig::RIGHT_READ_WRITE) {
             ++$allow_change_blog;
         }
     }
     $this->view->assign('allow_change_blog', $allow_change_blog);
     $this->view->assign('post_id', $post_id);
     $this->view->assign('datetime_timezone', waDateTime::date("T", null, wa()->getUser()->getTimezone()));
     /**
      * Backend post edit page
      * UI hook allow extends post edit page
      * @event backend_post_edit
      * @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%]['sidebar'] Plugin sidebar html output
      * @return array[string][string]string $return[%plugin_id%]['toolbar'] Plugin toolbar html output
      * @return array[string][string]string $return[%plugin_id%]['editor_tab'] Plugin editor tab html output
      */
     $this->view->assign('backend_post_edit', wa()->event('backend_post_edit', $post, array('sidebar', 'toolbar', 'editor_tab')));
     $app_settings = new waAppSettingsModel();
     $show_comments = $app_settings->get($this->getApp(), 'show_comments', true);
     $this->view->assign('show_comments', $show_comments);
     $this->view->assign('post', $post);
     /**
      * @deprecated 
      * For backward compatibility reason
      */
     $this->view->assign('cron_schedule_time', waSystem::getSetting('cron_schedule', 0, 'blog'));
     $this->view->assign('last_schedule_cron_time', waSystem::getSetting('last_schedule_cron_time', 0, 'blog'));
     $this->view->assign('cron_command', 'php ' . wa()->getConfig()->getRootPath() . '/cli.php blog schedule');
     $this->setLayout(new blogDefaultLayout());
     $this->getResponse()->setTitle($title);
 }
Пример #15
0
 public function execute()
 {
     $blog_model = new blogBlogModel();
     $this->response = array_values($blog_model->getAvailable(wa()->getUser(), array(), null, array('new' => true, 'expire' => 1, 'link' => false)));
     $this->response['_element'] = 'blog';
 }