BxTimelineTemplate.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup Timeline Timeline
  7. * @ingroup DolphinModules
  8. *
  9. * @{
  10. */
  11. bx_import('BxDolModuleTemplate');
  12. class BxTimelineTemplate extends BxDolModuleTemplate
  13. {
  14. function __construct(&$oConfig, &$oDb)
  15. {
  16. parent::BxDolModuleTemplate($oConfig, $oDb);
  17. }
  18. protected function getModule()
  19. {
  20. $sName = $this->_oConfig->getName();
  21. return BxDolModule::getInstance($sName);
  22. }
  23. public function getCssJs()
  24. {
  25. $this->addCss(array('plugins/jquery/themes/|jquery-ui.css', 'view.css', 'view-media-tablet.css', 'view-media-desktop.css', 'post.css'));
  26. $this->addJs(array('jquery.ui.all.min.js', 'jquery.resize.js', 'plugins/|masonry.pkgd.min.js', 'common_anim.js', 'main.js', 'view.js', 'post.js'));
  27. }
  28. public function getJsCode($sType, $aRequestParams = array(), $bWrap = true)
  29. {
  30. $oJson = new Services_JSON();
  31. $oModule = $this->getModule();
  32. $sJsClass = $this->_oConfig->getJsClass($sType);
  33. $sJsObject = $this->_oConfig->getJsObject($sType);
  34. ob_start();
  35. ?>
  36. var <?=$sJsObject; ?> = new <?=$sJsClass; ?>({
  37. sActionUrl: '<?=BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri(); ?>',
  38. sObjName: '<?=$sJsObject; ?>',
  39. iOwnerId: <?=$oModule->_iOwnerId; ?>,
  40. sAnimationEffect: '<?=$this->_oConfig->getAnimationEffect(); ?>',
  41. iAnimationSpeed: '<?=$this->_oConfig->getAnimationSpeed(); ?>',
  42. oRequestParams: <?php echo !empty($aRequestParams) ? $oJson->encode($aRequestParams) : '{}'; ?>
  43. });
  44. <?php
  45. $sContent = ob_get_clean();
  46. return !$bWrap ? $sContent : $this->_wrapInTagJsCode($sContent);
  47. }
  48. public function getPostBlock($iOwnerId)
  49. {
  50. $oModule = $this->getModule();
  51. $aFormText = $oModule->getFormText();
  52. $aFormLink = $oModule->getFormLink();
  53. $aFormPhoto = $oModule->getFormPhoto();
  54. return $this->parseHtmlByName('post.html', array (
  55. 'js_object' => $this->_oConfig->getJsObject('post'),
  56. 'js_content' => $this->getJsCode('post', array(
  57. 'owner_id' => $iOwnerId
  58. )),
  59. 'text_form' => $aFormText['form'],
  60. 'link_form' => $aFormLink['form'],
  61. 'photo_form' => $aFormPhoto['form'],
  62. 'music_form' => '',
  63. 'video_form' => '',
  64. ));
  65. }
  66. public function getViewBlock($aParams)
  67. {
  68. list($sContent, $sLoadMore, $sBack) = $this->getPosts($aParams);
  69. $this->getCssJs();
  70. return $this->parseHtmlByName('view.html', array(
  71. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  72. 'back' => $sBack,
  73. 'content' => $sContent,
  74. 'load_more' => $sLoadMore,
  75. 'js_content' => $this->getJsCode('view', array(
  76. 'type' => $aParams['type'],
  77. 'owner_id' => $aParams['owner_id'],
  78. 'start' => $aParams['start'],
  79. 'per_page' => $aParams['per_page'],
  80. 'filter' => $aParams['filter'],
  81. 'modules' => $aParams['modules'],
  82. 'timeline' => $aParams['timeline'],
  83. ))
  84. ));
  85. }
  86. public function getViewItemBlock($iId)
  87. {
  88. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  89. if(empty($aEvent))
  90. return '';
  91. $sContent = $this->getJsCode('view');
  92. $sContent .= $this->getPost($aEvent, array('type' => 'view_item'));
  93. $this->getCssJs();
  94. return $sContent;
  95. }
  96. public function getViewItemPopup($iId)
  97. {
  98. bx_import('BxTemplFunctions');
  99. return BxTemplFunctions::getInstance()->transBox('bx-timeline-item-popup-' + $iId, $this->getViewItemBlock($iId));
  100. }
  101. public function getPost(&$aEvent, $aBrowseParams = array())
  102. {
  103. $aResult = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $this->_getSystemData($aEvent) : $this->_getCommonData($aEvent);
  104. if(empty($aResult) || empty($aResult['owner_id']) || empty($aResult['content']))
  105. return '';
  106. list($sUserName) = $this->getModule()->getUserInfo($aResult['owner_id']);
  107. if(empty($aEvent['title']) || empty($aEvent['description'])) {
  108. $sTitle = !empty($aResult['title']) ? $aResult['title'] : '';
  109. if($sTitle == '') {
  110. $sSample = !empty($aResult['content']['sample']) ? $aResult['content']['sample'] : '_bx_timeline_txt_sample';
  111. $sTitle = _t('_bx_timeline_txt_user_added_sample', $sUserName, _t($sSample));
  112. }
  113. $sDescription = !empty($aResult['description']) ? $aResult['description'] : '';
  114. if($sDescription == '' && !empty($aResult['content']['text']))
  115. $sDescription = $aResult['content']['text'];
  116. $this->_oDb->updateEvent(array(
  117. 'title' => bx_process_input(strip_tags($sTitle)),
  118. 'description' => bx_process_input(strip_tags($sDescription))
  119. ), array('id' => $aEvent['id']));
  120. }
  121. $aEvent['object_owner_id'] = $aResult['owner_id'];
  122. $aEvent['content'] = $aResult['content'];
  123. $aEvent['votes'] = $aResult['votes'];
  124. $aEvent['comments'] = $aResult['comments'];
  125. $sType = !empty($aResult['content_type']) ? $aResult['content_type'] : BX_TIMELINE_PARSE_TYPE_DEFAULT;
  126. return $this->_getPost($sType, $aEvent, $aBrowseParams);
  127. }
  128. public function getPosts($aParams)
  129. {
  130. $iStart = $aParams['start'];
  131. $iPerPage = $aParams['per_page'];
  132. $aParamsDb = $aParams;
  133. //--- Check for Previous
  134. $bPrevious = false;
  135. if($iStart - 1 >= 0) {
  136. $aParamsDb['start'] -= 1;
  137. $aParamsDb['per_page'] += 1;
  138. $bPrevious = true;
  139. }
  140. //--- Check for Next
  141. $aParamsDb['per_page'] += 1;
  142. $aEvents = $this->_oDb->getEvents($aParamsDb);
  143. //--- Check for Previous
  144. if($bPrevious)
  145. $aEvent = array_shift($aEvents);
  146. //--- Check for Next
  147. $bNext = false;
  148. if(count($aEvents) > $iPerPage) {
  149. $aEvent = array_pop($aEvents);
  150. $bNext = true;
  151. }
  152. $iEvents = count($aEvents);
  153. $sContent = $this->getEmpty($iEvents <= 0);
  154. foreach($aEvents as $aEvent) {
  155. $sEvent = $this->getPost($aEvent, $aParams);
  156. if(empty($sEvent))
  157. continue;
  158. $sContent .= $sEvent;
  159. }
  160. $iYearSel = (int)$aParams['timeline'];
  161. $iYearMin = $this->_oDb->getMaxDuration($aParams);
  162. $sBack = $this->getBack($iYearSel);
  163. $sLoadMore = $this->getLoadMore($iStart, $iPerPage, $bNext, $iYearSel, $iYearMin, $iEvents > 0);
  164. return array($sContent, $sLoadMore, $sBack);
  165. }
  166. public function getEmpty($bVisible)
  167. {
  168. return $this->parseHtmlByName('empty.html', array(
  169. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  170. 'visible' => $bVisible ? 'block' : 'none',
  171. 'content' => MsgBox(_t('_bx_timeline_txt_msg_no_results'))
  172. ));
  173. }
  174. public function getBack($iYearSel)
  175. {
  176. if($iYearSel == 0)
  177. return '';
  178. $sStylePrefix = $this->_oConfig->getPrefix('style');
  179. $sJsObject = $this->_oConfig->getJsObject('view');
  180. $iYearNow = date('Y', time());
  181. return $this->parseHtmlByName('back.html', array(
  182. 'style_prefix' => $sStylePrefix,
  183. 'href' => 'javascript:void(0)',
  184. 'title' => _t('_bx_timeline_txt_jump_to_n_year', $iYearNow),
  185. 'bx_repeat:attrs' => array(
  186. array('key' => 'onclick', 'value' => 'javascript:' . $sJsObject . '.changeTimeline(this, 0)')
  187. ),
  188. 'content' => _t('_bx_timeline_txt_jump_to_recent')
  189. ));
  190. }
  191. public function getLoadMore($iStart, $iPerPage, $bEnabled, $iYearSel, $iYearMin, $bVisible = true)
  192. {
  193. $sStylePrefix = $this->_oConfig->getPrefix('style');
  194. $sJsObject = $this->_oConfig->getJsObject('view');
  195. $sYears = '';
  196. if(!empty($iYearMin)) {
  197. $iYearMax = date('Y', time()) - 1;
  198. for($i = $iYearMax; $i >= $iYearMin; $i--)
  199. $sYears .= ($i != $iYearSel ? $this->parseHtmlByName('bx_a.html', array(
  200. 'href' => 'javascript:void(0)',
  201. 'title' => _t('_bx_timeline_txt_jump_to_n_year', $i),
  202. 'bx_repeat:attrs' => array(
  203. array('key' => 'onclick', 'value' => 'javascript:' . $sJsObject . '.changeTimeline(this, ' . $i . ')')
  204. ),
  205. 'content' => $i
  206. )) : $i) . ', ';
  207. $sYears = substr($sYears, 0, -2);
  208. }
  209. $aTmplVars = array(
  210. 'style_prefix' => $sStylePrefix,
  211. 'visible' => $bVisible ? 'block' : 'none',
  212. 'bx_if:is_disabled' => array(
  213. 'condition' => !$bEnabled,
  214. 'content' => array()
  215. ),
  216. 'bx_if:show_on_click' => array(
  217. 'condition' => $bEnabled,
  218. 'content' => array(
  219. 'on_click' => 'javascript:' . $sJsObject . '.changePage(this, ' . ($iStart + $iPerPage) . ', ' . $iPerPage . ')'
  220. )
  221. ),
  222. 'bx_if:show_jump_to' => array(
  223. 'condition' => !empty($sYears),
  224. 'content' => array(
  225. 'style_prefix' => $sStylePrefix,
  226. 'years' => $sYears
  227. )
  228. )
  229. );
  230. return $this->parseHtmlByName('load_more.html', $aTmplVars);
  231. }
  232. public function getComments($sSystem, $iId)
  233. {
  234. $oModule = $this->getModule();
  235. $sStylePrefix = $this->_oConfig->getPrefix('style');
  236. $oCmts = $oModule->getCmtsObject($sSystem, $iId);
  237. if($oCmts === false)
  238. return '';
  239. $aComments = $oCmts->getCommentsBlock(0, 0, false);
  240. return $this->parseHtmlByName('comments.html', array(
  241. 'style_prefix' => $sStylePrefix,
  242. 'id' => $iId,
  243. 'content' => $aComments['content']
  244. ));
  245. }
  246. public function getVotes($sSystem, $iId)
  247. {
  248. $oModule = $this->getModule();
  249. $sStylePrefix = $this->_oConfig->getPrefix('style');
  250. $oVote = $oModule->getVoteObject($sSystem, $iId);
  251. if($oVote === false)
  252. return '';
  253. return $oVote->getJsScript();
  254. }
  255. protected function _getPost($sType, $aEvent, $aBrowseParams = array())
  256. {
  257. $oModule = $this->getModule();
  258. $sStylePrefix = $this->_oConfig->getPrefix('style');
  259. $sJsObject = $this->_oConfig->getJsObject('view');
  260. list($sAuthorName, $sAuthorUrl, $sAuthorIcon) = $oModule->getUserInfo($aEvent['object_owner_id']);
  261. $bAuthorIcon = !empty($sAuthorIcon);
  262. $aTmplVarsMenuItemManage = $this->_getTmplVarsMenuItemManage($aEvent, $aBrowseParams);
  263. $aTmplVarsMenuItemActions = $this->_getTmplVarsMenuItemActions($aEvent, $aBrowseParams);
  264. $aTmplVarsTimelineOwner = array();
  265. if(isset($aBrowseParams['type']) && $aBrowseParams['type'] == BX_TIMELINE_TYPE_CONNECTIONS)
  266. $aTmplVarsTimelineOwner = $this->_getTmplVarsTimelineOwner($aEvent);
  267. $aTmplVars = array (
  268. 'style_prefix' => $sStylePrefix,
  269. 'js_object' => $sJsObject,
  270. 'id' => $aEvent['id'],
  271. 'bx_if:show_menu_item_manage' => array(
  272. 'condition' => !empty($aTmplVarsMenuItemManage),
  273. 'content' => $aTmplVarsMenuItemManage
  274. ),
  275. 'bx_if:show_icon' => array(
  276. 'condition' => $bAuthorIcon,
  277. 'content' => array(
  278. 'author_icon' => $sAuthorIcon
  279. )
  280. ),
  281. 'bx_if:show_icon_empty' => array(
  282. 'condition' => !$bAuthorIcon,
  283. 'content' => array()
  284. ),
  285. 'item_owner_url' => $sAuthorUrl,
  286. 'item_owner_name' => $sAuthorName,
  287. 'bx_if:show_timeline_owner' => array(
  288. 'condition' => !empty($aTmplVarsTimelineOwner),
  289. 'content' => $aTmplVarsTimelineOwner
  290. ),
  291. 'item_view_url' => $this->_oConfig->getItemViewUrl($aEvent),
  292. 'item_date' => bx_time_js($aEvent['date']),
  293. /*
  294. //Comments and Shares counters
  295. 'bx_if:show_counter_comments' => array(
  296. 'condition' => (int)$aEvent['comments']['count'] > 0,
  297. 'content' => array(
  298. 'style_prefix' => $sStylePrefix,
  299. 'counter' => $aEvent['comments']['count']
  300. )
  301. ),
  302. 'bx_if:show_counter_shares' => array(
  303. 'condition' => (int)$aEvent['shares'] > 0,
  304. 'content' => array(
  305. 'style_prefix' => $sStylePrefix,
  306. 'counter' => $aEvent['shares']
  307. )
  308. ),
  309. */
  310. 'content' => is_string($aEvent['content']) ? $aEvent['content'] : $this->_getContent($sType, $aEvent['content'], $aBrowseParams),
  311. 'bx_if:show_menu_item_actions' => array(
  312. 'condition' => !empty($aTmplVarsMenuItemActions),
  313. 'content' => $aTmplVarsMenuItemActions
  314. ),
  315. 'comments' => isset($aBrowseParams['type']) && $aBrowseParams['type'] == 'view_item' ? $this->_getComments($aEvent['comments']) : '',
  316. 'votes' => $this->_getVotes($aEvent['votes'])
  317. );
  318. return $this->parseHtmlByName('item.html', $aTmplVars);
  319. }
  320. protected function _getContent($sType, $aContent)
  321. {
  322. $sMethod = '_getTmplVarsContent' . ucfirst($sType);
  323. if(!method_exists($this, $sMethod))
  324. return '';
  325. $aTmplVars = $this->$sMethod($aContent);
  326. return $this->parseHtmlByName($sType . '.html', $aTmplVars);
  327. }
  328. protected function _getComments($aComments)
  329. {
  330. $mixedComments = $this->getModule()->getCommentsData($aComments);
  331. if($mixedComments === false)
  332. return '';
  333. list($sSystem, $iObjectId, $iCount) = $mixedComments;
  334. return $this->getComments($sSystem, $iObjectId);
  335. }
  336. protected function _getVotes($aVotes)
  337. {
  338. $mixedVotes = $this->getModule()->getVotesData($aVotes);
  339. if($mixedVotes === false)
  340. return '';
  341. list($sSystem, $iObjectId, $iCount) = $mixedVotes;
  342. return $this->getVotes($sSystem, $iObjectId);
  343. }
  344. protected function _getTmplVarsMenuItemManage(&$aEvent) {
  345. $oModule = $this->getModule();
  346. bx_import('BxDolMenu');
  347. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'));
  348. $oMenu->setEvent($aEvent);
  349. bx_import('BxTemplFunctions');
  350. $sMenu = BxTemplFunctions::getInstance()->designBoxMenu($oMenu);
  351. if(empty($sMenu))
  352. return array();
  353. return array(
  354. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  355. 'js_object' => $this->_oConfig->getJsObject('view'),
  356. 'menu_item_manage' => $sMenu
  357. );
  358. }
  359. protected function _getTmplVarsMenuItemActions(&$aEvent) {
  360. $oModule = $this->getModule();
  361. bx_import('BxDolMenu');
  362. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_actions'));
  363. $oMenu->setEvent($aEvent);
  364. $sMenu = $oMenu->getCode();
  365. if(empty($sMenu))
  366. return array();
  367. return array(
  368. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  369. 'js_object' => $this->_oConfig->getJsObject('view'),
  370. 'menu_item_actions' => $sMenu
  371. );
  372. }
  373. protected function _getTmplVarsTimelineOwner(&$aEvent)
  374. {
  375. $oModule = $this->getModule();
  376. $aTmplVarsTimelineOwner = array();
  377. if((int)$aEvent['owner_id'] != (int)$aEvent['object_owner_id']) {
  378. list($sTimelineAuthorName, $sTimelineAuthorUrl) = $oModule->getUserInfo($aEvent['owner_id']);
  379. $aTmplVarsTimelineOwner = array(
  380. 'owner_url' => $sTimelineAuthorUrl,
  381. 'owner_username' => $sTimelineAuthorName,
  382. );
  383. }
  384. return $aTmplVarsTimelineOwner;
  385. }
  386. protected function _getTmplVarsContentText($aContent)
  387. {
  388. $sStylePrefix = $this->_oConfig->getPrefix('style');
  389. $sJsObject = $this->_oConfig->getJsObject('view');
  390. $sUrl = isset($aContent['url']) ? $aContent['url'] : '';
  391. $sTitle = isset($aContent['title']) ? bx_process_input(strip_tags($aContent['title'])) : '';
  392. if(!empty($sUrl) && !empty($sTitle))
  393. $sTitle = $this->parseHtmlByName('bx_a.html', array(
  394. 'href' => $sUrl,
  395. 'title' => $sTitle,
  396. 'bx_repeat:attrs' => array(
  397. array('key' => 'class', 'value' => $sStylePrefix . '-title')
  398. ),
  399. 'content' => $sTitle
  400. ));
  401. $sText = isset($aContent['text']) ? bx_process_input(strip_tags($aContent['text'])) : '';
  402. $sTextMore = '';
  403. $iMaxLength = $this->_oConfig->getCharsDisplayMax();
  404. if(strlen($sText) > $iMaxLength) {
  405. $iLength = strpos($sText, ' ', $iMaxLength);
  406. $sTextMore = trim(substr($sText, $iLength));
  407. $sText = trim(substr($sText, 0, $iLength));
  408. }
  409. $sText = $this->_prepareTextForOutput($sText);
  410. $sTextMore = $this->_prepareTextForOutput($sTextMore);
  411. return array(
  412. 'style_prefix' => $sStylePrefix,
  413. 'bx_if:show_images' => array(
  414. 'condition' => false,
  415. 'content' => array()
  416. ),
  417. 'bx_if:show_title' => array(
  418. 'condition' => !empty($sTitle),
  419. 'content' => array(
  420. 'style_prefix' => $sStylePrefix,
  421. 'title' => $sTitle,
  422. )
  423. ),
  424. 'bx_if:show_content' => array(
  425. 'condition' => !empty($sText),
  426. 'content' => array(
  427. 'style_prefix' => $sStylePrefix,
  428. 'item_content' => $sText,
  429. 'bx_if:show_more' => array(
  430. 'condition' => !empty($sTextMore),
  431. 'content' => array(
  432. 'style_prefix' => $sStylePrefix,
  433. 'js_object' => $sJsObject,
  434. 'item_content_more' => $sTextMore
  435. )
  436. ),
  437. )
  438. )
  439. );
  440. }
  441. protected function _getTmplVarsContentLink($aContent)
  442. {
  443. return $this->_getTmplVarsContentText($aContent);
  444. }
  445. protected function _getTmplVarsContentPhoto($aContent)
  446. {
  447. $aTmplVarsContent = $this->_getTmplVarsContentText($aContent);
  448. if(!isset($aContent['images']) || empty($aContent['images']))
  449. return $aTmplVarsContent;
  450. $sStylePrefix = $this->_oConfig->getPrefix('style');
  451. $sTitleDefault = isset($aContent['title']) && !empty($aContent['title']) ? $aContent['title'] : "";
  452. $aTmplVarsImages = array();
  453. foreach($aContent['images'] as $aImage) {
  454. $sTitle = isset($aImage['title']) && !empty($aImage['title']) ? $aImage['title'] : $sTitleDefault;
  455. $sImage = '';
  456. if(isset($aImage['src']) && !empty($aImage['src']))
  457. $sImage = $this->parseHtmlByName('bx_img.html', array(
  458. 'src' => $aImage['src'],
  459. 'bx_repeat:attrs' => array(
  460. array('key' => 'class', 'value' => $sStylePrefix . '-item-image'),
  461. array('key' => 'title', 'value' => $sTitle)
  462. )
  463. ));
  464. if(!empty($sImage) && (isset($aImage['url']) || isset($aImage['onclick']))) {
  465. $aAttrs = array();
  466. if(isset($aImage['onclick']))
  467. $aAttrs[] = array('key' => 'onclick', 'value' => $aImage['onclick']);
  468. $sImage = $this->parseHtmlByName('bx_a.html', array(
  469. 'href' => isset($aImage['url']) ? $aImage['url'] : 'javascript:void(0)',
  470. 'title' => $sTitle,
  471. 'bx_repeat:attrs' => $aAttrs,
  472. 'content' => $sImage
  473. ));
  474. }
  475. $aTmplVarsImages[] = array(
  476. 'style_prefix' => $sStylePrefix,
  477. 'image' => $sImage
  478. );
  479. }
  480. return array_merge($aTmplVarsContent, array(
  481. 'bx_if:show_images' => array(
  482. 'condition' => !empty($aTmplVarsImages),
  483. 'content' => array(
  484. 'bx_repeat:images' => $aTmplVarsImages
  485. )
  486. )
  487. ));
  488. }
  489. protected function _getTmplVarsContentShare($aContent)
  490. {
  491. $sStylePrefix = $this->_oConfig->getPrefix('style');
  492. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  493. $sJsObject = $this->_oConfig->getJsObject('view');
  494. $sOwnerLink = $this->parseHtmlByName('bx_a.html', array(
  495. 'href' => $aContent['owner_url'],
  496. 'title' => '',
  497. 'bx_repeat:attrs' => array(),
  498. 'content' => $aContent['owner_name']
  499. ));
  500. $sSample = _t($aContent['sample']);
  501. $sSampleLink = empty($aContent['url']) ? $sSample : $this->parseHtmlByName('bx_a.html', array(
  502. 'href' => $aContent['url'],
  503. 'title' => '',
  504. 'bx_repeat:attrs' => array(),
  505. 'content' => $sSample
  506. ));
  507. $sTitle = _t('_bx_timeline_txt_shared', $sOwnerLink, $sSampleLink);
  508. $sText = $this->_getContent($aContent['parse_type'], $aContent);
  509. return array(
  510. 'bx_if:show_title' => array(
  511. 'condition' => !empty($sTitle),
  512. 'content' => array(
  513. 'style_prefix' => $sStylePrefix,
  514. 'title' => $sTitle,
  515. )
  516. ),
  517. 'bx_if:show_content' => array(
  518. 'condition' => !empty($sText),
  519. 'content' => array(
  520. 'style_prefix' => $sStylePrefix,
  521. 'content' => $sText,
  522. )
  523. )
  524. );
  525. }
  526. protected function _getSystemData(&$aEvent)
  527. {
  528. $sHandler = $aEvent['type'] . '_' . $aEvent['action'];
  529. if(!$this->_oConfig->isHandler($sHandler))
  530. return '';
  531. $mixedResult = array();
  532. $aHandler = $this->_oConfig->getHandlers($sHandler);
  533. if(empty($aHandler['module_uri']) && empty($aHandler['module_class']) && empty($aHandler['module_method'])) {
  534. $sMethod = 'display' . str_replace(' ', '', ucwords(str_replace('_', ' ', $aHandler['alert_unit'] . '_' . $aHandler['alert_action'])));
  535. if(!method_exists($this, $sMethod))
  536. return '';
  537. $mixedResult = $this->$sMethod($aEvent);
  538. }
  539. else {
  540. $aEvent['js_mode'] = $this->_oConfig->getJsMode();
  541. $mixedResult = BxDolService::call($aHandler['module_name'], $aHandler['module_method'], array($aEvent), $aHandler['module_class']);
  542. }
  543. return $mixedResult;
  544. }
  545. protected function _getCommonData(&$aEvent)
  546. {
  547. $oModule = $this->getModule();
  548. $sPrefix = $this->_oConfig->getPrefix('common_post');
  549. $sType = str_replace($sPrefix, '', $aEvent['type']);
  550. $aResult = array(
  551. 'owner_id' => $aEvent['object_id'],
  552. 'content_type' => $sType,
  553. 'content' => array(
  554. 'sample' => '_bx_timeline_txt_common_' . $sType,
  555. 'url' => $this->_oConfig->getItemViewUrl($aEvent)
  556. ), //a string to display or array to parse default template before displaying.
  557. 'votes' => '',
  558. 'comments' => '',
  559. 'title' => '', //may be empty.
  560. 'description' => '' //may be empty.
  561. );
  562. switch($sType) {
  563. case BX_TIMELINE_PARSE_TYPE_TEXT:
  564. case BX_TIMELINE_PARSE_TYPE_LINK:
  565. if(empty($aEvent['content']))
  566. break;
  567. $aResult['content'] = array_merge($aResult['content'], unserialize($aEvent['content']));
  568. break;
  569. case BX_TIMELINE_PARSE_TYPE_PHOTO:
  570. $aPhotos = $this->_oDb->getPhotos($aEvent['id']);
  571. if(!is_array($aPhotos) || empty($aPhotos))
  572. break;
  573. $aFirst = current($aPhotos);
  574. if($aFirst !== false) {
  575. $aResult['content']['title'] = isset($aFirst['title']) ? $aFirst['title'] : '';
  576. $aResult['content']['text'] = isset($aFirst['text']) ? $aFirst['text'] : '';
  577. }
  578. bx_import('BxDolImageTranscoder');
  579. $oTranscoder = BxDolImageTranscoder::getObjectInstance($this->_oConfig->getObject('transcoder_preview'));
  580. foreach($aPhotos as $aPhoto)
  581. $aResult['content']['images'][] = array(
  582. 'src' => $oTranscoder->getImageUrl($aPhoto['id']),
  583. 'title' => isset($aPhoto['title']) ? $aPhoto['title'] : ''
  584. );
  585. break;
  586. case BX_TIMELINE_PARSE_TYPE_SHARE:
  587. if(empty($aEvent['content']))
  588. break;
  589. $aContent = unserialize($aEvent['content']);
  590. if(!$this->_oConfig->isSystem($aContent['type'] , $aContent['action'])) {
  591. $aShared = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $aContent['object_id']));
  592. $aShared = $this->_getCommonData($aShared);
  593. }
  594. else
  595. $aShared = $this->_getSystemData($aContent);
  596. $aResult['content'] = array_merge($aContent, $aShared['content']);
  597. $aResult['content']['parse_type'] = $aShared['content_type'];
  598. $aResult['content']['owner_id'] = $aShared['owner_id'];
  599. list($aResult['content']['owner_name'], $aResult['content']['owner_url']) = $oModule->getUserInfo($aShared['owner_id']);
  600. list($sUserName) = $oModule->getUserInfo($aEvent['object_id']);
  601. $sSample = !empty($aResult['content']['sample']) ? $aResult['content']['sample'] : '_bx_timeline_txt_sample';
  602. $aResult['title'] = _t('_bx_timeline_txt_user_shared_sample', $sUserName, $aResult['content']['owner_name'], _t($sSample));
  603. $aResult['description'] = '';
  604. break;
  605. }
  606. $sSystem = $this->_oConfig->getSystemName('vote');
  607. if($oModule->getVoteObject($sSystem, $aEvent['id']) !== false)
  608. $aResult['votes'] = array(
  609. 'system' => $sSystem,
  610. 'object_id' => $aEvent['id'],
  611. 'count' => $aEvent['votes']
  612. );
  613. $sSystem = $this->_oConfig->getSystemName('comment');
  614. if($oModule->getCmtsObject($sSystem, $aEvent['id']) !== false)
  615. $aResult['comments'] = array(
  616. 'system' => $sSystem,
  617. 'object_id' => $aEvent['id'],
  618. 'count' => $aEvent['comments']
  619. );
  620. return $aResult;
  621. }
  622. protected function _prepareTextForOutput($s)
  623. {
  624. $s = bx_process_output($s, BX_DATA_TEXT);
  625. $s = preg_replace("/((https?|ftp|news):\/\/)?([a-z]([a-z0-9\-]*\.)+(aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|[a-z]{2})|(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))(\/[a-z0-9_\-\.~]+)*(\/([a-z0-9_\-\.]*)(\?[a-z0-9+_\-\.%=&amp;]*)?)?(#[a-z][a-z0-9_]*)?/", '<a href="$0" target="_blank">$0</a>', $s);
  626. return $s;
  627. }
  628. }
  629. /** @} */