| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242 |
- <?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;
- protected $_bIsApi;
- public $aMethodsToCallAddJsCss = array('entry', 'unit');
- public function __construct(&$oConfig, &$oDb)
- {
- parent::__construct($oConfig, $oDb);
- $this->_bIsApi = bx_is_api();
- }
- public function addLocationBase()
- {
- parent::addLocationBase();
- $this->addLocation('mod_general', BX_DIRECTORY_PATH_MODULES . 'base' . DIRECTORY_SEPARATOR . 'general' . DIRECTORY_SEPARATOR, BX_DOL_URL_MODULES . 'base/general/');
- }
- 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([
- 'sActionUri' => $sBaseUri,
- 'sActionUrl' => BX_DOL_URL_ROOT . $sBaseUri,
- 'sObjName' => $sJsObject,
- 'aHtmlIds' => [],
- 'oRequestParams' => []
- ], $aParams);
- $sContent = false;
- /**
- * @hooks
- * @hookdef hook-system-get_js_code 'system', 'get_js_code' - hook to override an instance of JavaScript class associate with the page
- * - $unit_name - equals `system`
- * - $action - equals `get_js_code`
- * - $object_id - not used
- * - $sender_id - not used
- * - $extra_params - array of additional params with the following array keys:
- * - `mask` - [string] by ref, a mask to generate JS code, can be overridden in hook processing
- * - `mask_markers` - [array] by ref, an array of markers to be parsed in the mask, can be overridden in hook processing
- * - `object` - [string] by ref, a string with JS object name, can be overridden in hook processing
- * - `class` - [string] by ref, a string with JS class name, can be overridden in hook processing
- * - `params` - [array] by ref, an array of parameters as key&value pairs which will be passed to constructor, can be overridden in hook processing
- * - `override_result` - [string] or [boolean] by ref, if string is returned then it will be used as resulting JS code, can be overridden in hook processing
- * @hook @ref hook-system-get_js_code
- */
- bx_alert('system', 'get_js_code', 0, 0, [
- 'mask' => &$sMask,
- 'mask_markers' => &$aMaskMarkers,
- 'object' => &$sJsObject,
- 'class' => &$sJsClass,
- 'params' => &$aParams,
- 'override_result' => &$sContent,
- ]);
- if($sContent === false)
- $sContent = bx_replace_markers($sMask, array_merge([
- '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 getAbstract($aData, $mixedProcessOutput = BX_DATA_TEXT)
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
- if(!isset($CNF['FIELD_ABSTRACT']) || !isset($aData[$CNF['FIELD_ABSTRACT']]))
- return '';
- $sResult = $aData[$CNF['FIELD_ABSTRACT']];
- 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($CNF['FIELD_TEXT']) || !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 = '')
- {
- $sAbstract = $this->getAbstract($aData);
- if(!empty($sAbstract))
- return $sAbstract;
- $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_abstract'] = $this->getAbstract($aData);
- $aVars['bx_if:show_entry_abstract'] = [
- 'condition' => !empty($aVars['entry_abstract']),
- 'content' => [
- 'entry_abstract' => $aVars['entry_abstract']
- ]
- ];
- $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 bx_is_api() ? ['id' => 2, 'type' => 'breadcrumb', 'data' => ['name' => BxDolModule::getInstance($this->MODULE)->_aModule['title'], 'url' => BxDolPermalinks::getInstance()->permalink($CNF['URL_HOME'])]] : $this->parseHtmlByName('breadcrumb.html', [
- 'url_home' => bx_absolute_url(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 bx_is_api() ? $aVars : $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;
- $iListId = !empty($aList['id']) ? (int)$aList['id'] : 0;
- $oFavorite = BxDolFavorite::getObjectInstance($CNF['OBJECT_FAVORITES'], 0, true);
- $aListInfo = $oFavorite->getQueryObject()->getList(array('type' => 'info', 'list_id' => $iListId, 'author_id' => $oProfile->id()));
- $oPrivacy = BxDolPrivacy::getObjectInstance($CNF['OBJECT_PRIVACY_LIST_VIEW']);
- $sTitle = "";
- if ($aListInfo['allow_view_favorite_list_to'] < 0){
- $oProfileContext = BxDolProfile::getInstance(abs($aListInfo['allow_view_favorite_list_to']));
- $sTitle = $oProfileContext->getDisplayName();
- }
- else{
- if (empty($aListInfo['allow_view_favorite_list_to']))
- $aListInfo['allow_view_favorite_list_to'] = 3;
- $aPrivaciInfo = $oPrivacy->getGroupsBy(array('type'=>'id' , 'id'=> $aListInfo['allow_view_favorite_list_to']));
- $sTitle = _t($aPrivaciInfo['title']);
- }
-
- $aListsTmpl = array();
-
- if (!empty($aListInfo['created'])){
- $aListsTmpl[] = array('title' => _t('_sys_form_favorite_list_title_created'), 'value' => bx_time_js($aListInfo['created']));
- }
-
- $aListsTmpl = array_merge($aListsTmpl,
- array(
- array('title' => _t('_sys_form_favorite_list_title_updated'), 'value' => bx_time_js($aListInfo['updated'])),
- array('title' => _t('_sys_form_favorite_list_title_count'), 'value' => $aListInfo['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()));
- }
- public function getBrowsingFilters($aParams)
- {
- if(empty($aParams['mode']))
- return '';
- $mixedContent = $this->_getBrowsingFiltersContent($aParams);
- if($this->_bIsApi)
- return $mixedContent;
- if(empty($mixedContent))
- return '';
- $sPopupId = $this->_oConfig->getHtmlIds('popup_bfilters_' . $aParams['mode']);
- $sPopupContent = $this->parseHtmlByName('browsing_filters.html', [
- 'content' => $mixedContent
- ]);
- return BxTemplFunctions::getInstance()->transBox($sPopupId, $sPopupContent, true);
- }
- 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();
-
- if (bx_is_api()){
- foreach($mixedStorage as $sStorage) {
- $aAttachments = $this->getAttachments($sStorage, $aData, $aParams);
- if ($aAttachments){
- foreach($aAttachments as $aAttachment) {
- $aItem = [
- 'file_name' => $aAttachment['file_name'],
- 'mime_type' => $aAttachment['mime_type'],
- 'ext' => $aAttachment['ext'],
- 'type' => 'other',
- 'size' => $aAttachment['size'],
- 'url' => $aAttachment['bx_if:not_image']['content']['url_original']
- ];
- if ($aAttachment['bx_if:image']['condition'] == 1){
- $aItem['type'] = 'image';
- $aItem['data'] = bx_api_get_image($sStorage, $aAttachment['id']);
- }
- if ($aAttachment['bx_if:video']['condition'] == 1){
- $aItem['type'] = 'video';
- $aItem['data'] = bx_api_get_image($sStorage, $aAttachment['id']);
- }
- if ($aAttachment['bx_if:sound']['condition'] == 1){
- $aItem['type'] = 'sound';
- $aItem['data'] = bx_api_get_image($sStorage, $aAttachment['id']);
- }
-
- $aResult[] = $aItem;
- }
- }
- }
- return [bx_api_get_block('entity_attachments', $aResult)];
- }
-
- 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',
- ));
- $s = $this->addJs('pdfjs/pdf.min.mjs.js', true);
- return $s . $this->parseHtmlByName('attachments.html', array(
- 'bx_repeat:attachments' => $aResult,
- 'pdfjs_worker_url' => $this->getJsUrl('pdfjs/pdf.worker.min.mjs.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']);
- $oTranscoderView = !empty($CNF['OBJECT_IMAGES_TRANSCODER_PICTURE']) ? BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PICTURE']) : null;
- return array($oTranscoder, $oTranscoderView);
- }
- 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;
- }
-
- public function getAttachmentsData ($sStorage, $aData, $aParams = array())
- {
- return $this->getAttachments($sStorage, $aData, $aParams );
- }
-
- 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 = !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
- $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
- $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
- $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']);
- $aVideoFile = $oStorage->getFile($a['id']);
- if (!empty($aVideoFile['dimensions']) && $aTranscodersVideo['mp4_hd']->isProcessHD($aVideoFile['dimensions']))
- $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']);
- $aVideoFile = $oStorage->getFile($a['id']);
- if (!empty($aVideoFile['dimensions']) && $aTranscodersVideo['mp4_hd']->isProcessHD($aVideoFile['dimensions']))
- $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;
- }
- /**
- * Polls
- */
- public function entryPolls($aData)
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
-
- $aPolls = $this->_oDb->getPolls(array(
- 'type' => 'content_id',
- 'content_id' => $aData[$CNF['FIELD_ID']],
- ));
- if(empty($aPolls) || !is_array($aPolls))
- return;
- $iProfileId = bx_get_logged_profile_id();
- $sPolls = '';
- foreach($aPolls as $aPoll)
- $sPolls .= $this->getPollItem($aPoll, $iProfileId);
- if(empty($sPolls))
- return '';
- $this->_addCssJsPolls();
- return $this->getJsCode('poll') . $this->parseHtmlByName('poll_items.html', array(
- 'polls' => $sPolls
- ));
- }
- public function entryPollAnswers($aPoll, $bDynamic = false)
- {
- $sContent = $this->_getPollAnswers($aPoll, ['dynamic' => $bDynamic]);
- if(empty($sContent))
- return '';
- return [
- 'content' => $sContent,
- 'menu' => $this->_getPollBlockMenu($aPoll, 'answers')
- ];
- }
- public function entryPollResults($aPoll, $bDynamic = false)
- {
- $mixedContent = $this->_getPollResults($aPoll, ['dynamic' => $bDynamic]);
- if($this->_bIsApi)
- return $mixedContent;
- if(empty($mixedContent))
- return '';
- return [
- 'content' => $mixedContent,
- 'menu' => $this->_getPollBlockMenu($aPoll, 'results')
- ];
- }
- public function getPollForm($iParentCid = 0)
- {
- $aForm = $this->getModule()->getPollForm($iParentCid);
- return $this->parseHtmlByName('poll_form.html', [
- 'js_object' => $this->_oConfig->getJsObjectPoll($iParentCid),
- 'form_id' => $aForm['form_id'],
- 'form' => $aForm['form'],
- ]);
- }
-
- public function getPollField($iContentId = 0, $iProfileId = 0)
- {
- if(empty($iProfileId))
- $iProfileId = bx_get_logged_profile_id();
- $aPolls = [];
- if(!empty($iContentId))
- $aPolls = array_merge($aPolls, $this->_oDb->getPolls([
- 'type' => 'content_id',
- 'content_id' => $iContentId,
- ]));
- $aPolls = array_merge($aPolls, $this->_oDb->getPolls([
- 'type' => 'author_id',
- 'author_id' => $iProfileId,
- 'unused' => true
- ]));
- $mixedPolls = $this->_bIsApi ? [] : '';
- foreach($aPolls as $aPoll) {
- $mixedPoll = $this->getPollItem($aPoll, $iProfileId, [
- 'parent_cid' => $iContentId,
- 'manage' => true
- ]);
- if($this->_bIsApi)
- $mixedPolls[] = $mixedPoll;
- else
- $mixedPolls .= $mixedPoll;
- }
- return $this->_bIsApi ? $mixedPolls : $this->parseHtmlByName('poll_form_field.html', [
- 'html_id' => $this->_oConfig->getHtmlIds('add_poll_form_field'),
- 'polls' => $mixedPolls
- ]);
- }
- public function getPollItem($mixedPoll, $iProfileId = 0, $aParams = [])
- {
- $oModule = $this->getModule();
- $CNF = &$oModule->_oConfig->CNF;
- $aPoll = is_array($mixedPoll) ? $mixedPoll : $this->_oDb->getPolls(array('type' => 'id', 'id' => (int)$mixedPoll));
- if(empty($aPoll) || !is_array($aPoll))
- return $this->_bIsApi ? [] : '';
- $iPollId = (int)$aPoll[$CNF['FIELD_POLL_ID']];
- $sPollText = bx_process_output($aPoll[$CNF['FIELD_POLL_TEXT']], BX_DATA_TEXT);
- if($this->_bIsApi) {
- $bPerformed = $oModule->isPollPerformed($iPollId, $iProfileId);
- return [
- 'id' => $iPollId,
- 'title' => $sPollText,
- 'object' => $CNF['OBJECT_VOTES_POLL_ANSWERS'],
- 'subentries' => $this->_getPollAnswers($aPoll),
- 'results' => $this->_getPollResults($aPoll),
- 'is_performed' => $bPerformed,
- 'value' => $bPerformed ? $oModule->getPollPerformedValue($iPollId) : 0
- ];
- }
- $bDynamic = isset($aParams['dynamic']) && $aParams['dynamic'] === true;
- $bManage = isset($aParams['manage']) && $aParams['manage'] === true;
- $bSwitchMenu = isset($aParams['switch_menu']) ? (bool)$aParams['switch_menu'] : true;
- $bForceDisplayAnswers = isset($aParams['force_display_answers']) && (bool)$aParams['force_display_answers'] === true;
- $iParentСid = isset($aParams['parent_cid']) ? (int)$aParams['parent_cid'] : false;
- $sPollView = !$bForceDisplayAnswers && $oModule->isPollPerformed($iPollId, $iProfileId) ? 'results' : 'answers';
- $sMethod = '_getPoll' . ucfirst($sPollView);
- if(!method_exists($this, $sMethod))
- return '';
- $mixedMenu = '';
- if($bSwitchMenu)
- $mixedMenu = $this->_getPollBlockMenu($aPoll, $sPollView, [
- 'parent_cid' => $iParentСid,
- 'template' => 'menu_interactive.html'
- ]);
- $sJsObject = $iParentСid !== false ? $this->_oConfig->getJsObjectPoll($iParentСid) : $this->_oConfig->getJsObject('poll');
- return $this->parseHtmlByName('poll_item.html', array(
- 'html_id' => $this->_oConfig->getHtmlIds('poll') . $iPollId,
- 'bx_if:show_input_hidden' => array(
- 'condition' => $bManage,
- 'content' => array(
- 'name' => $CNF['FIELD_POLL'],
- 'id' => $iPollId
- )
- ),
- 'action_menu' => !empty($mixedMenu) ? $mixedMenu->getCode() : '',
- 'bx_if:show_action_embed' => array(
- 'condition' => $bManage,
- 'content' => array(
- 'js_object' => $sJsObject,
- 'id' => $iPollId
- )
- ),
- 'bx_if:show_action_delete' => array(
- 'condition' => $bManage,
- 'content' => array(
- 'js_object' => $sJsObject,
- 'id' => $iPollId,
- 'editor_id' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : ''
- )
- ),
- 'text' => $sPollText,
- 'content' => $this->$sMethod($aPoll, [
- 'dynamic' => $bDynamic,
- 'parent_cid' => $iParentСid
- ])
- ));
- }
- public function embedPollItem($mixedPoll, $aParams = array())
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
- $sHeader = '';
- $sContent = $this->getPollItem($mixedPoll, 0, $aParams);
- if(!empty($sContent)) {
- $aPoll = is_array($mixedPoll) ? $mixedPoll : $this->_oDb->getPolls(array('type' => 'id', 'id' => (int)$mixedPoll));
- $sHeader = strmaxtextlen($aPoll[$CNF['FIELD_POLL_TEXT']], 32, '...');
- $sContent = $this->getJsCode('poll') . $sContent;
- }
- $this->_addCssJsPolls();
- $oTemplate = BxDolTemplate::getInstance();
- $oTemplate->addCssStyle($CNF['STYLES_POLLS_EMBED_CLASS'], $CNF['STYLES_POLLS_EMBED_CONTENT']);
- $oTemplate->setPageNameIndex(BX_PAGE_EMBED);
- $oTemplate->setPageHeader($sHeader);
- $oTemplate->setPageContent('page_main_code', $sContent);
- $oTemplate->getPageCode();
- exit;
- }
- public function embedPollItems($mixedContentInfo, $aParams = array())
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
- $aContentInfo = is_array($mixedContentInfo) ? $mixedContentInfo : $this->_oDb->getContentInfoById((int)$mixedContentInfo);
- if(empty($aContentInfo) || !is_array($aContentInfo))
- return;
- $iContentId = (int)$aContentInfo[$CNF['FIELD_ID']];
- $aPolls = $this->_oDb->getPolls(array('type' => 'content_id', 'content_id' => $iContentId));
- if(empty($aPolls) || !is_array($aPolls))
- return;
- $iPolls = 0;
- $sContent = '';
- foreach($aPolls as $aPoll) {
- $sPoll = $this->getPollItem($aPoll, 0, $aParams);
- if(empty($sPoll))
- continue;
- $sContent .= $sPoll;
- $iPolls += 1;
- }
- $sJsObjectType = 'poll';
- if(!empty($sContent) && isset($aParams['showcase']) && (bool)$aParams['showcase'] === true) {
- $this->addJs(array('flickity/flickity.pkgd.min.js'));
- $this->addCss(BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flickity/|flickity.css');
- $sContent = $this->parseHtmlByName('poll_items_showcase.html', [
- 'js_object' => $this->_oConfig->getJsObject($sJsObjectType),
- 'html_id' => $this->_oConfig->getHtmlIds('polls_showcase') . $iContentId,
- 'type' => $iPolls == 1 ? 'single' : 'multiple',
- 'polls' => $sContent
- ]);
- }
- $sHeader = '';
- if(!empty($sContent)) {
- $sHeader = $iPolls == 1 ? array_shift($aPolls)[$CNF['FIELD_POLL_TEXT']] : _t('_polls_from', $aContentInfo[$CNF['FIELD_TITLE']]);
- $sHeader = strmaxtextlen($sHeader, 32, '...');
- $sContent = $this->getJsCode($sJsObjectType) . $sContent;
- }
- $this->_addCssJsPolls();
- $oTemplate = BxDolTemplate::getInstance();
- $oTemplate->addCssStyle($CNF['STYLES_POLLS_EMBED_CLASS'], $CNF['STYLES_POLLS_EMBED_CONTENT']);
- $oTemplate->setPageNameIndex(BX_PAGE_EMBED);
- $oTemplate->setPageHeader($sHeader);
- $oTemplate->setPageContent('page_main_code', $sContent);
- $oTemplate->getPageCode();
- exit;
- }
-
- protected function _addCssJsPolls($bDynamic = false)
- {
- $sInclude = '';
- $sInclude .= $this->addJs(['modules/base/general/js/|polls.js'], $bDynamic);
- $sInclude .= $this->addCss(['polls.css'], $bDynamic);
- return $bDynamic ? $sInclude : '';
- }
-
- protected function _getPollAnswers($aPoll, $aParams = [])
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
- $bDynamic = isset($aParams['dynamic']) && $aParams['dynamic'] === true;
- $iParentСid = isset($aParams['parent_cid']) && $aParams['parent_cid'] !== false ? (int)$aParams['parent_cid'] : false;
- $aAnswers = $this->_oDb->getPollAnswers(['type' => 'poll_id', 'poll_id' => $aPoll[$CNF['FIELD_POLL_ID']]]);
- if($this->_bIsApi)
- return $aAnswers;
- if(empty($aAnswers) || !is_array($aAnswers))
- return '';
- $aTmplVarsAnswers = [];
- foreach($aAnswers as $aAnswer) {
- $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES_POLL_ANSWERS'], $aAnswer['id']);
- if(!$oVotes)
- continue;
- $aTmplVarsAnswers[] = [
- 'answer' => $oVotes->getElementBlock([
- 'dynamic_mode' => $bDynamic,
- 'form_mode' => $iParentСid !== false
- ])
- ];
- }
- return $this->parseHtmlByName('poll_item_answers.html', [
- 'html_id' => $this->_oConfig->getHtmlIds('poll_content') . $aPoll[$CNF['FIELD_POLL_ID']],
- 'bx_repeat:answers' => $aTmplVarsAnswers
- ]);
- }
- protected function _getPollResults($aPoll, $aParams = [])
- {
- $CNF = &$this->getModule()->_oConfig->CNF;
- $bDynamic = isset($aParams['dynamic']) && $aParams['dynamic'] === true;
- $iParentСid = isset($aParams['parent_cid']) && $aParams['parent_cid'] !== false ? (int)$aParams['parent_cid'] : false;
- $aAnswers = $this->_oDb->getPollAnswers(['type' => 'poll_id', 'poll_id' => $aPoll[$CNF['FIELD_POLL_ID']]]);
- if(empty($aAnswers) || !is_array($aAnswers))
- return $this->_bIsApi ? [] : '';
- $iTotal = 0;
- foreach($aAnswers as $aAnswer)
- $iTotal += $aAnswer['votes'];
- $aTmplVarsAnswers = [];
- foreach($aAnswers as $aAnswer) {
- $oVotes = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES_POLL_ANSWERS'], $aAnswer['id']);
- if(!$oVotes)
- continue;
- $fPercent = $iTotal > 0 ? 100 * (float)$aAnswer['votes']/$iTotal : 0;
- $aTmplVarsAnswers[] = array_merge([
- 'title' => bx_process_output($aAnswer['title']),
- 'width' => (int)round($fPercent) . '%',
- 'percent' => _t($CNF['T']['txt_poll_answer_vote_percent'], $iTotal > 0 ? round($fPercent, 2) : 0),
- ], ($this->_bIsApi ? [
- 'votes' => $oVotes->getCounterAPI([
- 'show_counter_empty' => true,
- 'show_counter_in_brackets' => false
- ]),
- ] : [
- 'votes' => $oVotes->getCounter([
- 'show_counter_empty' => true,
- 'show_counter_in_brackets' => false,
- 'dynamic_mode' => $bDynamic,
- 'form_mode' => $iParentСid !== false
- ]),
- ]));
- }
- return $this->_bIsApi ? $aTmplVarsAnswers : $this->parseHtmlByName('poll_item_results.html', array(
- 'html_id' => $this->_oConfig->getHtmlIds('poll_content') . $aPoll[$CNF['FIELD_POLL_ID']],
- 'bx_repeat:answers' => $aTmplVarsAnswers,
- ));
- }
- protected function _getPollBlockMenu($aPoll, $sSelected = '', $aParams = [])
- {
- $CNF = &$this->_oConfig->CNF;
- $sJsObject = isset($aParams['parent_cid']) && $aParams['parent_cid'] !== false ? $this->_oConfig->getJsObjectPoll((int)$aParams['parent_cid']) : $this->_oConfig->getJsObject('poll');
- $iPollId = $aPoll[$CNF['FIELD_POLL_ID']];
- $aViews = [
- 'answers' => true,
- 'results' => $CNF['PARAM_POLL_HIDDEN_RESULTS'] === false || $this->getModule()->isPollPerformed($iPollId)
- ];
- $aMenu = array();
- foreach($aViews as $sView => $bActive) {
- if(!$bActive)
- continue;
- $sId = $this->_oConfig->getHtmlIds('poll_view_link_' . $sView) . $iPollId;
- if(!empty($sSelected) && $sSelected == $sView)
- $sSelected = $sId;
- $aMenu[] = array(
- 'id' => $sId,
- 'name' => $sId,
- 'class' => '',
- 'link' => 'javascript:void(0)',
- 'onclick' => 'javascript:' . $sJsObject . '.changePollView(this, \'' . $sView . '\', ' . $iPollId . ')',
- 'target' => '_self',
- 'title_attr' => _t($CNF['T']['txt_poll_menu_view_' . $sView]),
- 'title' => $this->parseIcon($CNF['ICON_POLLS_' . strtoupper($sView)])
- );
- }
- if(count($aMenu) <= 1)
- return '';
- $oMenu = new BxTemplMenuInteractive([
- 'template' => !empty($aParams['template']) ? $aParams['template'] : 'menu_interactive_vertical.html',
- 'menu_id' => $this->_oConfig->getHtmlIds('poll_view_menu') . '-' . time() . rand(0, PHP_INT_MAX),
- 'menu_items' => $aMenu
- ]);
- if(!empty($sSelected))
- $oMenu->setSelected('', $sSelected);
- return $oMenu;
- }
-
- 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);
- }
- function _getImageSettings($sField, $sSettings, $sUsage = '')
- {
- $sCoverSettings = '';
- if(($aCoverData = json_decode($sSettings, true)) && is_array($aCoverData))
- $sCoverSettings = 'background-position: ' . $aCoverData['x'] . '% ' . $aCoverData['y'] . '%';
- return $sCoverSettings;
- }
- function _prepareImage($aData, $sUniqId, $aUploaders, $sStorage, $sField, $bAllowTweak, $bAllowMultiple = false)
- {
- $oUploader = null;
- $sJsName = $sJsCode = '';
- foreach ($aUploaders as $sUploaderObject) {
- $oUploader = BxDolUploader::getObjectInstance($sUploaderObject, $sStorage, $sUniqId, $this);
- if (!$oUploader)
- continue;
- $sGhostTemplate = '{file_id}';
- $sJsCode .= $oUploader->getUploaderJs($sGhostTemplate, $bAllowMultiple, array_merge($oUploader->getUploaderJsParams(), [
- 'latest' => 1,
- 'content_id' => $aData['id'],
- 'storage_private' => '0',
- 'is_init_ghosts' => 0,
- 'is_init_reordering' => 0
- ]));
- $sJsName = $oUploader->getNameJsInstanceUploader();
- }
- $this->addJs(['BxDolUploader.js']);
- $this->addJsTranslation(['_sys_uploader_image_reposition_info']);
- return $this->parseHtmlByName('image_tweak.html', [
- 'id' => $aData['id'],
- 'js_object' => $sJsName,
- 'unique_id' => $sUniqId,
- 'id' => $aData['id'],
- 'allow_tweak' => $bAllowTweak,
- 'image_exists' => !$sField || $aData[$sField] == 0 ? 'bx-image-edit-buttons-no-image' : '',
- 'field' => $sField,
- 'action_url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri(),
- 'uploader' => !$oUploader ? '' : $oUploader->getUploaderButton([
- 'content_id' => $aData['id'],
- 'storage_private' => '0',
- 'btn_class' => '',
- 'button_title' => '',
- 'attrs' => "class='hidden'"
- ]),
- 'uploader_js' => $sJsCode,
- ]);
- }
- public function addCssJs()
- {
- $this->addCss('main.css');
- }
- }
- /** @} */
|