| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup BaseText Base classes for text modules
- * @ingroup UnaModules
- *
- * @{
- */
- /**
- * Module representation.
- */
- class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
- {
- function __construct(&$oConfig, &$oDb)
- {
- parent::__construct($oConfig, $oDb);
- }
- function unit ($aData, $isCheckPrivateContent = true, $sTemplateName = 'unit.html', $aParams = array())
- {
- $sResult = $this->checkPrivacy ($aData, $isCheckPrivateContent, $this->getModule(), $sTemplateName);
- if($sResult)
- return $sResult;
- return $this->parseHtmlByName($sTemplateName, $this->getUnit($aData, $aParams));
- }
- function getUnitMetaItemLink($sContent, $aAttrs = array())
- {
- return $this->parseHtmlTag(BX_DOL_TEMPLATE_TAG_A, $sContent, $aAttrs, 'unit_meta_item.html');
- }
- function getUnitMetaItemText($sContent, $aAttrs = array())
- {
- if(!is_array($aAttrs))
- $aAttrs = array();
- $aAttrs['class'] = (!empty($aAttrs['class']) ? $aAttrs['class'] . ' ' : '') . 'bx-def-font-grayed';
- return $this->parseHtmlTag(BX_DOL_TEMPLATE_TAG_SPAN, $sContent, $aAttrs, 'unit_meta_item.html');
- }
- function getUnitMetaItemCustom($sContent)
- {
- return $this->parseHtmlTag(BX_DOL_TEMPLATE_TAG_CUSTOM, $sContent, array(), 'unit_meta_item.html');
- }
- function entryAuthor ($aData, $iProfileId = false, $sFuncAuthorDesc = 'getAuthorDesc', $sTemplateName = 'author.html', $sFuncAuthorAddon = 'getAuthorAddon')
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
- if (!$iProfileId)
- $iProfileId = $aData[$CNF['FIELD_AUTHOR']];
- $oProfile = BxDolProfile::getInstance($iProfileId);
- if (!$oProfile)
- $oProfile = BxDolProfileUndefined::getInstance();
- if (!$oProfile)
- return '';
- $sName = $oProfile->getDisplayName();
- $sAddon = $sFuncAuthorAddon ? $this->$sFuncAuthorAddon($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' => $sFuncAuthorDesc ? $this->$sFuncAuthorDesc($aData) : '',
- 'bx_if:addon' => array (
- 'condition' => (bool)$sAddon,
- 'content' => array (
- 'content' => $sAddon,
- ),
- ),
- );
- return $this->parseHtmlByName($sTemplateName, $aVars);
- }
- function getAuthorDesc ($aData)
- {
- return '';
- }
- function getAuthorAddon ($aData, $oProfile)
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
- $sUrl = 'page.php?i=' . $CNF['URI_AUTHOR_ENTRIES'] . '&profile_id=' . $oProfile->id();
- $sUrl = BxDolPermalinks::getInstance()->permalink($sUrl);
- return _t($CNF['T']['txt_all_entries_by'], $sUrl, $oProfile->getDisplayName(), $this->getModule()->_oDb->getEntriesNumByAuthor($oProfile->id()));
- }
- 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
- ));
- }
- function entryAttachments ($aData, $aParams = array())
- {
- return $this->entryAttachmentsByStorage($this->getModule()->_oConfig->CNF['OBJECT_STORAGE'], $aData, $aParams);
- }
- function entryAttachmentsByStorage ($sStorage, $aData, $aParams = array())
- {
- if (!($a = $this->getAttachments($sStorage, $aData, $aParams)))
- return '';
- return $this->parseHtmlByName('attachments.html', array(
- 'bx_repeat:attachments' => $a,
- ));
- }
- protected function checkPrivacy ($aData, $isCheckPrivateContent, $oModule, $sTemplateName = '')
- {
- if ($isCheckPrivateContent && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $oModule->checkAllowedView($aData))) {
- $aVars = array (
- 'summary' => $sMsg,
- );
- return $this->parseHtmlByName($sTemplateName ? str_replace('.html', '_private.html', $sTemplateName) : 'unit_private.html', $aVars);
- }
- return '';
- }
- protected function getUnitThumbAndGallery ($aData)
- {
- $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
- $sPhotoThumb = '';
- $sPhotoGallery = '';
- if(!empty($CNF['FIELD_THUMB']) && !empty($aData[$CNF['FIELD_THUMB']])) {
- $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
- if ($oImagesTranscoder)
- $sPhotoThumb = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
- $oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']);
- if ($oImagesTranscoder)
- $sPhotoGallery = $oImagesTranscoder->getFileUrl($aData[$CNF['FIELD_THUMB']]);
- else
- $sPhotoGallery = $sPhotoThumb;
- }
- return array($sPhotoThumb, $sPhotoGallery);
- }
- protected function getUnit ($aData, $aParams = array())
- {
- $CNF = &BxDolModule::getInstance($this->MODULE)->_oConfig->CNF;
- // get thumb url
- list($sPhotoThumb, $sPhotoGallery) = $this->getUnitThumbAndGallery($aData);
- // get entry url
- $sUrl = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=' . $CNF['URI_VIEW_ENTRY'] . '&id=' . $aData[$CNF['FIELD_ID']]);
- $oProfile = BxDolProfile::getInstance($aData[$CNF['FIELD_AUTHOR']]);
- if (!$oProfile)
- $oProfile = BxDolProfileUndefined::getInstance();
- $sTitle = $this->getTitle($aData);
- $sText = $this->getText($aData);
- $sSummary = $this->getSummary($aData, $sTitle, $sText, $sUrl);
- $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'])) : '';
- if(!empty($CNF['OBJECT_METATAGS'])) {
- $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
-
- // keywords
- if ($oMetatags->keywordsIsEnabled())
- $sText = $oMetatags->keywordsParse($aData[$CNF['FIELD_ID']], $sText);
- }
- $sTitle = bx_process_output($sTitle);
- $sMeta = '';
- if(!empty($CNF['OBJECT_MENU_SNIPPET_META'])) {
- $oMenuMeta = BxDolMenu::getObjectInstance($CNF['OBJECT_MENU_SNIPPET_META'], $this);
- if($oMenuMeta) {
- $oMenuMeta->setContentId($aData[$CNF['FIELD_ID']]);
- $sMeta = $this->parseHtmlTag(BX_DOL_TEMPLATE_TAG_DIV, $oMenuMeta->getCode(), array(
- 'class' => 'bx-base-text-unit-meta'
- ));
- }
- }
- // generate html
- return array (
- 'id' => $aData[$CNF['FIELD_ID']],
- 'content_url' => $sUrl,
- 'title' => $sTitle,
- 'title_attr' => bx_html_attribute($sTitle),
- 'summary' => $sSummary,
- 'text' => $sText,
- 'author' => $oProfile->getDisplayName(),
- 'author_url' => $oProfile->getUrl(),
- 'author_icon' => $oProfile->getIcon(),
- 'author_thumb' => $oProfile->getThumb(),
- 'author_avatar' => $oProfile->getAvatar(),
- 'entry_posting_date' => bx_time_js($aData[$CNF['FIELD_ADDED']], BX_FORMAT_DATE),
- 'module_name' => _t($CNF['T']['txt_sample_single']),
- 'ts' => $aData[$CNF['FIELD_ADDED']],
- 'meta' => $sMeta,
- 'bx_if:thumb' => array (
- 'condition' => $sPhotoThumb,
- 'content' => array (
- 'title' => $sTitle,
- 'summary_attr' => bx_html_attribute($sSummaryPlain),
- 'content_url' => $sUrl,
- 'thumb_url' => $sPhotoThumb ? $sPhotoThumb : '',
- 'gallery_url' => $sPhotoGallery ? $sPhotoGallery : '',
- 'strecher' => str_repeat(' ', 40),
- ),
- ),
- 'bx_if:no_thumb' => array (
- 'condition' => !$sPhotoThumb,
- 'content' => array (
- 'content_url' => $sUrl,
- 'summary_plain' => $sSummaryPlain,
- 'strecher' => mb_strlen($sSummaryPlain) > 240 ? '' : str_repeat(' ', round((240 - mb_strlen($sSummaryPlain)) / 6)),
- ),
- ),
- );
- }
- protected function getTitle($aData)
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
- return isset($aData[$CNF['FIELD_TITLE']]) ? $aData[$CNF['FIELD_TITLE']] : '';
- }
- protected function getText($aData)
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
- return isset($aData[$CNF['FIELD_TEXT']]) ? $aData[$CNF['FIELD_TEXT']] : '';
- }
- 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);
- }
- protected function getAttachments ($sStorage, $aData, $aParams = array())
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
- $oStorage = BxDolStorage::getObjectInstance($sStorage);
- $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
- $aTranscodersVideo = false;
- if ($CNF['OBJECT_VIDEOS_TRANSCODERS'])
- $aTranscodersVideo = array (
- 'poster' => BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']),
- 'mp4' => BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']),
- 'webm' => BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['webm']),
- );
- $aGhostFiles = $oStorage->getGhosts ($aData[$CNF['FIELD_AUTHOR']], $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)); // preview for images, transcoder object for preview must be defined
- $isVideo = $aTranscodersVideo && (0 === strncmp('video/', $a['mime_type'], 6)); // preview for videos, transcoder object for video 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' => $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),
- ),
- );
- // 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']),
- $aTranscodersVideo['webm']->getFileUrl($a['id']),
- false, ''
- ) : '',
- ),
- );
- // non-images are displayed as text links to original file
- $a['bx_if:not_image'] = array (
- 'condition' => !$isImage && !$isVideo,
- '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;
- }
- }
- /** @} */
|