BxBaseModTextTemplate.php 33 KB

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