BxTimelineTemplate.php 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  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 $_bShowTimelineDividers;
  14. function __construct(&$oConfig, &$oDb)
  15. {
  16. parent::__construct($oConfig, $oDb);
  17. $this->_bShowTimelineDividers = false;
  18. }
  19. public function getCssJs()
  20. {
  21. parent::getCssJs();
  22. $this->addCss(array(
  23. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flickity/|flickity.css',
  24. 'jquery-ui/jquery-ui.css',
  25. 'post.css',
  26. 'repost.css',
  27. ));
  28. $this->addJs(array(
  29. 'jquery-ui/jquery-ui.custom.min.js',
  30. 'jquery.form.min.js',
  31. 'jquery.ba-resize.min.js',
  32. 'autosize.min.js',
  33. 'masonry.pkgd.min.js',
  34. 'modernizr.js',
  35. 'flickity/flickity.pkgd.min.js',
  36. 'post.js',
  37. 'repost.js',
  38. ));
  39. }
  40. public function getPostBlock($iOwnerId)
  41. {
  42. $aForm = $this->getModule()->getFormPost();
  43. return $this->parseHtmlByName('block_post.html', array (
  44. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  45. 'js_object' => $this->_oConfig->getJsObject('post'),
  46. 'js_content' => $this->getJsCode('post', array(
  47. 'oRequestParams' => array('owner_id' => $iOwnerId)
  48. )),
  49. 'form' => $aForm['form']
  50. ));
  51. }
  52. public function getViewBlock($aParams)
  53. {
  54. list($sContent, $sLoadMore, $sBack, $sEmpty) = $this->getPosts($aParams);
  55. return $this->parseHtmlByName('block_view.html', array(
  56. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  57. 'html_id' => $this->_oConfig->getHtmlIds('view', 'main_' . $aParams['view']),
  58. 'view' => $aParams['view'],
  59. 'back' => $sBack,
  60. 'empty' => $sEmpty,
  61. 'content' => $sContent,
  62. 'load_more' => $sLoadMore,
  63. 'view_image_popup' => $this->_getImagePopup($aParams),
  64. 'js_content' => $this->getJsCode('view', array(
  65. 'oRequestParams' => array(
  66. 'type' => $aParams['type'],
  67. 'owner_id' => $aParams['owner_id'],
  68. 'start' => $aParams['start'],
  69. 'per_page' => $aParams['per_page'],
  70. 'filter' => $aParams['filter'],
  71. 'modules' => $aParams['modules'],
  72. 'timeline' => $aParams['timeline'],
  73. )
  74. )) . $this->getJsCode('repost')
  75. ));
  76. }
  77. public function getSearchBlock($sContent)
  78. {
  79. $oModule = $this->getModule();
  80. $aParams = $oModule->getParams(BX_TIMELINE_VIEW_SEARCH);
  81. return $this->parseHtmlByName('block_search.html', array(
  82. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  83. 'html_id' => $this->_oConfig->getHtmlIds('view', 'main_' . $aParams['view']),
  84. 'view' => $aParams['view'],
  85. 'content' => $sContent,
  86. 'view_image_popup' => $this->_getImagePopup($aParams),
  87. 'js_content' => $this->getJsCode('view', array(
  88. 'oRequestParams' => array(
  89. 'type' => $aParams['type'],
  90. 'owner_id' => $aParams['owner_id'],
  91. 'start' => $aParams['start'],
  92. 'per_page' => $aParams['per_page'],
  93. 'filter' => $aParams['filter'],
  94. 'modules' => $aParams['modules'],
  95. 'timeline' => $aParams['timeline'],
  96. )
  97. ))
  98. ));
  99. }
  100. public function getItemBlock($iId)
  101. {
  102. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  103. if(empty($aEvent))
  104. return '';
  105. $aParams = array(
  106. 'view' => BX_TIMELINE_VIEW_DEFAULT,
  107. 'type' => BX_TIMELINE_TYPE_ITEM
  108. );
  109. $sContent = $this->getPost($aEvent, $aParams);
  110. $oModule = $this->getModule();
  111. if($oModule->isAllowedViewCounter($aEvent) !== true)
  112. return '';
  113. if(!$this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  114. $mixedViews = $oModule->getViewsData($aEvent['views']);
  115. if($mixedViews !== false) {
  116. list($sSystem, $iObjectId) = $mixedViews;
  117. $oModule->getViewObject($sSystem, $iObjectId)->doView();
  118. }
  119. }
  120. return $this->parseHtmlByName('block_item.html', array(
  121. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  122. 'html_id' => $this->_oConfig->getHtmlIds('view', 'main_item'),
  123. 'content' => $sContent,
  124. 'view_image_popup' => $this->_getImagePopup($aParams),
  125. 'js_content' => $this->getJsCode('view')
  126. ));
  127. }
  128. public function getUnit(&$aEvent, $aBrowseParams = array())
  129. {
  130. $oModule = $this->getModule();
  131. if(empty($aBrowseParams) || !is_array($aBrowseParams))
  132. $aBrowseParams = $oModule->getParams(BX_TIMELINE_VIEW_SEARCH);
  133. return $this->getPost($aEvent, $aBrowseParams);
  134. }
  135. public function getPost(&$aEvent, $aBrowseParams = array())
  136. {
  137. $aResult = $this->getData($aEvent);
  138. if($aResult === false)
  139. return '';
  140. $aEvent['object_owner_id'] = $aResult['owner_id'];
  141. $aEvent['icon'] = !empty($aResult['icon']) ? $aResult['icon'] : '';
  142. $aEvent['sample'] = !empty($aResult['sample']) ? $aResult['sample'] : '_bx_timeline_txt_sample';
  143. $aEvent['sample_action'] = !empty($aResult['sample_action']) ? $aResult['sample_action'] : '_bx_timeline_txt_added_sample';
  144. $aEvent['content'] = $aResult['content'];
  145. $aEvent['views'] = $aResult['views'];
  146. $aEvent['votes'] = $aResult['votes'];
  147. $aEvent['reports'] = $aResult['reports'];
  148. $aEvent['comments'] = $aResult['comments'];
  149. $sType = !empty($aResult['content_type']) ? $aResult['content_type'] : BX_TIMELINE_PARSE_TYPE_DEFAULT;
  150. return $this->_getPost($sType, $aEvent, $aBrowseParams);
  151. }
  152. public function getPosts($aParams)
  153. {
  154. $bViewTimeline = $aParams['view'] == BX_TIMELINE_VIEW_TIMELINE;
  155. $iStart = $aParams['start'];
  156. $iPerPage = $aParams['per_page'];
  157. $aParamsDb = $aParams;
  158. //--- Check for Previous
  159. $iDays = -1;
  160. $bPrevious = false;
  161. if($iStart - 1 >= 0) {
  162. $aParamsDb['start'] -= 1;
  163. $aParamsDb['per_page'] += 1;
  164. $bPrevious = true;
  165. }
  166. //--- Check for Next
  167. $aParamsDb['per_page'] += 1;
  168. $aEvents = $this->_oDb->getEvents($aParamsDb);
  169. //--- Check for Previous
  170. if($bPrevious) {
  171. $aEvent = array_shift($aEvents);
  172. $iDays = (int)$aEvent['days'];
  173. }
  174. //--- Check for Next
  175. $bNext = false;
  176. if(count($aEvents) > $iPerPage) {
  177. $aEvent = array_pop($aEvents);
  178. $bNext = true;
  179. }
  180. $iEvents = count($aEvents);
  181. $sContent = '';
  182. if($bViewTimeline && $iEvents <= 0)
  183. $sContent .= $this->getDividerToday();
  184. $bFirst = true;
  185. foreach($aEvents as $aEvent) {
  186. $sEvent = $this->getPost($aEvent, $aParams);
  187. $bEvent = !empty($sEvent);
  188. if(!$bEvent)
  189. continue;
  190. if($bViewTimeline && $bFirst) {
  191. $sContent .= $this->getDividerToday($aEvent);
  192. $bFirst = false;
  193. }
  194. $sContent .= $bViewTimeline && $bEvent ? $this->getDivider($iDays, $aEvent) : '';
  195. $sContent .= $sEvent;
  196. }
  197. $sBack = $this->getBack($aParams);
  198. $sLoadMore = $this->getLoadMore($aParams, $bNext, $iEvents > 0);
  199. $sEmpty = $this->getEmpty($iEvents <= 0);
  200. return array($sContent, $sLoadMore, $sBack, $sEmpty);
  201. }
  202. public function getEmpty($bVisible)
  203. {
  204. return $this->parseHtmlByName('empty.html', array(
  205. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  206. 'visible' => $bVisible ? 'block' : 'none',
  207. 'content' => MsgBox(_t('_bx_timeline_txt_msg_no_results'))
  208. ));
  209. }
  210. public function getDivider(&$iDays, &$aEvent)
  211. {
  212. if(!$this->_bShowTimelineDividers || $iDays == $aEvent['days'])
  213. return '';
  214. $iDays = $aEvent['days'];
  215. $iDaysAgo = (int)$aEvent['ago_days'];
  216. if($aEvent['today'] == $aEvent['days'] || (($aEvent['today'] - $aEvent['days']) == 1 && $iDaysAgo == 0))
  217. return '';
  218. return $this->parseHtmlByName('divider.html', array(
  219. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  220. 'type' => 'common',
  221. 'bx_if:show_hidden' => array(
  222. 'condition' => false,
  223. 'content' => array()
  224. ),
  225. 'content' => bx_time_js($aEvent['date'])
  226. ));
  227. }
  228. public function getDividerToday($aEvent = array())
  229. {
  230. if(!$this->_bShowTimelineDividers)
  231. return '';
  232. $bToday = !empty($aEvent) && ($aEvent['today'] == $aEvent['days'] || (($aEvent['today'] - $aEvent['days']) == 1 && (int)$aEvent['ago_days'] == 0));
  233. return $this->parseHtmlByName('divider.html', array(
  234. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  235. 'type' => 'today',
  236. 'bx_if:show_hidden' => array(
  237. 'condition' => !$bToday,
  238. 'content' => array()
  239. ),
  240. 'content' => _t('_bx_timeline_txt_today')
  241. ));
  242. }
  243. public function getBack($aParams)
  244. {
  245. $iYearSel = (int)$aParams['timeline'];
  246. if($iYearSel == 0)
  247. return '';
  248. $sStylePrefix = $this->_oConfig->getPrefix('style');
  249. $sJsObject = $this->_oConfig->getJsObject('view');
  250. $iYearNow = date('Y', time());
  251. return $this->parseHtmlByName('back.html', array(
  252. 'style_prefix' => $sStylePrefix,
  253. 'href' => 'javascript:void(0)',
  254. 'title' => _t('_bx_timeline_txt_jump_to_n_year', $iYearNow),
  255. 'bx_repeat:attrs' => array(
  256. array('key' => 'onclick', 'value' => 'javascript:' . $sJsObject . '.changeTimeline(this, 0)')
  257. ),
  258. 'content' => _t('_bx_timeline_txt_jump_to_recent')
  259. ));
  260. }
  261. public function getLoadMore($aParams, $bEnabled, $bVisible = true)
  262. {
  263. $iStart = $aParams['start'];
  264. $iPerPage = $aParams['per_page'];
  265. $iYearSel = (int)$aParams['timeline'];
  266. $iYearMin = $this->_oDb->getMaxDuration($aParams);
  267. $sStylePrefix = $this->_oConfig->getPrefix('style');
  268. $sJsObject = $this->_oConfig->getJsObject('view');
  269. $sYears = '';
  270. if(!empty($iYearMin)) {
  271. $iYearMax = date('Y', time()) - 1;
  272. for($i = $iYearMax; $i >= $iYearMin; $i--)
  273. $sYears .= ($i != $iYearSel ? $this->parseHtmlByName('bx_a.html', array(
  274. 'href' => 'javascript:void(0)',
  275. 'title' => _t('_bx_timeline_txt_jump_to_n_year', $i),
  276. 'bx_repeat:attrs' => array(
  277. array('key' => 'onclick', 'value' => 'javascript:' . $sJsObject . '.changeTimeline(this, ' . $i . ')')
  278. ),
  279. 'content' => $i
  280. )) : $i) . ', ';
  281. $sYears = substr($sYears, 0, -2);
  282. }
  283. $aTmplVars = array(
  284. 'style_prefix' => $sStylePrefix,
  285. 'visible' => ($aParams['view'] == BX_TIMELINE_VIEW_TIMELINE && $bVisible) || ($aParams['view'] == BX_TIMELINE_VIEW_OUTLINE && $bEnabled && $bVisible) ? 'block' : 'none',
  286. 'bx_if:is_disabled' => array(
  287. 'condition' => !$bEnabled,
  288. 'content' => array()
  289. ),
  290. 'bx_if:show_on_click' => array(
  291. 'condition' => $bEnabled,
  292. 'content' => array(
  293. 'on_click' => 'javascript:' . $sJsObject . '.changePage(this, ' . ($iStart + $iPerPage) . ', ' . $iPerPage . ')'
  294. )
  295. ),
  296. 'bx_if:show_jump_to' => array(
  297. 'condition' => !empty($sYears),
  298. 'content' => array(
  299. 'style_prefix' => $sStylePrefix,
  300. 'years' => $sYears
  301. )
  302. )
  303. );
  304. return $this->parseHtmlByName('load_more.html', $aTmplVars);
  305. }
  306. public function getComments($sSystem, $iId)
  307. {
  308. $oModule = $this->getModule();
  309. $sStylePrefix = $this->_oConfig->getPrefix('style');
  310. $oCmts = $oModule->getCmtsObject($sSystem, $iId);
  311. if($oCmts === false)
  312. return '';
  313. $aComments = $oCmts->getCommentsBlock(0, 0, false);
  314. return $this->parseHtmlByName('comments.html', array(
  315. 'style_prefix' => $sStylePrefix,
  316. 'id' => $iId,
  317. 'content' => $aComments['content']
  318. ));
  319. }
  320. public function getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  321. {
  322. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  323. if(empty($aReposted) || !is_array($aReposted))
  324. return '';
  325. $oModule = $this->getModule();
  326. $bDisabled = $oModule->isAllowedRepost($aReposted) !== true || $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $oModule->getUserId());
  327. if($bDisabled && (int)$aReposted['reposts'] == 0)
  328. return '';
  329. $sStylePrefix = $this->_oConfig->getPrefix('style');
  330. $sStylePrefixRepost = $sStylePrefix . '-repost-';
  331. $bShowDoRepostAsButtonSmall = isset($aParams['show_do_repost_as_button_small']) && $aParams['show_do_repost_as_button_small'] == true;
  332. $bShowDoRepostAsButton = !$bShowDoRepostAsButtonSmall && isset($aParams['show_do_repost_as_button']) && $aParams['show_do_repost_as_button'] == true;
  333. $bShowDoRepostIcon = isset($aParams['show_do_repost_icon']) && $aParams['show_do_repost_icon'] == true;
  334. $bShowDoRepostLabel = isset($aParams['show_do_repost_label']) && $aParams['show_do_repost_label'] == true;
  335. $bShowCounter = isset($aParams['show_counter']) && $aParams['show_counter'] === true;
  336. //--- Do repost link ---//
  337. $sClass = $sStylePrefixRepost . 'do-repost';
  338. if($bShowDoRepostAsButton)
  339. $sClass .= ' bx-btn';
  340. else if($bShowDoRepostAsButtonSmall)
  341. $sClass .= ' bx-btn bx-btn-small';
  342. $sOnClick = '';
  343. if(!$bDisabled) {
  344. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  345. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  346. $aRepostedData = $this->_getCommonData($aReposted);
  347. $sOnClick = $this->_getRepostJsClick($iOwnerId, $aRepostedData['content']['type'], $aRepostedData['content']['action'], $aRepostedData['content']['object_id']);
  348. }
  349. else
  350. $sOnClick = $this->_getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  351. }
  352. else
  353. $sClass .= $bShowDoRepostAsButton || $bShowDoRepostAsButtonSmall ? ' bx-btn-disabled' : ' ' . $sStylePrefixRepost . 'disabled';
  354. $aOnClickAttrs = array();
  355. if(!empty($sClass))
  356. $aOnClickAttrs[] = array('key' => 'class', 'value' => $sClass);
  357. if(!empty($sOnClick))
  358. $aOnClickAttrs[] = array('key' => 'onclick', 'value' => $sOnClick);
  359. $sDoRepost = '';
  360. if($bShowDoRepostIcon)
  361. $sDoRepost .= $this->parseHtmlByName('bx_icon.html', array('name' => 'repeat'));
  362. if($bShowDoRepostLabel)
  363. $sDoRepost .= ($sDoRepost != '' ? ' ' : '') . _t('_bx_timeline_txt_do_repost');
  364. return $this->parseHtmlByName('repost_element_block.html', array(
  365. 'style_prefix' => $sStylePrefix,
  366. 'html_id' => $this->_oConfig->getHtmlIds('repost', 'main') . $aReposted['id'],
  367. 'class' => ($bShowDoRepostAsButton ? $sStylePrefixRepost . 'button' : '') . ($bShowDoRepostAsButtonSmall ? $sStylePrefixRepost . 'button-small' : ''),
  368. 'count' => $aReposted['reposts'],
  369. 'do_repost' => $this->parseHtmlByName('bx_a.html', array(
  370. 'href' => 'javascript:void(0)',
  371. 'title' => _t('_bx_timeline_txt_do_repost'),
  372. 'bx_repeat:attrs' => $aOnClickAttrs,
  373. 'content' => $sDoRepost
  374. )),
  375. 'bx_if:show_counter' => array(
  376. 'condition' => $bShowCounter,
  377. 'content' => array(
  378. 'style_prefix' => $sStylePrefix,
  379. 'bx_if:show_hidden' => array(
  380. 'condition' => (int)$aReposted['reposts'] == 0,
  381. 'content' => array()
  382. ),
  383. 'counter' => $this->getRepostCounter($aReposted, $aParams)
  384. )
  385. ),
  386. 'script' => $this->getRepostJsScript()
  387. ));
  388. }
  389. public function getRepostCounter($aEvent, $aParams = array())
  390. {
  391. $sStylePrefix = $this->_oConfig->getPrefix('style');
  392. $sJsObject = $this->_oConfig->getJsObject('repost');
  393. $bShowDoRepostAsButtonSmall = isset($aParams['show_do_repost_as_button_small']) && $aParams['show_do_repost_as_button_small'] == true;
  394. $bShowDoRepostAsButton = !$bShowDoRepostAsButtonSmall && isset($aParams['show_do_repost_as_button']) && $aParams['show_do_repost_as_button'] == true;
  395. $sClass = $sStylePrefix . '-repost-counter';
  396. if($bShowDoRepostAsButtonSmall)
  397. $sClass .= ' bx-btn-small-height';
  398. if($bShowDoRepostAsButton)
  399. $sClass .= ' bx-btn-height';
  400. return $this->parseHtmlByName('repost_counter.html', array(
  401. 'href' => 'javascript:void(0)',
  402. 'title' => _t('_bx_timeline_txt_reposted_by'),
  403. 'bx_repeat:attrs' => array(
  404. array('key' => 'id', 'value' => $this->_oConfig->getHtmlIds('repost', 'counter') . $aEvent['id']),
  405. array('key' => 'class', 'value' => $sClass),
  406. array('key' => 'onclick', 'value' => 'javascript:' . $sJsObject . '.toggleByPopup(this, ' . $aEvent['id'] . ')')
  407. ),
  408. 'content' => !empty($aEvent['reposts']) && (int)$aEvent['reposts'] > 0 ? $aEvent['reposts'] : ''
  409. ));
  410. }
  411. public function getRepostedBy($iId)
  412. {
  413. $aTmplUsers = array();
  414. $oModule = $this->getModule();
  415. $sStylePrefix = $this->_oConfig->getPrefix('style');
  416. $aUserIds = $this->_oDb->getRepostedBy($iId);
  417. foreach($aUserIds as $iUserId) {
  418. list($sUserName, $sUserUrl, $sUserIcon, $sUserUnit) = $oModule->getUserInfo($iUserId);
  419. $aTmplUsers[] = array(
  420. 'style_prefix' => $sStylePrefix,
  421. 'user_unit' => $sUserUnit
  422. );
  423. }
  424. if(empty($aTmplUsers))
  425. $aTmplUsers = MsgBox(_t('_Empty'));
  426. return $this->parseHtmlByName('repost_by_list.html', array(
  427. 'style_prefix' => $sStylePrefix,
  428. 'bx_repeat:list' => $aTmplUsers
  429. ));
  430. }
  431. public function getRepostJsScript()
  432. {
  433. $this->addCss(array('repost.css'));
  434. $this->addJs(array('main.js', 'repost.js'));
  435. return $this->getJsCode('repost');
  436. }
  437. public function getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  438. {
  439. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  440. if(empty($aReposted) || !is_array($aReposted))
  441. return '';
  442. $sResult = '';
  443. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  444. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  445. $aRepostedData = $this->_getCommonData($aReposted);
  446. $sResult = $this->_getRepostJsClick($iOwnerId, $aRepostedData['content']['type'], $aRepostedData['content']['action'], $aRepostedData['content']['object_id']);
  447. }
  448. else
  449. $sResult = $this->_getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  450. return $sResult;
  451. }
  452. public function getAttachLinkForm()
  453. {
  454. $sStylePrefix = $this->_oConfig->getPrefix('style');
  455. $sJsObject = $this->_oConfig->getJsObject('post');
  456. $aForm = $this->getModule()->getFormAttachLink();
  457. return $this->parseHtmlByName('attach_link_form.html', array(
  458. 'style_prefix' => $sStylePrefix,
  459. 'js_object' => $sJsObject,
  460. 'form_id' => $aForm['form_id'],
  461. 'form' => $aForm['form'],
  462. ));
  463. }
  464. public function getAttachLinkField($iUserId)
  465. {
  466. $sStylePrefix = $this->_oConfig->getPrefix('style');
  467. $aLinks = $this->_oDb->getUnusedLinks($iUserId);
  468. $sLinks = '';
  469. foreach($aLinks as $aLink)
  470. $sLinks .= $this->getAttachLinkItem($iUserId, $aLink);
  471. return $this->parsePageByName('attach_link_form_field.html', array(
  472. 'html_id' => $this->_oConfig->getHtmlIds('post', 'attach_link_form_field'),
  473. 'style_prefix' => $sStylePrefix,
  474. 'links' => $sLinks
  475. ));
  476. }
  477. public function getAttachLinkItem($iUserId, $mixedLink)
  478. {
  479. $aLink = is_array($mixedLink) ? $mixedLink : $this->_oDb->getUnusedLinks($iUserId, (int)$mixedLink);
  480. if(empty($aLink) || !is_array($aLink))
  481. return '';
  482. $sStylePrefix = $this->_oConfig->getPrefix('style');
  483. $sJsObject = $this->_oConfig->getJsObject('post');
  484. $sLinkIdPrefix = $this->_oConfig->getHtmlIds('post', 'attach_link_item');
  485. $bTmplVarsEmbed = false;
  486. $aTmplVarsEmbed = array();
  487. $sEmbedlyKey = $this->_oDb->getParam('sys_embedly_api_key');
  488. $sEmbedlyPattern = $this->_oDb->getParam('sys_embedly_api_pattern');
  489. if(!empty($sEmbedlyKey) && !empty($sEmbedlyPattern) && preg_match($sEmbedlyPattern, $aLink['url'])) {
  490. $bTmplVarsEmbed = true;
  491. $aTmplVarsEmbed = array(
  492. 'style_prefix' => $sStylePrefix,
  493. 'embed' => $this->parsePageByName('bx_a.html', array(
  494. 'href' => $aLink['url'],
  495. 'title' => bx_html_attribute($aLink['title']),
  496. 'bx_repeat:attrs' => array(
  497. array('key' => 'class', 'value' => 'bx-link-embed')
  498. ),
  499. 'content' => $aLink['title'],
  500. ))
  501. );
  502. }
  503. else {
  504. $aLinkAttrs = array();
  505. if(!$this->_oConfig->isEqualUrls(BX_DOL_URL_ROOT, $aLink['url'])) {
  506. $aLinkAttrs[] = array('key' => 'target', 'value' => '_blank');
  507. if($this->_oDb->getParam('sys_add_nofollow') == 'on')
  508. $aLinkAttrs[] = array('key' => 'rel', 'value' => 'nofollow');
  509. }
  510. $sThumbnail = "";
  511. if((int)$aLink['media_id'] != 0)
  512. $sThumbnail = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_preview'))->getFileUrl($aLink['media_id']);
  513. $aTmplVarsEmbed = array(
  514. 'style_prefix' => $sStylePrefix,
  515. 'bx_if:show_thumbnail' => array(
  516. 'condition' => !empty($sThumbnail),
  517. 'content' => array(
  518. 'style_prefix' => $sStylePrefix,
  519. 'thumbnail' => $sThumbnail
  520. )
  521. ),
  522. 'url' => $aLink['url'],
  523. 'link' => $this->parsePageByName('bx_a.html', array(
  524. 'href' => $aLink['url'],
  525. 'title' => bx_html_attribute($aLink['title']),
  526. 'bx_repeat:attrs' => $aLinkAttrs,
  527. 'content' => $aLink['title'],
  528. ))
  529. );
  530. }
  531. return $this->parsePageByName('attach_link_item.html', array(
  532. 'html_id' => $sLinkIdPrefix . $aLink['id'],
  533. 'style_prefix' => $sStylePrefix,
  534. 'js_object' => $sJsObject,
  535. 'id' => $aLink['id'],
  536. 'bx_if:show_embed_outer' => array(
  537. 'condition' => $bTmplVarsEmbed,
  538. 'content' => $aTmplVarsEmbed
  539. ),
  540. 'bx_if:show_embed_inner' => array(
  541. 'condition' => !$bTmplVarsEmbed,
  542. 'content' => $aTmplVarsEmbed
  543. ),
  544. ));
  545. }
  546. public function getData(&$aEvent)
  547. {
  548. $aResult = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $this->_getSystemData($aEvent) : $this->_getCommonData($aEvent);
  549. if(empty($aResult) || empty($aResult['owner_id']) || empty($aResult['content']))
  550. return false;
  551. list($sUserName) = $this->getModule()->getUserInfo($aResult['owner_id']);
  552. $sSample = !empty($aResult['sample']) ? $aResult['sample'] : '_bx_timeline_txt_sample';
  553. if(empty($aEvent['title']) || empty($aEvent['description'])) {
  554. $sTitle = !empty($aResult['title']) ? $this->_oConfig->getTitle($aResult['title']) : _t($sSample);
  555. $sDescription = !empty($aResult['description']) ? $aResult['description'] : _t('_bx_timeline_txt_user_added_sample', $sUserName, _t($sSample));
  556. if($sDescription == '' && !empty($aResult['content']['text']))
  557. $sDescription = $aResult['content']['text'];
  558. $this->_oDb->updateEvent(array(
  559. 'title' => bx_process_input(strip_tags($sTitle)),
  560. 'description' => bx_process_input(strip_tags($sDescription))
  561. ), array('id' => $aEvent['id']));
  562. }
  563. return $aResult;
  564. }
  565. protected function _getPost($sType, $aEvent, $aBrowseParams = array())
  566. {
  567. $CNF = &$this->_oConfig->CNF;
  568. $oModule = $this->getModule();
  569. $sStylePrefix = $this->_oConfig->getPrefix('style');
  570. $sJsObject = $this->_oConfig->getJsObject('view');
  571. list($sAuthorName, $sAuthorUrl, $sAuthorIcon) = $oModule->getUserInfo($aEvent['object_owner_id']);
  572. $bAuthorIcon = !empty($sAuthorIcon);
  573. $aTmplVarsMenuItemActions = $this->_getTmplVarsMenuItemActions($aEvent, $aBrowseParams);
  574. $aTmplVarsTimelineOwner = array();
  575. if(isset($aBrowseParams['type']) && $aBrowseParams['type'] == BX_BASE_MOD_NTFS_TYPE_CONNECTIONS)
  576. $aTmplVarsTimelineOwner = $this->_getTmplVarsTimelineOwner($aEvent);
  577. $bBrowseItem = isset($aBrowseParams['type']) && $aBrowseParams['type'] == BX_TIMELINE_TYPE_ITEM;
  578. $bViewOutline = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_OUTLINE;
  579. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  580. $sLocation = $oMetatags->locationsString($aEvent['id']);
  581. $aTmplVars = array (
  582. 'style_prefix' => $sStylePrefix,
  583. 'js_object' => $sJsObject,
  584. 'html_id' => $this->_oConfig->getHtmlIds('view', 'item_' . $aBrowseParams['view']) . $aEvent['id'],
  585. 'class' => $bBrowseItem || !$bViewOutline ? 'bx-tl-view-sizer' : 'bx-tl-grid-sizer',
  586. 'class_content' => $bBrowseItem ? 'bx-def-color-bg-block' : 'bx-def-color-bg-box',
  587. 'id' => $aEvent['id'],
  588. 'bx_if:show_owner_icon' => array(
  589. 'condition' => $bAuthorIcon,
  590. 'content' => array(
  591. 'owner_icon' => $sAuthorIcon
  592. )
  593. ),
  594. 'bx_if:show_owner_icon_empty' => array(
  595. 'condition' => !$bAuthorIcon,
  596. 'content' => array()
  597. ),
  598. 'item_icon' => !empty($aEvent['icon']) ? $aEvent['icon'] : $CNF['ICON'],
  599. 'item_owner_url' => $sAuthorUrl,
  600. 'item_owner_title' => bx_html_attribute($sAuthorName),
  601. 'item_owner_name' => $sAuthorName,
  602. 'item_owner_action' => _t($aEvent['sample_action'], _t($aEvent['sample'])),
  603. 'bx_if:show_timeline_owner' => array(
  604. 'condition' => !empty($aTmplVarsTimelineOwner),
  605. 'content' => $aTmplVarsTimelineOwner
  606. ),
  607. 'item_view_url' => $this->_oConfig->getItemViewUrl($aEvent),
  608. 'item_date' => bx_time_js($aEvent['date']),
  609. 'bx_if:show_pinned' => array(
  610. 'condition' => (int)$aEvent['pinned'] != 0,
  611. 'content' => array(
  612. 'style_prefix' => $sStylePrefix,
  613. )
  614. ),
  615. 'content' => is_string($aEvent['content']) ? $aEvent['content'] : $this->_getContent($sType, $aEvent, $aBrowseParams),
  616. 'bx_if:show_location' => array(
  617. 'condition' => !empty($sLocation),
  618. 'content' => array(
  619. 'style_prefix' => $sStylePrefix,
  620. 'location' => $sLocation
  621. )
  622. ),
  623. 'bx_if:show_menu_item_actions' => array(
  624. 'condition' => !empty($aTmplVarsMenuItemActions),
  625. 'content' => $aTmplVarsMenuItemActions
  626. ),
  627. 'comments' => $bBrowseItem ? $this->_getComments($aEvent['comments']) : '',
  628. );
  629. return $this->parseHtmlByName('item_' . $aBrowseParams['view'] . '.html', $aTmplVars);
  630. }
  631. protected function _getContent($sType, $aEvent, $aBrowseParams = array())
  632. {
  633. $sMethod = '_getTmplVarsContent' . ucfirst($sType);
  634. if(!method_exists($this, $sMethod))
  635. return '';
  636. $aTmplVars = $this->$sMethod($aEvent, $aBrowseParams);
  637. return $this->parseHtmlByName('type_' . $sType . '.html', $aTmplVars);
  638. }
  639. protected function _getComments($aComments)
  640. {
  641. $mixedComments = $this->getModule()->getCommentsData($aComments);
  642. if($mixedComments === false)
  643. return '';
  644. list($sSystem, $iObjectId, $iCount) = $mixedComments;
  645. return $this->getComments($sSystem, $iObjectId);
  646. }
  647. protected function _getImagePopup($aParams)
  648. {
  649. $sViewImagePopupId = $this->_oConfig->getHtmlIds('view', 'photo_popup_' . $aParams['view']);
  650. $sViewImagePopupContent = $this->parseHtmlByName('popup_image.html', array(
  651. 'image_url' => ''
  652. ));
  653. return BxTemplFunctions::getInstance()->transBox($sViewImagePopupId, $sViewImagePopupContent, true);
  654. }
  655. protected function _getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  656. {
  657. $sJsObject = $this->_oConfig->getJsObject('repost');
  658. $sFormat = "%s.repostItem(this, %d, '%s', '%s', %d);";
  659. $iOwnerId = !empty($iOwnerId) ? (int)$iOwnerId : $this->getModule()->getUserId(); //--- in whose timeline the content will be reposted
  660. return sprintf($sFormat, $sJsObject, $iOwnerId, $sType, $sAction, (int)$iObjectId);
  661. }
  662. protected function _getTmplVarsMenuItemActions(&$aEvent, $aBrowseParams = array())
  663. {
  664. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_actions'));
  665. $oMenu->setEvent($aBrowseParams['view'], $aEvent);
  666. $oMenu->setDynamicMode(isset($aBrowseParams['dynamic_mode']) && $aBrowseParams['dynamic_mode'] === true);
  667. $sMenu = $oMenu->getCode();
  668. if(empty($sMenu))
  669. return array();
  670. return array(
  671. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  672. 'js_object' => $this->_oConfig->getJsObject('view'),
  673. 'menu_item_actions' => $sMenu
  674. );
  675. }
  676. protected function _getTmplVarsTimelineOwner(&$aEvent)
  677. {
  678. $oModule = $this->getModule();
  679. $aTmplVarsTimelineOwner = array();
  680. if((int)$aEvent['owner_id'] != (int)$aEvent['object_owner_id']) {
  681. list($sTimelineAuthorName, $sTimelineAuthorUrl) = $oModule->getUserInfo($aEvent['owner_id']);
  682. $aTmplVarsTimelineOwner = array(
  683. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  684. 'owner_url' => $sTimelineAuthorUrl,
  685. 'owner_username' => $sTimelineAuthorName,
  686. );
  687. }
  688. return $aTmplVarsTimelineOwner;
  689. }
  690. protected function _getTmplVarsContentPost($aEvent, $aBrowseParams = array())
  691. {
  692. $aContent = &$aEvent['content'];
  693. $sStylePrefix = $this->_oConfig->getPrefix('style');
  694. $sJsObject = $this->_oConfig->getJsObject('view');
  695. $bBrowseItem = isset($aBrowseParams['type']) && $aBrowseParams['type'] == BX_TIMELINE_TYPE_ITEM;
  696. //--- Process Raw ---//
  697. $sRaw = isset($aContent['raw']) ? $aContent['raw'] : '';
  698. //--- Process Text ---//
  699. $sUrl = isset($aContent['url']) ? bx_html_attribute($aContent['url']) : '';
  700. $sTitle = $sTitleAttr = '';
  701. if(isset($aContent['title'])) {
  702. $sTitle = bx_process_output($aContent['title']);
  703. $sTitleAttr = bx_html_attribute($aContent['title']);
  704. }
  705. if(!empty($sUrl) && !empty($sTitle))
  706. $sTitle = $this->parseHtmlByName('bx_a.html', array(
  707. 'href' => $sUrl,
  708. 'title' => $sTitleAttr,
  709. 'bx_repeat:attrs' => array(
  710. array('key' => 'class', 'value' => $sStylePrefix . '-title')
  711. ),
  712. 'content' => $sTitle
  713. ));
  714. $sText = isset($aContent['text']) ? $aContent['text'] : '';
  715. $sTextMore = '';
  716. if($bBrowseItem)
  717. $sText = strip_tags($sText, '<br><br/><p>');
  718. else {
  719. $sText = strip_tags($sText);
  720. $iMaxLength = $this->_oConfig->getCharsDisplayMax();
  721. if(strlen($sText) > $iMaxLength) {
  722. $iLength = strpos($sText, ' ', $iMaxLength);
  723. $sTextMore = trim(substr($sText, $iLength));
  724. $sText = trim(substr($sText, 0, $iLength));
  725. }
  726. $sTextMore = nl2br($sTextMore);
  727. $sText = nl2br($sText);
  728. }
  729. $sText = $this->_prepareTextForOutput($sText, $aEvent['id']);
  730. $sTextMore = $this->_prepareTextForOutput($sTextMore, $aEvent['id']);
  731. //--- Process Links ---//
  732. $bAddNofollow = $this->_oDb->getParam('sys_add_nofollow') == 'on';
  733. $aTmplVarsLinks = array();
  734. if(!empty($aContent['links']))
  735. foreach($aContent['links'] as $aLink) {
  736. $bTmplVarsEmbed = false;
  737. $aTmplVarsEmbed = array();
  738. $sEmbedlyKey = $this->_oDb->getParam('sys_embedly_api_key');
  739. $sEmbedlyPattern = $this->_oDb->getParam('sys_embedly_api_pattern');
  740. if(!empty($sEmbedlyKey) && !empty($sEmbedlyPattern) && preg_match($sEmbedlyPattern, $aLink['url'])) {
  741. $bTmplVarsEmbed = true;
  742. $aTmplVarsEmbed = array(
  743. 'style_prefix' => $sStylePrefix,
  744. 'embed' => $this->parsePageByName('bx_a.html', array(
  745. 'href' => $aLink['url'],
  746. 'title' => bx_html_attribute($aLink['title']),
  747. 'bx_repeat:attrs' => array(
  748. array('key' => 'class', 'value' => 'bx-link-embed')
  749. ),
  750. 'content' => $aLink['title'],
  751. ))
  752. );
  753. }
  754. else {
  755. $aLinkAttrs = array();
  756. if(!$this->_oConfig->isEqualUrls(BX_DOL_URL_ROOT, $aLink['url'])) {
  757. $aLinkAttrs[] = array('key' => 'target', 'value' => '_blank');
  758. if($bAddNofollow)
  759. $aLinkAttrs[] = array('key' => 'rel', 'value' => 'nofollow');
  760. }
  761. $aTmplVarsEmbed = array(
  762. 'bx_if:show_thumbnail' => array(
  763. 'condition' => !empty($aLink['thumbnail']),
  764. 'content' => array(
  765. 'style_prefix' => $sStylePrefix,
  766. 'thumbnail' => $aLink['thumbnail']
  767. )
  768. ),
  769. 'link' => $this->parsePageByName('bx_a.html', array(
  770. 'href' => $aLink['url'],
  771. 'title' => $aLink['title'],
  772. 'bx_repeat:attrs' => $aLinkAttrs,
  773. 'content' => $aLink['title'],
  774. )),
  775. 'bx_if:show_text' => array(
  776. 'condition' => !empty($aLink['text']),
  777. 'content' => array(
  778. 'style_prefix' => $sStylePrefix,
  779. 'text' => $aLink['text']
  780. )
  781. )
  782. );
  783. }
  784. $aTmplVarsLinks[] = array(
  785. 'style_prefix' => $sStylePrefix,
  786. 'bx_if:show_embed_outer' => array(
  787. 'condition' => $bTmplVarsEmbed,
  788. 'content' => $aTmplVarsEmbed
  789. ),
  790. 'bx_if:show_embed_inner' => array(
  791. 'condition' => !$bTmplVarsEmbed,
  792. 'content' => $aTmplVarsEmbed
  793. )
  794. );
  795. }
  796. //--- Process Photos ---//
  797. $aTmplVarsImages = array();
  798. if(!empty($aContent['images'])) {
  799. foreach($aContent['images'] as $aImage) {
  800. $sImage = '';
  801. if(!empty($aImage['src']))
  802. $sImage = $this->parseHtmlByName('bx_img.html', array(
  803. 'src' => $bBrowseItem && !empty($aImage['src_orig']) ? $aImage['src_orig'] : $aImage['src'],
  804. 'bx_repeat:attrs' => array(
  805. array('key' => 'class', 'value' => $sStylePrefix . '-item-img')
  806. )
  807. ));
  808. if(!empty($sImage) && (isset($aImage['url']) || isset($aImage['onclick']))) {
  809. $aAttrs = array();
  810. if(isset($aImage['onclick']))
  811. $aAttrs[] = array('key' => 'onclick', 'value' => $aImage['onclick']);
  812. $sImage = $this->parseHtmlByName('bx_a.html', array(
  813. 'href' => isset($aImage['url']) ? $aImage['url'] : 'javascript:void(0)',
  814. 'title' => '',
  815. 'bx_repeat:attrs' => $aAttrs,
  816. 'content' => $sImage
  817. ));
  818. }
  819. $aTmplVarsImages[] = array(
  820. 'style_prefix' => $sStylePrefix,
  821. 'image' => $sImage
  822. );
  823. }
  824. }
  825. //--- Process Videos ---//
  826. $aTmplVarsVideos = array();
  827. if(!empty($aContent['videos']))
  828. foreach($aContent['videos'] as $aVideo) {
  829. $aTmplVarsVideos[] = array(
  830. 'style_prefix' => $sStylePrefix,
  831. 'video' => BxTemplFunctions::getInstance()->videoPlayer($aVideo['src_poster'], $aVideo['src_mp4'], $aVideo['src_webm'])
  832. );
  833. }
  834. return array(
  835. 'style_prefix' => $sStylePrefix,
  836. 'bx_if:show_title' => array(
  837. 'condition' => !empty($sTitle),
  838. 'content' => array(
  839. 'style_prefix' => $sStylePrefix,
  840. 'title' => $sTitle,
  841. )
  842. ),
  843. 'bx_if:show_content' => array(
  844. 'condition' => !empty($sText),
  845. 'content' => array(
  846. 'style_prefix' => $sStylePrefix,
  847. 'item_content' => $sText,
  848. 'bx_if:show_more' => array(
  849. 'condition' => !empty($sTextMore),
  850. 'content' => array(
  851. 'style_prefix' => $sStylePrefix,
  852. 'js_object' => $sJsObject,
  853. 'item_content_more' => $sTextMore
  854. )
  855. ),
  856. )
  857. ),
  858. 'bx_if:show_content_raw' => array(
  859. 'condition' => !empty($sRaw),
  860. 'content' => array(
  861. 'item_content_raw' => $sRaw
  862. )
  863. ),
  864. 'bx_if:show_links' => array(
  865. 'condition' => !empty($aTmplVarsLinks),
  866. 'content' => array(
  867. 'style_prefix' => $sStylePrefix,
  868. 'bx_repeat:links' => $aTmplVarsLinks
  869. )
  870. ),
  871. 'bx_if:show_images' => array(
  872. 'condition' => !empty($aTmplVarsImages),
  873. 'content' => array(
  874. 'style_prefix' => $sStylePrefix,
  875. 'bx_repeat:images' => $aTmplVarsImages
  876. )
  877. ),
  878. 'bx_if:show_videos' => array(
  879. 'condition' => !empty($aTmplVarsVideos),
  880. 'content' => array(
  881. 'style_prefix' => $sStylePrefix,
  882. 'bx_repeat:videos' => $aTmplVarsVideos
  883. )
  884. )
  885. );
  886. }
  887. protected function _getTmplVarsContentRepost($aEvent, $aBrowseParams = array())
  888. {
  889. $aContent = &$aEvent['content'];
  890. $sStylePrefix = $this->_oConfig->getPrefix('style');
  891. $sOwnerLink = $this->parseHtmlByName('bx_a.html', array(
  892. 'href' => $aContent['owner_url'],
  893. 'title' => '',
  894. 'bx_repeat:attrs' => array(),
  895. 'content' => $aContent['owner_name']
  896. ));
  897. $sSample = _t($aContent['sample']);
  898. $sSampleLink = empty($aContent['url']) ? $sSample : $this->parseHtmlByName('bx_a.html', array(
  899. 'href' => $aContent['url'],
  900. 'title' => '',
  901. 'bx_repeat:attrs' => array(),
  902. 'content' => $sSample
  903. ));
  904. $sTitle = _t('_bx_timeline_txt_reposted', $sOwnerLink, $sSampleLink);
  905. $sText = $this->_getContent($aContent['parse_type'], $aEvent);
  906. return array(
  907. 'bx_if:show_title' => array(
  908. 'condition' => !empty($sTitle),
  909. 'content' => array(
  910. 'style_prefix' => $sStylePrefix,
  911. 'title' => $sTitle,
  912. )
  913. ),
  914. 'bx_if:show_content' => array(
  915. 'condition' => !empty($sText),
  916. 'content' => array(
  917. 'style_prefix' => $sStylePrefix,
  918. 'content' => $sText,
  919. )
  920. )
  921. );
  922. }
  923. protected function _getSystemData(&$aEvent)
  924. {
  925. $mixedResult = $this->_oConfig->getSystemData($aEvent);
  926. if($mixedResult !== false)
  927. return $mixedResult;
  928. $sMethod = 'display' . bx_gen_method_name($aEvent['type'] . '_' . $aEvent['action']);
  929. if(!method_exists($this, $sMethod))
  930. return '';
  931. return $this->$sMethod($aEvent);
  932. }
  933. protected function _getCommonData(&$aEvent)
  934. {
  935. $CNF = $this->_oConfig->CNF;
  936. $oModule = $this->getModule();
  937. $sJsObject = $this->_oConfig->getJsObject('view');
  938. $sPrefix = $this->_oConfig->getPrefix('common_post');
  939. $sType = str_replace($sPrefix, '', $aEvent['type']);
  940. $aResult = array(
  941. 'owner_id' => $aEvent['object_id'],
  942. 'icon' => $CNF['ICON'],
  943. 'sample' => '_bx_timeline_txt_sample_with_article',
  944. 'sample_wo_article' => '_bx_timeline_txt_sample',
  945. 'sample_action' => '_bx_timeline_txt_added_sample',
  946. 'content_type' => $sType,
  947. 'content' => array(
  948. 'sample' => '_bx_timeline_txt_sample_with_article',
  949. 'sample_wo_article' => '_bx_timeline_txt_sample',
  950. 'sample_action' => '_bx_timeline_txt_added_sample',
  951. 'url' => $this->_oConfig->getItemViewUrl($aEvent)
  952. ), //a string to display or array to parse default template before displaying.
  953. 'views' => '',
  954. 'votes' => '',
  955. 'reports' => '',
  956. 'comments' => '',
  957. 'title' => $aEvent['title'], //may be empty.
  958. 'description' => $aEvent['description'] //may be empty.
  959. );
  960. switch($sType) {
  961. case BX_TIMELINE_PARSE_TYPE_POST:
  962. if(!empty($aEvent['content']))
  963. $aResult['content'] = array_merge($aResult['content'], unserialize($aEvent['content']));
  964. $aLinks = $this->_oDb->getLinks($aEvent['id']);
  965. if(!empty($aLinks) && is_array($aLinks))
  966. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_preview'));
  967. foreach($aLinks as $aLink)
  968. $aResult['content']['links'][] = array(
  969. 'url' => $aLink['url'],
  970. 'title' => $aLink['title'],
  971. 'text' => $aLink['text'],
  972. 'thumbnail' => (int)$aLink['media_id'] != 0 ? $oTranscoder->getFileUrl($aLink['media_id']) : ''
  973. );
  974. $aPhotos = $this->_oDb->getMedia(BX_TIMELINE_MEDIA_PHOTO, $aEvent['id']);
  975. if(!empty($aPhotos) && is_array($aPhotos)) {
  976. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  977. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_view'));
  978. foreach($aPhotos as $iPhotoId) {
  979. $sPhotoSrcOrig = $oStorage->getFileUrlById($iPhotoId);
  980. $aResult['content']['images'][] = array(
  981. 'src' => $oTranscoder->getFileUrl($iPhotoId),
  982. 'src_orig' => $sPhotoSrcOrig,
  983. 'title' => '',
  984. 'onclick' => $sJsObject . '.showPhoto(this, \'' . $sPhotoSrcOrig . '\')'
  985. );
  986. }
  987. }
  988. $aVideos = $this->_oDb->getMedia(BX_TIMELINE_MEDIA_VIDEO, $aEvent['id']);
  989. if(!empty($aVideos) && is_array($aVideos)) {
  990. $oTranscoderPoster = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_poster'));
  991. $oTranscoderMp4 = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4'));
  992. $oTranscoderWebm = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_webm'));
  993. foreach($aVideos as $iVideoId) {
  994. $aResult['content']['videos'][] = array(
  995. 'src_poster' => $oTranscoderPoster->getFileUrl($iVideoId),
  996. 'src_mp4' => $oTranscoderMp4->getFileUrl($iVideoId),
  997. 'src_webm' => $oTranscoderWebm->getFileUrl($iVideoId),
  998. );
  999. }
  1000. }
  1001. break;
  1002. case BX_TIMELINE_PARSE_TYPE_REPOST:
  1003. if(empty($aEvent['content']))
  1004. return array();
  1005. $aContent = unserialize($aEvent['content']);
  1006. if(!$this->_oConfig->isSystem($aContent['type'] , $aContent['action'])) {
  1007. $aReposted = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $aContent['object_id']));
  1008. $aReposted = $this->_getCommonData($aReposted);
  1009. }
  1010. else
  1011. $aReposted = $this->_getSystemData($aContent);
  1012. if(empty($aReposted) || !is_array($aReposted))
  1013. return array();
  1014. $aResult['content'] = array_merge($aContent, $aReposted['content']);
  1015. $aResult['content']['parse_type'] = !empty($aReposted['content_type']) ? $aReposted['content_type'] : BX_TIMELINE_PARSE_TYPE_DEFAULT;
  1016. $aResult['content']['owner_id'] = $aReposted['owner_id'];
  1017. list($aResult['content']['owner_name'], $aResult['content']['owner_url']) = $oModule->getUserInfo($aReposted['owner_id']);
  1018. if(!empty($aReposted['sample']))
  1019. $aResult['content']['sample'] = $aReposted['sample'];
  1020. if(!empty($aReposted['sample_wo_article']))
  1021. $aResult['content']['sample'] = $aReposted['sample_wo_article'];
  1022. list($sUserName) = $oModule->getUserInfo($aEvent['object_id']);
  1023. $aResult['title'] = _t('_bx_timeline_txt_user_repost', $sUserName, _t($aResult['content']['sample']));
  1024. $aResult['description'] = _t('_bx_timeline_txt_user_reposted_user_sample', $sUserName, $aResult['content']['owner_name'], _t($aResult['content']['sample']));
  1025. break;
  1026. }
  1027. $sSystem = $this->_oConfig->getObject('view');
  1028. if($oModule->getViewObject($sSystem, $aEvent['id']) !== false)
  1029. $aResult['views'] = array(
  1030. 'system' => $sSystem,
  1031. 'object_id' => $aEvent['id'],
  1032. 'count' => $aEvent['views']
  1033. );
  1034. $sSystem = $this->_oConfig->getObject('vote');
  1035. if($oModule->getVoteObject($sSystem, $aEvent['id']) !== false)
  1036. $aResult['votes'] = array(
  1037. 'system' => $sSystem,
  1038. 'object_id' => $aEvent['id'],
  1039. 'count' => $aEvent['votes']
  1040. );
  1041. $sSystem = $this->_oConfig->getObject('report');
  1042. if($oModule->getReportObject($sSystem, $aEvent['id']) !== false)
  1043. $aResult['reports'] = array(
  1044. 'system' => $sSystem,
  1045. 'object_id' => $aEvent['id'],
  1046. 'count' => $aEvent['reports']
  1047. );
  1048. $sSystem = $this->_oConfig->getObject('comment');
  1049. if($oModule->getCmtsObject($sSystem, $aEvent['id']) !== false)
  1050. $aResult['comments'] = array(
  1051. 'system' => $sSystem,
  1052. 'object_id' => $aEvent['id'],
  1053. 'count' => $aEvent['comments']
  1054. );
  1055. return $aResult;
  1056. }
  1057. protected function _prepareTextForOutput($s, $iEventId = 0)
  1058. {
  1059. $s = bx_process_output($s, BX_DATA_HTML);
  1060. $s = bx_linkify_html($s, 'class="' . BX_DOL_LINK_CLASS . '"');
  1061. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  1062. $s = $oMetatags->keywordsParse($iEventId, $s);
  1063. return $s;
  1064. }
  1065. }
  1066. /** @} */