Beispiel #1
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);
 }
Beispiel #2
0
 /**
  * Create a post
  *
  * @apiMethod POST
  * @apiUri    /collections/{id}/posts
  * @apiParameter {
  * 		"name":        "collection_id",
  * 		"description": "Collection identifier",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "title",
  * 		"description": "Entry title",
  * 		"type":        "string",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "description",
  * 		"description": "Entry description",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     null
  * }
  * @apiParameter {
  * 		"name":        "url",
  * 		"description": "Entry URL; Requires 'type'='link'",
  * 		"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":        "type",
  * 		"description": "Item type",
  * 		"type":        "string",
  * 		"required":    false,
  * 		"default":     "file"
  * }
  * @apiParameter {
  * 		"name":        "object_id",
  * 		"description": "Object ID",
  * 		"type":        "integer",
  * 		"required":    false,
  * 		"default":     0
  * }
  * @return    void
  */
 public function createTask()
 {
     $this->requiresAuthentication();
     $fields = array('title' => Request::getVar('title', null, 'post', 'none', 2), 'description' => Request::getVar('description', null, 'post', 'none', 2), 'url' => Request::getVar('url', null, 'post'), 'created' => Request::getVar('created', new Date('now'), 'post'), 'created_by' => Request::getInt('created_by', 0, 'post'), 'state' => Request::getInt('state', 1, 'post'), 'access' => Request::getInt('access', 0, 'post'), 'type' => Request::getVar('type', 'file', 'post'), 'object_id' => Request::getInt('object_id', 0, 'post'), 'collection_id' => Request::getInt('collection_id', 0, 'post'));
     if (!$fields['collection_id']) {
         throw new Exception(Lang::txt('COM_COLLECTIONS_ERROR_MISSING_COLLECTION'), 422);
     }
     $row = new Item();
     if (!$row->bind($fields)) {
         throw new Exception(Lang::txt('COM_COLLECTIONS_ERROR_BINDING_DATA'), 500);
     }
     if (!$row->store(true)) {
         throw new Exception(Lang::txt('COM_COLLECTIONS_ERROR_SAVING_DATA'), 500);
     }
     $post = new Post();
     $post->set('item_id', $row->get('id'));
     $post->set('original', 1);
     $post->set('collection_id', $fields['collection_id']);
     if (!$post->store(true)) {
         throw new Exception(Lang::txt('COM_COLLECTIONS_ERROR_SAVING_DATA'), 500);
     }
     $this->send($row);
 }
Beispiel #3
0
 /**
  * Save post reordering
  *
  * @return   void
  */
 public function reorderTask()
 {
     // Check for request forgeries
     Request::checkToken(['get', 'post']);
     // Incoming
     $posts = Request::getVar('post', array());
     if (is_array($posts)) {
         $folder = null;
         $i = 0;
         foreach ($posts as $post) {
             $post = intval($post);
             if (!$post) {
                 continue;
             }
             $row = new Post($post);
             if (!$row->exists()) {
                 continue;
             }
             $row->set('ordering', $i + 1);
             $row->store(false);
             $i++;
         }
     }
     if (!$no_html) {
         // Output messsage and redirect
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller), Lang::txt('COM_COLLECTIONS_POSTS_REORDERED'));
         return;
     }
     $response = new \stdClass();
     $response->success = 1;
     $response->message = Lang::txt('COM_COLLECTIONS_POSTS_REORDERED');
     echo json_encode($response);
 }