Example #1
0
 /**
  * Class handler.
  *
  * @param array $args query arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if (!common_logged_in()) {
         // TRANS: Client error displayed when trying to remove a favorite while not logged in.
         $this->clientError(_('Not logged in.'));
         return;
     }
     $user = common_current_user();
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)));
         return;
     }
     $id = $this->trimmed('notice');
     $notice = Notice::staticGet($id);
     $token = $this->trimmed('token-' . $notice->id);
     if (!$token || $token != common_session_token()) {
         // TRANS: Client error displayed when the session token does not match or is not given.
         $this->clientError(_('There was a problem with your session token. Try again, please.'));
         return;
     }
     $fave = new Fave();
     $fave->user_id = $user->id;
     $fave->notice_id = $notice->id;
     if (!$fave->find(true)) {
         // TRANS: Client error displayed when trying to remove favorite status for a notice that is not a favorite.
         $this->clientError(_('This notice is not a favorite!'));
         return;
     }
     $result = $fave->delete();
     if (!$result) {
         common_log_db_error($fave, 'DELETE', __FILE__);
         // TRANS: Server error displayed when removing a favorite from the database fails.
         $this->serverError(_('Could not delete favorite.'));
         return;
     }
     $user->blowFavesCache();
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         // TRANS: Title for page on which favorites can be added.
         $this->element('title', null, _('Add to favorites'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $favor = new FavorForm($this, $notice);
         $favor->show();
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)), 303);
     }
 }
Example #2
0
 /**
  * Class handler.
  * 
  * @param array $args query arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if (!common_logged_in()) {
         $this->clientError(_('Not logged in.'));
         return;
     }
     $user = common_current_user();
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)));
         return;
     }
     $id = $this->trimmed('notice');
     $notice = Notice::staticGet($id);
     $token = $this->trimmed('token-' . $notice->id);
     if (!$token || $token != common_session_token()) {
         $this->clientError(_("There was a problem with your session token. Try again, please."));
         return;
     }
     $fave = new Fave();
     $fave->user_id = $this->id;
     $fave->notice_id = $notice->id;
     if (!$fave->find(true)) {
         $this->clientError(_('This notice is not a favorite!'));
         return;
     }
     $result = $fave->delete();
     if (!$result) {
         common_log_db_error($fave, 'DELETE', __FILE__);
         $this->serverError(_('Could not delete favorite.'));
         return;
     }
     $user->blowFavesCache();
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         $this->element('title', null, _('Add to favorites'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $favor = new FavorForm($this, $notice);
         $favor->show();
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         common_redirect(common_local_url('showfavorites', array('nickname' => $user->nickname)));
     }
 }
Example #3
0
 /**
  * Class handler.
  *
  * @param array $args query arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     $profile = AnonymousFavePlugin::getAnonProfile();
     if (empty($profile) || $_SERVER['REQUEST_METHOD'] != 'POST') {
         $this->clientError(_m('Could not disfavor notice! Please make sure your browser has cookies enabled.'));
         return;
     }
     $id = $this->trimmed('notice');
     $notice = Notice::staticGet($id);
     $token = $this->trimmed('token-' . $notice->id);
     if (!$token || $token != common_session_token()) {
         // TRANS: Client error.
         $this->clientError(_m('There was a problem with your session token. Try again, please.'));
         return;
     }
     $fave = new Fave();
     $fave->user_id = $profile->id;
     $fave->notice_id = $notice->id;
     if (!$fave->find(true)) {
         // TRANS: Client error.
         $this->clientError(_m('This notice is not a favorite!'));
         return;
     }
     $result = $fave->delete();
     if (!$result) {
         common_log_db_error($fave, 'DELETE', __FILE__);
         // TRANS: Server error.
         $this->serverError(_m('Could not delete favorite.'));
         return;
     }
     $profile->blowFavesCache();
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         // TRANS: Title.
         $this->element('title', null, _m('Add to favorites'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $favor = new AnonFavorForm($this, $notice);
         $favor->show();
         $this->elementEnd('body');
         $this->elementEnd('html');
     } else {
         $this->returnToPrevious();
     }
 }
Example #4
0
 /**
  * Class handler.
  *
  * @param array $args query arguments
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     $profile = AnonymousFavePlugin::getAnonProfile();
     if (empty($profile) || $_SERVER['REQUEST_METHOD'] != 'POST') {
         $this->clientError(_m('Could not disfavor notice! Please make sure your browser has cookies enabled.'));
     }
     $id = $this->trimmed('notice');
     $notice = Notice::getKV($id);
     $token = $this->checkSessionToken();
     $fave = new Fave();
     $fave->user_id = $profile->id;
     $fave->notice_id = $notice->id;
     if (!$fave->find(true)) {
         throw new NoResultException($fave);
     }
     $result = $fave->delete();
     if (!$result) {
         common_log_db_error($fave, 'DELETE', __FILE__);
         // TRANS: Server error.
         $this->serverError(_m('Could not delete favorite.'));
     }
     Fave::blowCacheForProfileId($profile->id);
     if ($this->boolean('ajax')) {
         $this->startHTML('text/xml;charset=utf-8');
         $this->elementStart('head');
         // TRANS: Title.
         $this->element('title', null, _m('Add to favorites'));
         $this->elementEnd('head');
         $this->elementStart('body');
         $favor = new AnonFavorForm($this, $notice);
         $favor->show();
         $this->elementEnd('body');
         $this->endHTML();
     } else {
         $this->returnToPrevious();
     }
 }
 function getNoticeIds($offset, $limit, $since_id, $max_id)
 {
     $weightexpr = common_sql_weight('modified', common_config('popular', 'dropoff'));
     $cutoff = sprintf("modified > '%s'", common_sql_date(time() - common_config('popular', 'cutoff')));
     $fave = new Fave();
     $fave->selectAdd();
     $fave->selectAdd('notice_id');
     $fave->selectAdd("{$weightexpr} as weight");
     $fave->whereAdd($cutoff);
     $fave->orderBy('weight DESC');
     $fave->groupBy('notice_id');
     if (!is_null($offset)) {
         $fave->limit($offset, $limit);
     }
     // FIXME: $since_id, $max_id are ignored
     $ids = array();
     if ($fave->find()) {
         while ($fave->fetch()) {
             $ids[] = $fave->notice_id;
         }
     }
     return $ids;
 }
 public function onAppendUserActivityStreamObjects(UserActivityStream $uas, array &$objs)
 {
     $fave = new Fave();
     $fave->user_id = $uas->getUser()->id;
     if (!empty($uas->after)) {
         $fave->whereAdd("modified > '" . common_sql_date($uas->after) . "'");
     }
     if ($fave->find()) {
         while ($fave->fetch()) {
             $objs[] = clone $fave;
         }
     }
     return true;
 }
 /**
  * Handle the request
  *
  * Check the format and show the user info
  *
  * @param array $args $_REQUEST data (unused)
  *
  * @return void
  */
 function handle($args)
 {
     parent::handle($args);
     if ($_SERVER['REQUEST_METHOD'] != 'POST') {
         $this->clientError(_('This method requires a POST.'), 400, $this->format);
         return;
     }
     if (!in_array($this->format, array('xml', 'json'))) {
         $this->clientError(_('API method not found.'), 404, $this->format);
         return;
     }
     if (empty($this->notice)) {
         $this->clientError(_('No status found with that ID.'), 404, $this->format);
         return;
     }
     $fave = new Fave();
     $fave->user_id = $this->user->id;
     $fave->notice_id = $this->notice->id;
     if (!$fave->find(true)) {
         $this->clientError(_('That status is not a favorite.'), 403, $this->favorite);
         return;
     }
     $result = $fave->delete();
     if (!$result) {
         common_log_db_error($fave, 'DELETE', __FILE__);
         $this->clientError(_('Could not delete favorite.'), 404, $this->format);
         return;
     }
     $this->user->blowFavesCache();
     if ($this->format == 'xml') {
         $this->showSingleXmlStatus($this->notice);
     } elseif ($this->format == 'json') {
         $this->show_single_json_status($this->notice);
     }
 }
Example #8
0
 /**
  * Fetch a stream of favorites by profile
  *
  * @param integer $profileId Profile that faved
  * @param integer $offset    Offset from last
  * @param integer $limit     Number to get
  *
  * @return mixed stream of faves, use fetch() to iterate
  *
  * @todo Cache results
  * @todo integrate with Fave::stream()
  */
 static function byProfile($profileId, $offset, $limit)
 {
     $fav = new Fave();
     $fav->user_id = $profileId;
     $fav->orderBy('modified DESC');
     $fav->limit($offset, $limit);
     $fav->find();
     return $fav;
 }
Example #9
0
 function __construct($notice, $out = null)
 {
     parent::__construct($notice, $out);
     //TODO: Rewrite this
     //Showing number of favorites
     $fave = new Fave();
     $fave->notice_id = $this->notice->id;
     $cnt = 0;
     if ($fave->find()) {
         while ($fave->fetch()) {
             $cnt++;
         }
     }
     $this->faves = $cnt;
 }
Example #10
0
 function handle($channel)
 {
     $notice = $this->getNotice($this->other);
     $fave = new Fave();
     $fave->user_id = $this->user->id;
     $fave->notice_id = $notice->id;
     $fave->find();
     if ($fave->fetch()) {
         // TRANS: Error message text shown when a favorite could not be set because it has already been favorited.
         $channel->error($this->user, _('Could not create favorite: already favorited.'));
         return;
     }
     $fave = Fave::addNew($this->user->getProfile(), $notice);
     if (!$fave) {
         // TRANS: Error message text shown when a favorite could not be set.
         $channel->error($this->user, _('Could not create favorite.'));
         return;
     }
     // @fixme favorite notification should be triggered
     // at a lower level
     $other = User::staticGet('id', $notice->profile_id);
     if ($other && $other->id != $this->user->id) {
         if ($other->email && $other->emailnotifyfav) {
             mail_notify_fave($other, $this->user, $notice);
         }
     }
     $this->user->blowFavesCache();
     // TRANS: Text shown when a notice has been marked as favourite successfully.
     $channel->output($this->user, _('Notice marked as fave.'));
 }
Example #11
0
 function clearFaves()
 {
     $fave = new Fave();
     $fave->notice_id = $this->id;
     if ($fave->find()) {
         while ($fave->fetch()) {
             self::blow('fave:ids_by_user_own:%d', $fave->user_id);
             self::blow('fave:ids_by_user_own:%d;last', $fave->user_id);
             self::blow('fave:ids_by_user:%d', $fave->user_id);
             self::blow('fave:ids_by_user:%d;last', $fave->user_id);
             $fave->delete();
         }
     }
     $fave->free();
 }
Example #12
0
function initFaveURI()
{
    printfnq("Ensuring all faves have a URI...");
    $fave = new Fave();
    $fave->whereAdd('uri IS NULL');
    if ($fave->find()) {
        while ($fave->fetch()) {
            try {
                $fave->decache();
                $fave->query(sprintf('update fave ' . 'set uri = "%s", ' . '    modified = "%s" ' . 'where user_id = %d ' . 'and notice_id = %d', Fave::newURI($fave->user_id, $fave->notice_id, $fave->modified), common_sql_date(strtotime($fave->modified)), $fave->user_id, $fave->notice_id));
            } catch (Exception $e) {
                common_log(LOG_ERR, "Error updated fave URI: " . $e->getMessage());
            }
        }
    }
    printfnq("DONE.\n");
}
Example #13
0
 /**
  * Grab a list of profile who have favored this notice.
  *
  * @return ArrayWrapper masquerading as a Fave
  */
 static function byNotice($noticeId)
 {
     $c = self::memcache();
     $key = Cache::key('fave:by_notice:' . $noticeId);
     $wrapper = $c->get($key);
     if (!$wrapper) {
         // @fixme caching & scalability!
         $fave = new Fave();
         $fave->notice_id = $noticeId;
         $fave->find();
         $list = array();
         while ($fave->fetch()) {
             $list[] = clone $fave;
         }
         $wrapper = new ArrayWrapper($list);
         $c->set($key, $wrapper);
     }
     return $wrapper;
 }
 function getFaves()
 {
     $faves = array();
     $fave = new Fave();
     $fave->user_id = $this->user->id;
     if ($fave->find()) {
         while ($fave->fetch()) {
             $faves[] = clone $fave;
         }
     }
     return $faves;
 }
Example #15
0
 function getFaves()
 {
     $faves = array();
     $fave = new Fave();
     $fave->user_id = $this->user->id;
     if (!empty($this->after)) {
         $fave->whereAdd("modified > '" . common_sql_date($this->after) . "'");
     }
     if ($fave->find()) {
         while ($fave->fetch()) {
             $faves[] = clone $fave;
         }
     }
     return $faves;
 }
Example #16
0
 function blowFavesCache($blowLast = false)
 {
     $cache = common_memcache();
     if ($cache) {
         $fave = new Fave();
         $fave->notice_id = $this->id;
         if ($fave->find()) {
             while ($fave->fetch()) {
                 $cache->delete(common_cache_key('user:faves:' . $fave->user_id));
                 if ($blowLast) {
                     $cache->delete(common_cache_key('user:faves:' . $fave->user_id . ';last'));
                 }
             }
         }
         $fave->free();
         unset($fave);
     }
 }