| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179 |
- <?php defined('BX_DOL') or die('hack attempt');
- /**
- * Copyright (c) UNA, Inc - https://una.io
- * MIT License - https://opensource.org/licenses/MIT
- *
- * @defgroup Timeline Timeline
- * @ingroup UnaModules
- *
- * @{
- */
- class BxTimelineTemplate extends BxBaseModNotificationsTemplate
- {
- protected static $_aMemoryCacheItems;
- protected static $_aMemoryCacheItemsData;
- protected static $_sMemoryCacheItemsKeyMask;
- protected static $_sTmplContentItemItem;
- protected static $_sTmplContentItemOutline;
- protected static $_sTmplContentItemOutlineSample;
- protected static $_sTmplContentItemTimeline;
- protected static $_sTmplContentItemTimelineSample;
- protected static $_sTmplContentItemSearch;
- protected static $_sTmplContentTypePost;
- protected static $_sTmplContentTypeRepost;
- protected $_bShowTimelineDividers;
- protected $_aAclId2Name;
- function __construct(&$oConfig, &$oDb)
- {
- parent::__construct($oConfig, $oDb);
- $this->_bShowTimelineDividers = false;
- $this->_aAclId2Name = array();
- bx_import('BxTemplAcl');
- $aAclLevels = BxDolAcl::getInstance()->getMemberships(false, false, false);
- foreach($aAclLevels as $iAclId => $sAclName)
- $this->_aAclId2Name[$iAclId] = str_replace('_', '-', str_replace('_adm_prm_txt_level_', '', $sAclName));
- }
- public function init()
- {
- parent::init();
- self::$_aMemoryCacheItems = array();
- self::$_aMemoryCacheItemsData = array();
- self::$_sMemoryCacheItemsKeyMask = "%s_%d";
- }
- public function getAddedCss($sType = '', $bDynamic = false)
- {
- $aCss = array();
- switch($sType) {
- case 'view':
- $aCss = array(
- BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flickity/|flickity.css',
- 'cmts.css',
- 'view.css',
- 'view-media-tablet.css',
- 'view-media-desktop.css',
- 'repost.css',
- );
- if($this->_oConfig->isJumpTo()) {
- list($aCssCalendar, $aJsCalendar) = BxBaseFormView::getCssJsCalendar();
- $aCss = array_merge($aCss, $aCssCalendar);
- }
- break;
- case 'post':
- if($this->_oConfig->isEmoji())
- $aCss[] = BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'emoji/css/|emoji.css';
- $aCss[] = 'post.css';
- break;
- }
- $mixedResult = $this->addCss($aCss, $bDynamic);
- if($bDynamic)
- return $mixedResult;
- }
- public function getAddedJs($sType = '', $bDynamic = false)
- {
- $aJs = array(
- 'autosize.min.js',
- 'jquery.anim.js',
- 'main.js',
- );
- switch($sType) {
- case 'view':
- $aJs = array_merge($aJs, array(
- 'masonry.pkgd.min.js',
- 'flickity/flickity.pkgd.min.js',
- 'embedly-player.min.js',
- 'BxDolCmts.js',
- 'view.js',
- 'repost.js',
- ));
- if ($this->_oConfig->isJumpTo()) {
- list($aCssCalendar, $aJsCalendar) = BxBaseFormView::getCssJsCalendar();
- $aJs = array_merge($aJs, $aJsCalendar);
- }
- break;
- case 'post':
- $aJs = array_merge($aJs, array(
- 'jquery.form.min.js',
- 'post.js',
- ));
- break;
- }
- $mixedResult = $this->addJs($aJs, $bDynamic);
- if($bDynamic)
- return $mixedResult;
- }
- public function getJsCodeView($aParams = array(), $bWrap = true, $bDynamic = false)
- {
- $aParams = array_merge([
- 'sObjNameMenuFeeds' => $this->_oConfig->getObject('menu_feeds'),
- 'bInfScroll' => $this->_oConfig->isInfiniteScroll(),
- 'iInfScrollAutoPreloads' => $this->_oConfig->getAutoPreloads(),
- 'iLimitAttachLinks' => $this->_oConfig->getLimitAttachLinks(),
- 'sLimitAttachLinksErr' => bx_js_string(_t('_bx_timeline_txt_err_attach_links')),
- 'oAttachedLinks' => []
- ], $aParams);
- return parent::getJsCode('view', $aParams, $bWrap, $bDynamic);
- }
- public function getJsCodePost($iOwnerId, $aParams = array(), $bWrap = true, $bDynamic = false)
- {
- $aGeneralParams = [];
- $aRequestParams = $aParams;
- if(isset($aParams['gparams'], $aParams['rparams'])) {
- $aGeneralParams = $aParams['gparams'];
- $aRequestParams = $aParams['rparams'];
- }
- return $this->getJsCode('post', array_merge(array(
- 'bEmoji' => $this->_oConfig->isEmoji(),
- 'bAutoAttach' => $this->_oConfig->isEditorAutoAttach(),
- 'iLimitAttachLinks' => $this->_oConfig->getLimitAttachLinks(),
- 'sLimitAttachLinksErr' => bx_js_string(_t('_bx_timeline_txt_err_attach_links')),
- 'oAttachedLinks' => $this->_oDb->getLinksBy(array(
- 'type' => 'unused',
- 'profile_id' => $this->getModule()->getUserId(),
- 'short' => true
- )),
- 'sVideosAutoplay' => $this->_oConfig->getVideosAutoplay(),
- 'oRequestParams' => array_merge(array(
- 'type' => isset($aRequestParams['type']) ? $aRequestParams['type'] : BX_TIMELINE_TYPE_DEFAULT,
- 'owner_id' => $iOwnerId
- ), $aRequestParams)
- ), $aGeneralParams), $bWrap, $bDynamic);
- }
- public function getPostBlock($iOwnerId, $aParams = array())
- {
- $CNF = &$this->_oConfig->CNF;
- $aForm = $this->getModule()->getFormPost($aParams);
- if($this->_oConfig->isEditorAutoattach() && !empty($aForm['form_object'])) {
- $aUploadersInfo = $aForm['form_object']->getUploadersInfo($CNF['FIELD_PHOTO']);
- if(!empty($aUploadersInfo) && is_array($aUploadersInfo))
- $aParams = [
- 'gparams' => ['sAutoUploader' => $aUploadersInfo['name'], 'sAutoUploaderId' => $aUploadersInfo['id']],
- 'rparams' => $aParams
- ];
- }
- return $this->parseHtmlByName('block_post.html', array (
- 'style_prefix' => $this->_oConfig->getPrefix('style'),
- 'js_object' => $this->_oConfig->getJsObject('post'),
- 'js_content' => $this->getJsCodePost($iOwnerId, $aParams),
- 'form' => $aForm['form']
- ));
- }
- public function getViewsBlock($aParams)
- {
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $sJsObject = $this->_oConfig->getJsObjectView($aParams);
-
- $sType = isset($aParams['type']) ? $aParams['type'] : '';
- $sMenu = $this->_oConfig->getObject('menu_view');
- $oMenu = BxDolMenu::getObjectInstance($sMenu);
- $aMenuItems = $oMenu->getMenuItems();
- if(empty($aMenuItems) || !is_array($aMenuItems))
- return '';
- if(empty($sType)) {
- $aMenuItem = array_shift($aMenuItems);
- $sType = $aMenuItem['name'];
- }
- $oMenu->setSelected($this->_oConfig->getName(), $sType);
- $oMenu->addMarkers(array(
- 'js_object_view' => $sJsObject
- ));
- $sTitle = _t('_bx_timeline_page_block_title_views_' . $aParams['view']);
- if (bx_is_api())
- return [
- 'content' => [bx_api_get_block('browse', ['unit' => 'feed', 'data' => $this->getViewBlock($aParams)])],
- 'menu' => $oMenu->getCodeAPI()
- ];
- return [
- 'content' => $this->parseHtmlByName('block_views.html', [
- 'style_prefix' => $sStylePrefix,
- 'html_id' => $this->_oConfig->getHtmlIdView('views', $aParams, ['with_type' => false]),
- 'html_id_content' => $this->_oConfig->getHtmlIdView('views_content', $aParams, ['with_type' => false]),
- 'html_id_view_placeholder' => $this->_oConfig->getHtmlIdView('main', array_merge($aParams, ['type' => 'placeholder'])),
- 'title' => $sTitle,
- 'content' => $this->getViewBlock($aParams)
- ]),
- 'menu' => $oMenu
- ];
- }
- public function getViewsDbBlock($aParams)
- {
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $sJsObject = $this->_oConfig->getJsObjectView($aParams);
- $sJsContent = $this->getJsCodeView([
- 'sObjName' => $sJsObject,
- 'sName' => $aParams['name'],
- 'sView' => $aParams['view'],
- 'sType' => $aParams['type'],
- 'sVideosAutoplay' => $this->_oConfig->getVideosAutoplay(),
- 'oRequestParams' => $aParams
- ], [
- 'wrap' => true,
- 'mask_markers' => ['object' => $sJsObject]
- ]);
- return array(
- 'content' => $this->parseHtmlByName('block_views_db.html', array(
- 'style_prefix' => $sStylePrefix,
- 'html_id' => $this->_oConfig->getHtmlIdView('views', $aParams, array('with_type' => false)),
- 'html_id_content' => $this->_oConfig->getHtmlIdView('views_content', $aParams, array('with_type' => false)),
- 'content' => $this->getViewBlock(array_merge($aParams, ['name' => ''])),
- 'js_content' => $sJsContent
- )),
- 'buttons' => [
- ['title' => _t('_bx_timeline_txt_filters'), 'href' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFeedFilters(this)']
- ]
- );
- }
- public function getViewFilters($aParams)
- {
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $sJsObject = $this->_oConfig->getJsObjectView($aParams);
- $aHandlers = $this->_oDb->getHandlers(['type' => 'by_type', 'value' => 'insert']);
- $aModules = [];
- foreach($aHandlers as $aHandler) {
- $sModule = $aHandler['alert_unit'];
- if(isset($aModules[$sModule]))
- continue;
- $aModule = $this->_oDb->getModuleByName($sModule);
- if(empty($aModule) || !is_array($aModule))
- continue;
- $sTitleKey = '_' . $sModule;
- $sTitleValue = _t($sTitleKey);
- if(strcmp($sTitleKey, $sTitleValue) == 0)
- $sTitleValue = $aModule['title'];
- $aModules[$sModule] = [
- 'key' => $aHandler['alert_unit'],
- 'value' => $sTitleValue
- ];
- }
- uasort($aModules, function($aV1, $aV2) {
- return strcmp($aV1['value'], $aV2['value']);
- });
- $aForm = [
- 'inputs' => [
- 'by_module' => [
- 'name' => 'by_module',
- 'type' => 'radio_set',
- 'caption' => _t('_bx_timeline_form_filters_input_by_modules'),
- 'values' => [
- ['key' => 'all', 'value' => _t('_bx_timeline_form_filters_input_by_modules_all')],
- ['key' => 'selected', 'value' => _t('_bx_timeline_form_filters_input_by_modules_selected')]
- ],
- 'value' => 'all',
- 'attrs' => ['onchange' => $sJsObject . '.onFilterByModuleChange(this)'],
- 'dv_thd' => 1
- ],
- 'modules' => [
- 'name' => 'modules',
- 'type' => 'checkbox_set',
- 'values' => array_values($aModules),
- 'tr_attrs' => ['class' => 'modules', 'style' => 'display:none']
- ],
- 'apply' => [
- 'name' => 'apply',
- 'type' => 'button',
- 'value' => _t('_bx_timeline_form_filters_input_do_apply'),
- 'attrs' => ['onclick' => $sJsObject . '.onFilterApply(this)']
- ]
- ]
- ];
- $oForm = new BxTemplFormView($aForm);
-
- $sViewFiltersPopupId = $this->_oConfig->getHtmlIdView('filters_popup', $aParams);
- $sViewFiltersPopupContent = $this->parseHtmlByName('block_view_filters.html', array(
- 'style_prefix' => $sStylePrefix,
- 'js_object' => $sJsObject,
- 'content' => $oForm->genRows()
- ));
- return BxTemplFunctions::getInstance()->transBox($sViewFiltersPopupId, $sViewFiltersPopupContent, true);
- }
- public function getViewBlock($aParams)
- {
- $oModule = $this->getModule();
-
- if (bx_is_api()){
- $aPosts = $this->getPosts(array_merge($aParams, ['return_data_type' => 'array']));
- foreach($aPosts as &$aPost) {
- $aPost['author_data'] = BxDolProfile::getData($aPost['object_owner_id']);
- $aPost['url'] = bx_ltrim_str($aPost['content']['url'], BX_DOL_URL_ROOT);
-
- $aCmts = [];
- $oCmts = $oModule->getCmtsObject($aPost['comments']['system'], $aPost['comments']['object_id']);
- if($oCmts !== false){
- $aParams = ['mode' => 'feed', 'order_way' => 'desc', 'start_from' => 0, 'per_view' => 1];
- $aCmts = bx_srv('system', 'get_comments_api', [$oCmts, $aParams], 'TemplCmtsServices');
-
- $aPost['cmts'] = $aCmts;
- $aPost['cmts']['count'] = $aPost['comments']['count'];
- }
- }
- return $aPosts;
- }
-
- list($sContent, $sLoadMore, $sBack, $sEmpty, $iEvent, $bEventsToLoad) = $this->getPosts($aParams);
- //--- Add live update
- $oModule->actionResumeLiveUpdate($aParams['type'], $aParams['owner_id']);
- $sModuleName = $oModule->getName();
- $sModuleMethod = !empty($aParams['get_live_updates']) ? $aParams['get_live_updates'] : 'get_live_update';
- $sService = BxDolService::getSerializedService($sModuleName, $sModuleMethod, array($aParams, $oModule->getUserId(), '{count}', '{init}'));
- $aLiveUpdateParams = array($this->_oConfig->getLiveUpdateKey($aParams), 1, $sService, true);
- if($sModuleMethod == 'get_live_update')
- $aLiveUpdateParams[] = $iEvent;
- $sLiveUpdateCode = null;
- bx_alert($sModuleName, 'add_live_update', 0, 0, array(
- 'browse_params' => $aParams,
- 'live_update_params' => &$aLiveUpdateParams,
- 'override_result' => &$sLiveUpdateCode,
- ));
- if($sLiveUpdateCode === null && ($oLiveUpdates = BxDolLiveUpdates::getInstance()) !== false)
- $sLiveUpdateCode = call_user_func_array([$oLiveUpdates, 'add'], $aLiveUpdateParams);
- //--- Add live update
- $sContentBefore = '';
- $sContentAfter = '';
- $sJsObject = $this->_oConfig->getJsObjectView($aParams);
- $sJsContent = $this->getJsCodeView(array(
- 'sObjName' => $sJsObject,
- 'sName' => $aParams['name'],
- 'sView' => $aParams['view'],
- 'sType' => $aParams['type'],
- 'sVideosAutoplay' => $this->_oConfig->getVideosAutoplay(),
- 'bEventsToLoad' => $bEventsToLoad,
- 'bAutoMarkAsViewed' => $this->_oConfig->isSortByUnread(),
- 'oRequestParams' => $aParams
- ), array(
- 'wrap' => true,
- 'mask_markers' => array('object' => $sJsObject)
- )) . $this->getJsCode('repost');
- bx_alert($sModuleName, 'get_view', 0, 0, array(
- 'params' => $aParams,
- 'event_first' => $iEvent,
- 'back' => &$sBack,
- 'empty' => &$sEmpty,
- 'content_before' => &$sContentBefore,
- 'content' => &$sContent,
- 'content_after' => &$sContentAfter,
- 'load_more' => &$sLoadMore,
- 'js_content' => &$sJsContent
- ));
- return $this->parseHtmlByName('block_view.html', array(
- 'style_prefix' => $this->_oConfig->getPrefix('style'),
- 'html_id' => $this->_oConfig->getHtmlIdView('main', $aParams),
- 'view' => $aParams['view'],
- 'back' => $sBack,
- 'empty' => $sEmpty,
- 'content_before' => $sContentBefore,
- 'content' => $sContent,
- 'content_after' => $sContentAfter,
- 'load_more' => $sLoadMore,
- 'show_more' => $this->_getShowMore($aParams),
- 'view_image_popup' => $this->_getImagePopup($aParams),
- 'live_update_code' => $sLiveUpdateCode,
- 'js_content' => $sJsContent
- ));
- }
- public function getSearchBlock($sContent)
- {
- $oModule = $this->getModule();
- $aParams = $oModule->getParams(BX_TIMELINE_VIEW_SEARCH);
- return $this->parseHtmlByName('block_search.html', array(
- 'style_prefix' => $this->_oConfig->getPrefix('style'),
- 'html_id' => $this->_oConfig->getHtmlIdView('main', $aParams),
- 'view' => $aParams['view'],
- 'content' => $sContent,
- 'view_image_popup' => $this->_getImagePopup($aParams),
- 'js_content' => $this->getJsCodeView(array(
- 'oRequestParams' => $aParams
- ))
- ));
- }
- public function getItemBlock($mixedId, $aBrowseParams = array())
- {
- $CNF = $this->_oConfig->CNF;
- $oModule = $this->getModule();
- if(is_numeric($mixedId))
- $mixedId = $oModule->getItemData($mixedId);
- if(empty($mixedId) || !is_array($mixedId))
- return array('content' => MsgBox(_t('_Empty')), 'designbox_id' => 13);
- if($mixedId['code'] != 0)
- return array('content' => MsgBox($mixedId['content']), 'designbox_id' => 13);
- $aEvent = $mixedId['event'];
- $sContent = $mixedId['content'];
- if(!$this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
- $mixedViews = $oModule->getViewsData($aEvent['views']);
- if($mixedViews !== false) {
- list($sSystem, $iObjectId) = $mixedViews;
- $oModule->getViewObject($sSystem, $iObjectId)->doView();
- }
- }
- $sAuthorName = $oModule->getObjectUser($aEvent['object_owner_id'])->getDisplayName();
- $sTitle = $sAuthorName . ' ' . _t($aEvent['sample_action'], _t($aEvent['sample']));
- $sDescription = $aEvent['title'];
- if(get_mb_substr($sDescription, 0, 1) == '_')
- $sDescription = _t($sDescription);
- $oTemplate = BxDolTemplate::getInstance();
- $oTemplate->setPageHeader(strip_tags($sTitle));
- $oTemplate->setPageDescription(strip_tags($sDescription));
- $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
- if($oMetatags)
- $oMetatags->addPageMetaInfo($aEvent[$CNF['FIELD_ID']]);
- $sReferrer = '';
- if(isset($_SERVER['HTTP_REFERER']) && mb_stripos($_SERVER['HTTP_REFERER'], BX_DOL_URL_ROOT) === 0)
- $sReferrer = $_SERVER['HTTP_REFERER'];
- else
- $sReferrer = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($this->_oConfig->CNF['URL_HOME']));
- $sJsObject = $this->_oConfig->getJsObjectView($aBrowseParams);
- return array('content' => $this->parseHtmlByName('block_item.html', array(
- 'style_prefix' => $this->_oConfig->getPrefix('style'),
- 'html_id' => $this->_oConfig->getHtmlIdView('main', $aBrowseParams),
- 'content' => $sContent,
- 'show_more' => $this->_getShowMore($aBrowseParams),
- 'view_image_popup' => $this->_getImagePopup($aBrowseParams),
- 'js_content' => $this->getJsCodeView(array(
- 'sObjName' => $sJsObject,
- 'sVideosAutoplay' => $this->_oConfig->getVideosAutoplay(),
- 'sReferrer' => $sReferrer,
- 'oRequestParams' => $aBrowseParams
- ), array(
- 'wrap' => true,
- 'mask_markers' => array('object' => $sJsObject)
- )) . $this->getJsCode('repost')
- )));
- }
- /**
- * Get event's content.
- * @param integer $iId - event ID.
- * @param string $sMode - 'file'/'photo'/'video' are available for now. But only images will be shown.
- */
- public function getItemBlockContent($iId, $sMode) {
- $oModule = $this->getModule();
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $aItemData = $oModule->getItemData($iId);
- if(empty($aItemData) || $aItemData['code'] != 0)
- return '';
- $aEvent = $aItemData['event'];
- $sKeyMain = $sKeyAttach = '';
- switch($sMode) {
- case 'file':
- $sKeyMain = 'files';
- $sKeyAttach = 'files_attach';
- break;
- case 'photo':
- $sKeyMain = 'images';
- $sKeyAttach = 'images_attach';
- break;
- case 'video':
- $sKeyMain = 'videos';
- $sKeyAttach = 'videos_attach';
- break;
- }
- $aImages = [];
- if(!empty($aEvent['content'][$sKeyMain]) && is_array($aEvent['content'][$sKeyMain]))
- $aImages = $aEvent['content'][$sKeyMain];
- else if(!empty($aEvent['content'][$sKeyAttach]) && is_array($aEvent['content'][$sKeyAttach]))
- $aImages = $aEvent['content'][$sKeyAttach];
- if(isset($aImages['total']) && isset($aImages['items']))
- $aImages = $aImages['items'];
- $bImageSingle = count($aImages) == 1;
- $sImageSelected = base64_decode(bx_process_input(bx_get('src')));
- $aTmplVarsImages = [];
- if(!$bImageSingle) {
- $iIndex = 1;
- foreach($aImages as $aImage) {
- if(!isset($aImage['src'], $aImage['src_orig']))
- continue;
- $iCurrent = $iIndex;
- if(strcmp($aImage['src'], $sImageSelected) == 0 || strcmp($aImage['src_orig'], $sImageSelected) == 0)
- $iCurrent = 0;
- $aTmplVarsImages[$iCurrent] = [
- 'style_prefix' => $sStylePrefix,
- 'url' => $aImage['url'],
- 'src' => $aImage[!empty($aImage['src_orig']) ? 'src_orig' : 'src']
- ];
- $iIndex++;
- }
- ksort($aTmplVarsImages);
- $aTmplVarsImages = array_values($aTmplVarsImages);
- }
- $aTmplVars = [
- 'style_prefix' => $sStylePrefix,
- 'bx_if:show_image' => [
- 'condition' => $bImageSingle,
- 'content' => [
- 'style_prefix' => $sStylePrefix,
- 'src' => $sImageSelected,
- ]
- ],
- 'bx_if:show_images' => [
- 'condition' => !$bImageSingle,
- 'content' => [
- 'style_prefix' => $sStylePrefix,
- 'bx_repeat:images' => $aTmplVarsImages
- ]
- ]
- ];
- return $this->parseHtmlByName('block_item_content.html', $aTmplVars);
- }
- public function getItemBlockInfo($iId) {
- $CNF = $this->_oConfig->CNF;
- $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
- if(empty($aEvent))
- return '';
- $aResult = $this->getDataCached($aEvent);
- if($aResult === false)
- return '';
- $sAuthorUnit = $this->getModule()->getObjectUser($aResult['object_owner_id'])->getUnit();
- $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_post'), $this->_oConfig->getObject('form_display_post_view'), $this);
- $oForm->initChecker($aEvent);
- return $this->parseHtmlByName('block_item_info.html', array(
- 'style_prefix' => $this->_oConfig->getPrefix('style'),
- 'author' => $sAuthorUnit,
- 'fields' => $oForm->getCode()
- ));
- }
- public function getItemBlockComments($iId)
- {
- $aEvent = $this->_oDb->getEvents(['browse' => 'id', 'value' => $iId]);
- if(empty($aEvent))
- return '';
- $aEventData = $this->getDataCached($aEvent);
- if($aEventData === false)
- return '';
- if(!$this->getModule()->isAllowedComment(array_merge($aEvent, $aEventData)))
- return '';
- return $this->parseHtmlByName('block_item_comments.html', [
- 'style_prefix' => $this->_oConfig->getPrefix('style'),
- 'content' => $this->_getComments($aEventData['comments'])
- ]);
-
- }
- public function getUnit(&$aEvent, $aBrowseParams = array())
- {
- $oModule = $this->getModule();
- if(empty($aBrowseParams) || !is_array($aBrowseParams))
- $aBrowseParams = $oModule->getParams(BX_TIMELINE_VIEW_SEARCH);
- return $this->getPost($aEvent, $aBrowseParams);
- }
- public function getPost(&$aEvent, $aBrowseParams = array())
- {
- $CNF = &$this->_oConfig->CNF;
- $iEventId = (int)$aEvent[$CNF['FIELD_ID']];
- $iViewerId = isset($aBrowseParams['viewer_id']) ? (int)$aBrowseParams['viewer_id'] : bx_get_logged_profile_id();
- $sMemoryCacheItemsKey = sprintf(self::$_sMemoryCacheItemsKeyMask, $aBrowseParams['view'], $iEventId);
- if(array_key_exists($sMemoryCacheItemsKey, self::$_aMemoryCacheItems)) {
- if(array_key_exists($sMemoryCacheItemsKey, self::$_aMemoryCacheItemsData))
- $aEvent = self::$_aMemoryCacheItemsData[$sMemoryCacheItemsKey];
- return self::$_aMemoryCacheItems[$sMemoryCacheItemsKey];
- }
- /**
- * Add all items in memory cache even if they are empty.
- */
- self::$_aMemoryCacheItems[$sMemoryCacheItemsKey] = '';
- self::$_aMemoryCacheItemsData[$sMemoryCacheItemsKey] = array();
- $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
- if($oPrivacy) {
- $oPrivacy->setTableFieldAuthor($this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? 'owner_id' : 'object_id');
- if(!$oPrivacy->check($iEventId, $iViewerId))
- return '';
- }
- $aResult = $this->getDataCached($aEvent, $aBrowseParams);
- if($aResult === false)
- return '';
- if(isset($aResult['owner_id']))
- $aEvent['owner_id'] = $aResult['owner_id'];
- $aEvent['object_owner_id'] = $aResult['object_owner_id'];
- $aEvent['icon'] = !empty($aResult['icon']) ? $aResult['icon'] : '';
- $aEvent['sample'] = !empty($aResult['sample']) ? $aResult['sample'] : '_bx_timeline_txt_sample';
- $aEvent['sample_action'] = !empty($aResult['sample_action']) ? $aResult['sample_action'] : '_bx_timeline_txt_added_sample';
- if(isset($aResult['sample_action_custom']))
- $aEvent['sample_action_custom'] = $aResult['sample_action_custom'];
- $aEvent['content'] = $aResult['content'];
- $aEvent['content_type'] = !empty($aResult['content_type']) ? $aResult['content_type'] : BX_TIMELINE_PARSE_TYPE_DEFAULT;
- $aEvent['views'] = $aResult['views'];
- $aEvent['votes'] = $aResult['votes'];
- $aEvent['reactions'] = $aResult['reactions'];
- $aEvent['scores'] = $aResult['scores'];
- $aEvent['reports'] = $aResult['reports'];
- $aEvent['comments'] = $aResult['comments'];
- $sKey = 'allowed_view';
- $aEvent[$sKey] = $this->_preparePrivacy($sKey, $aEvent, $aResult);
- if(isset($aEvent[$sKey]) && $aEvent[$sKey] !== CHECK_ACTION_RESULT_ALLOWED)
- return '';
- self::$_aMemoryCacheItems[$sMemoryCacheItemsKey] = $this->_getPost($aEvent['content_type'], $aEvent, $aBrowseParams);
- self::$_aMemoryCacheItemsData[$sMemoryCacheItemsKey] = $aEvent;
- return self::$_aMemoryCacheItems[$sMemoryCacheItemsKey];
- }
- public function getPosts($aParams)
- {
- $bReturnArray = isset($aParams['return_data_type']) && $aParams['return_data_type'] == 'array';
- $bViewTimeline = $aParams['view'] == BX_TIMELINE_VIEW_TIMELINE;
- $iStart = $aParams['start'];
- $iPerPage = $aParams['per_page'];
- $aParamsDb = $aParams;
- //--- Before: Check for Previous
- $iDays = -1;
- $bPrevious = false;
- if($iStart - 1 >= 0) {
- $aParamsDb['start'] -= 1;
- $aParamsDb['per_page'] += 1;
- $bPrevious = true;
- }
- //--- Before: Check for Next
- $aParamsDb['per_page'] += 1;
- $aEvents = $this->_oDb->getEvents($aParamsDb);
- //--- After: Check for Previous
- if($bPrevious) {
- $aEvent = array_shift($aEvents);
- if ($aEvent)
- $iDays = (int)$aEvent['days'];
- }
- //--- After: Check for Next
- $bNext = false;
- if(count($aEvents) > $iPerPage) {
- $aEvent = array_pop($aEvents);
- $bNext = true;
- }
- $sContent = '';
- $sContent .= $this->getSizer($aParams);
- $iFirst = 0;
- $iEvents = count($aEvents);
- if($iEvents > 0)
- $iFirst = $this->_getFirst($aEvents, $aParams);
- else
- $sContent .= $bViewTimeline ? $this->getDividerToday() : '';
- //--- Check for Visual Grouping
- $aGroups = array();
- foreach($aEvents as $iIndex => $aEvent) {
- $aContent = unserialize($aEvent['content']);
- if(!isset($aContent['timeline_group']))
- continue;
- $aGroup = $aContent['timeline_group'];
- $sGroup = $aGroup['by'];
- if(!isset($aGroups[$sGroup]))
- $aGroups[$sGroup] = array('field' => $aGroup['field'], 'indexes' => array(), 'processed' => false);
- $aGroups[$sGroup]['indexes'][] = $iIndex;
- }
- //--- Perform Visual Grouping
- foreach($aGroups as $sGroup => $aGroup) {
- if(empty($aGroup['field']) || empty($aGroup['indexes']))
- continue;
- switch($aGroup['field']) {
- case 'owner_id':
- $aOwnerIds = array();
- foreach($aGroup['indexes'] as $iIndex)
- if(!in_array($aEvents[$iIndex]['owner_id'], $aOwnerIds))
- $aOwnerIds[] = $aEvents[$iIndex]['owner_id'];
- $iGroupIndex = (int)array_shift($aGroup['indexes']);
- if(is_null($iGroupIndex))
- break;
- foreach($aGroup['indexes'] as $iIndex)
- unset($aEvents[$iIndex]);
- $aEvents[$iGroupIndex]['owner_id_grouped'] = $aOwnerIds;
- break;
- }
- }
- $iExtenalsEvery = $this->_oConfig->getExtenalsEvery($aParams['type']);
- $bFirst = true;
- $iEventIndex = 0;
- $mixedEvents = $bReturnArray ? array() : '';
- foreach($aEvents as $aEvent) {
- $iEvent = (int)$aEvent['id'];
- $sEvent = $this->getPost($aEvent, $aParams);
- if(empty($sEvent))
- continue;
- if($bReturnArray) {
- $mixedEvents[] = $aEvent;
- continue;
- }
- if($bFirst && $bViewTimeline) {
- $mixedEvents .= $this->getDividerToday($aEvent);
- $bFirst = false;
- }
- $mixedEvents .= $bViewTimeline ? $this->getDivider($iDays, $aEvent) : '';
- $mixedEvents .= $sEvent;
- $iEventIndex++;
- if($iExtenalsEvery > 0 && $iEventIndex % $iExtenalsEvery == 0) {
- $sExternalPost = false;
- bx_alert($this->_oConfig->getName(), 'get_external_post', 0, 0, array(
- 'params' => $aParams,
- 'override_result' => &$sExternalPost,
- ));
- if($sExternalPost !== false)
- $mixedEvents .= $sExternalPost;
- }
- }
- if($bReturnArray)
- return $mixedEvents;
- $sContent .= $mixedEvents;
- $bEvents = !empty($mixedEvents);
- $sBack = $this->getBack($aParams);
- $iPerPage = $this->_oConfig->getPerPage();
- $iPreloads = $this->_oConfig->getAutoPreloads();
- if(!$this->_oConfig->isInfiniteScroll() || (($aParams['start'] - $iPerPage * ($iPreloads - 1)) % ($iPerPage * $iPreloads) == 0))
- $sLoadMore = $this->getLoadMore($aParams, $bNext, $iEvents > 0 && $bEvents);
- else
- $sLoadMore = $this->getLoadMoreAuto($aParams, $bNext, $iEvents > 0 && $bEvents);
- $sEmpty = $this->getEmpty($iEvents <= 0 || !$bEvents);
- return array($sContent, $sLoadMore, $sBack, $sEmpty, $iFirst, $bNext);
- }
- public function getEmpty($bVisible)
- {
- return $this->parseHtmlByName('empty.html', array(
- 'style_prefix' => $this->_oConfig->getPrefix('style'),
- 'visible' => $bVisible ? 'block' : 'none',
- 'content' => MsgBox(_t('_bx_timeline_txt_msg_no_results'))
- ));
- }
- public function getDivider(&$iDays, &$aEvent)
- {
- if(!$this->_bShowTimelineDividers || $iDays == $aEvent['days'])
- return '';
- $iDays = $aEvent['days'];
- $iDaysAgo = (int)$aEvent['ago_days'];
- if($aEvent['today'] == $aEvent['days'] || (($aEvent['today'] - $aEvent['days']) == 1 && $iDaysAgo == 0))
- return '';
- return $this->parseHtmlByName('divider.html', array(
- 'style_prefix' => $this->_oConfig->getPrefix('style'),
- 'type' => 'common',
- 'bx_if:show_hidden' => array(
- 'condition' => false,
- 'content' => array()
- ),
- 'content' => bx_time_js($aEvent['date'])
- ));
- }
- public function getDividerToday($aEvent = array())
- {
- if(!$this->_bShowTimelineDividers)
- return '';
- $bToday = !empty($aEvent) && ($aEvent['today'] == $aEvent['days'] || (($aEvent['today'] - $aEvent['days']) == 1 && (int)$aEvent['ago_days'] == 0));
- return $this->parseHtmlByName('divider.html', array(
- 'style_prefix' => $this->_oConfig->getPrefix('style'),
- 'type' => 'today',
- 'bx_if:show_hidden' => array(
- 'condition' => !$bToday,
- 'content' => array()
- ),
- 'content' => _t('_bx_timeline_txt_today')
- ));
- }
- public function getSizer($aParams)
- {
- if($aParams['view'] != BX_TIMELINE_VIEW_OUTLINE)
- return '';
- return $this->parseHtmlByName('sizer_' . $aParams['view'] . '.html', array(
- 'style_prefix' => $this->_oConfig->getPrefix('style')
- ));
- }
- public function getBack($aParams)
- {
- $iYearSel = (int)$aParams['timeline'];
- if($iYearSel == 0)
- return '';
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $sJsObject = $this->_oConfig->getJsObjectView($aParams);
- $iYearNow = date('Y', time());
- return $this->parseHtmlByName('back.html', array(
- 'style_prefix' => $sStylePrefix,
- 'content' => $this->parseLink('javascript:void(0)', _t('_bx_timeline_txt_jump_to_recent'), array(
- 'title' => _t('_bx_timeline_txt_jump_to_n_year', $iYearNow),
- 'onclick' => 'javascript:' . $sJsObject . '.changeTimeline(this, 0)'
- ))
- ));
- }
- public function getLoadMore($aParams, $bEnabled, $bVisible = true)
- {
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $sJsObject = $this->_oConfig->getJsObjectView($aParams);
- $iStart = $aParams['start'];
- $iPerPage = $aParams['per_page'];
- $aTmplVars = array(
- 'style_prefix' => $sStylePrefix,
- 'visible' => ($aParams['view'] == BX_TIMELINE_VIEW_TIMELINE && $bVisible) || ($aParams['view'] == BX_TIMELINE_VIEW_OUTLINE && $bEnabled && $bVisible) ? 'block' : 'none',
- 'bx_if:is_disabled' => array(
- 'condition' => !$bEnabled,
- 'content' => array()
- ),
- 'bx_if:show_on_click' => array(
- 'condition' => $bEnabled,
- 'content' => array(
- 'on_click' => 'javascript:' . $sJsObject . '.changePage(this, ' . ($iStart + $iPerPage) . ', ' . $iPerPage . ')'
- )
- ),
- 'bx_if:show_jump_to' => array(
- 'condition' => $this->_oConfig->isJumpTo(),
- 'content' => array(
- 'style_prefix' => $sStylePrefix,
- 'content' => $this->getJumpTo($aParams)
- )
- )
- );
- return $this->parseHtmlByName('load_more.html', $aTmplVars);
- }
- public function getLoadMoreAuto($aParams, $bEnabled, $bVisible = true)
- {
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- return $this->parseHtmlByName('load_more_auto.html', array(
- 'style_prefix' => $sStylePrefix,
- 'visible' => ($aParams['view'] == BX_TIMELINE_VIEW_TIMELINE && $bVisible) || ($aParams['view'] == BX_TIMELINE_VIEW_OUTLINE && $bEnabled && $bVisible) ? 'block' : 'none',
- 'loading' => _t('_bx_timeline_txt_loading' . ($bEnabled ? '' : '_complete'))
- ));
- }
- /**
- * Note. For now both List and Caledar based Jump To elements are available.
- * Calendar based element is used by default. List based one can be removed
- * later if it won't be used completely.
- */
- public function getJumpTo($aParams)
- {
- if(!$this->_oConfig->isJumpTo())
- return '';
- $bList = false;
- $bDynamicMode = isset($aParams['dynamic_mode']) && (bool)$aParams['dynamic_mode'] === true;
- if($bList && !$bDynamicMode)
- return '';
- return $this->{'_getJumpTo' . ($bList ? 'List' : 'Caledar')}($aParams);
- }
- public function getComments($sSystem, $iId, $aBrowseParams = array())
- {
- $oModule = $this->getModule();
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $oCmts = $oModule->getCmtsObject($sSystem, $iId);
- if($oCmts === false)
- return '';
- if (bx_is_api()){
- $aParams = ['mode' => 'feed', 'order_way' => 'desc', 'start_from' => 0];
- return [bx_srv('system', 'get_comments_api', [$oCmts, $aParams], 'TemplCmtsServices')];
- }
-
- $aCmtsBp = array();
- if(!empty($aBrowseParams['cmts_preload_number']))
- $aCmtsBp['init_view'] = $aBrowseParams['cmts_preload_number'];
- $aCmtsDp = array(
- 'in_designbox' => false,
- 'dynamic_mode' => isset($aBrowseParams['dynamic_mode']) && $aBrowseParams['dynamic_mode'] === true
- );
- if(!empty($aBrowseParams['cmts_min_post_form']))
- $aCmtsDp['min_post_form'] = $aBrowseParams['cmts_min_post_form'];
- $aComments = $oCmts->getCommentsBlock($aCmtsBp, $aCmtsDp);
- if(empty($aComments) || !is_array($aComments))
- return '';
- return $this->parseHtmlByName('comments.html', array(
- 'style_prefix' => $sStylePrefix,
- 'id' => $iId,
- 'content' => $aComments['content']
- ));
- }
- public function getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams = [])
- {
- $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
- if(empty($aReposted) || !is_array($aReposted))
- return '';
- $oModule = $this->getModule();
- $bDisabled = $oModule->isAllowedRepost($aReposted) !== true || $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $oModule->getUserId());
- if($bDisabled && (int)$aReposted['reposts'] == 0)
- return '';
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $sStylePrefixRepost = $sStylePrefix . '-repost-';
- $sDo = isset($aParams['do']) ? $aParams['do'] : 'repost';
- $bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'] === true;
- $bShowDoRepostAsButtonSmall = isset($aParams['show_do_repost_as_button_small']) && $aParams['show_do_repost_as_button_small'] == true;
- $bShowDoRepostAsButton = !$bShowDoRepostAsButtonSmall && isset($aParams['show_do_repost_as_button']) && $aParams['show_do_repost_as_button'] == true;
- $bShowDoRepostIcon = isset($aParams['show_do_repost_icon']) && $aParams['show_do_repost_icon'] == true && !empty($aParams['icon_do_repost']);
- $bShowDoRepostText = isset($aParams['show_do_repost_text']) && $aParams['show_do_repost_text'] == true && !empty($aParams['text_do_repost']);
- $bShowCounter = isset($aParams['show_counter']) && $aParams['show_counter'] === true;
- //--- Do repost link ---//
- $sClass = $sStylePrefixRepost . 'do-repost';
- if($bShowDoRepostAsButton)
- $sClass .= ' bx-btn';
- else if($bShowDoRepostAsButtonSmall)
- $sClass .= ' bx-btn bx-btn-small';
- $sOnClick = '';
- if(!$bDisabled) {
- $sMethod = '_get' . bx_gen_method_name($sDo) . 'JsClick';
- if(!method_exists($this, $sMethod))
- $sMethod = '_getRepostJsClick';
- $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
- if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
- $aRepostedData = unserialize($aReposted['content']);
- $sOnClick = $this->$sMethod($iOwnerId, $aRepostedData['type'], $aRepostedData['action'], $aRepostedData['object_id']);
- }
- else
- $sOnClick = $this->$sMethod($iOwnerId, $sType, $sAction, $iObjectId);
- }
- else
- $sClass .= $bShowDoRepostAsButton || $bShowDoRepostAsButtonSmall ? ' bx-btn-disabled' : ' ' . $sStylePrefixRepost . 'disabled';
- $aOnClickAttrs = array(
- 'title' => _t('_bx_timeline_txt_do_' . $sDo)
- );
- if(!empty($sClass))
- $aOnClickAttrs['class'] = $sClass;
- if(!empty($sOnClick))
- $aOnClickAttrs['onclick'] = $sOnClick;
- //--- Do repost label ---//
- $sMethodDoRepostLabel = '';
- $sTemplateDoRepostLabel = '';
- if(!empty($aParams['template_do_repost_label'])) {
- $sMethodDoRepostLabel = 'parseHtmlByContent';
- $sTemplateDoRepostLabel = $aParams['template_do_repost_label'];
- }
- else {
- $sMethodDoRepostLabel = 'parseHtmlByName';
- $sTemplateDoRepostLabel = $aParams['template_do_repost_label_name'];
- }
- $sDoRepost = $this->$sMethodDoRepostLabel($sTemplateDoRepostLabel, array(
- 'style_prefix' => $sStylePrefix,
- 'bx_if:show_icon' => array(
- 'condition' => $bShowDoRepostIcon,
- 'content' => array(
- 'style_prefix' => $sStylePrefix,
- 'icon' => $this->getImageAuto($aParams['icon_do_' . $sDo])
- )
- ),
- 'bx_if:show_text' => array(
- 'condition' => $bShowDoRepostText,
- 'content' => array(
- 'style_prefix' => $sStylePrefix,
- 'text' => _t($aParams['text_do_' . $sDo])
- )
- )
- ));
- return $this->parseHtmlByName('repost_element_block.html', array(
- 'style_prefix' => $sStylePrefix,
- 'html_id' => $this->_oConfig->getHtmlIds('repost', 'main') . $aReposted['id'],
- 'class' => ($bShowDoRepostAsButton ? $sStylePrefixRepost . 'button' : '') . ($bShowDoRepostAsButtonSmall ? $sStylePrefixRepost . 'button-small' : ''),
- 'count' => $aReposted['reposts'],
- 'do_repost' => $this->parseLink('javascript:void(0)', $sDoRepost, $aOnClickAttrs),
- 'bx_if:show_counter' => array(
- 'condition' => $bShowCounter,
- 'content' => array(
- 'style_prefix' => $sStylePrefix,
- 'bx_if:show_hidden' => array(
- 'condition' => (int)$aReposted['reposts'] == 0,
- 'content' => array()
- ),
- 'counter' => $this->getRepostCounter($aReposted, array_merge($aParams, ['show_script' => false]))
- )
- ),
- 'script' => $this->getRepostJsScript($bDynamicMode)
- ));
- }
- public function getRepostCounter($aEvent, $aParams = [])
- {
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $sJsObject = $this->_oConfig->getJsObject('repost');
- $bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'] === true;
- $bShowDoRepostAsButtonSmall = isset($aParams['show_do_repost_as_button_small']) && $aParams['show_do_repost_as_button_small'] == true;
- $bShowDoRepostAsButton = !$bShowDoRepostAsButtonSmall && isset($aParams['show_do_repost_as_button']) && $aParams['show_do_repost_as_button'] == true;
- $bShowScript = !isset($aParams['show_script']) || (bool)$aParams['show_script'] === true;
- $sClass = $sStylePrefix . '-repost-counter';
- if($bShowDoRepostAsButtonSmall)
- $sClass .= ' bx-btn-small-height';
- if($bShowDoRepostAsButton)
- $sClass .= ' bx-btn-height';
- return $this->parseHtmlByName('repost_counter.html', [
- 'class' => $sClass,
- 'bx_repeat:attrs' => [
- ['key' => 'id', 'value' => $this->_oConfig->getHtmlIds('repost', 'counter') . $aEvent['id']],
- ['key' => 'title', 'value' => _t('_bx_timeline_txt_reposted_by')],
- ['key' => 'href', 'value' => 'javascript:void(0)'],
- ['key' => 'onclick', 'value' => 'javascript:' . $sJsObject . '.toggleByPopup(this, ' . $aEvent['id'] . ')']
- ],
- 'content' => !empty($aEvent['reposts']) && (int)$aEvent['reposts'] > 0 ? $this->getRepostCounterLabel($aEvent['reposts'], $aParams) : '',
- 'script' => $bShowScript ? $this->getRepostJsScript($bDynamicMode) : ''
- ]);
- }
- public function getRepostCounterLabel($iCount, $aParams = [])
- {
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- return $this->parseHtmlByName('repost_counter_label.html', [
- 'style_prefix' => $sStylePrefix,
- 'bx_if:show_icon' => array(
- 'condition' => !isset($aParams['show_counter_label_icon']) || (bool)$aParams['show_counter_label_icon'] === true,
- 'content' => array(
- 'style_prefix' => $sStylePrefix,
- 'icon' => $this->_getCounterIcon($aParams),
- )
- ),
- 'bx_if:show_text' => array(
- 'condition' => !isset($aParams['show_counter_label_text']) || (bool)$aParams['show_counter_label_text'] === true,
- 'content' => array(
- 'style_prefix' => $sStylePrefix,
- 'text' => $this->_getCounterLabel($iCount, $aParams)
- )
- )
- ]);
- }
- public function getRepostedBy($iId)
- {
- $aTmplUsers = array();
- $oModule = $this->getModule();
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $aUserIds = $this->_oDb->getRepostedBy($iId);
- foreach($aUserIds as $iUserId)
- $aTmplUsers[] = array(
- 'style_prefix' => $sStylePrefix,
- 'user_unit' => $oModule->getObjectUser($iUserId)->getUnit()
- );
- bx_alert($this->_oConfig->getName(), 'get_reposted_by', 0, 0, array(
- 'content_id' => $iId,
- 'user_ids' => $aUserIds,
- 'users' => &$aTmplUsers
- ));
-
- if(empty($aTmplUsers))
- $aTmplUsers = MsgBox(_t('_Empty'));
- return $this->parseHtmlByName('repost_by_list.html', array(
- 'style_prefix' => $sStylePrefix,
- 'bx_repeat:list' => $aTmplUsers
- ));
- }
- public function getRepostWith($oForm)
- {
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $sJsObject = $this->_oConfig->getJsObject('repost');
- return $this->parseHtmlByName('repost_with_popup.html', array(
- 'style_prefix' => $sStylePrefix,
- 'js_object' => $sJsObject,
- 'form' => $oForm->getCode(),
- 'form_id' => $oForm->getId()
- ));
- }
- public function getRepostWithFieldReposted($oForm, $aInput)
- {
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $aBrowseParams = $this->getModule()->getParams();
- $aReposted = $oForm->getReposted();
- $sReposted = $this->getPost($aReposted, $aBrowseParams);
- $sContent = '';
- if(!empty($sReposted))
- $sContent = $this->_getContent($aReposted['content_type'], $aReposted, $aBrowseParams);
- else
- $sContent = MsgBox(_t('_Empty'));
- return $this->parseHtmlByName('repost_with_reposted.html', array(
- 'style_prefix' => $sStylePrefix,
- 'content' => $sContent
- ));
- }
- public function getRepostTo($oForm)
- {
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $sJsObject = $this->_oConfig->getJsObject('repost');
- return $this->parseHtmlByName('repost_to_popup.html', array(
- 'style_prefix' => $sStylePrefix,
- 'js_object' => $sJsObject,
- 'form' => $oForm->getCode(),
- 'form_id' => $oForm->getId()
- ));
- }
- public function getRepostToFieldList($oForm, $aInput)
- {
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
- if(!$oConnection)
- return '';
- $iProfileId = bx_get_logged_profile_id();
- $aConnectedIds = $oConnection->getConnectedContent($iProfileId);
- $aSelected = array();
- $aTmplVarsModules = array();
- if(!empty($aConnectedIds) && is_array($aConnectedIds)) {
- $aCheckbox = $aInput;
- $aCheckbox['type'] = 'checkbox';
- $aCheckbox['name'] .= '[]';
- foreach($aConnectedIds as $iConnectedId) {
- $oProfile = BxDolProfile::getInstanceMagic($iConnectedId);
- if(!$oProfile)
- continue;
- $sProfileModule = $oProfile->getModule();
- if(!isset($aTmplVarsModules[$sProfileModule]))
- $aTmplVarsModules[$sProfileModule] = array(
- 'style_prefix' => $sStylePrefix,
- 'title' => _t('_' . $sProfileModule),
- 'bx_repeat:contexts' => array()
- );
-
- $aCheckbox['value'] = $iConnectedId;
- $aCheckbox['checked'] = in_array($iConnectedId, $aSelected) ? 1 : 0;
- $aTmplVarsModules[$sProfileModule]['bx_repeat:contexts'][] = array(
- 'style_prefix' => $sStylePrefix,
- 'checkbox' => $oForm->genInput($aCheckbox),
- 'unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_cover'))
- );
- }
- }
- return $this->parseHtmlByName('repost_to_list.html', array(
- 'style_prefix' => $sStylePrefix,
- 'bx_repeat:modules' => !empty($aTmplVarsModules)? array_values($aTmplVarsModules) : MsgBox(_t('_Empty'))
- ));
- }
- public function getRepostJsScript($bDynamicMode = false)
- {
- $sCode = $this->getJsCode('repost', array(), array('mask' => '{object} = new {class}({params});', 'wrap' => false));
- if($bDynamicMode) {
- $sJsObject = $this->_oConfig->getJsObject('repost');
- $sCode = "var " . $sJsObject . " = null;
- $.getScript('" . bx_js_string($this->getJsUrl('main.js'), BX_ESCAPE_STR_APOS) . "', function(data, textStatus, jqxhr) {
- $.getScript('" . bx_js_string($this->getJsUrl('repost.js'), BX_ESCAPE_STR_APOS) . "', function(data, textStatus, jqxhr) {
- bx_get_style('" . bx_js_string($this->getCssUrl('repost.css'), BX_ESCAPE_STR_APOS) . "');
- " . $sCode . "
- });
- }); ";
- }
- else {
- $sCode = "var " . $sCode;
- $this->addCss(array('repost.css'));
- $this->addJs(array('main.js', 'repost.js'));
- }
- return $this->_wrapInTagJsCode($sCode);
- }
- public function getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
- {
- $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
- if(empty($aReposted) || !is_array($aReposted))
- return '';
- $sResult = '';
- $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
- if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
- $aRepostedData = unserialize($aReposted['content']);
- $sResult = $this->_getRepostJsClick($iOwnerId, $aRepostedData['type'], $aRepostedData['action'], $aRepostedData['object_id']);
- }
- else
- $sResult = $this->_getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
- return $sResult;
- }
- public function getRepostWithJsClick($iReposterId, $sType, $sAction, $iObjectId)
- {
- $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
- if(empty($aReposted) || !is_array($aReposted))
- return '';
- $sResult = '';
- $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
- if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
- $aRepostedData = unserialize($aReposted['content']);
- $sResult = $this->_getRepostWithJsClick($iReposterId, $aRepostedData['type'], $aRepostedData['action'], $aRepostedData['object_id']);
- }
- else
- $sResult = $this->_getRepostWithJsClick($iReposterId, $sType, $sAction, $iObjectId);
- return $sResult;
- }
- public function getRepostToJsClick($iReposterId, $sType, $sAction, $iObjectId)
- {
- $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
- if(empty($aReposted) || !is_array($aReposted))
- return '';
- $sResult = '';
- $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
- if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
- $aRepostedData = unserialize($aReposted['content']);
- $sResult = $this->_getRepostToJsClick($iReposterId, $aRepostedData['type'], $aRepostedData['action'], $aRepostedData['object_id']);
- }
- else
- $sResult = $this->_getRepostToJsClick($iReposterId, $sType, $sAction, $iObjectId);
- return $sResult;
- }
- public function getAttachLinkForm($iEventId = 0)
- {
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $sJsObject = $this->_oConfig->getJsObject('post');
- $aForm = $this->getModule()->getFormAttachLink($iEventId);
- return $this->parseHtmlByName('attach_link_form.html', array(
- 'style_prefix' => $sStylePrefix,
- 'js_object' => $sJsObject,
- 'form_id' => $aForm['form_id'],
- 'form' => $aForm['form'],
- ));
- }
- public function getAttachLinkField($iUserId, $iEventId = 0)
- {
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- if(!$iEventId)
- $aLinks = $this->_oDb->getUnusedLinks($iUserId);
- else
- $aLinks = $this->_oDb->getLinks($iEventId);
- $sLinks = '';
- foreach($aLinks as $aLink)
- $sLinks .= $this->getAttachLinkItem($iUserId, $aLink);
- return $this->parseHtmlByName('attach_link_form_field.html', array(
- 'html_id' => $this->_oConfig->getHtmlIds('post', 'attach_link_form_field') . $iEventId,
- 'style_prefix' => $sStylePrefix,
- 'links' => $sLinks
- ));
- }
- public function getAttachLinkItem($iUserId, $mixedLink)
- {
- $aLink = is_array($mixedLink) ? $mixedLink : $this->_oDb->getLinksBy(array('type' => 'id', 'id' => (int)$mixedLink, 'profile_id' => $iUserId));
- if(empty($aLink) || !is_array($aLink))
- return '';
- $sLinkIdPrefix = $this->_oConfig->getHtmlIds('post', 'attach_link_item');
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $sClass = $sStylePrefix . '-al-item';
- $sJsObject = $this->_oConfig->getJsObject('post');
- $oEmbed = BxDolEmbed::getObjectInstance();
- $bEmbed = $oEmbed !== false;
- $sThumbnail = '';
- $aLinkAttrs = array();
- if(!$bEmbed) {
- $aLinkAttrs = array(
- 'title' => bx_html_attribute($aLink['title'])
- );
- if(!$this->_oConfig->isEqualUrls(BX_DOL_URL_ROOT, $aLink['url'])) {
- $aLinkAttrs['target'] = '_blank';
-
- if($this->_oDb->getParam('sys_add_nofollow') == 'on')
- $aLinkAttrs['rel'] = 'nofollow';
- }
- if((int)$aLink['media_id'] != 0)
- $sThumbnail = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_preview'))->getFileUrl($aLink['media_id']);
- }
- else
- $sClass .= ' embed';
- return $this->parseHtmlByName('attach_link_item.html', array(
- 'html_id' => $sLinkIdPrefix . $aLink['id'],
- 'style_prefix' => $sStylePrefix,
- 'class' => $sClass,
- 'js_object' => $sJsObject,
- 'id' => $aLink['id'],
- 'bx_if:show_embed_outer' => array(
- 'condition' => $bEmbed,
- 'content' => array(
- 'style_prefix' => $sStylePrefix,
- 'embed' => $bEmbed ? $oEmbed->getLinkHTML($aLink['url'], $aLink['title'], 300) : '',
- )
- ),
- 'bx_if:show_embed_inner' => array(
- 'condition' => !$bEmbed,
- 'content' => array(
- 'style_prefix' => $sStylePrefix,
- 'bx_if:show_thumbnail' => array(
- 'condition' => !empty($sThumbnail),
- 'content' => array(
- 'style_prefix' => $sStylePrefix,
- 'thumbnail' => $sThumbnail
- )
- ),
- 'url' => $aLink['url'],
- 'link' => $this->parseLink($aLink['url'], $aLink['title'], $aLinkAttrs)
- )
- ),
- ));
- }
- public function getData(&$aEvent, $aBrowseParams = array())
- {
- $aResult = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $this->_getSystemData($aEvent, $aBrowseParams) : $this->_getCommonData($aEvent, $aBrowseParams);
- if(empty($aResult) || empty($aResult['object_owner_id']) || empty($aResult['content']))
- return false;
- $sSample = !empty($aResult['sample']) ? $aResult['sample'] : '_bx_timeline_txt_sample';
- $aUpdate = array(
- 'object_owner_id' => $aResult['object_owner_id']
- );
- //--- Update Title if empty.
- if(empty($aEvent['title'])) {
- $sTitle = !empty($aResult['title']) ? $this->_oConfig->getTitle($aResult['title']) : _t($sSample);
- $aUpdate['title'] = bx_process_input(strip_tags($sTitle));
- }
- //--- Update Description if empty.
- if(empty($aEvent['description'])) {
- $sUserName = $this->getModule()->getObjectUser($aResult['object_owner_id'])->getDisplayName();
- $sDescription = !empty($aResult['description']) ? $aResult['description'] : _t('_bx_timeline_txt_user_added_sample', $sUserName, _t($sSample));
- if($sDescription == '' && !empty($aResult['content']['text']))
- $sDescription = $aResult['content']['text'];
- $aUpdate['description'] = bx_process_input(strip_tags($sDescription));
- }
- if(!empty($aUpdate) && is_array($aUpdate))
- $this->_oDb->updateEvent($aUpdate, array('id' => $aEvent['id']));
- return $aResult;
- }
- public function getDataCached($aEvent, $aBrowseParams = array())
- {
- if(!$this->_oConfig->isCacheItem() || bx_is_api())
- return $this->getData($aEvent, $aBrowseParams);
- /**
- * For now parameters from $aBrowseParams array aren't used during data retrieving.
- * If they will then the cache should be created depending on their values.
- */
- $sCacheKey = $this->_oConfig->getCacheItemKey($aEvent['id']);
- $iCacheLifetime = $this->_oConfig->getCacheItemLifetime();
- $oCache = $this->getModule()->getCacheItemObject();
- $aCached = $oCache->getData($sCacheKey, $iCacheLifetime);
- if(!empty($aCached))
- return unserialize($aCached);
- $aBrowseParams['dynamic_mode'] = true;
- $aResult = $this->getData($aEvent, $aBrowseParams);
- if(empty($aResult) || (isset($aResult['_cache']) && (bool)$aResult['_cache'] === false))
- return $aResult;
- $oCache->setData($sCacheKey, serialize($aResult), $iCacheLifetime);
- return $aResult;
- }
- public function getVideo($aEvent, $aVideo)
- {
- $sVideoId = $this->_oConfig->getHtmlIds('view', 'video') . $aEvent['id'] . '-' . $aVideo['id'];
- $oPlayer = BxDolPlayer::getObjectInstance();
- if (!$oPlayer)
- return '';
- $sPlayer = $oPlayer->getCodeVideo (BX_PLAYER_EMBED, array(
- 'poster' => $aVideo['src_poster'],
- 'mp4' => array('sd' => $aVideo['src_mp4'], 'hd' => $aVideo['src_mp4_hd']),
- 'attrs' => array('id' => $sVideoId),
- ));
- return $this->parseHtmlByName('video_player.html', array(
- 'player' => $sPlayer,
- 'html_id' => $sVideoId
- ));
- }
- /*
- * Show only one Live Update notification for all new Events.
- */
- function getLiveUpdate($aBrowseParams, $iProfileId, $iCountOld = 0, $iCountNew = 0)
- {
- $oModule = $this->getModule();
- $iCount = (int)$iCountNew - (int)$iCountOld;
- if($iCount < 0)
- return '';
- $aParams = $oModule->getParamsExt($aBrowseParams);
- $aParams['start'] = 0;
- $aParams['per_page'] = 1;
- $aParams['newest'] = true;
- $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
- $aEvents = $this->_oDb->getEvents($aParams);
- if(empty($aEvents) || !is_array($aEvents))
- return '';
- $aEvent = array_shift($aEvents);
- if(empty($aEvent) || !is_array($aEvent))
- return '';
- $sJsObject = $this->_oConfig->getJsObjectView($aParams);
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- return $this->parseHtmlByName('live_update_button.html', array(
- 'style_prefix' => $sStylePrefix,
- 'html_id' => $this->_oConfig->getHtmlIds('view', 'live_update_popup') . $aBrowseParams['type'],
- 'onclick_show' => "javascript:" . $sJsObject . ".goToBtn(this, 'timeline-event-" . $aEvent['id'] . "', '" . $aEvent['id'] . "');",
- ));
- }
- /*
- * Show Live Update notification separately for each new Event. Popup Chain is used here.
- *
- * Note. This way to display live update notifications isn't used for now.
- * See BxTimelineTemplate::getLiveUpdate method instead.
- */
- function getLiveUpdates($aBrowseParams, $iProfileId, $iCountOld = 0, $iCountNew = 0)
- {
- $bShowAll = true;
- $bShowActions = false;
- $oModule = $this->getModule();
- $iCount = (int)$iCountNew - (int)$iCountOld;
- if($iCount < 0)
- return '';
- $iCountMax = $this->_oConfig->getLiveUpdateLength();
- if($iCount > $iCountMax)
- $iCount = $iCountMax;
- $aParams = $oModule->getParamsExt($aBrowseParams);
- $aParams['start'] = 0;
- $aParams['per_page'] = $iCount;
- $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
- $aEvents = $this->_oDb->getEvents($aParams);
- if(empty($aEvents) || !is_array($aEvents))
- return '';
- $sJsObject = $this->_oConfig->getJsObjectView($aParams);
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $iUserId = $oModule->getUserId();
- $bModerator = $oModule->isModerator();
- $aEvents = array_reverse($aEvents);
- $iEvents = count($aEvents);
- $aTmplVarsItems = array();
- foreach($aEvents as $iIndex => $aEvent) {
- $aData = $this->getDataCached($aEvent);
- if($aData === false)
- continue;
- $iEventId = $aEvent['id'];
- $iEventAuthorId = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? (int)$aEvent['owner_id'] : (int)$aEvent['object_id'];
- if($iEventAuthorId < 0) {
- if(abs($iEventAuthorId) == $iUserId)
- continue;
- else if($bModerator)
- $iEventAuthorId *= -1;
- }
- $oAuthor = $oModule->getObjectUser($iEventAuthorId);
- $sAuthorName = $oAuthor->getDisplayName();
- $aTmplVarsItems[] = array(
- 'bx_if:show_as_hidden' => array(
- 'condition' => !$bShowAll && $iIndex < ($iEvents - 1),
- 'content' => array(),
- ),
- 'item' => $this->parseHtmlByName('live_update_notification.html', array(
- 'style_prefix' => $sStylePrefix,
- 'onclick_show' => "javascript:" . $sJsObject . ".goTo(this, 'timeline-event-" . $iEventId . "', '" . $iEventId . "');",
- 'author_link' => $oAuthor->getUrl(),
- 'author_title' => bx_html_attribute($sAuthorName),
- 'author_name' => $sAuthorName,
- 'author_unit' => $oAuthor->getUnit(0, array('template' => 'unit_wo_info_links')),
- 'text' => _t($aData['sample_action'], _t($aData['sample'])),
- )),
- 'bx_if:show_previous' => array(
- 'condition' => $bShowActions && $iIndex > 0,
- 'content' => array(
- 'onclick_previous' => $sJsObject . '.previousLiveUpdate(this)'
- )
- ),
- 'bx_if:show_close' => array(
- 'condition' => $bShowActions,
- 'content' => array(
- 'onclick_close' => $sJsObject . '.hideLiveUpdate(this)'
- )
- )
- );
- }
- return $this->parseHtmlByName('popup_chain.html', array(
- 'html_id' => $this->_oConfig->getHtmlIds('view', 'live_update_popup') . $aBrowseParams['type'],
- 'bx_repeat:items' => $aTmplVarsItems
- ));
- }
- protected function _getPost($sType, $aEvent, $aBrowseParams = array())
- {
- $CNF = &$this->_oConfig->CNF;
- $oModule = $this->getModule();
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $sJsObject = $this->_oConfig->getJsObjectView($aBrowseParams);
- $bViewItem = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_ITEM;
- $bViewOutline = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_OUTLINE;
- $oAuthor = $oModule->getObjectUser($aEvent['object_owner_id']);
- $sAuthorName = $oAuthor->getDisplayName();
- $sAuthorUrl = $oAuthor->getUrl();
- $sAuthorUnit = $oAuthor->getUnit(0, array('template' => 'unit_wo_info'));
- $sAuthorBadges = $oAuthor->getBadges();
- $sAuthorAction = '';
- if(!empty($aEvent['sample_action_custom']) && is_array($aEvent['sample_action_custom'])) {
- $aAuthorAction = $aEvent['sample_action_custom'];
- foreach($aAuthorAction['markers'] as $iIndex => $sMarker)
- if(get_mb_substr($sMarker, 0, 1) == '_')
- $aAuthorAction['markers'][$iIndex] = _t($sMarker);
- $sAuthorAction = bx_replace_markers(_t($aAuthorAction['content']), $aAuthorAction['markers']);
- }
- else
- $sAuthorAction = _t($aEvent['sample_action'], _t($aEvent['sample']));
- if(($bViewItem || $this->_oConfig->isCountAllViews()) && !empty($aEvent['views']) && is_array($aEvent['views']) && isset($aEvent['views']['system']))
- $oModule->getViewObject($aEvent['views']['system'], $aEvent['views']['object_id'])->doView();
- $aTmplVarsNote = $this->_getTmplVarsNote($aEvent);
- $aTmplVarsMenuItemCounters = $this->_getTmplVarsMenuItemCounters($aEvent, $aBrowseParams);
- $aTmplVarsMenuItemActions = $this->_getTmplVarsMenuItemActions($aEvent, $aBrowseParams);
- $aTmplVarsMenuItemMeta = $this->_getTmplVarsMenuItemMeta($aEvent, $aBrowseParams);
- $aTmplVarsManage = $this->_getTmplVarsManage($aEvent, $aBrowseParams);
- $aTmplVarsTimelineOwner = $this->_getTmplVarsTimelineOwner($aEvent);
- $bTmplVarsTimelineOwner = !empty($aTmplVarsTimelineOwner);
- $aTmplVarsOwnerActions = $this->_getTmplVarsOwnerActions($aEvent, $aBrowseParams);
- $bTmplVarsOwnerActions = !empty($aTmplVarsOwnerActions);
- $bPinned = $aBrowseParams['type'] == BX_BASE_MOD_NTFS_TYPE_OWNER && (int)$aEvent['pinned'] > 0;
- $bSticked = (int)$aEvent['sticked'] > 0;
- $bPromoted = (int)$aEvent['promoted'] > 0;
- $sClass = $sStylePrefix . '-view-sizer';
- if($bViewOutline) {
- $sClass = $sStylePrefix . '-grid-item-sizer';
- if($bPinned || $bSticked || $bPromoted) {
- $sClass .= ' ' . $sStylePrefix . '-gis';
- if($bPinned)
- $sClass .= '-pnd';
- if($bSticked)
- $sClass .= '-psd';
- if($bPromoted)
- $sClass .= '-pmd';
- }
- }
- $sClass .= ' ' . $aEvent['type'] . (!empty($aEvent['action']) ? ' ' . $aEvent['action'] : '');
- $aAuthorAcl = BxDolAcl::getInstance()->getMemberMembershipInfo($aEvent['object_owner_id']);
- if(!empty($aAuthorAcl) && isset($this->_aAclId2Name[$aAuthorAcl['id']]))
- $sClass .= ' ' . $sStylePrefix . '-aml-' . $this->_aAclId2Name[$aAuthorAcl['id']];
- if(!empty($aBrowseParams['blink']) && in_array($aEvent['id'], $aBrowseParams['blink']))
- $sClass .= ' ' . $sStylePrefix . '-blink';
- if($bPinned)
- $sClass .= ' ' . $sStylePrefix . '-pinned';
- if($bSticked)
- $sClass .= ' ' . $sStylePrefix . '-sticked';
- if($bPromoted)
- $sClass .= ' ' . $sStylePrefix . '-promoted';
- $sClassOwner = $bTmplVarsOwnerActions ? $sStylePrefix . '-io-with-actions' : '';
- $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
- $sLocation = $oMetatags->locationsString($aEvent['id']);
-
- $sFields = '';
- if(!$bViewItem) {
- $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_post'), $this->_oConfig->getObject('form_display_post_view'), $this, $aEvent['id']);
- $oForm->initChecker($aEvent);
- if(!empty($oForm->aInputs) && is_array($oForm->aInputs))
- foreach($oForm->aInputs as $aInput)
- if($aInput['type'] != 'hidden' && !empty($aInput['value'])) {
- $sFields = $oForm->getCode();
- break;
- }
- }
- $sIcon = !empty($aEvent['icon']) ? $aEvent['icon'] : $CNF['ICON'];
- $aTmplVars = array (
- 'style_prefix' => $sStylePrefix,
- 'js_object' => $sJsObject,
- 'html_id' => $this->_oConfig->getHtmlIdView('item', $aBrowseParams, array('whole' => false)) . $aEvent['id'],
- 'class' => $sClass,
- 'class_owner' => $sClassOwner,
- 'class_content' => $bViewItem ? 'bx-def-color-bg-block' : 'bx-def-color-bg-box',
- 'id' => $aEvent['id'],
- 'bx_if:show_note' => array(
- 'condition' => !empty($aTmplVarsNote),
- 'content' => $aTmplVarsNote
- ),
- 'bx_if:show_owner_actions' => array(
- 'condition' => $bTmplVarsOwnerActions,
- 'content' => $aTmplVarsOwnerActions
- ),
- 'item_icon' => $sIcon,
- 'item_owner_url' => $sAuthorUrl,
- 'item_owner_title' => bx_html_attribute($sAuthorName),
- 'item_owner_name' => $sAuthorName .' '. $sAuthorBadges,
- 'item_owner_unit' => $sAuthorUnit,
- 'item_view_url' => $this->_oConfig->getItemViewUrl($aEvent),
- 'item_date' => bx_time_js($aEvent['date']),
- 'bx_if:show_pinned' => array(
- 'condition' => $bPinned,
- 'content' => array(
- 'style_prefix' => $sStylePrefix,
- )
- ),
- 'bx_if:show_sticked' => array(
- 'condition' => $bSticked,
- 'content' => array(
- 'style_prefix' => $sStylePrefix,
- )
- ),
- 'bx_if:show_hot' => array(
- 'condition' => $this->_oConfig->isHotEvent($aEvent['id']),
- 'content' => array(
- 'style_prefix' => $sStylePrefix,
- )
- ),
- 'bx_if:show_manage' => array(
- 'condition' => !empty($aTmplVarsManage),
- 'content' => $aTmplVarsManage
- ),
- 'bx_if:show_item_action' => array(
- 'condition' => $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) || $bTmplVarsTimelineOwner,
- 'content' => array(
- 'style_prefix' => $sStylePrefix,
- 'item_icon' => $sIcon,
- 'item_owner_action' => $sAuthorAction,
- 'bx_if:show_timeline_owner' => array(
- 'condition' => $bTmplVarsTimelineOwner,
- 'content' => $aTmplVarsTimelineOwner
- ),
- )
- ),
- 'content_type' => $sType,
- 'content' => is_string($aEvent['content']) ? $aEvent['content'] : $this->_getContent($sType, $aEvent, $aBrowseParams),
- 'bx_if:show_location' => array(
- 'condition' => !empty($sLocation),
- 'content' => array(
- 'style_prefix' => $sStylePrefix,
- 'location' => $sLocation
- )
- ),
- 'bx_if:show_fields' => array(
- 'condition' => !empty($sFields),
- 'content' => array(
- 'style_prefix' => $sStylePrefix,
- 'fields' => $sFields
- )
- ),
- 'bx_if:show_menu_item_counters' => array(
- 'condition' => !empty($aTmplVarsMenuItemCounters),
- 'content' => $aTmplVarsMenuItemCounters
- ),
- 'bx_if:show_menu_item_actions' => array(
- 'condition' => !empty($aTmplVarsMenuItemActions),
- 'content' => $aTmplVarsMenuItemActions
- ),
- 'bx_if:show_menu_item_meta' => array(
- 'condition' => !empty($aTmplVarsMenuItemMeta),
- 'content' => $aTmplVarsMenuItemMeta
- ),
- 'comments' => '',
- );
- $iPreloadComments = $this->_oConfig->getPreloadComments();
- if($iPreloadComments > 0 && $oModule->isAllowedComment($aEvent) && in_array($aBrowseParams['view'], array(BX_TIMELINE_VIEW_TIMELINE, BX_TIMELINE_VIEW_OUTLINE)))
- $aTmplVars['comments'] = $this->_getComments($aEvent['comments'], array_merge($aBrowseParams, array(
- 'cmts_preload_number' => $iPreloadComments,
- 'cmts_min_post_form' => false
- )));
- $sVariable = '_sTmplContentItem' . bx_gen_method_name($aBrowseParams['view']);
- if(empty(self::$$sVariable))
- self::$$sVariable = $this->getHtml('item_' . $aBrowseParams['view'] . '.html');
- $sTmplCode = self::$$sVariable;
- bx_alert($this->_oConfig->getName(), 'get_post', 0, 0, array(
- 'type' => $sType,
- 'event' => $aEvent,
- 'browse_params' => $aBrowseParams,
- 'tmpl_code' => &$sTmplCode,
- 'tmpl_vars' => &$aTmplVars
- ));
- return $this->parseHtmlByContent($sTmplCode, $aTmplVars);
- }
- protected function _getContent($sType, $aEvent, $aBrowseParams = array())
- {
- $sMethod = '_getTmplVarsContent' . ucfirst($sType);
- if(!method_exists($this, $sMethod))
- return '';
- $aTmplVars = $this->$sMethod($aEvent, $aBrowseParams);
- $sVariable = '_sTmplContentType' . bx_gen_method_name($sType);
- if(empty(self::$$sVariable))
- self::$$sVariable = $this->getHtml('type_' . $sType . '.html');
- $sTmplCode = self::$$sVariable;
- bx_alert($this->_oConfig->getName(), 'get_post_content', 0, 0, array(
- 'type' => $sType,
- 'event' => $aEvent,
- 'browse_params' => $aBrowseParams,
- 'tmpl_code' => &$sTmplCode,
- 'tmpl_vars' => &$aTmplVars
- ));
- return $this->parseHtmlByContent($sTmplCode, $aTmplVars);
- }
- protected function _getComments($aComments, $aBrowseParams = array())
- {
-
- $mixedComments = $this->getModule()->getCommentsData($aComments);
- if($mixedComments === false)
- return '';
- list($sSystem, $iObjectId, $iCount) = $mixedComments;
- return $this->getComments($sSystem, $iObjectId, $aBrowseParams);
- }
- protected function _getShowMore($aParams)
- {
- return $this->parseHtmlByName('show_more.html', array(
- 'style_prefix' => $this->_oConfig->getPrefix('style'),
- 'js_object' => $this->_oConfig->getJsObjectView($aParams),
- ));
- }
- protected function _getImagePopup($aParams)
- {
- $sViewImagePopupId = $this->_oConfig->getHtmlIdView('photo_popup', $aParams);
- $sViewImagePopupContent = $this->parseHtmlByName('popup_image.html', array(
- 'image_url' => ''
- ));
- return BxTemplFunctions::getInstance()->transBox($sViewImagePopupId, $sViewImagePopupContent, true);
- }
- protected function _getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
- {
- $sJsObject = $this->_oConfig->getJsObject('repost');
- $sFormat = "%s.repostItem(this, %d, '%s', '%s', %d);";
- $iOwnerId = !empty($iOwnerId) ? (int)$iOwnerId : $this->getModule()->getUserId(); //--- in whose timeline the content will be reposted
- return sprintf($sFormat, $sJsObject, $iOwnerId, $sType, $sAction, (int)$iObjectId);
- }
- protected function _getRepostWithJsClick($iReposterId, $sType, $sAction, $iObjectId)
- {
- $sJsObject = $this->_oConfig->getJsObject('repost');
- $sFormat = "%s.repostItemWith(this, %d, '%s', '%s', %d);";
- $iReposterId = !empty($iReposterId) ? (int)$iReposterId : $this->getModule()->getUserId();
- return sprintf($sFormat, $sJsObject, $iReposterId, $sType, $sAction, (int)$iObjectId);
- }
- protected function _getRepostToJsClick($iReposterId, $sType, $sAction, $iObjectId)
- {
- $sJsObject = $this->_oConfig->getJsObject('repost');
- $sFormat = "%s.repostItemTo(this, %d, '%s', '%s', %d);";
- $iReposterId = !empty($iReposterId) ? (int)$iReposterId : $this->getModule()->getUserId();
- return sprintf($sFormat, $sJsObject, $iReposterId, $sType, $sAction, (int)$iObjectId);
- }
- protected function _getJumpToList($aParams)
- {
- $iYearSel = (int)$aParams['timeline'];
- $iYearMin = $this->_oDb->getMaxDuration($aParams);
- if(empty($iYearMin))
- return '';
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $sJsObject = $this->_oConfig->getJsObjectView($aParams);
- $aYears = array();
- $iYearMax = date('Y', time()) - 1;
- for($i = $iYearMax; $i >= $iYearMin; $i--) {
- $bCurrent = $i == $iYearSel;
- $aYears[] = array(
- 'style_prefix' => $sStylePrefix,
- 'bx_if:show_link' => array(
- 'condition' => !$bCurrent,
- 'content' => array(
- 'title' => _t('_bx_timeline_txt_jump_to_n_year', $i),
- 'onclick' => 'javascript:' . $sJsObject . '.changeTimeline(this, \'' . $i . '-12-31\')',
- 'content' => $i
- )
- ),
- 'bx_if:show_text' => array(
- 'condition' => $bCurrent,
- 'content' => array(
- 'content' => $i
- )
- ),
- );
- }
- return $this->parseHtmlByName('jump_to.html', array(
- 'bx_if:show_list' => array(
- 'condition' => true,
- 'content' => array(
- 'style_prefix' => $sStylePrefix,
- 'bx_repeat:links' => $aYears,
- )
- ),
- 'bx_if:show_calendar' => array(
- 'condition' => false,
- 'content' => array()
- )
- ));
- }
- protected function _getJumpToCaledar($aParams)
- {
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $sJsObject = $this->_oConfig->getJsObjectView($aParams);
-
- return $this->parseHtmlByName('jump_to.html', array(
- 'bx_if:show_list' => array(
- 'condition' => false,
- 'content' => array()
- ),
- 'bx_if:show_calendar' => array(
- 'condition' => true,
- 'content' => array(
- 'style_prefix' => $sStylePrefix,
- 'onclick' => 'javascript:' . $sJsObject . '.showCalendar(this)',
- )
- )
- ));
- }
- protected function _getTmplVarsMenuItemActions(&$aEvent, $aBrowseParams = array())
- {
- $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_actions_all'));
- if(!$oMenu) {
- $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_actions'));
- if(!$oMenu)
- return array();
- }
- $oMenu->setEvent($aEvent, $aBrowseParams);
- $oMenu->setDynamicMode(isset($aBrowseParams['dynamic_mode']) && $aBrowseParams['dynamic_mode'] === true);
- $sMenu = $oMenu->getCode();
- if(empty($sMenu))
- return array();
- return array(
- 'style_prefix' => $this->_oConfig->getPrefix('style'),
- 'js_object' => $this->_oConfig->getJsObjectView($aBrowseParams),
- 'menu_item_actions' => $sMenu
- );
- }
- protected function _getTmplVarsManage(&$aEvent, $aBrowseParams = array())
- {
- $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_actions_all'));
- if($oMenu)
- return array();
- $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'));
- if(!$oMenu)
- return array();
- $oMenu->setEvent($aEvent, $aBrowseParams);
- $oMenu->setDynamicMode(isset($aBrowseParams['dynamic_mode']) && $aBrowseParams['dynamic_mode'] === true);
- if(!$oMenu->isVisible())
- return array();
- $sOnclick = "bx_menu_popup('bx_timeline_menu_item_manage', this, {'id':'bx_timeline_menu_item_manage_{content_id}'}, {content_id:{content_id}, name:'{name}', view:'{view}', type:'{type}'});";
- $sOnclick = bx_replace_markers($sOnclick, array(
- 'content_id' => (int)$aEvent['id'],
- 'view' => bx_process_output($aBrowseParams['view']),
- 'type' => bx_process_output($aBrowseParams['type']),
- 'name' => bx_process_output($aBrowseParams['name']),
- ));
- return array(
- 'style_prefix' => $this->_oConfig->getPrefix('style'),
- 'onclick' => $sOnclick
- );
- }
- protected function _getTmplVarsMenuItemCounters(&$aEvent, $aBrowseParams = array())
- {
- $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_counters'));
- if(!$oMenu)
- return array();
- $oMenu->setEvent($aEvent, $aBrowseParams);
- $oMenu->setDynamicMode(isset($aBrowseParams['dynamic_mode']) && $aBrowseParams['dynamic_mode'] === true);
- $sMenu = $oMenu->getCode();
- if(empty($sMenu))
- return array();
- return array(
- 'style_prefix' => $this->_oConfig->getPrefix('style'),
- 'js_object' => $this->_oConfig->getJsObjectView($aBrowseParams),
- 'menu_item_counters' => $sMenu
- );
- }
- protected function _getTmplVarsMenuItemMeta(&$aEvent, $aBrowseParams = array())
- {
- $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_meta'));
- if(!$oMenu)
- return array();
- $oMenu->setEvent($aEvent);
- $sMenu = $oMenu->getCode();
- if(empty($sMenu))
- return array();
- return array(
- 'style_prefix' => $this->_oConfig->getPrefix('style'),
- 'meta' => $sMenu
- );
- }
- protected function _getTmplVarsTimelineOwner(&$aEvent)
- {
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $iUser = bx_get_logged_profile_id();
- $oModule = $this->getModule();
- $sConnection = $this->_oConfig->getObject('conn_subscriptions');
- $oConnection = BxDolConnection::getObjectInstance($sConnection);
- $sConnectionTitle = _t('_sys_menu_item_title_sm_subscribe');
- $sKeyOwnerId = isset($aEvent['owner_id_grouped']) ? 'owner_id_grouped' : 'owner_id';
- $aOwnerIds = is_array($aEvent[$sKeyOwnerId]) ? $aEvent[$sKeyOwnerId] : array($aEvent[$sKeyOwnerId]);
- $aTmplVarsOwners = array();
- foreach($aOwnerIds as $iOwnerId) {
- $iOwnerId = (int)$iOwnerId;
- $iObjectOwner = (int)$aEvent['object_owner_id'];
- if($iObjectOwner < 0 && abs($iObjectOwner) == $iUser)
- $iObjectOwner *= -1;
- if($iOwnerId == 0 || $iOwnerId == $iObjectOwner)
- continue;
- $oOwner = $oModule->getObjectUser($iOwnerId);
- $sToType = $oOwner->getModule();
- $sToName = $oOwner->getDisplayName();
- $sToUrl = $oOwner->getUrl();
- $aTmplVarsActions = array();
- if(!empty($iUser) && $iUser != $iOwnerId && $oConnection->checkAllowedConnect($iUser, $iOwnerId) === CHECK_ACTION_RESULT_ALLOWED) {
- $aTmplVarsActions[] = array(
- 'href' => "javascript:void(0)",
- 'onclick' => "bx_conn_action(this, '" . $sConnection . "', 'add', '" . $iOwnerId . "')",
- 'title' => bx_html_attribute($sConnectionTitle),
- 'content' => $sConnectionTitle,
- 'icon' => 'check'
- );
- }
- $aTmplVarsOwners[] = array(
- 'style_prefix' => $sStylePrefix,
- 'owner_type' => _t('_' . $sToType),
- 'owner_url' => $sToUrl,
- 'owner_username' => $sToName,
- 'bx_if:show_timeline_owner_actions' => array(
- 'condition' => !empty($aTmplVarsActions),
- 'content' => array(
- 'style_prefix' => $sStylePrefix,
- 'bx_repeat:timeline_owner_actions' => $aTmplVarsActions
- )
- )
- );
- }
- if(empty($aTmplVarsOwners))
- return array();
- return array(
- 'style_prefix' => $sStylePrefix,
- 'bx_repeat:owners' => $aTmplVarsOwners
- );
- }
- protected function _getTmplVarsContentPost(&$aEvent, $aBrowseParams = array())
- {
- $aContent = &$aEvent['content'];
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $bViewItem = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_ITEM;
- $bViewSearch = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_SEARCH;
- //--- Process Top Raw ---//
- $sTopRaw = isset($aContent['top_raw']) ? $aContent['top_raw'] : '';
- //--- Process Raw ---//
- $sRaw = isset($aContent['raw']) ? $aContent['raw'] : '';
- //--- Process Text ---//
- $sUrl = isset($aContent['url']) ? bx_html_attribute($aContent['url']) : '';
- $sTitle = '';
- if(isset($aContent['title']))
- $sTitle = bx_process_output($aContent['title']);
- if(!empty($sUrl) && !empty($sTitle))
- $sTitle = $this->parseLink($sUrl, $sTitle, array(
- 'class' => $sStylePrefix . '-title bx-lnk-src',
- 'title' => $sTitle
- ));
- $sMethodPrepare = '_prepareTextForOutput';
- if($this->_oConfig->isBriefCards() && !$bViewItem)
- $sMethodPrepare .= 'BriefCard';
- $sText = isset($aContent['text']) ? $aContent['text'] : '';
- $sText = $this->$sMethodPrepare($sText, $aEvent['id']);
- //--- Process Links ---//
- $bAddNofollow = $this->_oDb->getParam('sys_add_nofollow') == 'on';
- $aTmplVarsLinks = [];
- if(!empty($aContent['links']))
- foreach($aContent['links'] as $aLink) {
- $sLink = '';
- $oEmbed = BxDolEmbed::getObjectInstance();
- if ($oEmbed) {
- $sLink = $this->parseHtmlByName('link_embed_provider.html', array(
- 'style_prefix' => $sStylePrefix,
- 'embed' => $oEmbed->getLinkHTML($aLink['url'], $aLink['title']),
- ));
- }
- else {
- $aLinkAttrs = array(
- 'title' => $aLink['title']
- );
- if(!$this->_oConfig->isEqualUrls(BX_DOL_URL_ROOT, $aLink['url'])) {
- $aLinkAttrs['target'] = '_blank';
-
- if($bAddNofollow)
- $aLinkAttrs['rel'] = 'nofollow';
- }
- $sLinkAttrs = '';
- foreach($aLinkAttrs as $sKey => $sValue)
- $sLinkAttrs .= ' ' . $sKey . '="' . bx_html_attribute($sValue) . '"';
- $sLink = $this->parseHtmlByName('link_embed_common.html', array(
- 'bx_if:show_thumbnail' => [
- 'condition' => !empty($aLink['thumbnail']),
- 'content' => [
- 'style_prefix' => $sStylePrefix,
- 'thumbnail' => $aLink['thumbnail'],
- 'link' => !empty($aLink['url']) ? $aLink['url'] : 'javascript:void(0)',
- 'attrs' => $sLinkAttrs
- ]
- ],
- 'link' => !empty($aLink['url']) ? $aLink['url'] : 'javascript:void(0)',
- 'attrs' => $sLinkAttrs,
- 'content' => $aLink['title'],
- 'bx_if:show_text' => [
- 'condition' => !empty($aLink['text']),
- 'content' => [
- 'style_prefix' => $sStylePrefix,
- 'text' => $aLink['text']
- ]
- ]
- ));
- }
- $aTmplVarsLinks[] = [
- 'style_prefix' => $sStylePrefix,
- 'link' => $sLink
- ];
- }
- /*
- * View Item page and Snippet in Search Results should use Gallery layout.
- */
- $sAttachmentsLayout = $this->_oConfig->getAttachmentsLayout();
- if($bViewItem || $bViewSearch)
- $sAttachmentsLayout = BX_TIMELINE_ML_GALLERY;
- $iAttachmentsTotal = 0;
- $aTmplVarsImages = $aTmplVarsVideos = $aTmplVarsFiles = $aTmplVarsAttachments = $aTmplVarsAttachmentsFiles = array();
- //--- Process Photos ---//
- $bImages = !empty($aContent['images']) && is_array($aContent['images']);
- if($bImages) {
- $aImages = $this->_getTmplVarsImages($aContent['images'], true, $aEvent, $aBrowseParams);
- if(!empty($aImages))
- $aTmplVarsImages = array(
- 'style_prefix' => $sStylePrefix,
- 'display' => $aImages['display'],
- 'bx_repeat:items' => $aImages['items']
- );
- }
- $bImagesAttach = !empty($aContent['images_attach']) && is_array($aContent['images_attach']);
- if($bImagesAttach) {
- $aImagesAttach = $this->_getTmplVarsImages($aContent['images_attach'], ['layout' => $sAttachmentsLayout, 'first' => empty($aTmplVarsAttachments)], $aEvent, $aBrowseParams);
- if(!empty($aImagesAttach)) {
- $iAttachmentsTotal += $aImagesAttach['total'];
- $aTmplVarsAttachments = array_merge($aTmplVarsAttachments, $aImagesAttach['items']);
- }
- }
- //--- Add Meta Image when Item is viewed on a separate page ---//
- if($bViewItem) {
- $sMetaImageSrc = '';
- if($bImages && !empty($aContent['images'][0]['src']))
- $sMetaImageSrc = $aContent['images'][0]['src'];
- else if($bImagesAttach && !empty($aContent['images_attach'][0]['src']))
- $sMetaImageSrc = $aContent['images_attach'][0]['src'];
- if(!empty($sMetaImageSrc))
- BxDolTemplate::getInstance()->addPageMetaImage($sMetaImageSrc);
- }
- //--- Process Videos ---//
- $bVideos = !empty($aContent['videos']) && is_array($aContent['videos']);
- if($bVideos) {
- $aVideos = $this->_getTmplVarsVideos($aContent['videos'], true, $aEvent, $aBrowseParams);
- if(!empty($aVideos))
- $aTmplVarsVideos = [
- 'style_prefix' => $sStylePrefix,
- 'display' => $aVideos['display'],
- 'bx_repeat:items' => $aVideos['items']
- ];
- }
- $bVideosAttach = !empty($aContent['videos_attach']) && is_array($aContent['videos_attach']);
- if($bVideosAttach) {
- $aVideosAttach = $this->_getTmplVarsVideos($aContent['videos_attach'], ['layout' => $sAttachmentsLayout, 'first' => empty($aTmplVarsAttachments)], $aEvent, $aBrowseParams);
- if(!empty($aVideosAttach)) {
- $iAttachmentsTotal += $aVideosAttach['total'];
- $aTmplVarsAttachments = array_merge($aTmplVarsAttachments, $aVideosAttach['items']);
- }
- }
-
- //--- Process Files ---//
- $bFiles = !empty($aContent['files']) && is_array($aContent['files']);
- if($bFiles) {
- $aFiles = $this->_getTmplVarsFiles($aContent['files'], $aEvent, $aBrowseParams);
- if(!empty($aFiles))
- $aTmplVarsFiles = [
- 'style_prefix' => $sStylePrefix,
- 'display' => $aFiles['display'],
- 'bx_repeat:items' => $aFiles['items']
- ];
- }
- $bFilesAttach = !empty($aContent['files_attach']) && is_array($aContent['files_attach']);
- if($bFilesAttach) {
- $aFilesAttach = $this->_getTmplVarsFiles($aContent['files_attach'], $aEvent, $aBrowseParams);
- if(!empty($aFilesAttach)) {
- $aTmplVarsAttachmentsFiles = [
- 'style_prefix' => $sStylePrefix,
- 'display' => BX_TIMELINE_ML_GALLERY,
- 'count' => count($aFilesAttach['items']),
- 'bx_repeat:items' => $aFilesAttach['items']
- ];
- }
- }
- /*
- * Process collected attachments in case of Showcase layout.
- */
- $iAttachmentsShow = 4;
- $iAttachmentsCount = count($aTmplVarsAttachments);
- if($sAttachmentsLayout == BX_TIMELINE_ML_SHOWCASE && $iAttachmentsCount > 0) {
- $aTmplVarsAttachments[0]['class'] .= ' ' . $sStylePrefix . '-ia-first';
- if($iAttachmentsCount > $iAttachmentsShow)
- $aTmplVarsAttachments = array_slice($aTmplVarsAttachments, 0, $iAttachmentsShow);
- if($iAttachmentsTotal > $iAttachmentsShow)
- $aTmplVarsAttachments[$iAttachmentsShow - 1]['item'] .= $this->parseHtmlByName('attach_more.html', [
- 'style_prefix' => $sStylePrefix,
- 'link' => $this->_oConfig->getItemViewUrl($aEvent),
- 'more' => $iAttachmentsTotal - $iAttachmentsShow
- ]);
- }
- return [
- 'style_prefix' => $sStylePrefix,
- 'bx_if:show_title' => [
- 'condition' => !empty($sTitle),
- 'content' => [
- 'style_prefix' => $sStylePrefix,
- 'title' => $sTitle,
- ]
- ],
- 'bx_if:show_content' => [
- 'condition' => !empty($sText),
- 'content' => [
- 'style_prefix' => $sStylePrefix,
- 'item_content' => $sText
- ]
- ],
- 'bx_if:show_top_raw' => [
- 'condition' => !empty($sTopRaw),
- 'content' => [
- 'style_prefix' => $sStylePrefix,
- 'item_content_top_raw' => $sTopRaw
- ]
- ],
- 'bx_if:show_raw' => [
- 'condition' => !empty($sRaw),
- 'content' => [
- 'style_prefix' => $sStylePrefix,
- 'item_content_raw' => $sRaw
- ]
- ],
- 'bx_if:show_links' => [
- 'condition' => !empty($aTmplVarsLinks),
- 'content' => [
- 'style_prefix' => $sStylePrefix,
- 'bx_repeat:links' => $aTmplVarsLinks
- ]
- ],
- 'bx_if:show_images' => [
- 'condition' => !empty($aTmplVarsImages),
- 'content' => $aTmplVarsImages
- ],
- 'bx_if:show_videos' => [
- 'condition' => !empty($aTmplVarsVideos),
- 'content' => $aTmplVarsVideos
- ],
- 'bx_if:show_files' => [
- 'condition' => !empty($aTmplVarsFiles),
- 'content' => $aTmplVarsFiles
- ],
- 'bx_if:show_attachments' => [
- 'condition' => !empty($aTmplVarsAttachments),
- 'content' => [
- 'style_prefix' => $sStylePrefix,
- 'display' => $sAttachmentsLayout,
- 'count' => count($aTmplVarsAttachments),
- 'bx_repeat:items' => $aTmplVarsAttachments
- ]
- ],
- 'bx_if:show_attachments_files' => [
- 'condition' => !empty($aTmplVarsAttachmentsFiles),
- 'content' => $aTmplVarsAttachmentsFiles
- ]
- ];
- }
- protected function _getTmplVarsContentRepost(&$aEvent, $aBrowseParams = array())
- {
- $aContent = &$aEvent['content'];
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $sOwnerLink = $this->parseLink($aContent['owner_url'], $aContent['owner_name']);
- $sSample = _t($aContent['sample']);
- $sSampleLink = empty($aContent['url']) ? $sSample : $this->parseLink($aContent['url'], $sSample);
- $aTmplVarsData = [];
- if(!empty($aContent['rdata']) && is_array($aContent['rdata'])) {
- $aData = $aContent['rdata'];
- $aTmplVarsData['style_prefix'] = $sStylePrefix;
- if(isset($aData['text']))
- $aTmplVarsData['text'] = $this->_prepareTextForOutput($aData['text'], $aEvent['id']);
- }
- $sContent = $this->_getContent($aContent['parse_type'], $aEvent, $aBrowseParams);
- return [
- 'style_prefix' => $sStylePrefix,
- 'item_owner_action' => _t('_bx_timeline_txt_reposted', $sOwnerLink, $sSampleLink),
- 'bx_if:show_data' => [
- 'condition' => !empty($aTmplVarsData),
- 'content' => $aTmplVarsData
- ],
- 'bx_if:show_content' => [
- 'condition' => !empty($sContent),
- 'content' => [
- 'style_prefix' => $sStylePrefix,
- 'content' => $sContent,
- ]
- ]
- ];
- }
- protected function _getTmplVarsNote(&$aEvent)
- {
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $iUser = bx_get_logged_profile_id();
- $iOwner = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $aEvent['owner_id'] : $aEvent['object_id'];
- $aTmplVars = array();
- if(!empty($iOwner) && !is_array($iOwner) && !empty($aEvent['promoted'])) {
- $sConnection = $this->_oConfig->getObject('conn_subscriptions');
- $oConnection = BxDolConnection::getObjectInstance($sConnection);
- if(!$oConnection->isConnected($iUser, $iOwner))
- $aTmplVars[] = [
- 'style_prefix' => $sStylePrefix,
- 'class' => '',
- 'bx_if:show_note_color' => [
- 'condition' => false,
- 'content' => []
- ],
- 'item_note' => _t('_bx_timeline_txt_promoted')
- ];
- }
- //--- Awaiting status related notes.
- if($aEvent['status'] == BX_TIMELINE_STATUS_AWAITING) {
- $sNote = '';
- if((int)$aEvent['published'] > (int)$aEvent['date'])
- $sNote = _t('_bx_timeline_txt_note_scheduled_awaiting', bx_time_js($aEvent['published'], BX_FORMAT_DATE, true));
- else
- $sNote = _t('_bx_timeline_txt_note_processing_awaiting');
- $aTmplVars[] = [
- 'style_prefix' => $sStylePrefix,
- 'bx_if:show_note_color' => [
- 'condition' => true,
- 'content' => [
- 'item_note_color' => 'red3'
- ]
- ],
- 'item_note' => $sNote
- ];
- }
- //--- Failed status related notes.
- if($aEvent['status'] == BX_TIMELINE_STATUS_FAILED)
- $aTmplVars[] = [
- 'style_prefix' => $sStylePrefix,
- 'bx_if:show_note_color' => [
- 'condition' => true,
- 'content' => [
- 'item_note_color' => 'red2'
- ]
- ],
- 'item_note' => _t('_bx_timeline_txt_note_processing_failed')
- ];
- //--- Pending status related notes.
- if($aEvent['status_admin'] == BX_TIMELINE_STATUS_PENDING)
- $aTmplVars[] = [
- 'style_prefix' => $sStylePrefix,
- 'bx_if:show_note_color' => [
- 'condition' => true,
- 'content' => [
- 'item_note_color' => 'red3'
- ]
- ],
- 'item_note' => _t('_bx_timeline_txt_note_approve_pending')
- ];
- return empty($aTmplVars) ? [] : [
- 'style_prefix' => $sStylePrefix,
- 'bx_repeat:notes' => $aTmplVars
- ];
- }
- protected function _getTmplVarsOwnerActions(&$aEvent, $aBrowseParams = array())
- {
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $iUser = bx_get_logged_profile_id();
- $iOwner = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $aEvent['object_owner_id'] : $aEvent['object_id'];
- $aTmplVarsActions = array();
- if(!empty($iUser) && !empty($iOwner) && $iUser != $iOwner) {
- $oOwner = BxDolProfile::getInstance($iOwner);
- if($oOwner !== false && bx_srv($oOwner->getModule(), 'check_allowed_with_content', array('subscribe_add', $oOwner->getContentId())) === CHECK_ACTION_RESULT_ALLOWED) {
- $sJsObject = $this->_oConfig->getJsObjectView($aBrowseParams);
- $sConnection = $this->_oConfig->getObject('conn_subscriptions');
- $sContent = _t('_sys_menu_item_title_sm_subscribe');
- $aTmplVarsActions[] = array(
- 'style_prefix' => $sStylePrefix,
- 'href' => "javascript:void(0)",
- 'onclick' => "bx_conn_action(this, '" . $sConnection . "', 'add', '" . $iOwner . "', false, function(oData, eElement) {" . $sJsObject . ".onConnect(eElement, oData);})",
- 'title' => bx_html_attribute($sContent),
- 'content' => $sContent,
- 'icon' => 'check'
- );
- }
- }
- return array(
- 'style_prefix' => $sStylePrefix,
- 'bx_repeat:owner_actions' => $aTmplVarsActions
- );
- }
- protected function _getTmplVarsImages($aImages, $mixedLayout, &$aEvent, &$aBrowseParams)
- {
- if(empty($aImages) || !is_array($aImages))
- return [];
- $iTotal = 0; //--- Total count of images related to the event.
- if(isset($aImages['total']) && isset($aImages['items'])) {
- $iTotal = (int)$aImages['total'];
- $aImages = $aImages['items'];
- }
- else
- $iTotal = count($aImages);
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $sJsObject = $this->_oConfig->getJsObjectView($aBrowseParams);
- $bViewItem = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_ITEM;
- $sDisplay = '';
- $aTmplVarsImages = [];
- $sImageSrcKey = $sImageSrcKeyBig = '';
- $sImageSrcKeyDefault = 'src';
- if(count($aImages) == 1) {
- $sDisplay = BX_TIMELINE_ML_SINGLE;
- $sImageSrcKey = $bViewItem ? 'src_orig' : 'src_medium';
- }
- else if(is_array($mixedLayout) && !empty($mixedLayout['layout'])) {
- $sDisplay = $mixedLayout['layout'];
- $sImageSrcKey = 'src';
- $sImageSrcKeyBig = 'src_medium';
- }
- else {
- $sDisplay = BX_TIMELINE_ML_GALLERY;
- $sImageSrcKey = 'src';
- $sImageSrcKeyBig = 'src_medium';
- }
- $bAttachFirst = false;
- if($sDisplay == BX_TIMELINE_ML_SHOWCASE)
- $bAttachFirst = isset($mixedLayout['first']) && $mixedLayout['first'] === true;
- $aImageFirst = reset($aImages);
- $iImageFirst = isset($aImageFirst['id']) ? (int)$aImageFirst['id'] : 0;
- $aImageSizes = [
- 'small' => '300w',
- 'medium' => '500w',
- 'orig' => '1200w'
- ];
- foreach($aImages as $aImage) {
- $sImageSrcKeyCur = $sImageSrcKey;
- if(($bAttachFirst && isset($aImage['id']) && (int)$aImage['id'] == $iImageFirst) || $iTotal == 2)
- $sImageSrcKeyCur = $sImageSrcKeyBig;
- if (is_array($aImage))
- $sImageSrc = !empty($aImage[$sImageSrcKeyCur]) ? $aImage[$sImageSrcKeyCur] : $aImage[$sImageSrcKeyDefault];
- if(empty($sImageSrc))
- continue;
- $sImageAttrSrcset = '';
- foreach($aImageSizes as $sSize => $sWidth)
- if(isset($aImage['src_' . $sSize]))
- $sImageAttrSrcset .= $aImage['src_' . $sSize] . ' ' . $sWidth . ', ';
- $sImage = $this->parseImage($sImageSrc, array(
- 'class' => $sStylePrefix . '-item-image',
- 'srcset' => trim($sImageAttrSrcset, ", "),
- 'sizes' => '100%'
- ));
- $aAttrs = array();
- if(isset($aImage['onclick']))
- $aAttrs['onclick'] = $aImage['onclick'];
- else if(!empty($aImage['src_orig']))
- $aAttrs['onclick'] = 'return ' . $sJsObject . '.showItem(this, \'' . $aEvent['id'] . '\', \'photo\', ' . json_encode(array('src' => base64_encode($aImage['src_orig']))) . ')';
- $sImage = $this->parseLinkByName('image_link.html', isset($aImage['url']) ? $aImage['url'] : 'javascript:void(0)', $sImage, $aAttrs);
- $aTmplVarsImages[] = array(
- 'style_prefix' => $sStylePrefix,
- 'class' => '',
- 'item' => $sImage
- );
- }
-
- return array(
- 'display' => $sDisplay,
- 'total' => $iTotal,
- 'items' => $aTmplVarsImages
- );
- }
- protected function _getTmplVarsVideos($aVideos, $mixedLayout, &$aEvent, &$aBrowseParams)
- {
- if(empty($aVideos) || !is_array($aVideos))
- return array();
- $iTotal = 0; //--- Total count of videos related to the event.
- if(isset($aVideos['total']) && isset($aVideos['items'])) {
- $iTotal = (int)$aVideos['total'];
- $aVideos = $aVideos['items'];
- }
- else
- $iTotal = count($aVideos);
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $sJsObject = $this->_oConfig->getJsObjectView($aBrowseParams);
- $aTmplVarsVideos = array();
- /*
- * For now Main Section may have only one video which can use 'autoplay' feature.
- */
- $bMain = $mixedLayout === true;
- if($bMain) {
- $sDisplay = BX_TIMELINE_ML_SINGLE;
- if(count($aVideos) > 1)
- $aVideos = array_slice($aVideos, 0, 1);
- }
- else
- $sDisplay = is_array($mixedLayout) && !empty($mixedLayout['layout']) ? $mixedLayout['layout'] : BX_TIMELINE_AML_DEFAULT;
- /*
- * Main Section: Autoplay feature is only available here.
- */
- $sVap = $sVapId = $sVapSrc = $sVapTmpl = '';
- if($bMain) {
- $sVap = $this->_oConfig->getVideosAutoplay();
- if($sVap != BX_TIMELINE_VAP_OFF) {
- $sVapId = $this->_oConfig->getHtmlIds('view', 'video_iframe') . $aEvent['id'] . '-';
- $sVapSrc = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'video/' . $aEvent['id'] . '/';
- $sVapTmpl = $this->getHtml('video_iframe.html');
- }
- }
- /*
- * Attachments Section.
- */
- $sAttachTmpl = '';
- $bAttachFirst = false;
- if($sDisplay == BX_TIMELINE_ML_SHOWCASE) {
- $sAttachTmpl = $this->getHtml('attach_video_preview.html');
- $bAttachFirst = isset($mixedLayout['first']) && $mixedLayout['first'] === true;
- }
- $iVideoFirst = reset($aVideos)['id'];
- foreach($aVideos as $aVideo) {
- $iVideo = (int)$aVideo['id'];
- if($bMain && $sVap != BX_TIMELINE_VAP_OFF)
- $aTmplVarsVideos[] = array(
- 'style_prefix' => $sStylePrefix,
- 'class' => '',
- 'item' => $this->parseHtmlByContent($sVapTmpl, array(
- 'style_prefix' => $sStylePrefix,
- 'html_id' => $sVapId . $iVideo,
- 'src' => $sVapSrc . $iVideo . '/'
- ))
- );
- else {
- if($bMain || $sDisplay == BX_TIMELINE_ML_GALLERY || ($bAttachFirst && $iVideo == $iVideoFirst)) {
- $sItem = '';
- if(isset($aVideo['src'], $aVideo['src_orig'])) {
- $sItem = $this->parseImage($aVideo['src'], array(
- 'class' => $sStylePrefix . '-item-image'
- ));
- $aAttrs = array();
- if(!empty($aVideo['src_orig']))
- $aAttrs['onclick'] = 'return ' . $sJsObject . '.showItem(this, \'' . $aEvent['id'] . '\', \'video\', ' . json_encode(array('src' => base64_encode($aVideo['src_orig']))) . ')';
- $sItem = $this->parseLinkByName('image_link.html', isset($aVideo['url']) ? $aVideo['url'] : 'javascript:void(0)', $sItem, $aAttrs);
- }
- else
- $sItem = BxTemplFunctions::getInstance()->videoPlayer($aVideo['src_poster'], $aVideo['src_mp4'], $aVideo['src_mp4_hd'], array(
- 'preload' => $this->_oConfig->getVideosPreload(),
- ), '', $aBrowseParams['dynamic_mode']);
- $aTmplVarsVideos[] = array(
- 'style_prefix' => $sStylePrefix,
- 'class' => '',
- 'item' => $sItem
- );
- }
- else {
- $bUrl = !empty($aVideo['url']);
- $sUrl = $bUrl ? $aVideo['url'] : '';
- $sSrc = $aVideo[isset($aVideo['src'], $aVideo['src_orig']) ? 'src' : 'src_poster'];
- $bDuration = !empty($aVideo['duration']);
- $sDuration = _t_format_duration($bDuration ? $aVideo['duration'] : 0);
- $aTmplVarsVideos[] = array(
- 'style_prefix' => $sStylePrefix,
- 'class' => '',
- 'item' => $this->parseHtmlByContent($sAttachTmpl, array(
- 'style_prefix' => $sStylePrefix,
- 'bx_if:show_link' => array(
- 'condition' => $bUrl,
- 'content' => array(
- 'style_prefix' => $sStylePrefix,
- 'url' => $sUrl,
- 'src' => $sSrc,
- )
- ),
- 'bx_if:show_non_link' => array(
- 'condition' => !$bUrl,
- 'content' => array(
- 'style_prefix' => $sStylePrefix,
- 'src' => $sSrc,
- )
- ),
- 'bx_if:show_duration' => array(
- 'condition' => $bDuration,
- 'content' => array(
- 'style_prefix' => $sStylePrefix,
- 'duration' => $sDuration,
- )
- )
- ))
- );
- }
- }
- }
-
- return array(
- 'display' => $sDisplay,
- 'total' => $iTotal,
- 'items' => $aTmplVarsVideos
- );
- }
- protected function _getTmplVarsFiles($aFiles, &$aEvent, &$aBrowseParams)
- {
- if(empty($aFiles) || !is_array($aFiles))
- return array();
- $iTotal = 0; //--- Total count of files related to the event.
- if(isset($aFiles['total']) && isset($aFiles['items'])) {
- $iTotal = (int)$aFiles['total'];
- $aFiles = $aFiles['items'];
- }
- else
- $iTotal = count($aFiles);
- $sStylePrefix = $this->_oConfig->getPrefix('style');
- $sJsObject = $this->_oConfig->getJsObjectView($aBrowseParams);
- $bViewItem = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_ITEM;
- $sDisplay = '';
- $aTmplVarsFiles = array();
- $sFileSrcKey = '';
- $sFileSrcKeyDefault = 'src';
- if(count($aFiles) == 1) {
- $sDisplay = 'single';
- $sFileSrcKey = $bViewItem ? 'src_orig' : 'src_medium';
- }
- else {
- $sDisplay = 'gallery';
- $sFileSrcKey = 'src';
- }
- foreach($aFiles as $aFile) {
- $sFileSrc = !empty($aFile[$sFileSrcKey]) ? $aFile[$sFileSrcKey] : $aFile[$sFileSrcKeyDefault];
- if(empty($sFileSrc))
- continue;
- $aAttrs = ['target' => '_blank'];
- if(isset($aFile['onclick']))
- $aAttrs['onclick'] = $aFile['onclick'];
- else if(!$bViewItem && !empty($aFile['src_orig']))
- $aAttrs['onclick'] = 'return ' . $sJsObject . '.showItem(this, \'' . $aEvent['id'] . '\', \'file\', ' . json_encode(array('src' => base64_encode($aFile['src_orig']))) . ')';
- if(isset($aFile['title']))
- $aAttrs['title'] = $aFile['title'];
- $sAttrs = '';
- foreach($aAttrs as $sKey => $sValue)
- $sAttrs .= ' ' . $sKey . '="' . bx_html_attribute($sValue) . '"';
- $aTmplVarsFiles[] = [
- 'style_prefix' => $sStylePrefix,
- 'class' => '',
- 'item' => $this->parseHtmlByName('file_link.html', [
- 'href' => isset($aFile['url']) ? $aFile['url'] : 'javascript:void(0)',
- 'attrs' => $sAttrs,
- 'icon_src' => $sFileSrc,
- 'icon_class' => $sStylePrefix . '-item-file'
- ])
- ];
- }
- return array(
- 'display' => $sDisplay,
- 'total' => $iTotal,
- 'items' => $aTmplVarsFiles
- );
- }
- protected function _getSystemData(&$aEvent, $aBrowseParams = array())
- {
- $mixedResult = $this->_oConfig->getSystemData($aEvent, $aBrowseParams);
- if($mixedResult === false) {
- $sMethod = 'display' . bx_gen_method_name($aEvent['type'] . '_' . $aEvent['action']);
- if(method_exists($this, $sMethod))
- $mixedResult = $this->$sMethod($aEvent);
- }
- if($mixedResult === false)
- return '';
- $this->_preparetDataActions($aEvent, $mixedResult);
- return $mixedResult;
- }
- protected function _getCommonData(&$aEvent, $aBrowseParams = array())
- {
- $CNF = $this->_oConfig->CNF;
- $oModule = $this->getModule();
- $sJsObject = $this->_oConfig->getJsObjectView($aBrowseParams);
- $sPrefix = $this->_oConfig->getPrefix('common_post');
- $sType = str_replace($sPrefix, '', $aEvent['type']);
- $oObjectOwner = BxDolProfile::getInstanceMagic($aEvent['object_id']);
- $iOwnerId = $aEvent['owner_id'];
- if(is_array($aEvent['owner_id']))
- $iOwnerId = is_numeric($aEvent['object_privacy_view']) && (int)$aEvent['object_privacy_view'] < 0 ? abs((int)$aEvent['object_privacy_view']) : (int)array_shift($aEvent['owner_id']);
- $aResult = array(
- 'owner_id' => $iOwnerId,
- 'object_owner_id' => $aEvent['object_id'],
- 'icon' => $CNF['ICON'],
- 'sample' => '_bx_timeline_txt_sample_with_article',
- 'sample_wo_article' => '_bx_timeline_txt_sample',
- 'sample_action' => '_bx_timeline_txt_added_sample',
- 'content_type' => $sType,
- 'content' => array(
- 'sample' => '_bx_timeline_txt_sample_with_article',
- 'sample_wo_article' => '_bx_timeline_txt_sample',
- 'sample_action' => '_bx_timeline_txt_added_sample',
- 'url' => $this->_oConfig->getItemViewUrl($aEvent)
- ), //a string to display or array to parse default template before displaying.
- 'views' => '',
- 'votes' => '',
- 'reactions' => '',
- 'scores' => '',
- 'reports' => '',
- 'comments' => '',
- 'title' => $aEvent['title'], //may be empty.
- 'description' => bx_replace_markers($aEvent['description'], array(
- 'profile_name' => $oObjectOwner->getDisplayName()
- )) //may be empty.
- );
- switch($sType) {
- case BX_TIMELINE_PARSE_TYPE_POST:
- if(!empty($aEvent['content']))
- $aResult['content'] = array_merge($aResult['content'], unserialize($aEvent['content']));
- $aResult['content']['links'] = $oModule->getEventLinks($aEvent['id']);
- $aResult['content']['images_attach'] = $oModule->getEventImages($aEvent['id']);
- $aResult['content']['videos_attach'] = $oModule->getEventVideos($aEvent['id']);
- $aResult['content']['files_attach'] = $oModule->getEventFiles($aEvent['id']);
- break;
- case BX_TIMELINE_PARSE_TYPE_REPOST:
- if(empty($aEvent['content']))
- return array();
- $aContent = unserialize($aEvent['content']);
- if(!$this->_oConfig->isSystem($aContent['type'] , $aContent['action'])) {
- $aEventReposted = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $aContent['object_id']));
- $aReposted = $this->_getCommonData($aEventReposted, $aBrowseParams);
- }
- else {
- $aEventReposted = $this->_oDb->getEvents(array_merge(array('browse' => 'descriptor'), $aContent));
- $aReposted = $this->_getSystemData($aEventReposted, $aBrowseParams);
- }
- if(empty($aReposted) || !is_array($aReposted))
- return array();
- $aEventReposted['content'] = $aReposted['content'];
- $aResult['content'] = array_merge($aContent, $aReposted['content']);
- $aResult['content']['parse_type'] = !empty($aReposted['content_type']) ? $aReposted['content_type'] : BX_TIMELINE_PARSE_TYPE_DEFAULT;
- $sKey = 'allowed_view';
- $aResult['content'][$sKey] = $this->_preparePrivacy($sKey, $aEventReposted, $aReposted);
- $oObjectOwner = $oModule->getObjectUser($aReposted['object_owner_id']);
- $aResult['content']['owner_id'] = $aReposted['object_owner_id'];
- $aResult['content']['owner_name'] = $oObjectOwner->getDisplayName();
- $aResult['content']['owner_url'] = $oObjectOwner->getUrl();
- if(!empty($aReposted['sample']))
- $aResult['content']['sample'] = $aReposted['sample'];
- if(!empty($aReposted['sample_wo_article']))
- $aResult['content']['sample'] = $aReposted['sample_wo_article'];
- $sUserName = $oModule->getObjectUser($aEvent['object_id'])->getDisplayName();
- $aResult['title'] = _t('_bx_timeline_txt_user_repost', $sUserName, _t($aResult['content']['sample']));
- $aResult['description'] = _t('_bx_timeline_txt_user_reposted_user_sample', $sUserName, $aResult['content']['owner_name'], _t($aResult['content']['sample']));
- $aResult['allowed_view'] = array(
- 'module' => $this->_oConfig->getName(),
- 'method' => 'get_timeline_repost_allowed_view',
- );
- if(!$this->_oConfig->isRepostOwnActions()) {
- $aResult['views'] = $aReposted['views'];
- $aResult['votes'] = $aReposted['votes'];
- $aResult['reactions'] = $aReposted['reactions'];
- $aResult['scores'] = $aReposted['scores'];
- $aResult['reports'] = $aReposted['reports'];
- $aResult['comments'] = $aReposted['comments'];
- }
- break;
- }
- $this->_preparetDataActions($aEvent, $aResult);
- return $aResult;
- }
- protected function _getFirst($aEvents, $aParams = array())
- {
- $CNF = $this->_oConfig->CNF;
- foreach($aEvents as $aEvent)
- if((int)$aEvent[$CNF['FIELD_STICKED']] == 0)
- return (int)$aEvent[$CNF['FIELD_ID']];
- $aParams['start'] += $aParams['per_page'];
- $aEvents = $this->_oDb->getEvents($aParams);
- if(!empty($aEvents) && is_array($aEvents))
- return $this->_getFirst($aEvents, $aParams);
- return 0;
- }
- protected function _preparetDataActions(&$aEvent, &$aResult)
- {
- if(empty($aEvent) || !is_array($aEvent) || empty($aEvent['id']))
- return;
- $oModule = $this->getModule();
- $sSystem = $this->_oConfig->getObject('view');
- if(empty($aResult['views'])) {
- $aResult['views'] = array();
- if($oModule->getViewObject($sSystem, $aEvent['id']) !== false)
- $aResult['views'] = array(
- 'system' => $sSystem,
- 'object_id' => $aEvent['id'],
- 'count' => $aEvent['views']
- );
- }
- $sSystem = $this->_oConfig->getObject('vote');
- if(empty($aResult['votes'])) {
- $aResult['votes'] = array();
- if($oModule->getVoteObject($sSystem, $aEvent['id']) !== false)
- $aResult['votes'] = array(
- 'system' => $sSystem,
- 'object_id' => $aEvent['id'],
- 'count' => $aEvent['votes']
- );
- }
-
- $sSystem = $this->_oConfig->getObject('reaction');
- if(empty($aResult['reactions'])) {
- $aResult['reactions'] = array();
- if($oModule->getReactionObject($sSystem, $aEvent['id']) !== false)
- $aResult['reactions'] = array(
- 'system' => $sSystem,
- 'object_id' => $aEvent['id'],
- 'count' => $aEvent['rvotes']
- );
- }
- $sSystem = $this->_oConfig->getObject('score');
- if(empty($aResult['scores'])) {
- $aResult['scores'] = array();
- if($oModule->getScoreObject($sSystem, $aEvent['id']) !== false)
- $aResult['scores'] = array(
- 'system' => $sSystem,
- 'object_id' => $aEvent['id'],
- 'score' => $aEvent['score']
- );
- }
- $sSystem = $this->_oConfig->getObject('report');
- if(empty($aResult['reports'])) {
- $aResult['reports'] = array();
- if($oModule->getReportObject($sSystem, $aEvent['id']) !== false)
- $aResult['reports'] = array(
- 'system' => $sSystem,
- 'object_id' => $aEvent['id'],
- 'count' => $aEvent['reports']
- );
- }
- $sSystem = $this->_oConfig->getObject('comment');
- if(empty($aResult['comments'])) {
- $aResult['comments'] = array();
- if($oModule->getCmtsObject($sSystem, $aEvent['id']) !== false)
- $aResult['comments'] = array(
- 'system' => $sSystem,
- 'object_id' => $aEvent['id'],
- 'count' => $aEvent['comments']
- );
- }
- }
- protected function _prepareTextForOutputBriefCard($s, $iEventId = 0)
- {
- $s = strip_tags($s, $this->_oConfig->getBriefCardsTags(true));
-
- return $this->_prepareTextForOutput($s, $iEventId = 0);
- }
- protected function _prepareTextForOutput($s, $iEventId = 0)
- {
- $s = bx_process_output($s, BX_DATA_HTML);
- $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
- $s = $oMetatags->metaParse($iEventId, $s);
- return $s;
- }
-
- protected function _preparePrivacy($sKey, $aEvent, $aEventData)
- {
- $iResult = CHECK_ACTION_RESULT_ALLOWED;
- if(isset($aEventData[$sKey], $aEventData[$sKey]['module'], $aEventData[$sKey]['method']))
- $iResult = BxDolService::call($aEventData[$sKey]['module'], $aEventData[$sKey]['method'], array($aEvent));
- else if(($aHandler = $this->_oConfig->getHandler($aEvent)) !== false && BxDolRequest::serviceExists($aHandler['module_name'], 'get_timeline_post_allowed_view'))
- $iResult = BxDolService::call($aHandler['module_name'], 'get_timeline_post_allowed_view', array($aEvent));
- return $iResult;
- }
- protected function _getCounterIcon($aParams = array())
- {
- return $this->parseHtmlByName('repost_counter_icon.html', []);
- }
- protected function _getCounterLabel($iCount, $aParams = array())
- {
- return _t(isset($aParams['caption']) ? $aParams['caption'] : '_bx_timeline_txt_repost_counter', $iCount);
- }
- }
- /** @} */
|