本文整理汇总了PHP中ArrayValue函数的典型用法代码示例。如果您正苦于以下问题:PHP ArrayValue函数的具体用法?PHP ArrayValue怎么用?PHP ArrayValue使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ArrayValue函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: smarty_function_asset
/**
* Renders an asset from the controller.
*
* @param array The parameters passed into the function.
* The parameters that can be passed to this function are as follows.
* - <b>name</b>: The name of the asset.
* - <b>tag</b>: The type of tag to wrap the asset in.
* - <b>id</b>: The id of the tag if different than the name.
* @param Smarty The smarty object rendering the template.
* @return The rendered asset.
*/
function smarty_function_asset($Params, &$Smarty)
{
$Name = ArrayValue('name', $Params);
$Tag = ArrayValue('tag', $Params, '');
$Id = ArrayValue('id', $Params, $Name);
$Class = ArrayValue('class', $Params, '');
if ($Class != '') {
$Class = ' class="' . $Class . '"';
}
$Controller = $Smarty->get_template_vars('Controller');
// Get the asset from the controller.
$Asset = $Controller->GetAsset($Name);
if (!is_string($Asset)) {
ob_start();
$Asset->Render();
$Asset = ob_get_contents();
ob_end_clean();
}
if (!empty($Tag)) {
$Result = '<' . $Tag . ' id="' . $Id . '"' . $Class . '>' . $Asset . '</' . $Tag . '>';
} else {
$Result = $Asset;
}
return $Result;
}
示例2: WebRoot
/**
* Returns the path to the application's dispatcher. Optionally with the
* domain prepended.
* ie. http://domain.com/[web_root]/index.php/request
*
* @param boolean $WithDomain Should it include the domain with the WebRoot? Default is FALSE.
* @return string
*/
public static function WebRoot($WithDomain = FALSE)
{
static $WebRoot = NULL;
if (is_null($WebRoot)) {
// Attempt to get the webroot from the configuration array
$WebRoot = Gdn::Config('Garden.WebRoot');
// Attempt to get the webroot from the server
if ($WebRoot === FALSE) {
$WebRoot = explode('/', ArrayValue('PHP_SELF', $_SERVER, ''));
// Look for index.php to figure out where the web root is.
$Key = array_search('index.php', $WebRoot);
if ($Key !== FALSE) {
$WebRoot = implode('/', array_slice($WebRoot, 0, $Key));
} else {
$WebRoot = '';
}
}
}
if (is_string($WebRoot) && $WebRoot != '') {
// Strip forward slashes from the beginning of webroot
return ($WithDomain ? Gdn_Url::Domain() : '') . preg_replace('/(^\\/+)/', '', $WebRoot);
} else {
return $WithDomain ? Gdn_Url::Domain() : '';
}
}
示例3: smarty_function_asset
/**
* Renders an asset from the controller.
*
* @param array The parameters passed into the function.
* The parameters that can be passed to this function are as follows.
* - <b>name</b>: The name of the asset.
* - <b>tag</b>: The type of tag to wrap the asset in.
* - <b>id</b>: The id of the tag if different than the name.
* @param Smarty The smarty object rendering the template.
* @return The rendered asset.
*/
function smarty_function_asset($Params, &$Smarty)
{
$Name = ArrayValue('name', $Params);
$Tag = ArrayValue('tag', $Params, '');
$Id = ArrayValue('id', $Params, $Name);
$Class = ArrayValue('class', $Params, '');
if ($Class != '') {
$Class = ' class="' . $Class . '"';
}
$Controller = $Smarty->Controller;
$Controller->EventArguments['AssetName'] = $Name;
$Result = '';
ob_start();
$Controller->FireEvent('BeforeRenderAsset');
$Result .= ob_get_clean();
$Asset = $Controller->GetAsset($Name);
if (!is_string($Asset)) {
$Asset->AssetName = $Name;
$Asset = $Asset->ToString();
}
if (!empty($Tag)) {
$Result .= '<' . $Tag . ' id="' . $Id . '"' . $Class . '>' . $Asset . '</' . $Tag . '>';
} else {
$Result .= $Asset;
}
ob_start();
$Controller->FireEvent('AfterRenderAsset');
$Result .= ob_get_clean();
return $Result;
}
示例4: Base_Render_Before
public function Base_Render_Before(&$Sender)
{
$ConfigItem = C('WhosOnline.Location.Show', 'every');
$Controller = $Sender->ControllerName;
$Application = $Sender->ApplicationFolder;
$Session = Gdn::Session();
// Check if its visible to users
if (C('WhosOnline.Hide', TRUE) && !$Session->IsValid()) {
return;
}
$ShowOnController = array();
switch ($ConfigItem) {
case 'every':
$ShowOnController = array('discussioncontroller', 'categoriescontroller', 'discussionscontroller', 'profilecontroller', 'activitycontroller');
break;
case 'discussion':
default:
$ShowOnController = array('discussioncontroller', 'discussionscontroller', 'categoriescontroller');
}
if (!InArrayI($Controller, $ShowOnController)) {
return;
}
$UserMetaData = $this->GetUserMeta($Session->UserID, '%');
include_once PATH_PLUGINS . DS . 'WhosOnline' . DS . 'class.whosonlinemodule.php';
$WhosOnlineModule = new WhosOnlineModule($Sender);
$WhosOnlineModule->GetData(ArrayValue('Plugin.WhosOnline.Invisible', $UserMetaData));
$Sender->AddModule($WhosOnlineModule);
$Sender->AddJsFile('/plugins/WhosOnline/whosonline.js');
$Frequency = C('WhosOnline.Frequency', 4);
if (!is_numeric($Frequency)) {
$Frequency = 4;
}
$Sender->AddDefinition('WhosOnlineFrequency', $Frequency);
}
示例5: RenameColumn
/**
* Renames a column in $this->Table().
*
* @param string $OldName The name of the column to be renamed.
* @param string $NewName The new name for the column being renamed.
* @param string $TableName
* @return boolean
* @todo $TableName needs a description.
*/
public function RenameColumn($OldName, $NewName, $TableName = '') {
if ($TableName != '')
$this->_TableName = $TableName;
// Get the schema for this table
$OldPrefix = $this->Database->DatabasePrefix;
$this->Database->DatabasePrefix = $this->_DatabasePrefix;
$Schema = $this->Database->SQL()->FetchTableSchema($this->_TableName);
$this->Database->DatabasePrefix = $OldPrefix;
// Get the definition for this column
$OldColumn = ArrayValue($OldName, $Schema);
$NewColumn = ArrayValue($NewName, $Schema);
// Make sure that one column, or the other exists
if (!$OldColumn && !$NewColumn)
throw new Exception(sprintf(T('The `%1$s` column does not exist.'),$OldName));
// Make sure the new column name isn't already taken
if ($OldColumn && $NewColumn)
throw new Exception(sprintf(T('You cannot rename the `%1$s` column to `%2$s` because that column already exists.'), $OldName, $NewName));
// Rename the column
// The syntax for renaming a column is:
// ALTER TABLE tablename CHANGE COLUMN oldname newname originaldefinition;
if (!$this->Query('alter table `'.$this->_TableName.'` change column `'.$OldName.'` `'.$NewName.'` '.$this->_DefineColumn($OldColumn)))
throw new Exception(sprintf(T('Failed to rename table `%1$s` to `%2$s`.'), $OldName, $NewName));
return TRUE;
}
示例6: smarty_function_anchor
function smarty_function_anchor($Params, &$Smarty)
{
$Text = ArrayValue('text', $Params, '');
$Destination = ArrayValue('destination', $Params, '');
$CssClass = ArrayValue('class', $Params, '');
return Anchor($Text, $Destination, $CssClass);
}
示例7: IsRemovable
/**
* Is the application/plugin/theme removable?
*
* @param string $Type self::TYPE_APPLICATION or self::TYPE_PLUGIN or self::TYPE_THEME
* @param string $Name
* @return boolean
*/
public static function IsRemovable($Type, $Name)
{
switch ($Type) {
case self::TYPE_APPLICATION:
$ApplicationManager = Gdn::Factory('ApplicationManager');
if ($IsRemovable = !array_key_exists($Name, $ApplicationManager->EnabledApplications())) {
$ApplicationInfo = ArrayValue($Name, $ApplicationManager->AvailableApplications(), array());
$ApplicationFolder = ArrayValue('Folder', $ApplicationInfo, '');
$IsRemovable = IsWritable(PATH_APPLICATIONS . DS . $ApplicationFolder);
}
break;
case self::TYPE_PLUGIN:
if ($IsRemovable = !array_key_exists($Name, Gdn::PluginManager()->EnabledPlugins)) {
$PluginInfo = ArrayValue($Name, Gdn::PluginManager()->AvailablePlugins(), FALSE);
$PluginFolder = ArrayValue('Folder', $PluginInfo, FALSE);
$IsRemovable = IsWritable(PATH_PLUGINS . DS . $PluginFolder);
}
break;
case self::TYPE_THEME:
// TODO
$IsRemovable = FALSE;
break;
}
return $IsRemovable;
}
示例8: Save
public function Save($FormPostValues)
{
$Session = Gdn::Session();
// Define the primary key in this model's table.
$this->DefineSchema();
// Add & apply any extra validation rules:
$this->Validation->ApplyRule('Body', 'Required');
$this->AddInsertFields($FormPostValues);
// Validate the form posted values
$MessageID = FALSE;
if ($this->Validate($FormPostValues)) {
$Fields = $this->Validation->SchemaValidationFields();
// All fields on the form that relate to the schema
$MessageID = $this->SQL->Insert($this->Name, $Fields);
$ConversationID = ArrayValue('ConversationID', $Fields, 0);
// Update the conversation's DateUpdated field
$this->SQL->Update('Conversation')->Set('DateUpdated', Format::ToDateTime())->Set('UpdateUserID', $Session->UserID)->Where('ConversationID', $ConversationID)->Put();
// NOTE: INCREMENTING COUNTS INSTEAD OF GETTING ACTUAL COUNTS COULD
// BECOME A PROBLEM. WATCH FOR IT.
// Update the message counts for all users in the conversation
$this->SQL->Update('UserConversation')->Set('CountMessages', 'CountMessages + 1', FALSE)->Where('ConversationID', $ConversationID)->Put();
$this->SQL->Update('UserConversation')->Set('CountNewMessages', 'CountNewMessages + 1', FALSE)->Where('ConversationID', $ConversationID)->Where('UserID <>', $Session->UserID)->Put();
// Update the CountUnreadConversations count on each user related to the discussion.
$this->UpdateCountUnreadConversations($ConversationID, $Session->UserID);
// Update the userconversation records to reflect the most recently
// added message for all users other than the one that added the
// message (otherwise they would see their name/message on the
// conversation list instead of the person they are conversing with).
$this->SQL->Update('UserConversation')->Set('LastMessageID', $MessageID)->Where('ConversationID', $ConversationID)->Where('UserID <>', $Session->UserID)->Put();
}
return $MessageID;
}
示例9: _AttachBadge
protected function _AttachBadge(&$Sender)
{
$badge = ArrayValue($Sender->EventArguments['Author']->UserID, $Sender->Data('Plugin-Badge-Counts'));
if ($badge > 0) {
$icon = file_exists('plugins/TopPosters/badges/' . $badge . '.png') ? $badge . '.png' : 'medal-icon.png';
echo '<span><img src="' . str_replace("index.php?p=", "", Gdn::Request()->Domain() . Url('plugins/TopPosters/badges/' . $icon)) . '" style="width:16px;height:16px;vertical-align:middle"></span>';
}
}
示例10: smarty_function_url
/**
* Takes a route and prepends the web root (expects "/controller/action/params" as $Destination).
*
* @param array The parameters passed into the function.
* The parameters that can be passed to this function are as follows.
* - <b>dest</b>: The destination of the url.
* - <b>domain</b>: Whether or not to add the domain to the url.
* - <b>removeSyndication</b>: Whether or not to remove any syndication from the url.
* @param Smarty The smarty object rendering the template.
* @return The url.
*/
function smarty_function_url($Params, &$Smarty)
{
$Destination = ArrayValue('dest', $Params, '');
$WithDomain = ArrayValue('domain', $Params, FALSE);
$RemoveSyndication = ArrayValue('removeSyndication', $Params, FALSE);
$Result = Url($Destination, $WithDomain, $RemoveSyndication);
return $Result;
}
示例11: Save
public function Save($FormPostValues)
{
$Session = Gdn::Session();
// Define the primary key in this model's table.
$this->DefineSchema();
// Add & apply any extra validation rules:
$this->Validation->ApplyRule('Body', 'Required');
$MaxCommentLength = Gdn::Config('Vanilla.Comment.MaxLength');
if (is_numeric($MaxCommentLength) && $MaxCommentLength > 0) {
$this->Validation->SetSchemaProperty('Body', 'Length', $MaxCommentLength);
$this->Validation->ApplyRule('Body', 'Length');
}
// Get the DraftID from the form so we know if we are inserting or updating.
$DraftID = ArrayValue('DraftID', $FormPostValues, '');
$Insert = $DraftID == '' ? TRUE : FALSE;
// Remove the discussionid from the form value collection if it's empty
if (array_key_exists('DiscussionID', $FormPostValues) && $FormPostValues['DiscussionID'] == '') {
unset($FormPostValues['DiscussionID']);
}
if ($Insert) {
// If no categoryid is defined, grab the first available.
if (ArrayValue('CategoryID', $FormPostValues) === FALSE) {
$FormPostValues['CategoryID'] = $this->SQL->Get('Category', '', '', 1)->FirstRow()->CategoryID;
}
}
// Add the update fields because this table's default sort is by DateUpdated (see $this->Get()).
$this->AddInsertFields($FormPostValues);
$this->AddUpdateFields($FormPostValues);
// Remove checkboxes from the fields if they were unchecked
if (ArrayValue('Announce', $FormPostValues, '') === FALSE) {
unset($FormPostValues['Announce']);
}
if (ArrayValue('Closed', $FormPostValues, '') === FALSE) {
unset($FormPostValues['Closed']);
}
if (ArrayValue('Sink', $FormPostValues, '') === FALSE) {
unset($FormPostValues['Sink']);
}
// Validate the form posted values
if ($this->Validate($FormPostValues, $Insert)) {
$Fields = $this->Validation->SchemaValidationFields();
// All fields on the form that relate to the schema
$DraftID = intval(ArrayValue('DraftID', $Fields, 0));
// If the post is new and it validates, make sure the user isn't spamming
if ($DraftID > 0) {
// Update the draft
$Fields = RemoveKeyFromArray($Fields, 'DraftID');
// Remove the primary key from the fields for saving
$this->SQL->Put($this->Name, $Fields, array($this->PrimaryKey => $DraftID));
} else {
// Insert the draft
unset($Fields['DraftID']);
$DraftID = $this->SQL->Insert($this->Name, $Fields);
$this->UpdateUser($Session->UserID);
}
}
return $DraftID;
}
示例12: Gdn_HandshakeAuthenticator_AfterGetHandshakeData_Handler
public function Gdn_HandshakeAuthenticator_AfterGetHandshakeData_Handler(&$Sender)
{
$HandshakeData = ArrayValue('HandshakeData', $Sender->EventArguments);
if (is_array($HandshakeData)) {
// var_dump($HandshakeData);
// exit();
// Do something based on the data returned from the handshake...
}
}
示例13: Edit
public function Edit($RouteIndex = FALSE) {
$this->Permission('Garden.Routes.Manage');
$this->AddSideMenu('dashboard/routes');
$this->Route = Gdn::Router()->GetRoute($RouteIndex);
$Validation = new Gdn_Validation();
$ConfigurationModel = new Gdn_ConfigurationModel($Validation);
$ConfigurationModel->SetField(array('Route', 'Target', 'Type'));
// Set the model on the form.
$this->Form->SetModel($ConfigurationModel);
// If seeing the form for the first time...
if (!$this->Form->AuthenticatedPostBack()) {
// Apply the route info to the form.
if ($this->Route !== FALSE)
$this->Form->SetData(array(
'Route' => $this->Route['Route'],
'Target' => $this->Route['Destination'],
'Type' => $this->Route['Type']
));
} else {
// Define some validation rules for the fields being saved
$ConfigurationModel->Validation->ApplyRule('Route', 'Required');
$ConfigurationModel->Validation->ApplyRule('Target', 'Required');
$ConfigurationModel->Validation->ApplyRule('Type', 'Required');
// Validate & Save
$FormPostValues = $this->Form->FormValues();
// Dunno.
if ($this->Route['Reserved'])
$FormPostValues['Route'] = $this->Route['Route'];
if ($ConfigurationModel->Validate($FormPostValues)) {
$NewRouteName = ArrayValue('Route', $FormPostValues);
if ($this->Route !== FALSE && $NewRouteName != $this->Route['Route'])
Gdn::Router()->DeleteRoute($this->Route['Route']);
Gdn::Router()->SetRoute(
$NewRouteName,
ArrayValue('Target', $FormPostValues),
ArrayValue('Type', $FormPostValues)
);
$this->InformMessage(T("The route was saved successfully."));
$this->RedirectUrl = Url('dashboard/routes');
} else {
$this->Form->SetValidationResults($ConfigurationModel->ValidationResults());
}
}
$this->Render();
}
示例14: Setup
/**
* Special function automatically run upon clicking 'Enable' on your application.
* Change the word 'skeleton' anywhere you see it.
*/
public function Setup() {
// You need to manually include structure.php here for it to get run at install.
include(PATH_APPLICATIONS . DS . 'skeleton' . DS . 'settings' . DS . 'structure.php');
// This just gets the version number and stores it in the config file. Good practice but optional.
$ApplicationInfo = array();
include(CombinePaths(array(PATH_APPLICATIONS . DS . 'skeleton' . DS . 'settings' . DS . 'about.php')));
$Version = ArrayValue('Version', ArrayValue('Skeleton', $ApplicationInfo, array()), 'Undefined');
SaveToConfig('Skeleton.Version', $Version);
}
示例15: Save
public function Save($FormPostValues, $UserModel)
{
$Session = Gdn::Session();
$UserID = $Session->UserID;
// Define the primary key in this model's table.
$this->DefineSchema();
// Add & apply any extra validation rules:
$this->Validation->ApplyRule('Email', 'Email');
// Make sure required db fields are present
$this->AddInsertFields($FormPostValues);
$FormPostValues['Code'] = $this->GetInvitationCode();
// Validate the form posted values
if ($this->Validate($FormPostValues, TRUE) === TRUE) {
$Fields = $this->Validation->ValidationFields();
// All fields on the form that need to be validated
$Email = ArrayValue('Email', $Fields, '');
// Make sure this user has a spare invitation to send.
$InviteCount = $UserModel->GetInvitationCount($UserID);
if ($InviteCount == 0) {
$this->Validation->AddValidationResult('Email', 'You do not have enough invitations left.');
return FALSE;
}
// Make sure that the email does not already belong to an account in the application.
$TestData = $UserModel->GetWhere(array('Email' => $Email));
if ($TestData->NumRows() > 0) {
$this->Validation->AddValidationResult('Email', 'The email you have entered is already related to an existing account.');
return FALSE;
}
// Make sure that the email does not already belong to an invitation in the application.
$TestData = $this->GetWhere(array('Email' => $Email));
if ($TestData->NumRows() > 0) {
$this->Validation->AddValidationResult('Email', 'An invitation has already been sent to the email you entered.');
return FALSE;
}
// Define the fields to be inserted
$Fields = $this->Validation->SchemaValidationFields();
// Call the base model for saving
$InvitationID = $this->Insert($Fields);
// Now that saving has succeeded, update the user's invitation settings
if ($InviteCount > 0) {
$UserModel->ReduceInviteCount($UserID);
}
// And send the invitation email
try {
$this->Send($InvitationID);
} catch (Exception $ex) {
$this->Validation->AddValidationResult('Email', sprintf(T('Although the invitation was created successfully, the email failed to send. The server reported the following error: %s'), strip_tags($ex->getMessage())));
return FALSE;
}
return TRUE;
}
return FALSE;
}