本文整理汇总了PHP中Gdn_Controller::DeliveryType方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_Controller::DeliveryType方法的具体用法?PHP Gdn_Controller::DeliveryType怎么用?PHP Gdn_Controller::DeliveryType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn_Controller
的用法示例。
在下文中一共展示了Gdn_Controller::DeliveryType方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Base_ConnectData_Handler
/**
*
* @param Gdn_Controller $Sender
* @param array $Args
*/
public function Base_ConnectData_Handler($Sender, $Args)
{
if (GetValue(0, $Args) != 'sinaconnect') {
return;
}
$RequestToken = GetValue('oauth_token', $_GET);
// Get the access token.
if ($RequestToken || !($AccessToken = $this->AccessToken())) {
// Get the request secret.
$RequestToken = $this->GetOAuthToken($RequestToken);
$Consumer = new OAuthConsumer(C('Plugins.SinaConnect.ConsumerKey'), C('Plugins.SinaConnect.Secret'));
$Url = 'http://api.t.sina.com.cn/oauth/access_token';
$Params = array('oauth_verifier' => GetValue('oauth_verifier', $_GET));
$Request = OAuthRequest::from_consumer_and_token($Consumer, $RequestToken, 'POST', $Url, $Params);
$SignatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
$Request->sign_request($SignatureMethod, $Consumer, $RequestToken);
$Post = $Request->to_postdata();
$Curl = $this->_Curl($Request);
$Response = curl_exec($Curl);
if ($Response === FALSE) {
$Response = curl_error($Curl);
}
$HttpCode = curl_getinfo($Curl, CURLINFO_HTTP_CODE);
curl_close($Curl);
if ($HttpCode == '200') {
$Data = OAuthUtil::parse_parameters($Response);
$AccessToken = $this->AccessToken(GetValue('oauth_token', $Data), GetValue('oauth_token_secret', $Data));
// Save the access token to the database.
$this->SetOAuthToken($AccessToken);
// Delete the request token.
$this->DeleteOAuthToken($RequestToken);
} else {
// There was some sort of error.
}
$NewToken = TRUE;
}
// Get the profile.
try {
$Profile = $this->GetProfile($AccessToken);
} catch (Exception $Ex) {
if (!isset($NewToken)) {
// There was an error getting the profile, which probably means the saved access token is no longer valid. Try and reauthorize.
if ($Sender->DeliveryType() == DELIVERY_TYPE_ALL) {
Redirect($this->_AuthorizeHref());
} else {
$Sender->SetHeader('Content-type', 'application/json');
$Sender->DeliveryMethod(DELIVERY_METHOD_JSON);
$Sender->RedirectUrl = $this->_AuthorizeHref();
}
} else {
$Sender->Form->AddError($Ex);
}
}
//print_r($Profile);
$Form = $Sender->Form;
//new Gdn_Form();
$ID = GetValue('id', $Profile);
$Form->SetFormValue('UniqueID', $ID);
$Form->SetFormValue('Provider', self::$ProviderKey);
$Form->SetFormValue('ProviderName', 'Sina');
$Form->SetFormValue('Name', GetValue('screen_name', $Profile));
$Form->SetFormValue('FullName', GetValue('name', $Profile));
$Form->SetFormValue('Email', GetValue('id', $Profile) . '@weibo.com');
$Form->SetFormValue('Photo', GetValue('profile_image_url', $Profile));
$Sender->SetData('Verified', TRUE);
}
示例2: UtilityController_SiteMapIndex_Create
/**
* @param Gdn_Controller $Sender
* @param type $Args
*/
public function UtilityController_SiteMapIndex_Create($Sender)
{
// Clear the session to mimic a crawler.
Gdn::Session()->Start(0, FALSE, FALSE);
$Sender->DeliveryMethod(DELIVERY_METHOD_XHTML);
$Sender->DeliveryType(DELIVERY_TYPE_VIEW);
$Sender->SetHeader('Content-Type', 'text/xml');
$SiteMaps = array();
if (class_exists('CategoryModel')) {
$Categories = CategoryModel::Categories();
foreach ($Categories as $Category) {
if (!$Category['PermsDiscussionsView'] || $Category['CategoryID'] < 0 || $Category['CountDiscussions'] == 0) {
continue;
}
$SiteMap = array('Loc' => Url('/sitemap-category-' . rawurlencode($Category['UrlCode'] ? $Category['UrlCode'] : $Category['CategoryID']) . '.xml', TRUE), 'LastMod' => $Category['DateLastComment'], 'ChangeFreq' => '', 'Priority' => '');
$SiteMaps[] = $SiteMap;
}
}
$Sender->SetData('SiteMaps', $SiteMaps);
$Sender->Render('SiteMapIndex', '', 'plugins/Sitemaps');
}
示例3: SettingsController_AnalyticsTick_Create
/**
*
* @param Gdn_Controller $Sender
*/
public function SettingsController_AnalyticsTick_Create($Sender)
{
$Sender->DeliveryMethod(DELIVERY_METHOD_JSON);
$Sender->DeliveryType(DELIVERY_TYPE_DATA);
Gdn::Statistics()->Tick();
$this->FireEvent("AnalyticsTick");
$Sender->DeliveryType(DELIVERY_TYPE_VIEW);
$Sender->Render('tick', 'statistics', 'dashboard');
}
示例4: Base_ConnectData_Handler
/**
*
* @param Gdn_Controller $Sender
* @param array $Args
*/
public function Base_ConnectData_Handler($Sender, $Args)
{
if (GetValue(0, $Args) != 'twitter') {
return;
}
$Form = $Sender->Form;
//new Gdn_Form();
$RequestToken = GetValue('oauth_token', $_GET);
$AccessToken = $Form->GetFormValue('AccessToken');
if ($AccessToken) {
$AccessToken = $this->GetOAuthToken($AccessToken);
$this->AccessToken($AccessToken);
}
// Get the access token.
if ($RequestToken && !$AccessToken) {
// Get the request secret.
$RequestToken = $this->GetOAuthToken($RequestToken);
$Consumer = new OAuthConsumer(C('Plugins.Twitter.ConsumerKey'), C('Plugins.Twitter.Secret'));
$Url = 'https://api.twitter.com/oauth/access_token';
$Params = array('oauth_verifier' => GetValue('oauth_verifier', $_GET));
$Request = OAuthRequest::from_consumer_and_token($Consumer, $RequestToken, 'POST', $Url, $Params);
$SignatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
$Request->sign_request($SignatureMethod, $Consumer, $RequestToken);
$Post = $Request->to_postdata();
$Curl = $this->_Curl($Request);
$Response = curl_exec($Curl);
if ($Response === FALSE) {
$Response = curl_error($Curl);
}
$HttpCode = curl_getinfo($Curl, CURLINFO_HTTP_CODE);
curl_close($Curl);
if ($HttpCode == '200') {
$Data = OAuthUtil::parse_parameters($Response);
$AccessToken = new OAuthToken(GetValue('oauth_token', $Data), GetValue('oauth_token_secret', $Data));
// Save the access token to the database.
$this->SetOAuthToken($AccessToken->key, $AccessToken->secret, 'access');
$this->AccessToken($AccessToken->key, $AccessToken->secret);
// Delete the request token.
$this->DeleteOAuthToken($RequestToken);
} else {
// There was some sort of error.
throw new Exception('There was an error authenticating with twitter.', 400);
}
$NewToken = TRUE;
}
// Get the profile.
try {
$Profile = $this->GetProfile($AccessToken);
} catch (Exception $Ex) {
if (!isset($NewToken)) {
// There was an error getting the profile, which probably means the saved access token is no longer valid. Try and reauthorize.
if ($Sender->DeliveryType() == DELIVERY_TYPE_ALL) {
Redirect($this->_AuthorizeHref());
} else {
$Sender->SetHeader('Content-type', 'application/json');
$Sender->DeliveryMethod(DELIVERY_METHOD_JSON);
$Sender->RedirectUrl = $this->_AuthorizeHref();
}
} else {
throw $Ex;
}
}
$ID = GetValue('id', $Profile);
$Form->SetFormValue('UniqueID', $ID);
$Form->SetFormValue('Provider', self::ProviderKey);
$Form->SetFormValue('ProviderName', 'Twitter');
$Form->SetValue('ConnectName', GetValue('screen_name', $Profile));
$Form->SetFormValue('Name', GetValue('screen_name', $Profile));
$Form->SetFormValue('FullName', GetValue('name', $Profile));
$Form->SetFormValue('Photo', GetValue('profile_image_url', $Profile));
$Form->AddHidden('AccessToken', $AccessToken->key);
// Save some original data in the attributes of the connection for later API calls.
$Attributes = array(self::ProviderKey => array('AccessToken' => array($AccessToken->key, $AccessToken->secret), 'Profile' => $Profile));
$Form->SetFormValue('Attributes', $Attributes);
$Sender->SetData('Verified', TRUE);
}
示例5: Base_ConnectData_Handler
/**
*
* @param Gdn_Controller $Sender
* @param array $Args
*/
public function Base_ConnectData_Handler($Sender, $Args)
{
if (GetValue(0, $Args) != 'facebook') {
return;
}
if (isset($_GET['error'])) {
throw new Gdn_UserException(GetValue('error_description', $_GET, T('There was an error connecting to Facebook')));
}
$AppID = C('Plugins.Facebook.ApplicationID');
$Secret = C('Plugins.Facebook.Secret');
$Code = GetValue('code', $_GET);
$Query = '';
if ($Sender->Request->Get('display')) {
$Query = 'display=' . urlencode($Sender->Request->Get('display'));
}
$RedirectUri = ConcatSep('&', $this->RedirectUri(), $Query);
$RedirectUri = urlencode($RedirectUri);
// Get the access token.
if ($Code || !($AccessToken = $this->AccessToken())) {
// Exchange the token for an access token.
$Code = urlencode($Code);
$Url = "https://graph.facebook.com/oauth/access_token?client_id={$AppID}&client_secret={$Secret}&code={$Code}&redirect_uri={$RedirectUri}";
// Get the redirect URI.
$C = curl_init();
curl_setopt($C, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($C, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($C, CURLOPT_URL, $Url);
$Contents = curl_exec($C);
// $Contents = ProxyRequest($Url);
$Info = curl_getinfo($C);
if (strpos(GetValue('content_type', $Info, ''), '/javascript') !== FALSE) {
$Tokens = json_decode($Contents, TRUE);
} else {
parse_str($Contents, $Tokens);
}
if (GetValue('error', $Tokens)) {
throw new Gdn_UserException('Facebook returned the following error: ' . GetValueR('error.message', $Tokens, 'Unknown error.'), 400);
}
$AccessToken = GetValue('access_token', $Tokens);
$Expires = GetValue('expires', $Tokens, NULL);
setcookie('fb_access_token', $AccessToken, time() + $Expires, C('Garden.Cookie.Path', '/'), C('Garden.Cookie.Domain', ''), NULL, TRUE);
$NewToken = TRUE;
}
// Get the profile.
try {
$Profile = $this->GetProfile($AccessToken);
} catch (Exception $Ex) {
if (!isset($NewToken)) {
// There was an error getting the profile, which probably means the saved access token is no longer valid. Try and reauthorize.
if ($Sender->DeliveryType() == DELIVERY_TYPE_ALL) {
Redirect($this->AuthorizeUri());
} else {
$Sender->SetHeader('Content-type', 'application/json');
$Sender->DeliveryMethod(DELIVERY_METHOD_JSON);
$Sender->RedirectUrl = $this->AuthorizeUri();
}
} else {
$Sender->Form->AddError('There was an error with the Facebook connection.');
}
}
$Form = $Sender->Form;
//new Gdn_Form();
$ID = GetValue('id', $Profile);
$Form->SetFormValue('UniqueID', $ID);
$Form->SetFormValue('Provider', 'facebook');
$Form->SetFormValue('ProviderName', 'Facebook');
$Form->SetFormValue('FullName', GetValue('name', $Profile));
$Form->SetFormValue('Email', GetValue('email', $Profile));
$Form->SetFormValue('Photo', "http://graph.facebook.com/{$ID}/picture");
if (C('Plugins.Facebook.UseFacebookNames')) {
$Form->SetFormValue('Name', GetValue('name', $Profile));
SaveToConfig(array('Garden.User.ValidationRegex' => UserModel::USERNAME_REGEX_MIN, 'Garden.User.ValidationLength' => '{3,50}', 'Garden.Registration.NameUnique' => FALSE), '', FALSE);
}
// Save some original data in the attributes of the connection for later API calls.
$Attributes = array('Facebook.Profile' => $Profile);
$Form->SetFormValue('Attributes', $Attributes);
$Sender->SetData('Verified', TRUE);
}
示例6: Base_ConnectData_Handler
/**
*
* @param Gdn_Controller $Sender
* @param array $Args
*/
public function Base_ConnectData_Handler($Sender, $Args)
{
if (GetValue(0, $Args) != 'facebook') {
return;
}
if (isset($_GET['error'])) {
throw new Gdn_UserException(GetValue('error_description', $_GET, T('There was an error connecting to Facebook')));
}
$AppID = C('Plugins.Facebook.ApplicationID');
$Secret = C('Plugins.Facebook.Secret');
$Code = GetValue('code', $_GET);
$Query = '';
if ($Sender->Request->Get('display')) {
$Query = 'display=' . urlencode($Sender->Request->Get('display'));
}
$RedirectUri = ConcatSep('&', $this->RedirectUri(), $Query);
// $RedirectUri = urlencode($RedirectUri);
// Get the access token.
if ($Code) {
// Exchange the token for an access token.
$Code = urlencode($Code);
$AccessToken = $this->GetAccessToken($Code, $RedirectUri);
$NewToken = TRUE;
}
// Get the profile.
try {
$Profile = $this->GetProfile($AccessToken);
} catch (Exception $Ex) {
if (!isset($NewToken)) {
// There was an error getting the profile, which probably means the saved access token is no longer valid. Try and reauthorize.
if ($Sender->DeliveryType() == DELIVERY_TYPE_ALL) {
Redirect($this->AuthorizeUri());
} else {
$Sender->SetHeader('Content-type', 'application/json');
$Sender->DeliveryMethod(DELIVERY_METHOD_JSON);
$Sender->RedirectUrl = $this->AuthorizeUri();
}
} else {
$Sender->Form->AddError('There was an error with the Facebook connection.');
}
}
$Form = $Sender->Form;
//new Gdn_Form();
$ID = GetValue('id', $Profile);
$Form->SetFormValue('UniqueID', $ID);
$Form->SetFormValue('Provider', self::ProviderKey);
$Form->SetFormValue('ProviderName', 'Facebook');
$Form->SetFormValue('FullName', GetValue('name', $Profile));
$Form->SetFormValue('Email', GetValue('email', $Profile));
$Form->SetFormValue('Photo', "http://graph.facebook.com/{$ID}/picture");
if (C('Plugins.Facebook.UseFacebookNames')) {
$Form->SetFormValue('Name', GetValue('name', $Profile));
SaveToConfig(array('Garden.User.ValidationRegex' => UserModel::USERNAME_REGEX_MIN, 'Garden.User.ValidationLength' => '{3,50}', 'Garden.Registration.NameUnique' => FALSE), '', FALSE);
}
// Save some original data in the attributes of the connection for later API calls.
$Attributes = array();
$Attributes[self::ProviderKey] = array('AccessToken' => $AccessToken, 'Profile' => $Profile);
$Form->SetFormValue('Attributes', $Attributes);
$Sender->SetData('Verified', TRUE);
}
示例7: Base_Render_Before
/**
*
* @param Gdn_Controller $Sender
*/
public function Base_Render_Before($Sender)
{
$Session = Gdn::Session();
// Enable theme previewing
if ($Session->IsValid()) {
$PreviewThemeName = $Session->GetPreference('PreviewThemeName', '');
$PreviewThemeFolder = $Session->GetPreference('PreviewThemeFolder', '');
if ($PreviewThemeName != '') {
$Sender->Theme = $PreviewThemeName;
$Sender->InformMessage(sprintf(T('You are previewing the %s theme.'), Wrap($PreviewThemeName, 'em')) . '<div class="PreviewThemeButtons">' . Anchor(T('Apply'), 'settings/themes/' . $PreviewThemeName . '/' . $Session->TransientKey(), 'PreviewThemeButton') . ' ' . Anchor(T('Cancel'), 'settings/cancelpreview/', 'PreviewThemeButton') . '</div>', 'DoNotDismiss');
}
}
if ($Session->IsValid()) {
$ConfirmEmail = C('Garden.Registration.ConfirmEmail', false);
$Confirmed = GetValue('Confirmed', Gdn::Session()->User, true);
if ($ConfirmEmail && !$Confirmed) {
$Message = FormatString(T('You need to confirm your email address.', 'You need to confirm your email address. Click <a href="{/entry/emailconfirmrequest,url}">here</a> to resend the confirmation email.'));
$Sender->InformMessage($Message, '');
}
}
// Add Message Modules (if necessary)
$MessageCache = Gdn::Config('Garden.Messages.Cache', array());
$Location = $Sender->Application . '/' . substr($Sender->ControllerName, 0, -10) . '/' . $Sender->RequestMethod;
$Exceptions = array('[Base]');
// 2011-09-09 - mosullivan - No longer allowing messages in dashboard
// if ($Sender->MasterView == 'admin')
// $Exceptions[] = '[Admin]';
// else if (in_array($Sender->MasterView, array('', 'default')))
if (in_array($Sender->MasterView, array('', 'default'))) {
$Exceptions[] = '[NonAdmin]';
}
// SignIn popup is a special case
$SignInOnly = $Sender->DeliveryType() == DELIVERY_TYPE_VIEW && $Location == 'Dashboard/entry/signin';
if ($SignInOnly) {
$Exceptions = array();
}
if ($Sender->MasterView != 'admin' && !$Sender->Data('_NoMessages') && (GetValue('MessagesLoaded', $Sender) != '1' && $Sender->MasterView != 'empty' && ArrayInArray($Exceptions, $MessageCache, FALSE) || InArrayI($Location, $MessageCache))) {
$MessageModel = new MessageModel();
$MessageData = $MessageModel->GetMessagesForLocation($Location, $Exceptions, $Sender->Data('Category.CategoryID'));
foreach ($MessageData as $Message) {
$MessageModule = new MessageModule($Sender, $Message);
if ($SignInOnly) {
// Insert special messages even in SignIn popup
echo $MessageModule;
} elseif ($Sender->DeliveryType() == DELIVERY_TYPE_ALL) {
$Sender->AddModule($MessageModule);
}
}
$Sender->MessagesLoaded = '1';
// Fixes a bug where render gets called more than once and messages are loaded/displayed redundantly.
}
if ($Sender->DeliveryType() == DELIVERY_TYPE_ALL) {
$Gdn_Statistics = Gdn::Factory('Statistics');
$Gdn_Statistics->Check($Sender);
}
// Allow forum embedding
if ($Embed = C('Garden.Embed.Allow')) {
// Record the remote url where the forum is being embedded.
$RemoteUrl = C('Garden.Embed.RemoteUrl');
if (!$RemoteUrl) {
$RemoteUrl = GetIncomingValue('remote');
if ($RemoteUrl) {
SaveToConfig('Garden.Embed.RemoteUrl', $RemoteUrl);
}
}
if ($RemoteUrl) {
$Sender->AddDefinition('RemoteUrl', $RemoteUrl);
}
// Force embedding?
if (!IsSearchEngine() && !IsMobile() && strtolower($Sender->ControllerName) != 'entry') {
$Sender->AddDefinition('ForceEmbedForum', C('Garden.Embed.ForceForum') ? '1' : '0');
$Sender->AddDefinition('ForceEmbedDashboard', C('Garden.Embed.ForceDashboard') ? '1' : '0');
}
$Sender->AddDefinition('Path', Gdn::Request()->Path());
// $Sender->AddDefinition('MasterView', $Sender->MasterView);
$Sender->AddDefinition('InDashboard', $Sender->MasterView == 'admin' ? '1' : '0');
if ($Embed === 2) {
$Sender->AddJsFile('vanilla.embed.local.js');
} else {
$Sender->AddJsFile('embed_local.js');
}
} else {
$Sender->SetHeader('X-Frame-Options', 'SAMEORIGIN');
}
// Allow return to mobile site
$ForceNoMobile = Gdn_CookieIdentity::GetCookiePayload('VanillaNoMobile');
if ($ForceNoMobile !== FALSE && is_array($ForceNoMobile) && in_array('force', $ForceNoMobile)) {
$Sender->AddAsset('Foot', Wrap(Anchor(T('Back to Mobile Site'), '/profile/nomobile/1'), 'div'), 'MobileLink');
}
}
示例8: Base_Render_Before
/**
*
* @param Gdn_Controller $Sender
*/
public function Base_Render_Before($Sender)
{
$Session = Gdn::Session();
// Enable theme previewing
if ($Session->IsValid()) {
$PreviewThemeName = $Session->GetPreference('PreviewThemeName', '');
$PreviewThemeFolder = $Session->GetPreference('PreviewThemeFolder', '');
if ($PreviewThemeName != '') {
$Sender->Theme = $PreviewThemeName;
$Sender->InformMessage(sprintf(T('You are previewing the %s theme.'), Wrap($PreviewThemeName, 'em')) . '<div class="PreviewThemeButtons">' . Anchor(T('Apply'), 'settings/themes/' . $PreviewThemeName . '/' . $Session->TransientKey(), 'PreviewThemeButton') . ' ' . Anchor(T('Cancel'), 'settings/cancelpreview/', 'PreviewThemeButton') . '</div>', 'DoNotDismiss');
}
}
if ($Session->IsValid() && ($EmailKey = Gdn::Session()->GetAttribute('EmailKey'))) {
$NotifyEmailConfirm = TRUE;
// If this user was manually moved out of the confirmation role, get rid of their 'awaiting confirmation' flag
$ConfirmEmailRole = C('Garden.Registration.ConfirmEmailRole', FALSE);
$UserRoles = array();
$RoleData = Gdn::UserModel()->GetRoles($Session->UserID);
if ($RoleData !== FALSE && $RoleData->NumRows() > 0) {
$UserRoles = ConsolidateArrayValuesByKey($RoleData->Result(DATASET_TYPE_ARRAY), 'RoleID', 'Name');
}
if ($ConfirmEmailRole !== FALSE && !array_key_exists($ConfirmEmailRole, $UserRoles)) {
Gdn::UserModel()->SaveAttribute($Session->UserID, "EmailKey", NULL);
$NotifyEmailConfirm = FALSE;
}
if ($NotifyEmailConfirm) {
$Message = FormatString(T('You need to confirm your email address.', 'You need to confirm your email address. Click <a href="{/entry/emailconfirmrequest,url}">here</a> to resend the confirmation email.'));
$Sender->InformMessage($Message, '');
}
}
// Add Message Modules (if necessary)
$MessageCache = Gdn::Config('Garden.Messages.Cache', array());
$Location = $Sender->Application . '/' . substr($Sender->ControllerName, 0, -10) . '/' . $Sender->RequestMethod;
$Exceptions = array('[Base]');
// 2011-09-09 - mosullivan - No longer allowing messages in dashboard
// if ($Sender->MasterView == 'admin')
// $Exceptions[] = '[Admin]';
// else if (in_array($Sender->MasterView, array('', 'default')))
if (in_array($Sender->MasterView, array('', 'default'))) {
$Exceptions[] = '[NonAdmin]';
}
// SignIn popup is a special case
$SignInOnly = $Sender->DeliveryType() == DELIVERY_TYPE_VIEW && $Location == 'Dashboard/entry/signin';
if ($SignInOnly) {
$Exceptions = array();
}
if ($Sender->MasterView != 'admin' && (GetValue('MessagesLoaded', $Sender) != '1' && $Sender->MasterView != 'empty' && ArrayInArray($Exceptions, $MessageCache, FALSE) || InArrayI($Location, $MessageCache))) {
$MessageModel = new MessageModel();
$MessageData = $MessageModel->GetMessagesForLocation($Location, $Exceptions);
foreach ($MessageData as $Message) {
$MessageModule = new MessageModule($Sender, $Message);
if ($SignInOnly) {
// Insert special messages even in SignIn popup
echo $MessageModule;
} elseif ($Sender->DeliveryType() == DELIVERY_TYPE_ALL) {
$Sender->AddModule($MessageModule);
}
}
$Sender->MessagesLoaded = '1';
// Fixes a bug where render gets called more than once and messages are loaded/displayed redundantly.
}
// If there are applicants, alert admins by showing in the main menu
if (in_array($Sender->MasterView, array('', 'default')) && $Sender->Menu && C('Garden.Registration.Method') == 'Approval') {
// $CountApplicants = Gdn::UserModel()->GetApplicantCount();
// if ($CountApplicants > 0)
// $Sender->Menu->AddLink('Applicants', T('Applicants').' <span class="Alert">'.$CountApplicants.'</span>', '/dashboard/user/applicants', array('Garden.Applicants.Manage'));
$Sender->Menu->AddLink('Applicants', T('Applicants'), '/dashboard/user/applicants', array('Garden.Applicants.Manage'));
}
if ($Sender->DeliveryType() == DELIVERY_TYPE_ALL) {
$Gdn_Statistics = Gdn::Factory('Statistics');
$Gdn_Statistics->Check($Sender);
}
// Allow forum embedding
if (C('Garden.Embed.Allow')) {
// Record the remote url where the forum is being embedded.
$RemoteUrl = C('Garden.Embed.RemoteUrl');
if (!$RemoteUrl) {
$RemoteUrl = GetIncomingValue('remote');
if ($RemoteUrl) {
SaveToConfig('Garden.Embed.RemoteUrl', $RemoteUrl);
}
}
if ($RemoteUrl) {
$Sender->AddDefinition('RemoteUrl', $RemoteUrl);
}
// Force embedding?
if (!IsSearchEngine() && !IsMobile()) {
$Sender->AddDefinition('ForceEmbedForum', C('Garden.Embed.ForceForum') ? '1' : '0');
$Sender->AddDefinition('ForceEmbedDashboard', C('Garden.Embed.ForceDashboard') ? '1' : '0');
}
$Sender->AddDefinition('Path', Gdn::Request()->Path());
// $Sender->AddDefinition('MasterView', $Sender->MasterView);
$Sender->AddDefinition('InDashboard', $Sender->MasterView == 'admin' ? '1' : '0');
$Sender->AddJsFile('js/embed_local.js');
}
// Allow return to mobile site
//.........这里部分代码省略.........
示例9: Base_ConnectData_Handler
/**
*
* @param Gdn_Controller $Sender
* @param array $Args
*/
public function Base_ConnectData_Handler($Sender, $Args)
{
if (GetValue(0, $Args) != 'accounts9') {
return;
}
if (isset($_GET['error'])) {
throw new Gdn_UserException(GetValue('error_description', $_GET, T('There was an error connecting to Accounts9')));
}
$AppID = C('Plugins.Accounts9.ApplicationID');
$Secret = C('Plugins.Accounts9.Secret');
if (!$Code) {
if (!isset($_GET['code'])) {
throw new Gdn_UserException('could not retrieve code out of callback request and no code given');
}
$Code = $_GET['code'];
}
$Code = GetValue('code', $_GET);
/* $Query = '';
if ($Sender->Request->Get('display'))
$Query = 'display='.urlencode($Sender->Request->Get('display'));
*/
$RedirectUri = ConcatSep('&', $this->RedirectUri(), $Query);
$RedirectUri = urlencode($RedirectUri);
// Get the access token.
if ($Code || !($AccessToken = $this->AccessToken())) {
// Exchange the token for an access token.
$Code = urlencode($Code);
$Url = "https://accounts.net9.org/api/access_token?client_id={$AppID}&client_secret={$Secret}&code={$Code}&redirect_uri={$RedirectUri}";
// Get the redirect URI.
$C = curl_init();
curl_setopt($C, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($C, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($C, CURLOPT_URL, $Url);
$Contents = curl_exec($C);
// $Contents = ProxyRequest($Url);
$Info = curl_getinfo($C);
// if (strpos(GetValue('content_type', $Info, ''), '/javascript') !== FALSE) {
$Tokens = json_decode($Contents, TRUE);
/* } else {
parse_str($Contents, $Tokens);
}*/
if (GetValue('error', $Tokens)) {
throw new Gdn_UserException('Accounts9 returned the following error: ' . GetValueR('error.message', $Tokens, 'Unknown error.'), 400);
}
$AccessToken = GetValue('access_token', $Tokens);
$Expires = GetValue('expires_in', $Tokens, NULL);
setcookie('accounts9_access_token', $AccessToken, time() + $Expires, C('Garden.Cookie.Path', '/'), C('Garden.Cookie.Domain', ''));
$NewToken = TRUE;
}
// Get the profile.
try {
$Profile = $this->GetProfile($AccessToken);
} catch (Exception $Ex) {
if (!isset($NewToken)) {
// There was an error getting the profile, which probably means the saved access token is no longer valid. Try and reauthorize.
if ($Sender->DeliveryType() == DELIVERY_TYPE_ALL) {
Redirect($this->AuthorizeUri());
} else {
$Sender->SetHeader('Content-type', 'application/json');
$Sender->DeliveryMethod(DELIVERY_METHOD_JSON);
$Sender->RedirectUrl = $this->AuthorizeUri();
}
} else {
$Sender->Form->AddError('There was an error with the Accounts9 connection.');
}
}
//throw new Gdn_UserException($Profile);
$User = GetValue("user", $Profile);
// throw new Gdn_UserException($User['uid']);
// $User = json_decode($UContents,TRUE);
$Form = $Sender->Form;
//new Gdn_Form();
$ID = GetValue('uid', $User);
$Form->SetFormValue('UniqueID', $ID);
$Form->SetFormValue('Provider', 'accounts9');
$Form->SetFormValue('ProviderName', 'Accounts9');
$Form->SetFormValue('Name', GetValue('name', $User));
$Form->SetFormValue('NickName', GetValue('nickname', $User));
$Form->SetFormValue('FullName', GetValue('username', $User));
$Form->SetFormValue('Email', GetValue('email', $User));
// $Form->SetFormValue('Photo', "http://graph.facebook.com/$ID/picture");
$Sender->SetData('Verified', TRUE);
}