1
0

BxBaseModTextTemplate.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  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. $CNF = &$this->_oConfig->CNF;
  369. if($isCheckPrivateContent && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $oModule->checkAllowedView($aData)))
  370. return $this->parseHtmlByName($sTemplateName ? str_replace('.html', '_private.html', $sTemplateName) : 'unit_private.html', [
  371. 'module_name' => _t($CNF['T']['txt_sample_single']),
  372. 'module_icon' => $CNF['ICON'],
  373. 'title' => _t('_sys_private_content'),
  374. 'summary' => $sMsg,
  375. 'ts' => $aData[$CNF['FIELD_ADDED']],
  376. ]);
  377. return '';
  378. }
  379. protected function getUnitThumbAndGallery ($aData)
  380. {
  381. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  382. $sPhotoThumb = '';
  383. $sPhotoGallery = '';
  384. if(!empty($CNF['FIELD_THUMB']) && !empty($aData[$CNF['FIELD_THUMB']])) {
  385. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  386. if ($oImagesTranscoder)
  387. $sPhotoThumb = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  388. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  389. if ($oImagesTranscoder)
  390. $sPhotoGallery = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  391. else
  392. $sPhotoGallery = $sPhotoThumb;
  393. }
  394. return array($sPhotoThumb, $sPhotoGallery);
  395. }
  396. protected function getUnit ($aData, $aParams = array())
  397. {
  398. $CNF = &$this->_oConfig->CNF;
  399. $oModule = $this->getModule();
  400. // get thumb url
  401. list($sPhotoThumb, $sPhotoGallery) = $this->getUnitThumbAndGallery($aData);
  402. if ($sPhotoGallery == '' && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  403. if(!empty($CNF['OBJECT_STORAGE_PHOTOS'])){
  404. $sStorage = $CNF['OBJECT_STORAGE_PHOTOS'];
  405. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  406. list($oTranscoder, $oTranscoderView) = $this->getAttachmentsImagesTranscoders($sStorage);
  407. $aGhostFiles = $oStorage->getGhosts($oModule->serviceGetContentOwnerProfileId($aData[$CNF['FIELD_ID']]), $aData[$CNF['FIELD_ID']]);
  408. if(!empty($aGhostFiles) && is_array($aGhostFiles)) {
  409. $aGhostFile = array_shift($aGhostFiles);
  410. $sPhotoThumb = $oTranscoderView->getFileUrl($aGhostFile['id']);
  411. $sPhotoGallery = $oTranscoder->getFileUrl($aGhostFile['id']);
  412. }
  413. }
  414. }
  415. $oProfile = BxDolProfile::getInstanceMagic($aData[$CNF['FIELD_AUTHOR']]);
  416. $sUrl = $this->getUnitLink($aData);
  417. $sTitle = $this->getUnitTitle($aData);
  418. $sText = $this->getUnitText($aData);
  419. $sSummary = $this->getUnitSummary($aData, $sTitle, $sText, $sUrl);
  420. $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'])) : '';
  421. if(!empty($CNF['OBJECT_METATAGS'])) {
  422. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  423. $sText = $oMetatags->metaParse($aData[$CNF['FIELD_ID']], $sText);
  424. }
  425. $aTmplVarsMeta = [];
  426. if(!empty($CNF['OBJECT_MENU_SNIPPET_META'])) {
  427. $oMenuMeta = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this);
  428. if($oMenuMeta) {
  429. $oMenuMeta->setContentId($aData[$CNF['FIELD_ID']]);
  430. if(isset($aParams['context']))
  431. $oMenuMeta->setContext($aParams['context']);
  432. $aTmplVarsMeta = [
  433. 'meta' => $oMenuMeta->getCode()
  434. ];
  435. }
  436. }
  437. $bBadgesSingle = isset($aParams['badges_single']) ? $aParams['badges_single'] : false;
  438. $bBadgesCompact = isset($aParams['badges_compact']) ? $aParams['badges_compact'] : false;
  439. $sCoverData = ($sKey = 'FIELD_THUMB_POSITION') && isset($CNF[$sKey], $aData[$CNF[$sKey]]) ? $aData[$CNF[$sKey]] : '';
  440. $sCoverSettings = ($sKey = 'FIELD_THUMB') && isset($CNF[$sKey]) ? $this->_getImageSettings($CNF[$sKey], $sCoverData, 'unit_cover') : '';
  441. $aTmplVars = array (
  442. 'class' => $this->_getUnitClass($aData,(isset($aParams['template_name']) ? $aParams['template_name'] : '')),
  443. 'html_id' => $this->_getUnitHtmlId($aData,(isset($aParams['template_name']) ? $aParams['template_name'] : '')),
  444. 'id' => $aData[$CNF['FIELD_ID']],
  445. 'content_url' => $sUrl,
  446. 'content_url_attrs' => '',
  447. 'bx_if:show_onclick' => [
  448. 'condition' => false,
  449. 'content' => [
  450. 'content_onclick' => ''
  451. ]
  452. ],
  453. 'title' => $sTitle,
  454. 'badges' => $oModule->serviceGetBadges($aData[$CNF['FIELD_ID']], $bBadgesSingle, $bBadgesCompact),
  455. 'title_attr' => bx_html_attribute($sTitle),
  456. 'summary' => $sSummary,
  457. 'text' => $sText,
  458. 'author' => $oProfile->getDisplayName(),
  459. 'author_url' => $oProfile->getUrl(),
  460. 'author_icon' => $oProfile->getIcon(),
  461. 'author_thumb' => $oProfile->getThumb(),
  462. 'author_avatar' => $oProfile->getAvatar(),
  463. 'entry_posting_date' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE),
  464. 'module_name' => _t($CNF['T']['txt_sample_single']),
  465. 'ts' => $aData[$CNF['FIELD_ADDED']],
  466. 'bx_if:meta' => array(
  467. 'condition' => !empty($aTmplVarsMeta),
  468. 'content' => $aTmplVarsMeta
  469. ),
  470. 'bx_if:thumb' => array (
  471. 'condition' => $sPhotoThumb,
  472. 'content' => array (
  473. 'title' => $sTitle,
  474. 'summary_attr' => bx_html_attribute($sSummaryPlain),
  475. 'content_url' => $sUrl,
  476. 'bx_if:show_thumb_onclick' => [
  477. 'condition' => false,
  478. 'content' => [
  479. 'content_onclick' => ''
  480. ]
  481. ],
  482. 'thumb_url' => $sPhotoThumb ? $sPhotoThumb : '',
  483. 'gallery_url' => $sPhotoGallery ? $sPhotoGallery : '',
  484. 'image_settings' => $sCoverSettings,
  485. 'strecher' => str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', 40),
  486. ),
  487. ),
  488. 'bx_if:no_thumb' => array (
  489. 'condition' => !$sPhotoThumb,
  490. 'content' => array (
  491. 'module_icon' => $CNF['ICON'],
  492. 'content_url' => $sUrl,
  493. 'bx_if:show_no_thumb_onclick' => [
  494. 'condition' => false,
  495. 'content' => [
  496. 'content_onclick' => ''
  497. ]
  498. ],
  499. 'summary_plain' => $sSummaryPlain,
  500. 'summary_attr' => bx_html_attribute($sSummaryPlain),
  501. 'strecher' => mb_strlen($sSummaryPlain) > 240 ? '' : str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', round((240 - mb_strlen($sSummaryPlain)) / 6)),
  502. ),
  503. ),
  504. 'unit_content_before' => '',
  505. 'unit_content_after' => ''
  506. );
  507. if(isset($aParams['template_vars']) && is_array($aParams['template_vars']))
  508. $aTmplVars = array_merge($aTmplVars, $aParams['template_vars']);
  509. // generate html
  510. return $aTmplVars;
  511. }
  512. protected function getAttachmentsImagesTranscoders ($sStorage = '')
  513. {
  514. $CNF = &$this->getModule()->_oConfig->CNF;
  515. $oTranscoder = null;
  516. $oTranscoderView = null;
  517. if(isset($CNF['OBJECT_STORAGE_PHOTOS']) && $CNF['OBJECT_STORAGE_PHOTOS'] == $sStorage) {
  518. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']))
  519. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']);
  520. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']))
  521. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']);
  522. else if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']))
  523. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']);
  524. }
  525. else if(isset($CNF['OBJECT_STORAGE_FILES']) && $CNF['OBJECT_STORAGE_FILES'] == $sStorage) {
  526. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES']))
  527. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES']);
  528. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']))
  529. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']);
  530. }
  531. else
  532. list($oTranscoder, $oTranscoderView) = parent::getAttachmentsImagesTranscoders($sStorage);
  533. return array($oTranscoder, $oTranscoderView);
  534. }
  535. protected function _getUnitName($aData, $sTemplateName = 'unit.html')
  536. {
  537. return trim(str_replace('.html', '', $sTemplateName));
  538. }
  539. protected function _getUnitClass($aData, $sTemplateName = 'unit.html')
  540. {
  541. $sResult = '';
  542. switch($sTemplateName) {
  543. case 'unit_showcase.html':
  544. $sResult = $this->_sUnitClassShowCase;
  545. break;
  546. }
  547. return $sResult;
  548. }
  549. protected function _getUnitHtmlId($aData, $sTemplateName = 'unit.html')
  550. {
  551. $CNF = &$this->_oConfig->CNF;
  552. return str_replace('_', '-', $this->MODULE . '_unit_' . $aData[$CNF['FIELD_ID']]);
  553. }
  554. protected function _getHeaderImageParams()
  555. {
  556. $CNF = &$this->_oConfig->CNF;
  557. return [
  558. 'field' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : false,
  559. 'field_position' => isset($CNF['FIELD_THUMB_POSITION']) ? $CNF['FIELD_THUMB_POSITION'] : false,
  560. 'storage' => isset($CNF['OBJECT_STORAGE']) ? $CNF['OBJECT_STORAGE'] : false,
  561. 'uploaders' => isset($CNF['OBJECT_UPLOADERS']) ? $CNF['OBJECT_UPLOADERS'] : false,
  562. 'transcoder_cover' => isset($CNF['OBJECT_IMAGES_TRANSCODER_COVER']) ? $CNF['OBJECT_IMAGES_TRANSCODER_COVER'] : false,
  563. ];
  564. }
  565. protected function _getHeaderImage($aData)
  566. {
  567. return $this->getModule()->getEntryImageData($aData);
  568. }
  569. function mediaExif ($aMediaInfo, $iProfileId = false, $sFuncAuthorDesc = '', $sTemplateName = 'media-exif.html')
  570. {
  571. if (empty($aMediaInfo['exif']))
  572. return '';
  573. $a = unserialize($aMediaInfo['exif']);
  574. $s = '';
  575. if (!empty($a['Make'])) {
  576. $oModule = BxDolModule::getInstance($this->MODULE);
  577. $CNF = &$oModule->_oConfig->CNF;
  578. $sCamera = BxDolMetatags::keywordsCameraModel($a);
  579. if (!empty($CNF['OBJECT_METATAGS_MEDIA_CAMERA'])) {
  580. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS_MEDIA_CAMERA']);
  581. if ($oMetatags->keywordsIsEnabled()) {
  582. $sCamera = $oMetatags->keywordsParseOne($aMediaInfo['id'], $sCamera);
  583. }
  584. }
  585. if (!empty($sCamera))
  586. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  587. 'key' => _t($CNF['T']['txt_media_exif_camera']),
  588. 'val' => $sCamera,
  589. ));
  590. }
  591. if (!empty($a['FocalLength']))
  592. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  593. 'key' => _t($CNF['T']['txt_media_exif_focal_length']),
  594. 'val' => _t($CNF['T']['txt_media_exif_focal_length_value'], $a['FocalLength']),
  595. ));
  596. if (!empty($a['COMPUTED']['ApertureFNumber']))
  597. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  598. 'key' => _t($CNF['T']['txt_media_exif_aperture']),
  599. 'val' => $a['COMPUTED']['ApertureFNumber'],
  600. ));
  601. if (!empty($a['ExposureTime']))
  602. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  603. 'key' => _t($CNF['T']['txt_media_exif_shutter_speed']),
  604. 'val' => _t($CNF['T']['txt_media_exif_shutter_speed_value'], $a['ExposureTime']),
  605. ));
  606. if (!empty($a['ISOSpeedRatings']))
  607. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  608. 'key' => _t($CNF['T']['txt_media_exif_iso']),
  609. 'val' => $a['ISOSpeedRatings'],
  610. ));
  611. if (empty($s))
  612. return '';
  613. return $this->parseHtmlByName($sTemplateName, array('content' => $s));
  614. }
  615. }
  616. /** @} */