BxDolTemplate.php 98 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. ini_set('pcre.backtrack_limit', 1000000);
  10. define('BX_DOL_TEMPLATE_CODE_KEY', 'skin');
  11. define('BX_DOL_TEMPLATE_DEFAULT_CODE', 'protean');
  12. define('BX_DOL_TEMPLATE_FOLDER_ROOT', 'template');
  13. define('BX_DOL_TEMPLATE_INJECTIONS_CACHE', 'sys_injections.inc');
  14. define('BX_DOL_TEMPLATE_CHECK_IN_BOTH', 'both');
  15. define('BX_DOL_TEMPLATE_CHECK_IN_BASE', 'base');
  16. define('BX_DOL_TEMPLATE_CHECK_IN_TMPL', 'tmpl');
  17. define('BX_DOL_TEMPLATE_TAG_I', 'i');
  18. define('BX_DOL_TEMPLATE_TAG_SPAN', 'span');
  19. define('BX_DOL_TEMPLATE_TAG_DIV', 'div');
  20. define('BX_DOL_TEMPLATE_TAG_IMG', 'img');
  21. define('BX_DOL_TEMPLATE_TAG_A', 'a');
  22. define('BX_DOL_TEMPLATE_TAG_BUTTON', 'button');
  23. define('BX_DOL_TEMPLATE_TAG_CUSTOM', 'custom');
  24. define('BX_DOL_COLOR_BG', 'bg');
  25. define('BX_DOL_COLOR_FT', 'ft');
  26. define('BX_PAGE_DEFAULT', 0); ///< default, regular page
  27. define('BX_PAGE_CLEAR', 2); ///< clear page, without any headers and footers
  28. define('BX_PAGE_POPUP', 44); ///< popup page, without any headers and footers
  29. define('BX_PAGE_TRANSITION', 150); ///< transition page with redirect to display some msg, like 'please wait', without headers footers
  30. /**
  31. * Template engine.
  32. *
  33. * An object of the class allows to:
  34. * 1. Manage HTML templates.
  35. * 2. Get URL/path for any template image/icon.
  36. * 3. Attach CSS/JavaScript files to the output.
  37. * 4. Add some content to any template key using Injection engine.
  38. *
  39. *
  40. * Avalable constructions.
  41. * 1. &lt;bx_include_auto:template_name.html /&gt; - the content of the file would be inserted. File would be taken from current template if it existes there, and from base directory otherwise.
  42. * 2. &lt;bx_include_base:template_name.html /&gt; - the content of the file would be inserted. File would be taken from base directory.
  43. * 3. &lt;bx_include_tmpl:template_name.html /&gt; - the content of the file would be inserted. File would be taken from tmpl_xxx directory.
  44. * 4. &lt;bx_url_root /&gt; - the value of BX_DOL_URL_ROOT variable will be inserted.
  45. * 5. &lt;bx_url_admin /&gt; - the value of BX_DOL_URL_ADMIN variable will be inserted.
  46. * 6. &lt;bx_text:_language_key /&gt; - _language_key will be translated using language file(function _t()) and inserted.
  47. &lt;bx_text_js:_language_key /&gt; - _language_key will be translated using language file(function _t()) and inserted, use it to insert text into js string.
  48. &lt;bx_text_attribute:_language_key /&gt; - _language_key will be translated using language file(function _t()) and inserted, use it to insert text into html attribute.
  49. * 7. &lt;bx_image_url:image_file_name /&gt; - image with 'image_file_name' file name will be searched in the images folder of current template.
  50. * If it's not found, then it will be searched in the images folder of base template. On success full URL will be inserted, otherwise an empty string.
  51. * 8. &lt;bx_icon_url:icon_file_name /&gt; - the same with &lt;bx_image_url:image_file_name /&gt;, but icons will be searched in the images/icons/ folders.
  52. * 9. &lt;bx_injection:injection_name /&gt; - will be replaced with injections registered with the page and injection_name in the `sys_injections`/`sys_injections_admin`/ tables.
  53. * 10. &lt;bx_if:tag_name&gt;some_HTML&lt;/bx_if:tag_name&gt; - will be replaced with provided content if the condition is true, and with empty string otherwise.
  54. * 11. &lt;bx_repeat:cycle_name&gt;some_HTML&lt;/bx_repeat:cycle_name&gt; - an inner HTML content will be repeated in accordance with received data.
  55. *
  56. *
  57. * Related classes:
  58. * BxDolTemplateAdmin - for processing admin templates.
  59. * Template classes in modules - for processing modiles' templates.
  60. *
  61. *
  62. * Global variables:
  63. * oSysTemplate - is used for template processing in user part.
  64. * oAdmTemplate - is used for template processing in admin part.
  65. *
  66. *
  67. * Add injection:
  68. * 1. Register it in the `sys_injections` table or `sys_injections_admin` table for admin panel.
  69. * 2. Clear injections cache(sys_injections.inc and sys_injections_admin.inc in cache folder).
  70. *
  71. *
  72. * Predefined template keys to add injections:
  73. * 1. injection_head - add injections in the &lt;head&gt; tag.
  74. * 2. injection_body - add ingection(attribute) in the &lt;body&gt; tag.
  75. * 3. injection_header - add injection inside the &lt;body&gt; tag at the very beginning.
  76. * 4. injection_logo_before - add injection at the left of the main logo(inside logo's DIV).
  77. * 5. injection_logo_after - add injection at the right of the main logo(inside logo's DIV).
  78. * 6. injection_between_logo_top_menu - add injection between logo and top menu.
  79. * 7. injection_top_menu_before - add injection at the left of the top menu(inside top menu's DIV).
  80. * 8. injection_top_menu_after - add injection at the right of the top menu(inside top menu's DIV).
  81. * 13. injection_content_before - add injection just before main content(inside content's DIV).
  82. * 14. injection_content_after - add injection just after main content(inside content's DIV).
  83. * 15. injection_between_content_footer - add injection between content and footer.
  84. * 16. injection_footer_before - add injection at the left of the footer(inside footer's DIV).
  85. * 17. injection_footer_after - add injection at the right of the footer(inside footer's DIV).
  86. * 18. injection_footer - add injection inside the &lt;body&gt; tag at the very end.
  87. *
  88. *
  89. * Example of usage:
  90. * @code
  91. * $oSysTemplate = BxDolTemplate::getInstance();
  92. *
  93. * $oSysTemplate->addCss(array('test1.css', 'test2.css'));
  94. * $oSysTemplate->addJs(array('test1.js', 'test2.js'));
  95. * $oSysTemplate->parseHtmlByName('messageBox.html', array(
  96. * 'id' => $iId,
  97. * 'msgText' => $sText,
  98. * 'bx_if:timer' => array(
  99. * 'condition' => $iTimer > 0,
  100. * 'content' => array(
  101. * 'id' => $iId,
  102. * 'time' => 1000 * $iTimer,
  103. * 'on_close' => $sOnClose,
  104. * )
  105. * ),
  106. * 'bx_if:timer' => array(
  107. * array(
  108. * 'name' => $sName,
  109. * 'title' => $sTitle
  110. * ),
  111. * array(
  112. * 'name' => $sName,
  113. * 'title' => $sTitle
  114. * )
  115. * )
  116. * ));
  117. * @endcode
  118. *
  119. *
  120. * Memberships/ACL:
  121. * Doesn't depend on user's membership.
  122. *
  123. *
  124. * Alerts:
  125. * no alerts available
  126. *
  127. */
  128. class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
  129. {
  130. protected static $_aColors = array(
  131. 'red1' => array(216, 9, 96),
  132. 'red1-dark' => array(194, 7, 86),
  133. 'red2' => array(231, 68, 30),
  134. 'red2-dark' => array(207, 60, 25),
  135. 'red3' => array(243, 143, 0),
  136. 'red3-dark' => array(218, 128, 0),
  137. 'green1' => array(96, 174, 0),
  138. 'green1-dark' => array(86, 156, 0),
  139. 'green2' => array(209, 211, 0),
  140. 'green2-dark' => array(186, 188, 0),
  141. 'green3' => array(48, 116, 36),
  142. 'green3-dark' => array(43, 104, 32),
  143. 'blue1' => array(10, 61, 143),
  144. 'blue1-dark' => array(9, 54, 128),
  145. 'blue2' => array(0, 164, 165),
  146. 'blue2-dark' => array(0, 146, 148),
  147. 'blue3' => array(0, 160, 206),
  148. 'blue3-dark' => array(0, 143, 184),
  149. 'gray' => array(97, 97, 97),
  150. 'gray-dark' => array(87, 87, 87)
  151. );
  152. /**
  153. * Main fields
  154. */
  155. protected $_sName;
  156. protected $_sPrefix;
  157. protected $_sRootPath;
  158. protected $_sRootUrl;
  159. protected $_sSubPath;
  160. protected $_sInjectionsTable;
  161. protected $_sInjectionsCache;
  162. protected $_sCode;
  163. protected $_sCodeKey;
  164. protected $_sKeyWrapperHtml;
  165. protected $_sFolderHtml;
  166. protected $_sFolderCss;
  167. protected $_sFolderImages;
  168. protected $_sFolderIcons;
  169. protected $_aTemplates;
  170. protected $_aLocations;
  171. protected $_aLocationsJs;
  172. /**
  173. * Cache related fields
  174. */
  175. protected $_bCacheEnable;
  176. protected $_sCacheFolderUrl;
  177. protected $_sCachePublicFolderUrl;
  178. protected $_sCachePublicFolderPath;
  179. protected $_sCacheFilePrefix;
  180. protected $_bImagesInline;
  181. protected $_iImagesMaxSize;
  182. protected $_bCssCache;
  183. protected $_bCssMinify;
  184. protected $_bCssArchive;
  185. protected $_sCssCachePrefix;
  186. protected $_bJsCache;
  187. protected $_bJsMinify;
  188. protected $_bJsArchive;
  189. protected $_sJsCachePrefix;
  190. /**
  191. * Less related fields
  192. */
  193. protected $_bLessEnable;
  194. protected $_sLessCachePrefix;
  195. protected $aPage;
  196. protected $aPageContent;
  197. protected $_oTemplateConfig;
  198. protected $_oTemplateFunctions;
  199. /**
  200. * Constructor
  201. */
  202. protected function __construct($sRootPath = BX_DIRECTORY_PATH_ROOT, $sRootUrl = BX_DOL_URL_ROOT)
  203. {
  204. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  205. trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  206. parent::__construct();
  207. $this->_sPrefix = 'BxDolTemplate';
  208. $this->_sRootPath = $sRootPath;
  209. $this->_sRootUrl = $sRootUrl;
  210. $this->_sInjectionsTable = 'sys_injections';
  211. $this->_sInjectionsCache = BX_DOL_TEMPLATE_INJECTIONS_CACHE;
  212. $this->_sCodeKey = BX_DOL_TEMPLATE_CODE_KEY;
  213. list(
  214. $this->_sCode,
  215. $this->_sName,
  216. $this->_sSubPath
  217. ) = self::retrieveCode($this->_sCodeKey, $this->_sRootPath);
  218. if (!$this->_sSubPath)
  219. $this->_sSubPath = 'boonex/' . BX_DOL_TEMPLATE_DEFAULT_CODE . '/';
  220. if (!file_exists(BX_DIRECTORY_PATH_MODULES . $this->_sSubPath)) // just for 8.0.0-A6 upgrade
  221. $this->_sSubPath = 'boonex/uni/';
  222. if(isset($_GET[$this->_sCodeKey])) {
  223. if(BxDolPermalinks::getInstance()->redirectIfNecessary(array($this->_sCodeKey)))
  224. exit;
  225. }
  226. $this->_sKeyWrapperHtml = '__';
  227. $this->_sFolderHtml = '';
  228. $this->_sFolderCss = 'css/';
  229. $this->_sFolderImages = 'images/';
  230. $this->_sFolderIcons = 'images/icons/';
  231. $this->_aTemplates = array('html_tags', 'menu_item_addon');
  232. $this->addLocation('system', $this->_sRootPath, $this->_sRootUrl);
  233. $this->addLocationJs('system_inc_js', BX_DIRECTORY_PATH_INC . 'js/' , BX_DOL_URL_ROOT . 'inc/js/');
  234. $this->addLocationJs('system_inc_js_classes', BX_DIRECTORY_PATH_INC . 'js/classes/' , BX_DOL_URL_ROOT . 'inc/js/classes/');
  235. $this->addLocationJs('system_plugins_public', BX_DIRECTORY_PATH_PLUGINS_PUBLIC, BX_DOL_URL_PLUGINS_PUBLIC);
  236. $this->_bCacheEnable = !defined('BX_DOL_CRON_EXECUTE') && getParam('sys_template_cache_enable') == 'on';
  237. $this->_sCacheFolderUrl = '';
  238. $this->_sCachePublicFolderUrl = BX_DOL_URL_CACHE_PUBLIC;
  239. $this->_sCachePublicFolderPath = BX_DIRECTORY_PATH_CACHE_PUBLIC;
  240. $this->_sCacheFilePrefix = "bx_templ_";
  241. $this->_bImagesInline = getParam('sys_template_cache_image_enable') == 'on';
  242. $this->_iImagesMaxSize = (int)getParam('sys_template_cache_image_max_size') * 1024;
  243. $bArchive = getParam('sys_template_cache_compress_enable') == 'on';
  244. $this->_bCssCache = !defined('BX_DOL_CRON_EXECUTE') && getParam('sys_template_cache_css_enable') == 'on';
  245. $this->_bCssMinify = $this->_bCssCache && getParam('sys_template_cache_minify_css_enable') == 'on';
  246. $this->_bCssArchive = $this->_bCssCache && $bArchive;
  247. $this->_sCssCachePrefix = $this->_sCacheFilePrefix . 'css_';
  248. $this->_bJsCache = !defined('BX_DOL_CRON_EXECUTE') && getParam('sys_template_cache_js_enable') == 'on';
  249. $this->_bJsMinify = $this->_bJsCache && getParam('sys_template_cache_minify_js_enable') == 'on';
  250. $this->_bJsArchive = $this->_bJsCache && $bArchive;
  251. $this->_sJsCachePrefix = $this->_sCacheFilePrefix . 'js_';
  252. $this->_bLessEnable = true;
  253. $this->_sLessCachePrefix = $this->_sCacheFilePrefix . 'less_';
  254. $this->aPage = array();
  255. $this->aPageContent = array();
  256. }
  257. /**
  258. * Prevent cloning the instance
  259. */
  260. public function __clone()
  261. {
  262. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  263. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  264. }
  265. /**
  266. * Get singleton instance of the class
  267. */
  268. public static function getInstance()
  269. {
  270. if(!isset($GLOBALS['bxDolClasses'][__CLASS__])) {
  271. $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolTemplate();
  272. $GLOBALS['bxDolClasses'][__CLASS__]->init();
  273. }
  274. return $GLOBALS['bxDolClasses'][__CLASS__];
  275. }
  276. /**
  277. * Retrieve template code and check whether it's associated with active template or not.
  278. *
  279. * @param string $sCodeKey template's code key.
  280. * @param string $sRootPath path to root directory.
  281. */
  282. public static function retrieveCode($sCodeKey = BX_DOL_TEMPLATE_CODE_KEY, $sRootPath = BX_DIRECTORY_PATH_ROOT)
  283. {
  284. $fCheckCode = function($sCode, $bSetCookie) use($sCodeKey, $sRootPath) {
  285. if(empty($sCode) || !preg_match('/^[A-Za-z0-9_-]+$/', $sCode))
  286. return false;
  287. $aModule = BxDolModuleQuery::getInstance()->getModuleByUri($sCode);
  288. if(empty($aModule) || !is_array($aModule) || (int)$aModule['enabled'] != 1 || !file_exists($sRootPath . 'modules/' . $aModule['path'] . 'data/template/'))
  289. return false;
  290. $oConfig = new BxDolModuleConfig($aModule);
  291. $aResult = array(
  292. $oConfig->getUri(), //--- Template module's URI is used as template Code.
  293. $oConfig->getName(),
  294. $oConfig->getDirectory()
  295. );
  296. if(!$bSetCookie || bx_get('preview'))
  297. return $aResult;
  298. $aUrl = parse_url(BX_DOL_URL_ROOT);
  299. $sPath = isset($aUrl['path']) && !empty($aUrl['path']) ? $aUrl['path'] : '/';
  300. setcookie($sCodeKey, $sCode, time() + 60*60*24*365, $sPath);
  301. return $aResult;
  302. };
  303. $sCode = getParam('template');
  304. if(empty($sCode))
  305. $sCode = BX_DOL_TEMPLATE_DEFAULT_CODE;
  306. $aResult = $fCheckCode($sCode, false);
  307. //--- Check selected template in COOKIE(the lowest priority) ---//
  308. $sCode = !empty($_COOKIE[$sCodeKey]) ? $_COOKIE[$sCodeKey] : '';
  309. $aResultCheck = $fCheckCode($sCode, false);
  310. if($aResultCheck !== false)
  311. $aResult = $aResultCheck;
  312. //--- Check selected template in GET(the highest priority) ---//
  313. $sCode = !empty($_GET[$sCodeKey]) ? $_GET[$sCodeKey] : '';
  314. $aResultCheck = $fCheckCode($sCode, true);
  315. if($aResultCheck !== false)
  316. $aResult = $aResultCheck;
  317. return $aResult;
  318. }
  319. public static function getColorCode($mixedName = false, $fOpacity = false)
  320. {
  321. $aClasses = array_keys(self::$_aColors);
  322. if($mixedName === false || (is_string($mixedName) && !is_numeric($mixedName) && !in_array($mixedName, $aClasses)))
  323. $mixedName = $aClasses[rand(0, count($aClasses) - 1)];
  324. else if(is_numeric($mixedName))
  325. $mixedName = $aClasses[(int)$mixedName % count($aClasses)];
  326. $aColor = self::$_aColors[$mixedName];
  327. if($fOpacity !== false && is_numeric($fOpacity))
  328. $aColor[] = $fOpacity;
  329. return $aColor;
  330. }
  331. public static function getColorClass($sType = BX_DOL_COLOR_FT, $sName = '')
  332. {
  333. $aClasses = array_keys(self::$_aColors);
  334. if(empty($sName) || !in_array($sName, $aClasses))
  335. $sName = $aClasses[rand(0, count($aClasses) - 1)];
  336. $sPrefix = '';
  337. switch ($sType) {
  338. case BX_DOL_COLOR_FT:
  339. $sPrefix = 'col-';
  340. break;
  341. case BX_DOL_COLOR_BG:
  342. $sPrefix = 'bg-col-';
  343. break;
  344. }
  345. return $sPrefix . $sName;
  346. }
  347. /**
  348. * Load templates.
  349. */
  350. function loadTemplates()
  351. {
  352. $aResult = array();
  353. foreach($this->_aTemplates as $sName)
  354. $aResult[$sName] = $this->getHtml($sName . '.html');
  355. $this->_aTemplates = $aResult;
  356. }
  357. /**
  358. * Initialize template engine.
  359. * Note. The method is executed with the system, you shouldn't execute it in your subclasses.
  360. */
  361. function init()
  362. {
  363. $this->loadTemplates();
  364. //--- Load page elements related static variables ---//
  365. $this->aPage = array(
  366. 'name_index' => BX_PAGE_DEFAULT,
  367. 'header' => '',
  368. 'header_text' => '',
  369. 'keywords' => array(),
  370. 'location' => array(),
  371. 'description' => '',
  372. 'robots' => '',
  373. 'css_name' => array(),
  374. 'css_compiled' => array(),
  375. 'css_system' => array(),
  376. 'js_name' => array(),
  377. 'js_compiled' => array(),
  378. 'js_system' => array(),
  379. 'js_options' => array(),
  380. 'js_translations' => array(),
  381. 'js_images' => array(),
  382. 'injections' => array()
  383. );
  384. //--- Load default CSS ---//
  385. $this->addCssSystem(array(
  386. 'common.css',
  387. 'default.less',
  388. 'general.css',
  389. 'icons.css',
  390. 'colors.css',
  391. 'forms.css',
  392. 'media-desktop.css',
  393. 'media-tablet.css',
  394. 'media-phone.css',
  395. 'media-print.css',
  396. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'marka/|marka.min.css',
  397. ));
  398. //--- Load default JS ---//
  399. $this->addJsSystem(array(
  400. 'jquery/jquery.min.js',
  401. 'jquery/jquery-migrate.min.js',
  402. 'jquery-ui/jquery.ui.position.min.js',
  403. 'spin.min.js',
  404. 'jquery.easing.js',
  405. 'jquery.cookie.min.js',
  406. 'moment-with-locales.min.js',
  407. 'functions.js',
  408. 'jquery.webForms.js',
  409. 'jquery.dolPopup.js',
  410. 'jquery.dolConverLinks.js',
  411. 'marka/marka.min.js',
  412. 'headroom.min.js',
  413. ));
  414. //--- Load translations in JS ---//
  415. bx_import('BxDolLanguages');
  416. $this->addJsTranslation(array(
  417. '_Are_you_sure',
  418. '_error occured',
  419. '_sys_loading',
  420. '_copyright'
  421. ));
  422. //--- Load Embed.ly if Key and Pattern are available ---//
  423. $bEmbedly = !empty(getParam('sys_embedly_api_key'));
  424. if($bEmbedly) {
  425. $this->addJsSystem(array(
  426. 'jquery.embedly.min.js',
  427. ));
  428. $this->addJsOption(array(
  429. 'sys_embedly_api_key',
  430. 'sys_embedly_api_pattern',
  431. ));
  432. }
  433. //--- Load Iframely if Key is available and Embed.ly is disabled ---//
  434. $sIframely = getParam('sys_iframely_api_key');
  435. $bIframely = !$bEmbedly && !empty($sIframely);
  436. if($bIframely) {
  437. $this->addJsSystem(array(
  438. bx_proto() . '://cdn.iframe.ly/embed.js?key=' . md5($sIframely)
  439. ));
  440. $this->addJsOption(array(
  441. 'sys_iframely_api_key'
  442. ));
  443. }
  444. //--- Load injection's cache ---//
  445. if (getParam('sys_db_cache_enable')) {
  446. $oDb = BxDolDb::getInstance();
  447. $oCache = $oDb->getDbCacheObject();
  448. $sCacheKey = $oDb->genDbCacheKey($this->_sInjectionsCache);
  449. $aInjections = $oCache->getData($sCacheKey);
  450. if ($aInjections === null) {
  451. $aInjections = $this->getInjectionsData();
  452. $oCache->setData ($sCacheKey, $aInjections);
  453. }
  454. }
  455. else
  456. $aInjections = $this->getInjectionsData();
  457. $this->aPage['injections'] = $aInjections;
  458. bx_import('BxTemplConfig'); // TODO: for some reason autoloader isn't working here....
  459. $this->_oTemplateConfig = BxTemplConfig::getInstance();
  460. bx_import('BxTemplFunctions');
  461. $this->_oTemplateFunctions = BxTemplFunctions::getInstance($this);
  462. }
  463. protected function getInjectionsData ()
  464. {
  465. $oDb = BxDolDb::getInstance();
  466. $aInjections = $oDb->getAll("SELECT `page_index`, `name`, `key`, `type`, `data`, `replace` FROM `" . $this->_sInjectionsTable . "` WHERE `active`='1'");
  467. if (!$aInjections)
  468. return array();
  469. foreach ($aInjections as $aInjection)
  470. $aInjections['page_' . $aInjection['page_index']][$aInjection['key']][] = $aInjection;
  471. return $aInjections;
  472. }
  473. /**
  474. * Set page name index
  475. * @param int $i name index
  476. */
  477. function setPageNameIndex($i)
  478. {
  479. $this->aPage['name_index'] = $i;
  480. }
  481. /**
  482. * Get page name index
  483. * @return int $i name index
  484. */
  485. function getPageNameIndex()
  486. {
  487. return isset($this->aPage['name_index']) ? (int)$this->aPage['name_index'] : 0;
  488. }
  489. /**
  490. * Set page header
  491. * @param string $s page header
  492. */
  493. function setPageHeader($s)
  494. {
  495. $this->aPage['header'] = $s;
  496. }
  497. /**
  498. * Get page header
  499. * @return string $s page header
  500. */
  501. function getPageHeader()
  502. {
  503. return $this->aPage['header'];
  504. }
  505. /**
  506. * Set page params. Available page params are: name_index, header
  507. * @param array $a page params
  508. */
  509. function setPageParams($a)
  510. {
  511. if (!empty($this->aPage))
  512. $this->aPage = array_merge($this->aPage, $a);
  513. else
  514. $this->aPage = $a;
  515. }
  516. /**
  517. * Get page params.
  518. * @return array $a page params
  519. */
  520. function getPageParams()
  521. {
  522. return $this->aPage;
  523. }
  524. /**
  525. * Set page description.
  526. *
  527. * @param string $sDescription necessary page description.
  528. */
  529. function setPageDescription($sDescription)
  530. {
  531. $this->aPage['description'] = $sDescription;
  532. }
  533. /**
  534. * Set page meta robots.
  535. *
  536. * @param string $s page meta robots.
  537. */
  538. function setPageMetaRobots($s)
  539. {
  540. $this->aPage['robots'] = $s;
  541. }
  542. /**
  543. * Set page content for some variable.
  544. * @param string $sVar name of content variable
  545. * @param string $sContent content for $sVar variable
  546. * @param int $iIndex optional page index, default is index which was set before with @see setPageNameIndex function, or 0
  547. */
  548. function setPageContent($sVar, $sContent, $iIndex = false)
  549. {
  550. $i = false !== $iIndex ? $iIndex : $this->getPageNameIndex();
  551. $this->aPageContent[$i][$sVar] = $sContent;
  552. }
  553. /**
  554. * Get page content for some variable.
  555. * @param string $sVar name of content variable
  556. * @param int $iIndex optional page index, default is index which was set before with @see setPageNameIndex function, or 0
  557. * @return string page content for some variable or for the whole page.
  558. */
  559. function getPageContent($sVar = false, $iIndex = false)
  560. {
  561. $i = false !== $iIndex ? $iIndex : $this->getPageNameIndex();
  562. return false !== $sVar ? $this->aPageContent[$i][$sVar] : $this->aPageContent[$i];
  563. }
  564. /**
  565. * Get currently active template name.
  566. *
  567. * @return string template's name.
  568. */
  569. function getName()
  570. {
  571. return $this->_sName;
  572. }
  573. /**
  574. * Get currently active template code.
  575. *
  576. * @return string template's code.
  577. */
  578. function getCode()
  579. {
  580. return $this->_sCode;
  581. }
  582. /**
  583. * Get currently active template path.
  584. *
  585. * @return string template's path.
  586. */
  587. function getPath()
  588. {
  589. return $this->_sSubPath;
  590. }
  591. /**
  592. * Set page title.
  593. * @deprecated use setPageHeader
  594. *
  595. * @param string $sTitle necessary page title.
  596. */
  597. function setPageTitle($sTitle)
  598. {
  599. $this->setPageHeader($sTitle);
  600. }
  601. /**
  602. * Set page's main box title.
  603. * @deprecated use setPageParams
  604. *
  605. * @param string $sTitle necessary page's main box title.
  606. */
  607. function setPageMainBoxTitle($sTitle)
  608. {
  609. $this->setPageParams(array('header_text' => $sTitle));
  610. }
  611. /**
  612. * Check whether location exists or not.
  613. * @param string $sKey - location's unique key.
  614. */
  615. function isLocation($sKey)
  616. {
  617. return isset($this->_aLocations[$sKey]);
  618. }
  619. /**
  620. * Add location in array of locations.
  621. * Note. Location is the path/url to folder where 'templates' folder is stored.
  622. *
  623. * @param string $sKey - location's unique key.
  624. * @param string $sLocationPath - location's path. For modules: '[path_to_script]/modules/[vendor_name]/[module_name]/'
  625. * @param string $sLocationUrl - location's url. For modules: '[url_to_script]/modules/[vendor_name]/[module_name]/'
  626. */
  627. function addLocation($sKey, $sLocationPath, $sLocationUrl)
  628. {
  629. $this->_aLocations[$sKey] = array(
  630. 'path' => $sLocationPath,
  631. 'url' => $sLocationUrl,
  632. );
  633. return $sKey;
  634. }
  635. /**
  636. * Add dynamic location.
  637. *
  638. * @param string $sLocationPath - location's path. For modules: '[path_to_script]/modules/[vendor_name]/[module_name]/'
  639. * @param string $sLocationUrl - location's url. For modules: '[url_to_script]/modules/[vendor_name]/[module_name]/'
  640. * @return location key. Is needed to remove the location.
  641. */
  642. function addDynamicLocation($sLocationPath, $sLocationUrl)
  643. {
  644. $sLocationKey = time() . mt_rand();
  645. $this->addLocation($sLocationKey, $sLocationPath, $sLocationUrl);
  646. return $sLocationKey;
  647. }
  648. /**
  649. * Remove location from array of locations.
  650. * Note. Location is the path/url to folder where templates are stored.
  651. *
  652. * @param string $sKey - location's unique key.
  653. */
  654. function removeLocation($sKey)
  655. {
  656. if(isset($this->_aLocations[$sKey]))
  657. unset($this->_aLocations[$sKey]);
  658. }
  659. /**
  660. * Add JS location in array of JS locations.
  661. * Note. Location is the path/url to folder where JS files are stored.
  662. *
  663. * @param string $sKey - location's unique key.
  664. * @param string $sLocationPath - location's path. For modules: '[path_to_script]/modules/[vendor_name]/[module_name]/js/'
  665. * @param string $sLocationUrl - location's url. For modules: '[url_to_script]/modules/[vendor_name]/[module_name]/js/'
  666. */
  667. function addLocationJs($sKey, $sLocationPath, $sLocationUrl)
  668. {
  669. $this->_aLocationsJs[$sKey] = array(
  670. 'path' => $sLocationPath,
  671. 'url' => $sLocationUrl
  672. );
  673. }
  674. /**
  675. * Add dynamic JS location.
  676. *
  677. * @param string $sLocationPath - location's path. For modules: '[path_to_script]/modules/[vendor_name]/[module_name]/'
  678. * @param string $sLocationUrl - location's url. For modules: '[url_to_script]/modules/[vendor_name]/[module_name]/'
  679. * @return location key. Is needed to remove the location.
  680. */
  681. function addDynamicLocationJs($sLocationPath, $sLocationUrl)
  682. {
  683. $sLocationKey = time() . mt_rand();
  684. $this->addLocationJs($sLocationKey, $sLocationPath, $sLocationUrl);
  685. return $sLocationKey;
  686. }
  687. /**
  688. * Remove JS location from array of locations.
  689. * Note. Location is the path/url to folder where templates are stored.
  690. *
  691. * @param string $sKey - JS location's unique key.
  692. */
  693. function removeLocationJs($sKey)
  694. {
  695. if(isset($this->_aLocationsJs[$sKey]))
  696. unset($this->_aLocationsJs[$sKey]);
  697. }
  698. /**
  699. * Add Option in JS output.
  700. *
  701. * @param mixed $mixedName option's name or an array of options' names.
  702. */
  703. function addJsOption($mixedName)
  704. {
  705. if(is_string($mixedName))
  706. $mixedName = array($mixedName);
  707. foreach($mixedName as $sName)
  708. $this->aPage['js_options'][$sName] = getParam($sName);
  709. }
  710. /**
  711. * Add language translation for key in JS output.
  712. *
  713. * @param mixed $mixedKey language key or an array of keys.
  714. */
  715. function addJsTranslation($mixedKey)
  716. {
  717. if(is_string($mixedKey))
  718. $mixedKey = array($mixedKey);
  719. foreach($mixedKey as $sKey)
  720. $this->aPage['js_translations'][$sKey] = _t($sKey, '{0}', '{1}');
  721. }
  722. /**
  723. * Add image in JS output.
  724. *
  725. * @param array $aImages an array of image descriptors.
  726. * The descriptor is a key/value pear in the array of descriptors.
  727. */
  728. function addJsImage($aImages)
  729. {
  730. if(!is_array($aImages))
  731. return;
  732. foreach($aImages as $sKey => $sFile) {
  733. $sUrl = $this->getImageUrl($sFile);
  734. if(empty($sUrl))
  735. continue;
  736. $this->aPage['js_images'][$sKey] = $sUrl;
  737. }
  738. }
  739. /**
  740. * Add icon in JS output.
  741. *
  742. * @param array $aIcons an array of icons descriptors.
  743. * The descriptor is a key/value pear in the array of descriptors.
  744. */
  745. function addJsIcon($aIcons)
  746. {
  747. if(!is_array($aIcons))
  748. return;
  749. foreach($aIcons as $sKey => $sFile) {
  750. $sUrl = $this->getIconUrl($sFile);
  751. if(empty($sUrl))
  752. continue;
  753. $this->aPage['js_images'][$sKey] = $sUrl;
  754. }
  755. }
  756. /**
  757. * Add CSS style.
  758. *
  759. * @param string $sName CSS class name.
  760. * @param string $sContent CSS class styles.
  761. */
  762. function addCssStyle($sName, $sContent)
  763. {
  764. $this->aPage['css_styles'][$sName] = $sContent;
  765. }
  766. /**
  767. * Set page keywords.
  768. *
  769. * @param mixed $mixedKeywords necessary page keywords(string - single keyword, array - an array of keywords).
  770. * @param string $sDevider - string devider.
  771. */
  772. function addPageKeywords($mixedKeywords, $sDevider = ',')
  773. {
  774. if(is_string($mixedKeywords))
  775. $mixedKeywords = strpos($mixedKeywords, $sDevider) !== false ? explode($sDevider, $mixedKeywords) : array($mixedKeywords);
  776. foreach($mixedKeywords as $iKey => $sValue)
  777. $mixedKeywords[$iKey] = trim($sValue);
  778. $this->aPage['keywords'] = isset($this->aPage['keywords']) && is_array($this->aPage['keywords']) ? array_merge($this->aPage['keywords'], $mixedKeywords) : $mixedKeywords;
  779. }
  780. /**
  781. * Set page locatoin coordinates.
  782. *
  783. * @param $fLat latitude
  784. * @param $fLng longitude
  785. */
  786. function addPageMetaLocation($fLat, $fLng, $sCountryCode)
  787. {
  788. $this->aPage['location'] = array('lat' => $fLat, 'lng' => $fLng, 'country' => $sCountryCode);
  789. }
  790. /**
  791. * Set page meta image.
  792. *
  793. * @param $sImageUrl meta image url
  794. */
  795. function addPageMetaImage($sImageUrl)
  796. {
  797. $this->aPage['image'] = $sImageUrl;
  798. }
  799. /**
  800. * Set page rss link.
  801. *
  802. * @param $sTitle - rss feed title
  803. * @param $sUrl - rss feed URL
  804. */
  805. function addPageRssLink($sTitle, $sUrl)
  806. {
  807. if (!isset($this->aPage['rss']))
  808. $this->aPage['rss'] = array('title' => $sTitle, 'url' => $sUrl);
  809. else
  810. $this->aPage['rss'] = false;
  811. }
  812. /**
  813. * Returns page meta info, like meta keyword, meta description, location, etc
  814. */
  815. function getMetaInfo()
  816. {
  817. $sRet = '';
  818. if (!empty($this->aPage['keywords']) && is_array($this->aPage['keywords']))
  819. $sRet .= '<meta name="keywords" content="' . bx_html_attribute(implode(',', $this->aPage['keywords'])) . '" />';
  820. $bDescription = !empty($this->aPage['description']) && is_string($this->aPage['description']);
  821. if ($bDescription)
  822. $sRet .= '<meta name="description" content="' . bx_html_attribute($this->aPage['description']) . '" />';
  823. if (!empty($this->aPage['location']) && isset($this->aPage['location']['lat']) && isset($this->aPage['location']['lng']) && isset($this->aPage['location']['country']))
  824. $sRet .= '
  825. <meta name="ICBM" content="' . $this->aPage['location']['lat'] . ';' . $this->aPage['location']['lng'] . '" />
  826. <meta name="geo.position" content="' . $this->aPage['location']['lat'] . ';' . $this->aPage['location']['lng'] . '" />
  827. <meta name="geo.region" content="' . bx_html_attribute($this->aPage['location']['country']) . '" />';
  828. if (!empty($this->aPage['image'])) {
  829. $sRet .= '<meta property="og:image" content="' . $this->aPage['image'] . '" />';
  830. $sRet .= '
  831. <meta name="twitter:card" content="summary_large_image" />
  832. <meta name="twitter:title" content="' . (isset($this->aPage['header']) ? bx_html_attribute(strip_tags($this->aPage['header'])) : '') . '" />
  833. <meta name="twitter:description" content="' . ($bDescription ? bx_html_attribute($this->aPage['description']) : '') . '" />
  834. <meta name="twitter:image" content="' . $this->aPage['image'] . '" />';
  835. }
  836. $oFunctions = BxTemplFunctions::getInstance();
  837. $sRet .= $oFunctions->getManifests();
  838. $sRet .= $oFunctions->getMetaIcons();
  839. if (!empty($this->aPage['rss']) && !empty($this->aPage['rss']['url']))
  840. $sRet .= '<link rel="alternate" type="application/rss+xml" title="' . bx_html_attribute($this->aPage['rss']['title'], BX_ESCAPE_STR_QUOTE) . '" href="' . $this->aPage['rss']['url'] . '" />';
  841. return $sRet;
  842. }
  843. /**
  844. * Get template, which was loaded earlier.
  845. * @see method this->loadTemplates and field this->_aTemplates
  846. *
  847. * @param string $sName - template name.
  848. * @return string template's content.
  849. */
  850. public function getTemplate($sName)
  851. {
  852. return $this->_aTemplates[$sName];
  853. }
  854. /**
  855. * Get template functions object.
  856. * @see BxBaseFunctions
  857. */
  858. public function getTemplateFunctions()
  859. {
  860. return $this->_oTemplateFunctions;
  861. }
  862. /**
  863. * Get icon template in dependence of a value, provided in $mixedId.
  864. *
  865. * @param mixed $mixedId numeric id from Storage, string with template's file name or string with font icon.
  866. */
  867. public function getIcon($mixedId, $aParams = array())
  868. {
  869. return $this->_getImage('icon', $mixedId, $aParams);
  870. }
  871. /**
  872. * Get image template in dependence of a value, provided in $mixedId.
  873. *
  874. * @param mixed $mixedId numeric id from Storage, string with template's file name or string with font icon.
  875. */
  876. public function getImage($mixedId, $aParams = array())
  877. {
  878. return $this->_getImage('image', $mixedId, $aParams);
  879. }
  880. protected function _getImage($sType, $mixedId, $aParams = array())
  881. {
  882. $sUrl = "";
  883. $aType2Method = array('image' => 'getImageUrl', 'icon' => 'getIconUrl');
  884. //--- Check in System Storage.
  885. if(is_numeric($mixedId) && (int)$mixedId > 0) {
  886. $sStorage = BX_DOL_STORAGE_OBJ_IMAGES;
  887. if(!empty($aParams['storage'])) {
  888. $sStorage = $aParams['storage'];
  889. unset($aParams['storage']);
  890. }
  891. if(($sResult = BxDolStorage::getObjectInstance($sStorage)->getFileUrlById((int)$mixedId)) !== false)
  892. $sUrl = $sResult;
  893. }
  894. //--- Check in template folders.
  895. if($sUrl == "" && is_string($mixedId) && strpos($mixedId, '.') !== false)
  896. $sUrl = $this->{$aType2Method[$sType]}($mixedId);
  897. if($sUrl != "")
  898. return $this->parseImage($sUrl, array(
  899. 'class' => isset($aParams['class']) && !empty($aParams['class']) ? $aParams['class'] : '',
  900. 'alt' => isset($aParams['alt']) && !empty($aParams['alt']) ? $aParams['alt'] : ''
  901. ));
  902. //--- Use iconic font.
  903. return $this->parseIcon($mixedId);
  904. }
  905. /**
  906. * Get full URL for the icon.
  907. *
  908. * @param string $sName icon's file name.
  909. * @param string $sCheckIn where the content would be searched(base, template, both)
  910. * @return string full URL.
  911. */
  912. function getIconUrl($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  913. {
  914. $sContent = "";
  915. if(($sContent = $this->_getInlineData('icon', $sName, $sCheckIn)) !== false)
  916. return $sContent;
  917. return $this->_getAbsoluteLocation('url', $this->_sFolderIcons, $sName, $sCheckIn);
  918. }
  919. /**
  920. * Get absolute Path for the icon.
  921. *
  922. * @param string $sName - icon's file name.
  923. * @param string $sCheckIn where the content would be searched(base, template, both)
  924. * @return string absolute path.
  925. */
  926. function getIconPath($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  927. {
  928. return $this->_getAbsoluteLocation('path', $this->_sFolderIcons, $sName, $sCheckIn);
  929. }
  930. /**
  931. * Get full URL for the image.
  932. *
  933. * @param string $sName - images's file name.
  934. * @param string $sCheckIn where the content would be searched(base, template, both)
  935. * @return string full URL.
  936. */
  937. function getImageUrl($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  938. {
  939. $sContent = "";
  940. if(($sContent = $this->_getInlineData('image', $sName, $sCheckIn)) !== false)
  941. return $sContent;
  942. return $this->_getAbsoluteLocation('url', $this->_sFolderImages, $sName, $sCheckIn);
  943. }
  944. /**
  945. * Get absolute Path for the image.
  946. *
  947. * @param string $sName - image's file name.
  948. * @param string $sCheckIn where the content would be searched(base, template, both)
  949. * @return string absolute path.
  950. */
  951. function getImagePath($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  952. {
  953. return $this->_getAbsoluteLocation('path', $this->_sFolderImages, $sName, $sCheckIn);
  954. }
  955. /**
  956. * Get full URL of CSS file.
  957. *
  958. * @param string $sName - CSS file name.
  959. * @param string $sCheckIn where the content would be searched(base, template, both)
  960. * @return string full URL.
  961. */
  962. function getCssUrl($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  963. {
  964. return $this->_getAbsoluteLocation('url', $this->_sFolderCss, $sName, $sCheckIn);
  965. }
  966. /**
  967. * Get full Path of CSS file.
  968. *
  969. * @param string $sName - CSS file name.
  970. * @param string $sCheckIn where the content would be searched(base, template, both)
  971. * @return string full URL.
  972. */
  973. function getCssPath($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  974. {
  975. return $this->_getAbsoluteLocation('path', $this->_sFolderCss, $sName, $sCheckIn);
  976. }
  977. /**
  978. * Get full URL of JS file.
  979. *
  980. * @param string $sName - JS file name.
  981. * @return string full URL.
  982. */
  983. function getJsUrl($sName)
  984. {
  985. return $this->_getAbsoluteLocationJs('url', $sName);
  986. }
  987. /**
  988. * Get full Path of JS file.
  989. *
  990. * @param string $sName - JS file name.
  991. * @return string full URL.
  992. */
  993. function getJsPath($sName)
  994. {
  995. return $this->_getAbsoluteLocationJs('path', $sName);
  996. }
  997. /**
  998. * Get full URL of Template (HTML) file.
  999. *
  1000. * @param string $sName - Template file name.
  1001. * @return string full URL.
  1002. */
  1003. function getTemplateUrl($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  1004. {
  1005. return $this->_getAbsoluteLocation('url', $this->_sFolderHtml, $sName, $sCheckIn);
  1006. }
  1007. /**
  1008. * Get full Path of JS file.
  1009. *
  1010. * @param string $sName - JS file name.
  1011. * @return string full URL.
  1012. */
  1013. function getTemplatePath($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  1014. {
  1015. return $this->_getAbsoluteLocation('path', $this->_sFolderHtml, $sName, $sCheckIn);
  1016. }
  1017. /**
  1018. * Get menu.
  1019. * @param $s menu object name
  1020. * @return html or empty string
  1021. */
  1022. function getMenu ($s)
  1023. {
  1024. $oMenu = BxDolMenu::getObjectInstance($s);
  1025. return $oMenu ? $oMenu->getCode () : '';
  1026. }
  1027. /**
  1028. * Get content of HTML file.
  1029. *
  1030. * @param string $sName - HTML file name.
  1031. * @param string $sCheckIn where the content would be searched(base, template, both)
  1032. * @return string full content of the file and false on failure.
  1033. */
  1034. function getHtml($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  1035. {
  1036. $sAbsolutePath = $this->_getAbsoluteLocation('path', $this->_sFolderHtml, $sName, $sCheckIn);
  1037. return !empty($sAbsolutePath) ? trim(file_get_contents($sAbsolutePath)) : false;
  1038. }
  1039. /**
  1040. * Parse HTML template. Search for the template with accordance to it's file name.
  1041. *
  1042. * @see allows to use cache.
  1043. *
  1044. * @param string $sName - HTML file name.
  1045. * @param array $aVariables - key/value pairs. key should be the same as template's key, but without prefix and postfix.
  1046. * @param mixed $mixedKeyWrapperHtml - key wrapper(string value if left and right parts are the same, array(left, right) otherwise).
  1047. * @param string $sCheckIn where the content would be searched(base, template, both)
  1048. * @return string the result of operation.
  1049. */
  1050. function parseHtmlByName($sName, $aVariables, $mixedKeyWrapperHtml = null, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  1051. {
  1052. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->beginTemplate($sName, $sRand = time().rand());
  1053. if (($sContent = $this->getCached($sName, $aVariables, $mixedKeyWrapperHtml, $sCheckIn)) !== false) {
  1054. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->endTemplate($sName, $sRand, $sRet, true);
  1055. return $sContent;
  1056. }
  1057. $sRet = '';
  1058. if (($sContent = $this->getHtml($sName, $sCheckIn)) !== false)
  1059. $sRet = $this->_parseContent($sContent, $aVariables, $mixedKeyWrapperHtml);
  1060. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->endTemplate($sName, $sRand, $sRet, false);
  1061. return $sRet;
  1062. }
  1063. /**
  1064. * Parse HTML template.
  1065. *
  1066. * @see Doesn't allow to use cache.
  1067. *
  1068. * @param string $sContent - HTML file content.
  1069. * @param array $aVariables - key/value pairs. key should be the same as template's key, but without prefix and postfix.
  1070. * @param mixed $mixedKeyWrapperHtml - key wrapper(string value if left and right parts are the same, array(left, right) otherwise).
  1071. * @return string the result of operation.
  1072. */
  1073. function parseHtmlByContent($sContent, $aVariables, $mixedKeyWrapperHtml = null)
  1074. {
  1075. if(empty($sContent))
  1076. return "";
  1077. return $this->_parseContent($sContent, $aVariables, $mixedKeyWrapperHtml);
  1078. }
  1079. /**
  1080. * Parse earlier loaded HTML template.
  1081. *
  1082. * @see Doesn't allow to use cache.
  1083. *
  1084. * @param string $sName - template name.
  1085. * @param array $aVariables - key/value pairs. Key should be the same as template's key, excluding prefix and postfix.
  1086. * @return string the result of operation.
  1087. * @see $this->_aTemplates
  1088. */
  1089. function parseHtmlByTemplateName($sName, $aVariables, $mixedKeyWrapperHtml = null)
  1090. {
  1091. if(!isset($this->_aTemplates[$sName]) || empty($this->_aTemplates[$sName]))
  1092. return "";
  1093. return $this->_parseContent($this->_aTemplates[$sName], $aVariables, $mixedKeyWrapperHtml);
  1094. }
  1095. /**
  1096. * Parse page HTML template. Search for the page's template with accordance to it's file name.
  1097. *
  1098. * @see allows to use cache.
  1099. *
  1100. * @param string $sName - HTML file name.
  1101. * @param array $aVariables - key/value pairs. key should be the same as template's key, but without prefix and postfix.
  1102. * @return string the result of operation.
  1103. */
  1104. function parsePageByName($sName, $aVariables)
  1105. {
  1106. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->beginPage($sName);
  1107. $sContent = $this->parseHtmlByName($sName, $aVariables, $this->_sKeyWrapperHtml, BX_DOL_TEMPLATE_CHECK_IN_BOTH);
  1108. if(empty($sContent))
  1109. $sContent = $this->parseHtmlByName('default.html', $aVariables, $this->_sKeyWrapperHtml, BX_DOL_TEMPLATE_CHECK_IN_BOTH);
  1110. //--- Add CSS and JS at the very last ---//
  1111. if(strpos($sContent, '<bx_include_css_styles />') !== false) {
  1112. $aStyles = array(
  1113. 'display' => 'none !important'
  1114. );
  1115. if(isLogged())
  1116. $this->addCssStyle('.bx-hide-when-logged-in', $aStyles);
  1117. else
  1118. $this->addCssStyle('.bx-hide-when-logged-out', $aStyles);
  1119. $sContent = str_replace('<bx_include_css_styles />', $this->includeCssStyles(), $sContent);
  1120. }
  1121. if(strpos($sContent , '<bx_include_css_system />') !== false) {
  1122. $sContent = str_replace('<bx_include_css_system />', $this->includeFiles('css', true), $sContent);
  1123. }
  1124. if(strpos($sContent , '<bx_include_css />') !== false) {
  1125. if (!empty($this->aPage['css_name']))
  1126. $this->addCss($this->aPage['css_name']);
  1127. $sContent = str_replace('<bx_include_css />', $this->includeFiles('css'), $sContent);
  1128. }
  1129. if(strpos($sContent , '<bx_include_js_system />') !== false) {
  1130. $sContent = str_replace('<bx_include_js_system />', $this->includeFiles('js', true), $sContent);
  1131. }
  1132. if(strpos($sContent , '<bx_include_js />') !== false) {
  1133. if (!empty($this->aPage['js_name']))
  1134. $this->addJs($this->aPage['js_name']);
  1135. $sContent = str_replace('<bx_include_js />', $this->includeFiles('js'), $sContent);
  1136. }
  1137. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->endPage($sContent);
  1138. return $sContent;
  1139. }
  1140. /**
  1141. * Parse system keys.
  1142. *
  1143. * @param string $sKey key
  1144. * @return string value associated with the key.
  1145. */
  1146. function parseSystemKey($sKey, $mixedKeyWrapperHtml = null, $bProcessInjection = true)
  1147. {
  1148. $aKeyWrappers = $this->_getKeyWrappers($mixedKeyWrapperHtml);
  1149. $sRet = '';
  1150. switch( $sKey ) {
  1151. case 'page_charset':
  1152. $sRet = 'UTF-8';
  1153. break;
  1154. case 'page_robots':
  1155. if(!empty($this->aPage['robots']) && is_string($this->aPage['robots']))
  1156. $sRet = '<meta name="robots" content="' . bx_html_attribute($this->aPage['robots']) . '" />';
  1157. break;
  1158. case 'meta_info':
  1159. $sRet = $this->getMetaInfo();
  1160. break;
  1161. case 'page_header':
  1162. if(isset($this->aPage['header']))
  1163. $sRet = bx_process_output(strip_tags($this->aPage['header']));
  1164. break;
  1165. case 'page_header_text':
  1166. if(isset($this->aPage['header_text']))
  1167. $sRet = bx_process_output($this->aPage['header_text']);
  1168. break;
  1169. case 'popup_loading':
  1170. $s = $this->parsePageByName('popup_loading.html', array());
  1171. $sRet = BxTemplFunctions::getInstance()->transBox('bx-popup-loading', $s, true);
  1172. $oSearch = new BxTemplSearch();
  1173. $oSearch->setLiveSearch(true);
  1174. $sRet .= $this->parsePageByName('search.html', array(
  1175. 'search_form' => $oSearch->getForm(BX_DB_CONTENT_ONLY),
  1176. 'results' => $oSearch->getResultsContainer(),
  1177. ));
  1178. $sRet .= $this->getMenu ('sys_site');
  1179. $sRet .= isLogged() ? $this->getMenu ('sys_add_content') : '';
  1180. $sRet .= isLogged() ? $this->getMenu ('sys_account_popup') : '';
  1181. break;
  1182. case 'lang':
  1183. $sRet = bx_lang_name();
  1184. break;
  1185. case 'main_logo':
  1186. $sRet = BxTemplFunctions::getInstance()->getMainLogo();
  1187. break;
  1188. case 'informer':
  1189. $oInformer = BxDolInformer::getInstance($this);
  1190. $sRet = $oInformer ? $oInformer->display() : '';
  1191. break;
  1192. case 'cover':
  1193. $oCover = BxDolCover::getInstance($this);
  1194. if(!$oCover)
  1195. break;
  1196. $bCover = true;
  1197. $oPage = BxDolPage::getObjectInstanceByURI();
  1198. if($oPage !== false) {
  1199. $bCover = $oPage->isPageCover();
  1200. if($bCover && !$oCover->isCover()) {
  1201. $aCover = $oPage->getPageCoverImage();
  1202. if(!empty($aCover))
  1203. $oCover->setCoverImageUrl($aCover);
  1204. }
  1205. }
  1206. $sRet = $bCover ? $oCover->display() : $oCover->displayEmpty();
  1207. break;
  1208. case 'dol_images':
  1209. $sRet = $this->_processJsImages();
  1210. break;
  1211. case 'dol_lang':
  1212. $sRet = $this->_processJsTranslations();
  1213. break;
  1214. case 'dol_options':
  1215. $sRet = $this->_processJsOptions();
  1216. break;
  1217. case 'copyright':
  1218. $sRet = _t( '_copyright', date('Y') ) . getVersionComment();
  1219. break;
  1220. case 'copyright_attr':
  1221. $sRet = bx_html_attribute(_t('_copyright', date('Y')));
  1222. break;
  1223. case 'extra_js':
  1224. $sRet = empty($this->aPage['extra_js']) ? '' : $this->aPage['extra_js'];
  1225. break;
  1226. case 'is_profile_page':
  1227. $sRet = (defined('BX_PROFILE_PAGE')) ? 'true' : 'false';
  1228. break;
  1229. default:
  1230. $sRet = ($sTemplAdd = BxTemplFunctions::getInstance()->TemplPageAddComponent($sKey)) !== false ? $sTemplAdd : $aKeyWrappers['left'] . $sKey . $aKeyWrappers['right'];
  1231. }
  1232. if($bProcessInjection)
  1233. $sRet = $this->processInjection($this->getPageNameIndex(), $sKey, $sRet);
  1234. return $sRet;
  1235. }
  1236. /**
  1237. *
  1238. * Enter description here ...
  1239. * @param string $sName tag name (i, span, div, img, a, button, custom)
  1240. * @param string $sContent tag content (HTML)
  1241. * @param array $aAttrs an array of key - value pairs of attributes
  1242. * @param string $sTemplate
  1243. */
  1244. public function parseHtmlTag($sName, $sContent, $aAttrs = array(), $sTemplate = 'html_tags')
  1245. {
  1246. $aTags = array(BX_DOL_TEMPLATE_TAG_I, BX_DOL_TEMPLATE_TAG_SPAN, BX_DOL_TEMPLATE_TAG_DIV, BX_DOL_TEMPLATE_TAG_IMG, BX_DOL_TEMPLATE_TAG_A, BX_DOL_TEMPLATE_TAG_BUTTON, BX_DOL_TEMPLATE_TAG_CUSTOM);
  1247. $aTmplVarsAttrs = array();
  1248. foreach($aAttrs as $sKey => $sValue)
  1249. $aTmplVarsAttrs[] = array('key' => $sKey, 'value' => bx_html_attribute($sValue));
  1250. $aTmplVars = array();
  1251. foreach($aTags as $sTag) {
  1252. $aTmplVarsTag = array();
  1253. $bTmplVarsTag = $sTag == $sName;
  1254. if($bTmplVarsTag)
  1255. $aTmplVarsTag = array(
  1256. 'content' => $sContent,
  1257. 'bx_repeat:attrs' => $aTmplVarsAttrs
  1258. );
  1259. $aTmplVars['bx_if:' . $sTag] = array(
  1260. 'condition' => $bTmplVarsTag,
  1261. 'content' => $aTmplVarsTag
  1262. );
  1263. }
  1264. $sMethod = '';
  1265. if(strpos($sTemplate, '.') !== false)
  1266. $sMethod = 'parseHtmlByName';
  1267. else if(array_key_exists($sTemplate, $this->_aTemplates))
  1268. $sMethod = 'parseHtmlByTemplateName';
  1269. else
  1270. $sMethod = 'parseHtmlByContent';
  1271. return $this->$sMethod($sTemplate, $aTmplVars);
  1272. }
  1273. /**
  1274. * Parse tag <A>
  1275. *
  1276. * @param string $sLink link URL
  1277. * @param string $sContent link content
  1278. * @param array $aAttrs an array of key => value pairs
  1279. */
  1280. function parseLink($sLink, $sContent, $aAttrs = array())
  1281. {
  1282. if(!is_array($aAttrs))
  1283. $aAttrs = array();
  1284. $aAttrs['href'] = $sLink;
  1285. return $this->parseHtmlTag(BX_DOL_TEMPLATE_TAG_A, $sContent, $aAttrs);
  1286. }
  1287. /**
  1288. * Parse tag <BUTTON>
  1289. *
  1290. * @param string $sContent link content
  1291. * @param array $aAttrs an array of key => value pairs
  1292. */
  1293. function parseButton($sContent, $aAttrs = array())
  1294. {
  1295. return $this->parseHtmlTag(BX_DOL_TEMPLATE_TAG_BUTTON, $sContent, $aAttrs);
  1296. }
  1297. /**
  1298. * Parse tag <IMG>
  1299. *
  1300. * @param string $sLink URL to image source
  1301. * @param array $aAttrs an array of key => value pairs
  1302. */
  1303. function parseImage($sLink, $aAttrs = array())
  1304. {
  1305. if(!is_array($aAttrs))
  1306. $aAttrs = array();
  1307. $aAttrs['src'] = $sLink;
  1308. return $this->parseHtmlTag(BX_DOL_TEMPLATE_TAG_IMG, '', $aAttrs);
  1309. }
  1310. /**
  1311. * Parse font based icon in <I> tag
  1312. *
  1313. * @param string $sName font icon name
  1314. * @param array $aAttrs an array of key => value pairs
  1315. */
  1316. function parseIcon($sName, $aAttrs = array())
  1317. {
  1318. if(!is_array($aAttrs))
  1319. $aAttrs = array();
  1320. $aAttrs['class'] = 'sys-icon ' . $sName . (!empty($aAttrs['class']) ? ' ' . $aAttrs['class'] : '');
  1321. return $this->parseHtmlTag(BX_DOL_TEMPLATE_TAG_I, '', $aAttrs);
  1322. }
  1323. function getCacheFilePrefix($sType)
  1324. {
  1325. $sResult = '';
  1326. switch($sType) {
  1327. case 'template':
  1328. $sResult = $this->_sCacheFilePrefix;
  1329. break;
  1330. case 'css':
  1331. $sResult = $this->_sCssCachePrefix;
  1332. break;
  1333. case 'js':
  1334. $sResult = $this->_sJsCachePrefix;
  1335. break;
  1336. }
  1337. return $sResult;
  1338. }
  1339. /**
  1340. * Get cache object for templates
  1341. * @return cache class instance
  1342. */
  1343. function getTemplatesCacheObject ()
  1344. {
  1345. $sCacheEngine = getParam('sys_template_cache_engine');
  1346. $oCacheEngine = bx_instance('BxDolCache' . $sCacheEngine);
  1347. if(!$oCacheEngine->isAvailable())
  1348. $oCacheEngine = bx_instance('BxDolCacheFileHtml');
  1349. return $oCacheEngine;
  1350. }
  1351. /**
  1352. * Get template from cache if it's enabled.
  1353. *
  1354. * @param string $sName template name
  1355. * @param string $aVariables key/value pairs. key should be the same as template's key, but without prefix and postfix.
  1356. * @param mixed $mixedKeyWrapperHtml - key wrapper(string value if left and right parts are the same, array(0 => left, 1 => right) otherwise).
  1357. * @param string $sCheckIn where the content would be searched(base, template, both)
  1358. * @param boolean $bEvaluate need to evaluate the template or not.
  1359. * @return string result of operation or false on failure.
  1360. */
  1361. function getCached($sName, &$aVariables, $mixedKeyWrapperHtml = null, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH, $bEvaluate = true)
  1362. {
  1363. // initialization
  1364. if(!$this->_bCacheEnable)
  1365. return false;
  1366. $sAbsolutePath = $this->_getAbsoluteLocation('path', $this->_sFolderHtml, $sName, $sCheckIn);
  1367. if(empty($sAbsolutePath))
  1368. return false;
  1369. $oCacheEngine = $this->getTemplatesCacheObject ();
  1370. $isFileBasedEngine = $bEvaluate && method_exists($oCacheEngine, 'getDataFilePath');
  1371. // try to get cached content
  1372. $sCacheVariableName = "a";
  1373. $sCacheKey = $this->_getCacheFileName('html', $sAbsolutePath) . '.php';
  1374. if ($isFileBasedEngine)
  1375. $sCacheContent = $oCacheEngine->getDataFilePath($sCacheKey);
  1376. else
  1377. $sCacheContent = $oCacheEngine->getData($sCacheKey);
  1378. // recreate cache if it is empty
  1379. if ($sCacheContent === null && ($sContent = file_get_contents($sAbsolutePath)) !== false && ($sContent = $this->_compileContent($sContent, "\$" . $sCacheVariableName, 1, $aVariables, $mixedKeyWrapperHtml)) !== false) {
  1380. if (false === $oCacheEngine->setData($sCacheKey, trim($sContent)))
  1381. return false;
  1382. if ($isFileBasedEngine)
  1383. $sCacheContent = $oCacheEngine->getDataFilePath($sCacheKey);
  1384. else
  1385. $sCacheContent = $sContent;
  1386. }
  1387. if ($sCacheContent === null)
  1388. return false;
  1389. // return simple cache content
  1390. if(!$bEvaluate)
  1391. return $sCacheContent;
  1392. // return evaluated cache content
  1393. ob_start();
  1394. $$sCacheVariableName = &$aVariables;
  1395. if ($isFileBasedEngine)
  1396. include($sCacheContent);
  1397. else
  1398. eval('?'.'>' . $sCacheContent);
  1399. $sContent = ob_get_clean();
  1400. return $sContent;
  1401. }
  1402. /**
  1403. * Add JS file(s) to global output.
  1404. *
  1405. * @param mixed $mixedFiles string value represents a single JS file name. An array - array of JS file names.
  1406. * @param boolean $bDynamic in the dynamic mode JS file(s) are not included to global output, but are returned from the function directly.
  1407. * @return boolean/string result of operation.
  1408. */
  1409. function addJs($mixedFiles, $bDynamic = false)
  1410. {
  1411. return $this->_processFiles('js', 'add', $mixedFiles, $bDynamic);
  1412. }
  1413. /**
  1414. * Add System JS file(s) to global output.
  1415. * System JS files are the files which are attached to all pages. They will be cached separately from the others.
  1416. *
  1417. * @param mixed $mixedFiles string value represents a single JS file name. An array - array of JS file names.
  1418. * @param boolean $bDynamic in the dynamic mode JS file(s) are not included to global output, but are returned from the function directly.
  1419. * @return boolean/string result of operation.
  1420. */
  1421. function addJsSystem($mixedFiles)
  1422. {
  1423. return $this->_processFiles('js', 'add', $mixedFiles, false, true);
  1424. }
  1425. /**
  1426. * Delete JS file(s) from global output.
  1427. *
  1428. * @param mixed $mixedFiles string value represents a single JS file name. An array - array of JS file names.
  1429. * @return boolean result of operation.
  1430. */
  1431. function deleteJs($mixedFiles)
  1432. {
  1433. return $this->_processFiles('js', 'delete', $mixedFiles);
  1434. }
  1435. /**
  1436. * Delete System JS file(s) from global output.
  1437. *
  1438. * @param mixed $mixedFiles string value represents a single JS file name. An array - array of JS file names.
  1439. * @return boolean result of operation.
  1440. */
  1441. function deleteJsSystem($mixedFiles)
  1442. {
  1443. return $this->_processFiles('js', 'delete', $mixedFiles, false, true);
  1444. }
  1445. /**
  1446. * Compile JS files in one file.
  1447. *
  1448. * @param string $sAbsolutePath CSS file absolute path(full URL for external CSS/JS files).
  1449. * @param array $aIncluded an array of already included JS files.
  1450. * @return string result of operation.
  1451. */
  1452. function _compileJs($sAbsolutePath, &$aIncluded)
  1453. {
  1454. if(isset($aIncluded[$sAbsolutePath]))
  1455. return '';
  1456. $bExternal = strpos($sAbsolutePath, "http://") !== false || strpos($sAbsolutePath, "https://") !== false;
  1457. if($bExternal) {
  1458. $sPath = $sAbsolutePath;
  1459. $sName = '';
  1460. $sContent = bx_file_get_contents($sAbsolutePath);
  1461. } else {
  1462. $aFileInfo = pathinfo($sAbsolutePath);
  1463. $sPath = $aFileInfo['dirname'] . DIRECTORY_SEPARATOR;
  1464. $sName = $aFileInfo['basename'];
  1465. $sContent = file_get_contents($sPath . $sName);
  1466. }
  1467. if(empty($sContent))
  1468. return '';
  1469. $sUrl = bx_ltrim_str($sPath, realpath(BX_DIRECTORY_PATH_ROOT), BX_DOL_URL_ROOT);
  1470. $sUrl = str_replace(DIRECTORY_SEPARATOR, '/', $sUrl);
  1471. $sContent = "\r\n/*--- BEGIN: " . $sUrl . $sName . "---*/\r\n" . $sContent . ";\r\n/*--- END: " . $sUrl . $sName . "---*/\r\n";
  1472. $sContent = str_replace(array("\n\r", "\r\n", "\r"), "\n", $sContent);
  1473. $aIncluded[$sAbsolutePath] = 1;
  1474. return preg_replace(
  1475. array(
  1476. "'<bx_url_root />'",
  1477. "'\r\n'"
  1478. ),
  1479. array(
  1480. BX_DOL_URL_ROOT,
  1481. "\n"
  1482. ),
  1483. $sContent
  1484. );
  1485. }
  1486. /**
  1487. * Minify JS
  1488. *
  1489. * @param string $s JS string to minify
  1490. * @return string minified JS string.
  1491. */
  1492. function _minifyJs($s)
  1493. {
  1494. // since each JS file is minified separately, it has to be in own scope
  1495. return "\n {\n" . BxDolMinify::getInstance()->minifyJs($s) . "\n }\n";
  1496. }
  1497. /**
  1498. * Wrap an URL to JS file into JS tag.
  1499. *
  1500. * @param string $sFile - URL to JS file.
  1501. * @return string the result of operation.
  1502. */
  1503. function _wrapInTagJs($sFile)
  1504. {
  1505. return "<script language=\"javascript\" type=\"text/javascript\" src=\"" . $sFile . "\"></script>";
  1506. }
  1507. /**
  1508. * Wrap JS code into JS tag.
  1509. *
  1510. * @param string $sCode - JS code.
  1511. * @return string the result of operation.
  1512. */
  1513. function _wrapInTagJsCode($sCode)
  1514. {
  1515. return "<script language=\"javascript\" type=\"text/javascript\">\n<!--\n" . $sCode . "\n-->\n</script>";
  1516. }
  1517. /**
  1518. * Add CSS file(s) to global output.
  1519. *
  1520. * @param mixed $mixedFiles string value represents a single CSS file name. An array - array of CSS file names.
  1521. * @param boolean $bDynamic in the dynamic mode CSS file(s) are not included to global output, but are returned from the function directly.
  1522. * @return boolean/string result of operation
  1523. */
  1524. function addCss($mixedFiles, $bDynamic = false)
  1525. {
  1526. return $this->_processFiles('css', 'add', $mixedFiles, $bDynamic);
  1527. }
  1528. /**
  1529. * Add System CSS file(s) to global output.
  1530. * System CSS files are the files which are attached to all pages. They will be cached separately from the others.
  1531. *
  1532. * @param mixed $mixedFiles string value represents a single CSS file name. An array - array of CSS file names.
  1533. * @return boolean/string result of operation
  1534. */
  1535. function addCssSystem($mixedFiles)
  1536. {
  1537. return $this->_processFiles('css', 'add', $mixedFiles, false, true);
  1538. }
  1539. /**
  1540. * Delete CSS file(s) from global output.
  1541. *
  1542. * @param mixed $mixedFiles string value represents a single CSS file name. An array - array of CSS file names.
  1543. * @return boolean result of operation.
  1544. */
  1545. function deleteCss($mixedFiles)
  1546. {
  1547. return $this->_processFiles('css', 'delete', $mixedFiles);
  1548. }
  1549. /**
  1550. * Delete System CSS file(s) from global output.
  1551. *
  1552. * @param mixed $mixedFiles string value represents a single CSS file name. An array - array of CSS file names.
  1553. * @return boolean result of operation.
  1554. */
  1555. function deleteCssSystem($mixedFiles)
  1556. {
  1557. return $this->_processFiles('css', 'delete', $mixedFiles, false, true);
  1558. }
  1559. /**
  1560. * Compile CSS files' structure(@see \@import css_file_path) in one file.
  1561. *
  1562. * @param string $sAbsolutePath CSS file absolute path(full URL for external CSS/JS files).
  1563. * @param array $aIncluded an array of already included CSS files.
  1564. * @return string result of operation.
  1565. */
  1566. function _compileCss($sAbsolutePath, &$aIncluded)
  1567. {
  1568. if(isset($aIncluded[$sAbsolutePath]))
  1569. return '';
  1570. $bExternal = strpos($sAbsolutePath, "http://") !== false || strpos($sAbsolutePath, "https://") !== false;
  1571. if($bExternal) {
  1572. $sPath = $sAbsolutePath;
  1573. $sName = '';
  1574. $aAPUrl = parse_url($sAbsolutePath);
  1575. if(!empty($aAPUrl['path'])) {
  1576. $aAPPath = pathinfo($aAPUrl['path']);
  1577. if(!empty($aAPPath['basename'])) {
  1578. $sPath = bx_rtrim_str($sAbsolutePath, $aAPPath['basename']);
  1579. $sName = $aAPPath['basename'];
  1580. }
  1581. }
  1582. $sContent = bx_file_get_contents($sAbsolutePath);
  1583. } else {
  1584. $aFileInfo = pathinfo($sAbsolutePath);
  1585. $sPath = $aFileInfo['dirname'] . DIRECTORY_SEPARATOR;
  1586. $sName = $aFileInfo['basename'];
  1587. $sContent = file_get_contents($sPath . $sName);
  1588. }
  1589. if(empty($sContent))
  1590. return '';
  1591. $sUrl = bx_ltrim_str($sPath, realpath(BX_DIRECTORY_PATH_ROOT), BX_DOL_URL_ROOT);
  1592. $sUrl = str_replace(DIRECTORY_SEPARATOR, '/', $sUrl);
  1593. $sContent = "\r\n/*--- BEGIN: " . $sUrl . $sName . "---*/\r\n" . $sContent . "\r\n/*--- END: " . $sUrl . $sName . "---*/\r\n";
  1594. $aIncluded[$sAbsolutePath] = 1;
  1595. $sContent = str_replace(array("\n\r", "\r\n", "\r"), "\n", $sContent);
  1596. if($bExternal) {
  1597. $sContent = preg_replace(
  1598. array(
  1599. "'@import\s+url\s*\(\s*[\'|\"]*\s*([a-zA-Z0-9\.\/_-]+)\s*[\'|\"]*\s*\)\s*;'",
  1600. "'url\s*\(\s*[\'|\"]*\s*([a-zA-Z0-9\.\/\?\#_=-]+)\s*[\'|\"]*\s*\)'"
  1601. ),
  1602. array(
  1603. "",
  1604. "url(" . $sPath . "\\1)"
  1605. ),
  1606. $sContent
  1607. );
  1608. }
  1609. else {
  1610. try {
  1611. $oTemplate = &$this;
  1612. /* Match URL based imports like the following:
  1613. * @import 'http://[domain]/modules/[vendor]/[module]/template/css/view.css';
  1614. * Is mainly needed for CSS files which are gotten from LESS compiler.
  1615. */
  1616. $sContent = preg_replace_callback(
  1617. "'@import\s+[\'|\"]*\s*" . str_replace("/", "\/", BX_DOL_URL_ROOT) . "([a-zA-Z0-9\.\/_-]+)\s*[\'|\"]*\s*;'", function ($aMatches) use($oTemplate, $sPath, $aIncluded) {
  1618. return $oTemplate->_compileCss(realpath(BX_DIRECTORY_PATH_ROOT . $aMatches[1]), $aIncluded);
  1619. }, $sContent);
  1620. /* Match relative path based imports like the following:
  1621. * @import url(../../../../../../base/profile/template/css/main.css);
  1622. * Is mainly needed for default CSS files.
  1623. */
  1624. $sContent = preg_replace_callback(
  1625. "'@import\s+url\s*\(\s*[\'|\"]*\s*([a-zA-Z0-9\.\/_-]+)\s*[\'|\"]*\s*\)\s*;'", function ($aMatches) use($oTemplate, $sPath, $aIncluded) {
  1626. return $oTemplate->_compileCss(realpath($sPath . dirname($aMatches[1])) . DIRECTORY_SEPARATOR . basename($aMatches[1]), $aIncluded);
  1627. }, $sContent);
  1628. $sContent = preg_replace_callback(
  1629. "'url\s*\(\s*[\'|\"]*\s*([a-zA-Z0-9\.\/\?\#_=-]+)\s*[\'|\"]*\s*\)'", function ($aMatches) use($oTemplate, $sPath) {
  1630. $sFile = basename($aMatches[1]);
  1631. $sDirectory = dirname($aMatches[1]);
  1632. $sRootPath = realpath(BX_DIRECTORY_PATH_ROOT);
  1633. $sAbsolutePath = realpath(addslashes($sPath) . $sDirectory) . DIRECTORY_SEPARATOR . $sFile;
  1634. $sRootPath = str_replace(DIRECTORY_SEPARATOR, '/', $sRootPath);
  1635. $sAbsolutePath = str_replace(DIRECTORY_SEPARATOR, '/', $sAbsolutePath);
  1636. return 'url(' . bx_ltrim_str($sAbsolutePath, $sRootPath, BX_DOL_URL_ROOT) . ')';
  1637. }, $sContent);
  1638. }
  1639. catch(Exception $oException) {
  1640. return '';
  1641. }
  1642. }
  1643. return $sContent;
  1644. }
  1645. /**
  1646. * Less CSS
  1647. *
  1648. * @param mixed $mixed CSS string to process with Less compiler or an array with CSS file's Path and URL.
  1649. * @return mixed string or an array with CSS file's Path and URL.
  1650. */
  1651. function _lessCss($mixed)
  1652. {
  1653. require_once(BX_DIRECTORY_PATH_PLUGINS . 'lessphp/Less.php');
  1654. if(is_array($mixed) && isset($mixed['url']) && isset($mixed['path'])) {
  1655. $sPathFile = realpath($mixed['path']);
  1656. $aInfoFile = pathinfo($sPathFile);
  1657. if (!isset($aInfoFile['extension']) || $aInfoFile['extension'] != 'less')
  1658. return $mixed;
  1659. require_once(BX_DIRECTORY_PATH_PLUGINS . 'lessphp/Cache.php');
  1660. $aFiles = array($mixed['path'] => $mixed['url']);
  1661. $aOptions = array('cache_dir' => $this->_sCachePublicFolderPath);
  1662. $sFile = Less_Cache::Get($aFiles, $aOptions, $this->_oTemplateConfig->aLessConfig);
  1663. return array('url' => $this->_sCachePublicFolderUrl . $sFile, 'path' => $this->_sCachePublicFolderPath . $sFile);
  1664. }
  1665. $oLess = new Less_Parser();
  1666. $oLess->ModifyVars($this->_oTemplateConfig->aLessConfig);
  1667. $oLess->parse($mixed);
  1668. return $oLess->getCss();
  1669. }
  1670. /**
  1671. * Minify CSS
  1672. *
  1673. * @param string $s CSS string to minify
  1674. * @return string minified CSS string.
  1675. */
  1676. function _minifyCss($s)
  1677. {
  1678. return BxDolMinify::getInstance()->minifyCss($s);
  1679. }
  1680. /**
  1681. * Wrap an URL to CSS file into CSS tag.
  1682. *
  1683. * @param string $sFile - URL to CSS file.
  1684. * @return string the result of operation.
  1685. */
  1686. function _wrapInTagCss($sFile)
  1687. {
  1688. if (!$sFile)
  1689. return '';
  1690. return "<link href=\"" . $sFile . "\" rel=\"stylesheet\" type=\"text/css\" />";
  1691. }
  1692. /**
  1693. * Wrap CSS code into CSS tag.
  1694. *
  1695. * @param string $sCode - CSS code.
  1696. * @return string the result of operation.
  1697. */
  1698. function _wrapInTagCssCode($sCode)
  1699. {
  1700. return "<style>" . $sCode . "</style>";
  1701. }
  1702. /**
  1703. * Include CSS style(s) in the page's head section.
  1704. */
  1705. function includeCssStyles()
  1706. {
  1707. $sResult = "";
  1708. if(empty($this->aPage['css_styles']) || !is_array($this->aPage['css_styles']))
  1709. return $sResult;
  1710. foreach($this->aPage['css_styles'] as $sName => $aContent) {
  1711. $sContent = "";
  1712. if(!empty($aContent) && is_array($aContent))
  1713. foreach($aContent as $sStyleName => $sStyleValue)
  1714. $sContent .= "\t" . $sStyleName . ": " . $sStyleValue . ";\r\n";
  1715. $sResult .= $sName . " {\r\n" . $sContent . "}\r\n";
  1716. }
  1717. return !empty($sResult) ? $this->_wrapInTagCssCode($sResult) : '';
  1718. }
  1719. /**
  1720. * Include CSS/JS file(s) attached to the page in its head section.
  1721. * @see the method is system and would be called automatically.
  1722. *
  1723. * @param string $sType the type of file('js' or 'css')
  1724. * @return string the result CSS code.
  1725. */
  1726. function includeFiles($sType, $bSystem = false)
  1727. {
  1728. $sUpcaseType = ucfirst($sType);
  1729. $sArrayKey = $sType . ($bSystem ? '_system' : '_compiled');
  1730. $aFiles = isset($this->aPage[$sArrayKey]) ? $this->aPage[$sArrayKey] : array();
  1731. if(empty($aFiles) || !is_array($aFiles))
  1732. return "";
  1733. if(!$this->{'_b' . $sUpcaseType . 'Cache'})
  1734. return $this->_includeFiles($sType, $aFiles);
  1735. //--- If cache already exists, return it ---//
  1736. $sMethodWrap = '_wrapInTag' . $sUpcaseType;
  1737. $sMethodCompile = '_compile' . $sUpcaseType;
  1738. $sMethodLess = '_less' . $sUpcaseType;
  1739. $sMethodMinify = '_minify' . $sUpcaseType;
  1740. ksort($aFiles);
  1741. $sName = "";
  1742. foreach($aFiles as $aFile)
  1743. $sName .= $aFile['url'];
  1744. $sName = $this->_getCacheFileName($sType, $sName);
  1745. $sCacheAbsoluteUrl = $this->_sCachePublicFolderUrl . $sName . '.' . $sType;
  1746. $sCacheAbsolutePath = $this->_sCachePublicFolderPath . $sName . '.' . $sType;
  1747. if(file_exists($sCacheAbsolutePath)) {
  1748. if($this->{'_b' . $sUpcaseType . 'Archive'})
  1749. $sCacheAbsoluteUrl = $this->_getLoaderUrl($sType, $sName);
  1750. return $this->$sMethodWrap($sCacheAbsoluteUrl);
  1751. }
  1752. //--- Collect all attached CSS/JS in one file ---//
  1753. $bLess = $this->_bLessEnable && method_exists($this, $sMethodLess);
  1754. $sResult = "";
  1755. $aIncluded = array();
  1756. foreach($aFiles as $aFile) {
  1757. if($bLess)
  1758. $aFile = $this->$sMethodLess($aFile);
  1759. if(($sContent = $this->$sMethodCompile($aFile['path'], $aIncluded)) === false)
  1760. continue;
  1761. if (!preg_match('/[\.-]min.(js|css)$/i', $aFile['path']) && $this->{'_b' . $sUpcaseType . 'Minify'}) // don't minify minified files
  1762. $sContent = $this->$sMethodMinify($sContent);
  1763. $sResult .= $sContent;
  1764. }
  1765. $mixedWriteResult = false;
  1766. if(!empty($sResult) && ($rHandler = fopen($sCacheAbsolutePath, 'w')) !== false) {
  1767. $mixedWriteResult = fwrite($rHandler, $sResult);
  1768. fclose($rHandler);
  1769. @chmod ($sCacheAbsolutePath, BX_DOL_FILE_RIGHTS);
  1770. }
  1771. if($mixedWriteResult === false)
  1772. return $this->_includeFiles($sType, $aFiles);
  1773. if($this->{'_b' . $sUpcaseType . 'Archive'})
  1774. $sCacheAbsoluteUrl = $this->_getLoaderUrl($sType, $sName);
  1775. return $this->$sMethodWrap($sCacheAbsoluteUrl);
  1776. }
  1777. /**
  1778. * Include CSS/JS files without caching.
  1779. *
  1780. * @param string $sType the file type (css or js)
  1781. * @param array $aFiles CSS/JS files to be added to the page.
  1782. * @return string result of operation.
  1783. */
  1784. function _includeFiles($sType, &$aFiles)
  1785. {
  1786. $sUpcaseType = ucfirst($sType);
  1787. $sMethodWrap = '_wrapInTag' . $sUpcaseType;
  1788. $sMethodLess = '_less' . $sUpcaseType;
  1789. $sResult = "";
  1790. foreach($aFiles as $aFile) {
  1791. if($this->_bLessEnable && method_exists($this, $sMethodLess))
  1792. $aFile = $this->$sMethodLess($aFile);
  1793. $sResult .= $this->$sMethodWrap($aFile['url']);
  1794. }
  1795. return $sResult;
  1796. }
  1797. /**
  1798. * Insert/Delete CSS file from output stack.
  1799. *
  1800. * @param string $sType the file type (css or js)
  1801. * @param string $sAction add/delete
  1802. * @param mixed $mixedFiles string value represents a single CSS file name. An array - array of CSS file names.
  1803. * @return boolean result of operation.
  1804. */
  1805. function _processFiles($sType, $sAction, $mixedFiles, $bDynamic = false, $bSystem = false)
  1806. {
  1807. if(empty($mixedFiles))
  1808. return $bDynamic ? "" : false;
  1809. if(is_string($mixedFiles))
  1810. $mixedFiles = array($mixedFiles);
  1811. $sUpcaseType = ucfirst($sType);
  1812. $sMethodLocate = '_getAbsoluteLocation' . $sUpcaseType;
  1813. $sMethodWrap = '_wrapInTag' . $sUpcaseType;
  1814. $sResult = '';
  1815. foreach($mixedFiles as $sFile) {
  1816. //--- Process 3d Party CSS/JS file ---//
  1817. if(strpos($sFile, "http://") !== false || strpos($sFile, "https://") !== false) {
  1818. $sUrl = $sFile;
  1819. $sPath = $sFile;
  1820. }
  1821. //--- Process Custom CSS/JS file ---//
  1822. else if(strpos($sFile, "|") !== false) {
  1823. $sFile = implode('', explode("|", $sFile));
  1824. $sFile = bx_ltrim_str($sFile, BX_DIRECTORY_PATH_ROOT);
  1825. $sUrl = BX_DOL_URL_ROOT . $sFile;
  1826. $sPath = realpath(BX_DIRECTORY_PATH_ROOT . $sFile);
  1827. }
  1828. //--- Process Common CSS/JS file(check in default locations) ---//
  1829. else {
  1830. $sUrl = $this->$sMethodLocate('url', $sFile);
  1831. $sPath = $this->$sMethodLocate('path', $sFile);
  1832. }
  1833. if(empty($sPath) || empty($sUrl))
  1834. continue;
  1835. $sArrayKey = $sType . ($bSystem ? '_system' : '_compiled');
  1836. switch($sAction) {
  1837. case 'add':
  1838. if($bDynamic)
  1839. $sResult .= $this->$sMethodWrap($sUrl);
  1840. else {
  1841. $bFound = false;
  1842. $aSearchIn = $bSystem ? $this->aPage[$sArrayKey] : array_merge($this->aPage[$sType . '_system'], $this->aPage[$sArrayKey]);
  1843. foreach($aSearchIn as $iKey => $aValue)
  1844. if($aValue['url'] == $sUrl && $aValue['path'] == $sPath) {
  1845. $bFound = true;
  1846. break;
  1847. }
  1848. if(!$bFound)
  1849. $this->aPage[$sArrayKey][] = array('url' => $sUrl, 'path' => $sPath);
  1850. }
  1851. break;
  1852. case 'delete':
  1853. if(!$bDynamic)
  1854. foreach($this->aPage[$sArrayKey] as $iKey => $aValue)
  1855. if($aValue['url'] == $sUrl) {
  1856. unset($this->aPage[$sArrayKey][$iKey]);
  1857. break;
  1858. }
  1859. break;
  1860. }
  1861. }
  1862. return $bDynamic ? $sResult : true;
  1863. }
  1864. /**
  1865. * Parse content.
  1866. *
  1867. * @param string $sContent - HTML file's content.
  1868. * @param array $aVariables - key/value pairs. key should be the same as template's key, but without prefix and postfix.
  1869. * @param mixed $mixedKeyWrapperHtml - key wrapper(string value if left and right parts are the same, array(0 => left, 1 => right) otherwise).
  1870. * @return string the result of operation.
  1871. */
  1872. function _parseContent($sContent, $aVariables, $mixedKeyWrapperHtml = null)
  1873. {
  1874. $aKeysSrc = array_keys($aVariables);
  1875. $aValuesSrc = array_values($aVariables);
  1876. $aKeyWrappers = $this->_getKeyWrappers($mixedKeyWrapperHtml);
  1877. $sKeyIf = 'bx_if:';
  1878. $sKeyRepeat = 'bx_repeat:';
  1879. $iCountKeys = count($aKeysSrc);
  1880. $aKeys = $aValues = array();
  1881. //--- Parse simple keys ---//
  1882. for ($i = 0; $i < $iCountKeys; $i++) {
  1883. if (strncmp($aKeysSrc[$i], $sKeyRepeat, 10) === 0 || strncmp($aKeysSrc[$i], $sKeyIf, 6) === 0)
  1884. continue;
  1885. $aKeys[] = "'" . $aKeyWrappers['left'] . $aKeysSrc[$i] . $aKeyWrappers['right'] . "'s";
  1886. $aValues[] = str_replace('$', '\\$', $aValuesSrc[$i]);
  1887. }
  1888. //--- Parse keys with constructions ---//
  1889. for ($i = 0; $i < $iCountKeys; $i++) {
  1890. if (strncmp($aKeysSrc[$i], $sKeyRepeat, 10) === 0) {
  1891. $sKey = "'<" . $aKeysSrc[$i] . ">(.*)<\/" . $aKeysSrc[$i] . ">'s";
  1892. $aMatches = array();
  1893. preg_match($sKey, $sContent, $aMatches);
  1894. $sValue = '';
  1895. if(isset($aMatches[1]) && !empty($aMatches[1])) {
  1896. if(is_array($aValuesSrc[$i]))
  1897. foreach($aValuesSrc[$i] as $aValue)
  1898. $sValue .= $this->parseHtmlByContent($aMatches[1], $aValue, $mixedKeyWrapperHtml);
  1899. else if(is_string($aValuesSrc[$i]))
  1900. $sValue = $aValuesSrc[$i];
  1901. }
  1902. }
  1903. else if (strncmp($aKeysSrc[$i], $sKeyIf, 6) === 0) {
  1904. $sKey = "'<" . $aKeysSrc[$i] . ">(.*)<\/" . $aKeysSrc[$i] . ">'s";
  1905. $aMatches = array();
  1906. preg_match($sKey, $sContent, $aMatches);
  1907. $sValue = '';
  1908. if(isset($aMatches[1]) && !empty($aMatches[1]))
  1909. if(is_array($aValuesSrc[$i]) && isset($aValuesSrc[$i]['content']) && isset($aValuesSrc[$i]['condition']) && $aValuesSrc[$i]['condition'])
  1910. $sValue .= $this->parseHtmlByContent($aMatches[1], $aValuesSrc[$i]['content'], $mixedKeyWrapperHtml);
  1911. }
  1912. else
  1913. continue;
  1914. $aKeys[] = $sKey;
  1915. $aValues[] = str_replace('$', '\\$', $sValue);
  1916. }
  1917. try {
  1918. $oTemplate = &$this;
  1919. $aCallbackPatterns = array(
  1920. "'<bx_include_auto:([^\s]+) \/>'s" => BX_DOL_TEMPLATE_CHECK_IN_BOTH,
  1921. "'<bx_include_base:([^\s]+) \/>'s" => BX_DOL_TEMPLATE_CHECK_IN_BASE,
  1922. "'<bx_include_tmpl:([^\s]+) \/>'s" => BX_DOL_TEMPLATE_CHECK_IN_TMPL
  1923. );
  1924. foreach($aCallbackPatterns as $sPattern => $sCheckIn)
  1925. $sContent = preg_replace_callback($sPattern, function($aMatches) use($oTemplate, $aVariables, $mixedKeyWrapperHtml, $sCheckIn) {
  1926. return $oTemplate->parseHtmlByName($aMatches[1], $aVariables, $mixedKeyWrapperHtml, $sCheckIn);
  1927. }, $sContent);
  1928. $sContent = $this->_parseContentKeys($sContent, array(
  1929. "'<bx_injection:([^\s]+) />'s" => 'get_injection',
  1930. "'<bx_menu:([^\s]+) \/>'s" => 'get_menu',
  1931. ));
  1932. }
  1933. catch(Exception $oException) {
  1934. return '';
  1935. }
  1936. $aKeys = array_merge($aKeys, array(
  1937. "'<bx_url_root />'",
  1938. "'<bx_url_studio />'",
  1939. ));
  1940. $aValues = array_merge($aValues, array(
  1941. BX_DOL_URL_ROOT,
  1942. BX_DOL_URL_STUDIO,
  1943. ));
  1944. //--- Parse Predefined Keys ---//
  1945. $sContent = preg_replace($aKeys, $aValues, $sContent);
  1946. //--- Parse System Keys ---//
  1947. $sContent = preg_replace_callback("'" . $aKeyWrappers['left'] . "([a-zA-Z0-9_-]+)" . $aKeyWrappers['right'] . "'", function($aMatches) use($oTemplate, $mixedKeyWrapperHtml) {
  1948. return $oTemplate->parseSystemKey($aMatches[1], $mixedKeyWrapperHtml);
  1949. }, $sContent);
  1950. return $sContent;
  1951. }
  1952. /**
  1953. * Compile content
  1954. *
  1955. * @param string $sContent template.
  1956. * @param string $aVarName variable name to be saved in the output file.
  1957. * @param integer $iVarDepth depth is used to process nesting, for example, in cycles.
  1958. * @param array $aVarValues values to be compiled in.
  1959. * @param mixed $mixedKeyWrapperHtml key wrapper(string value if left and right parts are the same, array(0 => left, 1 => right) otherwise).
  1960. * @return string the result of operation.
  1961. */
  1962. function _compileContent($sContent, $aVarName, $iVarDepth, $aVarValues, $mixedKeyWrapperHtml = null)
  1963. {
  1964. $aKeys = array_keys($aVarValues);
  1965. $aValues = array_values($aVarValues);
  1966. $aKeyWrappers = $this->_getKeyWrappers($mixedKeyWrapperHtml);
  1967. for($i = 0; $i < count($aKeys); $i++) {
  1968. if(strpos($aKeys[$i], 'bx_repeat:') === 0) {
  1969. $sKey = "'<" . $aKeys[$i] . ">(.*)<\/" . $aKeys[$i] . ">'s";
  1970. $aMatches = array();
  1971. preg_match($sKey, $sContent, $aMatches);
  1972. $sValue = '';
  1973. if(isset($aMatches[1]) && !empty($aMatches[1])) {
  1974. if(empty($aValues[$i]) || !is_array($aValues[$i]))
  1975. return false;
  1976. $sIndex = "\$" . str_repeat("i", $iVarDepth);
  1977. $sValue .= "<?php if(is_array(" . $aVarName . "['" . $aKeys[$i] . "'])) for(" . $sIndex . "=0; " . $sIndex . "<count(" . $aVarName . "['" . $aKeys[$i] . "']); " . $sIndex . "++){ ?>";
  1978. if(($sInnerValue = $this->_compileContent($aMatches[1], $aVarName . "['" . $aKeys[$i] . "'][" . $sIndex . "]", $iVarDepth + 1, current($aValues[$i]), $mixedKeyWrapperHtml)) === false)
  1979. return false;
  1980. $sValue .= $sInnerValue;
  1981. $sValue .= "<?php } else if(is_string(" . $aVarName . "['" . $aKeys[$i] . "'])) echo " . $aVarName . "['" . $aKeys[$i] . "']; ?>";
  1982. }
  1983. } else if(strpos($aKeys[$i], 'bx_if:') === 0) {
  1984. $sKey = "'<" . $aKeys[$i] . ">(.*)<\/" . $aKeys[$i] . ">'s";
  1985. $aMatches = array();
  1986. preg_match($sKey, $sContent, $aMatches);
  1987. $sValue = '';
  1988. if(isset($aMatches[1]) && !empty($aMatches[1])) {
  1989. if(!is_array($aValues[$i]) || !isset($aValues[$i]['content']) || empty($aValues[$i]['content']) || !is_array($aValues[$i]['content']))
  1990. return false;
  1991. $sValue .= "<?php if(" . $aVarName . "['" . $aKeys[$i] . "']['condition']){ ?>";
  1992. if(($sInnerValue = $this->_compileContent($aMatches[1], $aVarName . "['" . $aKeys[$i] . "']['content']", $iVarDepth, $aValues[$i]['content'], $mixedKeyWrapperHtml)) === false)
  1993. return false;
  1994. $sValue .= $sInnerValue;
  1995. $sValue .= "<?php } ?>";
  1996. }
  1997. } else {
  1998. $sKey = "'" . $aKeyWrappers['left'] . $aKeys[$i] . $aKeyWrappers['right'] . "'s";
  1999. $sValue = "<?php echo " . $aVarName . "['" . $aKeys[$i] . "'];?>";
  2000. }
  2001. $aKeys[$i] = $sKey;
  2002. $aValues[$i] = $sValue;
  2003. }
  2004. try {
  2005. $oTemplate = &$this;
  2006. $aCallbackPatterns = array(
  2007. "'<bx_include_auto:([^\s]+) \/>'s" => BX_DOL_TEMPLATE_CHECK_IN_BOTH,
  2008. "'<bx_include_base:([^\s]+) \/>'s" => BX_DOL_TEMPLATE_CHECK_IN_BASE,
  2009. "'<bx_include_tmpl:([^\s]+) \/>'s" => BX_DOL_TEMPLATE_CHECK_IN_TMPL
  2010. );
  2011. foreach($aCallbackPatterns as $sPattern => $sCheckIn)
  2012. $sContent = preg_replace_callback($sPattern, function($aMatches) use($oTemplate, $aVarValues, $mixedKeyWrapperHtml, $sCheckIn) {
  2013. $mixedResult = $oTemplate->getCached($aMatches[1], $aVarValues, $mixedKeyWrapperHtml, $sCheckIn, false);
  2014. if($mixedResult === false)
  2015. throw new Exception('Unable to create cache file.');
  2016. return $mixedResult;
  2017. }, $sContent);
  2018. $sContent = $this->_parseContentKeys($sContent);
  2019. }
  2020. catch(Exception $oException) {
  2021. return false;
  2022. }
  2023. $aKeys = array_merge($aKeys, array(
  2024. "'<bx_injection:([^\s]+) />'s",
  2025. "'<bx_menu:([^\s]+) \/>'s",
  2026. "'<bx_url_root />'",
  2027. "'<bx_url_studio />'"
  2028. ));
  2029. $aValues = array_merge($aValues, array(
  2030. "<?php echo \$this->processInjection(\$this->aPage['name_index'], '\\1'); ?>",
  2031. "<?php echo \$this->getMenu('\\1'); ?>",
  2032. BX_DOL_URL_ROOT,
  2033. BX_DOL_URL_STUDIO
  2034. ));
  2035. //--- Parse Predefined Keys ---//
  2036. $sContent = preg_replace($aKeys, $aValues, $sContent);
  2037. //--- Parse System Keys ---//
  2038. $sContent = preg_replace( "'" . $aKeyWrappers['left'] . "([a-zA-Z0-9_-]+)" . $aKeyWrappers['right'] . "'", "<?php echo \$this->parseSystemKey('\\1', \$mixedKeyWrapperHtml);?>", $sContent);
  2039. return $sContent;
  2040. }
  2041. protected function _parseContentKeys($sContent, $aCallbackPatterns = array())
  2042. {
  2043. $oTemplate = &$this;
  2044. $aCallbackPatterns = array_merge($aCallbackPatterns, array(
  2045. "'<bx_image_url:([^\s]+) \/>'s" => "get_image_url",
  2046. "'<bx_icon_url:([^\s]+) \/>'s" => "get_icon_url",
  2047. "'<bx_text:([_\{\}\w\d\s]+[^\s]{1}) \/>'s" => "get_text",
  2048. "'<bx_text_js:([^\s]+) \/>'s" => "get_text_js",
  2049. "'<bx_text_attribute:([^\s]+) \/>'s" => "get_text_attribute",
  2050. ));
  2051. foreach($aCallbackPatterns as $sPattern => $sAction)
  2052. $sContent = preg_replace_callback($sPattern, function($aMatches) use($oTemplate, $sAction) {
  2053. $sResult = '';
  2054. switch($sAction) {
  2055. case 'get_image_url':
  2056. $sResult = $oTemplate->getImageUrl($aMatches[1]);
  2057. break;
  2058. case 'get_icon_url':
  2059. $sResult = $oTemplate->getIconUrl($aMatches[1]);
  2060. break;
  2061. case 'get_text':
  2062. $sResult = _t($aMatches[1]);
  2063. break;
  2064. case 'get_text_js':
  2065. $sResult = bx_js_string(_t($aMatches[1]));
  2066. break;
  2067. case 'get_text_attribute':
  2068. $sResult = bx_html_attribute(_t($aMatches[1]));
  2069. break;
  2070. case 'get_injection':
  2071. $sResult = $oTemplate->processInjection($oTemplate->getPageNameIndex(), $aMatches[1]);
  2072. break;
  2073. case 'get_menu':
  2074. $sResult = $oTemplate->getMenu($aMatches[1]);
  2075. break;
  2076. }
  2077. return $sResult;
  2078. }, $sContent);
  2079. return $sContent;
  2080. }
  2081. /**
  2082. * Get absolute location of some template's part.
  2083. *
  2084. * @param string $sType - result type. Available values 'url' and 'path'.
  2085. * @param string $sFolder - folders to be searched in. @see $_sFolderHtml, $_sFolderCss, $_sFolderImages and $_sFolderIcons
  2086. * @param string $sName - requested part name.
  2087. * @param string $sCheckIn where the content would be searched(base, template, both)
  2088. * @return string absolute location (path/url) of the part.
  2089. */
  2090. function _getAbsoluteLocation($sType, $sFolder, $sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  2091. {
  2092. $sDirectory = $this->getPath();
  2093. if($sType == 'path') {
  2094. $sDivider = DIRECTORY_SEPARATOR;
  2095. $sRoot = BX_DIRECTORY_PATH_ROOT;
  2096. } else if($sType == 'url') {
  2097. $sDivider = '/';
  2098. $sRoot = BX_DOL_URL_ROOT;
  2099. }
  2100. if(strpos($sName,'|') !== false) {
  2101. $aParts = explode('|', $sName);
  2102. $sName = $aParts[1];
  2103. if(strpos($aParts[0],'@') !== false) {
  2104. $aLocationParts = explode('@', $aParts[0]);
  2105. $sLocationKey = $this->addLocation($aLocationParts[0], BX_DIRECTORY_PATH_ROOT . $aLocationParts[1], BX_DOL_URL_ROOT . $aLocationParts[1]);
  2106. }
  2107. }
  2108. $sResult = '';
  2109. $aLocations = array_reverse($this->_aLocations, true);
  2110. foreach($aLocations as $sKey => $aLocation) {
  2111. if(($sCheckIn == BX_DOL_TEMPLATE_CHECK_IN_BOTH || $sCheckIn == BX_DOL_TEMPLATE_CHECK_IN_TMPL) && extFileExists(BX_DIRECTORY_PATH_MODULES . $this->getPath(). 'data' . DIRECTORY_SEPARATOR . BX_DOL_TEMPLATE_FOLDER_ROOT . DIRECTORY_SEPARATOR . $sKey . DIRECTORY_SEPARATOR . $sFolder . $sName))
  2112. $sResult = $sRoot . 'modules' . $sDivider . $sDirectory. 'data' . $sDivider . BX_DOL_TEMPLATE_FOLDER_ROOT . $sDivider . $sKey . $sDivider . $sFolder . $sName;
  2113. else if(($sCheckIn == BX_DOL_TEMPLATE_CHECK_IN_BOTH || $sCheckIn == BX_DOL_TEMPLATE_CHECK_IN_BASE) && extFileExists($aLocation['path'] . BX_DOL_TEMPLATE_FOLDER_ROOT . DIRECTORY_SEPARATOR . $sFolder . $sName))
  2114. $sResult = $aLocation[$sType] . BX_DOL_TEMPLATE_FOLDER_ROOT . $sDivider . $sFolder . $sName;
  2115. else
  2116. continue;
  2117. break;
  2118. }
  2119. /**
  2120. * try to find from received path
  2121. */
  2122. if(!$sResult && @is_file(BX_DIRECTORY_PATH_ROOT . $aParts[0] . DIRECTORY_SEPARATOR . $aParts[1])) {
  2123. $sResult = $sRoot . $aParts[0] . $sDivider . $aParts[1];
  2124. }
  2125. if(isset($sLocationKey))
  2126. $this->removeLocation($sLocationKey);
  2127. return $sType == 'path' && !empty($sResult) ? realpath($sResult) : $sResult;
  2128. }
  2129. /**
  2130. * Get absolute location of some template's part.
  2131. *
  2132. * @param string $sType result type. Available values 'url' and 'path'.
  2133. * @param string $sName requested part name.
  2134. * @return string absolute location (path/url) of the part.
  2135. */
  2136. function _getAbsoluteLocationJs($sType, $sName)
  2137. {
  2138. $sResult = '';
  2139. $aLocations = array_reverse($this->_aLocationsJs, true);
  2140. foreach($aLocations as $sKey => $aLocation) {
  2141. if(extFileExists($aLocation['path'] . $sName))
  2142. $sResult = $aLocation[$sType] . $sName;
  2143. else
  2144. continue;
  2145. break;
  2146. }
  2147. return $sType == 'path' && !empty($sResult) ? realpath($sResult) : $sResult;
  2148. }
  2149. function _getAbsoluteLocationCss($sType, $sName)
  2150. {
  2151. $sNameLess = str_replace('.css', '.less', $sName);
  2152. $sResult = $this->_getAbsoluteLocation($sType, $this->_sFolderCss, $sNameLess);
  2153. if(!empty($sResult))
  2154. return $sResult;
  2155. return $this->_getAbsoluteLocation($sType, $this->_sFolderCss, $sName);
  2156. }
  2157. /**
  2158. * Get inline data for Images and Icons.
  2159. *
  2160. * @param string $sType image/icon
  2161. * @param string $sName file name
  2162. * @param string $sCheckIn where the content would be searched(base, template, both)
  2163. * @return unknown
  2164. */
  2165. function _getInlineData($sType, $sName, $sCheckIn)
  2166. {
  2167. switch($sType) {
  2168. case 'image':
  2169. $sFolder = $this->_sFolderImages;
  2170. break;
  2171. case 'icon':
  2172. $sFolder = $this->_sFolderIcons;
  2173. break;
  2174. }
  2175. $sPath = $this->_getAbsoluteLocation('path', $sFolder, $sName, $sCheckIn);
  2176. $iFileSize = 0;
  2177. if($this->_bImagesInline && ($iFileSize = filesize($sPath)) !== false && $iFileSize < $this->_iImagesMaxSize) {
  2178. $aFileInfo = pathinfo($sPath);
  2179. return "data:image/" . strtolower($aFileInfo['extension']) . ";base64," . base64_encode(file_get_contents($sPath));
  2180. }
  2181. return false;
  2182. }
  2183. /**
  2184. * Get file name where the template would be cached.
  2185. *
  2186. * @param string $sAbsolutePath template's real path.
  2187. * @return string the result of operation.
  2188. */
  2189. function _getCacheFileName($sType, $sAbsolutePath)
  2190. {
  2191. $sResult = bx_site_hash($sAbsolutePath);
  2192. switch($sType) {
  2193. case 'html':
  2194. $sResult = $this->_sCacheFilePrefix . bx_lang_name() . '_' . $this->_sCode . '_' . $sResult;
  2195. break;
  2196. case 'css':
  2197. $sResult = $this->_sCssCachePrefix . $sResult;
  2198. break;
  2199. case 'js':
  2200. $sResult = $this->_sJsCachePrefix . $sResult;
  2201. break;
  2202. }
  2203. return $sResult;
  2204. }
  2205. /**
  2206. * Get template key wrappers(left, right)
  2207. *
  2208. * @param mixed $mixedKeyWrapperHtml key wrapper(string value if left and right parts are the same, array(0 => left, 1 => right) otherwise).
  2209. * @return array result of operation.
  2210. */
  2211. function _getKeyWrappers($mixedKeyWrapperHtml)
  2212. {
  2213. $aResult = array();
  2214. if(!empty($mixedKeyWrapperHtml) && is_string($mixedKeyWrapperHtml))
  2215. $aResult = array('left' => $mixedKeyWrapperHtml, 'right' => $mixedKeyWrapperHtml);
  2216. else if(!empty($mixedKeyWrapperHtml) && is_array($mixedKeyWrapperHtml))
  2217. $aResult = array('left' => $mixedKeyWrapperHtml[0], 'right' => $mixedKeyWrapperHtml[1]);
  2218. else
  2219. $aResult = array('left' => $this->_sKeyWrapperHtml, 'right' => $this->_sKeyWrapperHtml);
  2220. return $aResult;
  2221. }
  2222. /**
  2223. * Process all added language translations and return them as a string.
  2224. *
  2225. * @return string with JS code.
  2226. */
  2227. function _processJsTranslations()
  2228. {
  2229. $sReturn = '';
  2230. if(isset($this->aPage['js_translations']) && is_array($this->aPage['js_translations'])) {
  2231. foreach($this->aPage['js_translations'] as $sKey => $sString)
  2232. $sReturn .= "'" . bx_js_string($sKey) . "': '" . bx_js_string($sString) . "',";
  2233. $sReturn = substr($sReturn, 0, -1);
  2234. }
  2235. return '<script type="text/javascript" language="javascript">var aDolLang = {' . $sReturn . '};</script>';
  2236. }
  2237. /**
  2238. * Process all added options and return them as a string.
  2239. *
  2240. * @return string with JS code.
  2241. */
  2242. function _processJsOptions()
  2243. {
  2244. $sReturn = '';
  2245. if(isset($this->aPage['js_options']) && is_array($this->aPage['js_options'])) {
  2246. foreach($this->aPage['js_options'] as $sName => $mixedValue)
  2247. $sReturn .= "'" . bx_js_string($sName) . "': '" . bx_js_string($mixedValue) . "',";
  2248. $sReturn = substr($sReturn, 0, -1);
  2249. }
  2250. return '<script type="text/javascript" language="javascript">var aDolOptions = {' . $sReturn . '};</script>';
  2251. }
  2252. /**
  2253. * Process all added images and return them as a string.
  2254. *
  2255. * @return string with JS code.
  2256. */
  2257. function _processJsImages()
  2258. {
  2259. $sReturn = '';
  2260. if(isset($this->aPage['js_images']) && is_array($this->aPage['js_images'])) {
  2261. foreach($this->aPage['js_images'] as $sKey => $sUrl)
  2262. $sReturn .= "'" . bx_js_string($sKey) . "': '" . bx_js_string($sUrl) . "',";
  2263. $sReturn = substr($sReturn, 0, -1);
  2264. }
  2265. return '<script type="text/javascript" language="javascript">var aDolImages = {' . $sReturn . '};</script>';
  2266. }
  2267. /**
  2268. * Get Gzip loader URL.
  2269. *
  2270. * @param $sType content type CSS/JS
  2271. * @param $sName file name.
  2272. * @return string with URL
  2273. */
  2274. function _getLoaderUrl($sType, $sName)
  2275. {
  2276. return BX_DOL_URL_ROOT . 'gzip_loader.php?file=' . $sName . '.' . $sType;
  2277. }
  2278. /**
  2279. *
  2280. * Functions to display pages with errors, messages and so on.
  2281. *
  2282. */
  2283. function displayAccessDenied ($sMsg = '')
  2284. {
  2285. bx_import('BxDolLanguages');
  2286. header("HTTP/1.0 403 Forbidden");
  2287. $this->displayMsg($sMsg ? $sMsg : _t('_Access denied'));
  2288. }
  2289. function displayNoData ($sMsg = '')
  2290. {
  2291. bx_import('BxDolLanguages');
  2292. header("HTTP/1.0 204 No Content");
  2293. $this->displayMsg($sMsg ? $sMsg : _t('_Empty'));
  2294. }
  2295. function displayErrorOccured ($sMsg = '')
  2296. {
  2297. bx_import('BxDolLanguages');
  2298. header("HTTP/1.0 500 Internal Server Error");
  2299. $this->displayMsg($sMsg ? $sMsg : _t('_error occured'));
  2300. }
  2301. function displayPageNotFound ($sMsg = '')
  2302. {
  2303. bx_import('BxDolLanguages');
  2304. header("HTTP/1.0 404 Not Found");
  2305. $this->displayMsg($sMsg ? $sMsg : _t('_sys_request_page_not_found_cpt'));
  2306. }
  2307. function displayMsg ($s, $bTranslate = false)
  2308. {
  2309. $sTitle = $bTranslate ? _t($s) : $s;
  2310. $oTemplate = BxDolTemplate::getInstance();
  2311. $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
  2312. $oTemplate->setPageHeader (_t('_Error'));
  2313. $oTemplate->setPageContent ('page_main_code', DesignBoxContent(_t('_Error'), MsgBox($sTitle), BX_DB_PADDING_DEF));
  2314. $oTemplate->getPageCode();
  2315. exit;
  2316. }
  2317. /**
  2318. * * * * Static methods for work with template injections * * *
  2319. *
  2320. * Static method is used to add/replace the content of some key in the template.
  2321. * It's usefull when you don't want to modify existing template but need to add some data to existing template key.
  2322. *
  2323. * @param integer $iPageIndex - page index where injections would processed. Use 0 if you want it to be done on all the pages.
  2324. * @param string $sKey - template key.
  2325. * @param string $sValue - the data to be added.
  2326. * @return string the result of operation.
  2327. */
  2328. function processInjection($iPageIndex, $sKey, $sValue = "")
  2329. {
  2330. if($iPageIndex != 0 && isset($this->aPage['injections']['page_0'][$sKey]) && isset($this->aPage['injections']['page_' . $iPageIndex][$sKey]))
  2331. $aSelection = @array_merge($this->aPage['injections']['page_0'][$sKey], $this->aPage['injections']['page_' . $iPageIndex][$sKey]);
  2332. else if(isset($this->aPage['injections']['page_0'][$sKey]))
  2333. $aSelection = $this->aPage['injections']['page_0'][$sKey];
  2334. else if(isset($this->aPage['injections']['page_' . $iPageIndex][$sKey]))
  2335. $aSelection = $this->aPage['injections']['page_' . $iPageIndex][$sKey];
  2336. else
  2337. $aSelection = array();
  2338. if(is_array($aSelection))
  2339. foreach($aSelection as $aInjection) {
  2340. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->beginInjection($sRand = time().rand());
  2341. $sInjData = '';
  2342. switch($aInjection['type']) {
  2343. case 'text':
  2344. $sInjData = $aInjection['data'];
  2345. break;
  2346. case 'service':
  2347. if(BxDolService::isSerializedService($aInjection['data']))
  2348. $sInjData = BxDolService::callSerialized($aInjection['data']);
  2349. break;
  2350. }
  2351. if((int)$aInjection['replace'] == 1)
  2352. $sValue = $sInjData;
  2353. else
  2354. $sValue .= $sInjData;
  2355. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->endInjection($sRand, $aInjection);
  2356. }
  2357. return $sValue != '__' . $sKey . '__' ? str_replace('__' . $sKey . '__', '', $sValue) : $sValue;
  2358. }
  2359. /**
  2360. * Static method to add ingection available on the current page only.
  2361. *
  2362. * @param string $sKey - template's key.
  2363. * @param string $sType - injection type(text, php).
  2364. * @param string $sData - the data to be added.
  2365. * @param integer $iReplace - replace already existed data or not.
  2366. */
  2367. function addInjection($sKey, $sType, $sData, $iReplace = 0)
  2368. {
  2369. $this->aPage['injections']['page_0'][$sKey][] = array(
  2370. 'page_index' => 0,
  2371. 'key' => $sKey,
  2372. 'type' => $sType,
  2373. 'data' => $sData,
  2374. 'replace' => $iReplace
  2375. );
  2376. }
  2377. function getPageCode($oTemplate = null)
  2378. {
  2379. if (empty($oTemplate))
  2380. $oTemplate = $this;
  2381. $oZ = new BxDolAlerts('system', 'design_before_output', 0, 0, array('page' => &$this->aPage, 'page_content' => &$this->aPageContent));
  2382. $oZ->alert();
  2383. header( 'Content-type: text/html; charset=utf-8' );
  2384. header( 'X-Frame-Options: sameorigin' );
  2385. echo $oTemplate->parsePageByName('page_' . $oTemplate->getPageNameIndex() . '.html', $oTemplate->getPageContent());
  2386. }
  2387. }
  2388. /** @} */