BxBaseModTextTemplate.php 25 KB

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