BxBaseModGeneralConfig.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxBaseModGeneralConfig extends BxDolModuleConfig
  12. {
  13. public $CNF;
  14. protected $_aObjects;
  15. protected $_aPrefixes;
  16. protected $_aJsClasses;
  17. protected $_aJsObjects;
  18. protected $_aHtmlIds;
  19. protected $_aGridObjects;
  20. protected $_bIsApi;
  21. /**
  22. * Delayed Publishing Notification Time (in seconds)
  23. * If video transcoding takes more than specified amount of time
  24. * then author will be notified about publishing (failure).
  25. */
  26. protected $_iDpnTime;
  27. function __construct($aModule)
  28. {
  29. parent::__construct($aModule);
  30. $this->CNF = array();
  31. $this->_aObjects = array();
  32. $this->_aPrefixes = array();
  33. $this->_aJsClasses = array();
  34. $this->_aJsObjects = array();
  35. $this->_aGridObjects = array();
  36. $this->_bIsApi = bx_is_api();
  37. $this->_iDpnTime = 3600;
  38. }
  39. public function getCNF()
  40. {
  41. /**
  42. * @hooks
  43. * @hookdef hook-bx_base_general-get_cnf '{module_name}', 'get_cnf' - hook to override module's configuration array
  44. * - $unit_name - module name
  45. * - $action - equals `get_cnf`
  46. * - $object_id - not used
  47. * - $sender_id - not used
  48. * - $extra_params - array of additional params with the following array keys:
  49. * - `override_result` - [array] by ref, module's configuration array, can be overridden in hook processing
  50. * @hook @ref hook-bx_base_general-get_cnf
  51. */
  52. bx_alert($this->getName(), 'get_cnf', 0, 0, ['override_result' => &$this->CNF]);
  53. return $this->CNF;
  54. }
  55. public function getObject($sType = '')
  56. {
  57. if(empty($sType))
  58. return $this->_aObjects;
  59. return isset($this->_aObjects[$sType]) ? $this->_aObjects[$sType] : '';
  60. }
  61. public function getPrefix($sType = '')
  62. {
  63. if(empty($sType))
  64. return $this->_aPrefixes;
  65. return isset($this->_aPrefixes[$sType]) ? $this->_aPrefixes[$sType] : '';
  66. }
  67. public function getJsClass($sType)
  68. {
  69. return isset($this->_aJsClasses[$sType]) ? $this->_aJsClasses[$sType] : '';
  70. }
  71. public function getJsObject($sType)
  72. {
  73. return isset($this->_aJsObjects[$sType]) ? $this->_aJsObjects[$sType] : '';
  74. }
  75. public function getGridObject($sType)
  76. {
  77. return isset($this->_aGridObjects[$sType]) ? $this->_aGridObjects[$sType] : '';
  78. }
  79. /**
  80. * Is Auto Approve mode is available.
  81. */
  82. public function isAutoApprove()
  83. {
  84. return !empty($this->CNF['FIELD_STATUS_ADMIN']) && !empty($this->CNF['PARAM_AUTO_APPROVE']);
  85. }
  86. public function isAutoApproveEnabled()
  87. {
  88. return !$this->isAutoApprove() || getParam($this->CNF['PARAM_AUTO_APPROVE']) == 'on';
  89. }
  90. public function isEqualUrls($sUrl1, $sUrl2)
  91. {
  92. $sUrl1 = trim($sUrl1, "/");
  93. $sUrl2 = trim($sUrl2, "/");
  94. return strncmp($sUrl1, $sUrl2, strlen($sUrl1)) === 0;
  95. }
  96. public function getViewEntryUrl($mixedData)
  97. {
  98. if(!isset($this->CNF['URI_VIEW_ENTRY']))
  99. return '';
  100. $iId = 0;
  101. if(is_numeric($mixedData))
  102. $iId = (int)$mixedData;
  103. else if(is_array($mixedData) && isset($this->CNF['FIELD_ID'], $mixedData[$this->CNF['FIELD_ID']]))
  104. $iId = (int)$mixedData[$this->CNF['FIELD_ID']];
  105. else
  106. return '';
  107. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->CNF['URI_VIEW_ENTRY'] . '&id=' . $iId));
  108. }
  109. public function getEntryUri($sAction)
  110. {
  111. $sUri = '';
  112. if(($sKeyUri = 'URI_' . strtoupper($sAction) . '_ENTRY') && !empty($this->CNF[$sKeyUri]))
  113. $sUri = $this->CNF[$sKeyUri];
  114. if(!$sUri && $sAction == 'add' && ($sKeyUri = 'URI_EDIT_ENTRY') && !empty($this->CNF[$sKeyUri]))
  115. $sUri = str_replace('edit', 'create', $this->CNF[$sKeyUri]);
  116. return $sUri;
  117. }
  118. /*
  119. * Note. The first Transcoder in the array $aTranscoders has the highest priority.
  120. */
  121. public function getImageUrl($iId, $aTranscoders)
  122. {
  123. $sResult = '';
  124. if(empty($iId) || empty($aTranscoders) || !is_array($aTranscoders))
  125. return $sResult;
  126. foreach($aTranscoders as $sTranscoder) {
  127. if(empty($this->CNF[$sTranscoder]))
  128. continue;
  129. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->CNF[$sTranscoder]);
  130. if(!$oTranscoder)
  131. continue;
  132. $sResult = $oTranscoder->getFileUrl($iId);
  133. if(!empty($sResult))
  134. break;
  135. }
  136. return $sResult;
  137. }
  138. public function getDpnTime()
  139. {
  140. return $this->_iDpnTime;
  141. }
  142. }
  143. /** @} */