123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- <?php
- if (!defined('STATUSNET')) {
- exit(1);
- }
- class ApiListAction extends ApiBareAuthAction
- {
-
- var $list = null;
-
- var $update = false;
-
- var $delete = false;
-
- protected function prepare(array $args=array())
- {
- parent::prepare($args);
- $this->delete = ($_SERVER['REQUEST_METHOD'] == 'DELETE' ||
- ($this->trimmed('_method') == 'DELETE' &&
- $_SERVER['REQUEST_METHOD'] == 'POST'));
-
- $this->update = (!$this->delete &&
- in_array($_SERVER['REQUEST_METHOD'], array('POST', 'PUT')));
- $this->user = $this->getTargetUser($this->arg('user'));
- $this->list = $this->getTargetList($this->arg('user'), $this->arg('id'));
- if (empty($this->list)) {
-
- $this->clientError(_('List not found.'), 404);
- }
- return true;
- }
-
- protected function handle()
- {
- parent::handle();
- if($this->delete) {
- $this->handleDelete();
- return true;
- }
- if($this->update) {
- $this->handlePut();
- return true;
- }
- switch($this->format) {
- case 'xml':
- $this->showSingleXmlList($this->list);
- break;
- case 'json':
- $this->showSingleJsonList($this->list);
- break;
- default:
-
- $this->clientError(_('API method not found.'), 404);
- }
- }
-
- function requiresAuth()
- {
- return parent::requiresAuth() ||
- $this->create || $this->delete;
- }
-
- function handlePut()
- {
- if($this->auth_user->id != $this->list->tagger) {
-
- $this->clientError(_('You cannot update lists that do not belong to you.'), 401);
- }
- $new_list = clone($this->list);
- $new_list->tag = common_canonical_tag($this->arg('name'));
- $new_list->description = common_canonical_tag($this->arg('description'));
- $new_list->private = ($this->arg('mode') === 'private') ? true : false;
- $result = $new_list->update($this->list);
- if(!$result) {
-
- $this->clientError(_('An error occured.'), 503);
- }
- switch($this->format) {
- case 'xml':
- $this->showSingleXmlList($new_list);
- break;
- case 'json':
- $this->showSingleJsonList($new_list);
- break;
- default:
-
- $this->clientError(_('API method not found.'), 404);
- }
- }
-
- function handleDelete()
- {
- if($this->auth_user->id != $this->list->tagger) {
-
- $this->clientError(_('You cannot delete lists that do not belong to you.'), 401);
- }
- $record = clone($this->list);
- $this->list->delete();
- switch($this->format) {
- case 'xml':
- $this->showSingleXmlList($record);
- break;
- case 'json':
- $this->showSingleJsonList($record);
- break;
- default:
-
- $this->clientError(_('API method not found.'), 404);
- }
- }
-
- function isReadOnly($args)
- {
- return false;
- }
-
- function lastModified()
- {
- if(!empty($this->list)) {
- return strtotime($this->list->modified);
- }
- return null;
- }
-
- function etag()
- {
- if (!empty($this->list)) {
- return '"' . implode(
- ':',
- array($this->arg('action'),
- common_language(),
- $this->user->id,
- strtotime($this->list->created),
- strtotime($this->list->modified))
- )
- . '"';
- }
- return null;
- }
- }
|