/** * Récupère un chemin de ressource (situé dans www) * * Ira chercher dans l'ordre de priorité dans * ./nom_theme/lang_COUNTRY/$path * ./nom_theme/lang/$path * ./nom_theme/$path * ./default/lang_COUNTRY/$path * ./default/lang/$path * ./default/$path * ./$path * * <code> * //on souhaites récupérer la feuille de style * $path = CopixURL::getRessourcePath ('styles/copix.css'); * //$path == /var/www/themes/nom_du_theme/styles/copix.css si le fichier existe * </code> * * @param string $resourcePath le chemin du fichier que l'on souhaites récupérer * www/$ressourcePath (doit représenter un fichier) * @return string le $ressourcePath complet en fonction des thèmes */ public static function getResourcePath($pResourcePath) { static $calculated = array(); $theme = CopixTpl::getTheme(); $i18n = CopixConfig::instance()->i18n_path_enabled; $lang = CopixI18N::getLang(); $country = CopixI18N::getCountry(); $key = $theme . $i18n . $lang . $country . $pResourcePath; if (isset($calculated[$key])) { return $calculated[$key]; } list($resourcePath, $moduleName, $modulePath) = self::_parseResourcePath($pResourcePath); // Utilise CopixResource pour trouver la ressource return $calculated[$key] = CopixResource::findResourcePath($resourcePath, $moduleName, $modulePath, $theme, $i18n, $lang, $country); }
/** * Recupère la ressource * * @throws CopixResourceForbiddenException si l'accès à la ressource est interdit, * CopixResourceNotFoundException si la ressource n'a pas été trouvée. */ public function fetch() { // Vérifie qu'on ait pas de "backward" $unescapedPath = utf8_decode($this->_path); // Pas de blague avec l'UTF8 if (preg_match('@\\.\\.[/\\\\]@', $unescapedPath)) { throw new CopixResourceForbiddenException($this->_path); } // Vérifie l'existence du theme if (!$this->_theme || !is_dir('themes/' . $this->_theme)) { throw new CopixResourceNotFoundException($this->_theme); } $arModules = $this->_getArModules(); // Si on a bien un module if ($this->_module) { // Vérifie l'existence du module if (isset($arModules[$this->_module])) { $this->_modulePath = $arModules[$this->_module] . $this->_module . '/'; } else { throw new CopixResourceNotFoundException($this->_module); } // Vérifie l'existence du chemin 'www' du module if (!is_dir($this->_modulePath . "www")) { throw new CopixResourceNotFoundException($this->_module); } } // Récupère la config $config = $this->_getCopixConfig(); // Recherche le fichier if (!($filePath = CopixResource::findResourcePath($this->_path, $this->_module, $this->_modulePath, $this->_theme, $config->i18n_path_enabled, $this->_lang, $this->_country))) { throw new CopixResourceNotFoundException($this->_path); } // Récupère le type MIME $mimeType = CopixMIMETypes::getFromFileName($filePath); // La substitution ne touche que les fichiers des modules if ($this->_modulePath && substr($filePath, 0, strlen($this->_modulePath)) == $this->_modulePath) { $filePath = $this->_processModuleFile($filePath, $mimeType); } // Mode DEBUG ? if (isset($_REQUEST['DEBUG'])) { _dump(array('this' => $this, 'filePath' => $filePath, 'mimeType' => $mimeType, 'included_files' => get_included_files())); exit; } // Envoie le fichier $this->_sendFile($filePath, $mimeType); }