Ejemplo n.º 1
0
 /**
  * Display a list of all categories
  *
  * @return  void
  */
 public function displayTask()
 {
     // Get filters
     $this->view->filters = array('state' => -1, 'access' => -1, 'collection_id' => Request::getState($this->_option . '.' . $this->_controller . '.collection_id', 'collection_id', 0, 'int'), 'item_id' => Request::getState($this->_option . '.' . $this->_controller . '.item_id', 'item_id', 0, 'int'), 'sort' => Request::getState($this->_option . '.' . $this->_controller . '.sort', 'filter_order', 'created'), 'sort_Dir' => Request::getState($this->_option . '.' . $this->_controller . '.sortdir', 'filter_order_Dir', 'DESC'), 'search' => urldecode(Request::getState($this->_option . '.' . $this->_controller . '.search', 'search', '')), 'limit' => Request::getState($this->_option . '.' . $this->_controller . '.limit', 'limit', Config::get('list_limit'), 'int'), 'start' => Request::getState($this->_option . '.' . $this->_controller . '.limitstart', 'limitstart', 0, 'int'));
     $obj = new Collection($this->view->filters['collection_id']);
     // Get record count
     $this->view->filters['count'] = true;
     $this->view->total = $obj->posts($this->view->filters);
     // Get records
     $this->view->filters['count'] = false;
     $this->view->rows = $obj->posts($this->view->filters);
     // Output the HTML
     $this->view->display();
 }
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * HUBzero is a registered trademark of Purdue University.
 *
 * @package   hubzero-cms
 * @author    Shawn Rice <*****@*****.**>
 * @copyright Copyright 2005-2015 HUBzero Foundation, LLC.
 * @license   http://opensource.org/licenses/MIT MIT
 */
// No direct access
defined('_HZEXEC_') or die;
if ($this->row instanceof \Components\Collections\Models\Collection) {
    $collection = $this->row;
} else {
    $collection = \Components\Collections\Models\Collection::getInstance($this->row->item()->get('object_id'));
    if ($this->row->get('description')) {
        $collection->set('description', $this->row->get('description'));
    }
}
?>
		<h4<?php 
if ($collection->get('access', 0) == 4) {
    echo ' class="private"';
}
?>
>
			<a href="<?php 
echo Route::url($collection->link());
?>
">
Ejemplo n.º 3
0
 /**
  * Get a count for the specified key
  *
  * @param   string   $what  Key name [following, followers, collectios, posts]
  * @return  integer
  */
 public function count($what = 'following')
 {
     $what = strtolower(trim($what));
     $value = $this->get($what);
     switch ($what) {
         case 'following':
             if ($value === null) {
                 $value = $this->_tbl->count(array('follower_type' => $this->get('following_type'), 'follower_id' => $this->get('following_id')));
                 $this->set($what, $value);
             }
             break;
         case 'followers':
             if ($value === null) {
                 $value = $this->_tbl->count(array('following_type' => $this->get('following_type'), 'following_id' => $this->get('following_id')));
                 $this->set($what, $value);
             }
             break;
         case 'collections':
             if ($value === null && $this->get('following_type') != 'collection') {
                 $model = Collections::getInstance($this->get('following_type'), $this->get('following_id'));
                 $value = $model->collections(array('count'));
                 $this->set($what, $value);
             }
             break;
         case 'posts':
             if ($value === null) {
                 if ($this->get('following_type') != 'collection') {
                     $model = Archive::getInstance($this->get('following_type'), $this->get('following_id'));
                     $value = $model->posts(array('count'));
                     $this->set($what, $value);
                 } else {
                     $model = Collection::getInstance($this->get('following_id'));
                     $value = $model->posts(array('count'));
                     $this->set($what, $value);
                 }
             }
             break;
     }
     if ($value === null) {
         $value = 0;
     }
     return $value;
 }
Ejemplo n.º 4
0
 /**
  * Delete a collection
  *
  * @apiMethod DELETE
  * @apiUri    /collections/{id}
  * @apiParameter {
  * 		"name":        "id",
  * 		"description": "Entry identifier",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @return    void
  */
 public function deleteTask()
 {
     $this->requiresAuthentication();
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     if (count($ids) <= 0) {
         throw new Exception(Lang::txt('COM_COLLECTIONS_ERROR_MISSING_ID'), 500);
     }
     foreach ($ids as $id) {
         $row = new Collection(intval($id));
         if (!$row->exists()) {
             throw new Exception(Lang::txt('COM_COLLECTIONS_ERROR_MISSING_RECORD'), 404);
         }
         if (!$row->delete()) {
             throw new Exception($row->getError(), 500);
         }
     }
     $this->send(null, 204);
 }
Ejemplo n.º 5
0
 /**
  * Display a list of posts for all collections
  *
  * @return     string
  */
 private function _posts()
 {
     $view = $this->view('default', 'collection');
     $view->name = $this->_name;
     $view->group = $this->group;
     $view->option = $this->option;
     $view->params = $this->params;
     $view->model = $this->model;
     // Filters for returning results
     $view->filters = array('limit' => Request::getInt('limit', Config::get('list_limit')), 'start' => Request::getInt('limitstart', 0), 'search' => Request::getVar('search', ''), 'state' => 1, 'object_type' => 'group', 'object_id' => $this->group->get('gidNumber'), 'user_id' => User::get('id'), 'sort' => 'created', 'sort_Dir' => 'desc');
     // Filters for returning results
     $count = array('count' => true);
     if (!$this->params->get('access-manage-collection')) {
         $view->filters['access'] = User::isGuest() ? 0 : array(0, 1);
         if (in_array(User::get('id'), $this->group->get('members'))) {
             $view->filters['access'] = array(0, 1, 4);
         }
         $count['access'] = $view->filters['access'];
     }
     if ($this->authorized) {
         $count['access'] = -1;
         $view->filters['access'] = -1;
     }
     $view->collections = $this->model->collections($count);
     $view->posts = $this->model->posts($count);
     $view->followers = $this->model->followers($count);
     if ($this->params->get('access-can-follow')) {
         $view->following = $this->model->following($count);
     }
     $view->collection = \Components\Collections\Models\Collection::getInstance();
     //$view->filters['user_id'] = User::get('id');
     $view->count = $view->posts;
     $view->rows = $view->collection->posts($view->filters);
     $view->scope = 'posts';
     foreach ($this->getErrors() as $error) {
         $view->setError($error);
     }
     return $view->loadTemplate();
 }
Ejemplo n.º 6
0
 /**
  * Display posts for a collection
  *
  * @apiMethod GET
  * @apiUri    /collections/{id}/posts
  * @apiParameter {
  * 		"name":          "collection_id",
  * 		"description":   "Collection identifier",
  * 		"type":          "integer",
  * 		"required":      true,
  * 		"default":       null
  * }
  * @apiParameter {
  * 		"name":          "limit",
  * 		"description":   "Number of result to return.",
  * 		"type":          "integer",
  * 		"required":      false,
  * 		"default":       25
  * }
  * @apiParameter {
  * 		"name":          "start",
  * 		"description":   "Number of where to start returning results.",
  * 		"type":          "integer",
  * 		"required":      false,
  * 		"default":       0
  * }
  * @apiParameter {
  * 		"name":          "search",
  * 		"description":   "A word or phrase to search for.",
  * 		"type":          "string",
  * 		"required":      false,
  * 		"default":       ""
  * }
  * @apiParameter {
  * 		"name":          "sort",
  * 		"description":   "Field to sort results by.",
  * 		"type":          "string",
  * 		"required":      false,
  *      "default":       "created",
  * 		"allowedValues": "created, ordering"
  * }
  * @apiParameter {
  * 		"name":          "sort_Dir",
  * 		"description":   "Direction to sort results by.",
  * 		"type":          "string",
  * 		"required":      false,
  * 		"default":       "desc",
  * 		"allowedValues": "asc, desc"
  * }
  * @return  void
  */
 public function listTask()
 {
     $model = new Collection();
     $filters = array('collection_id' => Request::getInt('collection_id', -1), 'limit' => Request::getInt('limit', 25), 'start' => Request::getInt('limitstart', 0), 'search' => Request::getVar('search', ''), 'state' => 1, 'sort' => Request::getVar('sort', 'created'), 'sort_Dir' => strtoupper(Request::getWord('sortDir', 'DESC')), 'is_default' => 0, 'access' => 0, 'count' => true);
     $filters['sort'] = 'p.' . $filters['sort'];
     $response = new stdClass();
     $response->posts = array();
     $response->total = $model->posts($filters);
     if ($response->total) {
         $href = 'index.php?option=com_collections&controller=media&post=';
         $base = rtrim(Request::base(), '/');
         $filters['count'] = false;
         foreach ($model->posts($filters) as $i => $entry) {
             $item = $entry->item();
             $obj = new stdClass();
             $obj->id = $entry->get('id');
             $obj->title = $entry->get('title', $item->get('title'));
             $obj->type = $item->get('type');
             $obj->posted = $entry->get('created');
             $obj->author = $entry->creator()->get('name');
             $obj->uri = str_replace('/api', '', $base . '/' . ltrim(Route::url($entry->link()), '/'));
             $obj->tags = $item->tags('string');
             $obj->comments = $item->get('comments', 0);
             $obj->likes = $item->get('positive', 0);
             $obj->reposts = $item->get('reposts', 0);
             $obj->assets = array();
             $assets = $item->assets();
             if ($assets->total() > 0) {
                 foreach ($assets as $asset) {
                     $a = new stdClass();
                     $a->title = ltrim($asset->get('filename'), '/');
                     $a->description = $asset->get('description');
                     $a->url = $asset->get('type') == 'link' ? $asset->get('filename') : $base . '/' . ltrim(Route::url($href . $entry->get('id') . '&task=download&file=' . $a->title), '/');
                     $obj->assets[] = $a;
                 }
             }
             $response->posts[] = $obj;
         }
     }
     $this->send($response);
 }
Ejemplo n.º 7
0
 /**
  * Retrieve a post
  *
  * @apiMethod GET
  * @apiUri    /collections/posts/{id}
  * @apiParameter {
  * 		"name":        "id",
  * 		"description": "Entry identifier",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @return    void
  */
 public function readTask()
 {
     $id = Request::getInt('id', 0);
     $entry = new Post($id);
     if (!$entry->exists()) {
         throw new Exception(Lang::txt('COM_COLLECTIONS_ERROR_MISSING_RECORD'), 404);
     }
     $href = 'index.php?option=com_collections&controller=media&post=';
     $base = rtrim(Request::base(), '/');
     $base = str_replace('/api', '', $base) . '/';
     $item = $entry->item();
     $collection = new Collection($entry->get('collection_id'));
     $entry->set('object_type', $collection->get('object_type'));
     $entry->set('object_id', $collection->get('object_id'));
     $obj = new stdClass();
     $obj->id = $entry->get('id');
     $obj->collection_id = $entry->get('collection_id');
     $obj->item_id = $entry->get('item_id');
     $obj->original = $entry->get('original');
     $obj->ordering = $entry->get('ordering');
     $obj->title = $entry->get('title', $item->get('title'));
     $obj->type = $item->get('type');
     $obj->created = $entry->get('created');
     $obj->created_by = new stdClass();
     $obj->created_by->id = $entry->get('created_by');
     $obj->created_by->name = $entry->creator()->get('name');
     $obj->url = $base . ltrim(Route::url($entry->link()), '/');
     $obj->tags = $item->tags('string');
     $obj->comments = $item->get('comments', 0);
     $obj->likes = $item->get('positive', 0);
     $obj->reposts = $item->get('reposts', 0);
     $obj->assets = array();
     $assets = $item->assets();
     if ($assets->total() > 0) {
         foreach ($assets as $asset) {
             $a = new stdClass();
             $a->title = ltrim($asset->get('filename'), '/');
             $a->description = $asset->get('description');
             $a->url = $asset->get('type') == 'link' ? $asset->get('filename') : $base . ltrim(Route::url($href . $entry->get('id') . '&task=download&file=' . $a->title), '/');
             $obj->assets[] = $a;
         }
     }
     $this->send($obj);
 }
Ejemplo n.º 8
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'));
 }
Ejemplo n.º 9
0
 /**
  * Display a list of items in a collection
  *
  * @return     string
  */
 private function _posts()
 {
     $view = $this->view('default', 'collection');
     $view->name = $this->_name;
     $view->member = $this->member;
     $view->option = $this->option;
     $view->params = $this->params;
     $view->model = $this->model;
     // Filters for returning results
     $view->filters = array('limit' => Request::getInt('limit', Config::get('list_limit')), 'start' => Request::getInt('limitstart', 0), 'created_by' => $this->member->get('uidNumber'), 'search' => Request::getVar('search', ''), 'state' => 1, 'object_id' => $this->member->get('uidNumber'), 'object_type' => 'member', 'access' => -1, 'sort' => 'created', 'sort_Dir' => 'desc');
     // Filters for returning results
     //$filters = array();
     $count = array('count' => true);
     if (!$this->params->get('access-manage-collection')) {
         $view->filters['access'] = User::isGuest() ? 0 : array(0, 1);
         $count['access'] = $view->filters['access'];
     }
     $view->collections = $this->model->collections($count);
     $view->followers = $this->model->followers($count);
     $view->following = $this->model->following($count);
     $view->posts = $this->model->posts($count);
     $view->total = $view->posts;
     $view->collection = \Components\Collections\Models\Collection::getInstance();
     $view->filters['user_id'] = $this->member->get('uidNumber');
     $view->rows = $view->collection->posts($view->filters);
     $view->task = 'posts';
     foreach ($this->getErrors() as $error) {
         $view->setError($error);
     }
     return $view->loadTemplate();
 }
Ejemplo n.º 10
0
 /**
  * Set and get a specific collection
  *
  * @param   mixed   $id
  * @return  object
  */
 public function collection($id = null)
 {
     // If the current offering isn't set
     //    OR the ID passed doesn't equal the current offering's ID or alias
     if (!isset($this->_collection) || $id !== null && (int) $this->_collection->get('id') != $id && (string) $this->_collection->get('alias') != $id) {
         // Reset current offering
         $this->_collection = null;
         // If the list of all offerings is available ...
         if ($this->_collections instanceof ItemList) {
             // Find an offering in the list that matches the ID passed
             foreach ($this->collections() as $key => $collection) {
                 if ((int) $collection->get('id') == $id || (string) $collection->get('alias') == $id) {
                     // Set current offering
                     $this->_collection = $collection;
                     break;
                 }
             }
         }
         if (!$this->_collection) {
             $this->_collection = Collection::getInstance($id, $this->_object_id, $this->_object_type);
         }
     }
     // Return current offering
     return $this->_collection;
 }
Ejemplo n.º 11
0
 /**
  * Sets the state of one or more entries
  *
  * @param   integer  $state  The state to set entries to
  * @return  void
  */
 public function stateTask($state = 0)
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     // Incoming
     $state = $this->getTask() == 'publish' ? 1 : 0;
     $ids = Request::getVar('id', array());
     $ids = !is_array($ids) ? array($ids) : $ids;
     // Check for a resource
     if (count($ids) < 1) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_COLLECTIONS_ERROR_SELECT_TO', $this->_task), 'error');
         return;
     }
     // Loop through all the IDs
     $success = 0;
     foreach ($ids as $id) {
         // Load the article
         $row = new Collection(intval($id));
         $row->set('state', $state);
         // Store new content
         if (!$row->store()) {
             $this->setError($row->getError());
             continue;
         }
         $success++;
     }
     switch ($this->_task) {
         case 'publish':
             $message = Lang::txt('COM_COLLECTIONS_ITEMS_PUBLISHED', $success);
             break;
         case 'unpublish':
             $message = Lang::txt('COM_COLLECTIONS_ITEMS_UNPUBLISHED', $success);
             break;
         case 'archive':
             $message = Lang::txt('COM_COLLECTIONS_ITEMS_TRASHED', $success);
             break;
     }
     // Set the redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), $message);
 }