/**
  * Looks through the themes directory for valid themes and returns them as
  * an associative array of "Theme Name" => "Theme Info Array". It also adds
  * a "Folder" definition to the Theme Info Array for each.
  */
 public function AvailableThemes()
 {
     if (!is_array($this->_AvailableThemes)) {
         $ThemeInfo = array();
         $ThemeFolders = Gdn_FileSystem::Folders(PATH_THEMES);
         $ThemeAboutFiles = Gdn_FileSystem::FindAll(PATH_THEMES, 'about.php', $ThemeFolders);
         // Include them all right here and fill the theme info array
         $ThemeCount = is_array($ThemeAboutFiles) ? count($ThemeAboutFiles) : 0;
         for ($i = 0; $i < $ThemeCount; ++$i) {
             include $ThemeAboutFiles[$i];
             // Define the folder name for the newly added item
             foreach ($ThemeInfo as $ThemeName => $Info) {
                 if (array_key_exists('Folder', $ThemeInfo[$ThemeName]) === FALSE) {
                     $Folder = substr($ThemeAboutFiles[$i], strlen(PATH_THEMES));
                     if (substr($Folder, 0, 1) == DS) {
                         $Folder = substr($Folder, 1);
                     }
                     $Folder = substr($Folder, 0, strpos($Folder, DS));
                     $ThemeInfo[$ThemeName]['Folder'] = $Folder;
                     // Add the screenshot.
                     $ScreenshotPath = SafeGlob(PATH_THEMES . "/{$Folder}/screenshot.*", array('gif', 'jpg', 'png'));
                     if (count($ScreenshotPath) > 0) {
                         $ScreenshotPath = $ScreenshotPath[0];
                         $ThemeInfo[$ThemeName]['ScreenshotUrl'] = Asset(str_replace(PATH_ROOT, '', $ScreenshotPath));
                     }
                 }
             }
         }
         $this->_AvailableThemes = $ThemeInfo;
     }
     return $this->_AvailableThemes;
 }
 public function SettingsController_ProxyConnect_Create($Sender)
 {
     $Sender->Permission('Garden.Settings.Manage');
     $Sender->Title('Proxy Connect SSO');
     $Sender->Form = new Gdn_Form();
     $this->Provider = $this->LoadProviderData($Sender);
     // Load internal Integration Manager list
     $this->IntegrationManagers = array();
     $InternalPath = $this->GetResource('internal');
     try {
         // 2.0.18+
         // New PluginManager Code
         $IntegrationManagers = Gdn::PluginManager()->AvailablePluginFolders($InternalPath);
         $IntegrationList = array();
         foreach ($IntegrationManagers as $Integration) {
             $this->IntegrationManagers[$Integration] = Gdn::PluginManager()->GetPluginInfo($Integration);
         }
     } catch (Exception $e) {
         // 2.0.17.x and below
         // Old PluginManager Code
         if ($FolderHandle = opendir($InternalPath)) {
             // Loop through subfolders (ie. the actual plugin folders)
             while ($FolderHandle !== FALSE && ($Item = readdir($FolderHandle)) !== FALSE) {
                 if (in_array($Item, array('.', '..'))) {
                     continue;
                 }
                 $PluginPaths = SafeGlob($InternalPath . DS . $Item . DS . '*plugin.php');
                 $PluginPaths[] = $InternalPath . DS . $Item . DS . 'default.php';
                 foreach ($PluginPaths as $i => $PluginFile) {
                     if (file_exists($PluginFile)) {
                         $PluginInfo = Gdn::PluginManager()->ScanPluginFile($PluginFile);
                         if (!is_null($PluginInfo)) {
                             Gdn_LibraryMap::SafeCache('plugin', $PluginInfo['ClassName'], $PluginInfo['PluginFilePath']);
                             $Index = strtolower($PluginInfo['Index']);
                             $this->IntegrationManagers[$Index] = $PluginInfo;
                         }
                     }
                 }
             }
             closedir($FolderHandle);
         }
     }
     $this->IntegrationManager = C('Plugin.ProxyConnect.IntegrationManager', NULL);
     if (is_null($this->IntegrationManager)) {
         $this->SetIntegrationManager('proxyconnectmanual');
     }
     $this->EnableSlicing($Sender);
     $this->Dispatch($Sender, $Sender->RequestArgs);
 }
Ejemplo n.º 3
0
 /**
  * @package $Sender Gdn_Controller
  */
 public function PluginController_CssThemes_Create($Sender)
 {
     $Sender->Form = Gdn::Factory('Form');
     $Model = new Gdn_Model('ThemeSetting');
     $Sender->Form->SetModel($Model);
     if ($Sender->Form->AuthenticatedPostBack() === FALSE) {
         // Grab the colors.
         $Data = $Model->Get();
         //$Data = ConsolidateArrayValuesByKey($Data->ResultArray(), 'Name', 'Setting');
         $Sender->SetData('ThemeSettings', $Data->ResultArray());
         //$Sender->Form->SetData($Data);
     } else {
         $Data = $Sender->Form->FormDataSet();
         // Update the database.
         $SQL = Gdn::SQL();
         foreach ($Data as $Row) {
             $SQL->Put('ThemeSetting', array('Setting' => $Row['Setting']), array('Name' => $Row['Name']));
         }
         // Clear out the css cache.
         $Files = SafeGlob(PATH_CACHE . DS . 'css' . DS . '*.css');
         foreach ($Files as $File) {
             unlink($File);
         }
         $Sender->SetData('ThemeSettings', $Data);
         $Sender->StatusMessage = Gdn::Translate('Your changes have been saved.');
     }
     // Add the javascript & css.
     $Sender->Head->AddScript('/plugins/cssthemes/colorpicker.js');
     $Sender->Head->AddScript('/plugins/cssthemes/cssthemes.js');
     $Sender->Head->AddCss('/plugins/cssthemes/colorpicker.css');
     $Sender->Head->AddCss('/plugins/cssthemes/cssthemes.css');
     // Add the side module.
     $Sender->AddSideMenu('/plugin/cssthemes');
     $Sender->View = dirname(__FILE__) . DS . 'views' . DS . 'cssthemes.php';
     $Sender->Render();
 }
 /**
  * Temporarily enable a locale pack without installing it
  *
  * @param string $LocaleKey The key of the folder.
  */
 public function TestLocale($LocaleKey)
 {
     $Available = $this->AvailableLocalePacks();
     if (!isset($Available[$LocaleKey])) {
         throw NotFoundException('Locale');
     }
     // Grab all of the definition files from the locale.
     $Paths = SafeGlob(PATH_ROOT . "/locales/{$LocaleKey}/*.php");
     // Unload the dynamic config
     Gdn::Locale()->Unload();
     // Load each locale file, checking for errors
     foreach ($Paths as $Path) {
         Gdn::Locale()->Load($Path, FALSE);
     }
 }
Ejemplo n.º 5
0
 public function CreateZip()
 {
     if (!class_exists('ZipArchive')) {
         throw new Exception('Your server does not support zipping files.', 400);
     }
     $Info = $this->GetInfoArray();
     $this->EnsureDefinitionFile();
     // Get the basename of the locale.
     $Key = key($Info);
     $ZipPath = PATH_UPLOADS . "/{$Key}.zip";
     $TmpPath = PATH_UPLOADS . "/tmp_" . RandomString(10);
     $Zip = new ZipArchive();
     $Zip->open($TmpPath, ZIPARCHIVE::CREATE);
     // Add all of the files in the locale to the zip.
     $Files = SafeGlob(rtrim($this->LocalePath, '/') . '/*.*', array('php', 'txt'));
     foreach ($Files as $File) {
         $LocalPath = $Key . '/' . basename($File);
         $Zip->addFile($File, $LocalPath);
     }
     $Zip->close();
     rename($TmpPath, $ZipPath);
     return $ZipPath;
 }
Ejemplo n.º 6
0
 public function Base_BeforeAddCss_Handler($Sender)
 {
     $WebRoot = Gdn::Request()->WebRoot();
     // Find all css file paths
     $CssToCache = array();
     foreach ($Sender->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 = $Sender->ApplicationFolder;
             }
             // CSS comes from one of four places:
             $CssPaths = array();
             if ($Sender->Theme) {
                 // 1. Application-specific css. eg. root/themes/theme_name/app_name/design/
                 // $CssPaths[] = PATH_THEMES . DS . $Sender->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 ($Sender->ThemeOptions) {
                     $Filenames = GetValueR('Styles.Value', $Sender->ThemeOptions);
                     if (is_string($Filenames) && $Filenames != '%s') {
                         $CssPaths[] = PATH_THEMES . DS . $Sender->Theme . DS . 'design' . DS . ChangeBasename($CssFile, $Filenames);
                     }
                 }
                 // b) Use the default filename.
                 $CssPaths[] = PATH_THEMES . DS . $Sender->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;
             }
         }
         if ($CssPath !== FALSE) {
             $CssPath = substr($CssPath, strlen(PATH_ROOT) + 1);
             $CssPath = str_replace(DS, '/', $CssPath);
             $CssToCache[] = $CssPath;
         }
     }
     $CssToCache = array_unique($CssToCache);
     // And now search for/add all JS files
     $JsToCache = array();
     // Add the global js files
     $GlobalJS = array('jquery.js', 'jquery.livequery.js', 'jquery.form.js', 'jquery.popup.js', 'jquery.gardenhandleajaxform.js', 'global.js');
     foreach ($Sender->JsFiles() as $JsInfo) {
         $JsFile = $JsInfo['FileName'];
         // Ignore the JsFile if it is in the globaljs minify group (defined in plugins/Minifiy/min/groupsConfig.php).
         if (!in_array($JsFile, $GlobalJS)) {
             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 = $Sender->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 ($Sender->Theme) {
                     // 1. Application-specific js. eg. root/themes/theme_name/app_name/design/
                     $JsPaths[] = PATH_THEMES . DS . $Sender->Theme . DS . $AppFolder . DS . 'js' . DS . $JsFile;
                     // 2. Garden-wide theme view. eg. root/themes/theme_name/design/
                     $JsPaths[] = PATH_THEMES . DS . $Sender->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);
                 $JsPath = substr($JsPath, 0, 1) == '/' ? substr($JsPath, 1) : $JsPath;
                 $JsToCache[] = $JsPath;
             }
         }
     }
     $JsToCache = array_unique($JsToCache);
     // Remove all js & css from the controller
     $Sender->ClearCssFiles();
     $Sender->ClearJsFiles();
     // Add minified css & js directly to the head module
     $Url = 'plugins/Minify/min/?';
     $BasePath = Gdn::Request()->WebRoot();
     if ($BasePath != '') {
         $BasePath = 'b=' . $BasePath . '&';
     }
     $Sender->Head->AddCss($Url . $BasePath . 'f=' . implode(',', $CssToCache), 'screen');
     $Sender->Head->AddScript($Url . 'g=globaljs');
     $Sender->Head->AddScript($Url . $BasePath . 'f=' . implode(',', $JsToCache));
 }
 /**
  * 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_UPLOADS . '/export*', array('gz', 'txt'));
     $ExistingPaths2 = SafeGlob(PATH_UPLOADS . '/porter/export*', array('gz'));
     $ExistingPaths = array_merge($ExistingPaths, $ExistingPaths2);
     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 = val('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 ($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 = val('UploadedFiles', $Imp->Data, array());
         $ImportPaths = array_merge($ImportPaths, $UploadedFiles);
         $this->setData('ImportPaths', $ImportPaths);
         $this->setData('Header', $Imp->getImportHeader());
         $this->setData('Stats', val('Stats', $Imp->Data, array()));
         $this->setData('GenerateSQL', val('GenerateSQL', $Imp->Data));
         $this->setData('ImportPath', $Imp->ImportPath);
         $this->setData('OriginalFilename', val('OriginalFilename', $Imp->Data));
         $this->setData('CurrentStep', $Imp->CurrentStep);
         $this->setData('LoadSpeedWarning', $Imp->loadTableType(false) == 'LoadTableWithInsert');
     } catch (Gdn_UserException $Ex) {
         $this->Form->addError($Ex);
         $Imp->saveState();
         $this->View = 'Index';
     }
     $this->render();
 }
Ejemplo n.º 8
0
 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();
     if ($Imp->CurrentStep < 1) {
         // Check to see if there is a file.
         $ImportPath = Gdn::Config('Garden.Import.ImportPath');
         $Validation = new Gdn_Validation();
         if (strcasecmp(Gdn::Request()->RequestMethod(), 'post') == 0) {
             $Upload = new Gdn_Upload();
             $Validation = new Gdn_Validation();
             $TmpFile = $Upload->ValidateUpload('ImportFile', FALSE);
             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;
                 $Imp->Data['OriginalFilename'] = basename($Filename);
             } elseif (!$Imp->ImportPath) {
                 // There was no file uploaded this request or before.
                 $Validation->AddValidationResult('ImportFile', $Upload->Exception);
             }
             // Validate the overwrite.
             if (strcasecmp($this->Form->GetFormValue('Overwrite'), 'Overwrite') == 0) {
                 $Validation->ApplyRule('Email', 'Required');
                 $Validation->ApplyRule('Password', 'Required');
             }
             if ($Validation->Validate($this->Form->FormValues())) {
                 $Imp->Overwrite($this->Form->GetFormValue('Overwrite', 'Overwrite'), $this->Form->GetFormValue('Email'), $this->Form->GetFormValue('Password'));
                 $this->View = 'Info';
             } else {
                 $this->Form->SetValidationResults($Validation->Results());
             }
         } else {
             // Search for an existing file that was uploaded by the web admin.
             $ImportPaths = SafeGlob(PATH_ROOT . DS . 'uploads' . DS . 'import' . DS . 'import.*');
             if ($ImportPaths) {
                 $ImportPath = $ImportPaths[0];
                 if (in_array(pathinfo($ImportPath, PATHINFO_EXTENSION), array('gz', 'txt'))) {
                     $Imp->ImportPath = $ImportPath;
                     $Imp->Data['OriginalFilename'] = basename($ImportPath);
                 }
             }
         }
         $Imp->SaveState();
     } else {
         $this->View = 'Info';
     }
     $this->SetData('Header', $Imp->GetImportHeader());
     $this->SetData('ImportPath', $Imp->ImportPath);
     $this->SetData('OriginalFilename', GetValue('OriginalFilename', $Imp->Data));
     $this->Render();
 }
Ejemplo n.º 9
0
 <?php 
  $Alt = FALSE;
  $Cols = 3;
  $Col = 0;
  foreach ($this->AvailableThemes as $ThemeName => $ThemeInfo) {
      $ScreenName = ArrayValue('Name', $ThemeInfo, $ThemeName);
      $ThemeFolder = ArrayValue('Folder', $ThemeInfo, '');
      $Active = $ThemeFolder == $this->EnabledThemeFolder;
      if (!$Active) {
          $Version = ArrayValue('Version', $ThemeInfo, '');
          $ThemeUrl = ArrayValue('Url', $ThemeInfo, '');
          $Author = ArrayValue('Author', $ThemeInfo, '');
          $AuthorUrl = ArrayValue('AuthorUrl', $ThemeInfo, '');
          $NewVersion = ArrayValue('NewVersion', $ThemeInfo, '');
          $Upgrade = $NewVersion != '' && version_compare($NewVersion, $Version, '>');
          $PreviewImage = SafeGlob(PATH_THEMES . DS . $ThemeFolder . DS . "screenshot.*", GLOB_BRACE);
          $PreviewImage = count($PreviewImage) > 0 ? basename($PreviewImage[0]) : FALSE;
          if ($PreviewImage && !in_array(strtolower(pathinfo($PreviewImage, PATHINFO_EXTENSION)), array('gif', 'jpg', 'png'))) {
              $PreviewImage = FALSE;
          }
          $Col++;
          if ($Col == 1) {
              $ColClass = 'FirstCol';
              echo '<tr>';
          } elseif ($Col == 2) {
              $ColClass = 'MiddleCol';
          } else {
              $ColClass = 'LastCol';
              $Col = 0;
          }
          $ColClass .= $Active ? ' Enabled' : '';
Ejemplo n.º 10
0
 public function GetLocaleSources($LocaleName, $ApplicationWhiteList, $PluginWhiteList, $ForceRemapping = FALSE)
 {
     $SafeLocaleName = preg_replace('/([^\\w\\d_-])/', '', $LocaleName);
     // Removes everything from the string except letters, numbers, dashes, and underscores
     $LocaleSources = array();
     if (!is_array($ApplicationWhiteList)) {
         $ApplicationWhiteList = array();
     }
     if (!is_array($PluginWhiteList)) {
         $PluginWhiteList = array();
     }
     Gdn_LibraryMap::PrepareCache('locale', NULL, 'tree');
     $LocaleSources = Gdn_LibraryMap::GetCache('locale', $SafeLocaleName);
     if ($ForceRemapping === TRUE || !Gdn_LibraryMap::CacheReady('locale') || $LocaleSources === NULL) {
         $LocaleSources = array();
         // Get application-based locale definition files
         $ApplicationLocaleSources = Gdn_FileSystem::FindAll(PATH_APPLICATIONS, CombinePaths(array('locale', $LocaleName . '.php')), $ApplicationWhiteList);
         if ($ApplicationLocaleSources !== FALSE) {
             $LocaleSources = array_merge($LocaleSources, $ApplicationLocaleSources);
         }
         $ApplicationLocaleSources = Gdn_FileSystem::FindAll(PATH_APPLICATIONS, CombinePaths(array('locale', $LocaleName, 'definitions.php')), $ApplicationWhiteList);
         if ($ApplicationLocaleSources !== FALSE) {
             $LocaleSources = array_merge($LocaleSources, $ApplicationLocaleSources);
         }
         // Get locale-based locale definition files.
         $EnabledLocales = C('EnabledLocales');
         if (is_array($EnabledLocales)) {
             foreach ($EnabledLocales as $Key => $Locale) {
                 if ($Locale != $LocaleName) {
                     continue;
                 }
                 // skip locales that aren't in effect.
                 // Grab all of the files in the locale's folder.
                 $Paths = SafeGlob(PATH_ROOT . "/locales/{$Key}/*.php");
                 if (is_array($Paths)) {
                     foreach ($Paths as $Path) {
                         $LocaleSources[] = $Path;
                     }
                 }
             }
         }
         // Get plugin-based locale definition files
         $PluginLocaleSources = Gdn_FileSystem::FindAll(PATH_PLUGINS, CombinePaths(array('locale', $LocaleName . '.php')), $PluginWhiteList);
         if ($PluginLocaleSources !== FALSE) {
             $LocaleSources = array_merge($LocaleSources, $PluginLocaleSources);
         }
         $PluginLocaleSources = Gdn_FileSystem::FindAll(PATH_PLUGINS, CombinePaths(array('locale', $LocaleName, 'definitions.php')), $PluginWhiteList);
         if ($PluginLocaleSources !== FALSE) {
             $LocaleSources = array_merge($LocaleSources, $PluginLocaleSources);
         }
         // Get theme-based locale definition files.
         $Theme = C('Garden.Theme');
         if ($Theme) {
             $ThemeLocalePath = PATH_THEMES . "/{$Theme}/locale/{$LocaleName}.php";
             if (file_exists($ThemeLocalePath)) {
                 $LocaleSources[] = $ThemeLocalePath;
             }
         }
         // Save the mappings
         $FileContents = array();
         $Count = count($LocaleSources);
         for ($i = 0; $i < $Count; ++$i) {
             $FileContents[$SafeLocaleName][] = Gdn_Format::ArrayValueForPhp($LocaleSources[$i]);
         }
         // Look for a global locale.
         $ConfigLocale = PATH_CONF . '/locale.php';
         if (file_exists($ConfigLocale)) {
             $FileContents[$SafeLocaleName][] = $ConfigLocale;
         }
         // Look for a config locale that is locale-specific.
         $ConfigLocale = PATH_CONF . "/locale-{$LocaleName}.php";
         if (file_exists($ConfigLocale)) {
             $FileContents[$SafeLocaleName][] = $ConfigLocale;
         }
         Gdn_LibraryMap::PrepareCache('locale', $FileContents);
     }
     return $LocaleSources;
 }
Ejemplo n.º 11
0
 $Col = 0;
 $Classes = array('FirstCol', 'MiddleCol', 'LastCol');
 foreach ($this->data('ThemeInfo.Options.Styles') as $Key => $Options) {
     $Basename = val('Basename', $Options, '%s');
     if ($Col == 0) {
         echo '<tr>';
     }
     $Active = '';
     if ($this->data('ThemeOptions.Styles.Key') == $Key || !$this->data('ThemeOptions.Styles.Key') && $Basename == '%s') {
         $Active = ' Active';
     }
     $KeyID = str_replace(' ', '_', $Key);
     echo "<td id=\"{$KeyID}_td\" class=\"{$Classes[$Col]}{$Active}\">";
     echo '<h4>', t($Key), '</h4>';
     // Look for a screenshot for for the style.
     $Screenshot = SafeGlob(PATH_THEMES . DS . $this->data('ThemeFolder') . DS . 'design' . DS . ChangeBasename('screenshot.*', $Basename), array('gif', 'jpg', 'png'));
     if (is_array($Screenshot) && count($Screenshot) > 0) {
         $Screenshot = basename($Screenshot[0]);
         echo img('/themes/' . $this->data('ThemeFolder') . '/design/' . $Screenshot, array('alt' => t($Key), 'width' => '160'));
     }
     $Disabled = $Active ? ' Disabled' : '';
     echo '<div class="Buttons">', anchor(t('Select'), '?style=' . urlencode($Key), 'SmallButton SelectThemeStyle' . $Disabled, array('Key' => $Key)), '</div>';
     if (isset($Options['Description'])) {
         echo '<div class="Info2">', $Options['Description'], '</div>';
     }
     echo '</td>';
     $Col = ($Col + 1) % 3;
     if ($Col == 0) {
         echo '</tr>';
     }
 }
Ejemplo n.º 12
0
   /**
    * Defines and loads the locale.
    *
    * @param string $LocaleName The name of the locale to load. Locale definitions are kept in each
    * application's locale folder. For example:
    *  /dashboard/locale/$LocaleName.php
    *  /vanilla/locale/$LocaleName.php
    * @param array $ApplicationWhiteList An array of application folders that are safe to examine for locale
    *  definitions.
    * @param array $PluginWhiteList An array of plugin folders that are safe to examine for locale
    *  definitions.
    * @param bool $ForceRemapping For speed purposes, the application folders are crawled for locale
    *  sources. Once sources are found, they are saved in the
    *  cache/locale_mapppings.php file. If ForceRemapping is true, this file will
    *  be ignored and the folders will be recrawled and the mapping file will be
    *  re-generated. You can also simply delete the file and it will
    *  automatically force a remapping.
    */
   public function Set($LocaleName, $ApplicationWhiteList, $PluginWhiteList, $ForceRemapping = FALSE) {
      $SafeLocaleName = preg_replace('/([^\w\d_-])/', '', $LocaleName); // Removes everything from the string except letters, numbers, dashes, and underscores
      $LocaleSources = array();
      
      if(!is_array($ApplicationWhiteList)) $ApplicationWhiteList = array();
      if(!is_array($PluginWhiteList)) $PluginWhiteList = array();
      
      Gdn_LibraryMap::PrepareCache('locale', NULL, 'tree');
      $LocaleSources = Gdn_LibraryMap::GetCache('locale',$SafeLocaleName);
      if ($ForceRemapping === TRUE || !Gdn_LibraryMap::CacheReady('locale') || $LocaleSources === NULL) {
         $LocaleSources = array();
         // Get application-based locale definition files
         $ApplicationLocaleSources = Gdn_FileSystem::FindAll(PATH_APPLICATIONS, CombinePaths(array('locale', $LocaleName.'.php')), $ApplicationWhiteList);
         if ($ApplicationLocaleSources !== FALSE)
            $LocaleSources = array_merge($LocaleSources, $ApplicationLocaleSources);

         $ApplicationLocaleSources = Gdn_FileSystem::FindAll(PATH_APPLICATIONS, CombinePaths(array('locale', $LocaleName, 'definitions.php')), $ApplicationWhiteList);
         if ($ApplicationLocaleSources !== FALSE)
            $LocaleSources = array_merge($LocaleSources, $ApplicationLocaleSources);

         // Get plugin-based locale definition files
         $PluginLocaleSources = Gdn_FileSystem::FindAll(PATH_PLUGINS, CombinePaths(array('locale', $LocaleName.'.php')), $PluginWhiteList);
         if ($PluginLocaleSources !== FALSE)
            $LocaleSources = array_merge($LocaleSources, $PluginLocaleSources);
            
         $PluginLocaleSources = Gdn_FileSystem::FindAll(PATH_PLUGINS, CombinePaths(array('locale', $LocaleName, 'definitions.php')), $PluginWhiteList);
         if ($PluginLocaleSources !== FALSE)
            $LocaleSources = array_merge($LocaleSources, $PluginLocaleSources);

         // Get theme-based locale definition files.
         $Theme = C('Garden.Theme');
         if($Theme) {
            $ThemeLocalePath = PATH_THEMES."/$Theme/locale/$LocaleName.php";
            if(file_exists($ThemeLocalePath))
               $LocaleSources[] = $ThemeLocalePath;
         }

         // Get locale-based locale definition files.
         $EnabledLocales = C('EnabledLocales');
         if (is_array($EnabledLocales)) {
            foreach ($EnabledLocales as $Key => $Locale) {
               if ($Locale != $LocaleName)
                  continue; // skip locales that aren't in effect.

               // Grab all of the files in the locale's folder.
               $Paths = SafeGlob(PATH_ROOT."/locales/$Key/*.php");
               if (is_array($Paths)) {
                  foreach($Paths as $Path) {
                     $LocaleSources[] = $Path;
                  }
               }
            }
         }
            
         // Save the mappings
         $FileContents = array();
         $Count = count($LocaleSources);
         for($i = 0; $i < $Count; ++$i) {
            $FileContents[$SafeLocaleName][] = Gdn_Format::ArrayValueForPhp($LocaleSources[$i]);
         }

         // Look for a global locale.
         $ConfigLocale = PATH_LOCAL_CONF.'/locale.php';
         if (file_exists($ConfigLocale))
            $FileContents[$SafeLocaleName][] = $ConfigLocale;

         // Look for a config locale that is locale-specific.
         $ConfigLocale = PATH_LOCAL_CONF."/locale-$LocaleName.php";
         if (file_exists($ConfigLocale))
            $FileContents[$SafeLocaleName][] = $ConfigLocale;
         
         Gdn_LibraryMap::PrepareCache('locale', $FileContents);
      }

      // Set up defaults
      $Definition = array();
      $this->_Definition = array();

      // Now set the locale name and import all of the sources.
      $this->_Locale = $LocaleName;
      $LocaleSources = Gdn_LibraryMap::GetCache('locale', $SafeLocaleName);
      if (is_null($SafeLocaleName))
         $LocaleSources = array();

      $ConfLocaleOverride = PATH_LOCAL_CONF . DS . 'locale.php';
      $Count = count($LocaleSources);
      for($i = 0; $i < $Count; ++$i) {
         if ($ConfLocaleOverride != $LocaleSources[$i] && file_exists($LocaleSources[$i])) // Don't double include the conf override file... and make sure it comes last
            include($LocaleSources[$i]);
      }

      // Also load any custom defined definitions from the conf directory
      if (file_exists($ConfLocaleOverride))
         include($ConfLocaleOverride);

      // All of the included files should have contained
      // $Definition['Code'] = 'Definition'; assignments. The overwrote each
      // other in the order they were included. Now assign the $Definition array
      // to the local private _Definition property.
      $this->_Definition = $Definition;
   }
Ejemplo n.º 13
0
 public function Base_BeforeAddCss_Handler($Sender)
 {
     if ($Sender->DeliveryType() != DELIVERY_TYPE_ALL) {
         return;
     }
     $CssFiles =& $Sender->EventArguments['CssFiles'];
     foreach ($CssFiles as $Index => $CssInfo) {
         $CssFile = $CssInfo['FileName'];
         if (substr($CssFile, -7) != '.dt.css') {
             continue;
         }
         $AppFolder = $CssInfo['AppFolder'];
         if ($AppFolder == '') {
             $AppFolder = $Sender->ApplicationFolder;
         }
         $CssPaths = array();
         if (strpos($CssFile, '/') !== False) {
             $CssPaths[] = CombinePaths(array(PATH_ROOT, $CssFile));
         } else {
             if ($Sender->Theme) {
                 $CssPaths[] = PATH_THEMES . DS . $Sender->Theme . DS . 'design' . DS . $CssFile;
             }
             $CssPaths[] = PATH_APPLICATIONS . DS . $AppFolder . DS . 'design' . DS . $CssFile;
             $CssPaths[] = PATH_APPLICATIONS . DS . 'dashboard' . DS . 'design' . DS . $CssFile;
         }
         $CssPath = False;
         foreach ($CssPaths as $Glob) {
             $Paths = SafeGlob($Glob);
             if (count($Paths) > 0) {
                 $CssPath = $Paths[0];
                 break;
             }
         }
         if ($CssPath == False) {
             continue;
         }
         // not found
         $Basename = pathinfo(pathinfo($CssPath, 8), 8);
         // without .dt.css
         $Hash = self::GetHash($CssPath . filemtime($CssPath));
         $CacheFileName = sprintf('__%s-c-%s.css', $Basename, $Hash);
         $CachedCssFile = dirname($CssPath) . DS . $CacheFileName;
         if (!file_exists($CachedCssFile)) {
             self::MakeCssFile($CssPath, $CachedCssFile, True);
         }
         // TODO: use AbsoluteSource() from 2.0.18
         // ... and replace preprocessored dt.css file by css
         $CssInfo['FileName'] = substr($CachedCssFile, strlen(PATH_ROOT));
         $CssFiles[$Index] = $CssInfo;
         // AppFolder nevermind (will be ignored)
     }
 }
Ejemplo n.º 14
0
 <?php 
  $Alt = FALSE;
  $Cols = 3;
  $Col = 0;
  foreach ($this->AvailableThemes as $ThemeName => $ThemeInfo) {
      $ScreenName = ArrayValue('Name', $ThemeInfo, $ThemeName);
      $ThemeFolder = ArrayValue('Folder', $ThemeInfo, '');
      $Active = $ThemeFolder == $this->EnabledThemeFolder;
      if (!$Active) {
          $Version = ArrayValue('Version', $ThemeInfo, '');
          $ThemeUrl = ArrayValue('Url', $ThemeInfo, '');
          $Author = ArrayValue('Author', $ThemeInfo, '');
          $AuthorUrl = ArrayValue('AuthorUrl', $ThemeInfo, '');
          $NewVersion = ArrayValue('NewVersion', $ThemeInfo, '');
          $Upgrade = $NewVersion != '' && version_compare($NewVersion, $Version, '>');
          $PreviewImage = SafeGlob(PATH_THEMES . DS . $ThemeFolder . DS . "screenshot{.gif,.jpg,.png}", GLOB_BRACE);
          $PreviewImage = count($PreviewImage) > 0 ? basename($PreviewImage[0]) : FALSE;
          $Col++;
          if ($Col == 1) {
              $ColClass = 'FirstCol';
              echo '<tr>';
          } elseif ($Col == 2) {
              $ColClass = 'MiddleCol';
          } else {
              $ColClass = 'LastCol';
              $Col = 0;
          }
          $ColClass .= $Active ? ' Enabled' : '';
          $ColClass .= $PreviewImage ? ' HasPreview' : '';
          ?>
          <td class="<?php 
Ejemplo n.º 15
0
 /**
  * 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);
     }
 }
Ejemplo n.º 16
0
 <?php 
  $Alt = FALSE;
  $Cols = 3;
  $Col = 0;
  foreach ($this->Data('AvailableThemes') as $ThemeName => $ThemeInfo) {
      $ScreenName = GetValue('Name', $ThemeInfo, $ThemeName);
      $ThemeFolder = GetValue('Folder', $ThemeInfo, '');
      $Active = $ThemeFolder == $this->Data('EnabledThemeFolder');
      if (!$Active) {
          $Version = GetValue('Version', $ThemeInfo, '');
          $ThemeUrl = GetValue('Url', $ThemeInfo, '');
          $Author = GetValue('Author', $ThemeInfo, '');
          $AuthorUrl = GetValue('AuthorUrl', $ThemeInfo, '');
          $NewVersion = GetValue('NewVersion', $ThemeInfo, '');
          $Upgrade = $NewVersion != '' && version_compare($NewVersion, $Version, '>');
          $PreviewImage = SafeGlob(PATH_THEMES . DS . $ThemeFolder . DS . "screenshot.*", array('gif', 'jpg', 'png'));
          $PreviewImage = count($PreviewImage) > 0 ? basename($PreviewImage[0]) : FALSE;
          $Col++;
          if ($Col == 1) {
              $ColClass = 'FirstCol';
              echo '<tr>';
          } elseif ($Col == 2) {
              $ColClass = 'MiddleCol';
          } else {
              $ColClass = 'LastCol';
              $Col = 0;
          }
          $ColClass .= $Active ? ' Enabled' : '';
          $ColClass .= $PreviewImage ? ' HasPreview' : '';
          ?>
          <td class="<?php 
Ejemplo n.º 17
0
 /**
  * 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);
     }
 }
Ejemplo n.º 18
0
 /**
  * Syncs the doc tree to the discussion list and categories (add-only).
  *
  * @param $Path string
  */
 public function ParseDocuments($Path)
 {
     // Get folder structure and sync with categories, using Documentation as parent
     $Files = SafeGlob(rtrim($Path, '/') . '/*');
     // Recurse thru the file structure
     $CodesFound = array();
     foreach ($Files as $Path) {
         if (is_dir($Path)) {
             // Sync folders to categories
             $this->ParseFolder($Path);
             $CodesFound = array_merge($CodesFound, $this->ParseDocuments($Path));
         } else {
             // Sync files to discussions
             $Code = $this->ParseFile($Path);
             if ($Code) {
                 $CodesFound[] = $Code;
             }
         }
     }
     return $CodesFound;
 }
Ejemplo n.º 19
0
 /**
  * Crawl the various addons and locales for all of the applicable translation files.
  *
  * @param string[] $applicationWhiteList An array of enabled application folders.
  * @param string[] $pluginWhiteList An array of enabled plugin folders.
  * @return array Returns an array keyed by locale names where each value is an array of translation paths for that locale.
  */
 public function crawlAllLocaleSources($applicationWhiteList, $pluginWhiteList)
 {
     $result = array();
     // Get all of the locale files for the applications.
     $this->crawlAddonLocaleSources(PATH_APPLICATIONS, $applicationWhiteList, $result);
     // Get locale-based locale definition files.
     $enabledLocales = C('EnabledLocales');
     if (is_array($enabledLocales)) {
         foreach ($enabledLocales as $localeKey => $locale) {
             $locale = self::canonicalize($locale);
             // Grab all of the files in the locale's folder.
             $translationPaths = safeGlob(PATH_ROOT . "/locales/{$localeKey}/*.php");
             foreach ($translationPaths as $translationPath) {
                 $result[$locale][] = $translationPath;
             }
         }
     }
     // Get all of the locale files for plugins.
     // Notice that the plugins are processed here so that they have overriding power.
     $this->crawlAddonLocaleSources(PATH_PLUGINS, $pluginWhiteList, $result);
     // Get theme-based locale definition files.
     $theme = C('Garden.Theme');
     if ($theme) {
         $this->crawlAddonLocaleSources(PATH_THEMES, array($theme), $result);
     }
     // Look for a global locale.
     $configLocale = PATH_CONF . '/locale.php';
     if (file_exists($configLocale)) {
         foreach (array_keys($result) as $locale) {
             $result[$locale][] = $configLocale;
         }
     }
     // Look for locale specific config locales.
     $paths = SafeGlob(PATH_CONF . '/locale-*.php');
     foreach ($paths as $path) {
         if (preg_match('`^locale-([\\w-]+)$`i', basename($path, '.php'), $matches)) {
             $locale = self::canonicalize($matches[1]);
             $result[$locale][] = $path;
         }
     }
     return $result;
 }
Ejemplo n.º 20
0
 /**
  * Includes all of the plugin files for enabled plugins.
  *
  * Files are included in from the roots of each plugin directory of they have the following names.
  * - default.php
  * - *plugin.php
  *
  * @param array $EnabledPlugins An array of plugins that should be included.
  * If this argument is null then all enabled plugins will be included.
  * @return array The plugin info array for all included plugins.
  */
 public function IncludePlugins($EnabledPlugins = NULL)
 {
     // Include all of the plugins.
     if (is_null($EnabledPlugins)) {
         $EnabledPlugins = Gdn::Config('EnabledPlugins', array());
     }
     // Get a list of files to include.
     $Paths = array();
     foreach ($EnabledPlugins as $PluginName => $PluginFolder) {
         $Paths[] = PATH_PLUGINS . DS . $PluginFolder . DS . 'default.php';
         $Paths = array_merge($Paths, SafeGlob(PATH_PLUGINS . DS . $PluginFolder . DS . '*plugin.php'));
     }
     if (!is_array($Paths)) {
         $Paths = array();
     }
     // Include all of the paths.
     $PluginInfo = array();
     foreach ($Paths as $Path) {
         if (file_exists($Path)) {
             include $Path;
         }
     }
     return $PluginInfo;
 }
Ejemplo n.º 21
0
 /**
  * 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);
     }
 }
Ejemplo n.º 22
0
 /**
  * Includes all of the plugin files for enabled plugins.
  *
  * Files are included in from the roots of each plugin directory if they have the following names.
  * - default.php
  * - *plugin.php
  *
  * @param array $EnabledPlugins An array of plugins that should be included.
  * If this argument is null then all enabled plugins will be included.
  * @return array The plugin info array for all included plugins.
  */
 public function IncludePlugins($EnabledPlugins = NULL)
 {
     // Include all of the plugins.
     if (is_null($EnabledPlugins)) {
         $EnabledPlugins = Gdn::Config('EnabledPlugins', array());
     }
     // Get a list of files to include.
     $Paths = array();
     foreach ($EnabledPlugins as $PluginName => $PluginFolder) {
         $Paths[] = PATH_PLUGINS . DS . $PluginFolder . DS . 'default.php';
         $Paths = array_merge($Paths, SafeGlob(PATH_PLUGINS . DS . $PluginFolder . DS . '*plugin.php'));
         // Make sure the plugin is in the config.
         if (!C("EnabledPlugins.{$PluginName}")) {
             SaveToConfig("EnabledPlugins.{$PluginName}", $PluginFolder, FALSE);
         }
     }
     if (!is_array($Paths)) {
         $Paths = array();
     }
     // Include all of the paths.
     $PluginInfo = array();
     $PluginManager =& $this;
     $Paths = (array) $Paths;
     foreach ($Paths as $Path) {
         if (file_exists($Path)) {
             include_once $Path;
         }
     }
     $this->EnabledPlugins = $PluginInfo;
     return $PluginInfo;
 }
Ejemplo n.º 23
0
 /**
  * Enable a locale pack without installing it to the config or mappings.
  *
  * @param string $LocaleKey The key of the folder.
  */
 public function TestLocale($LocaleKey)
 {
     $Available = $this->AvailableLocalePacks();
     if (!isset($Available[$LocaleKey])) {
         throw NotFoundException('Locale');
     }
     // Grab all of the definition files from the locale.
     $Paths = SafeGlob(PATH_ROOT . "/locales/{$LocaleKey}/*.php");
     foreach ($Paths as $Path) {
         Gdn::Locale()->Load($Path);
     }
 }
Ejemplo n.º 24
0
   </div><?php 
$this->FireEvent('BeforeEmbedRecommend');
// Has the user applied the recommended theme?
if ($this->Data('EnabledThemeName') != $RecommendedThemeName) {
    ?>
<div class="EmbedRecommend">
      <strong>We Recommend</strong>
      <?php 
    // Does the user have the recommended theme?
    foreach ($this->Data('AvailableThemes') as $Theme) {
        if (GetValue('Name', $Theme) == $RecommendedThemeName) {
            $RecommendedThemeFolder = GetValue('Folder', $Theme);
            $HasRecommendedTheme = TRUE;
        }
    }
    $PreviewImage = SafeGlob(PATH_THEMES . DS . $RecommendedThemeFolder . DS . "screenshot.*");
    $PreviewImage = count($PreviewImage) > 0 ? basename($PreviewImage[0]) : FALSE;
    if ($PreviewImage && in_array(strtolower(pathinfo($PreviewImage, PATHINFO_EXTENSION)), array('gif', 'jpg', 'png'))) {
        echo Img('/themes/' . $RecommendedThemeFolder . '/' . $PreviewImage, array('alt' => $RecommendedThemeName, 'height' => '112', 'width' => '150'));
    }
    ?>
      <em>We recommend the <?php 
    echo Wrap($RecommendedThemeName, 'b');
    ?>
 theme. <?php 
    if ($HasRecommendedTheme) {
        echo Anchor(T('Click here to apply it.'), 'plugin/embed/' . $RecommendedThemeFolder . '/' . $Session->TransientKey());
    } else {
        echo Anchor(T('Click here to get it.'), 'http://vanillaforums.org/addons');
    }
    ?>