1
0

BxBaseModGeneralConfig.php 7.1 KB

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