BxBaseModTextPageEntry.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. $bLoggedOwner = isset($this->_aContentInfo[$CNF['FIELD_AUTHOR']]) && $this->_aContentInfo[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id();
  24. $bLoggedModerator = $this->_oModule->checkAllowedEditAnyEntry() === CHECK_ACTION_RESULT_ALLOWED;
  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_DOL_URL_ROOT . 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 && ($bLoggedOwner || $bLoggedModerator)) {
  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_TEXT_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 isActive()
  80. {
  81. return $this->_oModule->isEntryActive($this->_aContentInfo);
  82. }
  83. public function getCode ()
  84. {
  85. $mixedResult = parent::getCode();
  86. /*
  87. * Hide actions menu from View Page cover because
  88. * cover area should be decorative in Text Based modules.
  89. */
  90. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  91. if($oMenuSubmenu)
  92. $oMenuSubmenu->setObjectActionsMenu(false);
  93. return $mixedResult;
  94. }
  95. protected function _setSubmenu($aParams)
  96. {
  97. $CNF = &$this->_oModule->_oConfig->CNF;
  98. $oMenuSubmenu = BxDolMenu::getObjectInstance('sys_site_submenu');
  99. if(!$oMenuSubmenu)
  100. return false;
  101. $oMenuSubmenu->setObjectSubmenu(isset($this->_aObject['submenu']) && $this->_aObject['submenu'] ? $this->_aObject['submenu'] : $CNF['OBJECT_MENU_SUBMENU_VIEW_ENTRY'], array_merge(array(
  102. 'title' => '',
  103. 'link' => '',
  104. 'icon' => '',
  105. ), $aParams));
  106. return true;
  107. }
  108. protected function _getBlockService ($aBlock)
  109. {
  110. $a = parent::_getBlockService ($aBlock);
  111. $sTest = '_view_entry_comments';
  112. if (false !== strpos($aBlock['content'], 'entity_comments') && substr_compare($this->_sObject, $sTest, strlen($this->_sObject) - strlen($sTest), strlen($sTest)) === 0)
  113. unset($a['title']);
  114. return $a;
  115. }
  116. protected function _getImageForPageCover ()
  117. {
  118. return false;
  119. }
  120. }
  121. /** @} */