Example #1
0
 /**
  * Set and get a specific thread
  *
  * @param   mixed  $id  ID (integer) or alias (string)
  * @return  object
  */
 public function thread($id = null)
 {
     if (!isset($this->_cache['thread']) || $id !== null && (int) $this->_cache['thread']->get('id') != $id) {
         $this->_cache['thread'] = null;
         if (isset($this->_cache['threads']) && $this->_cache['threads'] instanceof ItemList) {
             foreach ($this->_cache['threads'] as $key => $thread) {
                 if ((int) $thread->get('id') == $id) {
                     $this->_cache['thread'] = $thread;
                     break;
                 }
             }
         }
         if (!$this->_cache['thread']) {
             $this->_cache['thread'] = Thread::getInstance($id);
         }
         if (!$this->_cache['thread']->exists()) {
             $this->_cache['thread']->set('scope', $this->get('scope'));
             $this->_cache['thread']->set('scope_id', $this->get('scope_id'));
         }
     }
     return $this->_cache['thread'];
 }
Example #2
0
 /**
  * Save an entry
  *
  * @return     void
  */
 public function saveTask()
 {
     if (User::isGuest()) {
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode(Route::url('index.php?option=' . $this->_option))));
         return;
     }
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $section = Request::getVar('section', '');
     $fields = Request::getVar('fields', array(), 'post', 'none', 2);
     $fields = array_map('trim', $fields);
     $assetType = 'thread';
     if ($fields['parent']) {
         $assetType = 'post';
     }
     if ($fields['id']) {
         $old = new Post(intval($fields['id']));
         if ($old->get('created_by') == User::get('id')) {
             $this->config->set('access-edit-' . $assetType, true);
         }
     }
     $this->_authorize($assetType, intval($fields['id']));
     if (!$this->config->get('access-edit-' . $assetType) && !$this->config->get('access-create-' . $assetType)) {
         App::redirect(Route::url('index.php?option=' . $this->_option));
         return;
     }
     $fields['sticky'] = isset($fields['sticky']) ? $fields['sticky'] : 0;
     $fields['closed'] = isset($fields['closed']) ? $fields['closed'] : 0;
     $fields['anonymous'] = isset($fields['anonymous']) ? $fields['anonymous'] : 0;
     // Bind data
     $model = new Post($fields['id']);
     if ($model->get('parent')) {
         $fields['thread'] = isset($fields['thread']) ? $fields['thread'] : $model->get('parent');
         $thread = new Thread($fields['thread']);
         if (!$thread->exists() || $thread->get('closed')) {
             Notify::error(Lang::txt('COM_FORUM_ERROR_THREAD_CLOSED'), 'forum');
             $this->editTask($model);
             return;
         }
     }
     if (!$model->bind($fields)) {
         Notify::error($model->getError(), 'forum');
         $this->editTask($model);
         return;
     }
     // Store new content
     if (!$model->store(true)) {
         Notify::error($model->getError(), 'forum');
         $this->editTask($model);
         return;
     }
     $parent = $model->get('thread', $model->get('id'));
     // Upload files
     $this->uploadTask($parent, $model->get('id'));
     // Save tags
     $model->tag(Request::getVar('tags', '', 'post'), User::get('id'));
     // Determine message
     if (!$fields['id']) {
         if (!$fields['parent']) {
             $message = Lang::txt('COM_FORUM_THREAD_STARTED');
         } else {
             $message = Lang::txt('COM_FORUM_POST_ADDED');
         }
     } else {
         $message = $model->get('modified_by') ? Lang::txt('COM_FORUM_POST_EDITED') : Lang::txt('COM_FORUM_POST_ADDED');
     }
     $category = new Category($model->get('category_id'));
     // Set the redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&section=' . $section . '&category=' . $category->get('alias') . '&thread=' . $parent . '#c' . $model->get('id')), $message, 'message');
 }