BxBaseModTextTemplate.php 43 KB

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