コード例 #1
0
ファイル: postsv1_0.php プロジェクト: kevinwojo/hubzero-cms
 /**
  * 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);
 }
コード例 #2
0
 /**
  * Retrieve a collection
  *
  * @apiMethod GET
  * @apiUri    /collections/{id}
  * @apiParameter {
  * 		"name":        "id",
  * 		"description": "Blog entry identifier",
  * 		"type":        "integer",
  * 		"required":    true,
  * 		"default":     null
  * }
  * @return    void
  */
 public function readTask()
 {
     $id = Request::getInt('id', 0);
     $row = new Collection($id);
     if (!$row->exists()) {
         throw new Exception(Lang::txt('COM_COLLECTIONS_ERROR_MISSING_RECORD'), 404);
     }
     $response = $row->toObject();
     $response->created_by = new stdClass();
     $response->created_by->id = $row->get('created_by');
     $response->created_by->name = $row->creator()->get('name');
     $response->url = str_replace('/api', '', rtrim(Request::base(), '/') . '/' . ltrim(Route::url($row->link()), '/'));
     $this->send($response);
 }
コード例 #3
0
ファイル: posts.php プロジェクト: sumudinie/hubzero-cms
 /**
  * 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'));
 }