BxTimelineTemplate.php 144 KB

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