Esempio n. 1
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'));
 }
Esempio n. 2
0
 /**
  * Collect an item
  *
  * @return  void
  */
 public function collect()
 {
     $collectible = Request::getVar('collectible', array(), 'post', 'none', 2);
     if (!$this->item->make()) {
         $this->setError($this->item->getError());
     }
     // No collection ID selected so show form
     if (empty($collectible)) {
         if (!$this->model->collections(array('count' => true))) {
             $collection = $this->model->collection();
             $collection->setup(User::get('id'), 'member');
         }
         $this->myboards = $this->model->mine();
         if ($this->myboards) {
             foreach ($this->myboards as $board) {
                 $ids[] = $board->id;
             }
         }
         $this->groupboards = $this->model->mine('groups');
         if ($this->groupboards) {
             foreach ($this->groupboards as $optgroup => $boards) {
                 if (count($boards) <= 0) {
                     continue;
                 }
                 foreach ($boards as $board) {
                     $ids[] = $board->id;
                 }
             }
         }
         $this->collections = array();
         if ($this->item->get('id')) {
             $posts = $this->model->posts(array('collection_id' => $ids, 'item_id' => $this->item->get('id'), 'limit' => 25, 'start' => 0, 'access' => array(0, 1, 4)));
             if ($posts) {
                 $found = array();
                 foreach ($posts as $post) {
                     foreach ($this->myboards as $board) {
                         if (!in_array($board->id, $found) && $board->id == $post->collection_id) {
                             $this->collections[] = new Collection($board);
                             $found[] = $board->id;
                         }
                     }
                     if (!in_array($post->collection_id, $found)) {
                         foreach ($this->groupboards as $optgroup => $boards) {
                             if (count($boards) <= 0) {
                                 continue;
                             }
                             foreach ($boards as $board) {
                                 if (!in_array($board->id, $found) && $board->id == $post->collection_id) {
                                     $this->collections[] = new Collection($board);
                                     $found[] = $board->id;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         ob_clean();
         require $this->getLayoutPath('collect');
         exit;
     }
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     // Was a collection title submitted?
     // If so, we'll create a new collection with that title.
     if (isset($collectible['title']) && $collectible['title']) {
         $collection = with(new Collection())->set('title', $collectible['title'])->set('access', 0)->set('object_id', User::get('id'))->set('object_type', 'member');
         if (!$collection->store()) {
             $this->setError($collection->getError());
         }
         $collectible['collection_id'] = $collection->get('id');
     }
     if (!$this->getError()) {
         // Try loading the current post to see if this has
         // already been posted to this collection (i.e., no duplicates)
         $database = \App::get('db');
         $post = new Post($database);
         $post->loadByBoard($collectible['collection_id'], $this->item->get('id'));
         if (!$post->id) {
             // No record found -- we're OK to add one
             $post = new Post($database);
             $post->item_id = $this->item->get('id');
             $post->collection_id = $collectible['collection_id'];
             $post->description = $collectible['description'];
             if ($post->check()) {
                 // Store new content
                 if (!$post->store()) {
                     $this->setError($post->getError());
                 }
             } else {
                 $this->setError($post->getError());
             }
         }
     }
     // Display success message
     $response = new stdClass();
     $response->success = true;
     if ($this->getError()) {
         $response->success = false;
         $response->message = $this->getError();
     } else {
         $response->message = Lang::txt('MOD_COLLECT_PAGE_COLLECTED');
     }
     ob_clean();
     header('Content-type: text/plain');
     echo json_encode($response);
     exit;
 }