8 ini_set(
'pcre.backtrack_limit', 1000000);
10 define(
'CH_WSB_TEMPLATE_DEFAULT_CODE',
'uni');
11 define(
'CH_WSB_TEMPLATE_FOLDER_ROOT',
'templates');
12 define(
'CH_WSB_TEMPLATE_FOLDER_BASE',
'base');
14 define(
'CH_WSB_TEMPLATE_INJECTIONS_CACHE',
'sys_injections.inc');
16 define(
'CH_WSB_TEMPLATE_CHECK_IN_BOTH',
'both');
17 define(
'CH_WSB_TEMPLATE_CHECK_IN_BASE',
'base');
18 define(
'CH_WSB_TEMPLATE_CHECK_IN_TMPL',
'tmpl');
164 $this->_sPrefix =
'ChWsbTemplate';
167 $this->_sRootUrl = $sRootUrl;
168 $this->_sInjectionsTable =
'sys_injections';
171 $this->_sCodeKey =
'skin';
172 $this->_sCode =
$GLOBALS[
'MySQL']->getParam(
'template');
173 if(
empty($this->_sCode))
178 if (!
empty(
$sCode) && preg_match(
'/^[A-Za-z0-9_-]+$/',
$sCode) && file_exists($this->_sRootPath .
'templates/tmpl_' .
$sCode) && !is_file($this->_sRootPath .
'templates/tmpl_' .
$sCode))
183 if(!
empty(
$sCode) && preg_match(
'/^[A-Za-z0-9_-]+$/',
$sCode) && file_exists($this->_sRootPath .
'templates/tmpl_' .
$sCode) && !is_file($this->_sRootPath .
'templates/tmpl_' .
$sCode)) {
186 $aUrl = parse_url(
$GLOBALS[
'site'][
'url']);
187 $sPath = isset($aUrl[
'path']) && !
empty($aUrl[
'path']) ? $aUrl[
'path'] :
'/';
190 setcookie( $this->_sCodeKey, $this->_sCode,
time() + 60*60*24*365, $sPath);
192 if (isset(
$_GET[$this->_sCodeKey])) {
195 if ($oPermalinks->redirectIfNecessary(array($this->_sCodeKey)))
201 $this->_sKeyWrapperHtml =
'__';
202 $this->_sFolderHtml =
'';
203 $this->_sFolderCss =
'css/';
204 $this->_sFolderImages =
'images/';
205 $this->_sFolderIcons =
'images/icons/';
206 $this->_aTemplates = array();
208 $this->
addLocation(
'system', $this->_sRootPath, $this->_sRootUrl);
210 $this->
addLocationJs(
'system_inc_js', CH_DIRECTORY_PATH_INC .
'js/' , CH_WSB_URL_ROOT .
'inc/js/');
211 $this->
addLocationJs(
'system_inc_js_classes', CH_DIRECTORY_PATH_INC .
'js/classes/' , CH_WSB_URL_ROOT .
'inc/js/classes/');
212 $this->
addLocationJs(
'system_plugins', CH_DIRECTORY_PATH_PLUGINS, CH_WSB_URL_PLUGINS);
213 $this->
addLocationJs(
'system_plugins_jquery', CH_DIRECTORY_PATH_PLUGINS .
'jquery/' , CH_WSB_URL_PLUGINS .
'jquery/');
214 $this->
addLocationJs(
'system_plugins_tinymce', CH_DIRECTORY_PATH_PLUGINS .
'tiny_mce/' , CH_WSB_URL_PLUGINS .
'tiny_mce/');
216 $this->_bCacheEnable = !defined(
'CH_WSB_CRON_EXECUTE') &&
getParam(
'sys_template_cache_enable') ==
'on';
217 $this->_sCacheFolderUrl =
'';
218 $this->_sCachePublicFolderUrl = CH_WSB_URL_CACHE_PUBLIC;
219 $this->_sCachePublicFolderPath = CH_DIRECTORY_PATH_CACHE_PUBLIC;
220 $this->_sCacheFilePrefix =
"ch_templ_";
222 $this->_bImagesInline =
getParam(
'sys_template_cache_image_enable') ==
'on';
223 $this->_iImagesMaxSize = (int)
getParam(
'sys_template_cache_image_max_size') * 1024;
225 $bArchive =
getParam(
'sys_template_cache_compress_enable') ==
'on';
226 $this->_bCssCache = !defined(
'CH_WSB_CRON_EXECUTE') &&
getParam(
'sys_template_cache_css_enable') ==
'on';
227 $this->_bCssArchive = $this->_bCssCache && $bArchive;
228 $this->_sCssCachePrefix = $this->_sCacheFilePrefix .
'css_';
230 $this->_bJsCache = !defined(
'CH_WSB_CRON_EXECUTE') &&
getParam(
'sys_template_cache_js_enable') ==
'on';
231 $this->_bJsArchive = $this->_bJsCache && $bArchive;
232 $this->_sJsCachePrefix = $this->_sCacheFilePrefix .
'js_';
241 foreach($this->_aTemplates
as $sName)
253 $aInjections =
$oCache->getData(
$GLOBALS[
'MySQL']->genDbCacheKey($this->_sInjectionsCache));
254 if (
null === $aInjections) {
255 $rInjections =
db_res(
"SELECT `page_index`, `name`, `key`, `type`, `data`, `replace` FROM `" . $this->_sInjectionsTable .
"` WHERE `active`='1'");
256 while($aInjection = $rInjections->fetch())
257 $aInjections[
'page_' . $aInjection[
'page_index']][$aInjection[
'key']][] = $aInjection;
259 $oCache->setData (
$GLOBALS[
'MySQL']->genDbCacheKey($this->_sInjectionsCache), $aInjections);
262 $GLOBALS[$this->_sPrefix .
'Injections'] = isset(
$GLOBALS[$this->_sPrefix .
'Injections']) ? array_merge_recursive (
$GLOBALS[$this->_sPrefix .
'Injections'], $aInjections) : $aInjections;
265 $GLOBALS[$this->_sPrefix .
'PageKeywords'] = array();
266 $GLOBALS[$this->_sPrefix .
'OG'] = array();
268 $GLOBALS[$this->_sPrefix .
'Js'] = array();
269 $GLOBALS[$this->_sPrefix .
'JsSystem'] = array();
271 $GLOBALS[$this->_sPrefix .
'Css'] = array();
272 $GLOBALS[$this->_sPrefix .
'CssSystem'] = array();
273 $GLOBALS[$this->_sPrefix .
'CssStyles'] = array();
274 $GLOBALS[$this->_sPrefix .
'CssAsync'] = array();
292 $this->_aLocations[$sKey] = array(
306 $sLocationKey =
time();
307 $this->
addLocation($sLocationKey, $sLocationPath, $sLocationUrl);
309 return $sLocationKey;
319 if(isset($this->_aLocations[$sKey]))
320 unset($this->_aLocations[$sKey]);
332 $this->_aLocationsJs[$sKey] = array(
333 'path' => $sLocationPath,
334 'url' => $sLocationUrl
346 $sLocationKey =
time();
347 $this->
addLocationJs($sLocationKey, $sLocationPath, $sLocationUrl);
349 return $sLocationKey;
359 if(isset($this->_aLocationsJs[$sKey]))
360 unset($this->_aLocationsJs[$sKey]);
387 return $GLOBALS[$this->_sPrefix .
'PageWidth'];
396 $GLOBALS[$this->_sPrefix .
'PageWidth'] = $sWidth;
399 'max-width' =>
$GLOBALS[$this->_sPrefix .
'PageWidth']
427 $GLOBALS[$this->_sPrefix .
'PageDescription'] = $sDescription;
436 if(is_string($mixedName))
437 $mixedName = array($mixedName);
449 if(is_string($mixedKey))
450 $mixedKey = array($mixedKey);
452 foreach($mixedKey
as $sKey)
453 $GLOBALS[
'ChWsbTemplateJsTranslations'][$sKey] =
_t($sKey,
'{0}',
'{1}');
463 if(!is_array($aImages))
466 foreach($aImages
as $sKey =>
$sFile) {
482 if(!is_array($aIcons))
485 foreach($aIcons
as $sKey =>
$sFile) {
514 if(is_string($mixedKeywords))
515 $mixedKeywords = strpos($mixedKeywords, $sDevider) !==
false ? explode($sDevider, $mixedKeywords) : array($mixedKeywords);
517 foreach($mixedKeywords
as $iKey => $sValue)
518 $mixedKeywords[$iKey] = trim($sValue);
520 $GLOBALS[$this->_sPrefix .
'PageKeywords'] = array_merge(
$GLOBALS[$this->_sPrefix .
'PageKeywords'], $mixedKeywords);
529 $GLOBALS[$this->_sPrefix .
'OG'][$sNamespace] = array_merge(isset(
$GLOBALS[$this->_sPrefix .
'OG'][$sNamespace]) ?
$GLOBALS[$this->_sPrefix .
'OG'][$sNamespace] : array(), $a);
538 if (!
empty(
$GLOBALS[$this->_sPrefix .
'PageKeywords']) && is_array(
$GLOBALS[$this->_sPrefix .
'PageKeywords']) &&
$GLOBALS[$this->_sPrefix .
'PageKeywords'])
539 $sRet .=
'<meta name="keywords" content="' .
ch_html_attribute(implode(
',',
$GLOBALS[$this->_sPrefix .
'PageKeywords'])) .
"\" />\n";
541 if (!
empty(
$GLOBALS[$this->_sPrefix .
'PageDescription']) && is_string(
$GLOBALS[$this->_sPrefix .
'PageDescription']))
542 $sRet .=
'<meta name="description" content="' .
ch_html_attribute(
$GLOBALS[$this->_sPrefix .
'PageDescription']) .
"\" />\n";
545 foreach (
$GLOBALS[$this->_sPrefix .
'OG']
as $sNamespace => $a)
546 foreach ($a
as $k =>
$s)
547 $sRet .=
'<meta property="' . ($sNamespace ? $sNamespace .
':' :
'') . $k .
'" content="' .
ch_html_attribute(
$s) .
"\" />\n";
560 return $this->_aTemplates[
$sName];
646 return !
empty($sAbsolutePath) ? file_get_contents($sAbsolutePath) :
false;
709 return $this->
_parseContent($this->_aTemplates[
$sName], $aVariables, $mixedKeyWrapperHtml);
725 if ($sFbId =
getParam(
'ch_facebook_connect_api_key'))
733 if(strpos(
$sContent,
'<ch_include_css_styles />') !==
false)
736 if(strpos(
$sContent ,
'<ch_include_css />') !==
false) {
743 if(strpos(
$sContent ,
'<ch_include_js />') !==
false) {
774 return $a[
'Direction'];
783 $sRet =
$GLOBALS[$this->_sPrefix .
'PageTitle'];
784 else if (isset(
$_page[
'header']))
788 if (isset($_SERVER[
'HTTP_X_REQUESTED_WITH']) && !
empty($_SERVER[
'HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER[
'HTTP_X_REQUESTED_WITH']) ==
'xmlhttprequest')
790 if ($_SERVER[
'HTTP_USER_AGENT'] ==
'')
796 if ($sRet ==
'Page was not found')
799 $sQuery =
"UPDATE `Profiles` SET `DateLastPage` = NOW(), `CurrentPageTitle` = ? WHERE `ID` = '{$iProfileId}'";
803 case 'page_header_text':
805 $sRet =
$GLOBALS[$this->_sPrefix .
'PageMainBoxTitle'];
806 else if(isset(
$_page[
'header_text']))
807 $sRet =
$_page[
'header_text'];
809 case 'main_div_width':
814 $sRet =
$GLOBALS[
'oFunctions']->genSiteLogo();
817 $sRet =
$GLOBALS[
'oFunctions']->genSiteSplash();
820 $sRet =
$GLOBALS[
'oFunctions']->genSiteSearch();
823 $sRet =
$GLOBALS[
'oFunctions']->genSiteServiceMenu();
828 case 'show_breadcrumb':
829 $sShow =
getParam(
'ext_breadcrumb_menu_enabled');
833 $sRet =
'display: none; visibility: hidden;';
836 case 'footer_style_breadcrumb':
837 $sShow =
getParam(
'ext_breadcrumb_menu_enabled');
841 $sRet =
'position: relative;';
844 case 'top_menu_breadcrumb':
847 case 'extra_top_menu':
859 case 'switch_skin_block':
872 $sRet =
_t(
'_bottom_text', date(
'Y') );
884 case 'is_profile_page':
885 $sRet = (defined(
'CH_PROFILE_PAGE')) ?
'true' :
'false';
888 case 'logged_member_id':
891 case 'logged_nickname':
894 case 'logged_usertitle':
897 case 'current_date_short':
900 case 'current_date_long':
904 $sRet = ($sTemplAdd =
$oFunctions->TemplPageAddComponent($sKey)) !==
false ? $sTemplAdd : $aKeyWrappers[
'left'] . $sKey . $aKeyWrappers[
'right'];
916 $sCacheEngine =
getParam(
'sys_template_cache_engine');
917 $oCacheEngine =
ch_instance(
'ChWsbCache' . $sCacheEngine);
918 if(!$oCacheEngine->isAvailable())
920 return $oCacheEngine;
936 if (!$this->_bCacheEnable)
940 if (
empty($sAbsolutePath))
944 $isFileBasedEngine = $bEvaluate && method_exists($oCacheEngine,
'getDataFilePath');
948 $sCacheVariableName =
"a";
950 if ($isFileBasedEngine)
951 $sCacheContent = $oCacheEngine->getDataFilePath($sCacheKey);
953 $sCacheContent = $oCacheEngine->getData($sCacheKey);
958 if ($sCacheContent ===
null && (
$sContent = file_get_contents($sAbsolutePath)) !==
false && (
$sContent = $this->
_compileContent(
$sContent,
"\$" . $sCacheVariableName, 1, $aVariables, $mixedKeyWrapperHtml)) !==
false) {
959 if (
false === $oCacheEngine->setData($sCacheKey,
$sContent))
962 if ($isFileBasedEngine)
963 $sCacheContent = $oCacheEngine->getDataFilePath($sCacheKey);
968 if ($sCacheContent ===
null)
974 return $sCacheContent;
980 $$sCacheVariableName = &$aVariables;
982 if ($isFileBasedEngine)
983 include($sCacheContent);
985 eval(
'?'.
'>' . $sCacheContent);
999 function addJs($mixedFiles, $bDynamic =
false)
1001 return $this->
_processFiles(
'js',
'add', $mixedFiles, $bDynamic);
1013 return $this->
_processFiles(
'js',
'add', $mixedFiles,
false,
true);
1034 return $this->
_processFiles(
'js',
'delete', $mixedFiles,
false,
true);
1046 if(isset($aIncluded[$sAbsolutePath]))
1049 $bExternal = strpos($sAbsolutePath,
"http://") !==
false || strpos($sAbsolutePath,
"https://") !==
false;
1051 $sPath = $sAbsolutePath;
1056 $aFileInfo = pathinfo($sAbsolutePath);
1057 $sPath = $aFileInfo[
'dirname'] . DIRECTORY_SEPARATOR;
1058 $sName = $aFileInfo[
'basename'];
1066 $sUrl =
ch_ltrim_str($sPath, realpath(CH_DIRECTORY_PATH_ROOT), CH_WSB_URL_ROOT);
1067 $sUrl = str_replace(DIRECTORY_SEPARATOR,
'/', $sPath);
1072 $aIncluded[$sAbsolutePath] = 1;
1074 return preg_replace(
1076 "'<ch_url_root />'",
1094 return "<script language=\"javascript\" type=\"text/javascript\" src=\"" .
$sFile .
"\"></script>";
1104 return "<script language=\"javascript\" type=\"text/javascript\">\n<!--\n" .
$sCode .
"\n-->\n</script>";
1114 function addCss($mixedFiles, $bDynamic =
false)
1116 return $this->
_processFiles(
'css',
'add', $mixedFiles, $bDynamic);
1125 if (!is_array($mixedFiles))
1126 $mixedFiles = array($mixedFiles);
1131 $this->
addJs(
'loadCSS.js');
1143 $GLOBALS[$this->_sPrefix .
'CssAsync'] = array_unique(
$GLOBALS[$this->_sPrefix .
'CssAsync']);
1147 $sList .=
'loadCSS("' .
$sUrl .
'", document.getElementById("ch_css_async"));';
1151 <script id="ch_css_async">
1152 if(!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
1167 return $this->
_processFiles(
'css',
'add', $mixedFiles,
false,
true);
1188 return $this->
_processFiles(
'css',
'delete', $mixedFiles,
false,
true);
1200 if(isset($aIncluded[$sAbsolutePath]))
1203 $bExternal = strpos($sAbsolutePath,
"http://") !==
false || strpos($sAbsolutePath,
"https://") !==
false;
1205 $sPath = $sAbsolutePath;
1210 $aFileInfo = pathinfo($sAbsolutePath);
1211 $sPath = $aFileInfo[
'dirname'] . DIRECTORY_SEPARATOR;
1212 $sName = $aFileInfo[
'basename'];
1220 $sUrl =
ch_ltrim_str($sPath, realpath(CH_DIRECTORY_PATH_ROOT), CH_WSB_URL_ROOT);
1221 $sUrl = str_replace(DIRECTORY_SEPARATOR,
'/', $sPath);
1224 $aIncluded[$sAbsolutePath] = 1;
1229 "'@import\s+url\s*\(\s*[\'|\"]*\s*([a-zA-Z0-9\.\/_-]+)\s*[\'|\"]*\s*\)\s*;'",
1230 function($matches) {
return ''; },
1235 "'url\s*\(\s*[\'|\"]*\s*([a-zA-Z0-9\.\/\?\#_=-]+)\s*[\'|\"]*\s*\)'",
1236 function($matches)
use ($sPath) {
return "url({$sPath}{$matches[1]});"; },
1241 "'@import\s+url\s*\(\s*[\'|\"]*\s*([a-zA-Z0-9\.\/_-]+)\s*[\'|\"]*\s*\)\s*;'",
1242 function($matches)
use ($sPath) {
return $this->
_compileCss(realpath($sPath . dirname($matches[1])) . DIRECTORY_SEPARATOR . basename($matches[1]), $aIncluded); },
1247 "'url\s*\(\s*[\'|\"]*\s*([a-zA-Z0-9\.\/\?\#_=-]+)\s*[\'|\"]*\s*\)'",
1248 function ($aMatches)
use ($sPath) {
1265 require_once(CH_DIRECTORY_PATH_PLUGINS .
'minify/lib/Minify/CSS/Compressor.php');
1278 $sFile = basename($aMatches[1]);
1279 $sDirectory = dirname($aMatches[1]);
1281 $sRootPath = realpath(CH_DIRECTORY_PATH_ROOT);
1282 $sAbsolutePath = realpath($sPath . $sDirectory) . DIRECTORY_SEPARATOR .
$sFile;
1285 $sAbsolutePath = str_replace(DIRECTORY_SEPARATOR,
'/', $sAbsolutePath);
1300 return "<link href=\"" .
$sFile .
"\" rel=\"stylesheet\" type=\"text/css\" />";
1310 return "<style>" .
$sCode .
"</style>";
1318 if(
empty(
$GLOBALS[$this->_sPrefix .
'CssStyles']) || !is_array(
$GLOBALS[$this->_sPrefix .
'CssStyles']))
1323 if(!
empty($aContent) && is_array($aContent))
1324 foreach($aContent
as $sStyleName => $sStyleValue)
1325 $sContent .=
"\t" . $sStyleName .
": " . $sStyleValue .
";\r\n";
1341 $sUpcaseType = ucfirst(
$sType);
1343 $sArrayKey = $this->_sPrefix . $sUpcaseType . ($bSystem ?
'System' :
'');
1345 if(
empty($aFiles) || !is_array($aFiles))
1348 if(!$this->{
'_b' . $sUpcaseType .
'Cache'})
1352 $sMethodWrap =
'_wrapInTag' . $sUpcaseType;
1353 $sMethodCompile =
'_compile' . $sUpcaseType;
1354 $sMethodMinify =
'_minify' . $sUpcaseType;
1359 foreach($aFiles
as $aFile)
1363 $sCacheAbsoluteUrl = $this->_sCachePublicFolderUrl .
$sName .
'.' .
$sType;
1364 $sCacheAbsolutePath = $this->_sCachePublicFolderPath .
$sName .
'.' .
$sType;
1365 if(file_exists($sCacheAbsolutePath)) {
1366 if($this->{
'_b' . $sUpcaseType .
'Archive'})
1369 return $this->$sMethodWrap($sCacheAbsoluteUrl);
1374 $aIncluded = array();
1375 foreach($aFiles
as $aFile)
1376 if((
$sContent = $this->$sMethodCompile($aFile[
'path'], $aIncluded)) !==
false)
1379 if (method_exists($this, $sMethodMinify))
1382 $mixedWriteResult =
false;
1383 if(!
empty(
$sResult) && ($rHandler = fopen($sCacheAbsolutePath,
'w')) !==
false) {
1384 $mixedWriteResult = fwrite($rHandler,
$sResult);
1386 @chmod ($sCacheAbsolutePath, 0666);
1389 if($mixedWriteResult ===
false)
1390 return $this->_includeFile(
$sType, $aFiles);
1392 if($this->{
'_b' . $sUpcaseType .
'Archive'})
1395 return $this->$sMethodWrap($sCacheAbsoluteUrl);
1406 $sMethod =
'_wrapInTag' . ucfirst(
$sType);
1409 foreach($aFiles
as $aFile)
1410 $sResult .= $this->$sMethod($aFile[
'url']);
1424 if(
empty($mixedFiles))
1425 return $bDynamic ?
"" :
false;
1427 if(is_string($mixedFiles))
1428 $mixedFiles = array($mixedFiles);
1430 $sUpcaseType = ucfirst(
$sType);
1431 $sMethodLocate =
'_getAbsoluteLocation' . $sUpcaseType;
1432 $sMethodWrap =
'_wrapInTag' . $sUpcaseType;
1436 if(strpos(
$sFile,
"http://") !==
false || strpos(
$sFile,
"https://") !==
false) {
1441 else if(strpos(
$sFile,
"|") !==
false && $aParts = explode(
"|",
$sFile)) {
1442 $sFile = array_pop($aParts);
1443 if (!isset($aParts[0]))
1445 $sUrl = CH_WSB_URL_ROOT . (isset($aParts[1]) ? $aParts[1] : $aParts[0]) .
$sFile;
1446 $sPath = realpath(CH_DIRECTORY_PATH_ROOT . $aParts[0] .
$sFile);
1451 $sPath = $this->$sMethodLocate(
'path',
$sFile);
1457 $sArrayKey = $this->_sPrefix . $sUpcaseType . ($bSystem ?
'System' :
'');
1464 foreach(
$GLOBALS[$sArrayKey]
as $iKey => $aValue)
1465 if($aValue[
'url'] ==
$sUrl && $aValue[
'path'] == $sPath) {
1471 $GLOBALS[$sArrayKey][] = array(
'url' =>
$sUrl,
'path' => $sPath);
1476 foreach(
$GLOBALS[$sArrayKey]
as $iKey => $aValue)
1477 if($aValue[
'url'] ==
$sUrl) {
1478 unset(
$GLOBALS[$sArrayKey][$iKey]);
1485 return $bDynamic ?
$sResult :
true;
1498 $aKeys = array_keys($aVariables);
1499 $aValues = array_values($aVariables);
1503 $iCountKeys = count($aKeys);
1504 for ($i = 0; $i < $iCountKeys; $i++) {
1505 if (strncmp($aKeys[$i],
'ch_repeat:', 10) === 0) {
1506 $sKey =
"'<" . $aKeys[$i] .
">(.*)<\/" . $aKeys[$i] .
">'s";
1508 $aMatches = array();
1509 preg_match($sKey,
$sContent, $aMatches);
1512 if(isset($aMatches[1]) && !
empty($aMatches[1])) {
1513 if(is_array($aValues[$i]))
1514 foreach($aValues[$i]
as $aValue)
1516 else if(is_string($aValues[$i]))
1517 $sValue = $aValues[$i];
1519 }
else if (strncmp($aKeys[$i],
'ch_if:', 6) === 0) {
1520 $sKey =
"'<" . $aKeys[$i] .
">(.*)<\/" . $aKeys[$i] .
">'s";
1522 $aMatches = array();
1523 preg_match($sKey,
$sContent, $aMatches);
1526 if(isset($aMatches[1]) && !
empty($aMatches[1]))
1527 if(is_array($aValues[$i]) && isset($aValues[$i][
'content']) && $aValues[$i][
'condition'])
1528 $sValue .= $this->
parseHtmlByContent($aMatches[1], $aValues[$i][
'content'], $mixedKeyWrapperHtml);
1530 $sKey =
"'" . $aKeyWrappers[
'left'] . $aKeys[$i] . $aKeyWrappers[
'right'] .
"'s";
1531 $sValue = $aValues[$i];
1536 $aValues[$i] = $sValue;
1539 $aKeys = array_merge($aKeys, array(
1540 "'<ch_include_auto:([^\s]+) \/>'s",
1541 "'<ch_include_tmpl:([^\s]+) \/>'s",
1542 "'<ch_include_base:([^\s]+) \/>'s",
1543 "'<ch_injection:([^\s]+) />'s",
1544 "'<ch_image_url:([^\s]+) \/>'s",
1545 "'<ch_icon_url:([^\s]+) \/>'s",
1546 "'<ch_text:([_\{\}\w\d\s]+[^\s]{1}) \/>'s",
1547 "'<ch_text_js:([^\s]+) \/>'s",
1548 "'<ch_text_attribute:([^\s]+) \/>'s",
1549 "'<ch_url_root />'",
1550 "'<ch_url_admin />'"
1553 $aValues = array_merge($aValues, array(
1558 function($matches) {
return $this->
getImageUrl($matches[1]); },
1559 function($matches) {
return $this->
getIconUrl($matches[1]); },
1560 function($matches) {
return _t($matches[1]); },
1570 $aCombined = array_combine($aKeys, $aValues);
1571 foreach($aCombined
as $sPattern => $sValue) {
1573 if(is_object($sValue) && ($sValue instanceof Closure)) {
1578 $sContent = preg_replace_callback($sPattern,
function($matches)
use ($sValue) {
1585 $sContent = preg_replace_callback(
"'" . $aKeyWrappers[
'left'] .
"([a-zA-Z0-9_-]+)" . $aKeyWrappers[
'right'] .
"'",
1586 function($matches)
use ($mixedKeyWrapperHtml) {
1606 $aKeys = array_keys($aVarValues);
1607 $aValues = array_values($aVarValues);
1611 for($i = 0; $i < count($aKeys); $i++) {
1612 if(strpos($aKeys[$i],
'ch_repeat:') === 0) {
1613 $sKey =
"'<" . $aKeys[$i] .
">(.*)<\/" . $aKeys[$i] .
">'s";
1615 $aMatches = array();
1616 preg_match($sKey,
$sContent, $aMatches);
1619 if(isset($aMatches[1]) && !
empty($aMatches[1])) {
1620 if(
empty($aValues[$i]) || !is_array($aValues[$i]))
1623 $sIndex =
"\$" . str_repeat(
"i", $iVarDepth);
1624 $sValue .=
'<'.
"?php if(is_array(" . $aVarName .
"['" . $aKeys[$i] .
"'])) for(" . $sIndex .
"=0; " . $sIndex .
"<count(" . $aVarName .
"['" . $aKeys[$i] .
"']); " . $sIndex .
"++){ ?".
'>';
1625 if(($sInnerValue = $this->
_compileContent($aMatches[1], $aVarName .
"['" . $aKeys[$i] .
"'][" . $sIndex .
"]", $iVarDepth + 1, current($aValues[$i]), $mixedKeyWrapperHtml)) ===
false)
1627 $sValue .= $sInnerValue;
1628 $sValue .=
'<'.
"?php } else if(is_string(" . $aVarName .
"['" . $aKeys[$i] .
"'])) echo " . $aVarName .
"['" . $aKeys[$i] .
"']; ?".
'>';
1630 }
else if(strpos($aKeys[$i],
'ch_if:') === 0) {
1631 $sKey =
"'<" . $aKeys[$i] .
">(.*)<\/" . $aKeys[$i] .
">'s";
1633 $aMatches = array();
1634 preg_match($sKey,
$sContent, $aMatches);
1637 if(isset($aMatches[1]) && !
empty($aMatches[1])) {
1638 if(!is_array($aValues[$i]) || !isset($aValues[$i][
'content']) ||
empty($aValues[$i][
'content']) || !is_array($aValues[$i][
'content']))
1641 $sValue .=
'<'.
"?php if(" . $aVarName .
"['" . $aKeys[$i] .
"']['condition']){ ?".
'>';
1642 if(($sInnerValue = $this->
_compileContent($aMatches[1], $aVarName .
"['" . $aKeys[$i] .
"']['content']", $iVarDepth, $aValues[$i][
'content'], $mixedKeyWrapperHtml)) ===
false)
1644 $sValue .= $sInnerValue;
1645 $sValue .=
'<'.
'?php } ?'.
'>';
1648 $sKey =
"'" . $aKeyWrappers[
'left'] . $aKeys[$i] . $aKeyWrappers[
'right'] .
"'s";
1649 $sValue =
'<'.
'?=' . $aVarName .
"['" . $aKeys[$i] .
"'];?".
'>';
1653 $aValues[$i] = $sValue;
1656 $aKeys = array_merge($aKeys, array(
1657 "'<ch_include_auto:([^\s]+) \/>'s",
1658 "'<ch_include_base:([^\s]+) \/>'s",
1659 "'<ch_include_tmpl:([^\s]+) \/>'s",
1660 "'<ch_injection:([^\s]+) />'s",
1661 "'<ch_image_url:([^\s]+) \/>'s",
1662 "'<ch_icon_url:([^\s]+) \/>'s",
1663 "'<ch_text:([_\{\}\w\d\s]+[^\s]{1}) \/>'s",
1664 "'<ch_text_js:([^\s]+) \/>'s",
1665 "'<ch_text_attribute:([^\s]+) \/>'s",
1666 "'<ch_url_root />'",
1667 "'<ch_url_admin />'"
1670 $aValues = array_merge($aValues, array(
1674 function($matches) {
return '<?=$this->processInjection($GLOBALS[\'_page\'][\'name_index\'], "'.$matches[1].
'")?>'; },
1675 function($matches) {
return $this->
getImageUrl($matches[1]); },
1676 function($matches) {
return $this->
getIconUrl($matches[1]); },
1677 function($matches) {
return _t($matches[1]); },
1685 $aCombined = array_combine($aKeys, $aValues);
1686 foreach($aCombined
as $sPattern => $sValue) {
1687 if(is_object($sValue) && ($sValue instanceof Closure)) {
1692 $sContent = preg_replace_callback($sPattern,
function($matches)
use ($sValue) {
1698 $sContent = preg_replace(
"'" . $aKeyWrappers[
'left'] .
"([a-zA-Z0-9_-]+)" . $aKeyWrappers[
'right'] .
"'",
"<?=\$this->parseSystemKey('\\1', \$mixedKeyWrapperHtml);?".
">",
$sContent);
1714 $sDivider = DIRECTORY_SEPARATOR;
1715 $sRoot = CH_DIRECTORY_PATH_ROOT;
1716 }
else if(
$sType ==
'url') {
1718 $sRoot = CH_WSB_URL_ROOT;
1721 if(strpos(
$sName,
'|') !==
false) {
1722 $aParts = explode(
'|',
$sName);
1725 $sLocationKey = $this->
addDynamicLocation(CH_DIRECTORY_PATH_ROOT . $aParts[0], CH_WSB_URL_ROOT . $aParts[0]);
1729 $aLocations = array_reverse($this->_aLocations,
true);
1730 foreach($aLocations
as $sKey => $aLocation) {
1745 if(!
$sResult && @is_file(CH_DIRECTORY_PATH_ROOT . $aParts[0] . DIRECTORY_SEPARATOR . $aParts[1])) {
1746 $sResult = $sRoot . $aParts[0] . $sDivider . $aParts[1];
1749 if(isset($sLocationKey))
1764 $aLocations = array_reverse($this->_aLocationsJs,
true);
1765 foreach($aLocations
as $sKey => $aLocation) {
1799 if($this->_bImagesInline && ($iFileSize = filesize($sPath)) !==
false && $iFileSize < $this->_iImagesMaxSize) {
1800 $aFileInfo = pathinfo($sPath);
1801 return "data:image/" . strtolower($aFileInfo[
'extension']) .
";base64," . base64_encode(file_get_contents($sPath));
1838 if(!
empty($mixedKeyWrapperHtml) && is_string($mixedKeyWrapperHtml))
1839 $aResult = array(
'left' => $mixedKeyWrapperHtml,
'right' => $mixedKeyWrapperHtml);
1840 else if(!
empty($mixedKeyWrapperHtml) && is_array($mixedKeyWrapperHtml))
1841 $aResult = array(
'left' => $mixedKeyWrapperHtml[0],
'right' => $mixedKeyWrapperHtml[1]);
1843 $aResult = array(
'left' => $this->_sKeyWrapperHtml,
'right' => $this->_sKeyWrapperHtml);
1854 $aSearch = array(
"\r",
"\n",
'\'');
1855 $aReplacement = array(
'',
'\n',
'\\\'');
1858 foreach(
$GLOBALS[
'ChWsbTemplateJsTranslations']
as $sKey => $sString) {
1859 $sKey = str_replace($aSearch, $aReplacement, $sKey);
1860 $sString = str_replace($aSearch, $aReplacement, $sString);
1862 $sReturn .=
"'" . $sKey .
"': '" . $sString .
"',";
1865 return '<script type="text/javascript" language="javascript">var aWsbLang = {' . substr($sReturn, 0, -1) .
'};</script>';
1876 $sReturn .=
"'" .
$sName .
"': '" . addslashes($mixedValue) .
"',";
1878 return '<script type="text/javascript" language="javascript">var aWsbOptions = {' . substr($sReturn, 0, -1) .
'};</script>';
1889 $sReturn .=
"'" . $sKey .
"': '" .
$sUrl .
"',";
1891 return '<script type="text/javascript" language="javascript">var aWsbImages = {' . substr($sReturn, 0, -1) .
'};</script>';
1903 return CH_WSB_URL_ROOT .
'gzip_loader.php?file=' .
$sName .
'.' .
$sType;
1955 $sTitle =
_t(
'_sys_request_page_not_found_cpt');
1964 header(
"HTTP/1.0 404 Not Found");
1996 if($iPageIndex != 0 && isset(
$GLOBALS[$this->_sPrefix .
'Injections'][
'page_0'][$sKey]) && isset(
$GLOBALS[$this->_sPrefix .
'Injections'][
'page_' . $iPageIndex][$sKey]))
1997 $aSelection = @array_merge(
$GLOBALS[$this->_sPrefix .
'Injections'][
'page_0'][$sKey],
$GLOBALS[$this->_sPrefix .
'Injections'][
'page_' . $iPageIndex][$sKey]);
1998 else if(isset(
$GLOBALS[$this->_sPrefix .
'Injections'][
'page_0'][$sKey]))
1999 $aSelection =
$GLOBALS[$this->_sPrefix .
'Injections'][
'page_0'][$sKey];
2000 else if(isset(
$GLOBALS[$this->_sPrefix .
'Injections'][
'page_' . $iPageIndex][$sKey]))
2001 $aSelection =
$GLOBALS[$this->_sPrefix .
'Injections'][
'page_' . $iPageIndex][$sKey];
2003 $aSelection = array();
2005 if(is_array($aSelection))
2006 foreach($aSelection
as $aInjection) {
2008 if (isset(
$GLOBALS[
'ch_profiler']))
$GLOBALS[
'ch_profiler']->beginInjection($sRand =
time().rand());
2010 switch($aInjection[
'type']) {
2012 $sInjData = $aInjection[
'data'];
2016 $sInjData = eval($aInjection[
'data']);
2017 if(!
empty($sInjData))
2020 $sInjData = ob_get_clean();
2023 if((
int)$aInjection[
'replace'] == 1)
2024 $sValue = $sInjData;
2026 $sValue .= $sInjData;
2028 if (isset(
$GLOBALS[
'ch_profiler']))
$GLOBALS[
'ch_profiler']->endInjection($sRand, $aInjection[
'name'], $aInjection[
'key'], (
int)$aInjection[
'replace'] == 1);
2032 return $sValue !=
'__' . $sKey .
'__' ? str_replace(
'__' . $sKey .
'__',
'', $sValue) : $sValue;
2044 $GLOBALS[$this->_sPrefix .
'Injections'][
'page_0'][$sKey][] = array(
2049 'replace' => $iReplace