/** * Render the given view. * * @param string $Path The path to the view's file. * @param Controller $Controller The controller that is rendering the view. */ public function Render($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, 'CountNotifications' => (int)GetValue('CountNotifications', $Session->User->CountNotifications, 0), 'CountUnreadConversations' => (int)GetValue('CountUnreadConversations', $Session->User, 0), 'SignedIn' => TRUE); } 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; } } $Controller->Data['BodyClass'] = GetValue('CssClass', $Controller->Data, '', TRUE); $Smarty->assign('Assets', (array)$Controller->Assets); $Smarty->assign('Path', Gdn::Request()->Path()); // Assigign 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('CheckPermission', 'GetValue', 'SetValue', 'Url')); $Smarty->secure_dir = array($Path); $Smarty->display($Path); }
/** * Render the given view. * * @param string $Path The path to the view's file. * @param Controller $Controller The controller that is rendering the view. */ public function Render($Path, $Controller) { $Smarty = $this->Smarty(); // Get a friendly name for the controller. $ControllerName = get_class($Controller); if (preg_match('/^(?:Gdn_)?(.*?)(?:Controller)?$/', $ControllerName, $Matches)) { $ControllerName = $Matches[1]; } $Smarty->assign('ControllerName', $ControllerName); // Get an ID for the body. $BodyIdentifier = strtolower($Controller->ApplicationFolder . '_' . $ControllerName . '_' . Gdn_Format::AlphaNumeric(strtolower($Controller->RequestMethod))); $Smarty->assign('BodyIdentifier', $BodyIdentifier); $Smarty->assign('Config', Gdn::Config()); // Make sure that any datasets use arrays instead of objects. foreach ($Controller->Data as $Key => $Value) { if ($Value instanceof Gdn_DataSet) { $Value->DatasetType(DATASET_TYPE_ARRAY); } } $Smarty->assign($Controller->Data); $Smarty->assign('Controller', $Controller); $Smarty->display($Path); }
/** * Undocumented method. * * @todo Method RenderMaster() needs a description. */ 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)) { if (ArrayHasValue($this->_CssFiles, 'style.css')) { $this->AddCssFile('custom.css'); } if (ArrayHasValue($this->_CssFiles, 'admin.css')) { $this->AddCssFile('customadmin.css'); } $this->EventArguments['CssFiles'] =& $this->_CssFiles; $this->FireEvent('BeforeAddCss'); // And now search for/add all css files foreach ($this->_CssFiles as $CssInfo) { $CssFile = $CssInfo['FileName']; if (strpos($CssFile, '/') !== FALSE) { // A direct path to the file was given. $CssPaths = array(CombinePaths(array(PATH_ROOT, str_replace('/', DS, $CssFile)))); } else { $CssGlob = preg_replace('/(.*)(\\.css)/', '\\1*\\2', $CssFile); $AppFolder = $CssInfo['AppFolder']; if ($AppFolder == '') { $AppFolder = $this->ApplicationFolder; } // CSS comes from one of four places: $CssPaths = array(); if ($this->Theme) { // 1. Application-specific css. eg. root/themes/theme_name/app_name/design/ // $CssPaths[] = PATH_THEMES . DS . $this->Theme . DS . $AppFolder . DS . 'design' . DS . $CssGlob; // 2. Theme-wide theme view. eg. root/themes/theme_name/design/ // a) Check to see if a customized version of the css is there. if ($this->ThemeOptions) { $Filenames = GetValueR('Styles.Value', $this->ThemeOptions); if (is_string($Filenames) && $Filenames != '%s') { $CssPaths[] = PATH_THEMES . DS . $this->Theme . DS . 'design' . DS . ChangeBasename($CssFile, $Filenames); } } // b) Use the default filename. $CssPaths[] = PATH_THEMES . DS . $this->Theme . DS . 'design' . DS . $CssFile; } // 3. Application or plugin. if (StringBeginsWith($AppFolder, 'plugins/')) { // The css is coming from a plugin. $AppFolder = substr($AppFolder, strlen('plugins/')); $CssPaths[] = PATH_PLUGINS . "/{$AppFolder}/design/{$CssFile}"; $CssPaths[] = PATH_PLUGINS . "/{$AppFolder}/{$CssFile}"; } else { // Application default. eg. root/applications/app_name/design/ $CssPaths[] = PATH_APPLICATIONS . DS . $AppFolder . DS . 'design' . DS . $CssFile; } // 4. Garden default. eg. root/applications/dashboard/design/ $CssPaths[] = PATH_APPLICATIONS . DS . 'dashboard' . DS . 'design' . DS . $CssFile; } // Find the first file that matches the path. $CssPath = FALSE; foreach ($CssPaths as $Glob) { $Paths = SafeGlob($Glob); if (is_array($Paths) && count($Paths) > 0) { $CssPath = $Paths[0]; break; } } // Check to see if there is a CSS cacher. $CssCacher = Gdn::Factory('CssCacher'); if (!is_null($CssCacher)) { $CssPath = $CssCacher->Get($CssPath, $AppFolder); } if ($CssPath !== FALSE) { $CssPath = substr($CssPath, strlen(PATH_ROOT)); $CssPath = str_replace(DS, '/', $CssPath); $this->Head->AddCss($CssPath, 'all', TRUE, $CssInfo['Options']); } } // Add a custom js file. if (ArrayHasValue($this->_CssFiles, 'style.css')) { $this->AddJsFile('custom.js'); } // only to non-admin pages. // And now search for/add all JS files foreach ($this->_JsFiles as $Index => $JsInfo) { $JsFile = $JsInfo['FileName']; if (strpos($JsFile, '//') !== FALSE) { // This is a link to an external file. $this->Head->AddScript($JsFile); continue; } if (strpos($JsFile, '/') !== FALSE) { // A direct path to the file was given. $JsPaths = array(CombinePaths(array(PATH_ROOT, str_replace('/', DS, $JsFile)), DS)); } else { $AppFolder = $JsInfo['AppFolder']; if ($AppFolder == '') { $AppFolder = $this->ApplicationFolder; } // JS can come from a theme, an any of the application folder, or it can come from the global js folder: $JsPaths = array(); if ($this->Theme) { // 1. Application-specific js. eg. root/themes/theme_name/app_name/design/ $JsPaths[] = PATH_THEMES . DS . $this->Theme . DS . $AppFolder . DS . 'js' . DS . $JsFile; // 2. Garden-wide theme view. eg. root/themes/theme_name/design/ $JsPaths[] = PATH_THEMES . DS . $this->Theme . DS . 'js' . DS . $JsFile; } // 3. The application or plugin folder. if (StringBeginsWith(trim($AppFolder, '/'), 'plugins/')) { $JsPaths[] = PATH_PLUGINS . strstr($AppFolder, '/') . "/js/{$JsFile}"; $JsPaths[] = PATH_PLUGINS . strstr($AppFolder, '/') . "/{$JsFile}"; } else { $JsPaths[] = PATH_APPLICATIONS . "/{$AppFolder}/js/{$JsFile}"; } // 4. Global JS folder. eg. root/js/ $JsPaths[] = PATH_ROOT . DS . 'js' . DS . $JsFile; // 5. Global JS library folder. eg. root/js/library/ $JsPaths[] = PATH_ROOT . DS . 'js' . DS . 'library' . DS . $JsFile; } // Find the first file that matches the path. $JsPath = FALSE; foreach ($JsPaths as $Glob) { $Paths = SafeGlob($Glob); if (is_array($Paths) && count($Paths) > 0) { $JsPath = $Paths[0]; break; } } if ($JsPath !== FALSE) { $JsSrc = str_replace(array(PATH_ROOT, DS), array('', '/'), $JsPath); $Options = (array) $JsInfo['Options']; $Options['path'] = $JsPath; $Version = GetValue('Version', $JsInfo); if ($Version) { TouchValue('version', $Options, $Version); } $this->Head->AddScript($JsSrc, 'text/javascript', $Options); } } } // Add the favicon $this->Head->SetFavIcon(C('Garden.FavIcon', Asset('themes/' . $this->Theme . '/design/favicon.png'))); // 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. Application default. eg. root/app_name/views/ $MasterViewPaths[] = CombinePaths(array(PATH_APPLICATIONS, $this->ApplicationFolder, 'views', $this->MasterView . '.master*')); // 4. 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); } }
/** * Creates the table defined with $this->Table() and $this->Column(). */ protected function _Create() { $PrimaryKey = array(); $UniqueKey = array(); $FullTextKey = array(); $AllowFullText = TRUE; $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) { if ($ColumnKeyType == 'primary') { $PrimaryKey[] = $ColumnName; } elseif ($ColumnKeyType == 'key') { $Keys .= ",\nkey `" . Gdn_Format::AlphaNumeric('`FK_' . $this->_TableName . '_' . $ColumnName) . '` (`' . $ColumnName . '`)'; } elseif ($ColumnKeyType == 'index') { $Keys .= ",\nindex `" . Gdn_Format::AlphaNumeric('`IX_' . $this->_TableName . '_' . $ColumnName) . '` (`' . $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) . "`)"; } $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; }
/** * Undocumented method. * * @todo Method RenderMaster() needs a description. */ 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)) { // if (ArrayHasValue($this->_CssFiles, 'style.css')) { // $this->AddCssFile('custom.css'); // // // Add the theme option's css file. // if ($this->Theme && $this->ThemeOptions) { // $Filenames = GetValueR('Styles.Value', $this->ThemeOptions); // if (is_string($Filenames) && $Filenames != '%s') // $this->_CssFiles[] = array('FileName' => ChangeBasename('custom.css', $Filenames), 'AppFolder' => FALSE, 'Options' => FALSE); // } // } elseif (ArrayHasValue($this->_CssFiles, 'admin.css')) { // $this->AddCssFile('customadmin.css'); // } $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']; // style.css and admin.css deserve some custom processing. if (in_array($CssFile, array('style.css', 'admin.css'))) { 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("/utility/css/{$ThemeType}/{$Basename}-{$ETag}.css", '//'), 'all', FALSE, $CssInfo['Options']); } continue; } if (StringBeginsWith($CssFile, 'http')) { $this->Head->AddCss($CssFile, 'all', GetValue('AddVersion', $CssInfo, TRUE), $CssInfo['Options']); continue; } elseif (strpos($CssFile, '/') !== FALSE) { // A direct path to the file was given. $CssPaths = array(CombinePaths(array(PATH_ROOT, str_replace('/', DS, $CssFile)))); } else { // $CssGlob = preg_replace('/(.*)(\.css)/', '\1*\2', $CssFile); $AppFolder = $CssInfo['AppFolder']; if ($AppFolder == '') { $AppFolder = $this->ApplicationFolder; } // CSS comes from one of four places: $CssPaths = array(); if ($this->Theme) { // Use the default filename. $CssPaths[] = PATH_THEMES . DS . $this->Theme . DS . 'design' . DS . $CssFile; } // 3. Application or plugin. if (StringBeginsWith($AppFolder, 'plugins/')) { // The css is coming from a plugin. $AppFolder = substr($AppFolder, strlen('plugins/')); $CssPaths[] = PATH_PLUGINS . "/{$AppFolder}/design/{$CssFile}"; $CssPaths[] = PATH_PLUGINS . "/{$AppFolder}/{$CssFile}"; } elseif (in_array($AppFolder, array('static', 'resources'))) { // This is a static css file. $CssPaths[] = PATH_ROOT . "/resources/css/{$CssFile}"; } else { // Application default. eg. root/applications/app_name/design/ $CssPaths[] = PATH_APPLICATIONS . DS . $AppFolder . DS . 'design' . DS . $CssFile; } // 4. Garden default. eg. root/applications/dashboard/design/ $CssPaths[] = PATH_APPLICATIONS . DS . 'dashboard' . DS . 'design' . DS . $CssFile; } // Find the first file that matches the path. $CssPath = FALSE; foreach ($CssPaths as $Glob) { $Paths = SafeGlob($Glob); if (is_array($Paths) && count($Paths) > 0) { $CssPath = $Paths[0]; break; } } // Check to see if there is a CSS cacher. $CssCacher = Gdn::Factory('CssCacher'); if (!is_null($CssCacher)) { $CssPath = $CssCacher->Get($CssPath, $AppFolder); } if ($CssPath !== FALSE) { $CssPath = substr($CssPath, strlen(PATH_ROOT)); $CssPath = str_replace(DS, '/', $CssPath); $this->Head->AddCss($CssPath, 'all', TRUE, $CssInfo['Options']); } } // Add a custom js file. if (ArrayHasValue($this->_CssFiles, 'style.css')) { $this->AddJsFile('custom.js'); } // only to non-admin pages. // And now search for/add all JS files. $Cdns = array(); if (Gdn::Request()->Scheme() != 'https' && !C('Garden.Cdns.Disable', FALSE)) { $Cdns = array('jquery.js' => 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'); } $this->EventArguments['Cdns'] =& $Cdns; $this->FireEvent('AfterJsCdns'); foreach ($this->_JsFiles as $Index => $JsInfo) { $JsFile = $JsInfo['FileName']; if (isset($Cdns[$JsFile])) { $JsFile = $Cdns[$JsFile]; } if (strpos($JsFile, '//') !== FALSE) { // This is a link to an external file. $this->Head->AddScript($JsFile, 'text/javascript', GetValue('Options', $JsInfo, array())); continue; } elseif (strpos($JsFile, '/') !== FALSE) { // A direct path to the file was given. $JsPaths = array(CombinePaths(array(PATH_ROOT, str_replace('/', DS, $JsFile)), DS)); } else { $AppFolder = $JsInfo['AppFolder']; if ($AppFolder == '') { $AppFolder = $this->ApplicationFolder; } // JS can come from a theme, an any of the application folder, or it can come from the global js folder: $JsPaths = array(); if ($this->Theme) { // 1. Application-specific js. eg. root/themes/theme_name/app_name/design/ $JsPaths[] = PATH_THEMES . DS . $this->Theme . DS . $AppFolder . DS . 'js' . DS . $JsFile; // 2. Garden-wide theme view. eg. root/themes/theme_name/design/ $JsPaths[] = PATH_THEMES . DS . $this->Theme . DS . 'js' . DS . $JsFile; } // 3. The application or plugin folder. if (StringBeginsWith(trim($AppFolder, '/'), 'plugins/')) { $JsPaths[] = PATH_PLUGINS . strstr($AppFolder, '/') . "/js/{$JsFile}"; $JsPaths[] = PATH_PLUGINS . strstr($AppFolder, '/') . "/{$JsFile}"; } else { $JsPaths[] = PATH_APPLICATIONS . "/{$AppFolder}/js/{$JsFile}"; } // 4. Global JS folder. eg. root/js/ $JsPaths[] = PATH_ROOT . DS . 'js' . DS . $JsFile; // 5. Global JS library folder. eg. root/js/library/ $JsPaths[] = PATH_ROOT . DS . 'js' . DS . 'library' . DS . $JsFile; } // Find the first file that matches the path. $JsPath = FALSE; foreach ($JsPaths as $Glob) { $Paths = SafeGlob($Glob); if (is_array($Paths) && count($Paths) > 0) { $JsPath = $Paths[0]; break; } } if ($JsPath !== FALSE) { $JsSrc = str_replace(array(PATH_ROOT, DS), array('', '/'), $JsPath); $Options = (array) $JsInfo['Options']; $Options['path'] = $JsPath; $Version = GetValue('Version', $JsInfo); if ($Version) { TouchValue('version', $Options, $Version); } $this->Head->AddScript($JsSrc, 'text/javascript', $Options); } } } // 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(); $MasterViewPath2 = ViewLocation($this->MasterView() . '.master', '', $this->ApplicationFolder); 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. Application default. eg. root/app_name/views/ $MasterViewPaths[] = CombinePaths(array(PATH_APPLICATIONS, $this->ApplicationFolder, 'views', $this->MasterView . '.master*')); // 4. 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; } } if ($MasterViewPath != $MasterViewPath2) { Trace("Master views differ. Controller: {$MasterViewPath}, ViewLocation(): {$MasterViewPath2}", TRACE_WARNING); } $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); } }
/** * Undocumented method. * * @todo Method RenderMaster() needs a description. */ public function RenderMaster() { // Build the master view if necessary if ($this->_DeliveryType == DELIVERY_TYPE_ALL) { // Define some default master views unless one was explicitly defined if ($this->MasterView == '') { // If this is a syndication request, use the appropriate master view if ($this->SyndicationMethod == SYNDICATION_ATOM) { $this->MasterView = 'atom'; } else { if ($this->SyndicationMethod == SYNDICATION_RSS) { $this->MasterView = 'rss'; } else { $this->MasterView = 'default'; } } // Otherwise go with the default } // Only get css & ui components if this is NOT a syndication request if ($this->SyndicationMethod == SYNDICATION_NONE && is_object($this->Head)) { if (ArrayHasValue($this->_CssFiles, 'style.css')) { $this->AddCssFile('custom.css'); } if (ArrayHasValue($this->_CssFiles, 'admin.css')) { $this->AddCssFile('customadmin.css'); } $this->EventArguments['CssFiles'] =& $this->_CssFiles; $this->FireEvent('BeforeAddCss'); // And now search for/add all css files foreach ($this->_CssFiles as $CssInfo) { $CssFile = $CssInfo['FileName']; if (strpos($CssFile, '/') !== FALSE) { // A direct path to the file was given. $CssPaths = array(CombinePaths(array(PATH_ROOT, str_replace('/', DS, $CssFile)))); } else { $CssGlob = preg_replace('/(.*)(\\.css)/', '\\1*\\2', $CssFile); $AppFolder = $CssInfo['AppFolder']; if ($AppFolder == '') { $AppFolder = $this->ApplicationFolder; } // CSS comes from one of four places: $CssPaths = array(); if ($this->Theme) { // 1. Application-specific css. eg. root/themes/theme_name/app_name/design/ // $CssPaths[] = PATH_THEMES . DS . $this->Theme . DS . $AppFolder . DS . 'design' . DS . $CssGlob; // 2. Theme-wide theme view. eg. root/themes/theme_name/design/ $CssPaths[] = PATH_THEMES . DS . $this->Theme . DS . 'design' . DS . $CssFile; } // 3. Application default. eg. root/applications/app_name/design/ $CssPaths[] = PATH_APPLICATIONS . DS . $AppFolder . DS . 'design' . DS . $CssFile; // 4. Garden default. eg. root/applications/dashboard/design/ $CssPaths[] = PATH_APPLICATIONS . DS . 'dashboard' . DS . 'design' . DS . $CssFile; } // Find the first file that matches the path. $CssPath = FALSE; foreach ($CssPaths as $Glob) { $Paths = SafeGlob($Glob); if (is_array($Paths) && count($Paths) > 0) { $CssPath = $Paths[0]; break; } } // Check to see if there is a CSS cacher. $CssCacher = Gdn::Factory('CssCacher'); if (!is_null($CssCacher)) { $CssPath = $CssCacher->Get($CssPath, $AppFolder); } if ($CssPath !== FALSE) { $CssPath = substr($CssPath, strlen(PATH_ROOT)); $CssPath = str_replace(DS, '/', $CssPath); $this->Head->AddCss($CssPath, 'screen'); } } // And now search for/add all JS files foreach ($this->_JsFiles as $JsInfo) { $JsFile = $JsInfo['FileName']; if (strpos($JsFile, '/') !== FALSE) { // A direct path to the file was given. $JsPaths = array(CombinePaths(array(PATH_ROOT, str_replace('/', DS, $JsFile)), DS)); } else { $AppFolder = $JsInfo['AppFolder']; if ($AppFolder == '') { $AppFolder = $this->ApplicationFolder; } // JS can come from a theme, an any of the application folder, or it can come from the global js folder: $JsPaths = array(); if ($this->Theme) { // 1. Application-specific js. eg. root/themes/theme_name/app_name/design/ $JsPaths[] = PATH_THEMES . DS . $this->Theme . DS . $AppFolder . DS . 'js' . DS . $JsFile; // 2. Garden-wide theme view. eg. root/themes/theme_name/design/ $JsPaths[] = PATH_THEMES . DS . $this->Theme . DS . 'js' . DS . $JsFile; } // 3. This application folder $JsPaths[] = PATH_APPLICATIONS . DS . $AppFolder . DS . 'js' . DS . $JsFile; // 4. Global JS folder. eg. root/js/ $JsPaths[] = PATH_ROOT . DS . 'js' . DS . $JsFile; // 5. Global JS library folder. eg. root/js/library/ $JsPaths[] = PATH_ROOT . DS . 'js' . DS . 'library' . DS . $JsFile; } // Find the first file that matches the path. $JsPath = FALSE; foreach ($JsPaths as $Glob) { $Paths = SafeGlob($Glob); if (is_array($Paths) && count($Paths) > 0) { $JsPath = $Paths[0]; break; } } if ($JsPath !== FALSE) { $JsPath = str_replace(array(PATH_ROOT, DS), array('', '/'), $JsPath); $this->Head->AddScript($JsPath); } } } // Add the favicon $this->Head->SetFavIcon(C('Garden.FavIcon', Asset('themes/' . $this->Theme . '/design/favicon.png'))); // 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. Application default. eg. root/app_name/views/ $MasterViewPaths[] = CombinePaths(array(PATH_APPLICATIONS, $this->ApplicationFolder, 'views', $this->MasterView . '.master*')); // 4. 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); } }
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) GetValue('CountNotifications', $Session->User, 0), 'CountUnreadConversations' => (int) GetValue('CountUnreadConversations', $Session->User, 0), 'SignedIn' => TRUE); $Photo = $Session->User->Photo; if ($Photo) { if (!preg_match('`^https?://`i', $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 = GetValue('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; $Smarty->assign('Assets', (array) $Controller->Assets); $Smarty->assign('Path', Gdn::Request()->Path()); // Assigign 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('CheckPermission', 'MultiCheckPermission', 'GetValue', 'SetValue', 'Url', 'InSection', 'InCategory')); $Smarty->security_settings['MODIFIER_FUNCS'] = array_merge($Smarty->security_settings['MODIFIER_FUNCS'], array('sprintf')); $Smarty->secure_dir = array($Path); }
/** * Display custom fields on Profile. */ public function UserInfoModule_OnBasicInfo_Handler($Sender) { 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; } // Display all non-hidden fields $ProfileFields = array_reverse($ProfileFields); foreach ($ProfileFields as $Name => $Value) { if (!$Value) { continue; } if (!GetValue('OnProfile', $AllFields[$Name])) { continue; } if (!in_array($Name, $this->MagicLabels)) { $Value = Gdn_Format::Links(htmlspecialchars($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) . '">' . $Value . '</dd> '; } } catch (Exception $ex) { // No errors } }
/** * Creates the table defined with $this->Table() and $this->Column(). */ protected function _Create() { $PrimaryKey = array(); $UniqueKey = array(); $FullTextKey = array(); $Keys = ''; $Sql = ''; foreach ($this->_Columns as $ColumnName => $Column) { if ($Sql != '') { $Sql .= ','; } $Sql .= "\n" . $this->_DefineColumn($Column); $ColumnKeyTypes = (array) $Column->KeyType; foreach ($ColumnKeyTypes as $ColumnKeyType) { if ($ColumnKeyType == 'primary') { $PrimaryKey[] = $ColumnName; } elseif ($ColumnKeyType == 'key') { $Keys .= ",\nkey `" . Gdn_Format::AlphaNumeric('`FK_' . $this->_TableName . '_' . $ColumnName) . '` (`' . $ColumnName . '`)'; } elseif ($ColumnKeyType == 'index') { $Keys .= ",\nindex `" . Gdn_Format::AlphaNumeric('`IX_' . $this->_TableName . '_' . $ColumnName) . '` (`' . $ColumnName . '`)'; } elseif ($ColumnKeyType == 'unique') { $UniqueKey[] = $ColumnName; } elseif ($ColumnKeyType == 'fulltext') { $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) . "`)"; } $Sql = 'create table `' . $this->_DatabasePrefix . $this->_TableName . '` (' . $Sql . $Keys . "\n)"; if (!is_null($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; }
function GetBodyIdentifier(&$Controller) { $ControllerName = GetShortControllerName($Controller); $BodyIdentifier = $Controller->ApplicationFolder . '_' . $ControllerName . '_' . Gdn_Format::AlphaNumeric(strtolower($Controller->RequestMethod)); return strtolower($BodyIdentifier); }
/** * 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) { while (in_array($tmp, $this->_IDCollection)) { $tmp = $ID . $i; $i++; } $this->_IDCollection[] = $tmp; } 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; while (in_array($tmp, $this->_IDCollection)) { $Found = TRUE; $tmp = $ID . $i; $i++; } if ($Found == TRUE && $i > 2) { $i = $i - 2; $tmp = $ID . $i; } else { $tmp = $ID; } } return $tmp; }
/** * Display custom fields on Profile. */ public function UserInfoModule_OnBasicInfo_Handler($Sender) { 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 $ProfileFields['DateOfBirth'] = date(T('Birthday Format', 'F j, Y'), Gdn_Format::ToTimestamp($Sender->User->DateOfBirth)); $AllFields['DateOfBirth'] = array('Label' => T('Birthday'), 'OnProfile' => TRUE); } // Display all non-hidden fields $ProfileFields = array_reverse($ProfileFields); foreach ($ProfileFields as $Name => $Value) { if (!$Value) { continue; } if (!GetValue('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::Html($Value) . '</dd> '; } } catch (Exception $ex) { // No errors } }
<h2>Debug Trace</h2> <table> <?php foreach ($this->data('Traces') as $Trace) { list($Message, $Type) = $Trace; $Var = 'Debug'; if (!in_array($Type, array(TRACE_ERROR, TRACE_INFO, TRACE_NOTICE, TRACE_WARNING))) { $Var = $Type; $Type = TRACE_INFO; } ?> <tr> <td class="TagColumn"> <span class="Tag Tag-<?php echo Gdn_Format::AlphaNumeric($Type); ?> "><?php echo htmlspecialchars($Type); ?> </span> </td> <td> <?php if (is_string($Message)) { if ($Var != 'Debug') { echo '<b>' . htmlspecialchars($Var) . '</b>: '; } echo nl2br(htmlspecialchars($Message)); } elseif (is_a($Message, 'Exception')) { echo '<pre>';
private function _FormatRoleCss($RawRole) { return 'Role_' . str_replace(' ', '_', Gdn_Format::AlphaNumeric($RawRole)); }
/** * 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 .= GetValue('Bookmarked', $Row) == '1' ? ' Bookmarked' : ''; $Announce = GetValue('Announce', $Row); if ($Announce == 2) { $CssClass .= ' Announcement Announcement-Category'; } elseif ($Announce) { $CssClass .= ' Announcement Announcement-Everywhere'; } $CssClass .= GetValue('Closed', $Row) == '1' ? ' Closed' : ''; $CssClass .= GetValue('InsertUserID', $Row) == $Session->UserID ? ' Mine' : ''; $CssClass .= GetValue('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 = GetValue('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 = GetValue('_CssClass', $Row)) { $CssClass .= ' ' . $_CssClss; } // Insert User classes. if ($UserID = GetValue('InsertUserID', $Row)) { $User = Gdn::UserModel()->GetID($UserID); if ($_CssClss = GetValue('_CssClass', $User)) { $CssClass .= ' ' . $_CssClss; } } return trim($CssClass); }
/** * 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 = GetValue($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) { try { // Get the custom fields $Fields = Gdn::UserModel()->GetMeta($Sender->User->UserID, 'Profile.%', 'Profile.'); // Reorder the custom fields // Use order of Plugins.ProfileExtender.ProfileFields first $Listed = $this->GetFields('Profile'); $Fields1 = array(); foreach ($Listed as $FieldName) { if (isset($Fields[$FieldName])) { $Fields1[$FieldName] = $Fields[$FieldName]; } } // Then append the user's arbitrary custom fields (if they have any) alphabetically by label $Fields2 = array_diff_key($Fields, $Listed); ksort($Fields2); $Fields = array_merge($Fields1, $Fields2); // Import from CustomProfileFields if available if (!count($Fields) && is_object($Sender->User) && C('Plugins.CustomProfileFields.SuggestedFields', FALSE)) { $Fields = Gdn::UserModel()->GetAttribute($Sender->User->UserID, 'CustomProfileFields', FALSE); if ($Fields) { // Migrate to UserMeta & delete original Gdn::UserModel()->SetMeta($Sender->User->UserID, $Fields, 'Profile.'); Gdn::UserModel()->SaveAttribute($Sender->User->UserID, 'CustomProfileFields', FALSE); } } // Send them off for magic formatting $Fields = $this->ParseSpecialFields($Fields); // Display all non-hidden fields $HideFields = $this->GetFields('Hide'); foreach ($Fields as $Label => $Value) { if (in_array($Label, $HideFields)) { continue; } if (!in_array($Label, $this->MagicLabels)) { $Value = Gdn_Format::Links(htmlspecialchars($Value)); } echo ' <dt class="ProfileExtend Profile' . Gdn_Format::AlphaNumeric($Label) . '">' . Gdn_Format::Text($Label) . '</dt> '; echo ' <dd class="ProfileExtend Profile' . Gdn_Format::AlphaNumeric($Label) . '">' . $Value . '</dd> '; } } catch (Exception $ex) { // No errors } }