BxAdsFormEntry.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 Ads Ads
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Create/Edit entry form
  13. */
  14. class BxAdsFormEntry extends BxBaseModTextFormEntry
  15. {
  16. protected $_sGhostTemplateCover = 'form_ghost_template_cover.html';
  17. public function __construct($aInfo, $oTemplate = false)
  18. {
  19. $this->MODULE = 'bx_ads';
  20. parent::__construct($aInfo, $oTemplate);
  21. $CNF = &$this->_oModule->_oConfig->CNF;
  22. $iCategory = 0;
  23. if(bx_get('category') !== false)
  24. $iCategory = (int)bx_get('category');
  25. $this->_initCategoryFields($iCategory);
  26. if(isset($CNF['FIELD_COVER']) && isset($this->aInputs[$CNF['FIELD_COVER']])) {
  27. if($this->_oModule->checkAllowedSetThumb() === CHECK_ACTION_RESULT_ALLOWED) {
  28. $this->aInputs[$CNF['FIELD_COVER']]['storage_object'] = $CNF['OBJECT_STORAGE'];
  29. $this->aInputs[$CNF['FIELD_COVER']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_COVER']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_COVER']]['value']) : $CNF['OBJECT_UPLOADERS'];
  30. $this->aInputs[$CNF['FIELD_COVER']]['upload_buttons_titles'] = array(
  31. 'Simple' => _t('_bx_ads_form_entry_input_covers_uploader_simple_title'),
  32. 'HTML5' => _t('_bx_ads_form_entry_input_covers_uploader_html5_title')
  33. );
  34. $this->aInputs[$CNF['FIELD_COVER']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW'];
  35. $this->aInputs[$CNF['FIELD_COVER']]['storage_private'] = 0;
  36. $this->aInputs[$CNF['FIELD_COVER']]['multiple'] = false;
  37. $this->aInputs[$CNF['FIELD_COVER']]['content_id'] = 0;
  38. $this->aInputs[$CNF['FIELD_COVER']]['ghost_template'] = '';
  39. }
  40. else
  41. unset($this->aInputs[$CNF['FIELD_COVER']]);
  42. }
  43. if(isset($CNF['FIELD_PHOTO']) && isset($this->aInputs[$CNF['FIELD_PHOTO']])) {
  44. $this->aInputs[$CNF['FIELD_PHOTO']]['storage_object'] = $CNF['OBJECT_STORAGE_PHOTOS'];
  45. $this->aInputs[$CNF['FIELD_PHOTO']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_PHOTO']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_PHOTO']]['value']) : $CNF['OBJECT_UPLOADERS'];
  46. $this->aInputs[$CNF['FIELD_PHOTO']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS'];
  47. $this->aInputs[$CNF['FIELD_PHOTO']]['storage_private'] = 0;
  48. $this->aInputs[$CNF['FIELD_PHOTO']]['multiple'] = true;
  49. $this->aInputs[$CNF['FIELD_PHOTO']]['content_id'] = 0;
  50. $this->aInputs[$CNF['FIELD_PHOTO']]['ghost_template'] = '';
  51. $this->aInputs[$CNF['FIELD_PHOTO']]['tr_attrs'] = array('class'=> 'bx-base-text-attachment-item');
  52. }
  53. if(isset($this->aInputs[$CNF['FIELD_VIDEO']])) {
  54. $this->aInputs[$CNF['FIELD_VIDEO']]['storage_object'] = $CNF['OBJECT_STORAGE_VIDEOS'];
  55. $this->aInputs[$CNF['FIELD_VIDEO']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_VIDEO']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_VIDEO']]['value']) : $CNF['OBJECT_UPLOADERS'];
  56. $this->aInputs[$CNF['FIELD_VIDEO']]['images_transcoder'] = $CNF['OBJECT_VIDEOS_TRANSCODERS']['poster_preview'];
  57. $this->aInputs[$CNF['FIELD_VIDEO']]['storage_private'] = 0;
  58. $this->aInputs[$CNF['FIELD_VIDEO']]['multiple'] = true;
  59. $this->aInputs[$CNF['FIELD_VIDEO']]['content_id'] = 0;
  60. $this->aInputs[$CNF['FIELD_VIDEO']]['ghost_template'] = '';
  61. $this->aInputs[$CNF['FIELD_VIDEO']]['tr_attrs'] = array('class'=> 'bx-base-text-attachment-item');
  62. }
  63. if (isset($CNF['FIELD_FILE']) && isset($this->aInputs[$CNF['FIELD_FILE']])) {
  64. $this->aInputs[$CNF['FIELD_FILE']]['storage_object'] = $CNF['OBJECT_STORAGE_FILES'];
  65. $this->aInputs[$CNF['FIELD_FILE']]['uploaders'] = !empty($this->aInputs[$CNF['FIELD_FILE']]['value']) ? unserialize($this->aInputs[$CNF['FIELD_FILE']]['value']) : $CNF['OBJECT_UPLOADERS'];
  66. $this->aInputs[$CNF['FIELD_FILE']]['images_transcoder'] = $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES'];
  67. $this->aInputs[$CNF['FIELD_FILE']]['storage_private'] = 0;
  68. $this->aInputs[$CNF['FIELD_FILE']]['multiple'] = true;
  69. $this->aInputs[$CNF['FIELD_FILE']]['content_id'] = 0;
  70. $this->aInputs[$CNF['FIELD_FILE']]['ghost_template'] = '';
  71. $this->aInputs[$CNF['FIELD_FILE']]['tr_attrs'] = array('class'=> 'bx-base-text-attachment-item');
  72. }
  73. if(isset($this->aInputs[$CNF['FIELD_POLL']])) {
  74. $this->aInputs[$CNF['FIELD_POLL']]['tr_attrs'] = array('class'=> 'bx-base-text-attachment-item');
  75. }
  76. }
  77. function getCode($bDynamicMode = false)
  78. {
  79. $this->_oModule->_oTemplate->addJs('entry.js');
  80. return $this->_oModule->_oTemplate->getJsCode('entry') . parent::getCode($bDynamicMode);
  81. }
  82. function initChecker ($aValues = array (), $aSpecificValues = array())
  83. {
  84. $CNF = &$this->_oModule->_oConfig->CNF;
  85. $bValues = $aValues && !empty($aValues['id']);
  86. $aContentInfo = $bValues ? $this->_oModule->_oDb->getContentInfoById($aValues['id']) : false;
  87. $this->_initCategoryFields($aContentInfo[$CNF['FIELD_CATEGORY']]);
  88. if(isset($CNF['FIELD_COVER']) && isset($this->aInputs[$CNF['FIELD_COVER']])) {
  89. if($bValues)
  90. $this->aInputs[$CNF['FIELD_COVER']]['content_id'] = $aValues['id'];
  91. $this->aInputs[$CNF['FIELD_COVER']]['ghost_template'] = $this->_oModule->_oTemplate->parseHtmlByName($this->_sGhostTemplateCover, $this->_getCoverGhostTmplVars($aContentInfo));
  92. }
  93. parent::initChecker ($aValues, $aSpecificValues);
  94. }
  95. public function insert ($aValsToAdd = array(), $isIgnore = false)
  96. {
  97. $CNF = &$this->_oModule->_oConfig->CNF;
  98. $iContentId = parent::insert ($aValsToAdd, $isIgnore);
  99. if(!empty($iContentId))
  100. $this->processFiles($CNF['FIELD_COVER'], $iContentId, true);
  101. return $iContentId;
  102. }
  103. public function update ($iContentId, $aValsToAdd = array(), &$aTrackTextFieldsChanges = null)
  104. {
  105. $CNF = &$this->_oModule->_oConfig->CNF;
  106. $iResult = parent::update ($iContentId, $aValsToAdd, $aTrackTextFieldsChanges);
  107. $this->processFiles($CNF['FIELD_COVER'], $iContentId, false);
  108. return $iResult;
  109. }
  110. protected function genCustomInputCategoryView(&$aInput)
  111. {
  112. $CNF = &$this->_oModule->_oConfig->CNF;
  113. if(!empty($aInput['value'])) {
  114. $aCategory = $this->_oModule->_oDb->getCategories(array('type' => 'id', 'id' => (int)$aInput['value']));
  115. if(!empty($aCategory) && is_array($aCategory))
  116. $aInput['value'] = bx_process_output(_t($aCategory['title']));
  117. }
  118. return $this->genInputStandard($aInput);
  119. }
  120. protected function genCustomViewRowValueCategoryView(&$aInput)
  121. {
  122. $CNF = &$this->_oModule->_oConfig->CNF;
  123. if(empty($aInput['value']))
  124. return '';
  125. $aCategory = $this->_oModule->_oDb->getCategories(array('type' => 'id', 'id' => $aInput['value']));
  126. if(empty($aCategory) || !is_array($aCategory))
  127. return '';
  128. $sLink = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_CATEGORIES'], array($CNF['GET_PARAM_CATEGORY'] => $aCategory['id']));
  129. return $this->_oModule->_oTemplate->parseLink($sLink, bx_process_output(_t($aCategory['title'])));
  130. }
  131. protected function _getCoverGhostTmplVars($aContentInfo = array())
  132. {
  133. $CNF = &$this->_oModule->_oConfig->CNF;
  134. return array (
  135. 'name' => $this->aInputs[$CNF['FIELD_COVER']]['name'],
  136. 'content_id' => $this->aInputs[$CNF['FIELD_COVER']]['content_id'],
  137. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : '',
  138. 'thumb_id' => isset($CNF['FIELD_THUMB']) && isset($aContentInfo[$CNF['FIELD_THUMB']]) ? $aContentInfo[$CNF['FIELD_THUMB']] : 0,
  139. 'name_thumb' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : ''
  140. );
  141. }
  142. protected function _getPhotoGhostTmplVars($aContentInfo = array())
  143. {
  144. $CNF = &$this->_oModule->_oConfig->CNF;
  145. return array (
  146. 'name' => $this->aInputs[$CNF['FIELD_PHOTO']]['name'],
  147. 'content_id' => (int)$this->aInputs[$CNF['FIELD_PHOTO']]['content_id'],
  148. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : ''
  149. );
  150. }
  151. protected function _initCategoryFields($iCategory)
  152. {
  153. $CNF = &$this->_oModule->_oConfig->CNF;
  154. if(isset($CNF['FIELD_CATEGORY']) && isset($this->aInputs[$CNF['FIELD_CATEGORY']]) && $iCategory != 0) {
  155. $this->aInputs[$CNF['FIELD_CATEGORY']]['value'] = $iCategory;
  156. }
  157. if(isset($CNF['FIELD_CATEGORY_VIEW']) && isset($this->aInputs[$CNF['FIELD_CATEGORY_VIEW']]) && $iCategory != 0) {
  158. $this->aInputs[$CNF['FIELD_CATEGORY_VIEW']]['value'] = $iCategory;
  159. }
  160. if(isset($CNF['FIELD_CATEGORY_SELECT']) && isset($this->aInputs[$CNF['FIELD_CATEGORY_SELECT']])) {
  161. $this->aInputs[$CNF['FIELD_CATEGORY_SELECT']]['values'] = $this->_oModule->serviceGetCategoryOptions(0, true);
  162. }
  163. }
  164. }
  165. /** @} */