BxBaseModTextTemplate.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  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 BaseText Base classes for text modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Module representation.
  13. */
  14. class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
  15. {
  16. protected $_sUnitClassShowCase;
  17. function __construct(&$oConfig, &$oDb)
  18. {
  19. parent::__construct($oConfig, $oDb);
  20. $this->_sUnitClassShowCase = 'bx-base-unit-showcase bx-base-text-unit-showcase bx-def-margin-sec-bottom';
  21. }
  22. public function addLocationBase()
  23. {
  24. parent::addLocationBase();
  25. $this->addLocation('mod_text', BX_DIRECTORY_PATH_MODULES . 'base' . DIRECTORY_SEPARATOR . 'text' . DIRECTORY_SEPARATOR, BX_DOL_URL_MODULES . 'base/text/');
  26. }
  27. public function getJsCode($sType, $aParams = array(), $bWrap = true)
  28. {
  29. $CNF = &$this->getModule()->_oConfig->CNF;
  30. $aParams = array_merge(array(
  31. 'aHtmlIds' => $this->_oConfig->getHtmlIds(),
  32. 'sEditorId' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : ''
  33. ), $aParams);
  34. return parent::getJsCode($sType, $aParams, $bWrap);
  35. }
  36. function unit ($aData, $isCheckPrivateContent = true, $sTemplateName = 'unit.html', $aParams = array())
  37. {
  38. if(!empty($aParams['template_name']))
  39. $sTemplateName = $aParams['template_name'];
  40. else
  41. $aParams['template_name'] = $sTemplateName;
  42. $sResult = $this->checkPrivacy ($aData, $isCheckPrivateContent, $this->getModule(), $sTemplateName);
  43. if($sResult)
  44. return $sResult;
  45. $aTemplateVars = $this->getUnit($aData, $aParams);
  46. /**
  47. * @hooks
  48. * @hookdef hook-bx_base_text-unit '{module_name}', 'unit' - hook to override content browsing unit
  49. * - $unit_name - module name
  50. * - $action - equals `unit`
  51. * - $object_id - not used
  52. * - $sender_id - not used
  53. * - $extra_params - array of additional params with the following array keys:
  54. * - `data` - [array] content info array as key&value pairs
  55. * - `check_private_content` - [boolean] check if it's a provate content
  56. * - `template` - [string] or [array] with template for content unit
  57. * - `params` - [array] additional params array as key&value pairs
  58. * - `tmpl_name` - [string] by ref, template name, can be overridden in hook processing
  59. * - `tmpl_vars` - [array] by ref, template parsable variables as key&value pairs, can be overridden in hook processing
  60. * @hook @ref hook-bx_base_text-unit
  61. */
  62. bx_alert($this->getModule()->getName(), 'unit', 0, 0, [
  63. 'data' => $aData,
  64. 'check_private_content' => $isCheckPrivateContent,
  65. 'template' => $sTemplateName,
  66. 'params' => $aParams,
  67. 'tmpl_name' => &$sTemplateName,
  68. 'tmpl_vars' => &$aTemplateVars
  69. ]);
  70. return $this->parseHtmlByName($sTemplateName, $aTemplateVars);
  71. }
  72. function entryAttachments ($aData, $aParams = array())
  73. {
  74. $CNF = &$this->getModule()->_oConfig->CNF;
  75. $aStoragesKeys = array('OBJECT_STORAGE_PHOTOS', 'OBJECT_STORAGE_VIDEOS', 'OBJECT_STORAGE_SOUNDS', 'OBJECT_STORAGE_FILES');
  76. $aStorages = array();
  77. foreach($aStoragesKeys as $sKey)
  78. if(!empty($CNF[$sKey]))
  79. $aStorages[] = $CNF[$sKey];
  80. if(!empty($aStorages))
  81. return $this->entryAttachmentsByStorage($aStorages, $aData, array_merge($aParams, array('filter_field' => '')));
  82. return parent::entryAttachments($aData, $aParams);
  83. }
  84. function entryAuthor ($aData, $iProfileId = false, $sFuncAuthorDesc = 'getAuthorDesc', $sTemplateName = 'author.html', $sFuncAuthorAddon = 'getAuthorAddon')
  85. {
  86. $oModule = $this->getModule();
  87. $CNF = &$oModule->_oConfig->CNF;
  88. if (!$iProfileId)
  89. $iProfileId = $aData[$CNF['FIELD_AUTHOR']];
  90. if($this->_bIsApi) {
  91. $sFldAdd = 'FIELD_ADDED';
  92. $sFldAvt = 'FIELD_ALLOW_VIEW_TO';
  93. return [
  94. bx_api_get_block('entity_author', [
  95. 'author_data' => BxDolProfile::getData($iProfileId),
  96. 'entry_date' => !empty($CNF[$sFldAdd]) && !empty($aData[$CNF[$sFldAdd]]) ? $aData[$CNF[$sFldAdd]] : '',
  97. 'entry_context' => !empty($CNF[$sFldAvt]) && (int)$aData[$CNF[$sFldAvt]] < 0 ? BxDolProfile::getData(abs((int)$aData[$CNF[$sFldAvt]])) : '',
  98. 'menu_manage' => $oModule->getEntryAllActions()
  99. ])
  100. ];
  101. }
  102. $oProfile = BxDolProfile::getInstanceMagic($iProfileId);
  103. $sName = $oProfile->getDisplayName();
  104. $sAddon = $sFuncAuthorAddon && is_a($oProfile, 'BxDolProfile') ? $this->$sFuncAuthorAddon($aData, $oProfile) : '';
  105. return $this->parseHtmlByName($sTemplateName, [
  106. 'author_url' => $oProfile->getUrl(),
  107. 'author_thumb_url' => $oProfile->getThumb(),
  108. 'author_unit' => $oProfile->getUnit(0, ['template' => 'unit_wo_info']),
  109. 'author_title' => $sName,
  110. 'author_title_attr' => bx_html_attribute($sName),
  111. 'author_desc' => $sFuncAuthorDesc ? $this->$sFuncAuthorDesc($aData, $oProfile) : '',
  112. 'author_profile_desc' => $this->getAuthorProfileDesc($aData, $oProfile),
  113. 'bx_if:addon' => [
  114. 'condition' => (bool)$sAddon,
  115. 'content' => [
  116. 'content' => $sAddon,
  117. ],
  118. ],
  119. ]);
  120. }
  121. public function entryBreadcrumb($aContentInfo, $aTmplVarsItems = array())
  122. {
  123. if(!empty($aTmplVarsItems) && is_array($aTmplVarsItems))
  124. return parent::entryBreadcrumb($aContentInfo, $aTmplVarsItems);
  125. $CNF = &$this->getModule()->_oConfig->CNF;
  126. $aTmplVarsItems = array();
  127. if(!empty($CNF['OBJECT_CATEGORY']) && !empty($CNF['FIELD_CATEGORY'])) {
  128. $oCategory = BxDolCategory::getObjectInstance($CNF['OBJECT_CATEGORY']);
  129. $aParams = [];
  130. if(isset($CNF['URL_CATEGORY']))
  131. $aParams['page'] = bx_append_url_params(BxDolPermalinks::getInstance()->permalink($CNF['URL_CATEGORY']), [
  132. 'category' => '{keyword}'
  133. ], true, ['{keyword}']);
  134. $aTmplVarsItems[] = array(
  135. 'url' => $oCategory->getCategoryUrl($aContentInfo[$CNF['FIELD_CATEGORY']], $aParams),
  136. 'title' => $oCategory->getCategoryTitle($aContentInfo[$CNF['FIELD_CATEGORY']])
  137. );
  138. }
  139. $aTmplVarsItems[] = array(
  140. 'url' => BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  141. 'title' => bx_process_output($aContentInfo[$CNF['FIELD_TITLE']])
  142. );
  143. return parent::entryBreadcrumb($aContentInfo, $aTmplVarsItems);
  144. }
  145. protected function _addCssJsPolls($bDynamic = false)
  146. {
  147. $sInclude = parent::_addCssJsPolls($bDynamic);
  148. $sInclude .= $this->addJs(['modules/base/text/js/|polls.js','polls.js'], $bDynamic);
  149. return $bDynamic ? $sInclude : '';
  150. }
  151. public function getAttachLinkForm($iContentId = 0)
  152. {
  153. $sStylePrefix = $this->_oConfig->getPrefix('style');
  154. $sJsObject = $this->_oConfig->getJsObject('links');
  155. $aForm = $this->getModule()->getFormAttachLink($iContentId);
  156. return $this->parseHtmlByName('attach_link_form.html', array(
  157. 'style_prefix' => $sStylePrefix,
  158. 'js_object' => $sJsObject,
  159. 'form_id' => $aForm['form_id'],
  160. 'form' => $aForm['form'],
  161. ));
  162. }
  163. public function getAttachLinkField($iUserId, $iContentId = 0)
  164. {
  165. $sStylePrefix = $this->_oConfig->getPrefix('style');
  166. if(!$iContentId)
  167. $aLinks = $this->_oDb->getUnusedLinks($iUserId);
  168. else
  169. $aLinks = $this->_oDb->getLinks($iContentId);
  170. $sLinks = '';
  171. foreach($aLinks as $aLink)
  172. $sLinks .= $this->getAttachLinkItem($iUserId, $aLink);
  173. return $this->parseHtmlByName('attach_link_form_field.html', array(
  174. 'html_id' => $this->_oConfig->getHtmlIds('attach_link_form_field') . $iContentId,
  175. 'style_prefix' => $sStylePrefix,
  176. 'links' => $sLinks
  177. ));
  178. }
  179. public function getAttachLinkItem($iUserId, $mixedLink, $aParams = [])
  180. {
  181. $CNF = &$this->getModule()->_oConfig->CNF;
  182. return parent::getAttachLinkItem($iUserId, $mixedLink, array_merge($aParams ?? [], [
  183. 'html_id_link_item' => $this->_oConfig->getHtmlIds('attach_link_item'),
  184. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  185. 'js_object' => $this->_oConfig->getJsObject('links'),
  186. 'transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']
  187. ]));
  188. }
  189. public function getEventLinks($iContentId)
  190. {
  191. $CNF = &$this->getModule()->_oConfig->CNF;
  192. $aLinks = $this->_oDb->getLinks($iContentId);
  193. if(empty($aLinks) || !is_array($aLinks))
  194. return array();
  195. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']);
  196. $aResult = array();
  197. foreach($aLinks as $aLink)
  198. $aResult[] = array(
  199. 'url' => $aLink['url'],
  200. 'title' => $aLink['title'],
  201. 'text' => $aLink['text'],
  202. 'thumbnail' => (int)$aLink['media_id'] != 0 ? $oTranscoder->getFileUrl($aLink['media_id']) : ''
  203. );
  204. return $aResult;
  205. }
  206. public function getTmplVarsText($aData)
  207. {
  208. $CNF = &$this->getModule()->_oConfig->CNF;
  209. $sStylePrefix = $this->_oConfig->getPrefix('style');
  210. $aVars = parent::getTmplVarsText($aData);
  211. $aImageParams = $this->_getHeaderImageParams();
  212. $mixedImage = $this->_getHeaderImage($aData);
  213. $sImage = '';
  214. if($mixedImage !== false) {
  215. if(!empty($mixedImage['object']))
  216. $o = BxDolStorage::getObjectInstance($mixedImage['object']);
  217. else if(!empty($mixedImage['transcoder']))
  218. $o = BxDolTranscoder::getObjectInstance($mixedImage['transcoder']);
  219. if($o)
  220. $sImage = $o->getFileUrlById($mixedImage['id']);
  221. }
  222. if($this->_bIsApi) {
  223. if($sImage)
  224. $aVars['image'] = bx_api_get_image($aImageParams['storage'], $mixedImage['id']);
  225. return $aVars;
  226. }
  227. $sAddClassPicture = "";
  228. $sAddCode = "";
  229. $oModule = $this->getModule();
  230. $bIsAllowEditPicture = CHECK_ACTION_RESULT_ALLOWED === $oModule->checkAllowedEdit($aData);
  231. if($aImageParams['field'] && $aImageParams['uploaders'] && $aImageParams['storage'] && $aImageParams['transcoder_cover']) {
  232. /**
  233. * @hooks
  234. * @hookdef hook-system-image_editor 'system', 'image_editor' - hook to override content header image editor
  235. * - $unit_name - equals `system`
  236. * - $action - equals `image_editor`
  237. * - $object_id - not used
  238. * - $sender_id - not used
  239. * - $extra_params - array of additional params with the following array keys:
  240. * - `module` - [string] module name
  241. * - `content_id` - [int] profile content id
  242. * - `is_allow_edit` - [boolean] if edit action is allowed to current user
  243. * - `image_type` - [string] image type equals to `header_image`
  244. * - `image_url` - [string] image URL
  245. * - `uploader` - [string] uploader name
  246. * - `storage` - [string] storage name
  247. * - `transcoder` - [string] transcoder name
  248. * - `field` - [string] field name
  249. * - `is_background` - [boolean] if image is used as background, always `false`
  250. * - `add_class` - [string] by ref, class to add, can be overridden in hook processing
  251. * - `add_code` - [array] by ref, code to add, can be overridden in hook processing
  252. * @hook @ref hook-system-image_editor
  253. */
  254. bx_alert('system', 'image_editor', 0, 0, [
  255. 'module' => $oModule->getName(),
  256. 'content_id' => $aData[$CNF['FIELD_ID']],
  257. 'is_allow_edit' => $bIsAllowEditPicture,
  258. 'image_type' => 'header_image',
  259. 'image_url' => $sImage,
  260. 'uploader' => $aImageParams['uploaders'] && is_array($aImageParams['uploaders']) ? $aImageParams['uploaders'][0] : '',
  261. 'storage' => $aImageParams['storage'],
  262. 'transcoder' => $aImageParams['transcoder_cover'],
  263. 'field' => $aImageParams['field'],
  264. 'is_background' => false,
  265. 'add_class' => &$sAddClassPicture,
  266. 'add_code' => &$sAddCode
  267. ]);
  268. }
  269. $sImageTweak = '';
  270. $sUniqIdImage = genRndPwd (8, false);
  271. if ($bIsAllowEditPicture && empty($sAddCode) && $aImageParams['field_position']){
  272. $sImageTweak = $this->_prepareImage($aData, $sUniqIdImage, $aImageParams['uploaders'], $aImageParams['storage'], $aImageParams['field'], true);
  273. }
  274. $aVars['content_description_before'] = '';
  275. $aVars['content_description_after'] = '';
  276. $aVars['bx_if:show_image'] = array(
  277. 'condition' => !empty($sImage),
  278. 'content' => array(
  279. 'entry_image' => $sImage,
  280. 'image_settings' => $aImageParams['field_position'] ? $this->_getImageSettings($aImageParams['field'], $aData[$aImageParams['field_position']], 'page_cover') : '',
  281. 'add_class' => $sAddClassPicture,
  282. 'img_class' => $sAddClassPicture != '' ? 'bx-media-editable-src' : '',
  283. 'additional_code' => $sAddCode,
  284. 'image_tweak' => $sImageTweak,
  285. 'unique_id' => $sUniqIdImage,
  286. )
  287. );
  288. $aTmplVarsLinks = [];
  289. if(isset($CNF['FIELD_LINK'])){
  290. $aLinks = $this->getEventLinks($aData[$CNF['FIELD_ID']]);
  291. $sClass = $sStylePrefix . '-al-item';
  292. $bAddNofollow = $this->_oDb->getParam('sys_add_nofollow') == 'on';
  293. foreach($aLinks as $aLink) {
  294. $sLink = '';
  295. $oEmbed = BxDolEmbed::getObjectInstance();
  296. if ($oEmbed) {
  297. $sLink = $this->parseHtmlByName('link_embed_provider.html', array(
  298. 'style_prefix' => $sStylePrefix,
  299. 'embed' => $oEmbed->getLinkHTML($aLink['url'], $aLink['title']),
  300. ));
  301. }
  302. else {
  303. $aLinkAttrs = array(
  304. 'title' => $aLink['title']
  305. );
  306. if(!$this->_oConfig->isEqualUrls(BX_DOL_URL_ROOT, $aLink['url'])) {
  307. $aLinkAttrs['target'] = '_blank';
  308. if($bAddNofollow)
  309. $aLinkAttrs['rel'] = 'nofollow';
  310. }
  311. $sLinkAttrs = '';
  312. foreach($aLinkAttrs as $sKey => $sValue)
  313. $sLinkAttrs .= ' ' . $sKey . '="' . bx_html_attribute($sValue) . '"';
  314. $sLink = $this->parseHtmlByName('link_embed_common.html', array(
  315. 'bx_if:show_thumbnail' => [
  316. 'condition' => !empty($aLink['thumbnail']),
  317. 'content' => [
  318. 'style_prefix' => $sStylePrefix,
  319. 'thumbnail' => $aLink['thumbnail'],
  320. 'link' => !empty($aLink['url']) ? $aLink['url'] : 'javascript:void(0)',
  321. 'attrs' => $sLinkAttrs
  322. ]
  323. ],
  324. 'link' => !empty($aLink['url']) ? $aLink['url'] : 'javascript:void(0)',
  325. 'attrs' => $sLinkAttrs,
  326. 'content' => $aLink['title'],
  327. 'bx_if:show_text' => [
  328. 'condition' => !empty($aLink['text']),
  329. 'content' => [
  330. 'style_prefix' => $sStylePrefix,
  331. 'text' => $aLink['text']
  332. ]
  333. ]
  334. ));
  335. }
  336. $aTmplVarsLinks[] = [
  337. 'style_prefix' => $sStylePrefix,
  338. 'link' => $sLink
  339. ];
  340. }
  341. }
  342. $aVars['bx_if:show_links'] = [
  343. 'condition' => count($aTmplVarsLinks) > 0,
  344. 'content' => [
  345. 'style_prefix' => $sStylePrefix,
  346. 'bx_repeat:links' => $aTmplVarsLinks
  347. ]
  348. ];
  349. if(!empty($CNF['OBJECT_REACTIONS']) && ($oReactions = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $aData[$CNF['FIELD_ID']])) !== false)
  350. $aVars['content_description_after'] .= $oReactions->getCounter([
  351. 'show_counter' => true,
  352. 'show_counter_empty' => false
  353. ]);
  354. $this->addCss(array('cover.css'));
  355. return $aVars;
  356. }
  357. function getAuthorDesc($aData, $oProfile)
  358. {
  359. $CNF = &$this->getModule()->_oConfig->CNF;
  360. $aItem = array(
  361. 'bx_if:text' => array(
  362. 'condition' => false,
  363. 'content' => array(
  364. 'content' => ''
  365. )
  366. ),
  367. 'bx_if:link' => array(
  368. 'condition' => false,
  369. 'content' => array(
  370. 'link' => '',
  371. 'content' => ''
  372. )
  373. )
  374. );
  375. $aTmplVarsItems = array();
  376. if(!empty($CNF['FIELD_ADDED']) && !empty($aData[$CNF['FIELD_ADDED']]))
  377. $aTmplVarsItems[] = array_merge($aItem, array('bx_if:text' => array(
  378. 'condition' => true,
  379. 'content' => array(
  380. 'content' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE)
  381. )
  382. )));
  383. if(!empty($CNF['URI_AUTHOR_ENTRIES']))
  384. $aTmplVarsItems[] = array_merge($aItem, array('bx_if:link' => array(
  385. 'condition' => true,
  386. 'content' => array(
  387. 'link' => BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id=' . $oProfile->id()),
  388. 'content' => _t($CNF['T']['txt_all_entries_by'], $this->getModule()->serviceGetMenuAddonManageToolsProfileStats($oProfile->id()))
  389. )
  390. )));
  391. return $this->parseHtmlByName('author_desc.html', array(
  392. 'bx_repeat:items' => $aTmplVarsItems
  393. ));
  394. }
  395. function getAuthorProfileDesc ($aData, $oProfile)
  396. {
  397. $aSnippetMeta = $this->getProfileSnippetMenu($aData);
  398. if(empty($aSnippetMeta) || !is_array($aSnippetMeta) || !isset($aSnippetMeta['meta']))
  399. return '';
  400. return $aSnippetMeta['meta'];
  401. }
  402. function getProfileSnippetMenu ($aData)
  403. {
  404. $CNF = &$this->getModule()->_oConfig->CNF;
  405. if (!($oProfile = BxDolProfile::getInstance($aData[$CNF['FIELD_AUTHOR']])))
  406. return array();
  407. return bx_srv($oProfile->getModule(), 'get_snippet_menu_vars', array($oProfile->id()));
  408. }
  409. function getAuthorAddon ($aData, $oProfile)
  410. {
  411. return '';
  412. }
  413. protected function checkPrivacy ($aData, $isCheckPrivateContent, $oModule, $sTemplateName = '')
  414. {
  415. if ($isCheckPrivateContent && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $oModule->checkAllowedView($aData))) {
  416. $aVars = array (
  417. 'summary' => $sMsg,
  418. );
  419. return $this->parseHtmlByName($sTemplateName ? str_replace('.html', '_private.html', $sTemplateName) : 'unit_private.html', $aVars);
  420. }
  421. return '';
  422. }
  423. protected function getUnitThumbAndGallery ($aData)
  424. {
  425. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  426. $sPhotoThumb = '';
  427. $sPhotoGallery = '';
  428. if(!empty($CNF['FIELD_THUMB']) && !empty($aData[$CNF['FIELD_THUMB']])) {
  429. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  430. if ($oImagesTranscoder)
  431. $sPhotoThumb = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  432. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  433. if ($oImagesTranscoder)
  434. $sPhotoGallery = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  435. else
  436. $sPhotoGallery = $sPhotoThumb;
  437. }
  438. return array($sPhotoThumb, $sPhotoGallery);
  439. }
  440. protected function getUnit ($aData, $aParams = array())
  441. {
  442. $CNF = &$this->_oConfig->CNF;
  443. $oModule = $this->getModule();
  444. // get thumb url
  445. list($sPhotoThumb, $sPhotoGallery) = $this->getUnitThumbAndGallery($aData);
  446. if ($sPhotoGallery == '' && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  447. if(!empty($CNF['OBJECT_STORAGE_PHOTOS'])){
  448. $sStorage = $CNF['OBJECT_STORAGE_PHOTOS'];
  449. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  450. list($oTranscoder, $oTranscoderView) = $this->getAttachmentsImagesTranscoders($sStorage);
  451. $aGhostFiles = $oStorage->getGhosts($oModule->serviceGetContentOwnerProfileId($aData[$CNF['FIELD_ID']]), $aData[$CNF['FIELD_ID']]);
  452. if(!empty($aGhostFiles) && is_array($aGhostFiles)) {
  453. $aGhostFile = array_shift($aGhostFiles);
  454. $sPhotoThumb = $oTranscoderView->getFileUrl($aGhostFile['id']);
  455. $sPhotoGallery = $oTranscoder->getFileUrl($aGhostFile['id']);
  456. }
  457. }
  458. }
  459. // get entry url
  460. $sUrl = $this->_oConfig->getViewEntryUrl($aData[$CNF['FIELD_ID']]);
  461. $oProfile = BxDolProfile::getInstanceMagic($aData[$CNF['FIELD_AUTHOR']]);
  462. $sTitle = $this->getTitle($aData);
  463. $sText = $this->getText($aData);
  464. $sSummary = $this->getSummary($aData, $sTitle, $sText, $sUrl);
  465. $sSummaryPlain = isset($CNF['PARAM_CHARS_SUMMARY_PLAIN']) && $CNF['PARAM_CHARS_SUMMARY_PLAIN'] ? BxTemplFunctions::getInstance()->getStringWithLimitedLength(strip_tags($sSummary), (int)getParam($CNF['PARAM_CHARS_SUMMARY_PLAIN'])) : '';
  466. if(!empty($CNF['OBJECT_METATAGS'])) {
  467. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  468. $sText = $oMetatags->metaParse($aData[$CNF['FIELD_ID']], $sText);
  469. }
  470. $aTmplVarsMeta = [];
  471. if(!empty($CNF['OBJECT_MENU_SNIPPET_META'])) {
  472. $oMenuMeta = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this);
  473. if($oMenuMeta) {
  474. $oMenuMeta->setContentId($aData[$CNF['FIELD_ID']]);
  475. if(isset($aParams['context']))
  476. $oMenuMeta->setContext($aParams['context']);
  477. $aTmplVarsMeta = [
  478. 'meta' => $oMenuMeta->getCode()
  479. ];
  480. }
  481. }
  482. $bBadgesSingle = isset($aParams['badges_single']) ? $aParams['badges_single'] : false;
  483. $bBadgesCompact = isset($aParams['badges_compact']) ? $aParams['badges_compact'] : false;
  484. $sCoverData = ($sKey = 'FIELD_THUMB_POSITION') && isset($CNF[$sKey], $aData[$CNF[$sKey]]) ? $aData[$CNF[$sKey]] : '';
  485. $sCoverSettings = $this->_getImageSettings($CNF['FIELD_THUMB'], $sCoverData, 'unit_cover');
  486. $aTmplVars = array (
  487. 'class' => $this->_getUnitClass($aData,(isset($aParams['template_name']) ? $aParams['template_name'] : '')),
  488. 'html_id' => $this->_getUnitHtmlId($aData,(isset($aParams['template_name']) ? $aParams['template_name'] : '')),
  489. 'id' => $aData[$CNF['FIELD_ID']],
  490. 'content_url' => $sUrl,
  491. 'bx_if:show_onclick' => [
  492. 'condition' => false,
  493. 'content' => [
  494. 'content_onclick' => ''
  495. ]
  496. ],
  497. 'title' => $sTitle,
  498. 'badges' => $oModule->serviceGetBadges($aData[$CNF['FIELD_ID']], $bBadgesSingle, $bBadgesCompact),
  499. 'title_attr' => bx_html_attribute($sTitle),
  500. 'summary' => $sSummary,
  501. 'text' => $sText,
  502. 'author' => $oProfile->getDisplayName(),
  503. 'author_url' => $oProfile->getUrl(),
  504. 'author_icon' => $oProfile->getIcon(),
  505. 'author_thumb' => $oProfile->getThumb(),
  506. 'author_avatar' => $oProfile->getAvatar(),
  507. 'entry_posting_date' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE),
  508. 'module_name' => _t($CNF['T']['txt_sample_single']),
  509. 'ts' => $aData[$CNF['FIELD_ADDED']],
  510. 'bx_if:meta' => array(
  511. 'condition' => !empty($aTmplVarsMeta),
  512. 'content' => $aTmplVarsMeta
  513. ),
  514. 'bx_if:thumb' => array (
  515. 'condition' => $sPhotoThumb,
  516. 'content' => array (
  517. 'title' => $sTitle,
  518. 'summary_attr' => bx_html_attribute($sSummaryPlain),
  519. 'content_url' => $sUrl,
  520. 'bx_if:show_thumb_onclick' => [
  521. 'condition' => false,
  522. 'content' => [
  523. 'content_onclick' => ''
  524. ]
  525. ],
  526. 'thumb_url' => $sPhotoThumb ? $sPhotoThumb : '',
  527. 'gallery_url' => $sPhotoGallery ? $sPhotoGallery : '',
  528. 'image_settings' => $sCoverSettings,
  529. 'strecher' => str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', 40),
  530. ),
  531. ),
  532. 'bx_if:no_thumb' => array (
  533. 'condition' => !$sPhotoThumb,
  534. 'content' => array (
  535. 'module_icon' => $CNF['ICON'],
  536. 'content_url' => $sUrl,
  537. 'bx_if:show_no_thumb_onclick' => [
  538. 'condition' => false,
  539. 'content' => [
  540. 'content_onclick' => ''
  541. ]
  542. ],
  543. 'summary_plain' => $sSummaryPlain,
  544. 'strecher' => mb_strlen($sSummaryPlain) > 240 ? '' : str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', round((240 - mb_strlen($sSummaryPlain)) / 6)),
  545. ),
  546. ),
  547. 'unit_content_before' => '',
  548. 'unit_content_after' => ''
  549. );
  550. if(isset($aParams['template_vars']) && is_array($aParams['template_vars']))
  551. $aTmplVars = array_merge($aTmplVars, $aParams['template_vars']);
  552. // generate html
  553. return $aTmplVars;
  554. }
  555. protected function getAttachmentsImagesTranscoders ($sStorage = '')
  556. {
  557. $CNF = &$this->getModule()->_oConfig->CNF;
  558. $oTranscoder = null;
  559. $oTranscoderView = null;
  560. if(isset($CNF['OBJECT_STORAGE_PHOTOS']) && $CNF['OBJECT_STORAGE_PHOTOS'] == $sStorage) {
  561. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']))
  562. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']);
  563. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']))
  564. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']);
  565. else if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']))
  566. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']);
  567. }
  568. else if(isset($CNF['OBJECT_STORAGE_FILES']) && $CNF['OBJECT_STORAGE_FILES'] == $sStorage) {
  569. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES']))
  570. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES']);
  571. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']))
  572. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']);
  573. }
  574. else
  575. list($oTranscoder, $oTranscoderView) = parent::getAttachmentsImagesTranscoders($sStorage);
  576. return array($oTranscoder, $oTranscoderView);
  577. }
  578. protected function _getUnitName($aData, $sTemplateName = 'unit.html')
  579. {
  580. return trim(str_replace('.html', '', $sTemplateName));
  581. }
  582. protected function _getUnitClass($aData, $sTemplateName = 'unit.html')
  583. {
  584. $sResult = '';
  585. switch($sTemplateName) {
  586. case 'unit_showcase.html':
  587. $sResult = $this->_sUnitClassShowCase;
  588. break;
  589. }
  590. return $sResult;
  591. }
  592. protected function _getUnitHtmlId($aData, $sTemplateName = 'unit.html')
  593. {
  594. $CNF = &$this->_oConfig->CNF;
  595. return str_replace('_', '-', $this->MODULE . '_unit_' . $aData[$CNF['FIELD_ID']]);
  596. }
  597. protected function _getHeaderImageParams()
  598. {
  599. $CNF = &$this->_oConfig->CNF;
  600. return [
  601. 'field' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : false,
  602. 'field_position' => isset($CNF['FIELD_THUMB_POSITION']) ? $CNF['FIELD_THUMB_POSITION'] : false,
  603. 'storage' => isset($CNF['OBJECT_STORAGE']) ? $CNF['OBJECT_STORAGE'] : false,
  604. 'uploaders' => isset($CNF['OBJECT_UPLOADERS']) ? $CNF['OBJECT_UPLOADERS'] : false,
  605. 'transcoder_cover' => isset($CNF['OBJECT_IMAGES_TRANSCODER_COVER']) ? $CNF['OBJECT_IMAGES_TRANSCODER_COVER'] : false,
  606. ];
  607. }
  608. protected function _getHeaderImage($aData)
  609. {
  610. return $this->getModule()->getEntryImageData($aData);
  611. }
  612. function mediaExif ($aMediaInfo, $iProfileId = false, $sFuncAuthorDesc = '', $sTemplateName = 'media-exif.html')
  613. {
  614. if (empty($aMediaInfo['exif']))
  615. return '';
  616. $a = unserialize($aMediaInfo['exif']);
  617. $s = '';
  618. if (!empty($a['Make'])) {
  619. $oModule = BxDolModule::getInstance($this->MODULE);
  620. $CNF = &$oModule->_oConfig->CNF;
  621. $sCamera = BxDolMetatags::keywordsCameraModel($a);
  622. if (!empty($CNF['OBJECT_METATAGS_MEDIA_CAMERA'])) {
  623. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS_MEDIA_CAMERA']);
  624. if ($oMetatags->keywordsIsEnabled()) {
  625. $sCamera = $oMetatags->keywordsParseOne($aMediaInfo['id'], $sCamera);
  626. }
  627. }
  628. if (!empty($sCamera))
  629. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  630. 'key' => _t($CNF['T']['txt_media_exif_camera']),
  631. 'val' => $sCamera,
  632. ));
  633. }
  634. if (!empty($a['FocalLength']))
  635. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  636. 'key' => _t($CNF['T']['txt_media_exif_focal_length']),
  637. 'val' => _t($CNF['T']['txt_media_exif_focal_length_value'], $a['FocalLength']),
  638. ));
  639. if (!empty($a['COMPUTED']['ApertureFNumber']))
  640. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  641. 'key' => _t($CNF['T']['txt_media_exif_aperture']),
  642. 'val' => $a['COMPUTED']['ApertureFNumber'],
  643. ));
  644. if (!empty($a['ExposureTime']))
  645. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  646. 'key' => _t($CNF['T']['txt_media_exif_shutter_speed']),
  647. 'val' => _t($CNF['T']['txt_media_exif_shutter_speed_value'], $a['ExposureTime']),
  648. ));
  649. if (!empty($a['ISOSpeedRatings']))
  650. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  651. 'key' => _t($CNF['T']['txt_media_exif_iso']),
  652. 'val' => $a['ISOSpeedRatings'],
  653. ));
  654. if (empty($s))
  655. return '';
  656. return $this->parseHtmlByName($sTemplateName, array('content' => $s));
  657. }
  658. }
  659. /** @} */