BxBaseStudioDesigner.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. bx_import('BxTemplPaginate');
  11. bx_import('BxDolStudioDesigner');
  12. bx_import('BxTemplStudioFormView');
  13. class BxBaseStudioDesigner extends BxDolStudioDesigner
  14. {
  15. protected $sLogoFormId = 'adm-dsg-logo-form';
  16. protected $sLogoIframeId = 'adm-dsg-logo-iframe';
  17. protected $sIconFormId = 'adm-dsg-icon-form';
  18. protected $sIconIframeId = 'adm-dsg-icon-iframe';
  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_SETTINGS => array('icon' => 'cogs'),
  44. );
  45. foreach($aMenuItems as $sMenuItem => $aItem)
  46. $aMenu[] = array(
  47. 'name' => $sMenuItem,
  48. 'icon' => $aItem['icon'],
  49. 'link' => BX_DOL_URL_STUDIO . 'designer.php?page=' . $sMenuItem,
  50. 'title' => _t('_adm_lmi_cpt_' . $sMenuItem),
  51. 'selected' => $sMenuItem == $this->sPage
  52. );
  53. return parent::getPageMenu($aMenu);
  54. }
  55. function getPageCode($bHidden = false)
  56. {
  57. $sMethod = 'get' . ucfirst($this->sPage);
  58. if(!method_exists($this, $sMethod))
  59. return '';
  60. return $this->$sMethod();
  61. }
  62. protected function getGeneral()
  63. {
  64. $sJsObject = $this->getPageJsObject();
  65. $oTemplate = BxDolStudioTemplate::getInstance();
  66. $sResult = '';
  67. $sTemplate = getParam('template');
  68. $aTemplates = get_templates_array(true, false);
  69. $aTmplVarsTemplates = array ();
  70. foreach($aTemplates as $sUri => $aTemplate) {
  71. $sIcon = $this->getModuleIcon($aTemplate, 'store');
  72. $bIcon = strpos($sIcon, '.') === false;
  73. $aTmplVarsTemplates[] = array(
  74. 'uri' => $sUri,
  75. 'title' => htmlspecialchars_adv($aTemplate['title']),
  76. 'version' => htmlspecialchars_adv($aTemplate['version']),
  77. 'vendor' => htmlspecialchars_adv($aTemplate['vendor']),
  78. 'bx_if:icon' => array (
  79. 'condition' => $bIcon,
  80. 'content' => array('icon' => $sIcon),
  81. ),
  82. 'bx_if:image' => array (
  83. 'condition' => !$bIcon,
  84. 'content' => array('icon_url' => $sIcon),
  85. ),
  86. 'bx_if:default' => array (
  87. 'condition' => $sUri == $sTemplate,
  88. 'content' => array (),
  89. ),
  90. 'bx_if:make_default' => array (
  91. 'condition' => $sUri != $sTemplate,
  92. 'content' => array(
  93. 'js_object' => $sJsObject,
  94. 'uri' => $sUri
  95. ),
  96. )
  97. );
  98. }
  99. $sContent = $sResult ? MsgBox($sResult, 10) : '';
  100. $sContent .= $oTemplate->parseHtmlByName('templates.html', array(
  101. 'bx_repeat:templates' => $aTmplVarsTemplates,
  102. ));
  103. $aTmplVars = array(
  104. 'js_object' => $this->getPageJsObject(),
  105. 'bx_repeat:blocks' => $sContent,
  106. );
  107. return $oTemplate->parseHtmlByName('designer.html', $aTmplVars);
  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. $aTmplVars = array(
  195. 'js_object' => $this->getPageJsObject(),
  196. 'bx_repeat:blocks' => array(
  197. array(
  198. 'caption' => '',
  199. 'panel_top' => '',
  200. 'items' => $oTemplate->parseHtmlByName('dsr_logo.html', array('logo_iframe_id' => $this->sLogoIframeId, 'form' => $oForm->getCode())),
  201. 'panel_bottom' => ''
  202. )
  203. )
  204. );
  205. return $oTemplate->parseHtmlByName('designer.html', $aTmplVars);
  206. }
  207. protected function getIcon()
  208. {
  209. $oTemplate = BxDolStudioTemplate::getInstance();
  210. $sPreview = "";
  211. $aTmplVars = array('bx_repeat:images' => array());
  212. if(($iId = (int)getParam('sys_site_icon')) != 0) {
  213. $aTranscoders = array(
  214. BX_DOL_TRANSCODER_OBJ_ICON_APPLE => '_adm_dsg_txt_icon_apple',
  215. BX_DOL_TRANSCODER_OBJ_ICON_FACEBOOK => '_adm_dsg_txt_icon_facebook',
  216. BX_DOL_TRANSCODER_OBJ_ICON_FAVICON => '_adm_dsg_txt_icon_favicon'
  217. );
  218. bx_import('BxDolTranscoderImage');
  219. foreach($aTranscoders as $sTranscoder => $sTitle) {
  220. $oTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  221. $sImageUrl = $oTranscoder->getFileUrl($iId);
  222. if($sImageUrl === false) {
  223. setParam('sys_site_icon', 0);
  224. break;
  225. }
  226. $aTmplVars['bx_repeat:images'][] = array(
  227. 'caption' => _t($sTitle),
  228. 'url' => $sImageUrl
  229. );
  230. }
  231. $sPreview = $oTemplate->parseHtmlByName('dsr_icon_preview.html', $aTmplVars);
  232. }
  233. $aForm = array(
  234. 'form_attrs' => array(
  235. 'id' => $this->sIconFormId,
  236. 'name' => $this->sIconFormId,
  237. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  238. 'method' => 'post',
  239. 'enctype' => 'multipart/form-data',
  240. 'target' => $this->sIconIframeId
  241. ),
  242. 'params' => array(
  243. 'db' => array(
  244. 'table' => '',
  245. 'key' => '',
  246. 'uri' => '',
  247. 'uri_title' => '',
  248. 'submit_name' => 'save'
  249. ),
  250. ),
  251. 'inputs' => array(
  252. 'page' => array(
  253. 'type' => 'hidden',
  254. 'name' => 'page',
  255. 'value' => $this->sPage
  256. ),
  257. 'preview' => array(
  258. 'type' => 'custom',
  259. 'name' => 'preview',
  260. 'content' => $sPreview
  261. ),
  262. 'image' => array(
  263. 'type' => 'file',
  264. 'name' => 'image',
  265. 'caption' => _t('_adm_dsg_txt_upload_icon')
  266. ),
  267. 'save' => array(
  268. 'type' => 'submit',
  269. 'name' => 'save',
  270. 'value' => _t('_adm_btn_designer_submit'),
  271. )
  272. )
  273. );
  274. $oForm = new BxTemplStudioFormView($aForm);
  275. $oForm->initChecker();
  276. if($oForm->isSubmittedAndValid()) {
  277. echo $this->submitIcon($oForm);
  278. exit;
  279. }
  280. $aTmplVars = array(
  281. 'js_object' => $this->getPageJsObject(),
  282. 'bx_repeat:blocks' => array(
  283. array(
  284. 'caption' => '',
  285. 'panel_top' => '',
  286. 'items' => $oTemplate->parseHtmlByName('dsr_icon.html', array('icon_iframe_id' => $this->sIconIframeId, 'form' => $oForm->getCode())),
  287. 'panel_bottom' => ''
  288. )
  289. )
  290. );
  291. return $oTemplate->parseHtmlByName('designer.html', $aTmplVars);
  292. }
  293. protected function getSettings()
  294. {
  295. $oTemplate = BxDolStudioTemplate::getInstance();
  296. bx_import('BxTemplStudioSettings');
  297. $oPage = new BxTemplStudioSettings(BX_DOL_STUDIO_STG_TYPE_SYSTEM, BX_DOL_STUDIO_STG_CATEGORY_TEMPLATES);
  298. $aTmplVars = array(
  299. 'js_object' => $this->getPageJsObject(),
  300. 'bx_repeat:blocks' => $oPage->getPageCode(),
  301. );
  302. return $oTemplate->parseHtmlByName('designer.html', $aTmplVars);
  303. }
  304. }
  305. /** @} */