BxBaseModTextTemplate.php 29 KB

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