| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup BaseGeneral Base classes for modules
- * @ingroup UnaModules
- *
- * @{
- */
- /**
- * Module representation.
- */
- class BxBaseModGeneralTemplate extends BxDolModuleTemplate
- {
- protected $MODULE;
-
- public $aMethodsToCallAddJsCss = array('entry', 'unit');
- function __construct(&$oConfig, &$oDb)
- {
- parent::__construct($oConfig, $oDb);
- }
- public function getJsCode($sType, $aParams = array(), $mixedWrap = true)
- {
- $sMask = "{var} {object} = new {class}({params});";
- $aMaskMarkers = array();
- if(is_array($mixedWrap)) {
- if(!empty($mixedWrap['mask']))
- $sMask = $mixedWrap['mask'];
- if(!empty($mixedWrap['mask_markers']) && is_array($mixedWrap['mask_markers']))
- $aMaskMarkers = $mixedWrap['mask_markers'];
- }
- $sJsClass = $this->_oConfig->getJsClass($sType);
- if(!empty($aParams['js_class'])) {
- $sJsClass = $aParams['js_class'];
- unset($aParams['js_class']);
- }
- $sJsObject = $this->_oConfig->getJsObject($sType);
- if(!empty($aParams['js_object'])) {
- $sJsObject = $aParams['js_object'];
- unset($aParams['js_object']);
- }
- $sBaseUri = $this->_oConfig->getBaseUri();
- $aParams = array_merge(array(
- 'sActionUri' => $sBaseUri,
- 'sActionUrl' => BX_DOL_URL_ROOT . $sBaseUri,
- 'sObjName' => $sJsObject,
- 'aHtmlIds' => array(),
- 'oRequestParams' => array()
- ), $aParams);
- $sContent = bx_replace_markers($sMask, array_merge(array(
- 'var' => 'var',
- 'object' => $sJsObject,
- 'class' => $sJsClass,
- 'params' => json_encode($aParams)
- ), $aMaskMarkers));
- return ($mixedWrap === true || (is_array($mixedWrap) && isset($mixedWrap['wrap']) && $mixedWrap['wrap'] === true)) ? $this->_wrapInTagJsCode($sContent) : $sContent;
- }
- public function getTitleAuto($aData, $iMaxLen = 20, $sEllipsisSign = '...')
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
- if(isset($aData[$CNF['FIELD_TITLE']]))
- return $this->getTitle($aData);
- $sResult = $this->getText($aData);
- if(strlen($sResult) > 0 && $iMaxLen > 0)
- $sResult = strmaxtextlen($sResult, $iMaxLen, $sEllipsisSign);
- return $sResult;
- }
- public function getTitle($aData, $mixedProcessOutput = BX_DATA_TEXT)
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
-
- if(!isset($aData[$CNF['FIELD_TITLE']]))
- return '';
- $sResult = $aData[$CNF['FIELD_TITLE']];
- if($mixedProcessOutput !== false && !empty($sResult))
- $sResult = bx_process_output($sResult, (int)$mixedProcessOutput);
- return $sResult;
- }
- public function getText($aData, $mixedProcessOutput = BX_DATA_HTML)
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
-
- if(!isset($aData[$CNF['FIELD_TEXT']]))
- return '';
- $sResult = $aData[$CNF['FIELD_TEXT']];
- if($mixedProcessOutput !== false && !empty($sResult))
- $sResult = bx_process_output($sResult, (int)$mixedProcessOutput);
- return $sResult;
- }
- protected function getSummary($aData, $sTitle = '', $sText = '', $sUrl = '')
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
- if(empty($CNF['PARAM_CHARS_SUMMARY']))
- return '';
- // get summary
- $sLinkMore = ' <a title="' . bx_html_attribute(_t('_sys_read_more', $sTitle)) . '" href="' . $sUrl . '"><i class="sys-icon ellipsis-h"></i></a>';
- return strmaxtextlen($sText, (int)getParam($CNF['PARAM_CHARS_SUMMARY']), $sLinkMore);
- }
- public function getProfileLink($mixedProfile)
- {
- if(!is_array($mixedProfile))
- $mixedProfile = $this->getModule()->getProfileInfo((int)$mixedProfile);
- return $this->getLink('link', array(
- 'href' => $mixedProfile['link'],
- 'title' => bx_html_attribute(!empty($mixedProfile['title']) ? $mixedProfile['title'] : $mixedProfile['name']),
- 'content' => $mixedProfile['name']
- ));
- }
- public function getLink($sTemplate, $aParams)
- {
- return $this->parseHtmlByName($sTemplate . '.html', array(
- 'href' => $aParams['href'],
- 'title' => $aParams['title'],
- 'content' => $aParams['content']
- ));
- }
-
- function getContextAddon ($aData, $oProfile)
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
- $sUrl = 'page.php?i=' . $CNF['URI_ENTRIES_BY_CONTEXT'] . '&profile_id=' . $oProfile->id();
- $bActAsProfile = BxDolService::call($oProfile->getModule(), 'act_as_profile');
- if ($bActAsProfile)
- $sUrl = 'page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id=' . $oProfile->id();
- $sUrl = BxDolPermalinks::getInstance()->permalink($sUrl);
- return _t($CNF['T']['txt_all_entries_in'], $sUrl, $oProfile->getDisplayName(), $this->getModule()->_oDb->getEntriesNumByContext($oProfile->id()));
- }
-
- function getContextDesc ($aData)
- {
- return '';
- }
- public function getTmplVarsText($aData)
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
- $aVars = $aData;
- $aVars['entry_title'] = $this->getTitle($aData);
- $aVars['entry_text'] = $this->getText($aData);
- $aVars['badges'] = $this->getModule()->serviceGetBadges($aData[$CNF['FIELD_ID']]);
- if (!empty($CNF['OBJECT_METATAGS'])) {
- $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
- // keywords
- if ($oMetatags->keywordsIsEnabled()) {
- $aFields = array_merge($oMetatags->metaFields($aData, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_VIEW']), array('entry_title', 'entry_text'));
- foreach ($aFields as $sField)
- $aVars[$sField] = $oMetatags->keywordsParse($aData[$CNF['FIELD_ID']], $aVars[$sField]);
- }
- // mentions
- if ($oMetatags->mentionsIsEnabled()) {
- $aFields = array_merge($oMetatags->metaFields($aData, $CNF, $CNF['OBJECT_FORM_ENTRY_DISPLAY_VIEW'], true), array('entry_text'));
- foreach ($aFields as $sField)
- $aVars[$sField] = $oMetatags->mentionsParse($aData[$CNF['FIELD_ID']], $aVars[$sField]);
- }
-
- // location
- $aVars['location'] = $oMetatags->locationsIsEnabled() ? $oMetatags->locationsString($aData[$CNF['FIELD_ID']]) : '';
- }
- unset($aVars['recipients']);
- return $aVars;
- }
- public function entryBreadcrumb($aContentInfo, $aTmplVarsItems = array())
- {
- $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
- return $this->parseHtmlByName('breadcrumb.html', array(
- 'url_home' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME']),
- 'icon_home' => $CNF['ICON'],
- 'bx_repeat:items' => $aTmplVarsItems
- ));
- }
- public function entryText ($aData, $sTemplateName = 'entry-text.html')
- {
- $aVars = $this->getTmplVarsText($aData);
- if (empty($aVars['entry_text']))
- return false;
-
- return $this->parseHtmlByName($sTemplateName, $aVars);
- }
- public function entryLocation ($iContentId)
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
- if (empty($CNF['OBJECT_METATAGS']))
- return '';
- $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
- if (!($sLocationString = $oMetatags->locationsString($iContentId)))
- return '';
- $aVars = array (
- 'location' => $sLocationString
- );
- return $this->parseHtmlByName('entry-location.html', $aVars);
- }
- public function entryInfo($aData, $aValues = array())
- {
- $CNF = $this->_oConfig->CNF;
- $aValuesDefault = array();
- if (isset($aData[$CNF['FIELD_ADDED']]))
- $aValuesDefault[] = array(
- 'title' => _t('_sys_txt_field_created'),
- 'value' => bx_time_js($aData[$CNF['FIELD_ADDED']]),
- );
- if (isset($aData[$CNF['FIELD_CHANGED']]))
- $aValuesDefault[] = array(
- 'title' => _t('_sys_txt_field_updated'),
- 'value' => bx_time_js($aData[$CNF['FIELD_CHANGED']]),
- );
- $aValues = array_merge($aValuesDefault, $aValues);
- return $this->parseHtmlByName('entry-info.html', array(
- 'bx_repeat:info' => $aValues,
- ));
- }
-
- public function getFavoriteList($oProfile, $iStart, $iPerPage, $aParams)
- {
- $CNF = $this->_oConfig->CNF;
-
- $bEmptyMessage = false;
- if(isset($aParams['empty_message'])) {
- $bEmptyMessage = (bool)$aParams['empty_message'];
- unset($aParams['empty_message']);
- }
-
- $oFavorite = BxDolFavorite::getObjectInstance($CNF['OBJECT_FAVORITES'], 0, true);
- $aListsData = $oFavorite->getQueryObject()->getList(array('type' => 'active', 'author_id' => $oProfile->id(), 'need_default' => true, 'start' => $iStart, 'limit' => $iPerPage + 1));
- $iNum = count($aListsData);
- if ($iNum > $iPerPage)
- $aListsData = array_slice($aListsData, 0, $iPerPage);
-
- $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_LIST_VIEW']);
- $aListsTmpl = array();
- foreach($aListsData as $iListId => $sName) {
- $aParams['list_id'] = $iListId;
- if ($oPrivacy->check($iListId) || $iListId == 0){
- $aTmp = $this->getModule()->_serviceBrowse ('favorite', array_merge(array('user' => $oProfile->id()), $aParams), BX_DB_PADDING_DEF, $bEmptyMessage, false);
- if ($aTmp && $aTmp['content']){
- $aListsTmpl[] = array(
- 'title' => $sName,
- 'content_url' => $this->getModule()->_getFavoriteListUrl($iListId, $oProfile->id()),
- 'content' => $aTmp['content']
- );
- }
- }
- else{
- $aListsTmpl[] = array(
- 'title' => 'private list',
- 'content_url' => 'javascript:',
- 'content' => ''
- );
- }
- }
-
- $oPaginate = new BxTemplPaginate(array(
- 'on_change_page' => "return !loadDynamicBlockAutoPaginate(this, '{start}', '{per_page}', " . bx_js_string(json_encode($aParams)) . ", 'list_start', 'list_per_page');",
- 'num' => $iNum,
- 'per_page' => $iPerPage,
- 'start' => $iStart,
- ));
- if (count($aListsTmpl) > 0)
- return $this->parseHtmlByName('favorite-lists.html', array('bx_repeat:items' => $aListsTmpl)) . $oPaginate->getSimplePaginate() . $oFavorite->getJsScript();
-
- return false;
- }
-
- public function getFavoritesListInfo($aList, $oProfile)
- {
- $CNF = $this->_oConfig->CNF;
-
- $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_LIST_VIEW']);
- $sTitle = "";
- if ($aList['allow_view_favorite_list_to'] < 0){
- $oProfileContext = BxDolProfile::getInstance(abs($aList['allow_view_favorite_list_to']));
- $sTitle = $oProfileContext->getDisplayName();
- }
- else{
- if (empty($aList['allow_view_favorite_list_to']))
- $aList['allow_view_favorite_list_to'] = 3;
- $aPrivaciInfo = $oPrivacy->getGroupsBy(array('type'=>'id' , 'id'=> $aList['allow_view_favorite_list_to']));
- $sTitle = _t($aPrivaciInfo['title']);
- }
-
- $aListsTmpl = array();
-
- if (!empty($aList['created'])){
- $aListsTmpl[] = array('title' => _t('_sys_form_favorite_list_title_created'), 'value' => bx_time_js($aList['created']));
- }
-
- $aListsTmpl = array_merge($aListsTmpl,
- array(
- array('title' => _t('_sys_form_favorite_list_title_updated'), 'value' => bx_time_js($aList['updated'])),
- array('title' => _t('_sys_form_favorite_list_title_count'), 'value' => $aList['count']),
- array('title' => _t('_sys_form_favorite_list_title_visibility'), 'value' => $sTitle)
- )
- );
-
- return $this->parseHtmlByName('favorite-list-info.html', array('bx_repeat:items' => $aListsTmpl, 'author' => $oProfile->getUnit()));
- }
-
- function entryAllActions($sActions)
- {
- if(empty($sActions))
- return '';
- return $this->parseHtmlByName('entry-all-actions.html', array (
- 'actions' => $sActions
- ));
- }
- function entryAttachments ($aData, $aParams = array())
- {
- return $this->entryAttachmentsByStorage($this->getModule()->_oConfig->CNF['OBJECT_STORAGE'], $aData, $aParams);
- }
- function entryAttachmentsByStorage ($mixedStorage, $aData, $aParams = array())
- {
- if(!is_array($mixedStorage))
- $mixedStorage = array($mixedStorage);
- $aResult = array();
- foreach($mixedStorage as $sStorage) {
- $aAttachments = $this->getAttachments($sStorage, $aData, $aParams);
- if(empty($aAttachments) || !is_array($aAttachments))
- continue;
- $aResult = array_merge($aResult, $aAttachments);
- }
- if(empty($aResult) || !is_array($aResult))
- return '';
- $this->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flickity/|flickity.css');
- $this->addJs(array(
- 'flickity/flickity.pkgd.min.js',
- 'pdfjs/build/pdf.min.js',
- ));
- return $this->parseHtmlByName('attachments.html', array(
- 'bx_repeat:attachments' => $aResult,
- 'pdfjs_worker_url' => $this->getJsUrl('pdfjs/build/pdf.worker.min.js'),
- ));
- }
-
- function entryContext ($aData, $iProfileId = false, $sFuncContextDesc = 'getContextDesc', $sTemplateName = 'context.html', $sFuncContextAddon = 'getContextAddon')
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
- $iContextId = $aData[$CNF['FIELD_ALLOW_VIEW_TO']];
- if ($iContextId >= 0)
- return '';
-
- $iProfileId = - $iContextId;
- $oProfile = BxDolProfile::getInstance($iProfileId);
- if (!$oProfile)
- $oProfile = BxDolProfileUndefined::getInstance();
- if (!$oProfile)
- return '';
- $sName = $oProfile->getDisplayName();
- $sAddon = $sFuncContextAddon ? $this->$sFuncContextAddon($aData, $oProfile) : '';
- $aVars = array (
- 'author_url' => $oProfile->getUrl(),
- 'author_thumb_url' => $oProfile->getThumb(),
- 'author_unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_info')),
- 'author_title' => $sName,
- 'author_title_attr' => bx_html_attribute($sName),
- 'author_desc' => $sFuncContextDesc ? $this->$sFuncContextDesc($aData) : '',
- 'bx_if:addon' => array (
- 'condition' => (bool)$sAddon,
- 'content' => array (
- 'content' => $sAddon,
- ),
- ),
- );
- return $this->parseHtmlByName($sTemplateName, $aVars);
- }
- protected function getAttachmentsImagesTranscoders ($sStorage = '')
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
- $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
- $oTranscoderPreview = isset($CNF['OBJECT_IMAGES_TRANSCODER_PICTURE']) && $CNF['OBJECT_IMAGES_TRANSCODER_PICTURE'] ? BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PICTURE']) : null;
- return array($oTranscoder, $oTranscoderPreview);
- }
- protected function getAttachmentsVideoTranscoders ($sStorage = '')
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
- if (isset($CNF['OBJECT_VIDEOS_TRANSCODERS']) && $CNF['OBJECT_VIDEOS_TRANSCODERS'])
- return array (
- 'poster' => BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']),
- 'mp4' => BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']),
- 'mp4_hd' => BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4_hd']),
- );
- return false;
- }
-
- protected function getAttachments ($sStorage, $aData, $aParams = array())
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
- $oStorage = BxDolStorage::getObjectInstance($sStorage);
- list($oTranscoder, $oTranscoderPreview) = $this->getAttachmentsImagesTranscoders($sStorage);
- $oTranscoderSound = isset($CNF['OBJECT_SOUNDS_TRANSCODER']) && $CNF['OBJECT_SOUNDS_TRANSCODER'] ? BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_SOUNDS_TRANSCODER']) : null;
- $aTranscodersVideo = $this->getAttachmentsVideoTranscoders($sStorage);
- $aGhostFiles = $oStorage->getGhosts ($this->getModule()->serviceGetContentOwnerProfileId($aData[$CNF['FIELD_ID']]), $aData[$CNF['FIELD_ID']]);
- if (!$aGhostFiles)
- return false;
- $sFilterField = isset($aParams['filter_field']) ? $aParams['filter_field'] : $CNF['FIELD_THUMB'];
- if(!empty($sFilterField) && isset($aData[$sFilterField]))
- foreach ($aGhostFiles as $k => $a) {
- // don't show thumbnail in attachments
- if ($a['id'] == $aData[$sFilterField])
- unset($aGhostFiles[$k]);
- }
- if(!$aGhostFiles)
- return false;
- $aAttachmnts = array();
- foreach ($aGhostFiles as $k => $a) {
- $isImage = $oTranscoder && (0 === strncmp('image/', $a['mime_type'], 6)) && $oTranscoder->isMimeTypeSupported($a['mime_type']); // preview for images, transcoder object for preview must be defined
- $isVideo = $aTranscodersVideo && (0 === strncmp('video/', $a['mime_type'], 6)) && $aTranscodersVideo['poster']->isMimeTypeSupported($a['mime_type']); // preview for videos, transcoder object for video must be defined
- $isSound = $oTranscoderSound && (0 === strncmp('audio/', $a['mime_type'], 6)) && $oTranscoderSound->isMimeTypeSupported($a['mime_type']); // preview for sounds, transcoder object for sounds must be defined
- $sUrlOriginal = $oStorage->getFileUrlById($a['id']);
- $sImgPopupId = 'bx-messages-atachment-popup-' . $a['id'];
- // images are displayed with preview and popup upon clicking
- $a['bx_if:image'] = array (
- 'condition' => $isImage,
- 'content' => array (
- 'url_original' => $isImage && $oTranscoderPreview ? $oTranscoderPreview->getFileUrl($a['id']) : $sUrlOriginal,
- 'attr_file_name' => bx_html_attribute($a['file_name']),
- 'popup_id' => $sImgPopupId,
- 'url_preview' => $isImage ? $oTranscoder->getFileUrl($a['id']) : '',
- 'popup' => BxTemplFunctions::getInstance()->transBox($sImgPopupId, '<img src="' . $sUrlOriginal . '" />', true, true),
- ),
- );
- $sVideoUrlHd = '';
- if($isVideo) {
- $sVideoUrl = $oStorage->getFileUrlById($a['id']);
- $aVideoSize = $aTranscodersVideo['mp4_hd']->getVideoSize($sVideoUrl);
- if(!empty($aVideoSize) && is_array($aVideoSize) && (int)$aVideoSize['h'] >= 720)
- $sVideoUrlHd = $aTranscodersVideo['mp4_hd']->getFileUrl($a['id']);
- }
- // videos are displayed inline
- $a['bx_if:video'] = array (
- 'condition' => $isVideo,
- 'content' => array (
- 'video' => $isVideo && $aTranscodersVideo ? BxTemplFunctions::getInstance()->videoPlayer(
- $aTranscodersVideo['poster']->getFileUrl($a['id']),
- $aTranscodersVideo['mp4']->getFileUrl($a['id']),
- $sVideoUrlHd,
- false, ''
- ) : '',
- ),
- );
- // sounds are displayed inline
- $a['bx_if:sound'] = array (
- 'condition' => $isSound,
- 'content' => array (
- 'sound' => $isSound && $oTranscoderSound && ($oPlayer = BxDolPlayer::getObjectInstance()) ? $this->parseHtmlByName('attachment_sound.html', array(
- 'file_name' => $a['file_name'],
- 'file_url' => $oTranscoderSound ? $oTranscoderSound->getFileUrl($a['id']) : '',
- 'player' => $oTranscoderSound && $oTranscoderSound->isFileReady($a['id']) ?
- $oPlayer->getCodeAudio (BX_PLAYER_STANDARD, array(
- 'mp3' => $oTranscoderSound->getFileUrl($a['id']),
- )) : _t('_sys_txt_err_sound_not_transcoded_yet'),
- )) : '',
- ),
- );
- // non-images are displayed as text links to original file
- $a['bx_if:not_image'] = array (
- 'condition' => !$isImage && !$isVideo && !$isSound,
- 'content' => array (
- 'url_original' => $sUrlOriginal,
- 'attr_file_name' => bx_html_attribute($a['file_name']),
- 'file_name' => bx_process_output($a['file_name']),
- ),
- );
- $aAttachmnts[] = $a;
- }
- return $aAttachmnts;
- }
- public function embedVideo($iFileId)
- {
- $CNF = $this->getModule()->_oConfig->CNF;
- list($oPlayer, $oStorage, $aContentInfo, $a) = $this->_embedChecks('OBJECT_STORAGE_VIDEOS', $iFileId);
- // check if file is really video
- $aTranscodersVideo = $this->getAttachmentsVideoTranscoders();
- if (!$aTranscodersVideo || (0 !== strncmp('video/', $a['mime_type'], 6)) || !$aTranscodersVideo['poster']->isMimeTypeSupported($a['mime_type'])) {
- $this->displayErrorOccured('', BX_PAGE_EMBED);
- exit;
- }
- // check HD video version
- $sVideoUrlHd = '';
- $sVideoUrl = $oStorage->getFileUrlById($a['id']);
- $aVideoSize = $aTranscodersVideo['mp4_hd']->getVideoSize($sVideoUrl);
- if (!empty($aVideoSize) && is_array($aVideoSize) && (int)$aVideoSize['h'] >= 720)
- $sVideoUrlHd = $aTranscodersVideo['mp4_hd']->getFileUrl($a['id']);
- // generate player code
- $sCode = $oPlayer->getCodeVideo (BX_PLAYER_EMBED, array(
- 'poster' => $aTranscodersVideo['poster']->getFileUrl($a['id']),
- 'mp4' => array(
- 'sd' => $aTranscodersVideo['mp4']->getFileUrl($a['id']),
- 'hd' => $sVideoUrlHd
- ),
- ));
- // display page
- $oTemplate = BxDolTemplate::getInstance();
- $oTemplate->setPageNameIndex (BX_PAGE_EMBED);
- $oTemplate->setPageHeader ($a['file_name']);
- $oTemplate->setPageContent ('page_main_code', $sCode);
- $oTemplate->getPageCode();
- exit;
- }
- public function embedSound($iFileId)
- {
- $CNF = $this->getModule()->_oConfig->CNF;
- list($oPlayer, $oStorage, $aContentInfo, $a) = $this->_embedChecks('OBJECT_STORAGE_SOUNDS', $iFileId);
- // check if file is really audio
- $oTranscoderSound = isset($CNF['OBJECT_SOUNDS_TRANSCODER']) ? BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_SOUNDS_TRANSCODER']) : null;
- if (!$oTranscoderSound || (0 !== strncmp('audio/', $a['mime_type'], 6)) || !$oTranscoderSound->isMimeTypeSupported($a['mime_type'])) {
- $this->displayErrorOccured('', BX_PAGE_EMBED);
- exit;
- }
- if (!$oTranscoderSound->isFileReady($a['id'])) {
- $oTranscoderSound->getFileUrl($a['id']); // queue for encoding
- $this->displayMsg('_sys_txt_err_sound_not_transcoded_yet', true, BX_PAGE_EMBED);
- exit;
- }
- // generate player code
- $sCode = $oPlayer->getCodeAudio (BX_PLAYER_EMBED, array(
- 'mp3' => $oTranscoderSound->getFileUrl($a['id']),
- ));
- // display page
- $oTemplate = BxDolTemplate::getInstance();
- $oTemplate->setPageNameIndex (BX_PAGE_EMBED);
- $oTemplate->setPageHeader ($a['file_name']);
- $oTemplate->setPageContent ('page_main_code', $sCode);
- $oTemplate->getPageCode();
- exit;
- }
- protected function _embedChecks($sStorageKey, $iFileId)
- {
- // general checks
- $oPlayer = BxDolPlayer::getObjectInstance();
- $CNF = $this->getModule()->_oConfig->CNF;
- $sStorage = isset($CNF[$sStorageKey]) ? $CNF[$sStorageKey] : false;
- if (!$oPlayer || !$sStorage || !($oStorage = BxDolStorage::getObjectInstance($sStorage))) {
- $this->displayErrorOccured('', BX_PAGE_EMBED);
- exit;
- }
- // privacy check
- $aGhost = $oStorage->getGhost($iFileId);
- $aContentInfo = $aGhost && $aGhost['content_id'] ? $this->getModule()->_oDb->getContentInfoById($aGhost['content_id']) : false;
- if (!$aGhost || ($aGhost['content_id'] && !$aContentInfo)) {
- $this->displayPageNotFound('', BX_PAGE_EMBED);
- exit;
- }
-
- if (!$aGhost['content_id']) {
- // if file is not associated with content yet, then only admin and owner can view it
- if (!isAdmin() && CHECK_ACTION_RESULT_ALLOWED !== $this->getModule()->checkAllowedEditAnyEntry() && $aGhost['profile_id'] != bx_get_logged_profile_id()) {
- $this->displayAccessDenied('', BX_PAGE_EMBED);
- exit;
- }
- }
- else {
- // if file is associated with content, then check entry privacy
- if (CHECK_ACTION_RESULT_ALLOWED !== $this->getModule()->checkAllowedView($aContentInfo)) {
- $this->displayAccessDenied('', BX_PAGE_EMBED);
- exit;
- }
- }
- // get file info
- if (!($a = $oStorage->getFile($iFileId))) {
- $this->displayPageNotFound('', BX_PAGE_EMBED);
- exit;
- }
- return array($oPlayer, $oStorage, $aContentInfo, $a);
- }
- public function addCssJs()
- {
- $this->addCss('main.css');
- }
- }
- /** @} */
|