BxBaseStudioDesigner.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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. 'content' => $sContent,
  107. ));
  108. }
  109. protected function getLogo()
  110. {
  111. $oTemplate = BxDolStudioTemplate::getInstance();
  112. $aForm = array(
  113. 'form_attrs' => array(
  114. 'id' => $this->sLogoFormId,
  115. 'name' => $this->sLogoFormId,
  116. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  117. 'method' => 'post',
  118. 'enctype' => 'multipart/form-data',
  119. 'target' => $this->sLogoIframeId
  120. ),
  121. 'params' => array(
  122. 'db' => array(
  123. 'table' => '',
  124. 'key' => '',
  125. 'uri' => '',
  126. 'uri_title' => '',
  127. 'submit_name' => 'save'
  128. ),
  129. ),
  130. 'inputs' => array(
  131. 'page' => array(
  132. 'type' => 'hidden',
  133. 'name' => 'page',
  134. 'value' => $this->sPage
  135. ),
  136. 'image' => array(
  137. 'type' => 'image_uploader',
  138. 'name' => 'image',
  139. 'caption' => _t('_adm_dsg_txt_upload_image'),
  140. 'caption_preview' => _t('_adm_dsg_txt_upload_image_preview'),
  141. 'ajax_action_delete' => $this->getPageJsObject() . '.deleteLogo()',
  142. 'storage_object' => 'sys_images_custom',
  143. 'transcoder_object' => 'sys_custom_images',
  144. 'transcoder_image_width' => getParam('sys_site_logo_width'),
  145. 'transcoder_image_height' => getParam('sys_site_logo_height'),
  146. 'value' => (int)getParam('sys_site_logo'),
  147. ),
  148. 'width' => array(
  149. 'type' => 'text',
  150. 'name' => 'width',
  151. 'caption' => _t('_adm_stg_cpt_option_sys_site_logo_width'),
  152. 'value' => getParam('sys_site_logo_width'),
  153. 'db' => array (
  154. 'pass' => 'Int',
  155. ),
  156. ),
  157. 'height' => array(
  158. 'type' => 'text',
  159. 'name' => 'height',
  160. 'caption' => _t('_adm_stg_cpt_option_sys_site_logo_height'),
  161. 'value' => getParam('sys_site_logo_height'),
  162. 'db' => array (
  163. 'pass' => 'Int',
  164. ),
  165. ),
  166. 'alt' => array(
  167. 'type' => 'text',
  168. 'name' => 'alt',
  169. 'caption' => _t('_adm_dsg_txt_alt_text'),
  170. 'info' => _t('_adm_dsg_dsc_alt_text'),
  171. 'value' => getParam('sys_site_logo_alt'),
  172. 'checker' => array(
  173. 'func' => '',
  174. 'params' => array(),
  175. 'error' => ''
  176. ),
  177. 'db' => array (
  178. 'pass' => 'Xss',
  179. ),
  180. ),
  181. 'save' => array(
  182. 'type' => 'submit',
  183. 'name' => 'save',
  184. 'value' => _t('_adm_btn_designer_submit'),
  185. )
  186. )
  187. );
  188. $oForm = new BxTemplStudioFormView($aForm);
  189. $oForm->initChecker();
  190. if($oForm->isSubmittedAndValid()) {
  191. echo $this->submitLogo($oForm);
  192. exit;
  193. }
  194. return $oTemplate->parseHtmlByName('designer.html', array(
  195. 'js_object' => $this->getPageJsObject(),
  196. 'content' => $this->getBlockCode(array(
  197. 'items' => $oTemplate->parseHtmlByName('dsr_logo.html', array('logo_iframe_id' => $this->sLogoIframeId, 'form' => $oForm->getCode())),
  198. ))
  199. ));
  200. }
  201. protected function getIcon()
  202. {
  203. $oTemplate = BxDolStudioTemplate::getInstance();
  204. $sPreview = "";
  205. $aTmplVars = array('bx_repeat:images' => array());
  206. if(($iId = (int)getParam('sys_site_icon')) != 0) {
  207. $aTranscoders = array(
  208. BX_DOL_TRANSCODER_OBJ_ICON_APPLE => '_adm_dsg_txt_icon_apple',
  209. BX_DOL_TRANSCODER_OBJ_ICON_FACEBOOK => '_adm_dsg_txt_icon_facebook',
  210. BX_DOL_TRANSCODER_OBJ_ICON_FAVICON => '_adm_dsg_txt_icon_favicon'
  211. );
  212. foreach($aTranscoders as $sTranscoder => $sTitle) {
  213. $oTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  214. $sImageUrl = $oTranscoder->getFileUrl($iId);
  215. if($sImageUrl === false) {
  216. setParam('sys_site_icon', 0);
  217. break;
  218. }
  219. $aFilterParams = $oTranscoder->getFilterParams('Resize');
  220. $bFilterWidth = !empty($aFilterParams['w']);
  221. $bFilterHeight = !empty($aFilterParams['h']);
  222. $aTmplVars['bx_repeat:images'][] = array(
  223. 'caption' => _t($sTitle),
  224. 'url' => $sImageUrl,
  225. 'bx_if:show_width' => array(
  226. 'condition' => $bFilterWidth,
  227. 'content' => array(
  228. 'width' => $bFilterWidth ? (int)$aFilterParams['w'] : 0
  229. )
  230. ),
  231. 'bx_if:show_height' => array(
  232. 'condition' => $bFilterHeight,
  233. 'content' => array(
  234. 'height' => $bFilterHeight ? (int)$aFilterParams['h'] : 0
  235. )
  236. ),
  237. );
  238. }
  239. $sPreview = $oTemplate->parseHtmlByName('dsr_icon_preview.html', $aTmplVars);
  240. }
  241. $aForm = array(
  242. 'form_attrs' => array(
  243. 'id' => $this->sIconFormId,
  244. 'name' => $this->sIconFormId,
  245. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  246. 'method' => 'post',
  247. 'enctype' => 'multipart/form-data',
  248. 'target' => $this->sIconIframeId
  249. ),
  250. 'params' => array(
  251. 'db' => array(
  252. 'table' => '',
  253. 'key' => '',
  254. 'uri' => '',
  255. 'uri_title' => '',
  256. 'submit_name' => 'save'
  257. ),
  258. ),
  259. 'inputs' => array(
  260. 'page' => array(
  261. 'type' => 'hidden',
  262. 'name' => 'page',
  263. 'value' => $this->sPage
  264. ),
  265. 'preview' => array(
  266. 'type' => 'custom',
  267. 'name' => 'preview',
  268. 'content' => $sPreview
  269. ),
  270. 'image' => array(
  271. 'type' => 'file',
  272. 'name' => 'image',
  273. 'caption' => _t('_adm_dsg_txt_upload_icon')
  274. ),
  275. 'save' => array(
  276. 'type' => 'submit',
  277. 'name' => 'save',
  278. 'value' => _t('_adm_btn_designer_submit'),
  279. )
  280. )
  281. );
  282. $oForm = new BxTemplStudioFormView($aForm);
  283. $oForm->initChecker();
  284. if($oForm->isSubmittedAndValid()) {
  285. echo $this->submitIcon($oForm);
  286. exit;
  287. }
  288. return $oTemplate->parseHtmlByName('designer.html', array(
  289. 'js_object' => $this->getPageJsObject(),
  290. 'content' => $this->getBlockCode(array(
  291. 'items' => $oTemplate->parseHtmlByName('dsr_icon.html', array('icon_iframe_id' => $this->sIconIframeId, 'form' => $oForm->getCode())),
  292. ))
  293. ));
  294. }
  295. protected function getCover()
  296. {
  297. $oTemplate = BxDolStudioTemplate::getInstance();
  298. $aForm = array(
  299. 'form_attrs' => array(
  300. 'id' => $this->sCoverFormId,
  301. 'name' => $this->sCoverFormId,
  302. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  303. 'method' => 'post',
  304. 'enctype' => 'multipart/form-data',
  305. 'target' => $this->sCoverIframeId
  306. ),
  307. 'params' => array(
  308. 'db' => array(
  309. 'table' => '',
  310. 'key' => '',
  311. 'uri' => '',
  312. 'uri_title' => '',
  313. 'submit_name' => 'save'
  314. ),
  315. ),
  316. 'inputs' => array(
  317. 'page' => array(
  318. 'type' => 'hidden',
  319. 'name' => 'page',
  320. 'value' => $this->sPage
  321. ),
  322. 'enabled' => array(
  323. 'type' => 'checkbox',
  324. 'name' => 'enabled',
  325. 'caption' => _t('_adm_dsg_txt_cover_enabled'),
  326. 'value' => 'on',
  327. 'checked' => getParam('sys_site_cover_enabled') == 'on',
  328. 'db' => array (
  329. 'pass' => 'Xss',
  330. ),
  331. ),
  332. 'code' => array(
  333. 'type' => 'textarea',
  334. 'name' => 'code',
  335. 'caption' => '',
  336. 'value' => getParam('sys_site_cover_code'),
  337. 'db' => array (
  338. 'pass' => 'XssHtml',
  339. ),
  340. ),
  341. 'save' => array(
  342. 'type' => 'submit',
  343. 'name' => 'save',
  344. 'value' => _t('_adm_btn_designer_submit'),
  345. )
  346. )
  347. );
  348. $oForm = new BxTemplStudioFormView($aForm, $oTemplate);
  349. $oForm->initChecker();
  350. if($oForm->isSubmittedAndValid()) {
  351. echo $this->submitCover($oForm);
  352. exit;
  353. }
  354. $oTemplate->addJs(array('codemirror/codemirror.min.js'));
  355. $oTemplate->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'codemirror/|codemirror.css');
  356. return $oTemplate->parseHtmlByName('designer.html', array(
  357. 'js_object' => $this->getPageJsObject(),
  358. 'content' => $this->getBlockCode(array(
  359. 'items' => $oTemplate->parseHtmlByName('dsr_cover.html', array(
  360. 'warning' => MsgBox(_t('_adm_dsg_dsc_cover_warning')),
  361. 'cover_iframe_id' => $this->sCoverIframeId,
  362. 'form' => $oForm->getCode()
  363. )),
  364. ))
  365. ));
  366. }
  367. protected function getSettings()
  368. {
  369. $oPage = new BxTemplStudioSettings(BX_DOL_STUDIO_STG_TYPE_SYSTEM, BX_DOL_STUDIO_STG_CATEGORY_TEMPLATES);
  370. return BxDolStudioTemplate::getInstance()->parseHtmlByName('designer.html', array(
  371. 'js_object' => $this->getPageJsObject(),
  372. 'content' => $oPage->getPageCode()
  373. ));
  374. }
  375. }
  376. /** @} */