1
0

BxBaseModTextTemplate.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  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. protected function _addCssJsPolls($bDynamic = false)
  146. {
  147. $sInclude = parent::_addCssJsPolls($bDynamic);
  148. $sInclude .= $this->addJs(['modules/base/text/js/|polls.js','polls.js'], $bDynamic);
  149. return $bDynamic ? $sInclude : '';
  150. }
  151. public function getAttachLinkForm($iContentId = 0)
  152. {
  153. $sStylePrefix = $this->_oConfig->getPrefix('style');
  154. $sJsObject = $this->_oConfig->getJsObject('links');
  155. $aForm = $this->getModule()->getFormAttachLink($iContentId);
  156. return $this->parseHtmlByName('attach_link_form.html', array(
  157. 'style_prefix' => $sStylePrefix,
  158. 'js_object' => $sJsObject,
  159. 'form_id' => $aForm['form_id'],
  160. 'form' => $aForm['form'],
  161. ));
  162. }
  163. public function getAttachLinkField($iUserId, $iContentId = 0)
  164. {
  165. $sStylePrefix = $this->_oConfig->getPrefix('style');
  166. if(!$iContentId)
  167. $aLinks = $this->_oDb->getUnusedLinks($iUserId);
  168. else
  169. $aLinks = $this->_oDb->getLinks($iContentId);
  170. $sLinks = '';
  171. foreach($aLinks as $aLink)
  172. $sLinks .= $this->getAttachLinkItem($iUserId, $aLink);
  173. return $this->parseHtmlByName('attach_link_form_field.html', array(
  174. 'html_id' => $this->_oConfig->getHtmlIds('attach_link_form_field') . $iContentId,
  175. 'style_prefix' => $sStylePrefix,
  176. 'links' => $sLinks
  177. ));
  178. }
  179. public function getAttachLinkItem($iUserId, $mixedLink)
  180. {
  181. $CNF = &$this->getModule()->_oConfig->CNF;
  182. $aLink = is_array($mixedLink) ? $mixedLink : $this->_oDb->getLinksBy(array('type' => 'id', 'id' => (int)$mixedLink, 'profile_id' => $iUserId));
  183. if(empty($aLink) || !is_array($aLink))
  184. return '';
  185. $sLinkIdPrefix = $this->_oConfig->getHtmlIds('attach_link_item');
  186. $sStylePrefix = $this->_oConfig->getPrefix('style');
  187. $sClass = $sStylePrefix . '-al-item';
  188. $sJsObject = $this->_oConfig->getJsObject('links');
  189. $oEmbed = BxDolEmbed::getObjectInstance();
  190. $bEmbed = $oEmbed !== false;
  191. $sThumbnail = '';
  192. $aLinkAttrs = array();
  193. if(!$bEmbed) {
  194. $aLinkAttrs = array(
  195. 'title' => bx_html_attribute($aLink['title'])
  196. );
  197. if(!$this->_oConfig->isEqualUrls(BX_DOL_URL_ROOT, $aLink['url'])) {
  198. $aLinkAttrs['target'] = '_blank';
  199. if($this->_oDb->getParam('sys_add_nofollow') == 'on')
  200. $aLinkAttrs['rel'] = 'nofollow';
  201. }
  202. if((int)$aLink['media_id'] != 0)
  203. $sThumbnail = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS'])->getFileUrl($aLink['media_id']);
  204. }
  205. else
  206. $sClass .= ' embed';
  207. return $this->parseHtmlByName('attach_link_item.html', array(
  208. 'html_id' => $sLinkIdPrefix . $aLink['id'],
  209. 'style_prefix' => $sStylePrefix,
  210. 'class' => $sClass,
  211. 'js_object' => $sJsObject,
  212. 'id' => $aLink['id'],
  213. 'bx_if:show_embed_outer' => array(
  214. 'condition' => $bEmbed,
  215. 'content' => array(
  216. 'style_prefix' => $sStylePrefix,
  217. 'embed' => $bEmbed ? $oEmbed->getLinkHTML($aLink['url'], $aLink['title'], 300) : '',
  218. )
  219. ),
  220. 'bx_if:show_embed_inner' => array(
  221. 'condition' => !$bEmbed,
  222. 'content' => array(
  223. 'style_prefix' => $sStylePrefix,
  224. 'bx_if:show_thumbnail' => array(
  225. 'condition' => !empty($sThumbnail),
  226. 'content' => array(
  227. 'style_prefix' => $sStylePrefix,
  228. 'thumbnail' => $sThumbnail
  229. )
  230. ),
  231. 'url' => $aLink['url'],
  232. 'link' => $this->parseLink($aLink['url'], $aLink['title'], $aLinkAttrs)
  233. )
  234. ),
  235. ));
  236. }
  237. public function getEventLinks($iContentId)
  238. {
  239. $CNF = &$this->getModule()->_oConfig->CNF;
  240. $aLinks = $this->_oDb->getLinks($iContentId);
  241. if(empty($aLinks) || !is_array($aLinks))
  242. return array();
  243. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']);
  244. $aResult = array();
  245. foreach($aLinks as $aLink)
  246. $aResult[] = array(
  247. 'url' => $aLink['url'],
  248. 'title' => $aLink['title'],
  249. 'text' => $aLink['text'],
  250. 'thumbnail' => (int)$aLink['media_id'] != 0 ? $oTranscoder->getFileUrl($aLink['media_id']) : ''
  251. );
  252. return $aResult;
  253. }
  254. public function getTmplVarsText($aData)
  255. {
  256. $CNF = &$this->getModule()->_oConfig->CNF;
  257. $sStylePrefix = $this->_oConfig->getPrefix('style');
  258. $aVars = parent::getTmplVarsText($aData);
  259. $aImageParams = $this->_getHeaderImageParams();
  260. $mixedImage = $this->_getHeaderImage($aData);
  261. $sImage = '';
  262. if($mixedImage !== false) {
  263. if(!empty($mixedImage['object']))
  264. $o = BxDolStorage::getObjectInstance($mixedImage['object']);
  265. else if(!empty($mixedImage['transcoder']))
  266. $o = BxDolTranscoder::getObjectInstance($mixedImage['transcoder']);
  267. if($o)
  268. $sImage = $o->getFileUrlById($mixedImage['id']);
  269. }
  270. if($this->_bIsApi) {
  271. if($sImage)
  272. $aVars['image'] = bx_api_get_image($aImageParams['storage'], $mixedImage['id']);
  273. return $aVars;
  274. }
  275. $sAddClassPicture = "";
  276. $sAddCode = "";
  277. $oModule = $this->getModule();
  278. $bIsAllowEditPicture = CHECK_ACTION_RESULT_ALLOWED === $oModule->checkAllowedEdit($aData);
  279. if($aImageParams['field'] && $aImageParams['uploaders'] && $aImageParams['storage'] && $aImageParams['transcoder_cover']) {
  280. /**
  281. * @hooks
  282. * @hookdef hook-system-image_editor 'system', 'image_editor' - hook to override content header image editor
  283. * - $unit_name - equals `system`
  284. * - $action - equals `image_editor`
  285. * - $object_id - not used
  286. * - $sender_id - not used
  287. * - $extra_params - array of additional params with the following array keys:
  288. * - `module` - [string] module name
  289. * - `content_id` - [int] profile content id
  290. * - `is_allow_edit` - [boolean] if edit action is allowed to current user
  291. * - `image_type` - [string] image type equals to `header_image`
  292. * - `image_url` - [string] image URL
  293. * - `uploader` - [string] uploader name
  294. * - `storage` - [string] storage name
  295. * - `transcoder` - [string] transcoder name
  296. * - `field` - [string] field name
  297. * - `is_background` - [boolean] if image is used as background, always `false`
  298. * - `add_class` - [string] by ref, class to add, can be overridden in hook processing
  299. * - `add_code` - [array] by ref, code to add, can be overridden in hook processing
  300. * @hook @ref hook-system-image_editor
  301. */
  302. bx_alert('system', 'image_editor', 0, 0, [
  303. 'module' => $oModule->getName(),
  304. 'content_id' => $aData[$CNF['FIELD_ID']],
  305. 'is_allow_edit' => $bIsAllowEditPicture,
  306. 'image_type' => 'header_image',
  307. 'image_url' => $sImage,
  308. 'uploader' => $aImageParams['uploaders'] && is_array($aImageParams['uploaders']) ? $aImageParams['uploaders'][0] : '',
  309. 'storage' => $aImageParams['storage'],
  310. 'transcoder' => $aImageParams['transcoder_cover'],
  311. 'field' => $aImageParams['field'],
  312. 'is_background' => false,
  313. 'add_class' => &$sAddClassPicture,
  314. 'add_code' => &$sAddCode
  315. ]);
  316. }
  317. $sImageTweak = '';
  318. $sUniqIdImage = genRndPwd (8, false);
  319. if ($bIsAllowEditPicture && empty($sAddCode) && $aImageParams['field_position']){
  320. $sImageTweak = $this->_prepareImage($aData, $sUniqIdImage, $aImageParams['uploaders'], $aImageParams['storage'], $aImageParams['field'], true);
  321. }
  322. $aVars['content_description_before'] = '';
  323. $aVars['content_description_after'] = '';
  324. $aVars['bx_if:show_image'] = array(
  325. 'condition' => !empty($sImage),
  326. 'content' => array(
  327. 'entry_image' => $sImage,
  328. 'image_settings' => $aImageParams['field_position'] ? $this->_getImageSettings($aImageParams['field'], $aData[$aImageParams['field_position']], 'page_cover') : '',
  329. 'add_class' => $sAddClassPicture,
  330. 'img_class' => $sAddClassPicture != '' ? 'bx-media-editable-src' : '',
  331. 'additional_code' => $sAddCode,
  332. 'image_tweak' => $sImageTweak,
  333. 'unique_id' => $sUniqIdImage,
  334. )
  335. );
  336. $aTmplVarsLinks = [];
  337. if(isset($CNF['FIELD_LINK'])){
  338. $aLinks = $this->getEventLinks($aData[$CNF['FIELD_ID']]);
  339. $sClass = $sStylePrefix . '-al-item';
  340. $bAddNofollow = $this->_oDb->getParam('sys_add_nofollow') == 'on';
  341. foreach($aLinks as $aLink) {
  342. $sLink = '';
  343. $oEmbed = BxDolEmbed::getObjectInstance();
  344. if ($oEmbed) {
  345. $sLink = $this->parseHtmlByName('link_embed_provider.html', array(
  346. 'style_prefix' => $sStylePrefix,
  347. 'embed' => $oEmbed->getLinkHTML($aLink['url'], $aLink['title']),
  348. ));
  349. }
  350. else {
  351. $aLinkAttrs = array(
  352. 'title' => $aLink['title']
  353. );
  354. if(!$this->_oConfig->isEqualUrls(BX_DOL_URL_ROOT, $aLink['url'])) {
  355. $aLinkAttrs['target'] = '_blank';
  356. if($bAddNofollow)
  357. $aLinkAttrs['rel'] = 'nofollow';
  358. }
  359. $sLinkAttrs = '';
  360. foreach($aLinkAttrs as $sKey => $sValue)
  361. $sLinkAttrs .= ' ' . $sKey . '="' . bx_html_attribute($sValue) . '"';
  362. $sLink = $this->parseHtmlByName('link_embed_common.html', array(
  363. 'bx_if:show_thumbnail' => [
  364. 'condition' => !empty($aLink['thumbnail']),
  365. 'content' => [
  366. 'style_prefix' => $sStylePrefix,
  367. 'thumbnail' => $aLink['thumbnail'],
  368. 'link' => !empty($aLink['url']) ? $aLink['url'] : 'javascript:void(0)',
  369. 'attrs' => $sLinkAttrs
  370. ]
  371. ],
  372. 'link' => !empty($aLink['url']) ? $aLink['url'] : 'javascript:void(0)',
  373. 'attrs' => $sLinkAttrs,
  374. 'content' => $aLink['title'],
  375. 'bx_if:show_text' => [
  376. 'condition' => !empty($aLink['text']),
  377. 'content' => [
  378. 'style_prefix' => $sStylePrefix,
  379. 'text' => $aLink['text']
  380. ]
  381. ]
  382. ));
  383. }
  384. $aTmplVarsLinks[] = [
  385. 'style_prefix' => $sStylePrefix,
  386. 'link' => $sLink
  387. ];
  388. }
  389. }
  390. $aVars['bx_if:show_links'] = [
  391. 'condition' => count($aTmplVarsLinks) > 0,
  392. 'content' => [
  393. 'style_prefix' => $sStylePrefix,
  394. 'bx_repeat:links' => $aTmplVarsLinks
  395. ]
  396. ];
  397. if(!empty($CNF['OBJECT_REACTIONS']) && ($oReactions = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $aData[$CNF['FIELD_ID']])) !== false)
  398. $aVars['content_description_after'] .= $oReactions->getCounter([
  399. 'show_counter' => true,
  400. 'show_counter_empty' => false
  401. ]);
  402. $this->addCss(array('cover.css'));
  403. return $aVars;
  404. }
  405. function getAuthorDesc($aData, $oProfile)
  406. {
  407. $CNF = &$this->getModule()->_oConfig->CNF;
  408. $aItem = array(
  409. 'bx_if:text' => array(
  410. 'condition' => false,
  411. 'content' => array(
  412. 'content' => ''
  413. )
  414. ),
  415. 'bx_if:link' => array(
  416. 'condition' => false,
  417. 'content' => array(
  418. 'link' => '',
  419. 'content' => ''
  420. )
  421. )
  422. );
  423. $aTmplVarsItems = array();
  424. if(!empty($CNF['FIELD_ADDED']) && !empty($aData[$CNF['FIELD_ADDED']]))
  425. $aTmplVarsItems[] = array_merge($aItem, array('bx_if:text' => array(
  426. 'condition' => true,
  427. 'content' => array(
  428. 'content' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE)
  429. )
  430. )));
  431. if(!empty($CNF['URI_AUTHOR_ENTRIES']))
  432. $aTmplVarsItems[] = array_merge($aItem, array('bx_if:link' => array(
  433. 'condition' => true,
  434. 'content' => array(
  435. 'link' => BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id=' . $oProfile->id()),
  436. 'content' => _t($CNF['T']['txt_all_entries_by'], $this->getModule()->serviceGetMenuAddonManageToolsProfileStats($oProfile->id()))
  437. )
  438. )));
  439. return $this->parseHtmlByName('author_desc.html', array(
  440. 'bx_repeat:items' => $aTmplVarsItems
  441. ));
  442. }
  443. function getAuthorProfileDesc ($aData, $oProfile)
  444. {
  445. $aSnippetMeta = $this->getProfileSnippetMenu($aData);
  446. if(empty($aSnippetMeta) || !is_array($aSnippetMeta) || !isset($aSnippetMeta['meta']))
  447. return '';
  448. return $aSnippetMeta['meta'];
  449. }
  450. function getProfileSnippetMenu ($aData)
  451. {
  452. $CNF = &$this->getModule()->_oConfig->CNF;
  453. if (!($oProfile = BxDolProfile::getInstance($aData[$CNF['FIELD_AUTHOR']])))
  454. return array();
  455. return bx_srv($oProfile->getModule(), 'get_snippet_menu_vars', array($oProfile->id()));
  456. }
  457. function getAuthorAddon ($aData, $oProfile)
  458. {
  459. return '';
  460. }
  461. protected function checkPrivacy ($aData, $isCheckPrivateContent, $oModule, $sTemplateName = '')
  462. {
  463. if ($isCheckPrivateContent && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $oModule->checkAllowedView($aData))) {
  464. $aVars = array (
  465. 'summary' => $sMsg,
  466. );
  467. return $this->parseHtmlByName($sTemplateName ? str_replace('.html', '_private.html', $sTemplateName) : 'unit_private.html', $aVars);
  468. }
  469. return '';
  470. }
  471. protected function getUnitThumbAndGallery ($aData)
  472. {
  473. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  474. $sPhotoThumb = '';
  475. $sPhotoGallery = '';
  476. if(!empty($CNF['FIELD_THUMB']) && !empty($aData[$CNF['FIELD_THUMB']])) {
  477. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  478. if ($oImagesTranscoder)
  479. $sPhotoThumb = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  480. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  481. if ($oImagesTranscoder)
  482. $sPhotoGallery = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  483. else
  484. $sPhotoGallery = $sPhotoThumb;
  485. }
  486. return array($sPhotoThumb, $sPhotoGallery);
  487. }
  488. protected function getUnit ($aData, $aParams = array())
  489. {
  490. $CNF = &$this->_oConfig->CNF;
  491. $oModule = $this->getModule();
  492. // get thumb url
  493. list($sPhotoThumb, $sPhotoGallery) = $this->getUnitThumbAndGallery($aData);
  494. if ($sPhotoGallery == '' && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  495. if(!empty($CNF['OBJECT_STORAGE_PHOTOS'])){
  496. $sStorage = $CNF['OBJECT_STORAGE_PHOTOS'];
  497. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  498. list($oTranscoder, $oTranscoderView) = $this->getAttachmentsImagesTranscoders($sStorage);
  499. $aGhostFiles = $oStorage->getGhosts($oModule->serviceGetContentOwnerProfileId($aData[$CNF['FIELD_ID']]), $aData[$CNF['FIELD_ID']]);
  500. if(!empty($aGhostFiles) && is_array($aGhostFiles)) {
  501. $aGhostFile = array_shift($aGhostFiles);
  502. $sPhotoThumb = $oTranscoderView->getFileUrl($aGhostFile['id']);
  503. $sPhotoGallery = $oTranscoder->getFileUrl($aGhostFile['id']);
  504. }
  505. }
  506. }
  507. // get entry url
  508. $sUrl = $this->_oConfig->getViewEntryUrl($aData[$CNF['FIELD_ID']]);
  509. $oProfile = BxDolProfile::getInstanceMagic($aData[$CNF['FIELD_AUTHOR']]);
  510. $sTitle = $this->getTitle($aData);
  511. $sText = $this->getText($aData);
  512. $sSummary = $this->getSummary($aData, $sTitle, $sText, $sUrl);
  513. $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'])) : '';
  514. if(!empty($CNF['OBJECT_METATAGS'])) {
  515. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  516. $sText = $oMetatags->metaParse($aData[$CNF['FIELD_ID']], $sText);
  517. }
  518. $aTmplVarsMeta = [];
  519. if(!empty($CNF['OBJECT_MENU_SNIPPET_META'])) {
  520. $oMenuMeta = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this);
  521. if($oMenuMeta) {
  522. $oMenuMeta->setContentId($aData[$CNF['FIELD_ID']]);
  523. if(isset($aParams['context']))
  524. $oMenuMeta->setContext($aParams['context']);
  525. $aTmplVarsMeta = [
  526. 'meta' => $oMenuMeta->getCode()
  527. ];
  528. }
  529. }
  530. $bBadgesSingle = isset($aParams['badges_single']) ? $aParams['badges_single'] : false;
  531. $bBadgesCompact = isset($aParams['badges_compact']) ? $aParams['badges_compact'] : false;
  532. $sCoverData = ($sKey = 'FIELD_THUMB_POSITION') && isset($CNF[$sKey]) && $aData[$CNF[$sKey]] ?? '';
  533. $sCoverSettings = $this->_getImageSettings($CNF['FIELD_THUMB'], $sCoverData, 'unit_cover');
  534. $aTmplVars = array (
  535. 'class' => $this->_getUnitClass($aData,(isset($aParams['template_name']) ? $aParams['template_name'] : '')),
  536. 'html_id' => $this->_getUnitHtmlId($aData,(isset($aParams['template_name']) ? $aParams['template_name'] : '')),
  537. 'id' => $aData[$CNF['FIELD_ID']],
  538. 'content_url' => $sUrl,
  539. 'bx_if:show_onclick' => [
  540. 'condition' => false,
  541. 'content' => [
  542. 'content_onclick' => ''
  543. ]
  544. ],
  545. 'title' => $sTitle,
  546. 'badges' => $oModule->serviceGetBadges($aData[$CNF['FIELD_ID']], $bBadgesSingle, $bBadgesCompact),
  547. 'title_attr' => bx_html_attribute($sTitle),
  548. 'summary' => $sSummary,
  549. 'text' => $sText,
  550. 'author' => $oProfile->getDisplayName(),
  551. 'author_url' => $oProfile->getUrl(),
  552. 'author_icon' => $oProfile->getIcon(),
  553. 'author_thumb' => $oProfile->getThumb(),
  554. 'author_avatar' => $oProfile->getAvatar(),
  555. 'entry_posting_date' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE),
  556. 'module_name' => _t($CNF['T']['txt_sample_single']),
  557. 'ts' => $aData[$CNF['FIELD_ADDED']],
  558. 'bx_if:meta' => array(
  559. 'condition' => !empty($aTmplVarsMeta),
  560. 'content' => $aTmplVarsMeta
  561. ),
  562. 'bx_if:thumb' => array (
  563. 'condition' => $sPhotoThumb,
  564. 'content' => array (
  565. 'title' => $sTitle,
  566. 'summary_attr' => bx_html_attribute($sSummaryPlain),
  567. 'content_url' => $sUrl,
  568. 'bx_if:show_thumb_onclick' => [
  569. 'condition' => false,
  570. 'content' => [
  571. 'content_onclick' => ''
  572. ]
  573. ],
  574. 'thumb_url' => $sPhotoThumb ? $sPhotoThumb : '',
  575. 'gallery_url' => $sPhotoGallery ? $sPhotoGallery : '',
  576. 'image_settings' => $sCoverSettings,
  577. 'strecher' => str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', 40),
  578. ),
  579. ),
  580. 'bx_if:no_thumb' => array (
  581. 'condition' => !$sPhotoThumb,
  582. 'content' => array (
  583. 'module_icon' => $CNF['ICON'],
  584. 'content_url' => $sUrl,
  585. 'bx_if:show_no_thumb_onclick' => [
  586. 'condition' => false,
  587. 'content' => [
  588. 'content_onclick' => ''
  589. ]
  590. ],
  591. 'summary_plain' => $sSummaryPlain,
  592. 'strecher' => mb_strlen($sSummaryPlain) > 240 ? '' : str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', round((240 - mb_strlen($sSummaryPlain)) / 6)),
  593. ),
  594. ),
  595. 'unit_content_before' => '',
  596. 'unit_content_after' => ''
  597. );
  598. if(isset($aParams['template_vars']) && is_array($aParams['template_vars']))
  599. $aTmplVars = array_merge($aTmplVars, $aParams['template_vars']);
  600. // generate html
  601. return $aTmplVars;
  602. }
  603. protected function getAttachmentsImagesTranscoders ($sStorage = '')
  604. {
  605. $CNF = &$this->getModule()->_oConfig->CNF;
  606. $oTranscoder = null;
  607. $oTranscoderView = null;
  608. if(isset($CNF['OBJECT_STORAGE_PHOTOS']) && $CNF['OBJECT_STORAGE_PHOTOS'] == $sStorage) {
  609. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']))
  610. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']);
  611. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']))
  612. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']);
  613. else if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']))
  614. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']);
  615. }
  616. else if(isset($CNF['OBJECT_STORAGE_FILES']) && $CNF['OBJECT_STORAGE_FILES'] == $sStorage) {
  617. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES']))
  618. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES']);
  619. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']))
  620. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']);
  621. }
  622. else
  623. list($oTranscoder, $oTranscoderView) = parent::getAttachmentsImagesTranscoders($sStorage);
  624. return array($oTranscoder, $oTranscoderView);
  625. }
  626. protected function _getUnitName($aData, $sTemplateName = 'unit.html')
  627. {
  628. return trim(str_replace('.html', '', $sTemplateName));
  629. }
  630. protected function _getUnitClass($aData, $sTemplateName = 'unit.html')
  631. {
  632. $sResult = '';
  633. switch($sTemplateName) {
  634. case 'unit_showcase.html':
  635. $sResult = $this->_sUnitClassShowCase;
  636. break;
  637. }
  638. return $sResult;
  639. }
  640. protected function _getUnitHtmlId($aData, $sTemplateName = 'unit.html')
  641. {
  642. $CNF = &$this->_oConfig->CNF;
  643. return str_replace('_', '-', $this->MODULE . '_unit_' . $aData[$CNF['FIELD_ID']]);
  644. }
  645. protected function _getHeaderImageParams()
  646. {
  647. $CNF = &$this->_oConfig->CNF;
  648. return [
  649. 'field' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : false,
  650. 'field_position' => isset($CNF['FIELD_THUMB_POSITION']) ? $CNF['FIELD_THUMB_POSITION'] : false,
  651. 'storage' => isset($CNF['OBJECT_STORAGE']) ? $CNF['OBJECT_STORAGE'] : false,
  652. 'uploaders' => isset($CNF['OBJECT_UPLOADERS']) ? $CNF['OBJECT_UPLOADERS'] : false,
  653. 'transcoder_cover' => isset($CNF['OBJECT_IMAGES_TRANSCODER_COVER']) ? $CNF['OBJECT_IMAGES_TRANSCODER_COVER'] : false,
  654. ];
  655. }
  656. protected function _getHeaderImage($aData)
  657. {
  658. return $this->getModule()->getEntryImageData($aData);
  659. }
  660. function mediaExif ($aMediaInfo, $iProfileId = false, $sFuncAuthorDesc = '', $sTemplateName = 'media-exif.html')
  661. {
  662. if (empty($aMediaInfo['exif']))
  663. return '';
  664. $a = unserialize($aMediaInfo['exif']);
  665. $s = '';
  666. if (!empty($a['Make'])) {
  667. $oModule = BxDolModule::getInstance($this->MODULE);
  668. $CNF = &$oModule->_oConfig->CNF;
  669. $sCamera = BxDolMetatags::keywordsCameraModel($a);
  670. if (!empty($CNF['OBJECT_METATAGS_MEDIA_CAMERA'])) {
  671. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS_MEDIA_CAMERA']);
  672. if ($oMetatags->keywordsIsEnabled()) {
  673. $sCamera = $oMetatags->keywordsParseOne($aMediaInfo['id'], $sCamera);
  674. }
  675. }
  676. if (!empty($sCamera))
  677. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  678. 'key' => _t($CNF['T']['txt_media_exif_camera']),
  679. 'val' => $sCamera,
  680. ));
  681. }
  682. if (!empty($a['FocalLength']))
  683. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  684. 'key' => _t($CNF['T']['txt_media_exif_focal_length']),
  685. 'val' => _t($CNF['T']['txt_media_exif_focal_length_value'], $a['FocalLength']),
  686. ));
  687. if (!empty($a['COMPUTED']['ApertureFNumber']))
  688. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  689. 'key' => _t($CNF['T']['txt_media_exif_aperture']),
  690. 'val' => $a['COMPUTED']['ApertureFNumber'],
  691. ));
  692. if (!empty($a['ExposureTime']))
  693. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  694. 'key' => _t($CNF['T']['txt_media_exif_shutter_speed']),
  695. 'val' => _t($CNF['T']['txt_media_exif_shutter_speed_value'], $a['ExposureTime']),
  696. ));
  697. if (!empty($a['ISOSpeedRatings']))
  698. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  699. 'key' => _t($CNF['T']['txt_media_exif_iso']),
  700. 'val' => $a['ISOSpeedRatings'],
  701. ));
  702. if (empty($s))
  703. return '';
  704. return $this->parseHtmlByName($sTemplateName, array('content' => $s));
  705. }
  706. }
  707. /** @} */