BxTimelineTemplate.php 109 KB

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