Ejemplo n.º 1
0
 public function execute()
 {
     $is_admin = $this->getUser()->isAdmin($this->getApp());
     $storage = $this->getStorage();
     if (waRequest::post('save')) {
         $this->save();
         $save_id = rand(10000, 99999);
         $storage->write('blog_setttings_save_id', $save_id);
         $this->redirect(array('module' => 'settings', 'save' => $save_id));
     }
     if ($is_admin) {
         $e_g = blogHelper::getAvailable();
         reset($e_g);
         $user = $this->getUser();
         $this->view->assign('e_g', current($e_g));
         $this->view->assign('user_email', $user->get('email', 'default'));
         // Checking if have saved now
         $save_id = $storage->read('blog_setttings_save_id');
     }
     // Checking if have saved now
     $save_id = $storage->read('blog_setttings_save_id');
     if ($save_id && $save_id == waRequest::get('save', 0)) {
         $storage->del('blog_setttings_save_id');
         $this->view->assign('saved', 1);
     }
     $this->getResponse()->setTitle(_w('Blog settings page'));
     $this->setLayout(new blogDefaultLayout());
     $this->view->assign('user_settings', $res = $this->getUserSettings());
     if ($is_admin) {
         $this->view->assign('backend_settings', $this->getFrontendSettings());
         // to mislead potential foes, apparently...
         $this->view->assign('routing_settings_url', blogHelper::getRouteSettingsUrl());
         $this->view->assign('photos_app_available', blogPhotosBridge::isAvailable());
     }
     $app_settings_model = new waAppSettingsModel();
     $this->view->assign('last_reminder_cron_time', $app_settings_model->get('blog', 'last_reminder_cron_time'));
     $this->view->assign('cron_command', 'php ' . wa()->getConfig()->getRootPath() . '/cli.php blog reminder');
 }
 /**
  * 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'), 'meta_title' => waRequest::post('meta_title', null, waRequest::TYPE_STRING_TRIM), 'meta_keywords' => waRequest::post('meta_keywords', null, waRequest::TYPE_STRING_TRIM), 'meta_description' => waRequest::post('meta_description', null, waRequest::TYPE_STRING_TRIM), 'album_id' => waRequest::post('album_id', null, waRequest::TYPE_INT), 'album_link_type' => waRequest::post('album_link_type', null, waRequest::TYPE_STRING_TRIM));
     if ($post['album_id'] && blogPhotosBridge::isAvailable()) {
         wa('photos');
         $album_model = new photosAlbumModel();
         $album = $album_model->getById($post['album_id']);
         if (!$album) {
             $album = $post['album_id'] = null;
         } else {
             if ($album['status'] <= 0) {
                 $post['album_link_type'] = null;
             }
         }
     } else {
         $post['album_id'] = null;
     }
     if (!$post['album_id']) {
         $post['album_id'] = $post['album_link_type'] = null;
     } else {
         if ($post['album_link_type'] != 'photos') {
             $post['album_link_type'] = 'blog';
         }
     }
     $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;
 }
Ejemplo n.º 3
0
 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);
 }