BxBaseStudioDesigner.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  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. $aTmplVars['bx_repeat:images'][] = array(
  220. 'caption' => _t($sTitle),
  221. 'url' => $sImageUrl
  222. );
  223. }
  224. $sPreview = $oTemplate->parseHtmlByName('dsr_icon_preview.html', $aTmplVars);
  225. }
  226. $aForm = array(
  227. 'form_attrs' => array(
  228. 'id' => $this->sIconFormId,
  229. 'name' => $this->sIconFormId,
  230. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  231. 'method' => 'post',
  232. 'enctype' => 'multipart/form-data',
  233. 'target' => $this->sIconIframeId
  234. ),
  235. 'params' => array(
  236. 'db' => array(
  237. 'table' => '',
  238. 'key' => '',
  239. 'uri' => '',
  240. 'uri_title' => '',
  241. 'submit_name' => 'save'
  242. ),
  243. ),
  244. 'inputs' => array(
  245. 'page' => array(
  246. 'type' => 'hidden',
  247. 'name' => 'page',
  248. 'value' => $this->sPage
  249. ),
  250. 'preview' => array(
  251. 'type' => 'custom',
  252. 'name' => 'preview',
  253. 'content' => $sPreview
  254. ),
  255. 'image' => array(
  256. 'type' => 'file',
  257. 'name' => 'image',
  258. 'caption' => _t('_adm_dsg_txt_upload_icon')
  259. ),
  260. 'save' => array(
  261. 'type' => 'submit',
  262. 'name' => 'save',
  263. 'value' => _t('_adm_btn_designer_submit'),
  264. )
  265. )
  266. );
  267. $oForm = new BxTemplStudioFormView($aForm);
  268. $oForm->initChecker();
  269. if($oForm->isSubmittedAndValid()) {
  270. echo $this->submitIcon($oForm);
  271. exit;
  272. }
  273. return $oTemplate->parseHtmlByName('designer.html', array(
  274. 'js_object' => $this->getPageJsObject(),
  275. 'content' => $this->getBlockCode(array(
  276. 'items' => $oTemplate->parseHtmlByName('dsr_icon.html', array('icon_iframe_id' => $this->sIconIframeId, 'form' => $oForm->getCode())),
  277. ))
  278. ));
  279. }
  280. protected function getCover()
  281. {
  282. $oTemplate = BxDolStudioTemplate::getInstance();
  283. $aForm = array(
  284. 'form_attrs' => array(
  285. 'id' => $this->sCoverFormId,
  286. 'name' => $this->sCoverFormId,
  287. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  288. 'method' => 'post',
  289. 'enctype' => 'multipart/form-data',
  290. 'target' => $this->sCoverIframeId
  291. ),
  292. 'params' => array(
  293. 'db' => array(
  294. 'table' => '',
  295. 'key' => '',
  296. 'uri' => '',
  297. 'uri_title' => '',
  298. 'submit_name' => 'save'
  299. ),
  300. ),
  301. 'inputs' => array(
  302. 'page' => array(
  303. 'type' => 'hidden',
  304. 'name' => 'page',
  305. 'value' => $this->sPage
  306. ),
  307. 'enabled' => array(
  308. 'type' => 'checkbox',
  309. 'name' => 'enabled',
  310. 'caption' => _t('_adm_dsg_txt_cover_enabled'),
  311. 'value' => 'on',
  312. 'checked' => getParam('sys_site_cover_enabled') == 'on',
  313. 'db' => array (
  314. 'pass' => 'Xss',
  315. ),
  316. ),
  317. 'code' => array(
  318. 'type' => 'textarea',
  319. 'name' => 'code',
  320. 'caption' => '',
  321. 'value' => getParam('sys_site_cover_code'),
  322. 'db' => array (
  323. 'pass' => 'XssHtml',
  324. ),
  325. ),
  326. 'save' => array(
  327. 'type' => 'submit',
  328. 'name' => 'save',
  329. 'value' => _t('_adm_btn_designer_submit'),
  330. )
  331. )
  332. );
  333. $oForm = new BxTemplStudioFormView($aForm, $oTemplate);
  334. $oForm->initChecker();
  335. if($oForm->isSubmittedAndValid()) {
  336. echo $this->submitCover($oForm);
  337. exit;
  338. }
  339. $oTemplate->addJs(array(
  340. 'codemirror/lib/codemirror.js',
  341. 'codemirror/mode/xml/xml.js',
  342. 'codemirror/mode/javascript/javascript.js',
  343. 'codemirror/mode/css/css.js',
  344. 'codemirror/mode/htmlmixed/htmlmixed.js',
  345. ));
  346. $oTemplate->addCss(BX_DOL_URL_PLUGINS_PUBLIC . 'codemirror/lib/codemirror.css');
  347. return $oTemplate->parseHtmlByName('designer.html', array(
  348. 'js_object' => $this->getPageJsObject(),
  349. 'content' => $this->getBlockCode(array(
  350. 'items' => $oTemplate->parseHtmlByName('dsr_cover.html', array(
  351. 'warning' => MsgBox(_t('_adm_dsg_dsc_cover_warning')),
  352. 'cover_iframe_id' => $this->sCoverIframeId,
  353. 'form' => $oForm->getCode()
  354. )),
  355. ))
  356. ));
  357. }
  358. protected function getSettings()
  359. {
  360. $oPage = new BxTemplStudioSettings(BX_DOL_STUDIO_STG_TYPE_SYSTEM, BX_DOL_STUDIO_STG_CATEGORY_TEMPLATES);
  361. return BxDolStudioTemplate::getInstance()->parseHtmlByName('designer.html', array(
  362. 'js_object' => $this->getPageJsObject(),
  363. 'content' => $oPage->getPageCode()
  364. ));
  365. }
  366. }
  367. /** @} */