BxMarketTemplate.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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 Market Market
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /*
  12. * Module representation.
  13. */
  14. class BxMarketTemplate extends BxBaseModTextTemplate
  15. {
  16. public function __construct(&$oConfig, &$oDb)
  17. {
  18. $this->MODULE = 'bx_market';
  19. parent::__construct($oConfig, $oDb);
  20. }
  21. public function entryRating($aData)
  22. {
  23. $CNF = &$this->getModule()->_oConfig->CNF;
  24. $sVotes = '';
  25. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aData['id']);
  26. if($oVotes) {
  27. $sVotes = $oVotes->getElementBlock(array('show_counter' => true, 'show_legend' => true));
  28. if(!empty($sVotes))
  29. $sVotes = $this->parseHtmlByName('entry-rating.html', array(
  30. 'content' => $sVotes,
  31. ));
  32. }
  33. return $sVotes;
  34. }
  35. public function getTmplVarsText($aData)
  36. {
  37. $oModule = $this->getModule();
  38. $CNF = &$oModule->_oConfig->CNF;
  39. $aVars = parent::getTmplVarsText($aData);
  40. $bIcon = getParam($CNF['PARAM_USE_ICON']) == 'on';
  41. if($this->_bIsApi) {
  42. if($bIcon)
  43. $aVars['icon'] = bx_api_get_image($CNF['OBJECT_STORAGE'], (int)$aData[$CNF['FIELD_THUMB']]);
  44. return $aVars;
  45. }
  46. //--- Process RAW Cover
  47. $bCoverRaw = !empty($CNF['FIELD_COVER_RAW']) && !empty($aData[$CNF['FIELD_COVER_RAW']]);
  48. $aVars['bx_if:show_image_raw'] = [
  49. 'condition' => $bCoverRaw,
  50. 'content' => [
  51. 'image_raw' => $aData[$CNF['FIELD_COVER_RAW']]
  52. ]
  53. ];
  54. //--- Process Cover
  55. $bIsAllowEditCover = $oModule->checkAllowedEdit($aData) === CHECK_ACTION_RESULT_ALLOWED && $oModule->checkAllowedSetCover() === CHECK_ACTION_RESULT_ALLOWED;
  56. $bShowImage = $aVars['bx_if:show_image']['condition'];
  57. $aVars['bx_if:show_entry_cover'] = [
  58. 'condition' => !$bCoverRaw && ($bShowImage || $bIsAllowEditCover),
  59. 'content' => array_merge([
  60. 'bx_if:show_image' => [
  61. 'condition' => $bShowImage,
  62. 'content' => [true]
  63. ],
  64. 'bx_if:show_image_empty' => [
  65. 'condition' => !$bShowImage,
  66. 'content' => [true]
  67. ]
  68. ], $aVars['bx_if:show_image']['content'])
  69. ];
  70. //--- Process Icon (Thumb)
  71. $bIsAllowEditIcon = $bIsAllowEditCover;
  72. $sIcon = '';
  73. if($bIcon) {
  74. $mixedIcon = $oModule->getEntryImageData($aData, 'FIELD_THUMB', ['OBJECT_IMAGES_TRANSCODER_THUMB', 'OBJECT_IMAGES_TRANSCODER_GALLERY']);
  75. if($mixedIcon !== false) {
  76. if(!empty($mixedIcon['object']))
  77. $o = BxDolStorage::getObjectInstance($mixedIcon['object']);
  78. else if(!empty($mixedIcon['transcoder']))
  79. $o = BxDolTranscoder::getObjectInstance($mixedIcon['transcoder']);
  80. if($o)
  81. $sIcon = $o->getFileUrlById($mixedIcon['id']);
  82. }
  83. }
  84. $sIconUniqId = genRndPwd(8, false);
  85. $sIconTweak = '';
  86. if($bIsAllowEditIcon)
  87. $sIconTweak = $this->_prepareImage($aData, $sIconUniqId, $CNF['OBJECT_UPLOADERS'], $CNF['OBJECT_STORAGE'], $CNF['FIELD_THUMB'], false);
  88. $aVars = array_merge($aVars, [
  89. 'bx_if:show_entry_icon' => [
  90. 'condition' => $bIcon,
  91. 'content' => [
  92. 'bx_if:show_icon' => [
  93. 'condition' => !empty($sIcon),
  94. 'content' => [true]
  95. ],
  96. 'bx_if:show_icon_empty' => [
  97. 'condition' => empty($sIcon),
  98. 'content' => [true]
  99. ],
  100. 'unique_id' => $sIconUniqId,
  101. 'entry_icon' => $sIcon,
  102. 'icon' => $CNF['ICON'],
  103. 'icon_tweak' => $sIconTweak
  104. ]
  105. ]
  106. ]);
  107. //--- Process Screenshots
  108. $sScreenshots = $this->getScreenshots($aData);
  109. $bScreenshots = !empty($sScreenshots);
  110. if($bScreenshots) {
  111. $this->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flickity/|flickity.css');
  112. $this->addJs('flickity/flickity.pkgd.min.js');
  113. }
  114. $aVars['bx_if:show_screenshots'] = array(
  115. 'condition' => $bScreenshots,
  116. 'content' => array(
  117. 'screenshots' => $sScreenshots
  118. )
  119. );
  120. return $aVars;
  121. }
  122. public function getScreenshots($aData)
  123. {
  124. $oModule = $this->getModule();
  125. $CNF = &$oModule->_oConfig->CNF;
  126. $aPhotos = $oModule->serviceGetScreenshots($aData[$CNF['FIELD_ID']]);
  127. if (bx_is_api()){
  128. return $aPhotos;
  129. }
  130. if(empty($aPhotos) || !is_array($aPhotos))
  131. return '';
  132. return $this->parseHtmlByName('entry-screenshots.html', array(
  133. 'bx_repeat:items' => $aPhotos
  134. ));
  135. }
  136. public function getAuthorAddon ($aData, $oProfile)
  137. {
  138. $aAccount = $oProfile->getAccountObject()->getInfo();
  139. $sContent = $this->parseHtmlByName('entry-author.html', array(
  140. 'joined' => bx_time_js($aAccount['added']),
  141. 'last_active' => bx_time_js($aAccount['logged']),
  142. 'installs' => '?',
  143. ));
  144. return $sContent . parent::getAuthorAddon ($aData, $oProfile);
  145. }
  146. public function getGhostTemplateFileOptions($sField, $aFile, $aVersions)
  147. {
  148. $bField = !empty($aFile) && is_array($aFile) && isset($aFile[$sField]);
  149. $aTmplVarsVersions = array();
  150. foreach ($aVersions as $aVersion) {
  151. if($aVersion['type'] != 'version' || empty($aVersion['version']))
  152. continue;
  153. $aTmplVarsVersions[] = array(
  154. 'value' => $aVersion['version'],
  155. 'title' => $aVersion['version'],
  156. 'bx_if:selected' => array(
  157. 'condition' => $bField && $aFile[$sField] == $aVersion['version'],
  158. 'content' => array()
  159. )
  160. );
  161. }
  162. return $this->parseHtmlByName('form_ghost_template_file_options.html', array(
  163. 'bx_repeat:versions' => $aTmplVarsVersions
  164. ));
  165. }
  166. protected function getUnit ($aData, $aParams = [])
  167. {
  168. $bTmplVarsSectionAuthor = true;
  169. $bTmplVarsSectionPricing = false;
  170. $bTmplVarsSectionVoting = true;
  171. $oModule = $this->getModule();
  172. $CNF = &$oModule->_oConfig->CNF;
  173. $aUnit = parent::getUnit($aData, $aParams);
  174. $oPayment = BxDolPayments::getInstance();
  175. $oPermalinks = BxDolPermalinks::getInstance();
  176. $bEmbed = isset($aParams['embed']) && $aParams['embed'] === true;
  177. $iAuthorId = (int)$aData[$CNF['FIELD_AUTHOR']];
  178. list($sAuthorName, $sAuthorUrl, $sAuthorIcon, $sAuthorUnit, $sAuthorUnitShort) = $oModule->getUserInfo($iAuthorId);
  179. $sAuthorCurrencySign = $oPayment->getCurrencySign($iAuthorId);
  180. $aTmplVarsSectionAuthor = array();
  181. if($bTmplVarsSectionAuthor) {
  182. //--- Author Info
  183. $bAuthorIcon = !empty($sAuthorIcon);
  184. $sAuthorName = $this->parseHtmlByName('author_link.html', array(
  185. 'href' => $sAuthorUrl,
  186. 'title' => bx_html_attribute($sAuthorName),
  187. 'content' => $sAuthorName,
  188. 'bx_if:show_account' => array(
  189. 'condition' => false,
  190. 'content' => array()
  191. )
  192. ));
  193. //--- Actions
  194. $sActions = '';
  195. if(!$bEmbed && ($oActions = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_ACTIONS_SNIPPET'])) !== false) {
  196. $oActions->setContentId($aData[$CNF['FIELD_ID']]);
  197. $sActions = $oActions->getCode();
  198. }
  199. $sDate = $this->parseHtmlByName('snippet-date.html', array(
  200. 'date' => bx_time_js($aData[$CNF['FIELD_ADDED']])
  201. ));
  202. $aTmplVarsSectionAuthor = array(
  203. 'actions' => $sActions,
  204. 'author_unit' => $sAuthorUnitShort,
  205. 'author_width_date' => _t('_bx_market_txt_author_added_product', $sAuthorName, $sDate),
  206. );
  207. }
  208. //--- Main Info
  209. $sUrl = bx_absolute_url($oPermalinks->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]));
  210. $sLinkMore = ' <a title="' . bx_html_attribute(_t('_sys_read_more', $aData[$CNF['FIELD_TITLE']])) . '" href="' . $sUrl . '"><i class="sys-icon ellipsis-h"></i></a>';
  211. $sSummary = strmaxtextlen($aData[$CNF['FIELD_TEXT']], (int)getParam($CNF['PARAM_CHARS_SUMMARY']), $sLinkMore);
  212. $sSummaryPlain = BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($sSummary), (int)getParam($CNF['PARAM_CHARS_SUMMARY_PLAIN']));
  213. //--- Icon Info
  214. $sIconUrl = '';
  215. $bIcon = getParam($CNF['PARAM_USE_ICON']) == 'on';
  216. if($bIcon && !empty($CNF['FIELD_THUMB']) && $aData[$CNF['FIELD_THUMB']]) {
  217. $iThumb = (int)$aData[$CNF['FIELD_THUMB']];
  218. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  219. $aThumb = $oStorage->getFile($iThumb);
  220. if(!empty($aThumb) && is_array($aThumb)) {
  221. if(strpos($aThumb['mime_type'], 'svg') !== false)
  222. $sIconUrl = $oStorage->getFileUrlById($iThumb);
  223. if(empty($sIconUrl) && ($oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_ICON'])) !== false)
  224. $sIconUrl = $oImagesTranscoder->getFileUrl($iThumb);
  225. if(empty($sIconUrl) && ($oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_THUMB'])) !== false)
  226. $sIconUrl = $oImagesTranscoder->getFileUrl($iThumb);
  227. }
  228. }
  229. //--- Cover Info
  230. $bCoverRaw = !empty($CNF['FIELD_COVER_RAW']) && !empty($aData[$CNF['FIELD_COVER_RAW']]);
  231. $sCoverUrl = '';
  232. if(!$bCoverRaw && !empty($CNF['FIELD_COVER']) && $aData[$CNF['FIELD_COVER']]) {
  233. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  234. if($oImagesTranscoder)
  235. $sCoverUrl = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_COVER']]);
  236. if(empty($sCoverUrl)) {
  237. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_COVER']);
  238. if($oImagesTranscoder)
  239. $sCoverUrl = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_COVER']]);
  240. }
  241. }
  242. $aTmplVarsSectionPricing = array();
  243. if($bTmplVarsSectionPricing) {
  244. //--- Price Single
  245. $bTmplVarsSingle = (float)$aData[$CNF['FIELD_PRICE_SINGLE']] != 0;
  246. $aTmplVarsSingle = array();
  247. if($bTmplVarsSingle) {
  248. $aJsSingle = $oPayment->getAddToCartJs($iAuthorId, $this->_oConfig->getName(), $aData[$CNF['FIELD_ID']], 1, true);
  249. if(!empty($aJsSingle) && is_array($aJsSingle)) {
  250. list($sJsCode, $sSingleOnclick) = $aJsSingle;
  251. $aTmplVarsSingle = array(
  252. 'price_single_onclick' => $sSingleOnclick,
  253. 'price_single' => _t('_bx_market_txt_price_single', $sAuthorCurrencySign, $aData[$CNF['FIELD_PRICE_SINGLE']])
  254. );
  255. }
  256. else
  257. $bTmplVarsSingle = false;
  258. }
  259. //--- Price Recurring
  260. $bTmplVarsRecurring = !$oPayment->isCreditsOnly() && (float)$aData[$CNF['FIELD_PRICE_RECURRING']] != 0;
  261. $aTmplVarsRecurring = array();
  262. if($bTmplVarsRecurring) {
  263. $aJsRecurring = $oPayment->getSubscribeJs($iAuthorId, '', $this->_oConfig->getName(), $aData[$CNF['FIELD_ID']], 1);
  264. if(!empty($aJsRecurring) && is_array($aJsRecurring)) {
  265. list($sJsCode, $sRecurringOnclick) = $aJsRecurring;
  266. $aTmplVarsRecurring = array(
  267. 'price_recurring_onclick' => $sRecurringOnclick,
  268. 'price_recurring' => _t('_bx_market_txt_price_recurring', $sAuthorCurrencySign, $aData[$CNF['FIELD_PRICE_RECURRING']], _t($CNF['T']['txt_per_' . $aData[$CNF['FIELD_DURATION_RECURRING']] . '_short']))
  269. );
  270. }
  271. else
  272. $bTmplVarsRecurring = false;
  273. }
  274. $aTmplVarsSectionPricing = array(
  275. 'bx_if:show_single' => array(
  276. 'condition' => $bTmplVarsSingle,
  277. 'content' => $aTmplVarsSingle
  278. ),
  279. 'bx_if:show_recurring' => array(
  280. 'condition' => $bTmplVarsRecurring,
  281. 'content' => $aTmplVarsRecurring
  282. ),
  283. 'bx_if:show_free' => array(
  284. 'condition' => !$bTmplVarsSingle && !$bTmplVarsRecurring,
  285. 'content' => array(
  286. 'price_free_href' => $oPermalinks->permalink('page.php?i=' . $CNF['URI_DOWNLOAD_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']])
  287. )
  288. )
  289. );
  290. }
  291. $aTmplVarsSectionVoting = array();
  292. if($bTmplVarsSectionVoting) {
  293. $sVoting = '';
  294. if(($oVoting = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $aData[$CNF['FIELD_ID']])) !== false)
  295. $sVoting = $oVoting->getElementBlock([
  296. 'show_counter' => false,
  297. 'read_only' => $bEmbed
  298. ]);
  299. $sPricing = "";
  300. if((float)$aData[$CNF['FIELD_PRICE_RECURRING']] != 0) {
  301. $sDuration = 'txt_per_' . $aData[$CNF['FIELD_DURATION_RECURRING']] . '_short';
  302. $sDuration = _t(!empty($CNF['T'][$sDuration]) ? $CNF['T'][$sDuration] : '_bx_market_txt_per_' . $aData[$CNF['FIELD_DURATION_RECURRING']] . '_short');
  303. $sPricing = _t('_bx_market_txt_price_recurring_short', $sAuthorCurrencySign, $aData[$CNF['FIELD_PRICE_RECURRING']], $sDuration);
  304. }
  305. if(empty($sPricing) && (float)$aData[$CNF['FIELD_PRICE_SINGLE']] != 0)
  306. $sPricing = _t('_bx_market_txt_price_single_short', $sAuthorCurrencySign, $aData[$CNF['FIELD_PRICE_SINGLE']]);
  307. if(empty($sPricing))
  308. $sPricing = _t('_bx_market_txt_price_free');
  309. $aTmplVarsSectionVoting = array(
  310. 'voting' => $sVoting,
  311. 'pricing' => $sPricing
  312. );
  313. }
  314. $aUnit = array_merge($aUnit, array(
  315. 'bx_if:show_section_author' => array(
  316. 'condition' => $bTmplVarsSectionAuthor,
  317. 'content' => $aTmplVarsSectionAuthor
  318. ),
  319. 'bx_if:show_icon' => array (
  320. 'condition' => $sIconUrl,
  321. 'content' => array(
  322. 'content_url' => $sUrl,
  323. 'icon_url' => $sIconUrl,
  324. ),
  325. ),
  326. 'bx_if:show_icon_empty' => array (
  327. 'condition' => $bIcon && !$sIconUrl,
  328. 'content' => array(
  329. 'content_url' => $sUrl,
  330. 'icon' => $CNF['ICON']
  331. ),
  332. ),
  333. 'bx_if:show_cover_raw' => array (
  334. 'condition' => $bCoverRaw,
  335. 'content' => array (
  336. 'summary_attr' => bx_html_attribute($sSummaryPlain),
  337. 'content_url' => $sUrl,
  338. 'cover_raw' => $aData[$CNF['FIELD_COVER_RAW']],
  339. ),
  340. ),
  341. 'bx_if:show_cover' => array (
  342. 'condition' => $sCoverUrl,
  343. 'content' => array (
  344. 'summary_attr' => bx_html_attribute($sSummaryPlain),
  345. 'content_url' => $sUrl,
  346. 'cover_url' => $sCoverUrl,
  347. 'strecher' => str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', 40),
  348. ),
  349. ),
  350. 'bx_if:show_cover_empty' => array (
  351. 'condition' => !$bCoverRaw && !$sCoverUrl,
  352. 'content' => array (
  353. 'summary_plain' => $sSummaryPlain,
  354. 'strecher' => mb_strlen($sSummaryPlain) > 240 ? '' : str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', round((240 - mb_strlen($sSummaryPlain)) / 6)),
  355. ),
  356. ),
  357. 'author_name' => $sAuthorName,
  358. 'content_url' => $sUrl,
  359. 'bx_if:show_section_pricing' => array(
  360. 'condition' => $bTmplVarsSectionPricing,
  361. 'content' => $aTmplVarsSectionPricing
  362. ),
  363. 'bx_if:show_section_voting' => array(
  364. 'condition' => $bTmplVarsSectionVoting,
  365. 'content' => $aTmplVarsSectionVoting
  366. )
  367. ));
  368. return $aUnit;
  369. }
  370. protected function getAttachments($sStorage, $aData, $aParams = array())
  371. {
  372. $mixedAttachments = parent::getAttachments($sStorage, $aData, $aParams);
  373. if(empty($mixedAttachments) || !is_array($mixedAttachments))
  374. return $mixedAttachments;
  375. $aAttachments = [];
  376. foreach($mixedAttachments as $aAttachment)
  377. $aAttachments[(int)$aAttachment['id']] = $aAttachment;
  378. $aFiles = $this->_oDb->getFile(['type' => 'content_id_key_file_id', 'content_id' => $aData['id']]);
  379. $aResults = [];
  380. $sCaptionType = "";
  381. foreach($aFiles as $iAttachmentId => $aFile) {
  382. $aAttachments[$iAttachmentId]['class'] = (int)$aData['package'] == $iAttachmentId ? ' bx-market-attachment-main' : '';
  383. $aAttachments[$iAttachmentId]['bx_if:main'] = [
  384. 'condition' => (int)$aData['package'] == $iAttachmentId,
  385. 'content' => []
  386. ];
  387. $bSeparatorNeeded = false;
  388. if ($aFiles[$iAttachmentId]['type'] != $sCaptionType){
  389. $bSeparatorNeeded = true;
  390. $sCaptionType = $aFiles[$iAttachmentId]['type'];
  391. }
  392. if ((int)$aData['package'] == $iAttachmentId){
  393. $bSeparatorNeeded = true;
  394. $sCaptionType = 'latest';
  395. }
  396. $bAttachment = !empty($aFiles[$iAttachmentId]);
  397. $aAttachments[$iAttachmentId]['bx_if:not_image']['content'] = array_merge($aAttachments[$iAttachmentId]['bx_if:not_image']['content'], [
  398. 'file_type' => $bAttachment ? _t('_bx_market_form_entry_input_files_type_' . $aFiles[$iAttachmentId]['type']) : '',
  399. 'file_name_attr' => bx_html_attribute($aAttachments[$iAttachmentId]['file_name']),
  400. 'bx_if:show_version' => [
  401. 'condition' => $bAttachment && $aFiles[$iAttachmentId]['type'] == BX_MARKET_FILE_TYPE_VERSION,
  402. 'content' => [
  403. 'file_version' => $bAttachment ? $aFiles[$iAttachmentId]['version'] : ''
  404. ]
  405. ],
  406. 'bx_if:show_update' => [
  407. 'condition' => $bAttachment && $aFiles[$iAttachmentId]['type'] == BX_MARKET_FILE_TYPE_UPDATE,
  408. 'content' => [
  409. 'file_version_from_to' => $bAttachment ? _t('_bx_market_form_entry_input_files_version_from_x_to_y', $aFiles[$iAttachmentId]['version'], $aFiles[$iAttachmentId]['version_to']) : ''
  410. ]
  411. ]
  412. ]);
  413. $aAttachments[$iAttachmentId]['bx_if:show_separator'] = [
  414. 'condition' => $bSeparatorNeeded,
  415. 'content' => [
  416. 'type' => _t('_bx_market_form_entry_input_files_version_caption_' . $sCaptionType)
  417. ]
  418. ];
  419. $aFiles[$iAttachmentId] = $aAttachments[$iAttachmentId];
  420. $aResults[$iAttachmentId] = $aAttachments[$iAttachmentId];
  421. }
  422. return array_intersect_key($aFiles, $aResults);
  423. }
  424. protected function getAttachmentsImagesTranscoders ($sStorage = '')
  425. {
  426. $CNF = &$this->getModule()->_oConfig->CNF;
  427. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  428. $oTranscoderPreview = isset($CNF['OBJECT_IMAGES_TRANSCODER_PICTURE']) && $CNF['OBJECT_IMAGES_TRANSCODER_PICTURE'] ? BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PICTURE']) : null;
  429. return array($oTranscoder, $oTranscoderPreview);
  430. }
  431. protected function _getHeaderImageParams()
  432. {
  433. $CNF = &$this->_oConfig->CNF;
  434. return array_merge(parent::_getHeaderImageParams(), [
  435. 'field' => isset($CNF['FIELD_COVER']) ? $CNF['FIELD_COVER'] : false,
  436. 'field_position' => isset($CNF['FIELD_COVER_POSITION']) ? $CNF['FIELD_COVER_POSITION'] : false,
  437. ]);
  438. }
  439. protected function _getHeaderImage($aData)
  440. {
  441. return $this->getModule()->getEntryImageData($aData, 'FIELD_COVER');
  442. }
  443. protected function _getImagesEditApi($aData)
  444. {
  445. $oModule = $this->getModule();
  446. $CNF = &$oModule->_oConfig->CNF;
  447. // The same rule as for Header Image and Icon uploaders on the site's view product page.
  448. if($oModule->checkAllowedEdit($aData) !== CHECK_ACTION_RESULT_ALLOWED || $oModule->checkAllowedSetCover() !== CHECK_ACTION_RESULT_ALLOWED)
  449. return [];
  450. $aResult = [
  451. 'cover' => $this->_getImageEditApi($CNF['FIELD_COVER']),
  452. ];
  453. if(getParam($CNF['PARAM_USE_ICON']) == 'on')
  454. $aResult['picture'] = $this->_getImageEditApi($CNF['FIELD_THUMB']);
  455. return $aResult;
  456. }
  457. function _prepareImage($aData, $sUniqId, $sUploader, $sStorage, $sField, $bAllowTweak, $bAllowMultiple = false)
  458. {
  459. $CNF = &$this->_oConfig->CNF;
  460. if(in_array($sField, [$CNF['FIELD_THUMB'], $CNF['FIELD_COVER']]))
  461. $bAllowMultiple = true;
  462. return parent::_prepareImage($aData, $sUniqId, $sUploader, $sStorage, $sField, $bAllowTweak, $bAllowMultiple);
  463. }
  464. public function entryAttachments ($aData, $aParams = [])
  465. {
  466. $mixedResult = parent::entryAttachments($aData, $aParams);
  467. if(!$this->_bIsApi || !is_array($mixedResult) || !isset($mixedResult[0]['data']))
  468. return $mixedResult;
  469. $CNF = &$this->getModule()->_oConfig->CNF;
  470. /*
  471. * The product page shows photos here. Product files (OBJECT_STORAGE_FILES, what the parent returns)
  472. * stay out on purpose: they are downloads for buyers, the app gets them from entity_downloads
  473. * (market_attachments) after checkAllowedDownload, as the site does.
  474. */
  475. $mixedResult[0]['data'] = [];
  476. $oStorage = BxDolStorage::getObjectInstance($CNF['OBJECT_STORAGE']);
  477. if(!$oStorage) {
  478. return $mixedResult;
  479. }
  480. $aPhotos = $this->_oDb->getPhoto(['type' => 'content_id', 'content_id' => $aData[$CNF['FIELD_ID']], 'except' => [$aData[$CNF['FIELD_THUMB']], $aData[$CNF['FIELD_COVER']]]]);
  481. if(empty($aPhotos) || !is_array($aPhotos))
  482. return $mixedResult;
  483. $aItems = [];
  484. foreach($aPhotos as $aPhoto) {
  485. $aFile = $oStorage->getFile($aPhoto['file_id']);
  486. if(empty($aFile))
  487. continue;
  488. $aItems[] = [
  489. 'file_name' => $aFile['file_name'],
  490. 'mime_type' => $aFile['mime_type'],
  491. 'ext' => $aFile['ext'],
  492. 'type' => 'image',
  493. 'size' => $aFile['size'],
  494. 'url' => $oStorage->getFileUrlById($aPhoto['file_id']),
  495. 'data' => bx_api_get_image($CNF['OBJECT_STORAGE'], $aPhoto['file_id']),
  496. ];
  497. }
  498. $mixedResult[0]['data'] = $aItems;
  499. return $mixedResult;
  500. }
  501. }
  502. /** @} */