BxBaseModTextPageEntry.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. $iContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  24. if ($iContentId)
  25. $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
  26. $iProfileId = bx_get_logged_profile_id();
  27. $this->_bLoggedOwner = isset($this->_aContentInfo[$CNF['FIELD_AUTHOR']]) && $this->_aContentInfo[$CNF['FIELD_AUTHOR']] == $iProfileId;
  28. $this->_bLoggedModerator = $this->_oModule->checkAllowedEditAnyEntry() === CHECK_ACTION_RESULT_ALLOWED;
  29. $this->_bLoggedContextModerator = false;
  30. if($this->_aContentInfo && !empty($CNF['FIELD_ALLOW_VIEW_TO']) && (int)$this->_aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
  31. $iContextProfileId = abs((int)$this->_aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
  32. if(($oContextProfile = BxDolProfile::getInstance($iContextProfileId)) !== false) {
  33. $aAdmins = bx_srv($oContextProfile->getModule(), 'get_admins_to_manage_content', [$iContextProfileId]);
  34. if(!empty($aAdmins) && in_array($iProfileId, $aAdmins))
  35. $this->_bLoggedContextModerator = true;
  36. }
  37. }
  38. $sTitle = $sUrl = $sIcon = "";
  39. if ($this->_aContentInfo && CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedView($this->_aContentInfo)) {
  40. $sTitle = $this->_oModule->_oTemplate->getTitleAuto($this->_aContentInfo);
  41. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $this->_aContentInfo[$CNF['FIELD_ID']]));
  42. $sIcon = $CNF['ICON'];
  43. $this->addMarkers($this->_aContentInfo); // every field can be used as marker
  44. }
  45. $this->addMarkers(array(
  46. 'title' => $sTitle,
  47. 'entry_link' => $sUrl,
  48. ));
  49. // select view entry submenu
  50. $this->_setSubmenu(array(
  51. 'title' => $sTitle,
  52. 'link' => $sUrl,
  53. 'icon' => $sIcon
  54. ));
  55. $aInformers = array ();
  56. $oInformer = BxDolInformer::getInstance($this->_oTemplate);
  57. if($oInformer && ($this->_bLoggedOwner || $this->_bLoggedModerator || $this->_bLoggedContextModerator)) {
  58. $iNow = time();
  59. $bFieldPublished = isset($CNF['FIELD_PUBLISHED']);
  60. $sStatus = isset($CNF['FIELD_STATUS']) && isset($this->_aContentInfo[$CNF['FIELD_STATUS']]) ? $this->_aContentInfo[$CNF['FIELD_STATUS']] : '';
  61. $sStatusAdmin = isset($CNF['FIELD_STATUS_ADMIN']) && isset($this->_aContentInfo[$CNF['FIELD_STATUS_ADMIN']]) ? $this->_aContentInfo[$CNF['FIELD_STATUS_ADMIN']] : '';
  62. //--- Display 'approving' informer.
  63. if(!empty($sStatusAdmin) && $sStatusAdmin != BX_BASE_MOD_GENERAL_STATUS_ACTIVE) {
  64. if(!empty($CNF['INFORMERS']['approving']) && isset($CNF['INFORMERS']['approving']['map'][$sStatusAdmin])) {
  65. $aInformer = $CNF['INFORMERS']['approving'];
  66. $aInformers[] = array ('name' => $aInformer['name'], 'msg' => _t($aInformer['map'][$sStatusAdmin]['msg']), 'type' => $aInformer['map'][$sStatusAdmin]['type']);
  67. }
  68. }
  69. //--- Display 'processing' informer if an item was already published but awaiting/failed to be processed.
  70. if(!$bFieldPublished || (isset($this->_aContentInfo[$CNF['FIELD_PUBLISHED']]) && $this->_aContentInfo[$CNF['FIELD_PUBLISHED']] <= $iNow)) {
  71. if(!empty($CNF['INFORMERS']['processing']) && isset($CNF['INFORMERS']['processing']['map'][$sStatus])) {
  72. $aInformer = $CNF['INFORMERS']['processing'];
  73. $aInformers[] = array ('name' => $aInformer['name'], 'msg' => _t($aInformer['map'][$sStatus]['msg']), 'type' => $aInformer['map'][$sStatus]['type']);
  74. }
  75. }
  76. //--- Display 'scheduled' informer if an item wasn't published yet.
  77. else if($bFieldPublished) {
  78. if(!empty($CNF['INFORMERS']['scheduled']) && isset($CNF['INFORMERS']['scheduled']['map'][$sStatus])) {
  79. $this->addMarkers(array(
  80. 'date_publish_uf' => bx_time_js((int)$this->_aContentInfo[$CNF['FIELD_PUBLISHED']], BX_FORMAT_DATE, true)
  81. ));
  82. $aInformer = $CNF['INFORMERS']['scheduled'];
  83. $aInformers[] = array ('name' => $aInformer['name'], 'msg' => _t($aInformer['map'][$sStatus]['msg']), 'type' => $aInformer['map'][$sStatus]['type']);
  84. }
  85. }
  86. // add informers
  87. if($aInformers)
  88. foreach($aInformers as $aInformer)
  89. $oInformer->add($aInformer['name'], $this->_replaceMarkers($aInformer['msg']), $aInformer['type']);
  90. }
  91. }
  92. public function isActive()
  93. {
  94. return $this->_oModule->isEntryActive($this->_aContentInfo);
  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 _setSubmenu($aParams)
  109. {
  110. $CNF = &$this->_oModule->_oConfig->CNF;
  111. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  112. if(!$oMenuSubmenu)
  113. return false;
  114. $oMenuSubmenu->setObjectSubmenu(isset($this->_aObject['submenu']) && $this->_aObject['submenu'] ? $this->_aObject['submenu'] : $CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'], array_merge(array(
  115. 'title' => '',
  116. 'link' => '',
  117. 'icon' => '',
  118. ), $aParams));
  119. return true;
  120. }
  121. protected function _getBlockService ($aBlock)
  122. {
  123. $a = parent::_getBlockService ($aBlock);
  124. $sTest = '_view_entry_comments';
  125. if (false !== strpos($aBlock['content'], 'entity_comments') && substr_compare($this->_sObject, $sTest, strlen($this->_sObject) - strlen($sTest), strlen($sTest)) === 0)
  126. unset($a['title']);
  127. return $a;
  128. }
  129. protected function _getImageForPageCover ()
  130. {
  131. return false;
  132. }
  133. }
  134. /** @} */