/** * Prepare to run */ function prepare($args) { parent::prepare($args); if (!common_logged_in()) { // TRANS: Client error displayed when trying to perform an action while not logged in. $this->clientError(_('You must be logged in to unsubscribe from a list.')); } // Only allow POST requests if ($_SERVER['REQUEST_METHOD'] != 'POST') { // TRANS: Client error displayed when trying to use another method than POST. $this->clientError(_('This action only accepts POST requests.')); } // CSRF protection $token = $this->trimmed('token'); 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.')); } $tagger_arg = $this->trimmed('tagger'); $tag_arg = $this->trimmed('tag'); $id = intval($this->arg('id')); if ($id) { $this->peopletag = Profile_list::getKV('id', $id); } else { // TRANS: Client error displayed when trying to perform an action without providing an ID. $this->clientError(_('No ID given.'), 404); } if (!$this->peopletag || $this->peopletag->private) { // TRANS: Client error displayed trying to reference a non-existing list. $this->clientError(_('No such list.'), 404); } $this->tagger = Profile::getKV('id', $this->peopletag->tagger); return true; }
/** * Get ready * * @param array $args misc. arguments * * @return boolean true */ function prepare($args) { parent::prepare($args); $this->start = $this->arg('start'); $this->duration = $this->boolean('duration', false); return true; }
/** * Read arguments and initialize members * * @param array $args Arguments from $_REQUEST * @return boolean success */ function prepare($args) { parent::prepare($args); $this->limit = (int) $this->trimmed('limit'); if ($this->limit == 0) { $this->limit = DEFAULT_RSS_LIMIT; } if (common_config('site', 'private')) { if (!isset($_SERVER['PHP_AUTH_USER'])) { # This header makes basic auth go header('WWW-Authenticate: Basic realm="StatusNet RSS"'); # If the user hits cancel -- bam! $this->show_basic_auth_error(); return; } else { $nickname = $_SERVER['PHP_AUTH_USER']; $password = $_SERVER['PHP_AUTH_PW']; if (!common_check_user($nickname, $password)) { # basic authentication failed list($proxy, $ip) = common_client_ip(); common_log(LOG_WARNING, "Failed RSS auth attempt, nickname = {$nickname}, proxy = {$proxy}, ip = {$ip}."); $this->show_basic_auth_error(); return; } } } return true; }
function prepare($args) { parent::prepare($args); if (common_config('singleuser', 'enabled')) { $nickname_arg = User::singleUserNickname(); } else { $nickname_arg = $this->arg('nickname'); } $nickname = common_canonical_nickname($nickname_arg); // Permanent redirect on non-canonical nickname if ($nickname_arg != $nickname) { $args = array('nickname' => $nickname); if ($this->arg('page') && $this->arg('page') != 1) { $args['page'] = $this->arg['page']; } common_redirect(common_local_url('peopletagsforuser', $args), 301); } $this->user = User::getKV('nickname', $nickname); if (!$this->user) { // TRANS: Client error displayed trying to perform an action related to a non-existing user. $this->clientError(_('No such user.'), 404); } $this->tagged = $this->user->getProfile(); if (!$this->tagged) { // TRANS: Error message displayed when referring to a user without a profile. $this->serverError(_('User has no profile.')); } $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1; return true; }
function prepare($args) { parent::prepare($args); if (!common_logged_in()) { $this->clientError(_('Not logged in.')); return false; } $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { $this->clientError(_('网页错误,请返回重试 ')); return false; } $id = $this->trimmed('profile'); if (!$id) { $this->clientError(_('No profile specified.')); return false; } $this->profile = Profile::staticGet('id', $id); if (!$this->profile) { $this->clientError(_('No profile with that ID.')); return false; } return true; }
function prepare($args) { parent::prepare($args); // Check cookie for a valid access_token if (isset($_COOKIE['fb_access_token'])) { $this->accessToken = $_COOKIE['fb_access_token']; } if (empty($this->accessToken)) { $this->clientError(_m("Unable to authenticate you with Facebook.")); return false; } $graphUrl = 'https://graph.facebook.com/me?access_token=' . urlencode($this->accessToken); $this->fbuser = json_decode(file_get_contents($graphUrl)); if (!empty($this->fbuser)) { $this->fbuid = $this->fbuser->id; // OKAY, all is well... proceed to register return true; } else { // log badness list($proxy, $ip) = common_client_ip(); common_log(LOG_WARNING, sprintf('Failed Facebook authentication attempt, proxy = %s, ip = %s.', $proxy, $ip), __FILE__); $this->clientError(_m('You must be logged into Facebook to register a local account using Facebook.')); } return false; }
function prepare($args) { parent::prepare($args); $nickname_arg = $this->arg('nickname'); if (empty($nickname_arg)) { // TRANS: Client error displayed when requesting Friends of a Friend feed without providing a group nickname. $this->clientError(_('No such group.'), 404); } $this->nickname = common_canonical_nickname($nickname_arg); // Permanent redirect on non-canonical nickname if ($nickname_arg != $this->nickname) { common_redirect(common_local_url('foafgroup', array('nickname' => $this->nickname)), 301); return false; } $local = Local_group::getKV('nickname', $this->nickname); if (!$local) { // TRANS: Client error displayed when requesting Friends of a Friend feed for a non-local group. $this->clientError(_('No such group.'), 404); } $this->group = User_group::getKV('id', $local->group_id); if (!$this->group) { // TRANS: Client error displayed when requesting Friends of a Friend feed for a nickname that is not a group. $this->clientError(_('No such group.'), 404); } common_set_returnto($this->selfUrl()); return true; }
/** * Read and validate arguments * * @param array $args URL parameters * * @return boolean success value */ function prepare($args) { parent::prepare($args); $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1; if ($this->page > MAX_PUBLIC_PAGE) { // TRANS: Client error displayed when requesting a public timeline page beyond the page limit. // TRANS: %s is the page limit. $this->clientError(sprintf(_('Beyond the page limit (%s).'), MAX_PUBLIC_PAGE)); } common_set_returnto($this->selfUrl()); $this->userProfile = Profile::current(); $user = common_current_user(); if (!empty($user) && $user->streamModeOnly()) { $stream = new PublicNoticeStream($this->userProfile); } else { $stream = new ThreadingPublicNoticeStream($this->userProfile); } $this->notice = $stream->getNotices(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); if (!$this->notice) { // TRANS: Server error displayed when a public timeline cannot be retrieved. $this->serverError(_('Could not retrieve public timeline.')); return; } if ($this->page > 1 && $this->notice->N == 0) { // TRANS: Server error when page not found (404). $this->serverError(_('No such page.'), $code = 404); } return true; }
/** * For initializing members of the class. * * @param array $argarray misc. arguments * * @return boolean true */ function prepare($argarray) { parent::prepare($argarray); $this->user = common_current_user(); if (empty($this->user)) { // TRANS: Client exception thrown when trying to view group private messages without being logged in. throw new ClientException(_m('Only logged-in users can view private messages.'), 403); } $id = $this->trimmed('id'); $this->gm = Group_message::getKV('id', $id); if (empty($this->gm)) { // TRANS: Client exception thrown when trying to view a non-existing group private message. throw new ClientException(_m('No such message.'), 404); } $this->group = User_group::getKV('id', $this->gm->to_group); if (empty($this->group)) { // TRANS: Server exception thrown when trying to view group private messages for a non-exsting group. throw new ServerException(_m('Group not found.')); } if (!$this->user->isMember($this->group)) { // TRANS: Client exception thrown when trying to view a group private message without being a group member. throw new ClientException(_m('Cannot read message.'), 403); } $this->sender = Profile::getKV('id', $this->gm->from_profile); if (empty($this->sender)) { // TRANS: Server exception thrown when trying to view a group private message without a sender. throw new ServerException(_m('No sender found.')); } return true; }
/** * Take arguments for running * * @param array $args $_REQUEST args * * @return boolean success flag */ function prepare($args) { parent::prepare($args); $user = common_current_user(); // User must be logged in. if (!common_logged_in()) { $this->clientError(_('Not logged in.')); return; } $user = common_current_user(); // ...because they're logged in assert(!empty($user)); // It must be a "real" login, not saved cookie login if (!common_is_real_login()) { // Cookie theft is too easy; we require automatic // logins to re-authenticate before admining the site common_set_returnto($this->selfUrl()); if (Event::handle('RedirectToLogin', array($this, $user))) { common_redirect(common_local_url('login'), 303); } } // User must have the right to review flags if (!$user->hasRight(UserFlagPlugin::REVIEWFLAGS)) { $this->clientError(_('You cannot review profile flags.')); return false; } $this->page = $this->trimmed('page'); if (empty($this->page)) { $this->page = 1; } $this->profiles = $this->getProfiles(); return true; }
/** * Prepare the object * * Check the input values and initialize the object. * Shows an error page on bad input. * * @param array $args $_REQUEST data * * @return boolean success flag */ function prepare($args) { parent::prepare($args); $nickname = common_canonical_nickname($this->arg('nickname')); $this->user = User::staticGet('nickname', $nickname); if (!$this->user) { // TRANS: Client error displayed when trying to reply to a non-exsting user. $this->clientError(_('No such user.')); return false; } $profile = $this->user->getProfile(); if (!$profile) { // TRANS: Error message displayed when referring to a user without a profile. $this->serverError(_('User has no profile.')); return false; } $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1; common_set_returnto($this->selfUrl()); $stream = new ReplyNoticeStream($this->user->id, Profile::current()); $this->notice = $stream->getNotices(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); if ($this->page > 1 && $this->notice->N == 0) { // TRANS: Server error when page not found (404) $this->serverError(_('No such page.'), $code = 404); } return true; }
function prepare($args) { parent::prepare($args); $this->facebook = new Facebook(array('appId' => common_config('facebook', 'appid'), 'secret' => common_config('facebook', 'secret'), 'cookie' => true)); // Check for a Facebook user session $session = $this->facebook->getSession(); $me = null; if ($session) { try { $this->fbuid = $this->facebook->getUser(); $this->fbuser = $this->facebook->api('/me'); } catch (FacebookApiException $e) { common_log(LOG_ERROR, $e, __FILE__); } } if (!empty($this->fbuser)) { // OKAY, all is well... proceed to register common_debug("Found a valid Facebook user.", __FILE__); } else { // This shouldn't happen in the regular course of things list($proxy, $ip) = common_client_ip(); common_log(LOG_WARNING, sprintf('Failed Facebook authentication attempt, proxy = %s, ip = %s.', $proxy, $ip), __FILE__); $this->clientError(_m('You must be logged into Facebook to register a local account using Facebook.')); } return true; }
/** * Prepare page to run * * * @param $args * @return string title */ function prepare($args) { parent::prepare($args); $this->code = $this->trimmed('code'); // @todo this check should really be in index.php for all sensitive actions $ssl = common_config('site', 'ssl'); if (empty($_SERVER['HTTPS']) && ($ssl == 'always' || $ssl == 'sometimes')) { common_redirect(common_local_url('register')); // exit } if (empty($this->code)) { common_ensure_session(); if (array_key_exists('invitecode', $_SESSION)) { $this->code = $_SESSION['invitecode']; } } if (common_config('site', 'inviteonly') && empty($this->code)) { $this->clientError(_('Sorry, only invited people can register.')); return false; } if (!empty($this->code)) { $this->invite = Invitation::staticGet('code', $this->code); if (empty($this->invite)) { $this->clientError(_('Sorry, invalid invitation code.')); return false; } // Store this in case we need it common_ensure_session(); $_SESSION['invitecode'] = $this->code; } return true; }
/** * Prepare page to run * * * @param $args * @return string title */ protected function prepare(array $args = array()) { parent::prepare($args); $this->code = $this->trimmed('code'); if (empty($this->code)) { common_ensure_session(); if (array_key_exists('invitecode', $_SESSION)) { $this->code = $_SESSION['invitecode']; } } if (common_config('site', 'inviteonly') && empty($this->code)) { // TRANS: Client error displayed when trying to register to an invite-only site without an invitation. $this->clientError(_('Sorry, only invited people can register.')); } if (!empty($this->code)) { $this->invite = Invitation::getKV('code', $this->code); if (!$this->invite instanceof Invitation) { // TRANS: Client error displayed when trying to register to an invite-only site without a valid invitation. $this->clientError(_('Sorry, invalid invitation code.')); } // Store this in case we need it common_ensure_session(); $_SESSION['invitecode'] = $this->code; } return true; }
/** * For initializing members of the class. * * @param array $args misc. arguments * * @return boolean true */ function prepare($args) { parent::prepare($args); if (!$this->isPost()) { throw new ClientException(_('POST only'), 405); } $this->checkSessionToken(); $this->url = $this->trimmed('url'); if (empty($this->url)) { throw new ClientException(_('URL is required.'), 400); } if (!Validate::uri($this->url, array('allowed_schemes' => array('http', 'https')))) { throw new ClientException(_('Invalid URL.'), 400); } $f = File::staticGet('url', $this->url); if (empty($url)) { $f = File::processNew($this->url); } // How about now? if (!empty($f)) { $this->oembed = File_oembed::staticGet('file_id', $f->id); if (!empty($this->oembed)) { $this->title = $this->oembed->title; } $this->thumbnail = File_thumbnail::staticGet('file_id', $f->id); } return true; }
/** * Take arguments for running * * This method is called first, and it lets the action class get * all its arguments and validate them. It's also the time * to fetch any relevant data from the database. * * Action classes should run parent::prepare($args) as the first * line of this method to make sure the default argument-processing * happens. * * @param array $args $_REQUEST args * * @return boolean success flag */ function prepare($args) { parent::prepare($args); if (!common_logged_in()) { // TRANS: Error message displayed when trying to perform an action that requires a logged in user. $this->clientError(_('Not logged in.')); return; } else { if (!common_is_real_login()) { // Cookie theft means that automatic logins can't // change important settings or see private info, and // _all_ our settings are important common_set_returnto($this->selfUrl()); $user = common_current_user(); if (Event::handle('RedirectToLogin', array($this, $user))) { common_redirect(common_local_url('login'), 303); } } else { $this->user = common_current_user(); $sdate = !isset($_REQUEST['sdate']) ? new DateTime('first day of this month') : new DateTime($_REQUEST['sdate']); $edate = !isset($_REQUEST['edate']) ? new DateTime('last day of this month') : new DateTime($_REQUEST['edate']); // Custom date range $this->sa = Social_analytics::init($this->user->id, $sdate, $edate); } } return true; }
/** * Read and validate arguments * * @param array $args URL parameters * * @return boolean success value */ function prepare($args) { parent::prepare($args); $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1; common_set_returnto($this->selfUrl()); return true; }
/** * Check pre-requisites and instantiate attributes * * @param Array $args array of arguments (URL, GET, POST) * * @return boolean success flag */ function prepare($args) { parent::prepare($args); // @fixme these are pretty common, should a parent class factor these out? // Only allow POST requests if ($_SERVER['REQUEST_METHOD'] != 'POST') { // TRANS: Client error displayed when trying to use another method than POST. // TRANS: Do not translate POST. $this->clientError(_('This action only accepts POST requests.')); } // CSRF protection $token = $this->trimmed('token'); 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.')); } // Only for logged-in users $this->user = common_current_user(); if (empty($this->user)) { // TRANS: Error message displayed when trying to perform an action that requires a logged in user. $this->clientError(_('Not logged in.')); } if (!AdminPanelAction::canAdmin('plugins')) { // TRANS: Client error displayed when trying to enable or disable a plugin without access rights. $this->clientError(_('You cannot administer plugins.')); } $this->plugin = $this->arg('plugin'); $defaultPlugins = common_config('plugins', 'default'); if (!array_key_exists($this->plugin, $defaultPlugins)) { // TRANS: Client error displayed when trying to enable or disable a non-existing plugin. $this->clientError(_('No such plugin.')); } return true; }
function prepare($args) { parent::prepare($args); $nickname_arg = $this->arg('nickname'); if (empty($nickname_arg)) { $this->clientError(_('No such group.'), 404); return false; } $this->nickname = common_canonical_nickname($nickname_arg); // Permanent redirect on non-canonical nickname if ($nickname_arg != $this->nickname) { common_redirect(common_local_url('foafgroup', array('nickname' => $this->nickname)), 301); return false; } $local = Local_group::staticGet('nickname', $this->nickname); if (!$local) { $this->clientError(_('No such group.'), 404); return false; } $this->group = User_group::staticGet('id', $local->group_id); if (!$this->group) { $this->clientError(_('No such group.'), 404); return false; } common_set_returnto($this->selfUrl()); return true; }
function prepare($args) { parent::prepare($args); $nickname_arg = $this->arg('nickname'); $nickname = common_canonical_nickname($nickname_arg); // Permanent redirect on non-canonical nickname if ($nickname_arg != $nickname) { $args = array('nickname' => $nickname); if ($this->arg('page') && $this->arg('page') != 1) { $args['page'] = $this->arg['page']; } common_redirect(common_local_url($this->trimmed('action'), $args), 301); return false; } $this->user = User::staticGet('nickname', $nickname); if (!$this->user) { // TRANS: Client error displayed when calling a profile action without specifying a user. $this->clientError(_('No such user.'), 404); return false; } $this->profile = $this->user->getProfile(); if (!$this->profile) { // TRANS: Error message displayed when referring to a user without a profile. $this->serverError(_('User has no profile.')); return false; } $user = common_current_user(); if ($this->profile->hasRole(Profile_role::SILENCED) && (empty($user) || !$user->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; }
/** * Take arguments for running * * This method is called first, and it lets the action class get * all its arguments and validate them. It's also the time * to fetch any relevant data from the database. * * Action classes should run parent::prepare($args) as the first * line of this method to make sure the default argument-processing * happens. * * @param array $args $_REQUEST args * * @return boolean success flag */ function prepare($args) { parent::prepare($args); if (common_config('singleuser', 'enabled')) { $nickname = User::singleUserNickname(); } else { // PHP 5.4 // $nickname = $this->returnToArgs()[1]['nickname']; // PHP < 5.4 $nickname = $this->returnToArgs(); $nickname = $nickname[1]['nickname']; } $this->user = User::staticGet('nickname', $nickname); if (!$this->user) { // TRANS: Client error displayed when trying to display bookmarks for a non-existing user. $this->clientError(_('No such user.')); return false; } $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1; $stream = new BookmarksNoticeStream($this->user->id, true); $this->notices = $stream->getNotices(($this->page - 1) * NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); if ($this->page > 1 && $this->notices->N == 0) { throw new ClientException(_('No such page.'), 404); } return true; }
function prepare($args) { parent::prepare($args); $nickname_arg = $this->arg('nickname'); if (empty($nickname_arg)) { // TRANS: Client error displayed when requesting Friends of a Friend feed without providing a user nickname. $this->clientError(_('No such user.'), 404); return false; } $this->nickname = common_canonical_nickname($nickname_arg); // Permanent redirect on non-canonical nickname if ($nickname_arg != $this->nickname) { common_redirect(common_local_url('foaf', array('nickname' => $this->nickname)), 301); return false; } $this->user = User::staticGet('nickname', $this->nickname); if (!$this->user) { // TRANS: Client error displayed when requesting Friends of a Friend feed for an object that is not a user. $this->clientError(_('No such user.'), 404); return false; } $this->profile = $this->user->getProfile(); if (!$this->profile) { // TRANS: Error message displayed when referring to a user without a profile. $this->serverError(_('User has no profile.'), 500); return false; } return true; }
function prepare($args) { StatusNet::setApi(true); // Send smaller error pages parent::prepare($args); if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError(_m('This method requires a POST.')); } if (empty($_SERVER['CONTENT_TYPE']) || $_SERVER['CONTENT_TYPE'] != 'application/magic-envelope+xml') { $this->clientError(_m('Salmon requires application/magic-envelope+xml')); } $xml = file_get_contents('php://input'); // Check the signature $salmon = new Salmon(); if (!$salmon->verifyMagicEnv($xml)) { common_log(LOG_DEBUG, "Salmon signature verification failed."); $this->clientError(_m('Salmon signature verification failed.')); } else { $magic_env = new MagicEnvelope(); $env = $magic_env->parse($xml); $xml = $magic_env->unfold($env); } $dom = DOMDocument::loadXML($xml); if ($dom->documentElement->namespaceURI != Activity::ATOM || $dom->documentElement->localName != 'entry') { common_log(LOG_DEBUG, "Got invalid Salmon post: {$xml}"); $this->clientError(_m('Salmon post must be an Atom entry.')); } $this->act = new Activity($dom->documentElement); return true; }
function prepare($args) { parent::prepare($args); if (!common_logged_in()) { // TRANS: Client error displayed trying a change a subscription while not logged in. $this->clientError(_('Not logged in.')); return false; } $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { $this->clientError(_('There was a problem with your session token. ' . 'Try again, please.')); return false; } $id = $this->trimmed('profile'); if (!$id) { // TRANS: Client error displayed trying a change a subscription without providing a profile. $this->clientError(_('No profile specified.')); return false; } $this->profile = Profile::staticGet('id', $id); if (!$this->profile) { // TRANS: Client error displayed trying a change a subscription for a non-existant profile ID. $this->clientError(_('No profile with that ID.')); return false; } return true; }
function prepare($args) { parent::prepare($args); $nickname_arg = $this->arg('nickname'); $nickname = common_canonical_nickname($nickname_arg); // Permanent redirect on non-canonical nickname if ($nickname_arg != $nickname) { $args = array('nickname' => $nickname); if ($this->arg('page') && $this->arg('page') != 1) { $args['page'] = $this->arg['page']; } common_redirect(common_local_url('showstream', $args), 301); return false; } $this->user = User::staticGet('nickname', $nickname); if (!$this->user) { $this->clientError(_('No such user.'), 404); return false; } $this->profile = $this->user->getProfile(); if (!$this->profile) { $this->serverError(_('User has no profile.')); return false; } $this->page = $this->arg('page') ? $this->arg('page') + 0 : 1; common_set_returnto($this->selfUrl()); return true; }
function prepare($args) { parent::prepare($args); $this->user = common_current_user(); if (empty($this->user)) { $this->clientError(_('Only logged-in users can repeat notices.')); return false; } $id = $this->trimmed('notice'); if (empty($id)) { $this->clientError(_('No notice specified.')); return false; } $this->notice = Notice::staticGet('id', $id); if (empty($this->notice)) { $this->clientError(_('No notice specified.')); return false; } if ($this->user->id == $this->notice->profile_id) { $this->clientError(_("You can't repeat your own notice.")); return false; } $token = $this->trimmed('token-' . $id); if (empty($token) || $token != common_session_token()) { $this->clientError(_('There was a problem with your session token. Try again, please.')); return false; } $profile = $this->user->getProfile(); if ($profile->hasRepeated($id)) { $this->clientError(_('You already repeated that notice.')); return false; } return true; }
/** * For initializing members of the class. * * @param array $argarray misc. arguments * * @return boolean true */ function prepare($argarray) { Action::prepare($argarray); $this->id = $this->trimmed('id'); $this->answer = QnA_Answer::staticGet('id', $this->id); if (empty($this->answer)) { // TRANS: Client exception thrown when requesting a non-existing answer. throw new ClientException(_m('No such answer.'), 404); } $this->question = $this->answer->getQuestion(); if (empty($this->question)) { // TRANS: Client exception thrown when requesting an answer that has no connected question. throw new ClientException(_m('No question for this answer.'), 404); } $this->notice = Notice::staticGet('uri', $this->answer->uri); if (empty($this->notice)) { // TRANS: Did we used to have it, and it got deleted? throw new ClientException(_m('No such answer.'), 404); } $this->user = User::staticGet('id', $this->answer->profile_id); if (empty($this->user)) { // TRANS: Client exception thrown when requesting answer data for a non-existing user. throw new ClientException(_m('No such user.'), 404); } $this->profile = $this->user->getProfile(); if (empty($this->profile)) { // TRANS: Client exception thrown when requesting answer data for a user without a profile. throw new ServerException(_m('User without a profile.')); } $this->avatar = $this->profile->getAvatar(AVATAR_PROFILE_SIZE); return true; }
/** * Take arguments for running * * @param array $args $_REQUEST args * * @return boolean success flag */ function prepare($args) { if (!parent::prepare($args)) { return false; } if (!common_logged_in()) { // TRANS: Client error displayed trying to delete an application while not logged in. $this->clientError(_('You must be logged in to delete an application.')); return false; } $id = (int) $this->arg('id'); $this->app = Oauth_application::staticGet('id', $id); if (empty($this->app)) { // TRANS: Client error displayed trying to delete an application that does not exist. $this->clientError(_('Application not found.')); return false; } $cur = common_current_user(); if ($cur->id != $this->app->owner) { // TRANS: Client error displayed trying to delete an application the current user does not own. $this->clientError(_('You are not the owner of this application.'), 401); return false; } return true; }
function prepare($args) { parent::prepare($args); common_debug('IndexAction -> redirect -> ' . $this->lang); common_redirect(common_get_route('home', array('lang' => $this->lang)), 303); return true; }
function prepare($args) { parent::prepare($args); $this->id = $this->trimmed('notice'); if (empty($this->id)) { $this->clientError(_('No notice ID.')); } $notice = Notice::staticGet('id', $this->id); if (empty($notice)) { $this->clientError(_('No notice.')); } $atts = $notice->attachments(); if (empty($atts)) { $this->clientError(_('No attachments.')); } foreach ($atts as $att) { if (!empty($att->filename)) { $this->filerec = $att; break; } } if (empty($this->filerec)) { $this->clientError(_('No uploaded attachments.')); } return true; }