make profile flag actions work like other profile actions

This commit is contained in:
Evan Prodromou 2009-11-16 18:24:59 +01:00
parent bea580873f
commit 55d00a3a90
2 changed files with 31 additions and 159 deletions

View File

@ -41,11 +41,8 @@ if (!defined('STATUSNET')) {
* @link http://status.net/ * @link http://status.net/
*/ */
class FlagprofileAction extends Action class FlagprofileAction extends ProfileFormAction
{ {
var $profile = null;
var $flag = null;
/** /**
* Take arguments for running * Take arguments for running
* *
@ -56,34 +53,14 @@ class FlagprofileAction extends Action
function prepare($args) function prepare($args)
{ {
parent::prepare($args); if (!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.'));
return false; return false;
} }
$user = common_current_user(); $user = common_current_user();
assert(!empty($user)); // checked above assert(!empty($user)); // checked above
assert(!empty($this->profile)); // checked above
if (User_flag_profile::exists($this->profile->id, if (User_flag_profile::exists($this->profile->id,
$user->id)) $user->id))
@ -96,46 +73,12 @@ class FlagprofileAction extends Action
} }
/** /**
* Handle request * Handle POST
*
* @param array $args $_REQUEST args; handled in prepare()
* *
* @return void * @return void
*/ */
function handle($args) function handlePost()
{
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();
}
}
function title() {
return _('Flag profile');
}
/**
* save the profile flag
*
* @return void
*/
function flagProfile()
{ {
$user = common_current_user(); $user = common_current_user();
@ -149,25 +92,24 @@ class FlagprofileAction extends Action
$ufp->created = common_sql_now(); $ufp->created = common_sql_now();
if (!$ufp->insert()) { if (!$ufp->insert()) {
throw new ServerException(sprintf(_("Couldn't flag profile '%s' with flag '%s'."), throw new ServerException(sprintf(_("Couldn't flag profile '%s' for review."),
$this->profile->nickname, $this->flag)); $this->profile->nickname));
} }
$ufp->free(); $ufp->free();
} }
function returnTo() function ajaxResults() {
{ header('Content-Type: text/xml;charset=utf-8');
// Now, gotta figure where we go back to $this->xw->startDocument('1.0', 'UTF-8');
foreach ($this->args as $k => $v) { $this->elementStart('html');
if ($k == 'returnto-action') { $this->elementStart('head');
$action = $v; $this->element('title', null, _('Flagged for review'));
} elseif (substr($k, 0, 9) == 'returnto-') { $this->elementEnd('head');
$args[substr($k, 9)] = $v; $this->elementStart('body');
} $this->element('p', 'flagged', _('Flagged'));
} $this->elementEnd('body');
$this->elementEnd('html');
common_redirect(common_local_url($action, $args), 303);
} }
} }

View File

@ -45,108 +45,38 @@ require_once INSTALLDIR.'/lib/form.php';
* @link http://status.net/ * @link http://status.net/
*/ */
class FlagProfileForm extends Form class FlagProfileForm extends ProfileActionForm
{ {
/** /**
* Profile of profile to flag * Action this form provides
*/
var $profile = null;
/**
* Return-to args
*/
var $args = null;
/**
* Constructor
* *
* @param HTMLOutputter $out output channel * @return string Name of the action, lowercased.
* @param Profile $profile profile of user to flag
* @param array $args return-to args
*/ */
function __construct($out=null, $profile=null, $args=null) function target()
{ {
parent::__construct($out); return 'flagprofile';
$this->profile = $profile;
$this->args = $args;
} }
/** /**
* ID of the form * Title of the form
* *
* @return int ID of the form * @return string Title of the form, internationalized
*/ */
function id() function title()
{ {
return 'flagprofile-' . $this->profile->id; return _('Flag');
} }
/** /**
* class of the form * Description of the form
* *
* @return string class of the form * @return string description of the form, internationalized
*/ */
function formClass() function description()
{ {
return 'form_entity_flag'; return _('Flag profile for review');
}
/**
* Action of the form
*
* @return string URL of the action
*/
function action()
{
return common_local_url('flagprofile');
}
/**
* Legend of the Form
*
* @return void
*/
function formLegend()
{
$this->out->element('legend', null, _('Flag profile for review'));
}
/**
* Data elements of the form
*
* @return void
*/
function formData()
{
// TODO: let the user choose a flag
$this->out->hidden('flagprofileto-' . $this->profile->id,
$this->profile->id,
'flagprofileto');
if ($this->args) {
foreach ($this->args as $k => $v) {
$this->out->hidden('returnto-' . $k, $v);
}
}
}
/**
* Action elements
*
* @return void
*/
function formActions()
{
$this->out->submit('submit', _('Flag'), 'submit', null, _('Flag profile for review'));
} }
} }