Beispiel #1
0
 /**
  * Download a file
  *
  * @return  void
  */
 public function downloadTask()
 {
     $file = Request::getVar('file', '');
     $item = Request::getInt('post', 0);
     $size = Request::getWord('size', '');
     $post = Post::getInstance($item);
     // Instantiate an attachment object
     $asset = Asset::getInstance($file, $post->get('item_id'));
     // Ensure record exist
     if (!$asset->get('id') || $post->item()->get('state') == 2) {
         throw new Exception(Lang::txt('COM_COLLECTIONS_FILE_NOT_FOUND'), 404);
     }
     // Check authorization
     if ($post->collection()->get('access') == 4 && User::isGuest()) {
         throw new Exception(Lang::txt('COM_COLLECTIONS_ERROR_ACCESS_DENIED_TO_FILE'), 403);
     }
     // Check authorization
     if (!$post->collection()->canAccess(User::get('id'))) {
         throw new Exception(Lang::txt('COM_COLLECTIONS_ERROR_ACCESS_DENIED_TO_FILE'), 403);
     }
     // Ensure we have a path
     if (!$asset->get('filename')) {
         throw new Exception(Lang::txt('COM_COLLECTIONS_FILE_NOT_FOUND'), 404);
     }
     $file = $asset->file($size);
     // Get the configured upload path
     $filename = $asset->filespace() . DS . $asset->get('item_id') . DS . ltrim($file, DS);
     // Ensure the file exist
     if (!file_exists($filename)) {
         throw new Exception(Lang::txt('COM_COLLECTIONS_FILE_NOT_FOUND') . ' ' . $filename, 404);
     }
     $ext = strtolower(Filesystem::extension($filename));
     // Initiate a new content server and serve up the file
     $server = new Server();
     $server->filename($filename);
     $server->disposition('attachment');
     if (in_array($ext, array('jpg', 'jpeg', 'jpe', 'png', 'gif'))) {
         $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_COLLECTIONS_SERVER_ERROR'), 500);
     } else {
         exit;
     }
 }
Beispiel #2
0
 /**
  * Vote for an item
  *
  * @return     void
  */
 private function _vote()
 {
     // Incoming
     $id = Request::getInt('post', 0);
     // Get the post model
     $post = \Components\Collections\Models\Post::getInstance($id);
     // Record the vote
     if (!$post->item()->vote()) {
         $this->setError($post->item()->getError());
     }
     // Display updated item stats if called via AJAX
     $no_html = Request::getInt('no_html', 0);
     if ($no_html) {
         echo Lang::txt('PLG_GROUPS_COLLECTIONS_POST_LIKES', $post->item()->get('positive'));
         exit;
     }
     // Get the collection model
     $collection = $this->model->collection($post->get('collection_id'));
     // Display the main listing
     App::redirect(Route::url('index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=' . $this->_name . '&scope=' . $collection->get('alias')));
 }
Beispiel #3
0
 /**
  * Vote for an item
  *
  * @return  void
  */
 private function _vote()
 {
     // Incoming
     $id = Request::getInt('post', 0);
     // Get the post model
     $post = \Components\Collections\Models\Post::getInstance($id);
     // Record the vote
     if (!$post->item()->vote()) {
         $this->setError($post->item()->getError());
     }
     // Display updated item stats if called via AJAX
     $no_html = Request::getInt('no_html', 0);
     if ($no_html) {
         echo Lang::txt('PLG_GROUPS_COLLECTIONS_POST_LIKES', $post->item()->get('positive'));
         exit;
     }
     // Get the collection model
     $collection = $this->model->collection($post->get('collection_id'));
     $url = Route::url('index.php?option=' . $this->option . '&cn=' . $this->group->get('cn') . '&active=' . $this->_name . '&scope=' . $collection->get('alias'));
     // Record the activity
     $recipients = array(['group', $this->group->get('gidNumber')], ['collection', $collection->get('id')], ['user', $post->item()->get('created_by')], ['user', User::get('id')]);
     Event::trigger('system.logActivity', ['activity' => ['action' => 'voted', 'scope' => 'collections.item', 'scope_id' => $post->item()->get('id'), 'description' => Lang::txt('PLG_GROUPS_COLLECTIONS_ACTIVITY_ITEM_VOTED', '<a href="' . $url . '">' . $collection->get('title') . '</a>'), 'details' => array('collection_id' => $collection->get('id'), 'post_id' => $post->get('id'), 'item_id' => $post->item()->get('id'))], 'recipients' => $recipients]);
     // Display the main listing
     App::redirect($url);
 }
Beispiel #4
0
 /**
  * Repost an entry
  *
  * @return     string
  */
 public function collectTask()
 {
     if (User::isGuest()) {
         return $this->loginTask();
     }
     $model = new Archive('member', User::get('id'));
     $no_html = Request::getInt('no_html', 0);
     // No collection ID selected so present repost form
     $repost = Request::getInt('repost', 0);
     if (!$repost) {
         // Incoming
         $post_id = Request::getInt('post', 0);
         $collection_id = Request::getVar('board', 0);
         if (!$post_id && $collection_id) {
             $collection = $model->collection($collection_id);
             $item_id = $collection->item()->get('id');
             $collection_id = $collection->item()->get('object_id');
         } else {
             $post = Post::getInstance($post_id);
             $item_id = $post->get('item_id');
         }
         $this->view->myboards = $model->mine();
         $this->view->groupboards = $model->mine('groups');
         //$this->view->name          = $this->_name;
         $this->view->option = $this->_option;
         $this->view->no_html = $no_html;
         $this->view->post_id = $post_id;
         $this->view->collection_id = $collection_id;
         $this->view->item_id = $item_id;
         $this->view->display();
         return;
     }
     Request::checkToken();
     $collection_title = Request::getVar('collection_title', '');
     $collection_id = Request::getInt('collection_id', 0);
     $item_id = Request::getInt('item_id', 0);
     if ($collection_title) {
         $collection = new Collection();
         $collection->set('title', $collection_title);
         $collection->set('object_id', User::get('id'));
         $collection->set('object_type', 'member');
         if (!$collection->store()) {
             $this->setError($collection->getError());
         }
         $collection_id = $collection->get('id');
     }
     // Try loading the current collection/post to see
     // if this has already been posted to the collection (i.e., no duplicates)
     $post = new Tables\Post($this->database);
     $post->loadByBoard($collection_id, $item_id);
     if (!$post->get('id')) {
         // No record found -- we're OK to add one
         $post->item_id = $item_id;
         $post->collection_id = $collection_id;
         $post->description = Request::getVar('description', '');
         if ($post->check()) {
             $this->setError($post->getError());
         }
         // Store new content
         if (!$post->store()) {
             $this->setError($post->getError());
         }
     }
     if ($this->getError()) {
         return $this->getError();
     }
     // Display updated item stats if called via AJAX
     if ($no_html) {
         echo Lang::txt('COM_COLLECTIONS_NUM_REPOSTS', $post->getCount(array('item_id' => $post->get('item_id'), 'original' => 0)));
         exit;
     }
     // Display the main listing
     App::redirect(Route::url('index.php?option=' . $this->option . '&controller=collections&task=posts'));
 }
 /**
  * Vote for an item
  *
  * @return     void
  */
 private function _vote()
 {
     // Incoming
     $id = Request::getInt('post', 0);
     // Get the post model
     $post = \Components\Collections\Models\Post::getInstance($id);
     // Record the vote
     if (!$post->item()->vote()) {
         $this->setError($post->item()->getError());
     }
     // Display updated item stats if called via AJAX
     $no_html = Request::getInt('no_html', 0);
     if ($no_html) {
         echo Lang::txt('%s likes', $post->item()->get('positive'));
         exit;
     }
     // Get the collection model
     $collection = $this->model->collection($post->get('collection_id'));
     // Display the main listing
     App::redirect(Route::url($this->member->getLink() . '&active=' . $this->_name . '&task=' . $collection->get('alias')));
 }
 /**
  * Set and get a specific post
  *
  * @param   integer $id Post ID
  * @return  object  CollectionsModelPost
  */
 public function post($id = null)
 {
     // If the current post isn't set
     //    OR the ID passed doesn't equal the current post's ID
     if (!isset($this->_post) || $id !== null && (int) $this->_post->get('id') != $id) {
         // Reset current offering
         $this->_post = null;
         // If the list of all posts is available ...
         if (isset($this->_posts) && $this->_posts instanceof ItemList) {
             // Find a post in the list that matches the ID passed
             foreach ($this->posts() as $key => $post) {
                 if ((int) $post->get('id') == $id) {
                     // Set current offering
                     $this->_post = $post;
                     break;
                 }
             }
         }
         if (!$this->_post) {
             $this->_post = Post::getInstance($id);
         }
     }
     // Return current post
     return $this->_post;
 }