BxBaseStudioDesigner.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup TridentView Trident Studio Representation classes
  7. * @ingroup TridentStudio
  8. * @{
  9. */
  10. class BxBaseStudioDesigner extends BxDolStudioDesigner
  11. {
  12. protected $sLogoFormId = 'adm-dsg-logo-form';
  13. protected $sLogoIframeId = 'adm-dsg-logo-iframe';
  14. protected $sIconFormId = 'adm-dsg-icon-form';
  15. protected $sIconIframeId = 'adm-dsg-icon-iframe';
  16. protected $sCoverFormId = 'adm-dsg-cover-form';
  17. protected $sCoverIframeId = 'adm-dsg-cover-iframe';
  18. protected $sSplashFormId = 'adm-dsg-splash-form';
  19. protected $sSplashIframeId = 'adm-dsg-splash-iframe';
  20. protected $sSplashEditorId = 'adm-dsg-splash-editor';
  21. protected $sInjectionsFormId = 'adm-dsg-injections-form';
  22. protected $sInjectionsIframeId = 'adm-dsg-injections-iframe';
  23. protected $sInjectionsEditorId = 'adm-dsg-injections-editor';
  24. protected $aPageCss;
  25. protected $aPageJs;
  26. function __construct($sPage = '')
  27. {
  28. parent::__construct($sPage);
  29. $this->aPageCss = array('forms.css', 'designer.css');
  30. $this->aPageJs = array('settings.js', 'designer.js');
  31. }
  32. function getPageCss()
  33. {
  34. return array_merge(parent::getPageCss(), $this->aPageCss);
  35. }
  36. function getPageJs()
  37. {
  38. return array_merge(parent::getPageJs(), $this->aPageJs);
  39. }
  40. function getPageJsObject()
  41. {
  42. return 'oBxDolStudioDesigner';
  43. }
  44. function getPageJsClass()
  45. {
  46. return 'BxDolStudioDesigner';
  47. }
  48. public function getPageJsCode($aOptions = array(), $bWrap = true)
  49. {
  50. $aOptions = array_merge(array(
  51. 'sActionUrl' => $this->sManageUrl
  52. ), $aOptions);
  53. return parent::getPageJsCode($aOptions, $bWrap);
  54. }
  55. function getPageMenu($aMenu = array(), $aMarkers = array())
  56. {
  57. $sJsObject = $this->getPageJsObject();
  58. $aMenu = array();
  59. $aMenuItems = array(
  60. BX_DOL_STUDIO_DSG_TYPE_GENERAL => array('icon' => 'globe'),
  61. BX_DOL_STUDIO_DSG_TYPE_LOGO => array('icon' => 'pencil'),
  62. BX_DOL_STUDIO_DSG_TYPE_ICON => array('icon' => 'picture-o'),
  63. BX_DOL_STUDIO_DSG_TYPE_COVER => array('icon' => 'file-image-o'),
  64. BX_DOL_STUDIO_DSG_TYPE_SPLASH => array('icon' => 'file-image-o'),
  65. BX_DOL_STUDIO_DSG_TYPE_INJECTIONS => array('icon' => 'object-group'),
  66. BX_DOL_STUDIO_DSG_TYPE_SETTINGS => array('icon' => 'cogs'),
  67. );
  68. foreach($aMenuItems as $sMenuItem => $aItem)
  69. $aMenu[] = array(
  70. 'name' => $sMenuItem,
  71. 'icon' => $aItem['icon'],
  72. 'link' => BX_DOL_URL_STUDIO . 'designer.php?page=' . $sMenuItem,
  73. 'title' => _t('_adm_lmi_cpt_' . $sMenuItem),
  74. 'selected' => $sMenuItem == $this->sPage
  75. );
  76. return parent::getPageMenu($aMenu);
  77. }
  78. function getPageCode($bHidden = false)
  79. {
  80. $sMethod = 'get' . ucfirst($this->sPage);
  81. if(!method_exists($this, $sMethod))
  82. return '';
  83. return $this->$sMethod();
  84. }
  85. protected function getGeneral()
  86. {
  87. $sJsObject = $this->getPageJsObject();
  88. $oTemplate = BxDolStudioTemplate::getInstance();
  89. $sResult = '';
  90. $sTemplate = getParam('template');
  91. $aTemplates = get_templates_array(true, false);
  92. $aTmplVarsTemplates = array ();
  93. foreach($aTemplates as $sUri => $aTemplate) {
  94. $sIcon = $this->getModuleIcon($aTemplate, 'store');
  95. $bIcon = strpos($sIcon, '.') === false;
  96. $aTmplVarsTemplates[] = array(
  97. 'uri' => $sUri,
  98. 'title' => htmlspecialchars_adv($aTemplate['title']),
  99. 'version' => htmlspecialchars_adv($aTemplate['version']),
  100. 'vendor' => htmlspecialchars_adv($aTemplate['vendor']),
  101. 'bx_if:icon' => array (
  102. 'condition' => $bIcon,
  103. 'content' => array('icon' => $sIcon),
  104. ),
  105. 'bx_if:image' => array (
  106. 'condition' => !$bIcon,
  107. 'content' => array('icon_url' => $sIcon),
  108. ),
  109. 'bx_if:default' => array (
  110. 'condition' => $sUri == $sTemplate,
  111. 'content' => array (),
  112. ),
  113. 'bx_if:make_default' => array (
  114. 'condition' => $sUri != $sTemplate,
  115. 'content' => array(
  116. 'js_object' => $sJsObject,
  117. 'uri' => $sUri
  118. ),
  119. )
  120. );
  121. }
  122. $sContent = $sResult ? MsgBox($sResult, 10) : '';
  123. $sContent .= $oTemplate->parseHtmlByName('templates.html', array(
  124. 'bx_repeat:templates' => $aTmplVarsTemplates,
  125. ));
  126. return $oTemplate->parseHtmlByName('designer.html', array(
  127. 'content' => $sContent,
  128. 'js_content' => $this->getPageJsCode()
  129. ));
  130. }
  131. protected function getLogo()
  132. {
  133. $oTemplate = BxDolStudioTemplate::getInstance();
  134. $aForm = array(
  135. 'form_attrs' => array(
  136. 'id' => $this->sLogoFormId,
  137. 'name' => $this->sLogoFormId,
  138. 'action' => $this->sManageUrl,
  139. 'method' => 'post',
  140. 'enctype' => 'multipart/form-data',
  141. 'target' => $this->sLogoIframeId
  142. ),
  143. 'params' => array(
  144. 'db' => array(
  145. 'table' => '',
  146. 'key' => '',
  147. 'uri' => '',
  148. 'uri_title' => '',
  149. 'submit_name' => 'save'
  150. ),
  151. ),
  152. 'inputs' => array(
  153. 'page' => array(
  154. 'type' => 'hidden',
  155. 'name' => 'page',
  156. 'value' => $this->sPage
  157. ),
  158. 'image' => array(
  159. 'type' => 'image_uploader',
  160. 'name' => 'image',
  161. 'caption' => _t('_adm_dsg_txt_upload_image'),
  162. 'caption_preview' => _t('_adm_dsg_txt_upload_image_preview'),
  163. 'ajax_action_delete' => $this->getPageJsObject() . '.deleteLogo()',
  164. 'storage_object' => 'sys_images_custom',
  165. 'transcoder_object' => 'sys_custom_images',
  166. 'transcoder_image_width' => (int)getParam($this->sParamLogoWidth),
  167. 'transcoder_image_height' => (int)getParam($this->sParamLogoHeight),
  168. 'value' => (int)getParam($this->sParamLogo),
  169. ),
  170. 'width' => array(
  171. 'type' => 'text',
  172. 'name' => 'width',
  173. 'caption' => _t('_adm_stg_cpt_option_sys_site_logo_width'),
  174. 'value' => (int)getParam($this->sParamLogoWidth),
  175. 'db' => array (
  176. 'pass' => 'Int',
  177. ),
  178. ),
  179. 'height' => array(
  180. 'type' => 'text',
  181. 'name' => 'height',
  182. 'caption' => _t('_adm_stg_cpt_option_sys_site_logo_height'),
  183. 'value' => (int)getParam($this->sParamLogoHeight),
  184. 'db' => array (
  185. 'pass' => 'Int',
  186. ),
  187. ),
  188. 'alt' => array(
  189. 'type' => 'text',
  190. 'name' => 'alt',
  191. 'caption' => _t('_adm_dsg_txt_alt_text'),
  192. 'info' => _t('_adm_dsg_dsc_alt_text'),
  193. 'value' => getParam($this->sParamLogoAlt),
  194. 'checker' => array(
  195. 'func' => '',
  196. 'params' => array(),
  197. 'error' => ''
  198. ),
  199. 'db' => array (
  200. 'pass' => 'Xss',
  201. ),
  202. ),
  203. 'save' => array(
  204. 'type' => 'submit',
  205. 'name' => 'save',
  206. 'value' => _t('_adm_btn_designer_submit'),
  207. )
  208. )
  209. );
  210. $oForm = new BxTemplStudioFormView($aForm);
  211. $oForm->initChecker();
  212. if($oForm->isSubmittedAndValid()) {
  213. echo $this->submitLogo($oForm);
  214. exit;
  215. }
  216. return $oTemplate->parseHtmlByName('designer.html', array(
  217. 'content' => $this->getBlockCode(array(
  218. 'items' => $oTemplate->parseHtmlByName('dsr_logo.html', array('logo_iframe_id' => $this->sLogoIframeId, 'form' => $oForm->getCode())),
  219. )),
  220. 'js_content' => $this->getPageJsCode()
  221. ));
  222. }
  223. protected function getIcon()
  224. {
  225. $oTemplate = BxDolStudioTemplate::getInstance();
  226. $sPreview = "";
  227. $aTmplVars = array('bx_repeat:images' => array());
  228. if(($iId = (int)getParam('sys_site_icon')) != 0) {
  229. $aTranscoders = array(
  230. BX_DOL_TRANSCODER_OBJ_ICON_APPLE => '_adm_dsg_txt_icon_apple',
  231. BX_DOL_TRANSCODER_OBJ_ICON_FACEBOOK => '_adm_dsg_txt_icon_facebook',
  232. BX_DOL_TRANSCODER_OBJ_ICON_FAVICON => '_adm_dsg_txt_icon_favicon'
  233. );
  234. foreach($aTranscoders as $sTranscoder => $sTitle) {
  235. $oTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  236. $sImageUrl = $oTranscoder->getFileUrl($iId);
  237. if($sImageUrl === false) {
  238. setParam('sys_site_icon', 0);
  239. break;
  240. }
  241. $aFilterParams = $oTranscoder->getFilterParams('Resize');
  242. $bFilterWidth = !empty($aFilterParams['w']);
  243. $bFilterHeight = !empty($aFilterParams['h']);
  244. $aTmplVars['bx_repeat:images'][] = array(
  245. 'caption' => _t($sTitle),
  246. 'url' => $sImageUrl,
  247. 'bx_if:show_width' => array(
  248. 'condition' => $bFilterWidth,
  249. 'content' => array(
  250. 'width' => $bFilterWidth ? (int)$aFilterParams['w'] : 0
  251. )
  252. ),
  253. 'bx_if:show_height' => array(
  254. 'condition' => $bFilterHeight,
  255. 'content' => array(
  256. 'height' => $bFilterHeight ? (int)$aFilterParams['h'] : 0
  257. )
  258. ),
  259. );
  260. }
  261. $sPreview = $oTemplate->parseHtmlByName('dsr_icon_preview.html', $aTmplVars);
  262. }
  263. $aForm = array(
  264. 'form_attrs' => array(
  265. 'id' => $this->sIconFormId,
  266. 'name' => $this->sIconFormId,
  267. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  268. 'method' => 'post',
  269. 'enctype' => 'multipart/form-data',
  270. 'target' => $this->sIconIframeId
  271. ),
  272. 'params' => array(
  273. 'db' => array(
  274. 'table' => '',
  275. 'key' => '',
  276. 'uri' => '',
  277. 'uri_title' => '',
  278. 'submit_name' => 'save'
  279. ),
  280. ),
  281. 'inputs' => array(
  282. 'page' => array(
  283. 'type' => 'hidden',
  284. 'name' => 'page',
  285. 'value' => $this->sPage
  286. ),
  287. 'preview' => array(
  288. 'type' => 'custom',
  289. 'name' => 'preview',
  290. 'content' => $sPreview
  291. ),
  292. 'image' => array(
  293. 'type' => 'file',
  294. 'name' => 'image',
  295. 'caption' => _t('_adm_dsg_txt_upload_icon')
  296. ),
  297. 'save' => array(
  298. 'type' => 'submit',
  299. 'name' => 'save',
  300. 'value' => _t('_adm_btn_designer_submit'),
  301. )
  302. )
  303. );
  304. $oForm = new BxTemplStudioFormView($aForm);
  305. $oForm->initChecker();
  306. if($oForm->isSubmittedAndValid()) {
  307. echo $this->submitIcon($oForm);
  308. exit;
  309. }
  310. return $oTemplate->parseHtmlByName('designer.html', array(
  311. 'content' => $this->getBlockCode(array(
  312. 'items' => $oTemplate->parseHtmlByName('dsr_icon.html', array('icon_iframe_id' => $this->sIconIframeId, 'form' => $oForm->getCode())),
  313. )),
  314. 'js_content' => $this->getPageJsCode()
  315. ));
  316. }
  317. protected function getCover()
  318. {
  319. $sJsObject = $this->getPageJsObject();
  320. $oTemplate = BxDolStudioTemplate::getInstance();
  321. $aFormInputs = array();
  322. $aTmplVarsCovers = array();
  323. foreach($this->aCovers as $sCover => $aCover) {
  324. $aFormInputs[$sCover] = array(
  325. 'type' => 'file',
  326. 'name' => $sCover,
  327. 'caption' => _t('_adm_dsg_txt_upload_' . $sCover)
  328. );
  329. if(($iImageId = (int)getParam($aCover['setting'])) == 0)
  330. continue;
  331. $sImageUrl = BxDolTranscoderImage::getObjectInstance(BX_DOL_TRANSCODER_OBJ_COVER)->getFileUrl($iImageId);
  332. if($sImageUrl === false) {
  333. setParam($aCover['setting'], 0);
  334. continue;
  335. }
  336. $aTmplVarsCovers[] = array(
  337. 'js_object' => $sJsObject,
  338. 'type' => $sCover,
  339. 'caption' => _t($aCover['title']),
  340. 'image_id' => $iImageId,
  341. 'bx_if:show_bg' => array(
  342. 'condition' => !empty($sImageUrl),
  343. 'content' => array(
  344. 'image_url' => $sImageUrl
  345. )
  346. ),
  347. );
  348. }
  349. $aForm = array(
  350. 'form_attrs' => array(
  351. 'id' => $this->sCoverFormId,
  352. 'name' => $this->sCoverFormId,
  353. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  354. 'method' => 'post',
  355. 'enctype' => 'multipart/form-data',
  356. 'target' => $this->sCoverIframeId
  357. ),
  358. 'params' => array(
  359. 'db' => array(
  360. 'table' => '',
  361. 'key' => '',
  362. 'uri' => '',
  363. 'uri_title' => '',
  364. 'submit_name' => 'save'
  365. ),
  366. ),
  367. 'inputs' => array(
  368. 'page' => array(
  369. 'type' => 'hidden',
  370. 'name' => 'page',
  371. 'value' => $this->sPage
  372. ),
  373. 'preview' => array(
  374. 'type' => 'custom',
  375. 'name' => 'preview',
  376. 'content' => $oTemplate->parseHtmlByName('dsr_cover_preview.html', array(
  377. 'bx_repeat:covers' => $aTmplVarsCovers
  378. ))
  379. ),
  380. 'save' => array(
  381. 'type' => 'submit',
  382. 'name' => 'save',
  383. 'value' => _t('_adm_btn_designer_submit'),
  384. )
  385. )
  386. );
  387. $aForm['inputs'] = bx_array_insert_after($aFormInputs, $aForm['inputs'], 'preview');
  388. $oForm = new BxTemplStudioFormView($aForm);
  389. $oForm->initChecker();
  390. if($oForm->isSubmittedAndValid()) {
  391. echo $this->submitCover($oForm);
  392. exit;
  393. }
  394. $this->aPageCss[] = 'cover.css';
  395. return $oTemplate->parseHtmlByName('designer.html', array(
  396. 'content' => $this->getBlockCode(array(
  397. 'items' => $oTemplate->parseHtmlByName('dsr_cover.html', array('iframe_id' => $this->sCoverIframeId, 'form' => $oForm->getCode())),
  398. )),
  399. 'js_content' => $this->getPageJsCode()
  400. ));
  401. }
  402. protected function getSplash()
  403. {
  404. $oTemplate = BxDolStudioTemplate::getInstance();
  405. $aForm = array(
  406. 'form_attrs' => array(
  407. 'id' => $this->sSplashFormId,
  408. 'name' => $this->sSplashFormId,
  409. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  410. 'method' => 'post',
  411. 'enctype' => 'multipart/form-data',
  412. 'target' => $this->sSplashIframeId
  413. ),
  414. 'params' => array(
  415. 'db' => array(
  416. 'table' => '',
  417. 'key' => '',
  418. 'uri' => '',
  419. 'uri_title' => '',
  420. 'submit_name' => 'save'
  421. ),
  422. ),
  423. 'inputs' => array(
  424. 'page' => array(
  425. 'type' => 'hidden',
  426. 'name' => 'page',
  427. 'value' => $this->sPage
  428. ),
  429. 'enabled' => array(
  430. 'type' => 'checkbox',
  431. 'name' => 'enabled',
  432. 'caption' => _t('_adm_dsg_txt_splash_enabled'),
  433. 'value' => 'on',
  434. 'checked' => getParam('sys_site_splash_enabled') == 'on',
  435. 'db' => array (
  436. 'pass' => 'Xss',
  437. ),
  438. ),
  439. 'code' => array(
  440. 'type' => 'textarea',
  441. 'code' => true,
  442. 'name' => 'code',
  443. 'caption' => '',
  444. 'value' => getParam('sys_site_splash_code'),
  445. ),
  446. 'save' => array(
  447. 'type' => 'submit',
  448. 'name' => 'save',
  449. 'value' => _t('_adm_btn_designer_submit'),
  450. )
  451. )
  452. );
  453. $oForm = new BxTemplStudioFormView($aForm, $oTemplate);
  454. $oForm->initChecker();
  455. if($oForm->isSubmittedAndValid()) {
  456. echo $this->submitSplash($oForm);
  457. exit;
  458. }
  459. $oTemplate->addJs(array('codemirror/codemirror.min.js'));
  460. $oTemplate->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css');
  461. return $oTemplate->parseHtmlByName('designer.html', array(
  462. 'content' => $this->getBlockCode(array(
  463. 'items' => $oTemplate->parseHtmlByName('dsr_splash.html', array(
  464. 'warning' => MsgBox(_t('_adm_dsg_dsc_splash_warning')),
  465. 'splash_iframe_id' => $this->sSplashIframeId,
  466. 'form' => $oForm->getCode()
  467. )),
  468. )),
  469. 'js_content' => $this->getPageJsCode(array(
  470. 'sCodeMirror' => 'textarea[name=code]'
  471. ))
  472. ));
  473. }
  474. protected function getInjections()
  475. {
  476. $oTemplate = BxDolStudioTemplate::getInstance();
  477. $aForm = array(
  478. 'form_attrs' => array(
  479. 'id' => $this->sInjectionsFormId,
  480. 'name' => $this->sInjectionsFormId,
  481. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  482. 'method' => 'post',
  483. 'enctype' => 'multipart/form-data',
  484. 'target' => $this->sInjectionsIframeId
  485. ),
  486. 'params' => array(
  487. 'db' => array(
  488. 'table' => '',
  489. 'key' => '',
  490. 'uri' => '',
  491. 'uri_title' => '',
  492. 'submit_name' => 'save'
  493. ),
  494. ),
  495. 'inputs' => array(
  496. 'page' => array(
  497. 'type' => 'hidden',
  498. 'name' => 'page',
  499. 'value' => $this->sPage
  500. ),
  501. 'code' => array(
  502. 'type' => 'textarea',
  503. 'code' => true,
  504. 'name' => 'code',
  505. 'caption' => '',
  506. 'value' => BxDolTemplate::getInstance()->getHtml('_header.html', BX_DOL_TEMPLATE_CHECK_IN_BASE),
  507. ),
  508. 'save' => array(
  509. 'type' => 'submit',
  510. 'name' => 'save',
  511. 'value' => _t('_adm_btn_designer_submit'),
  512. )
  513. )
  514. );
  515. $oForm = new BxTemplStudioFormView($aForm, $oTemplate);
  516. $oForm->initChecker();
  517. if($oForm->isSubmittedAndValid()) {
  518. echo $this->submitInjections($oForm);
  519. exit;
  520. }
  521. $oTemplate->addJs(array('codemirror/codemirror.min.js'));
  522. $oTemplate->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css');
  523. return $oTemplate->parseHtmlByName('designer.html', array(
  524. 'content' => $this->getBlockCode(array(
  525. 'items' => $oTemplate->parseHtmlByName('dsr_injections.html', array(
  526. 'warning' => MsgBox(_t('_adm_dsg_dsc_splash_warning')),
  527. 'splash_iframe_id' => $this->sInjectionsIframeId,
  528. 'form' => $oForm->getCode()
  529. )),
  530. )),
  531. 'js_content' => $this->getPageJsCode(array(
  532. 'sCodeMirror' => 'textarea[name=code]'
  533. ))
  534. ));
  535. }
  536. protected function getSettings()
  537. {
  538. $oPage = new BxTemplStudioSettings(BX_DOL_STUDIO_STG_TYPE_SYSTEM, BX_DOL_STUDIO_STG_CATEGORY_TEMPLATES);
  539. return BxDolStudioTemplate::getInstance()->parseHtmlByName('designer.html', array(
  540. 'content' => $oPage->getPageCode(),
  541. 'js_content' => $this->getPageJsCode()
  542. ));
  543. }
  544. }
  545. /** @} */