/** * 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); }
/** * Get basic metadata for a post * * @return void */ public function metadataTask() { $id = Request::getInt('post', 0); $post = new Post($id); if (!Request::getInt('no_html', 0)) { // Output messsage and redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller)); return; } $response = new \stdClass(); $response->id = $id; $response->reposts = Lang::txt('COM_COLLECTIONS_NUM_REPOSTS', $post->item()->get('reposts', 0)); $response->comments = Lang::txt('COM_COLLECTIONS_NUM_COMMENTS', $post->item()->get('comments', 0)); $response->likes = Lang::txt('COM_COLLECTIONS_NUM_LIKES', $post->item()->get('positive', 0)); echo json_encode($response); }