/** * Check if request came from IE < 10 and too large CSS (> 4095 selectors). * Split if necessary. * * @param \stdClass $item data item * @param array $details Theme item details * * @return string */ protected function splitCssForIe(\stdClass $item, $details) { $file = $details['path']; // Return right away if the file doesn't exist or is too small to // be a problem, hopefully if (!file_exists($file) || filesize($file) < 65535) { return ''; } $agent = $this->request->getHeader('User-Agent')->toString(); if (strstr($agent, 'MSIE 9.0') || strstr($agent, 'MSIE 8.0') || strstr($agent, 'MSIE 7.0')) { $theme = $details['theme']; $basename = basename($file); $fileTime = filemtime($file); $cache = $this->cacheManager->getCache('stylesheet')->getOptions()->getCacheDir(); if (!file_exists("{$cache}/{$theme}/{$basename}_part1.css") || filemtime("{$cache}/{$theme}/{$basename}_part1.css") < $fileTime) { // Populate cache if (!is_dir("{$cache}/{$theme}")) { mkdir("{$cache}/{$theme}"); } $handle = $this->acquireLock("{$cache}/{$theme}/.lockfile"); array_map('unlink', glob("{$cache}/{$theme}/{$basename}_*") ?: []); $css = file_get_contents($file); $splitter = new \CssSplitter\Splitter($css); $selectorCount = $splitter->countSelectors(); $partCount = ceil($selectorCount / 4095); for ($part = 1; $part <= $partCount; $part++) { file_put_contents("{$cache}/{$theme}/{$basename}_part{$part}.css", $splitter->split(null, $part)); } $this->releaseLock($handle); } $result = []; $urlHelper = $this->getView()->plugin('url'); $files = glob("{$cache}/{$theme}/{$basename}_part*"); foreach ($files as $css) { $url = $urlHelper('home') . "themes/{$theme}/css/" . basename($css); $url .= strstr($url, '?') ? '&_=' : '?_='; $url .= filemtime($css); $item->href = $url; $result[] = parent::itemToString($item); } return implode("\n", $result); } return ''; }
public function getUserCss() { $arrReturn = $this->arrReturn; $strCss = $this->objUserCssFile->getContent(); if ($this->rewrite || $this->rewriteBootstrap) { try { $this->objLess->SetImportDirs($this->arrLessImportDirs); $strCss = $this->objLess->getCss(); $this->objUserCssFile->write($strCss); } catch (\Exception $e) { echo '<pre>'; echo $e->getMessage(); echo '</pre>'; } } $splitter = new \CssSplitter\Splitter(); $count = $splitter->countSelectors($strCss); // IE 6 - 9 has a limit of 4096 selectors if ($count > 0) { $parts = ceil($count / 4095); for ($i = 1; $i <= $parts; $i++) { $objFile = new \File("assets/css/{$this->title}-part-{$i}.css"); $objFile->write($splitter->split($strCss, $i)); $objFile->close(); $arrReturn[self::$userCssKey][] = array('src' => $objFile->value, 'type' => 'all', 'mode' => '', 'hash' => version_compare(VERSION, '3.4', '>=') ? $this->objUserCssFile->mtime : $this->objUserCssFile->hash); } } else { $arrReturn[self::$userCssKey][] = array('src' => $this->objUserCssFile->value, 'type' => 'all', 'mode' => $this->mode, 'hash' => version_compare(VERSION, '3.4', '>=') ? $this->objUserCssFile->mtime : $this->objUserCssFile->hash); } if ($this->debug) { print '<pre>'; print_r('ExtCssCombiner execution time: ' . (microtime(true) - $this->start) . ' seconds'); print '</pre>'; } return $arrReturn; }