本文整理汇总了PHP中Gdn::Get方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn::Get方法的具体用法?PHP Gdn::Get怎么用?PHP Gdn::Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn
的用法示例。
在下文中一共展示了Gdn::Get方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Index
public function Index() {
$this->Permission('Garden.Settings.Manage');
$this->AddSideMenu('dashboard/statistics');
//$this->AddJsFile('statistics.js');
$this->Title(T('Vanilla Statistics'));
$this->EnableSlicing($this);
if ($this->Form->IsPostBack()) {
$Flow = TRUE;
if ($Flow && $this->Form->GetFormValue('ClearCredentials')) {
Gdn::InstallationID(FALSE);
Gdn::InstallationSecret(FALSE);
Gdn::Statistics()->Tick();
$Flow = FALSE;
}
if ($Flow && $this->Form->GetFormValue('SaveIdentity')) {
Gdn::InstallationID($this->Form->GetFormValue('InstallationID'));
Gdn::InstallationSecret($this->Form->GetFormValue('InstallationSecret'));
$this->InformMessage(T("Your settings have been saved."));
}
if ($Flow && $this->Form->GetFormValue('AllowLocal')) {
SaveToConfig('Garden.Analytics.AllowLocal', TRUE);
}
if ($Flow && $this->Form->GetFormValue('Allow')) {
SaveToConfig('Garden.Analytics.Enabled', TRUE);
}
}
$AnalyticsEnabled = Gdn_Statistics::CheckIsEnabled();
if ($AnalyticsEnabled) {
$ConfFile = PATH_LOCAL_CONF.DS.'config.php';
$this->SetData('ConfWritable', $ConfWritable = is_writable($ConfFile));
if (!$ConfWritable)
$AnalyticsEnabled = FALSE;
}
$this->SetData('AnalyticsEnabled', $AnalyticsEnabled);
$NotifyMessage = Gdn::Get('Garden.Analytics.Notify', FALSE);
$this->SetData('NotifyMessage', $NotifyMessage);
if ($NotifyMessage !== FALSE)
Gdn::Set('Garden.Analytics.Notify', NULL);
$this->Form->SetFormValue('InstallationID', Gdn::InstallationID());
$this->Form->SetFormValue('InstallationSecret', Gdn::InstallationSecret());
$this->Render();
}
示例2: DiscussionsController_AfterRenderAsset_Handler
public function DiscussionsController_AfterRenderAsset_Handler($Sender)
{
$AssetName = GetValueR('EventArguments.AssetName', $Sender);
if ($AssetName != "Content") {
return;
}
$CurTime = time();
$LastTime = Gdn::Get('TimeCheck', $LastTime);
$SFVcount = Gdn::Get('ViewCount', $SFVcount);
$SFUcount = Gdn::Get('UserCount', $SFUcount);
$SFDcount = Gdn::Get('DiscussionCount', $SFDcount);
$SFCcount = Gdn::Get('CommentCount', $SFCcount);
// refresh counts every 60 seconds unless config is set
// e.g. $Configuration['Plugins']['StatisticsFooter']['Refresh'] = '90';
$IncSec = C('Plugins.StatisticsFooter.Refresh', 60);
if ($CurTime > $LastTime) {
$LastTime = time() + $IncSec;
Gdn::Set('TimeCheck', $LastTime);
$SFVcount = $this->GetViewCount();
Gdn::Set('ViewCount', $SFVcount);
$SFUcount = $this->GetUserCount();
Gdn::Set('UserCount', $SFUcount);
$SFDcount = $this->GetDiscussionCount();
Gdn::Set('DiscussionCount', $SFDcount);
$SFCcount = $this->GetCommentCount();
Gdn::Set('CommentCount', $SFCcount);
}
$SFPcount = $SFDcount + $SFCcount;
$ShowMe = C('Plugins.StatisticsFooter.Show');
if (strpos($ShowMe, "v") !== FALSE) {
echo Wrap(Wrap(T('View Count')) . Gdn_Format::BigNumber($SFVcount), 'div', array('class' => 'SFBox SFVCBox'));
}
if (strpos($ShowMe, "u") !== FALSE) {
echo Wrap(Wrap(T('User Count')) . Gdn_Format::BigNumber($SFUcount), 'div', array('class' => 'SFBox SFUBox'));
}
if (strpos($ShowMe, "t") !== FALSE) {
echo Wrap(Wrap(T('Topic Count')) . Gdn_Format::BigNumber($SFDcount), 'div', array('class' => 'SFBox SFTBox'));
}
if (strpos($ShowMe, "c") !== FALSE) {
echo Wrap(Wrap(T('Post Count')) . Gdn_Format::BigNumber($SFPcount), 'div', array('class' => 'SFBox SFPBox'));
}
}
示例3: Update
public function Update() {
// Check for permission or flood control.
// These settings are loaded/saved to the database because we don't want the config file storing non/config information.
$Now = time();
$LastTime = Gdn::Get('Garden.Update.LastTimestamp', 0);
if ($LastTime + (60 * 60 * 24) > $Now) {
// Check for flood control.
$Count = Gdn::Get('Garden.Update.Count', 0) + 1;
if ($Count > 5) {
if (!Gdn::Session()->CheckPermission('Garden.Settings.Manage')) {
// We are only allowing an update of 5 times every 24 hours.
throw PermissionException();
}
}
} else {
$Count = 1;
}
Gdn::Set('Garden.Update.LastTimestamp', $Now);
Gdn::Set('Garden.Update.Count', $Count);
// Run the structure.
$UpdateModel = new UpdateModel();
$UpdateModel->RunStructure();
$this->SetData('Success', TRUE);
$this->MasterView = 'none';
$this->Render();
}
示例4: Tick
/**
* This is the asynchronous callback
*
* This method is triggerd on every page request via a callback AJAX request
* so that it may execute asychronously and reduce lag for users. It tracks
* views, handles registration for new installations, and sends stats every
* day as needed.
*
* @return void;
*/
public function Tick()
{
// If we're local and not allowed, or just directly disabled, gtfo
if (!self::CheckIsEnabled()) {
return;
}
if (Gdn::Session()->CheckPermission('Garden.Settings.Manage')) {
if (Gdn::Get('Garden.Analytics.Notify', FALSE) !== FALSE) {
$CallMessage = '<span class="InformSprite Bandaid"></span> ';
$CallMessage .= sprintf(T("There's a problem with Vanilla Analytics that needs your attention.<br/> Handle it <a href=\"%s\">here »</a>"), Url('dashboard/statistics'));
Gdn::Controller()->InformMessage($CallMessage, array('CssClass' => 'HasSprite'));
}
}
// If the config file is not writable, gtfo
$ConfFile = PATH_LOCAL_CONF . DS . 'config.php';
if (!is_writable($ConfFile)) {
return;
}
$InstallationID = Gdn::InstallationID();
// Check if we're registered with the central server already. If not, this request is
// hijacked and used to perform that task instead of sending stats or recording a tick.
if (is_null($InstallationID)) {
$AttemptedRegistration = Gdn::Get('Garden.Analytics.Registering', FALSE);
// If we last attempted to register less than 60 seconds ago, do nothing. Could still be working.
if ($AttemptedRegistration !== FALSE && time() - $AttemptedRegistration < 60) {
return;
}
return $this->Register();
}
// Add a pageview entry.
$TimeSlot = date('Ymd');
$Px = Gdn::Database()->DatabasePrefix;
try {
Gdn::Database()->Query("insert into {$Px}AnalyticsLocal (TimeSlot, Views) values (:TimeSlot, 1)\n on duplicate key update Views = Views+1", array(':TimeSlot' => $TimeSlot));
} catch (Exception $e) {
// If we just tried to run the structure, and failed, don't blindly try again.
// Just disable ourselves quietly.
if (Gdn::Get('Garden.Analytics.AutoStructure', FALSE)) {
SaveToConfig('Garden.Analytics.Enabled', FALSE);
Gdn::Set('Garden.Analytics.AutoStructure', NULL);
return;
}
// If we get here, insert failed. Try proxyconnect to the utility structure
Gdn::Set('Garden.Analytics.AutoStructure', TRUE);
ProxyRequest(Url('utility/update', TRUE), 0, FALSE);
}
// If we get here and this is true, we successfully ran the auto structure. Remove config flag.
if (Gdn::Get('Garden.Analytics.AutoStructure', FALSE)) {
Gdn::Set('Garden.Analytics.AutoStructure', NULL);
}
// Fire an event for plugins to track their own stats.
// TODO: Make this analyze the path and throw a specific event (this event will change in future versions).
$this->EventArguments['Path'] = Gdn::Request()->Post('Path');
$this->FireEvent('Tick');
// If we get here, the installation is registered and we can decide on whether or not to send stats now.
$LastSentDate = self::LastSentDate();
if (empty($LastSentDate) || $LastSentDate < date('Ymd', strtotime('-1 day'))) {
return $this->Stats();
}
}
示例5: Update
/**
* Run a structure update on the database.
*
* @since 2.0.?
* @access public
*/
public function Update()
{
try {
// Check for permission or flood control.
// These settings are loaded/saved to the database because we don't want the config file storing non/config information.
$Now = time();
$LastTime = Gdn::Get('Garden.Update.LastTimestamp', 0);
if ($LastTime + 60 * 60 * 24 > $Now) {
// Check for flood control.
$Count = Gdn::Get('Garden.Update.Count', 0) + 1;
if ($Count > 5) {
if (!Gdn::Session()->CheckPermission('Garden.Settings.Manage')) {
// We are only allowing an update of 5 times every 24 hours.
throw PermissionException();
}
}
} else {
$Count = 1;
}
Gdn::Set('Garden.Update.LastTimestamp', $Now);
Gdn::Set('Garden.Update.Count', $Count);
} catch (PermissionException $Ex) {
return;
} catch (Exception $Ex) {
}
try {
// Run the structure.
$UpdateModel = new UpdateModel();
$UpdateModel->RunStructure();
$this->SetData('Success', TRUE);
} catch (Exception $Ex) {
$this->SetData('Success', FALSE);
if (Debug()) {
throw $Ex;
}
}
if (Gdn::Session()->CheckPermission('Garden.Settings.Manage')) {
SaveToConfig('Garden.Version', APPLICATION_VERSION);
}
if ($Target = $this->Request->Get('Target')) {
Redirect($Target);
}
$this->FireEvent('AfterUpdate');
$this->MasterView = 'empty';
$this->CssClass = 'Home';
$this->Render();
}
示例6: GetBatch
public function GetBatch($Table, $Key, $Limit = 10000, $Max = FALSE)
{
$Key = "DBA.Range.{$Key}";
// See if there is already a range.
$Current = @unserialize(Gdn::Get($Key, ''));
if (!is_array($Current) || !isset($Current['Min']) || !isset($Current['Max'])) {
list($Current['Min'], $Current['Max']) = $this->PrimaryKeyRange($Table);
if ($Max && $Current['Max'] > $Max) {
$Current['Max'] = $Max;
}
}
if (!isset($Current['To'])) {
$Current['To'] = $Current['Max'];
} else {
$Current['To'] -= $Limit - 1;
}
$Current['From'] = $Current['To'] - $Limit;
Gdn::Set($Key, serialize($Current));
$Current['Complete'] = $Current['To'] < $Current['Min'];
$Total = $Current['Max'] - $Current['Min'];
if ($Total > 0) {
$Complete = $Current['Max'] - $Current['From'];
$Percent = 100 * $Complete / $Total;
if ($Percent > 100) {
$Percent = 100;
}
$Current['Percent'] = round($Percent) . '%';
}
return $Current;
}
示例7: Tick
/**
* This is the asynchronous callback
*
* This method is triggerd on every page request via a callback AJAX request
* so that it may execute asychronously and reduce lag for users. It tracks
* views, handles registration for new installations, and sends stats every
* day as needed.
*
* @return void;
*/
public function Tick()
{
// If we're local and not allowed, or just directly disabled, gtfo
if (!self::CheckIsEnabled()) {
return;
}
if (Gdn::Session()->CheckPermission('Garden.Settings.Manage')) {
if (Gdn::Get('Garden.Analytics.Notify', FALSE) !== FALSE) {
$CallMessage = Sprite('Bandaid', 'InformSprite');
$CallMessage .= sprintf(T("There's a problem with Vanilla Analytics that needs your attention.<br/> Handle it <a href=\"%s\">here »</a>"), Url('dashboard/statistics'));
Gdn::Controller()->InformMessage($CallMessage, array('CssClass' => 'HasSprite'));
}
}
// If the config file is not writable, gtfo
$ConfFile = PATH_CONF . '/config.php';
if (!is_writable($ConfFile)) {
return;
}
$InstallationID = Gdn::InstallationID();
// Check if we're registered with the central server already. If not, this request is
// hijacked and used to perform that task instead of sending stats or recording a tick.
if (is_null($InstallationID)) {
$AttemptedRegistration = Gdn::Get('Garden.Analytics.Registering', FALSE);
// If we last attempted to register less than 60 seconds ago, do nothing. Could still be working.
if ($AttemptedRegistration !== FALSE && time() - $AttemptedRegistration < 60) {
return;
}
return $this->Register();
}
// Store the view, using denormalization if enabled
$ViewType = 'normal';
if (preg_match('`discussion/embed`', Gdn::Request()->Post('ResolvedPath', ''))) {
$ViewType = 'embed';
}
$this->AddView($ViewType);
// Fire an event for plugins to track their own stats.
// TODO: Make this analyze the path and throw a specific event (this event will change in future versions).
$this->EventArguments['Path'] = Gdn::Request()->Post('Path');
$this->FireEvent('Tick');
// If we get here, the installation is registered and we can decide on whether or not to send stats now.
$LastSentDate = self::LastSentDate();
if (empty($LastSentDate) || $LastSentDate < date('Ymd', strtotime('-1 day'))) {
return $this->Stats();
}
}