function dir_to_nav_links($dir) { global $URL_BASE; $dirs = preg_replace("/\\/\\//", "/", $dir); $dirs = preg_replace("/\\/\$/", "", $dirs); $dirs = preg_split("/\\//", $dirs); if ($dirs == false) { return "<a href=\"{$URL_BASE}/\">Home</a>"; } $link = "{$URL_BASE}/?Dir=/"; $ret = "<a href=\"{$link}\">" . HOME_PAGE_NAME . "</a>"; foreach ($dirs as $dir) { $link = $link . encode_filename("{$dir}"); if ($dir == "") { continue; } else { $link = $link . "/"; } $ret = $ret . " / <a href=\"" . $link . "\">" . $dir . "</a>"; } return $ret; }
function minify($type, $files, $excludes) { if (!in_array($type, array('css', 'js'))) { return $files; } //extract local fylesystem path clean_file_paths($files, $excludes); global $registry; $oc_root = dirname(DIR_APPLICATION); $cache = NULL; $cachefile = NULL; $filename = NULL; if (!defined('DS')) { define('DS', DIRECTORY_SEPARATOR); } if (!file_exists($oc_root . DS . 'assets')) { mkdir($oc_root . DS . 'assets'); } if (!file_exists($oc_root . DS . 'assets' . DS . $type)) { mkdir($oc_root . DS . 'assets' . DS . $type); } $cachefile = $oc_root . DS . 'assets' . DS . $type . DS . getSSLCachePrefix() . $type . '.cache'; if (!file_exists($cachefile)) { touch($cachefile); file_put_contents($cachefile, json_encode(array())); } $cache = json_decode(file_get_contents($cachefile), true); switch ($type) { case 'js': include_once NITRO_LIB_FOLDER . 'minifier' . DS . 'JSShrink.php'; break; case 'css': if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == '1')) { $webshopUrl = $registry->get('config')->get('config_ssl'); } else { $webshopUrl = $registry->get('config')->get('config_url'); } $webshopUrl = rtrim(preg_replace('~^https?\\:~i', '', $webshopUrl), '/'); include_once NITRO_LIB_FOLDER . 'minifier' . DS . 'CSSMin.php'; break; } foreach ($files as $hash => $file) { $recache = false; if (!is_excluded_file($file, $excludes)) { $filename = $oc_root . DS . trim(str_replace('/', DS, $file), DS); $basefilename = basename($file, '.' . $type); $target = '/assets/' . $type . '/' . getSSLCachePrefix() . 'nitro-mini-' . encode_filename($filename) . '.' . $type; $targetAbsolutePath = $oc_root . DS . trim(str_replace('/', DS, $target), DS); if (!empty($cache[$filename])) { if (!is_url($file) && $cache[$filename] != filemtime($filename)) { $recache = true; } } else { $recache = true; } if ($recache || !file_exists($targetAbsolutePath)) { touch($targetAbsolutePath); $content = is_url($file) ? fetchRemoteContent($file) : file_get_contents($filename); switch ($type) { case 'js': $content = Minifier::minify($content, array('flaggedComments' => false)); break; case 'css': $urlToCurrentDir = is_url($file) ? dirname($file) : $webshopUrl . dirname('/' . trim($file, '/')); $content = preg_replace('/(url\\()(?![\'\\"]?(?:(?:https?\\:\\/\\/)|(?:data\\:)|(?:\\/)))([\'\\"]?)\\/?(?!\\/)/', '$1$2' . $urlToCurrentDir . '/', $content); $content = Nitro_Minify_CSS_Compressor::process($content); break; } file_put_contents($targetAbsolutePath, $content); $cache[$filename] = is_url($file) ? time() : filemtime($filename); } $files[$hash] = trim($target, '/'); } } file_put_contents($cachefile, json_encode($cache)); return $files; }