BxBaseModTextTemplate.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  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 getAttachLinks($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']) && ($aLinks = $this->getAttachLinks($aData[$CNF['FIELD_ID']])))
  290. $aTmplVarsLinks = $this->getTmplVarsAttachedLinks($aLinks);
  291. $aVars['bx_if:show_links'] = [
  292. 'condition' => count($aTmplVarsLinks) > 0,
  293. 'content' => [
  294. 'style_prefix' => $sStylePrefix,
  295. 'bx_repeat:links' => $aTmplVarsLinks
  296. ]
  297. ];
  298. if(!empty($CNF['OBJECT_REACTIONS']) && ($oReactions = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $aData[$CNF['FIELD_ID']])) !== false)
  299. $aVars['content_description_after'] .= $oReactions->getCounter([
  300. 'show_counter' => true,
  301. 'show_counter_empty' => false
  302. ]);
  303. $this->addCss(array('cover.css'));
  304. return $aVars;
  305. }
  306. function getAuthorDesc($aData, $oProfile)
  307. {
  308. $CNF = &$this->getModule()->_oConfig->CNF;
  309. $aItem = array(
  310. 'bx_if:text' => array(
  311. 'condition' => false,
  312. 'content' => array(
  313. 'content' => ''
  314. )
  315. ),
  316. 'bx_if:link' => array(
  317. 'condition' => false,
  318. 'content' => array(
  319. 'link' => '',
  320. 'content' => ''
  321. )
  322. )
  323. );
  324. $aTmplVarsItems = array();
  325. if(!empty($CNF['FIELD_ADDED']) && !empty($aData[$CNF['FIELD_ADDED']]))
  326. $aTmplVarsItems[] = array_merge($aItem, array('bx_if:text' => array(
  327. 'condition' => true,
  328. 'content' => array(
  329. 'content' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE)
  330. )
  331. )));
  332. if(!empty($CNF['URI_AUTHOR_ENTRIES']))
  333. $aTmplVarsItems[] = array_merge($aItem, array('bx_if:link' => array(
  334. 'condition' => true,
  335. 'content' => array(
  336. 'link' => BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id=' . $oProfile->id()),
  337. 'content' => _t($CNF['T']['txt_all_entries_by'], $this->getModule()->serviceGetMenuAddonManageToolsProfileStats($oProfile->id()))
  338. )
  339. )));
  340. return $this->parseHtmlByName('author_desc.html', array(
  341. 'bx_repeat:items' => $aTmplVarsItems
  342. ));
  343. }
  344. function getAuthorProfileDesc ($aData, $oProfile)
  345. {
  346. $aSnippetMeta = $this->getProfileSnippetMenu($aData);
  347. if(empty($aSnippetMeta) || !is_array($aSnippetMeta) || !isset($aSnippetMeta['meta']))
  348. return '';
  349. return $aSnippetMeta['meta'];
  350. }
  351. function getProfileSnippetMenu ($aData)
  352. {
  353. $CNF = &$this->getModule()->_oConfig->CNF;
  354. if (!($oProfile = BxDolProfile::getInstance($aData[$CNF['FIELD_AUTHOR']])))
  355. return array();
  356. return bx_srv($oProfile->getModule(), 'get_snippet_menu_vars', array($oProfile->id()));
  357. }
  358. function getAuthorAddon ($aData, $oProfile)
  359. {
  360. return '';
  361. }
  362. protected function checkPrivacy ($aData, $isCheckPrivateContent, $oModule, $sTemplateName = '')
  363. {
  364. if ($isCheckPrivateContent && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $oModule->checkAllowedView($aData))) {
  365. $aVars = array (
  366. 'summary' => $sMsg,
  367. );
  368. return $this->parseHtmlByName($sTemplateName ? str_replace('.html', '_private.html', $sTemplateName) : 'unit_private.html', $aVars);
  369. }
  370. return '';
  371. }
  372. protected function getUnitThumbAndGallery ($aData)
  373. {
  374. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  375. $sPhotoThumb = '';
  376. $sPhotoGallery = '';
  377. if(!empty($CNF['FIELD_THUMB']) && !empty($aData[$CNF['FIELD_THUMB']])) {
  378. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  379. if ($oImagesTranscoder)
  380. $sPhotoThumb = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  381. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  382. if ($oImagesTranscoder)
  383. $sPhotoGallery = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  384. else
  385. $sPhotoGallery = $sPhotoThumb;
  386. }
  387. return array($sPhotoThumb, $sPhotoGallery);
  388. }
  389. protected function getUnit ($aData, $aParams = array())
  390. {
  391. $CNF = &$this->_oConfig->CNF;
  392. $oModule = $this->getModule();
  393. // get thumb url
  394. list($sPhotoThumb, $sPhotoGallery) = $this->getUnitThumbAndGallery($aData);
  395. if ($sPhotoGallery == '' && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  396. if(!empty($CNF['OBJECT_STORAGE_PHOTOS'])){
  397. $sStorage = $CNF['OBJECT_STORAGE_PHOTOS'];
  398. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  399. list($oTranscoder, $oTranscoderView) = $this->getAttachmentsImagesTranscoders($sStorage);
  400. $aGhostFiles = $oStorage->getGhosts($oModule->serviceGetContentOwnerProfileId($aData[$CNF['FIELD_ID']]), $aData[$CNF['FIELD_ID']]);
  401. if(!empty($aGhostFiles) && is_array($aGhostFiles)) {
  402. $aGhostFile = array_shift($aGhostFiles);
  403. $sPhotoThumb = $oTranscoderView->getFileUrl($aGhostFile['id']);
  404. $sPhotoGallery = $oTranscoder->getFileUrl($aGhostFile['id']);
  405. }
  406. }
  407. }
  408. $oProfile = BxDolProfile::getInstanceMagic($aData[$CNF['FIELD_AUTHOR']]);
  409. $sUrl = $this->getUnitLink($aData);
  410. $sTitle = $this->getUnitTitle($aData);
  411. $sText = $this->getUnitText($aData);
  412. $sSummary = $this->getUnitSummary($aData, $sTitle, $sText, $sUrl);
  413. $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'])) : '';
  414. if(!empty($CNF['OBJECT_METATAGS'])) {
  415. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  416. $sText = $oMetatags->metaParse($aData[$CNF['FIELD_ID']], $sText);
  417. }
  418. $aTmplVarsMeta = [];
  419. if(!empty($CNF['OBJECT_MENU_SNIPPET_META'])) {
  420. $oMenuMeta = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this);
  421. if($oMenuMeta) {
  422. $oMenuMeta->setContentId($aData[$CNF['FIELD_ID']]);
  423. if(isset($aParams['context']))
  424. $oMenuMeta->setContext($aParams['context']);
  425. $aTmplVarsMeta = [
  426. 'meta' => $oMenuMeta->getCode()
  427. ];
  428. }
  429. }
  430. $bBadgesSingle = isset($aParams['badges_single']) ? $aParams['badges_single'] : false;
  431. $bBadgesCompact = isset($aParams['badges_compact']) ? $aParams['badges_compact'] : false;
  432. $sCoverData = ($sKey = 'FIELD_THUMB_POSITION') && isset($CNF[$sKey], $aData[$CNF[$sKey]]) ? $aData[$CNF[$sKey]] : '';
  433. $sCoverSettings = ($sKey = 'FIELD_THUMB') && isset($CNF[$sKey]) ? $this->_getImageSettings($CNF[$sKey], $sCoverData, 'unit_cover') : '';
  434. $aTmplVars = array (
  435. 'class' => $this->_getUnitClass($aData,(isset($aParams['template_name']) ? $aParams['template_name'] : '')),
  436. 'html_id' => $this->_getUnitHtmlId($aData,(isset($aParams['template_name']) ? $aParams['template_name'] : '')),
  437. 'id' => $aData[$CNF['FIELD_ID']],
  438. 'content_url' => $sUrl,
  439. 'content_url_attrs' => '',
  440. 'bx_if:show_onclick' => [
  441. 'condition' => false,
  442. 'content' => [
  443. 'content_onclick' => ''
  444. ]
  445. ],
  446. 'title' => $sTitle,
  447. 'badges' => $oModule->serviceGetBadges($aData[$CNF['FIELD_ID']], $bBadgesSingle, $bBadgesCompact),
  448. 'title_attr' => bx_html_attribute($sTitle),
  449. 'summary' => $sSummary,
  450. 'text' => $sText,
  451. 'author' => $oProfile->getDisplayName(),
  452. 'author_url' => $oProfile->getUrl(),
  453. 'author_icon' => $oProfile->getIcon(),
  454. 'author_thumb' => $oProfile->getThumb(),
  455. 'author_avatar' => $oProfile->getAvatar(),
  456. 'entry_posting_date' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE),
  457. 'module_name' => _t($CNF['T']['txt_sample_single']),
  458. 'ts' => $aData[$CNF['FIELD_ADDED']],
  459. 'bx_if:meta' => array(
  460. 'condition' => !empty($aTmplVarsMeta),
  461. 'content' => $aTmplVarsMeta
  462. ),
  463. 'bx_if:thumb' => array (
  464. 'condition' => $sPhotoThumb,
  465. 'content' => array (
  466. 'title' => $sTitle,
  467. 'summary_attr' => bx_html_attribute($sSummaryPlain),
  468. 'content_url' => $sUrl,
  469. 'bx_if:show_thumb_onclick' => [
  470. 'condition' => false,
  471. 'content' => [
  472. 'content_onclick' => ''
  473. ]
  474. ],
  475. 'thumb_url' => $sPhotoThumb ? $sPhotoThumb : '',
  476. 'gallery_url' => $sPhotoGallery ? $sPhotoGallery : '',
  477. 'image_settings' => $sCoverSettings,
  478. 'strecher' => str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', 40),
  479. ),
  480. ),
  481. 'bx_if:no_thumb' => array (
  482. 'condition' => !$sPhotoThumb,
  483. 'content' => array (
  484. 'module_icon' => $CNF['ICON'],
  485. 'content_url' => $sUrl,
  486. 'bx_if:show_no_thumb_onclick' => [
  487. 'condition' => false,
  488. 'content' => [
  489. 'content_onclick' => ''
  490. ]
  491. ],
  492. 'summary_plain' => $sSummaryPlain,
  493. 'strecher' => mb_strlen($sSummaryPlain) > 240 ? '' : str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', round((240 - mb_strlen($sSummaryPlain)) / 6)),
  494. ),
  495. ),
  496. 'unit_content_before' => '',
  497. 'unit_content_after' => ''
  498. );
  499. if(isset($aParams['template_vars']) && is_array($aParams['template_vars']))
  500. $aTmplVars = array_merge($aTmplVars, $aParams['template_vars']);
  501. // generate html
  502. return $aTmplVars;
  503. }
  504. protected function getAttachmentsImagesTranscoders ($sStorage = '')
  505. {
  506. $CNF = &$this->getModule()->_oConfig->CNF;
  507. $oTranscoder = null;
  508. $oTranscoderView = null;
  509. if(isset($CNF['OBJECT_STORAGE_PHOTOS']) && $CNF['OBJECT_STORAGE_PHOTOS'] == $sStorage) {
  510. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']))
  511. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']);
  512. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']))
  513. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']);
  514. else if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']))
  515. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']);
  516. }
  517. else if(isset($CNF['OBJECT_STORAGE_FILES']) && $CNF['OBJECT_STORAGE_FILES'] == $sStorage) {
  518. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES']))
  519. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES']);
  520. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']))
  521. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']);
  522. }
  523. else
  524. list($oTranscoder, $oTranscoderView) = parent::getAttachmentsImagesTranscoders($sStorage);
  525. return array($oTranscoder, $oTranscoderView);
  526. }
  527. protected function _getUnitName($aData, $sTemplateName = 'unit.html')
  528. {
  529. return trim(str_replace('.html', '', $sTemplateName));
  530. }
  531. protected function _getUnitClass($aData, $sTemplateName = 'unit.html')
  532. {
  533. $sResult = '';
  534. switch($sTemplateName) {
  535. case 'unit_showcase.html':
  536. $sResult = $this->_sUnitClassShowCase;
  537. break;
  538. }
  539. return $sResult;
  540. }
  541. protected function _getUnitHtmlId($aData, $sTemplateName = 'unit.html')
  542. {
  543. $CNF = &$this->_oConfig->CNF;
  544. return str_replace('_', '-', $this->MODULE . '_unit_' . $aData[$CNF['FIELD_ID']]);
  545. }
  546. protected function _getHeaderImageParams()
  547. {
  548. $CNF = &$this->_oConfig->CNF;
  549. return [
  550. 'field' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : false,
  551. 'field_position' => isset($CNF['FIELD_THUMB_POSITION']) ? $CNF['FIELD_THUMB_POSITION'] : false,
  552. 'storage' => isset($CNF['OBJECT_STORAGE']) ? $CNF['OBJECT_STORAGE'] : false,
  553. 'uploaders' => isset($CNF['OBJECT_UPLOADERS']) ? $CNF['OBJECT_UPLOADERS'] : false,
  554. 'transcoder_cover' => isset($CNF['OBJECT_IMAGES_TRANSCODER_COVER']) ? $CNF['OBJECT_IMAGES_TRANSCODER_COVER'] : false,
  555. ];
  556. }
  557. protected function _getHeaderImage($aData)
  558. {
  559. return $this->getModule()->getEntryImageData($aData);
  560. }
  561. function mediaExif ($aMediaInfo, $iProfileId = false, $sFuncAuthorDesc = '', $sTemplateName = 'media-exif.html')
  562. {
  563. if (empty($aMediaInfo['exif']))
  564. return '';
  565. $a = unserialize($aMediaInfo['exif']);
  566. $s = '';
  567. if (!empty($a['Make'])) {
  568. $oModule = BxDolModule::getInstance($this->MODULE);
  569. $CNF = &$oModule->_oConfig->CNF;
  570. $sCamera = BxDolMetatags::keywordsCameraModel($a);
  571. if (!empty($CNF['OBJECT_METATAGS_MEDIA_CAMERA'])) {
  572. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS_MEDIA_CAMERA']);
  573. if ($oMetatags->keywordsIsEnabled()) {
  574. $sCamera = $oMetatags->keywordsParseOne($aMediaInfo['id'], $sCamera);
  575. }
  576. }
  577. if (!empty($sCamera))
  578. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  579. 'key' => _t($CNF['T']['txt_media_exif_camera']),
  580. 'val' => $sCamera,
  581. ));
  582. }
  583. if (!empty($a['FocalLength']))
  584. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  585. 'key' => _t($CNF['T']['txt_media_exif_focal_length']),
  586. 'val' => _t($CNF['T']['txt_media_exif_focal_length_value'], $a['FocalLength']),
  587. ));
  588. if (!empty($a['COMPUTED']['ApertureFNumber']))
  589. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  590. 'key' => _t($CNF['T']['txt_media_exif_aperture']),
  591. 'val' => $a['COMPUTED']['ApertureFNumber'],
  592. ));
  593. if (!empty($a['ExposureTime']))
  594. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  595. 'key' => _t($CNF['T']['txt_media_exif_shutter_speed']),
  596. 'val' => _t($CNF['T']['txt_media_exif_shutter_speed_value'], $a['ExposureTime']),
  597. ));
  598. if (!empty($a['ISOSpeedRatings']))
  599. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  600. 'key' => _t($CNF['T']['txt_media_exif_iso']),
  601. 'val' => $a['ISOSpeedRatings'],
  602. ));
  603. if (empty($s))
  604. return '';
  605. return $this->parseHtmlByName($sTemplateName, array('content' => $s));
  606. }
  607. }
  608. /** @} */