Exemplo n.º 1
0
 /**
  * Prepare a cache library for use, either by loading it from file, filling it with
  * pre existing data in array form, or leaving it empty and waiting for new entries.
  * 
  * @param string $CacheName name of cache library
  * @param array $ExistingCacheArray optional array containing an initial seed cache
  * @param string $CacheMode optional mode of the cache... defaults to flat
  * @return void
  */
 public static function PrepareCache($CacheName, $ExistingCacheArray = NULL, $CacheMode = 'flat')
 {
     // Onetime initialization of in-memory file cache
     if (!is_array(self::$_Caches)) {
         self::$_Caches = array();
     }
     if ($CacheName != 'locale') {
         return;
     }
     if (!array_key_exists($CacheName, self::$_Caches)) {
         $OnDiskCacheName = sprintf(self::DISK_CACHE_NAME_FORMAT, strtolower($CacheName));
         self::$_Caches[$CacheName] = array('ondisk' => $OnDiskCacheName, 'cache' => array(), 'mode' => $CacheMode);
         // Loading cache for the first time by name+path only... import data now.
         if (file_exists(PATH_LOCAL_CACHE . DS . $OnDiskCacheName)) {
             $CacheContents = parse_ini_file(PATH_LOCAL_CACHE . DS . $OnDiskCacheName, TRUE);
             if ($CacheContents != FALSE && is_array($CacheContents)) {
                 self::Import($CacheName, $CacheContents);
             } else {
                 @unlink(PATH_LOCAL_CACHE . DS . $OnDiskCacheName);
             }
         }
     }
     // If cache data array is passed in, merge it with our existing cache
     if (is_array($ExistingCacheArray)) {
         self::Import($CacheName, $ExistingCacheArray, TRUE);
     }
 }
 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);
 }
Exemplo n.º 3
0
 /**
  * Prepare a cache library for use, either by loading it from file, filling it with
  * pre existing data in array form, or leaving it empty and waiting for new entries.
  *
  * @param string $CacheName The name of cache library.
  * @param array|null $ExistingCacheArray An optional array containing an initial seed cache.
  * @param string $CacheMode An optional mode of the cache. Defaults to flat.
  * @return void
  */
 public static function prepareCache($CacheName, $ExistingCacheArray = null, $CacheMode = 'flat')
 {
     // Onetime initialization of in-memory file cache
     if (!is_array(self::$Caches)) {
         self::$Caches = array();
     }
     if ($CacheName != 'locale') {
         return;
     }
     if (!array_key_exists($CacheName, self::$Caches)) {
         self::$Caches[$CacheName] = array('cache' => array(), 'mode' => $CacheMode);
         $UseCache = Gdn::cache()->type() == Gdn_Cache::CACHE_TYPE_MEMORY && Gdn::cache()->activeEnabled();
         if ($UseCache) {
             $CacheKey = sprintf(Gdn_LibraryMap::CACHE_CACHE_NAME_FORMAT, $CacheName);
             $CacheContents = Gdn::cache()->get($CacheKey);
             $LoadedFromCache = $CacheContents !== Gdn_Cache::CACHEOP_FAILURE;
             if ($LoadedFromCache && is_array($CacheContents)) {
                 self::import($CacheName, $CacheContents);
             }
         } else {
             $OnDiskCacheName = sprintf(self::DISK_CACHE_NAME_FORMAT, strtolower($CacheName));
             self::$Caches[$CacheName]['ondisk'] = $OnDiskCacheName;
             // Loading cache for the first time by name+path only... import data now.
             if (file_exists(PATH_CACHE . DS . $OnDiskCacheName)) {
                 $CacheContents = parse_ini_file(PATH_CACHE . DS . $OnDiskCacheName, true);
                 if ($CacheContents != false && is_array($CacheContents)) {
                     self::import($CacheName, $CacheContents);
                 } else {
                     @unlink(PATH_CACHE . DS . $OnDiskCacheName);
                 }
             }
         }
     }
     // If cache data array is passed in, merge it with our existing cache
     if (is_array($ExistingCacheArray)) {
         self::import($CacheName, $ExistingCacheArray, true);
     }
 }
 /**
  * Manage list of plugins.
  *
  * @since 2.0.0
  * @access public
  * @param string $Filter 'enabled', 'disabled', or 'all' (default)
  * @param string $PluginName Unique ID of plugin to be modified.
  * @param string $TransientKey Security token.
  */
 public function Plugins($Filter = '', $PluginName = '', $TransientKey = '')
 {
     $this->Permission('Garden.Settings.Manage');
     // Page setup
     $this->AddJsFile('addons.js');
     $this->Title(T('Plugins'));
     $this->AddSideMenu('dashboard/settings/plugins');
     // Validate and set properties
     $Session = Gdn::Session();
     $PluginName = $Session->ValidateTransientKey($TransientKey) ? $PluginName : '';
     if (!in_array($Filter, array('enabled', 'disabled'))) {
         $Filter = 'all';
     }
     $this->Filter = $Filter;
     // Retrieve all available plugins from the plugins directory
     $this->EnabledPlugins = Gdn::PluginManager()->EnabledPlugins();
     self::SortAddons($this->EnabledPlugins);
     $this->AvailablePlugins = Gdn::PluginManager()->AvailablePlugins();
     self::SortAddons($this->AvailablePlugins);
     // Loop through all of the available plugins and mark them if they have an update available
     // Retrieve the list of plugins that require updates from the config file
     $RequiredUpdates = Gdn_Format::Unserialize(Gdn::Config('Garden.RequiredUpdates', ''));
     if (is_array($RequiredUpdates)) {
         foreach ($RequiredUpdates as $UpdateInfo) {
             if (is_object($UpdateInfo)) {
                 $UpdateInfo = Gdn_Format::ObjectAsArray($UpdateInfo);
             }
             $NewVersion = ArrayValue('Version', $UpdateInfo, '');
             $Name = ArrayValue('Name', $UpdateInfo, '');
             $Type = ArrayValue('Type', $UpdateInfo, '');
             foreach ($this->AvailablePlugins as $Plugin => $Info) {
                 $CurrentName = ArrayValue('Name', $Info, $Plugin);
                 if ($CurrentName == $Name && $Type == 'Plugin') {
                     $Info['NewVersion'] = $NewVersion;
                     $this->AvailablePlugins[$Plugin] = $Info;
                 }
             }
         }
     }
     if ($PluginName != '') {
         try {
             $this->EventArguments['PluginName'] = $PluginName;
             if (array_key_exists($PluginName, $this->EnabledPlugins) === TRUE) {
                 Gdn::PluginManager()->DisablePlugin($PluginName);
                 Gdn_LibraryMap::ClearCache();
                 $this->FireEvent('AfterDisablePlugin');
             } else {
                 $Validation = new Gdn_Validation();
                 if (!Gdn::PluginManager()->EnablePlugin($PluginName, $Validation)) {
                     $this->Form->SetValidationResults($Validation->Results());
                 } else {
                     Gdn_LibraryMap::ClearCache();
                 }
                 $this->EventArguments['Validation'] = $Validation;
                 $this->FireEvent('AfterEnablePlugin');
             }
         } catch (Exception $e) {
             $this->Form->AddError($e);
         }
         if ($this->Form->ErrorCount() == 0) {
             Redirect('/settings/plugins/' . $this->Filter);
         }
     }
     $this->Render();
 }
Exemplo n.º 5
0
 /**
  * Gets the locale sources for a given locale.
  *
  * @param string $locale The name of the locale.
  * @param string[] $applicationWhiteList An array of enabled application folders.
  * @param string[] $pluginWhiteList An array of enabled plugin folders.
  * @param bool $forceRemapping Whether or not to force a rebuild of the cache.
  * @return array Returns an array of paths to the translations for the locale.
  */
 public function getLocaleSources($locale, $applicationWhiteList, $pluginWhiteList, $forceRemapping = false)
 {
     $safeLocale = static::canonicalize($locale);
     // First try and grab the locale sources from the cache.
     Gdn_LibraryMap::prepareCache('locale', null, 'tree');
     $allLocaleSources = Gdn_LibraryMap::getCache('locale');
     if ($forceRemapping || !Gdn_LibraryMap::cacheReady('locale') || $allLocaleSources === null) {
         // Build the entire locale sources array and cache it.
         $allLocaleSources = $this->crawlAllLocaleSources($applicationWhiteList, $pluginWhiteList);
         Gdn_LibraryMap::prepareCache('locale', $allLocaleSources);
     }
     $localeSources = val($safeLocale, $allLocaleSources, array());
     return $localeSources;
 }
 /**
  * Manage list of plugins.
  *
  * @since 2.0.0
  * @access public
  * @param string $Filter 'enabled', 'disabled', or 'all' (default)
  * @param string $PluginName Unique ID of plugin to be modified.
  * @param string $TransientKey Security token.
  */
 public function plugins($Filter = '', $PluginName = '', $TransientKey = '')
 {
     $this->permission('Garden.Settings.Manage');
     // Page setup
     $this->addJsFile('addons.js');
     $this->title(t('Plugins'));
     $this->addSideMenu('dashboard/settings/plugins');
     // Validate and set properties
     $Session = Gdn::session();
     if ($PluginName && !$Session->validateTransientKey($TransientKey)) {
         $PluginName = '';
     }
     if (!in_array($Filter, array('enabled', 'disabled'))) {
         $Filter = 'all';
     }
     $this->Filter = $Filter;
     // Retrieve all available plugins from the plugins directory
     $this->EnabledPlugins = Gdn::pluginManager()->enabledPlugins();
     self::sortAddons($this->EnabledPlugins);
     $this->AvailablePlugins = Gdn::pluginManager()->availablePlugins();
     self::sortAddons($this->AvailablePlugins);
     if ($PluginName != '') {
         try {
             $this->EventArguments['PluginName'] = $PluginName;
             if (array_key_exists($PluginName, $this->EnabledPlugins) === true) {
                 Gdn::pluginManager()->disablePlugin($PluginName);
                 Gdn_LibraryMap::clearCache();
                 $this->fireEvent('AfterDisablePlugin');
             } else {
                 $Validation = new Gdn_Validation();
                 if (!Gdn::pluginManager()->enablePlugin($PluginName, $Validation)) {
                     $this->Form->setValidationResults($Validation->results());
                 } else {
                     Gdn_LibraryMap::ClearCache();
                 }
                 $this->EventArguments['Validation'] = $Validation;
                 $this->fireEvent('AfterEnablePlugin');
             }
         } catch (Exception $e) {
             $this->Form->addError($e);
         }
         if ($this->Form->errorCount() == 0) {
             redirect('/settings/plugins/' . $this->Filter);
         }
     }
     $this->render();
 }
Exemplo n.º 7
0
 /**
  * Recursively convert the provided array to a string, suitable for storage on disk
  *
  * @param string $RootCacheKey if not null, the name of the key fr this iteration
  * @param array $Cache cache data
  * @param ref $CacheStr reference to the destination string
  * @param int $FormatIndentLevel depth of indentation for pretty data files
  * @return string innards of cache data array
  */
 public static function RecurseArrayStr($RootCacheKey, $Cache, &$CacheStr, $FormatIndentLevel = 0)
 {
     if ($RootCacheKey !== NULL) {
         $CacheStr .= str_repeat('   ', $FormatIndentLevel) . "'{$RootCacheKey}'   => ";
     }
     if (is_array($Cache)) {
         $CacheStr .= "array(\n";
     }
     $First = TRUE;
     foreach ($Cache as $CacheKey => $CacheValue) {
         if (!$First) {
             $CacheStr .= ",\n";
         }
         if ($First) {
             $First = FALSE;
         }
         if (!is_array($CacheValue)) {
             $CacheStr .= str_repeat('   ', $FormatIndentLevel + 1);
             if (!is_numeric($CacheKey)) {
                 $CacheStr .= "'{$CacheKey}' => ";
             }
             $CacheStr .= "'{$CacheValue}'";
         } else {
             Gdn_LibraryMap::RecurseArrayStr($CacheKey, $CacheValue, $CacheStr, $FormatIndentLevel + 1);
         }
     }
     if (is_array($Cache)) {
         $CacheStr .= "\n" . str_repeat('   ', $FormatIndentLevel) . ")";
     }
 }
Exemplo n.º 8
0
 /**
  * Searches in the specified mapping cache for $LibraryName. If a mapping is
  * found, it returns it. If not, it searches through the application
  * directories $Depth levels deep looking for $LibraryName. Returns FALSE
  * if not found.
  *
  * @param string $MappingsFileName The name of the mappings file to look in for library mappings. These
  * files are contained in the application's /cache folder.
  * @param string $SourceFolders The path to the folders that should be considered the "root" of this search.
  * @param mixed $FolderWhiteList A white-list array of sub-folders within $SourceFolder in which the
  * search can be performed. If FALSE is specified instead, the search will
  * only be performed in $SourceFolders.
  * @param string $LibraryName The name of the library to search for. This is a valid file name.
  * ie. "class.database.php"
  */
 public static function findByMapping($MappingCacheName, $SourceFolders, $FolderWhiteList, $LibraryName)
 {
     // If the application folder was provided, it will be the only entry in the whitelist, so prepend it.
     if (is_array($FolderWhiteList) && count($FolderWhiteList) == 1) {
         $LibraryName = combinePaths(array($FolderWhiteList[0], $LibraryName));
     }
     $LibraryKey = str_replace('.', '__', $LibraryName);
     Gdn_LibraryMap::prepareCache($MappingCacheName);
     $LibraryPath = Gdn_LibraryMap::getCache($MappingCacheName, $LibraryKey);
     if ($LibraryPath === null) {
         // $LibraryName wasn't contained in the mappings array.
         // I need to look through the folders in this application for the requested file.
         // Once I find it, I need to save the mapping so we don't have to search for it again.
         // Attempt to find the file directly off the root (if the app folder was provided in the querystring)
         /*if ($FolderWhiteList !== FALSE && count($FolderWhiteList) == 1) {
              $LibraryPath = self::Find($SourceFolders, $LibraryName);
           } else {
              $LibraryPath = self::Find($SourceFolders, $LibraryName, $FolderWhiteList);
           }*/
         $LibraryPath = self::find($SourceFolders, $LibraryName, $FolderWhiteList);
         // If the mapping was found
         if ($LibraryPath !== false) {
             Gdn_LibraryMap::cache($MappingCacheName, $LibraryKey, $LibraryPath);
         }
     }
     return $LibraryPath;
 }
Exemplo n.º 9
0
 public function enablePlugin($pluginName, $filter = 'all')
 {
     if (!Gdn::request()->isAuthenticatedPostBack(true)) {
         throw new Exception('Requires POST', 405);
     }
     $this->permission('Garden.Settings.Manage');
     $action = 'none';
     if ($filter == 'disabled') {
         $action = 'SlideUp';
     }
     $addon = Gdn::addonManager()->lookupAddon($pluginName);
     try {
         $validation = new Gdn_Validation();
         if (!Gdn::pluginManager()->enablePlugin($pluginName, $validation)) {
             $this->Form->setValidationResults($validation->results());
         } else {
             Gdn_LibraryMap::ClearCache();
             $this->informMessage(sprintf(t('%s Enabled.'), val('name', $addon->getInfo(), t('Plugin'))));
         }
         $this->EventArguments['PluginName'] = $pluginName;
         $this->EventArguments['Validation'] = $validation;
         $this->fireEvent('AfterEnablePlugin');
     } catch (Exception $e) {
         $this->Form->addError($e);
     }
     $this->handleAddonToggle($pluginName, $addon->getInfo(), 'plugins', true, $filter, $action);
 }
Exemplo 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;
 }
Exemplo n.º 11
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');
     if ($ForceRemapping === TRUE || !Gdn_LibraryMap::CacheReady('locale')) {
         $LocaleSources = array();
         // Get application-based locale definition files
         $ApplicationLocaleSources = Gdn_FileSystem::FindAll(PATH_APPLICATIONS, CombinePaths(array('locale', $LocaleName, 'definitions.php')), $ApplicationWhiteList);
         if ($ApplicationLocaleSources !== FALSE) {
             $LocaleSources = $ApplicationLocaleSources;
         }
         // Get plugin-based locale definition files
         $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]);
         }
         // Add the config locale if it exists
         $ConfigLocale = PATH_CONF . DS . 'locale.php';
         if (file_exists($ConfigLocale)) {
             $FileContents[$SafeLocaleName][] = $ConfigLocale;
         }
         Gdn_LibraryMap::Import('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_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_once $LocaleSources[$i];
         }
     }
     // Also load any custom defined definitions from the conf directory
     if (file_exists($ConfLocaleOverride)) {
         include_once $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;
 }
   'Description' => 'This plugin enables SingleSignOn (SSO) between your forum and other authorized consumers on the same domain, via cookie sharing.',
   'Version' => '1.9.7',
   'MobileFriendly' => TRUE,
   'RequiredApplications' => array('Vanilla' => '2.0.17.9'),
   'RequiredTheme' => FALSE, 
   'RequiredPlugins' => FALSE,
   'SettingsUrl' => '/dashboard/authentication/proxy',
   'SettingsPermission' => 'Garden.Settings.Manage',
   'HasLocale' => TRUE,
   'RegisterPermissions' => FALSE,
   'Author' => "Tim Gunter",
   'AuthorEmail' => '*****@*****.**',
   'AuthorUrl' => 'http://www.vanillaforums.com'
);

Gdn_LibraryMap::SafeCache('library','class.proxyauthenticator.php',dirname(__FILE__).DS.'class.proxyauthenticator.php');
class ProxyConnectPlugin extends Gdn_Plugin {
   
   public function __construct() {
      parent::__construct();
      
      // 2.0.18+
      // Ensure that when ProxyConnect is turned on, we always have its SearchPath indexed
      try {
         $ProxyConnectSearchPathName = 'ProxyConnect RIMs';
         $CustomSearchPaths = Gdn::PluginManager()->SearchPaths(TRUE);

         if (!in_array($ProxyConnectSearchPathName, $CustomSearchPaths)) {
            $InternalPluginFolder = $this->GetResource('internal');
            Gdn::PluginManager()->AddSearchPath($InternalPluginFolder, 'ProxyConnect RIMs');
         }
 public function EnablePlugin($PluginName, $Validation, $Setup = FALSE, $EnabledPluginValueIndex = 'Folder')
 {
     // Check that the plugin is in AvailablePlugins...
     $Plugin = $this->GetPluginInfo($PluginName, self::ACCESS_PLUGINNAME);
     // If not, we're dealing with a special case. Enabling with a classname...
     if (!$Plugin) {
         $ClassName = $PluginName;
         $PluginFile = Gdn_LibraryMap::GetCache('plugin', $ClassName);
         if ($PluginFile) {
             $Plugin = $this->PluginAvailable($PluginFile);
             $PluginName = $Plugin['Index'];
         }
     }
     // Couldn't load the plugin info.
     if (!$Plugin) {
         return;
     }
     $PluginName = $Plugin['Index'];
     $this->TestPlugin($PluginName, $Validation, $Setup);
     if (is_object($Validation) && count($Validation->Results()) > 0) {
         return FALSE;
     }
     // If everything succeeded, add the plugin to the $EnabledPlugins array in conf/config.php
     // $EnabledPlugins['PluginClassName'] = 'Plugin Folder Name';
     // $PluginInfo = ArrayValue($PluginName, $this->AvailablePlugins(), FALSE);
     $PluginInfo = $this->GetPluginInfo($PluginName);
     $PluginFolder = ArrayValue('Folder', $PluginInfo);
     $PluginEnabledValue = ArrayValue($EnabledPluginValueIndex, $PluginInfo, $PluginFolder);
     SaveToConfig('EnabledPlugins.' . $PluginName, $PluginEnabledValue);
     $this->EnabledPlugins[$PluginName] = $PluginInfo;
     $this->RegisterPlugin($PluginInfo['ClassName'], $PluginInfo);
     $ApplicationManager = new Gdn_ApplicationManager();
     $Locale = Gdn::Locale();
     $Locale->Set($Locale->Current(), $ApplicationManager->EnabledApplicationFolders(), $this->EnabledPluginFolders(), TRUE);
     return TRUE;
 }
Exemplo n.º 14
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;
   }
Exemplo n.º 15
0
 /**
  * This method is deprecated, but since cache files call it there will be low-level crashes without it.
  */
 public static function PrepareCache($CacheName, $ExistingCacheArray = NULL)
 {
     Gdn_LibraryMap::PrepareCache($CacheName, $ExistingCacheArray);
 }
Exemplo n.º 16
0
 /**
  * This method is deprecated, but since cache files call it there will be low-level crashes without it.
  */
 public static function prepareCache($CacheName, $ExistingCacheArray = null)
 {
     Gdn_LibraryMap::prepareCache($CacheName, $ExistingCacheArray);
 }