1
0

BxBaseModTextPageEntry.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup BaseText Base classes for text modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Entry create/edit pages
  13. */
  14. class BxBaseModTextPageEntry extends BxBaseModGeneralPageEntry
  15. {
  16. protected $_bLoggedOwner;
  17. protected $_bLoggedModerator;
  18. protected $_bLoggedContextModerator;
  19. public function __construct($aObject, $oTemplate = false)
  20. {
  21. parent::__construct($aObject, $oTemplate);
  22. $CNF = &$this->_oModule->_oConfig->CNF;
  23. if(($iContentId = bx_get('id')) !== false)
  24. $this->setContentId(bx_process_input($iContentId, BX_DATA_INT));
  25. $sTitle = $sUrl = $sIcon = "";
  26. if ($this->_aContentInfo && CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedView($this->_aContentInfo)) {
  27. $sTitle = $this->_oModule->_oTemplate->getTitleAuto($this->_aContentInfo);
  28. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $this->_aContentInfo[$CNF['FIELD_ID']]));
  29. $sIcon = $CNF['ICON'];
  30. $this->addMarkers($this->_aContentInfo); // every field can be used as marker
  31. }
  32. $this->addMarkers(array(
  33. 'title' => $sTitle,
  34. 'entry_link' => $sUrl,
  35. ));
  36. // select view entry submenu
  37. $this->_setSubmenu(array(
  38. 'title' => $sTitle,
  39. 'link' => $sUrl,
  40. 'icon' => $sIcon
  41. ));
  42. $aInformers = array ();
  43. $oInformer = BxDolInformer::getInstance($this->_oTemplate);
  44. if($oInformer && ($this->_bLoggedOwner || $this->_bLoggedModerator || $this->_bLoggedContextModerator)) {
  45. $iNow = time();
  46. $bFieldPublished = isset($CNF['FIELD_PUBLISHED']);
  47. $sStatus = isset($CNF['FIELD_STATUS']) && isset($this->_aContentInfo[$CNF['FIELD_STATUS']]) ? $this->_aContentInfo[$CNF['FIELD_STATUS']] : '';
  48. $sStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']) && isset($this->_aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) ? $this->_aContentInfo[$CNF['FIELD_STATUS_ADMIN']] : '';
  49. //--- Display 'approving' informer.
  50. if(!empty($sStatusAdmin) && $sStatusAdmin != BX_BASE_MOD_GENERAL_STATUS_ACTIVE) {
  51. if(!empty($CNF['INFORMERS']['approving']) && isset($CNF['INFORMERS']['approving']['map'][$sStatusAdmin])) {
  52. $aInformer = $CNF['INFORMERS']['approving'];
  53. $aInformers[] = array ('name' => $aInformer['name'], 'msg' => _t($aInformer['map'][$sStatusAdmin]['msg']), 'type' => $aInformer['map'][$sStatusAdmin]['type']);
  54. }
  55. }
  56. //--- Display 'processing' informer if an item was already published but awaiting/failed to be processed.
  57. if(!$bFieldPublished || (isset($this->_aContentInfo[$CNF['FIELD_PUBLISHED']]) && $this->_aContentInfo[$CNF['FIELD_PUBLISHED']] <= $iNow)) {
  58. if(!empty($CNF['INFORMERS']['processing']) && isset($CNF['INFORMERS']['processing']['map'][$sStatus])) {
  59. $aInformer = $CNF['INFORMERS']['processing'];
  60. $aInformers[] = array ('name' => $aInformer['name'], 'msg' => _t($aInformer['map'][$sStatus]['msg']), 'type' => $aInformer['map'][$sStatus]['type']);
  61. }
  62. }
  63. //--- Display 'scheduled' informer if an item wasn't published yet.
  64. else if($bFieldPublished) {
  65. if(!empty($CNF['INFORMERS']['scheduled']) && isset($CNF['INFORMERS']['scheduled']['map'][$sStatus])) {
  66. $this->addMarkers(array(
  67. 'date_publish_uf' => bx_time_js((int)$this->_aContentInfo[$CNF['FIELD_PUBLISHED']], BX_FORMAT_DATE, true)
  68. ));
  69. $aInformer = $CNF['INFORMERS']['scheduled'];
  70. $aInformers[] = array ('name' => $aInformer['name'], 'msg' => _t($aInformer['map'][$sStatus]['msg']), 'type' => $aInformer['map'][$sStatus]['type']);
  71. }
  72. }
  73. // add informers
  74. if($aInformers)
  75. foreach($aInformers as $aInformer)
  76. $oInformer->add($aInformer['name'], $this->_replaceMarkers($aInformer['msg']), $aInformer['type']);
  77. }
  78. }
  79. public function setContentId($iId)
  80. {
  81. $CNF = &$this->_oModule->_oConfig->CNF;
  82. $iProfileId = bx_get_logged_profile_id();
  83. $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($iId);
  84. $this->_bLoggedOwner = isset($this->_aContentInfo[$CNF['FIELD_AUTHOR']]) && $this->_aContentInfo[$CNF['FIELD_AUTHOR']] == $iProfileId;
  85. $this->_bLoggedModerator = $this->_oModule->checkAllowedEditAnyEntry() === CHECK_ACTION_RESULT_ALLOWED;
  86. $this->_bLoggedContextModerator = false;
  87. if($this->_aContentInfo && !empty($CNF['FIELD_ALLOW_VIEW_TO']) && (int)$this->_aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  88. $iContextProfileId = abs((int)$this->_aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  89. if(($oContextProfile = BxDolProfile::getInstance($iContextProfileId)) !== false) {
  90. $aAdmins = bx_srv($oContextProfile->getModule(), 'get_admins_to_manage_content', [$iContextProfileId]);
  91. if(!empty($aAdmins) && in_array($iProfileId, $aAdmins))
  92. $this->_bLoggedContextModerator = true;
  93. }
  94. }
  95. }
  96. public function getCode ()
  97. {
  98. $mixedResult = parent::getCode();
  99. /*
  100. * Hide actions menu from View Page cover because
  101. * cover area should be decorative in Text Based modules.
  102. */
  103. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  104. if($oMenuSubmenu)
  105. $oMenuSubmenu->setObjectActionsMenu(false);
  106. return $mixedResult;
  107. }
  108. protected function _isAvailablePage($a)
  109. {
  110. if(!$this->_aContentInfo || !$this->_oModule->isEntryActive($this->_aContentInfo))
  111. return false;
  112. return parent::_isAvailablePage($a);
  113. }
  114. protected function _setSubmenu($aParams)
  115. {
  116. $CNF = &$this->_oModule->_oConfig->CNF;
  117. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  118. if(!$oMenuSubmenu)
  119. return false;
  120. $oMenuSubmenu->setObjectSubmenu(isset($this->_aObject['submenu']) && $this->_aObject['submenu'] ? $this->_aObject['submenu'] : $CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'], array_merge(array(
  121. 'title' => '',
  122. 'link' => '',
  123. 'icon' => '',
  124. ), $aParams));
  125. return true;
  126. }
  127. protected function _getBlockService ($aBlock)
  128. {
  129. $a = parent::_getBlockService ($aBlock);
  130. $sTest = '_view_entry_comments';
  131. if (false !== strpos($aBlock['content'], 'entity_comments') && substr_compare($this->_sObject, $sTest, strlen($this->_sObject) - strlen($sTest), strlen($sTest)) === 0)
  132. unset($a['title']);
  133. return $a;
  134. }
  135. protected function _getImageForPageCover ()
  136. {
  137. return false;
  138. }
  139. }
  140. /** @} */