function GetAllTemplateParams($templateID, $site, $findcomponent = true, $arAdditionalParams = array()) { global $APPLICATION; $db_templ = CSiteTemplate::GetByID($templateID); if (!($ar_templ = $db_templ->Fetch())) { $templateID = ""; $db_site_templ = CSite::GetTemplateList($site); while ($ar_site_templ = $db_site_templ->Fetch()) { if (strlen($ar_site_templ["CONDITION"]) <= 0) { $templateID = $ar_site_templ["TEMPLATE"]; break; } } if (strlen($templateID) > 0) { $db_templ = CSiteTemplate::GetByID($templateID); $ar_templ = $db_templ->Fetch(); } } if ($ar_templ) { $arResult = array("ID" => $ar_templ["ID"], "NAME" => $ar_templ["NAME"]); if (is_set($ar_templ, "STYLES")) { // Fetch @import and include it to CSS - will include css from comments also :(. $pattern = '/^@import(.*)$/im'; $matches = array(); if (preg_match_all($pattern, $ar_templ["STYLES"], $matches)) { for ($j = 0, $l = count($matches[0]); $j < $l; $j++) { $str = $matches[0][$j]; $url = trim(trim($matches[1][$j]), '"\';'); $css = ""; if (substr($url, -5) != 'print') { $url = trim(trim($url), ' "\';'); if (substr($url, 0, 4) == 'url(' && substr($url, -1) == ')') { $url = trim(substr($url, 4, -1), ' "\''); } $url = trim(trim($url), '\'";'); if (substr($url, 0, 1) != '/' && file_exists($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/templates/" . $ar_templ["ID"] . "/" . $url)) { $css = "\n" . $APPLICATION->GetFileContent($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/templates/" . $ar_templ["ID"] . "/" . $url) . "\n"; } else { if (file_exists($_SERVER["DOCUMENT_ROOT"] . $url)) { $css = "\n" . $APPLICATION->GetFileContent($_SERVER["DOCUMENT_ROOT"] . $url) . "\n"; } } } $ar_templ["STYLES"] = str_replace($matches[0][$j], $css, $ar_templ["STYLES"]); } } $arResult["STYLES"] = $ar_templ["STYLES"]; $arResult["STYLES_TITLE"] = $ar_templ["STYLES_TITLE"]; $arResult["EDITOR_STYLES"] = $ar_templ["EDITOR_STYLES"]; } } else { $arResult = array("ID" => ".default", "NAME" => GetMessage("FILEMAN_DDEF_TEMPLATE")); $templateID = ""; } if (!is_set($arResult, "STYLES") || $arResult["STYLES"] == false) { if (file_exists($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/php_interface/" . (strlen($site) <= 0 ? LANGUAGE_ID : $site) . "/styles.css")) { $arResult["STYLES"] = $APPLICATION->GetFileContent($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/php_interface/" . (strlen($site) <= 0 ? LANGUAGE_ID : $site) . "/styles.css"); $arResult["STYLES_TITLE"] = CSiteTemplate::__GetByStylesTitle($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/php_interface/" . (strlen($site) <= 0 ? LANGUAGE_ID : $site) . "/.styles.php"); } elseif (file_exists($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/php_interface/styles.css")) { $arResult["STYLES"] = $APPLICATION->GetFileContent($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/php_interface/styles.css"); $arResult["STYLES_TITLE"] = CSiteTemplate::__GetByStylesTitle($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/php_interface/.styles.php"); } else { $arResult["STYLES"] = $APPLICATION->GetFileContent($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/templates/.default/styles.css"); $arResult["STYLES_TITLE"] = CSiteTemplate::__GetByStylesTitle($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/templates/.default/.styles.php"); } } if (isset($arAdditionalParams['additionalCSS'])) { $additionalCSS = $arAdditionalParams['additionalCSS']; for ($i = 0, $l = count($additionalCSS); $i < $l; $i++) { $css_file_path = $additionalCSS[$i]; $arResult["STYLES"] .= "\r\n" . $APPLICATION->GetFileContent($css_file_path); } } if (strlen($templateID) > 0 && file_exists($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/templates/" . $templateID . "/editor.css")) { $arResult["STYLES"] .= "\r\n" . $APPLICATION->GetFileContent($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/templates/" . $templateID . "/editor.css"); } elseif (file_exists($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/templates/.default/editor.css")) { $arResult["STYLES"] .= "\r\n" . $APPLICATION->GetFileContent($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/templates/.default/editor.css"); } elseif (file_exists($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/php_interface/" . $site . "/editor.css")) { $arResult["STYLES"] .= "\r\n" . $APPLICATION->GetFileContent($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/php_interface/" . (strlen($site) <= 0 ? LANGUAGE_ID : $site) . "/editor.css"); } elseif (file_exists($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/php_interface/editor.css")) { $arResult["STYLES"] .= "\r\n" . $APPLICATION->GetFileContent($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/php_interface/editor.css"); } $arResult["STYLES"] = preg_replace("/\r\n/", " ", $arResult["STYLES"]); $arResult["STYLES"] = preg_replace("/\n/", " ", $arResult["STYLES"]); $arResult["SITE_TEMPLATE_PATH"] = getLocalPath('templates/' . $templateID, BX_PERSONAL_ROOT); return $arResult; }
function GetList($arOrder = array(), $arFilter = array(), $arSelect = false) { /** @global CMain $APPLICATION */ global $APPLICATION; if (isset($arFilter["ID"]) && !is_array($arFilter["ID"])) { $arFilter["ID"] = array($arFilter["ID"]); } $arRes = array(); $path = $_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/templates"; $handle = opendir($path); if ($handle) { while (($file = readdir($handle)) !== false) { if ($file == "." || $file == ".." || !is_dir($path . "/" . $file)) { continue; } if ($file == ".default") { continue; } if (isset($arFilter["ID"]) && !in_array($file, $arFilter["ID"])) { continue; } $arTemplate = array("DESCRIPTION" => ""); if (file_exists($fname = $path . "/" . $file . "/lang/" . LANGUAGE_ID . "/description.php")) { __IncludeLang($fname, false, true); } elseif (file_exists($fname = $path . "/" . $file . "/lang/" . LangSubst(LANGUAGE_ID) . "/description.php")) { __IncludeLang($fname, false, true); } if (file_exists($fname = $path . "/" . $file . "/description.php")) { include $fname; } $arTemplate["ID"] = $file; if (!isset($arTemplate["NAME"])) { $arTemplate["NAME"] = $file; } if ($arSelect === false || in_array("SCREENSHOT", $arSelect)) { if (file_exists($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/templates/" . $file . "/lang/" . LANGUAGE_ID . "/screen.gif")) { $arTemplate["SCREENSHOT"] = BX_PERSONAL_ROOT . "/templates/" . $file . "/lang/" . LANGUAGE_ID . "/screen.gif"; } elseif (file_exists($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/templates/" . $file . "/screen.gif")) { $arTemplate["SCREENSHOT"] = BX_PERSONAL_ROOT . "/templates/" . $file . "/screen.gif"; } else { $arTemplate["SCREENSHOT"] = false; } if (file_exists($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/templates/" . $file . "/lang/" . LANGUAGE_ID . "/preview.gif")) { $arTemplate["PREVIEW"] = BX_PERSONAL_ROOT . "/templates/" . $file . "/lang/" . LANGUAGE_ID . "/preview.gif"; } elseif (file_exists($_SERVER["DOCUMENT_ROOT"] . BX_PERSONAL_ROOT . "/templates/" . $file . "/preview.gif")) { $arTemplate["PREVIEW"] = BX_PERSONAL_ROOT . "/templates/" . $file . "/preview.gif"; } else { $arTemplate["PREVIEW"] = false; } } if ($arSelect === false || in_array("CONTENT", $arSelect)) { $arTemplate["CONTENT"] = $APPLICATION->GetFileContent($path . "/" . $file . "/header.php") . "#WORK_AREA#" . $APPLICATION->GetFileContent($path . "/" . $file . "/footer.php"); } if ($arSelect === false || in_array("STYLES", $arSelect)) { if (file_exists($path . "/" . $file . "/styles.css")) { $arTemplate["STYLES"] = $APPLICATION->GetFileContent($path . "/" . $file . "/styles.css"); $arTemplate["STYLES_TITLE"] = CSiteTemplate::__GetByStylesTitle($path . "/" . $file . "/.styles.php"); } if (file_exists($path . "/" . $file . "/template_styles.css")) { $arTemplate["TEMPLATE_STYLES"] = $APPLICATION->GetFileContent($path . "/" . $file . "/template_styles.css"); } } $arRes[] = $arTemplate; } closedir($handle); } $db_res = new CDBResult(); $db_res->InitFromArray($arRes); return $db_res; }
function GetList($arOrder = array(), $arFilter = array(), $arSelect = false) { /** @global CMain $APPLICATION */ global $APPLICATION; if (isset($arFilter["ID"]) && !is_array($arFilter["ID"])) { $arFilter["ID"] = array($arFilter["ID"]); } $folders = array("/local/templates", BX_PERSONAL_ROOT . "/templates"); $arRes = array(); foreach ($folders as $folder) { $path = $_SERVER["DOCUMENT_ROOT"] . $folder; if (is_dir($path)) { $handle = opendir($path); if ($handle) { while (($file = readdir($handle)) !== false) { if ($file == "." || $file == ".." || !is_dir($path . "/" . $file)) { continue; } if ($file == ".default") { continue; } if (isset($arRes[$file])) { continue; } if (isset($arFilter["ID"]) && !in_array($file, $arFilter["ID"])) { continue; } $arTemplate = array("DESCRIPTION" => ""); if (file_exists($fname = $path . "/" . $file . "/lang/" . LANGUAGE_ID . "/description.php")) { __IncludeLang($fname, false, true); } elseif (file_exists($fname = $path . "/" . $file . "/lang/" . LangSubst(LANGUAGE_ID) . "/description.php")) { __IncludeLang($fname, false, true); } if (file_exists($fname = $path . "/" . $file . "/description.php")) { include $fname; } $arTemplate["ID"] = $file; $arTemplate["PATH"] = $folder . "/" . $file; if (!isset($arTemplate["NAME"])) { $arTemplate["NAME"] = $file; } if ($arSelect === false || in_array("SCREENSHOT", $arSelect)) { if (file_exists($path . "/" . $file . "/lang/" . LANGUAGE_ID . "/screen.gif")) { $arTemplate["SCREENSHOT"] = $folder . "/" . $file . "/lang/" . LANGUAGE_ID . "/screen.gif"; } elseif (file_exists($path . "/" . $file . "/screen.gif")) { $arTemplate["SCREENSHOT"] = $folder . "/" . $file . "/screen.gif"; } else { $arTemplate["SCREENSHOT"] = false; } if (file_exists($path . "/" . $file . "/lang/" . LANGUAGE_ID . "/preview.gif")) { $arTemplate["PREVIEW"] = $folder . "/" . $file . "/lang/" . LANGUAGE_ID . "/preview.gif"; } elseif (file_exists($path . "/" . $file . "/preview.gif")) { $arTemplate["PREVIEW"] = $folder . "/" . $file . "/preview.gif"; } else { $arTemplate["PREVIEW"] = false; } } if ($arSelect === false || in_array("CONTENT", $arSelect)) { $arTemplate["CONTENT"] = $APPLICATION->GetFileContent($path . "/" . $file . "/header.php") . "#WORK_AREA#" . $APPLICATION->GetFileContent($path . "/" . $file . "/footer.php"); } if ($arSelect === false || in_array("STYLES", $arSelect)) { if (file_exists($path . "/" . $file . "/styles.css")) { $arTemplate["STYLES"] = $APPLICATION->GetFileContent($path . "/" . $file . "/styles.css"); $arTemplate["STYLES_TITLE"] = CSiteTemplate::__GetByStylesTitle($path . "/" . $file . "/.styles.php"); } if (file_exists($path . "/" . $file . "/template_styles.css")) { $arTemplate["TEMPLATE_STYLES"] = $APPLICATION->GetFileContent($path . "/" . $file . "/template_styles.css"); } } $arRes[$file] = $arTemplate; } closedir($handle); } } } if (is_array($arOrder)) { $columns = array(); static $fields = array("ID" => 1, "NAME" => 1, "DESCRIPTION" => 1, "SORT" => 1); foreach ($arOrder as $key => $val) { $key = strtoupper($key); if (isset($fields[$key])) { $columns[$key] = strtoupper($val) == "DESC" ? SORT_DESC : SORT_ASC; } } if (!empty($columns)) { \Bitrix\Main\Type\Collection::sortByColumn($arRes, $columns); } } $db_res = new CDBResult(); $db_res->InitFromArray($arRes); return $db_res; }
public static function SaveStyleDescription($stylesDesc = array(), $stylesPath) { /** @global CMain $APPLICATION */ global $APPLICATION; if (isset($stylesDesc) && is_array($stylesDesc)) { $curStylesDesc = CSiteTemplate::__GetByStylesTitle($stylesPath); if (is_array($curStylesDesc)) { foreach ($curStylesDesc as $code => $val) { if (!is_array($curStylesDesc[$code])) { unset($curStylesDesc[$code]); } } } foreach ($stylesDesc as $code => $val) { if (!isset($curStylesDesc[EscapePHPString($code)]) || !is_array($curStylesDesc[EscapePHPString($code)])) { $curStylesDesc[EscapePHPString($code)] = EscapePHPString($val); } } $APPLICATION->SaveFileContent($stylesPath, '<' . '?' . "\nreturn " . var_export($curStylesDesc, 1) . ";\n" . '?' . '>'); } }
<td align="center" colspan="2"> <? $stylesPath = $_SERVER["DOCUMENT_ROOT"].BX_PERSONAL_ROOT."/templates/".$ID."/.styles.php"; if($bVarsFromForm) { $i = 0; $arStyles = array(); while(isset($_POST["CODE_".$i])) { $arStyles[$_POST["CODE_".$i]] = $_POST["VALUE_".$i]; $i++; } } else { $arStyles = (file_exists($stylesPath)) ? CSiteTemplate::__GetByStylesTitle($stylesPath) : array(); } ?> <script> function _MoreRProps() { var prt = BX("proptab"); var cnt = parseInt(BX("maxind").value) + 1; var r = prt.insertRow(prt.rows.length - 1); var c = r.insertCell(-1); c.innerHTML = '<input type="text" id="CODE_'+cnt+'" name="CODE_'+cnt+'" value="" size="30">'; c = r.insertCell(-1); c.innerHTML = '<input type="text" name="VALUE_'+cnt+'" id="VALUE_'+cnt+'" value="" size="60">'; BX("maxind").value = cnt; } </script>
<tr> <td align="center" colspan="2"> <?php $io = CBXVirtualIo::GetInstance(); $stylesPath = $io->RelativeToAbsolutePath($templFields["PATH"] . "/.styles.php"); $arStyles = array(); if ($bVarsFromForm) { $i = 0; while (isset($_POST["CODE_" . $i])) { $arStyles[$_POST["CODE_" . $i]] = $_POST["VALUE_" . $i]; $i++; } } else { $io = CBXVirtualIo::GetInstance(); if ($io->FileExists($stylesPath)) { $arStyles = CSiteTemplate::__GetByStylesTitle($stylesPath); } } ?> <script> function _MoreRProps() { var prt = BX("proptab"); var cnt = parseInt(BX("maxind").value) + 1; var r = prt.insertRow(prt.rows.length - 1); var c = r.insertCell(-1); c.innerHTML = '<input type="text" id="CODE_'+cnt+'" name="CODE_'+cnt+'" value="" size="30">'; c = r.insertCell(-1); c.innerHTML = '<input type="text" name="VALUE_'+cnt+'" id="VALUE_'+cnt+'" value="" size="60">'; BX("maxind").value = cnt; }