1
0

BxBaseModTextTemplate.php 30 KB

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