1
0

BxBaseModGeneralConfig.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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 getApiFormType()
  106. {
  107. return 'content';
  108. }
  109. public function getPrefix($sType = '')
  110. {
  111. if(empty($sType))
  112. return $this->_aPrefixes;
  113. return isset($this->_aPrefixes[$sType]) ? $this->_aPrefixes[$sType] : '';
  114. }
  115. public function getJsClass($sType)
  116. {
  117. return isset($this->_aJsClasses[$sType]) ? $this->_aJsClasses[$sType] : '';
  118. }
  119. public function getJsObject($sType)
  120. {
  121. return isset($this->_aJsObjects[$sType]) ? $this->_aJsObjects[$sType] : '';
  122. }
  123. public function getJsObjectPoll($iId = 0)
  124. {
  125. if(($sJsObject = $this->getJsObject('poll')) !== '')
  126. return $sJsObject .= (int)$iId == 0 ? 'Add' : 'Edit' . $iId;
  127. return '';
  128. }
  129. public function getGridObject($sType)
  130. {
  131. return isset($this->_aGridObjects[$sType]) ? $this->_aGridObjects[$sType] : '';
  132. }
  133. /**
  134. * Is Auto Approve mode is available.
  135. */
  136. public function isAutoApprove()
  137. {
  138. return !empty($this->CNF['FIELD_STATUS_ADMIN']) && !empty($this->CNF['PARAM_AUTO_APPROVE']);
  139. }
  140. public function isAutoApproveEnabled()
  141. {
  142. return !$this->isAutoApprove() || getParam($this->CNF['PARAM_AUTO_APPROVE']) == 'on';
  143. }
  144. public function isEqualUrls($sUrl1, $sUrl2)
  145. {
  146. $sUrl1 = trim($sUrl1, "/");
  147. $sUrl2 = trim($sUrl2, "/");
  148. return strncmp($sUrl1, $sUrl2, strlen($sUrl1)) === 0;
  149. }
  150. public function getViewEntryUrl($mixedData)
  151. {
  152. if(!isset($this->CNF['URI_VIEW_ENTRY']))
  153. return '';
  154. $iId = 0;
  155. if(is_numeric($mixedData))
  156. $iId = (int)$mixedData;
  157. else if(is_array($mixedData) && isset($this->CNF['FIELD_ID'], $mixedData[$this->CNF['FIELD_ID']]))
  158. $iId = (int)$mixedData[$this->CNF['FIELD_ID']];
  159. else
  160. return '';
  161. return bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $this->CNF['URI_VIEW_ENTRY'] . '&id=' . $iId));
  162. }
  163. public function getEntryUri($sAction)
  164. {
  165. $sUri = '';
  166. if(($sKeyUri = 'URI_' . strtoupper($sAction) . '_ENTRY') && !empty($this->CNF[$sKeyUri]))
  167. $sUri = $this->CNF[$sKeyUri];
  168. if(!$sUri && $sAction == 'add' && ($sKeyUri = 'URI_EDIT_ENTRY') && !empty($this->CNF[$sKeyUri]))
  169. $sUri = str_replace('edit', 'create', $this->CNF[$sKeyUri]);
  170. return $sUri;
  171. }
  172. /*
  173. * Note. The first Transcoder in the array $aTranscoders has the highest priority.
  174. */
  175. public function getImageUrl($iId, $aTranscoders)
  176. {
  177. $sResult = '';
  178. if(empty($iId) || empty($aTranscoders) || !is_array($aTranscoders))
  179. return $sResult;
  180. foreach($aTranscoders as $sTranscoder) {
  181. if(empty($this->CNF[$sTranscoder]))
  182. continue;
  183. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->CNF[$sTranscoder]);
  184. if(!$oTranscoder)
  185. continue;
  186. $sResult = $oTranscoder->getFileUrl($iId);
  187. if(!empty($sResult))
  188. break;
  189. }
  190. return $sResult;
  191. }
  192. public function getDpnTime()
  193. {
  194. return $this->_iDpnTime;
  195. }
  196. }
  197. /** @} */