1
0

BxBaseStudioDesigner.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 DolphinView Dolphin Studio Representation classes
  7. * @ingroup DolphinStudio
  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. $sAlt = getParam('sys_site_logo_alt');
  113. $aForm = array(
  114. 'form_attrs' => array(
  115. 'id' => $this->sLogoFormId,
  116. 'name' => $this->sLogoFormId,
  117. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  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. 'value' => (int)getParam('sys_site_logo')
  144. ),
  145. 'alt' => array(
  146. 'type' => 'text',
  147. 'name' => 'alt',
  148. 'caption' => _t('_adm_dsg_txt_alt_text'),
  149. 'info' => _t('_adm_dsg_dsc_alt_text'),
  150. 'value' => $sAlt,
  151. 'checker' => array(
  152. 'func' => '',
  153. 'params' => array(),
  154. 'error' => ''
  155. ),
  156. 'db' => array (
  157. 'pass' => 'Xss',
  158. ),
  159. ),
  160. 'save' => array(
  161. 'type' => 'submit',
  162. 'name' => 'save',
  163. 'value' => _t('_adm_btn_designer_submit'),
  164. )
  165. )
  166. );
  167. $oForm = new BxTemplStudioFormView($aForm);
  168. $oForm->initChecker();
  169. if($oForm->isSubmittedAndValid()) {
  170. echo $this->submitLogo($oForm);
  171. exit;
  172. }
  173. $aTmplVars = array(
  174. 'js_object' => $this->getPageJsObject(),
  175. 'bx_repeat:blocks' => array(
  176. array(
  177. 'caption' => '',
  178. 'panel_top' => '',
  179. 'items' => $oTemplate->parseHtmlByName('dsr_logo.html', array('logo_iframe_id' => $this->sLogoIframeId, 'form' => $oForm->getCode())),
  180. 'panel_bottom' => ''
  181. )
  182. )
  183. );
  184. return $oTemplate->parseHtmlByName('designer.html', $aTmplVars);
  185. }
  186. protected function getIcon()
  187. {
  188. $oTemplate = BxDolStudioTemplate::getInstance();
  189. $sPreview = "";
  190. $aTmplVars = array('bx_repeat:images' => array());
  191. if(($iId = (int)getParam('sys_site_icon')) != 0) {
  192. $aTranscoders = array(
  193. BX_DOL_TRANSCODER_OBJ_ICON_APPLE => '_adm_dsg_txt_icon_apple',
  194. BX_DOL_TRANSCODER_OBJ_ICON_FACEBOOK => '_adm_dsg_txt_icon_facebook',
  195. BX_DOL_TRANSCODER_OBJ_ICON_FAVICON => '_adm_dsg_txt_icon_favicon'
  196. );
  197. bx_import('BxDolTranscoderImage');
  198. foreach($aTranscoders as $sTranscoder => $sTitle) {
  199. $oTranscoder = BxDolTranscoderImage::getObjectInstance($sTranscoder);
  200. $sImageUrl = $oTranscoder->getImageUrl($iId);
  201. if($sImageUrl === false) {
  202. setParam('sys_site_icon', 0);
  203. break;
  204. }
  205. $aTmplVars['bx_repeat:images'][] = array(
  206. 'caption' => _t($sTitle),
  207. 'url' => $sImageUrl
  208. );
  209. }
  210. $sPreview = $oTemplate->parseHtmlByName('dsr_icon_preview.html', $aTmplVars);
  211. }
  212. $aForm = array(
  213. 'form_attrs' => array(
  214. 'id' => $this->sIconFormId,
  215. 'name' => $this->sIconFormId,
  216. 'action' => BX_DOL_URL_STUDIO . 'designer.php',
  217. 'method' => 'post',
  218. 'enctype' => 'multipart/form-data',
  219. 'target' => $this->sIconIframeId
  220. ),
  221. 'params' => array(
  222. 'db' => array(
  223. 'table' => '',
  224. 'key' => '',
  225. 'uri' => '',
  226. 'uri_title' => '',
  227. 'submit_name' => 'save'
  228. ),
  229. ),
  230. 'inputs' => array(
  231. 'page' => array(
  232. 'type' => 'hidden',
  233. 'name' => 'page',
  234. 'value' => $this->sPage
  235. ),
  236. 'preview' => array(
  237. 'type' => 'custom',
  238. 'name' => 'preview',
  239. 'content' => $sPreview
  240. ),
  241. 'image' => array(
  242. 'type' => 'file',
  243. 'name' => 'image',
  244. 'caption' => _t('_adm_dsg_txt_upload_icon')
  245. ),
  246. 'save' => array(
  247. 'type' => 'submit',
  248. 'name' => 'save',
  249. 'value' => _t('_adm_btn_designer_submit'),
  250. )
  251. )
  252. );
  253. $oForm = new BxTemplStudioFormView($aForm);
  254. $oForm->initChecker();
  255. if($oForm->isSubmittedAndValid()) {
  256. echo $this->submitIcon($oForm);
  257. exit;
  258. }
  259. $aTmplVars = array(
  260. 'js_object' => $this->getPageJsObject(),
  261. 'bx_repeat:blocks' => array(
  262. array(
  263. 'caption' => '',
  264. 'panel_top' => '',
  265. 'items' => $oTemplate->parseHtmlByName('dsr_icon.html', array('icon_iframe_id' => $this->sIconIframeId, 'form' => $oForm->getCode())),
  266. 'panel_bottom' => ''
  267. )
  268. )
  269. );
  270. return $oTemplate->parseHtmlByName('designer.html', $aTmplVars);
  271. }
  272. protected function getSettings()
  273. {
  274. $oTemplate = BxDolStudioTemplate::getInstance();
  275. bx_import('BxTemplStudioSettings');
  276. $oPage = new BxTemplStudioSettings(BX_DOL_STUDIO_STG_TYPE_SYSTEM, BX_DOL_STUDIO_STG_CATEGORY_TEMPLATES);
  277. $aTmplVars = array(
  278. 'js_object' => $this->getPageJsObject(),
  279. 'bx_repeat:blocks' => $oPage->getPageCode(),
  280. );
  281. return $oTemplate->parseHtmlByName('designer.html', $aTmplVars);
  282. }
  283. }
  284. /** @} */