BxTimelineTemplate.php 124 KB

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