BxDolTemplate.php 138 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820
  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_INJECTIONS_CACHE', 'sys_injections.inc');
  11. define('BX_DOL_TEMPLATE_CHECK_IN_BOTH', 'both');
  12. define('BX_DOL_TEMPLATE_CHECK_IN_BASE', 'base');
  13. define('BX_DOL_TEMPLATE_CHECK_IN_TMPL', 'tmpl');
  14. define('BX_DOL_COLOR_BG', 'bg');
  15. define('BX_DOL_COLOR_FT', 'ft');
  16. define('BX_DOL_PAGE_WIDTH', '1024px');
  17. /**
  18. * Page display levels.
  19. * Note. Both levels may refer to the same HTML templates.
  20. *
  21. * 'System' level. It uses page's NameIndex and
  22. * is mainly used for pages which aren't registered
  23. * in 'sys_objects_page' table. Also it's used
  24. * in 'Injections' engine.
  25. */
  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_EMBED', 22); ///< page used for embeds
  29. define('BX_PAGE_POPUP', 44); ///< popup page, without any headers and footers
  30. define('BX_PAGE_CONTENT_PRELOAD', 50); ///< page content preload for dynamic (htmx) loading
  31. define('BX_PAGE_CONTENT_WITH_COVER', 54); ///< page content with cover and submenu for dynamic (htmx) loading
  32. define('BX_PAGE_CONTENT_WITH_SUBMENU', 56); ///< page content with submenu for dynamic (htmx) loading
  33. define('BX_PAGE_CONTENT', 58); ///< page content only for dynamic (htmx) loading
  34. define('BX_PAGE_TRANSITION', 150); ///< transition page with redirect to display some msg, like 'please wait', without headers footers
  35. /**
  36. * 'Builder based' level. It uses page's Type
  37. * from BxDolPage class and is used for pages
  38. * which are registered in 'sys_objects_page' table.
  39. * Changeable in Studio -> Pages Builder -> Settings.
  40. */
  41. define('BX_PAGE_TYPE_DEFAULT', 1); ///< default, depends on the settins
  42. define('BX_PAGE_TYPE_DEFAULT_WO_HF', 2); ///< clear page, without any headers and footers
  43. define('BX_PAGE_TYPE_STANDARD', 3); ///< regular page divided on columns
  44. define('BX_PAGE_TYPE_APPLICATION', 4); ///< regular page divided on columns with left vertical menu(s) column
  45. /**
  46. * Template engine.
  47. *
  48. * An object of the class allows to:
  49. * 1. Manage HTML templates.
  50. * 2. Get URL/path for any template image/icon.
  51. * 3. Attach CSS/JavaScript files to the output.
  52. * 4. Add some content to any template key using Injection engine.
  53. *
  54. *
  55. * Avalable constructions.
  56. * 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.
  57. * 2. &lt;bx_include_base:template_name.html /&gt; - the content of the file would be inserted. File would be taken from base directory.
  58. * 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.
  59. * 4. &lt;bx_url_root /&gt; - the value of BX_DOL_URL_ROOT variable will be inserted.
  60. * 5. &lt;bx_url_admin /&gt; - the value of BX_DOL_URL_ADMIN variable will be inserted.
  61. * 6. &lt;bx_text:_language_key /&gt; - _language_key will be translated using language file(function _t()) and inserted.
  62. &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.
  63. &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.
  64. * 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.
  65. * 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.
  66. * 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.
  67. * 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.
  68. * 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.
  69. * 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.
  70. *
  71. *
  72. * Related classes:
  73. * BxDolTemplateAdmin - for processing admin templates.
  74. * Template classes in modules - for processing modiles' templates.
  75. *
  76. *
  77. * Global variables:
  78. * oSysTemplate - is used for template processing in user part.
  79. * oAdmTemplate - is used for template processing in admin part.
  80. *
  81. *
  82. * Add injection:
  83. * 1. Register it in the `sys_injections` table or `sys_injections_admin` table for admin panel.
  84. * 2. Clear injections cache(sys_injections.inc and sys_injections_admin.inc in cache folder).
  85. *
  86. *
  87. * Predefined template keys to add injections:
  88. * 1. injection_head - add injections in the &lt;head&gt; tag.
  89. * 2. injection_body - add ingection(attribute) in the &lt;body&gt; tag.
  90. * 3. injection_header - add injection inside the &lt;body&gt; tag at the very beginning.
  91. * 4. injection_logo_before - add injection at the left of the main logo(inside logo's DIV).
  92. * 5. injection_logo_after - add injection at the right of the main logo(inside logo's DIV).
  93. * 6. injection_between_logo_top_menu - add injection between logo and top menu.
  94. * 7. injection_top_menu_before - add injection at the left of the top menu(inside top menu's DIV).
  95. * 8. injection_top_menu_after - add injection at the right of the top menu(inside top menu's DIV).
  96. * 13. injection_content_before - add injection just before main content(inside content's DIV).
  97. * 14. injection_content_after - add injection just after main content(inside content's DIV).
  98. * 15. injection_between_content_footer - add injection between content and footer.
  99. * 16. injection_footer_before - add injection at the left of the footer(inside footer's DIV).
  100. * 17. injection_footer_after - add injection at the right of the footer(inside footer's DIV).
  101. * 18. injection_footer - add injection inside the &lt;body&gt; tag at the very end.
  102. *
  103. *
  104. * Example of usage:
  105. * @code
  106. * $oSysTemplate = BxDolTemplate::getInstance();
  107. *
  108. * $oSysTemplate->addCss(array('test1.css', 'test2.css'));
  109. * $oSysTemplate->addJs(array('test1.js', 'test2.js'));
  110. * $oSysTemplate->parseHtmlByName('messageBox.html', array(
  111. * 'id' => $iId,
  112. * 'msgText' => $sText,
  113. * 'bx_if:timer' => array(
  114. * 'condition' => $iTimer > 0,
  115. * 'content' => array(
  116. * 'id' => $iId,
  117. * 'time' => 1000 * $iTimer,
  118. * 'on_close' => $sOnClose,
  119. * )
  120. * ),
  121. * 'bx_if:timer' => array(
  122. * array(
  123. * 'name' => $sName,
  124. * 'title' => $sTitle
  125. * ),
  126. * array(
  127. * 'name' => $sName,
  128. * 'title' => $sTitle
  129. * )
  130. * )
  131. * ));
  132. * @endcode
  133. *
  134. *
  135. * Memberships/ACL:
  136. * Doesn't depend on user's membership.
  137. *
  138. *
  139. * Alerts:
  140. * no alerts available
  141. *
  142. */
  143. class BxDolTemplate extends BxDolFactory implements iBxDolSingleton
  144. {
  145. protected static $_sColorClassPrefix = 'col-';
  146. protected static $_sColorClassPrefixBg = 'bg-col-';
  147. protected static $_aColors = array(
  148. 'red1' => array(216, 9, 96),
  149. 'red1-dark' => array(194, 7, 86),
  150. 'red2' => array(231, 68, 30),
  151. 'red2-dark' => array(207, 60, 25),
  152. 'red3' => array(243, 143, 0),
  153. 'red3-dark' => array(218, 128, 0),
  154. 'green1' => array(96, 174, 0),
  155. 'green1-dark' => array(86, 156, 0),
  156. 'green2' => array(209, 211, 0),
  157. 'green2-dark' => array(186, 188, 0),
  158. 'green3' => array(48, 116, 36),
  159. 'green3-dark' => array(43, 104, 32),
  160. 'blue1' => array(10, 61, 143),
  161. 'blue1-dark' => array(9, 54, 128),
  162. 'blue2' => array(0, 164, 165),
  163. 'blue2-dark' => array(0, 146, 148),
  164. 'blue3' => array(0, 160, 206),
  165. 'blue3-dark' => array(0, 143, 184),
  166. 'gray' => array(97, 97, 97),
  167. 'gray-dark' => array(87, 87, 87)
  168. );
  169. protected static $_aImages;
  170. protected static $_sImagesCacheKey;
  171. protected static $_iImagesCacheTTL;
  172. /**
  173. * Main fields
  174. */
  175. protected $_sName;
  176. protected $_sPrefix;
  177. protected $_sRootPath;
  178. protected $_sRootUrl;
  179. protected $_sSubPath;
  180. protected $_sInjectionsTable;
  181. protected $_sInjectionsCache;
  182. protected $_sCode;
  183. protected $_sCodeKey;
  184. protected $_iMix;
  185. protected $_sMixKey;
  186. protected $_sKeyWrapperHtml;
  187. protected $_sFolderHtml;
  188. protected $_sFolderCss;
  189. protected $_sFolderImages;
  190. protected $_sFolderIcons;
  191. protected $_aTemplates;
  192. protected $_aTemplatePatterns;
  193. protected $_aLocations;
  194. protected $_aLocationsJs;
  195. /**
  196. * Cache related fields
  197. */
  198. protected $_bCacheEnable;
  199. protected $_sCacheFolderUrl;
  200. protected $_sCachePublicFolderUrl;
  201. protected $_sCachePublicFolderPath;
  202. protected $_sCacheFilePrefix;
  203. protected $_aCacheExceptions;
  204. protected $_bImagesInline;
  205. protected $_iImagesMaxSize;
  206. protected $_bCssLess;
  207. protected $_bCssCache;
  208. protected $_bCssMinify;
  209. protected $_bCssArchive;
  210. protected $_sCssLessPrefix;
  211. protected $_sCssCachePrefix;
  212. protected $_bJsLess;
  213. protected $_bJsCache;
  214. protected $_bJsMinify;
  215. protected $_bJsArchive;
  216. protected $_sJsCachePrefix;
  217. protected $aPage;
  218. protected $aPageContent;
  219. protected $aPageSnapshot = array();
  220. protected $_oTemplateConfig;
  221. protected $_oTemplateFunctions;
  222. /**
  223. * Constructor
  224. */
  225. protected function __construct($sRootPath = BX_DIRECTORY_PATH_ROOT, $sRootUrl = BX_DOL_URL_ROOT)
  226. {
  227. if(isset($GLOBALS['bxDolClasses'][get_class($this)]))
  228. trigger_error ('Multiple instances are not allowed for the class: ' . get_class($this), E_USER_ERROR);
  229. parent::__construct();
  230. $this->_sPrefix = 'BxDolTemplate';
  231. $this->_sRootPath = $sRootPath;
  232. $this->_sRootUrl = $sRootUrl;
  233. $this->_sInjectionsTable = 'sys_injections';
  234. $this->_sInjectionsCache = BX_DOL_TEMPLATE_INJECTIONS_CACHE;
  235. $this->_sCodeKey = BX_DOL_TEMPLATE_CODE_KEY;
  236. $this->_sMixKey = BX_DOL_TEMPLATE_MIX_KEY;
  237. list(
  238. $this->_sCode,
  239. $this->_sName,
  240. $this->_sSubPath
  241. ) = self::retrieveCode($this->_sCodeKey, $this->_sMixKey, $this->_sRootPath);
  242. $this->_iMix = 0;
  243. if(is_array($this->_sCode))
  244. list($this->_sCode, $this->_iMix) = $this->_sCode;
  245. if(!$this->_sSubPath)
  246. $this->_sSubPath = 'boonex/' . BX_DOL_TEMPLATE_DEFAULT_CODE . '/';
  247. if(!file_exists(BX_DIRECTORY_PATH_MODULES . $this->_sSubPath)) // just for 8.0.0-A6 upgrade
  248. $this->_sSubPath = 'boonex/uni/';
  249. if(isset($_GET[$this->_sCodeKey])) {
  250. if(BxDolPermalinks::getInstance()->redirectIfNecessary(array($this->_sCodeKey)))
  251. exit;
  252. }
  253. $this->_sKeyWrapperHtml = '__';
  254. $this->_sFolderHtml = '';
  255. $this->_sFolderCss = 'css/';
  256. $this->_sFolderImages = 'images/';
  257. $this->_sFolderIcons = 'images/icons/';
  258. $this->_aTemplates = ['html_tags', 'menu_item_addon', 'menu_item_addon_small', 'menu_item_addon_middle'];
  259. $this->_aTemplatePatterns = [
  260. "'<bx_include_auto:([^\s]+) \/>'s" => BX_DOL_TEMPLATE_CHECK_IN_BOTH,
  261. "'<bx_include_auto_mod_general:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_BOTH, 'sub' => 'mod_general'],
  262. "'<bx_include_auto_mod_profile:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_BOTH, 'sub' => 'mod_profile'],
  263. "'<bx_include_auto_mod_group:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_BOTH, 'sub' => 'mod_group'],
  264. "'<bx_include_auto_mod_text:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_BOTH, 'sub' => 'mod_text'],
  265. "'<bx_include_base:([^\s]+) \/>'s" => BX_DOL_TEMPLATE_CHECK_IN_BASE,
  266. "'<bx_include_base_mod_general:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_BASE, 'sub' => 'mod_general'],
  267. "'<bx_include_base_mod_profile:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_BASE, 'sub' => 'mod_profile'],
  268. "'<bx_include_base_mod_group:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_BASE, 'sub' => 'mod_group'],
  269. "'<bx_include_base_mod_text:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_BASE, 'sub' => 'mod_text'],
  270. "'<bx_include_tmpl:([^\s]+) \/>'s" => BX_DOL_TEMPLATE_CHECK_IN_TMPL,
  271. "'<bx_include_tmpl_mod_general:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_TMPL, 'sub' => 'mod_general'],
  272. "'<bx_include_tmpl_mod_profile:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_TMPL, 'sub' => 'mod_profile'],
  273. "'<bx_include_tmpl_mod_group:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_TMPL, 'sub' => 'mod_group'],
  274. "'<bx_include_tmpl_mod_text:([^\s]+) \/>'s" => ['in' => BX_DOL_TEMPLATE_CHECK_IN_TMPL, 'sub' => 'mod_text']
  275. ];
  276. $this->addLocation('system', $this->_sRootPath, $this->_sRootUrl);
  277. $this->addLocationJs('system_inc_js', BX_DIRECTORY_PATH_INC . 'js/' , BX_DOL_URL_ROOT . 'inc/js/');
  278. $this->addLocationJs('system_inc_js_classes', BX_DIRECTORY_PATH_INC . 'js/classes/' , BX_DOL_URL_ROOT . 'inc/js/classes/');
  279. $this->addLocationJs('system_plugins_public', BX_DIRECTORY_PATH_PLUGINS_PUBLIC, BX_DOL_URL_PLUGINS_PUBLIC);
  280. $this->_bCacheEnable = !bx_is_dbg() && !defined('BX_DOL_CRON_EXECUTE') && getParam('sys_template_cache_enable') == 'on';
  281. $this->_sCacheFolderUrl = '';
  282. $this->_sCachePublicFolderUrl = BX_DOL_URL_CACHE_PUBLIC;
  283. $this->_sCachePublicFolderPath = BX_DIRECTORY_PATH_CACHE_PUBLIC;
  284. $this->_sCacheFilePrefix = "bx_templ_";
  285. $this->_aCacheExceptions = ['pt_standard.html', 'menu_icon.html', 'unit_showcase.html'];
  286. $this->_bImagesInline = getParam('sys_template_cache_image_enable') == 'on';
  287. $this->_iImagesMaxSize = (int)getParam('sys_template_cache_image_max_size') * 1024;
  288. $bArchive = getParam('sys_template_cache_compress_enable') == 'on';
  289. $this->_bCssLess = true; //--- Less cannot be disabled for CSS.
  290. $this->_bCssCache = !bx_is_dbg() && !defined('BX_DOL_CRON_EXECUTE') && getParam('sys_template_cache_css_enable') == 'on';
  291. $this->_bCssMinify = $this->_bCssCache && getParam('sys_template_cache_minify_css_enable') == 'on';
  292. $this->_bCssArchive = $this->_bCssCache && $bArchive;
  293. $this->_sCssLessPrefix = $this->_sCacheFilePrefix . 'less_';
  294. $this->_sCssCachePrefix = $this->_sCacheFilePrefix . 'css_';
  295. $this->_bJsLess = false; //--- Less language isn't available for JS at all.
  296. $this->_bJsCache = !bx_is_dbg() && !defined('BX_DOL_CRON_EXECUTE') && getParam('sys_template_cache_js_enable') == 'on';
  297. $this->_bJsMinify = $this->_bJsCache && getParam('sys_template_cache_minify_js_enable') == 'on';
  298. $this->_bJsArchive = $this->_bJsCache && $bArchive;
  299. $this->_sJsCachePrefix = $this->_sCacheFilePrefix . 'js_';
  300. $this->aPage = [];
  301. $this->aPageContent = [];
  302. }
  303. /**
  304. * Prevent cloning the instance
  305. */
  306. public function __clone()
  307. {
  308. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  309. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  310. }
  311. /**
  312. * Get singleton instance of the class
  313. */
  314. public static function getInstance()
  315. {
  316. if(!isset($GLOBALS['bxDolClasses'][__CLASS__])) {
  317. $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolTemplate();
  318. $GLOBALS['bxDolClasses'][__CLASS__]->init();
  319. }
  320. return $GLOBALS['bxDolClasses'][__CLASS__];
  321. }
  322. /**
  323. * Retrieve template code and check whether it's associated with active template or not.
  324. *
  325. * @param string $sCodeKey template's code key.
  326. * @param string $sMixKey template's mix key.
  327. * @param string $sRootPath path to root directory.
  328. */
  329. public static function retrieveCode($sCodeKey = BX_DOL_TEMPLATE_CODE_KEY, $sMixKey = BX_DOL_TEMPLATE_MIX_KEY, $sRootPath = BX_DIRECTORY_PATH_ROOT)
  330. {
  331. $oDb = BxDolDb::getInstance();
  332. $fCheckCode = function($sCode, $bSetCookie) use($sCodeKey, $sRootPath) {
  333. if(empty($sCode) || !preg_match('/^[A-Za-z0-9_-]+$/', $sCode))
  334. return false;
  335. $aModule = BxDolModuleQuery::getInstance()->getModuleByUri($sCode);
  336. if(empty($aModule) || !is_array($aModule) || (int)$aModule['enabled'] != 1 || !file_exists(BX_DIRECTORY_PATH_MODULES . $aModule['path'] . 'data/template/'))
  337. return false;
  338. $aResult = array(
  339. $aModule['uri'], //--- Template module's URI is used as template Code.
  340. $aModule['name'],
  341. $aModule['path'],
  342. );
  343. if(!$bSetCookie || bx_get('preview'))
  344. return $aResult;
  345. bx_setcookie($sCodeKey, $sCode, time() + 60*60*24*365);
  346. return $aResult;
  347. };
  348. $fCheckMix = function($aResult, $iMix, $bSetCookie) use($sMixKey, $sRootPath, $oDb) {
  349. list($sCode, $sName) = $aResult;
  350. if(empty($sName) || empty($iMix))
  351. return false;
  352. $aMix = $oDb->getParamsMix($iMix);
  353. if(empty($aMix) || !is_array($aMix) || $aMix['type'] != $sName)
  354. return false;
  355. if(!$bSetCookie)
  356. return $iMix;
  357. bx_setcookie($sMixKey, $iMix, time() + 60*60*24*365);
  358. return $iMix;
  359. };
  360. $sCode = getParam('template');
  361. if(empty($sCode))
  362. $sCode = BX_DOL_TEMPLATE_DEFAULT_CODE;
  363. $aResult = $fCheckCode($sCode, false);
  364. //--- Check selected template in COOKIE(the lowest priority) ---//
  365. $sCode = !empty($_COOKIE[$sCodeKey]) ? $_COOKIE[$sCodeKey] : '';
  366. $aResultCheck = $fCheckCode($sCode, false);
  367. if($aResultCheck !== false)
  368. $aResult = $aResultCheck;
  369. //--- Check selected template in GET(the highest priority) ---//
  370. $sCode = !empty($_GET[$sCodeKey]) ? $_GET[$sCodeKey] : '';
  371. $aResultCheck = $fCheckCode($sCode, true);
  372. if($aResultCheck !== false)
  373. $aResult = $aResultCheck;
  374. if($aResult === false)
  375. return $aResult;
  376. if(!is_array($aResult[0]))
  377. $aResult[0] = array($aResult[0]);
  378. $iMixDefault = 0;
  379. if (!empty($aResult[1])) {
  380. if (!BxDolDb::getInstance()->isParamInCache($aResult[1] . '_default_mix')) {
  381. $GLOBALS['glMixesDisabled'] = true; // disable mixes, if template doesn't support mixes
  382. } else {
  383. $iMixDefault = (int)getParam($aResult[1] . '_default_mix');
  384. }
  385. }
  386. //--- Check selected mix in COOKIE(the lowest priority) ---//
  387. $iMix = !empty($_COOKIE[$sMixKey]) ? (int)$_COOKIE[$sMixKey] : 0;
  388. $iResultCheck = $fCheckMix($aResult, $iMix, false);
  389. if($iResultCheck !== false) {
  390. $aMix = $oDb->getParamsMix($iMix);
  391. if((int)$aMix['published'] == 0 && $iMix != $iMixDefault) {
  392. $aUrl = parse_url(BX_DOL_URL_ROOT);
  393. $sPath = isset($aUrl['path']) && !empty($aUrl['path']) ? $aUrl['path'] : '/';
  394. setcookie($sMixKey, '', time() - 96 * 3600, $sPath);
  395. unset($_COOKIE[$sMixKey]);
  396. }
  397. else
  398. $aResult[0][1] = $iResultCheck;
  399. }
  400. //--- Check selected mix in GET(the highest priority) ---//
  401. $iMix = !empty($_GET[$sMixKey]) ? (int)$_GET[$sMixKey] : 0;
  402. $iResultCheck = $fCheckMix($aResult, $iMix, true);
  403. if($iResultCheck !== false)
  404. $aResult[0][1] = $iResultCheck;
  405. //--- Get default mix for currently selected template ---//
  406. if(empty($aResult[0][1]) && !empty($iMixDefault)) {
  407. $iResultCheck = $fCheckMix($aResult, $iMixDefault, false);
  408. if($iResultCheck !== false)
  409. $aResult[0][1] = $iResultCheck;
  410. }
  411. if(is_array($aResult[0]) && count($aResult[0]) == 1)
  412. $aResult[0] = $aResult[0][0];
  413. return $aResult;
  414. }
  415. public function getIncludedUrls($sType)
  416. {
  417. if (!isset($this->aPage[$sType]))
  418. return array();
  419. $a = array();
  420. foreach ($this->aPage[$sType] as $r)
  421. $a[] = $r['url'];
  422. return $a;
  423. }
  424. /**
  425. * Remember current state of aPage variable with all css, js, etc
  426. */
  427. public function collectingStart()
  428. {
  429. $this->aPageSnapshot = $this->aPage;
  430. }
  431. public function collectingInject($aCss, $aJs)
  432. {
  433. $a = array('css' => 'aCss', 'js' => 'aJs');
  434. foreach ($a as $s => $sVar) {
  435. if (empty($$sVar))
  436. continue;
  437. $sKey = $s . '_compiled';
  438. foreach ($$sVar as $r)
  439. $this->aPage[$sKey][] = $r;
  440. }
  441. }
  442. /**
  443. * Get difference for non-system css and js files from previously remembered state as ready HTML code,
  444. * additionally filter out css and js from $aExcludeCss and $aExcludeJs arrays
  445. */
  446. public function collectingEndGetCode($aExcludeCss = array(), $aExcludeJs = array(), $sFormat = 'html')
  447. {
  448. if (!is_array($aExcludeCss))
  449. $aExcludeCss = [];
  450. if (!is_array($aExcludeJs))
  451. $aExcludeJs = [];
  452. $aPageSave = $this->aPage; // save current state to restore later
  453. // filter funcs
  454. $fFilterCss = function ($a) use ($aExcludeCss) {
  455. if (in_array($a['url'], $aExcludeCss))
  456. return false;
  457. if (isset($this->aPageSnapshot['css_compiled']))
  458. foreach ($this->aPageSnapshot['css_compiled'] as $r)
  459. if ($r['url'] == $a['url'])
  460. return false;
  461. return true;
  462. };
  463. $fFilterJs = function ($a) use ($aExcludeJs) {
  464. if (in_array($a['url'], $aExcludeJs))
  465. return false;
  466. if (isset($this->aPageSnapshot['js_compiled']))
  467. foreach ($this->aPageSnapshot['js_compiled'] as $r)
  468. if ($r['url'] == $a['url'])
  469. return false;
  470. return true;
  471. };
  472. // diff aPageSnapshot and aPage and output only newly added css/js
  473. $this->aPage['css_compiled'] = array_filter($this->aPage['css_compiled'], $fFilterCss);
  474. $this->aPage['js_compiled'] = array_filter($this->aPage['js_compiled'], $fFilterJs);
  475. // return js/css
  476. $mixedRet = '';
  477. if ('html' == $sFormat) {
  478. $mixedRet .= $this->includeFiles('css');
  479. $mixedRet .= $this->includeFiles('js');
  480. }
  481. else {
  482. $mixedRet = array(
  483. 'css' => $this->aPage['css_compiled'],
  484. 'js' => $this->aPage['js_compiled'],
  485. );
  486. }
  487. // restore original state
  488. $this->aPageSnapshot = array();
  489. $this->aPage = $aPageSave;
  490. return $mixedRet;
  491. }
  492. public function getClassName()
  493. {
  494. return get_class($this);
  495. }
  496. public static function getColorPalette()
  497. {
  498. $aResult = self::$_aColors;
  499. /**
  500. * @hooks
  501. * @hookdef hook-system-get_color_palette 'system', 'get_color_palette' - hook on get color palette
  502. * - $unit_name - equals `system`
  503. * - $action - equals `get_color_palette`
  504. * - $object_id - not used
  505. * - $sender_id - not used
  506. * - $extra_params - array of additional params with the following array keys:
  507. * - `override_result` - [array] by ref, array of colors, can be overridden in hook processing
  508. * @hook @ref hook-system-get_color_palette
  509. */
  510. bx_alert('system', 'get_color_palette', 0, false, array(
  511. 'override_result' => &$aResult
  512. ));
  513. if($aResult != self::$_aColors) {
  514. $oTemplate = self::getInstance();
  515. foreach($aResult as $sName => $aRgb) {
  516. $sRgb = 'rgb(' . trim(implode(', ', $aRgb)) . ') !important';
  517. $oTemplate->addCssStyle('.' . self::$_sColorClassPrefix . $sName, array(
  518. 'color' => $sRgb
  519. ));
  520. $oTemplate->addCssStyle('.' . self::$_sColorClassPrefixBg . $sName, array(
  521. 'background-color' => $sRgb
  522. ));
  523. }
  524. }
  525. return $aResult;
  526. }
  527. public static function getColorCode($mixedName = false, $fOpacity = false)
  528. {
  529. $aPalette = self::getColorPalette();
  530. $aClasses = array_keys($aPalette);
  531. if($mixedName === false || (is_string($mixedName) && !is_numeric($mixedName) && !in_array($mixedName, $aClasses)))
  532. $mixedName = $aClasses[rand(0, count($aClasses) - 1)];
  533. else if(is_numeric($mixedName))
  534. $mixedName = $aClasses[(int)$mixedName % count($aClasses)];
  535. $aColor = $aPalette[$mixedName];
  536. if($fOpacity !== false && is_numeric($fOpacity))
  537. $aColor[] = $fOpacity;
  538. return $aColor;
  539. }
  540. public static function getColorClass($sType = BX_DOL_COLOR_FT, $sName = '')
  541. {
  542. $aClasses = array_keys(self::getColorPalette());
  543. if(empty($sName) || !in_array($sName, $aClasses))
  544. $sName = $aClasses[rand(0, count($aClasses) - 1)];
  545. $sPrefix = '';
  546. switch ($sType) {
  547. case BX_DOL_COLOR_FT:
  548. $sPrefix = self::$_sColorClassPrefix;
  549. break;
  550. case BX_DOL_COLOR_BG:
  551. $sPrefix = self::$_sColorClassPrefixBg;
  552. break;
  553. }
  554. return $sPrefix . $sName;
  555. }
  556. /**
  557. * Load templates.
  558. */
  559. function loadTemplates()
  560. {
  561. $aResult = array();
  562. foreach($this->_aTemplates as $sName)
  563. $aResult[$sName] = $this->getHtml($sName . '.html');
  564. $this->_aTemplates = $aResult;
  565. }
  566. /**
  567. * Initialize template engine.
  568. * Note. The method is executed with the system, you shouldn't execute it in your subclasses.
  569. */
  570. function init()
  571. {
  572. $this->loadTemplates();
  573. //--- Load page elements related static variables ---//
  574. $this->aPage = array(
  575. 'name_index' => BX_PAGE_DEFAULT,
  576. 'type' => BX_PAGE_TYPE_DEFAULT,
  577. 'url' => '',
  578. 'header' => '',
  579. 'header_text' => '',
  580. 'keywords' => array(),
  581. 'location' => array(),
  582. 'title' => '',
  583. 'description' => '',
  584. 'robots' => '',
  585. 'base' => ['href' => BX_DOL_URL_ROOT],
  586. 'css_name' => array(),
  587. 'css_compiled' => array(),
  588. 'css_system' => array(),
  589. 'css_async' => array(),
  590. 'js_name' => array(),
  591. 'js_compiled' => array(),
  592. 'js_system' => array(),
  593. 'js_options' => array(),
  594. 'js_translations' => array(),
  595. 'js_images' => array(),
  596. 'injections' => array()
  597. );
  598. //--- Load default CSS, JS, etc ---//
  599. BxDolPreloader::getInstance()->perform($this);
  600. //--- Load injection's cache ---//
  601. if (getParam('sys_db_cache_enable')) {
  602. $oDb = BxDolDb::getInstance();
  603. $oCache = $oDb->getDbCacheObject();
  604. $sCacheKey = $oDb->genDbCacheKey($this->_sInjectionsCache);
  605. $aInjections = $oCache->getData($sCacheKey);
  606. if ($aInjections === null) {
  607. $aInjections = $this->getInjectionsData();
  608. $oCache->setData ($sCacheKey, $aInjections);
  609. }
  610. }
  611. else
  612. $aInjections = $this->getInjectionsData();
  613. $this->aPage['injections'] = $aInjections;
  614. //--- Load images/icons cache ---//
  615. $this->initImages();
  616. bx_import('BxTemplConfig'); // TODO: for some reason autoloader isn't working here....
  617. $this->_oTemplateConfig = BxTemplConfig::getInstance();
  618. bx_import('BxTemplFunctions');
  619. $this->_oTemplateFunctions = BxTemplFunctions::getInstance($this);
  620. $this->addJsOption('sys_fixed_header');
  621. $this->addJsOption('sys_confirmation_before_redirect');
  622. $this->addJsOption('sys_storage_s3_endpoint');
  623. }
  624. protected function initImages()
  625. {
  626. self::$_iImagesCacheTTL = 86400;
  627. self::$_sImagesCacheKey = 'sys_layout_images_' . $this->_sCode . '_' . bx_site_hash('images') . '.php';
  628. self::$_aImages = BxDolDb::getInstance()->getDbCacheObject()->getData(self::$_sImagesCacheKey);
  629. if(!self::$_aImages)
  630. self::$_aImages = [];
  631. /**
  632. * @hooks
  633. * @hookdef hook-system-get_layout_images 'system', 'get_layout_images' - hook on get layout images
  634. * - $unit_name - equals `system`
  635. * - $action - equals `get_layout_images`
  636. * - $object_id - not used
  637. * - $sender_id - not used
  638. * - $extra_params - array of additional params with the following array keys:
  639. * - `code` - [string] page code
  640. * - `override_result` - [array] by ref, array of images, can be overridden in hook processing
  641. * @hook @ref hook-system-get_layout_images
  642. */
  643. bx_alert('system', 'get_layout_images', 0, false, [
  644. 'code' => $this->_sCode,
  645. 'override_result' => &self::$_aImages
  646. ]);
  647. }
  648. protected function saveImages()
  649. {
  650. if(!self::$_iImagesCacheTTL)
  651. $this->initImages();
  652. BxDolDb::getInstance()->getDbCacheObject()->setData(self::$_sImagesCacheKey, self::$_aImages, self::$_iImagesCacheTTL);
  653. }
  654. protected function getInjectionsData ()
  655. {
  656. $oDb = BxDolDb::getInstance();
  657. $aInjections = $oDb->getAll("SELECT `page_index`, `name`, `key`, `type`, `data`, `replace` FROM `" . $this->_sInjectionsTable . "` WHERE `active`='1'");
  658. if (!$aInjections)
  659. return array();
  660. foreach ($aInjections as $aInjection)
  661. $aInjections['page_' . $aInjection['page_index']][$aInjection['key']][] = $aInjection;
  662. return $aInjections;
  663. }
  664. /**
  665. * Set page name index
  666. * @param int $i name index
  667. */
  668. function setPageNameIndex($i)
  669. {
  670. $this->aPage['name_index'] = $i;
  671. }
  672. /**
  673. * Set page name index by target.
  674. * @param string $s target.
  675. */
  676. function setPageNameIndexByTarget($s)
  677. {
  678. $i = BX_PAGE_DEFAULT;
  679. switch($s) {
  680. case 'bx-content-preload':
  681. $i = BX_PAGE_CONTENT_PRELOAD;
  682. break;
  683. case 'bx-content-with-toolbar-wrapper':
  684. //$i = 52;
  685. break;
  686. case 'bx-content-with-cover-wrapper':
  687. $i = BX_PAGE_CONTENT_WITH_COVER;
  688. break;
  689. case 'bx-content-with-submenu-wrapper':
  690. $i = BX_PAGE_CONTENT_WITH_SUBMENU;
  691. break;
  692. case 'bx-content-wrapper':
  693. $i = BX_PAGE_CONTENT;
  694. break;
  695. }
  696. $this->aPage['name_index'] = $i;
  697. }
  698. /**
  699. * Get page name index
  700. * @return int $i name index
  701. */
  702. function getPageNameIndex()
  703. {
  704. return isset($this->aPage['name_index']) ? (int)$this->aPage['name_index'] : 0;
  705. }
  706. /**
  707. * Set page type
  708. * @param int $i page type
  709. */
  710. function setPageType($i)
  711. {
  712. $this->aPage['type'] = $i;
  713. }
  714. /**
  715. * Set page url
  716. * @param string $s page url
  717. */
  718. function setPageUrl($s)
  719. {
  720. $this->aPage['url'] = $s;
  721. }
  722. /**
  723. * Get page type
  724. * @return int $i page type
  725. */
  726. function getPageType()
  727. {
  728. $iType = BX_PAGE_TYPE_DEFAULT;
  729. if(isset($this->aPage['type']))
  730. $iType = (int)$this->aPage['type'];
  731. if($iType == BX_PAGE_TYPE_DEFAULT)
  732. $iType = (int)getParam('sys_pt_default_' . (isLogged() ? 'member' : 'visitor'));
  733. return $iType;
  734. }
  735. /**
  736. * Set page header
  737. * @param string $s page header
  738. */
  739. function setPageHeader($s)
  740. {
  741. $this->aPage['header'] = $s;
  742. }
  743. /**
  744. * Get page header
  745. * @return string $s page header
  746. */
  747. function getPageHeader()
  748. {
  749. return $this->aPage['header'];
  750. }
  751. /**
  752. * Set page params. Available page params are: name_index, header
  753. * @param array $a page params
  754. */
  755. function setPageParams($a)
  756. {
  757. if (!empty($this->aPage))
  758. $this->aPage = array_merge($this->aPage, $a);
  759. else
  760. $this->aPage = $a;
  761. }
  762. /**
  763. * Get page params.
  764. * @return array $a page params
  765. */
  766. function getPageParams()
  767. {
  768. return $this->aPage;
  769. }
  770. /**
  771. * Set page meta title.
  772. *
  773. * @param string sTitle necessary page description.
  774. */
  775. function setPageMetaTitle($sTitle)
  776. {
  777. $this->aPage['title'] = $sTitle;
  778. }
  779. /**
  780. * Set page description.
  781. *
  782. * @param string $sDescription necessary page description.
  783. */
  784. function setPageDescription($sDescription)
  785. {
  786. $this->aPage['description'] = $sDescription;
  787. }
  788. /**
  789. * Set page meta robots.
  790. *
  791. * @param string $s page meta robots.
  792. */
  793. function setPageMetaRobots($s)
  794. {
  795. $this->aPage['robots'] = $s;
  796. }
  797. /**
  798. * Set page injections.
  799. *
  800. * @param array $aInjections name => value injections.
  801. */
  802. function setPageInjections($aInjections)
  803. {
  804. if(empty($aInjections) || !is_array($aInjections))
  805. return;
  806. foreach($aInjections as $sName => $sValue)
  807. $this->addInjection('injection_' . $sName, 'text', $sValue);
  808. }
  809. /**
  810. * Set page content for some variable.
  811. * @param string $sVar name of content variable
  812. * @param string $sContent content for $sVar variable
  813. * @param int $iIndex optional page index, default is index which was set before with @see setPageNameIndex function, or 0
  814. */
  815. function setPageContent($sVar, $sContent, $iIndex = false)
  816. {
  817. $i = false !== $iIndex ? $iIndex : $this->getPageNameIndex();
  818. $this->aPageContent[$i][$sVar] = $sContent;
  819. }
  820. /**
  821. * Get page content for some variable.
  822. * @param string $sVar name of content variable
  823. * @param int $iIndex optional page index, default is index which was set before with @see setPageNameIndex function, or 0
  824. * @return string page content for some variable or for the whole page.
  825. */
  826. function getPageContent($sVar = false, $iIndex = false)
  827. {
  828. $i = false !== $iIndex ? $iIndex : $this->getPageNameIndex();
  829. return false !== $sVar ? $this->aPageContent[$i][$sVar] : $this->aPageContent[$i];
  830. }
  831. /**
  832. * Get currently active template name.
  833. *
  834. * @return string template's name.
  835. */
  836. function getName()
  837. {
  838. return $this->_sName;
  839. }
  840. /**
  841. * Get currently active template name.
  842. *
  843. * @return string template's name.
  844. */
  845. function getCssClassName()
  846. {
  847. return str_replace('_', '-', $this->_sName);
  848. }
  849. /**
  850. * Get currently active template code.
  851. *
  852. * @return string template's code.
  853. */
  854. function getCode()
  855. {
  856. return $this->_sCode;
  857. }
  858. /**
  859. * Get embed code.
  860. *
  861. * @return string embed's code.
  862. */
  863. function getEmbed($sContent)
  864. {
  865. if ($sContent == ''){
  866. header('Content-Security-Policy: frame-ancestors ' . getParam('sys_csp_frame_ancestors')) ;
  867. $this->displayPageNotFound('', BX_PAGE_EMBED);
  868. exit;
  869. }
  870. $this->addJs(['inc/js/|embed.js']);
  871. $this->addCss(['embed.css']);
  872. $this->aPage['base']['target'] = '_blank';
  873. $this->setPageNameIndex (BX_PAGE_EMBED);
  874. $this->setPageContent('page_main_code', '<div class="bx-embed">' . $sContent . '</div>');
  875. $this->getPageCode();
  876. }
  877. /**
  878. * Get code key.
  879. *
  880. * @return string template's code key.
  881. */
  882. function getCodeKey()
  883. {
  884. return $this->_sCodeKey;
  885. }
  886. /**
  887. * Get currently active template mix.
  888. *
  889. * @return integer template's mix.
  890. */
  891. function getMix()
  892. {
  893. return $this->_iMix;
  894. }
  895. /**
  896. * Get currently active template path.
  897. *
  898. * @return string template's path.
  899. */
  900. function getPath()
  901. {
  902. return $this->_sSubPath;
  903. }
  904. /**
  905. * Set page title.
  906. * @deprecated use setPageHeader
  907. *
  908. * @param string $sTitle necessary page title.
  909. */
  910. function setPageTitle($sTitle)
  911. {
  912. $this->setPageHeader($sTitle);
  913. }
  914. /**
  915. * Set page's main box title.
  916. * @deprecated use setPageParams
  917. *
  918. * @param string $sTitle necessary page's main box title.
  919. */
  920. function setPageMainBoxTitle($sTitle)
  921. {
  922. $this->setPageParams(array('header_text' => $sTitle));
  923. }
  924. /**
  925. * Check whether location exists or not.
  926. * @param string $sKey - location's unique key.
  927. */
  928. function isLocation($sKey)
  929. {
  930. return isset($this->_aLocations[$sKey]);
  931. }
  932. /**
  933. * Get a lis of all added locations.
  934. * @return array with locations.
  935. */
  936. function getLocations()
  937. {
  938. return $this->_aLocations;
  939. }
  940. /**
  941. * Add location in array of locations.
  942. * Note. Location is the path/url to folder where 'templates' folder is stored.
  943. *
  944. * @param string $sKey - location's unique key.
  945. * @param string $sLocationPath - location's path. For modules: '[path_to_script]/modules/[vendor_name]/[module_name]/'
  946. * @param string $sLocationUrl - location's url. For modules: '[url_to_script]/modules/[vendor_name]/[module_name]/'
  947. */
  948. function addLocation($sKey, $sLocationPath, $sLocationUrl)
  949. {
  950. $this->_aLocations[$sKey] = array(
  951. 'path' => $sLocationPath,
  952. 'url' => $sLocationUrl,
  953. );
  954. return $sKey;
  955. }
  956. /**
  957. * Add dynamic location.
  958. *
  959. * @param string $sLocationPath - location's path. For modules: '[path_to_script]/modules/[vendor_name]/[module_name]/'
  960. * @param string $sLocationUrl - location's url. For modules: '[url_to_script]/modules/[vendor_name]/[module_name]/'
  961. * @return location key. Is needed to remove the location.
  962. */
  963. function addDynamicLocation($sLocationPath, $sLocationUrl)
  964. {
  965. $sLocationKey = time() . mt_rand();
  966. $this->addLocation($sLocationKey, $sLocationPath, $sLocationUrl);
  967. return $sLocationKey;
  968. }
  969. /**
  970. * Remove location from array of locations.
  971. * Note. Location is the path/url to folder where templates are stored.
  972. *
  973. * @param string $sKey - location's unique key.
  974. */
  975. function removeLocation($sKey)
  976. {
  977. if(isset($this->_aLocations[$sKey]))
  978. unset($this->_aLocations[$sKey]);
  979. }
  980. /**
  981. * Check whether JS location exists or not.
  982. * @param string $sKey - JS location's unique key.
  983. */
  984. function isLocationJs($sKey)
  985. {
  986. return isset($this->_aLocationsJs[$sKey]);
  987. }
  988. /**
  989. * Add JS location in array of JS locations.
  990. * Note. Location is the path/url to folder where JS files are stored.
  991. *
  992. * @param string $sKey - location's unique key.
  993. * @param string $sLocationPath - location's path. For modules: '[path_to_script]/modules/[vendor_name]/[module_name]/js/'
  994. * @param string $sLocationUrl - location's url. For modules: '[url_to_script]/modules/[vendor_name]/[module_name]/js/'
  995. */
  996. function addLocationJs($sKey, $sLocationPath, $sLocationUrl)
  997. {
  998. $this->_aLocationsJs[$sKey] = array(
  999. 'path' => $sLocationPath,
  1000. 'url' => $sLocationUrl
  1001. );
  1002. return $sKey;
  1003. }
  1004. /**
  1005. * Add dynamic JS location.
  1006. *
  1007. * @param string $sLocationPath - location's path. For modules: '[path_to_script]/modules/[vendor_name]/[module_name]/'
  1008. * @param string $sLocationUrl - location's url. For modules: '[url_to_script]/modules/[vendor_name]/[module_name]/'
  1009. * @return location key. Is needed to remove the location.
  1010. */
  1011. function addDynamicLocationJs($sLocationPath, $sLocationUrl)
  1012. {
  1013. $sLocationKey = time() . mt_rand();
  1014. $this->addLocationJs($sLocationKey, $sLocationPath, $sLocationUrl);
  1015. return $sLocationKey;
  1016. }
  1017. /**
  1018. * Remove JS location from array of locations.
  1019. * Note. Location is the path/url to folder where templates are stored.
  1020. *
  1021. * @param string $sKey - JS location's unique key.
  1022. */
  1023. function removeLocationJs($sKey)
  1024. {
  1025. if(isset($this->_aLocationsJs[$sKey]))
  1026. unset($this->_aLocationsJs[$sKey]);
  1027. }
  1028. /**
  1029. * Add Option in JS output.
  1030. *
  1031. * @param mixed $mixedName option's name or an array of options' names.
  1032. */
  1033. function addJsOption($mixedName)
  1034. {
  1035. if(is_string($mixedName))
  1036. $mixedName = array($mixedName);
  1037. foreach($mixedName as $sName)
  1038. $this->aPage['js_options'][$sName] = getParam($sName);
  1039. }
  1040. /**
  1041. * Add language translation for key in JS output.
  1042. *
  1043. * @param mixed $mixedKey language key or an array of keys.
  1044. */
  1045. function addJsTranslation($mixedKey, $bDynamic = false)
  1046. {
  1047. if(is_string($mixedKey))
  1048. $mixedKey = array($mixedKey);
  1049. foreach($mixedKey as $sKey)
  1050. $this->aPage['js_translations'][$sKey] = _t($sKey, '{0}', '{1}');
  1051. return $bDynamic ? $this->_processJsTranslations() : '';
  1052. }
  1053. /**
  1054. * get added js translations
  1055. */
  1056. function getJsTranslation($bDynamic = false)
  1057. {
  1058. return $bDynamic ? $this->_processJsTranslations() : $this->aPage['js_translations'];
  1059. }
  1060. /**
  1061. * Add image in JS output.
  1062. *
  1063. * @param array $aImages an array of image descriptors.
  1064. * The descriptor is a key/value pear in the array of descriptors.
  1065. */
  1066. function addJsImage($aImages)
  1067. {
  1068. if(!is_array($aImages))
  1069. return;
  1070. foreach($aImages as $sKey => $sFile) {
  1071. $sUrl = $this->getImageUrl($sFile);
  1072. if(empty($sUrl))
  1073. continue;
  1074. $this->aPage['js_images'][$sKey] = $sUrl;
  1075. }
  1076. }
  1077. /**
  1078. * Add icon in JS output.
  1079. *
  1080. * @param array $aIcons an array of icons descriptors.
  1081. * The descriptor is a key/value pear in the array of descriptors.
  1082. */
  1083. function addJsIcon($aIcons)
  1084. {
  1085. if(!is_array($aIcons))
  1086. return;
  1087. foreach($aIcons as $sKey => $sFile) {
  1088. $sUrl = $this->getIconUrl($sFile);
  1089. if(empty($sUrl))
  1090. continue;
  1091. $this->aPage['js_images'][$sKey] = $sUrl;
  1092. }
  1093. }
  1094. /**
  1095. * Add CSS style.
  1096. *
  1097. * @param string $sName CSS class name.
  1098. * @param string $sContent CSS class styles.
  1099. */
  1100. function addCssStyle($sName, $sContent)
  1101. {
  1102. $this->aPage['css_styles'][$sName] = $sContent;
  1103. }
  1104. /**
  1105. * Set page keywords.
  1106. *
  1107. * @param mixed $mixedKeywords necessary page keywords(string - single keyword, array - an array of keywords).
  1108. * @param string $sDevider - string devider.
  1109. */
  1110. function addPageKeywords($mixedKeywords, $sDevider = ',')
  1111. {
  1112. if(is_string($mixedKeywords))
  1113. $mixedKeywords = strpos($mixedKeywords, $sDevider) !== false ? explode($sDevider, $mixedKeywords) : array($mixedKeywords);
  1114. foreach($mixedKeywords as $iKey => $sValue)
  1115. $mixedKeywords[$iKey] = trim($sValue);
  1116. $this->aPage['keywords'] = isset($this->aPage['keywords']) && is_array($this->aPage['keywords']) ? array_merge($this->aPage['keywords'], $mixedKeywords) : $mixedKeywords;
  1117. }
  1118. /**
  1119. * Set page locatoin coordinates.
  1120. *
  1121. * @param $fLat latitude
  1122. * @param $fLng longitude
  1123. */
  1124. function addPageMetaLocation($fLat, $fLng, $sCountryCode)
  1125. {
  1126. $this->aPage['location'] = array('lat' => $fLat, 'lng' => $fLng, 'country' => $sCountryCode);
  1127. }
  1128. /**
  1129. * Set page meta image.
  1130. *
  1131. * @param $sImageUrl meta image url
  1132. */
  1133. function addPageMetaImage($sImageUrl)
  1134. {
  1135. $this->aPage['image'] = $sImageUrl;
  1136. }
  1137. /**
  1138. * Set page rss link.
  1139. *
  1140. * @param $sTitle - rss feed title
  1141. * @param $sUrl - rss feed URL
  1142. */
  1143. function addPageRssLink($sTitle, $sUrl)
  1144. {
  1145. if (!isset($this->aPage['rss']))
  1146. $this->aPage['rss'] = array('title' => $sTitle, 'url' => $sUrl);
  1147. else
  1148. $this->aPage['rss'] = false;
  1149. }
  1150. /**
  1151. * Returns page meta info, like meta keyword, meta description, location, etc
  1152. */
  1153. function getMetaInfo()
  1154. {
  1155. $sRet = '';
  1156. $oPage = BxDolPage::getObjectInstanceByURI();
  1157. $bPage = $oPage !== false;
  1158. // general meta tags
  1159. if(!empty($this->aPage['keywords']) && is_array($this->aPage['keywords']))
  1160. $sRet .= '<meta name="keywords" content="' . bx_html_attribute(implode(',', $this->aPage['keywords'])) . '" />';
  1161. $sDescription = '';
  1162. if(!empty($this->aPage['description']) && is_string($this->aPage['description']))
  1163. $sDescription = $this->aPage['description'];
  1164. if(!$sDescription && $bPage)
  1165. $sDescription = $oPage->getMetaDescription();
  1166. $bDescription = !empty($sDescription);
  1167. if($bDescription)
  1168. $sRet .= '<meta name="description" content="' . bx_html_attribute($sDescription) . '" />';
  1169. // location
  1170. if(!empty($this->aPage['location']) && isset($this->aPage['location']['lat']) && isset($this->aPage['location']['lng']) && isset($this->aPage['location']['country']))
  1171. $sRet .= '
  1172. <meta name="ICBM" content="' . $this->aPage['location']['lat'] . ';' . $this->aPage['location']['lng'] . '" />
  1173. <meta name="geo.position" content="' . $this->aPage['location']['lat'] . ';' . $this->aPage['location']['lng'] . '" />
  1174. <meta name="geo.region" content="' . bx_html_attribute($this->aPage['location']['country']) . '" />';
  1175. //set meta[image] value
  1176. if(empty($this->aPage['image'])) {
  1177. // use cover image if exists
  1178. if($bPage && ($aCover = $oPage->getPageCoverImage()))
  1179. $this->aPage['image'] = BxDolCover::getInstance($this)->getCoverImageUrl($aCover);
  1180. // use system Apple/Android icons if exists
  1181. if(empty($this->aPage['image'])) {
  1182. $oImgStorage = BxDolStorage::getObjectInstance(BX_DOL_STORAGE_OBJ_IMAGES);
  1183. foreach(['icon_android_splash', 'icon_android', 'icon_apple'] as $sIcon)
  1184. if(($iIcon = (int)getParam('sys_site_' . $sIcon)) != 0 && ($sUrl = $oImgStorage->getFileUrlById($iIcon))) {
  1185. $this->aPage['image'] = $sUrl;
  1186. break;
  1187. }
  1188. }
  1189. }
  1190. // facebook / twitter
  1191. $bPageImage = !empty($this->aPage['image']);
  1192. $sRet .= '<meta name="twitter:card" content="' . ($bPageImage ? 'summary_large_image' : 'summary') . '" />';
  1193. if ($bPageImage)
  1194. $sRet .= '<meta property="og:image" content="' . $this->aPage['image'] . '" />';
  1195. $sRet .= '<meta property="og:title" content="' . (isset($this->aPage['header']) ? bx_html_attribute(strip_tags($this->aPage['header'])) : '') . '" />';
  1196. $sRet .= '<meta property="og:description" content="' . ($bDescription ? bx_html_attribute($sDescription) : '') . '" />';
  1197. // Smart App Banner
  1198. if (getParam('smart_app_banner') && false === strpos($_SERVER['HTTP_USER_AGENT'], 'UNAMobileApp')) {
  1199. if ($sAppIdIOS = getParam('smart_app_banner_ios_app_id'))
  1200. $sRet .= '<meta name="apple-itunes-app" content="app-id=' . $sAppIdIOS . '" />';
  1201. }
  1202. // RSS
  1203. $oFunctions = BxTemplFunctions::getInstance();
  1204. $sRet .= $oFunctions->getManifests();
  1205. $sRet .= $oFunctions->getMetaIcons();
  1206. if (!empty($this->aPage['rss']) && !empty($this->aPage['rss']['url']))
  1207. $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'] . '" />';
  1208. $sRet .= "<link rel=\"alternate\" type=\"application/json+oembed\" href=\"" . BX_DOL_URL_ROOT ."em.php?url=" . urlencode($_SERVER["REQUEST_URI"]) . "&format=json\" title=\"". (isset($this->aPage['header']) ? bx_html_attribute(strip_tags($this->aPage['header'])) : '') . "\" />";
  1209. if (!empty($this->aPage['url'])){
  1210. $sRet .= '<link rel="canonical" href="' . bx_absolute_url(BxDolPermalinks::getInstance()->permalink($this->aPage['url'])) . '" />';
  1211. }
  1212. return $sRet;
  1213. }
  1214. /**
  1215. * Get template, which was loaded earlier.
  1216. * @see method this->loadTemplates and field this->_aTemplates
  1217. *
  1218. * @param string $sName - template name.
  1219. * @return string template's content.
  1220. */
  1221. public function getTemplate($sName)
  1222. {
  1223. return $this->_aTemplates[$sName];
  1224. }
  1225. /**
  1226. * Get template functions object.
  1227. * @see BxBaseFunctions
  1228. */
  1229. public function getTemplateFunctions()
  1230. {
  1231. return $this->_oTemplateFunctions;
  1232. }
  1233. /**
  1234. * Get image MIME type.
  1235. *
  1236. * @param string $sExtension - image file's extension.
  1237. * @return string with MIME type.
  1238. */
  1239. function getImageMimeType($sExtension)
  1240. {
  1241. $sExtension = strtolower($sExtension);
  1242. $sResult = '';
  1243. switch($sExtension) {
  1244. case 'svg':
  1245. $sResult = 'svg+xml';
  1246. break;
  1247. default:
  1248. $sResult = $sExtension;
  1249. }
  1250. return 'data:image/' . $sResult;
  1251. }
  1252. /**
  1253. * Get icon template in dependence of a value, provided in $mixedId.
  1254. *
  1255. * @param mixed $mixedId numeric id from Storage, string with template's file name or string with font icon.
  1256. */
  1257. public function getIcon($mixedId, $aParams = array())
  1258. {
  1259. return $this->_getImage('icon', $mixedId, $aParams);
  1260. }
  1261. /**
  1262. * Get image template in dependence of a value, provided in $mixedId.
  1263. *
  1264. * @param mixed $mixedId numeric id from Storage, string with template's file name or string with font icon.
  1265. */
  1266. public function getImage($mixedId, $aParams = [])
  1267. {
  1268. return $this->_getImage('image', $mixedId, $aParams);
  1269. }
  1270. protected function _getImage($sType, $mixedId, $aParams = [])
  1271. {
  1272. $bWrap = ($sKey = 'wrap_in_tag') && (!isset($aParams[$sKey]) || $aParams[$sKey] === true);
  1273. $sUrl = "";
  1274. $aType2Method = ['image' => 'getImageUrl', 'icon' => 'getIconUrl'];
  1275. //--- Check in System Storage.
  1276. if(is_numeric($mixedId) && (int)$mixedId > 0) {
  1277. $sStorage = BX_DOL_STORAGE_OBJ_IMAGES;
  1278. if(!empty($aParams['storage'])) {
  1279. $sStorage = $aParams['storage'];
  1280. unset($aParams['storage']);
  1281. }
  1282. if(($sResult = BxDolStorage::getObjectInstance($sStorage)->getFileUrlById((int)$mixedId)) !== false)
  1283. $sUrl = $sResult;
  1284. }
  1285. //--- Check in template folders.
  1286. if($sUrl == "" && is_string($mixedId) && strpos($mixedId, '.') !== false)
  1287. $sUrl = $this->{$aType2Method[$sType]}($mixedId);
  1288. if($sUrl != "")
  1289. return $bWrap ? $this->parseImage($sUrl, [
  1290. 'class' => isset($aParams['class']) && !empty($aParams['class']) ? $aParams['class'] : '',
  1291. 'alt' => isset($aParams['alt']) && !empty($aParams['alt']) ? $aParams['alt'] : ''
  1292. ]) : $sUrl;
  1293. //--- Use iconic font.
  1294. return $bWrap ? $this->parseIcon($mixedId, $aParams) : $mixedId;
  1295. }
  1296. /**
  1297. * Get full URL for the icon.
  1298. *
  1299. * @param string $sName icon's file name.
  1300. * @param string $sCheckIn where the content would be searched(base, template, both)
  1301. * @return string full URL.
  1302. */
  1303. function getIconUrl($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  1304. {
  1305. $sContent = "";
  1306. if(($sContent = $this->_getInlineData('icon', $sName, $sCheckIn)) !== false)
  1307. return $sContent;
  1308. return $this->_getAbsoluteLocation('url', $this->_sFolderIcons, $sName, $sCheckIn);
  1309. }
  1310. /**
  1311. * Get absolute Path for the icon.
  1312. *
  1313. * @param string $sName - icon's file name.
  1314. * @param string $sCheckIn where the content would be searched(base, template, both)
  1315. * @return string absolute path.
  1316. */
  1317. function getIconPath($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  1318. {
  1319. return $this->_getAbsoluteLocation('path', $this->_sFolderIcons, $sName, $sCheckIn);
  1320. }
  1321. function getIconContent($sName)
  1322. {
  1323. if(strpos($sName, '.svg') === false)
  1324. return false;
  1325. $mixedResult = false;
  1326. if(($sIconPath = $this->getIconPath($sName)))
  1327. $mixedResult = file_get_contents($sIconPath);
  1328. else
  1329. $mixedResult = bx_file_get_contents($sName);
  1330. return $mixedResult;
  1331. }
  1332. /**
  1333. * Get image/icon by name automatically. Cache item description:
  1334. * [
  1335. * 'v' => value (name, url or source),
  1336. * 'c' => classes list divided with comma (,)
  1337. * 't' => parse type (ic - icon, im - image, sc - source)
  1338. * ]
  1339. * Cached images can be overwritten by listening 'system' - 'get_layout_images' alert.
  1340. *
  1341. * @param string $sName unique name. The following format can be used: name|classes.
  1342. * Where name and classes can consists of multiple parts (divided with comma (,) in HTML variant). For example,
  1343. * in PHP: $this->getImageAuto('far star|class1 class2');
  1344. * in HTML: <bx_image_auto:far,star|class1,class2 />
  1345. * @param boolean $bWrapped wrap in HTML tag or not.
  1346. * @param string $sCheckIn where the content would be searched(base, template, both)
  1347. * @return string icon/image value (name, url or source) or final HTML code.
  1348. */
  1349. function getImageAuto($sName, $bWrapped = true, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  1350. {
  1351. $sDivParts = '|';
  1352. $sDivItems = ',';
  1353. $sKey = md5($sName);
  1354. $sClasses = '';
  1355. if(strpos($sName, $sDivParts) !== false)
  1356. list($sName, $sClasses) = explode($sDivParts, $sName);
  1357. if(strpos($sName, $sDivItems) !== false)
  1358. $sName = implode(' ', explode($sDivItems, $sName));
  1359. if(!isset(self::$_aImages[$sKey])) {
  1360. $aResult = [
  1361. 'v' => $sName,
  1362. 't' => 'ic',
  1363. 'c' => $sClasses
  1364. ];
  1365. $sUrl = '';
  1366. foreach(['Image', 'Icon'] as $sType)
  1367. foreach(['svg', 'png', 'jpg', 'gif'] as $sExt)
  1368. if(($sUrl = $this->{'get' . $sType . 'Url'}($sName . '.' . $sExt, $sCheckIn)) != '') {
  1369. $aResult = [
  1370. 'v' => $sUrl,
  1371. 't' => 'im',
  1372. 'c' => $sClasses
  1373. ];
  1374. break 2;
  1375. }
  1376. self::$_aImages[$sKey] = $aResult;
  1377. $this->saveImages();
  1378. }
  1379. if(!self::$_aImages[$sKey]['v'])
  1380. return '';
  1381. if(!$bWrapped || self::$_aImages[$sKey]['t'] == 'sc')
  1382. return self::$_aImages[$sKey]['v'];
  1383. $aAttrs = [];
  1384. if(self::$_aImages[$sKey]['c'] != '')
  1385. $aAttrs['class'] = implode(' ', explode($sDivItems, self::$_aImages[$sKey]['c']));
  1386. $aType2Method = ['ic' => 'parseIcon', 'im' => 'parseImage'];
  1387. return $this->{$aType2Method[self::$_aImages[$sKey]['t']]}(self::$_aImages[$sKey]['v'], $aAttrs);
  1388. }
  1389. /**
  1390. * Get full URL for the image.
  1391. *
  1392. * @param string $sName - images's file name.
  1393. * @param string $sCheckIn where the content would be searched(base, template, both)
  1394. * @return string full URL.
  1395. */
  1396. function getImageUrl($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  1397. {
  1398. $sContent = "";
  1399. if(($sContent = $this->_getInlineData('image', $sName, $sCheckIn)) !== false)
  1400. return $sContent;
  1401. return $this->_getAbsoluteLocation('url', $this->_sFolderImages, $sName, $sCheckIn);
  1402. }
  1403. /**
  1404. * Get absolute Path for the image.
  1405. *
  1406. * @param string $sName - image's file name.
  1407. * @param string $sCheckIn where the content would be searched(base, template, both)
  1408. * @return string absolute path.
  1409. */
  1410. function getImagePath($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  1411. {
  1412. return $this->_getAbsoluteLocation('path', $this->_sFolderImages, $sName, $sCheckIn);
  1413. }
  1414. /**
  1415. * Get full URL of CSS file.
  1416. *
  1417. * @param string $sName - CSS file name.
  1418. * @param string $sCheckIn where the content would be searched(base, template, both)
  1419. * @return string full URL.
  1420. */
  1421. function getCssUrl($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  1422. {
  1423. if(($aFile = $this->_locateFile('css', $sName)) !== false)
  1424. return $aFile[0];
  1425. return $this->_getAbsoluteLocation('url', $this->_sFolderCss, $sName, $sCheckIn);
  1426. }
  1427. function getCssUrlWithRevision($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  1428. {
  1429. $sUrl = $this->getCssUrl($sName, $sCheckIn);
  1430. if(!empty($sUrl))
  1431. $sUrl = $this->addRevision($sUrl);
  1432. return $sUrl;
  1433. }
  1434. /**
  1435. * Get full Path of CSS file.
  1436. *
  1437. * @param string $sName - CSS file name.
  1438. * @param string $sCheckIn where the content would be searched(base, template, both)
  1439. * @return string full URL.
  1440. */
  1441. function getCssPath($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  1442. {
  1443. if(($aFile = $this->_locateFile('css', $sName)) !== false)
  1444. return $aFile[1];
  1445. return $this->_getAbsoluteLocation('path', $this->_sFolderCss, $sName, $sCheckIn);
  1446. }
  1447. /**
  1448. * Get full URL of JS file.
  1449. *
  1450. * @param string $sName - JS file name.
  1451. * @return string full URL.
  1452. */
  1453. function getJsUrl($sName)
  1454. {
  1455. if(($aFile = $this->_locateFile('js', $sName)) !== false)
  1456. return $aFile[0];
  1457. return $this->_getAbsoluteLocationJs('url', $sName);
  1458. }
  1459. function getJsUrlWithRevision($sName)
  1460. {
  1461. $sUrl = $this->getJsUrl($sName);
  1462. if(!empty($sUrl))
  1463. $sUrl = $this->addRevision($sUrl);
  1464. return $sUrl;
  1465. }
  1466. /**
  1467. * Get full Path of JS file.
  1468. *
  1469. * @param string $sName - JS file name.
  1470. * @return string full URL.
  1471. */
  1472. function getJsPath($sName)
  1473. {
  1474. if(($aFile = $this->_locateFile('js', $sName)) !== false)
  1475. return $aFile[1];
  1476. return $this->_getAbsoluteLocationJs('path', $sName);
  1477. }
  1478. /**
  1479. * Get full URL of Template (HTML) file.
  1480. *
  1481. * @param string $sName - Template file name.
  1482. * @return string full URL.
  1483. */
  1484. function getTemplateUrl($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  1485. {
  1486. return $this->_getAbsoluteLocation('url', $this->_sFolderHtml, $sName, $sCheckIn);
  1487. }
  1488. /**
  1489. * Get full Path of JS file.
  1490. *
  1491. * @param string $sName - JS file name.
  1492. * @return string full URL.
  1493. */
  1494. function getTemplatePath($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  1495. {
  1496. return $this->_getAbsoluteLocation('path', $this->_sFolderHtml, $sName, $sCheckIn);
  1497. }
  1498. /**
  1499. * Get menu.
  1500. * @param $s menu object name
  1501. * @return html or empty string
  1502. */
  1503. function getMenu ($s)
  1504. {
  1505. $oMenu = BxDolMenu::getObjectInstance($s);
  1506. if($s == 'sys_site_submenu'){
  1507. $oPage = BxDolPage::getObjectInstanceByURI();
  1508. if ($oPage && $oPage->getSubMenu() == 'disabled'){
  1509. return;
  1510. }
  1511. }
  1512. return $oMenu ? $oMenu->getCode () : '';
  1513. }
  1514. /**
  1515. * Check whether HTML file exists or not.
  1516. *
  1517. * @param string $sName - HTML file name.
  1518. * @param string $sCheckIn where the content would be searched(base, template, both)
  1519. * @return boolean result of operation.
  1520. */
  1521. function isHtml($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  1522. {
  1523. return $this->_getAbsoluteLocation('path', $this->_sFolderHtml, $sName, $sCheckIn) != '';
  1524. }
  1525. /**
  1526. * Get content of HTML file.
  1527. *
  1528. * @param string $sName - HTML file name.
  1529. * @param string $sCheckIn where the content would be searched(base, template, both)
  1530. * @return string full content of the file and false on failure.
  1531. */
  1532. function getHtml($sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  1533. {
  1534. $sAbsolutePath = $this->_getAbsoluteLocation('path', $this->_sFolderHtml, $sName, $sCheckIn);
  1535. return !empty($sAbsolutePath) ? trim(file_get_contents($sAbsolutePath)) : false;
  1536. }
  1537. /**
  1538. * Parse HTML template. Search for the template with accordance to it's file name.
  1539. *
  1540. * @see allows to use cache.
  1541. *
  1542. * @param string $sName - HTML file name.
  1543. * @param array $aVariables - key/value pairs. key should be the same as template's key, but without prefix and postfix.
  1544. * @param mixed $mixedKeyWrapperHtml - key wrapper(string value if left and right parts are the same, array(left, right) otherwise).
  1545. * @param string $sCheckIn where the content would be searched(base, template, both)
  1546. * @return string the result of operation.
  1547. */
  1548. function parseHtmlByName($sName, $aVariables, $mixedKeyWrapperHtml = null, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  1549. {
  1550. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->beginTemplate($sName, $sRand = time().rand());
  1551. if (($sContent = $this->getCached($sName, $aVariables, $mixedKeyWrapperHtml, $sCheckIn)) !== false) {
  1552. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->endTemplate($sName, $sRand, $sContent, true);
  1553. return $sContent;
  1554. }
  1555. $sRet = '';
  1556. if (($sContent = $this->getHtml($sName, $sCheckIn)) !== false)
  1557. $sRet = $this->_parseContent($sContent, $aVariables, $mixedKeyWrapperHtml);
  1558. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->endTemplate($sName, $sRand, $sRet, false);
  1559. return $sRet;
  1560. }
  1561. /**
  1562. * Parse HTML template.
  1563. *
  1564. * @see Doesn't allow to use cache.
  1565. *
  1566. * @param string $sContent - HTML file content.
  1567. * @param array $aVariables - key/value pairs. key should be the same as template's key, but without prefix and postfix.
  1568. * @param mixed $mixedKeyWrapperHtml - key wrapper(string value if left and right parts are the same, array(left, right) otherwise).
  1569. * @return string the result of operation.
  1570. */
  1571. function parseHtmlByContent($sContent, $aVariables, $mixedKeyWrapperHtml = null)
  1572. {
  1573. if(empty($sContent))
  1574. return "";
  1575. return $this->_parseContent($sContent, $aVariables, $mixedKeyWrapperHtml);
  1576. }
  1577. /**
  1578. * Parse earlier loaded HTML template.
  1579. *
  1580. * @see Doesn't allow to use cache.
  1581. *
  1582. * @param string $sName - template name.
  1583. * @param array $aVariables - key/value pairs. Key should be the same as template's key, excluding prefix and postfix.
  1584. * @return string the result of operation.
  1585. * @see $this->_aTemplates
  1586. */
  1587. function parseHtmlByTemplateName($sName, $aVariables, $mixedKeyWrapperHtml = null)
  1588. {
  1589. if(!isset($this->_aTemplates[$sName]) || empty($this->_aTemplates[$sName]))
  1590. return "";
  1591. return $this->_parseContent($this->_aTemplates[$sName], $aVariables, $mixedKeyWrapperHtml);
  1592. }
  1593. /**
  1594. * Parse page HTML template. Search for the page's template with accordance to it's file name.
  1595. *
  1596. * @see allows to use cache.
  1597. *
  1598. * @param string $sName - HTML file name.
  1599. * @param array $aVariables - key/value pairs. key should be the same as template's key, but without prefix and postfix.
  1600. * @return string the result of operation.
  1601. */
  1602. function parsePageByName($sName, $aVariables)
  1603. {
  1604. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->beginPage($sName);
  1605. $sContent = $this->parseHtmlByName($sName, $aVariables, $this->_sKeyWrapperHtml, BX_DOL_TEMPLATE_CHECK_IN_BOTH);
  1606. if(empty($sContent)) {
  1607. $aType = BxDolPageQuery::getPageType($this->getPageType());
  1608. if(!empty($aType) && is_array($aType))
  1609. $sContent = $this->parseHtmlByName($aType['template'], $aVariables, $this->_sKeyWrapperHtml, BX_DOL_TEMPLATE_CHECK_IN_BOTH);
  1610. }
  1611. if(empty($sContent))
  1612. $sContent = $this->parseHtmlByName('default.html', $aVariables, $this->_sKeyWrapperHtml, BX_DOL_TEMPLATE_CHECK_IN_BOTH);
  1613. //---Process injection at the very last ---//
  1614. $oTemplate = &$this;
  1615. $sContent = preg_replace_callback("'<bx_injection:([^\s]+) />'s", function($aMatches) use($oTemplate) {
  1616. return $oTemplate->processInjection($oTemplate->getPageNameIndex(), $aMatches[1]);
  1617. }, $sContent);
  1618. //--- Add CSS and JS at the very last ---//
  1619. if(strpos($sContent, '<bx_include_css_styles />') !== false) {
  1620. $aStyles = array(
  1621. 'display' => 'none !important'
  1622. );
  1623. if(isLogged())
  1624. $this->addCssStyle('.bx-hide-when-logged-in', $aStyles);
  1625. else
  1626. $this->addCssStyle('.bx-hide-when-logged-out', $aStyles);
  1627. $sContent = str_replace('<bx_include_css_styles />', $this->includeCssStyles(), $sContent);
  1628. }
  1629. if(strpos($sContent , '<bx_include_css_system />') !== false) {
  1630. $sContent = str_replace('<bx_include_css_system />', $this->includeFiles('css', true), $sContent);
  1631. }
  1632. if(strpos($sContent , '<bx_include_css />') !== false) {
  1633. if (!empty($this->aPage['css_name']))
  1634. $this->addCss($this->aPage['css_name']);
  1635. $sContent = str_replace('<bx_include_css />', $this->includeFiles('css'), $sContent);
  1636. }
  1637. if(strpos($sContent , '<bx_include_js_system />') !== false) {
  1638. $sContent = str_replace('<bx_include_js_system />', $this->includeFiles('js', true), $sContent);
  1639. }
  1640. if(strpos($sContent , '<bx_include_js />') !== false) {
  1641. if (!empty($this->aPage['js_name']))
  1642. $this->addJs($this->aPage['js_name']);
  1643. $sContent = str_replace('<bx_include_js />', $this->includeFiles('js') . $this->includeCssAsync(), $sContent);
  1644. }
  1645. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->endPage($sContent);
  1646. return $sContent;
  1647. }
  1648. /**
  1649. * Parse system keys.
  1650. *
  1651. * @param string $sKey key
  1652. * @return string value associated with the key.
  1653. */
  1654. function parseSystemKey($sKey, $mixedKeyWrapperHtml = null, $bProcessInjection = true)
  1655. {
  1656. $aKeyWrappers = $this->_getKeyWrappers($mixedKeyWrapperHtml);
  1657. $sRet = '';
  1658. switch( $sKey ) {
  1659. case 'page_charset':
  1660. $sRet = 'UTF-8';
  1661. break;
  1662. case 'page_robots':
  1663. if(!empty($this->aPage['robots']) && is_string($this->aPage['robots']))
  1664. $sRet = '<meta name="robots" content="' . bx_html_attribute($this->aPage['robots']) . '" />';
  1665. break;
  1666. case 'meta_info':
  1667. $sRet = $this->getMetaInfo();
  1668. break;
  1669. case 'page_header':
  1670. if (isset($this->aPage['title']) && !empty($this->aPage['title']))
  1671. $sRet = bx_process_output(strip_tags($this->aPage['title']));
  1672. if(empty($sRet) && isset($this->aPage['header']))
  1673. $sRet = bx_process_output(strip_tags($this->aPage['header']));
  1674. break;
  1675. case 'page_header_text':
  1676. if(isset($this->aPage['header_text']))
  1677. $sRet = bx_process_output($this->aPage['header_text']);
  1678. break;
  1679. case 'page_width':
  1680. if (false === strpos($this->_oTemplateConfig->aLessConfig['bx-page-width'], 'px'))
  1681. $sRet = BX_DOL_PAGE_WIDTH;
  1682. else
  1683. $sRet = $this->_oTemplateConfig->aLessConfig['bx-page-width'];
  1684. break;
  1685. case 'page_viewport':
  1686. $sRet = getParam('sys_viewport_meta_tag');
  1687. break;
  1688. case 'system_injection_head':
  1689. $sRet = $this->_oTemplateFunctions->getInjectionHead();
  1690. break;
  1691. case 'system_injection_header':
  1692. $sRet = $this->_oTemplateFunctions->getInjectionHeader();
  1693. break;
  1694. case 'system_injection_footer':
  1695. $sRet = $this->_oTemplateFunctions->getInjectionFooter();
  1696. break;
  1697. case 'lang':
  1698. $sRet = bx_lang_code();
  1699. break;
  1700. case 'lang_direction':
  1701. $sRet = bx_lang_direction();
  1702. break;
  1703. case 'lang_country':
  1704. $sRet = bx_lang_country();
  1705. break;
  1706. case 'lang_with_country':
  1707. $sRet = bx_lang_code_with_country();
  1708. break;
  1709. case 'main_logo':
  1710. $sRet = BxTemplFunctions::getInstance()->getMainLogo();
  1711. break;
  1712. case 'informer':
  1713. $oInformer = BxDolInformer::getInstance($this);
  1714. $sRet = $oInformer ? $oInformer->display() : '';
  1715. break;
  1716. case 'cover':
  1717. $oCover = BxDolCover::getInstance($this);
  1718. $bCover = $oCover->isEnabled();
  1719. if($bCover && ($oPage = BxDolPage::getObjectInstanceByURI()) !== false) {
  1720. $bCover = $oPage->isPageCover();
  1721. if($bCover && !$oCover->isCover()) {
  1722. $aCover = $oPage->getPageCoverImage();
  1723. if(!empty($aCover))
  1724. $oCover->setCoverImageUrl($aCover);
  1725. }
  1726. }
  1727. $sRet = $bCover ? $oCover->display() : $oCover->displayEmpty();
  1728. break;
  1729. case 'site_submenu_class':
  1730. $oMenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  1731. if($oMenu)
  1732. $sRet = $oMenu->getClass();
  1733. break;
  1734. case 'site_submenu_hidden':
  1735. $sClass = 'bx-menu-main-bar-hidden';
  1736. $oPage = BxDolPage::getObjectInstanceByURI();
  1737. if($oPage !== false && !$oPage->isVisiblePageSubmenu()) {
  1738. $sRet = $sClass;
  1739. break;
  1740. }
  1741. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  1742. $oMenuManage = BxDolMenu::getObjectInstance('sys_site_manage');
  1743. if($oMenuSubmenu !== false && !$oMenuSubmenu->isVisible() && $oMenuManage !== false && !$oMenuManage->isVisible()) {
  1744. $sRet = $sClass;
  1745. break;
  1746. }
  1747. break;
  1748. case 'dol_images':
  1749. $sRet = $this->_processJsImages();
  1750. break;
  1751. case 'dol_lang':
  1752. $sRet = $this->_processJsTranslations();
  1753. break;
  1754. case 'dol_options':
  1755. $sRet = $this->_processJsOptions();
  1756. break;
  1757. case 'copyright':
  1758. $sRet = _t( '_copyright', date('Y') ) . getVersionComment();
  1759. break;
  1760. case 'copyright_attr':
  1761. $sRet = bx_html_attribute(_t('_copyright', date('Y')));
  1762. break;
  1763. case 'extra_js':
  1764. $sRet = empty($this->aPage['extra_js']) ? '' : $this->aPage['extra_js'];
  1765. break;
  1766. case 'is_profile_page':
  1767. $sRet = (defined('BX_PROFILE_PAGE')) ? 'true' : 'false';
  1768. break;
  1769. case 'system_js_requred':
  1770. $sRet = _t('_sys_javascript_requred');
  1771. break;
  1772. case 'included_css':
  1773. $sRet = json_encode($this->getIncludedUrls('css_compiled'));
  1774. break;
  1775. case 'included_js':
  1776. $sRet = json_encode($this->getIncludedUrls('js_compiled'));
  1777. break;
  1778. case 'base':
  1779. $sRet = bx_convert_array2attrs($this->aPage['base']);
  1780. break;
  1781. case 'class_name':
  1782. $sRet = $this->getCssClassName();
  1783. if (preg_match('/^[A-Za-z0-9_\-]+$/', bx_get('i')))
  1784. $sRet .= ' bx-page-' . bx_get('i');
  1785. if(!empty($this->_iMix)) {
  1786. $aMix = BxDolDb::getInstance()->getParamsMix($this->_iMix);
  1787. if(isset($aMix['dark']) && (int)$aMix['dark'] == 1)
  1788. $sRet .= ' dark';
  1789. }
  1790. $sRet .= ' bx-dir-' . strtolower(bx_lang_direction());
  1791. break;
  1792. case 'css_media_phone':
  1793. case 'css_media_phone2':
  1794. case 'css_media_tablet':
  1795. case 'css_media_tablet2':
  1796. case 'css_media_desktop':
  1797. $aData = json_decode(getParam('sys_css_media_classes'), true);
  1798. $sKey = str_replace('css_media_', '', $sKey);
  1799. $sRet = $aData[$sKey];
  1800. break;
  1801. case 'service_worker':
  1802. if(getParam('sys_pwa_sw_enable') != 'on')
  1803. break;
  1804. $sRet = "if(navigator && navigator.serviceWorker) navigator.serviceWorker.register('sw.js.php');";
  1805. break;
  1806. case 'socket_engine':
  1807. $sRet = BxDolSockets::getInstance()->getJsCode();
  1808. break;
  1809. case 'info':
  1810. $sRet = 'L:' . bx_get_logged_profile_id();
  1811. if(($oPage = BxDolPage::getObjectInstanceByURI()) !== false && method_exists($oPage, 'getContentInfo')) {
  1812. $aContentInfo = $oPage->getContentInfo();
  1813. if(isset($aContentInfo['id']))
  1814. $sRet .= '-C:' . (int)$aContentInfo['id'];
  1815. if(isset($aContentInfo['profile_id']))
  1816. $sRet .= '-P:' . (int)$aContentInfo['profile_id'];
  1817. }
  1818. break;
  1819. default:
  1820. $sRet = ($sTemplAdd = BxTemplFunctions::getInstance()->TemplPageAddComponent($sKey)) !== false ? $sTemplAdd : $aKeyWrappers['left'] . $sKey . $aKeyWrappers['right'];
  1821. }
  1822. if($bProcessInjection)
  1823. $sRet = $this->processInjection($this->getPageNameIndex(), $sKey, $sRet);
  1824. return $sRet;
  1825. }
  1826. /**
  1827. * Parse tag <A>
  1828. *
  1829. * @param string $sLink link URL
  1830. * @param string $sContent link content
  1831. * @param array $aAttrs an array of key => value pairs
  1832. */
  1833. function parseLink($sLink, $sContent, $aAttrs = array())
  1834. {
  1835. $sAttrs = '';
  1836. foreach($aAttrs as $sKey => $sValue)
  1837. $sAttrs .= ' ' . $sKey . '="' . bx_html_attribute($sValue) . '"';
  1838. return '<a href="' . $sLink . '"' . $sAttrs . '>' . $sContent . '</a>';
  1839. }
  1840. /**
  1841. * Parse tag <A> using provided HTML template
  1842. *
  1843. * @param string $sName template's file name
  1844. * @param string $sLink link URL
  1845. * @param string $sContent link content
  1846. * @param array $aAttrs an array of key => value pairs
  1847. */
  1848. function parseLinkByName($sName, $sLink, $sContent, $aAttrs = array())
  1849. {
  1850. $sAttrs = '';
  1851. foreach($aAttrs as $sKey => $sValue)
  1852. $sAttrs .= ' ' . $sKey . '="' . bx_html_attribute($sValue) . '"';
  1853. return $this->parseHtmlByName($sName, array(
  1854. 'href' => $sLink,
  1855. 'attrs' => $sAttrs,
  1856. 'content' => $sContent
  1857. ));
  1858. }
  1859. /**
  1860. * Parse tag <BUTTON>
  1861. *
  1862. * @param string $sContent link content
  1863. * @param array $aAttrs an array of key => value pairs
  1864. */
  1865. function parseButton($sContent, $aAttrs = array())
  1866. {
  1867. $sAttrs = '';
  1868. foreach($aAttrs as $sKey => $sValue)
  1869. $sAttrs .= ' ' . $sKey . '="' . bx_html_attribute($sValue) . '"';
  1870. return '<button' . $sAttrs . '>' . $sContent . '</button>';
  1871. }
  1872. /**
  1873. * Parse tag <IMG>
  1874. *
  1875. * @param string $sLink URL to image source
  1876. * @param array $aAttrs an array of key => value pairs
  1877. */
  1878. function parseImage($sLink, $aAttrs = [])
  1879. {
  1880. $sAttrs = '';
  1881. foreach($aAttrs as $sKey => $sValue)
  1882. $sAttrs .= ' ' . $sKey . '="' . bx_html_attribute($sValue) . '"';
  1883. return '<img src="' . $sLink . '"' . $sAttrs . ' />';
  1884. }
  1885. function parseImageInline($sName, $aAttrs = [])
  1886. {
  1887. $sAttrs = '';
  1888. foreach($aAttrs as $sKey => $sValue)
  1889. $sAttrs .= ' ' . $sKey . '="' . bx_html_attribute($sValue) . '"';
  1890. return '<img src="' . $this->_getInlineData('image', $sName, BX_DOL_TEMPLATE_CHECK_IN_BOTH, true) . '"' . $sAttrs . ' />';
  1891. }
  1892. /**
  1893. * Parse font based icon in <I> tag
  1894. *
  1895. * @param string $sName font icon name
  1896. * @param array $aAttrs an array of key => value pairs
  1897. */
  1898. function parseIcon($sName, $aAttrs = [])
  1899. {
  1900. $aIcons = BxTemplFunctions::getInstance()->getIcon($sName, $aAttrs);
  1901. if($aIcons[0] != '')
  1902. $aIcons[0] = '';
  1903. return implode($aIcons);
  1904. }
  1905. function parseIconInline($sName, $aAttrs = [])
  1906. {
  1907. $sAttrs = '';
  1908. foreach($aAttrs as $sKey => $sValue)
  1909. $sAttrs .= ' ' . $sKey . '="' . bx_html_attribute($sValue) . '"';
  1910. return '<img src="' . $this->_getInlineData('icon', $sName, BX_DOL_TEMPLATE_CHECK_IN_BOTH, true) . '"' . $sAttrs . ' />';
  1911. }
  1912. function parseTag($sName, $sContent, $aAttrs = [], $aParseParams = [])
  1913. {
  1914. if(!is_array($aAttrs))
  1915. $aAttrs = [];
  1916. $aTags = ['span', 'a', 'button', 'sbutton', 'custom', 'nl', 'extended'];
  1917. $sTmplVarsClass = '';
  1918. $aTmplVarsAttrs = [];
  1919. foreach($aAttrs as $sKey => $sValue) {
  1920. if($sKey == 'class')
  1921. $sTmplVarsClass = $aAttrs[$sKey];
  1922. else
  1923. $aTmplVarsAttrs[] = ['key' => $sKey, 'value' => bx_html_attribute($sValue)];
  1924. }
  1925. $aTemplateVars = $aParseParams['template_vars'] ?? [];
  1926. $aTmplVars = [];
  1927. foreach($aTags as $sTag) {
  1928. $aTmplVarsTag = [];
  1929. $bTmplVarsTag = $sTag == $sName;
  1930. if($bTmplVarsTag)
  1931. $aTmplVarsTag = array_merge([
  1932. 'class' => $sTmplVarsClass,
  1933. 'content' => $sContent,
  1934. 'bx_repeat:attrs' => $aTmplVarsAttrs
  1935. ], $aTemplateVars);
  1936. $aTmplVars['bx_if:' . $sTag] = [
  1937. 'condition' => $bTmplVarsTag,
  1938. 'content' => $aTmplVarsTag
  1939. ];
  1940. }
  1941. $sTemplate = $aParseParams['template_name'] ?? '_tags.html';
  1942. return $this->parseHtmlByName($sTemplate, $aTmplVars);
  1943. }
  1944. function getCacheFilePrefix($sType)
  1945. {
  1946. $sResult = '';
  1947. switch($sType) {
  1948. case 'template':
  1949. $sResult = $this->_sCacheFilePrefix;
  1950. break;
  1951. case 'less':
  1952. $sResult = $this->_sCssLessPrefix;
  1953. break;
  1954. case 'css':
  1955. $sResult = $this->_sCssCachePrefix;
  1956. break;
  1957. case 'js':
  1958. $sResult = $this->_sJsCachePrefix;
  1959. break;
  1960. }
  1961. return $sResult;
  1962. }
  1963. /**
  1964. * Get cache object for templates
  1965. * @return cache class instance
  1966. */
  1967. function getTemplatesCacheObject ()
  1968. {
  1969. $sCacheEngine = getParam('sys_template_cache_engine');
  1970. $oCacheEngine = bx_instance('BxDolCache' . $sCacheEngine);
  1971. if(!$oCacheEngine->isAvailable())
  1972. $oCacheEngine = bx_instance('BxDolCacheFileHtml');
  1973. return $oCacheEngine;
  1974. }
  1975. /**
  1976. * Get template from cache if it's enabled.
  1977. *
  1978. * @param string $sName template name
  1979. * @param string $aVariables key/value pairs. key should be the same as template's key, but without prefix and postfix.
  1980. * @param mixed $mixedKeyWrapperHtml - key wrapper(string value if left and right parts are the same, array(0 => left, 1 => right) otherwise).
  1981. * @param string $sCheckIn where the content would be searched(base, template, both)
  1982. * @param boolean $bEvaluate need to evaluate the template or not.
  1983. * @return string result of operation or false on failure.
  1984. */
  1985. function getCached($sName, &$aVariables, $mixedKeyWrapperHtml = null, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH, $bEvaluate = true)
  1986. {
  1987. // initialization
  1988. if(!$this->_bCacheEnable)
  1989. return false;
  1990. if (in_array($sName, $this->_aCacheExceptions))
  1991. return false;
  1992. $sAbsolutePath = $this->_getAbsoluteLocation('path', $this->_sFolderHtml, $sName, $sCheckIn);
  1993. if(empty($sAbsolutePath))
  1994. return false;
  1995. $oCacheEngine = $this->getTemplatesCacheObject ();
  1996. $isFileBasedEngine = $bEvaluate && method_exists($oCacheEngine, 'getDataFilePath');
  1997. // try to get cached content
  1998. $sCacheVariableName = "a";
  1999. $sCacheKey = $this->_getCacheFileName('html', $sAbsolutePath) . '.php';
  2000. if ($isFileBasedEngine)
  2001. $sCacheContent = $oCacheEngine->getDataFilePath($sCacheKey);
  2002. else
  2003. $sCacheContent = $oCacheEngine->getData($sCacheKey);
  2004. // recreate cache if it is empty
  2005. if ($sCacheContent === null && ($sContent = file_get_contents($sAbsolutePath)) !== false && ($sContent = $this->_compileContent($sContent, "\$" . $sCacheVariableName, 1, $aVariables, $mixedKeyWrapperHtml)) !== false) {
  2006. if (false === $oCacheEngine->setData($sCacheKey, trim($sContent)))
  2007. return false;
  2008. if ($isFileBasedEngine)
  2009. $sCacheContent = $oCacheEngine->getDataFilePath($sCacheKey);
  2010. else
  2011. $sCacheContent = $sContent;
  2012. }
  2013. if ($sCacheContent === null)
  2014. return false;
  2015. // return simple cache content
  2016. if(!$bEvaluate)
  2017. return $sCacheContent;
  2018. // return evaluated cache content
  2019. ob_start();
  2020. $$sCacheVariableName = &$aVariables;
  2021. if ($isFileBasedEngine)
  2022. include($sCacheContent);
  2023. else
  2024. eval('?'.'>' . $sCacheContent);
  2025. $sContent = ob_get_clean();
  2026. return $sContent;
  2027. }
  2028. public function clearTemplatesCache($sType = '')
  2029. {
  2030. if(!$sType)
  2031. $sType = 'template';
  2032. $this->getTemplatesCacheObject()->removeAllByPrefix($this->getCacheFilePrefix($sType));
  2033. }
  2034. public function clearImagesCache($sCode = '')
  2035. {
  2036. if(!$sCode)
  2037. $sCode = $this->_sCode;
  2038. BxDolDb::getInstance()->getDbCacheObject()->removeAllByPrefix('sys_layout_images_' . $sCode . '_');
  2039. }
  2040. /**
  2041. * Add JS file(s) to global output.
  2042. *
  2043. * @param mixed $mixedFiles string value represents a single JS file name. An array - array of JS file names.
  2044. * @param boolean $bDynamic in the dynamic mode JS file(s) are not included to global output, but are returned from the function directly.
  2045. * @return boolean/string result of operation.
  2046. */
  2047. function addJs($mixedFiles, $bDynamic = false)
  2048. {
  2049. return $this->_processFiles('js', 'add', $mixedFiles, $bDynamic);
  2050. }
  2051. function addJsPreloaded($aFiles, $sCallback = false, $sCondition = false, $sConditionElseCallback = false)
  2052. {
  2053. if(!$aFiles)
  2054. return '';
  2055. if(!is_array($aFiles))
  2056. $aFiles = [$aFiles];
  2057. $sMaskLoad = "bx_get_scripts(%s);";
  2058. $sMaskLoadWithCallback = "bx_get_scripts(%s, function() {%s});";
  2059. $sMaskCondition = "if(%s) {%s}";
  2060. $sMaskConditionWithElse = "if(%s) {%s} else {setTimeout(function() {%s}, 10);}";
  2061. $aFilesLocated = [];
  2062. foreach($aFiles as $sFile) {
  2063. $mixedFile = $this->_locateFile('js', $sFile);
  2064. if($mixedFile === false)
  2065. continue;
  2066. list($sUrl) = $mixedFile;
  2067. $aFilesLocated[] = $this->addRevision($sUrl);
  2068. }
  2069. $sFilesLocated = json_encode($aFilesLocated);
  2070. if($sCallback !== false)
  2071. $sResult = sprintf($sMaskLoadWithCallback, $sFilesLocated, $sCallback);
  2072. else
  2073. $sResult = sprintf($sMaskLoad, $sFilesLocated);
  2074. if($sCondition === false)
  2075. return $sResult;
  2076. if($sConditionElseCallback !== false)
  2077. $sResult = sprintf($sMaskConditionWithElse, $sCondition, $sResult, $sConditionElseCallback);
  2078. else
  2079. $sResult = sprintf($sMaskCondition, $sCondition, $sResult);
  2080. return $sResult;
  2081. }
  2082. function addJsPreloadedWrapped($aFiles, $sCallback = false, $sCondition = false, $sConditionElseCallback = false)
  2083. {
  2084. $sCode = $this->addJsPreloaded($aFiles, $sCallback, $sCondition, $sConditionElseCallback);
  2085. if(!$sCode)
  2086. return '';
  2087. return $this->_wrapInTagJsCode($sCode);
  2088. }
  2089. function addJsCodeOnLoad($sCallback)
  2090. {
  2091. $sMaskLoad = "$(document).ready(function() {%s});";
  2092. return sprintf($sMaskLoad, $sCallback);
  2093. }
  2094. function addJsCodeOnLoadWrapped($sCallback)
  2095. {
  2096. $sCode = $this->addJsCodeOnLoad($sCallback);
  2097. return $this->_wrapInTagJsCode($sCode);
  2098. }
  2099. /**
  2100. * get added js files
  2101. */
  2102. function getJs()
  2103. {
  2104. return $this->aPage['js_compiled'];
  2105. }
  2106. /**
  2107. * Add System JS file(s) to global output.
  2108. * System JS files are the files which are attached to all pages. They will be cached separately from the others.
  2109. *
  2110. * @param mixed $mixedFiles string value represents a single JS file name. An array - array of JS file names.
  2111. * @param boolean $bDynamic in the dynamic mode JS file(s) are not included to global output, but are returned from the function directly.
  2112. * @return boolean/string result of operation.
  2113. */
  2114. function addJsSystem($mixedFiles)
  2115. {
  2116. return $this->_processFiles('js', 'add', $mixedFiles, false, true);
  2117. }
  2118. /**
  2119. * Delete JS file(s) from global output.
  2120. *
  2121. * @param mixed $mixedFiles string value represents a single JS file name. An array - array of JS file names.
  2122. * @return boolean result of operation.
  2123. */
  2124. function deleteJs($mixedFiles)
  2125. {
  2126. return $this->_processFiles('js', 'delete', $mixedFiles);
  2127. }
  2128. /**
  2129. * Delete System JS file(s) from global output.
  2130. *
  2131. * @param mixed $mixedFiles string value represents a single JS file name. An array - array of JS file names.
  2132. * @return boolean result of operation.
  2133. */
  2134. function deleteJsSystem($mixedFiles)
  2135. {
  2136. return $this->_processFiles('js', 'delete', $mixedFiles, false, true);
  2137. }
  2138. /**
  2139. * Compile JS files in one file.
  2140. *
  2141. * @param string $sAbsolutePath CSS file absolute path(full URL for external CSS/JS files).
  2142. * @param array $aIncluded an array of already included JS files.
  2143. * @return string result of operation.
  2144. */
  2145. function _compileJs($sAbsolutePath, &$aIncluded)
  2146. {
  2147. if(isset($aIncluded[$sAbsolutePath]))
  2148. return '';
  2149. $bExternal = strpos($sAbsolutePath, "http://") !== false || strpos($sAbsolutePath, "https://") !== false;
  2150. if($bExternal) {
  2151. $sPath = $sAbsolutePath;
  2152. $sName = '';
  2153. $sContent = bx_file_get_contents($sAbsolutePath);
  2154. } else {
  2155. $aFileInfo = pathinfo($sAbsolutePath);
  2156. $sPath = $aFileInfo['dirname'] . DIRECTORY_SEPARATOR;
  2157. $sName = $aFileInfo['basename'];
  2158. $sContent = file_get_contents($sPath . $sName);
  2159. }
  2160. if(empty($sContent))
  2161. return '';
  2162. $sUrl = bx_ltrim_str($sPath, realpath(BX_DIRECTORY_PATH_ROOT), BX_DOL_URL_ROOT);
  2163. $sUrl = str_replace(DIRECTORY_SEPARATOR, '/', $sUrl);
  2164. $sContent = "\r\n/*--- BEGIN: " . $sUrl . $sName . "---*/\r\n" . $sContent . ";\r\n/*--- END: " . $sUrl . $sName . "---*/\r\n";
  2165. $sContent = preg_replace("/\/\/# sourceMappingURL\s*=.*/si", "", $sContent);
  2166. $sContent = str_replace(["\n\r", "\r\n", "\r"], "\n", $sContent);
  2167. $aIncluded[$sAbsolutePath] = 1;
  2168. return preg_replace(
  2169. array(
  2170. "'<bx_url_root />'",
  2171. "'\r\n'"
  2172. ),
  2173. array(
  2174. BX_DOL_URL_ROOT,
  2175. "\n"
  2176. ),
  2177. $sContent
  2178. );
  2179. }
  2180. /**
  2181. * Minify JS
  2182. *
  2183. * @param string $s JS string to minify
  2184. * @return string minified JS string.
  2185. */
  2186. function _minifyJs($s)
  2187. {
  2188. // since each JS file is minified separately, it has to be in own scope
  2189. return "\n {\n" . BxDolMinify::getInstance()->minifyJs($s) . "\n }\n";
  2190. }
  2191. /**
  2192. * Wrap an URL to JS file into JS tag.
  2193. *
  2194. * @param string $sFile - URL to JS file.
  2195. * @return string the result of operation.
  2196. */
  2197. function _wrapInTagJs($sFile)
  2198. {
  2199. if (false !== strpos($sFile, '.mjs.js'))
  2200. return "<script type=\"module\" src=\"" . $sFile . "\"></script>";
  2201. return "<script language=\"javascript\" src=\"" . $sFile . "\"></script>";
  2202. }
  2203. /**
  2204. * Wrap JS code into JS tag.
  2205. *
  2206. * @param string $sCode - JS code.
  2207. * @return string the result of operation.
  2208. */
  2209. function _wrapInTagJsCode($sCode)
  2210. {
  2211. return "<script language=\"javascript\">\n" . $sCode . "\n</script>";
  2212. }
  2213. /**
  2214. * Add CSS file(s) to global output.
  2215. *
  2216. * @param mixed $mixedFiles string value represents a single CSS file name. An array - array of CSS file names.
  2217. * @param boolean $bDynamic in the dynamic mode CSS file(s) are not included to global output, but are returned from the function directly.
  2218. * @return boolean/string result of operation
  2219. */
  2220. function addCss($mixedFiles, $bDynamic = false)
  2221. {
  2222. if($bDynamic)
  2223. return $this->addCssPreloadedWrapped($mixedFiles);
  2224. else
  2225. return $this->_processFiles('css', 'add', $mixedFiles, $bDynamic);
  2226. }
  2227. function addCssPreloaded($aFiles)
  2228. {
  2229. if(!$aFiles)
  2230. return '';
  2231. if(!is_array($aFiles))
  2232. $aFiles = [$aFiles];
  2233. $sMaskLoad = "bx_get_style(%s);";
  2234. $aFilesLocated = [];
  2235. foreach($aFiles as $sFile) {
  2236. $mixedFile = $this->_locateFile('css', $sFile);
  2237. if($mixedFile === false)
  2238. continue;
  2239. list($sUrl) = $mixedFile;
  2240. $aFilesLocated[] = $this->addRevision($sUrl);
  2241. }
  2242. $sFilesLocated = json_encode($aFilesLocated);
  2243. return sprintf($sMaskLoad, $sFilesLocated);
  2244. }
  2245. function addCssPreloadedWrapped($aFiles)
  2246. {
  2247. $sCode = $this->addCssPreloaded($aFiles);
  2248. if(!$sCode)
  2249. return '';
  2250. return $this->_wrapInTagJsCode($sCode);
  2251. }
  2252. /**
  2253. * get added css files
  2254. */
  2255. function getCss()
  2256. {
  2257. return $this->aPage['css_compiled'];
  2258. }
  2259. /**
  2260. * Add additional heavy css file (not very necessary) to load asynchronously for desktop browsers only
  2261. * @param mixed $mixedFiles string value represents a single CSS file name. An array - array of CSS file names.
  2262. */
  2263. function addCssAsync($mixedFiles)
  2264. {
  2265. if (!is_array($mixedFiles))
  2266. $mixedFiles = array($mixedFiles);
  2267. foreach ($mixedFiles as $sFile)
  2268. $this->aPage['css_async'][] = $this->_getAbsoluteLocationCss('url', $sFile);
  2269. $this->addJs('loadCSS.js');
  2270. }
  2271. /**
  2272. * Return script tag with special code to load async css.
  2273. * This tag is added after js files list
  2274. */
  2275. function includeCssAsync ()
  2276. {
  2277. if (empty($this->aPage['css_async']))
  2278. return '';
  2279. $this->aPage['css_async'] = array_unique($this->aPage['css_async']);
  2280. $sList = '';
  2281. foreach ($this->aPage['css_async'] as $sUrl)
  2282. $sList .= 'loadCSS("' . $sUrl . '", document.getElementById("bx_css_async"));';
  2283. // don't load css for mobile devices
  2284. return '
  2285. <script id="bx_css_async">
  2286. if(!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
  2287. ' . $sList . '
  2288. }
  2289. </script>
  2290. ';
  2291. }
  2292. /**
  2293. * Add System CSS file(s) to global output.
  2294. * System CSS files are the files which are attached to all pages. They will be cached separately from the others.
  2295. *
  2296. * @param mixed $mixedFiles string value represents a single CSS file name. An array - array of CSS file names.
  2297. * @return boolean/string result of operation
  2298. */
  2299. function addCssSystem($mixedFiles)
  2300. {
  2301. return $this->_processFiles('css', 'add', $mixedFiles, false, true);
  2302. }
  2303. /**
  2304. * Delete CSS file(s) from global output.
  2305. *
  2306. * @param mixed $mixedFiles string value represents a single CSS file name. An array - array of CSS file names.
  2307. * @return boolean result of operation.
  2308. */
  2309. function deleteCss($mixedFiles)
  2310. {
  2311. return $this->_processFiles('css', 'delete', $mixedFiles);
  2312. }
  2313. /**
  2314. * Delete System CSS file(s) from global output.
  2315. *
  2316. * @param mixed $mixedFiles string value represents a single CSS file name. An array - array of CSS file names.
  2317. * @return boolean result of operation.
  2318. */
  2319. function deleteCssSystem($mixedFiles)
  2320. {
  2321. return $this->_processFiles('css', 'delete', $mixedFiles, false, true);
  2322. }
  2323. /**
  2324. * Compile CSS files' structure(@see \@import css_file_path) in one file.
  2325. *
  2326. * @param string $sAbsolutePath CSS file absolute path(full URL for external CSS/JS files).
  2327. * @param array $aIncluded an array of already included CSS files.
  2328. * @return string result of operation.
  2329. */
  2330. function _compileCss($sAbsolutePath, &$aIncluded)
  2331. {
  2332. if(isset($aIncluded[$sAbsolutePath]))
  2333. return '';
  2334. $bExternal = strpos($sAbsolutePath, "http://") !== false || strpos($sAbsolutePath, "https://") !== false;
  2335. if($bExternal) {
  2336. $sPath = $sAbsolutePath;
  2337. $sName = '';
  2338. $aAPUrl = parse_url($sAbsolutePath);
  2339. if(!empty($aAPUrl['path'])) {
  2340. $aAPPath = pathinfo($aAPUrl['path']);
  2341. if(!empty($aAPPath['basename'])) {
  2342. $sPath = bx_rtrim_str($sAbsolutePath, $aAPPath['basename']);
  2343. $sName = $aAPPath['basename'];
  2344. }
  2345. }
  2346. $sContent = bx_file_get_contents($sAbsolutePath);
  2347. } else {
  2348. $aFileInfo = pathinfo($sAbsolutePath);
  2349. $sPath = $aFileInfo['dirname'] . DIRECTORY_SEPARATOR;
  2350. $sName = $aFileInfo['basename'];
  2351. $sContent = file_get_contents($sPath . $sName);
  2352. }
  2353. if(empty($sContent))
  2354. return '';
  2355. $sUrl = bx_ltrim_str($sPath, realpath(BX_DIRECTORY_PATH_ROOT), BX_DOL_URL_ROOT);
  2356. $sUrl = str_replace(DIRECTORY_SEPARATOR, '/', $sUrl);
  2357. $sContent = "\r\n/*--- BEGIN: " . $sUrl . $sName . "---*/\r\n" . $sContent . "\r\n/*--- END: " . $sUrl . $sName . "---*/\r\n";
  2358. $aIncluded[$sAbsolutePath] = 1;
  2359. $sContent = str_replace(array("\n\r", "\r\n", "\r"), "\n", $sContent);
  2360. if($bExternal) {
  2361. $sContent = preg_replace(
  2362. array(
  2363. "'@import\s+url\s*\(\s*[\'|\"]*\s*([a-zA-Z0-9\.\/_-]+)\s*[\'|\"]*\s*\)\s*;'",
  2364. "'url\s*\(\s*[\'|\"]*\s*([a-zA-Z0-9\.\/\?\#_=-]+)\s*[\'|\"]*\s*\)'"
  2365. ),
  2366. array(
  2367. "",
  2368. "url(" . $sPath . "\\1)"
  2369. ),
  2370. $sContent
  2371. );
  2372. }
  2373. else {
  2374. try {
  2375. $oTemplate = &$this;
  2376. /* Match URL based imports like the following:
  2377. * @import 'http://[domain]/modules/[vendor]/[module]/template/css/view.css';
  2378. * Is mainly needed for CSS files which are gotten from LESS compiler.
  2379. */
  2380. $sContent = preg_replace_callback(
  2381. "'@import\s+[\'|\"]*\s*" . str_replace("/", "\/", BX_DOL_URL_ROOT) . "([a-zA-Z0-9\.\/_-]+)\s*[\'|\"]*\s*;'", function ($aMatches) use($oTemplate, $sPath, &$aIncluded) {
  2382. return $oTemplate->_compileCss(realpath(BX_DIRECTORY_PATH_ROOT . $aMatches[1]), $aIncluded);
  2383. }, $sContent);
  2384. /* Match relative path based imports like the following:
  2385. * @import url(../../../../../../base/profile/template/css/main.css);
  2386. * Is mainly needed for default CSS files.
  2387. */
  2388. $sContent = preg_replace_callback(
  2389. "'@import\s+url\s*\(\s*[\'|\"]*\s*([a-zA-Z0-9\.\/_-]+)\s*[\'|\"]*\s*\)\s*;'", function ($aMatches) use($oTemplate, $sPath, &$aIncluded) {
  2390. return $oTemplate->_compileCss(realpath($sPath . dirname($aMatches[1])) . DIRECTORY_SEPARATOR . basename($aMatches[1]), $aIncluded);
  2391. }, $sContent);
  2392. $sContent = preg_replace_callback(
  2393. "'url\s*\(\s*[\'|\"]*\s*([a-zA-Z0-9\.\/\?\#_=-]+)\s*[\'|\"]*\s*\)'", function ($aMatches) use($oTemplate, $sPath) {
  2394. $sFile = basename($aMatches[1]);
  2395. $sDirectory = dirname($aMatches[1]);
  2396. $sRootPath = realpath(BX_DIRECTORY_PATH_ROOT) . '/';
  2397. $sAbsolutePath = realpath(addslashes($sPath) . $sDirectory) . DIRECTORY_SEPARATOR . $sFile;
  2398. $sRootPath = str_replace(DIRECTORY_SEPARATOR, '/', $sRootPath);
  2399. $sAbsolutePath = str_replace(DIRECTORY_SEPARATOR, '/', $sAbsolutePath);
  2400. return 'url(' . bx_ltrim_str($sAbsolutePath, $sRootPath, BX_DOL_URL_ROOT) . ')';
  2401. }, $sContent);
  2402. }
  2403. catch(Exception $oException) {
  2404. return '';
  2405. }
  2406. }
  2407. return $sContent;
  2408. }
  2409. /**
  2410. * Less CSS
  2411. *
  2412. * @param mixed $mixed CSS string to process with Less compiler or an array with CSS file's Path and URL.
  2413. * @return mixed string or an array with CSS file's Path and URL.
  2414. */
  2415. function _lessCss($mixed)
  2416. {
  2417. if(is_array($mixed) && isset($mixed['url']) && isset($mixed['path'])) {
  2418. $sPathFile = realpath($mixed['path']);
  2419. $aInfoFile = pathinfo($sPathFile);
  2420. if (!isset($aInfoFile['extension']) || $aInfoFile['extension'] != 'less')
  2421. return $mixed;
  2422. $aFiles = array($mixed['path'] => $mixed['url']);
  2423. $aOptions = array('cache_dir' => $this->_sCachePublicFolderPath, 'prefix' => $this->_sCssLessPrefix);
  2424. $sFile = Less_Cache::Get($aFiles, $aOptions, $this->_oTemplateConfig->aLessConfig);
  2425. return array('url' => $this->_sCachePublicFolderUrl . $sFile, 'path' => $this->_sCachePublicFolderPath . $sFile);
  2426. }
  2427. $oLess = new Less_Parser();
  2428. $oLess->ModifyVars($this->_oTemplateConfig->aLessConfig);
  2429. $oLess->parse($mixed);
  2430. return $oLess->getCss();
  2431. }
  2432. /**
  2433. * Minify CSS
  2434. *
  2435. * @param string $s CSS string to minify
  2436. * @return string minified CSS string.
  2437. */
  2438. function _minifyCss($s)
  2439. {
  2440. return BxDolMinify::getInstance()->minifyCss($s);
  2441. }
  2442. /**
  2443. * Wrap an URL to CSS file into CSS tag.
  2444. *
  2445. * @param string $sFile - URL to CSS file.
  2446. * @return string the result of operation.
  2447. */
  2448. function _wrapInTagCss($sFile)
  2449. {
  2450. if (!$sFile)
  2451. return '';
  2452. return "<link href=\"" . $sFile . "\" rel=\"stylesheet\" type=\"text/css\" />";
  2453. }
  2454. /**
  2455. * Wrap CSS code into CSS tag.
  2456. *
  2457. * @param string $sCode - CSS code.
  2458. * @return string the result of operation.
  2459. */
  2460. function _wrapInTagCssCode($sCode)
  2461. {
  2462. return "<style>" . $sCode . "</style>";
  2463. }
  2464. /**
  2465. * Include CSS style(s) in the page's head section.
  2466. */
  2467. function includeCssStyles()
  2468. {
  2469. $sResult = "";
  2470. if(empty($this->aPage['css_styles']) || !is_array($this->aPage['css_styles']))
  2471. return $sResult;
  2472. foreach($this->aPage['css_styles'] as $sName => $aContent) {
  2473. $sContent = "";
  2474. if(!empty($aContent) && is_array($aContent))
  2475. foreach($aContent as $sStyleName => $sStyleValue)
  2476. $sContent .= "\t" . $sStyleName . ": " . $sStyleValue . ";\r\n";
  2477. $sResult .= $sName . " {\r\n" . $sContent . "}\r\n";
  2478. }
  2479. return !empty($sResult) ? $this->_wrapInTagCssCode($sResult) : '';
  2480. }
  2481. /**
  2482. * Include CSS/JS file(s) attached to the page in its head section.
  2483. * @see the method is system and would be called automatically.
  2484. *
  2485. * @param string $sType the type of file('js' or 'css')
  2486. * @return string the result CSS code.
  2487. */
  2488. function includeFiles($sType, $bSystem = false, $bWrap = true)
  2489. {
  2490. $sUpcaseType = ucfirst($sType);
  2491. $sArrayKey = $sType . ($bSystem ? '_system' : '_compiled');
  2492. $aFiles = isset($this->aPage[$sArrayKey]) ? $this->aPage[$sArrayKey] : array();
  2493. if(empty($aFiles) || !is_array($aFiles))
  2494. return "";
  2495. if(!$this->{'_b' . $sUpcaseType . 'Cache'})
  2496. return $this->_includeFiles($sType, $aFiles, $bWrap);
  2497. //--- If cache already exists, return it ---//
  2498. $sMethodWrap = '_wrapInTag' . $sUpcaseType;
  2499. $sMethodCompile = '_compile' . $sUpcaseType;
  2500. $sMethodLess = '_less' . $sUpcaseType;
  2501. $sMethodMinify = '_minify' . $sUpcaseType;
  2502. ksort($aFiles);
  2503. $sName = "";
  2504. foreach($aFiles as $aFile)
  2505. $sName .= $aFile['url'];
  2506. $sName = $this->_getCacheFileName($sType, $sName);
  2507. $sCacheAbsoluteUrl = $this->_sCachePublicFolderUrl . $sName . '.' . $sType;
  2508. $sCacheAbsolutePath = $this->_sCachePublicFolderPath . $sName . '.' . $sType;
  2509. if(file_exists($sCacheAbsolutePath)) {
  2510. if($this->{'_b' . $sUpcaseType . 'Archive'})
  2511. $sCacheAbsoluteUrl = $this->_getLoaderUrl($sType, $sName);
  2512. return $bWrap ? $this->$sMethodWrap($sCacheAbsoluteUrl) : $sCacheAbsoluteUrl;
  2513. }
  2514. //--- Collect all attached CSS/JS in one file ---//
  2515. $sResult = "";
  2516. $aIncluded = array();
  2517. foreach($aFiles as $aFile) {
  2518. if($this->{'_b' . $sUpcaseType . 'Less'})
  2519. $aFile = $this->$sMethodLess($aFile);
  2520. if(($sContent = $this->$sMethodCompile($aFile['path'], $aIncluded)) === false)
  2521. continue;
  2522. if(!preg_match('/[\.-]min.(js|css)$/i', $aFile['path']) && $this->{'_b' . $sUpcaseType . 'Minify'}) // don't minify minified files
  2523. $sContent = $this->$sMethodMinify($sContent);
  2524. $sResult .= $sContent;
  2525. }
  2526. $mixedWriteResult = false;
  2527. if(!empty($sResult) && ($rHandler = fopen($sCacheAbsolutePath, 'w')) !== false) {
  2528. $mixedWriteResult = fwrite($rHandler, $sResult);
  2529. fclose($rHandler);
  2530. @chmod ($sCacheAbsolutePath, BX_DOL_FILE_RIGHTS);
  2531. }
  2532. if($mixedWriteResult === false)
  2533. return $this->_includeFiles($sType, $aFiles, $bWrap);
  2534. if($this->{'_b' . $sUpcaseType . 'Archive'})
  2535. $sCacheAbsoluteUrl = $this->_getLoaderUrl($sType, $sName);
  2536. return $bWrap ? $this->$sMethodWrap($sCacheAbsoluteUrl) : $sCacheAbsoluteUrl;
  2537. }
  2538. /**
  2539. * Include CSS/JS files without caching.
  2540. *
  2541. * @param string $sType the file type (css or js)
  2542. * @param array $aFiles CSS/JS files to be added to the page.
  2543. * @return string result of operation.
  2544. */
  2545. function _includeFiles($sType, &$aFiles, $bWrap = true)
  2546. {
  2547. $sUpcaseType = ucfirst($sType);
  2548. $sMethodWrap = '_wrapInTag' . $sUpcaseType;
  2549. $sMethodLess = '_less' . $sUpcaseType;
  2550. $mixedResult = $bWrap ? "" : [];
  2551. foreach($aFiles as $aFile) {
  2552. if($this->{'_b' . $sUpcaseType . 'Less'})
  2553. $aFile = $this->$sMethodLess($aFile);
  2554. $sFileUrl = $aFile['url'];
  2555. if(!$this->{'_b' . $sUpcaseType . 'Cache'})
  2556. $sFileUrl = $this->addRevision($sFileUrl);
  2557. if($bWrap)
  2558. $mixedResult .= $this->$sMethodWrap($sFileUrl);
  2559. else
  2560. $mixedResult[] = $sFileUrl;
  2561. }
  2562. return $mixedResult;
  2563. }
  2564. /**
  2565. * Insert/Delete CSS file from output stack.
  2566. *
  2567. * @param string $sType the file type (css or js)
  2568. * @param string $sAction add/delete
  2569. * @param mixed $mixedFiles string value represents a single CSS file name. An array - array of CSS file names.
  2570. * @return boolean result of operation.
  2571. */
  2572. function _processFiles($sType, $sAction, $mixedFiles, $bDynamic = false, $bSystem = false)
  2573. {
  2574. if(empty($mixedFiles))
  2575. return $bDynamic ? "" : false;
  2576. if(is_string($mixedFiles))
  2577. $mixedFiles = array($mixedFiles);
  2578. $sUpcaseType = ucfirst($sType);
  2579. $sMethodLocate = '_getAbsoluteLocation' . $sUpcaseType;
  2580. $sMethodWrap = '_wrapInTag' . $sUpcaseType;
  2581. $sResult = '';
  2582. foreach($mixedFiles as $sFile) {
  2583. $mixedFile = $this->_locateFile($sType, $sFile);
  2584. if($mixedFile === false)
  2585. continue;
  2586. list($sUrl, $sPath) = $mixedFile;
  2587. $sArrayKey = $sType . ($bSystem ? '_system' : '_compiled');
  2588. switch($sAction) {
  2589. case 'add':
  2590. /**
  2591. * @hooks
  2592. * @hookdef hook-system-add_files 'system', 'add_files' - hook on add file to page
  2593. * - $unit_name - equals `system`
  2594. * - $action - equals `add_files`
  2595. * - $object_id - not used
  2596. * - $sender_id - not used
  2597. * - $extra_params - array of additional params with the following array keys:
  2598. * - `file` - [string] file name
  2599. * - `type` - [string] file type
  2600. * - `dynamic` - [bool] true if added as dynamic
  2601. * - `system` - [bool] true if system file
  2602. * - `url` - [string] by ref, file url, can be overridden in hook processing
  2603. * - `path` - [string] by ref, file path, can be overridden in hook processing
  2604. * @hook @ref hook-system-add_files
  2605. */
  2606. bx_alert('system', 'add_files', 0, 0, [
  2607. 'file' => $sFile,
  2608. 'type' => $sType,
  2609. 'dynamic' => $bDynamic,
  2610. 'system' => $bSystem,
  2611. 'url' => &$sUrl,
  2612. 'path' => &$sPath,
  2613. ]);
  2614. if($bDynamic)
  2615. $sResult .= $this->$sMethodWrap($this->addRevision($sUrl));
  2616. else {
  2617. $bFound = false;
  2618. $aSearchIn = $bSystem ? $this->aPage[$sArrayKey] : array_merge($this->aPage[$sType . '_system'], $this->aPage[$sArrayKey]);
  2619. foreach($aSearchIn as $iKey => $aValue)
  2620. if($aValue['url'] == $sUrl && $aValue['path'] == $sPath) {
  2621. $bFound = true;
  2622. break;
  2623. }
  2624. if(!$bFound)
  2625. $this->aPage[$sArrayKey][] = array('url' => $sUrl, 'path' => $sPath);
  2626. }
  2627. break;
  2628. case 'delete':
  2629. if(!$bDynamic)
  2630. foreach($this->aPage[$sArrayKey] as $iKey => $aValue)
  2631. if($aValue['url'] == $sUrl) {
  2632. unset($this->aPage[$sArrayKey][$iKey]);
  2633. break;
  2634. }
  2635. break;
  2636. }
  2637. }
  2638. return $bDynamic ? $sResult : true;
  2639. }
  2640. function _locateFile($sType, $sFile)
  2641. {
  2642. //--- Process 3d Party CSS/JS file ---//
  2643. if(strpos($sFile, "http://") !== false || strpos($sFile, "https://") !== false) {
  2644. $sUrl = $sFile;
  2645. $sPath = $sFile;
  2646. }
  2647. //--- Process Custom CSS/JS file ---//
  2648. else if(strpos($sFile, "|") !== false) {
  2649. $sFile = implode('', explode("|", $sFile));
  2650. $sFile = bx_ltrim_str($sFile, BX_DIRECTORY_PATH_ROOT);
  2651. $sUrl = BX_DOL_URL_ROOT . $sFile;
  2652. $sPath = realpath(BX_DIRECTORY_PATH_ROOT . $sFile);
  2653. }
  2654. //--- Process Common CSS/JS file(check in default locations) ---//
  2655. else {
  2656. $sMethodLocate = '_getAbsoluteLocation' . ucfirst($sType);
  2657. $sUrl = $this->$sMethodLocate('url', $sFile);
  2658. $sPath = $this->$sMethodLocate('path', $sFile);
  2659. }
  2660. return !empty($sUrl) && !empty($sPath) ? [$sUrl, $sPath] : false;
  2661. }
  2662. /**
  2663. * Parse content.
  2664. *
  2665. * @param string $sContent - HTML file's content.
  2666. * @param array $aVariables - key/value pairs. key should be the same as template's key, but without prefix and postfix.
  2667. * @param mixed $mixedKeyWrapperHtml - key wrapper(string value if left and right parts are the same, array(0 => left, 1 => right) otherwise).
  2668. * @return string the result of operation.
  2669. */
  2670. function _parseContent($sContent, $aVariables, $mixedKeyWrapperHtml = null)
  2671. {
  2672. $aKeysSrc = array_keys($aVariables);
  2673. $aValuesSrc = array_values($aVariables);
  2674. $aKeyWrappers = $this->_getKeyWrappers($mixedKeyWrapperHtml);
  2675. $sKeyIf = 'bx_if:';
  2676. $sKeyRepeat = 'bx_repeat:';
  2677. $iCountKeys = count($aKeysSrc);
  2678. $aKeys = $aValues = array();
  2679. //--- Parse simple keys ---//
  2680. for ($i = 0; $i < $iCountKeys; $i++) {
  2681. if (strncmp($aKeysSrc[$i], $sKeyRepeat, 10) === 0 || strncmp($aKeysSrc[$i], $sKeyIf, 6) === 0)
  2682. continue;
  2683. $aKeys[] = "'" . $aKeyWrappers['left'] . $aKeysSrc[$i] . $aKeyWrappers['right'] . "'s";
  2684. if (is_string($aValuesSrc[$i]) || is_null($aValuesSrc[$i]))
  2685. $aValues[] = is_null($aValuesSrc[$i]) ? '' : str_replace('$', '\\$', str_replace('\\', '\\\\', $aValuesSrc[$i]));
  2686. else if(is_array($aValuesSrc[$i]))
  2687. $aValues[] = _t('_error occured');
  2688. else
  2689. $aValues[] = $aValuesSrc[$i];
  2690. }
  2691. //--- Parse keys with constructions ---//
  2692. for ($i = 0; $i < $iCountKeys; $i++) {
  2693. if (strncmp($aKeysSrc[$i], $sKeyRepeat, 10) === 0) {
  2694. $sKey = "'<" . $aKeysSrc[$i] . ">(.*)<\/" . $aKeysSrc[$i] . ">'s";
  2695. $aMatches = array();
  2696. preg_match($sKey, $sContent, $aMatches);
  2697. $sValue = '';
  2698. if(isset($aMatches[1]) && !empty($aMatches[1])) {
  2699. if(is_array($aValuesSrc[$i]))
  2700. foreach($aValuesSrc[$i] as $aValue)
  2701. if(is_array($aValue))
  2702. $sValue .= $this->parseHtmlByContent($aMatches[1], $aValue, $mixedKeyWrapperHtml);
  2703. else if(is_string($aValue))
  2704. $sValue .= $aValue;
  2705. else if(is_string($aValuesSrc[$i]))
  2706. $sValue = $aValuesSrc[$i];
  2707. }
  2708. }
  2709. else if (strncmp($aKeysSrc[$i], $sKeyIf, 6) === 0) {
  2710. $sKey = "'<" . $aKeysSrc[$i] . ">(.*)<\/" . $aKeysSrc[$i] . ">'s";
  2711. $aMatches = array();
  2712. preg_match($sKey, $sContent, $aMatches);
  2713. $sValue = '';
  2714. if(isset($aMatches[1]) && !empty($aMatches[1]))
  2715. if(is_array($aValuesSrc[$i]) && isset($aValuesSrc[$i]['content']) && isset($aValuesSrc[$i]['condition']) && $aValuesSrc[$i]['condition'])
  2716. $sValue .= $this->parseHtmlByContent($aMatches[1], $aValuesSrc[$i]['content'], $mixedKeyWrapperHtml);
  2717. }
  2718. else
  2719. continue;
  2720. $aKeys[] = $sKey;
  2721. $aValues[] = str_replace('$', '\\$', str_replace('\\', '\\\\', $sValue));
  2722. }
  2723. try {
  2724. $oTemplate = &$this;
  2725. foreach($this->_aTemplatePatterns as $sPattern => $sCheckIn)
  2726. $sContent = preg_replace_callback($sPattern, function($aMatches) use($oTemplate, $aVariables, $mixedKeyWrapperHtml, $sCheckIn) {
  2727. return $oTemplate->parseHtmlByName($aMatches[1], $aVariables, $mixedKeyWrapperHtml, $sCheckIn);
  2728. }, $sContent);
  2729. $sContent = $this->_parseContentKeys($sContent, array(
  2730. "'<bx_menu:([^\s]+) \/>'s" => 'get_menu',
  2731. ));
  2732. }
  2733. catch(Exception $oException) {
  2734. bx_log('sys_template', "Error in _parseContent method. Cannot parse template insertion (<bx_include... />).\n" .
  2735. " Error ({$oException->getCode()}): {$oException->getMessage()}\n" .
  2736. (getLoggedId() ? " Account ID: " . getLoggedId() . "\n" : ""),
  2737. BX_LOG_ERR
  2738. );
  2739. return '';
  2740. }
  2741. $aKeys = array_merge($aKeys, array(
  2742. "'<bx_url_root />'",
  2743. "'<bx_url_studio />'",
  2744. ));
  2745. $aValues = array_merge($aValues, array(
  2746. BX_DOL_URL_ROOT,
  2747. BX_DOL_URL_STUDIO,
  2748. ));
  2749. //--- Parse Predefined Keys ---//
  2750. $sContent = preg_replace($aKeys, $aValues, $sContent);
  2751. //--- Parse System Keys ---//
  2752. try {
  2753. $sContent = preg_replace_callback("'" . $aKeyWrappers['left'] . "([a-zA-Z0-9_-]+)" . $aKeyWrappers['right'] . "'", function($aMatches) use($oTemplate, $mixedKeyWrapperHtml) {
  2754. return $oTemplate->parseSystemKey($aMatches[1], $mixedKeyWrapperHtml);
  2755. }, $sContent);
  2756. }
  2757. catch(Exception $oException) {
  2758. bx_log('sys_template', "Error in _parseContent method. Cannot parse System Keys.\n" .
  2759. " Error ({$oException->getCode()}): {$oException->getMessage()}\n" .
  2760. (getLoggedId() ? " Account ID: " . getLoggedId() . "\n" : ""),
  2761. BX_LOG_ERR
  2762. );
  2763. return '';
  2764. }
  2765. return $sContent;
  2766. }
  2767. /**
  2768. * Compile content
  2769. *
  2770. * @param string $sContent template.
  2771. * @param string $aVarName variable name to be saved in the output file.
  2772. * @param integer $iVarDepth depth is used to process nesting, for example, in cycles.
  2773. * @param array $aVarValues values to be compiled in.
  2774. * @param mixed $mixedKeyWrapperHtml key wrapper(string value if left and right parts are the same, array(0 => left, 1 => right) otherwise).
  2775. * @return string the result of operation.
  2776. */
  2777. function _compileContent($sContent, $aVarName, $iVarDepth, $aVarValues, $mixedKeyWrapperHtml = null)
  2778. {
  2779. $aKeys = array_keys($aVarValues);
  2780. $aValues = array_values($aVarValues);
  2781. $aKeyWrappers = $this->_getKeyWrappers($mixedKeyWrapperHtml);
  2782. for($i = 0; $i < count($aKeys); $i++) {
  2783. $sVarNameKey = $aVarName . "['" . $aKeys[$i] . "']";
  2784. if(strpos($aKeys[$i], 'bx_repeat:') === 0) {
  2785. $sKey = "'<" . $aKeys[$i] . ">(.*)<\/" . $aKeys[$i] . ">'s";
  2786. $aMatches = array();
  2787. preg_match($sKey, $sContent, $aMatches);
  2788. $sValue = '';
  2789. if(isset($aMatches[1]) && !empty($aMatches[1])) {
  2790. if(empty($aValues[$i]) || !is_array($aValues[$i]))
  2791. return false;
  2792. $sIndex = "\$" . str_repeat("i", $iVarDepth);
  2793. $sValue .= "<?php if(is_array(" . $sVarNameKey . ")) for(" . $sIndex . "=0; " . $sIndex . "<count(" . $sVarNameKey . "); " . $sIndex . "++){ ?>";
  2794. if(($sInnerValue = $this->_compileContent($aMatches[1], $sVarNameKey . "[" . $sIndex . "]", $iVarDepth + 1, current($aValues[$i]), $mixedKeyWrapperHtml)) === false)
  2795. return false;
  2796. $sValue .= $sInnerValue;
  2797. $sValue .= "<?php } else if(is_string(" . $sVarNameKey . ")) echo " . $sVarNameKey . "; ?>";
  2798. }
  2799. }
  2800. else if(strpos($aKeys[$i], 'bx_if:') === 0) {
  2801. $sKey = "'<" . $aKeys[$i] . ">(.*)<\/" . $aKeys[$i] . ">'s";
  2802. $aMatches = array();
  2803. preg_match($sKey, $sContent, $aMatches);
  2804. $sValue = '';
  2805. if(isset($aMatches[1]) && !empty($aMatches[1])) {
  2806. if(!is_array($aValues[$i]) || empty($aValues[$i]['content']) || !is_array($aValues[$i]['content']))
  2807. return false;
  2808. $sValue .= "<?php if(isset(" . $sVarNameKey .") && " . $sVarNameKey . "['condition']){ ?>";
  2809. if(($sInnerValue = $this->_compileContent($aMatches[1], $sVarNameKey . "['content']", $iVarDepth, $aValues[$i]['content'], $mixedKeyWrapperHtml)) === false)
  2810. return false;
  2811. $sValue .= $sInnerValue;
  2812. $sValue .= "<?php } ?>";
  2813. }
  2814. }
  2815. else {
  2816. $sKey = "'" . $aKeyWrappers['left'] . $aKeys[$i] . $aKeyWrappers['right'] . "'s";
  2817. $sValue = "<?php echo(isset(" . $sVarNameKey . ") ? " . $sVarNameKey . " : '');?>";
  2818. }
  2819. $aKeys[$i] = $sKey;
  2820. $aValues[$i] = $sValue;
  2821. }
  2822. try {
  2823. $oTemplate = &$this;
  2824. foreach($this->_aTemplatePatterns as $sPattern => $sCheckIn)
  2825. $sContent = preg_replace_callback($sPattern, function($aMatches) use($oTemplate, $aVarValues, $mixedKeyWrapperHtml, $sCheckIn) {
  2826. $mixedResult = $oTemplate->getCached($aMatches[1], $aVarValues, $mixedKeyWrapperHtml, $sCheckIn, false);
  2827. if($mixedResult === false)
  2828. throw new Exception("Unable to create cache file ({$aMatches[1]}).", 1);
  2829. return $mixedResult;
  2830. }, $sContent);
  2831. $sContent = $this->_parseContentKeys($sContent);
  2832. }
  2833. catch(Exception $oException) {
  2834. if(($iCode = $oException->getCode()) != 1)
  2835. bx_log('sys_template', "Error in _compileContent method. Cannot parse template insertion (<bx_include... />).\n" .
  2836. " Error ({$iCode}): {$oException->getMessage()}\n" .
  2837. (getLoggedId() ? " Account ID: " . getLoggedId() . "\n" : ""),
  2838. BX_LOG_ERR
  2839. );
  2840. return false;
  2841. }
  2842. $aKeys = array_merge($aKeys, [
  2843. "'<bx_menu:([^\s]+) \/>'s",
  2844. "'<bx_url_root />'",
  2845. "'<bx_url_studio />'"
  2846. ]);
  2847. $aValues = array_merge($aValues, [
  2848. "<?php echo \$this->getMenu('\\1'); ?>",
  2849. BX_DOL_URL_ROOT,
  2850. BX_DOL_URL_STUDIO
  2851. ]);
  2852. //--- Parse Predefined Keys ---//
  2853. $sContent = preg_replace($aKeys, $aValues, $sContent);
  2854. //--- Parse System Keys ---//
  2855. $sContent = preg_replace( "'" . $aKeyWrappers['left'] . "([a-zA-Z0-9_-]+)" . $aKeyWrappers['right'] . "'", "<?php echo \$this->parseSystemKey('\\1', \$mixedKeyWrapperHtml);?>", $sContent);
  2856. return $sContent;
  2857. }
  2858. protected function _parseContentKeys($sContent, $aCallbackPatterns = array())
  2859. {
  2860. $oTemplate = &$this;
  2861. $aCallbackPatterns = array_merge($aCallbackPatterns, array(
  2862. "'<bx_image_auto:([^\s]+) \/>'s" => "get_image_auto",
  2863. "'<bx_image_url:([^\s]+) \/>'s" => "get_image_url",
  2864. "'<bx_icon_url:([^\s]+) \/>'s" => "get_icon_url",
  2865. "'<bx_icon_inline:([^\s]+) \/>'s" => "get_icon_inline",
  2866. "'<bx_text:([_\{\}\w\d\s]+[^\s]{1}) \/>'s" => "get_text",
  2867. "'<bx_text_js:([^\s]+) \/>'s" => "get_text_js",
  2868. "'<bx_text_attribute:([^\s]+) \/>'s" => "get_text_attribute",
  2869. "'<bx_page:([^\s]+) \/>'s" => "get_page",
  2870. ));
  2871. foreach($aCallbackPatterns as $sPattern => $sAction)
  2872. $sContent = preg_replace_callback($sPattern, function($aMatches) use($oTemplate, $sAction) {
  2873. $sResult = '';
  2874. switch($sAction) {
  2875. case 'get_image_auto':
  2876. $sResult = $oTemplate->getImageAuto($aMatches[1]);
  2877. break;
  2878. case 'get_image_url':
  2879. $sResult = $oTemplate->getImageUrl($aMatches[1]);
  2880. break;
  2881. case 'get_icon_url':
  2882. $sResult = $oTemplate->getIconUrl($aMatches[1]);
  2883. break;
  2884. case 'get_icon_inline':
  2885. if(($sResult = $this->getIconContent($aMatches[1])) === false)
  2886. $sResult = '';
  2887. break;
  2888. case 'get_text':
  2889. $sResult = _t($aMatches[1]);
  2890. break;
  2891. case 'get_text_js':
  2892. $sResult = bx_js_string(_t($aMatches[1]));
  2893. break;
  2894. case 'get_text_attribute':
  2895. $sResult = bx_html_attribute(_t($aMatches[1]));
  2896. break;
  2897. case 'get_injection':
  2898. $sResult = $oTemplate->processInjection($oTemplate->getPageNameIndex(), $aMatches[1]);
  2899. break;
  2900. case 'get_menu':
  2901. $sResult = $oTemplate->getMenu($aMatches[1]);
  2902. break;
  2903. case 'get_page':
  2904. $oPage = BxDolPage::getObjectInstanceByURI($aMatches[1], false, true);
  2905. $oPage->setSubPage(true);
  2906. $sResult = $oPage ? $oPage->getCode() : '';
  2907. break;
  2908. }
  2909. return $sResult;
  2910. }, $sContent);
  2911. return $sContent;
  2912. }
  2913. /**
  2914. * Get absolute location of some template's part.
  2915. *
  2916. * @param string $sType - result type. Available values 'url' and 'path'.
  2917. * @param string $sFolder - folders to be searched in. @see $_sFolderHtml, $_sFolderCss, $_sFolderImages and $_sFolderIcons
  2918. * @param string $sName - requested part name.
  2919. * @param string $sCheckIn where the content would be searched(base, template, both)
  2920. * @return string absolute location (path/url) of the part.
  2921. */
  2922. function _getAbsoluteLocation($sType, $sFolder, $sName, $sCheckIn = BX_DOL_TEMPLATE_CHECK_IN_BOTH)
  2923. {
  2924. $sDirectory = $this->getPath();
  2925. if($sType == 'path') {
  2926. $sDivider = DIRECTORY_SEPARATOR;
  2927. $sRoot = BX_DIRECTORY_PATH_ROOT;
  2928. } else if($sType == 'url') {
  2929. $sDivider = '/';
  2930. $sRoot = BX_DOL_URL_ROOT;
  2931. }
  2932. $aParts = [];
  2933. if(strpos($sName,'|') !== false) {
  2934. $aParts = explode('|', $sName);
  2935. $sName = $aParts[1];
  2936. if(strpos($aParts[0],'@') !== false) {
  2937. $aLocationParts = explode('@', $aParts[0]);
  2938. $sLocationKey = $this->addLocation($aLocationParts[0], BX_DIRECTORY_PATH_ROOT . $aLocationParts[1], BX_DOL_URL_ROOT . $aLocationParts[1]);
  2939. }
  2940. }
  2941. /**
  2942. * Module(mod) related locations will be checked first in TMPL and BASE,
  2943. * then system(sys) location(s) will be checked in TMPL and BASE.
  2944. */
  2945. $aLocationsList = array_reverse($this->_aLocations, true);
  2946. $aLocationsGrouped = ['mod' => [], 'sys' => []];
  2947. foreach($aLocationsList as $sLocation => $aLocation) {
  2948. if(in_array($sLocation, ['system', 'studio']))
  2949. $aLocationsGrouped['sys'][$sLocation] = $aLocation;
  2950. else
  2951. $aLocationsGrouped['mod'][$sLocation] = $aLocation;
  2952. }
  2953. $sResult = '';
  2954. foreach($aLocationsGrouped as $aLocations) {
  2955. //--- Check it Template.
  2956. $bInSub = false;
  2957. $aCheckIn = [BX_DOL_TEMPLATE_CHECK_IN_BOTH, BX_DOL_TEMPLATE_CHECK_IN_TMPL];
  2958. if(in_array($sCheckIn, $aCheckIn) || $bInSub = (isset($sCheckIn['in'], $sCheckIn['sub']) && in_array($sCheckIn['in'], $aCheckIn)))
  2959. foreach($aLocations as $sKey => $aLocation)
  2960. if((!$bInSub || $sCheckIn['sub'] == $sKey) && extFileExists(BX_DIRECTORY_PATH_MODULES . $this->getPath(). 'data' . DIRECTORY_SEPARATOR . BX_DOL_TEMPLATE_FOLDER_ROOT . DIRECTORY_SEPARATOR . $sKey . DIRECTORY_SEPARATOR . $sFolder . $sName)) {
  2961. $sResult = $sRoot . 'modules' . $sDivider . $sDirectory. 'data' . $sDivider . BX_DOL_TEMPLATE_FOLDER_ROOT . $sDivider . $sKey . $sDivider . $sFolder . $sName;
  2962. break 2;
  2963. }
  2964. //--- Check it Base.
  2965. $bInSub = false;
  2966. $aCheckIn = [BX_DOL_TEMPLATE_CHECK_IN_BOTH, BX_DOL_TEMPLATE_CHECK_IN_BASE];
  2967. if(empty($sResult) && (in_array($sCheckIn, $aCheckIn) || $bInSub = (isset($sCheckIn['in'], $sCheckIn['sub']) && in_array($sCheckIn['in'], $aCheckIn))))
  2968. foreach($aLocations as $sKey => $aLocation)
  2969. if((!$bInSub || $sCheckIn['sub'] == $sKey) && extFileExists($aLocation['path'] . BX_DOL_TEMPLATE_FOLDER_ROOT . DIRECTORY_SEPARATOR . $sFolder . $sName)) {
  2970. $sResult = $aLocation[$sType] . BX_DOL_TEMPLATE_FOLDER_ROOT . $sDivider . $sFolder . $sName;
  2971. break 2;
  2972. }
  2973. }
  2974. /**
  2975. * try to find from received path
  2976. */
  2977. if(!$sResult && isset($aParts[0], $aParts[1]) && @is_file(BX_DIRECTORY_PATH_ROOT . $aParts[0] . DIRECTORY_SEPARATOR . $aParts[1]))
  2978. $sResult = $sRoot . $aParts[0] . $sDivider . $aParts[1];
  2979. if(isset($sLocationKey))
  2980. $this->removeLocation($sLocationKey);
  2981. return $sType == 'path' && !empty($sResult) ? realpath($sResult) : $sResult;
  2982. }
  2983. /**
  2984. * Get absolute location of some template's part.
  2985. *
  2986. * @param string $sType result type. Available values 'url' and 'path'.
  2987. * @param string $sName requested part name.
  2988. * @return string absolute location (path/url) of the part.
  2989. */
  2990. function _getAbsoluteLocationJs($sType, $sName)
  2991. {
  2992. $sResult = '';
  2993. $aLocations = array_reverse($this->_aLocationsJs, true);
  2994. foreach($aLocations as $sKey => $aLocation) {
  2995. if(extFileExists($aLocation['path'] . $sName))
  2996. $sResult = $aLocation[$sType] . $sName;
  2997. else
  2998. continue;
  2999. break;
  3000. }
  3001. return $sType == 'path' && !empty($sResult) ? realpath($sResult) : $sResult;
  3002. }
  3003. function _getAbsoluteLocationCss($sType, $sName)
  3004. {
  3005. $sNameLess = str_replace('.css', '.less', $sName);
  3006. $sResult = $this->_getAbsoluteLocation($sType, $this->_sFolderCss, $sNameLess);
  3007. if(!empty($sResult))
  3008. return $sResult;
  3009. return $this->_getAbsoluteLocation($sType, $this->_sFolderCss, $sName);
  3010. }
  3011. /**
  3012. * Get inline data for Images and Icons.
  3013. *
  3014. * @param string $sType image/icon
  3015. * @param string $sName file name
  3016. * @param string $sCheckIn where the content would be searched(base, template, both)
  3017. * @return unknown
  3018. */
  3019. function _getInlineData($sType, $sName, $sCheckIn, $bForceInline = false)
  3020. {
  3021. switch($sType) {
  3022. case 'image':
  3023. $sFolder = $this->_sFolderImages;
  3024. break;
  3025. case 'icon':
  3026. $sFolder = $this->_sFolderIcons;
  3027. break;
  3028. }
  3029. $sPath = $this->_getAbsoluteLocation('path', $sFolder, $sName, $sCheckIn);
  3030. $iFileSize = 0;
  3031. if(($this->_bImagesInline && ($iFileSize = filesize($sPath)) !== false && $iFileSize < $this->_iImagesMaxSize) || $bForceInline) {
  3032. $aFileInfo = pathinfo($sPath);
  3033. return $this->getImageMimeType($aFileInfo['extension']) . ";base64," . base64_encode(file_get_contents($sPath));
  3034. }
  3035. return false;
  3036. }
  3037. /**
  3038. * Get file name where the template would be cached.
  3039. *
  3040. * @param string $sAbsolutePath template's real path.
  3041. * @return string the result of operation.
  3042. */
  3043. function _getCacheFileName($sType, $sAbsolutePath)
  3044. {
  3045. $sResult = bx_site_hash($sAbsolutePath);
  3046. switch($sType) {
  3047. case 'html':
  3048. $sResult = $this->_sCacheFilePrefix . bx_lang_name() . '_' . $this->_sCode . '_' . $sResult;
  3049. break;
  3050. case 'css':
  3051. $sResult = $this->_sCssCachePrefix . (!empty($this->_iMix) ? $this->_iMix . '_' : '') . $sResult;
  3052. break;
  3053. case 'js':
  3054. $sResult = $this->_sJsCachePrefix . $sResult;
  3055. break;
  3056. }
  3057. return $sResult;
  3058. }
  3059. /**
  3060. * Get template key wrappers(left, right)
  3061. *
  3062. * @param mixed $mixedKeyWrapperHtml key wrapper(string value if left and right parts are the same, array(0 => left, 1 => right) otherwise).
  3063. * @return array result of operation.
  3064. */
  3065. function _getKeyWrappers($mixedKeyWrapperHtml)
  3066. {
  3067. $aResult = array();
  3068. if(!empty($mixedKeyWrapperHtml) && is_string($mixedKeyWrapperHtml))
  3069. $aResult = array('left' => $mixedKeyWrapperHtml, 'right' => $mixedKeyWrapperHtml);
  3070. else if(!empty($mixedKeyWrapperHtml) && is_array($mixedKeyWrapperHtml))
  3071. $aResult = array('left' => $mixedKeyWrapperHtml[0], 'right' => $mixedKeyWrapperHtml[1]);
  3072. else
  3073. $aResult = array('left' => $this->_sKeyWrapperHtml, 'right' => $this->_sKeyWrapperHtml);
  3074. return $aResult;
  3075. }
  3076. /**
  3077. * Process all added language translations and return them as a string.
  3078. *
  3079. * @return string with JS code.
  3080. */
  3081. function _processJsTranslations()
  3082. {
  3083. $sReturn = '';
  3084. if(isset($this->aPage['js_translations']) && is_array($this->aPage['js_translations'])) {
  3085. foreach($this->aPage['js_translations'] as $sKey => $sString)
  3086. $sReturn .= "'" . bx_js_string($sKey) . "': '" . bx_js_string($sString) . "',";
  3087. $sReturn = substr($sReturn, 0, -1);
  3088. }
  3089. return '
  3090. <script language="javascript">
  3091. if (\'undefined\' === typeof(aDolLang))
  3092. var aDolLang = {' . $sReturn . '};
  3093. else
  3094. $.extend(aDolLang, {' . $sReturn . '});
  3095. </script>';
  3096. }
  3097. /**
  3098. * Process all added options and return them as a string.
  3099. *
  3100. * @return string with JS code.
  3101. */
  3102. function _processJsOptions()
  3103. {
  3104. $sReturn = '';
  3105. if(isset($this->aPage['js_options']) && is_array($this->aPage['js_options'])) {
  3106. foreach($this->aPage['js_options'] as $sName => $mixedValue)
  3107. $sReturn .= "'" . bx_js_string($sName) . "': '" . bx_js_string($mixedValue) . "',";
  3108. $sReturn = substr($sReturn, 0, -1);
  3109. }
  3110. return '<script language="javascript">var aDolOptions = {' . $sReturn . '};</script>';
  3111. }
  3112. /**
  3113. * Process all added images and return them as a string.
  3114. *
  3115. * @return string with JS code.
  3116. */
  3117. function _processJsImages()
  3118. {
  3119. $sReturn = '';
  3120. if(isset($this->aPage['js_images']) && is_array($this->aPage['js_images'])) {
  3121. foreach($this->aPage['js_images'] as $sKey => $sUrl)
  3122. $sReturn .= "'" . bx_js_string($sKey) . "': '" . bx_js_string($sUrl) . "',";
  3123. $sReturn = substr($sReturn, 0, -1);
  3124. }
  3125. return '<script language="javascript">var aDolImages = {' . $sReturn . '};</script>';
  3126. }
  3127. /**
  3128. * Get Gzip loader URL.
  3129. *
  3130. * @param $sType content type CSS/JS
  3131. * @param $sName file name.
  3132. * @return string with URL
  3133. */
  3134. function _getLoaderUrl($sType, $sName)
  3135. {
  3136. return BX_DOL_URL_ROOT . 'gzip_loader.php?file=' . $sName . '.' . $sType;
  3137. }
  3138. /**
  3139. * Get current revision number.
  3140. *
  3141. * @return integer number
  3142. */
  3143. public function getRevision()
  3144. {
  3145. return (int)getParam('sys_revision');
  3146. }
  3147. /**
  3148. * Add current revision number to URL.
  3149. *
  3150. * @return string with URL
  3151. */
  3152. public function addRevision($sUrl)
  3153. {
  3154. return bx_append_url_params($sUrl, ['rev' => $this->getRevision()]);
  3155. }
  3156. /**
  3157. *
  3158. * Functions to display pages with errors, messages and so on.
  3159. *
  3160. */
  3161. function displayAccessDenied ($sMsg = '', $iPage = BX_PAGE_DEFAULT, $iDesignBox = BX_DB_PADDING_DEF)
  3162. {
  3163. bx_import('BxDolLanguages');
  3164. header('HTTP/1.0 403 Forbidden');
  3165. header('Status: 403 Forbidden');
  3166. $a = [
  3167. 'title' => _t('_access_denied_page_title'),
  3168. 'content' => _t('_access_denied_page_content'),
  3169. ];
  3170. $this->displayMsg($sMsg ? $sMsg : _t('_Access denied'), false, $iPage, $iDesignBox);
  3171. }
  3172. function displayNoData ($sMsg = '', $iPage = BX_PAGE_DEFAULT, $iDesignBox = BX_DB_PADDING_DEF)
  3173. {
  3174. bx_import('BxDolLanguages');
  3175. header('HTTP/1.0 204 No Content');
  3176. header('Status: 204 No Content');
  3177. $this->displayMsg($sMsg ? $sMsg : _t('_Empty'), false, $iPage, $iDesignBox);
  3178. }
  3179. function displayErrorOccured ($sMsg = '', $iPage = BX_PAGE_DEFAULT, $iDesignBox = BX_DB_PADDING_DEF)
  3180. {
  3181. bx_import('BxDolLanguages');
  3182. header('HTTP/1.0 500 Internal Server Error');
  3183. header('Status: 500 Internal Server Error');
  3184. $this->displayMsg($sMsg ? $sMsg : _t('_error occured'), false, $iPage, $iDesignBox);
  3185. }
  3186. function displayPageNotFound ($sMsg = '', $iPage = BX_PAGE_DEFAULT, $iDesignBox = BX_DB_PADDING_DEF)
  3187. {
  3188. bx_import('BxDolLanguages');
  3189. header('HTTP/1.0 404 Not Found');
  3190. header('Status: 404 Not Found');
  3191. $this->displayMsg($sMsg ? $sMsg : _t('_sys_request_page_not_found_cpt'), false, $iPage, $iDesignBox);
  3192. }
  3193. function displayMsg ($s, $bTranslate = false, $iPage = BX_PAGE_DEFAULT, $iDesignBox = BX_DB_PADDING_DEF)
  3194. {
  3195. $sError = '_Error';
  3196. $bArray = is_array($s);
  3197. $sTitle = $bArray ? $s['title'] : ($bTranslate ? $sError : _t($sError));
  3198. $sContent = $bArray ? $s['content'] : $s;
  3199. if($bTranslate) {
  3200. $sTitle = _t($sTitle);
  3201. $sContent = _t($sContent);
  3202. }
  3203. if (bx_is_api())
  3204. return [bx_api_get_msg($sContent)];
  3205. $sContent = MsgBox($sContent);
  3206. if($iPage == BX_PAGE_DEFAULT)
  3207. $sContent = DesignBoxContent($sTitle, $sContent, $iDesignBox);
  3208. $oTemplate = BxDolTemplate::getInstance();
  3209. $oTemplate->setPageNameIndex ($iPage);
  3210. $oTemplate->setPageHeader ($sTitle);
  3211. $oTemplate->setPageContent ('page_main_code', $sContent);
  3212. $oTemplate->getPageCode();
  3213. exit;
  3214. }
  3215. /**
  3216. * * * * Static methods for work with template injections * * *
  3217. *
  3218. * Static method is used to add/replace the content of some key in the template.
  3219. * It's usefull when you don't want to modify existing template but need to add some data to existing template key.
  3220. *
  3221. * @param integer $iPageIndex - page index where injections would processed. Use 0 if you want it to be done on all the pages.
  3222. * @param string $sKey - template key.
  3223. * @param string $sValue - the data to be added.
  3224. * @return string the result of operation.
  3225. */
  3226. function processInjection($iPageIndex, $sKey, $sValue = "")
  3227. {
  3228. if($iPageIndex != 0 && isset($this->aPage['injections']['page_0'][$sKey]) && isset($this->aPage['injections']['page_' . $iPageIndex][$sKey]))
  3229. $aSelection = @array_merge($this->aPage['injections']['page_0'][$sKey], $this->aPage['injections']['page_' . $iPageIndex][$sKey]);
  3230. else if(isset($this->aPage['injections']['page_0'][$sKey]))
  3231. $aSelection = $this->aPage['injections']['page_0'][$sKey];
  3232. else if(isset($this->aPage['injections']['page_' . $iPageIndex][$sKey]))
  3233. $aSelection = $this->aPage['injections']['page_' . $iPageIndex][$sKey];
  3234. else
  3235. $aSelection = array();
  3236. if(is_array($aSelection))
  3237. foreach($aSelection as $aInjection) {
  3238. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->beginInjection($sRand = time().rand());
  3239. $sInjData = '';
  3240. switch($aInjection['type']) {
  3241. case 'text':
  3242. $sInjData = $aInjection['data'];
  3243. break;
  3244. case 'service':
  3245. if(BxDolService::isSerializedService($aInjection['data']))
  3246. $sInjData = BxDolService::callSerialized($aInjection['data']);
  3247. break;
  3248. }
  3249. if((int)$aInjection['replace'] == 1)
  3250. $sValue = $sInjData;
  3251. else
  3252. $sValue .= $sInjData;
  3253. if (isset($GLOBALS['bx_profiler'])) $GLOBALS['bx_profiler']->endInjection($sRand, $aInjection);
  3254. }
  3255. return $sValue != '__' . $sKey . '__' ? str_replace('__' . $sKey . '__', '', $sValue) : $sValue;
  3256. }
  3257. /**
  3258. * Static method to add ingection available on the current page only.
  3259. *
  3260. * @param string $sKey - template's key.
  3261. * @param string $sType - injection type(text, php).
  3262. * @param string $sData - the data to be added.
  3263. * @param integer $iReplace - replace already existed data or not.
  3264. */
  3265. function addInjection($sKey, $sType, $sData, $iReplace = 0)
  3266. {
  3267. $this->aPage['injections']['page_0'][$sKey][] = array(
  3268. 'page_index' => 0,
  3269. 'key' => $sKey,
  3270. 'type' => $sType,
  3271. 'data' => $sData,
  3272. 'replace' => $iReplace
  3273. );
  3274. }
  3275. function getPageCode($oTemplate = null)
  3276. {
  3277. if (empty($oTemplate))
  3278. $oTemplate = $this;
  3279. /**
  3280. * @hooks
  3281. * @hookdef hook-system-design_before_output 'system', 'design_before_output' - hook on before page's html generated
  3282. * - $unit_name - equals `system`
  3283. * - $action - equals `design_before_output`
  3284. * - $object_id - not used
  3285. * - $sender_id - not used
  3286. * - $extra_params - array of additional params with the following array keys:
  3287. * - `page` - [array] by ref, page object paramenters, can be overridden in hook processing
  3288. * - `page_content` - [array] by ref, page content values, can be overridden in hook processing
  3289. * @hook @ref hook-system-design_before_output
  3290. */
  3291. bx_alert('system', 'design_before_output', 0, 0, ['page' => &$this->aPage, 'page_content' => &$this->aPageContent]);
  3292. header( 'Content-type: text/html; charset=utf-8' );
  3293. $sXFrameOpts = getParam('sys_x_frame_options');
  3294. if ('Off' !== $sXFrameOpts)
  3295. header( 'X-Frame-Options: ' . $sXFrameOpts );
  3296. if (BX_PAGE_EMBED == $oTemplate->getPageNameIndex())
  3297. header('Content-Security-Policy: frame-ancestors ' . getParam('sys_csp_frame_ancestors'));
  3298. $sResult = $oTemplate->parsePageByName('page_' . $oTemplate->getPageNameIndex() . '.html', $oTemplate->getPageContent());
  3299. /**
  3300. * @hooks
  3301. * @hookdef hook-system-design_after_output 'system', 'design_after_output' - hook on after page's html generated
  3302. * - $unit_name - equals `system`
  3303. * - $action - equals `design_after_output`
  3304. * - $object_id - not used
  3305. * - $sender_id - not used
  3306. * - $extra_params - array of additional params with the following array keys:
  3307. * - `override_result` - [string] by ref, html content for current page, can be overridden in hook processing
  3308. * @hook @ref hook-system-design_after_output
  3309. */
  3310. bx_alert('system', 'design_after_output', 0, false, ['override_result' => &$sResult]);
  3311. echo $sResult;
  3312. }
  3313. }
  3314. /** @} */