BxTimelineTemplate.php 126 KB

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