Example #1
0
 /**
  * Load attributes based on database arguments
  *
  * Loads all the DB stuff
  *
  * @param array $args $_REQUEST array
  *
  * @return success flag
  */
 protected function prepare(array $args = array())
 {
     parent::prepare($args);
     if ($this->boolean('ajax')) {
         GNUsocial::setApi(true);
     }
     $this->notice = $this->getNotice();
     if (!$this->notice->inScope($this->scoped)) {
         // TRANS: Client exception thrown when trying a view a notice the user has no access to.
         throw new ClientException(_('Access restricted.'), 403);
     }
     $this->profile = $this->notice->getProfile();
     if (!$this->profile instanceof Profile) {
         // TRANS: Server error displayed trying to show a notice without a connected profile.
         $this->serverError(_('Notice has no profile.'), 500);
     }
     try {
         $this->user = $this->profile->getUser();
     } catch (NoSuchUserException $e) {
         // FIXME: deprecate $this->user stuff in extended classes
         $this->user = null;
     }
     try {
         $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE);
     } catch (Exception $e) {
         $this->avatar = null;
     }
     return true;
 }
Example #2
0
 protected function handle()
 {
     $this->setXRD();
     if (common_config('discovery', 'cors')) {
         header('Access-Control-Allow-Origin: *');
     }
     parent::handle();
 }
Example #3
0
 /**
  * Initialization.
  *
  * @param array $args Web and URL arguments
  *
  * @return boolean false if id not passed in
  */
 protected function prepare(array $args = array())
 {
     parent::prepare($args);
     $convId = $this->int('id');
     $this->conv = Conversation::getKV('id', $convId);
     if (!$this->conv instanceof Conversation) {
         throw new ClientException('Could not find specified conversation');
     }
     return true;
 }
 function extraHead()
 {
     parent::extraHead();
     $rsd = common_local_url('rsd');
     // RSD, http://tales.phrasewise.com/rfc/rsd
     $this->element('link', array('rel' => 'EditURI', 'type' => 'application/rsd+xml', 'href' => $rsd));
     if ($this->page != 1) {
         $this->element('link', array('rel' => 'canonical', 'href' => common_local_url('public')));
     }
 }
Example #5
0
 protected function prepare(array $args = array())
 {
     parent::prepare($args);
     $args = $this->returnToArgs();
     $this->photoid = $args[1]['photoid'];
     $this->photo = GNUsocialPhoto::getKV('id', $this->photoid);
     $this->notice = Notice::getKV('id', $this->photo->notice_id);
     $this->user = Profile::getKV('id', $this->notice->profile_id);
     $this->conv = $this->notice->getConversation();
     return true;
 }
 protected function prepare(array $args = array())
 {
     // this will call ->doPreparation() which child classes use to set $this->target
     parent::prepare($args);
     if ($this->target->hasRole(Profile_role::SILENCED) && (!$this->scoped instanceof Profile || !$this->scoped->hasRight(Right::SILENCEUSER))) {
         throw new ClientException(_('This profile has been silenced by site moderators'), 403);
     }
     $this->tag = $this->trimmed('tag');
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     common_set_returnto($this->selfUrl());
     return true;
 }
Example #7
0
 protected function prepare(array $args = array())
 {
     parent::prepare($args);
     $this->form = $this->form ?: $this->action;
     $this->args['form'] = $this->form;
     $this->type = !is_null($this->type) ? $this->type : $this->trimmed('type');
     $this->args['context'] = $this->trimmed('action');
     // reply for notice for example
     if (!$this->type) {
         $this->type = null;
     }
     return true;
 }
Example #8
0
 protected function prepare(array $args = array())
 {
     parent::prepare($args);
     $taginput = $this->trimmed('tag');
     $this->tag = common_canonical_tag($taginput);
     if (empty($this->tag)) {
         common_redirect(common_local_url('publictagcloud'), 301);
     }
     // after common_canonical_tag we have a lowercase, no-specials tag string
     if ($this->tag !== $taginput) {
         common_redirect(common_local_url('tag', array('tag' => $this->tag)), 301);
     }
     $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1;
     common_set_returnto($this->selfUrl());
     $this->notice = Notice_tag::getStream($this->tag)->getNotices(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1);
     if ($this->page > 1 && $this->notice->N == 0) {
         // TRANS: Client error when page not found (404).
         $this->clientError(_('No such page.'), 404);
     }
     return true;
 }
 protected function doActionPreparation(ManagedAction $action, $verb, Notice $target, Profile $scoped)
 {
     if ($action->isPost()) {
         // The below tests are only for presenting to the user. POSTs which inflict
         // duplicate favorite entries are handled with AlreadyFulfilledException.
         return false;
     }
     $exists = Fave::existsForProfile($target, $scoped);
     $expected_verb = $exists ? ActivityVerb::UNFAVORITE : ActivityVerb::FAVORITE;
     switch (true) {
         case $exists && ActivityUtils::compareVerbs($verb, array(ActivityVerb::FAVORITE, ActivityVerb::LIKE)):
         case !$exists && ActivityUtils::compareVerbs($verb, array(ActivityVerb::UNFAVORITE, ActivityVerb::UNLIKE)):
             common_redirect(common_local_url('activityverb', array('id' => $target->getID(), 'verb' => ActivityUtils::resolveUri($expected_verb, true))));
             break;
         default:
             // No need to redirect as we are on the correct action already.
     }
     return false;
 }
Example #10
0
 public function showPage()
 {
     if (empty($this->attachment->filename)) {
         // if it's not a local file, gtfo
         common_redirect($this->attachment->url, 303);
     }
     parent::showPage();
 }