fileName = $pathInfo['basename']; $file->filePath = $this->_getAbsFileUrl($pathInfo['dirname']); $file->fileExtension = strtolower($pathInfo['extension']); $file->cdnPath = $cdnPath; $availableExtension = array('css', 'js'); if (!in_array($file->fileExtension, $availableExtension)) return; $file->targetIe = $args[2]; $file->index = (int)$args[3]; if ($file->fileExtension == 'css') { $file->media = $args[1]; $map = &$this->cssMap; $mapIndex = &$this->cssMapIndex; $key = $file->filePath . $file->fileName . "\t" . $file->targetIe . "\t" . $file->media; } else if ($file->fileExtension == 'js') { $type = $args[1]; if ($type == 'body') { $map = &$this->jsBodyMap; $mapIndex = &$this->jsBodyMapIndex; } else { $map = &$this->jsHeadMap; $mapIndex = &$this->jsHeadMapIndex; } $key = $file->filePath . $file->fileName . "\t" . $file->targetIe; } if (!isset($map[$key]) || $map[$key]->index > $file->index) { $file->index = ((int)$file->index + count($map)); $map[$key] = $file; $mapIndex[$key] = $file->index; } } function unloadFile($fileName, $targetIe = '', $media = 'all') { $pathInfo = pathinfo($fileName); $fileName = $pathInfo['basename']; $filePath = $this->_getAbsFileUrl($pathInfo['dirname']); $fileExtension = strtolower($pathInfo['extension']); $key = $filePath . $fileName . "\t" . $targetIe; if ($fileExtension == 'css') { $key .= "\t" . $media; unset($this->cssMap[$key]); unset($this->cssMapIndex[$key]); } else { unset($this->jsHeadMap[$key]); unset($this->jsBodyMap[$key]); unset($this->jsHeadMapIndex[$key]); unset($this->jsBodyMapIndex[$key]); } } function unloadAllFiles($type = 'all') { if ($type == 'css' || $type == 'all') { $cssMap = array(); $cssMapIndex = array(); } if ($type == 'js' || $type == 'all') { $jsHeadMap = array(); $jsBodyMap = array(); $jsHeadMapIndex = array(); $jsBodyMapIndex = array(); } } function getCssFileList() { $map = &$this->cssMap; $mapIndex = &$this->cssMapIndex; $this->_sortMap($map, $mapIndex); $dbInfo = Context::get('db_info'); $useCdn = $dbInfo->use_cdn; $result = array(); foreach($map as $file) { if ($useCdn == 'Y' && $file->cdnPath) { $fullFilePath = __XE_CDN__ . $file->cdnPath . '/' . $file->fileName; } else { $fullFilePath = $file->filePath . '/' . $file->fileName; } $result[] = array('file' => $fullFilePath, 'media' => $file->media, 'targetie' => $file->targetIe); } return $result; } function getJsFileList($type = 'head') { if ($type == 'head') { $map = &$this->jsHeadMap; $mapIndex = &$this->jsHeadMapIndex; } else { $map = &$this->jsBodyMap; $mapIndex = &$this->jsBodyMapIndex; } $this->_sortMap($map, $mapIndex); $dbInfo = Context::get('db_info'); $useCdn = $dbInfo->use_cdn; $result = array(); foreach($map as $file) { if ($useCdn == 'Y' && $file->cdnPath) { $fullFilePath = __XE_CDN__ . $file->cdnPath . '/' . $file->fileName; } else { $fullFilePath = $file->filePath . '/' . $file->fileName; } $result[] = array('file' => $fullFilePath, 'targetie' => $file->targetIe); } return $result; } function _sortMap(&$map, &$index) { asort($index); $sortedMap = array(); foreach($index as $key => $val) { $sortedMap[$key] = $map[$key]; } $map = $sortedMap; } function _normalizeFilePath($path) { if (strpos($path, '://') === false && $path{0} != '/' && $path{0} != '.') { $path = './' . $path; } $path = preg_replace('@/\./|(?_normalizeFilePath($path); if(strpos($path, './') === 0) { $path = dirname($_SERVER['SCRIPT_NAME']) . '/' . substr($path, 2); } else if(strpos($file, '../') === 0) { $file = $this->_normalizeFilePath(dirname($_SERVER['SCRIPT_NAME']) . "/{$path}"); } return $path; } }