示例#1
0
 /**
  * Deletes one or more records and redirects to listing
  *
  * @return  void
  */
 public function removeTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     // Do we have any IDs?
     if (count($ids) > 0) {
         // Loop through each ID
         foreach ($ids as $id) {
             $id = intval($id);
             $section = new Tables\Section($this->database);
             $section->load($id);
             // Get the categories in this section
             $cModel = new Tables\Category($this->database);
             $categories = $cModel->getRecords(array('section_id' => $section->id));
             // Loop through each category
             foreach ($categories as $category) {
                 // Remove the posts in this category
                 $tModel = new Tables\Post($this->database);
                 if (!$tModel->deleteByCategory($category->id)) {
                     throw new Exception($tModel->getError(), 500);
                 }
                 // Remove this category
                 if (!$cModel->delete($category->id)) {
                     throw new Exception($cModel->getError(), 500);
                 }
             }
             // Remove this section
             if (!$section->delete()) {
                 throw new Exception($section->getError(), 500);
             }
         }
     }
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&section_id=' . Request::getInt('section_id', 0), false), Lang::txt('COM_FORUM_SECTIONS_DELETED'));
 }
示例#2
0
 /**
  * Get the most recent post
  *
  * @return  object
  */
 public function lastActivity()
 {
     if (!$this->_cache['last'] instanceof Post) {
         $post = new Tables\Post($this->_db);
         if (!($last = $post->getLastActivity($this->get('scope_id'), $this->get('scope'), $this->get('id')))) {
             $last = 0;
         }
         $this->_cache['last'] = new Post($last);
     }
     return $this->_cache['last'];
 }
示例#3
0
 /**
  * Deletes one or more records and redirects to listing
  *
  * @return  void
  */
 public function removeTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $section = Request::getInt('section_id', 0);
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     // Do we have any IDs?
     if (count($ids) > 0) {
         // Instantiate some objects
         $category = new Category($this->database);
         // Loop through each ID
         foreach ($ids as $id) {
             $id = intval($id);
             // Remove the posts in this category
             $tModel = new Post($this->database);
             if (!$tModel->deleteByCategory($id)) {
                 throw new Exception($tModel->getError(), 500);
             }
             // Remove this category
             if (!$category->delete($id)) {
                 throw new Exception($category->getError(), 500);
             }
         }
     }
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&section_id=' . $section, false), Lang::txt('COM_FORUM_CATEGORIES_DELETED'));
 }
示例#4
0
 /**
  * Delete a category and all associated content
  *
  * @param   integer  $oid  Object ID (primary key)
  * @return  boolean  True if successful otherwise returns and error message
  */
 public function delete($oid = null)
 {
     $k = $this->_tbl_key;
     if ($oid) {
         $this->{$k} = intval($oid);
     }
     include_once __DIR__ . DS . 'post.php';
     $post = new Post($this->_db);
     if (!$post->deleteByCategory($this->{$k})) {
         $this->setError($post->getErrorMsg());
         return false;
     }
     return parent::delete();
 }
示例#5
0
 /**
  * Serves up files only after passing access checks
  *
  * @return  void
  */
 public function downloadTask()
 {
     // Incoming
     $section = Request::getVar('section', '');
     $category = Request::getVar('category', '');
     $thread = Request::getInt('thread', 0);
     $post = Request::getInt('post', 0);
     $file = Request::getVar('file', '');
     // Ensure we have a database object
     if (!$this->database) {
         throw new Exception(Lang::txt('COM_FORUM_DATABASE_NOT_FOUND'), 500);
     }
     // Instantiate an attachment object
     $attach = new Tables\Attachment($this->database);
     if (!$post) {
         $attach->loadByThread($thread, $file);
     } else {
         $attach->loadByPost($post);
     }
     if (!$attach->filename) {
         throw new Exception(Lang::txt('COM_FORUM_FILE_NOT_FOUND'), 404);
     }
     $file = $attach->filename;
     // Get the parent ticket the file is attached to
     $row = new Tables\Post($this->database);
     $row->load($attach->post_id);
     if (!$row->id) {
         throw new Exception(Lang::txt('COM_FORUM_POST_NOT_FOUND'), 404);
     }
     // Check logged in status
     if ($row->access > 0 && User::isGuest()) {
         $return = base64_encode(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&section=' . $section . '&category=' . $category . '&thread=' . $thread . '&post=' . $post . '&file=' . $file));
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . $return));
         return;
     }
     // Load ACL
     $this->_authorize('thread', $row->id);
     // Ensure the user is authorized to view this file
     if (!$this->config->get('access-view-thread')) {
         throw new Exception(Lang::txt('COM_FORUM_NOT_AUTH_FILE'), 403);
     }
     // Ensure we have a path
     if (empty($file)) {
         throw new Exception(Lang::txt('COM_FORUM_FILE_NOT_FOUND'), 404);
     }
     // Get the configured upload path
     $basePath = DS . trim($this->config->get('webpath', '/site/forum'), DS) . DS . $attach->parent . DS . $attach->post_id;
     // Does the path start with a slash?
     if (substr($file, 0, 1) != DS) {
         $file = DS . $file;
         // Does the beginning of the $attachment->filename match the config path?
         if (substr($file, 0, strlen($basePath)) == $basePath) {
             // Yes - this means the full path got saved at some point
         } else {
             // No - append it
             $file = $basePath . $file;
         }
     }
     // Add PATH_CORE
     $filename = PATH_APP . $file;
     // Ensure the file exist
     if (!file_exists($filename)) {
         throw new Exception(Lang::txt('COM_FORUM_FILE_NOT_FOUND') . ' ' . $filename, 404);
     }
     // Initiate a new content server and serve up the file
     $server = new \Hubzero\Content\Server();
     $server->filename($filename);
     $server->disposition('inline');
     $server->acceptranges(false);
     // @TODO fix byte range support
     if (!$server->serve()) {
         // Should only get here on error
         throw new Exception(Lang::txt('COM_FORUM_SERVER_ERROR'), 500);
     } else {
         exit;
     }
     return;
 }
示例#6
0
 /**
  * Sets the state of one or more entries
  *
  * @return  void
  */
 public function accessTask()
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     // Incoming
     $category = Request::getInt('category_id', 0);
     $state = Request::getInt('access', 0);
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     // Check for an ID
     if (count($ids) < 1) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&category_id=' . $category, false), Lang::txt('COM_FORUM_SELECT_ENTRY_TO_CHANGE_ACCESS'), 'error');
         return;
     }
     foreach ($ids as $id) {
         // Update record(s)
         $row = new Post($this->database);
         $row->load(intval($id));
         $row->access = $state;
         if (!$row->store()) {
             throw new Exception($row->getError(), 500);
         }
     }
     // set message
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&category_id=' . $category, false), Lang::txt('COM_FORUM_ITEMS_ACCESS_CHANGED', count($ids)));
 }
示例#7
0
 /**
  * Store changes to this entry
  *
  * @param     boolean $check Perform data validation check?
  * @return    boolean False if error, True on success
  */
 public function store($check = true)
 {
     // Get the entry before changes were made
     $old = new self($this->get('id'));
     // Store entry
     if (!parent::store($check)) {
         return false;
     }
     // If the section is marked as "deleted" and it wasn't already marked as such
     if ($this->get('state') == self::APP_STATE_DELETED && $old->get('state') != self::APP_STATE_DELETED) {
         // Collect a list of category IDs
         $cats = array();
         foreach ($this->categories('list', array('state' => -1)) as $category) {
             $cats[] = $category->get('id');
         }
         if (count($cats) > 0) {
             // Set all the threads/posts in all the categories to "deleted"
             $post = new Tables\Post($this->_db);
             if (!$post->setStateByCategory($cats, self::APP_STATE_DELETED)) {
                 $this->setError($post->getError());
             }
             // Set all the categories to "deleted"
             $cModel = new Tables\Category($this->_db);
             if (!$cModel->setStateBySection($this->get('id'), self::APP_STATE_DELETED)) {
                 $this->setError($cModel->getError());
             }
         }
     }
     return true;
 }
示例#8
0
 /**
  * Delete a category
  *
  * @return     void
  */
 public function deleteTask()
 {
     // Is the user logged in?
     if (User::isGuest()) {
         App::redirect(Route::url('index.php?option=com_users&view=login&return=' . base64_encode(Route::url('index.php?option=' . $this->_option, false, true))), Lang::txt('COM_FORUM_LOGIN_NOTICE'), 'warning');
         return;
     }
     // Load the section
     $section = $this->model->section(Request::getVar('section', ''));
     // Load the category
     $category = $section->category(Request::getVar('category', ''));
     // Make the sure the category exist
     if (!$category->exists()) {
         App::redirect(Route::url('index.php?option=' . $this->_option), Lang::txt('COM_FORUM_MISSING_ID'), 'error');
         return;
     }
     // Check if user is authorized to delete entries
     $this->_authorize('category', $category->get('id'));
     if (!$this->config->get('access-delete-category')) {
         App::redirect(Route::url('index.php?option=' . $this->_option), Lang::txt('COM_FORUM_NOT_AUTHORIZED'), 'warning');
         return;
     }
     // Set all the threads/posts in all the categories to "deleted"
     $tModel = new Tables\Post($this->database);
     if (!$tModel->setStateByCategory($category->get('id'), 2)) {
         $this->setError($tModel->getError());
     }
     // Set the category to "deleted"
     $category->set('state', 2);
     /* 0 = unpublished, 1 = published, 2 = deleted */
     if (!$category->store()) {
         App::redirect(Route::url('index.php?option=' . $this->_option), $category->getError(), 'error');
         return;
     }
     // Redirect to main listing
     App::redirect(Route::url('index.php?option=' . $this->_option), Lang::txt('COM_FORUM_CATEGORY_DELETED'), 'message');
 }