BxBaseModTextTemplate.php 27 KB

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