X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FUserFlag%2Fflagprofile.php;h=7096d3748e4cb9fd3cfe2edab43264799d71e6a2;hb=87d46e1ae5e5effcc985021ff5af3f10815f3d3c;hp=77c86b233bd50e800a5e44baa69ab12e9d2795fb;hpb=086759f32ab6d2c5aadecb57941e7e14015b8bd6;p=quix0rs-gnu-social.git diff --git a/plugins/UserFlag/flagprofile.php b/plugins/UserFlag/flagprofile.php index 77c86b233b..7096d3748e 100644 --- a/plugins/UserFlag/flagprofile.php +++ b/plugins/UserFlag/flagprofile.php @@ -40,12 +40,8 @@ if (!defined('STATUSNET')) { * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3 * @link http://status.net/ */ - -class FlagprofileAction extends Action +class FlagprofileAction extends ProfileFormAction { - var $profile = null; - var $flag = null; - /** * Take arguments for running * @@ -53,44 +49,16 @@ class FlagprofileAction extends Action * * @return boolean success flag */ - function prepare($args) { - parent::prepare($args); - - if ($_SERVER['REQUEST_METHOD'] != 'POST') { - throw new ClientException(_('Action only accepts POST')); - } - - if (!common_logged_in()) { - $this->clientError(_('Not logged in.')); - return false; - } - - $id = $this->trimmed('flagprofileto'); - - if (!$id) { - $this->clientError(_('No profile specified.')); - return false; - } - - $this->profile = Profile::staticGet('id', $id); - - if (empty($this->profile)) { - $this->clientError(_('No profile with that ID.')); + if (!parent::prepare($args)) { return false; } $user = common_current_user(); assert(!empty($user)); // checked above - - if (User_flag_profile::exists($this->profile->id, - $user->id)) - { - $this->clientError(_('Flag already exists.')); - return false; - } + assert(!empty($this->profile)); // checked above return true; } @@ -98,76 +66,68 @@ class FlagprofileAction extends Action /** * Handle request * + * Overriding the base Action's handle() here to deal check + * for Ajax and return an HXR response if necessary + * * @param array $args $_REQUEST args; handled in prepare() * * @return void */ - function handle($args) { - parent::handle($args); - - $this->flagProfile(); - - if ($this->boolean('ajax')) { - header('Content-Type: text/xml;charset=utf-8'); - $this->xw->startDocument('1.0', 'UTF-8'); - $this->elementStart('html'); - $this->elementStart('head'); - $this->element('title', null, _('Flagged for review')); - $this->elementEnd('head'); - $this->elementStart('body'); - $this->element('p', 'flagged', _('Flagged')); - $this->elementEnd('body'); - $this->elementEnd('html'); - } else { - $this->returnTo(); + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + $this->handlePost(); + if (!$this->boolean('ajax')) { + $this->returnToPrevious(); + } } } - function title() { - return _('Flag profile'); - } - /** - * save the profile flag + * Handle POST * * @return void */ - - function flagProfile() + function handlePost() { $user = common_current_user(); assert(!empty($user)); assert(!empty($this->profile)); - $ufp = new User_flag_profile(); - - $ufp->profile_id = $this->profile->id; - $ufp->user_id = $user->id; - $ufp->created = common_sql_now(); + // throws an exception on error - if (!$ufp->insert()) { - throw new ServerException(sprintf(_("Couldn't flag profile '%s' with flag '%s'."), - $this->profile->nickname, $this->flag)); + if (User_flag_profile::exists($this->profile->id, + $user->id)) { + // We'll return to the profile page (or return the updated AJAX form) + // showing the current state, so no harm done. + } else { + User_flag_profile::create($user->id, $this->profile->id); } - $ufp->free(); + if ($this->boolean('ajax')) { + $this->ajaxResults(); + } } - function returnTo() + /** + * Return results as AJAX message + * + * @return void + */ + function ajaxResults() { - // Now, gotta figure where we go back to - foreach ($this->args as $k => $v) { - if ($k == 'returnto-action') { - $action = $v; - } elseif (substr($k, 0, 9) == 'returnto-') { - $args[substr($k, 9)] = $v; - } - } - - common_redirect(common_local_url($action, $args), 303); + header('Content-Type: text/xml;charset=utf-8'); + $this->xw->startDocument('1.0', 'UTF-8'); + $this->elementStart('html'); + $this->elementStart('head'); + // TRANS: AJAX form title for a flagged profile. + $this->element('title', null, _m('Flagged for review')); + $this->elementEnd('head'); + $this->elementStart('body'); + // TRANS: Body text for AJAX form when a profile has been flagged for review. + $this->element('p', 'flagged', _m('Flagged')); + $this->elementEnd('body'); + $this->elementEnd('html'); } } -