BxBaseModTextTemplate.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  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. $oModule = $this->getModule();
  71. $CNF = &$oModule->_oConfig->CNF;
  72. if (!$iProfileId)
  73. $iProfileId = $aData[$CNF['FIELD_AUTHOR']];
  74. $oProfile = BxDolProfile::getInstanceMagic($iProfileId);
  75. $sName = $oProfile->getDisplayName();
  76. $sAddon = $sFuncAuthorAddon && is_a($oProfile, 'BxDolProfile') ? $this->$sFuncAuthorAddon($aData, $oProfile) : '';
  77. $bIsApi = bx_is_api();
  78. if($bIsApi)
  79. $sFuncAuthorDesc .= 'API';
  80. $aVars = [
  81. 'author_url' => $oProfile->getUrl(),
  82. 'author_thumb_url' => $oProfile->getThumb(),
  83. 'author_unit' => $bIsApi ? BxDolProfile::getData($oProfile, ['display_type' => 'unit_wo_info']) : $oProfile->getUnit(0, ['template' => 'unit_wo_info']),
  84. 'author_title' => $sName,
  85. 'author_title_attr' => bx_html_attribute($sName),
  86. 'author_desc' => $sFuncAuthorDesc ? $this->$sFuncAuthorDesc($aData, $oProfile) : '',
  87. 'author_profile_desc' => $this->getAuthorProfileDesc($aData, $oProfile),
  88. 'bx_if:addon' => [
  89. 'condition' => (bool)$sAddon,
  90. 'content' => [
  91. 'content' => $sAddon,
  92. ],
  93. ],
  94. ];
  95. return $bIsApi ? [['id' => 1, 'type' => 'author', 'data' => [
  96. 'author' => $aVars,
  97. 'menu_manage' => $oModule->getEntryAllActions()
  98. ]]] : $this->parseHtmlByName($sTemplateName, $aVars);
  99. }
  100. public function entryBreadcrumb($aContentInfo, $aTmplVarsItems = array())
  101. {
  102. if(!empty($aTmplVarsItems) && is_array($aTmplVarsItems))
  103. return parent::entryBreadcrumb($aContentInfo, $aTmplVarsItems);
  104. $CNF = &$this->getModule()->_oConfig->CNF;
  105. $aTmplVarsItems = array();
  106. if(!empty($CNF['OBJECT_CATEGORY']) && !empty($CNF['FIELD_CATEGORY'])) {
  107. $oCategory = BxDolCategory::getObjectInstance($CNF['OBJECT_CATEGORY']);
  108. $aTmplVarsItems[] = array(
  109. 'url' => $oCategory->getCategoryUrl($aContentInfo[$CNF['FIELD_CATEGORY']]),
  110. 'title' => $oCategory->getCategoryTitle($aContentInfo[$CNF['FIELD_CATEGORY']])
  111. );
  112. }
  113. $aTmplVarsItems[] = array(
  114. 'url' => BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  115. 'title' => bx_process_output($aContentInfo[$CNF['FIELD_TITLE']])
  116. );
  117. return parent::entryBreadcrumb($aContentInfo, $aTmplVarsItems);
  118. }
  119. public function entryPolls($aData)
  120. {
  121. $CNF = &$this->getModule()->_oConfig->CNF;
  122. $aPolls = $this->_oDb->getPolls(array(
  123. 'type' => 'content_id',
  124. 'content_id' => $aData[$CNF['FIELD_ID']],
  125. ));
  126. if(empty($aPolls) || !is_array($aPolls))
  127. return;
  128. $iProfileId = bx_get_logged_profile_id();
  129. $sPolls = '';
  130. foreach($aPolls as $aPoll)
  131. $sPolls .= $this->getPollItem($aPoll, $iProfileId);
  132. if(empty($sPolls))
  133. return '';
  134. $this->_addCssJs();
  135. return $this->getJsCode('poll') . $this->parseHtmlByName('poll_items.html', array(
  136. 'polls' => $sPolls
  137. ));
  138. }
  139. public function entryPollAnswers($aPoll, $bDynamic = false)
  140. {
  141. $sContent = $this->_getPollAnswers($aPoll, $bDynamic);
  142. if(empty($sContent))
  143. return '';
  144. return array(
  145. 'content' => $sContent,
  146. 'menu' => $this->_getPollBlockMenu($aPoll, 'answers')
  147. );
  148. }
  149. public function entryPollResults($aPoll, $bDynamic = false)
  150. {
  151. $sContent = $this->_getPollResults($aPoll, $bDynamic);
  152. if(empty($sContent))
  153. return '';
  154. return array(
  155. 'content' => $sContent,
  156. 'menu' => $this->_getPollBlockMenu($aPoll, 'results')
  157. );
  158. }
  159. public function getPollForm()
  160. {
  161. $aForm = $this->getModule()->getPollForm();
  162. return $this->parseHtmlByName('poll_form.html', array(
  163. 'js_object' => $this->_oConfig->getJsObject('poll'),
  164. 'form_id' => $aForm['form_id'],
  165. 'form' => $aForm['form'],
  166. ));
  167. }
  168. public function getPollField($iContentId = 0, $iProfileId = 0)
  169. {
  170. if(empty($iProfileId))
  171. $iProfileId = bx_get_logged_profile_id();
  172. $aPolls = array();
  173. if(!empty($iContentId))
  174. $aPolls = array_merge($aPolls, $this->_oDb->getPolls(array(
  175. 'type' => 'content_id',
  176. 'content_id' => $iContentId,
  177. )));
  178. $aPolls = array_merge($aPolls, $this->_oDb->getPolls(array(
  179. 'type' => 'author_id',
  180. 'author_id' => $iProfileId,
  181. 'unused' => true
  182. )));
  183. $sPolls = '';
  184. foreach($aPolls as $aPoll)
  185. $sPolls .= $this->getPollItem($aPoll, $iProfileId, array(
  186. 'manage' => true
  187. ));
  188. return $this->parseHtmlByName('poll_form_field.html', array(
  189. 'html_id' => $this->_oConfig->getHtmlIds('add_poll_form_field'),
  190. 'polls' => $sPolls
  191. ));
  192. }
  193. public function getPollItem($mixedPoll, $iProfileId = 0, $aParams = array())
  194. {
  195. $oModule = $this->getModule();
  196. $CNF = &$oModule->_oConfig->CNF;
  197. $aPoll = is_array($mixedPoll) ? $mixedPoll : $this->_oDb->getPolls(array('type' => 'id', 'id' => (int)$mixedPoll));
  198. if(empty($aPoll) || !is_array($aPoll))
  199. return '';
  200. $sJsObject = $this->_oConfig->getJsObject('poll');
  201. $bDynamic = isset($aParams['dynamic']) && $aParams['dynamic'] === true;
  202. $bManage = isset($aParams['manage']) && $aParams['manage'] === true;
  203. $bSwitchMenu = isset($aParams['switch_menu']) ? (bool)$aParams['switch_menu'] : true;
  204. $bForceDisplayAnswers = isset($aParams['force_display_answers']) && (bool)$aParams['force_display_answers'] === true;
  205. $iPollId = (int)$aPoll[$CNF['FIELD_POLL_ID']];
  206. $sPollView = !$bForceDisplayAnswers && $oModule->isPollPerformed($iPollId, $iProfileId) ? 'results' : 'answers';
  207. $sMethod = '_getPoll' . ucfirst($sPollView);
  208. if(!method_exists($this, $sMethod))
  209. return '';
  210. $mixedMenu = '';
  211. if($bSwitchMenu)
  212. $mixedMenu = $this->_getPollBlockMenu($aPoll, $sPollView, array('template' => 'menu_interactive.html'));
  213. return $this->parseHtmlByName('poll_item.html', array(
  214. 'html_id' => $this->_oConfig->getHtmlIds('poll') . $iPollId,
  215. 'bx_if:show_input_hidden' => array(
  216. 'condition' => $bManage,
  217. 'content' => array(
  218. 'name' => $CNF['FIELD_POLL'],
  219. 'id' => $iPollId
  220. )
  221. ),
  222. 'action_menu' => !empty($mixedMenu) ? $mixedMenu->getCode() : '',
  223. 'bx_if:show_action_embed' => array(
  224. 'condition' => $bManage,
  225. 'content' => array(
  226. 'js_object' => $sJsObject,
  227. 'id' => $iPollId
  228. )
  229. ),
  230. 'bx_if:show_action_delete' => array(
  231. 'condition' => $bManage,
  232. 'content' => array(
  233. 'js_object' => $sJsObject,
  234. 'id' => $iPollId,
  235. 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : ''
  236. )
  237. ),
  238. 'text' => bx_process_output($aPoll[$CNF['FIELD_POLL_TEXT']], BX_DATA_TEXT),
  239. 'content' => $this->$sMethod($aPoll, $bDynamic)
  240. ));
  241. }
  242. public function embedPollItem($mixedPoll, $aParams = array())
  243. {
  244. $CNF = &$this->getModule()->_oConfig->CNF;
  245. $sHeader = '';
  246. $sContent = $this->getPollItem($mixedPoll, 0, $aParams);
  247. if(!empty($sContent)) {
  248. $aPoll = is_array($mixedPoll) ? $mixedPoll : $this->_oDb->getPolls(array('type' => 'id', 'id' => (int)$mixedPoll));
  249. $sHeader = strmaxtextlen($aPoll[$CNF['FIELD_POLL_TEXT']], 32, '...');
  250. $sContent = $this->getJsCode('poll') . $sContent;
  251. }
  252. $this->_addCssJs();
  253. $oTemplate = BxDolTemplate::getInstance();
  254. $oTemplate->addCssStyle($CNF['STYLES_POLLS_EMBED_CLASS'], $CNF['STYLES_POLLS_EMBED_CONTENT']);
  255. $oTemplate->setPageNameIndex(BX_PAGE_EMBED);
  256. $oTemplate->setPageHeader($sHeader);
  257. $oTemplate->setPageContent('page_main_code', $sContent);
  258. $oTemplate->getPageCode();
  259. exit;
  260. }
  261. public function embedPollItems($mixedContentInfo, $aParams = array())
  262. {
  263. $CNF = &$this->getModule()->_oConfig->CNF;
  264. $aContentInfo = is_array($mixedContentInfo) ? $mixedContentInfo : $this->_oDb->getContentInfoById((int)$mixedContentInfo);
  265. if(empty($aContentInfo) || !is_array($aContentInfo))
  266. return;
  267. $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
  268. $aPolls = $this->_oDb->getPolls(array('type' => 'content_id', 'content_id' => $iContentId));
  269. if(empty($aPolls) || !is_array($aPolls))
  270. return;
  271. $iPolls = 0;
  272. $sContent = '';
  273. foreach($aPolls as $aPoll) {
  274. $sPoll = $this->getPollItem($aPoll, 0, $aParams);
  275. if(empty($sPoll))
  276. continue;
  277. $sContent .= $sPoll;
  278. $iPolls += 1;
  279. }
  280. if(!empty($sContent) && isset($aParams['showcase']) && (bool)$aParams['showcase'] === true) {
  281. $this->addJs(array('flickity/flickity.pkgd.min.js'));
  282. $this->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flickity/|flickity.css');
  283. $sContent = $this->parseHtmlByName('poll_items_showcase.html', array(
  284. 'js_object' => $this->_oConfig->getJsObject('poll'),
  285. 'html_id' => $this->_oConfig->getHtmlIds('polls_showcase') . $iContentId,
  286. 'type' => $iPolls == 1 ? 'single' : 'multiple',
  287. 'polls' => $sContent
  288. ));
  289. }
  290. $sHeader = '';
  291. if(!empty($sContent)) {
  292. $sHeader = strmaxtextlen($aContentInfo[$CNF['FIELD_TITLE']], 32, '...');
  293. $sContent = $this->getJsCode('poll') . $sContent;
  294. }
  295. $this->_addCssJs();
  296. $oTemplate = BxDolTemplate::getInstance();
  297. $oTemplate->addCssStyle($CNF['STYLES_POLLS_EMBED_CLASS'], $CNF['STYLES_POLLS_EMBED_CONTENT']);
  298. $oTemplate->setPageNameIndex(BX_PAGE_EMBED);
  299. $oTemplate->setPageHeader($sHeader);
  300. $oTemplate->setPageContent('page_main_code', $sContent);
  301. $oTemplate->getPageCode();
  302. exit;
  303. }
  304. protected function _addCssJs()
  305. {
  306. $this->addJs(array(
  307. 'modules/base/text/js/|polls.js',
  308. 'polls.js'
  309. ));
  310. $this->addCss(array('polls.css'));
  311. }
  312. protected function _getPollAnswers($aPoll, $bDynamic = false)
  313. {
  314. $CNF = &$this->getModule()->_oConfig->CNF;
  315. $aAnswers = $this->_oDb->getPollAnswers(array('type' => 'poll_id', 'poll_id' => $aPoll[$CNF['FIELD_POLL_ID']]));
  316. if(empty($aAnswers) || !is_array($aAnswers))
  317. return '';
  318. $aTmplVarsAnswers = array();
  319. foreach($aAnswers as $aAnswer) {
  320. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES_POLL_ANSWERS'], $aAnswer['id']);
  321. $aTmplVarsAnswers[] = array(
  322. 'answer' => $oVotes->getElementBlock(array(
  323. 'dynamic_mode' => $bDynamic
  324. ))
  325. );
  326. }
  327. return $this->parseHtmlByName('poll_item_answers.html', array(
  328. 'html_id' => $this->_oConfig->getHtmlIds('poll_content') . $aPoll[$CNF['FIELD_POLL_ID']],
  329. 'bx_repeat:answers' => $aTmplVarsAnswers
  330. ));
  331. }
  332. protected function _getPollResults($aPoll, $bDynamic = false)
  333. {
  334. $CNF = &$this->getModule()->_oConfig->CNF;
  335. $aAnswers = $this->_oDb->getPollAnswers(array('type' => 'poll_id', 'poll_id' => $aPoll[$CNF['FIELD_POLL_ID']]));
  336. if(empty($aAnswers) || !is_array($aAnswers))
  337. return '';
  338. $iTotal = 0;
  339. foreach($aAnswers as $aAnswer)
  340. $iTotal += $aAnswer['votes'];
  341. $aTmplVarsAnswers = array();
  342. foreach($aAnswers as $aAnswer) {
  343. $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES_POLL_ANSWERS'], $aAnswer['id']);
  344. $aVotesParams = array('show_counter_empty' => true, 'show_counter_in_brackets' => false, 'dynamic_mode' => $bDynamic);
  345. $fPercent = $iTotal > 0 ? 100 * (float)$aAnswer['votes']/$iTotal : 0;
  346. $aTmplVarsAnswers[] = array(
  347. 'title' => bx_process_output($aAnswer['title']),
  348. 'width' => (int)round($fPercent) . '%',
  349. 'votes' => $oVotes->getCounter($aVotesParams),
  350. 'percent' => _t($CNF['T']['txt_poll_answer_vote_percent'], $iTotal > 0 ? round($fPercent, 2) : 0)
  351. );
  352. }
  353. return $this->parseHtmlByName('poll_item_results.html', array(
  354. 'html_id' => $this->_oConfig->getHtmlIds('poll_content') . $aPoll[$CNF['FIELD_POLL_ID']],
  355. 'bx_repeat:answers' => $aTmplVarsAnswers,
  356. ));
  357. }
  358. protected function _getPollBlockMenu($aPoll, $sSelected = '', $aParams = array())
  359. {
  360. $oModule = $this->getModule();
  361. $CNF = &$oModule->_oConfig->CNF;
  362. $sPostfix = '-' . time() . rand(0, PHP_INT_MAX);
  363. $sJsObject = $this->_oConfig->getJsObject('poll');
  364. $iPollId = $aPoll[$CNF['FIELD_POLL_ID']];
  365. $aViews = array(
  366. 'answers' => true,
  367. 'results' => $CNF['PARAM_POLL_HIDDEN_RESULTS'] === false || $oModule->isPollPerformed($iPollId)
  368. );
  369. $aMenu = array();
  370. foreach($aViews as $sView => $bActive) {
  371. if(!$bActive)
  372. continue;
  373. $sId = $this->_oConfig->getHtmlIds('poll_view_link_' . $sView) . $iPollId;
  374. if(!empty($sSelected) && $sSelected == $sView)
  375. $sSelected = $sId;
  376. $aMenu[] = array(
  377. 'id' => $sId,
  378. 'name' => $sId,
  379. 'class' => '',
  380. 'link' => 'javascript:void(0)',
  381. 'onclick' => 'javascript:' . $sJsObject . '.changePollView(this, \'' . $sView . '\', ' . $iPollId . ')',
  382. 'target' => '_self',
  383. 'title_attr' => _t($CNF['T']['txt_poll_menu_view_' . $sView]),
  384. 'title' => $this->parseIcon($CNF['ICON_POLLS_' . strtoupper($sView)])
  385. );
  386. }
  387. if(count($aMenu) <= 1)
  388. return '';
  389. $oMenu = new BxTemplMenuInteractive(array(
  390. 'template' => !empty($aParams['template']) ? $aParams['template'] : 'menu_interactive_vertical.html',
  391. 'menu_id' => $this->_oConfig->getHtmlIds('poll_view_menu') . $sPostfix,
  392. 'menu_items' => $aMenu
  393. ));
  394. if(!empty($sSelected))
  395. $oMenu->setSelected('', $sSelected);
  396. return $oMenu;
  397. }
  398. public function getAttachLinkForm($iContentId = 0)
  399. {
  400. $sStylePrefix = $this->_oConfig->getPrefix('style');
  401. $sJsObject = $this->_oConfig->getJsObject('links');
  402. $aForm = $this->getModule()->getFormAttachLink($iContentId);
  403. return $this->parseHtmlByName('attach_link_form.html', array(
  404. 'style_prefix' => $sStylePrefix,
  405. 'js_object' => $sJsObject,
  406. 'form_id' => $aForm['form_id'],
  407. 'form' => $aForm['form'],
  408. ));
  409. }
  410. public function getAttachLinkField($iUserId, $iContentId = 0)
  411. {
  412. $sStylePrefix = $this->_oConfig->getPrefix('style');
  413. if(!$iContentId)
  414. $aLinks = $this->_oDb->getUnusedLinks($iUserId);
  415. else
  416. $aLinks = $this->_oDb->getLinks($iContentId);
  417. $sLinks = '';
  418. foreach($aLinks as $aLink)
  419. $sLinks .= $this->getAttachLinkItem($iUserId, $aLink);
  420. return $this->parseHtmlByName('attach_link_form_field.html', array(
  421. 'html_id' => $this->_oConfig->getHtmlIds('attach_link_form_field') . $iContentId,
  422. 'style_prefix' => $sStylePrefix,
  423. 'links' => $sLinks
  424. ));
  425. }
  426. public function getAttachLinkItem($iUserId, $mixedLink)
  427. {
  428. $CNF = &$this->getModule()->_oConfig->CNF;
  429. $aLink = is_array($mixedLink) ? $mixedLink : $this->_oDb->getLinksBy(array('type' => 'id', 'id' => (int)$mixedLink, 'profile_id' => $iUserId));
  430. if(empty($aLink) || !is_array($aLink))
  431. return '';
  432. $sLinkIdPrefix = $this->_oConfig->getHtmlIds('attach_link_item');
  433. $sStylePrefix = $this->_oConfig->getPrefix('style');
  434. $sClass = $sStylePrefix . '-al-item';
  435. $sJsObject = $this->_oConfig->getJsObject('links');
  436. $oEmbed = BxDolEmbed::getObjectInstance();
  437. $bEmbed = $oEmbed !== false;
  438. $sThumbnail = '';
  439. $aLinkAttrs = array();
  440. if(!$bEmbed) {
  441. $aLinkAttrs = array(
  442. 'title' => bx_html_attribute($aLink['title'])
  443. );
  444. if(!$this->_oConfig->isEqualUrls(BX_DOL_URL_ROOT, $aLink['url'])) {
  445. $aLinkAttrs['target'] = '_blank';
  446. if($this->_oDb->getParam('sys_add_nofollow') == 'on')
  447. $aLinkAttrs['rel'] = 'nofollow';
  448. }
  449. if((int)$aLink['media_id'] != 0)
  450. $sThumbnail = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS'])->getFileUrl($aLink['media_id']);
  451. }
  452. else
  453. $sClass .= ' embed';
  454. return $this->parseHtmlByName('attach_link_item.html', array(
  455. 'html_id' => $sLinkIdPrefix . $aLink['id'],
  456. 'style_prefix' => $sStylePrefix,
  457. 'class' => $sClass,
  458. 'js_object' => $sJsObject,
  459. 'id' => $aLink['id'],
  460. 'bx_if:show_embed_outer' => array(
  461. 'condition' => $bEmbed,
  462. 'content' => array(
  463. 'style_prefix' => $sStylePrefix,
  464. 'embed' => $bEmbed ? $oEmbed->getLinkHTML($aLink['url'], $aLink['title'], 300) : '',
  465. )
  466. ),
  467. 'bx_if:show_embed_inner' => array(
  468. 'condition' => !$bEmbed,
  469. 'content' => array(
  470. 'style_prefix' => $sStylePrefix,
  471. 'bx_if:show_thumbnail' => array(
  472. 'condition' => !empty($sThumbnail),
  473. 'content' => array(
  474. 'style_prefix' => $sStylePrefix,
  475. 'thumbnail' => $sThumbnail
  476. )
  477. ),
  478. 'url' => $aLink['url'],
  479. 'link' => $this->parseLink($aLink['url'], $aLink['title'], $aLinkAttrs)
  480. )
  481. ),
  482. ));
  483. }
  484. public function getEventLinks($iContentId)
  485. {
  486. $CNF = &$this->getModule()->_oConfig->CNF;
  487. $aLinks = $this->_oDb->getLinks($iContentId);
  488. if(empty($aLinks) || !is_array($aLinks))
  489. return array();
  490. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']);
  491. $aResult = array();
  492. foreach($aLinks as $aLink)
  493. $aResult[] = array(
  494. 'url' => $aLink['url'],
  495. 'title' => $aLink['title'],
  496. 'text' => $aLink['text'],
  497. 'thumbnail' => (int)$aLink['media_id'] != 0 ? $oTranscoder->getFileUrl($aLink['media_id']) : ''
  498. );
  499. return $aResult;
  500. }
  501. public function getTmplVarsText($aData)
  502. {
  503. $CNF = &$this->getModule()->_oConfig->CNF;
  504. $sStylePrefix = $this->_oConfig->getPrefix('style');
  505. $aVars = parent::getTmplVarsText($aData);
  506. $sImage = '';
  507. $mixedImage = $this->_getHeaderImage($aData);
  508. if($mixedImage !== false) {
  509. if(!empty($mixedImage['object']))
  510. $o = BxDolStorage::getObjectInstance($mixedImage['object']);
  511. else if(!empty($mixedImage['transcoder']))
  512. $o = BxDolTranscoder::getObjectInstance($mixedImage['transcoder']);
  513. if($o)
  514. $sImage = $o->getFileUrlById($mixedImage['id']);
  515. }
  516. $sAddClassPicture = "";
  517. $sAddCode = "";
  518. $oModule = $this->getModule();
  519. $bIsAllowEditPicture = CHECK_ACTION_RESULT_ALLOWED === $oModule->checkAllowedEdit($aData);
  520. if(isset($CNF['FIELD_THUMB']) && isset($CNF['OBJECT_UPLOADERS']) && isset($CNF['OBJECT_STORAGE']) && isset($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW'])){
  521. bx_alert('system', 'image_editor', 0, 0, array(
  522. 'module' => $oModule->getName(),
  523. 'content_id' => $aData[$CNF['FIELD_ID']],
  524. 'image_type' => 'header_image',
  525. 'image_url' => $sImage,
  526. 'is_allow_edit' => $bIsAllowEditPicture,
  527. 'uploader' => !empty($CNF['OBJECT_UPLOADERS']) && is_array($CNF['OBJECT_UPLOADERS']) ? $CNF['OBJECT_UPLOADERS'][0] : '',
  528. 'storage' => isset($CNF['OBJECT_STORAGE']) ? $CNF['OBJECT_STORAGE'] : '',
  529. 'transcoder' => isset($CNF['OBJECT_IMAGES_TRANSCODER_COVER']) ? $CNF['OBJECT_IMAGES_TRANSCODER_COVER'] : '',
  530. 'field' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : '',
  531. 'is_background' => false,
  532. 'add_class' => &$sAddClassPicture,
  533. 'add_code' => &$sAddCode
  534. ));
  535. }
  536. $sImageTweak = '';
  537. $sUniqIdImage = genRndPwd (8, false);
  538. if ($bIsAllowEditPicture && empty($sAddCode) && isset($CNF['FIELD_THUMB_POSITION'])){
  539. $sImageTweak = $this->_prepareImage($aData, $sUniqIdImage, $CNF['OBJECT_UPLOADERS'], $CNF['OBJECT_STORAGE'], $CNF['FIELD_THUMB'], true);
  540. }
  541. $aVars['content_description_before'] = '';
  542. $aVars['content_description_after'] = '';
  543. $aVars['bx_if:show_image'] = array(
  544. 'condition' => !empty($sImage),
  545. 'content' => array(
  546. 'entry_image' => $sImage,
  547. 'image_settings' => isset($CNF['FIELD_THUMB_POSITION']) ? $this->_getImageSettings($aData[$CNF['FIELD_THUMB_POSITION']]) : '',
  548. 'add_class' => $sAddClassPicture,
  549. 'img_class' => $sAddClassPicture != '' ? 'bx-media-editable-src' : '',
  550. 'additional_code' => $sAddCode,
  551. 'image_tweak' => $sImageTweak,
  552. 'unique_id' => $sUniqIdImage,
  553. )
  554. );
  555. $aTmplVarsLinks = [];
  556. if(isset($CNF['FIELD_LINK'])){
  557. $aLinks = $this->getEventLinks($aData[$CNF['FIELD_ID']]);
  558. $sClass = $sStylePrefix . '-al-item';
  559. $bAddNofollow = $this->_oDb->getParam('sys_add_nofollow') == 'on';
  560. foreach($aLinks as $aLink) {
  561. $sLink = '';
  562. $oEmbed = BxDolEmbed::getObjectInstance();
  563. if ($oEmbed) {
  564. $sLink = $this->parseHtmlByName('link_embed_provider.html', array(
  565. 'style_prefix' => $sStylePrefix,
  566. 'embed' => $oEmbed->getLinkHTML($aLink['url'], $aLink['title']),
  567. ));
  568. }
  569. else {
  570. $aLinkAttrs = array(
  571. 'title' => $aLink['title']
  572. );
  573. if(!$this->_oConfig->isEqualUrls(BX_DOL_URL_ROOT, $aLink['url'])) {
  574. $aLinkAttrs['target'] = '_blank';
  575. if($bAddNofollow)
  576. $aLinkAttrs['rel'] = 'nofollow';
  577. }
  578. $sLinkAttrs = '';
  579. foreach($aLinkAttrs as $sKey => $sValue)
  580. $sLinkAttrs .= ' ' . $sKey . '="' . bx_html_attribute($sValue) . '"';
  581. $sLink = $this->parseHtmlByName('link_embed_common.html', array(
  582. 'bx_if:show_thumbnail' => [
  583. 'condition' => !empty($aLink['thumbnail']),
  584. 'content' => [
  585. 'style_prefix' => $sStylePrefix,
  586. 'thumbnail' => $aLink['thumbnail'],
  587. 'link' => !empty($aLink['url']) ? $aLink['url'] : 'javascript:void(0)',
  588. 'attrs' => $sLinkAttrs
  589. ]
  590. ],
  591. 'link' => !empty($aLink['url']) ? $aLink['url'] : 'javascript:void(0)',
  592. 'attrs' => $sLinkAttrs,
  593. 'content' => $aLink['title'],
  594. 'bx_if:show_text' => [
  595. 'condition' => !empty($aLink['text']),
  596. 'content' => [
  597. 'style_prefix' => $sStylePrefix,
  598. 'text' => $aLink['text']
  599. ]
  600. ]
  601. ));
  602. }
  603. $aTmplVarsLinks[] = [
  604. 'style_prefix' => $sStylePrefix,
  605. 'link' => $sLink
  606. ];
  607. }
  608. }
  609. $aVars['bx_if:show_links'] = [
  610. 'condition' => count($aTmplVarsLinks) > 0,
  611. 'content' => [
  612. 'style_prefix' => $sStylePrefix,
  613. 'bx_repeat:links' => $aTmplVarsLinks
  614. ]
  615. ];
  616. if(!empty($CNF['OBJECT_REACTIONS']) && ($oReactions = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $aData[$CNF['FIELD_ID']])) !== false)
  617. $aVars['content_description_after'] .= $oReactions->getCounter([
  618. 'show_counter' => true,
  619. 'show_counter_empty' => false
  620. ]);
  621. $this->addCss(array('cover.css'));
  622. return $aVars;
  623. }
  624. function getAuthorDesc($aData, $oProfile)
  625. {
  626. $CNF = &$this->getModule()->_oConfig->CNF;
  627. $aItem = array(
  628. 'bx_if:text' => array(
  629. 'condition' => false,
  630. 'content' => array(
  631. 'content' => ''
  632. )
  633. ),
  634. 'bx_if:link' => array(
  635. 'condition' => false,
  636. 'content' => array(
  637. 'link' => '',
  638. 'content' => ''
  639. )
  640. )
  641. );
  642. $aTmplVarsItems = array();
  643. if(!empty($CNF['FIELD_ADDED']) && !empty($aData[$CNF['FIELD_ADDED']]))
  644. $aTmplVarsItems[] = array_merge($aItem, array('bx_if:text' => array(
  645. 'condition' => true,
  646. 'content' => array(
  647. 'content' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE)
  648. )
  649. )));
  650. if(!empty($CNF['URI_AUTHOR_ENTRIES']))
  651. $aTmplVarsItems[] = array_merge($aItem, array('bx_if:link' => array(
  652. 'condition' => true,
  653. 'content' => array(
  654. 'link' => BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id=' . $oProfile->id()),
  655. 'content' => _t($CNF['T']['txt_all_entries_by'], $this->getModule()->_oDb->getEntriesNumByAuthor($oProfile->id()))
  656. )
  657. )));
  658. return $this->parseHtmlByName('author_desc.html', array(
  659. 'bx_repeat:items' => $aTmplVarsItems
  660. ));
  661. }
  662. function getAuthorDescAPI($aData, $oProfile)
  663. {
  664. $CNF = &$this->getModule()->_oConfig->CNF;
  665. $aResult = ['object' => '', 'items' => []];
  666. if(!empty($CNF['FIELD_ADDED']) && !empty($aData[$CNF['FIELD_ADDED']]))
  667. $aResult['items'][] = [
  668. 'id' => 1,
  669. 'content_type' => 'time',
  670. 'title' => $aData[$CNF['FIELD_ADDED']]
  671. ];
  672. if(!empty($CNF['URI_AUTHOR_ENTRIES']))
  673. $aResult['items'][] = [
  674. 'id' => 2,
  675. 'link' => BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id=' . $oProfile->id()),
  676. 'title' => _t($CNF['T']['txt_all_entries_by'], $this->getModule()->_oDb->getEntriesNumByAuthor($oProfile->id()))
  677. ];
  678. return $aResult;
  679. }
  680. function getAuthorProfileDesc ($aData, $oProfile)
  681. {
  682. $aSnippetMeta = $this->getProfileSnippetMenu($aData);
  683. if(empty($aSnippetMeta) || !is_array($aSnippetMeta) || !isset($aSnippetMeta['meta']))
  684. return '';
  685. return $aSnippetMeta['meta'];
  686. }
  687. function getProfileSnippetMenu ($aData)
  688. {
  689. $CNF = &$this->getModule()->_oConfig->CNF;
  690. if (!($oProfile = BxDolProfile::getInstance($aData[$CNF['FIELD_AUTHOR']])))
  691. return array();
  692. return bx_srv($oProfile->getModule(), 'get_snippet_menu_vars', array($oProfile->id()));
  693. }
  694. function getAuthorAddon ($aData, $oProfile)
  695. {
  696. return '';
  697. }
  698. protected function checkPrivacy ($aData, $isCheckPrivateContent, $oModule, $sTemplateName = '')
  699. {
  700. if ($isCheckPrivateContent && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $oModule->checkAllowedView($aData))) {
  701. $aVars = array (
  702. 'summary' => $sMsg,
  703. );
  704. return $this->parseHtmlByName($sTemplateName ? str_replace('.html', '_private.html', $sTemplateName) : 'unit_private.html', $aVars);
  705. }
  706. return '';
  707. }
  708. protected function getUnitThumbAndGallery ($aData)
  709. {
  710. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  711. $sPhotoThumb = '';
  712. $sPhotoGallery = '';
  713. if(!empty($CNF['FIELD_THUMB']) && !empty($aData[$CNF['FIELD_THUMB']])) {
  714. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  715. if ($oImagesTranscoder)
  716. $sPhotoThumb = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  717. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  718. if ($oImagesTranscoder)
  719. $sPhotoGallery = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  720. else
  721. $sPhotoGallery = $sPhotoThumb;
  722. }
  723. return array($sPhotoThumb, $sPhotoGallery);
  724. }
  725. protected function getUnit ($aData, $aParams = array())
  726. {
  727. $CNF = &$this->_oConfig->CNF;
  728. $oModule = $this->getModule();
  729. // get thumb url
  730. list($sPhotoThumb, $sPhotoGallery) = $this->getUnitThumbAndGallery($aData);
  731. if ($sPhotoGallery == '' && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  732. if(!empty($CNF['OBJECT_STORAGE_PHOTOS'])){
  733. $sStorage = $CNF['OBJECT_STORAGE_PHOTOS'];
  734. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  735. list($oTranscoder, $oTranscoderView) = $this->getAttachmentsImagesTranscoders($sStorage);
  736. $aGhostFiles = $oStorage->getGhosts($oModule->serviceGetContentOwnerProfileId($aData[$CNF['FIELD_ID']]), $aData[$CNF['FIELD_ID']]);
  737. if(!empty($aGhostFiles) && is_array($aGhostFiles)) {
  738. $aGhostFile = array_shift($aGhostFiles);
  739. $sPhotoThumb = $oTranscoderView->getFileUrl($aGhostFile['id']);
  740. $sPhotoGallery = $oTranscoder->getFileUrl($aGhostFile['id']);
  741. }
  742. }
  743. }
  744. // get entry url
  745. $sUrl = bx_absolute_url(BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]));
  746. $oProfile = BxDolProfile::getInstanceMagic($aData[$CNF['FIELD_AUTHOR']]);
  747. $sTitle = $this->getTitle($aData);
  748. $sText = $this->getText($aData);
  749. $sSummary = $this->getSummary($aData, $sTitle, $sText, $sUrl);
  750. $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'])) : '';
  751. if(!empty($CNF['OBJECT_METATAGS'])) {
  752. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  753. $sText = $oMetatags->metaParse($aData[$CNF['FIELD_ID']], $sText);
  754. }
  755. $aTmplVarsMeta = array();
  756. if(!empty($CNF['OBJECT_MENU_SNIPPET_META'])) {
  757. $oMenuMeta = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this);
  758. if($oMenuMeta) {
  759. $oMenuMeta->setContentId($aData[$CNF['FIELD_ID']]);
  760. $aTmplVarsMeta = array(
  761. 'meta' => $oMenuMeta->getCode()
  762. );
  763. }
  764. }
  765. $bBadgesSingle = isset($aParams['badges_single']) ? $aParams['badges_single'] : false;
  766. $bBadgesCompact = isset($aParams['badges_compact']) ? $aParams['badges_compact'] : false;
  767. $sCoverData = isset($aData['thumb_data']) ? $aData['thumb_data'] : '';
  768. $aTmplVars = array (
  769. 'class' => $this->_getUnitClass($aData,(isset($aParams['template_name']) ? $aParams['template_name'] : '')),
  770. 'id' => $aData[$CNF['FIELD_ID']],
  771. 'content_url' => $sUrl,
  772. 'title' => $sTitle,
  773. 'badges' => $oModule->serviceGetBadges($aData[$CNF['FIELD_ID']], $bBadgesSingle, $bBadgesCompact),
  774. 'title_attr' => bx_html_attribute($sTitle),
  775. 'summary' => $sSummary,
  776. 'text' => $sText,
  777. 'author' => $oProfile->getDisplayName(),
  778. 'author_url' => $oProfile->getUrl(),
  779. 'author_icon' => $oProfile->getIcon(),
  780. 'author_thumb' => $oProfile->getThumb(),
  781. 'author_avatar' => $oProfile->getAvatar(),
  782. 'entry_posting_date' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE),
  783. 'module_name' => _t($CNF['T']['txt_sample_single']),
  784. 'ts' => $aData[$CNF['FIELD_ADDED']],
  785. 'bx_if:meta' => array(
  786. 'condition' => !empty($aTmplVarsMeta),
  787. 'content' => $aTmplVarsMeta
  788. ),
  789. 'bx_if:thumb' => array (
  790. 'condition' => $sPhotoThumb,
  791. 'content' => array (
  792. 'title' => $sTitle,
  793. 'summary_attr' => bx_html_attribute($sSummaryPlain),
  794. 'content_url' => $sUrl,
  795. 'thumb_url' => $sPhotoThumb ? $sPhotoThumb : '',
  796. 'gallery_url' => $sPhotoGallery ? $sPhotoGallery : '',
  797. 'image_settings' => $this->_getImageSettings($sCoverData),
  798. 'strecher' => str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', 40),
  799. ),
  800. ),
  801. 'bx_if:no_thumb' => array (
  802. 'condition' => !$sPhotoThumb,
  803. 'content' => array (
  804. 'module_icon' => $CNF['ICON'],
  805. 'content_url' => $sUrl,
  806. 'summary_plain' => $sSummaryPlain,
  807. 'strecher' => mb_strlen($sSummaryPlain) > 240 ? '' : str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', round((240 - mb_strlen($sSummaryPlain)) / 6)),
  808. ),
  809. ),
  810. );
  811. if(isset($aParams['template_vars']) && is_array($aParams['template_vars']))
  812. $aTmplVars = array_merge($aTmplVars, $aParams['template_vars']);
  813. // generate html
  814. return $aTmplVars;
  815. }
  816. protected function getAttachmentsImagesTranscoders ($sStorage = '')
  817. {
  818. $CNF = &$this->getModule()->_oConfig->CNF;
  819. $oTranscoder = null;
  820. $oTranscoderView = null;
  821. if(isset($CNF['OBJECT_STORAGE_PHOTOS']) && $CNF['OBJECT_STORAGE_PHOTOS'] == $sStorage) {
  822. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']))
  823. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']);
  824. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']))
  825. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']);
  826. else if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']))
  827. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']);
  828. }
  829. else if(isset($CNF['OBJECT_STORAGE_FILES']) && $CNF['OBJECT_STORAGE_FILES'] == $sStorage) {
  830. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES']))
  831. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES']);
  832. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']))
  833. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']);
  834. }
  835. else
  836. list($oTranscoder, $oTranscoderView) = parent::getAttachmentsImagesTranscoders($sStorage);
  837. return array($oTranscoder, $oTranscoderView);
  838. }
  839. protected function _getUnitName($aData, $sTemplateName = 'unit.html')
  840. {
  841. return trim(str_replace('.html', '', $sTemplateName));
  842. }
  843. protected function _getUnitClass($aData, $sTemplateName = 'unit.html')
  844. {
  845. $sResult = '';
  846. switch($sTemplateName) {
  847. case 'unit_showcase.html':
  848. $sResult = $this->_sUnitClassShowCase;
  849. break;
  850. }
  851. return $sResult;
  852. }
  853. protected function _getHeaderImage($aData)
  854. {
  855. return $this->getModule()->getEntryImageData($aData);
  856. }
  857. function mediaExif ($aMediaInfo, $iProfileId = false, $sFuncAuthorDesc = '', $sTemplateName = 'media-exif.html')
  858. {
  859. if (empty($aMediaInfo['exif']))
  860. return '';
  861. $a = unserialize($aMediaInfo['exif']);
  862. $s = '';
  863. if (!empty($a['Make'])) {
  864. $oModule = BxDolModule::getInstance($this->MODULE);
  865. $CNF = &$oModule->_oConfig->CNF;
  866. $sCamera = BxDolMetatags::keywordsCameraModel($a);
  867. if (!empty($CNF['OBJECT_METATAGS_MEDIA_CAMERA'])) {
  868. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS_MEDIA_CAMERA']);
  869. if ($oMetatags->keywordsIsEnabled()) {
  870. $sCamera = $oMetatags->keywordsParseOne($aMediaInfo['id'], $sCamera);
  871. }
  872. }
  873. if (!empty($sCamera))
  874. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  875. 'key' => _t($CNF['T']['txt_media_exif_camera']),
  876. 'val' => $sCamera,
  877. ));
  878. }
  879. if (!empty($a['FocalLength']))
  880. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  881. 'key' => _t($CNF['T']['txt_media_exif_focal_length']),
  882. 'val' => _t($CNF['T']['txt_media_exif_focal_length_value'], $a['FocalLength']),
  883. ));
  884. if (!empty($a['COMPUTED']['ApertureFNumber']))
  885. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  886. 'key' => _t($CNF['T']['txt_media_exif_aperture']),
  887. 'val' => $a['COMPUTED']['ApertureFNumber'],
  888. ));
  889. if (!empty($a['ExposureTime']))
  890. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  891. 'key' => _t($CNF['T']['txt_media_exif_shutter_speed']),
  892. 'val' => _t($CNF['T']['txt_media_exif_shutter_speed_value'], $a['ExposureTime']),
  893. ));
  894. if (!empty($a['ISOSpeedRatings']))
  895. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  896. 'key' => _t($CNF['T']['txt_media_exif_iso']),
  897. 'val' => $a['ISOSpeedRatings'],
  898. ));
  899. if (empty($s))
  900. return '';
  901. return $this->parseHtmlByName($sTemplateName, array('content' => $s));
  902. }
  903. }
  904. /** @} */