BxTimelineTemplate.php 105 KB

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