BxBaseModTextTemplate.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  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. if(!empty($aParams['template_name']))
  34. $sTemplateName = $aParams['template_name'];
  35. else
  36. $aParams['template_name'] = $sTemplateName;
  37. $sResult = $this->checkPrivacy ($aData, $isCheckPrivateContent, $this->getModule(), $sTemplateName);
  38. if($sResult)
  39. return $sResult;
  40. $aTemplateVars = $this->getUnit($aData, $aParams);
  41. bx_alert($this->getModule()->getName(), 'unit', 0, 0, array(
  42. 'data' => $aData,
  43. 'check_private_content' => $isCheckPrivateContent,
  44. 'template' => $sTemplateName,
  45. 'params' => $aParams,
  46. 'tmpl_name' => &$sTemplateName,
  47. 'tmpl_vars' => &$aTemplateVars
  48. ));
  49. return $this->parseHtmlByName($sTemplateName, $aTemplateVars);
  50. }
  51. function entryAttachments ($aData, $aParams = array())
  52. {
  53. $CNF = &$this->getModule()->_oConfig->CNF;
  54. $aStoragesKeys = array('OBJECT_STORAGE_PHOTOS', 'OBJECT_STORAGE_VIDEOS', 'OBJECT_STORAGE_SOUNDS', 'OBJECT_STORAGE_FILES');
  55. $aStorages = array();
  56. foreach($aStoragesKeys as $sKey)
  57. if(!empty($CNF[$sKey]))
  58. $aStorages[] = $CNF[$sKey];
  59. if(!empty($aStorages))
  60. return $this->entryAttachmentsByStorage($aStorages, $aData, array_merge($aParams, array('filter_field' => '')));
  61. return parent::entryAttachments($aData, $aParams);
  62. }
  63. function entryAuthor ($aData, $iProfileId = false, $sFuncAuthorDesc = 'getAuthorDesc', $sTemplateName = 'author.html', $sFuncAuthorAddon = 'getAuthorAddon')
  64. {
  65. $CNF = &$this->getModule()->_oConfig->CNF;
  66. if (!$iProfileId)
  67. $iProfileId = $aData[$CNF['FIELD_AUTHOR']];
  68. $oProfile = BxDolProfile::getInstanceMagic($iProfileId);
  69. $sName = $oProfile->getDisplayName();
  70. $sAddon = $sFuncAuthorAddon && is_a($oProfile, 'BxDolProfile') ? $this->$sFuncAuthorAddon($aData, $oProfile) : '';
  71. $aVars = array (
  72. 'author_url' => $oProfile->getUrl(),
  73. 'author_thumb_url' => $oProfile->getThumb(),
  74. 'author_unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  75. 'author_title' => $sName,
  76. 'author_title_attr' => bx_html_attribute($sName),
  77. 'author_desc' => $sFuncAuthorDesc ? $this->$sFuncAuthorDesc($aData, $oProfile) : '',
  78. 'author_profile_desc' => $this->getAuthorProfileDesc($aData, $oProfile),
  79. 'bx_if:addon' => array (
  80. 'condition' => (bool)$sAddon,
  81. 'content' => array (
  82. 'content' => $sAddon,
  83. ),
  84. ),
  85. );
  86. return $this->parseHtmlByName($sTemplateName, $aVars);
  87. }
  88. public function entryBreadcrumb($aContentInfo, $aTmplVarsItems = array())
  89. {
  90. if(!empty($aTmplVarsItems) && is_array($aTmplVarsItems))
  91. return parent::entryBreadcrumb($aContentInfo, $aTmplVarsItems);
  92. $CNF = &$this->getModule()->_oConfig->CNF;
  93. $aTmplVarsItems = array();
  94. if(!empty($CNF['OBJECT_CATEGORY']) && !empty($CNF['FIELD_CATEGORY'])) {
  95. $oCategory = BxDolCategory::getObjectInstance($CNF['OBJECT_CATEGORY']);
  96. $aTmplVarsItems[] = array(
  97. 'url' => $oCategory->getCategoryUrl($aContentInfo[$CNF['FIELD_CATEGORY']]),
  98. 'title' => $oCategory->getCategoryTitle($aContentInfo[$CNF['FIELD_CATEGORY']])
  99. );
  100. }
  101. $aTmplVarsItems[] = array(
  102. 'url' => BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  103. 'title' => bx_process_output($aContentInfo[$CNF['FIELD_TITLE']])
  104. );
  105. return parent::entryBreadcrumb($aContentInfo, $aTmplVarsItems);
  106. }
  107. public function entryPolls($aData)
  108. {
  109. $CNF = &$this->getModule()->_oConfig->CNF;
  110. $aPolls = $this->_oDb->getPolls(array(
  111. 'type' => 'content_id',
  112. 'content_id' => $aData[$CNF['FIELD_ID']],
  113. ));
  114. if(empty($aPolls) || !is_array($aPolls))
  115. return;
  116. $iProfileId = bx_get_logged_profile_id();
  117. $sPolls = '';
  118. foreach($aPolls as $aPoll)
  119. $sPolls .= $this->getPollItem($aPoll, $iProfileId);
  120. if(empty($sPolls))
  121. return '';
  122. $this->_addCssJs();
  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. $oModule = $this->getModule();
  184. $CNF = &$oModule->_oConfig->CNF;
  185. $aPoll = is_array($mixedPoll) ? $mixedPoll : $this->_oDb->getPolls(array('type' => 'id', 'id' => (int)$mixedPoll));
  186. if(empty($aPoll) || !is_array($aPoll))
  187. return '';
  188. $sJsObject = $this->_oConfig->getJsObject('poll');
  189. $bDynamic = isset($aParams['dynamic']) && $aParams['dynamic'] === true;
  190. $bManage = isset($aParams['manage']) && $aParams['manage'] === true;
  191. $bSwitchMenu = isset($aParams['switch_menu']) ? (bool)$aParams['switch_menu'] : true;
  192. $bForceDisplayAnswers = isset($aParams['force_display_answers']) && (bool)$aParams['force_display_answers'] === true;
  193. $iPollId = (int)$aPoll[$CNF['FIELD_POLL_ID']];
  194. $sPollView = !$bForceDisplayAnswers && $oModule->isPollPerformed($iPollId, $iProfileId) ? 'results' : 'answers';
  195. $sMethod = '_getPoll' . ucfirst($sPollView);
  196. if(!method_exists($this, $sMethod))
  197. return '';
  198. $mixedMenu = '';
  199. if($bSwitchMenu)
  200. $mixedMenu = $this->_getPollBlockMenu($aPoll, $sPollView, array('template' => 'menu_interactive.html'));
  201. return $this->parseHtmlByName('poll_item.html', array(
  202. 'html_id' => $this->_oConfig->getHtmlIds('poll') . $iPollId,
  203. 'bx_if:show_input_hidden' => array(
  204. 'condition' => $bManage,
  205. 'content' => array(
  206. 'name' => $CNF['FIELD_POLL'],
  207. 'id' => $iPollId
  208. )
  209. ),
  210. 'action_menu' => !empty($mixedMenu) ? $mixedMenu->getCode() : '',
  211. 'bx_if:show_action_embed' => array(
  212. 'condition' => $bManage,
  213. 'content' => array(
  214. 'js_object' => $sJsObject,
  215. 'id' => $iPollId
  216. )
  217. ),
  218. 'bx_if:show_action_delete' => array(
  219. 'condition' => $bManage,
  220. 'content' => array(
  221. 'js_object' => $sJsObject,
  222. 'id' => $iPollId
  223. )
  224. ),
  225. 'text' => bx_process_output($aPoll[$CNF['FIELD_POLL_TEXT']], BX_DATA_TEXT),
  226. 'content' => $this->$sMethod($aPoll, $bDynamic)
  227. ));
  228. }
  229. public function embedPollItem($mixedPoll, $aParams = array())
  230. {
  231. $CNF = &$this->getModule()->_oConfig->CNF;
  232. $sHeader = '';
  233. $sContent = $this->getPollItem($mixedPoll, 0, $aParams);
  234. if(!empty($sContent)) {
  235. $aPoll = is_array($mixedPoll) ? $mixedPoll : $this->_oDb->getPolls(array('type' => 'id', 'id' => (int)$mixedPoll));
  236. $sHeader = strmaxtextlen($aPoll[$CNF['FIELD_POLL_TEXT']], 32, '...');
  237. $sContent = $this->getJsCode('poll') . $sContent;
  238. }
  239. $this->_addCssJs();
  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. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  255. $aPolls = $this->_oDb->getPolls(array('type' => 'content_id', 'content_id' => $iContentId));
  256. if(empty($aPolls) || !is_array($aPolls))
  257. return;
  258. $iPolls = 0;
  259. $sContent = '';
  260. foreach($aPolls as $aPoll) {
  261. $sPoll = $this->getPollItem($aPoll, 0, $aParams);
  262. if(empty($sPoll))
  263. continue;
  264. $sContent .= $sPoll;
  265. $iPolls += 1;
  266. }
  267. if(!empty($sContent) && isset($aParams['showcase']) && (bool)$aParams['showcase'] === true) {
  268. $this->addJs(array('flickity/flickity.pkgd.min.js'));
  269. $this->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flickity/|flickity.css');
  270. $sContent = $this->parseHtmlByName('poll_items_showcase.html', array(
  271. 'js_object' => $this->_oConfig->getJsObject('poll'),
  272. 'html_id' => $this->_oConfig->getHtmlIds('polls_showcase') . $iContentId,
  273. 'type' => $iPolls == 1 ? 'single' : 'multiple',
  274. 'polls' => $sContent
  275. ));
  276. }
  277. $sHeader = '';
  278. if(!empty($sContent)) {
  279. $sHeader = strmaxtextlen($aContentInfo[$CNF['FIELD_TITLE']], 32, '...');
  280. $sContent = $this->getJsCode('poll') . $sContent;
  281. }
  282. $this->_addCssJs();
  283. $oTemplate = BxDolTemplate::getInstance();
  284. $oTemplate->addCssStyle($CNF['STYLES_POLLS_EMBED_CLASS'], $CNF['STYLES_POLLS_EMBED_CONTENT']);
  285. $oTemplate->setPageNameIndex(BX_PAGE_EMBED);
  286. $oTemplate->setPageHeader($sHeader);
  287. $oTemplate->setPageContent('page_main_code', $sContent);
  288. $oTemplate->getPageCode();
  289. exit;
  290. }
  291. protected function _addCssJs()
  292. {
  293. $this->addJs(array(
  294. 'modules/base/text/js/|polls.js',
  295. 'polls.js'
  296. ));
  297. $this->addCss(array('polls.css'));
  298. }
  299. protected function _getPollAnswers($aPoll, $bDynamic = false)
  300. {
  301. $CNF = &$this->getModule()->_oConfig->CNF;
  302. $aAnswers = $this->_oDb->getPollAnswers(array('type' => 'poll_id', 'poll_id' => $aPoll[$CNF['FIELD_POLL_ID']]));
  303. if(empty($aAnswers) || !is_array($aAnswers))
  304. return '';
  305. $aTmplVarsAnswers = array();
  306. foreach($aAnswers as $aAnswer) {
  307. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES_POLL_ANSWERS'], $aAnswer['id']);
  308. $aTmplVarsAnswers[] = array(
  309. 'answer' => $oVotes->getElementBlock(array(
  310. 'dynamic_mode' => $bDynamic
  311. ))
  312. );
  313. }
  314. return $this->parseHtmlByName('poll_item_answers.html', array(
  315. 'html_id' => $this->_oConfig->getHtmlIds('poll_content') . $aPoll[$CNF['FIELD_POLL_ID']],
  316. 'bx_repeat:answers' => $aTmplVarsAnswers
  317. ));
  318. }
  319. protected function _getPollResults($aPoll, $bDynamic = false)
  320. {
  321. $CNF = &$this->getModule()->_oConfig->CNF;
  322. $aAnswers = $this->_oDb->getPollAnswers(array('type' => 'poll_id', 'poll_id' => $aPoll[$CNF['FIELD_POLL_ID']]));
  323. if(empty($aAnswers) || !is_array($aAnswers))
  324. return '';
  325. $iTotal = 0;
  326. foreach($aAnswers as $aAnswer)
  327. $iTotal += $aAnswer['votes'];
  328. $aTmplVarsAnswers = array();
  329. foreach($aAnswers as $aAnswer) {
  330. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES_POLL_ANSWERS'], $aAnswer['id']);
  331. $aVotesParams = array('show_counter_empty' => true, 'show_counter_in_brackets' => false, 'dynamic_mode' => $bDynamic);
  332. $fPercent = $iTotal > 0 ? 100 * (float)$aAnswer['votes']/$iTotal : 0;
  333. $aTmplVarsAnswers[] = array(
  334. 'title' => bx_process_output($aAnswer['title']),
  335. 'width' => (int)round($fPercent) . '%',
  336. 'votes' => $oVotes->getCounter($aVotesParams),
  337. 'percent' => _t($CNF['T']['txt_poll_answer_vote_percent'], $iTotal > 0 ? round($fPercent, 2) : 0)
  338. );
  339. }
  340. return $this->parseHtmlByName('poll_item_results.html', array(
  341. 'html_id' => $this->_oConfig->getHtmlIds('poll_content') . $aPoll[$CNF['FIELD_POLL_ID']],
  342. 'bx_repeat:answers' => $aTmplVarsAnswers,
  343. ));
  344. }
  345. protected function _getPollBlockMenu($aPoll, $sSelected = '', $aParams = array())
  346. {
  347. $oModule = $this->getModule();
  348. $CNF = &$oModule->_oConfig->CNF;
  349. $sPostfix = '-' . time() . rand(0, PHP_INT_MAX);
  350. $sJsObject = $this->_oConfig->getJsObject('poll');
  351. $iPollId = $aPoll[$CNF['FIELD_POLL_ID']];
  352. $aViews = array(
  353. 'answers' => true,
  354. 'results' => $CNF['PARAM_POLL_HIDDEN_RESULTS'] === false || $oModule->isPollPerformed($iPollId)
  355. );
  356. $aMenu = array();
  357. foreach($aViews as $sView => $bActive) {
  358. if(!$bActive)
  359. continue;
  360. $sId = $this->_oConfig->getHtmlIds('poll_view_link_' . $sView) . $iPollId;
  361. if(!empty($sSelected) && $sSelected == $sView)
  362. $sSelected = $sId;
  363. $aMenu[] = array(
  364. 'id' => $sId,
  365. 'name' => $sId,
  366. 'class' => '',
  367. 'link' => 'javascript:void(0)',
  368. 'onclick' => 'javascript:' . $sJsObject . '.changePollView(this, \'' . $sView . '\', ' . $iPollId . ')',
  369. 'target' => '_self',
  370. 'title_attr' => _t($CNF['T']['txt_poll_menu_view_' . $sView]),
  371. 'title' => $this->parseIcon($CNF['ICON_POLLS_' . strtoupper($sView)])
  372. );
  373. }
  374. if(count($aMenu) <= 1)
  375. return '';
  376. $oMenu = new BxTemplMenuInteractive(array(
  377. 'template' => !empty($aParams['template']) ? $aParams['template'] : 'menu_interactive_vertical.html',
  378. 'menu_id' => $this->_oConfig->getHtmlIds('poll_view_menu') . $sPostfix,
  379. 'menu_items' => $aMenu
  380. ));
  381. if(!empty($sSelected))
  382. $oMenu->setSelected('', $sSelected);
  383. return $oMenu;
  384. }
  385. public function getTmplVarsText($aData)
  386. {
  387. $CNF = &$this->getModule()->_oConfig->CNF;
  388. $aVars = parent::getTmplVarsText($aData);
  389. $sImage = '';
  390. $mixedImage = $this->_getHeaderImage($aData);
  391. if($mixedImage !== false) {
  392. if(!empty($mixedImage['object']))
  393. $o = BxDolStorage::getObjectInstance($mixedImage['object']);
  394. else if(!empty($mixedImage['transcoder']))
  395. $o = BxDolTranscoder::getObjectInstance($mixedImage['transcoder']);
  396. if($o)
  397. $sImage = $o->getFileUrlById($mixedImage['id']);
  398. }
  399. $aVars['content_description_before'] = '';
  400. $aVars['content_description_after'] = '';
  401. $aVars['bx_if:show_image'] = array(
  402. 'condition' => !empty($sImage),
  403. 'content' => array(
  404. 'entry_image' => $sImage
  405. )
  406. );
  407. if(!empty($CNF['OBJECT_REACTIONS'])) {
  408. $oReactions = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $aData[$CNF['FIELD_ID']]);
  409. if($oReactions)
  410. $aVars['content_description_after'] .= $oReactions->getCounter(array(
  411. 'show_counter' => true
  412. ));
  413. }
  414. return $aVars;
  415. }
  416. function getAuthorDesc($aData, $oProfile)
  417. {
  418. $CNF = &$this->getModule()->_oConfig->CNF;
  419. $aItem = array(
  420. 'bx_if:text' => array(
  421. 'condition' => false,
  422. 'content' => array(
  423. 'content' => ''
  424. )
  425. ),
  426. 'bx_if:link' => array(
  427. 'condition' => false,
  428. 'content' => array(
  429. 'link' => '',
  430. 'content' => ''
  431. )
  432. )
  433. );
  434. $aTmplVarsItems = array();
  435. if(!empty($CNF['FIELD_ADDED']) && !empty($aData[$CNF['FIELD_ADDED']]))
  436. $aTmplVarsItems[] = array_merge($aItem, array('bx_if:text' => array(
  437. 'condition' => true,
  438. 'content' => array(
  439. 'content' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE)
  440. )
  441. )));
  442. if(!empty($CNF['URI_AUTHOR_ENTRIES']))
  443. $aTmplVarsItems[] = array_merge($aItem, array('bx_if:link' => array(
  444. 'condition' => true,
  445. 'content' => array(
  446. 'link' => BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id=' . $oProfile->id()),
  447. 'content' => _t($CNF['T']['txt_all_entries_by'], $this->getModule()->_oDb->getEntriesNumByAuthor($oProfile->id()))
  448. )
  449. )));
  450. return $this->parseHtmlByName('author_desc.html', array(
  451. 'bx_repeat:items' => $aTmplVarsItems
  452. ));
  453. }
  454. function getAuthorProfileDesc ($aData, $oProfile)
  455. {
  456. $aSnippetMeta = $this->getProfileSnippetMenu($aData);
  457. if(empty($aSnippetMeta) || !is_array($aSnippetMeta) || !isset($aSnippetMeta['meta']))
  458. return '';
  459. return $aSnippetMeta['meta'];
  460. }
  461. function getProfileSnippetMenu ($aData)
  462. {
  463. $CNF = &$this->getModule()->_oConfig->CNF;
  464. if (!($oProfile = BxDolProfile::getInstance($aData[$CNF['FIELD_AUTHOR']])))
  465. return array();
  466. return bx_srv($oProfile->getModule(), 'get_snippet_menu_vars', array($oProfile->id()));
  467. }
  468. function getAuthorAddon ($aData, $oProfile)
  469. {
  470. return '';
  471. }
  472. protected function checkPrivacy ($aData, $isCheckPrivateContent, $oModule, $sTemplateName = '')
  473. {
  474. if ($isCheckPrivateContent && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $oModule->checkAllowedView($aData))) {
  475. $aVars = array (
  476. 'summary' => $sMsg,
  477. );
  478. return $this->parseHtmlByName($sTemplateName ? str_replace('.html', '_private.html', $sTemplateName) : 'unit_private.html', $aVars);
  479. }
  480. return '';
  481. }
  482. protected function getUnitThumbAndGallery ($aData)
  483. {
  484. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  485. $sPhotoThumb = '';
  486. $sPhotoGallery = '';
  487. if(!empty($CNF['FIELD_THUMB']) && !empty($aData[$CNF['FIELD_THUMB']])) {
  488. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  489. if ($oImagesTranscoder)
  490. $sPhotoThumb = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  491. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  492. if ($oImagesTranscoder)
  493. $sPhotoGallery = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  494. else
  495. $sPhotoGallery = $sPhotoThumb;
  496. }
  497. return array($sPhotoThumb, $sPhotoGallery);
  498. }
  499. protected function getUnit ($aData, $aParams = array())
  500. {
  501. $oModule = BxDolModule::getInstance($this->MODULE);
  502. $CNF = &$oModule->_oConfig->CNF;
  503. // get thumb url
  504. list($sPhotoThumb, $sPhotoGallery) = $this->getUnitThumbAndGallery($aData);
  505. if ($sPhotoGallery == '' && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  506. if(!empty($CNF['OBJECT_STORAGE_PHOTOS'])){
  507. $sStorage = $CNF['OBJECT_STORAGE_PHOTOS'];
  508. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  509. list($oTranscoder, $oTranscoderPreview) = $this->getAttachmentsImagesTranscoders($sStorage);
  510. $aGhostFiles = $oStorage->getGhosts ($this->getModule()->serviceGetContentOwnerProfileId($aData[$CNF['FIELD_ID']]), $aData[$CNF['FIELD_ID']]);
  511. if ($aGhostFiles){
  512. foreach ($aGhostFiles as $k => $a) {
  513. $sPhotoGallery = $oTranscoder->getFileUrl($a['id']);
  514. $sPhotoThumb = $oTranscoderPreview->getFileUrl($a['id']);
  515. break;
  516. }
  517. }
  518. }
  519. }
  520. // get entry url
  521. $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]);
  522. $oProfile = BxDolProfile::getInstanceMagic($aData[$CNF['FIELD_AUTHOR']]);
  523. $sTitle = $this->getTitle($aData);
  524. $sText = $this->getText($aData);
  525. $sSummary = $this->getSummary($aData, $sTitle, $sText, $sUrl);
  526. $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'])) : '';
  527. if(!empty($CNF['OBJECT_METATAGS'])) {
  528. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  529. $sText = $oMetatags->metaParse($aData[$CNF['FIELD_ID']], $sText);
  530. }
  531. $aTmplVarsMeta = array();
  532. if(!empty($CNF['OBJECT_MENU_SNIPPET_META'])) {
  533. $oMenuMeta = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this);
  534. if($oMenuMeta) {
  535. $oMenuMeta->setContentId($aData[$CNF['FIELD_ID']]);
  536. $aTmplVarsMeta = array(
  537. 'meta' => $oMenuMeta->getCode()
  538. );
  539. }
  540. }
  541. $aTmplVars = array (
  542. 'class' => $this->_getUnitClass($aData,(isset($aParams['template_name']) ? $aParams['template_name'] : '')),
  543. 'id' => $aData[$CNF['FIELD_ID']],
  544. 'content_url' => $sUrl,
  545. 'title' => $sTitle,
  546. 'badges' => $oModule->serviceGetBadges($aData[$CNF['FIELD_ID']], false, true),
  547. 'title_attr' => bx_html_attribute($sTitle),
  548. 'summary' => $sSummary,
  549. 'text' => $sText,
  550. 'author' => $oProfile->getDisplayName(),
  551. 'author_url' => $oProfile->getUrl(),
  552. 'author_icon' => $oProfile->getIcon(),
  553. 'author_thumb' => $oProfile->getThumb(),
  554. 'author_avatar' => $oProfile->getAvatar(),
  555. 'entry_posting_date' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE),
  556. 'module_name' => _t($CNF['T']['txt_sample_single']),
  557. 'ts' => $aData[$CNF['FIELD_ADDED']],
  558. 'bx_if:meta' => array(
  559. 'condition' => !empty($aTmplVarsMeta),
  560. 'content' => $aTmplVarsMeta
  561. ),
  562. 'bx_if:thumb' => array (
  563. 'condition' => $sPhotoThumb,
  564. 'content' => array (
  565. 'title' => $sTitle,
  566. 'summary_attr' => bx_html_attribute($sSummaryPlain),
  567. 'content_url' => $sUrl,
  568. 'thumb_url' => $sPhotoThumb ? $sPhotoThumb : '',
  569. 'gallery_url' => $sPhotoGallery ? $sPhotoGallery : '',
  570. 'strecher' => str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', 40),
  571. ),
  572. ),
  573. 'bx_if:no_thumb' => array (
  574. 'condition' => !$sPhotoThumb,
  575. 'content' => array (
  576. 'module_icon' => $CNF['ICON'],
  577. 'content_url' => $sUrl,
  578. 'summary_plain' => $sSummaryPlain,
  579. 'strecher' => mb_strlen($sSummaryPlain) > 240 ? '' : str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', round((240 - mb_strlen($sSummaryPlain)) / 6)),
  580. ),
  581. ),
  582. );
  583. if(isset($aParams['template_vars']) && is_array($aParams['template_vars']))
  584. $aTmplVars = array_merge($aTmplVars, $aParams['template_vars']);
  585. // generate html
  586. return $aTmplVars;
  587. }
  588. protected function getAttachmentsImagesTranscoders ($sStorage = '')
  589. {
  590. $CNF = &$this->getModule()->_oConfig->CNF;
  591. $oTranscoder = null;
  592. $oTranscoderView = null;
  593. if(isset($CNF['OBJECT_STORAGE_PHOTOS']) && $CNF['OBJECT_STORAGE_PHOTOS'] == $sStorage) {
  594. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']))
  595. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']);
  596. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']))
  597. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']);
  598. }
  599. else if(isset($CNF['OBJECT_STORAGE_FILES']) && $CNF['OBJECT_STORAGE_FILES'] == $sStorage) {
  600. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES']))
  601. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES']);
  602. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']))
  603. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']);
  604. }
  605. else
  606. list($oTranscoder, $oTranscoderView) = parent::getAttachmentsImagesTranscoders($sStorage);
  607. return array($oTranscoder, $oTranscoderView);
  608. }
  609. protected function _getUnitClass($aData, $sTemplateName = 'unit.html')
  610. {
  611. $sResult = '';
  612. switch($sTemplateName) {
  613. case 'unit_showcase.html':
  614. $sResult = $this->_sUnitClassShowCase;
  615. break;
  616. }
  617. return $sResult;
  618. }
  619. protected function _getHeaderImage($aData)
  620. {
  621. return $this->getModule()->getEntryImageData($aData);
  622. }
  623. function mediaExif ($aMediaInfo, $iProfileId = false, $sFuncAuthorDesc = '', $sTemplateName = 'media-exif.html')
  624. {
  625. if (!$aMediaInfo['exif'])
  626. return '';
  627. $a = unserialize($aMediaInfo['exif']);
  628. $s = '';
  629. if (!empty($a['Make'])) {
  630. $oModule = BxDolModule::getInstance($this->MODULE);
  631. $CNF = &$oModule->_oConfig->CNF;
  632. $sCamera = BxDolMetatags::keywordsCameraModel($a);
  633. if (!empty($CNF['OBJECT_METATAGS_MEDIA_CAMERA'])) {
  634. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS_MEDIA_CAMERA']);
  635. if ($oMetatags->keywordsIsEnabled()) {
  636. $sCamera = $oMetatags->keywordsParseOne($aMediaInfo['id'], $sCamera);
  637. }
  638. }
  639. if (!empty($sCamera))
  640. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  641. 'key' => _t($CNF['T']['txt_media_exif_camera']),
  642. 'val' => $sCamera,
  643. ));
  644. }
  645. if (!empty($a['FocalLength']))
  646. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  647. 'key' => _t($CNF['T']['txt_media_exif_focal_length']),
  648. 'val' => _t($CNF['T']['txt_media_exif_focal_length_value'], $a['FocalLength']),
  649. ));
  650. if (!empty($a['COMPUTED']['ApertureFNumber']))
  651. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  652. 'key' => _t($CNF['T']['txt_media_exif_aperture']),
  653. 'val' => $a['COMPUTED']['ApertureFNumber'],
  654. ));
  655. if (!empty($a['ExposureTime']))
  656. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  657. 'key' => _t($CNF['T']['txt_media_exif_shutter_speed']),
  658. 'val' => _t($CNF['T']['txt_media_exif_shutter_speed_value'], $a['ExposureTime']),
  659. ));
  660. if (!empty($a['ISOSpeedRatings']))
  661. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  662. 'key' => _t($CNF['T']['txt_media_exif_iso']),
  663. 'val' => $a['ISOSpeedRatings'],
  664. ));
  665. if (empty($s))
  666. return '';
  667. return $this->parseHtmlByName($sTemplateName, array('content' => $s));
  668. }
  669. }
  670. /** @} */