BxBaseModTextTemplate.php 29 KB

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