1
0

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