/** * */ 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); } }