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() { $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() { $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); }