1
0

BxBaseModTextTemplate.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  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. 'tmpl_name_ref' => &$sTemplateName,
  70. 'tmpl_vars_ref' => &$aTemplateVars,
  71. ]);
  72. return $this->parseHtmlByName($sTemplateName, $aTemplateVars);
  73. }
  74. function entryAttachments ($aData, $aParams = array())
  75. {
  76. $CNF = &$this->getModule()->_oConfig->CNF;
  77. $aStoragesKeys = array('OBJECT_STORAGE_PHOTOS', 'OBJECT_STORAGE_VIDEOS', 'OBJECT_STORAGE_SOUNDS', 'OBJECT_STORAGE_FILES');
  78. $aStorages = array();
  79. foreach($aStoragesKeys as $sKey)
  80. if(!empty($CNF[$sKey]))
  81. $aStorages[] = $CNF[$sKey];
  82. if(!empty($aStorages))
  83. return $this->entryAttachmentsByStorage($aStorages, $aData, array_merge($aParams, array('filter_field' => '')));
  84. return parent::entryAttachments($aData, $aParams);
  85. }
  86. function entryAuthor ($aData, $iProfileId = false, $sFuncAuthorDesc = 'getAuthorDesc', $sTemplateName = 'author.html', $sFuncAuthorAddon = 'getAuthorAddon')
  87. {
  88. $oModule = $this->getModule();
  89. $CNF = &$oModule->_oConfig->CNF;
  90. if (!$iProfileId)
  91. $iProfileId = $aData[$CNF['FIELD_AUTHOR']];
  92. if($this->_bIsApi) {
  93. $sFldAdd = 'FIELD_ADDED';
  94. $sFldAvt = 'FIELD_ALLOW_VIEW_TO';
  95. return [
  96. bx_api_get_block('entity_author', [
  97. 'author_data' => BxDolProfile::getData($iProfileId),
  98. 'entry_date' => !empty($CNF[$sFldAdd]) && !empty($aData[$CNF[$sFldAdd]]) ? $aData[$CNF[$sFldAdd]] : '',
  99. 'entry_context' => !empty($CNF[$sFldAvt]) && (int)$aData[$CNF[$sFldAvt]] < 0 ? BxDolProfile::getData(abs((int)$aData[$CNF[$sFldAvt]])) : '',
  100. 'menu_manage' => $oModule->getEntryAllActions()
  101. ])
  102. ];
  103. }
  104. $oProfile = BxDolProfile::getInstanceMagic($iProfileId);
  105. $sName = $oProfile->getDisplayName();
  106. $sAddon = $sFuncAuthorAddon && is_a($oProfile, 'BxDolProfile') ? $this->$sFuncAuthorAddon($aData, $oProfile) : '';
  107. return $this->parseHtmlByName($sTemplateName, [
  108. 'author_url' => $oProfile->getUrl(),
  109. 'author_thumb_url' => $oProfile->getThumb(),
  110. 'author_unit' => $oProfile->getUnit(0, ['template' => 'unit_wo_info']),
  111. 'author_title' => $sName,
  112. 'author_title_attr' => bx_html_attribute($sName),
  113. 'author_desc' => $sFuncAuthorDesc ? $this->$sFuncAuthorDesc($aData, $oProfile) : '',
  114. 'author_profile_desc' => $this->getAuthorProfileDesc($aData, $oProfile),
  115. 'bx_if:addon' => [
  116. 'condition' => (bool)$sAddon,
  117. 'content' => [
  118. 'content' => $sAddon,
  119. ],
  120. ],
  121. ]);
  122. }
  123. public function entryBreadcrumb($aContentInfo, $aTmplVarsItems = array())
  124. {
  125. if(!empty($aTmplVarsItems) && is_array($aTmplVarsItems))
  126. return parent::entryBreadcrumb($aContentInfo, $aTmplVarsItems);
  127. $CNF = &$this->getModule()->_oConfig->CNF;
  128. $aTmplVarsItems = array();
  129. if(!empty($CNF['OBJECT_CATEGORY']) && !empty($CNF['FIELD_CATEGORY'])) {
  130. $oCategory = BxDolCategory::getObjectInstance($CNF['OBJECT_CATEGORY']);
  131. $aParams = [];
  132. if(isset($CNF['URL_CATEGORY']))
  133. $aParams['page'] = bx_append_url_params(BxDolPermalinks::getInstance()->permalink($CNF['URL_CATEGORY']), [
  134. 'category' => '{keyword}'
  135. ], true, ['{keyword}']);
  136. $aTmplVarsItems[] = array(
  137. 'url' => $oCategory->getCategoryUrl($aContentInfo[$CNF['FIELD_CATEGORY']], $aParams),
  138. 'title' => $oCategory->getCategoryTitle($aContentInfo[$CNF['FIELD_CATEGORY']])
  139. );
  140. }
  141. $aTmplVarsItems[] = array(
  142. 'url' => BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aContentInfo[$CNF['FIELD_ID']]),
  143. 'title' => bx_process_output($aContentInfo[$CNF['FIELD_TITLE']])
  144. );
  145. return parent::entryBreadcrumb($aContentInfo, $aTmplVarsItems);
  146. }
  147. protected function _addCssJsPolls($bDynamic = false)
  148. {
  149. $sInclude = parent::_addCssJsPolls($bDynamic);
  150. $sInclude .= $this->addJs(['modules/base/text/js/|polls.js','polls.js'], $bDynamic);
  151. return $bDynamic ? $sInclude : '';
  152. }
  153. public function getAttachLinkForm($iContentId = 0)
  154. {
  155. $sStylePrefix = $this->_oConfig->getPrefix('style');
  156. $sJsObject = $this->_oConfig->getJsObject('links');
  157. $aForm = $this->getModule()->getFormAttachLink($iContentId);
  158. return $this->parseHtmlByName('attach_link_form.html', array(
  159. 'style_prefix' => $sStylePrefix,
  160. 'js_object' => $sJsObject,
  161. 'form_id' => $aForm['form_id'],
  162. 'form' => $aForm['form'],
  163. ));
  164. }
  165. public function getAttachLinkField($iUserId, $iContentId = 0)
  166. {
  167. $sStylePrefix = $this->_oConfig->getPrefix('style');
  168. if(!$iContentId)
  169. $aLinks = $this->_oDb->getUnusedLinks($iUserId);
  170. else
  171. $aLinks = $this->_oDb->getLinks($iContentId);
  172. $sLinks = '';
  173. foreach($aLinks as $aLink)
  174. $sLinks .= $this->getAttachLinkItem($iUserId, $aLink);
  175. return $this->parseHtmlByName('attach_link_form_field.html', array(
  176. 'html_id' => $this->_oConfig->getHtmlIds('attach_link_form_field') . $iContentId,
  177. 'style_prefix' => $sStylePrefix,
  178. 'links' => $sLinks
  179. ));
  180. }
  181. public function getAttachLinkItem($iUserId, $mixedLink, $aParams = [])
  182. {
  183. $CNF = &$this->getModule()->_oConfig->CNF;
  184. return parent::getAttachLinkItem($iUserId, $mixedLink, array_merge($aParams ?? [], [
  185. 'html_id_link_item' => $this->_oConfig->getHtmlIds('attach_link_item'),
  186. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  187. 'js_object' => $this->_oConfig->getJsObject('links'),
  188. 'transcoder' => $CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']
  189. ]));
  190. }
  191. public function getAttachLinks($iContentId)
  192. {
  193. $CNF = &$this->getModule()->_oConfig->CNF;
  194. $aLinks = $this->_oDb->getLinks($iContentId);
  195. if(empty($aLinks) || !is_array($aLinks))
  196. return array();
  197. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']);
  198. $aResult = array();
  199. foreach($aLinks as $aLink)
  200. $aResult[] = array(
  201. 'url' => $aLink['url'],
  202. 'title' => $aLink['title'],
  203. 'text' => $aLink['text'],
  204. 'thumbnail' => (int)$aLink['media_id'] != 0 ? $oTranscoder->getFileUrl($aLink['media_id']) : ''
  205. );
  206. return $aResult;
  207. }
  208. public function getTmplVarsText($aData)
  209. {
  210. $CNF = &$this->getModule()->_oConfig->CNF;
  211. $sStylePrefix = $this->_oConfig->getPrefix('style');
  212. $aVars = parent::getTmplVarsText($aData);
  213. $aImageParams = $this->_getHeaderImageParams();
  214. $mixedImage = $this->_getHeaderImage($aData);
  215. $sImage = '';
  216. if($mixedImage !== false) {
  217. if(!empty($mixedImage['object']))
  218. $o = BxDolStorage::getObjectInstance($mixedImage['object']);
  219. else if(!empty($mixedImage['transcoder']))
  220. $o = BxDolTranscoder::getObjectInstance($mixedImage['transcoder']);
  221. if($o)
  222. $sImage = $o->getFileUrlById($mixedImage['id']);
  223. }
  224. if($this->_bIsApi) {
  225. if($sImage)
  226. $aVars['image'] = bx_api_get_image($aImageParams['storage'], $mixedImage['id']);
  227. // Lets the app change the images right on the view page, like a profile cover.
  228. $aVars['images_edit'] = $this->_getImagesEditApi($aData);
  229. return $aVars;
  230. }
  231. $sAddClassPicture = "";
  232. $sAddCode = "";
  233. $oModule = $this->getModule();
  234. $bIsAllowEditPicture = CHECK_ACTION_RESULT_ALLOWED === $oModule->checkAllowedEdit($aData);
  235. if($aImageParams['field'] && $aImageParams['uploaders'] && $aImageParams['storage'] && $aImageParams['transcoder_cover']) {
  236. /**
  237. * @hooks
  238. * @hookdef hook-system-image_editor 'system', 'image_editor' - hook to override content header image editor
  239. * - $unit_name - equals `system`
  240. * - $action - equals `image_editor`
  241. * - $object_id - not used
  242. * - $sender_id - not used
  243. * - $extra_params - array of additional params with the following array keys:
  244. * - `module` - [string] module name
  245. * - `content_id` - [int] profile content id
  246. * - `is_allow_edit` - [boolean] if edit action is allowed to current user
  247. * - `image_type` - [string] image type equals to `header_image`
  248. * - `image_url` - [string] image URL
  249. * - `uploader` - [string] uploader name
  250. * - `storage` - [string] storage name
  251. * - `transcoder` - [string] transcoder name
  252. * - `field` - [string] field name
  253. * - `is_background` - [boolean] if image is used as background, always `false`
  254. * - `add_class` - [string] by ref, class to add, can be overridden in hook processing
  255. * - `add_code` - [array] by ref, code to add, can be overridden in hook processing
  256. * @hook @ref hook-system-image_editor
  257. */
  258. bx_alert('system', 'image_editor', 0, 0, [
  259. 'module' => $oModule->getName(),
  260. 'content_id' => $aData[$CNF['FIELD_ID']],
  261. 'is_allow_edit' => $bIsAllowEditPicture,
  262. 'image_type' => 'header_image',
  263. 'image_url' => $sImage,
  264. 'uploader' => $aImageParams['uploaders'] && is_array($aImageParams['uploaders']) ? $aImageParams['uploaders'][0] : '',
  265. 'storage' => $aImageParams['storage'],
  266. 'transcoder' => $aImageParams['transcoder_cover'],
  267. 'field' => $aImageParams['field'],
  268. 'is_background' => false,
  269. 'add_class' => &$sAddClassPicture,
  270. 'add_code' => &$sAddCode,
  271. 'add_class_ref' => &$sAddClassPicture,
  272. 'add_code_ref' => &$sAddCode,
  273. ]);
  274. }
  275. $sImageTweak = '';
  276. $sUniqIdImage = genRndPwd (8, false);
  277. if ($bIsAllowEditPicture && empty($sAddCode) && $aImageParams['field_position']){
  278. $sImageTweak = $this->_prepareImage($aData, $sUniqIdImage, $aImageParams['uploaders'], $aImageParams['storage'], $aImageParams['field'], true);
  279. }
  280. $aVars['content_description_before'] = '';
  281. $aVars['content_description_after'] = '';
  282. $aVars['bx_if:show_image'] = array(
  283. 'condition' => !empty($sImage),
  284. 'content' => array(
  285. 'entry_image' => $sImage,
  286. 'image_settings' => $aImageParams['field_position'] ? $this->_getImageSettings($aImageParams['field'], $aData[$aImageParams['field_position']], 'page_cover') : '',
  287. 'add_class' => $sAddClassPicture,
  288. 'img_class' => $sAddClassPicture != '' ? 'bx-media-editable-src' : '',
  289. 'additional_code' => $sAddCode,
  290. 'image_tweak' => $sImageTweak,
  291. 'unique_id' => $sUniqIdImage,
  292. )
  293. );
  294. $aTmplVarsLinks = [];
  295. if(isset($CNF['FIELD_LINK']) && ($aLinks = $this->getAttachLinks($aData[$CNF['FIELD_ID']])))
  296. $aTmplVarsLinks = $this->getTmplVarsAttachedLinks($aLinks);
  297. $aVars['bx_if:show_links'] = [
  298. 'condition' => count($aTmplVarsLinks) > 0,
  299. 'content' => [
  300. 'style_prefix' => $sStylePrefix,
  301. 'bx_repeat:links' => $aTmplVarsLinks
  302. ]
  303. ];
  304. if(!empty($CNF['OBJECT_REACTIONS']) && ($oReactions = BxDolVote::getObjectInstance($CNF['OBJECT_REACTIONS'], $aData[$CNF['FIELD_ID']])) !== false)
  305. $aVars['content_description_after'] .= $oReactions->getCounter([
  306. 'show_counter' => true,
  307. 'show_counter_empty' => false
  308. ]);
  309. $this->addCss(array('cover.css'));
  310. return $aVars;
  311. }
  312. function getAuthorDesc($aData, $oProfile)
  313. {
  314. $CNF = &$this->getModule()->_oConfig->CNF;
  315. $aItem = array(
  316. 'bx_if:text' => array(
  317. 'condition' => false,
  318. 'content' => array(
  319. 'content' => ''
  320. )
  321. ),
  322. 'bx_if:link' => array(
  323. 'condition' => false,
  324. 'content' => array(
  325. 'link' => '',
  326. 'content' => ''
  327. )
  328. )
  329. );
  330. $aTmplVarsItems = array();
  331. if(!empty($CNF['FIELD_ADDED']) && !empty($aData[$CNF['FIELD_ADDED']]))
  332. $aTmplVarsItems[] = array_merge($aItem, array('bx_if:text' => array(
  333. 'condition' => true,
  334. 'content' => array(
  335. 'content' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE)
  336. )
  337. )));
  338. if(!empty($CNF['URI_AUTHOR_ENTRIES']))
  339. $aTmplVarsItems[] = array_merge($aItem, array('bx_if:link' => array(
  340. 'condition' => true,
  341. 'content' => array(
  342. 'link' => BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id=' . $oProfile->id()),
  343. 'content' => _t($CNF['T']['txt_all_entries_by'], $this->getModule()->serviceGetMenuAddonManageToolsProfileStats($oProfile->id()))
  344. )
  345. )));
  346. return $this->parseHtmlByName('author_desc.html', array(
  347. 'bx_repeat:items' => $aTmplVarsItems
  348. ));
  349. }
  350. function getAuthorProfileDesc ($aData, $oProfile)
  351. {
  352. $aSnippetMeta = $this->getProfileSnippetMenu($aData);
  353. if(empty($aSnippetMeta) || !is_array($aSnippetMeta) || !isset($aSnippetMeta['meta']))
  354. return '';
  355. return $aSnippetMeta['meta'];
  356. }
  357. function getProfileSnippetMenu ($aData)
  358. {
  359. $CNF = &$this->getModule()->_oConfig->CNF;
  360. if (!($oProfile = BxDolProfile::getInstance($aData[$CNF['FIELD_AUTHOR']])))
  361. return array();
  362. return bx_srv($oProfile->getModule(), 'get_snippet_menu_vars', array($oProfile->id()));
  363. }
  364. function getAuthorAddon ($aData, $oProfile)
  365. {
  366. return '';
  367. }
  368. protected function checkPrivacy ($aData, $isCheckPrivateContent, $oModule, $sTemplateName = '')
  369. {
  370. $CNF = &$this->_oConfig->CNF;
  371. if($isCheckPrivateContent && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $oModule->checkAllowedView($aData)))
  372. return $this->parseHtmlByName($sTemplateName ? str_replace('.html', '_private.html', $sTemplateName) : 'unit_private.html', [
  373. 'module_name' => _t($CNF['T']['txt_sample_single']),
  374. 'module_icon' => $CNF['ICON'],
  375. 'title' => _t('_sys_private_content'),
  376. 'summary' => $sMsg,
  377. 'ts' => $aData[$CNF['FIELD_ADDED']],
  378. ]);
  379. return '';
  380. }
  381. protected function getUnitThumbAndGallery ($aData)
  382. {
  383. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  384. $sPhotoThumb = '';
  385. $sPhotoGallery = '';
  386. if(!empty($CNF['FIELD_THUMB']) && !empty($aData[$CNF['FIELD_THUMB']])) {
  387. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  388. if ($oImagesTranscoder)
  389. $sPhotoThumb = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  390. $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
  391. if ($oImagesTranscoder)
  392. $sPhotoGallery = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
  393. else
  394. $sPhotoGallery = $sPhotoThumb;
  395. }
  396. return array($sPhotoThumb, $sPhotoGallery);
  397. }
  398. protected function getUnit ($aData, $aParams = array())
  399. {
  400. $CNF = &$this->_oConfig->CNF;
  401. $oModule = $this->getModule();
  402. // get thumb url
  403. list($sPhotoThumb, $sPhotoGallery) = $this->getUnitThumbAndGallery($aData);
  404. if ($sPhotoGallery == '' && isset($CNF['PARAM_USE_GALERY_AS_COVER']) && getParam($CNF['PARAM_USE_GALERY_AS_COVER']) == 'on'){
  405. if(!empty($CNF['OBJECT_STORAGE_PHOTOS'])){
  406. $sStorage = $CNF['OBJECT_STORAGE_PHOTOS'];
  407. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  408. list($oTranscoder, $oTranscoderView) = $this->getAttachmentsImagesTranscoders($sStorage);
  409. $aGhostFiles = $oStorage->getGhosts($oModule->serviceGetContentOwnerProfileId($aData[$CNF['FIELD_ID']]), $aData[$CNF['FIELD_ID']]);
  410. if(!empty($aGhostFiles) && is_array($aGhostFiles)) {
  411. $aGhostFile = array_shift($aGhostFiles);
  412. $sPhotoThumb = $oTranscoderView->getFileUrl($aGhostFile['id']);
  413. $sPhotoGallery = $oTranscoder->getFileUrl($aGhostFile['id']);
  414. }
  415. }
  416. }
  417. $oProfile = BxDolProfile::getInstanceMagic($aData[$CNF['FIELD_AUTHOR']]);
  418. $sUrl = $this->getUnitLink($aData);
  419. $sTitle = $this->getUnitTitle($aData);
  420. $sText = $this->getUnitText($aData);
  421. $sSummary = $this->getUnitSummary($aData, $sTitle, $sText, $sUrl);
  422. $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'])) : '';
  423. if(!empty($CNF['OBJECT_METATAGS'])) {
  424. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  425. $sText = $oMetatags->metaParse($aData[$CNF['FIELD_ID']], $sText);
  426. }
  427. $aTmplVarsMeta = [];
  428. if(!empty($CNF['OBJECT_MENU_SNIPPET_META'])) {
  429. $oMenuMeta = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this);
  430. if($oMenuMeta) {
  431. $oMenuMeta->setContentId($aData[$CNF['FIELD_ID']]);
  432. if(isset($aParams['context']))
  433. $oMenuMeta->setContext($aParams['context']);
  434. $aTmplVarsMeta = [
  435. 'meta' => $oMenuMeta->getCode()
  436. ];
  437. }
  438. }
  439. $bBadgesSingle = isset($aParams['badges_single']) ? $aParams['badges_single'] : false;
  440. $bBadgesCompact = isset($aParams['badges_compact']) ? $aParams['badges_compact'] : false;
  441. $sCoverData = ($sKey = 'FIELD_THUMB_POSITION') && isset($CNF[$sKey], $aData[$CNF[$sKey]]) ? $aData[$CNF[$sKey]] : '';
  442. $sCoverSettings = ($sKey = 'FIELD_THUMB') && isset($CNF[$sKey]) ? $this->_getImageSettings($CNF[$sKey], $sCoverData, 'unit_cover') : '';
  443. $aTmplVars = array (
  444. 'class' => $this->_getUnitClass($aData,(isset($aParams['template_name']) ? $aParams['template_name'] : '')),
  445. 'html_id' => $this->_getUnitHtmlId($aData,(isset($aParams['template_name']) ? $aParams['template_name'] : '')),
  446. 'id' => $aData[$CNF['FIELD_ID']],
  447. 'content_url' => $sUrl,
  448. 'content_url_attrs' => '',
  449. 'bx_if:show_onclick' => [
  450. 'condition' => false,
  451. 'content' => [
  452. 'content_onclick' => ''
  453. ]
  454. ],
  455. 'title' => $sTitle,
  456. 'badges' => $oModule->serviceGetBadges($aData[$CNF['FIELD_ID']], $bBadgesSingle, $bBadgesCompact),
  457. 'title_attr' => bx_html_attribute($sTitle),
  458. 'summary' => $sSummary,
  459. 'text' => $sText,
  460. 'author' => $oProfile->getDisplayName(),
  461. 'author_url' => $oProfile->getUrl(),
  462. 'author_icon' => $oProfile->getIcon(),
  463. 'author_thumb' => $oProfile->getThumb(),
  464. 'author_avatar' => $oProfile->getAvatar(),
  465. 'entry_posting_date' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE),
  466. 'module_name' => _t($CNF['T']['txt_sample_single']),
  467. 'ts' => $aData[$CNF['FIELD_ADDED']],
  468. 'bx_if:meta' => array(
  469. 'condition' => !empty($aTmplVarsMeta),
  470. 'content' => $aTmplVarsMeta
  471. ),
  472. 'bx_if:thumb' => array (
  473. 'condition' => $sPhotoThumb,
  474. 'content' => array (
  475. 'title' => $sTitle,
  476. 'summary_attr' => bx_html_attribute($sSummaryPlain),
  477. 'content_url' => $sUrl,
  478. 'bx_if:show_thumb_onclick' => [
  479. 'condition' => false,
  480. 'content' => [
  481. 'content_onclick' => ''
  482. ]
  483. ],
  484. 'thumb_url' => $sPhotoThumb ? $sPhotoThumb : '',
  485. 'gallery_url' => $sPhotoGallery ? $sPhotoGallery : '',
  486. 'image_settings' => $sCoverSettings,
  487. 'strecher' => str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', 40),
  488. ),
  489. ),
  490. 'bx_if:no_thumb' => array (
  491. 'condition' => !$sPhotoThumb,
  492. 'content' => array (
  493. 'module_icon' => $CNF['ICON'],
  494. 'content_url' => $sUrl,
  495. 'bx_if:show_no_thumb_onclick' => [
  496. 'condition' => false,
  497. 'content' => [
  498. 'content_onclick' => ''
  499. ]
  500. ],
  501. 'summary_plain' => $sSummaryPlain,
  502. 'summary_attr' => bx_html_attribute($sSummaryPlain),
  503. 'strecher' => mb_strlen($sSummaryPlain) > 240 ? '' : str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ', round((240 - mb_strlen($sSummaryPlain)) / 6)),
  504. ),
  505. ),
  506. 'unit_content_before' => '',
  507. 'unit_content_after' => ''
  508. );
  509. if(isset($aParams['template_vars']) && is_array($aParams['template_vars']))
  510. $aTmplVars = array_merge($aTmplVars, $aParams['template_vars']);
  511. // generate html
  512. return $aTmplVars;
  513. }
  514. protected function getAttachmentsImagesTranscoders ($sStorage = '')
  515. {
  516. $CNF = &$this->getModule()->_oConfig->CNF;
  517. $oTranscoder = null;
  518. $oTranscoderView = null;
  519. if(isset($CNF['OBJECT_STORAGE_PHOTOS']) && $CNF['OBJECT_STORAGE_PHOTOS'] == $sStorage) {
  520. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']))
  521. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_PHOTOS']);
  522. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']))
  523. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_VIEW_PHOTOS']);
  524. else if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']))
  525. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_PHOTOS']);
  526. }
  527. else if(isset($CNF['OBJECT_STORAGE_FILES']) && $CNF['OBJECT_STORAGE_FILES'] == $sStorage) {
  528. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES']))
  529. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW_FILES']);
  530. if(!empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']))
  531. $oTranscoderView = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY_FILES']);
  532. }
  533. else
  534. list($oTranscoder, $oTranscoderView) = parent::getAttachmentsImagesTranscoders($sStorage);
  535. return array($oTranscoder, $oTranscoderView);
  536. }
  537. protected function _getUnitName($aData, $sTemplateName = 'unit.html')
  538. {
  539. return trim(str_replace('.html', '', $sTemplateName));
  540. }
  541. protected function _getUnitClass($aData, $sTemplateName = 'unit.html')
  542. {
  543. $sResult = '';
  544. switch($sTemplateName) {
  545. case 'unit_showcase.html':
  546. $sResult = $this->_sUnitClassShowCase;
  547. break;
  548. }
  549. return $sResult;
  550. }
  551. protected function _getUnitHtmlId($aData, $sTemplateName = 'unit.html')
  552. {
  553. $CNF = &$this->_oConfig->CNF;
  554. return str_replace('_', '-', $this->MODULE . '_unit_' . $aData[$CNF['FIELD_ID']]);
  555. }
  556. protected function _getHeaderImageParams()
  557. {
  558. $CNF = &$this->_oConfig->CNF;
  559. return [
  560. 'field' => isset($CNF['FIELD_THUMB']) ? $CNF['FIELD_THUMB'] : false,
  561. 'field_position' => isset($CNF['FIELD_THUMB_POSITION']) ? $CNF['FIELD_THUMB_POSITION'] : false,
  562. 'storage' => isset($CNF['OBJECT_STORAGE']) ? $CNF['OBJECT_STORAGE'] : false,
  563. 'uploaders' => isset($CNF['OBJECT_UPLOADERS']) ? $CNF['OBJECT_UPLOADERS'] : false,
  564. 'transcoder_cover' => isset($CNF['OBJECT_IMAGES_TRANSCODER_COVER']) ? $CNF['OBJECT_IMAGES_TRANSCODER_COVER'] : false,
  565. ];
  566. }
  567. protected function _getHeaderImage($aData)
  568. {
  569. return $this->getModule()->getEntryImageData($aData);
  570. }
  571. /**
  572. * Images the viewer may change on the view page, for API: [image_type => [field, storage, uploader]].
  573. * Empty when it's not allowed. The app uploads to the storage and calls update_image with the field.
  574. */
  575. protected function _getImagesEditApi($aData)
  576. {
  577. $CNF = &$this->getModule()->_oConfig->CNF;
  578. if(empty($CNF['FIELD_THUMB']) || empty($CNF['OBJECT_STORAGE']) || empty($CNF['OBJECT_UPLOADERS']))
  579. return [];
  580. // The same rule as for the header image editor on the site.
  581. if($this->getModule()->checkAllowedEdit($aData) !== CHECK_ACTION_RESULT_ALLOWED)
  582. return [];
  583. return [
  584. 'cover' => $this->_getImageEditApi($CNF['FIELD_THUMB']),
  585. ];
  586. }
  587. protected function _getImageEditApi($sField)
  588. {
  589. $CNF = &$this->getModule()->_oConfig->CNF;
  590. $mixedUploaders = $CNF['OBJECT_UPLOADERS'];
  591. return [
  592. 'field' => $sField,
  593. 'storage' => $CNF['OBJECT_STORAGE'],
  594. 'uploader' => is_array($mixedUploaders) ? reset($mixedUploaders) : $mixedUploaders,
  595. ];
  596. }
  597. function mediaExif ($aMediaInfo, $iProfileId = false, $sFuncAuthorDesc = '', $sTemplateName = 'media-exif.html')
  598. {
  599. if (empty($aMediaInfo['exif']))
  600. return '';
  601. $a = unserialize($aMediaInfo['exif']);
  602. $s = '';
  603. if (!empty($a['Make'])) {
  604. $oModule = BxDolModule::getInstance($this->MODULE);
  605. $CNF = &$oModule->_oConfig->CNF;
  606. $sCamera = BxDolMetatags::keywordsCameraModel($a);
  607. if (!empty($CNF['OBJECT_METATAGS_MEDIA_CAMERA'])) {
  608. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS_MEDIA_CAMERA']);
  609. if ($oMetatags->keywordsIsEnabled()) {
  610. $sCamera = $oMetatags->keywordsParseOne($aMediaInfo['id'], $sCamera);
  611. }
  612. }
  613. if (!empty($sCamera))
  614. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  615. 'key' => _t($CNF['T']['txt_media_exif_camera']),
  616. 'val' => $sCamera,
  617. ));
  618. }
  619. if (!empty($a['FocalLength']))
  620. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  621. 'key' => _t($CNF['T']['txt_media_exif_focal_length']),
  622. 'val' => _t($CNF['T']['txt_media_exif_focal_length_value'], $a['FocalLength']),
  623. ));
  624. if (!empty($a['COMPUTED']['ApertureFNumber']))
  625. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  626. 'key' => _t($CNF['T']['txt_media_exif_aperture']),
  627. 'val' => $a['COMPUTED']['ApertureFNumber'],
  628. ));
  629. if (!empty($a['ExposureTime']))
  630. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  631. 'key' => _t($CNF['T']['txt_media_exif_shutter_speed']),
  632. 'val' => _t($CNF['T']['txt_media_exif_shutter_speed_value'], $a['ExposureTime']),
  633. ));
  634. if (!empty($a['ISOSpeedRatings']))
  635. $s .= $this->parseHtmlByName('media-exif-value.html', array(
  636. 'key' => _t($CNF['T']['txt_media_exif_iso']),
  637. 'val' => $a['ISOSpeedRatings'],
  638. ));
  639. if (empty($s))
  640. return '';
  641. return $this->parseHtmlByName($sTemplateName, array('content' => $s));
  642. }
  643. }
  644. /** @} */