BxTimelineTemplate.php 89 KB

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