BxBaseModGeneralConfig.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. bx_alert($this->getName(), 'get_cnf', 0, 0, ['override_result' => &$this->CNF]);
  40. return $this->CNF;
  41. }
  42. public function getObject($sType = '')
  43. {
  44. if(empty($sType))
  45. return $this->_aObjects;
  46. return isset($this->_aObjects[$sType]) ? $this->_aObjects[$sType] : '';
  47. }
  48. public function getPrefix($sType = '')
  49. {
  50. if(empty($sType))
  51. return $this->_aPrefixes;
  52. return isset($this->_aPrefixes[$sType]) ? $this->_aPrefixes[$sType] : '';
  53. }
  54. public function getJsClass($sType)
  55. {
  56. return isset($this->_aJsClasses[$sType]) ? $this->_aJsClasses[$sType] : '';
  57. }
  58. public function getJsObject($sType)
  59. {
  60. return isset($this->_aJsObjects[$sType]) ? $this->_aJsObjects[$sType] : '';
  61. }
  62. public function getGridObject($sType)
  63. {
  64. return isset($this->_aGridObjects[$sType]) ? $this->_aGridObjects[$sType] : '';
  65. }
  66. /**
  67. * Is Auto Approve mode is available.
  68. */
  69. public function isAutoApprove()
  70. {
  71. return !empty($this->CNF['FIELD_STATUS_ADMIN']) && !empty($this->CNF['PARAM_AUTO_APPROVE']);
  72. }
  73. public function isAutoApproveEnabled()
  74. {
  75. return !$this->isAutoApprove() || getParam($this->CNF['PARAM_AUTO_APPROVE']) == 'on';
  76. }
  77. public function isEqualUrls($sUrl1, $sUrl2)
  78. {
  79. $sUrl1 = trim($sUrl1, "/");
  80. $sUrl2 = trim($sUrl2, "/");
  81. return strncmp($sUrl1, $sUrl2, strlen($sUrl1)) === 0;
  82. }
  83. public function getViewEntryUrl($mixedData)
  84. {
  85. if(!isset($this->CNF['URI_VIEW_ENTRY']))
  86. return '';
  87. $iId = 0;
  88. if(is_numeric($mixedData))
  89. $iId = (int)$mixedData;
  90. else if(is_array($mixedData) && isset($this->CNF['FIELD_ID'], $mixedData[$this->CNF['FIELD_ID']]))
  91. $iId = (int)$mixedData[$this->CNF['FIELD_ID']];
  92. else
  93. return '';
  94. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->CNF['URI_VIEW_ENTRY'] . '&id=' . $iId));
  95. }
  96. /*
  97. * Note. The first Transcoder in the array $aTranscoders has the highest priority.
  98. */
  99. public function getImageUrl($iId, $aTranscoders)
  100. {
  101. $sResult = '';
  102. if(empty($iId) || empty($aTranscoders) || !is_array($aTranscoders))
  103. return $sResult;
  104. foreach($aTranscoders as $sTranscoder) {
  105. if(empty($this->CNF[$sTranscoder]))
  106. continue;
  107. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->CNF[$sTranscoder]);
  108. if(!$oTranscoder)
  109. continue;
  110. $sResult = $oTranscoder->getFileUrl($iId);
  111. if(!empty($sResult))
  112. break;
  113. }
  114. return $sResult;
  115. }
  116. public function getDpnTime()
  117. {
  118. return $this->_iDpnTime;
  119. }
  120. }
  121. /** @} */