/** * 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 an waiting for new entries. * * @param string $CacheName name of cache library * @param array $ExistingCacheArray optional array containing an initial seed cache * @return void */ public static function PrepareCache($CacheName, $ExistingCacheArray = NULL) { // Onetime initialization of in-memory file cache if (!is_array(Gdn_LibraryMap::$_Caches)) { Gdn_LibraryMap::$_Caches = array(); } if (!array_key_exists($CacheName, Gdn_LibraryMap::$_Caches)) { $OnDiskCacheName = sprintf(Gdn_LibraryMap::DISK_CACHE_NAME_FORMAT, strtolower($CacheName)); Gdn_LibraryMap::$_Caches[$CacheName] = array('ondisk' => $OnDiskCacheName, 'cache' => array()); // Loading cache for the first time by name+path only... import data now. if (file_exists(PATH_CACHE . DS . $OnDiskCacheName)) { require_once PATH_CACHE . DS . $OnDiskCacheName; } } // If cache data array is passed in, merge it with our existing cache if (is_array($ExistingCacheArray)) { Gdn_LibraryMap::Import($CacheName, $ExistingCacheArray); } }
/** * 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; }