]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/apisubscriptions.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / actions / apisubscriptions.php
index 63d65f2893ca51e37002153b9defd2eac4008d53..3f5d5f797b32d84f408ee4a922623b1115ff435d 100644 (file)
@@ -33,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
@@ -48,8 +46,7 @@ require_once INSTALLDIR . '/lib/apibareauth.php';
  * @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 $profiles = null;
     var $tag      = null;
@@ -62,10 +59,8 @@ 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);
 
@@ -81,11 +76,11 @@ class ApiSubscriptionsAction extends ApiBareAuthAction
         $this->count    = isset($this->ids_only) ?
             5000 : (int)$this->arg('count', 100);
 
-        $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();
@@ -98,18 +93,15 @@ 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->initDocument($this->format);
@@ -124,14 +116,11 @@ class ApiSubscriptionsAction extends ApiBareAuthAction
     }
 
     /**
-     * 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?
@@ -140,8 +129,7 @@ class ApiSubscriptionsAction extends ApiBareAuthAction
      *
      * @return boolean true
      */
-
-    function isReadOnly($args)
+    function isReadOnly(array $args=array())
     {
         return true;
     }
@@ -151,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)) {
@@ -171,7 +158,6 @@ class ApiSubscriptionsAction extends ApiBareAuthAction
      *
      * @return string etag
      */
-
     function etag()
     {
         if (!empty($this->profiles) && (count($this->profiles) > 0)) {
@@ -181,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))
@@ -201,7 +189,6 @@ class ApiSubscriptionsAction extends ApiBareAuthAction
      *
      * @return void
      */
-
     function showProfiles($include_statuses = true)
     {
         switch ($this->format) {
@@ -229,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;
         }
@@ -240,7 +228,6 @@ class ApiSubscriptionsAction extends ApiBareAuthAction
      *
      * @return void
      */
-
     function showIds()
     {
         switch ($this->format) {
@@ -259,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;
         }
     }
-
 }