X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=actions%2Fapisubscriptions.php;h=081445129dfd37e4f35785cd0a3f2a84aa4cd592;hb=64b72a3c9b8c9ee2d8716a3271834293d1e863f8;hp=78dcd722dd09e00c3a2fae595cae9579129a09b1;hpb=4e1b95db283285f1ae0668745a151a6fdb5171eb;p=quix0rs-gnu-social.git diff --git a/actions/apisubscriptions.php b/actions/apisubscriptions.php index 78dcd722dd..081445129d 100644 --- a/actions/apisubscriptions.php +++ b/actions/apisubscriptions.php @@ -21,6 +21,8 @@ * * @category API * @package StatusNet + * @author Dan Moore + * @author Evan Prodromou * @author Zach Copley * @copyright 2009 StatusNet, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 @@ -31,8 +33,6 @@ if (!defined('STATUSNET')) { exit(1); } -require_once INSTALLDIR.'/lib/apibareauth.php'; - /** * This class outputs a list of profiles as Twitter-style user and status objects. * It is used by the API methods /api/statuses/(friends|followers). To support the @@ -40,19 +40,15 @@ require_once INSTALLDIR.'/lib/apibareauth.php'; * * @category API * @package StatusNet + * @author Dan Moore + * @author Evan Prodromou * @author Zach Copley * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ - -class ApiSubscriptionsAction extends ApiBareAuthAction +abstract class ApiSubscriptionsAction extends ApiBareAuthAction { - - var $page = null; - var $count = null; - var $user = null; var $profiles = null; - var $format = null; var $tag = null; var $lite = null; var $ids_only = null; @@ -63,16 +59,12 @@ class ApiSubscriptionsAction extends ApiBareAuthAction * @param array $args $_REQUEST args * * @return boolean success flag - * */ - - function prepare($args) + protected function prepare(array $args=array()) { parent::prepare($args); - $this->page = (int)$this->arg('page', 1); $this->tag = $this->arg('tag'); - $this->format = $this->arg('format'); // Note: Twitter no longer supports 'lite' $this->lite = $this->arg('lite'); @@ -84,17 +76,11 @@ class ApiSubscriptionsAction extends ApiBareAuthAction $this->count = isset($this->ids_only) ? 5000 : (int)$this->arg('count', 100); - if ($this->requiresAuth()) { - if ($this->checkBasicAuthUser() == false) { - return false; - } - } - - $this->user = $this->getTargetUser($this->arg('id')); + $this->target = $this->getTargetProfile($this->arg('id')); - if (empty($this->user)) { - $this->clientError(_('No such user!'), 404, $this->format); - return false; + if (!($this->target instanceof Profile)) { + // TRANS: Client error displayed when requesting a list of followers for a non-existing user. + $this->clientError(_('No such user.'), 404); } $this->profiles = $this->getProfiles(); @@ -107,21 +93,18 @@ class ApiSubscriptionsAction extends ApiBareAuthAction * * Show the profiles * - * @param array $args $_REQUEST data (unused) - * * @return void */ - - function handle($args) + protected function handle() { - parent::handle($args); + parent::handle(); if (!in_array($this->format, array('xml', 'json'))) { - $this->clientError(_('API method not found!'), $code = 404); - return; + // TRANS: Client error displayed when coming across a non-supported API method. + $this->clientError(_('API method not found.'), 404); } - $this->init_document($this->format); + $this->initDocument($this->format); if (isset($this->ids_only)) { $this->showIds(); @@ -129,18 +112,15 @@ class ApiSubscriptionsAction extends ApiBareAuthAction $this->showProfiles(isset($this->lite) ? false : true); } - $this->end_document($this->format); + $this->endDocument($this->format); } /** - * Get profiles - should get overrrided + * Get profiles related to the type of subscriber/subscription action * * @return array Profiles */ - - function getProfiles() - { - } + abstract protected function getProfiles(); /** * Is this action read only? @@ -149,7 +129,6 @@ class ApiSubscriptionsAction extends ApiBareAuthAction * * @return boolean true */ - function isReadOnly($args) { return true; @@ -160,7 +139,6 @@ class ApiSubscriptionsAction extends ApiBareAuthAction * * @return string datestamp of the latest profile in the stream */ - function lastModified() { if (!empty($this->profiles) && (count($this->profiles) > 0)) { @@ -180,7 +158,6 @@ class ApiSubscriptionsAction extends ApiBareAuthAction * * @return string etag */ - function etag() { if (!empty($this->profiles) && (count($this->profiles) > 0)) { @@ -190,8 +167,10 @@ class ApiSubscriptionsAction extends ApiBareAuthAction return '"' . implode( ':', array($this->arg('action'), + common_user_cache_hash($this->auth_user), common_language(), - $this->user->id, + $this->target->id, + // Caching tags. isset($this->ids_only) ? 'IDs' : 'Profiles', strtotime($this->profiles[0]->created), strtotime($this->profiles[$last]->created)) @@ -210,14 +189,14 @@ class ApiSubscriptionsAction extends ApiBareAuthAction * * @return void */ - function showProfiles($include_statuses = true) { switch ($this->format) { case 'xml': - $this->elementStart('users', array('type' => 'array')); + $this->elementStart('users', array('type' => 'array', + 'xmlns:statusnet' => 'http://status.net/schema/api/1/')); foreach ($this->profiles as $profile) { - $this->show_profile( + $this->showProfile( $profile, $this->format, null, @@ -229,7 +208,7 @@ class ApiSubscriptionsAction extends ApiBareAuthAction case 'json': $arrays = array(); foreach ($this->profiles as $profile) { - $arrays[] = $this->twitter_user_array( + $arrays[] = $this->twitterUserArray( $profile, $include_statuses ); @@ -237,6 +216,7 @@ class ApiSubscriptionsAction extends ApiBareAuthAction print json_encode($arrays); break; default: + // TRANS: Client error displayed when requesting profiles of followers in an unsupported format. $this->clientError(_('Unsupported format.')); break; } @@ -248,7 +228,6 @@ class ApiSubscriptionsAction extends ApiBareAuthAction * * @return void */ - function showIds() { switch ($this->format) { @@ -267,9 +246,9 @@ class ApiSubscriptionsAction extends ApiBareAuthAction print json_encode($ids); break; default: + // TRANS: Client error displayed when requesting IDs of followers in an unsupported format. $this->clientError(_('Unsupported format.')); break; } } - }