BxBaseModTextTemplate.php 46 KB

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