]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/apistatusesdestroy.php
Merge branch 'nightly' into 'nightly'
[quix0rs-gnu-social.git] / actions / apistatusesdestroy.php
index 485eae66eab0c304c0816f828159bc137b029917..0bad3da5dfc9bf6816f6b84a63532df9cb5eb8ce 100644 (file)
  * @link      http://status.net/
  */
 
-if (!defined('STATUSNET')) {
-    exit(1);
-}
-
-require_once INSTALLDIR . '/lib/apiauth.php';
+if (!defined('GNUSOCIAL')) { exit(1); }
 
 /**
  * Deletes one of the authenticating user's statuses (notices).
@@ -55,88 +51,48 @@ require_once INSTALLDIR . '/lib/apiauth.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 ApiStatusesDestroyAction extends ApiAuthAction
 {
-    var $status = null;
-
-    /**
-     * Take arguments for running
-     *
-     * @param array $args $_REQUEST args
-     *
-     * @return boolean success flag
-     *
-     */
-
-    function prepare($args)
+    protected function prepare(array $args=array())
     {
         parent::prepare($args);
 
-        $this->user = $this->auth_user;
-        $this->notice_id = (int)$this->trimmed('id');
+        if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) {
+            // TRANS: Client error displayed trying to delete a status not using POST or DELETE.
+            // TRANS: POST and DELETE should not be translated.
+            throw new ClientException(_('This method requires a POST or DELETE.'));
+        }
 
-        if (empty($notice_id)) {
-            $this->notice_id = (int)$this->arg('id');
+        // FIXME: Return with a Not Acceptable status code?
+        if (!in_array($this->format, array('xml', 'json'))) {
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            throw new ClientException(_('API method not found.'), 404);
         }
 
-        $this->notice = Notice::staticGet((int)$this->notice_id);
+        try {
+            $this->notice = Notice::getByID($this->trimmed('id'));
+        } catch (NoResultException $e) {
+            // TRANS: Client error displayed trying to delete a status with an invalid ID.
+            throw new ClientException(_('No status found with that ID.'), 404);
+        }
 
         return true;
      }
 
-    /**
-     * Handle the request
-     *
-     * Delete the notice and all related replies
-     *
-     * @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.'),
-                404
-            );
-            return;
+        if (!$this->scoped->sameAs($this->notice->getProfile()) && !$this->scoped->hasRight(Right::DELETEOTHERSNOTICE)) {
+            // TRANS: Client error displayed trying to delete a status of another user.
+            throw new AuthorizationException(_('You may not delete another user\'s status.'));
         }
 
-        if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) {
-            $this->clientError(
-                _('This method requires a POST or DELETE.'),
-                400,
-                $this->format
-            );
-            return;
-        }
-
-        if (empty($this->notice)) {
-            $this->clientError(
-                _('No status found with that ID.'),
-                404, $this->format
-            );
-            return;
-        }
-
-        if ($this->user->id == $this->notice->profile_id) {
-            if (Event::handle('StartDeleteOwnNotice', array($this->user, $this->notice))) {
-                $this->notice->delete();
-                Event::handle('EndDeleteOwnNotice', array($this->user, $this->notice));
-            }
-               $this->showNotice();
-        } else {
-            $this->clientError(
-                _('You may not delete another user\'s status.'),
-                403,
-                $this->format
-            );
+        if (Event::handle('StartDeleteOwnNotice', array($this->scoped->getUser(), $this->notice))) {
+            $this->notice->deleteAs($this->scoped);
+            Event::handle('EndDeleteOwnNotice', array($this->scoped->getUser(), $this->notice));
         }
+        $this->showNotice();
     }
 
     /**
@@ -144,7 +100,6 @@ class ApiStatusesDestroyAction extends ApiAuthAction
      *
      * @return void
      */
-
     function showNotice()
     {
         if (!empty($this->notice)) {
@@ -155,5 +110,4 @@ class ApiStatusesDestroyAction extends ApiAuthAction
             }
         }
     }
-
 }