From 09f4d1ef236c160afe6b9874793e43b501e1120a Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 9 Oct 2009 13:35:54 -0700 Subject: New actions for blocks via API --- actions/apiblockcreate.php | 121 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 actions/apiblockcreate.php (limited to 'actions/apiblockcreate.php') diff --git a/actions/apiblockcreate.php b/actions/apiblockcreate.php new file mode 100644 index 000000000..ff303863e --- /dev/null +++ b/actions/apiblockcreate.php @@ -0,0 +1,121 @@ +. + * + * @category API + * @package StatusNet + * @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 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +require_once INSTALLDIR . '/lib/apiauth.php'; + +/** + * Blocks the user specified in the ID parameter as the authenticating user. + * Destroys a friendship to the blocked user if it exists. Returns the + * blocked user in the requested format when successful. + * + * @category API + * @package StatusNet + * @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 ApiBlockCreateAction extends ApiAuthAction +{ + var $format = null; + var $user = null; + var $other = null; + + /** + * Take arguments for running + * + * @param array $args $_REQUEST args + * + * @return boolean success flag + * + */ + + function prepare($args) + { + parent::prepare($args); + + if ($this->requiresAuth()) { + if ($this->checkBasicAuthUser() == false) { + return; + } + } + + $this->user = $this->auth_user; + $this->other = $this->getTargetUser($this->arg('id')); + $this->format = $this->arg('format'); + + return true; + } + + /** + * Handle the request + * + * Save the new message + * + * @param array $args $_REQUEST data (unused) + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + + if ($_SERVER['REQUEST_METHOD'] != 'POST') { + $this->clientError( + _('This method requires a POST.'), + 400, + $this->format + ); + return; + } + + if (empty($this->user) || empty($this->other)) { + $this->clientError(_('No such user!'), 404, $this->format); + return; + } + + if ($this->user->hasBlocked($this->other) + || $this->user->block($this->other) + ) { + $this->init_document($this->format); + $this->show_profile($this->other, $this->format); + $this->end_document($this->format); + } else { + $this->serverError(_('Block user failed.'), 500, $this->format); + } + + } + +} + -- cgit v1.2.3-54-g00ecf