BxBaseStudioDesigner.php 18 KB

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