本文整理汇总了PHP中StringBeginsWith函数的典型用法代码示例。如果您正苦于以下问题:PHP StringBeginsWith函数的具体用法?PHP StringBeginsWith怎么用?PHP StringBeginsWith使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StringBeginsWith函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: StatsDashboard
/**
* Override the default index method of the settings controller in the
* dashboard application to render new statistics.
*/
public function StatsDashboard($Sender)
{
$StatsUrl = $this->AnalyticsServer;
if (!StringBeginsWith($StatsUrl, 'http:') && !StringBeginsWith($StatsUrl, 'https:')) {
$StatsUrl = Gdn::Request()->Scheme() . "://{$StatsUrl}";
}
// Tell the page where to find the Vanilla Analytics provider
$Sender->AddDefinition('VanillaStatsUrl', $StatsUrl);
$Sender->SetData('VanillaStatsUrl', $StatsUrl);
// Load javascript & css, check permissions, and load side menu for this page.
$Sender->AddJsFile('settings.js');
$Sender->Title(T('Dashboard'));
$Sender->RequiredAdminPermissions[] = 'Garden.Settings.Manage';
$Sender->RequiredAdminPermissions[] = 'Garden.Users.Add';
$Sender->RequiredAdminPermissions[] = 'Garden.Users.Edit';
$Sender->RequiredAdminPermissions[] = 'Garden.Users.Delete';
$Sender->RequiredAdminPermissions[] = 'Garden.Users.Approve';
$Sender->FireEvent('DefineAdminPermissions');
$Sender->Permission($Sender->RequiredAdminPermissions, '', FALSE);
$Sender->AddSideMenu('dashboard/settings');
if (!Gdn_Statistics::CheckIsEnabled() && Gdn_Statistics::CheckIsLocalhost()) {
$Sender->Render('dashboardlocalhost', '', 'plugins/VanillaStats');
} else {
$Sender->AddJsFile('plugins/VanillaStats/js/vanillastats.js');
$Sender->AddJsFile('plugins/VanillaStats/js/picker.js');
$Sender->AddCSSFile('plugins/VanillaStats/design/picker.css');
$this->ConfigureRange($Sender);
$VanillaID = Gdn::InstallationID();
$Sender->SetData('VanillaID', $VanillaID);
$Sender->SetData('VanillaVersion', APPLICATION_VERSION);
$Sender->SetData('SecurityToken', $this->SecurityToken());
// Render the custom dashboard view
$Sender->Render('dashboard', '', 'plugins/VanillaStats');
}
}
示例2: Page
public function Page($Reference)
{
$PageModel = new PageModel();
$Page = $PageModel->GetFullID($Reference);
if (!$Page) {
throw NotFoundException();
}
$this->Page = $Page;
if ($this->Head) {
SetMetaTags($Page, $this);
if ($Page->CustomCss) {
$CustomCss = "\n" . $Page->CustomCss;
if (!StringBeginsWith(trim($CustomCss), '<style', True)) {
$CustomCss = Wrap($CustomCss, 'style', array('type' => 'text/css'));
}
$this->Head->AddString($CustomCss);
}
if ($Page->CustomJs) {
$CustomJs = $Page->CustomJs;
if (!StringBeginsWith(trim($CustomJs), '<script', True)) {
$CustomJs = Wrap($CustomJs, 'script', array('type' => 'text/javascript'));
}
$this->Head->AddString($CustomJs);
}
}
if ($Page->SectionID) {
$this->Section = BuildNode($Page, 'Section');
$this->SectionID = $Page->SectionID;
CandyHooks::AddModules($this, $this->Section);
}
$this->FireEvent('ContentPage');
if ($Page->View) {
$this->View = $this->FetchViewLocation($this->View, False, False, False);
}
if (!$this->View) {
$this->View = $this->FetchViewLocation('view', 'page', '', False);
if (!$this->View) {
$this->View = 'default';
}
}
$this->Title($Page->Title);
$this->SetData('Content', $Page, True);
$this->EventArguments['Format'] =& $Page->Format;
$this->EventArguments['Body'] =& $Page->Body;
$this->FireEvent('BeforeBodyFormat');
$this->ContentBodyHtml = Gdn_Format::To($Page->Body, $Page->Format);
$Doc = PqDocument($this->ContentBodyHtml);
$Header = $Doc->Find('h1');
$CountH1 = count($Header);
if ($CountH1 == 0) {
$this->SetData('Headline', Gdn_Format::Text($Page->Title));
} elseif ($CountH1 == 1) {
$this->SetData('Headline', $Header->Text());
$Header->Remove();
$this->ContentBodyHtml = $Doc->Html();
}
//
$this->AddModule('PageInfoModule');
$this->Render();
}
示例3: Settings
/**
* Manage the current ranks and add new ones
*/
public function Settings()
{
$this->Permission('Yaga.Ranks.Manage');
$this->AddSideMenu('rank/settings');
$this->Title(T('Yaga.Ranks.Manage'));
// Get list of ranks from the model and pass to the view
$this->SetData('Ranks', $this->RankModel->Get());
if ($this->Form->IsPostBack() == TRUE) {
// Handle the photo upload
$Upload = new Gdn_Upload();
$TmpImage = $Upload->ValidateUpload('PhotoUpload', FALSE);
if ($TmpImage) {
// Generate the target image name
$TargetImage = $Upload->GenerateTargetName(PATH_UPLOADS);
$ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
// Save the uploaded image
$Parts = $Upload->SaveAs($TmpImage, 'yaga' . DS . $ImageBaseName);
$RelativeUrl = StringBeginsWith($Parts['Url'], Gdn_Url::WebRoot(TRUE), TRUE, TRUE);
SaveToConfig('Yaga.Ranks.Photo', $RelativeUrl);
if (C('Yaga.Ranks.Photo') == $Parts['SaveName']) {
$this->InformMessage(T('Yaga.Rank.PhotoUploaded'));
}
}
}
include_once $this->FetchViewLocation('helper_functions', 'rank');
$this->Render();
}
示例4: ButtonGroup
/**
*
* @param array $Links An array of arrays with the following keys:
* - Text: The text of the link.
* - Url: The url of the link.
* @param string|array $CssClass The css class of the link. This can be a two-item array where the second element will be added to the buttons.
* @param string|false $Default The url of the default link.
* @since 2.1
*/
function ButtonGroup($Links, $CssClass = 'Button', $Default = FALSE)
{
if (!is_array($Links) || count($Links) < 1) {
return;
}
$Text = $Links[0]['Text'];
$Url = $Links[0]['Url'];
$ButtonClass = '';
if (is_array($CssClass)) {
list($CssClass, $ButtonClass) = $CssClass;
}
if ($Default) {
// Find the default button.
$Default = ltrim($Default, '/');
foreach ($Links as $Link) {
if (StringBeginsWith(ltrim($Link['Url'], '/'), $Default)) {
$Text = $Link['Text'];
$Url = $Link['Url'];
break;
}
}
}
if (count($Links) < 2) {
echo Anchor($Text, $Url, $CssClass);
} else {
// NavButton or Button?
$ButtonClass = ConcatSep(' ', $ButtonClass, strpos($CssClass, 'NavButton') !== FALSE ? 'NavButton' : 'Button');
if (strpos($CssClass, 'Primary') !== FALSE) {
$ButtonClass .= ' Primary';
}
// Strip "Button" or "NavButton" off the group class.
echo '<div class="ButtonGroup ' . str_replace(array('NavButton', 'Button'), array('', ''), $CssClass) . '">';
echo Anchor($Text, $Url, $ButtonClass);
echo Anchor(Sprite('SpDropdownHandle'), '#', $ButtonClass . ' Handle');
echo '<ul class="Dropdown MenuItems">';
foreach ($Links as $Link) {
echo Wrap(Anchor($Link['Text'], $Link['Url'], GetValue('CssClass', $Link, '')), 'li');
}
echo '</ul>';
echo '</div>';
}
}
示例5: SaveMaskInfo
/**
* Save mask information.
*
* @param array $PostValues
* @param mixed $Validation.
*/
public static function SaveMaskInfo($PostValues, $Validation = False)
{
$MaskValues = array();
foreach ($PostValues as $Key => $Value) {
if (StringBeginsWith($Key, 'Mask_')) {
$MaskValues[$Value] = GetValue('Description_' . $Value, $PostValues);
}
}
$NewMaskValues = array_combine($PostValues['Mask'], $PostValues['Description']);
$MaskValues = $MaskValues + $NewMaskValues;
$Data = array();
foreach ($MaskValues as $Int => $Description) {
$Int = sprintf('%u', $Int);
if ($Int > 0 && !($Int & $Int - 1)) {
$Data[$Int] = $Description;
}
}
K('Candy.Mask.Info', $Data);
return True;
}
示例6: CalculateRow
public function CalculateRow(&$Row)
{
$ActivityType = self::GetActivityType($Row['ActivityTypeID']);
$Row['ActivityType'] = GetValue('Name', $ActivityType);
if (is_string($Row['Data'])) {
$Row['Data'] = @unserialize($Row['Data']);
}
$Row['PhotoUrl'] = Url($Row['Route'], TRUE);
if (!$Row['Photo']) {
if (isset($Row['ActivityPhoto'])) {
$Row['Photo'] = $Row['ActivityPhoto'];
$Row['PhotoUrl'] = UserUrl($Row, 'Activity');
} else {
$User = Gdn::UserModel()->GetID($Row['ActivityUserID'], DATASET_TYPE_ARRAY);
if ($User) {
$Photo = $User['Photo'];
$Row['PhotoUrl'] = UserUrl($User);
if (!$Photo || StringBeginsWith($Photo, 'http')) {
$Row['Photo'] = $Photo;
} else {
$Row['Photo'] = Gdn_Upload::Url(ChangeBasename($Photo, 'n%s'));
}
}
}
}
$Data = $Row['Data'];
if (isset($Data['ActivityUserIDs'])) {
$Row['ActivityUserID'] = array_merge(array($Row['ActivityUserID']), $Data['ActivityUserIDs']);
}
if (isset($Data['RegardingUserIDs'])) {
$Row['RegardingUserID'] = array_merge(array($Row['RegardingUserID']), $Data['RegardingUserIDs']);
}
$Row['Url'] = ExternalUrl($Row['Route']);
if ($Row['HeadlineFormat']) {
$Row['Headline'] = FormatString($Row['HeadlineFormat'], $Row);
} else {
$Row['Headline'] = Gdn_Format::ActivityHeadline($Row);
}
}
示例7: Parse
public static function Parse($Name)
{
$Result = FALSE;
$Name = str_replace('\\', '/', $Name);
if (preg_match('`^https?://`', $Name)) {
$Result = array('Name' => $Name, 'Type' => 'external', 'SaveName' => $Name, 'SaveFormat' => '%s', 'Url' => $Name);
return $Result;
} elseif (StringBeginsWith($Name, PATH_UPLOADS)) {
$Name = ltrim(substr($Name, strlen(PATH_UPLOADS)), '/');
// This is an upload.
$Result = array('Name' => $Name, 'Type' => '', 'SaveName' => $Name, 'SaveFormat' => '%s');
} elseif (preg_match('`^~([^/]*)/(.*)$`', $Name, $Matches)) {
// The first part of the name tells us the type.
$Type = $Matches[1];
$Name = $Matches[2];
$Result = array('Name' => $Name, 'Type' => $Type, 'SaveName' => "~{$Type}/{$Name}", 'SaveFormat' => "~{$Type}/%s");
} else {
$Name = ltrim($Name, '/');
// This is an upload in the uploads folder.
$Result = array('Name' => $Name, 'Type' => '', 'SaveName' => $Name, 'SaveFormat' => '%s');
}
$UrlPrefix = self::Urls($Result['Type']);
if ($UrlPrefix === FALSE) {
$Result['Url'] = FALSE;
} else {
$Result['Url'] = $UrlPrefix . '/' . $Result['Name'];
}
return $Result;
}
示例8: Index
/**
* Main import page.
*
* @since 2.0.0
* @access public
*/
public function Index()
{
$this->Permission('Garden.Import');
// This permission doesn't exist, so only users with Admin == '1' will succeed.
$Timer = new Gdn_Timer();
// Determine the current step.
$this->Form = new Gdn_Form();
$Imp = new ImportModel();
$Imp->LoadState();
// Search for the list of acceptable imports.
$ImportPaths = array();
$ExistingPaths = SafeGlob(PATH_ROOT . '/uploads/export*', array('gz', 'txt'));
foreach ($ExistingPaths as $Path) {
$ImportPaths[$Path] = basename($Path);
}
// Add the database as a path.
$ImportPaths = array_merge(array('db:' => T('This Database')), $ImportPaths);
if ($Imp->CurrentStep < 1) {
// Check to see if there is a file.
$ImportPath = C('Garden.Import.ImportPath');
$Validation = new Gdn_Validation();
if (strcasecmp(Gdn::Request()->RequestMethod(), 'post') == 0) {
$Upload = new Gdn_Upload();
$Validation = new Gdn_Validation();
if (count($ImportPaths) > 0) {
$Validation->ApplyRule('PathSelect', 'Required', T('You must select a file to import.'));
}
if (count($ImportPaths) == 0 || $this->Form->GetFormValue('PathSelect') == 'NEW') {
$TmpFile = $Upload->ValidateUpload('ImportFile', FALSE);
} else {
$TmpFile = '';
}
if ($TmpFile) {
$Filename = $_FILES['ImportFile']['name'];
$Extension = pathinfo($Filename, PATHINFO_EXTENSION);
$TargetFolder = PATH_ROOT . DS . 'uploads' . DS . 'import';
if (!file_exists($TargetFolder)) {
mkdir($TargetFolder, 0777, TRUE);
}
$ImportPath = $Upload->GenerateTargetName(PATH_ROOT . DS . 'uploads' . DS . 'import', $Extension);
$Upload->SaveAs($TmpFile, $ImportPath);
$Imp->ImportPath = $ImportPath;
$this->Form->SetFormValue('PathSelect', $ImportPath);
$UploadedFiles = GetValue('UploadedFiles', $Imp->Data);
$UploadedFiles[$ImportPath] = basename($Filename);
$Imp->Data['UploadedFiles'] = $UploadedFiles;
} elseif ($PathSelect = $this->Form->GetFormValue('PathSelect')) {
if ($PathSelect == 'NEW') {
$Validation->AddValidationResult('ImportFile', 'ValidateRequired');
} else {
$Imp->ImportPath = $PathSelect;
}
} elseif (!$Imp->ImportPath && count($ImportPaths) == 0) {
// There was no file uploaded this request or before.
$Validation->AddValidationResult('ImportFile', $Upload->Exception);
}
// Validate the overwrite.
if (TRUE || strcasecmp($this->Form->GetFormValue('Overwrite'), 'Overwrite') == 0) {
if (!StringBeginsWith($this->Form->GetFormValue('PathSelect'), 'Db:', TRUE)) {
$Validation->ApplyRule('Email', 'Required');
if (!$this->Form->GetFormValue('UseCurrentPassword')) {
$Validation->ApplyRule('Password', 'Required');
}
}
}
if ($Validation->Validate($this->Form->FormValues())) {
$this->Form->SetFormValue('Overwrite', 'overwrite');
$Imp->FromPost($this->Form->FormValues());
$this->View = 'Info';
} else {
$this->Form->SetValidationResults($Validation->Results());
}
} else {
$this->Form->SetFormValue('PathSelect', $Imp->ImportPath);
}
$Imp->SaveState();
} else {
$this->SetData('Steps', $Imp->Steps());
$this->View = 'Info';
}
if (!StringBeginsWith($Imp->ImportPath, 'db:') && !file_exists($Imp->ImportPath)) {
$Imp->DeleteState();
}
try {
$UploadedFiles = GetValue('UploadedFiles', $Imp->Data, array());
$ImportPaths = array_merge($ImportPaths, $UploadedFiles);
$this->SetData('ImportPaths', $ImportPaths);
$this->SetData('Header', $Imp->GetImportHeader());
$this->SetData('Stats', GetValue('Stats', $Imp->Data, array()));
$this->SetData('GenerateSQL', GetValue('GenerateSQL', $Imp->Data));
$this->SetData('ImportPath', $Imp->ImportPath);
$this->SetData('OriginalFilename', GetValue('OriginalFilename', $Imp->Data));
$this->SetData('CurrentStep', $Imp->CurrentStep);
$this->SetData('LoadSpeedWarning', $Imp->LoadTableType(FALSE) == 'LoadTableWithInsert');
//.........这里部分代码省略.........
示例9: viewLocation
/**
* Get the path of a view.
*
* @param string $View The name of the view.
* @param string $Controller The name of the controller invoking the view or blank.
* @param string $Folder The application folder or plugins/plugin folder.
* @return string|false The path to the view or false if it wasn't found.
* @deprecated
*/
function viewLocation($View, $Controller, $Folder)
{
deprecated('viewLocation()');
$Paths = array();
if (strpos($View, '/') !== false) {
// This is a path to the view from the root.
$Paths[] = $View;
} else {
$View = strtolower($View);
$Controller = strtolower(StringEndsWith($Controller, 'Controller', true, true));
if ($Controller) {
$Controller = '/' . $Controller;
}
$Extensions = array('tpl', 'php');
// 1. First we check the theme.
if (Gdn::Controller() && ($Theme = Gdn::Controller()->Theme)) {
foreach ($Extensions as $Ext) {
$Paths[] = PATH_THEMES . "/{$Theme}/views{$Controller}/{$View}.{$Ext}";
}
}
// 2. Then we check the application/plugin.
if (StringBeginsWith($Folder, 'plugins/')) {
// This is a plugin view.
foreach ($Extensions as $Ext) {
$Paths[] = PATH_ROOT . "/{$Folder}/views{$Controller}/{$View}.{$Ext}";
}
} else {
// This is an application view.
$Folder = strtolower($Folder);
foreach ($Extensions as $Ext) {
$Paths[] = PATH_APPLICATIONS . "/{$Folder}/views{$Controller}/{$View}.{$Ext}";
}
if ($Folder != 'dashboard' && StringEndsWith($View, '.master')) {
// This is a master view that can always fall back to the dashboard.
foreach ($Extensions as $Ext) {
$Paths[] = PATH_APPLICATIONS . "/dashboard/views{$Controller}/{$View}.{$Ext}";
}
}
}
}
// Now let's search the paths for the view.
foreach ($Paths as $Path) {
if (file_exists($Path)) {
return $Path;
}
}
Trace(array('view' => $View, 'controller' => $Controller, 'folder' => $Folder), 'View');
Trace($Paths, 'ViewLocation()');
return false;
}
示例10: Sort
/**
* Set user preference for sorting discussions.
*/
public function Sort($Target = '')
{
if (!Gdn::Session()->IsValid()) {
throw PermissionException();
}
if (!$this->Request->IsAuthenticatedPostBack()) {
throw ForbiddenException('GET');
}
// Get param
$SortField = Gdn::Request()->Post('DiscussionSort');
$SortField = 'd.' . StringBeginsWith($SortField, 'd.', TRUE, TRUE);
// Use whitelist here too to keep database clean
if (!in_array($SortField, DiscussionModel::AllowedSortFields())) {
throw new Gdn_UserException("Unknown sort {$SortField}.");
}
// Set user pref
Gdn::UserModel()->SavePreference(Gdn::Session()->UserID, 'Discussions.SortField', $SortField);
if ($Target) {
Redirect($Target);
}
// Send sorted discussions.
$this->DeliveryMethod(DELIVERY_METHOD_JSON);
$this->Render();
}
示例11: Query
/**
* Run a query, replacing database prefixes.
* @param string $Sql The sql to execute.
* - :_z will be replaced by the import prefix.
* - :_ will be replaced by the database prefix.
* @param array $Parameters PDO parameters to pass to the query.
* @return Gdn_DataSet
*/
public function Query($Sql, $Parameters = NULL)
{
$Db = Gdn::Database();
// Replace db prefixes.
$Sql = str_replace(array(':_z', ':_'), array($Db->DatabasePrefix . self::TABLE_PREFIX, $Db->DatabasePrefix), $Sql);
// Figure out the type of the type of the query.
if (StringBeginsWith($Sql, 'select')) {
$Type = 'select';
} elseif (StringBeginsWith($Sql, 'truncate')) {
$Type = 'truncate';
} elseif (StringBeginsWith($Sql, 'insert')) {
$Type = 'insert';
} elseif (StringBeginsWith($Sql, 'update')) {
$Type = 'update';
} elseif (StringBeginsWith($Sql, 'delete')) {
$Type = 'delete';
} else {
$Type = 'select';
}
// Execute the query.
if (is_array($Parameters)) {
$this->SQL->NamedParameters($Parameters);
}
$Result = $this->SQL->Query($Sql, $Type);
//$this->Timer->Split('Sql: '. str_replace("\n", "\n ", $Sql));
return $Result;
}
示例12: Banner
/**
* Banner management screen.
*
* @since 2.0.0
* @access public
*/
public function Banner()
{
$this->Permission('Garden.Settings.Manage');
$this->AddSideMenu('dashboard/settings/banner');
$this->Title(T('Banner'));
$Validation = new Gdn_Validation();
$ConfigurationModel = new Gdn_ConfigurationModel($Validation);
$ConfigurationModel->SetField(array('Garden.HomepageTitle' => C('Garden.Title'), 'Garden.Title', 'Garden.Description'));
// Set the model on the form.
$this->Form->SetModel($ConfigurationModel);
// Get the current logo.
$Logo = C('Garden.Logo');
if ($Logo) {
$Logo = ltrim($Logo, '/');
// Fix the logo path.
if (StringBeginsWith($Logo, 'uploads/')) {
$Logo = substr($Logo, strlen('uploads/'));
}
$this->SetData('Logo', $Logo);
}
// Get the current favicon.
$Favicon = C('Garden.FavIcon');
$this->SetData('Favicon', $Favicon);
$ShareImage = C('Garden.ShareImage');
$this->SetData('ShareImage', $ShareImage);
// If seeing the form for the first time...
if (!$this->Form->AuthenticatedPostBack()) {
// Apply the config settings to the form.
$this->Form->SetData($ConfigurationModel->Data);
} else {
// Define some validation rules for the fields being saved
$ConfigurationModel->Validation->ApplyRule('Garden.Title', 'Required');
$SaveData = array();
if ($this->Form->Save() !== FALSE) {
$Upload = new Gdn_Upload();
try {
// Validate the upload
$TmpImage = $Upload->ValidateUpload('Logo', FALSE);
if ($TmpImage) {
// Generate the target image name
$TargetImage = $Upload->GenerateTargetName(PATH_UPLOADS);
$ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
// Delete any previously uploaded images.
if ($Logo) {
$Upload->Delete($Logo);
}
// Save the uploaded image
$Parts = $Upload->SaveAs($TmpImage, $ImageBaseName);
$ImageBaseName = $Parts['SaveName'];
$SaveData['Garden.Logo'] = $ImageBaseName;
$this->SetData('Logo', $ImageBaseName);
}
$ImgUpload = new Gdn_UploadImage();
$TmpFavicon = $ImgUpload->ValidateUpload('Favicon', FALSE);
if ($TmpFavicon) {
$ICOName = 'favicon_' . substr(md5(microtime()), 16) . '.ico';
if ($Favicon) {
$Upload->Delete($Favicon);
}
// Resize the to a png.
$Parts = $ImgUpload->SaveImageAs($TmpFavicon, $ICOName, 16, 16, array('OutputType' => 'ico', 'Crop' => TRUE));
$SaveData['Garden.FavIcon'] = $Parts['SaveName'];
$this->SetData('Favicon', $Parts['SaveName']);
}
$TmpShareImage = $Upload->ValidateUpload('ShareImage', FALSE);
if ($TmpShareImage) {
$TargetImage = $Upload->GenerateTargetName(PATH_UPLOADS, FALSE);
$ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
if ($ShareImage) {
$Upload->Delete($ShareImage);
}
$Parts = $Upload->SaveAs($TmpShareImage, $ImageBaseName);
$SaveData['Garden.ShareImage'] = $Parts['SaveName'];
$this->SetData('ShareImage', $Parts['SaveName']);
}
} catch (Exception $ex) {
$this->Form->AddError($ex);
}
// If there were no errors, save the path to the logo in the config
if ($this->Form->ErrorCount() == 0) {
SaveToConfig($SaveData);
}
$this->InformMessage(T("Your settings have been saved."));
}
}
$this->Render();
}
示例13: _SetBreadcrumbs
public function _SetBreadcrumbs($Name = NULL, $Url = NULL)
{
// Add the root link.
if (GetValue('UserID', $this->User) == Gdn::Session()->UserID) {
$Root = array('Name' => T('Profile'), 'Url' => '/profile');
$Breadcrumb = array('Name' => $Name, 'Url' => $Url);
} else {
$NameUnique = C('Garden.Registration.NameUnique');
$Root = array('Name' => GetValue('Name', $this->User), 'Url' => UserUrl($this->User));
$Breadcrumb = array('Name' => $Name, 'Url' => $Url . '/' . ($NameUnique ? '' : GetValue('UserID', $this->User) . '/') . rawurlencode(GetValue('Name', $this->User)));
}
$this->Data['Breadcrumbs'][] = $Root;
if ($Name && !StringBeginsWith($Root['Url'], $Url)) {
$this->Data['Breadcrumbs'][] = array('Name' => $Name, 'Url' => $Url);
}
}
示例14: Connect
/**
* Connect the user with an external source.
*
* This controller method is meant to be used with plugins that set its data array to work.
* Events: ConnectData
*
* @since 2.0.0
* @access public
*
* @param string $Method Used to register multiple providers on ConnectData event.
*/
public function Connect($Method)
{
$this->AddJsFile('entry.js');
$this->View = 'connect';
$IsPostBack = $this->Form->IsPostBack() && $this->Form->GetFormValue('Connect', NULL) !== NULL;
if (!$IsPostBack) {
// Here are the initial data array values. that can be set by a plugin.
$Data = array('Provider' => '', 'ProviderName' => '', 'UniqueID' => '', 'FullName' => '', 'Name' => '', 'Email' => '', 'Photo' => '', 'Target' => $this->Target());
$this->Form->SetData($Data);
$this->Form->AddHidden('Target', $this->Request->Get('Target', '/'));
}
// The different providers can check to see if they are being used and modify the data array accordingly.
$this->EventArguments = array($Method);
// Fire ConnectData event & error handling.
$CurrentData = $this->Form->FormValues();
try {
$this->FireEvent('ConnectData');
} catch (Gdn_UserException $Ex) {
$this->Form->AddError($Ex);
return $this->Render('ConnectError');
} catch (Exception $Ex) {
if (Debug()) {
$this->Form->AddError($Ex);
} else {
$this->Form->AddError('There was an error fetching the connection data.');
}
return $this->Render('ConnectError');
}
if (!UserModel::NoEmail()) {
if (!$this->Form->GetFormValue('Email') || $this->Form->GetFormValue('EmailVisible')) {
$this->Form->SetFormValue('EmailVisible', TRUE);
$this->Form->AddHidden('EmailVisible', TRUE);
if ($IsPostBack) {
$this->Form->SetFormValue('Email', GetValue('Email', $CurrentData));
}
}
}
$FormData = $this->Form->FormValues();
// debug
// Make sure the minimum required data has been provided to the connect.
if (!$this->Form->GetFormValue('Provider')) {
$this->Form->AddError('ValidateRequired', T('Provider'));
}
if (!$this->Form->GetFormValue('UniqueID')) {
$this->Form->AddError('ValidateRequired', T('UniqueID'));
}
if (!$this->Data('Verified')) {
// Whatever event handler catches this must Set the data 'Verified' to true to prevent a random site from connecting without credentials.
// This must be done EVERY postback and is VERY important.
$this->Form->AddError('The connection data has not been verified.');
}
if ($this->Form->ErrorCount() > 0) {
return $this->Render();
}
$UserModel = Gdn::UserModel();
// Check to see if there is an existing user associated with the information above.
$Auth = $UserModel->GetAuthentication($this->Form->GetFormValue('UniqueID'), $this->Form->GetFormValue('Provider'));
$UserID = GetValue('UserID', $Auth);
// Check to synchronise roles upon connecting.
if (($this->Data('Trusted') || C('Garden.SSO.SynchRoles')) && $this->Form->GetFormValue('Roles', NULL) !== NULL) {
$SaveRoles = TRUE;
// Translate the role names to IDs.
$Roles = $this->Form->GetFormValue('Roles', NULL);
$Roles = RoleModel::GetByName($Roles);
$RoleIDs = array_keys($Roles);
if (empty($RoleIDs)) {
// The user must have at least one role. This protects that.
$RoleIDs = $this->UserModel->NewUserRoleIDs();
}
$this->Form->SetFormValue('RoleID', $RoleIDs);
} else {
$SaveRoles = FALSE;
}
if ($UserID) {
// The user is already connected.
$this->Form->SetFormValue('UserID', $UserID);
if (C('Garden.Registration.ConnectSynchronize', TRUE)) {
$User = Gdn::UserModel()->GetID($UserID, DATASET_TYPE_ARRAY);
$Data = $this->Form->FormValues();
// Don't overwrite the user photo if the user uploaded a new one.
$Photo = GetValue('Photo', $User);
if (!GetValue('Photo', $Data) || $Photo && !StringBeginsWith($Photo, 'http')) {
unset($Data['Photo']);
}
// Synchronize the user's data.
$UserModel->Save($Data, array('NoConfirmEmail' => TRUE, 'FixUnique' => TRUE, 'SaveRoles' => $SaveRoles));
}
// Always save the attributes because they may contain authorization information.
if ($Attributes = $this->Form->GetFormValue('Attributes')) {
//.........这里部分代码省略.........
示例15: buttonGroup
/**
* Write a button group control.
*
* @param array $Links An array of arrays with the following keys:
* - Text: The text of the link.
* - Url: The url of the link.
* @param string|array $CssClass The css class of the link. This can be a two-item array where the second element will be added to the buttons.
* @param string|false $Default The url of the default link.
* @since 2.1
*/
function buttonGroup($Links, $CssClass = 'Button', $Default = false)
{
if (!is_array($Links) || count($Links) < 1) {
return;
}
$Text = $Links[0]['Text'];
$Url = $Links[0]['Url'];
$ButtonClass = '';
if (is_array($CssClass)) {
list($CssClass, $ButtonClass) = $CssClass;
}
if ($Default && count($Links) > 1) {
if (is_array($Default)) {
$DefaultText = $Default['Text'];
$Default = $Default['Url'];
}
// Find the default button.
$Default = ltrim($Default, '/');
foreach ($Links as $Link) {
if (StringBeginsWith(ltrim($Link['Url'], '/'), $Default)) {
$Text = $Link['Text'];
$Url = $Link['Url'];
break;
}
}
if (isset($DefaultText)) {
$Text = $DefaultText;
}
}
if (count($Links) < 2) {
echo anchor($Text, $Url, $CssClass);
} else {
// NavButton or Button?
$ButtonClass = concatSep(' ', $ButtonClass, strpos($CssClass, 'NavButton') !== false ? 'NavButton' : 'Button');
if (strpos($CssClass, 'Primary') !== false) {
$ButtonClass .= ' Primary';
}
// Strip "Button" or "NavButton" off the group class.
echo '<div class="ButtonGroup Multi ' . str_replace(array('NavButton', 'Button'), array('', ''), $CssClass) . '">';
echo anchor($Text, $Url, $ButtonClass);
echo '<ul class="Dropdown MenuItems">';
foreach ($Links as $Link) {
echo wrap(anchor($Link['Text'], $Link['Url'], val('CssClass', $Link, '')), 'li');
}
echo '</ul>';
echo anchor(sprite('SpDropdownHandle', 'Sprite', t('Expand for more options.')), '#', $ButtonClass . ' Handle');
echo '</div>';
}
}