/** * get all css files added for the theme * this process compile - merge css files base if theme configuration enable compression */ public function getCssLinks() { $config = $this->config->get('themecontrol'); $compress = $config['enable_compress_css']; /** ENABLE DEVELOPMENT MODE s**/ if (isset($config['enable_development_mode']) && $config['enable_development_mode']) { $compress = false; } /** ENABLE COMPRESSION MODE **/ if (trim($compress) && $this->_themeDir && is_dir($this->_themeDir)) { $excludes = explode(",", $config['exclude_css_files']); $output = array(); require_once $this->_themeDir . '/development/libs/cache.php'; require_once $this->_themeDir . '/development/libs/csscompressor.php'; $pcache = new PavCache(); $pcache->setExtension('css'); if ($compress == 'compress-merge') { $siteURL = HTTP_SERVER; $all = ''; $aKey = md5(serialize($this->_cssFiles) . serialize($excludes)); if (!$pcache->isExisted($aKey)) { foreach ($this->_cssFiles as $key => $file) { $css = preg_match("#^http#", $file['href']) ? $file['href'] : $siteURL . $file['href']; $t = explode("/", $css); $content = file_get_contents($css); if (!in_array($t[count($t) - 1], $excludes)) { if (!empty($content)) { $content = PavoCompressHelper::process($content, $css); } } $all .= $content; } $pcache->set($aKey, $all); } $_cssFiles = array(); if ($excludes) { foreach ($this->_cssFiles as $key => $file) { $css = $file['href']; $t = explode("/", $css); if (in_array($t[count($t) - 1], $excludes)) { $_cssFiles[$key] = $file; } } } $_cssFiles[$aKey] = array('rel' => 'stylesheet', 'href' => PAV_SUB_PATH . $aKey . ".css", 'media' => ''); $this->_cssFiles = $_cssFiles; $output = $this->_cssFiles; } else { $siteURL = HTTP_SERVER; foreach ($this->_cssFiles as $key => $file) { $css = preg_match("#^http#", $file['href']) ? $file['href'] : $siteURL . $file['href']; $t = explode("/", $css); if (!in_array($t[count($t) - 1], $excludes)) { $content = file_get_contents($css); if (!empty($content)) { if (!$pcache->isExisted(md5($key))) { $content = PavoCompressHelper::process($content, $css); $pcache->set(md5($key), $content); } $this->_cssFiles[$key]['href'] = PAV_SUB_PATH . md5($key) . ".css"; } else { unset($this->_cssFiles[$key]); } } } $output = $this->_cssFiles; } return $output; } return $this->_cssFiles; }
/** * read including less file and compiles those files in target folder. */ protected function _rcomplie($file, $lessDir, $lessTarget) { $less = new lessc(); $content = file_get_contents($file); $content = preg_replace('!/\\*[^*]*\\*+([^/][^*]*\\*+)*/!', '', $content); preg_match_all('#^\\s*@import\\s+"([^"]*)"#im', $content, $matches); if (isset($matches[1]) && ($lessFiles = $matches[1])) { $mixs = ''; $vars = ''; $lastTime = ''; foreach ($lessFiles as $lessFile) { if (preg_match("#mixins#", $lessFile)) { $content = file_get_contents($lessDir . $lessFile); $mixs .= $content; } if (preg_match("#vars#", $lessFile)) { $content = file_get_contents($lessDir . $lessFile); $vars .= $content; } } $mixvars = $mixs . "\r\n" . $vars; foreach ($lessFiles as $lessFile) { if (preg_match("#mixins#", $lessFile)) { continue; } if (!preg_match("#vars#", $lessFile) && file_exists($lessDir . $lessFile)) { $content = file_get_contents($lessDir . $lessFile); $cssURL = $this->themeURL . str_replace($this->_lessAppFolder . '/', '', str_replace('\\', '/', $lessFile)); $lessFile = str_replace("../", "", $lessFile); $expfile = str_replace('/', '-', $lessFile); $expfile = str_replace(".less", "-less.css", $expfile); $isChange = true; /* check this file have any changes based on file time */ if ($this->hasChange($lessDir . $lessFile, $lessTarget . $expfile)) { $out = $less->compile($mixvars . "\r\n" . $content); $out = PavoCompressHelper::replaceURL($out, $cssURL); $aa = file_put_contents($lessTarget . $expfile, $out); } $this->addCss($this->_lessDevURL . $expfile . '?r=' . rand(1, 9)); } } /* end foreach */ } }