Beispiel #1
0
 /**
  * Repost an entry
  *
  * @return  string
  */
 private function _repost()
 {
     if (User::isGuest()) {
         return $this->_login();
     }
     /*if (!$this->params->get('access-create-item'))
     		{
     			$this->setError(Lang::txt('PLG_GROUPS_COLLECTIONS_NOT_AUTHORIZED'));
     			return $this->_collections();
     		}*/
     $no_html = Request::getInt('no_html', 0);
     // No board 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 = $this->model->collection($collection_id);
             $item_id = $collection->item()->get('id');
             $collection_id = $collection->item()->get('object_id');
         } else {
             $post = \Components\Collections\Models\Post::getInstance($post_id);
             $item_id = $post->get('item_id');
         }
         $view = $this->view('repost', 'post');
         $view->myboards = $this->model->mine();
         $view->groupboards = $this->model->mine('groups');
         $view->name = $this->_name;
         $view->option = $this->option;
         $view->group = $this->group;
         $view->no_html = $no_html;
         $view->post_id = $post_id;
         $view->collection_id = $collection_id;
         $view->item_id = $item_id;
         if ($no_html) {
             $view->display();
             exit;
         }
         return $view->loadTemplate();
     }
     // Check for request forgeries
     Request::checkToken();
     $collection_id = Request::getInt('collection_id', 0);
     if (!$collection_id) {
         $collection = new \Components\Collections\Models\Collection();
         $collection->set('title', Request::getVar('collection_title', ''));
         $collection->set('object_id', $this->group->get('gidNumber'));
         $collection->set('object_type', 'group');
         $collection->set('access', $this->params->get('access-plugin'));
         if (!$collection->store()) {
             $this->setError($collection->getError());
         }
         $collection_id = $collection->get('id');
     }
     $item_id = Request::getInt('item_id', 0);
     // Try loading the current board/bulletin to see
     // if this has already been posted to the board (i.e., no duplicates)
     $post = new \Components\Collections\Tables\Post($this->database);
     $post->loadByBoard($collection_id, $item_id);
     if (!$post->get('id')) {
         // No record found -- we're OK to add one
         $post = new \Components\Collections\Tables\Post($this->database);
         $post->item_id = $item_id;
         $post->collection_id = $collection_id;
         $post->description = Request::getVar('description', '', 'none', 2);
         if (!$post->check()) {
             $this->setError($post->getError());
         } else {
             // Store new content
             if (!$post->store()) {
                 $this->setError($post->getError());
             }
         }
     }
     if ($this->getError()) {
         return $this->getError();
     }
     // Record the activity
     $recipients = array(['group', $this->group->get('gidNumber')], ['collection', $collection_id], ['user', $post->get('created_by')]);
     foreach ($this->group->get('managers') as $recipient) {
         $recipients[] = ['user', $recipient];
     }
     if (!isset($collection)) {
         $collection = new \Components\Collections\Models\Collection($collection_id);
     }
     Event::trigger('system.logActivity', ['activity' => ['action' => 'created', 'scope' => 'collections.post', 'scope_id' => $post->id, 'description' => Lang::txt('PLG_GROUPS_COLLECTIONS_ACTIVITY_POST_CREATED', '<a href="' . Route::url($collection->link()) . '">' . $collection->get('title') . '</a>'), 'details' => array('collection_id' => $post->collection_id, 'item_id' => $post->item_id, 'post_id' => $post->id)], 'recipients' => $recipients]);
     // Display updated bulletin stats if called via AJAX
     if ($no_html) {
         echo Lang::txt('PLG_GROUPS_COLLECTIONS_POST_REPOSTS', $post->getCount(array('item_id' => $post->get('item_id'), 'original' => 0)));
         exit;
     }
     // Display the main listing
     return $this->_collection();
 }
Beispiel #2
0
 /**
  * Repost an entry
  *
  * @return     string
  */
 private function _repost()
 {
     if (User::isGuest()) {
         return $this->_login();
     }
     if (!$this->params->get('access-create-item')) {
         $this->setError(Lang::txt('PLG_GROUPS_COLLECTIONS_NOT_AUTHORIZED'));
         return $this->_collections();
     }
     $no_html = Request::getInt('no_html', 0);
     // No board 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 = $this->model->collection($collection_id);
             $item_id = $collection->item()->get('id');
             $collection_id = $collection->item()->get('object_id');
         } else {
             $post = \Components\Collections\Models\Post::getInstance($post_id);
             $item_id = $post->get('item_id');
         }
         $view = $this->view('repost', 'post');
         $view->myboards = $this->model->mine();
         $view->groupboards = $this->model->mine('groups');
         $view->name = $this->_name;
         $view->option = $this->option;
         $view->group = $this->group;
         $view->no_html = $no_html;
         $view->post_id = $post_id;
         $view->collection_id = $collection_id;
         $view->item_id = $item_id;
         if ($no_html) {
             $view->display();
             exit;
         }
         return $view->loadTemplate();
     }
     // Check for request forgeries
     Request::checkToken();
     $collection_id = Request::getInt('collection_id', 0);
     if (!$collection_id) {
         $collection = new \Components\Collections\Models\Collection();
         $collection->set('title', Request::getVar('collection_title', ''));
         $collection->set('object_id', $this->group->get('gidNumber'));
         $collection->set('object_type', 'group');
         $collection->set('access', $this->params->get('access-plugin'));
         if (!$collection->store()) {
             $this->setError($collection->getError());
         }
         $collection_id = $collection->get('id');
     }
     $item_id = Request::getInt('item_id', 0);
     // Try loading the current board/bulletin to see
     // if this has already been posted to the board (i.e., no duplicates)
     $post = new \Components\Collections\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', '', 'none', 2);
         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 bulletin stats if called via AJAX
     if ($no_html) {
         echo Lang::txt('PLG_GROUPS_COLLECTIONS_POST_REPOSTS', $post->getCount(array('item_id' => $post->get('item_id'), 'original' => 0)));
         exit;
     }
     // Display the main listing
     return $this->_collection();
 }
 /**
  * Repost an entry
  *
  * @return     string
  */
 private function _repost()
 {
     if (User::isGuest()) {
         return $this->_login();
     }
     $no_html = Request::getInt('no_html', 0);
     // No board 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 = $this->model->collection($collection_id);
             $item_id = $collection->item()->get('id');
             $collection_id = $collection->item()->get('object_id');
         } else {
             $post = \Components\Collections\Models\Post::getInstance($post_id);
             $item_id = $post->get('item_id');
         }
         $view = $this->view('repost', 'post');
         $view->myboards = $this->model->mine();
         $view->groupboards = $this->model->mine('groups');
         $view->name = $this->_name;
         $view->option = $this->option;
         $view->member = $this->member;
         $view->no_html = $no_html;
         $view->post_id = $post_id;
         $view->collection_id = $collection_id;
         $view->item_id = $item_id;
         if ($no_html) {
             $view->display();
             exit;
         }
         return $view->loadTemplate();
     }
     // Check for request forgeries
     Request::checkToken();
     $collection_id = Request::getInt('collection_id', 0);
     if (!$collection_id) {
         $collection = new \Components\Collections\Models\Collection();
         $collection->set('title', Request::getVar('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');
     }
     $item_id = Request::getInt('item_id', 0);
     // Try loading the current board/bulletin to see
     // if this has already been posted to the board (i.e., no duplicates)
     $post = new \Components\Collections\Tables\Post($this->database);
     $post->loadByBoard($collection_id, $item_id);
     if (!$post->get('id')) {
         // No record found -- we're OK to add one
         $post = new \Components\Collections\Tables\Post($this->database);
         $post->item_id = $item_id;
         $post->collection_id = $collection_id;
         $post->description = Request::getVar('description', '', 'none', 2);
         if (!$post->check()) {
             $this->setError($post->getError());
         } else {
             // 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('%s reposts', $post->getCount(array('item_id' => $post->get('item_id'), 'original' => 0)));
         exit;
     }
     // Display the main listing
     App::redirect(Route::url($this->member->getLink() . '&active=' . $this->_name));
 }