alphaNumeric() public static method

Removes all non-alpha-numeric characters (except for _ and -) from
public static alphaNumeric ( string $Mixed ) : string
$Mixed string An object, array, or string to be formatted.
return string
Ejemplo n.º 1
0
 /**
  * Output markup for extended profile fields.
  *
  * @param array $profileFields Formatted profile fields.
  * @param array $allFields Extended profile field data.
  * @param array $magicLabels "Magic" labels configured on the Profile Extender plug-in class.
  */
 function extendedProfileFields($profileFields, $allFields, $magicLabels = [])
 {
     foreach ($profileFields as $name => $value) {
         // Skip empty and hidden fields.
         if (!$value || !val('OnProfile', $allFields[$name])) {
             continue;
         }
         // Non-magic fields must be plain text, but we'll auto-link
         if (!in_array($name, $magicLabels)) {
             $value = Gdn_Format::links(Gdn_Format::text($value));
         }
         $class = 'Profile' . Gdn_Format::alphaNumeric($name);
         $label = Gdn_Format::text($allFields[$name]['Label']);
         $filteredVal = Gdn_Format::htmlFilter($value);
         echo " <dt class=\"ProfileExtend {$class}\">{$label}</dt> ";
         echo " <dd class=\"ProfileExtend {$class}\">{$filteredVal}</dd> ";
     }
 }
Ejemplo n.º 2
0
 /**
  * Add CSS class names to a row depending on other elements/values in that row.
  *
  * Used by category, discussion, and comment lists.
  *
  * @param array|object $Row
  * @return string The CSS classes to be inserted into the row.
  */
 function cssClass($Row, $InList = true)
 {
     static $Alt = false;
     $Row = (array) $Row;
     $CssClass = 'Item';
     $Session = Gdn::session();
     // Alt rows
     if ($Alt) {
         $CssClass .= ' Alt';
     }
     $Alt = !$Alt;
     // Category list classes
     if (array_key_exists('UrlCode', $Row)) {
         $CssClass .= ' Category-' . Gdn_Format::alphaNumeric($Row['UrlCode']);
     }
     if (GetValue('CssClass', $Row)) {
         $CssClass .= ' Item-' . $Row['CssClass'];
     }
     if (array_key_exists('Depth', $Row)) {
         $CssClass .= " Depth{$Row['Depth']} Depth-{$Row['Depth']}";
     }
     if (array_key_exists('Archive', $Row)) {
         $CssClass .= ' Archived';
     }
     // Discussion list classes.
     if ($InList) {
         $CssClass .= val('Bookmarked', $Row) == '1' ? ' Bookmarked' : '';
         $Announce = val('Announce', $Row);
         if ($Announce == 2) {
             $CssClass .= ' Announcement Announcement-Category';
         } elseif ($Announce) {
             $CssClass .= ' Announcement Announcement-Everywhere';
         }
         $CssClass .= val('Closed', $Row) == '1' ? ' Closed' : '';
         $CssClass .= val('InsertUserID', $Row) == $Session->UserID ? ' Mine' : '';
         $CssClass .= val('Participated', $Row) == '1' ? ' Participated' : '';
         if (array_key_exists('CountUnreadComments', $Row) && $Session->isValid()) {
             $CountUnreadComments = $Row['CountUnreadComments'];
             if ($CountUnreadComments === true) {
                 $CssClass .= ' New';
             } elseif ($CountUnreadComments == 0) {
                 $CssClass .= ' Read';
             } else {
                 $CssClass .= ' Unread';
             }
         } elseif (($IsRead = val('Read', $Row, null)) !== null) {
             // Category list
             $CssClass .= $IsRead ? ' Read' : ' Unread';
         }
     }
     // Comment list classes
     if (array_key_exists('CommentID', $Row)) {
         $CssClass .= ' ItemComment';
     } elseif (array_key_exists('DiscussionID', $Row)) {
         $CssClass .= ' ItemDiscussion';
     }
     if (function_exists('IsMeAction')) {
         $CssClass .= isMeAction($Row) ? ' MeAction' : '';
     }
     if ($_CssClss = val('_CssClass', $Row)) {
         $CssClass .= ' ' . $_CssClss;
     }
     // Insert User classes.
     if ($UserID = val('InsertUserID', $Row)) {
         $User = Gdn::userModel()->getID($UserID);
         if ($_CssClss = val('_CssClass', $User)) {
             $CssClass .= ' ' . $_CssClss;
         }
     }
     return trim($CssClass);
 }
Ejemplo n.º 3
0
 /**
  *
  *
  * @param $Path
  * @param $Controller
  */
 public function init($Path, $Controller)
 {
     $Smarty = $this->smarty();
     // Get a friendly name for the controller.
     $ControllerName = get_class($Controller);
     if (StringEndsWith($ControllerName, 'Controller', true)) {
         $ControllerName = substr($ControllerName, 0, -10);
     }
     // Get an ID for the body.
     $BodyIdentifier = strtolower($Controller->ApplicationFolder . '_' . $ControllerName . '_' . Gdn_Format::alphaNumeric(strtolower($Controller->RequestMethod)));
     $Smarty->assign('BodyID', $BodyIdentifier);
     //$Smarty->assign('Config', Gdn::Config());
     // Assign some information about the user.
     $Session = Gdn::session();
     if ($Session->isValid()) {
         $User = array('Name' => $Session->User->Name, 'Photo' => '', 'CountNotifications' => (int) val('CountNotifications', $Session->User, 0), 'CountUnreadConversations' => (int) val('CountUnreadConversations', $Session->User, 0), 'SignedIn' => true);
         $Photo = $Session->User->Photo;
         if ($Photo) {
             if (!IsUrl($Photo)) {
                 $Photo = Gdn_Upload::Url(ChangeBasename($Photo, 'n%s'));
             }
         } else {
             if (function_exists('UserPhotoDefaultUrl')) {
                 $Photo = UserPhotoDefaultUrl($Session->User, 'ProfilePhoto');
             } elseif ($ConfigPhoto = C('Garden.DefaultAvatar')) {
                 $Photo = Gdn_Upload::url($ConfigPhoto);
             } else {
                 $Photo = Asset('/applications/dashboard/design/images/defaulticon.png', true);
             }
         }
         $User['Photo'] = $Photo;
     } else {
         $User = false;
         /*array(
           'Name' => '',
           'CountNotifications' => 0,
           'SignedIn' => FALSE);*/
     }
     $Smarty->assign('User', $User);
     // Make sure that any datasets use arrays instead of objects.
     foreach ($Controller->Data as $Key => $Value) {
         if ($Value instanceof Gdn_DataSet) {
             $Controller->Data[$Key] = $Value->resultArray();
         } elseif ($Value instanceof stdClass) {
             $Controller->Data[$Key] = (array) $Value;
         }
     }
     $BodyClass = val('CssClass', $Controller->Data, '', true);
     $Sections = Gdn_Theme::section(null, 'get');
     if (is_array($Sections)) {
         foreach ($Sections as $Section) {
             $BodyClass .= ' Section-' . $Section;
         }
     }
     $Controller->Data['BodyClass'] = $BodyClass;
     // Set the current locale for themes to take advantage of.
     $Locale = Gdn::locale()->Locale;
     $CurrentLocale = array('Key' => $Locale, 'Lang' => str_replace('_', '-', $Locale));
     if (class_exists('Locale')) {
         $CurrentLocale['Language'] = Locale::getPrimaryLanguage($Locale);
         $CurrentLocale['Region'] = Locale::getRegion($Locale);
         $CurrentLocale['DisplayName'] = Locale::getDisplayName($Locale, $Locale);
         $CurrentLocale['DisplayLanguage'] = Locale::getDisplayLanguage($Locale, $Locale);
         $CurrentLocale['DisplayRegion'] = Locale::getDisplayRegion($Locale, $Locale);
     }
     $Smarty->assign('CurrentLocale', $CurrentLocale);
     $Smarty->assign('Assets', (array) $Controller->Assets);
     $Smarty->assign('Path', Gdn::request()->path());
     // Assign the controller data last so the controllers override any default data.
     $Smarty->assign($Controller->Data);
     $Smarty->Controller = $Controller;
     // for smarty plugins
     $Smarty->security = true;
     $Smarty->security_settings['IF_FUNCS'] = array_merge($Smarty->security_settings['IF_FUNCS'], array('Category', 'CheckPermission', 'InSection', 'InCategory', 'MultiCheckPermission', 'GetValue', 'SetValue', 'Url'));
     $Smarty->security_settings['MODIFIER_FUNCS'] = array_merge($Smarty->security_settings['MODIFIER_FUNCS'], array('sprintf'));
     $Smarty->secure_dir = array($Path);
 }
Ejemplo n.º 4
0
 /**
  *
  */
 public function renderMaster()
 {
     // Build the master view if necessary
     if (in_array($this->_DeliveryType, array(DELIVERY_TYPE_ALL))) {
         $this->MasterView = $this->masterView();
         // Only get css & ui components if this is NOT a syndication request
         if ($this->SyndicationMethod == SYNDICATION_NONE && is_object($this->Head)) {
             $CssAnchors = AssetModel::getAnchors();
             $this->EventArguments['CssFiles'] =& $this->_CssFiles;
             $this->fireEvent('BeforeAddCss');
             $ETag = AssetModel::eTag();
             $CombineAssets = c('Garden.CombineAssets');
             $ThemeType = isMobile() ? 'mobile' : 'desktop';
             // And now search for/add all css files.
             foreach ($this->_CssFiles as $CssInfo) {
                 $CssFile = $CssInfo['FileName'];
                 if (!array_key_exists('Options', $CssInfo) || !is_array($CssInfo['Options'])) {
                     $CssInfo['Options'] = array();
                 }
                 $Options =& $CssInfo['Options'];
                 // style.css and admin.css deserve some custom processing.
                 if (in_array($CssFile, $CssAnchors)) {
                     if (!$CombineAssets) {
                         // Grab all of the css files from the asset model.
                         $AssetModel = new AssetModel();
                         $CssFiles = $AssetModel->getCssFiles($ThemeType, ucfirst(substr($CssFile, 0, -4)), $ETag);
                         foreach ($CssFiles as $Info) {
                             $this->Head->addCss($Info[1], 'all', true, $CssInfo);
                         }
                     } else {
                         $Basename = substr($CssFile, 0, -4);
                         $this->Head->addCss(url("/asset/css/{$ThemeType}/{$Basename}-{$ETag}.css", '//'), 'all', false, $CssInfo['Options']);
                     }
                     continue;
                 }
                 $AppFolder = $CssInfo['AppFolder'];
                 $LookupFolder = !empty($AppFolder) ? $AppFolder : $this->ApplicationFolder;
                 $Search = AssetModel::CssPath($CssFile, $LookupFolder, $ThemeType);
                 if (!$Search) {
                     continue;
                 }
                 list($Path, $UrlPath) = $Search;
                 if (isUrl($Path)) {
                     $this->Head->AddCss($Path, 'all', val('AddVersion', $Options, true), $Options);
                     continue;
                 } else {
                     // Check to see if there is a CSS cacher.
                     $CssCacher = Gdn::factory('CssCacher');
                     if (!is_null($CssCacher)) {
                         $Path = $CssCacher->get($Path, $AppFolder);
                     }
                     if ($Path !== false) {
                         $Path = substr($Path, strlen(PATH_ROOT));
                         $Path = str_replace(DS, '/', $Path);
                         $this->Head->addCss($Path, 'all', true, $Options);
                     }
                 }
             }
             // Add a custom js file.
             if (arrayHasValue($this->_CssFiles, 'style.css')) {
                 $this->addJsFile('custom.js');
                 // only to non-admin pages.
             }
             $Cdns = array();
             if (!c('Garden.Cdns.Disable', false)) {
                 $Cdns = array('jquery.js' => "//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js");
             }
             // And now search for/add all JS files.
             $this->EventArguments['Cdns'] =& $Cdns;
             $this->fireEvent('AfterJsCdns');
             $this->Head->addScript('', 'text/javascript', false, array('content' => $this->definitionList(false)));
             foreach ($this->_JsFiles as $Index => $JsInfo) {
                 $JsFile = $JsInfo['FileName'];
                 if (!is_array($JsInfo['Options'])) {
                     $JsInfo['Options'] = array();
                 }
                 $Options =& $JsInfo['Options'];
                 if (isset($Cdns[$JsFile])) {
                     $JsFile = $Cdns[$JsFile];
                 }
                 $AppFolder = $JsInfo['AppFolder'];
                 $LookupFolder = !empty($AppFolder) ? $AppFolder : $this->ApplicationFolder;
                 $Search = AssetModel::JsPath($JsFile, $LookupFolder, $ThemeType);
                 if (!$Search) {
                     continue;
                 }
                 list($Path, $UrlPath) = $Search;
                 if ($Path !== false) {
                     $AddVersion = true;
                     if (!isUrl($Path)) {
                         $Path = substr($Path, strlen(PATH_ROOT));
                         $Path = str_replace(DS, '/', $Path);
                         $AddVersion = val('AddVersion', $Options, true);
                     }
                     $this->Head->addScript($Path, 'text/javascript', $AddVersion, $Options);
                     continue;
                 }
             }
         }
         // Add the favicon.
         $Favicon = C('Garden.FavIcon');
         if ($Favicon) {
             $this->Head->setFavIcon(Gdn_Upload::url($Favicon));
         }
         // Make sure the head module gets passed into the assets collection.
         $this->addModule('Head');
     }
     // Master views come from one of four places:
     $MasterViewPaths = array();
     if (strpos($this->MasterView, '/') !== false) {
         $MasterViewPaths[] = combinePaths(array(PATH_ROOT, str_replace('/', DS, $this->MasterView) . '.master*'));
     } else {
         if ($this->Theme) {
             // 1. Application-specific theme view. eg. root/themes/theme_name/app_name/views/
             $MasterViewPaths[] = combinePaths(array(PATH_THEMES, $this->Theme, $this->ApplicationFolder, 'views', $this->MasterView . '.master*'));
             // 2. Garden-wide theme view. eg. /path/to/application/themes/theme_name/views/
             $MasterViewPaths[] = combinePaths(array(PATH_THEMES, $this->Theme, 'views', $this->MasterView . '.master*'));
         }
         // 3. Plugin default. eg. root/plugin_name/views/
         $MasterViewPaths[] = combinePaths(array(PATH_ROOT, $this->ApplicationFolder, 'views', $this->MasterView . '.master*'));
         // 4. Application default. eg. root/app_name/views/
         $MasterViewPaths[] = combinePaths(array(PATH_APPLICATIONS, $this->ApplicationFolder, 'views', $this->MasterView . '.master*'));
         // 5. Garden default. eg. root/dashboard/views/
         $MasterViewPaths[] = combinePaths(array(PATH_APPLICATIONS, 'dashboard', 'views', $this->MasterView . '.master*'));
     }
     // Find the first file that matches the path.
     $MasterViewPath = false;
     foreach ($MasterViewPaths as $Glob) {
         $Paths = safeGlob($Glob);
         if (is_array($Paths) && count($Paths) > 0) {
             $MasterViewPath = $Paths[0];
             break;
         }
     }
     $this->EventArguments['MasterViewPath'] =& $MasterViewPath;
     $this->fireEvent('BeforeFetchMaster');
     if ($MasterViewPath === false) {
         trigger_error(errorMessage("Could not find master view: {$this->MasterView}.master*", $this->ClassName, '_FetchController'), E_USER_ERROR);
     }
     /// A unique identifier that can be used in the body tag of the master view if needed.
     $ControllerName = $this->ClassName;
     // Strip "Controller" from the body identifier.
     if (substr($ControllerName, -10) == 'Controller') {
         $ControllerName = substr($ControllerName, 0, -10);
     }
     // Strip "Gdn_" from the body identifier.
     if (substr($ControllerName, 0, 4) == 'Gdn_') {
         $ControllerName = substr($ControllerName, 4);
     }
     $this->setData('CssClass', $this->Application . ' ' . $ControllerName . ' ' . $this->RequestMethod . ' ' . $this->CssClass, true);
     // Check to see if there is a handler for this particular extension.
     $ViewHandler = Gdn::factory('ViewHandler' . strtolower(strrchr($MasterViewPath, '.')));
     if (is_null($ViewHandler)) {
         $BodyIdentifier = strtolower($this->ApplicationFolder . '_' . $ControllerName . '_' . Gdn_Format::alphaNumeric(strtolower($this->RequestMethod)));
         include $MasterViewPath;
     } else {
         $ViewHandler->render($MasterViewPath, $this);
     }
 }
Ejemplo n.º 5
0
 /**
  * Returns the provided fieldname with non-alpha-numeric values stripped and
  * $this->IDPrefix prepended.
  *
  * @param string $FieldName
  * @param bool $ForceUniqueID
  * @return string
  */
 public function escapeID($FieldName, $ForceUniqueID = true)
 {
     $ID = $FieldName;
     if (substr($ID, -2) == '[]') {
         $ID = substr($ID, 0, -2);
     }
     $ID = $this->IDPrefix . Gdn_Format::alphaNumeric(str_replace('.', '-dot-', $ID));
     $tmp = $ID;
     $i = 1;
     if ($ForceUniqueID === true) {
         if (array_key_exists($ID, $this->_IDCollection)) {
             $tmp = $ID . $this->_IDCollection[$ID];
             $this->_IDCollection[$ID]++;
         } else {
             $tmp = $ID;
             $this->_IDCollection[$ID] = 1;
         }
     } else {
         // If not forcing unique (ie. getting the id for a label's "for" tag),
         // get the last used copy of the requested id.
         $Found = false;
         $Count = val($ID, $this->_IDCollection, 0);
         if ($Count <= 1) {
             $tmp = $ID;
         } else {
             $tmp = $ID . ($Count - 1);
         }
     }
     return $tmp;
 }
 /**
  * Display custom fields on Profile.
  */
 public function userInfoModule_onBasicInfo_handler($Sender)
 {
     if ($Sender->User->Banned) {
         return;
     }
     try {
         // Get the custom fields
         $ProfileFields = Gdn::userModel()->getMeta($Sender->User->UserID, 'Profile.%', 'Profile.');
         // Import from CustomProfileFields if available
         if (!count($ProfileFields) && is_object($Sender->User) && c('Plugins.CustomProfileFields.SuggestedFields', false)) {
             $ProfileFields = Gdn::userModel()->getAttribute($Sender->User->UserID, 'CustomProfileFields', false);
             if ($ProfileFields) {
                 // Migrate to UserMeta & delete original
                 Gdn::userModel()->setMeta($Sender->User->UserID, $ProfileFields, 'Profile.');
                 Gdn::userModel()->saveAttribute($Sender->User->UserID, 'CustomProfileFields', false);
             }
         }
         // Send them off for magic formatting
         $ProfileFields = $this->parseSpecialFields($ProfileFields);
         // Get all field data, error check
         $AllFields = $this->getProfileFields();
         if (!is_array($AllFields) || !is_array($ProfileFields)) {
             return;
         }
         // DateOfBirth is special case that core won't handle
         // Hack it in here instead
         if (c('ProfileExtender.Fields.DateOfBirth.OnProfile')) {
             // Do not use Gdn_Format::Date because it shifts to local timezone
             $BirthdayStamp = Gdn_Format::toTimestamp($Sender->User->DateOfBirth);
             if ($BirthdayStamp) {
                 $ProfileFields['DateOfBirth'] = date(t('Birthday Format', 'F j, Y'), $BirthdayStamp);
                 $AllFields['DateOfBirth'] = array('Label' => t('Birthday'), 'OnProfile' => true);
             }
         }
         // Display all non-hidden fields
         $ProfileFields = array_reverse($ProfileFields);
         foreach ($ProfileFields as $Name => $Value) {
             // Skip empty and hidden fields.
             if (!$Value || !val('OnProfile', $AllFields[$Name])) {
                 continue;
             }
             // Non-magic fields must be plain text, but we'll auto-link
             if (!in_array($Name, $this->MagicLabels)) {
                 $Value = Gdn_Format::links(Gdn_Format::text($Value));
             }
             echo ' <dt class="ProfileExtend Profile' . Gdn_Format::alphaNumeric($Name) . '">' . Gdn_Format::text($AllFields[$Name]['Label']) . '</dt> ';
             echo ' <dd class="ProfileExtend Profile' . Gdn_Format::alphaNumeric($Name) . '">' . Gdn_Format::htmlFilter($Value) . '</dd> ';
         }
     } catch (Exception $ex) {
         // No errors
     }
 }
Ejemplo n.º 7
0
 /**
  * Generate a valid css class from a role name.
  *
  * @param string $rawRole role name
  * @return string CSS class
  */
 private function formatRoleCss($rawRole)
 {
     return 'Role_' . str_replace(' ', '_', Gdn_Format::alphaNumeric($rawRole));
 }
Ejemplo n.º 8
0
 /**
  * Creates the table defined with $this->Table() and $this->Column().
  */
 protected function _create()
 {
     $PrimaryKey = array();
     $UniqueKey = array();
     $FullTextKey = array();
     $AllowFullText = true;
     $Indexes = array();
     $Keys = '';
     $Sql = '';
     $ForceDatabaseEngine = C('Database.ForceStorageEngine');
     if ($ForceDatabaseEngine && !$this->_TableStorageEngine) {
         $this->_TableStorageEngine = $ForceDatabaseEngine;
         $AllowFullText = $this->_supportsFulltext();
     }
     foreach ($this->_Columns as $ColumnName => $Column) {
         if ($Sql != '') {
             $Sql .= ',';
         }
         $Sql .= "\n" . $this->_defineColumn($Column);
         $ColumnKeyTypes = (array) $Column->KeyType;
         foreach ($ColumnKeyTypes as $ColumnKeyType) {
             $KeyTypeParts = explode('.', $ColumnKeyType, 2);
             $ColumnKeyType = $KeyTypeParts[0];
             $IndexGroup = val(1, $KeyTypeParts, '');
             if ($ColumnKeyType == 'primary') {
                 $PrimaryKey[] = $ColumnName;
             } elseif ($ColumnKeyType == 'key') {
                 $Indexes['FK'][$IndexGroup][] = $ColumnName;
             } elseif ($ColumnKeyType == 'index') {
                 $Indexes['IX'][$IndexGroup][] = $ColumnName;
             } elseif ($ColumnKeyType == 'unique') {
                 $UniqueKey[] = $ColumnName;
             } elseif ($ColumnKeyType == 'fulltext' && $AllowFullText) {
                 $FullTextKey[] = $ColumnName;
             }
         }
     }
     // Build primary keys
     if (count($PrimaryKey) > 0) {
         $Keys .= ",\nprimary key (`" . implode('`, `', $PrimaryKey) . "`)";
     }
     // Build unique keys.
     if (count($UniqueKey) > 0) {
         $Keys .= ",\nunique index `" . Gdn_Format::alphaNumeric('UX_' . $this->_TableName) . '` (`' . implode('`, `', $UniqueKey) . "`)";
     }
     // Build full text index.
     if (count($FullTextKey) > 0) {
         $Keys .= ",\nfulltext index `" . Gdn_Format::alphaNumeric('TX_' . $this->_TableName) . '` (`' . implode('`, `', $FullTextKey) . "`)";
     }
     // Build the rest of the keys.
     foreach ($Indexes as $IndexType => $IndexGroups) {
         $CreateString = val($IndexType, array('FK' => 'key', 'IX' => 'index'));
         foreach ($IndexGroups as $IndexGroup => $ColumnNames) {
             if (!$IndexGroup) {
                 foreach ($ColumnNames as $ColumnName) {
                     $Keys .= ",\n{$CreateString} `{$IndexType}_{$this->_TableName}_{$ColumnName}` (`{$ColumnName}`)";
                 }
             } else {
                 $Keys .= ",\n{$CreateString} `{$IndexType}_{$this->_TableName}_{$IndexGroup}` (`" . implode('`, `', $ColumnNames) . '`)';
             }
         }
     }
     $Sql = 'create table `' . $this->_DatabasePrefix . $this->_TableName . '` (' . $Sql . $Keys . "\n)";
     // Check to see if there are any fulltext columns, otherwise use innodb.
     if (!$this->_TableStorageEngine) {
         $HasFulltext = false;
         foreach ($this->_Columns as $Column) {
             $ColumnKeyTypes = (array) $Column->KeyType;
             array_map('strtolower', $ColumnKeyTypes);
             if (in_array('fulltext', $ColumnKeyTypes)) {
                 $HasFulltext = true;
                 break;
             }
         }
         if ($HasFulltext) {
             $this->_TableStorageEngine = 'myisam';
         } else {
             $this->_TableStorageEngine = C('Database.DefaultStorageEngine', 'innodb');
         }
         if (!$this->hasEngine($this->_TableStorageEngine)) {
             $this->_TableStorageEngine = 'myisam';
         }
     }
     if ($this->_TableStorageEngine) {
         $Sql .= ' engine=' . $this->_TableStorageEngine;
     }
     if ($this->_CharacterEncoding !== false && $this->_CharacterEncoding != '') {
         $Sql .= ' default character set ' . $this->_CharacterEncoding;
     }
     if (array_key_exists('Collate', $this->Database->ExtendedProperties)) {
         $Sql .= ' collate ' . $this->Database->ExtendedProperties['Collate'];
     }
     $Sql .= ';';
     $Result = $this->query($Sql);
     $this->reset();
     return $Result;
 }
Ejemplo n.º 9
0
 /**
  *
  *
  * @param string $Path
  * @param Gdn_Controller $Controller
  */
 public function init($Path, $Controller)
 {
     $Smarty = $this->smarty();
     // Get a friendly name for the controller.
     $ControllerName = get_class($Controller);
     if (StringEndsWith($ControllerName, 'Controller', true)) {
         $ControllerName = substr($ControllerName, 0, -10);
     }
     // Get an ID for the body.
     $BodyIdentifier = strtolower($Controller->ApplicationFolder . '_' . $ControllerName . '_' . Gdn_Format::alphaNumeric(strtolower($Controller->RequestMethod)));
     $Smarty->assign('BodyID', htmlspecialchars($BodyIdentifier));
     //$Smarty->assign('Config', Gdn::Config());
     // Assign some information about the user.
     $Session = Gdn::session();
     if ($Session->isValid()) {
         $User = array('Name' => htmlspecialchars($Session->User->Name), 'Photo' => '', 'CountNotifications' => (int) val('CountNotifications', $Session->User, 0), 'CountUnreadConversations' => (int) val('CountUnreadConversations', $Session->User, 0), 'SignedIn' => true);
         $Photo = $Session->User->Photo;
         if ($Photo) {
             if (!isUrl($Photo)) {
                 $Photo = Gdn_Upload::url(changeBasename($Photo, 'n%s'));
             }
         } else {
             $Photo = UserModel::getDefaultAvatarUrl($Session->User);
         }
         $User['Photo'] = $Photo;
     } else {
         $User = false;
         /*array(
           'Name' => '',
           'CountNotifications' => 0,
           'SignedIn' => FALSE);*/
     }
     $Smarty->assign('User', $User);
     // Make sure that any datasets use arrays instead of objects.
     foreach ($Controller->Data as $Key => $Value) {
         if ($Value instanceof Gdn_DataSet) {
             $Controller->Data[$Key] = $Value->resultArray();
         } elseif ($Value instanceof stdClass) {
             $Controller->Data[$Key] = (array) $Value;
         }
     }
     $BodyClass = val('CssClass', $Controller->Data, '', true);
     $Sections = Gdn_Theme::section(null, 'get');
     if (is_array($Sections)) {
         foreach ($Sections as $Section) {
             $BodyClass .= ' Section-' . $Section;
         }
     }
     $Controller->Data['BodyClass'] = $BodyClass;
     // Set the current locale for themes to take advantage of.
     $Locale = Gdn::locale()->Locale;
     $CurrentLocale = array('Key' => $Locale, 'Lang' => str_replace('_', '-', Gdn::locale()->language(true)));
     if (class_exists('Locale')) {
         $CurrentLocale['Language'] = Locale::getPrimaryLanguage($Locale);
         $CurrentLocale['Region'] = Locale::getRegion($Locale);
         $CurrentLocale['DisplayName'] = Locale::getDisplayName($Locale, $Locale);
         $CurrentLocale['DisplayLanguage'] = Locale::getDisplayLanguage($Locale, $Locale);
         $CurrentLocale['DisplayRegion'] = Locale::getDisplayRegion($Locale, $Locale);
     }
     $Smarty->assign('CurrentLocale', $CurrentLocale);
     $Smarty->assign('Assets', (array) $Controller->Assets);
     // 2016-07-07 Linc: Request used to return blank for homepage.
     // Now it returns defaultcontroller. This restores BC behavior.
     $isHomepage = val('isHomepage', $Controller->Data);
     $Path = $isHomepage ? "" : Gdn::request()->path();
     $Smarty->assign('Path', $Path);
     $Smarty->assign('Homepage', $isHomepage);
     // true/false
     // Assign the controller data last so the controllers override any default data.
     $Smarty->assign($Controller->Data);
     $security = new SmartySecurityVanilla($Smarty);
     $security->php_handling = Smarty::PHP_REMOVE;
     $security->allow_constants = false;
     $security->allow_super_globals = false;
     $security->streams = null;
     $security->setPhpFunctions(array_merge($security->php_functions, ['array', 'category', 'checkPermission', 'inSection', 'inCategory', 'ismobile', 'multiCheckPermission', 'getValue', 'setValue', 'url', 'useragenttype']));
     $security->php_modifiers = array_merge($security->php_functions, array('sprintf'));
     $Smarty->enableSecurity($security);
 }