Ejemplo n.º 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->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();
 }
Ejemplo n.º 2
0
 /**
  * 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));
 }
Ejemplo n.º 3
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();
 }
 /**
  * Up
  **/
 public function up()
 {
     // add comment ID
     if ($this->db->tableExists('#__xfavorites')) {
         $this->callback('progress', 'init', array('Running ' . __CLASS__ . '.php:'));
         // Check if there are any favorites
         $query = "SELECT * FROM `#__xfavorites` ORDER BY uid ASC;";
         $this->db->setQuery($query);
         if ($results = $this->db->loadObjectList()) {
             require_once PATH_CORE . DS . 'components' . DS . 'com_collections' . DS . 'models' . DS . 'archive.php';
             $objs = array();
             $usrs = array();
             $total = count($results);
             $i = 1;
             foreach ($results as $result) {
                 // Does this user already have this favorite as a collection item?
                 $query = "SELECT p.id\n\t\t\t\t\t\t\tFROM `#__collections_posts` AS p\n\t\t\t\t\t\t\tJOIN `#__collections_items` AS i ON p.`item_id`=i.`id`\n\t\t\t\t\t\t\tWHERE p.`created_by`=" . $this->db->quote($result->uid) . " AND i.`type`='resource' AND i.`object_id`=" . $this->db->quote($result->oid);
                 $this->db->setQuery($query);
                 if (!$this->db->loadResult()) {
                     // No collection item
                     // Do we have a collection ID for this user?
                     if (!isset($usrs[$result->uid])) {
                         // No ID yet. Check if the user has a default collection
                         $query = "SELECT p.id FROM `#__collections` AS p WHERE p.`object_id`=" . $this->db->quote($result->uid) . " AND p.`object_type`='member' AND p.`is_default`=1";
                         $this->db->setQuery($query);
                         if (!($collection_id = $this->db->loadResult())) {
                             // No default collection.
                             // So, we make one.
                             $tbl = new \Components\Collections\Tables\Collection($this->db);
                             $tbl->setup($result->uid, 'member');
                             $usrs[$result->uid] = $tbl->id;
                         } else {
                             $usrs[$result->uid] = $collection_id;
                         }
                     }
                     // Check if we already have an item_id
                     if (!isset($objs[$result->oid])) {
                         // Check if an item entry exists
                         $b = new \Components\Collections\Tables\Item($this->db);
                         $b->loadType($result->oid, 'resource');
                         if (!$b->id) {
                             // No item entry
                             // Get some resource data
                             $query = "SELECT id, title, introtext FROM `#__resources` WHERE id=" . $this->db->quote($result->oid);
                             $this->db->setQuery($query);
                             $resource = $this->db->loadObject();
                             if (!$resource || !$resource->id) {
                                 continue;
                             }
                             // Create the item
                             $b->type = 'resource';
                             $b->object_id = $resource->id;
                             $b->title = $resource->title;
                             $b->description = $resource->introtext;
                             $b->url = 'index.php?option=com_resources&id=' . $resource->id;
                             if (!$b->check()) {
                                 continue;
                             }
                             if (!$b->store()) {
                                 continue;
                             }
                         }
                         // Set the item_id for thsi resource
                         // as it's most likely to be needed again
                         $objs[$result->oid] = $b->id;
                         unset($b);
                     }
                     // Create a post associating the item to a collection
                     $stick = new \Components\Collections\Tables\Post($this->db);
                     $stick->item_id = $objs[$result->oid];
                     $stick->collection_id = $usrs[$result->uid];
                     $stick->created_by = $result->uid;
                     if ($stick->check()) {
                         // Store new content
                         if (!$stick->store()) {
                             continue;
                         }
                     }
                 }
                 $progress = round($i / $total * 100);
                 $this->callback('progress', 'setProgress', array($progress));
                 $i++;
             }
         }
         $this->callback('progress', 'done');
         $query = "DROP TABLE IF EXISTS `#__xfavorites`;";
         $this->db->setQuery($query);
         $this->db->query();
         $this->deletePluginEntry('members', 'favorites');
         $this->deletePluginEntry('resources', 'favorite');
         $this->deletePluginEntry('publications', 'favorite');
         $this->deleteModuleEntry('mod_myfavorites');
     }
 }