1
0

BxBaseStudioDesigner.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. function __construct($sPage = '')
  17. {
  18. parent::__construct($sPage);
  19. }
  20. function getPageCss()
  21. {
  22. return array_merge(parent::getPageCss(), array('forms.css', 'designer.css'));
  23. }
  24. function getPageJs()
  25. {
  26. return array_merge(parent::getPageJs(), array('settings.js', 'designer.js'));
  27. }
  28. function getPageJsObject()
  29. {
  30. return 'oBxDolStudioDesigner';
  31. }
  32. function getPageMenu($aMenu = array(), $aMarkers = array())
  33. {
  34. $sJsObject = $this->getPageJsObject();
  35. $aMenu = array();
  36. $aMenuItems = array(
  37. BX_DOL_STUDIO_DSG_TYPE_GENERAL => array('icon' => 'globe'),
  38. BX_DOL_STUDIO_DSG_TYPE_LOGO => array('icon' => 'pencil'),
  39. BX_DOL_STUDIO_DSG_TYPE_ICON => array('icon' => 'picture-o'),
  40. BX_DOL_STUDIO_DSG_TYPE_SETTINGS => array('icon' => 'cogs'),
  41. );
  42. foreach($aMenuItems as $sMenuItem => $aItem)
  43. $aMenu[] = array(
  44. 'name' => $sMenuItem,
  45. 'icon' => $aItem['icon'],
  46. 'link' => BX_DOL_URL_STUDIO . 'designer.php?page=' . $sMenuItem,
  47. 'title' => _t('_adm_lmi_cpt_' . $sMenuItem),
  48. 'selected' => $sMenuItem == $this->sPage
  49. );
  50. return parent::getPageMenu($aMenu);
  51. }
  52. function getPageCode($bHidden = false)
  53. {
  54. $sMethod = 'get' . ucfirst($this->sPage);
  55. if(!method_exists($this, $sMethod))
  56. return '';
  57. return $this->$sMethod();
  58. }
  59. protected function getGeneral()
  60. {
  61. $sJsObject = $this->getPageJsObject();
  62. $oTemplate = BxDolStudioTemplate::getInstance();
  63. $sResult = '';
  64. $sTemplate = getParam('template');
  65. $aTemplates = get_templates_array(true, false);
  66. $aTmplVarsTemplates = array ();
  67. foreach($aTemplates as $sUri => $aTemplate) {
  68. $sIcon = $this->getModuleIcon($aTemplate, 'store');
  69. $bIcon = strpos($sIcon, '.') === false;
  70. $aTmplVarsTemplates[] = array(
  71. 'uri' => $sUri,
  72. 'title' => htmlspecialchars_adv($aTemplate['title']),
  73. 'version' => htmlspecialchars_adv($aTemplate['version']),
  74. 'vendor' => htmlspecialchars_adv($aTemplate['vendor']),
  75. 'bx_if:icon' => array (
  76. 'condition' => $bIcon,
  77. 'content' => array('icon' => $sIcon),
  78. ),
  79. 'bx_if:image' => array (
  80. 'condition' => !$bIcon,
  81. 'content' => array('icon_url' => $sIcon),
  82. ),
  83. 'bx_if:default' => array (
  84. 'condition' => $sUri == $sTemplate,
  85. 'content' => array (),
  86. ),
  87. 'bx_if:make_default' => array (
  88. 'condition' => $sUri != $sTemplate,
  89. 'content' => array(
  90. 'js_object' => $sJsObject,
  91. 'uri' => $sUri
  92. ),
  93. )
  94. );
  95. }
  96. $sContent = $sResult ? MsgBox($sResult, 10) : '';
  97. $sContent .= $oTemplate->parseHtmlByName('templates.html', array(
  98. 'bx_repeat:templates' => $aTmplVarsTemplates,
  99. ));
  100. $aTmplVars = array(
  101. 'js_object' => $this->getPageJsObject(),
  102. 'bx_repeat:blocks' => $sContent,
  103. );
  104. return $oTemplate->parseHtmlByName('designer.html', $aTmplVars);
  105. }
  106. protected function getLogo()
  107. {
  108. $oTemplate = BxDolStudioTemplate::getInstance();
  109. $aForm = array(
  110. 'form_attrs' => array(
  111. 'id' => $this->sLogoFormId,
  112. 'name' => $this->sLogoFormId,
  113. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  114. 'method' => 'post',
  115. 'enctype' => 'multipart/form-data',
  116. 'target' => $this->sLogoIframeId
  117. ),
  118. 'params' => array(
  119. 'db' => array(
  120. 'table' => '',
  121. 'key' => '',
  122. 'uri' => '',
  123. 'uri_title' => '',
  124. 'submit_name' => 'save'
  125. ),
  126. ),
  127. 'inputs' => array(
  128. 'page' => array(
  129. 'type' => 'hidden',
  130. 'name' => 'page',
  131. 'value' => $this->sPage
  132. ),
  133. 'image' => array(
  134. 'type' => 'image_uploader',
  135. 'name' => 'image',
  136. 'caption' => _t('_adm_dsg_txt_upload_image'),
  137. 'caption_preview' => _t('_adm_dsg_txt_upload_image_preview'),
  138. 'ajax_action_delete' => $this->getPageJsObject() . '.deleteLogo()',
  139. 'storage_object' => 'sys_images_custom',
  140. 'transcoder_object' => 'sys_custom_images',
  141. 'transcoder_image_width' => getParam('sys_site_logo_width'),
  142. 'transcoder_image_height' => getParam('sys_site_logo_height'),
  143. 'value' => (int)getParam('sys_site_logo'),
  144. ),
  145. 'width' => array(
  146. 'type' => 'text',
  147. 'name' => 'width',
  148. 'caption' => _t('_adm_stg_cpt_option_sys_site_logo_width'),
  149. 'value' => getParam('sys_site_logo_width'),
  150. 'db' => array (
  151. 'pass' => 'Int',
  152. ),
  153. ),
  154. 'height' => array(
  155. 'type' => 'text',
  156. 'name' => 'height',
  157. 'caption' => _t('_adm_stg_cpt_option_sys_site_logo_height'),
  158. 'value' => getParam('sys_site_logo_height'),
  159. 'db' => array (
  160. 'pass' => 'Int',
  161. ),
  162. ),
  163. 'alt' => array(
  164. 'type' => 'text',
  165. 'name' => 'alt',
  166. 'caption' => _t('_adm_dsg_txt_alt_text'),
  167. 'info' => _t('_adm_dsg_dsc_alt_text'),
  168. 'value' => getParam('sys_site_logo_alt'),
  169. 'checker' => array(
  170. 'func' => '',
  171. 'params' => array(),
  172. 'error' => ''
  173. ),
  174. 'db' => array (
  175. 'pass' => 'Xss',
  176. ),
  177. ),
  178. 'save' => array(
  179. 'type' => 'submit',
  180. 'name' => 'save',
  181. 'value' => _t('_adm_btn_designer_submit'),
  182. )
  183. )
  184. );
  185. $oForm = new BxTemplStudioFormView($aForm);
  186. $oForm->initChecker();
  187. if($oForm->isSubmittedAndValid()) {
  188. echo $this->submitLogo($oForm);
  189. exit;
  190. }
  191. $aTmplVars = array(
  192. 'js_object' => $this->getPageJsObject(),
  193. 'bx_repeat:blocks' => array(
  194. array(
  195. 'caption' => '',
  196. 'panel_top' => '',
  197. 'items' => $oTemplate->parseHtmlByName('dsr_logo.html', array('logo_iframe_id' => $this->sLogoIframeId, 'form' => $oForm->getCode())),
  198. 'panel_bottom' => ''
  199. )
  200. )
  201. );
  202. return $oTemplate->parseHtmlByName('designer.html', $aTmplVars);
  203. }
  204. protected function getIcon()
  205. {
  206. $oTemplate = BxDolStudioTemplate::getInstance();
  207. $sPreview = "";
  208. $aTmplVars = array('bx_repeat:images' => array());
  209. if(($iId = (int)getParam('sys_site_icon')) != 0) {
  210. $aTranscoders = array(
  211. BX_DOL_TRANSCODER_OBJ_ICON_APPLE => '_adm_dsg_txt_icon_apple',
  212. BX_DOL_TRANSCODER_OBJ_ICON_FACEBOOK => '_adm_dsg_txt_icon_facebook',
  213. BX_DOL_TRANSCODER_OBJ_ICON_FAVICON => '_adm_dsg_txt_icon_favicon'
  214. );
  215. foreach($aTranscoders as $sTranscoder => $sTitle) {
  216. $oTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  217. $sImageUrl = $oTranscoder->getFileUrl($iId);
  218. if($sImageUrl === false) {
  219. setParam('sys_site_icon', 0);
  220. break;
  221. }
  222. $aTmplVars['bx_repeat:images'][] = array(
  223. 'caption' => _t($sTitle),
  224. 'url' => $sImageUrl
  225. );
  226. }
  227. $sPreview = $oTemplate->parseHtmlByName('dsr_icon_preview.html', $aTmplVars);
  228. }
  229. $aForm = array(
  230. 'form_attrs' => array(
  231. 'id' => $this->sIconFormId,
  232. 'name' => $this->sIconFormId,
  233. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  234. 'method' => 'post',
  235. 'enctype' => 'multipart/form-data',
  236. 'target' => $this->sIconIframeId
  237. ),
  238. 'params' => array(
  239. 'db' => array(
  240. 'table' => '',
  241. 'key' => '',
  242. 'uri' => '',
  243. 'uri_title' => '',
  244. 'submit_name' => 'save'
  245. ),
  246. ),
  247. 'inputs' => array(
  248. 'page' => array(
  249. 'type' => 'hidden',
  250. 'name' => 'page',
  251. 'value' => $this->sPage
  252. ),
  253. 'preview' => array(
  254. 'type' => 'custom',
  255. 'name' => 'preview',
  256. 'content' => $sPreview
  257. ),
  258. 'image' => array(
  259. 'type' => 'file',
  260. 'name' => 'image',
  261. 'caption' => _t('_adm_dsg_txt_upload_icon')
  262. ),
  263. 'save' => array(
  264. 'type' => 'submit',
  265. 'name' => 'save',
  266. 'value' => _t('_adm_btn_designer_submit'),
  267. )
  268. )
  269. );
  270. $oForm = new BxTemplStudioFormView($aForm);
  271. $oForm->initChecker();
  272. if($oForm->isSubmittedAndValid()) {
  273. echo $this->submitIcon($oForm);
  274. exit;
  275. }
  276. $aTmplVars = array(
  277. 'js_object' => $this->getPageJsObject(),
  278. 'bx_repeat:blocks' => array(
  279. array(
  280. 'caption' => '',
  281. 'panel_top' => '',
  282. 'items' => $oTemplate->parseHtmlByName('dsr_icon.html', array('icon_iframe_id' => $this->sIconIframeId, 'form' => $oForm->getCode())),
  283. 'panel_bottom' => ''
  284. )
  285. )
  286. );
  287. return $oTemplate->parseHtmlByName('designer.html', $aTmplVars);
  288. }
  289. protected function getSettings()
  290. {
  291. $oPage = new BxTemplStudioSettings(BX_DOL_STUDIO_STG_TYPE_SYSTEM, BX_DOL_STUDIO_STG_CATEGORY_TEMPLATES);
  292. $aTmplVars = array(
  293. 'js_object' => $this->getPageJsObject(),
  294. 'bx_repeat:blocks' => $oPage->getPageCode(),
  295. );
  296. return BxDolStudioTemplate::getInstance()->parseHtmlByName('designer.html', $aTmplVars);
  297. }
  298. }
  299. /** @} */