BxBaseModTextPageEntry.php 6.7 KB

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