summaryrefslogtreecommitdiff
path: root/plugins/UserFlag
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/UserFlag')
-rw-r--r--plugins/UserFlag/UserFlagPlugin.php25
-rw-r--r--plugins/UserFlag/User_flag_profile.php21
-rw-r--r--plugins/UserFlag/adminprofileflag.php113
-rw-r--r--plugins/UserFlag/flagprofile.php80
-rw-r--r--plugins/UserFlag/flagprofileform.php96
5 files changed, 177 insertions, 158 deletions
diff --git a/plugins/UserFlag/UserFlagPlugin.php b/plugins/UserFlag/UserFlagPlugin.php
index fe4a74869..4d8671c72 100644
--- a/plugins/UserFlag/UserFlagPlugin.php
+++ b/plugins/UserFlag/UserFlagPlugin.php
@@ -48,16 +48,7 @@ class UserFlagPlugin extends Plugin
$schema = Schema::get();
// For storing user-submitted flags on profiles
-
- $schema->ensureTable('user_flag_profile',
- array(new ColumnDef('profile_id', 'integer', null,
- false, 'PRI'),
- new ColumnDef('user_id', 'integer', null,
- false, 'PRI'),
- new ColumnDef('created', 'datetime', null,
- false, 'MUL'),
- new ColumnDef('cleared', 'datetime', null,
- true, 'MUL')));
+ $schema->ensureDataObject('User_flag_profile');
return true;
}
@@ -122,7 +113,11 @@ class UserFlagPlugin extends Plugin
if (!empty($user)) {
- $form = new FlagProfileForm($item->action, $item->profile);
+ list($action, $args) = $item->action->returnToArgs();
+
+ $args['action'] = $action;
+
+ $form = new FlagProfileForm($item->action, $item->profile, $args);
$form->show();
}
@@ -140,4 +135,12 @@ class UserFlagPlugin extends Plugin
return true;
}
+
+ function onEndShowScripts($action)
+ {
+ $action->elementStart('script', array('type' => 'text/javascript'));
+ $action->raw('/*<![CDATA[*/ SN.U.FormXHR($(".form_entity_flag")); /*]]>*/');
+ $action->elementEnd('script');
+ return true;
+ }
}
diff --git a/plugins/UserFlag/User_flag_profile.php b/plugins/UserFlag/User_flag_profile.php
index 30bd4ae68..2fb27912d 100644
--- a/plugins/UserFlag/User_flag_profile.php
+++ b/plugins/UserFlag/User_flag_profile.php
@@ -21,9 +21,9 @@ if (!defined('STATUSNET')) {
exit(1);
}
-require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
+require_once INSTALLDIR.'/classes/Plugin_DataObject.php';
-class User_flag_profile extends Memcached_DataObject
+class User_flag_profile extends Plugin_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
@@ -65,4 +65,21 @@ class User_flag_profile extends Memcached_DataObject
return !empty($ufp);
}
+
+ /**
+ * Get the TableDef object that represents the table backing this class
+ * @return TableDef TableDef instance
+ */
+ function tableDef()
+ {
+ return new TableDef($this->__table,
+ array(new ColumnDef('profile_id', 'integer', null,
+ false, 'PRI'),
+ new ColumnDef('user_id', 'integer', null,
+ false, 'PRI'),
+ new ColumnDef('created', 'datetime', null,
+ false, 'MUL'),
+ new ColumnDef('cleared', 'datetime', null,
+ true, 'MUL')));
+ }
}
diff --git a/plugins/UserFlag/adminprofileflag.php b/plugins/UserFlag/adminprofileflag.php
index b264beecb..1ac76b506 100644
--- a/plugins/UserFlag/adminprofileflag.php
+++ b/plugins/UserFlag/adminprofileflag.php
@@ -53,6 +53,8 @@ class AdminprofileflagAction extends Action
function prepare($args)
{
+ parent::prepare($args);
+
return true;
}
@@ -83,6 +85,117 @@ class AdminprofileflagAction extends Action
function showContent()
{
+ $profile = $this->getProfiles();
+
+ $pl = new FlaggedProfileList($profile, $this);
+
+ $pl->show();
+ }
+
+ function getProfiles()
+ {
+ $ufp = new User_flag_profile();
+
+ $ufp->selectAdd();
+ $ufp->selectAdd('profile_id');
+ $ufp->selectAdd('count(*) as flag_count');
+
+ $ufp->whereAdd('cleared is NULL');
+
+ $ufp->groupBy('profile_id');
+ $ufp->orderBy('flag_count DESC');
+
+ $profiles = array();
+
+ if ($ufp->find()) {
+ while ($ufp->fetch()) {
+ $profile = Profile::staticGet('id', $ufp->profile_id);
+ if (!empty($profile)) {
+ $profiles[] = $profile;
+ }
+ }
+ }
+
+ $ufp->free();
+
+ return new ArrayWrapper($profiles);
+ }
+}
+
+class FlaggedProfileList extends ProfileList {
+
+ function newListItem($profile)
+ {
+ return new FlaggedProfileListItem($this->profile, $this->action);
}
}
+class FlaggedProfileListItem extends ProfileListItem
+{
+ var $user = null;
+ var $r2args = null;
+
+ function showActions()
+ {
+ $this->user = common_current_user();
+
+ list($action, $this->r2args) = $this->out->returnToArgs();
+
+ $this->r2args['action'] = $action;
+
+ $this->startActions();
+ if (Event::handle('StartProfileListItemActionElements', array($this))) {
+ $this->showSandboxButton();
+ $this->showSilenceButton();
+ $this->showDeleteButton();
+ $this->showClearButton();
+ Event::handle('EndProfileListItemActionElements', array($this));
+ }
+ $this->endActions();
+ }
+
+ function showSandboxButton()
+ {
+ if ($this->user->hasRight(Right::SANDBOXUSER)) {
+ $this->out->elementStart('li', 'entity_sandbox');
+ if ($this->profile->isSandboxed()) {
+ $usf = new UnSandboxForm($this->out, $this->profile, $this->r2args);
+ $usf->show();
+ } else {
+ $sf = new SandboxForm($this->out, $this->profile, $this->r2args);
+ $sf->show();
+ }
+ $this->out->elementEnd('li');
+ }
+ }
+
+ function showSilenceButton()
+ {
+ if ($this->user->hasRight(Right::SILENCEUSER)) {
+ $this->out->elementStart('li', 'entity_silence');
+ if ($this->profile->isSilenced()) {
+ $usf = new UnSilenceForm($this->out, $this->profile, $this->r2args);
+ $usf->show();
+ } else {
+ $sf = new SilenceForm($this->out, $this->profile, $this->r2args);
+ $sf->show();
+ }
+ $this->out->elementEnd('li');
+ }
+ }
+
+ function showDeleteButton()
+ {
+
+ if ($this->user->hasRight(Right::DELETEUSER)) {
+ $this->out->elementStart('li', 'entity_delete');
+ $df = new DeleteUserForm($this->out, $this->profile, $this->r2args);
+ $df->show();
+ $this->out->elementEnd('li');
+ }
+ }
+
+ function showClearButton()
+ {
+ }
+}
diff --git a/plugins/UserFlag/flagprofile.php b/plugins/UserFlag/flagprofile.php
index c72b74c6a..8ff2f1f72 100644
--- a/plugins/UserFlag/flagprofile.php
+++ b/plugins/UserFlag/flagprofile.php
@@ -41,11 +41,8 @@ if (!defined('STATUSNET')) {
* @link http://status.net/
*/
-class FlagprofileAction extends Action
+class FlagprofileAction extends ProfileFormAction
{
- var $profile = null;
- var $flag = null;
-
/**
* Take arguments for running
*
@@ -56,34 +53,14 @@ class FlagprofileAction extends Action
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
+ assert(!empty($this->profile)); // checked above
if (User_flag_profile::exists($this->profile->id,
$user->id))
@@ -96,32 +73,12 @@ class FlagprofileAction extends Action
}
/**
- * Handle request
- *
- * @param array $args $_REQUEST args; handled in prepare()
+ * Handle POST
*
* @return void
*/
- function handle($args)
- {
- parent::handle($args);
-
- $this->flagProfile();
- $this->returnTo();
- }
-
- function title() {
- return _('Flag profile');
- }
-
- /**
- * save the profile flag
- *
- * @return void
- */
-
- function flagProfile()
+ function handlePost()
{
$user = common_current_user();
@@ -135,25 +92,24 @@ class FlagprofileAction extends Action
$ufp->created = common_sql_now();
if (!$ufp->insert()) {
- throw new ServerException(sprintf(_("Couldn't flag profile '%s' with flag '%s'."),
- $this->profile->nickname, $this->flag));
+ throw new ServerException(sprintf(_("Couldn't flag profile '%s' for review."),
+ $this->profile->nickname));
}
$ufp->free();
}
- function returnTo()
- {
- // 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);
+ function ajaxResults() {
+ 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');
}
}
diff --git a/plugins/UserFlag/flagprofileform.php b/plugins/UserFlag/flagprofileform.php
index 0811dbb9d..262dad4a7 100644
--- a/plugins/UserFlag/flagprofileform.php
+++ b/plugins/UserFlag/flagprofileform.php
@@ -45,108 +45,38 @@ require_once INSTALLDIR.'/lib/form.php';
* @link http://status.net/
*/
-class FlagProfileForm extends Form
+class FlagProfileForm extends ProfileActionForm
{
/**
- * Profile of profile to flag
- */
-
- var $profile = null;
-
- /**
- * Return-to args
- */
-
- var $args = null;
-
- /**
- * Constructor
- *
- * @param HTMLOutputter $out output channel
- * @param Profile $profile profile of user to flag
- * @param array $args return-to args
- */
-
- function __construct($out=null, $profile=null, $args=null)
- {
- parent::__construct($out);
-
- $this->profile = $profile;
- $this->args = $args;
- }
-
- /**
- * ID of the form
- *
- * @return int ID of the form
- */
-
- function id()
- {
- return 'flagprofile-' . $this->profile->id;
- }
-
- /**
- * class of the form
+ * Action this form provides
*
- * @return string class of the form
+ * @return string Name of the action, lowercased.
*/
- function formClass()
+ function target()
{
- return 'form_profile_flag';
+ return 'flagprofile';
}
/**
- * Action of the form
+ * Title of the form
*
- * @return string URL of the action
+ * @return string Title of the form, internationalized
*/
- function action()
- {
- return common_local_url('flagprofile');
- }
-
- /**
- * Legend of the Form
- *
- * @return void
- */
- function formLegend()
+ function title()
{
- $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);
- }
- }
+ return _('Flag');
}
/**
- * Action elements
+ * Description of the form
*
- * @return void
+ * @return string description of the form, internationalized
*/
- function formActions()
+ function description()
{
- $this->out->submit('submit', _('Flag'), 'submit', null, _('Flag profile for review'));
+ return _('Flag profile for review');
}
}