BxBaseModGeneralTemplate.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  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 BaseGeneral Base classes for modules
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. /**
  12. * Module representation.
  13. */
  14. class BxBaseModGeneralTemplate extends BxDolModuleTemplate
  15. {
  16. protected $MODULE;
  17. public $aMethodsToCallAddJsCss = array('entry', 'unit');
  18. function __construct(&$oConfig, &$oDb)
  19. {
  20. parent::__construct($oConfig, $oDb);
  21. }
  22. public function addLocationBase()
  23. {
  24. parent::addLocationBase();
  25. $this->addLocation('mod_general', BX_DIRECTORY_PATH_MODULES . 'base' . DIRECTORY_SEPARATOR . 'general' . DIRECTORY_SEPARATOR, BX_DOL_URL_MODULES . 'base/general/');
  26. }
  27. public function getJsCode($sType, $aParams = array(), $mixedWrap = true)
  28. {
  29. $sMask = "{var} {object} = new {class}({params});";
  30. $aMaskMarkers = array();
  31. if(is_array($mixedWrap)) {
  32. if(!empty($mixedWrap['mask']))
  33. $sMask = $mixedWrap['mask'];
  34. if(!empty($mixedWrap['mask_markers']) && is_array($mixedWrap['mask_markers']))
  35. $aMaskMarkers = $mixedWrap['mask_markers'];
  36. }
  37. $sJsClass = $this->_oConfig->getJsClass($sType);
  38. if(!empty($aParams['js_class'])) {
  39. $sJsClass = $aParams['js_class'];
  40. unset($aParams['js_class']);
  41. }
  42. $sJsObject = $this->_oConfig->getJsObject($sType);
  43. if(!empty($aParams['js_object'])) {
  44. $sJsObject = $aParams['js_object'];
  45. unset($aParams['js_object']);
  46. }
  47. $sBaseUri = $this->_oConfig->getBaseUri();
  48. $aParams = array_merge(array(
  49. 'sActionUri' => $sBaseUri,
  50. 'sActionUrl' => BX_DOL_URL_ROOT . $sBaseUri,
  51. 'sObjName' => $sJsObject,
  52. 'aHtmlIds' => array(),
  53. 'oRequestParams' => array()
  54. ), $aParams);
  55. $sContent = bx_replace_markers($sMask, array_merge(array(
  56. 'var' => 'var',
  57. 'object' => $sJsObject,
  58. 'class' => $sJsClass,
  59. 'params' => json_encode($aParams)
  60. ), $aMaskMarkers));
  61. return ($mixedWrap === true || (is_array($mixedWrap) && isset($mixedWrap['wrap']) && $mixedWrap['wrap'] === true)) ? $this->_wrapInTagJsCode($sContent) : $sContent;
  62. }
  63. public function getTitleAuto($aData, $iMaxLen = 20, $sEllipsisSign = '...')
  64. {
  65. $CNF = &$this->getModule()->_oConfig->CNF;
  66. if(isset($aData[$CNF['FIELD_TITLE']]))
  67. return $this->getTitle($aData);
  68. $sResult = $this->getText($aData);
  69. if(strlen($sResult) > 0 && $iMaxLen > 0)
  70. $sResult = strmaxtextlen($sResult, $iMaxLen, $sEllipsisSign);
  71. return $sResult;
  72. }
  73. public function getTitle($aData, $mixedProcessOutput = BX_DATA_TEXT)
  74. {
  75. $CNF = &$this->getModule()->_oConfig->CNF;
  76. if(!isset($aData[$CNF['FIELD_TITLE']]))
  77. return '';
  78. $sResult = $aData[$CNF['FIELD_TITLE']];
  79. if($mixedProcessOutput !== false && !empty($sResult))
  80. $sResult = bx_process_output($sResult, (int)$mixedProcessOutput);
  81. return $sResult;
  82. }
  83. public function getText($aData, $mixedProcessOutput = BX_DATA_HTML)
  84. {
  85. $CNF = &$this->getModule()->_oConfig->CNF;
  86. if(!isset($aData[$CNF['FIELD_TEXT']]))
  87. return '';
  88. $sResult = $aData[$CNF['FIELD_TEXT']];
  89. if($mixedProcessOutput !== false && !empty($sResult))
  90. $sResult = bx_process_output($sResult, (int)$mixedProcessOutput);
  91. return $sResult;
  92. }
  93. protected function getSummary($aData, $sTitle = '', $sText = '', $sUrl = '')
  94. {
  95. $CNF = &$this->getModule()->_oConfig->CNF;
  96. if(empty($CNF['PARAM_CHARS_SUMMARY']))
  97. return '';
  98. // get summary
  99. $sLinkMore = ' <a title="' . bx_html_attribute(_t('_sys_read_more', $sTitle)) . '" href="' . $sUrl . '"><i class="sys-icon ellipsis-h"></i></a>';
  100. return strmaxtextlen($sText, (int)getParam($CNF['PARAM_CHARS_SUMMARY']), $sLinkMore);
  101. }
  102. public function getProfileLink($mixedProfile)
  103. {
  104. if(!is_array($mixedProfile))
  105. $mixedProfile = $this->getModule()->getProfileInfo((int)$mixedProfile);
  106. return $this->getLink('link', array(
  107. 'href' => $mixedProfile['link'],
  108. 'title' => bx_html_attribute(!empty($mixedProfile['title']) ? $mixedProfile['title'] : $mixedProfile['name']),
  109. 'content' => $mixedProfile['name']
  110. ));
  111. }
  112. public function getLink($sTemplate, $aParams)
  113. {
  114. return $this->parseHtmlByName($sTemplate . '.html', array(
  115. 'href' => $aParams['href'],
  116. 'title' => $aParams['title'],
  117. 'content' => $aParams['content']
  118. ));
  119. }
  120. function getContextAddon ($aData, $oProfile)
  121. {
  122. $CNF = &$this->getModule()->_oConfig->CNF;
  123. $sUrl = 'page.php?i=' . $CNF['URI_ENTRIES_BY_CONTEXT'] . '&profile_id=' . $oProfile->id();
  124. $bActAsProfile = BxDolService::call($oProfile->getModule(), 'act_as_profile');
  125. if ($bActAsProfile)
  126. $sUrl = 'page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id=' . $oProfile->id();
  127. $sUrl = BxDolPermalinks::getInstance()->permalink($sUrl);
  128. return _t($CNF['T']['txt_all_entries_in'], $sUrl, $oProfile->getDisplayName(), $this->getModule()->_oDb->getEntriesNumByContext($oProfile->id()));
  129. }
  130. function getContextDesc ($aData)
  131. {
  132. return '';
  133. }
  134. public function getTmplVarsText($aData)
  135. {
  136. $CNF = &$this->getModule()->_oConfig->CNF;
  137. $aVars = $aData;
  138. $aVars['entry_title'] = $this->getTitle($aData);
  139. $aVars['entry_text'] = $this->getText($aData);
  140. $aVars['badges'] = $this->getModule()->serviceGetBadges($aData[$CNF['FIELD_ID']]);
  141. if (!empty($CNF['OBJECT_METATAGS'])) {
  142. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  143. // keywords
  144. if ($oMetatags->keywordsIsEnabled()) {
  145. $aFields = array_merge($oMetatags->metaFields($aData, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_VIEW']), array('entry_title', 'entry_text'));
  146. foreach ($aFields as $sField)
  147. $aVars[$sField] = $oMetatags->keywordsParse($aData[$CNF['FIELD_ID']], $aVars[$sField]);
  148. }
  149. // mentions
  150. if ($oMetatags->mentionsIsEnabled()) {
  151. $aFields = array_merge($oMetatags->metaFields($aData, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_VIEW'], true), array('entry_text'));
  152. foreach ($aFields as $sField)
  153. $aVars[$sField] = $oMetatags->mentionsParse($aData[$CNF['FIELD_ID']], $aVars[$sField]);
  154. }
  155. // location
  156. $aVars['location'] = $oMetatags->locationsIsEnabled() ? $oMetatags->locationsString($aData[$CNF['FIELD_ID']]) : '';
  157. }
  158. unset($aVars['recipients']);
  159. return $aVars;
  160. }
  161. public function entryBreadcrumb($aContentInfo, $aTmplVarsItems = array())
  162. {
  163. $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
  164. return $this->parseHtmlByName('breadcrumb.html', array(
  165. 'url_home' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']),
  166. 'icon_home' => $CNF['ICON'],
  167. 'bx_repeat:items' => $aTmplVarsItems
  168. ));
  169. }
  170. public function entryText ($aData, $sTemplateName = 'entry-text.html')
  171. {
  172. $aVars = $this->getTmplVarsText($aData);
  173. if (empty($aVars['entry_text']))
  174. return false;
  175. return $this->parseHtmlByName($sTemplateName, $aVars);
  176. }
  177. public function entryLocation ($iContentId)
  178. {
  179. $CNF = &$this->getModule()->_oConfig->CNF;
  180. if (empty($CNF['OBJECT_METATAGS']))
  181. return '';
  182. $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
  183. if (!($sLocationString = $oMetatags->locationsString($iContentId)))
  184. return '';
  185. $aVars = array (
  186. 'location' => $sLocationString
  187. );
  188. return $this->parseHtmlByName('entry-location.html', $aVars);
  189. }
  190. public function entryInfo($aData, $aValues = array())
  191. {
  192. $CNF = $this->_oConfig->CNF;
  193. $aValuesDefault = array();
  194. if (isset($aData[$CNF['FIELD_ADDED']]))
  195. $aValuesDefault[] = array(
  196. 'title' => _t('_sys_txt_field_created'),
  197. 'value' => bx_time_js($aData[$CNF['FIELD_ADDED']]),
  198. );
  199. if (isset($aData[$CNF['FIELD_CHANGED']]))
  200. $aValuesDefault[] = array(
  201. 'title' => _t('_sys_txt_field_updated'),
  202. 'value' => bx_time_js($aData[$CNF['FIELD_CHANGED']]),
  203. );
  204. $aValues = array_merge($aValuesDefault, $aValues);
  205. return $this->parseHtmlByName('entry-info.html', array(
  206. 'bx_repeat:info' => $aValues,
  207. ));
  208. }
  209. public function getFavoriteList($oProfile, $iStart, $iPerPage, $aParams)
  210. {
  211. $CNF = $this->_oConfig->CNF;
  212. $bEmptyMessage = false;
  213. if(isset($aParams['empty_message'])) {
  214. $bEmptyMessage = (bool)$aParams['empty_message'];
  215. unset($aParams['empty_message']);
  216. }
  217. $oFavorite = BxDolFavorite::getObjectInstance($CNF['OBJECT_FAVORITES'], 0, true);
  218. $aListsData = $oFavorite->getQueryObject()->getList(array('type' => 'active', 'author_id' => $oProfile->id(), 'need_default' => true, 'start' => $iStart, 'limit' => $iPerPage + 1));
  219. $iNum = count($aListsData);
  220. if ($iNum > $iPerPage)
  221. $aListsData = array_slice($aListsData, 0, $iPerPage);
  222. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_LIST_VIEW']);
  223. $aListsTmpl = array();
  224. foreach($aListsData as $iListId => $sName) {
  225. $aParams['list_id'] = $iListId;
  226. if ($oPrivacy->check($iListId) || $iListId == 0){
  227. $aTmp = $this->getModule()->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage, false);
  228. if ($aTmp && $aTmp['content']){
  229. $aListsTmpl[] = array(
  230. 'title' => $sName,
  231. 'content_url' => $this->getModule()->_getFavoriteListUrl($iListId, $oProfile->id()),
  232. 'content' => $aTmp['content']
  233. );
  234. }
  235. }
  236. else{
  237. $aListsTmpl[] = array(
  238. 'title' => 'private list',
  239. 'content_url' => 'javascript:',
  240. 'content' => ''
  241. );
  242. }
  243. }
  244. $oPaginate = new BxTemplPaginate(array(
  245. 'on_change_page' => "return !loadDynamicBlockAutoPaginate(this, '{start}', '{per_page}', " . bx_js_string(json_encode($aParams)) . ", 'list_start', 'list_per_page');",
  246. 'num' => $iNum,
  247. 'per_page' => $iPerPage,
  248. 'start' => $iStart,
  249. ));
  250. if (count($aListsTmpl) > 0)
  251. return $this->parseHtmlByName('favorite-lists.html', array('bx_repeat:items' => $aListsTmpl)) . $oPaginate->getSimplePaginate() . $oFavorite->getJsScript();
  252. return false;
  253. }
  254. public function getFavoritesListInfo($aList, $oProfile)
  255. {
  256. $CNF = $this->_oConfig->CNF;
  257. $iListId = !empty($aList['id']) ? (int)$aList['id'] : 0;
  258. $oFavorite = BxDolFavorite::getObjectInstance($CNF['OBJECT_FAVORITES'], 0, true);
  259. $aListInfo = $oFavorite->getQueryObject()->getList(array('type' => 'info', 'list_id' => $iListId, 'author_id' => $oProfile->id()));
  260. $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_LIST_VIEW']);
  261. $sTitle = "";
  262. if ($aListInfo['allow_view_favorite_list_to'] < 0){
  263. $oProfileContext = BxDolProfile::getInstance(abs($aListInfo['allow_view_favorite_list_to']));
  264. $sTitle = $oProfileContext->getDisplayName();
  265. }
  266. else{
  267. if (empty($aListInfo['allow_view_favorite_list_to']))
  268. $aListInfo['allow_view_favorite_list_to'] = 3;
  269. $aPrivaciInfo = $oPrivacy->getGroupsBy(array('type'=>'id' , 'id'=> $aListInfo['allow_view_favorite_list_to']));
  270. $sTitle = _t($aPrivaciInfo['title']);
  271. }
  272. $aListsTmpl = array();
  273. if (!empty($aListInfo['created'])){
  274. $aListsTmpl[] = array('title' => _t('_sys_form_favorite_list_title_created'), 'value' => bx_time_js($aListInfo['created']));
  275. }
  276. $aListsTmpl = array_merge($aListsTmpl,
  277. array(
  278. array('title' => _t('_sys_form_favorite_list_title_updated'), 'value' => bx_time_js($aListInfo['updated'])),
  279. array('title' => _t('_sys_form_favorite_list_title_count'), 'value' => $aListInfo['count']),
  280. array('title' => _t('_sys_form_favorite_list_title_visibility'), 'value' => $sTitle)
  281. )
  282. );
  283. return $this->parseHtmlByName('favorite-list-info.html', array('bx_repeat:items' => $aListsTmpl, 'author' => $oProfile->getUnit()));
  284. }
  285. function entryAllActions($sActions)
  286. {
  287. if(empty($sActions))
  288. return '';
  289. return $this->parseHtmlByName('entry-all-actions.html', array (
  290. 'actions' => $sActions
  291. ));
  292. }
  293. function entryAttachments ($aData, $aParams = array())
  294. {
  295. return $this->entryAttachmentsByStorage($this->getModule()->_oConfig->CNF['OBJECT_STORAGE'], $aData, $aParams);
  296. }
  297. function entryAttachmentsByStorage ($mixedStorage, $aData, $aParams = array())
  298. {
  299. if(!is_array($mixedStorage))
  300. $mixedStorage = array($mixedStorage);
  301. $aResult = array();
  302. foreach($mixedStorage as $sStorage) {
  303. $aAttachments = $this->getAttachments($sStorage, $aData, $aParams);
  304. if(empty($aAttachments) || !is_array($aAttachments))
  305. continue;
  306. $aResult = array_merge($aResult, $aAttachments);
  307. }
  308. if(empty($aResult) || !is_array($aResult))
  309. return '';
  310. $this->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flickity/|flickity.css');
  311. $this->addJs(array(
  312. 'flickity/flickity.pkgd.min.js',
  313. 'pdfjs/build/pdf.min.js',
  314. ));
  315. return $this->parseHtmlByName('attachments.html', array(
  316. 'bx_repeat:attachments' => $aResult,
  317. 'pdfjs_worker_url' => $this->getJsUrl('pdfjs/build/pdf.worker.min.js'),
  318. ));
  319. }
  320. function entryContext ($aData, $iProfileId = false, $sFuncContextDesc = 'getContextDesc', $sTemplateName = 'context.html', $sFuncContextAddon = 'getContextAddon')
  321. {
  322. $CNF = &$this->getModule()->_oConfig->CNF;
  323. $iContextId = $aData[$CNF['FIELD_ALLOW_VIEW_TO']];
  324. if ($iContextId >= 0)
  325. return '';
  326. $iProfileId = - $iContextId;
  327. $oProfile = BxDolProfile::getInstance($iProfileId);
  328. if (!$oProfile)
  329. $oProfile = BxDolProfileUndefined::getInstance();
  330. if (!$oProfile)
  331. return '';
  332. $sName = $oProfile->getDisplayName();
  333. $sAddon = $sFuncContextAddon ? $this->$sFuncContextAddon($aData, $oProfile) : '';
  334. $aVars = array (
  335. 'author_url' => $oProfile->getUrl(),
  336. 'author_thumb_url' => $oProfile->getThumb(),
  337. 'author_unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
  338. 'author_title' => $sName,
  339. 'author_title_attr' => bx_html_attribute($sName),
  340. 'author_desc' => $sFuncContextDesc ? $this->$sFuncContextDesc($aData) : '',
  341. 'bx_if:addon' => array (
  342. 'condition' => (bool)$sAddon,
  343. 'content' => array (
  344. 'content' => $sAddon,
  345. ),
  346. ),
  347. );
  348. return $this->parseHtmlByName($sTemplateName, $aVars);
  349. }
  350. protected function getAttachmentsImagesTranscoders ($sStorage = '')
  351. {
  352. $CNF = &$this->getModule()->_oConfig->CNF;
  353. $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
  354. $oTranscoderView = !empty($CNF['OBJECT_IMAGES_TRANSCODER_PICTURE']) ? BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PICTURE']) : null;
  355. return array($oTranscoder, $oTranscoderView);
  356. }
  357. protected function getAttachmentsVideoTranscoders ($sStorage = '')
  358. {
  359. $CNF = &$this->getModule()->_oConfig->CNF;
  360. if (isset($CNF['OBJECT_VIDEOS_TRANSCODERS']) && $CNF['OBJECT_VIDEOS_TRANSCODERS'])
  361. return array (
  362. 'poster' => BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']),
  363. 'mp4' => BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']),
  364. 'mp4_hd' => BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4_hd']),
  365. );
  366. return false;
  367. }
  368. protected function getAttachments ($sStorage, $aData, $aParams = array())
  369. {
  370. $CNF = &$this->getModule()->_oConfig->CNF;
  371. $oStorage = BxDolStorage::getObjectInstance($sStorage);
  372. list($oTranscoder, $oTranscoderPreview) = $this->getAttachmentsImagesTranscoders($sStorage);
  373. $oTranscoderSound = isset($CNF['OBJECT_SOUNDS_TRANSCODER']) && $CNF['OBJECT_SOUNDS_TRANSCODER'] ? BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_SOUNDS_TRANSCODER']) : null;
  374. $aTranscodersVideo = $this->getAttachmentsVideoTranscoders($sStorage);
  375. $aGhostFiles = $oStorage->getGhosts ($this->getModule()->serviceGetContentOwnerProfileId($aData[$CNF['FIELD_ID']]), $aData[$CNF['FIELD_ID']]);
  376. if (!$aGhostFiles)
  377. return false;
  378. $sFilterField = isset($aParams['filter_field']) ? $aParams['filter_field'] : $CNF['FIELD_THUMB'];
  379. if(!empty($sFilterField) && isset($aData[$sFilterField]))
  380. foreach ($aGhostFiles as $k => $a) {
  381. // don't show thumbnail in attachments
  382. if ($a['id'] == $aData[$sFilterField])
  383. unset($aGhostFiles[$k]);
  384. }
  385. if(!$aGhostFiles)
  386. return false;
  387. $aAttachmnts = array();
  388. foreach ($aGhostFiles as $k => $a) {
  389. $isImage = !empty($CNF['OBJECT_STORAGE_PHOTOS']) && $sStorage == $CNF['OBJECT_STORAGE_PHOTOS'] && $oTranscoder && (0 === strncmp('image/', $a['mime_type'], 6)) && $oTranscoder->isMimeTypeSupported($a['mime_type']); // preview for images, transcoder object for preview must be defined
  390. $isVideo = !empty($CNF['OBJECT_STORAGE_VIDEOS']) && $sStorage == $CNF['OBJECT_STORAGE_VIDEOS'] && $aTranscodersVideo && (0 === strncmp('video/', $a['mime_type'], 6)) && $aTranscodersVideo['poster']->isMimeTypeSupported($a['mime_type']); // preview for videos, transcoder object for video must be defined
  391. $isSound = !empty($CNF['OBJECT_STORAGE_SOUNDS']) && $sStorage == $CNF['OBJECT_STORAGE_SOUNDS'] && $oTranscoderSound && (0 === strncmp('audio/', $a['mime_type'], 6)) && $oTranscoderSound->isMimeTypeSupported($a['mime_type']); // preview for sounds, transcoder object for sounds must be defined
  392. $sUrlOriginal = $oStorage->getFileUrlById($a['id']);
  393. $sImgPopupId = 'bx-messages-atachment-popup-' . $a['id'];
  394. // images are displayed with preview and popup upon clicking
  395. $a['bx_if:image'] = array (
  396. 'condition' => $isImage,
  397. 'content' => array (
  398. 'url_original' => $isImage && $oTranscoderPreview ? $oTranscoderPreview->getFileUrl($a['id']) : $sUrlOriginal,
  399. 'attr_file_name' => bx_html_attribute($a['file_name']),
  400. 'popup_id' => $sImgPopupId,
  401. 'url_preview' => $isImage ? $oTranscoder->getFileUrl($a['id']) : '',
  402. 'popup' => BxTemplFunctions::getInstance()->transBox($sImgPopupId, '<img src="' . $sUrlOriginal . '" />', true, true),
  403. ),
  404. );
  405. $sVideoUrlHd = '';
  406. if($isVideo) {
  407. $sVideoUrl = $oStorage->getFileUrlById($a['id']);
  408. $aVideoFile = $oStorage->getFile($a['id']);
  409. if (!empty($aVideoFile['dimensions']) && $aTranscodersVideo['mp4_hd']->isProcessHD($aVideoFile['dimensions']))
  410. $sVideoUrlHd = $aTranscodersVideo['mp4_hd']->getFileUrl($a['id']);
  411. }
  412. // videos are displayed inline
  413. $a['bx_if:video'] = array (
  414. 'condition' => $isVideo,
  415. 'content' => array (
  416. 'video' => $isVideo && $aTranscodersVideo ? BxTemplFunctions::getInstance()->videoPlayer(
  417. $aTranscodersVideo['poster']->getFileUrl($a['id']),
  418. $aTranscodersVideo['mp4']->getFileUrl($a['id']),
  419. $sVideoUrlHd,
  420. false, ''
  421. ) : '',
  422. ),
  423. );
  424. // sounds are displayed inline
  425. $a['bx_if:sound'] = array (
  426. 'condition' => $isSound,
  427. 'content' => array (
  428. 'sound' => $isSound && $oTranscoderSound && ($oPlayer = BxDolPlayer::getObjectInstance()) ? $this->parseHtmlByName('attachment_sound.html', array(
  429. 'file_name' => $a['file_name'],
  430. 'file_url' => $oTranscoderSound ? $oTranscoderSound->getFileUrl($a['id']) : '',
  431. 'player' => $oTranscoderSound && $oTranscoderSound->isFileReady($a['id']) ?
  432. $oPlayer->getCodeAudio (BX_PLAYER_STANDARD, array(
  433. 'mp3' => $oTranscoderSound->getFileUrl($a['id']),
  434. )) : _t('_sys_txt_err_sound_not_transcoded_yet'),
  435. )) : '',
  436. ),
  437. );
  438. // non-images are displayed as text links to original file
  439. $a['bx_if:not_image'] = array (
  440. 'condition' => !$isImage && !$isVideo && !$isSound,
  441. 'content' => array (
  442. 'url_original' => $sUrlOriginal,
  443. 'attr_file_name' => bx_html_attribute($a['file_name']),
  444. 'file_name' => bx_process_output($a['file_name']),
  445. ),
  446. );
  447. $aAttachmnts[] = $a;
  448. }
  449. return $aAttachmnts;
  450. }
  451. public function embedVideo($iFileId)
  452. {
  453. $CNF = $this->getModule()->_oConfig->CNF;
  454. list($oPlayer, $oStorage, $aContentInfo, $a) = $this->_embedChecks('OBJECT_STORAGE_VIDEOS', $iFileId);
  455. // check if file is really video
  456. $aTranscodersVideo = $this->getAttachmentsVideoTranscoders();
  457. if (!$aTranscodersVideo || (0 !== strncmp('video/', $a['mime_type'], 6)) || !$aTranscodersVideo['poster']->isMimeTypeSupported($a['mime_type'])) {
  458. $this->displayErrorOccured('', BX_PAGE_EMBED);
  459. exit;
  460. }
  461. // check HD video version
  462. $sVideoUrlHd = '';
  463. $sVideoUrl = $oStorage->getFileUrlById($a['id']);
  464. $aVideoFile = $oStorage->getFile($a['id']);
  465. if (!empty($aVideoFile['dimensions']) && $aTranscodersVideo['mp4_hd']->isProcessHD($aVideoFile['dimensions']))
  466. $sVideoUrlHd = $aTranscodersVideo['mp4_hd']->getFileUrl($a['id']);
  467. // generate player code
  468. $sCode = $oPlayer->getCodeVideo (BX_PLAYER_EMBED, array(
  469. 'poster' => $aTranscodersVideo['poster']->getFileUrl($a['id']),
  470. 'mp4' => array(
  471. 'sd' => $aTranscodersVideo['mp4']->getFileUrl($a['id']),
  472. 'hd' => $sVideoUrlHd
  473. ),
  474. ));
  475. // display page
  476. $oTemplate = BxDolTemplate::getInstance();
  477. $oTemplate->setPageNameIndex (BX_PAGE_EMBED);
  478. $oTemplate->setPageHeader ($a['file_name']);
  479. $oTemplate->setPageContent ('page_main_code', $sCode);
  480. $oTemplate->getPageCode();
  481. exit;
  482. }
  483. public function embedSound($iFileId)
  484. {
  485. $CNF = $this->getModule()->_oConfig->CNF;
  486. list($oPlayer, $oStorage, $aContentInfo, $a) = $this->_embedChecks('OBJECT_STORAGE_SOUNDS', $iFileId);
  487. // check if file is really audio
  488. $oTranscoderSound = isset($CNF['OBJECT_SOUNDS_TRANSCODER']) ? BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_SOUNDS_TRANSCODER']) : null;
  489. if (!$oTranscoderSound || (0 !== strncmp('audio/', $a['mime_type'], 6)) || !$oTranscoderSound->isMimeTypeSupported($a['mime_type'])) {
  490. $this->displayErrorOccured('', BX_PAGE_EMBED);
  491. exit;
  492. }
  493. if (!$oTranscoderSound->isFileReady($a['id'])) {
  494. $oTranscoderSound->getFileUrl($a['id']); // queue for encoding
  495. $this->displayMsg('_sys_txt_err_sound_not_transcoded_yet', true, BX_PAGE_EMBED);
  496. exit;
  497. }
  498. // generate player code
  499. $sCode = $oPlayer->getCodeAudio (BX_PLAYER_EMBED, array(
  500. 'mp3' => $oTranscoderSound->getFileUrl($a['id']),
  501. ));
  502. // display page
  503. $oTemplate = BxDolTemplate::getInstance();
  504. $oTemplate->setPageNameIndex (BX_PAGE_EMBED);
  505. $oTemplate->setPageHeader ($a['file_name']);
  506. $oTemplate->setPageContent ('page_main_code', $sCode);
  507. $oTemplate->getPageCode();
  508. exit;
  509. }
  510. protected function _embedChecks($sStorageKey, $iFileId)
  511. {
  512. // general checks
  513. $oPlayer = BxDolPlayer::getObjectInstance();
  514. $CNF = $this->getModule()->_oConfig->CNF;
  515. $sStorage = isset($CNF[$sStorageKey]) ? $CNF[$sStorageKey] : false;
  516. if (!$oPlayer || !$sStorage || !($oStorage = BxDolStorage::getObjectInstance($sStorage))) {
  517. $this->displayErrorOccured('', BX_PAGE_EMBED);
  518. exit;
  519. }
  520. // privacy check
  521. $aGhost = $oStorage->getGhost($iFileId);
  522. $aContentInfo = $aGhost && $aGhost['content_id'] ? $this->getModule()->_oDb->getContentInfoById($aGhost['content_id']) : false;
  523. if (!$aGhost || ($aGhost['content_id'] && !$aContentInfo)) {
  524. $this->displayPageNotFound('', BX_PAGE_EMBED);
  525. exit;
  526. }
  527. if (!$aGhost['content_id']) {
  528. // if file is not associated with content yet, then only admin and owner can view it
  529. if (!isAdmin() && CHECK_ACTION_RESULT_ALLOWED !== $this->getModule()->checkAllowedEditAnyEntry() && $aGhost['profile_id'] != bx_get_logged_profile_id()) {
  530. $this->displayAccessDenied('', BX_PAGE_EMBED);
  531. exit;
  532. }
  533. }
  534. else {
  535. // if file is associated with content, then check entry privacy
  536. if (CHECK_ACTION_RESULT_ALLOWED !== $this->getModule()->checkAllowedView($aContentInfo)) {
  537. $this->displayAccessDenied('', BX_PAGE_EMBED);
  538. exit;
  539. }
  540. }
  541. // get file info
  542. if (!($a = $oStorage->getFile($iFileId))) {
  543. $this->displayPageNotFound('', BX_PAGE_EMBED);
  544. exit;
  545. }
  546. return array($oPlayer, $oStorage, $aContentInfo, $a);
  547. }
  548. public function addCssJs()
  549. {
  550. $this->addCss('main.css');
  551. }
  552. }
  553. /** @} */