summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2009-11-01 23:25:30 -0500
committerEvan Prodromou <evan@status.net>2009-11-01 23:25:30 -0500
commitf2b642ce822c480cfc418c38106cc18c3a428cf4 (patch)
tree9e9467e9e205bcd6d975367f83bab222820f0fd9 /plugins
parent70e4580c3f2e8d400e53babe1f0aa8b9fb53aa52 (diff)
insert profile flags more or less correctly
Diffstat (limited to 'plugins')
-rw-r--r--plugins/UserFlag/Profile_flag.php2
-rw-r--r--plugins/UserFlag/UserFlagPlugin.php17
-rw-r--r--plugins/UserFlag/User_flag_profile.php8
-rw-r--r--plugins/UserFlag/flagprofile.php73
-rw-r--r--plugins/UserFlag/flagprofileform.php1
5 files changed, 98 insertions, 3 deletions
diff --git a/plugins/UserFlag/Profile_flag.php b/plugins/UserFlag/Profile_flag.php
index 1a99f1061..812d11d51 100644
--- a/plugins/UserFlag/Profile_flag.php
+++ b/plugins/UserFlag/Profile_flag.php
@@ -39,6 +39,8 @@ class Profile_flag extends Memcached_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
+ const DEFAULTFLAG = 'review'; // default flag
+
function table() {
return array(
'flag' => DB_DATAOBJECT_STR,
diff --git a/plugins/UserFlag/UserFlagPlugin.php b/plugins/UserFlag/UserFlagPlugin.php
index 003c066af..fc56249e6 100644
--- a/plugins/UserFlag/UserFlagPlugin.php
+++ b/plugins/UserFlag/UserFlagPlugin.php
@@ -128,9 +128,20 @@ class UserFlagPlugin extends Plugin
if (!empty($user)) {
- $form = new FlagProfileForm($action, $profile);
-
- $form->show();
+ $action->elementStart('li', 'entity_flag');
+
+ if (User_flag_profile::exists($profile->id, $user->id,
+ Profile_flag::DEFAULTFLAG)) {
+ $action->element('span',
+ _('Flagged for review'));
+ } else {
+ $form = new FlagProfileForm($action, $profile,
+ array('action' => 'showstream',
+ 'nickname' => $profile->nickname));
+ $form->show();
+ }
+
+ $action->elementEnd('li');
}
return true;
diff --git a/plugins/UserFlag/User_flag_profile.php b/plugins/UserFlag/User_flag_profile.php
index 99dce7529..895da5323 100644
--- a/plugins/UserFlag/User_flag_profile.php
+++ b/plugins/UserFlag/User_flag_profile.php
@@ -57,4 +57,12 @@ class User_flag_profile extends Memcached_DataObject
{
return Memcached_DataObject::pkeyGet('User_flag_profile', $kv);
}
+
+ static function exists($profile_id, $user_id, $flag)
+ {
+ $ufp = User_flag_profile::pkeyGet(array('profile_id' => $profile_id,
+ 'user_id' => $user_id));
+
+ return !empty($ufp);
+ }
}
diff --git a/plugins/UserFlag/flagprofile.php b/plugins/UserFlag/flagprofile.php
index 794151099..f128b9c40 100644
--- a/plugins/UserFlag/flagprofile.php
+++ b/plugins/UserFlag/flagprofile.php
@@ -44,6 +44,7 @@ if (!defined('STATUSNET')) {
class FlagprofileAction extends Action
{
var $profile = null;
+ var $flag = null;
/**
* Take arguments for running
@@ -55,10 +56,49 @@ 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.'));
+ return false;
+ }
+
+ $this->flag = $this->trimmed('flag');
+
+ if (empty($this->flag)) {
+ $this->flag = Profile_flag::DEFAULTFLAG;
+ }
+
+ $user = common_current_user();
+
+ assert(!empty($user)); // checked above
+
+ if (User_flag_profile::exists($this->profile->id,
+ $user->id,
+ $this->flag))
+ {
+ $this->clientError(_('Flag already exists.'));
+ return false;
+ }
+
return true;
}
@@ -90,6 +130,39 @@ class FlagprofileAction extends Action
function flagProfile()
{
+ $user = common_current_user();
+
+ assert(!empty($user));
+ assert(!empty($this->profile));
+ assert(!empty($this->flag));
+
+ $ufp = new User_flag_profile();
+
+ $ufp->profile_id = $this->profile->id;
+ $ufp->user_id = $user->id;
+ $ufp->flag = $this->flag;
+ $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));
+ }
+
+ $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);
}
}
diff --git a/plugins/UserFlag/flagprofileform.php b/plugins/UserFlag/flagprofileform.php
index d9f116e7f..3f4834aac 100644
--- a/plugins/UserFlag/flagprofileform.php
+++ b/plugins/UserFlag/flagprofileform.php
@@ -131,6 +131,7 @@ class FlagProfileForm extends Form
$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);