BxTimelineTemplate.php 150 KB

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