BxBaseModTextTemplate.php 43 KB

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