BxTimelineTemplate.php 133 KB

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