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
 /**
  * Delete a comment
  *
  * @return  string
  */
 public function deletecommentTask()
 {
     // Ensure the user is logged in
     if (User::isGuest()) {
         return $this->loginTask();
     }
     // Incoming
     $id = Request::getInt('comment', 0);
     if (!$id) {
         return $this->displayTask();
     }
     // Initiate a whiteboard comment object
     $comment = Comment::oneOrFail($id);
     $comment->set('state', $comment::STATE_DELETED);
     // Delete the entry itself
     if (!$comment->save()) {
         $this->setError($comment->getError());
     }
     // Log activity
     $post = new Post(Request::getInt('post', 0));
     $title = $post->item()->get('title');
     $title = $title ? $title : $post->item()->get('description', '#' . $post->get('id'));
     $title = \Hubzero\Utility\String::truncate(strip_tags($title), 70);
     $url = 'index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&post=' . $post->get('id');
     $item = '<a href="' . Route::url($url) . '">' . $title . '</a>';
     Event::trigger('system.logActivity', ['activity' => ['action' => 'deleted', 'scope' => 'collections.comment', 'scope_id' => $comment->get('id'), 'description' => Lang::txt('COM_COLLECTIONS_ACTIVITY_COMMENT_DELETED', $comment->get('id'), $item), 'details' => array('collection_id' => $post->get('collection_id'), 'post_id' => $post->get('id'), 'item_id' => $comment->get('item_id'), 'url' => Route::url($url))], 'recipients' => array(['collection', $post->get('collection_id')], ['user', $row->get('created_by')], ['user', $post->item()->get('created_by')])]);
     // Return the topics list
     return $this->displayTask();
 }