本文整理汇总了PHP中Action::prepare方法的典型用法代码示例。如果您正苦于以下问题:PHP Action::prepare方法的具体用法?PHP Action::prepare怎么用?PHP Action::prepare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Action
的用法示例。
在下文中一共展示了Action::prepare方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prepare
/**
* 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;
}
示例2: prepare
/**
* 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;
}
示例3: prepare
/**
* 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;
}
示例4: prepare
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;
}
示例5: prepare
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;
}
示例6: prepare
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;
}
示例7: prepare
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;
}
示例8: prepare
/**
* 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;
}
示例9: prepare
/**
* 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;
}
示例10: prepare
/**
* 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;
}
示例11: prepare
/**
* 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;
}
示例12: prepare
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;
}
示例13: prepare
/**
* 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;
}
示例14: prepare
/**
* 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;
}
示例15: prepare
/**
* 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;
}