1
0

BxBaseModGeneralConfig.php 4.4 KB

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