public function execute() { $blog_id = wa()->getRequest()->param('blog_url_type'); if ($blog_id <= 0) { $blog_id = waRequest::request('blog_id', 0, 'int'); } $this->setLayout(new blogFrontendLayout()); // Get contact id and name as post author if (wa()->getUser()->get('is_user')) { $post_contact_id = wa()->getUser()->getId(); $post_contact_name = wa()->getUser()->getName(); } else { foreach (blogHelper::getAuthors($blog_id) as $post_contact_id => $post_contact_name) { break; } } // Prepare empty fake post data $post_model = new blogPostModel(); $post = $post_model->prepareView(array(array('id' => 0, 'blog_id' => $blog_id, 'contact_id' => $post_contact_id, 'contact_name' => $post_contact_name, 'datetime' => date('Y-m-d H:i:s'), 'title' => '%replace-with-real-post-title%', 'status' => 'published', 'text' => '<div class="replace-with-real-post-text"></div>' . $this->getScripts(), 'comments_allowed' => 0) + $post_model->getEmptyRow())); $post = array_merge($post[0], array('comments' => array(), 'comment_link' => '', 'link' => '')); $this->getResponse()->setTitle(_w('Preview')); $this->getResponse()->setMeta('keywords', ''); $this->getResponse()->setMeta('description', ''); $current_auth = wa()->getStorage()->read('auth_user_data'); $current_auth_source = $current_auth ? $current_auth['source'] : null; $this->view->assign(array('realtime_preview' => true, 'frontend_post' => array(), 'errors' => array(), 'form' => array(), 'show_comments' => false, 'request_captcha' => false, 'require_authorization' => false, 'theme' => waRequest::param('theme', 'default'), 'current_auth_source' => $current_auth_source, 'current_auth' => $current_auth, true, 'auth_adapters' => wa()->getAuthAdapters(), 'post' => $post)); }
public function 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); $post_model = new blogPostModel(); if ($post_id) { // edit post $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('status' => $date ? blogPostModel::STATUS_DEADLINE : blogPostModel::STATUS_DRAFT, '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(), 'blog_id' => $blog_id) + $post_model->getEmptyRow(); $title = _w('Adding new post'); } // Album tree $albums = array(); $photos_frontend_url = null; if (blogPhotosBridge::isAvailable()) { if ($post['album_link_type'] != 'photos') { $post['album_link_type'] = 'blog'; } wa('photos'); $album_model = new photosAlbumModel(); $albums = $album_model->getAlbums(); foreach ($albums as &$a) { if ($a['status'] == 1) { $a['frontend_link'] = photosFrontendAlbum::getLink($a); } else { $a['frontend_link'] = ''; } } unset($a); } // Frontend URLs for this post $album_link_type = $post['album_link_type']; $post['album_link_type'] = 'blog'; $all_links = blogPostModel::getPureUrls($post); $post['album_link_type'] = $album_link_type; $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('albums', $albums); $this->view->assign('no_settlements', !wa()->getRouteUrl('blog/')); $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); }