/** * 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')); }
/** * Update a collection * * @apiMethod PUT * @apiUri /collections/{id} * @apiParameter { * "name": "id", * "description": "Entry identifier", * "type": "integer", * "required": true, * "default": null * } * @apiParameter { * "name": "object_type", * "description": "Object type (group, member, etc.)", * "type": "string", * "required": false, * "default": null * } * @apiParameter { * "name": "object_id", * "description": "Object ID", * "type": "integer", * "required": false, * "default": null * } * @apiParameter { * "name": "title", * "description": "Entry title", * "type": "string", * "required": true, * "default": null * } * @apiParameter { * "name": "alias", * "description": "Entry alias", * "type": "string", * "required": false, * "default": null * } * @apiParameter { * "name": "description", * "description": "Entry description", * "type": "string", * "required": false, * "default": null * } * @apiParameter { * "name": "created", * "description": "Created timestamp (YYYY-MM-DD HH:mm:ss)", * "type": "string", * "required": false, * "default": "now" * } * @apiParameter { * "name": "created_by", * "description": "User ID of entry creator", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "state", * "description": "Published state (0 = unpublished, 1 = published)", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "access", * "description": "Access level (0 = public, 1 = registered users, 4 = private)", * "type": "integer", * "required": false, * "default": 0 * } * @apiParameter { * "name": "layout", * "description": "How to display posts", * "type": "string", * "required": false, * "default": "grid" * } * @apiParameter { * "name": "sort", * "description": "How to sort posts (created, ordering)", * "type": "string", * "required": false, * "default": "created" * } * @return void */ public function updateTask() { $this->requiresAuthentication(); $fields = array('id' => Request::getInt('id', 0, 'post'), 'object_type' => Request::getVar('object_type', '', 'post'), 'object_id' => Request::getInt('object_id', 0, 'post'), 'title' => Request::getVar('title', null, 'post', 'none', 2), 'alias' => Request::getVar('alias', 0, 'post'), 'description' => Request::getVar('description', null, 'post', 'none', 2), 'created' => Request::getVar('created', new Date('now'), 'post'), 'created_by' => Request::getInt('created_by', 0, 'post'), 'state' => Request::getInt('state', 0, 'post'), 'access' => Request::getInt('access', 0, 'post'), 'layout' => Request::getVar('layout', 'grid', 'post'), 'sort' => Request::getVar('sort', 'created', 'post')); $row = new Collection($fields['id']); if (!$row->exists()) { throw new Exception(Lang::txt('COM_COLLECTIONS_ERROR_MISSING_RECORD'), 404); } if (!$row->bind($fields)) { throw new Exception(Lang::txt('COM_COLLECTIONS_ERROR_BINDING_DATA'), 422); } if (!$row->store(true)) { throw new Exception(Lang::txt('COM_COLLECTIONS_ERROR_SAVING_DATA'), 500); } $this->send($row); }
/** * 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); }