1
0

BxBaseModTextTemplate.php 32 KB

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