function GetCSS($cMaxStylesCnt=true, $bXhtmlStyle=true) { if($cMaxStylesCnt === true) $cMaxStylesCnt = COption::GetOptionInt('main', 'max_css_files', 15); $res = ''; $site_template = ''; $arCSS = $this->sPath2css; $addTemplateStyle = true; $arTemplateCss = array(); $optimizeCSS = COption::GetOptionString('main', 'optimize_css_files', 'N'); global $USER; if(isset($_GET['bx_template_preview_mode']) && $_GET['bx_template_preview_mode'] == 'Y' && $USER->CanDoOperation('edit_other_settings')) { $addTemplateStyle = false; $path = BX_PERSONAL_ROOT."/tmp/templates/__bx_preview/"; $arTemplateCss[] = $path."styles.css"; $arTemplateCss[] = $path."template_styles.css"; } elseif(defined("SITE_TEMPLATE_ID")) { $site_template = SITE_TEMPLATE_ID; $path = BX_PERSONAL_ROOT."/templates/".SITE_TEMPLATE_ID; $arTemplateCss[] = $path."/styles.css"; $arTemplateCss[] = $path."/template_styles.css"; } else { $site_template = '.default'; $path = BX_PERSONAL_ROOT."/templates/.default"; $arTemplateCss[] = $path."/styles.css"; $arTemplateCss[] = $path."/template_styles.css"; } if($optimizeCSS == 'Y') { $cssFile = array(); $cssSrcFile = array(); $cssMD5 = ''; $oldCssMD5 = ''; } else { $arCSS[] = $arTemplateCss[0]; $arCSS[] = $arTemplateCss[1]; } $arCSS = array_unique($arCSS); $isIE = IsIE(); $cnt = 0; $res_content = ''; $ruleCount = 0; foreach($arCSS as $css_path) { $bExternalLink = (strncmp($css_path, 'http://', 7) == 0 || strncmp($css_path, 'https://', 8) == 0); if(!$bExternalLink) { if(($p = strpos($css_path, "?"))>0) $css_file = substr($css_path, 0, $p); else $css_file = $css_path; $filename = $_SERVER["DOCUMENT_ROOT"].$css_file; } $bLink = ($bExternalLink || substr($css_file, -4, 4) != '.css'); $addCSS = (strncmp($css_path, '/bitrix/themes/', 15) != 0); if((($cnt < $cMaxStylesCnt || ($optimizeCSS == 'Y' && $addCSS) || !$isIE) || $bLink) && strncmp($css_path, '/bitrix/modules/', 16) != 0) { if($bExternalLink || file_exists($filename)) { if($res_content != '') { $res .= '<style type="text/css">'."\n".$res_content."\n</style>\n"; $res_content = ''; } if(!$bExternalLink && strpos($css_path, '?') === false) $css_path = CUtil::GetAdditionalFileURL($css_path, true); if($optimizeCSS == 'Y' && $addCSS) { $cssSrcFile[] = $css_path; $cssFile[] = $css_file; } else { $res .= '<link href="'.$css_path.'" type="text/css" rel="stylesheet"'.($bXhtmlStyle? ' /':'').'>'."\n"; } $cnt++; } } elseif(!$bLink && file_exists($filename) && filesize($filename) > 0) { $contents = file_get_contents($filename); if($contents != '') { $contents = preg_replace('#([;\s:]+url\s*\(\s*)([^\)]+)\)#sie', "'\\1'.CMain::__ReplaceUrlCSS('\\2', '".AddSlashes($css_path)."').')'", $contents); if($isIE) { $c = CMain::__GetCssSelectCnt($contents); $ruleCount += $c; if($ruleCount > 4000) { $ruleCount = $c; if($res_content <> '') $res_content .= "</style>\n<style type=\"text/css\">"; } } $res_content .= "\n".$contents."\n"; } } } if($optimizeCSS == 'Y' && $cnt > 0) { $res .= CMain::__OptimizeCss($cssFile, $cssSrcFile, $site_template, $addTemplateStyle, $arTemplateCss, $bXhtmlStyle); unset($cssFile, $cssSrcFile, $addTemplateStyle); } if($res_content!='') $res .= '<style type="text/css">'."\n".$res_content."\n</style>\n"; return $res; }