BxTimelineTemplate.php 126 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Timeline Timeline
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxTimelineTemplate extends BxBaseModNotificationsTemplate
  12. {
  13. protected static $_aMemoryCacheItems;
  14. protected static $_aMemoryCacheItemsData;
  15. protected static $_sMemoryCacheItemsKeyMask;
  16. protected static $_sTmplContentItemItem;
  17. protected static $_sTmplContentItemOutline;
  18. protected static $_sTmplContentItemOutlineSample;
  19. protected static $_sTmplContentItemTimeline;
  20. protected static $_sTmplContentItemTimelineSample;
  21. protected static $_sTmplContentItemSearch;
  22. protected static $_sTmplContentTypePost;
  23. protected static $_sTmplContentTypeRepost;
  24. protected $_bShowTimelineDividers;
  25. protected $_aAclId2Name;
  26. function __construct(&$oConfig, &$oDb)
  27. {
  28. parent::__construct($oConfig, $oDb);
  29. $this->_bShowTimelineDividers = false;
  30. $this->_aAclId2Name = array();
  31. bx_import('BxTemplAcl');
  32. $aAclLevels = BxDolAcl::getInstance()->getMemberships(false, false, false);
  33. foreach($aAclLevels as $iAclId => $sAclName)
  34. $this->_aAclId2Name[$iAclId] = str_replace('_', '-', str_replace('_adm_prm_txt_level_', '', $sAclName));
  35. }
  36. public function init()
  37. {
  38. parent::init();
  39. self::$_aMemoryCacheItems = array();
  40. self::$_aMemoryCacheItemsData = array();
  41. self::$_sMemoryCacheItemsKeyMask = "%s_%d";
  42. }
  43. public function getAddedCss($sType = '', $bDynamic = false)
  44. {
  45. $aCss = array();
  46. switch($sType) {
  47. case 'view':
  48. $aCss = array(
  49. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flickity/|flickity.css',
  50. 'cmts.css',
  51. 'view.css',
  52. 'view-media-tablet.css',
  53. 'view-media-desktop.css',
  54. 'repost.css',
  55. );
  56. if($this->_oConfig->isJumpTo()) {
  57. list($aCssCalendar, $aJsCalendar) = BxBaseFormView::getCssJsCalendar();
  58. $aCss = array_merge($aCss, $aCssCalendar);
  59. }
  60. break;
  61. case 'post':
  62. if($this->_oConfig->isEmoji())
  63. $aCss[] = BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'emoji/css/|emoji.css';
  64. $aCss[] = 'post.css';
  65. break;
  66. }
  67. $mixedResult = $this->addCss($aCss, $bDynamic);
  68. if($bDynamic)
  69. return $mixedResult;
  70. }
  71. public function getAddedJs($sType = '', $bDynamic = false)
  72. {
  73. $aJs = array(
  74. 'autosize.min.js',
  75. 'jquery.anim.js',
  76. 'main.js',
  77. );
  78. switch($sType) {
  79. case 'view':
  80. $aJs = array_merge($aJs, array(
  81. 'masonry.pkgd.min.js',
  82. 'flickity/flickity.pkgd.min.js',
  83. 'embedly-player.min.js',
  84. 'BxDolCmts.js',
  85. 'view.js',
  86. 'repost.js',
  87. ));
  88. if ($this->_oConfig->isJumpTo()) {
  89. list($aCssCalendar, $aJsCalendar) = BxBaseFormView::getCssJsCalendar();
  90. $aJs = array_merge($aJs, $aJsCalendar);
  91. }
  92. break;
  93. case 'post':
  94. $aJs = array_merge($aJs, array(
  95. 'jquery.form.min.js',
  96. 'post.js',
  97. ));
  98. break;
  99. }
  100. $mixedResult = $this->addJs($aJs, $bDynamic);
  101. if($bDynamic)
  102. return $mixedResult;
  103. }
  104. public function getJsCodeView($aParams = array(), $bWrap = true, $bDynamic = false)
  105. {
  106. $aParams = array_merge([
  107. 'sObjNameMenuFeeds' => $this->_oConfig->getObject('menu_feeds'),
  108. 'bInfScroll' => $this->_oConfig->isInfiniteScroll(),
  109. 'iInfScrollAutoPreloads' => $this->_oConfig->getAutoPreloads(),
  110. 'iLimitAttachLinks' => $this->_oConfig->getLimitAttachLinks(),
  111. 'sLimitAttachLinksErr' => bx_js_string(_t('_bx_timeline_txt_err_attach_links')),
  112. 'oAttachedLinks' => []
  113. ], $aParams);
  114. return parent::getJsCode('view', $aParams, $bWrap, $bDynamic);
  115. }
  116. public function getJsCodePost($iOwnerId, $aParams = array(), $bWrap = true, $bDynamic = false)
  117. {
  118. $aGeneralParams = [];
  119. $aRequestParams = $aParams;
  120. if(isset($aParams['gparams'], $aParams['rparams'])) {
  121. $aGeneralParams = $aParams['gparams'];
  122. $aRequestParams = $aParams['rparams'];
  123. }
  124. return $this->getJsCode('post', array_merge(array(
  125. 'bEmoji' => $this->_oConfig->isEmoji(),
  126. 'bAutoAttach' => $this->_oConfig->isEditorAutoAttach(),
  127. 'iLimitAttachLinks' => $this->_oConfig->getLimitAttachLinks(),
  128. 'sLimitAttachLinksErr' => bx_js_string(_t('_bx_timeline_txt_err_attach_links')),
  129. 'oAttachedLinks' => $this->_oDb->getLinksBy(array(
  130. 'type' => 'unused',
  131. 'profile_id' => $this->getModule()->getUserId(),
  132. 'short' => true
  133. )),
  134. 'sVideosAutoplay' => $this->_oConfig->getVideosAutoplay(),
  135. 'oRequestParams' => array_merge(array(
  136. 'type' => isset($aRequestParams['type']) ? $aRequestParams['type'] : BX_TIMELINE_TYPE_DEFAULT,
  137. 'owner_id' => $iOwnerId
  138. ), $aRequestParams)
  139. ), $aGeneralParams), $bWrap, $bDynamic);
  140. }
  141. public function getPostBlock($iOwnerId, $aParams = array())
  142. {
  143. $CNF = &$this->_oConfig->CNF;
  144. $aForm = $this->getModule()->getFormPost($aParams);
  145. if($this->_oConfig->isEditorAutoattach() && !empty($aForm['form_object'])) {
  146. $aUploadersInfo = $aForm['form_object']->getUploadersInfo($CNF['FIELD_PHOTO']);
  147. if(!empty($aUploadersInfo) && is_array($aUploadersInfo))
  148. $aParams = [
  149. 'gparams' => ['sAutoUploader' => $aUploadersInfo['name'], 'sAutoUploaderId' => $aUploadersInfo['id']],
  150. 'rparams' => $aParams
  151. ];
  152. }
  153. return $this->parseHtmlByName('block_post.html', array (
  154. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  155. 'js_object' => $this->_oConfig->getJsObject('post'),
  156. 'js_content' => $this->getJsCodePost($iOwnerId, $aParams),
  157. 'form' => $aForm['form']
  158. ));
  159. }
  160. public function getViewsBlock($aParams)
  161. {
  162. $sStylePrefix = $this->_oConfig->getPrefix('style');
  163. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  164. $sType = isset($aParams['type']) ? $aParams['type'] : '';
  165. $sMenu = $this->_oConfig->getObject('menu_view');
  166. $oMenu = BxDolMenu::getObjectInstance($sMenu);
  167. $aMenuItems = $oMenu->getMenuItems();
  168. if(empty($aMenuItems) || !is_array($aMenuItems))
  169. return '';
  170. if(empty($sType)) {
  171. $aMenuItem = array_shift($aMenuItems);
  172. $sType = $aMenuItem['name'];
  173. }
  174. $oMenu->setSelected($this->_oConfig->getName(), $sType);
  175. $oMenu->addMarkers(array(
  176. 'js_object_view' => $sJsObject
  177. ));
  178. $sTitle = _t('_bx_timeline_page_block_title_views_' . $aParams['view']);
  179. if (bx_is_api())
  180. return [
  181. 'content' => [bx_api_get_block('browse', ['unit' => 'feed', 'data' => $this->getViewBlock($aParams)])],
  182. 'menu' => $oMenu->getCodeAPI()
  183. ];
  184. return [
  185. 'content' => $this->parseHtmlByName('block_views.html', [
  186. 'style_prefix' => $sStylePrefix,
  187. 'html_id' => $this->_oConfig->getHtmlIdView('views', $aParams, ['with_type' => false]),
  188. 'html_id_content' => $this->_oConfig->getHtmlIdView('views_content', $aParams, ['with_type' => false]),
  189. 'html_id_view_placeholder' => $this->_oConfig->getHtmlIdView('main', array_merge($aParams, ['type' => 'placeholder'])),
  190. 'title' => $sTitle,
  191. 'content' => $this->getViewBlock($aParams)
  192. ]),
  193. 'menu' => $oMenu
  194. ];
  195. }
  196. public function getViewsDbBlock($aParams)
  197. {
  198. $sStylePrefix = $this->_oConfig->getPrefix('style');
  199. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  200. $sJsContent = $this->getJsCodeView([
  201. 'sObjName' => $sJsObject,
  202. 'sName' => $aParams['name'],
  203. 'sView' => $aParams['view'],
  204. 'sType' => $aParams['type'],
  205. 'sVideosAutoplay' => $this->_oConfig->getVideosAutoplay(),
  206. 'oRequestParams' => $aParams
  207. ], [
  208. 'wrap' => true,
  209. 'mask_markers' => ['object' => $sJsObject]
  210. ]);
  211. return array(
  212. 'content' => $this->parseHtmlByName('block_views_db.html', array(
  213. 'style_prefix' => $sStylePrefix,
  214. 'html_id' => $this->_oConfig->getHtmlIdView('views', $aParams, array('with_type' => false)),
  215. 'html_id_content' => $this->_oConfig->getHtmlIdView('views_content', $aParams, array('with_type' => false)),
  216. 'content' => $this->getViewBlock(array_merge($aParams, ['name' => ''])),
  217. 'js_content' => $sJsContent
  218. )),
  219. 'buttons' => [
  220. ['title' => _t('_bx_timeline_txt_filters'), 'href' => 'javascript:void(0)', 'onclick' => 'javascript:' . $sJsObject . '.changeFeedFilters(this)']
  221. ]
  222. );
  223. }
  224. public function getViewFilters($aParams)
  225. {
  226. $sStylePrefix = $this->_oConfig->getPrefix('style');
  227. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  228. $aHandlers = $this->_oDb->getHandlers(['type' => 'by_type', 'value' => 'insert']);
  229. $aModules = [];
  230. foreach($aHandlers as $aHandler) {
  231. $sModule = $aHandler['alert_unit'];
  232. if(isset($aModules[$sModule]))
  233. continue;
  234. $aModule = $this->_oDb->getModuleByName($sModule);
  235. if(empty($aModule) || !is_array($aModule))
  236. continue;
  237. $sTitleKey = '_' . $sModule;
  238. $sTitleValue = _t($sTitleKey);
  239. if(strcmp($sTitleKey, $sTitleValue) == 0)
  240. $sTitleValue = $aModule['title'];
  241. $aModules[$sModule] = [
  242. 'key' => $aHandler['alert_unit'],
  243. 'value' => $sTitleValue
  244. ];
  245. }
  246. uasort($aModules, function($aV1, $aV2) {
  247. return strcmp($aV1['value'], $aV2['value']);
  248. });
  249. $aForm = [
  250. 'inputs' => [
  251. 'by_module' => [
  252. 'name' => 'by_module',
  253. 'type' => 'radio_set',
  254. 'caption' => _t('_bx_timeline_form_filters_input_by_modules'),
  255. 'values' => [
  256. ['key' => 'all', 'value' => _t('_bx_timeline_form_filters_input_by_modules_all')],
  257. ['key' => 'selected', 'value' => _t('_bx_timeline_form_filters_input_by_modules_selected')]
  258. ],
  259. 'value' => 'all',
  260. 'attrs' => ['onchange' => $sJsObject . '.onFilterByModuleChange(this)'],
  261. 'dv_thd' => 1
  262. ],
  263. 'modules' => [
  264. 'name' => 'modules',
  265. 'type' => 'checkbox_set',
  266. 'values' => array_values($aModules),
  267. 'tr_attrs' => ['class' => 'modules', 'style' => 'display:none']
  268. ],
  269. 'apply' => [
  270. 'name' => 'apply',
  271. 'type' => 'button',
  272. 'value' => _t('_bx_timeline_form_filters_input_do_apply'),
  273. 'attrs' => ['onclick' => $sJsObject . '.onFilterApply(this)']
  274. ]
  275. ]
  276. ];
  277. $oForm = new BxTemplFormView($aForm);
  278. $sViewFiltersPopupId = $this->_oConfig->getHtmlIdView('filters_popup', $aParams);
  279. $sViewFiltersPopupContent = $this->parseHtmlByName('block_view_filters.html', array(
  280. 'style_prefix' => $sStylePrefix,
  281. 'js_object' => $sJsObject,
  282. 'content' => $oForm->genRows()
  283. ));
  284. return BxTemplFunctions::getInstance()->transBox($sViewFiltersPopupId, $sViewFiltersPopupContent, true);
  285. }
  286. public function getViewBlock($aParams)
  287. {
  288. $oModule = $this->getModule();
  289. if (bx_is_api()){
  290. $aPosts = $this->getPosts(array_merge($aParams, ['return_data_type' => 'array']));
  291. foreach($aPosts as &$aPost) {
  292. $aPost['author_data'] = BxDolProfile::getData($aPost['object_owner_id']);
  293. $aPost['url'] = bx_ltrim_str($aPost['content']['url'], BX_DOL_URL_ROOT);
  294. $aCmts = [];
  295. $oCmts = $oModule->getCmtsObject($aPost['comments']['system'], $aPost['comments']['object_id']);
  296. if($oCmts !== false){
  297. $aParams = ['mode' => 'feed', 'order_way' => 'desc', 'start_from' => 0, 'per_view' => 1];
  298. $aCmts = bx_srv('system', 'get_comments_api', [$oCmts, $aParams], 'TemplCmtsServices');
  299. $aPost['cmts'] = $aCmts;
  300. $aPost['cmts']['count'] = $aPost['comments']['count'];
  301. }
  302. }
  303. return $aPosts;
  304. }
  305. list($sContent, $sLoadMore, $sBack, $sEmpty, $iEvent, $bEventsToLoad) = $this->getPosts($aParams);
  306. //--- Add live update
  307. $oModule->actionResumeLiveUpdate($aParams['type'], $aParams['owner_id']);
  308. $sModuleName = $oModule->getName();
  309. $sModuleMethod = !empty($aParams['get_live_updates']) ? $aParams['get_live_updates'] : 'get_live_update';
  310. $sService = BxDolService::getSerializedService($sModuleName, $sModuleMethod, array($aParams, $oModule->getUserId(), '{count}', '{init}'));
  311. $aLiveUpdateParams = array($this->_oConfig->getLiveUpdateKey($aParams), 1, $sService, true);
  312. if($sModuleMethod == 'get_live_update')
  313. $aLiveUpdateParams[] = $iEvent;
  314. $sLiveUpdateCode = null;
  315. bx_alert($sModuleName, 'add_live_update', 0, 0, array(
  316. 'browse_params' => $aParams,
  317. 'live_update_params' => &$aLiveUpdateParams,
  318. 'override_result' => &$sLiveUpdateCode,
  319. ));
  320. if($sLiveUpdateCode === null && ($oLiveUpdates = BxDolLiveUpdates::getInstance()) !== false)
  321. $sLiveUpdateCode = call_user_func_array([$oLiveUpdates, 'add'], $aLiveUpdateParams);
  322. //--- Add live update
  323. $sContentBefore = '';
  324. $sContentAfter = '';
  325. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  326. $sJsContent = $this->getJsCodeView(array(
  327. 'sObjName' => $sJsObject,
  328. 'sName' => $aParams['name'],
  329. 'sView' => $aParams['view'],
  330. 'sType' => $aParams['type'],
  331. 'sVideosAutoplay' => $this->_oConfig->getVideosAutoplay(),
  332. 'bEventsToLoad' => $bEventsToLoad,
  333. 'bAutoMarkAsViewed' => $this->_oConfig->isSortByUnread(),
  334. 'oRequestParams' => $aParams
  335. ), array(
  336. 'wrap' => true,
  337. 'mask_markers' => array('object' => $sJsObject)
  338. )) . $this->getJsCode('repost');
  339. bx_alert($sModuleName, 'get_view', 0, 0, array(
  340. 'params' => $aParams,
  341. 'event_first' => $iEvent,
  342. 'back' => &$sBack,
  343. 'empty' => &$sEmpty,
  344. 'content_before' => &$sContentBefore,
  345. 'content' => &$sContent,
  346. 'content_after' => &$sContentAfter,
  347. 'load_more' => &$sLoadMore,
  348. 'js_content' => &$sJsContent
  349. ));
  350. return $this->parseHtmlByName('block_view.html', array(
  351. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  352. 'html_id' => $this->_oConfig->getHtmlIdView('main', $aParams),
  353. 'view' => $aParams['view'],
  354. 'back' => $sBack,
  355. 'empty' => $sEmpty,
  356. 'content_before' => $sContentBefore,
  357. 'content' => $sContent,
  358. 'content_after' => $sContentAfter,
  359. 'load_more' => $sLoadMore,
  360. 'show_more' => $this->_getShowMore($aParams),
  361. 'view_image_popup' => $this->_getImagePopup($aParams),
  362. 'live_update_code' => $sLiveUpdateCode,
  363. 'js_content' => $sJsContent
  364. ));
  365. }
  366. public function getSearchBlock($sContent)
  367. {
  368. $oModule = $this->getModule();
  369. $aParams = $oModule->getParams(BX_TIMELINE_VIEW_SEARCH);
  370. return $this->parseHtmlByName('block_search.html', array(
  371. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  372. 'html_id' => $this->_oConfig->getHtmlIdView('main', $aParams),
  373. 'view' => $aParams['view'],
  374. 'content' => $sContent,
  375. 'view_image_popup' => $this->_getImagePopup($aParams),
  376. 'js_content' => $this->getJsCodeView(array(
  377. 'oRequestParams' => $aParams
  378. ))
  379. ));
  380. }
  381. public function getItemBlock($mixedId, $aBrowseParams = array())
  382. {
  383. $CNF = $this->_oConfig->CNF;
  384. $oModule = $this->getModule();
  385. if(is_numeric($mixedId))
  386. $mixedId = $oModule->getItemData($mixedId);
  387. if(empty($mixedId) || !is_array($mixedId))
  388. return array('content' => MsgBox(_t('_Empty')), 'designbox_id' => 13);
  389. if($mixedId['code'] != 0)
  390. return array('content' => MsgBox($mixedId['content']), 'designbox_id' => 13);
  391. $aEvent = $mixedId['event'];
  392. $sContent = $mixedId['content'];
  393. if(!$this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  394. $mixedViews = $oModule->getViewsData($aEvent['views']);
  395. if($mixedViews !== false) {
  396. list($sSystem, $iObjectId) = $mixedViews;
  397. $oModule->getViewObject($sSystem, $iObjectId)->doView();
  398. }
  399. }
  400. $sAuthorName = $oModule->getObjectUser($aEvent['object_owner_id'])->getDisplayName();
  401. $sTitle = $sAuthorName . ' ' . _t($aEvent['sample_action'], _t($aEvent['sample']));
  402. $sDescription = $aEvent['title'];
  403. if(get_mb_substr($sDescription, 0, 1) == '_')
  404. $sDescription = _t($sDescription);
  405. $oTemplate = BxDolTemplate::getInstance();
  406. $oTemplate->setPageHeader(strip_tags($sTitle));
  407. $oTemplate->setPageDescription(strip_tags($sDescription));
  408. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  409. if($oMetatags)
  410. $oMetatags->addPageMetaInfo($aEvent[$CNF['FIELD_ID']]);
  411. $sReferrer = '';
  412. if(isset($_SERVER['HTTP_REFERER']) && mb_stripos($_SERVER['HTTP_REFERER'], BX_DOL_URL_ROOT) === 0)
  413. $sReferrer = $_SERVER['HTTP_REFERER'];
  414. else
  415. $sReferrer = bx_absolute_url(BxDolPermalinks::getInstance()->permalink($this->_oConfig->CNF['URL_HOME']));
  416. $sJsObject = $this->_oConfig->getJsObjectView($aBrowseParams);
  417. return array('content' => $this->parseHtmlByName('block_item.html', array(
  418. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  419. 'html_id' => $this->_oConfig->getHtmlIdView('main', $aBrowseParams),
  420. 'content' => $sContent,
  421. 'show_more' => $this->_getShowMore($aBrowseParams),
  422. 'view_image_popup' => $this->_getImagePopup($aBrowseParams),
  423. 'js_content' => $this->getJsCodeView(array(
  424. 'sObjName' => $sJsObject,
  425. 'sVideosAutoplay' => $this->_oConfig->getVideosAutoplay(),
  426. 'sReferrer' => $sReferrer,
  427. 'oRequestParams' => $aBrowseParams
  428. ), array(
  429. 'wrap' => true,
  430. 'mask_markers' => array('object' => $sJsObject)
  431. )) . $this->getJsCode('repost')
  432. )));
  433. }
  434. /**
  435. * Get event's content.
  436. * @param integer $iId - event ID.
  437. * @param string $sMode - 'file'/'photo'/'video' are available for now. But only images will be shown.
  438. */
  439. public function getItemBlockContent($iId, $sMode) {
  440. $oModule = $this->getModule();
  441. $sStylePrefix = $this->_oConfig->getPrefix('style');
  442. $aItemData = $oModule->getItemData($iId);
  443. if(empty($aItemData) || $aItemData['code'] != 0)
  444. return '';
  445. $aEvent = $aItemData['event'];
  446. $sKeyMain = $sKeyAttach = '';
  447. switch($sMode) {
  448. case 'file':
  449. $sKeyMain = 'files';
  450. $sKeyAttach = 'files_attach';
  451. break;
  452. case 'photo':
  453. $sKeyMain = 'images';
  454. $sKeyAttach = 'images_attach';
  455. break;
  456. case 'video':
  457. $sKeyMain = 'videos';
  458. $sKeyAttach = 'videos_attach';
  459. break;
  460. }
  461. $aImages = [];
  462. if(!empty($aEvent['content'][$sKeyMain]) && is_array($aEvent['content'][$sKeyMain]))
  463. $aImages = $aEvent['content'][$sKeyMain];
  464. else if(!empty($aEvent['content'][$sKeyAttach]) && is_array($aEvent['content'][$sKeyAttach]))
  465. $aImages = $aEvent['content'][$sKeyAttach];
  466. if(isset($aImages['total']) && isset($aImages['items']))
  467. $aImages = $aImages['items'];
  468. $bImageSingle = count($aImages) == 1;
  469. $sImageSelected = base64_decode(bx_process_input(bx_get('src')));
  470. $aTmplVarsImages = [];
  471. if(!$bImageSingle) {
  472. $iIndex = 1;
  473. foreach($aImages as $aImage) {
  474. if(!isset($aImage['src'], $aImage['src_orig']))
  475. continue;
  476. $iCurrent = $iIndex;
  477. if(strcmp($aImage['src'], $sImageSelected) == 0 || strcmp($aImage['src_orig'], $sImageSelected) == 0)
  478. $iCurrent = 0;
  479. $aTmplVarsImages[$iCurrent] = [
  480. 'style_prefix' => $sStylePrefix,
  481. 'url' => $aImage['url'],
  482. 'src' => $aImage[!empty($aImage['src_orig']) ? 'src_orig' : 'src']
  483. ];
  484. $iIndex++;
  485. }
  486. ksort($aTmplVarsImages);
  487. $aTmplVarsImages = array_values($aTmplVarsImages);
  488. }
  489. $aTmplVars = [
  490. 'style_prefix' => $sStylePrefix,
  491. 'bx_if:show_image' => [
  492. 'condition' => $bImageSingle,
  493. 'content' => [
  494. 'style_prefix' => $sStylePrefix,
  495. 'src' => $sImageSelected,
  496. ]
  497. ],
  498. 'bx_if:show_images' => [
  499. 'condition' => !$bImageSingle,
  500. 'content' => [
  501. 'style_prefix' => $sStylePrefix,
  502. 'bx_repeat:images' => $aTmplVarsImages
  503. ]
  504. ]
  505. ];
  506. return $this->parseHtmlByName('block_item_content.html', $aTmplVars);
  507. }
  508. public function getItemBlockInfo($iId) {
  509. $CNF = $this->_oConfig->CNF;
  510. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  511. if(empty($aEvent))
  512. return '';
  513. $aResult = $this->getDataCached($aEvent);
  514. if($aResult === false)
  515. return '';
  516. $sAuthorUnit = $this->getModule()->getObjectUser($aResult['object_owner_id'])->getUnit();
  517. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_post'), $this->_oConfig->getObject('form_display_post_view'), $this);
  518. $oForm->initChecker($aEvent);
  519. return $this->parseHtmlByName('block_item_info.html', array(
  520. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  521. 'author' => $sAuthorUnit,
  522. 'fields' => $oForm->getCode()
  523. ));
  524. }
  525. public function getItemBlockComments($iId)
  526. {
  527. $aEvent = $this->_oDb->getEvents(['browse' => 'id', 'value' => $iId]);
  528. if(empty($aEvent))
  529. return '';
  530. $aEventData = $this->getDataCached($aEvent);
  531. if($aEventData === false)
  532. return '';
  533. if(!$this->getModule()->isAllowedComment(array_merge($aEvent, $aEventData)))
  534. return '';
  535. return $this->parseHtmlByName('block_item_comments.html', [
  536. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  537. 'content' => $this->_getComments($aEventData['comments'])
  538. ]);
  539. }
  540. public function getUnit(&$aEvent, $aBrowseParams = array())
  541. {
  542. $oModule = $this->getModule();
  543. if(empty($aBrowseParams) || !is_array($aBrowseParams))
  544. $aBrowseParams = $oModule->getParams(BX_TIMELINE_VIEW_SEARCH);
  545. return $this->getPost($aEvent, $aBrowseParams);
  546. }
  547. public function getPost(&$aEvent, $aBrowseParams = array())
  548. {
  549. $CNF = &$this->_oConfig->CNF;
  550. $iEventId = (int)$aEvent[$CNF['FIELD_ID']];
  551. $iViewerId = isset($aBrowseParams['viewer_id']) ? (int)$aBrowseParams['viewer_id'] : bx_get_logged_profile_id();
  552. $sMemoryCacheItemsKey = sprintf(self::$_sMemoryCacheItemsKeyMask, $aBrowseParams['view'], $iEventId);
  553. if(array_key_exists($sMemoryCacheItemsKey, self::$_aMemoryCacheItems)) {
  554. if(array_key_exists($sMemoryCacheItemsKey, self::$_aMemoryCacheItemsData))
  555. $aEvent = self::$_aMemoryCacheItemsData[$sMemoryCacheItemsKey];
  556. return self::$_aMemoryCacheItems[$sMemoryCacheItemsKey];
  557. }
  558. /**
  559. * Add all items in memory cache even if they are empty.
  560. */
  561. self::$_aMemoryCacheItems[$sMemoryCacheItemsKey] = '';
  562. self::$_aMemoryCacheItemsData[$sMemoryCacheItemsKey] = array();
  563. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
  564. if($oPrivacy) {
  565. $oPrivacy->setTableFieldAuthor($this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? 'owner_id' : 'object_id');
  566. if(!$oPrivacy->check($iEventId, $iViewerId))
  567. return '';
  568. }
  569. $aResult = $this->getDataCached($aEvent, $aBrowseParams);
  570. if($aResult === false)
  571. return '';
  572. if(isset($aResult['owner_id']))
  573. $aEvent['owner_id'] = $aResult['owner_id'];
  574. $aEvent['object_owner_id'] = $aResult['object_owner_id'];
  575. $aEvent['icon'] = !empty($aResult['icon']) ? $aResult['icon'] : '';
  576. $aEvent['sample'] = !empty($aResult['sample']) ? $aResult['sample'] : '_bx_timeline_txt_sample';
  577. $aEvent['sample_action'] = !empty($aResult['sample_action']) ? $aResult['sample_action'] : '_bx_timeline_txt_added_sample';
  578. if(isset($aResult['sample_action_custom']))
  579. $aEvent['sample_action_custom'] = $aResult['sample_action_custom'];
  580. $aEvent['content'] = $aResult['content'];
  581. $aEvent['content_type'] = !empty($aResult['content_type']) ? $aResult['content_type'] : BX_TIMELINE_PARSE_TYPE_DEFAULT;
  582. $aEvent['views'] = $aResult['views'];
  583. $aEvent['votes'] = $aResult['votes'];
  584. $aEvent['reactions'] = $aResult['reactions'];
  585. $aEvent['scores'] = $aResult['scores'];
  586. $aEvent['reports'] = $aResult['reports'];
  587. $aEvent['comments'] = $aResult['comments'];
  588. $sKey = 'allowed_view';
  589. $aEvent[$sKey] = $this->_preparePrivacy($sKey, $aEvent, $aResult);
  590. if(isset($aEvent[$sKey]) && $aEvent[$sKey] !== CHECK_ACTION_RESULT_ALLOWED)
  591. return '';
  592. self::$_aMemoryCacheItems[$sMemoryCacheItemsKey] = $this->_getPost($aEvent['content_type'], $aEvent, $aBrowseParams);
  593. self::$_aMemoryCacheItemsData[$sMemoryCacheItemsKey] = $aEvent;
  594. return self::$_aMemoryCacheItems[$sMemoryCacheItemsKey];
  595. }
  596. public function getPosts($aParams)
  597. {
  598. $bReturnArray = isset($aParams['return_data_type']) && $aParams['return_data_type'] == 'array';
  599. $bViewTimeline = $aParams['view'] == BX_TIMELINE_VIEW_TIMELINE;
  600. $iStart = $aParams['start'];
  601. $iPerPage = $aParams['per_page'];
  602. $aParamsDb = $aParams;
  603. //--- Before: Check for Previous
  604. $iDays = -1;
  605. $bPrevious = false;
  606. if($iStart - 1 >= 0) {
  607. $aParamsDb['start'] -= 1;
  608. $aParamsDb['per_page'] += 1;
  609. $bPrevious = true;
  610. }
  611. //--- Before: Check for Next
  612. $aParamsDb['per_page'] += 1;
  613. $aEvents = $this->_oDb->getEvents($aParamsDb);
  614. //--- After: Check for Previous
  615. if($bPrevious) {
  616. $aEvent = array_shift($aEvents);
  617. if ($aEvent)
  618. $iDays = (int)$aEvent['days'];
  619. }
  620. //--- After: Check for Next
  621. $bNext = false;
  622. if(count($aEvents) > $iPerPage) {
  623. $aEvent = array_pop($aEvents);
  624. $bNext = true;
  625. }
  626. $sContent = '';
  627. $sContent .= $this->getSizer($aParams);
  628. $iFirst = 0;
  629. $iEvents = count($aEvents);
  630. if($iEvents > 0)
  631. $iFirst = $this->_getFirst($aEvents, $aParams);
  632. else
  633. $sContent .= $bViewTimeline ? $this->getDividerToday() : '';
  634. //--- Check for Visual Grouping
  635. $aGroups = array();
  636. foreach($aEvents as $iIndex => $aEvent) {
  637. $aContent = unserialize($aEvent['content']);
  638. if(!isset($aContent['timeline_group']))
  639. continue;
  640. $aGroup = $aContent['timeline_group'];
  641. $sGroup = $aGroup['by'];
  642. if(!isset($aGroups[$sGroup]))
  643. $aGroups[$sGroup] = array('field' => $aGroup['field'], 'indexes' => array(), 'processed' => false);
  644. $aGroups[$sGroup]['indexes'][] = $iIndex;
  645. }
  646. //--- Perform Visual Grouping
  647. foreach($aGroups as $sGroup => $aGroup) {
  648. if(empty($aGroup['field']) || empty($aGroup['indexes']))
  649. continue;
  650. switch($aGroup['field']) {
  651. case 'owner_id':
  652. $aOwnerIds = array();
  653. foreach($aGroup['indexes'] as $iIndex)
  654. if(!in_array($aEvents[$iIndex]['owner_id'], $aOwnerIds))
  655. $aOwnerIds[] = $aEvents[$iIndex]['owner_id'];
  656. $iGroupIndex = (int)array_shift($aGroup['indexes']);
  657. if(is_null($iGroupIndex))
  658. break;
  659. foreach($aGroup['indexes'] as $iIndex)
  660. unset($aEvents[$iIndex]);
  661. $aEvents[$iGroupIndex]['owner_id_grouped'] = $aOwnerIds;
  662. break;
  663. }
  664. }
  665. $iExtenalsEvery = $this->_oConfig->getExtenalsEvery($aParams['type']);
  666. $bFirst = true;
  667. $iEventIndex = 0;
  668. $mixedEvents = $bReturnArray ? array() : '';
  669. foreach($aEvents as $aEvent) {
  670. $iEvent = (int)$aEvent['id'];
  671. $sEvent = $this->getPost($aEvent, $aParams);
  672. if(empty($sEvent))
  673. continue;
  674. if($bReturnArray) {
  675. $mixedEvents[] = $aEvent;
  676. continue;
  677. }
  678. if($bFirst && $bViewTimeline) {
  679. $mixedEvents .= $this->getDividerToday($aEvent);
  680. $bFirst = false;
  681. }
  682. $mixedEvents .= $bViewTimeline ? $this->getDivider($iDays, $aEvent) : '';
  683. $mixedEvents .= $sEvent;
  684. $iEventIndex++;
  685. if($iExtenalsEvery > 0 && $iEventIndex % $iExtenalsEvery == 0) {
  686. $sExternalPost = false;
  687. bx_alert($this->_oConfig->getName(), 'get_external_post', 0, 0, array(
  688. 'params' => $aParams,
  689. 'override_result' => &$sExternalPost,
  690. ));
  691. if($sExternalPost !== false)
  692. $mixedEvents .= $sExternalPost;
  693. }
  694. }
  695. if($bReturnArray)
  696. return $mixedEvents;
  697. $sContent .= $mixedEvents;
  698. $bEvents = !empty($mixedEvents);
  699. $sBack = $this->getBack($aParams);
  700. $iPerPage = $this->_oConfig->getPerPage();
  701. $iPreloads = $this->_oConfig->getAutoPreloads();
  702. if(!$this->_oConfig->isInfiniteScroll() || (($aParams['start'] - $iPerPage * ($iPreloads - 1)) % ($iPerPage * $iPreloads) == 0))
  703. $sLoadMore = $this->getLoadMore($aParams, $bNext, $iEvents > 0 && $bEvents);
  704. else
  705. $sLoadMore = $this->getLoadMoreAuto($aParams, $bNext, $iEvents > 0 && $bEvents);
  706. $sEmpty = $this->getEmpty($iEvents <= 0 || !$bEvents);
  707. return array($sContent, $sLoadMore, $sBack, $sEmpty, $iFirst, $bNext);
  708. }
  709. public function getEmpty($bVisible)
  710. {
  711. return $this->parseHtmlByName('empty.html', array(
  712. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  713. 'visible' => $bVisible ? 'block' : 'none',
  714. 'content' => MsgBox(_t('_bx_timeline_txt_msg_no_results'))
  715. ));
  716. }
  717. public function getDivider(&$iDays, &$aEvent)
  718. {
  719. if(!$this->_bShowTimelineDividers || $iDays == $aEvent['days'])
  720. return '';
  721. $iDays = $aEvent['days'];
  722. $iDaysAgo = (int)$aEvent['ago_days'];
  723. if($aEvent['today'] == $aEvent['days'] || (($aEvent['today'] - $aEvent['days']) == 1 && $iDaysAgo == 0))
  724. return '';
  725. return $this->parseHtmlByName('divider.html', array(
  726. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  727. 'type' => 'common',
  728. 'bx_if:show_hidden' => array(
  729. 'condition' => false,
  730. 'content' => array()
  731. ),
  732. 'content' => bx_time_js($aEvent['date'])
  733. ));
  734. }
  735. public function getDividerToday($aEvent = array())
  736. {
  737. if(!$this->_bShowTimelineDividers)
  738. return '';
  739. $bToday = !empty($aEvent) && ($aEvent['today'] == $aEvent['days'] || (($aEvent['today'] - $aEvent['days']) == 1 && (int)$aEvent['ago_days'] == 0));
  740. return $this->parseHtmlByName('divider.html', array(
  741. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  742. 'type' => 'today',
  743. 'bx_if:show_hidden' => array(
  744. 'condition' => !$bToday,
  745. 'content' => array()
  746. ),
  747. 'content' => _t('_bx_timeline_txt_today')
  748. ));
  749. }
  750. public function getSizer($aParams)
  751. {
  752. if($aParams['view'] != BX_TIMELINE_VIEW_OUTLINE)
  753. return '';
  754. return $this->parseHtmlByName('sizer_' . $aParams['view'] . '.html', array(
  755. 'style_prefix' => $this->_oConfig->getPrefix('style')
  756. ));
  757. }
  758. public function getBack($aParams)
  759. {
  760. $iYearSel = (int)$aParams['timeline'];
  761. if($iYearSel == 0)
  762. return '';
  763. $sStylePrefix = $this->_oConfig->getPrefix('style');
  764. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  765. $iYearNow = date('Y', time());
  766. return $this->parseHtmlByName('back.html', array(
  767. 'style_prefix' => $sStylePrefix,
  768. 'content' => $this->parseLink('javascript:void(0)', _t('_bx_timeline_txt_jump_to_recent'), array(
  769. 'title' => _t('_bx_timeline_txt_jump_to_n_year', $iYearNow),
  770. 'onclick' => 'javascript:' . $sJsObject . '.changeTimeline(this, 0)'
  771. ))
  772. ));
  773. }
  774. public function getLoadMore($aParams, $bEnabled, $bVisible = true)
  775. {
  776. $sStylePrefix = $this->_oConfig->getPrefix('style');
  777. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  778. $iStart = $aParams['start'];
  779. $iPerPage = $aParams['per_page'];
  780. $aTmplVars = array(
  781. 'style_prefix' => $sStylePrefix,
  782. 'visible' => ($aParams['view'] == BX_TIMELINE_VIEW_TIMELINE && $bVisible) || ($aParams['view'] == BX_TIMELINE_VIEW_OUTLINE && $bEnabled && $bVisible) ? 'block' : 'none',
  783. 'bx_if:is_disabled' => array(
  784. 'condition' => !$bEnabled,
  785. 'content' => array()
  786. ),
  787. 'bx_if:show_on_click' => array(
  788. 'condition' => $bEnabled,
  789. 'content' => array(
  790. 'on_click' => 'javascript:' . $sJsObject . '.changePage(this, ' . ($iStart + $iPerPage) . ', ' . $iPerPage . ')'
  791. )
  792. ),
  793. 'bx_if:show_jump_to' => array(
  794. 'condition' => $this->_oConfig->isJumpTo(),
  795. 'content' => array(
  796. 'style_prefix' => $sStylePrefix,
  797. 'content' => $this->getJumpTo($aParams)
  798. )
  799. )
  800. );
  801. return $this->parseHtmlByName('load_more.html', $aTmplVars);
  802. }
  803. public function getLoadMoreAuto($aParams, $bEnabled, $bVisible = true)
  804. {
  805. $sStylePrefix = $this->_oConfig->getPrefix('style');
  806. return $this->parseHtmlByName('load_more_auto.html', array(
  807. 'style_prefix' => $sStylePrefix,
  808. 'visible' => ($aParams['view'] == BX_TIMELINE_VIEW_TIMELINE && $bVisible) || ($aParams['view'] == BX_TIMELINE_VIEW_OUTLINE && $bEnabled && $bVisible) ? 'block' : 'none',
  809. 'loading' => _t('_bx_timeline_txt_loading' . ($bEnabled ? '' : '_complete'))
  810. ));
  811. }
  812. /**
  813. * Note. For now both List and Caledar based Jump To elements are available.
  814. * Calendar based element is used by default. List based one can be removed
  815. * later if it won't be used completely.
  816. */
  817. public function getJumpTo($aParams)
  818. {
  819. if(!$this->_oConfig->isJumpTo())
  820. return '';
  821. $bList = false;
  822. $bDynamicMode = isset($aParams['dynamic_mode']) && (bool)$aParams['dynamic_mode'] === true;
  823. if($bList && !$bDynamicMode)
  824. return '';
  825. return $this->{'_getJumpTo' . ($bList ? 'List' : 'Caledar')}($aParams);
  826. }
  827. public function getComments($sSystem, $iId, $aBrowseParams = array())
  828. {
  829. $oModule = $this->getModule();
  830. $sStylePrefix = $this->_oConfig->getPrefix('style');
  831. $oCmts = $oModule->getCmtsObject($sSystem, $iId);
  832. if($oCmts === false)
  833. return '';
  834. if (bx_is_api()){
  835. $aParams = ['mode' => 'feed', 'order_way' => 'desc', 'start_from' => 0];
  836. return [bx_srv('system', 'get_comments_api', [$oCmts, $aParams], 'TemplCmtsServices')];
  837. }
  838. $aCmtsBp = array();
  839. if(!empty($aBrowseParams['cmts_preload_number']))
  840. $aCmtsBp['init_view'] = $aBrowseParams['cmts_preload_number'];
  841. $aCmtsDp = array(
  842. 'in_designbox' => false,
  843. 'dynamic_mode' => isset($aBrowseParams['dynamic_mode']) && $aBrowseParams['dynamic_mode'] === true
  844. );
  845. if(!empty($aBrowseParams['cmts_min_post_form']))
  846. $aCmtsDp['min_post_form'] = $aBrowseParams['cmts_min_post_form'];
  847. $aComments = $oCmts->getCommentsBlock($aCmtsBp, $aCmtsDp);
  848. if(empty($aComments) || !is_array($aComments))
  849. return '';
  850. return $this->parseHtmlByName('comments.html', array(
  851. 'style_prefix' => $sStylePrefix,
  852. 'id' => $iId,
  853. 'content' => $aComments['content']
  854. ));
  855. }
  856. public function getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams = [])
  857. {
  858. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  859. if(empty($aReposted) || !is_array($aReposted))
  860. return '';
  861. $oModule = $this->getModule();
  862. $bDisabled = $oModule->isAllowedRepost($aReposted) !== true || $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $oModule->getUserId());
  863. if($bDisabled && (int)$aReposted['reposts'] == 0)
  864. return '';
  865. $sStylePrefix = $this->_oConfig->getPrefix('style');
  866. $sStylePrefixRepost = $sStylePrefix . '-repost-';
  867. $sDo = isset($aParams['do']) ? $aParams['do'] : 'repost';
  868. $bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'] === true;
  869. $bShowDoRepostAsButtonSmall = isset($aParams['show_do_repost_as_button_small']) && $aParams['show_do_repost_as_button_small'] == true;
  870. $bShowDoRepostAsButton = !$bShowDoRepostAsButtonSmall && isset($aParams['show_do_repost_as_button']) && $aParams['show_do_repost_as_button'] == true;
  871. $bShowDoRepostIcon = isset($aParams['show_do_repost_icon']) && $aParams['show_do_repost_icon'] == true && !empty($aParams['icon_do_repost']);
  872. $bShowDoRepostText = isset($aParams['show_do_repost_text']) && $aParams['show_do_repost_text'] == true && !empty($aParams['text_do_repost']);
  873. $bShowCounter = isset($aParams['show_counter']) && $aParams['show_counter'] === true;
  874. //--- Do repost link ---//
  875. $sClass = $sStylePrefixRepost . 'do-repost';
  876. if($bShowDoRepostAsButton)
  877. $sClass .= ' bx-btn';
  878. else if($bShowDoRepostAsButtonSmall)
  879. $sClass .= ' bx-btn bx-btn-small';
  880. $sOnClick = '';
  881. if(!$bDisabled) {
  882. $sMethod = '_get' . bx_gen_method_name($sDo) . 'JsClick';
  883. if(!method_exists($this, $sMethod))
  884. $sMethod = '_getRepostJsClick';
  885. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  886. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  887. $aRepostedData = unserialize($aReposted['content']);
  888. $sOnClick = $this->$sMethod($iOwnerId, $aRepostedData['type'], $aRepostedData['action'], $aRepostedData['object_id']);
  889. }
  890. else
  891. $sOnClick = $this->$sMethod($iOwnerId, $sType, $sAction, $iObjectId);
  892. }
  893. else
  894. $sClass .= $bShowDoRepostAsButton || $bShowDoRepostAsButtonSmall ? ' bx-btn-disabled' : ' ' . $sStylePrefixRepost . 'disabled';
  895. $aOnClickAttrs = array(
  896. 'title' => _t('_bx_timeline_txt_do_' . $sDo)
  897. );
  898. if(!empty($sClass))
  899. $aOnClickAttrs['class'] = $sClass;
  900. if(!empty($sOnClick))
  901. $aOnClickAttrs['onclick'] = $sOnClick;
  902. //--- Do repost label ---//
  903. $sMethodDoRepostLabel = '';
  904. $sTemplateDoRepostLabel = '';
  905. if(!empty($aParams['template_do_repost_label'])) {
  906. $sMethodDoRepostLabel = 'parseHtmlByContent';
  907. $sTemplateDoRepostLabel = $aParams['template_do_repost_label'];
  908. }
  909. else {
  910. $sMethodDoRepostLabel = 'parseHtmlByName';
  911. $sTemplateDoRepostLabel = $aParams['template_do_repost_label_name'];
  912. }
  913. $sDoRepost = $this->$sMethodDoRepostLabel($sTemplateDoRepostLabel, array(
  914. 'style_prefix' => $sStylePrefix,
  915. 'bx_if:show_icon' => array(
  916. 'condition' => $bShowDoRepostIcon,
  917. 'content' => array(
  918. 'style_prefix' => $sStylePrefix,
  919. 'icon' => $this->getImageAuto($aParams['icon_do_' . $sDo])
  920. )
  921. ),
  922. 'bx_if:show_text' => array(
  923. 'condition' => $bShowDoRepostText,
  924. 'content' => array(
  925. 'style_prefix' => $sStylePrefix,
  926. 'text' => _t($aParams['text_do_' . $sDo])
  927. )
  928. )
  929. ));
  930. return $this->parseHtmlByName('repost_element_block.html', array(
  931. 'style_prefix' => $sStylePrefix,
  932. 'html_id' => $this->_oConfig->getHtmlIds('repost', 'main') . $aReposted['id'],
  933. 'class' => ($bShowDoRepostAsButton ? $sStylePrefixRepost . 'button' : '') . ($bShowDoRepostAsButtonSmall ? $sStylePrefixRepost . 'button-small' : ''),
  934. 'count' => $aReposted['reposts'],
  935. 'do_repost' => $this->parseLink('javascript:void(0)', $sDoRepost, $aOnClickAttrs),
  936. 'bx_if:show_counter' => array(
  937. 'condition' => $bShowCounter,
  938. 'content' => array(
  939. 'style_prefix' => $sStylePrefix,
  940. 'bx_if:show_hidden' => array(
  941. 'condition' => (int)$aReposted['reposts'] == 0,
  942. 'content' => array()
  943. ),
  944. 'counter' => $this->getRepostCounter($aReposted, array_merge($aParams, ['show_script' => false]))
  945. )
  946. ),
  947. 'script' => $this->getRepostJsScript($bDynamicMode)
  948. ));
  949. }
  950. public function getRepostCounter($aEvent, $aParams = [])
  951. {
  952. $sStylePrefix = $this->_oConfig->getPrefix('style');
  953. $sJsObject = $this->_oConfig->getJsObject('repost');
  954. $bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'] === true;
  955. $bShowDoRepostAsButtonSmall = isset($aParams['show_do_repost_as_button_small']) && $aParams['show_do_repost_as_button_small'] == true;
  956. $bShowDoRepostAsButton = !$bShowDoRepostAsButtonSmall && isset($aParams['show_do_repost_as_button']) && $aParams['show_do_repost_as_button'] == true;
  957. $bShowScript = !isset($aParams['show_script']) || (bool)$aParams['show_script'] === true;
  958. $sClass = $sStylePrefix . '-repost-counter';
  959. if($bShowDoRepostAsButtonSmall)
  960. $sClass .= ' bx-btn-small-height';
  961. if($bShowDoRepostAsButton)
  962. $sClass .= ' bx-btn-height';
  963. return $this->parseHtmlByName('repost_counter.html', [
  964. 'class' => $sClass,
  965. 'bx_repeat:attrs' => [
  966. ['key' => 'id', 'value' => $this->_oConfig->getHtmlIds('repost', 'counter') . $aEvent['id']],
  967. ['key' => 'title', 'value' => _t('_bx_timeline_txt_reposted_by')],
  968. ['key' => 'href', 'value' => 'javascript:void(0)'],
  969. ['key' => 'onclick', 'value' => 'javascript:' . $sJsObject . '.toggleByPopup(this, ' . $aEvent['id'] . ')']
  970. ],
  971. 'content' => !empty($aEvent['reposts']) && (int)$aEvent['reposts'] > 0 ? $this->getRepostCounterLabel($aEvent['reposts'], $aParams) : '',
  972. 'script' => $bShowScript ? $this->getRepostJsScript($bDynamicMode) : ''
  973. ]);
  974. }
  975. public function getRepostCounterLabel($iCount, $aParams = [])
  976. {
  977. $sStylePrefix = $this->_oConfig->getPrefix('style');
  978. return $this->parseHtmlByName('repost_counter_label.html', [
  979. 'style_prefix' => $sStylePrefix,
  980. 'bx_if:show_icon' => array(
  981. 'condition' => !isset($aParams['show_counter_label_icon']) || (bool)$aParams['show_counter_label_icon'] === true,
  982. 'content' => array(
  983. 'style_prefix' => $sStylePrefix,
  984. 'icon' => $this->_getCounterIcon($aParams),
  985. )
  986. ),
  987. 'bx_if:show_text' => array(
  988. 'condition' => !isset($aParams['show_counter_label_text']) || (bool)$aParams['show_counter_label_text'] === true,
  989. 'content' => array(
  990. 'style_prefix' => $sStylePrefix,
  991. 'text' => $this->_getCounterLabel($iCount, $aParams)
  992. )
  993. )
  994. ]);
  995. }
  996. public function getRepostedBy($iId)
  997. {
  998. $aTmplUsers = array();
  999. $oModule = $this->getModule();
  1000. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1001. $aUserIds = $this->_oDb->getRepostedBy($iId);
  1002. foreach($aUserIds as $iUserId)
  1003. $aTmplUsers[] = array(
  1004. 'style_prefix' => $sStylePrefix,
  1005. 'user_unit' => $oModule->getObjectUser($iUserId)->getUnit()
  1006. );
  1007. bx_alert($this->_oConfig->getName(), 'get_reposted_by', 0, 0, array(
  1008. 'content_id' => $iId,
  1009. 'user_ids' => $aUserIds,
  1010. 'users' => &$aTmplUsers
  1011. ));
  1012. if(empty($aTmplUsers))
  1013. $aTmplUsers = MsgBox(_t('_Empty'));
  1014. return $this->parseHtmlByName('repost_by_list.html', array(
  1015. 'style_prefix' => $sStylePrefix,
  1016. 'bx_repeat:list' => $aTmplUsers
  1017. ));
  1018. }
  1019. public function getRepostWith($oForm)
  1020. {
  1021. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1022. $sJsObject = $this->_oConfig->getJsObject('repost');
  1023. return $this->parseHtmlByName('repost_with_popup.html', array(
  1024. 'style_prefix' => $sStylePrefix,
  1025. 'js_object' => $sJsObject,
  1026. 'form' => $oForm->getCode(),
  1027. 'form_id' => $oForm->getId()
  1028. ));
  1029. }
  1030. public function getRepostWithFieldReposted($oForm, $aInput)
  1031. {
  1032. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1033. $aBrowseParams = $this->getModule()->getParams();
  1034. $aReposted = $oForm->getReposted();
  1035. $sReposted = $this->getPost($aReposted, $aBrowseParams);
  1036. $sContent = '';
  1037. if(!empty($sReposted))
  1038. $sContent = $this->_getContent($aReposted['content_type'], $aReposted, $aBrowseParams);
  1039. else
  1040. $sContent = MsgBox(_t('_Empty'));
  1041. return $this->parseHtmlByName('repost_with_reposted.html', array(
  1042. 'style_prefix' => $sStylePrefix,
  1043. 'content' => $sContent
  1044. ));
  1045. }
  1046. public function getRepostTo($oForm)
  1047. {
  1048. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1049. $sJsObject = $this->_oConfig->getJsObject('repost');
  1050. return $this->parseHtmlByName('repost_to_popup.html', array(
  1051. 'style_prefix' => $sStylePrefix,
  1052. 'js_object' => $sJsObject,
  1053. 'form' => $oForm->getCode(),
  1054. 'form_id' => $oForm->getId()
  1055. ));
  1056. }
  1057. public function getRepostToFieldList($oForm, $aInput)
  1058. {
  1059. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1060. $oConnection = BxDolConnection::getObjectInstance('sys_profiles_subscriptions');
  1061. if(!$oConnection)
  1062. return '';
  1063. $iProfileId = bx_get_logged_profile_id();
  1064. $aConnectedIds = $oConnection->getConnectedContent($iProfileId);
  1065. $aSelected = array();
  1066. $aTmplVarsModules = array();
  1067. if(!empty($aConnectedIds) && is_array($aConnectedIds)) {
  1068. $aCheckbox = $aInput;
  1069. $aCheckbox['type'] = 'checkbox';
  1070. $aCheckbox['name'] .= '[]';
  1071. foreach($aConnectedIds as $iConnectedId) {
  1072. $oProfile = BxDolProfile::getInstanceMagic($iConnectedId);
  1073. if(!$oProfile)
  1074. continue;
  1075. $sProfileModule = $oProfile->getModule();
  1076. if(!isset($aTmplVarsModules[$sProfileModule]))
  1077. $aTmplVarsModules[$sProfileModule] = array(
  1078. 'style_prefix' => $sStylePrefix,
  1079. 'title' => _t('_' . $sProfileModule),
  1080. 'bx_repeat:contexts' => array()
  1081. );
  1082. $aCheckbox['value'] = $iConnectedId;
  1083. $aCheckbox['checked'] = in_array($iConnectedId, $aSelected) ? 1 : 0;
  1084. $aTmplVarsModules[$sProfileModule]['bx_repeat:contexts'][] = array(
  1085. 'style_prefix' => $sStylePrefix,
  1086. 'checkbox' => $oForm->genInput($aCheckbox),
  1087. 'unit' => $oProfile->getUnit(0, array('template' => 'unit_wo_cover'))
  1088. );
  1089. }
  1090. }
  1091. return $this->parseHtmlByName('repost_to_list.html', array(
  1092. 'style_prefix' => $sStylePrefix,
  1093. 'bx_repeat:modules' => !empty($aTmplVarsModules)? array_values($aTmplVarsModules) : MsgBox(_t('_Empty'))
  1094. ));
  1095. }
  1096. public function getRepostJsScript($bDynamicMode = false)
  1097. {
  1098. $sCode = $this->getJsCode('repost', array(), array('mask' => '{object} = new {class}({params});', 'wrap' => false));
  1099. if($bDynamicMode) {
  1100. $sJsObject = $this->_oConfig->getJsObject('repost');
  1101. $sCode = "var " . $sJsObject . " = null;
  1102. $.getScript('" . bx_js_string($this->getJsUrl('main.js'), BX_ESCAPE_STR_APOS) . "', function(data, textStatus, jqxhr) {
  1103. $.getScript('" . bx_js_string($this->getJsUrl('repost.js'), BX_ESCAPE_STR_APOS) . "', function(data, textStatus, jqxhr) {
  1104. bx_get_style('" . bx_js_string($this->getCssUrl('repost.css'), BX_ESCAPE_STR_APOS) . "');
  1105. " . $sCode . "
  1106. });
  1107. }); ";
  1108. }
  1109. else {
  1110. $sCode = "var " . $sCode;
  1111. $this->addCss(array('repost.css'));
  1112. $this->addJs(array('main.js', 'repost.js'));
  1113. }
  1114. return $this->_wrapInTagJsCode($sCode);
  1115. }
  1116. public function getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  1117. {
  1118. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1119. if(empty($aReposted) || !is_array($aReposted))
  1120. return '';
  1121. $sResult = '';
  1122. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  1123. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  1124. $aRepostedData = unserialize($aReposted['content']);
  1125. $sResult = $this->_getRepostJsClick($iOwnerId, $aRepostedData['type'], $aRepostedData['action'], $aRepostedData['object_id']);
  1126. }
  1127. else
  1128. $sResult = $this->_getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  1129. return $sResult;
  1130. }
  1131. public function getRepostWithJsClick($iReposterId, $sType, $sAction, $iObjectId)
  1132. {
  1133. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1134. if(empty($aReposted) || !is_array($aReposted))
  1135. return '';
  1136. $sResult = '';
  1137. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  1138. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  1139. $aRepostedData = unserialize($aReposted['content']);
  1140. $sResult = $this->_getRepostWithJsClick($iReposterId, $aRepostedData['type'], $aRepostedData['action'], $aRepostedData['object_id']);
  1141. }
  1142. else
  1143. $sResult = $this->_getRepostWithJsClick($iReposterId, $sType, $sAction, $iObjectId);
  1144. return $sResult;
  1145. }
  1146. public function getRepostToJsClick($iReposterId, $sType, $sAction, $iObjectId)
  1147. {
  1148. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1149. if(empty($aReposted) || !is_array($aReposted))
  1150. return '';
  1151. $sResult = '';
  1152. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  1153. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  1154. $aRepostedData = unserialize($aReposted['content']);
  1155. $sResult = $this->_getRepostToJsClick($iReposterId, $aRepostedData['type'], $aRepostedData['action'], $aRepostedData['object_id']);
  1156. }
  1157. else
  1158. $sResult = $this->_getRepostToJsClick($iReposterId, $sType, $sAction, $iObjectId);
  1159. return $sResult;
  1160. }
  1161. public function getAttachLinkForm($iEventId = 0)
  1162. {
  1163. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1164. $sJsObject = $this->_oConfig->getJsObject('post');
  1165. $aForm = $this->getModule()->getFormAttachLink($iEventId);
  1166. return $this->parseHtmlByName('attach_link_form.html', array(
  1167. 'style_prefix' => $sStylePrefix,
  1168. 'js_object' => $sJsObject,
  1169. 'form_id' => $aForm['form_id'],
  1170. 'form' => $aForm['form'],
  1171. ));
  1172. }
  1173. public function getAttachLinkField($iUserId, $iEventId = 0)
  1174. {
  1175. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1176. if(!$iEventId)
  1177. $aLinks = $this->_oDb->getUnusedLinks($iUserId);
  1178. else
  1179. $aLinks = $this->_oDb->getLinks($iEventId);
  1180. $sLinks = '';
  1181. foreach($aLinks as $aLink)
  1182. $sLinks .= $this->getAttachLinkItem($iUserId, $aLink);
  1183. return $this->parseHtmlByName('attach_link_form_field.html', array(
  1184. 'html_id' => $this->_oConfig->getHtmlIds('post', 'attach_link_form_field') . $iEventId,
  1185. 'style_prefix' => $sStylePrefix,
  1186. 'links' => $sLinks
  1187. ));
  1188. }
  1189. public function getAttachLinkItem($iUserId, $mixedLink)
  1190. {
  1191. $aLink = is_array($mixedLink) ? $mixedLink : $this->_oDb->getLinksBy(array('type' => 'id', 'id' => (int)$mixedLink, 'profile_id' => $iUserId));
  1192. if(empty($aLink) || !is_array($aLink))
  1193. return '';
  1194. $sLinkIdPrefix = $this->_oConfig->getHtmlIds('post', 'attach_link_item');
  1195. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1196. $sClass = $sStylePrefix . '-al-item';
  1197. $sJsObject = $this->_oConfig->getJsObject('post');
  1198. $oEmbed = BxDolEmbed::getObjectInstance();
  1199. $bEmbed = $oEmbed !== false;
  1200. $sThumbnail = '';
  1201. $aLinkAttrs = array();
  1202. if(!$bEmbed) {
  1203. $aLinkAttrs = array(
  1204. 'title' => bx_html_attribute($aLink['title'])
  1205. );
  1206. if(!$this->_oConfig->isEqualUrls(BX_DOL_URL_ROOT, $aLink['url'])) {
  1207. $aLinkAttrs['target'] = '_blank';
  1208. if($this->_oDb->getParam('sys_add_nofollow') == 'on')
  1209. $aLinkAttrs['rel'] = 'nofollow';
  1210. }
  1211. if((int)$aLink['media_id'] != 0)
  1212. $sThumbnail = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_preview'))->getFileUrl($aLink['media_id']);
  1213. }
  1214. else
  1215. $sClass .= ' embed';
  1216. return $this->parseHtmlByName('attach_link_item.html', array(
  1217. 'html_id' => $sLinkIdPrefix . $aLink['id'],
  1218. 'style_prefix' => $sStylePrefix,
  1219. 'class' => $sClass,
  1220. 'js_object' => $sJsObject,
  1221. 'id' => $aLink['id'],
  1222. 'bx_if:show_embed_outer' => array(
  1223. 'condition' => $bEmbed,
  1224. 'content' => array(
  1225. 'style_prefix' => $sStylePrefix,
  1226. 'embed' => $bEmbed ? $oEmbed->getLinkHTML($aLink['url'], $aLink['title'], 300) : '',
  1227. )
  1228. ),
  1229. 'bx_if:show_embed_inner' => array(
  1230. 'condition' => !$bEmbed,
  1231. 'content' => array(
  1232. 'style_prefix' => $sStylePrefix,
  1233. 'bx_if:show_thumbnail' => array(
  1234. 'condition' => !empty($sThumbnail),
  1235. 'content' => array(
  1236. 'style_prefix' => $sStylePrefix,
  1237. 'thumbnail' => $sThumbnail
  1238. )
  1239. ),
  1240. 'url' => $aLink['url'],
  1241. 'link' => $this->parseLink($aLink['url'], $aLink['title'], $aLinkAttrs)
  1242. )
  1243. ),
  1244. ));
  1245. }
  1246. public function getData(&$aEvent, $aBrowseParams = array())
  1247. {
  1248. $aResult = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $this->_getSystemData($aEvent, $aBrowseParams) : $this->_getCommonData($aEvent, $aBrowseParams);
  1249. if(empty($aResult) || empty($aResult['object_owner_id']) || empty($aResult['content']))
  1250. return false;
  1251. $sSample = !empty($aResult['sample']) ? $aResult['sample'] : '_bx_timeline_txt_sample';
  1252. $aUpdate = array(
  1253. 'object_owner_id' => $aResult['object_owner_id']
  1254. );
  1255. //--- Update Title if empty.
  1256. if(empty($aEvent['title'])) {
  1257. $sTitle = !empty($aResult['title']) ? $this->_oConfig->getTitle($aResult['title']) : _t($sSample);
  1258. $aUpdate['title'] = bx_process_input(strip_tags($sTitle));
  1259. }
  1260. //--- Update Description if empty.
  1261. if(empty($aEvent['description'])) {
  1262. $sUserName = $this->getModule()->getObjectUser($aResult['object_owner_id'])->getDisplayName();
  1263. $sDescription = !empty($aResult['description']) ? $aResult['description'] : _t('_bx_timeline_txt_user_added_sample', $sUserName, _t($sSample));
  1264. if($sDescription == '' && !empty($aResult['content']['text']))
  1265. $sDescription = $aResult['content']['text'];
  1266. $aUpdate['description'] = bx_process_input(strip_tags($sDescription));
  1267. }
  1268. if(!empty($aUpdate) && is_array($aUpdate))
  1269. $this->_oDb->updateEvent($aUpdate, array('id' => $aEvent['id']));
  1270. return $aResult;
  1271. }
  1272. public function getDataCached($aEvent, $aBrowseParams = array())
  1273. {
  1274. if(!$this->_oConfig->isCacheItem() || bx_is_api())
  1275. return $this->getData($aEvent, $aBrowseParams);
  1276. /**
  1277. * For now parameters from $aBrowseParams array aren't used during data retrieving.
  1278. * If they will then the cache should be created depending on their values.
  1279. */
  1280. $sCacheKey = $this->_oConfig->getCacheItemKey($aEvent['id']);
  1281. $iCacheLifetime = $this->_oConfig->getCacheItemLifetime();
  1282. $oCache = $this->getModule()->getCacheItemObject();
  1283. $aCached = $oCache->getData($sCacheKey, $iCacheLifetime);
  1284. if(!empty($aCached))
  1285. return unserialize($aCached);
  1286. $aBrowseParams['dynamic_mode'] = true;
  1287. $aResult = $this->getData($aEvent, $aBrowseParams);
  1288. if(empty($aResult) || (isset($aResult['_cache']) && (bool)$aResult['_cache'] === false))
  1289. return $aResult;
  1290. $oCache->setData($sCacheKey, serialize($aResult), $iCacheLifetime);
  1291. return $aResult;
  1292. }
  1293. public function getVideo($aEvent, $aVideo)
  1294. {
  1295. $sVideoId = $this->_oConfig->getHtmlIds('view', 'video') . $aEvent['id'] . '-' . $aVideo['id'];
  1296. $oPlayer = BxDolPlayer::getObjectInstance();
  1297. if (!$oPlayer)
  1298. return '';
  1299. $sPlayer = $oPlayer->getCodeVideo (BX_PLAYER_EMBED, array(
  1300. 'poster' => $aVideo['src_poster'],
  1301. 'mp4' => array('sd' => $aVideo['src_mp4'], 'hd' => $aVideo['src_mp4_hd']),
  1302. 'attrs' => array('id' => $sVideoId),
  1303. ));
  1304. return $this->parseHtmlByName('video_player.html', array(
  1305. 'player' => $sPlayer,
  1306. 'html_id' => $sVideoId
  1307. ));
  1308. }
  1309. /*
  1310. * Show only one Live Update notification for all new Events.
  1311. */
  1312. function getLiveUpdate($aBrowseParams, $iProfileId, $iCountOld = 0, $iCountNew = 0)
  1313. {
  1314. $oModule = $this->getModule();
  1315. $iCount = (int)$iCountNew - (int)$iCountOld;
  1316. if($iCount < 0)
  1317. return '';
  1318. $aParams = $oModule->getParamsExt($aBrowseParams);
  1319. $aParams['start'] = 0;
  1320. $aParams['per_page'] = 1;
  1321. $aParams['newest'] = true;
  1322. $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
  1323. $aEvents = $this->_oDb->getEvents($aParams);
  1324. if(empty($aEvents) || !is_array($aEvents))
  1325. return '';
  1326. $aEvent = array_shift($aEvents);
  1327. if(empty($aEvent) || !is_array($aEvent))
  1328. return '';
  1329. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  1330. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1331. return $this->parseHtmlByName('live_update_button.html', array(
  1332. 'style_prefix' => $sStylePrefix,
  1333. 'html_id' => $this->_oConfig->getHtmlIds('view', 'live_update_popup') . $aBrowseParams['type'],
  1334. 'onclick_show' => "javascript:" . $sJsObject . ".goToBtn(this, 'timeline-event-" . $aEvent['id'] . "', '" . $aEvent['id'] . "');",
  1335. ));
  1336. }
  1337. /*
  1338. * Show Live Update notification separately for each new Event. Popup Chain is used here.
  1339. *
  1340. * Note. This way to display live update notifications isn't used for now.
  1341. * See BxTimelineTemplate::getLiveUpdate method instead.
  1342. */
  1343. function getLiveUpdates($aBrowseParams, $iProfileId, $iCountOld = 0, $iCountNew = 0)
  1344. {
  1345. $bShowAll = true;
  1346. $bShowActions = false;
  1347. $oModule = $this->getModule();
  1348. $iCount = (int)$iCountNew - (int)$iCountOld;
  1349. if($iCount < 0)
  1350. return '';
  1351. $iCountMax = $this->_oConfig->getLiveUpdateLength();
  1352. if($iCount > $iCountMax)
  1353. $iCount = $iCountMax;
  1354. $aParams = $oModule->getParamsExt($aBrowseParams);
  1355. $aParams['start'] = 0;
  1356. $aParams['per_page'] = $iCount;
  1357. $aParams['filter'] = BX_TIMELINE_FILTER_OTHER_VIEWER;
  1358. $aEvents = $this->_oDb->getEvents($aParams);
  1359. if(empty($aEvents) || !is_array($aEvents))
  1360. return '';
  1361. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  1362. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1363. $iUserId = $oModule->getUserId();
  1364. $bModerator = $oModule->isModerator();
  1365. $aEvents = array_reverse($aEvents);
  1366. $iEvents = count($aEvents);
  1367. $aTmplVarsItems = array();
  1368. foreach($aEvents as $iIndex => $aEvent) {
  1369. $aData = $this->getDataCached($aEvent);
  1370. if($aData === false)
  1371. continue;
  1372. $iEventId = $aEvent['id'];
  1373. $iEventAuthorId = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? (int)$aEvent['owner_id'] : (int)$aEvent['object_id'];
  1374. if($iEventAuthorId < 0) {
  1375. if(abs($iEventAuthorId) == $iUserId)
  1376. continue;
  1377. else if($bModerator)
  1378. $iEventAuthorId *= -1;
  1379. }
  1380. $oAuthor = $oModule->getObjectUser($iEventAuthorId);
  1381. $sAuthorName = $oAuthor->getDisplayName();
  1382. $aTmplVarsItems[] = array(
  1383. 'bx_if:show_as_hidden' => array(
  1384. 'condition' => !$bShowAll && $iIndex < ($iEvents - 1),
  1385. 'content' => array(),
  1386. ),
  1387. 'item' => $this->parseHtmlByName('live_update_notification.html', array(
  1388. 'style_prefix' => $sStylePrefix,
  1389. 'onclick_show' => "javascript:" . $sJsObject . ".goTo(this, 'timeline-event-" . $iEventId . "', '" . $iEventId . "');",
  1390. 'author_link' => $oAuthor->getUrl(),
  1391. 'author_title' => bx_html_attribute($sAuthorName),
  1392. 'author_name' => $sAuthorName,
  1393. 'author_unit' => $oAuthor->getUnit(0, array('template' => 'unit_wo_info_links')),
  1394. 'text' => _t($aData['sample_action'], _t($aData['sample'])),
  1395. )),
  1396. 'bx_if:show_previous' => array(
  1397. 'condition' => $bShowActions && $iIndex > 0,
  1398. 'content' => array(
  1399. 'onclick_previous' => $sJsObject . '.previousLiveUpdate(this)'
  1400. )
  1401. ),
  1402. 'bx_if:show_close' => array(
  1403. 'condition' => $bShowActions,
  1404. 'content' => array(
  1405. 'onclick_close' => $sJsObject . '.hideLiveUpdate(this)'
  1406. )
  1407. )
  1408. );
  1409. }
  1410. return $this->parseHtmlByName('popup_chain.html', array(
  1411. 'html_id' => $this->_oConfig->getHtmlIds('view', 'live_update_popup') . $aBrowseParams['type'],
  1412. 'bx_repeat:items' => $aTmplVarsItems
  1413. ));
  1414. }
  1415. protected function _getPost($sType, $aEvent, $aBrowseParams = array())
  1416. {
  1417. $CNF = &$this->_oConfig->CNF;
  1418. $oModule = $this->getModule();
  1419. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1420. $sJsObject = $this->_oConfig->getJsObjectView($aBrowseParams);
  1421. $bViewItem = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_ITEM;
  1422. $bViewOutline = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_OUTLINE;
  1423. $oAuthor = $oModule->getObjectUser($aEvent['object_owner_id']);
  1424. $sAuthorName = $oAuthor->getDisplayName();
  1425. $sAuthorUrl = $oAuthor->getUrl();
  1426. $sAuthorUnit = $oAuthor->getUnit(0, array('template' => 'unit_wo_info'));
  1427. $sAuthorBadges = $oAuthor->getBadges();
  1428. $sAuthorAction = '';
  1429. if(!empty($aEvent['sample_action_custom']) && is_array($aEvent['sample_action_custom'])) {
  1430. $aAuthorAction = $aEvent['sample_action_custom'];
  1431. foreach($aAuthorAction['markers'] as $iIndex => $sMarker)
  1432. if(get_mb_substr($sMarker, 0, 1) == '_')
  1433. $aAuthorAction['markers'][$iIndex] = _t($sMarker);
  1434. $sAuthorAction = bx_replace_markers(_t($aAuthorAction['content']), $aAuthorAction['markers']);
  1435. }
  1436. else
  1437. $sAuthorAction = _t($aEvent['sample_action'], _t($aEvent['sample']));
  1438. if(($bViewItem || $this->_oConfig->isCountAllViews()) && !empty($aEvent['views']) && is_array($aEvent['views']) && isset($aEvent['views']['system']))
  1439. $oModule->getViewObject($aEvent['views']['system'], $aEvent['views']['object_id'])->doView();
  1440. $aTmplVarsNote = $this->_getTmplVarsNote($aEvent);
  1441. $aTmplVarsMenuItemCounters = $this->_getTmplVarsMenuItemCounters($aEvent, $aBrowseParams);
  1442. $aTmplVarsMenuItemActions = $this->_getTmplVarsMenuItemActions($aEvent, $aBrowseParams);
  1443. $aTmplVarsMenuItemMeta = $this->_getTmplVarsMenuItemMeta($aEvent, $aBrowseParams);
  1444. $aTmplVarsManage = $this->_getTmplVarsManage($aEvent, $aBrowseParams);
  1445. $aTmplVarsTimelineOwner = $this->_getTmplVarsTimelineOwner($aEvent);
  1446. $bTmplVarsTimelineOwner = !empty($aTmplVarsTimelineOwner);
  1447. $aTmplVarsOwnerActions = $this->_getTmplVarsOwnerActions($aEvent, $aBrowseParams);
  1448. $bTmplVarsOwnerActions = !empty($aTmplVarsOwnerActions);
  1449. $bPinned = $aBrowseParams['type'] == BX_BASE_MOD_NTFS_TYPE_OWNER && (int)$aEvent['pinned'] > 0;
  1450. $bSticked = (int)$aEvent['sticked'] > 0;
  1451. $bPromoted = (int)$aEvent['promoted'] > 0;
  1452. $sClass = $sStylePrefix . '-view-sizer';
  1453. if($bViewOutline) {
  1454. $sClass = $sStylePrefix . '-grid-item-sizer';
  1455. if($bPinned || $bSticked || $bPromoted) {
  1456. $sClass .= ' ' . $sStylePrefix . '-gis';
  1457. if($bPinned)
  1458. $sClass .= '-pnd';
  1459. if($bSticked)
  1460. $sClass .= '-psd';
  1461. if($bPromoted)
  1462. $sClass .= '-pmd';
  1463. }
  1464. }
  1465. $sClass .= ' ' . $aEvent['type'] . (!empty($aEvent['action']) ? ' ' . $aEvent['action'] : '');
  1466. $aAuthorAcl = BxDolAcl::getInstance()->getMemberMembershipInfo($aEvent['object_owner_id']);
  1467. if(!empty($aAuthorAcl) && isset($this->_aAclId2Name[$aAuthorAcl['id']]))
  1468. $sClass .= ' ' . $sStylePrefix . '-aml-' . $this->_aAclId2Name[$aAuthorAcl['id']];
  1469. if(!empty($aBrowseParams['blink']) && in_array($aEvent['id'], $aBrowseParams['blink']))
  1470. $sClass .= ' ' . $sStylePrefix . '-blink';
  1471. if($bPinned)
  1472. $sClass .= ' ' . $sStylePrefix . '-pinned';
  1473. if($bSticked)
  1474. $sClass .= ' ' . $sStylePrefix . '-sticked';
  1475. if($bPromoted)
  1476. $sClass .= ' ' . $sStylePrefix . '-promoted';
  1477. $sClassOwner = $bTmplVarsOwnerActions ? $sStylePrefix . '-io-with-actions' : '';
  1478. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  1479. $sLocation = $oMetatags->locationsString($aEvent['id']);
  1480. $sFields = '';
  1481. if(!$bViewItem) {
  1482. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_post'), $this->_oConfig->getObject('form_display_post_view'), $this, $aEvent['id']);
  1483. $oForm->initChecker($aEvent);
  1484. if(!empty($oForm->aInputs) && is_array($oForm->aInputs))
  1485. foreach($oForm->aInputs as $aInput)
  1486. if($aInput['type'] != 'hidden' && !empty($aInput['value'])) {
  1487. $sFields = $oForm->getCode();
  1488. break;
  1489. }
  1490. }
  1491. $sIcon = !empty($aEvent['icon']) ? $aEvent['icon'] : $CNF['ICON'];
  1492. $aTmplVars = array (
  1493. 'style_prefix' => $sStylePrefix,
  1494. 'js_object' => $sJsObject,
  1495. 'html_id' => $this->_oConfig->getHtmlIdView('item', $aBrowseParams, array('whole' => false)) . $aEvent['id'],
  1496. 'class' => $sClass,
  1497. 'class_owner' => $sClassOwner,
  1498. 'class_content' => $bViewItem ? 'bx-def-color-bg-block' : 'bx-def-color-bg-box',
  1499. 'id' => $aEvent['id'],
  1500. 'bx_if:show_note' => array(
  1501. 'condition' => !empty($aTmplVarsNote),
  1502. 'content' => $aTmplVarsNote
  1503. ),
  1504. 'bx_if:show_owner_actions' => array(
  1505. 'condition' => $bTmplVarsOwnerActions,
  1506. 'content' => $aTmplVarsOwnerActions
  1507. ),
  1508. 'item_icon' => $sIcon,
  1509. 'item_owner_url' => $sAuthorUrl,
  1510. 'item_owner_title' => bx_html_attribute($sAuthorName),
  1511. 'item_owner_name' => $sAuthorName .' '. $sAuthorBadges,
  1512. 'item_owner_unit' => $sAuthorUnit,
  1513. 'item_view_url' => $this->_oConfig->getItemViewUrl($aEvent),
  1514. 'item_date' => bx_time_js($aEvent['date']),
  1515. 'bx_if:show_pinned' => array(
  1516. 'condition' => $bPinned,
  1517. 'content' => array(
  1518. 'style_prefix' => $sStylePrefix,
  1519. )
  1520. ),
  1521. 'bx_if:show_sticked' => array(
  1522. 'condition' => $bSticked,
  1523. 'content' => array(
  1524. 'style_prefix' => $sStylePrefix,
  1525. )
  1526. ),
  1527. 'bx_if:show_hot' => array(
  1528. 'condition' => $this->_oConfig->isHotEvent($aEvent['id']),
  1529. 'content' => array(
  1530. 'style_prefix' => $sStylePrefix,
  1531. )
  1532. ),
  1533. 'bx_if:show_manage' => array(
  1534. 'condition' => !empty($aTmplVarsManage),
  1535. 'content' => $aTmplVarsManage
  1536. ),
  1537. 'bx_if:show_item_action' => array(
  1538. 'condition' => $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) || $bTmplVarsTimelineOwner,
  1539. 'content' => array(
  1540. 'style_prefix' => $sStylePrefix,
  1541. 'item_icon' => $sIcon,
  1542. 'item_owner_action' => $sAuthorAction,
  1543. 'bx_if:show_timeline_owner' => array(
  1544. 'condition' => $bTmplVarsTimelineOwner,
  1545. 'content' => $aTmplVarsTimelineOwner
  1546. ),
  1547. )
  1548. ),
  1549. 'content_type' => $sType,
  1550. 'content' => is_string($aEvent['content']) ? $aEvent['content'] : $this->_getContent($sType, $aEvent, $aBrowseParams),
  1551. 'bx_if:show_location' => array(
  1552. 'condition' => !empty($sLocation),
  1553. 'content' => array(
  1554. 'style_prefix' => $sStylePrefix,
  1555. 'location' => $sLocation
  1556. )
  1557. ),
  1558. 'bx_if:show_fields' => array(
  1559. 'condition' => !empty($sFields),
  1560. 'content' => array(
  1561. 'style_prefix' => $sStylePrefix,
  1562. 'fields' => $sFields
  1563. )
  1564. ),
  1565. 'bx_if:show_menu_item_counters' => array(
  1566. 'condition' => !empty($aTmplVarsMenuItemCounters),
  1567. 'content' => $aTmplVarsMenuItemCounters
  1568. ),
  1569. 'bx_if:show_menu_item_actions' => array(
  1570. 'condition' => !empty($aTmplVarsMenuItemActions),
  1571. 'content' => $aTmplVarsMenuItemActions
  1572. ),
  1573. 'bx_if:show_menu_item_meta' => array(
  1574. 'condition' => !empty($aTmplVarsMenuItemMeta),
  1575. 'content' => $aTmplVarsMenuItemMeta
  1576. ),
  1577. 'comments' => '',
  1578. );
  1579. $iPreloadComments = $this->_oConfig->getPreloadComments();
  1580. if($iPreloadComments > 0 && $oModule->isAllowedComment($aEvent) && in_array($aBrowseParams['view'], array(BX_TIMELINE_VIEW_TIMELINE, BX_TIMELINE_VIEW_OUTLINE)))
  1581. $aTmplVars['comments'] = $this->_getComments($aEvent['comments'], array_merge($aBrowseParams, array(
  1582. 'cmts_preload_number' => $iPreloadComments,
  1583. 'cmts_min_post_form' => false
  1584. )));
  1585. $sVariable = '_sTmplContentItem' . bx_gen_method_name($aBrowseParams['view']);
  1586. if(empty(self::$$sVariable))
  1587. self::$$sVariable = $this->getHtml('item_' . $aBrowseParams['view'] . '.html');
  1588. $sTmplCode = self::$$sVariable;
  1589. bx_alert($this->_oConfig->getName(), 'get_post', 0, 0, array(
  1590. 'type' => $sType,
  1591. 'event' => $aEvent,
  1592. 'browse_params' => $aBrowseParams,
  1593. 'tmpl_code' => &$sTmplCode,
  1594. 'tmpl_vars' => &$aTmplVars
  1595. ));
  1596. return $this->parseHtmlByContent($sTmplCode, $aTmplVars);
  1597. }
  1598. protected function _getContent($sType, $aEvent, $aBrowseParams = array())
  1599. {
  1600. $sMethod = '_getTmplVarsContent' . ucfirst($sType);
  1601. if(!method_exists($this, $sMethod))
  1602. return '';
  1603. $aTmplVars = $this->$sMethod($aEvent, $aBrowseParams);
  1604. $sVariable = '_sTmplContentType' . bx_gen_method_name($sType);
  1605. if(empty(self::$$sVariable))
  1606. self::$$sVariable = $this->getHtml('type_' . $sType . '.html');
  1607. $sTmplCode = self::$$sVariable;
  1608. bx_alert($this->_oConfig->getName(), 'get_post_content', 0, 0, array(
  1609. 'type' => $sType,
  1610. 'event' => $aEvent,
  1611. 'browse_params' => $aBrowseParams,
  1612. 'tmpl_code' => &$sTmplCode,
  1613. 'tmpl_vars' => &$aTmplVars
  1614. ));
  1615. return $this->parseHtmlByContent($sTmplCode, $aTmplVars);
  1616. }
  1617. protected function _getComments($aComments, $aBrowseParams = array())
  1618. {
  1619. $mixedComments = $this->getModule()->getCommentsData($aComments);
  1620. if($mixedComments === false)
  1621. return '';
  1622. list($sSystem, $iObjectId, $iCount) = $mixedComments;
  1623. return $this->getComments($sSystem, $iObjectId, $aBrowseParams);
  1624. }
  1625. protected function _getShowMore($aParams)
  1626. {
  1627. return $this->parseHtmlByName('show_more.html', array(
  1628. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  1629. 'js_object' => $this->_oConfig->getJsObjectView($aParams),
  1630. ));
  1631. }
  1632. protected function _getImagePopup($aParams)
  1633. {
  1634. $sViewImagePopupId = $this->_oConfig->getHtmlIdView('photo_popup', $aParams);
  1635. $sViewImagePopupContent = $this->parseHtmlByName('popup_image.html', array(
  1636. 'image_url' => ''
  1637. ));
  1638. return BxTemplFunctions::getInstance()->transBox($sViewImagePopupId, $sViewImagePopupContent, true);
  1639. }
  1640. protected function _getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  1641. {
  1642. $sJsObject = $this->_oConfig->getJsObject('repost');
  1643. $sFormat = "%s.repostItem(this, %d, '%s', '%s', %d);";
  1644. $iOwnerId = !empty($iOwnerId) ? (int)$iOwnerId : $this->getModule()->getUserId(); //--- in whose timeline the content will be reposted
  1645. return sprintf($sFormat, $sJsObject, $iOwnerId, $sType, $sAction, (int)$iObjectId);
  1646. }
  1647. protected function _getRepostWithJsClick($iReposterId, $sType, $sAction, $iObjectId)
  1648. {
  1649. $sJsObject = $this->_oConfig->getJsObject('repost');
  1650. $sFormat = "%s.repostItemWith(this, %d, '%s', '%s', %d);";
  1651. $iReposterId = !empty($iReposterId) ? (int)$iReposterId : $this->getModule()->getUserId();
  1652. return sprintf($sFormat, $sJsObject, $iReposterId, $sType, $sAction, (int)$iObjectId);
  1653. }
  1654. protected function _getRepostToJsClick($iReposterId, $sType, $sAction, $iObjectId)
  1655. {
  1656. $sJsObject = $this->_oConfig->getJsObject('repost');
  1657. $sFormat = "%s.repostItemTo(this, %d, '%s', '%s', %d);";
  1658. $iReposterId = !empty($iReposterId) ? (int)$iReposterId : $this->getModule()->getUserId();
  1659. return sprintf($sFormat, $sJsObject, $iReposterId, $sType, $sAction, (int)$iObjectId);
  1660. }
  1661. protected function _getJumpToList($aParams)
  1662. {
  1663. $iYearSel = (int)$aParams['timeline'];
  1664. $iYearMin = $this->_oDb->getMaxDuration($aParams);
  1665. if(empty($iYearMin))
  1666. return '';
  1667. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1668. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  1669. $aYears = array();
  1670. $iYearMax = date('Y', time()) - 1;
  1671. for($i = $iYearMax; $i >= $iYearMin; $i--) {
  1672. $bCurrent = $i == $iYearSel;
  1673. $aYears[] = array(
  1674. 'style_prefix' => $sStylePrefix,
  1675. 'bx_if:show_link' => array(
  1676. 'condition' => !$bCurrent,
  1677. 'content' => array(
  1678. 'title' => _t('_bx_timeline_txt_jump_to_n_year', $i),
  1679. 'onclick' => 'javascript:' . $sJsObject . '.changeTimeline(this, \'' . $i . '-12-31\')',
  1680. 'content' => $i
  1681. )
  1682. ),
  1683. 'bx_if:show_text' => array(
  1684. 'condition' => $bCurrent,
  1685. 'content' => array(
  1686. 'content' => $i
  1687. )
  1688. ),
  1689. );
  1690. }
  1691. return $this->parseHtmlByName('jump_to.html', array(
  1692. 'bx_if:show_list' => array(
  1693. 'condition' => true,
  1694. 'content' => array(
  1695. 'style_prefix' => $sStylePrefix,
  1696. 'bx_repeat:links' => $aYears,
  1697. )
  1698. ),
  1699. 'bx_if:show_calendar' => array(
  1700. 'condition' => false,
  1701. 'content' => array()
  1702. )
  1703. ));
  1704. }
  1705. protected function _getJumpToCaledar($aParams)
  1706. {
  1707. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1708. $sJsObject = $this->_oConfig->getJsObjectView($aParams);
  1709. return $this->parseHtmlByName('jump_to.html', array(
  1710. 'bx_if:show_list' => array(
  1711. 'condition' => false,
  1712. 'content' => array()
  1713. ),
  1714. 'bx_if:show_calendar' => array(
  1715. 'condition' => true,
  1716. 'content' => array(
  1717. 'style_prefix' => $sStylePrefix,
  1718. 'onclick' => 'javascript:' . $sJsObject . '.showCalendar(this)',
  1719. )
  1720. )
  1721. ));
  1722. }
  1723. protected function _getTmplVarsMenuItemActions(&$aEvent, $aBrowseParams = array())
  1724. {
  1725. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_actions_all'));
  1726. if(!$oMenu) {
  1727. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_actions'));
  1728. if(!$oMenu)
  1729. return array();
  1730. }
  1731. $oMenu->setEvent($aEvent, $aBrowseParams);
  1732. $oMenu->setDynamicMode(isset($aBrowseParams['dynamic_mode']) && $aBrowseParams['dynamic_mode'] === true);
  1733. $sMenu = $oMenu->getCode();
  1734. if(empty($sMenu))
  1735. return array();
  1736. return array(
  1737. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  1738. 'js_object' => $this->_oConfig->getJsObjectView($aBrowseParams),
  1739. 'menu_item_actions' => $sMenu
  1740. );
  1741. }
  1742. protected function _getTmplVarsManage(&$aEvent, $aBrowseParams = array())
  1743. {
  1744. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_actions_all'));
  1745. if($oMenu)
  1746. return array();
  1747. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'));
  1748. if(!$oMenu)
  1749. return array();
  1750. $oMenu->setEvent($aEvent, $aBrowseParams);
  1751. $oMenu->setDynamicMode(isset($aBrowseParams['dynamic_mode']) && $aBrowseParams['dynamic_mode'] === true);
  1752. if(!$oMenu->isVisible())
  1753. return array();
  1754. $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}'});";
  1755. $sOnclick = bx_replace_markers($sOnclick, array(
  1756. 'content_id' => (int)$aEvent['id'],
  1757. 'view' => bx_process_output($aBrowseParams['view']),
  1758. 'type' => bx_process_output($aBrowseParams['type']),
  1759. 'name' => bx_process_output($aBrowseParams['name']),
  1760. ));
  1761. return array(
  1762. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  1763. 'onclick' => $sOnclick
  1764. );
  1765. }
  1766. protected function _getTmplVarsMenuItemCounters(&$aEvent, $aBrowseParams = array())
  1767. {
  1768. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_counters'));
  1769. if(!$oMenu)
  1770. return array();
  1771. $oMenu->setEvent($aEvent, $aBrowseParams);
  1772. $oMenu->setDynamicMode(isset($aBrowseParams['dynamic_mode']) && $aBrowseParams['dynamic_mode'] === true);
  1773. $sMenu = $oMenu->getCode();
  1774. if(empty($sMenu))
  1775. return array();
  1776. return array(
  1777. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  1778. 'js_object' => $this->_oConfig->getJsObjectView($aBrowseParams),
  1779. 'menu_item_counters' => $sMenu
  1780. );
  1781. }
  1782. protected function _getTmplVarsMenuItemMeta(&$aEvent, $aBrowseParams = array())
  1783. {
  1784. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_meta'));
  1785. if(!$oMenu)
  1786. return array();
  1787. $oMenu->setEvent($aEvent);
  1788. $sMenu = $oMenu->getCode();
  1789. if(empty($sMenu))
  1790. return array();
  1791. return array(
  1792. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  1793. 'meta' => $sMenu
  1794. );
  1795. }
  1796. protected function _getTmplVarsTimelineOwner(&$aEvent)
  1797. {
  1798. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1799. $iUser = bx_get_logged_profile_id();
  1800. $oModule = $this->getModule();
  1801. $sConnection = $this->_oConfig->getObject('conn_subscriptions');
  1802. $oConnection = BxDolConnection::getObjectInstance($sConnection);
  1803. $sConnectionTitle = _t('_sys_menu_item_title_sm_subscribe');
  1804. $sKeyOwnerId = isset($aEvent['owner_id_grouped']) ? 'owner_id_grouped' : 'owner_id';
  1805. $aOwnerIds = is_array($aEvent[$sKeyOwnerId]) ? $aEvent[$sKeyOwnerId] : array($aEvent[$sKeyOwnerId]);
  1806. $aTmplVarsOwners = array();
  1807. foreach($aOwnerIds as $iOwnerId) {
  1808. $iOwnerId = (int)$iOwnerId;
  1809. $iObjectOwner = (int)$aEvent['object_owner_id'];
  1810. if($iObjectOwner < 0 && abs($iObjectOwner) == $iUser)
  1811. $iObjectOwner *= -1;
  1812. if($iOwnerId == 0 || $iOwnerId == $iObjectOwner)
  1813. continue;
  1814. $oOwner = $oModule->getObjectUser($iOwnerId);
  1815. $sToType = $oOwner->getModule();
  1816. $sToName = $oOwner->getDisplayName();
  1817. $sToUrl = $oOwner->getUrl();
  1818. $aTmplVarsActions = array();
  1819. if(!empty($iUser) && $iUser != $iOwnerId && $oConnection->checkAllowedConnect($iUser, $iOwnerId) === CHECK_ACTION_RESULT_ALLOWED) {
  1820. $aTmplVarsActions[] = array(
  1821. 'href' => "javascript:void(0)",
  1822. 'onclick' => "bx_conn_action(this, '" . $sConnection . "', 'add', '" . $iOwnerId . "')",
  1823. 'title' => bx_html_attribute($sConnectionTitle),
  1824. 'content' => $sConnectionTitle,
  1825. 'icon' => 'check'
  1826. );
  1827. }
  1828. $aTmplVarsOwners[] = array(
  1829. 'style_prefix' => $sStylePrefix,
  1830. 'owner_type' => _t('_' . $sToType),
  1831. 'owner_url' => $sToUrl,
  1832. 'owner_username' => $sToName,
  1833. 'bx_if:show_timeline_owner_actions' => array(
  1834. 'condition' => !empty($aTmplVarsActions),
  1835. 'content' => array(
  1836. 'style_prefix' => $sStylePrefix,
  1837. 'bx_repeat:timeline_owner_actions' => $aTmplVarsActions
  1838. )
  1839. )
  1840. );
  1841. }
  1842. if(empty($aTmplVarsOwners))
  1843. return array();
  1844. return array(
  1845. 'style_prefix' => $sStylePrefix,
  1846. 'bx_repeat:owners' => $aTmplVarsOwners
  1847. );
  1848. }
  1849. protected function _getTmplVarsContentPost(&$aEvent, $aBrowseParams = array())
  1850. {
  1851. $aContent = &$aEvent['content'];
  1852. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1853. $bViewItem = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_ITEM;
  1854. $bViewSearch = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_SEARCH;
  1855. //--- Process Top Raw ---//
  1856. $sTopRaw = isset($aContent['top_raw']) ? $aContent['top_raw'] : '';
  1857. //--- Process Raw ---//
  1858. $sRaw = isset($aContent['raw']) ? $aContent['raw'] : '';
  1859. //--- Process Text ---//
  1860. $sUrl = isset($aContent['url']) ? bx_html_attribute($aContent['url']) : '';
  1861. $sTitle = '';
  1862. if(isset($aContent['title']))
  1863. $sTitle = bx_process_output($aContent['title']);
  1864. if(!empty($sUrl) && !empty($sTitle))
  1865. $sTitle = $this->parseLink($sUrl, $sTitle, array(
  1866. 'class' => $sStylePrefix . '-title bx-lnk-src',
  1867. 'title' => $sTitle
  1868. ));
  1869. $sMethodPrepare = '_prepareTextForOutput';
  1870. if($this->_oConfig->isBriefCards() && !$bViewItem)
  1871. $sMethodPrepare .= 'BriefCard';
  1872. $sText = isset($aContent['text']) ? $aContent['text'] : '';
  1873. $sText = $this->$sMethodPrepare($sText, $aEvent['id']);
  1874. //--- Process Links ---//
  1875. $bAddNofollow = $this->_oDb->getParam('sys_add_nofollow') == 'on';
  1876. $aTmplVarsLinks = [];
  1877. if(!empty($aContent['links']))
  1878. foreach($aContent['links'] as $aLink) {
  1879. $sLink = '';
  1880. $oEmbed = BxDolEmbed::getObjectInstance();
  1881. if ($oEmbed) {
  1882. $sLink = $this->parseHtmlByName('link_embed_provider.html', array(
  1883. 'style_prefix' => $sStylePrefix,
  1884. 'embed' => $oEmbed->getLinkHTML($aLink['url'], $aLink['title']),
  1885. ));
  1886. }
  1887. else {
  1888. $aLinkAttrs = array(
  1889. 'title' => $aLink['title']
  1890. );
  1891. if(!$this->_oConfig->isEqualUrls(BX_DOL_URL_ROOT, $aLink['url'])) {
  1892. $aLinkAttrs['target'] = '_blank';
  1893. if($bAddNofollow)
  1894. $aLinkAttrs['rel'] = 'nofollow';
  1895. }
  1896. $sLinkAttrs = '';
  1897. foreach($aLinkAttrs as $sKey => $sValue)
  1898. $sLinkAttrs .= ' ' . $sKey . '="' . bx_html_attribute($sValue) . '"';
  1899. $sLink = $this->parseHtmlByName('link_embed_common.html', array(
  1900. 'bx_if:show_thumbnail' => [
  1901. 'condition' => !empty($aLink['thumbnail']),
  1902. 'content' => [
  1903. 'style_prefix' => $sStylePrefix,
  1904. 'thumbnail' => $aLink['thumbnail'],
  1905. 'link' => !empty($aLink['url']) ? $aLink['url'] : 'javascript:void(0)',
  1906. 'attrs' => $sLinkAttrs
  1907. ]
  1908. ],
  1909. 'link' => !empty($aLink['url']) ? $aLink['url'] : 'javascript:void(0)',
  1910. 'attrs' => $sLinkAttrs,
  1911. 'content' => $aLink['title'],
  1912. 'bx_if:show_text' => [
  1913. 'condition' => !empty($aLink['text']),
  1914. 'content' => [
  1915. 'style_prefix' => $sStylePrefix,
  1916. 'text' => $aLink['text']
  1917. ]
  1918. ]
  1919. ));
  1920. }
  1921. $aTmplVarsLinks[] = [
  1922. 'style_prefix' => $sStylePrefix,
  1923. 'link' => $sLink
  1924. ];
  1925. }
  1926. /*
  1927. * View Item page and Snippet in Search Results should use Gallery layout.
  1928. */
  1929. $sAttachmentsLayout = $this->_oConfig->getAttachmentsLayout();
  1930. if($bViewItem || $bViewSearch)
  1931. $sAttachmentsLayout = BX_TIMELINE_ML_GALLERY;
  1932. $iAttachmentsTotal = 0;
  1933. $aTmplVarsImages = $aTmplVarsVideos = $aTmplVarsFiles = $aTmplVarsAttachments = $aTmplVarsAttachmentsFiles = array();
  1934. //--- Process Photos ---//
  1935. $bImages = !empty($aContent['images']) && is_array($aContent['images']);
  1936. if($bImages) {
  1937. $aImages = $this->_getTmplVarsImages($aContent['images'], true, $aEvent, $aBrowseParams);
  1938. if(!empty($aImages))
  1939. $aTmplVarsImages = array(
  1940. 'style_prefix' => $sStylePrefix,
  1941. 'display' => $aImages['display'],
  1942. 'bx_repeat:items' => $aImages['items']
  1943. );
  1944. }
  1945. $bImagesAttach = !empty($aContent['images_attach']) && is_array($aContent['images_attach']);
  1946. if($bImagesAttach) {
  1947. $aImagesAttach = $this->_getTmplVarsImages($aContent['images_attach'], ['layout' => $sAttachmentsLayout, 'first' => empty($aTmplVarsAttachments)], $aEvent, $aBrowseParams);
  1948. if(!empty($aImagesAttach)) {
  1949. $iAttachmentsTotal += $aImagesAttach['total'];
  1950. $aTmplVarsAttachments = array_merge($aTmplVarsAttachments, $aImagesAttach['items']);
  1951. }
  1952. }
  1953. //--- Add Meta Image when Item is viewed on a separate page ---//
  1954. if($bViewItem) {
  1955. $sMetaImageSrc = '';
  1956. if($bImages && !empty($aContent['images'][0]['src']))
  1957. $sMetaImageSrc = $aContent['images'][0]['src'];
  1958. else if($bImagesAttach && !empty($aContent['images_attach'][0]['src']))
  1959. $sMetaImageSrc = $aContent['images_attach'][0]['src'];
  1960. if(!empty($sMetaImageSrc))
  1961. BxDolTemplate::getInstance()->addPageMetaImage($sMetaImageSrc);
  1962. }
  1963. //--- Process Videos ---//
  1964. $bVideos = !empty($aContent['videos']) && is_array($aContent['videos']);
  1965. if($bVideos) {
  1966. $aVideos = $this->_getTmplVarsVideos($aContent['videos'], true, $aEvent, $aBrowseParams);
  1967. if(!empty($aVideos))
  1968. $aTmplVarsVideos = [
  1969. 'style_prefix' => $sStylePrefix,
  1970. 'display' => $aVideos['display'],
  1971. 'bx_repeat:items' => $aVideos['items']
  1972. ];
  1973. }
  1974. $bVideosAttach = !empty($aContent['videos_attach']) && is_array($aContent['videos_attach']);
  1975. if($bVideosAttach) {
  1976. $aVideosAttach = $this->_getTmplVarsVideos($aContent['videos_attach'], ['layout' => $sAttachmentsLayout, 'first' => empty($aTmplVarsAttachments)], $aEvent, $aBrowseParams);
  1977. if(!empty($aVideosAttach)) {
  1978. $iAttachmentsTotal += $aVideosAttach['total'];
  1979. $aTmplVarsAttachments = array_merge($aTmplVarsAttachments, $aVideosAttach['items']);
  1980. }
  1981. }
  1982. //--- Process Files ---//
  1983. $bFiles = !empty($aContent['files']) && is_array($aContent['files']);
  1984. if($bFiles) {
  1985. $aFiles = $this->_getTmplVarsFiles($aContent['files'], $aEvent, $aBrowseParams);
  1986. if(!empty($aFiles))
  1987. $aTmplVarsFiles = [
  1988. 'style_prefix' => $sStylePrefix,
  1989. 'display' => $aFiles['display'],
  1990. 'bx_repeat:items' => $aFiles['items']
  1991. ];
  1992. }
  1993. $bFilesAttach = !empty($aContent['files_attach']) && is_array($aContent['files_attach']);
  1994. if($bFilesAttach) {
  1995. $aFilesAttach = $this->_getTmplVarsFiles($aContent['files_attach'], $aEvent, $aBrowseParams);
  1996. if(!empty($aFilesAttach)) {
  1997. $aTmplVarsAttachmentsFiles = [
  1998. 'style_prefix' => $sStylePrefix,
  1999. 'display' => BX_TIMELINE_ML_GALLERY,
  2000. 'count' => count($aFilesAttach['items']),
  2001. 'bx_repeat:items' => $aFilesAttach['items']
  2002. ];
  2003. }
  2004. }
  2005. /*
  2006. * Process collected attachments in case of Showcase layout.
  2007. */
  2008. $iAttachmentsShow = 4;
  2009. $iAttachmentsCount = count($aTmplVarsAttachments);
  2010. if($sAttachmentsLayout == BX_TIMELINE_ML_SHOWCASE && $iAttachmentsCount > 0) {
  2011. $aTmplVarsAttachments[0]['class'] .= ' ' . $sStylePrefix . '-ia-first';
  2012. if($iAttachmentsCount > $iAttachmentsShow)
  2013. $aTmplVarsAttachments = array_slice($aTmplVarsAttachments, 0, $iAttachmentsShow);
  2014. if($iAttachmentsTotal > $iAttachmentsShow)
  2015. $aTmplVarsAttachments[$iAttachmentsShow - 1]['item'] .= $this->parseHtmlByName('attach_more.html', [
  2016. 'style_prefix' => $sStylePrefix,
  2017. 'link' => $this->_oConfig->getItemViewUrl($aEvent),
  2018. 'more' => $iAttachmentsTotal - $iAttachmentsShow
  2019. ]);
  2020. }
  2021. return [
  2022. 'style_prefix' => $sStylePrefix,
  2023. 'bx_if:show_title' => [
  2024. 'condition' => !empty($sTitle),
  2025. 'content' => [
  2026. 'style_prefix' => $sStylePrefix,
  2027. 'title' => $sTitle,
  2028. ]
  2029. ],
  2030. 'bx_if:show_content' => [
  2031. 'condition' => !empty($sText),
  2032. 'content' => [
  2033. 'style_prefix' => $sStylePrefix,
  2034. 'item_content' => $sText
  2035. ]
  2036. ],
  2037. 'bx_if:show_top_raw' => [
  2038. 'condition' => !empty($sTopRaw),
  2039. 'content' => [
  2040. 'style_prefix' => $sStylePrefix,
  2041. 'item_content_top_raw' => $sTopRaw
  2042. ]
  2043. ],
  2044. 'bx_if:show_raw' => [
  2045. 'condition' => !empty($sRaw),
  2046. 'content' => [
  2047. 'style_prefix' => $sStylePrefix,
  2048. 'item_content_raw' => $sRaw
  2049. ]
  2050. ],
  2051. 'bx_if:show_links' => [
  2052. 'condition' => !empty($aTmplVarsLinks),
  2053. 'content' => [
  2054. 'style_prefix' => $sStylePrefix,
  2055. 'bx_repeat:links' => $aTmplVarsLinks
  2056. ]
  2057. ],
  2058. 'bx_if:show_images' => [
  2059. 'condition' => !empty($aTmplVarsImages),
  2060. 'content' => $aTmplVarsImages
  2061. ],
  2062. 'bx_if:show_videos' => [
  2063. 'condition' => !empty($aTmplVarsVideos),
  2064. 'content' => $aTmplVarsVideos
  2065. ],
  2066. 'bx_if:show_files' => [
  2067. 'condition' => !empty($aTmplVarsFiles),
  2068. 'content' => $aTmplVarsFiles
  2069. ],
  2070. 'bx_if:show_attachments' => [
  2071. 'condition' => !empty($aTmplVarsAttachments),
  2072. 'content' => [
  2073. 'style_prefix' => $sStylePrefix,
  2074. 'display' => $sAttachmentsLayout,
  2075. 'count' => count($aTmplVarsAttachments),
  2076. 'bx_repeat:items' => $aTmplVarsAttachments
  2077. ]
  2078. ],
  2079. 'bx_if:show_attachments_files' => [
  2080. 'condition' => !empty($aTmplVarsAttachmentsFiles),
  2081. 'content' => $aTmplVarsAttachmentsFiles
  2082. ]
  2083. ];
  2084. }
  2085. protected function _getTmplVarsContentRepost(&$aEvent, $aBrowseParams = array())
  2086. {
  2087. $aContent = &$aEvent['content'];
  2088. $sStylePrefix = $this->_oConfig->getPrefix('style');
  2089. $sOwnerLink = $this->parseLink($aContent['owner_url'], $aContent['owner_name']);
  2090. $sSample = _t($aContent['sample']);
  2091. $sSampleLink = empty($aContent['url']) ? $sSample : $this->parseLink($aContent['url'], $sSample);
  2092. $aTmplVarsData = [];
  2093. if(!empty($aContent['rdata']) && is_array($aContent['rdata'])) {
  2094. $aData = $aContent['rdata'];
  2095. $aTmplVarsData['style_prefix'] = $sStylePrefix;
  2096. if(isset($aData['text']))
  2097. $aTmplVarsData['text'] = $this->_prepareTextForOutput($aData['text'], $aEvent['id']);
  2098. }
  2099. $sContent = $this->_getContent($aContent['parse_type'], $aEvent, $aBrowseParams);
  2100. return [
  2101. 'style_prefix' => $sStylePrefix,
  2102. 'item_owner_action' => _t('_bx_timeline_txt_reposted', $sOwnerLink, $sSampleLink),
  2103. 'bx_if:show_data' => [
  2104. 'condition' => !empty($aTmplVarsData),
  2105. 'content' => $aTmplVarsData
  2106. ],
  2107. 'bx_if:show_content' => [
  2108. 'condition' => !empty($sContent),
  2109. 'content' => [
  2110. 'style_prefix' => $sStylePrefix,
  2111. 'content' => $sContent,
  2112. ]
  2113. ]
  2114. ];
  2115. }
  2116. protected function _getTmplVarsNote(&$aEvent)
  2117. {
  2118. $sStylePrefix = $this->_oConfig->getPrefix('style');
  2119. $iUser = bx_get_logged_profile_id();
  2120. $iOwner = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $aEvent['owner_id'] : $aEvent['object_id'];
  2121. $aTmplVars = array();
  2122. if(!empty($iOwner) && !is_array($iOwner) && !empty($aEvent['promoted'])) {
  2123. $sConnection = $this->_oConfig->getObject('conn_subscriptions');
  2124. $oConnection = BxDolConnection::getObjectInstance($sConnection);
  2125. if(!$oConnection->isConnected($iUser, $iOwner))
  2126. $aTmplVars[] = [
  2127. 'style_prefix' => $sStylePrefix,
  2128. 'class' => '',
  2129. 'bx_if:show_note_color' => [
  2130. 'condition' => false,
  2131. 'content' => []
  2132. ],
  2133. 'item_note' => _t('_bx_timeline_txt_promoted')
  2134. ];
  2135. }
  2136. //--- Awaiting status related notes.
  2137. if($aEvent['status'] == BX_TIMELINE_STATUS_AWAITING) {
  2138. $sNote = '';
  2139. if((int)$aEvent['published'] > (int)$aEvent['date'])
  2140. $sNote = _t('_bx_timeline_txt_note_scheduled_awaiting', bx_time_js($aEvent['published'], BX_FORMAT_DATE, true));
  2141. else
  2142. $sNote = _t('_bx_timeline_txt_note_processing_awaiting');
  2143. $aTmplVars[] = [
  2144. 'style_prefix' => $sStylePrefix,
  2145. 'bx_if:show_note_color' => [
  2146. 'condition' => true,
  2147. 'content' => [
  2148. 'item_note_color' => 'red3'
  2149. ]
  2150. ],
  2151. 'item_note' => $sNote
  2152. ];
  2153. }
  2154. //--- Failed status related notes.
  2155. if($aEvent['status'] == BX_TIMELINE_STATUS_FAILED)
  2156. $aTmplVars[] = [
  2157. 'style_prefix' => $sStylePrefix,
  2158. 'bx_if:show_note_color' => [
  2159. 'condition' => true,
  2160. 'content' => [
  2161. 'item_note_color' => 'red2'
  2162. ]
  2163. ],
  2164. 'item_note' => _t('_bx_timeline_txt_note_processing_failed')
  2165. ];
  2166. //--- Pending status related notes.
  2167. if($aEvent['status_admin'] == BX_TIMELINE_STATUS_PENDING)
  2168. $aTmplVars[] = [
  2169. 'style_prefix' => $sStylePrefix,
  2170. 'bx_if:show_note_color' => [
  2171. 'condition' => true,
  2172. 'content' => [
  2173. 'item_note_color' => 'red3'
  2174. ]
  2175. ],
  2176. 'item_note' => _t('_bx_timeline_txt_note_approve_pending')
  2177. ];
  2178. return empty($aTmplVars) ? [] : [
  2179. 'style_prefix' => $sStylePrefix,
  2180. 'bx_repeat:notes' => $aTmplVars
  2181. ];
  2182. }
  2183. protected function _getTmplVarsOwnerActions(&$aEvent, $aBrowseParams = array())
  2184. {
  2185. $sStylePrefix = $this->_oConfig->getPrefix('style');
  2186. $iUser = bx_get_logged_profile_id();
  2187. $iOwner = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $aEvent['object_owner_id'] : $aEvent['object_id'];
  2188. $aTmplVarsActions = array();
  2189. if(!empty($iUser) && !empty($iOwner) && $iUser != $iOwner) {
  2190. $oOwner = BxDolProfile::getInstance($iOwner);
  2191. if($oOwner !== false && bx_srv($oOwner->getModule(), 'check_allowed_with_content', array('subscribe_add', $oOwner->getContentId())) === CHECK_ACTION_RESULT_ALLOWED) {
  2192. $sJsObject = $this->_oConfig->getJsObjectView($aBrowseParams);
  2193. $sConnection = $this->_oConfig->getObject('conn_subscriptions');
  2194. $sContent = _t('_sys_menu_item_title_sm_subscribe');
  2195. $aTmplVarsActions[] = array(
  2196. 'style_prefix' => $sStylePrefix,
  2197. 'href' => "javascript:void(0)",
  2198. 'onclick' => "bx_conn_action(this, '" . $sConnection . "', 'add', '" . $iOwner . "', false, function(oData, eElement) {" . $sJsObject . ".onConnect(eElement, oData);})",
  2199. 'title' => bx_html_attribute($sContent),
  2200. 'content' => $sContent,
  2201. 'icon' => 'check'
  2202. );
  2203. }
  2204. }
  2205. return array(
  2206. 'style_prefix' => $sStylePrefix,
  2207. 'bx_repeat:owner_actions' => $aTmplVarsActions
  2208. );
  2209. }
  2210. protected function _getTmplVarsImages($aImages, $mixedLayout, &$aEvent, &$aBrowseParams)
  2211. {
  2212. if(empty($aImages) || !is_array($aImages))
  2213. return [];
  2214. $iTotal = 0; //--- Total count of images related to the event.
  2215. if(isset($aImages['total']) && isset($aImages['items'])) {
  2216. $iTotal = (int)$aImages['total'];
  2217. $aImages = $aImages['items'];
  2218. }
  2219. else
  2220. $iTotal = count($aImages);
  2221. $sStylePrefix = $this->_oConfig->getPrefix('style');
  2222. $sJsObject = $this->_oConfig->getJsObjectView($aBrowseParams);
  2223. $bViewItem = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_ITEM;
  2224. $sDisplay = '';
  2225. $aTmplVarsImages = [];
  2226. $sImageSrcKey = $sImageSrcKeyBig = '';
  2227. $sImageSrcKeyDefault = 'src';
  2228. if(count($aImages) == 1) {
  2229. $sDisplay = BX_TIMELINE_ML_SINGLE;
  2230. $sImageSrcKey = $bViewItem ? 'src_orig' : 'src_medium';
  2231. }
  2232. else if(is_array($mixedLayout) && !empty($mixedLayout['layout'])) {
  2233. $sDisplay = $mixedLayout['layout'];
  2234. $sImageSrcKey = 'src';
  2235. $sImageSrcKeyBig = 'src_medium';
  2236. }
  2237. else {
  2238. $sDisplay = BX_TIMELINE_ML_GALLERY;
  2239. $sImageSrcKey = 'src';
  2240. $sImageSrcKeyBig = 'src_medium';
  2241. }
  2242. $bAttachFirst = false;
  2243. if($sDisplay == BX_TIMELINE_ML_SHOWCASE)
  2244. $bAttachFirst = isset($mixedLayout['first']) && $mixedLayout['first'] === true;
  2245. $aImageFirst = reset($aImages);
  2246. $iImageFirst = isset($aImageFirst['id']) ? (int)$aImageFirst['id'] : 0;
  2247. $aImageSizes = [
  2248. 'small' => '300w',
  2249. 'medium' => '500w',
  2250. 'orig' => '1200w'
  2251. ];
  2252. foreach($aImages as $aImage) {
  2253. $sImageSrcKeyCur = $sImageSrcKey;
  2254. if(($bAttachFirst && isset($aImage['id']) && (int)$aImage['id'] == $iImageFirst) || $iTotal == 2)
  2255. $sImageSrcKeyCur = $sImageSrcKeyBig;
  2256. if (is_array($aImage))
  2257. $sImageSrc = !empty($aImage[$sImageSrcKeyCur]) ? $aImage[$sImageSrcKeyCur] : $aImage[$sImageSrcKeyDefault];
  2258. if(empty($sImageSrc))
  2259. continue;
  2260. $sImageAttrSrcset = '';
  2261. foreach($aImageSizes as $sSize => $sWidth)
  2262. if(isset($aImage['src_' . $sSize]))
  2263. $sImageAttrSrcset .= $aImage['src_' . $sSize] . ' ' . $sWidth . ', ';
  2264. $sImage = $this->parseImage($sImageSrc, array(
  2265. 'class' => $sStylePrefix . '-item-image',
  2266. 'srcset' => trim($sImageAttrSrcset, ", "),
  2267. 'sizes' => '100%'
  2268. ));
  2269. $aAttrs = array();
  2270. if(isset($aImage['onclick']))
  2271. $aAttrs['onclick'] = $aImage['onclick'];
  2272. else if(!empty($aImage['src_orig']))
  2273. $aAttrs['onclick'] = 'return ' . $sJsObject . '.showItem(this, \'' . $aEvent['id'] . '\', \'photo\', ' . json_encode(array('src' => base64_encode($aImage['src_orig']))) . ')';
  2274. $sImage = $this->parseLinkByName('image_link.html', isset($aImage['url']) ? $aImage['url'] : 'javascript:void(0)', $sImage, $aAttrs);
  2275. $aTmplVarsImages[] = array(
  2276. 'style_prefix' => $sStylePrefix,
  2277. 'class' => '',
  2278. 'item' => $sImage
  2279. );
  2280. }
  2281. return array(
  2282. 'display' => $sDisplay,
  2283. 'total' => $iTotal,
  2284. 'items' => $aTmplVarsImages
  2285. );
  2286. }
  2287. protected function _getTmplVarsVideos($aVideos, $mixedLayout, &$aEvent, &$aBrowseParams)
  2288. {
  2289. if(empty($aVideos) || !is_array($aVideos))
  2290. return array();
  2291. $iTotal = 0; //--- Total count of videos related to the event.
  2292. if(isset($aVideos['total']) && isset($aVideos['items'])) {
  2293. $iTotal = (int)$aVideos['total'];
  2294. $aVideos = $aVideos['items'];
  2295. }
  2296. else
  2297. $iTotal = count($aVideos);
  2298. $sStylePrefix = $this->_oConfig->getPrefix('style');
  2299. $sJsObject = $this->_oConfig->getJsObjectView($aBrowseParams);
  2300. $aTmplVarsVideos = array();
  2301. /*
  2302. * For now Main Section may have only one video which can use 'autoplay' feature.
  2303. */
  2304. $bMain = $mixedLayout === true;
  2305. if($bMain) {
  2306. $sDisplay = BX_TIMELINE_ML_SINGLE;
  2307. if(count($aVideos) > 1)
  2308. $aVideos = array_slice($aVideos, 0, 1);
  2309. }
  2310. else
  2311. $sDisplay = is_array($mixedLayout) && !empty($mixedLayout['layout']) ? $mixedLayout['layout'] : BX_TIMELINE_AML_DEFAULT;
  2312. /*
  2313. * Main Section: Autoplay feature is only available here.
  2314. */
  2315. $sVap = $sVapId = $sVapSrc = $sVapTmpl = '';
  2316. if($bMain) {
  2317. $sVap = $this->_oConfig->getVideosAutoplay();
  2318. if($sVap != BX_TIMELINE_VAP_OFF) {
  2319. $sVapId = $this->_oConfig->getHtmlIds('view', 'video_iframe') . $aEvent['id'] . '-';
  2320. $sVapSrc = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'video/' . $aEvent['id'] . '/';
  2321. $sVapTmpl = $this->getHtml('video_iframe.html');
  2322. }
  2323. }
  2324. /*
  2325. * Attachments Section.
  2326. */
  2327. $sAttachTmpl = '';
  2328. $bAttachFirst = false;
  2329. if($sDisplay == BX_TIMELINE_ML_SHOWCASE) {
  2330. $sAttachTmpl = $this->getHtml('attach_video_preview.html');
  2331. $bAttachFirst = isset($mixedLayout['first']) && $mixedLayout['first'] === true;
  2332. }
  2333. $iVideoFirst = reset($aVideos)['id'];
  2334. foreach($aVideos as $aVideo) {
  2335. $iVideo = (int)$aVideo['id'];
  2336. if($bMain && $sVap != BX_TIMELINE_VAP_OFF)
  2337. $aTmplVarsVideos[] = array(
  2338. 'style_prefix' => $sStylePrefix,
  2339. 'class' => '',
  2340. 'item' => $this->parseHtmlByContent($sVapTmpl, array(
  2341. 'style_prefix' => $sStylePrefix,
  2342. 'html_id' => $sVapId . $iVideo,
  2343. 'src' => $sVapSrc . $iVideo . '/'
  2344. ))
  2345. );
  2346. else {
  2347. if($bMain || $sDisplay == BX_TIMELINE_ML_GALLERY || ($bAttachFirst && $iVideo == $iVideoFirst)) {
  2348. $sItem = '';
  2349. if(isset($aVideo['src'], $aVideo['src_orig'])) {
  2350. $sItem = $this->parseImage($aVideo['src'], array(
  2351. 'class' => $sStylePrefix . '-item-image'
  2352. ));
  2353. $aAttrs = array();
  2354. if(!empty($aVideo['src_orig']))
  2355. $aAttrs['onclick'] = 'return ' . $sJsObject . '.showItem(this, \'' . $aEvent['id'] . '\', \'video\', ' . json_encode(array('src' => base64_encode($aVideo['src_orig']))) . ')';
  2356. $sItem = $this->parseLinkByName('image_link.html', isset($aVideo['url']) ? $aVideo['url'] : 'javascript:void(0)', $sItem, $aAttrs);
  2357. }
  2358. else
  2359. $sItem = BxTemplFunctions::getInstance()->videoPlayer($aVideo['src_poster'], $aVideo['src_mp4'], $aVideo['src_mp4_hd'], array(
  2360. 'preload' => $this->_oConfig->getVideosPreload(),
  2361. ), '', $aBrowseParams['dynamic_mode']);
  2362. $aTmplVarsVideos[] = array(
  2363. 'style_prefix' => $sStylePrefix,
  2364. 'class' => '',
  2365. 'item' => $sItem
  2366. );
  2367. }
  2368. else {
  2369. $bUrl = !empty($aVideo['url']);
  2370. $sUrl = $bUrl ? $aVideo['url'] : '';
  2371. $sSrc = $aVideo[isset($aVideo['src'], $aVideo['src_orig']) ? 'src' : 'src_poster'];
  2372. $bDuration = !empty($aVideo['duration']);
  2373. $sDuration = _t_format_duration($bDuration ? $aVideo['duration'] : 0);
  2374. $aTmplVarsVideos[] = array(
  2375. 'style_prefix' => $sStylePrefix,
  2376. 'class' => '',
  2377. 'item' => $this->parseHtmlByContent($sAttachTmpl, array(
  2378. 'style_prefix' => $sStylePrefix,
  2379. 'bx_if:show_link' => array(
  2380. 'condition' => $bUrl,
  2381. 'content' => array(
  2382. 'style_prefix' => $sStylePrefix,
  2383. 'url' => $sUrl,
  2384. 'src' => $sSrc,
  2385. )
  2386. ),
  2387. 'bx_if:show_non_link' => array(
  2388. 'condition' => !$bUrl,
  2389. 'content' => array(
  2390. 'style_prefix' => $sStylePrefix,
  2391. 'src' => $sSrc,
  2392. )
  2393. ),
  2394. 'bx_if:show_duration' => array(
  2395. 'condition' => $bDuration,
  2396. 'content' => array(
  2397. 'style_prefix' => $sStylePrefix,
  2398. 'duration' => $sDuration,
  2399. )
  2400. )
  2401. ))
  2402. );
  2403. }
  2404. }
  2405. }
  2406. return array(
  2407. 'display' => $sDisplay,
  2408. 'total' => $iTotal,
  2409. 'items' => $aTmplVarsVideos
  2410. );
  2411. }
  2412. protected function _getTmplVarsFiles($aFiles, &$aEvent, &$aBrowseParams)
  2413. {
  2414. if(empty($aFiles) || !is_array($aFiles))
  2415. return array();
  2416. $iTotal = 0; //--- Total count of files related to the event.
  2417. if(isset($aFiles['total']) && isset($aFiles['items'])) {
  2418. $iTotal = (int)$aFiles['total'];
  2419. $aFiles = $aFiles['items'];
  2420. }
  2421. else
  2422. $iTotal = count($aFiles);
  2423. $sStylePrefix = $this->_oConfig->getPrefix('style');
  2424. $sJsObject = $this->_oConfig->getJsObjectView($aBrowseParams);
  2425. $bViewItem = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_ITEM;
  2426. $sDisplay = '';
  2427. $aTmplVarsFiles = array();
  2428. $sFileSrcKey = '';
  2429. $sFileSrcKeyDefault = 'src';
  2430. if(count($aFiles) == 1) {
  2431. $sDisplay = 'single';
  2432. $sFileSrcKey = $bViewItem ? 'src_orig' : 'src_medium';
  2433. }
  2434. else {
  2435. $sDisplay = 'gallery';
  2436. $sFileSrcKey = 'src';
  2437. }
  2438. foreach($aFiles as $aFile) {
  2439. $sFileSrc = !empty($aFile[$sFileSrcKey]) ? $aFile[$sFileSrcKey] : $aFile[$sFileSrcKeyDefault];
  2440. if(empty($sFileSrc))
  2441. continue;
  2442. $aAttrs = ['target' => '_blank'];
  2443. if(isset($aFile['onclick']))
  2444. $aAttrs['onclick'] = $aFile['onclick'];
  2445. else if(!$bViewItem && !empty($aFile['src_orig']))
  2446. $aAttrs['onclick'] = 'return ' . $sJsObject . '.showItem(this, \'' . $aEvent['id'] . '\', \'file\', ' . json_encode(array('src' => base64_encode($aFile['src_orig']))) . ')';
  2447. if(isset($aFile['title']))
  2448. $aAttrs['title'] = $aFile['title'];
  2449. $sAttrs = '';
  2450. foreach($aAttrs as $sKey => $sValue)
  2451. $sAttrs .= ' ' . $sKey . '="' . bx_html_attribute($sValue) . '"';
  2452. $aTmplVarsFiles[] = [
  2453. 'style_prefix' => $sStylePrefix,
  2454. 'class' => '',
  2455. 'item' => $this->parseHtmlByName('file_link.html', [
  2456. 'href' => isset($aFile['url']) ? $aFile['url'] : 'javascript:void(0)',
  2457. 'attrs' => $sAttrs,
  2458. 'icon_src' => $sFileSrc,
  2459. 'icon_class' => $sStylePrefix . '-item-file'
  2460. ])
  2461. ];
  2462. }
  2463. return array(
  2464. 'display' => $sDisplay,
  2465. 'total' => $iTotal,
  2466. 'items' => $aTmplVarsFiles
  2467. );
  2468. }
  2469. protected function _getSystemData(&$aEvent, $aBrowseParams = array())
  2470. {
  2471. $mixedResult = $this->_oConfig->getSystemData($aEvent, $aBrowseParams);
  2472. if($mixedResult === false) {
  2473. $sMethod = 'display' . bx_gen_method_name($aEvent['type'] . '_' . $aEvent['action']);
  2474. if(method_exists($this, $sMethod))
  2475. $mixedResult = $this->$sMethod($aEvent);
  2476. }
  2477. if($mixedResult === false)
  2478. return '';
  2479. $this->_preparetDataActions($aEvent, $mixedResult);
  2480. return $mixedResult;
  2481. }
  2482. protected function _getCommonData(&$aEvent, $aBrowseParams = array())
  2483. {
  2484. $CNF = $this->_oConfig->CNF;
  2485. $oModule = $this->getModule();
  2486. $sJsObject = $this->_oConfig->getJsObjectView($aBrowseParams);
  2487. $sPrefix = $this->_oConfig->getPrefix('common_post');
  2488. $sType = str_replace($sPrefix, '', $aEvent['type']);
  2489. $oObjectOwner = BxDolProfile::getInstanceMagic($aEvent['object_id']);
  2490. $iOwnerId = $aEvent['owner_id'];
  2491. if(is_array($aEvent['owner_id']))
  2492. $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']);
  2493. $aResult = array(
  2494. 'owner_id' => $iOwnerId,
  2495. 'object_owner_id' => $aEvent['object_id'],
  2496. 'icon' => $CNF['ICON'],
  2497. 'sample' => '_bx_timeline_txt_sample_with_article',
  2498. 'sample_wo_article' => '_bx_timeline_txt_sample',
  2499. 'sample_action' => '_bx_timeline_txt_added_sample',
  2500. 'content_type' => $sType,
  2501. 'content' => array(
  2502. 'sample' => '_bx_timeline_txt_sample_with_article',
  2503. 'sample_wo_article' => '_bx_timeline_txt_sample',
  2504. 'sample_action' => '_bx_timeline_txt_added_sample',
  2505. 'url' => $this->_oConfig->getItemViewUrl($aEvent)
  2506. ), //a string to display or array to parse default template before displaying.
  2507. 'views' => '',
  2508. 'votes' => '',
  2509. 'reactions' => '',
  2510. 'scores' => '',
  2511. 'reports' => '',
  2512. 'comments' => '',
  2513. 'title' => $aEvent['title'], //may be empty.
  2514. 'description' => bx_replace_markers($aEvent['description'], array(
  2515. 'profile_name' => $oObjectOwner->getDisplayName()
  2516. )) //may be empty.
  2517. );
  2518. switch($sType) {
  2519. case BX_TIMELINE_PARSE_TYPE_POST:
  2520. if(!empty($aEvent['content']))
  2521. $aResult['content'] = array_merge($aResult['content'], unserialize($aEvent['content']));
  2522. $aResult['content']['links'] = $oModule->getEventLinks($aEvent['id']);
  2523. $aResult['content']['images_attach'] = $oModule->getEventImages($aEvent['id']);
  2524. $aResult['content']['videos_attach'] = $oModule->getEventVideos($aEvent['id']);
  2525. $aResult['content']['files_attach'] = $oModule->getEventFiles($aEvent['id']);
  2526. break;
  2527. case BX_TIMELINE_PARSE_TYPE_REPOST:
  2528. if(empty($aEvent['content']))
  2529. return array();
  2530. $aContent = unserialize($aEvent['content']);
  2531. if(!$this->_oConfig->isSystem($aContent['type'] , $aContent['action'])) {
  2532. $aEventReposted = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $aContent['object_id']));
  2533. $aReposted = $this->_getCommonData($aEventReposted, $aBrowseParams);
  2534. }
  2535. else {
  2536. $aEventReposted = $this->_oDb->getEvents(array_merge(array('browse' => 'descriptor'), $aContent));
  2537. $aReposted = $this->_getSystemData($aEventReposted, $aBrowseParams);
  2538. }
  2539. if(empty($aReposted) || !is_array($aReposted))
  2540. return array();
  2541. $aEventReposted['content'] = $aReposted['content'];
  2542. $aResult['content'] = array_merge($aContent, $aReposted['content']);
  2543. $aResult['content']['parse_type'] = !empty($aReposted['content_type']) ? $aReposted['content_type'] : BX_TIMELINE_PARSE_TYPE_DEFAULT;
  2544. $sKey = 'allowed_view';
  2545. $aResult['content'][$sKey] = $this->_preparePrivacy($sKey, $aEventReposted, $aReposted);
  2546. $oObjectOwner = $oModule->getObjectUser($aReposted['object_owner_id']);
  2547. $aResult['content']['owner_id'] = $aReposted['object_owner_id'];
  2548. $aResult['content']['owner_name'] = $oObjectOwner->getDisplayName();
  2549. $aResult['content']['owner_url'] = $oObjectOwner->getUrl();
  2550. if(!empty($aReposted['sample']))
  2551. $aResult['content']['sample'] = $aReposted['sample'];
  2552. if(!empty($aReposted['sample_wo_article']))
  2553. $aResult['content']['sample'] = $aReposted['sample_wo_article'];
  2554. $sUserName = $oModule->getObjectUser($aEvent['object_id'])->getDisplayName();
  2555. $aResult['title'] = _t('_bx_timeline_txt_user_repost', $sUserName, _t($aResult['content']['sample']));
  2556. $aResult['description'] = _t('_bx_timeline_txt_user_reposted_user_sample', $sUserName, $aResult['content']['owner_name'], _t($aResult['content']['sample']));
  2557. $aResult['allowed_view'] = array(
  2558. 'module' => $this->_oConfig->getName(),
  2559. 'method' => 'get_timeline_repost_allowed_view',
  2560. );
  2561. if(!$this->_oConfig->isRepostOwnActions()) {
  2562. $aResult['views'] = $aReposted['views'];
  2563. $aResult['votes'] = $aReposted['votes'];
  2564. $aResult['reactions'] = $aReposted['reactions'];
  2565. $aResult['scores'] = $aReposted['scores'];
  2566. $aResult['reports'] = $aReposted['reports'];
  2567. $aResult['comments'] = $aReposted['comments'];
  2568. }
  2569. break;
  2570. }
  2571. $this->_preparetDataActions($aEvent, $aResult);
  2572. return $aResult;
  2573. }
  2574. protected function _getFirst($aEvents, $aParams = array())
  2575. {
  2576. $CNF = $this->_oConfig->CNF;
  2577. foreach($aEvents as $aEvent)
  2578. if((int)$aEvent[$CNF['FIELD_STICKED']] == 0)
  2579. return (int)$aEvent[$CNF['FIELD_ID']];
  2580. $aParams['start'] += $aParams['per_page'];
  2581. $aEvents = $this->_oDb->getEvents($aParams);
  2582. if(!empty($aEvents) && is_array($aEvents))
  2583. return $this->_getFirst($aEvents, $aParams);
  2584. return 0;
  2585. }
  2586. protected function _preparetDataActions(&$aEvent, &$aResult)
  2587. {
  2588. if(empty($aEvent) || !is_array($aEvent) || empty($aEvent['id']))
  2589. return;
  2590. $oModule = $this->getModule();
  2591. $sSystem = $this->_oConfig->getObject('view');
  2592. if(empty($aResult['views'])) {
  2593. $aResult['views'] = array();
  2594. if($oModule->getViewObject($sSystem, $aEvent['id']) !== false)
  2595. $aResult['views'] = array(
  2596. 'system' => $sSystem,
  2597. 'object_id' => $aEvent['id'],
  2598. 'count' => $aEvent['views']
  2599. );
  2600. }
  2601. $sSystem = $this->_oConfig->getObject('vote');
  2602. if(empty($aResult['votes'])) {
  2603. $aResult['votes'] = array();
  2604. if($oModule->getVoteObject($sSystem, $aEvent['id']) !== false)
  2605. $aResult['votes'] = array(
  2606. 'system' => $sSystem,
  2607. 'object_id' => $aEvent['id'],
  2608. 'count' => $aEvent['votes']
  2609. );
  2610. }
  2611. $sSystem = $this->_oConfig->getObject('reaction');
  2612. if(empty($aResult['reactions'])) {
  2613. $aResult['reactions'] = array();
  2614. if($oModule->getReactionObject($sSystem, $aEvent['id']) !== false)
  2615. $aResult['reactions'] = array(
  2616. 'system' => $sSystem,
  2617. 'object_id' => $aEvent['id'],
  2618. 'count' => $aEvent['rvotes']
  2619. );
  2620. }
  2621. $sSystem = $this->_oConfig->getObject('score');
  2622. if(empty($aResult['scores'])) {
  2623. $aResult['scores'] = array();
  2624. if($oModule->getScoreObject($sSystem, $aEvent['id']) !== false)
  2625. $aResult['scores'] = array(
  2626. 'system' => $sSystem,
  2627. 'object_id' => $aEvent['id'],
  2628. 'score' => $aEvent['score']
  2629. );
  2630. }
  2631. $sSystem = $this->_oConfig->getObject('report');
  2632. if(empty($aResult['reports'])) {
  2633. $aResult['reports'] = array();
  2634. if($oModule->getReportObject($sSystem, $aEvent['id']) !== false)
  2635. $aResult['reports'] = array(
  2636. 'system' => $sSystem,
  2637. 'object_id' => $aEvent['id'],
  2638. 'count' => $aEvent['reports']
  2639. );
  2640. }
  2641. $sSystem = $this->_oConfig->getObject('comment');
  2642. if(empty($aResult['comments'])) {
  2643. $aResult['comments'] = array();
  2644. if($oModule->getCmtsObject($sSystem, $aEvent['id']) !== false)
  2645. $aResult['comments'] = array(
  2646. 'system' => $sSystem,
  2647. 'object_id' => $aEvent['id'],
  2648. 'count' => $aEvent['comments']
  2649. );
  2650. }
  2651. }
  2652. protected function _prepareTextForOutputBriefCard($s, $iEventId = 0)
  2653. {
  2654. $s = strip_tags($s, $this->_oConfig->getBriefCardsTags(true));
  2655. return $this->_prepareTextForOutput($s, $iEventId = 0);
  2656. }
  2657. protected function _prepareTextForOutput($s, $iEventId = 0)
  2658. {
  2659. $s = bx_process_output($s, BX_DATA_HTML);
  2660. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  2661. $s = $oMetatags->metaParse($iEventId, $s);
  2662. return $s;
  2663. }
  2664. protected function _preparePrivacy($sKey, $aEvent, $aEventData)
  2665. {
  2666. $iResult = CHECK_ACTION_RESULT_ALLOWED;
  2667. if(isset($aEventData[$sKey], $aEventData[$sKey]['module'], $aEventData[$sKey]['method']))
  2668. $iResult = BxDolService::call($aEventData[$sKey]['module'], $aEventData[$sKey]['method'], array($aEvent));
  2669. else if(($aHandler = $this->_oConfig->getHandler($aEvent)) !== false && BxDolRequest::serviceExists($aHandler['module_name'], 'get_timeline_post_allowed_view'))
  2670. $iResult = BxDolService::call($aHandler['module_name'], 'get_timeline_post_allowed_view', array($aEvent));
  2671. return $iResult;
  2672. }
  2673. protected function _getCounterIcon($aParams = array())
  2674. {
  2675. return $this->parseHtmlByName('repost_counter_icon.html', []);
  2676. }
  2677. protected function _getCounterLabel($iCount, $aParams = array())
  2678. {
  2679. return _t(isset($aParams['caption']) ? $aParams['caption'] : '_bx_timeline_txt_repost_counter', $iCount);
  2680. }
  2681. }
  2682. /** @} */