BxTimelineTemplate.php 50 KB

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