/** * Create an item entry * * @param integer $id Optional ID to use * @return boolean */ public function make($id = null) { if ($this->exists()) { return true; } $id = $id ?: Request::getInt('post', 0); if ($id) { require_once dirname(__DIR__) . DS . 'tables' . DS . 'post.php'; $post = new Tables\Post($this->_db); $post->load($id); if (!$this->_tbl->load($post->item_id)) { $this->setError($this->_tbl->getError()); return false; } } if ($this->exists()) { return true; } $this->set('type', 'file')->set('object_id', 0); if (!$this->store()) { return false; } return true; }
/** * 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')); }
/** * Get a count or list of posts * * @param array $filters Filters to apply to the query that retrieves records * @return mixed Integer or array */ public function posts($filters = array()) { $filters['object_id'] = $this->_object_id; $filters['object_type'] = $this->_object_type; if (!isset($filters['state'])) { $filters['state'] = 1; } if (isset($filters['count']) && $filters['count']) { $tbl = new Tables\Post($this->_db); return $tbl->getCount($filters); } $tbl = new Tables\Post($this->_db); return $tbl->getRecords($filters); }
/** * 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; }
/** * Get a list of posts in this collection * Accepts an array of filters for database query * that retrieves results * * @param array $filters Filters to apply * @param boolean $clear Clear cached data? * @return mixed Integer or object */ public function posts($filters = array(), $clear = false) { if (!isset($filters['collection_id'])) { $filters['collection_id'] = $this->get('id'); } if (!isset($filters['state'])) { $filters['state'] = self::APP_STATE_PUBLISHED; } if (!isset($filters['access'])) { $filters['access'] = User::isGuest() ? 0 : array(0, 1); } if (!isset($filters['sort'])) { if ($sort = $this->get('sort', 'created')) { $filters['sort'] = 'p.' . $sort; } $filters['sort_Dir'] = $this->get('sort', 'created') == 'ordering' ? 'asc' : 'desc'; } if (isset($filters['count']) && $filters['count']) { $tbl = new Tables\Post($this->_db); return $tbl->getCount($filters); } if (!isset($this->_posts) || !$this->_posts instanceof ItemList) { $tbl = new Tables\Post($this->_db); if ($results = $tbl->getRecords($filters)) { $ids = array(); foreach ($results as $key => $result) { $ids[] = $result->item_id; } // Get all the assets for this list of items $ba = new Tables\Asset($this->_db); $assets = $ba->getRecords(array('item_id' => $ids)); // Get all the tags for this list of items $bt = new Tags(); $tags = $bt->getTagsForIds($ids); // Loop through all the items and push assets and tags foreach ($results as $key => $result) { $results[$key] = new Post($result); if ($assets) { foreach ($assets as $asset) { if ($asset->item_id == $results[$key]->get('item_id')) { $results[$key]->item()->addAsset($asset); } else { $results[$key]->item()->addAsset(null); } } } else { $results[$key]->item()->addAsset(null); } if (isset($tags[$results[$key]->get('item_id')])) { $results[$key]->item()->addTag($tags[$results[$key]->get('item_id')]); } else { $results[$key]->item()->addTag(null); } } } else { $results = array(); } $this->_posts = new ItemList($results); } return $this->_posts; }