本文整理汇总了PHP中valr函数的典型用法代码示例。如果您正苦于以下问题:PHP valr函数的具体用法?PHP valr怎么用?PHP valr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了valr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: smarty_function_custom_menu
/**
* A placeholder for future menu items.
*
* @param array $Params The parameters passed into the function.
* @param Smarty $Smarty The smarty object rendering the template.
* @return string
*/
function smarty_function_custom_menu($Params, &$Smarty)
{
$Controller = $Smarty->Controller;
if (is_object($Menu = val('Menu', $Controller))) {
$Format = val('format', $Params, wrap('<a href="%url" class="%class">%text</a>', val('wrap', $Params, 'li')));
$Result = '';
foreach ($Menu->Items as $Group) {
foreach ($Group as $Item) {
// Make sure the item is a custom item.
if (valr('Attributes.Standard', $Item)) {
continue;
}
// Make sure the user has permission for the item.
if ($Permission = val('Permission', $Item)) {
if (!Gdn::session()->checkPermission($Permission)) {
continue;
}
}
if (($Url = val('Url', $Item)) && ($Text = val('Text', $Item))) {
$Attributes = val('Attributes', $Item);
$Result .= Gdn_Theme::link($Url, $Text, $Format, $Attributes) . "\r\n";
}
}
}
return $Result;
}
return '';
}
开发者ID:caidongyun,项目名称:vanilla,代码行数:35,代码来源:function.custom_menu.php
示例2: cachePageWhere
/**
*
*
* @param $Result
* @param $PageWhere
* @param $DiscussionID
* @param $Page
* @param null $Limit
*/
public function cachePageWhere($Result, $PageWhere, $DiscussionID, $Page, $Limit = null)
{
if (!$this->pageCache || !empty($this->_Where) || $this->_OrderBy[0][0] != 'c.DateInserted' || $this->_OrderBy[0][1] == 'desc') {
return;
}
if (count($Result) == 0) {
return;
}
$ConfigLimit = c('Vanilla.Comments.PerPage', 30);
if (!$Limit) {
$Limit = $ConfigLimit;
}
if ($Limit != $ConfigLimit) {
return;
}
if (is_array($PageWhere)) {
$Curr = array_values($PageWhere);
} else {
$Curr = false;
}
$New = array(GetValueR('0.DateInserted', $Result));
if (count($Result) >= $Limit) {
$New[] = valr($Limit - 1 . '.DateInserted', $Result);
}
if ($Curr != $New) {
trace('CommentModel->CachePageWhere()');
$CacheKey = "Comment.Page.{$Limit}.{$DiscussionID}.{$Page}";
Gdn::cache()->store($CacheKey, $New, array(Gdn_Cache::FEATURE_EXPIRY => 86400));
trace($New, $CacheKey);
// Gdn::controller()->setData('_PageCacheStore', array($CacheKey, $New));
}
}
开发者ID:mcnasby,项目名称:datto-vanilla,代码行数:41,代码来源:class.commentmodel.php
示例3: discussionModel_afterSaveDiscussion_handler
public function discussionModel_afterSaveDiscussion_handler($Sender)
{
$FormPostValues = val('FormPostValues', $Sender->EventArguments, array());
$url = valr("Discussion.Url", $Sender->EventArguments);
if (val('IsNewDiscussion', $FormPostValues, false) !== false) {
$this->_push(array($url));
}
}
开发者ID:xjtdy888,项目名称:vanilla-BaiduURLPush,代码行数:8,代码来源:class.baiduurlpush.plugin.php
示例4: check
/**
*
*
* @param $Data
* @param $Options
* @return bool
*/
public static function check(&$Data, &$Options)
{
// Make the request.
$Get = array();
if (isset($Data['IPAddress'])) {
$AddIP = true;
// Don't check against the localhost.
foreach (array('127.0.0.1/0', '10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16') as $LocalCIDR) {
if (Gdn_Statistics::cidrCheck($Data['IPAddress'], $LocalCIDR)) {
$AddIP = false;
break;
}
}
if ($AddIP) {
$Get['ip'] = $Data['IPAddress'];
}
}
if (isset($Data['Username'])) {
$Get['username'] = $Data['Username'];
}
if (isset($Data['Email'])) {
$Get['email'] = $Data['Email'];
}
if (empty($Get)) {
return false;
}
$Get['f'] = 'json';
$Url = "http://www.stopforumspam.com/api?" . http_build_query($Get);
$Curl = curl_init();
curl_setopt($Curl, CURLOPT_URL, $Url);
curl_setopt($Curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($Curl, CURLOPT_TIMEOUT, 4);
curl_setopt($Curl, CURLOPT_FAILONERROR, 1);
$ResultString = curl_exec($Curl);
curl_close($Curl);
if ($ResultString) {
$Result = json_decode($ResultString, true);
$IPFrequency = valr('ip.frequency', $Result, 0);
$EmailFrequency = valr('email.frequency', $Result, 0);
$IsSpam = false;
// Flag registrations as spam above a certain threshold.
if ($IPFrequency >= c('Plugins.StopForumSpam.IPThreshold1', 5) || $EmailFrequency >= c('Plugins.StopForumSpam.EmailThreshold1', 20)) {
$IsSpam = true;
}
// Don't even log registrations that are above another threahold.
if ($IPFrequency >= c('Plugins.StopForumSpam.IPThreshold2', 20) || $EmailFrequency >= c('Plugins.StopForumSpam.EmailThreshold2', 50)) {
$Options['Log'] = false;
}
if ($Result) {
$Data['_Meta']['IP Frequency'] = $IPFrequency;
$Data['_Meta']['Email Frequency'] = $EmailFrequency;
}
return $IsSpam;
}
return false;
}
开发者ID:sitexa,项目名称:vanilla,代码行数:63,代码来源:class.stopforumspam.plugin.php
示例5: getTutorials
/**
* Get all tutorials, or a specific one.
*/
function getTutorials($TutorialCode = '')
{
// Define all Tutorials
$Tutorials = array(array('Code' => 'introduction', 'Name' => 'Introduction to Vanilla', 'Description' => 'This video gives you a brief overview of the Vanilla administrative dashboard and the forum itself.', 'VideoID' => '31043422'), array('Code' => 'using-the-forum', 'Name' => 'Using the Forum', 'Description' => 'Learn how to start, announce, close, edit and delete discussions and comments.', 'VideoID' => '31502992'), array('Code' => 'private-conversations', 'Name' => 'Private Conversations', 'Description' => 'Learn how to start new private conversations and add people to them.', 'VideoID' => '31498383'), array('Code' => 'user-profiles', 'Name' => 'User Profiles', 'Description' => 'Learn how to use and manage your user profile. ', 'VideoID' => '31499266'), array('Code' => 'appearance', 'Name' => 'Changing the appearance of your forum', 'Description' => 'This tutorial takes you through the "Appearance" section of the Vanilla Forums administrative dashboard.', 'VideoID' => '31089641'), array('Code' => 'roles-and-permissions', 'Name' => 'Managing Roles and Permissions in Vanilla', 'Description' => 'This tutorial walks you through how to create new roles and how to use permissions.', 'VideoID' => '31091056'), array('Code' => 'users', 'Name' => 'Finding & Managing Users', 'Description' => 'This tutorial shows you how to search for and manage users.', 'VideoID' => '31094514'), array('Code' => 'category-management-and-advanced-settings', 'Name' => 'Category Management & Advanced Settings', 'Description' => 'Learn how to add, edit, and manage categories. Also learn about advanced forum settings.', 'VideoID' => '31492046'), array('Code' => 'user-registration', 'Name' => 'User Registration', 'Description' => 'Learn to control how new users get into your community.', 'VideoID' => '31493119'));
// Default Thumbnails
$Thumbnail = Asset('applications/dashboard/design/images/help-tn-200.jpg');
$LargeThumbnail = Asset('applications/dashboard/design/images/help-tn-640.jpg');
for ($i = 0; $i < count($Tutorials); $i++) {
$Tutorials[$i]['Thumbnail'] = $Thumbnail;
$Tutorials[$i]['LargeThumbnail'] = $LargeThumbnail;
}
if ($TutorialCode != '') {
$Keys = consolidateArrayValuesByKey($Tutorials, 'Code');
$Index = array_search($TutorialCode, $Keys);
if ($Index === FALSE) {
return FALSE;
}
// Not found!
// Found it, so define it's thumbnail location
$Tutorial = val($Index, $Tutorials);
$VideoID = val('VideoID', $Tutorial);
try {
$Vimeo = unserialize(file_get_contents("http://vimeo.com/api/v2/video/" . $Tutorial['VideoID'] . ".php"));
$Tutorial['Thumbnail'] = str_replace('http://', '//', valr('0.thumbnail_medium', $Vimeo));
$Tutorial['LargeThumbnail'] = str_replace('http://', '//', valr('0.thumbnail_large', $Vimeo));
} catch (Exception $Ex) {
// Do nothing
}
return $Tutorial;
} else {
// Loop through each tutorial populating the thumbnail image location
try {
foreach ($Tutorials as $Key => $Tutorial) {
$Vimeo = unserialize(file_get_contents("http://vimeo.com/api/v2/video/" . $Tutorial['VideoID'] . ".php"));
$Tutorial['Thumbnail'] = str_replace('http://', '//', valr('0.thumbnail_medium', $Vimeo));
$Tutorial['LargeThumbnail'] = str_replace('http://', '//', valr('0.thumbnail_large', $Vimeo));
}
} catch (Exception $Ex) {
// Do nothing
}
return $Tutorials;
}
}
开发者ID:karanjitsingh,项目名称:iecse-forum,代码行数:46,代码来源:helper_functions.php
示例6: writeConnection
function writeConnection($Row)
{
$c = Gdn::controller();
$Connected = val('Connected', $Row);
?>
<li id="<?php
echo "Provider_{$Row['ProviderKey']}";
?>
" class="Item">
<div class="Connection-Header">
<span class="IconWrap">
<?php
echo img(val('Icon', $Row, Asset('/applications/dashboard/design/images/connection-64.png')));
?>
</span>
<span class="Connection-Name">
<?php
echo val('Name', $Row, t('Unknown'));
if ($Connected) {
echo ' <span class="Gloss Connected">';
if ($Photo = valr('Profile.Photo', $Row)) {
echo ' ' . Img($Photo, array('class' => 'ProfilePhoto ProfilePhotoSmall'));
}
echo ' ' . htmlspecialchars(GetValueR('Profile.Name', $Row)) . '</span>';
}
?>
</span>
<span class="Connection-Connect">
<?php
echo ConnectButton($Row);
?>
</span>
</div>
<!-- <div class="Connection-Body">
<?php
// if (Debug()) {
// decho(val($Row['ProviderKey'], $c->User->Attributes), 'Attributes');
// }
?>
</div>-->
</li>
<?php
}
开发者ID:vanilla,项目名称:vanilla,代码行数:43,代码来源:connection_functions.php
示例7: comment
//.........这里部分代码省略.........
if ($this->Form->errorCount() > 0) {
// Return the form errors
$this->errorMessage($this->Form->errors());
} else {
// Make sure that the ajax request form knows about the newly created comment or draft id
$this->setJson('CommentID', $CommentID);
$this->setJson('DraftID', $DraftID);
if ($Preview) {
// If this was a preview click, create a comment shell with the values for this comment
$this->Comment = new stdClass();
$this->Comment->InsertUserID = $Session->User->UserID;
$this->Comment->InsertName = $Session->User->Name;
$this->Comment->InsertPhoto = $Session->User->Photo;
$this->Comment->DateInserted = Gdn_Format::date();
$this->Comment->Body = val('Body', $FormValues, '');
$this->Comment->Format = val('Format', $FormValues, c('Garden.InputFormatter'));
$this->View = 'preview';
} elseif (!$Draft) {
// If the comment was not a draft
// If Editing a comment
if ($Editing) {
// Just reload the comment in question
$this->Offset = 1;
$Comments = $this->CommentModel->getIDData($CommentID, array('Slave' => false));
$this->setData('Comments', $Comments);
$this->setData('Discussion', $Discussion);
// Load the discussion
$this->ControllerName = 'discussion';
$this->View = 'comments';
// Also define the discussion url in case this request came from the post screen and needs to be redirected to the discussion
$this->setJson('DiscussionUrl', DiscussionUrl($this->Discussion) . '#Comment_' . $CommentID);
} else {
// If the comment model isn't sorted by DateInserted or CommentID then we can't do any fancy loading of comments.
$OrderBy = valr('0.0', $this->CommentModel->orderBy());
// $Redirect = !in_array($OrderBy, array('c.DateInserted', 'c.CommentID'));
// $DisplayNewCommentOnly = $this->Form->getFormValue('DisplayNewCommentOnly');
// if (!$Redirect) {
// // Otherwise load all new comments that the user hasn't seen yet
// $LastCommentID = $this->Form->getFormValue('LastCommentID');
// if (!is_numeric($LastCommentID))
// $LastCommentID = $CommentID - 1; // Failsafe back to this new comment if the lastcommentid was not defined properly
//
// // Don't reload the first comment if this new comment is the first one.
// $this->Offset = $LastCommentID == 0 ? 1 : $this->CommentModel->GetOffset($LastCommentID);
// // Do not load more than a single page of data...
// $Limit = c('Vanilla.Comments.PerPage', 30);
//
// // Redirect if the new new comment isn't on the same page.
// $Redirect |= !$DisplayNewCommentOnly && PageNumber($this->Offset, $Limit) != PageNumber($Discussion->CountComments - 1, $Limit);
// }
// if ($Redirect) {
// // The user posted a comment on a page other than the last one, so just redirect to the last page.
// $this->RedirectUrl = Gdn::request()->Url("discussion/comment/$CommentID/#Comment_$CommentID", true);
// } else {
// // Make sure to load all new comments since the page was last loaded by this user
// if ($DisplayNewCommentOnly)
$this->Offset = $this->CommentModel->GetOffset($CommentID);
$Comments = $this->CommentModel->GetIDData($CommentID, array('Slave' => false));
$this->setData('Comments', $Comments);
$this->setData('NewComments', true);
$this->ClassName = 'DiscussionController';
$this->ControllerName = 'discussion';
$this->View = 'comments';
// }
// Make sure to set the user's discussion watch records
$CountComments = $this->CommentModel->getCount($DiscussionID);
开发者ID:vanilla,项目名称:vanilla,代码行数:67,代码来源:class.postcontroller.php
示例8: importExists
/** Checks to see of a table and/or column exists in the import data.
*
* @param string $Table The name of the table to check for.
* @param string $Column
* @return bool
*/
public function importExists($Table, $Column = '')
{
if (!array_key_exists('Tables', $this->Data) || !array_key_exists($Table, $this->Data['Tables'])) {
return false;
}
if (!$Column) {
return true;
}
$Tables = $this->Data['Tables'];
$Exists = valr("Tables.{$Table}.Columns.{$Column}", $this->Data, false);
return $Exists !== false;
}
开发者ID:oMadMartigaNo,项目名称:readjust-forum,代码行数:18,代码来源:class.importmodel.php
示例9: eTag
/**
* Generate an e-tag for the application from the versions of all of its enabled applications/plugins.
**/
public static function eTag()
{
$Data = array();
$Data['vanilla-core-' . APPLICATION_VERSION] = true;
$Plugins = Gdn::pluginManager()->EnabledPlugins();
foreach ($Plugins as $Info) {
$Data[strtolower("{$Info['Index']}-plugin-{$Info['Version']}")] = true;
}
// echo(Gdn_Upload::FormatFileSize(strlen(serialize($Plugins))));
// decho($Plugins);
$Applications = Gdn::ApplicationManager()->EnabledApplications();
foreach ($Applications as $Info) {
$Data[strtolower("{$Info['Index']}-app-{$Info['Version']}")] = true;
}
// Add the desktop theme version.
$Info = Gdn::ThemeManager()->GetThemeInfo(Gdn::ThemeManager()->DesktopTheme());
if (!empty($Info)) {
$Version = val('Version', $Info, 'v0');
$Data[strtolower("{$Info['Index']}-theme-{$Version}")] = true;
if (Gdn::controller()->Theme && Gdn::controller()->ThemeOptions) {
$Filenames = valr('Styles.Value', Gdn::controller()->ThemeOptions);
$Data[$Filenames] = true;
}
}
// Add the mobile theme version.
$Info = Gdn::ThemeManager()->GetThemeInfo(Gdn::ThemeManager()->MobileTheme());
if (!empty($Info)) {
$Version = val('Version', $Info, 'v0');
$Data[strtolower("{$Info['Index']}-theme-{$Version}")] = true;
}
Gdn::pluginManager()->EventArguments['ETagData'] =& $Data;
$Suffix = '';
Gdn::pluginManager()->EventArguments['Suffix'] =& $Suffix;
Gdn::pluginManager()->FireAs('AssetModel')->fireEvent('GenerateETag');
unset(Gdn::pluginManager()->EventArguments['ETagData']);
ksort($Data);
$Result = substr(md5(implode(',', array_keys($Data))), 0, 8) . $Suffix;
// decho($Data);
// die();
return $Result;
}
开发者ID:rensi4rn,项目名称:vanilla,代码行数:44,代码来源:class.assetmodel.php
示例10: getAccessToken
/**
*
*
* @param $Code
* @param $RedirectUri
* @param bool $ThrowError
* @return mixed
* @throws Gdn_UserException
*/
protected function getAccessToken($Code, $RedirectUri, $ThrowError = true)
{
$Get = array('client_id' => c('Plugins.Facebook.ApplicationID'), 'client_secret' => c('Plugins.Facebook.Secret'), 'code' => $Code, 'redirect_uri' => $RedirectUri);
$Url = 'https://graph.facebook.com/oauth/access_token?' . http_build_query($Get);
// 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);
$Info = curl_getinfo($C);
if (strpos(val('content_type', $Info, ''), '/javascript') !== false) {
$Tokens = json_decode($Contents, true);
} else {
parse_str($Contents, $Tokens);
}
if (val('error', $Tokens)) {
throw new Gdn_UserException('Facebook returned the following error: ' . valr('error.message', $Tokens, 'Unknown error.'), 400);
}
$AccessToken = val('access_token', $Tokens);
// $Expires = val('expires', $Tokens, null);
return $AccessToken;
}
开发者ID:caidongyun,项目名称:vanilla,代码行数:32,代码来源:class.facebook.plugin.php
示例11: sendWelcomeEmail
/**
* Send welcome email to user.
*
* @param int $UserID
* @param string $Password
* @param string $RegisterType
* @param array|null $AdditionalData
* @throws Exception
*/
public function sendWelcomeEmail($UserID, $Password, $RegisterType = 'Add', $AdditionalData = null)
{
$Session = Gdn::session();
$Sender = $this->getID($Session->UserID);
$User = $this->getID($UserID);
if (!ValidateEmail($User->Email)) {
return;
}
$AppTitle = Gdn::config('Garden.Title');
$Email = new Gdn_Email();
$Email->subject(sprintf(t('[%s] Welcome Aboard!'), $AppTitle));
$Email->to($User->Email);
$emailTemplate = $Email->getEmailTemplate();
$Data = [];
$Data['User'] = arrayTranslate((array) $User, ['UserID', 'Name', 'Email']);
$Data['Sender'] = arrayTranslate((array) $Sender, ['Name', 'Email']);
$Data['Title'] = $AppTitle;
if (is_array($AdditionalData)) {
$Data = array_merge($Data, $AdditionalData);
}
$Data['EmailKey'] = valr('Attributes.EmailKey', $User);
$message = '<p>' . formatString(t('Hello {User.Name}!'), $Data) . ' ';
$message .= $this->getEmailWelcome($RegisterType, $User, $Data, $Password);
// Add the email confirmation key.
if ($Data['EmailKey']) {
$emailUrlFormat = '{/entry/emailconfirm,exurl,domain}/{User.UserID,rawurlencode}/{EmailKey,rawurlencode}';
$url = formatString($emailUrlFormat, $Data);
$message .= '<p>' . t('You need to confirm your email address before you can continue.') . '</p>';
$emailTemplate->setButton($url, t('Confirm My Email Address'));
} else {
$emailTemplate->setButton(externalUrl('/'), t('Access the Site'));
}
$emailTemplate->setMessage($message);
$emailTemplate->setTitle(t('Welcome Aboard!'));
$Email->setEmailTemplate($emailTemplate);
try {
$Email->send();
} catch (Exception $e) {
if (debug()) {
throw $e;
}
}
}
开发者ID:vanilla,项目名称:vanilla,代码行数:52,代码来源:class.usermodel.php
示例12: _formatStringCallback
/**
* The callback helper for {@link formatString()}.
*
* @param array $Match Either the array of arguments or the regular expression match.
* @param bool $SetArgs Whether this is a call to initialize the arguments or a matching callback.
* @return mixed Returns the matching string or nothing when setting the arguments.
* @access private
*/
function _formatStringCallback($Match, $SetArgs = false)
{
static $Args = array(), $ContextUserID = null;
if ($SetArgs) {
$Args = $Match;
if (isset($Args['_ContextUserID'])) {
$ContextUserID = $Args['_ContextUserID'];
} else {
$ContextUserID = Gdn::session() && Gdn::session()->isValid() ? Gdn::session()->UserID : null;
}
return '';
}
$Match = $Match[1];
if ($Match == '{') {
return $Match;
}
// Parse out the field and format.
$Parts = explode(',', $Match);
$Field = trim($Parts[0]);
$Format = trim(val(1, $Parts, ''));
$SubFormat = strtolower(trim(val(2, $Parts, '')));
$FormatArgs = val(3, $Parts, '');
if (in_array($Format, array('currency', 'integer', 'percent'))) {
$FormatArgs = $SubFormat;
$SubFormat = $Format;
$Format = 'number';
} elseif (is_numeric($SubFormat)) {
$FormatArgs = $SubFormat;
$SubFormat = '';
}
$Value = valr($Field, $Args, null);
if ($Value === null && !in_array($Format, array('url', 'exurl', 'number', 'plural'))) {
$Result = '';
} else {
switch (strtolower($Format)) {
case 'date':
switch ($SubFormat) {
case 'short':
$Result = Gdn_Format::date($Value, '%d/%m/%Y');
break;
case 'medium':
$Result = Gdn_Format::date($Value, '%e %b %Y');
break;
case 'long':
$Result = Gdn_Format::date($Value, '%e %B %Y');
break;
default:
$Result = Gdn_Format::date($Value);
break;
}
break;
case 'html':
case 'htmlspecialchars':
$Result = htmlspecialchars($Value);
break;
case 'number':
if (!is_numeric($Value)) {
$Result = $Value;
} else {
switch ($SubFormat) {
case 'currency':
$Result = '$' . number_format($Value, is_numeric($FormatArgs) ? $FormatArgs : 2);
break;
case 'integer':
$Result = (string) round($Value);
if (is_numeric($FormatArgs) && strlen($Result) < $FormatArgs) {
$Result = str_repeat('0', $FormatArgs - strlen($Result)) . $Result;
}
break;
case 'percent':
$Result = round($Value * 100, is_numeric($FormatArgs) ? $FormatArgs : 0);
break;
default:
$Result = number_format($Value, is_numeric($FormatArgs) ? $FormatArgs : 0);
break;
}
}
break;
case 'plural':
if (is_array($Value)) {
$Value = count($Value);
} elseif (StringEndsWith($Field, 'UserID', true)) {
$Value = 1;
}
if (!is_numeric($Value)) {
$Result = $Value;
} else {
if (!$SubFormat) {
$SubFormat = rtrim("%s {$Field}", 's');
}
if (!$FormatArgs) {
$FormatArgs = $SubFormat . 's';
//.........这里部分代码省略.........
开发者ID:sitexa,项目名称:vanilla,代码行数:101,代码来源:functions.general.php
示例13: simple
/**
* Generates a multi-field form from a schema.
*
* @param array $Schema An array where each item of the array is a row that identifies a form field with the following information:
* - Name: The name of the form field.
* - Control: The type of control used for the field. This is one of the control methods on the Gdn_Form object.
* - LabelCode: The translation code for the label. Optional.
* - Description: An optional description for the field.
* - Items: If the control is a list control then its items are specified here.
* - Options: Additional options to be passed into the control.
* @param type $Options Additional options to pass into the form.
* - Wrap: A two item array specifying the text to wrap the form in.
* - ItemWrap: A two item array specifying the text to wrap each form item in.
*/
public function simple($Schema, $Options = array())
{
$Result = valr('Wrap.0', $Options, '<ul>');
$ItemWrap = val('ItemWrap', $Options, array("<li>\n ", "\n</li>\n"));
foreach ($Schema as $Index => $Row) {
if (is_string($Row)) {
$Row = array('Name' => $Index, 'Control' => $Row);
}
if (!isset($Row['Name'])) {
$Row['Name'] = $Index;
}
if (!isset($Row['Options'])) {
$Row['Options'] = array();
}
$Result .= $ItemWrap[0];
$LabelCode = self::labelCode($Row);
$Description = val('Description', $Row, '');
if ($Description) {
$Description = '<div class="Info">' . $Description . '</div>';
}
touchValue('Control', $Row, 'TextBox');
switch (strtolower($Row['Control'])) {
case 'categorydropdown':
$Result .= $this->label($LabelCode, $Row['Name']) . $Description . $this->categoryDropDown($Row['Name'], $Row['Options']);
break;
case 'checkbox':
$Result .= $Description . $this->checkBox($Row['Name'], $LabelCode);
break;
case 'dropdown':
$Result .= $this->label($LabelCode, $Row['Name']) . $Description . $this->dropDown($Row['Name'], $Row['Items'], $Row['Options']);
break;
case 'radiolist':
$Result .= $Description . $this->radioList($Row['Name'], $Row['Items'], $Row['Options']);
break;
case 'checkboxlist':
$Result .= $this->label($LabelCode, $Row['Name']) . $Description . $this->checkBoxList($Row['Name'], $Row['Items'], null, $Row['Options']);
break;
case 'textbox':
$Result .= $this->label($LabelCode, $Row['Name']) . $Description . $this->textBox($Row['Name'], $Row['Options']);
break;
case 'callback':
$Row['DescriptionHtml'] = $Description;
$Row['LabelCode'] = $LabelCode;
$Result .= call_user_func($Row['Callback'], $this, $Row);
break;
default:
$Result .= "Error a control type of {$Row['Control']} is not supported.";
break;
}
$Result .= $ItemWrap[1];
}
$Result .= valr('Wrap.1', $Options, '</ul>');
return $Result;
}
开发者ID:bryanjamesmiller,项目名称:vanilla,代码行数:68,代码来源:class.form.php
示例14: eTag
/**
* Generate an e-tag for the application from the versions of all of its enabled applications/plugins.
*
* @return string etag
**/
public static function eTag()
{
$data = [];
$data['vanilla-core-' . APPLICATION_VERSION] = true;
// Look through the enabled addons.
/* @var Addon $addon */
foreach (Gdn::addonManager()->getEnabled() as $addon) {
if ($addon->getType() == Addon::TYPE_THEME) {
// Themes have to figured out separately.
continue;
}
$key = $addon->getKey();
$version = $addon->getVersion();
$type = $addon->getType();
$data[strtolower("{$key}-{$type}-{$version}")] = true;
}
// Add the desktop theme version.
$themes = ['' => Gdn::addonManager()->lookupTheme(Gdn::themeManager()->desktopTheme()), 'Mobile' => Gdn::addonManager()->lookupTheme(Gdn::themeManager()->mobileTheme())];
foreach ($themes as $optionsPx => $theme) {
if (!$theme instanceof Addon) {
continue;
}
$data[$theme->getKey() . '-theme-' . $theme->getVersion()] = true;
// Look for theme options.
$options = c("Garden.{$optionsPx}ThemeOptions");
if (!empty($options)) {
$data[valr('Styles.Value', $options)] = true;
}
}
$info = Gdn::themeManager()->getThemeInfo(Gdn::themeManager()->desktopTheme());
if (!empty($info)) {
$version = val('Version', $info, 'v0');
$data[strtolower("{$info['Index']}-theme-{$version}")] = true;
if (Gdn::controller()->Theme && Gdn::controller()->ThemeOptions) {
$filenames = valr('Styles.Value', Gdn::controller()->ThemeOptions);
$data[$filenames] = true;
}
}
// Add the mobile theme version.
$info = Gdn::themeManager()->getThemeInfo(Gdn::themeManager()->mobileTheme());
if (!empty($info)) {
$version = val('Version', $info, 'v0');
$data[strtolower("{$info['Index']}-theme-{$version}")] = true;
}
Gdn::pluginManager()->EventArguments['ETagData'] =& $data;
$suffix = '';
Gdn::pluginManager()->EventArguments['Suffix'] =& $suffix;
Gdn::pluginManager()->fireAs('AssetModel')->fireEvent('GenerateETag');
unset(Gdn::pluginManager()->EventArguments['ETagData']);
ksort($data);
$result = substr(md5(implode(',', array_keys($data))), 0, 8) . $suffix;
return $result;
}
开发者ID:vanilla,项目名称:vanilla,代码行数:58,代码来源:class.assetmodel.php
示例15: enableTheme
/**
*
*
* @param $ThemeName
* @param bool $IsMobile
* @return bool
* @throws Exception
*/
public function enableTheme($ThemeName, $IsMobile = false)
{
// Make sure to run the setup
$this->testTheme($ThemeName);
// Set the theme.
$ThemeInfo = $this->getThemeInfo($ThemeName);
$ThemeFolder = val('Folder', $ThemeInfo, '');
$oldTheme = $IsMobile ? c('Garden.MobileTheme', 'mobile') : c('Garden.Theme', 'default');
if ($ThemeFolder == '') {
throw new Exception(t('The theme folder was not properly defined.'));
} else {
$Options = valr("{$ThemeName}.Options", $this->AvailableThemes());
if ($Options) {
if ($IsMobile) {
saveToConfig(array('Garden.MobileTheme' => $ThemeName, 'Garden.MobileThemeOptions.Name' => valr("{$ThemeName}.Name", $this->availableThemes(), $ThemeFolder)));
} else {
saveToConfig(array('Garden.Theme' => $ThemeName, 'Garden.ThemeOptions.Name' => valr("{$ThemeName}.Name", $this->availableThemes(), $ThemeFolder)));
}
} else {
if ($IsMobile) {
saveToConfig('Garden.MobileTheme', $ThemeName);
removeFromConfig('Garden.MobileThemeOptions');
} else {
saveToConfig('Garden.Theme', $ThemeName);
removeFromConfig('Garden.ThemeOptions');
}
}
}
if ($oldTheme !== $ThemeName) {
$this->themeHook($ThemeName, self::ACTION_ENABLE, true);
Logger::event('theme_changed', Logger::NOTICE, 'The {themeType} theme changed from {oldTheme} to {newTheme}.', array('themeType' => $IsMobile ? 'mobile' : 'desktop', 'oldTheme' => $oldTheme, 'newTheme' => $ThemeName));
}
// Tell the locale cache to refresh itself.
Gdn::locale()->refresh();
return true;
}
开发者ID:vanilla,项目名称:vanilla,代码行数:44,代码来源:class.thememanager.php
示例16: simple
/**
* Generates a multi-field form from a schema.
*
* @param array $Schema An array where each item of the array is a row that identifies a form field with the following information:
* - Name: The name of the form field.
* - Control: The type of control used for the field. This is one of the control methods on the Gdn_Form object.
* - LabelCode: The translation code for the label. Optional.
* - Description: An optional description for the field.
* - Items: If the control is a list control then its items are specified here.
* - Options: Additional options to be passed into the control.
* @param type $Options Additional options to pass into the form.
* - Wrap: A two item array specifying the text to wrap the form in.
* - ItemWrap: A two item array specifying the text to wrap each form item in.
*/
public function simple($Schema, $Options = array())
{
$Result = valr('Wrap.0', $Options, '<ul>');
foreach ($Schema as $Index => $Row) {
if (is_string($Row)) {
$Row = array('Name' => $Index, 'Control' => $Row);
}
if (!isset($Row['Name'])) {
$Row['Name'] = $Index;
}
if (!isset($Row['Options'])) {
$Row['Options'] = array();
}
if (strtolower($Row['Control']) == 'callback') {
$ItemWrap = '';
} else {
$ItemWrap = val('ItemWrap', $Options, array('<li class="' . $this->getStyle('form-group') . "\">\n", "\n</li>\n"));
}
$Result .= $ItemWrap[0];
$LabelCode = self::labelCode($Row);
$image = '';
if (strtolower($Row['Control']) == 'imageupload') {
$image = $this->currentImage($Row['Name'], $Row['Options']);
$image = wrap($image, 'div', ['class' => 'image-wrap-label']);
}
$Description = val('Description', $Row, '');
if ($Description) {
$Description = wrap($Description, 'div', ['class' => 'description info']);
}
$Description .= $image;
if ($Description) {
$labelWrap = wrap($this->label($LabelCode, $Row['Name']) . $Description, 'div', ['class' => 'label-wrap']);
} else {
$labelWrap = wrap($this->label($LabelCode, $Row['Name']), 'div', ['class' => 'label-wrap']);
}
touchValue('Control', $Row, 'TextBox');
switch (strtolower($Row['Control'])) {
case 'categorydropdown':
$Result .= $this->label($LabelCode, $Row['Name']) . $Description . $this->categoryDropDown($Row['Name'], $Row['Options']);
break;
case 'checkbox':
$Result .= $labelWrap . wrap($this->checkBox($Row['Name'], $LabelCode, $Row['Options']), 'div', ['class' => 'input-wrap']);
break;
case 'toggle':
$Result .= $Description . $this->toggle($Row['Name'], $LabelCode, $Row['Options']);
break;
case 'dropdown':
$Row['Options']['Wrap'] = true;
$Result .= $labelWrap . $this->dropDown($Row['Name'], $Row['Items'], $Row['Options']);
break;
case 'radiolist':
$Result .= $labelWrap . wrap($this->radioList($Row['Name'], $Row['Items'], $Row['Options']), 'div', ['class' => 'input-wrap']);
break;
case 'checkboxlist':
$Result .= $labelWrap . wrap($this->checkBoxList($Row['Name'], $Row['Items'], null, $Row['Options']), 'div', ['class' => 'input-wrap']);
break;
case 'imageupload':
$Result .= $labelWrap . $this->imageUploadWrap($Row['Name'], $Row['Options']);
break;
case 'textbox':
$Row['Options']['Wrap'] = true;
$Result .= $labelWrap . $this->textBox($Row['Name'], $Row['Options']);
break;
case 'callback':
$Row['DescriptionHtml'] = $Description;
$Row['LabelCode'] = $LabelCode;
$Result .= call_user_func($Row['Callback'], $this, $Row);
break;
default:
$Result .= "Error a control type of {$Row['Control']} is not supported.";
break;
}
$Result .= $ItemWrap[1];
}
$Result .= valr('Wrap.1', $Options, '</ul>');
return $Result;
}
开发者ID:vanilla,项目名称:vanilla,代码行数:91,代码来源:class.form.php
示例17: check
/**
* Do code checks on an uploaded addon.
*
* @param int $AddonID Addon to check.
* @param bool|false $SaveVersionID Whether to save the version id.
* @throws Exception Addon not found.
*/
public function check($AddonID, $SaveVersionID = false)
{
$this->permission('Addons.Addon.Manage');
if ($SaveVersionID !== false) {
// Get the version data.
$Version = $this->AddonModel->SQL->getWhere('AddonVersion', array('AddonVersionID' => $SaveVersionID))->firstRow(DATASET_TYPE_ARRAY);
$this->AddonModel->save($Version);
$this->Form->setValidationResults($this->AddonModel->validationResults());
}
$Addon = $this->AddonModel->getID($AddonID, false, ['GetVersions' => true]);
$AddonTypes = Gdn::sql()->get('AddonType')->resultArray();
$AddonTypes = Gdn_DataSet::index($AddonTypes, 'AddonTypeID');
if (!$Addon) {
throw notFoundException('Addon');
}
// Get the data for the most recent version of the addon.
$upload = new Gdn_Upload();
// Also used per version below.
$Path = $upload->copyLocal($Addon['File']);
$AddonData = arrayTranslate((array) $Addon, array('AddonID', 'AddonKey', 'Name', 'Type', 'Description', 'Requirements', 'Checked'));
try {
$FileAddonData = UpdateModel::analyzeAddon($Path);
if ($FileAddonData) {
$AddonData = array_merge($AddonData, arrayTranslate($FileAddonData, array('AddonKey' => 'File_AddonKey', 'Name' => 'File_Name', 'File_Type', 'Description' => 'File_Description', 'Requirements' => 'File_Requirements', 'Checked' => 'File_Checked')));
$AddonData['File_Type'] = valr($FileAddonData['AddonTypeID'] . '.Label', $AddonTypes, 'Unknown');
}
$upload->delete($Path);
} catch (Exception $Ex) {
$AddonData['File_Error'] = $Ex->getMess
|
请发表评论