Ejemplo n.º 1
0
 /**
  * Handle POST
  *
  * @return void
  */
 function handlePost()
 {
     $user = common_current_user();
     assert(!empty($user));
     assert(!empty($this->profile));
     // throws an exception on error
     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);
     }
     if ($this->boolean('ajax')) {
         $this->ajaxResults();
     }
 }
 /**
  * Create a new flag
  *
  * @param integer $user_id    ID of user who's flagging
  * @param integer $profile_id ID of profile being flagged
  *
  * @return boolean success flag
  */
 static function create($user_id, $profile_id)
 {
     $ufp = new User_flag_profile();
     $ufp->profile_id = $profile_id;
     $ufp->user_id = $user_id;
     $ufp->created = common_sql_now();
     if (!$ufp->insert()) {
         $msg = sprintf(_("Couldn't flag profile '%d' for review."), $profile_id);
         throw new ServerException($msg);
     }
     $ufp->free();
     return true;
 }
Ejemplo n.º 3
0
 /**
  * Handle POST
  *
  * Executes the actions; deletes all flags
  *
  * @return void
  */
 function handlePost()
 {
     $ufp = new User_flag_profile();
     $result = $ufp->query('UPDATE user_flag_profile ' . 'SET cleared = now() ' . 'WHERE cleared is null ' . 'AND profile_id = ' . $this->profile->id);
     if ($result == false) {
         // TRANS: Server exception given when flags could not be cleared.
         $msg = sprintf(_m('Couldn\'t clear flags for profile "%s".'), $this->profile->nickname);
         throw new ServerException($msg);
     }
     $ufp->free();
     if ($this->boolean('ajax')) {
         $this->ajaxResults();
     }
 }
Ejemplo n.º 4
0
 /**
  * Create a new flag
  *
  * @param integer $user_id    ID of user who's flagging
  * @param integer $profile_id ID of profile being flagged
  *
  * @return boolean success flag
  */
 static function create($user_id, $profile_id)
 {
     $ufp = new User_flag_profile();
     $ufp->profile_id = $profile_id;
     $ufp->user_id = $user_id;
     $ufp->created = common_sql_now();
     if (!$ufp->insert()) {
         // TRANS: Server exception.
         $msg = sprintf(_m('Couldn\'t flag profile "%d" for review.'), $profile_id);
         throw new ServerException($msg);
     }
     $ufp->free();
     return true;
 }
Ejemplo n.º 5
0
 /**
  * Optionally flag profile when a block happens
  *
  * We optionally add a flag when a profile has been blocked
  *
  * @param User    $user    User doing the block
  * @param Profile $profile Profile being blocked
  *
  * @return boolean hook result
  */
 function onEndBlockProfile($user, $profile)
 {
     if ($this->flagOnBlock && !User_flag_profile::exists($profile->id, $user->id)) {
         User_flag_profile::create($user->id, $profile->id);
     }
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Show a list of people who've flagged this profile
  *
  * @return void
  */
 function showFlaggersList()
 {
     $flaggers = array();
     $ufp = new User_flag_profile();
     $ufp->selectAdd();
     $ufp->selectAdd('user_id');
     $ufp->profile_id = $this->profile->id;
     $ufp->orderBy('created');
     if ($ufp->find()) {
         // XXX: this should always happen
         while ($ufp->fetch()) {
             $user = User::staticGet('id', $ufp->user_id);
             if (!empty($user)) {
                 // XXX: this would also be unusual
                 $flaggers[] = clone $user;
             }
         }
     }
     $cnt = count($flaggers);
     $others = 0;
     if ($cnt > self::MAX_FLAGGERS) {
         $flaggers = array_slice($flaggers, 0, self::MAX_FLAGGERS);
         $others = $cnt - self::MAX_FLAGGERS;
     }
     $lnks = array();
     foreach ($flaggers as $flagger) {
         $url = common_local_url('showstream', array('nickname' => $flagger->nickname));
         $lnks[] = XMLStringer::estring('a', array('href' => $url, 'class' => 'flagger'), $flagger->nickname);
     }
     if ($cnt > 0) {
         if ($others > 0) {
             $flagging_users = implode(', ', $lnks);
             // TRANS: Message displayed on a profile if it has been flagged.
             // TRANS: %1$s is a comma separated list of at most 5 user nicknames that flagged.
             // TRANS: %2$d is a positive integer of additional flagging users. Also used for the plural.
             $text .= sprintf(_m('Flagged by %1$s and %2$d other', 'Flagged by %1$s and %2$d others', $others), $flagging_users, $others);
         } else {
             // TRANS: Message displayed on a profile if it has been flagged.
             // TRANS: %s is a comma separated list of at most 5 user nicknames that flagged.
             $text .= sprintf(_m('Flagged by %s'), $flagging_users);
         }
         $this->out->elementStart('p', array('class' => 'flaggers'));
         $this->out->raw($text);
         $this->out->elementEnd('p');
     }
 }
 /**
  * Handle POST
  *
  * Executes the actions; deletes all flags
  *
  * @return void
  */
 function handlePost()
 {
     $ufp = new User_flag_profile();
     $result = $ufp->query('UPDATE user_flag_profile ' . 'SET cleared = now() ' . 'WHERE cleared is null ' . 'AND profile_id = ' . $this->profile->id);
     if ($result == false) {
         $msg = sprintf(_("Couldn't clear flags for profile '%s'."), $this->profile->nickname);
         throw new ServerException($msg);
     }
     $ufp->free();
     if ($this->boolean('ajax')) {
         $this->ajaxResults();
     }
 }
Ejemplo n.º 8
0
 /**
  * Show a list of people who've flagged this profile
  *
  * @return void
  */
 function showFlaggersList()
 {
     $flaggers = array();
     $ufp = new User_flag_profile();
     $ufp->selectAdd();
     $ufp->selectAdd('user_id');
     $ufp->profile_id = $this->profile->id;
     $ufp->orderBy('created');
     if ($ufp->find()) {
         // XXX: this should always happen
         while ($ufp->fetch()) {
             $user = User::staticGet('id', $ufp->user_id);
             if (!empty($user)) {
                 // XXX: this would also be unusual
                 $flaggers[] = clone $user;
             }
         }
     }
     $cnt = count($flaggers);
     $others = 0;
     if ($cnt > self::MAX_FLAGGERS) {
         $flaggers = array_slice($flaggers, 0, self::MAX_FLAGGERS);
         $others = $cnt - self::MAX_FLAGGERS;
     }
     $lnks = array();
     foreach ($flaggers as $flagger) {
         $url = common_local_url('showstream', array('nickname' => $flagger->nickname));
         $lnks[] = XMLStringer::estring('a', array('href' => $url, 'class' => 'flagger'), $flagger->nickname);
     }
     if ($cnt > 0) {
         $text = _('Flagged by ');
         $text .= implode(', ', $lnks);
         if ($others > 0) {
             $text .= sprintf(_(' and %d others'), $others);
         }
         $this->out->elementStart('p', array('class' => 'flaggers'));
         $this->out->raw($text);
         $this->out->elementEnd('p');
     }
 }
 /**
  * Handle POST
  *
  * @return void
  */
 function handlePost()
 {
     $user = common_current_user();
     assert(!empty($user));
     assert(!empty($this->profile));
     // throws an exception on error
     User_flag_profile::create($user->id, $this->profile->id);
     if ($this->boolean('ajax')) {
         $this->ajaxResults();
     }
 }