BxTimelineTemplate.php 148 KB

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