/**
  * 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);
 }
 /**
  * Récupère le chemin du fichier template qui sera utilisé pour l'identifiant donné
  * @param string	$pTplName	L'identifiant du template à utiliser
  * @return string 	le chemin du fichier qui sera utilisé pour l'identifiant donnée
  */
 public function getFilePath($pTplName)
 {
     if (isset(self::$_tplFilePathCache[$pTplName])) {
         return self::$_tplFilePathCache[$pTplName];
     }
     //Using a selector to find out the fileName
     $fileSelector = CopixSelectorFactory::create($pTplName);
     $fileName = $fileSelector->fileName;
     $config = CopixConfig::instance();
     $toReturn = false;
     //On a donné un chemin complet direct, on retourne directement
     if ($fileSelector->type !== 'module') {
         if (file_exists($templateFilePath = $fileSelector->getPath() . $fileName)) {
             $toReturn = $templateFilePath;
         }
     } else {
         $toReturn = CopixResource::findThemeTemplate($fileSelector->fileName, $fileSelector->module, $fileSelector->getPath(), self::getTheme(), $config->i18n_path_enabled, CopixI18N::getLang(), CopixI18N::getCountry());
     }
     // Met en cache le résultat
     self::$_tplFilePathCache[$pTplName] = $toReturn;
     self::$_tplFilePathCache[$fileSelector->getSelector()] = $toReturn;
     return $toReturn;
 }
 /**
  * Calcule l'URL d'une ressource à partir de  de la capture d'une expression régulière.
  *
  * @param array $parts Résultat de la capture de l'expression régulière.
  * @return string L'URL à utiliser.
  */
 private function _replaceCopixresource($parts)
 {
     list(, , $fullPath, $modulePrefix, $forceModule, $path) = $parts;
     if (!isset($this->_urlCache[$fullPath])) {
         if (!empty($modulePrefix)) {
             if (!empty($forceModule) && isset($this->_arModules[$forceModule])) {
                 $this->_urlCache[$fullPath] = CopixResource::findResourceURL($path, $forceModule, $this->_arModules[$forceModule] . $forceModule . '/', $this->_theme, $this->_config->i18n_path_enabled, $this->_lang, $this->_country);
             } else {
                 $this->_urlCache[$fullPath] = CopixResource::findResourceURL($path, $this->_module, $this->_modulePath, $this->_theme, $this->_config->i18n_path_enabled, $this->_lang, $this->_country);
             }
         } else {
             $this->_urlCache[$fullPath] = CopixResource::findResourceURL($path, null, null, $this->_theme, $this->_config->i18n_path_enabled, $this->_lang, $this->_country);
         }
     }
     return $this->_urlCache[$fullPath];
 }
 /**
  * Demande le chargement de Mootools.
  *
  * @param array $pPlugins Liste de plugins à charger.
  */
 public static function addJSFramework($pPlugins = null)
 {
     // Charge le noyau
     if (!isset(self::$_JSFrameworkAdded['*core*'])) {
         self::$_JSFrameworkAdded['*core*'] = true;
         // Initialise Mootools et l'identifiant de session
         if (!CopixAJAX::isAJAXRequest()) {
             // Ajoute MooTools et FirebugLite
             if (CopixConfig::instance()->getMode() == CopixConfig::DEVEL) {
                 // MooTools non compressé et FirebugLite normal
                 self::addJSLink(_resource('js/firebuglite/firebug.js'), array('id' => 'firebug_js'));
                 self::addJSLink(_resource('js/mootools/mootools-devel.js'), array('id' => 'mootools_core_js'));
             } else {
                 // MooTools compressé et FirebugLite qui ne fait rien.
                 self::addJSLink(_resource('js/firebuglite/firebugx.js'), array('id' => 'firebug_js'));
                 self::addJSLink(_resource('js/mootools/mootools.js'), array('id' => 'mootools_core_js'));
             }
             // Ajoute le framework JS spécifique de Copix
             self::addJSLink(_resource('js/copix.js'), array('id' => 'copix_js', 'charset' => 'UTF-8'));
             // Ajoute le code d'initialisation
             $urlBase = CopixUrl::get();
             self::addJSCode(sprintf('Copix = new CopixClass(%s);', CopixJSON::encode(array('ajaxSessionId' => CopixAJAX::getSessionId(), 'module' => CopixContext::get(), 'urlBase' => $urlBase, 'resourceUrlBase' => CopixResource::getResourceBaseUrl($urlBase, CopixTpl::getTheme(), CopixI18N::getLang(), CopixI18N::getCountry())))), 'copixajax_init', CopixHTMLHeader::DOMREADY_ALWAYS);
         }
     }
     // Charge les plugins
     if (is_array($pPlugins)) {
         foreach ($pPlugins as $pluginName) {
             if (!isset(self::$_JSFrameworkAdded[$pluginName])) {
                 self::$_JSFrameworkAdded[$pluginName] = true;
                 $pluginId = 'mootools_plugin_' . $pluginName;
                 $scriptId = $pluginId . '_js';
                 $stylesheetId = $pluginId . '_css';
                 if (file_exists(CopixUrl::getResourcePath($path = 'js/mootools/plugins/' . $pluginName . '.js'))) {
                     self::addJSLink(_resource($path), array("id" => $scriptId));
                 } elseif (file_exists(CopixUrl::getResourcePath($path = 'js/mootools/plugins/' . $pluginName . '.js.php'))) {
                     self::addJSLink(_resource($path), array("id" => $scriptId));
                 } else {
                     throw new CopixException('[Mootools] Plugin ' . $pluginName . ' not found in ' . $pluginPath);
                 }
                 if (file_exists(CopixUrl::getResourcePath($path = 'js/mootools/css/' . $pluginName . '.css'))) {
                     self::addCssLink(_resource($path), array("id" => $stylesheetId));
                 }
             }
         }
     }
 }