Esempio n. 1
0
 /**
  * Get a list of posts in this thread
  *
  * @param   string  $rtrn    What data to return?
  * @param   array   $filters Filters to apply to data fetch
  * @param   boolean $clear   Clear cached data?
  * @return  mixed
  */
 public function posts($rtrn = 'list', $filters = array(), $clear = false)
 {
     $filters['thread'] = isset($filters['thread']) ? $filters['thread'] : $this->get('thread');
     $filters['state'] = isset($filters['state']) ? $filters['state'] : array(self::APP_STATE_PUBLISHED, self::APP_STATE_FLAGGED);
     switch (strtolower($rtrn)) {
         case 'count':
             if (!isset($this->_cache['posts_count']) || $clear) {
                 $this->_cache['posts_count'] = $this->_tbl->getCount($filters);
             }
             return $this->_cache['posts_count'];
             break;
         case 'first':
             return $this->posts('list', $filters)->first();
             break;
         case 'tree':
             if (!$this->_cache['tree'] instanceof ItemList || $clear) {
                 if ($rows = $this->_tbl->getTree($filters['thread'])) {
                     $children = array(0 => array());
                     $levellimit = $filters['limit'] == 0 ? 500 : $filters['limit'];
                     foreach ($rows as $row) {
                         $v = new Post($row);
                         $v->set('category', $this->get('category'));
                         $v->set('section', $this->get('section'));
                         $pt = $v->get('parent');
                         $list = @$children[$pt] ? $children[$pt] : array();
                         array_push($list, $v);
                         $children[$pt] = $list;
                     }
                     $results = $this->_treeRecurse($children[$this->get('parent')], $children);
                 }
                 $this->_cache['tree'] = new ItemList($results);
             }
             return $this->_cache['tree'];
             break;
         case 'list':
         case 'results':
         default:
             if (!$this->_cache['posts'] instanceof ItemList || $clear) {
                 if ($results = $this->_tbl->getRecords($filters)) {
                     foreach ($results as $key => $result) {
                         $results[$key] = new Post($result);
                         $results[$key]->set('category', $this->get('category'));
                         $results[$key]->set('section', $this->get('section'));
                     }
                 } else {
                     $results = array();
                 }
                 $this->_cache['posts'] = new ItemList($results);
             }
             return $this->_cache['posts'];
             break;
     }
 }
Esempio n. 2
0
 /**
  * Create an item entry for a forum thread
  *
  * @param   integer  $id  Optional ID to use
  * @return  boolean
  */
 public function make($id = null)
 {
     if ($this->exists()) {
         return true;
     }
     $id = $id ?: Request::getInt('thread', 0);
     $this->_tbl->loadType($id, $this->_type);
     if ($this->exists()) {
         return true;
     }
     include_once PATH_CORE . DS . 'components' . DS . 'com_forum' . DS . 'models' . DS . 'post.php';
     $thread = new Post($id);
     if (!$thread->exists()) {
         $this->setError(Lang::txt('Forum thread not found.'));
         return false;
     }
     $this->set('type', $this->_type)->set('object_id', $thread->get('id'))->set('created', $thread->get('created'))->set('created_by', $thread->get('created_by'))->set('title', $thread->get('title'))->set('description', $thread->content('clean', 200))->set('url', $thread->link());
     if (!$this->store()) {
         return false;
     }
     return true;
 }
Esempio n. 3
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');
 }