BxBaseStudioDesigner.php 14 KB

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