BxDolStudioPage.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 DolphinStudio Dolphin Studio
  7. * @{
  8. */
  9. bx_import('BxDol');
  10. bx_import('BxDolStudioUtils');
  11. bx_import('BxDolStudioPageQuery');
  12. define('BX_DOL_STUDIO_PAGE_HOME', 'home');
  13. define('BX_DOL_STUDIO_PAGE_JS_OBJECT', 'oBxDolStudioPage');
  14. define('BX_DOL_STUDIO_MIT_CAPTION', 'caption');
  15. define('BX_DOL_STUDIO_MIT_ITEM', 'item');
  16. class BxDolStudioPage extends BxDol
  17. {
  18. protected $oDb;
  19. protected $aPage;
  20. protected $bPageMultiple;
  21. protected $sPageSelected;
  22. protected $sPageRssHelpObject;
  23. protected $sPageRssHelpUrl;
  24. protected $iPageRssHelpLength;
  25. protected $sPageRssHelpId;
  26. protected $aActions;
  27. protected $aMarkers;
  28. function __construct($mixedPageName)
  29. {
  30. parent::__construct();
  31. $this->oDb = new BxDolStudioPageQuery();
  32. $this->aPage = array();
  33. $this->bPageMultiple = false;
  34. $this->sPageSelected = '';
  35. $this->sPageRssHelpObject = 'sys_studio_page_help';
  36. $this->sPageRssHelpUrl = 'http://feed.boonex.com/?section={page_name}';
  37. $this->iPageRssHelpLength = 5;
  38. $this->aActions = array();
  39. $this->aMarkers = array();
  40. if(is_string($mixedPageName)) {
  41. $this->oDb->getPages(array('type' => 'by_page_name_full', 'value' => $mixedPageName), $this->aPage, false);
  42. if(empty($this->aPage) || !is_array($this->aPage))
  43. return;
  44. $this->aPage['bookmarked'] = $this->oDb->isBookmarked($this->aPage);
  45. }
  46. else if(is_array($mixedPageName)) {
  47. $aPages = array();
  48. $this->oDb->getPages(array('type' => 'by_page_names_full', 'value' => array_keys($mixedPageName)), $aPages, false);
  49. if(empty($aPages) || !is_array($aPages))
  50. return;
  51. $this->bPageMultiple = true;
  52. foreach($aPages as $aPage) {
  53. if((int)$mixedPageName[$aPage['name']] == 1)
  54. $this->sPageSelected = $aPage['name'];
  55. $aPage['bookmarked'] = $this->oDb->isBookmarked($aPage);
  56. $this->aPage[$aPage['name']] = $aPage;
  57. }
  58. }
  59. if(!$this->bPageMultiple) {
  60. $this->sPageRssHelpId = $this->aPage['name'];
  61. $this->addAction(array(
  62. 'type' => 'switcher',
  63. 'name' => 'bookmark',
  64. 'caption' => '_adm_txt_pca_favorite',
  65. 'checked' => $this->aPage['bookmarked'],
  66. 'onchange' => "javascript:" . BX_DOL_STUDIO_PAGE_JS_OBJECT . ".bookmark('" . $this->aPage['name'] . "', this)"
  67. ));
  68. $this->aMarkers['page_name'] = $this->aPage['name'];
  69. }
  70. }
  71. public function getRssHelpUrl()
  72. {
  73. return bx_replace_markers($this->sPageRssHelpUrl, $this->aMarkers);
  74. }
  75. public function addAction($aAction, $bOnRight = true)
  76. {
  77. if($bOnRight)
  78. $this->aActions[] = $aAction;
  79. else
  80. $this->aActions = array_merge(array($aAction), $this->aActions);
  81. }
  82. /**
  83. * Add replace markers.
  84. * @param $a array of markers as key => value
  85. * @return true on success or false on error
  86. */
  87. public function addMarkers ($a)
  88. {
  89. if(empty($a) || !is_array($a))
  90. return false;
  91. $this->aMarkers = array_merge($this->aMarkers, $a);
  92. return true;
  93. }
  94. public function removeActions()
  95. {
  96. $this->aActions = array();
  97. }
  98. public function bookmark()
  99. {
  100. $bResult = $this->oDb->bookmark($this->aPage);
  101. if(!$bResult)
  102. return array('code' => 1, 'message' => _t('_adm_err_operation_failed'));
  103. bx_import('BxDolStudioTemplate');
  104. $oTemplate = BxDolStudioTemplate::getInstance();
  105. return array('code' => 0, 'message' => _t('_adm_scs_operation_done'));
  106. }
  107. protected function getSystemName($sValue)
  108. {
  109. return BxDolStudioUtils::getSystemName($sValue);
  110. }
  111. protected function getClassName($sValue)
  112. {
  113. return BxDolStudioUtils::getClassName($sValue);
  114. }
  115. protected function getModuleTitle($sName)
  116. {
  117. return BxDolStudioUtils::getModuleTitle($sName);
  118. }
  119. protected function getModuleIcon($sName, $sType = 'menu', $bReturnAsUrl = true)
  120. {
  121. return BxDolStudioUtils::getModuleIcon($sName, $sType, $bReturnAsUrl);
  122. }
  123. protected function getModules($bShowCustom = true, $bShowSystem = true)
  124. {
  125. return BxDolStudioUtils::getModules($bShowCustom, $bShowSystem);
  126. }
  127. }
  128. /** @} */