BxBaseModGeneralConfig.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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 $_aHtmlIdsPoll;
  20. protected $_aGridObjects;
  21. protected $_bIsApi;
  22. /**
  23. * Delayed Publishing Notification Time (in seconds)
  24. * If video transcoding takes more than specified amount of time
  25. * then author will be notified about publishing (failure).
  26. */
  27. protected $_iDpnTime;
  28. function __construct($aModule)
  29. {
  30. parent::__construct($aModule);
  31. $this->CNF = [
  32. // modules icon
  33. 'ICON_POLLS_ANSWERS' => 'vote-yea',
  34. 'ICON_POLLS_RESULTS' => 'poll-h',
  35. // database tables
  36. 'TABLE_POLLS' => $aModule['db_prefix'] . 'polls',
  37. 'TABLE_POLLS_ANSWERS' => $aModule['db_prefix'] . 'polls_answers',
  38. 'TABLE_POLLS_ANSWERS_VOTES' => $aModule['db_prefix'] . 'polls_answers_votes',
  39. 'TABLE_POLLS_ANSWERS_VOTES_TRACK' => $aModule['db_prefix'] . 'polls_answers_votes_track',
  40. // database fields
  41. 'FIELD_POLL_ID' => 'id',
  42. 'FIELD_POLL_AUTHOR_ID' => 'author_id',
  43. 'FIELD_POLL_CONTENT_ID' => 'content_id',
  44. 'FIELD_POLL_TEXT' => 'text',
  45. 'FIELD_POLL_ANSWERS' => 'answers',
  46. // some params
  47. 'PARAM_POLL_ENABLED' => true,
  48. 'PARAM_POLL_HIDDEN_RESULTS' => false,
  49. 'PARAM_POLL_ANONYMOUS_VOTING' => true,
  50. // objects
  51. 'OBJECT_VOTES_POLL_ANSWERS' => $this->_sName . '_poll_answers',
  52. // styles
  53. 'STYLES_POLLS_EMBED_CLASS' => 'body.bx-page-iframe.bx-def-color-bg-page',
  54. 'STYLES_POLLS_EMBED_CONTENT' => [
  55. 'background-color' => '#ffffff'
  56. ]
  57. ];
  58. $sPrefix = str_replace('_', '-', $this->_sName);
  59. $this->_aObjects = [];
  60. $this->_aPrefixes = [];
  61. $this->_aJsClasses = [
  62. 'poll' => $this->_sClassPrefix . 'Polls'
  63. ];
  64. $this->_aJsObjects = [
  65. 'poll' => 'o' . $this->_sClassPrefix . 'Polls'
  66. ];
  67. $this->_aGridObjects = [];
  68. $this->_aHtmlIds = [];
  69. $this->_aHtmlIdsPoll = [
  70. 'add_poll_popup' => $sPrefix . '-add-poll-popup',
  71. 'add_poll_form_field' => $sPrefix . '-add-poll-form-field',
  72. 'polls_showcase' => $sPrefix . '-polls-showcase-',
  73. 'poll' => $sPrefix . '-poll-',
  74. 'poll_content' => $sPrefix . '-poll-content-',
  75. 'poll_view_menu' => $sPrefix . '-poll-view-menu',
  76. 'poll_view_link_answers' => $sPrefix . '-poll-view-answers-',
  77. 'poll_view_link_results' => $sPrefix . '-poll-view-results-',
  78. ];
  79. $this->_bIsApi = bx_is_api();
  80. $this->_iDpnTime = 3600;
  81. }
  82. public function getCNF()
  83. {
  84. /**
  85. * @hooks
  86. * @hookdef hook-bx_base_general-get_cnf '{module_name}', 'get_cnf' - hook to override module's configuration array
  87. * - $unit_name - module name
  88. * - $action - equals `get_cnf`
  89. * - $object_id - not used
  90. * - $sender_id - not used
  91. * - $extra_params - array of additional params with the following array keys:
  92. * - `override_result` - [array] by ref, module's configuration array, can be overridden in hook processing
  93. * @hook @ref hook-bx_base_general-get_cnf
  94. */
  95. bx_alert($this->getName(), 'get_cnf', 0, 0, ['override_result' => &$this->CNF]);
  96. return $this->CNF;
  97. }
  98. public function getObject($sType = '')
  99. {
  100. if(empty($sType))
  101. return $this->_aObjects;
  102. return isset($this->_aObjects[$sType]) ? $this->_aObjects[$sType] : '';
  103. }
  104. public function getPrefix($sType = '')
  105. {
  106. if(empty($sType))
  107. return $this->_aPrefixes;
  108. return isset($this->_aPrefixes[$sType]) ? $this->_aPrefixes[$sType] : '';
  109. }
  110. public function getJsClass($sType)
  111. {
  112. return isset($this->_aJsClasses[$sType]) ? $this->_aJsClasses[$sType] : '';
  113. }
  114. public function getJsObject($sType)
  115. {
  116. return isset($this->_aJsObjects[$sType]) ? $this->_aJsObjects[$sType] : '';
  117. }
  118. public function getGridObject($sType)
  119. {
  120. return isset($this->_aGridObjects[$sType]) ? $this->_aGridObjects[$sType] : '';
  121. }
  122. /**
  123. * Is Auto Approve mode is available.
  124. */
  125. public function isAutoApprove()
  126. {
  127. return !empty($this->CNF['FIELD_STATUS_ADMIN']) && !empty($this->CNF['PARAM_AUTO_APPROVE']);
  128. }
  129. public function isAutoApproveEnabled()
  130. {
  131. return !$this->isAutoApprove() || getParam($this->CNF['PARAM_AUTO_APPROVE']) == 'on';
  132. }
  133. public function isEqualUrls($sUrl1, $sUrl2)
  134. {
  135. $sUrl1 = trim($sUrl1, "/");
  136. $sUrl2 = trim($sUrl2, "/");
  137. return strncmp($sUrl1, $sUrl2, strlen($sUrl1)) === 0;
  138. }
  139. public function getViewEntryUrl($mixedData)
  140. {
  141. if(!isset($this->CNF['URI_VIEW_ENTRY']))
  142. return '';
  143. $iId = 0;
  144. if(is_numeric($mixedData))
  145. $iId = (int)$mixedData;
  146. else if(is_array($mixedData) && isset($this->CNF['FIELD_ID'], $mixedData[$this->CNF['FIELD_ID']]))
  147. $iId = (int)$mixedData[$this->CNF['FIELD_ID']];
  148. else
  149. return '';
  150. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->CNF['URI_VIEW_ENTRY'] . '&id=' . $iId));
  151. }
  152. public function getEntryUri($sAction)
  153. {
  154. $sUri = '';
  155. if(($sKeyUri = 'URI_' . strtoupper($sAction) . '_ENTRY') && !empty($this->CNF[$sKeyUri]))
  156. $sUri = $this->CNF[$sKeyUri];
  157. if(!$sUri && $sAction == 'add' && ($sKeyUri = 'URI_EDIT_ENTRY') && !empty($this->CNF[$sKeyUri]))
  158. $sUri = str_replace('edit', 'create', $this->CNF[$sKeyUri]);
  159. return $sUri;
  160. }
  161. /*
  162. * Note. The first Transcoder in the array $aTranscoders has the highest priority.
  163. */
  164. public function getImageUrl($iId, $aTranscoders)
  165. {
  166. $sResult = '';
  167. if(empty($iId) || empty($aTranscoders) || !is_array($aTranscoders))
  168. return $sResult;
  169. foreach($aTranscoders as $sTranscoder) {
  170. if(empty($this->CNF[$sTranscoder]))
  171. continue;
  172. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->CNF[$sTranscoder]);
  173. if(!$oTranscoder)
  174. continue;
  175. $sResult = $oTranscoder->getFileUrl($iId);
  176. if(!empty($sResult))
  177. break;
  178. }
  179. return $sResult;
  180. }
  181. public function getDpnTime()
  182. {
  183. return $this->_iDpnTime;
  184. }
  185. }
  186. /** @} */