BxBaseModTextTemplate.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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 getJsCode($sType, $aParams = array(), $bWrap = true)
  23. {
  24. $aParams = array_merge(array(
  25. 'aHtmlIds' => $this->_oConfig->getHtmlIds()
  26. ), $aParams);
  27. return parent::getJsCode($sType, $aParams, $bWrap);
  28. }
  29. function unit ($aData, $isCheckPrivateContent = true, $sTemplateName = 'unit.html', $aParams = array())
  30. {
  31. $sResult = $this->checkPrivacy ($aData, $isCheckPrivateContent, $this->getModule(), $sTemplateName);
  32. if($sResult)
  33. return $sResult;
  34. $aParams['template_name'] = $sTemplateName;
  35. return $this->parseHtmlByName($sTemplateName, $this->getUnit($aData, $aParams));
  36. }
  37. function entryAttachments ($aData, $aParams = array())
  38. {
  39. $CNF = &$this->getModule()->_oConfig->CNF;
  40. $aStoragesKeys = array('OBJECT_STORAGE_PHOTOS', 'OBJECT_STORAGE_VIDEOS', 'OBJECT_STORAGE_FILES');
  41. $aStorages = array();
  42. foreach($aStoragesKeys as $sKey)
  43. if(!empty($CNF[$sKey]))
  44. $aStorages[] = $CNF[$sKey];
  45. return $this->entryAttachmentsByStorage($aStorages, $aData, $aParams);
  46. }
  47. function entryAuthor ($aData, $iProfileId = false, $sFuncAuthorDesc = 'getAuthorDesc', $sTemplateName = 'author.html', $sFuncAuthorAddon = 'getAuthorAddon')
  48. {
  49. $CNF = &$this->getModule()->_oConfig->CNF;
  50. if (!$iProfileId)
  51. $iProfileId = $aData[$CNF['FIELD_AUTHOR']];
  52. $oProfile = BxDolProfile::getInstanceMagic($iProfileId);
  53. $sName = $oProfile->getDisplayName();
  54. $sAddon = $sFuncAuthorAddon && is_a($oProfile, 'BxDolProfile') ? $this->$sFuncAuthorAddon($aData, $oProfile) : '';
  55. $aVars = array (
  56. 'author_url' => $oProfile->getUrl(),
  57. 'author_thumb_url' => $oProfile->getThumb(),
  58. 'author_unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  59. 'author_title' => $sName,
  60. 'author_title_attr' => bx_html_attribute($sName),
  61. 'author_desc' => $sFuncAuthorDesc ? $this->$sFuncAuthorDesc($aData, $oProfile) : '',
  62. 'author_profile_desc' => $this->getAuthorProfileDesc($aData, $oProfile),
  63. 'bx_if:addon' => array (
  64. 'condition' => (bool)$sAddon,
  65. 'content' => array (
  66. 'content' => $sAddon,
  67. ),
  68. ),
  69. );
  70. return $this->parseHtmlByName($sTemplateName, $aVars);
  71. }
  72. function entryContext ($aData, $iProfileId = false, $sFuncContextDesc = 'getContextDesc', $sTemplateName = 'context.html', $sFuncContextAddon = 'getContextAddon')
  73. {
  74. $CNF = &$this->getModule()->_oConfig->CNF;
  75. $iContextId = $aData[$CNF['FIELD_ALLOW_VIEW_TO']];
  76. if ($iContextId >= 0)
  77. return '';
  78. $iProfileId = - $iContextId;
  79. $oProfile = BxDolProfile::getInstance($iProfileId);
  80. if (!$oProfile)
  81. $oProfile = BxDolProfileUndefined::getInstance();
  82. if (!$oProfile)
  83. return '';
  84. $sName = $oProfile->getDisplayName();
  85. $sAddon = $sFuncContextAddon ? $this->$sFuncContextAddon($aData, $oProfile) : '';
  86. $aVars = array (
  87. 'author_url' => $oProfile->getUrl(),
  88. 'author_thumb_url' => $oProfile->getThumb(),
  89. 'author_unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  90. 'author_title' => $sName,
  91. 'author_title_attr' => bx_html_attribute($sName),
  92. 'author_desc' => $sFuncContextDesc ? $this->$sFuncContextDesc($aData) : '',
  93. 'bx_if:addon' => array (
  94. 'condition' => (bool)$sAddon,
  95. 'content' => array (
  96. 'content' => $sAddon,
  97. ),
  98. ),
  99. );
  100. return $this->parseHtmlByName($sTemplateName, $aVars);
  101. }
  102. public function entryPolls($aData)
  103. {
  104. $CNF = &$this->getModule()->_oConfig->CNF;
  105. $aPolls = $this->_oDb->getPolls(array(
  106. 'type' => 'content_id',
  107. 'content_id' => $aData[$CNF['FIELD_ID']],
  108. ));
  109. if(empty($aPolls) || !is_array($aPolls))
  110. return;
  111. $iProfileId = bx_get_logged_profile_id();
  112. $sPolls = '';
  113. foreach($aPolls as $aPoll)
  114. $sPolls .= $this->getPollItem($aPoll, $iProfileId);
  115. if(empty($sPolls))
  116. return '';
  117. $this->addCss(array('polls.css'));
  118. $this->addJs(array('polls.js'));
  119. return $this->getJsCode('poll') . $this->parseHtmlByName('poll_items.html', array(
  120. 'polls' => $sPolls
  121. ));
  122. }
  123. public function entryPollAnswers($aPoll, $bDynamic = false)
  124. {
  125. $sContent = $this->_getPollAnswers($aPoll, $bDynamic);
  126. if(empty($sContent))
  127. return '';
  128. return array(
  129. 'content' => $sContent,
  130. 'menu' => $this->_getPollBlockMenu($aPoll, 'answers')
  131. );
  132. }
  133. public function entryPollResults($aPoll, $bDynamic = false)
  134. {
  135. $sContent = $this->_getPollResults($aPoll, $bDynamic);
  136. if(empty($sContent))
  137. return '';
  138. return array(
  139. 'content' => $sContent,
  140. 'menu' => $this->_getPollBlockMenu($aPoll, 'results')
  141. );
  142. }
  143. public function getPollForm()
  144. {
  145. $aForm = $this->getModule()->getPollForm();
  146. return $this->parseHtmlByName('poll_form.html', array(
  147. 'js_object' => $this->_oConfig->getJsObject('poll'),
  148. 'form_id' => $aForm['form_id'],
  149. 'form' => $aForm['form'],
  150. ));
  151. }
  152. public function getPollField($iContentId = 0, $iProfileId = 0)
  153. {
  154. if(empty($iProfileId))
  155. $iProfileId = bx_get_logged_profile_id();
  156. $aPolls = array();
  157. if(!empty($iContentId))
  158. $aPolls = array_merge($aPolls, $this->_oDb->getPolls(array(
  159. 'type' => 'content_id',
  160. 'content_id' => $iContentId,
  161. )));
  162. $aPolls = array_merge($aPolls, $this->_oDb->getPolls(array(
  163. 'type' => 'author_id',
  164. 'author_id' => $iProfileId,
  165. 'unused' => true
  166. )));
  167. $sPolls = '';
  168. foreach($aPolls as $aPoll)
  169. $sPolls .= $this->getPollItem($aPoll, $iProfileId, array(
  170. 'manage' => true
  171. ));
  172. return $this->parseHtmlByName('poll_form_field.html', array(
  173. 'html_id' => $this->_oConfig->getHtmlIds('add_poll_form_field'),
  174. 'polls' => $sPolls
  175. ));
  176. }
  177. public function getPollItem($mixedPoll, $iProfileId = 0, $aParams = array())
  178. {
  179. $CNF = &$this->getModule()->_oConfig->CNF;
  180. $aPoll = is_array($mixedPoll) ? $mixedPoll : $this->_oDb->getPolls(array('type' => 'id', 'id' => (int)$mixedPoll));
  181. if(empty($aPoll) || !is_array($aPoll))
  182. return '';
  183. $sJsObject = $this->_oConfig->getJsObject('poll');
  184. $bDynamic = isset($aParams['dynamic']) && $aParams['dynamic'] === true;
  185. $bManage = isset($aParams['manage']) && $aParams['manage'] === true;
  186. $bSwitchMenu = isset($aParams['switch_menu']) ? (bool)$aParams['switch_menu'] : true;
  187. $bForceDisplayAnswers = isset($aParams['force_display_answers']) && (bool)$aParams['force_display_answers'] === true;
  188. $iPollId = (int)$aPoll[$CNF['FIELD_POLL_ID']];
  189. $sPollView = !$bForceDisplayAnswers && $this->_oDb->isPollPerformed($iPollId, $iProfileId) ? 'results' : 'answers';
  190. $sMethod = '_getPoll' . ucfirst($sPollView);
  191. if(!method_exists($this, $sMethod))
  192. return '';
  193. $mixedMenu = '';
  194. if($bSwitchMenu)
  195. $mixedMenu = $this->_getPollBlockMenu($aPoll, $sPollView, array('template' => 'menu_interactive.html'));
  196. return $this->parseHtmlByName('poll_item.html', array(
  197. 'html_id' => $this->_oConfig->getHtmlIds('poll') . $iPollId,
  198. 'bx_if:show_input_hidden' => array(
  199. 'condition' => $bManage,
  200. 'content' => array(
  201. 'name' => $CNF['FIELD_POLL'],
  202. 'id' => $iPollId
  203. )
  204. ),
  205. 'action_menu' => !empty($mixedMenu) ? $mixedMenu->getCode() : '',
  206. 'bx_if:show_action_delete' => array(
  207. 'condition' => $bManage,
  208. 'content' => array(
  209. 'js_object' => $sJsObject,
  210. 'id' => $iPollId
  211. )
  212. ),
  213. 'text' => bx_process_output($aPoll[$CNF['FIELD_POLL_TEXT']], BX_DATA_HTML),
  214. 'content' => $this->$sMethod($aPoll, $bDynamic)
  215. ));
  216. }
  217. protected function _getPollAnswers($aPoll, $bDynamic = false)
  218. {
  219. $CNF = &$this->getModule()->_oConfig->CNF;
  220. $aAnswers = $this->_oDb->getPollAnswers(array('type' => 'poll_id', 'poll_id' => $aPoll[$CNF['FIELD_POLL_ID']]));
  221. if(empty($aAnswers) || !is_array($aAnswers))
  222. return '';
  223. $aTmplVarsAnswers = array();
  224. foreach($aAnswers as $aAnswer) {
  225. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES_POLL_ANSWERS'], $aAnswer['id']);
  226. $aTmplVarsAnswers[] = array(
  227. 'answer' => $oVotes->getElementBlock(array(
  228. 'dynamic_mode' => $bDynamic
  229. ))
  230. );
  231. }
  232. return $this->parseHtmlByName('poll_item_answers.html', array(
  233. 'html_id' => $this->_oConfig->getHtmlIds('poll_content') . $aPoll[$CNF['FIELD_POLL_ID']],
  234. 'bx_repeat:answers' => $aTmplVarsAnswers
  235. ));
  236. }
  237. protected function _getPollResults($aPoll, $bDynamic = false)
  238. {
  239. $CNF = &$this->getModule()->_oConfig->CNF;
  240. $aAnswers = $this->_oDb->getPollAnswers(array('type' => 'poll_id', 'poll_id' => $aPoll[$CNF['FIELD_POLL_ID']]));
  241. if(empty($aAnswers) || !is_array($aAnswers))
  242. return '';
  243. $iTotal = 0;
  244. foreach($aAnswers as $aAnswer)
  245. $iTotal += $aAnswer['votes'];
  246. $aTmplVarsAnswers = array();
  247. foreach($aAnswers as $aAnswer) {
  248. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES_POLL_ANSWERS'], $aAnswer['id']);
  249. $fPercent = $iTotal > 0 ? 100 * (float)$aAnswer['votes']/$iTotal : 0;
  250. $aTmplVarsAnswers[] = array(
  251. 'title' => bx_process_output($aAnswer['title']),
  252. 'width' => (int)round($fPercent) . '%',
  253. 'votes' => $oVotes->getCounter(array('show_counter_empty' => true, 'show_counter_in_brackets' => false)),
  254. 'percent' => _t($CNF['T']['txt_poll_answer_vote_percent'], $iTotal > 0 ? round($fPercent, 2) : 0),
  255. 'js_code' => $oVotes->getJsScript($bDynamic)
  256. );
  257. }
  258. return $this->parseHtmlByName('poll_item_results.html', array(
  259. 'html_id' => $this->_oConfig->getHtmlIds('poll_content') . $aPoll[$CNF['FIELD_POLL_ID']],
  260. 'bx_repeat:answers' => $aTmplVarsAnswers,
  261. ));
  262. }
  263. protected function _getPollBlockMenu($aPoll, $sSelected = '', $aParams = array())
  264. {
  265. $CNF = &$this->getModule()->_oConfig->CNF;
  266. $sPostfix = '-' . time() . rand(0, PHP_INT_MAX);
  267. $sJsObject = $this->_oConfig->getJsObject('poll');
  268. $iPollId = $aPoll[$CNF['FIELD_POLL_ID']];
  269. $aViews = array(
  270. 'answers' => true,
  271. 'results' => $CNF['PARAM_POLL_HIDDEN_RESULTS'] === false || $this->_oDb->isPollPerformed($iPollId, bx_get_logged_profile_id())
  272. );
  273. $aMenu = array();
  274. foreach($aViews as $sView => $bActive) {
  275. if(!$bActive)
  276. continue;
  277. $sId = $this->_oConfig->getHtmlIds('poll_view_link_' . $sView) . $iPollId;
  278. if(!empty($sSelected) && $sSelected == $sView)
  279. $sSelected = $sId;
  280. $aMenu[] = array('id' => $sId, 'name' => $sId, 'class' => '', 'link' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changePollView(this, \'' . $sView . '\', ' . $iPollId . ')', 'target' => '_self', 'title' => _t('_bx_posts_txt_poll_view_' . $sView));
  281. }
  282. if(count($aMenu) <= 1)
  283. return '';
  284. $oMenu = new BxTemplMenuInteractive(array(
  285. 'template' => !empty($aParams['template']) ? $aParams['template'] : 'menu_interactive_vertical.html',
  286. 'menu_id' => $this->_oConfig->getHtmlIds('poll_view_menu') . $sPostfix,
  287. 'menu_items' => $aMenu
  288. ));
  289. if(!empty($sSelected))
  290. $oMenu->setSelected('', $sSelected);
  291. return $oMenu;
  292. }
  293. public function getTmplVarsText($aData)
  294. {
  295. $CNF = &$this->getModule()->_oConfig->CNF;
  296. $aVars = parent::getTmplVarsText($aData);
  297. $sImage = '';
  298. $mixedImage = $this->_getHeaderImage($aData);
  299. if($mixedImage !== false) {
  300. if(!empty($mixedImage['object']))
  301. $o = BxDolStorage::getObjectInstance($mixedImage['object']);
  302. else if(!empty($mixedImage['transcoder']))
  303. $o = BxDolTranscoder::getObjectInstance($mixedImage['transcoder']);
  304. if($o)
  305. $sImage = $o->getFileUrlById($mixedImage['id']);
  306. }
  307. $aVars['content_description_before'] = '';
  308. $aVars['content_description_after'] = '';
  309. $aVars['bx_if:show_image'] = array(
  310. 'condition' => !empty($sImage),
  311. 'content' => array(
  312. 'entry_image' => $sImage
  313. )
  314. );
  315. if(!empty($CNF['OBJECT_REACTIONS'])) {
  316. $oReactions = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $aData[$CNF['FIELD_ID']]);
  317. if($oReactions)
  318. $aVars['content_description_after'] .= $oReactions->getCounter(array(
  319. 'show_counter' => true
  320. ));
  321. }
  322. return $aVars;
  323. }
  324. function getAuthorDesc($aData, $oProfile)
  325. {
  326. $CNF = &$this->getModule()->_oConfig->CNF;
  327. $aItem = array(
  328. 'bx_if:text' => array(
  329. 'condition' => false,
  330. 'content' => array(
  331. 'content' => ''
  332. )
  333. ),
  334. 'bx_if:link' => array(
  335. 'condition' => false,
  336. 'content' => array(
  337. 'link' => '',
  338. 'content' => ''
  339. )
  340. )
  341. );
  342. $aTmplVarsItems = array();
  343. if(!empty($CNF['FIELD_ADDED']) && !empty($aData[$CNF['FIELD_ADDED']]))
  344. $aTmplVarsItems[] = array_merge($aItem, array('bx_if:text' => array(
  345. 'condition' => true,
  346. 'content' => array(
  347. 'content' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE)
  348. )
  349. )));
  350. if(!empty($CNF['URI_AUTHOR_ENTRIES']))
  351. $aTmplVarsItems[] = array_merge($aItem, array('bx_if:link' => array(
  352. 'condition' => true,
  353. 'content' => array(
  354. 'link' => BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id=' . $oProfile->id()),
  355. 'content' => _t($CNF['T']['txt_all_entries_by'], $this->getModule()->_oDb->getEntriesNumByAuthor($oProfile->id()))
  356. )
  357. )));
  358. return $this->parseHtmlByName('author_desc.html', array(
  359. 'bx_repeat:items' => $aTmplVarsItems
  360. ));
  361. }
  362. function getAuthorProfileDesc ($aData, $oProfile)
  363. {
  364. $aSnippetMeta = $this->getProfileSnippetMenu($aData);
  365. if(empty($aSnippetMeta) || !is_array($aSnippetMeta) || !isset($aSnippetMeta['meta']))
  366. return '';
  367. return $aSnippetMeta['meta'];
  368. }
  369. function getContextDesc ($aData)
  370. {
  371. return '';
  372. }
  373. function getProfileSnippetMenu ($aData)
  374. {
  375. $CNF = &$this->getModule()->_oConfig->CNF;
  376. if (!($oProfile = BxDolProfile::getInstance($aData[$CNF['FIELD_AUTHOR']])))
  377. return array();
  378. return bx_srv($oProfile->getModule(), 'get_snippet_menu_vars', array($oProfile->id()));
  379. }
  380. function getAuthorAddon ($aData, $oProfile)
  381. {
  382. return '';
  383. }
  384. function getContextAddon ($aData, $oProfile)
  385. {
  386. $CNF = &$this->getModule()->_oConfig->CNF;
  387. $sUrl = 'page.php?i=' . $CNF['URI_ENTRIES_BY_CONTEXT'] . '&profile_id=' . $oProfile->id();
  388. $sUrl = BxDolPermalinks::getInstance()->permalink($sUrl);
  389. return _t($CNF['T']['txt_all_entries_in'], $sUrl, $oProfile->getDisplayName(), $this->getModule()->_oDb->getEntriesNumByContext($oProfile->id()));
  390. }
  391. protected function checkPrivacy ($aData, $isCheckPrivateContent, $oModule, $sTemplateName = '')
  392. {
  393. if ($isCheckPrivateContent && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $oModule->checkAllowedView($aData))) {
  394. $aVars = array (
  395. 'summary' => $sMsg,
  396. );
  397. return $this->parseHtmlByName($sTemplateName ? str_replace('.html', '_private.html', $sTemplateName) : 'unit_private.html', $aVars);
  398. }
  399. return '';
  400. }
  401. protected function getUnitThumbAndGallery ($aData)
  402. {
  403. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  404. $sPhotoThumb = '';
  405. $sPhotoGallery = '';
  406. if(!empty($CNF['FIELD_THUMB']) && !empty($aData[$CNF['FIELD_THUMB']])) {
  407. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  408. if ($oImagesTranscoder)
  409. $sPhotoThumb = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  410. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  411. if ($oImagesTranscoder)
  412. $sPhotoGallery = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  413. else
  414. $sPhotoGallery = $sPhotoThumb;
  415. }
  416. return array($sPhotoThumb, $sPhotoGallery);
  417. }
  418. protected function getUnit ($aData, $aParams = array())
  419. {
  420. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  421. // get thumb url
  422. list($sPhotoThumb, $sPhotoGallery) = $this->getUnitThumbAndGallery($aData);
  423. // get entry url
  424. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]);
  425. $oProfile = BxDolProfile::getInstanceMagic($aData[$CNF['FIELD_AUTHOR']]);
  426. $sTitle = $this->getTitle($aData);
  427. $sText = $this->getText($aData);
  428. $sSummary = $this->getSummary($aData, $sTitle, $sText, $sUrl);
  429. $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'])) : '';
  430. if(!empty($CNF['OBJECT_METATAGS'])) {
  431. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  432. $sText = $oMetatags->metaParse($aData[$CNF['FIELD_ID']], $sText);
  433. }
  434. $sTitle = bx_process_output($sTitle);
  435. $aTmplVarsMeta = array();
  436. if(!empty($CNF['OBJECT_MENU_SNIPPET_META'])) {
  437. $oMenuMeta = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this);
  438. if($oMenuMeta) {
  439. $oMenuMeta->setContentId($aData[$CNF['FIELD_ID']]);
  440. $aTmplVarsMeta = array(
  441. 'meta' => $oMenuMeta->getCode()
  442. );
  443. }
  444. }
  445. // generate html
  446. return array (
  447. 'class' => $this->_getUnitClass($aData,(isset($aParams['template_name']) ? $aParams['template_name'] : '')),
  448. 'id' => $aData[$CNF['FIELD_ID']],
  449. 'content_url' => $sUrl,
  450. 'title' => $sTitle,
  451. 'title_attr' => bx_html_attribute($sTitle),
  452. 'summary' => $sSummary,
  453. 'text' => $sText,
  454. 'author' => $oProfile->getDisplayName(),
  455. 'author_url' => $oProfile->getUrl(),
  456. 'author_icon' => $oProfile->getIcon(),
  457. 'author_thumb' => $oProfile->getThumb(),
  458. 'author_avatar' => $oProfile->getAvatar(),
  459. 'entry_posting_date' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE),
  460. 'module_name' => _t($CNF['T']['txt_sample_single']),
  461. 'ts' => $aData[$CNF['FIELD_ADDED']],
  462. 'bx_if:meta' => array(
  463. 'condition' => !empty($aTmplVarsMeta),
  464. 'content' => $aTmplVarsMeta
  465. ),
  466. 'bx_if:thumb' => array (
  467. 'condition' => $sPhotoThumb,
  468. 'content' => array (
  469. 'title' => $sTitle,
  470. 'summary_attr' => bx_html_attribute($sSummaryPlain),
  471. 'content_url' => $sUrl,
  472. 'thumb_url' => $sPhotoThumb ? $sPhotoThumb : '',
  473. 'gallery_url' => $sPhotoGallery ? $sPhotoGallery : '',
  474. 'strecher' => str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', 40),
  475. ),
  476. ),
  477. 'bx_if:no_thumb' => array (
  478. 'condition' => !$sPhotoThumb,
  479. 'content' => array (
  480. 'module_icon' => $CNF['ICON'],
  481. 'content_url' => $sUrl,
  482. 'summary_plain' => $sSummaryPlain,
  483. 'strecher' => mb_strlen($sSummaryPlain) > 240 ? '' : str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', round((240 - mb_strlen($sSummaryPlain)) / 6)),
  484. ),
  485. ),
  486. );
  487. }
  488. protected function getTitle($aData)
  489. {
  490. $CNF = &$this->getModule()->_oConfig->CNF;
  491. return isset($aData[$CNF['FIELD_TITLE']]) ? $aData[$CNF['FIELD_TITLE']] : '';
  492. }
  493. protected function getText($aData)
  494. {
  495. $CNF = &$this->getModule()->_oConfig->CNF;
  496. return isset($aData[$CNF['FIELD_TEXT']]) ? $aData[$CNF['FIELD_TEXT']] : '';
  497. }
  498. protected function getSummary($aData, $sTitle = '', $sText = '', $sUrl = '')
  499. {
  500. $CNF = &$this->getModule()->_oConfig->CNF;
  501. if(empty($CNF['PARAM_CHARS_SUMMARY']))
  502. return '';
  503. // get summary
  504. $sLinkMore = ' <a title="' . bx_html_attribute(_t('_sys_read_more', $sTitle)) . '" href="' . $sUrl . '"><i class="sys-icon ellipsis-h"></i></a>';
  505. return strmaxtextlen($sText, (int)getParam($CNF['PARAM_CHARS_SUMMARY']), $sLinkMore);
  506. }
  507. protected function getAttachmentsImagesTranscoders ($sStorage = '')
  508. {
  509. $CNF = &$this->getModule()->_oConfig->CNF;
  510. $oTranscoder = null;
  511. $oTranscoderView = null;
  512. switch($sStorage) {
  513. case $CNF['OBJECT_STORAGE_PHOTOS']:
  514. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']))
  515. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']);
  516. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']))
  517. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']);
  518. break;
  519. case $CNF['OBJECT_STORAGE_FILES']:
  520. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES']))
  521. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES']);
  522. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']))
  523. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']);
  524. break;
  525. }
  526. return array($oTranscoder, $oTranscoderView);
  527. }
  528. protected function _getUnitClass($aData, $sTemplateName = 'unit.html')
  529. {
  530. $sResult = '';
  531. switch($sTemplateName) {
  532. case 'unit_showcase.html':
  533. $sResult = $this->_sUnitClassShowCase;
  534. break;
  535. }
  536. return $sResult;
  537. }
  538. protected function _getHeaderImage($aData)
  539. {
  540. return $this->getModule()->getEntryImageData($aData);
  541. }
  542. }
  543. /** @} */