BxTimelineTemplate.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  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('BxBaseModNotificationsTemplate');
  12. class BxTimelineTemplate extends BxBaseModNotificationsTemplate
  13. {
  14. function __construct(&$oConfig, &$oDb)
  15. {
  16. parent::__construct($oConfig, $oDb);
  17. }
  18. public function getCssJs()
  19. {
  20. parent::getCssJs();
  21. $this->addCss(array(
  22. 'jquery-ui/jquery-ui.css',
  23. 'post.css',
  24. 'share.css',
  25. ));
  26. $this->addJs(array(
  27. 'jquery-ui/jquery-ui.custom.min.js',
  28. 'jquery.form.min.js',
  29. 'jquery.ba-resize.min.js',
  30. 'masonry.pkgd.min.js',
  31. 'post.js',
  32. 'share.js',
  33. ));
  34. }
  35. public function getPostBlock($iOwnerId)
  36. {
  37. $aForm = $this->getModule()->getFormPost();
  38. return $this->parseHtmlByName('block_post.html', array (
  39. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  40. 'js_object' => $this->_oConfig->getJsObject('post'),
  41. 'js_content' => $this->getJsCode('post', array(
  42. 'oRequestParams' => array('owner_id' => $iOwnerId)
  43. )),
  44. 'form' => $aForm['form']
  45. ));
  46. }
  47. public function getViewBlock($aParams)
  48. {
  49. list($sContent, $sLoadMore, $sBack) = $this->getPosts($aParams);
  50. return $this->parseHtmlByName('block_view.html', array(
  51. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  52. 'html_id' => $this->_oConfig->getHtmlIds('view', 'main'),
  53. 'back' => $sBack,
  54. 'content' => $sContent,
  55. 'load_more' => $sLoadMore,
  56. 'view_image_popup' => $this->_getImagePopup(),
  57. 'js_content' => $this->getJsCode('view', array(
  58. 'oRequestParams' => array(
  59. 'type' => $aParams['type'],
  60. 'owner_id' => $aParams['owner_id'],
  61. 'start' => $aParams['start'],
  62. 'per_page' => $aParams['per_page'],
  63. 'filter' => $aParams['filter'],
  64. 'modules' => $aParams['modules'],
  65. 'timeline' => $aParams['timeline'],
  66. )
  67. )) . $this->getJsCode('share')
  68. ));
  69. }
  70. public function getItemBlock($iId)
  71. {
  72. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  73. if(empty($aEvent))
  74. return '';
  75. $sContent = $this->getJsCode('view');
  76. $sContent .= $this->getPost($aEvent, array('type' => BX_TIMELINE_TYPE_ITEM));
  77. $sContent .= $this->_getImagePopup();
  78. return $sContent;
  79. }
  80. public function getPost(&$aEvent, $aBrowseParams = array())
  81. {
  82. $aResult = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $this->_getSystemData($aEvent) : $this->_getCommonData($aEvent);
  83. if(empty($aResult) || empty($aResult['owner_id']) || empty($aResult['content']))
  84. return '';
  85. list($sUserName) = $this->getModule()->getUserInfo($aResult['owner_id']);
  86. if(empty($aEvent['title']) || empty($aEvent['description'])) {
  87. $sTitle = !empty($aResult['title']) ? $aResult['title'] : '';
  88. if($sTitle == '') {
  89. $sSample = !empty($aResult['content']['sample']) ? $aResult['content']['sample'] : '_bx_timeline_txt_sample';
  90. $sTitle = _t('_bx_timeline_txt_user_added_sample', $sUserName, _t($sSample));
  91. }
  92. $sDescription = !empty($aResult['description']) ? $aResult['description'] : '';
  93. if($sDescription == '' && !empty($aResult['content']['text']))
  94. $sDescription = $aResult['content']['text'];
  95. $this->_oDb->updateEvent(array(
  96. 'title' => bx_process_input(strip_tags($sTitle)),
  97. 'description' => bx_process_input(strip_tags($sDescription))
  98. ), array('id' => $aEvent['id']));
  99. }
  100. $aEvent['object_owner_id'] = $aResult['owner_id'];
  101. $aEvent['content'] = $aResult['content'];
  102. $aEvent['votes'] = $aResult['votes'];
  103. $aEvent['comments'] = $aResult['comments'];
  104. $sType = !empty($aResult['content_type']) ? $aResult['content_type'] : BX_TIMELINE_PARSE_TYPE_DEFAULT;
  105. return $this->_getPost($sType, $aEvent, $aBrowseParams);
  106. }
  107. public function getPosts($aParams)
  108. {
  109. $iStart = $aParams['start'];
  110. $iPerPage = $aParams['per_page'];
  111. $aParamsDb = $aParams;
  112. //--- Check for Previous
  113. $bPrevious = false;
  114. if($iStart - 1 >= 0) {
  115. $aParamsDb['start'] -= 1;
  116. $aParamsDb['per_page'] += 1;
  117. $bPrevious = true;
  118. }
  119. //--- Check for Next
  120. $aParamsDb['per_page'] += 1;
  121. $aEvents = $this->_oDb->getEvents($aParamsDb);
  122. //--- Check for Previous
  123. if($bPrevious)
  124. $aEvent = array_shift($aEvents);
  125. //--- Check for Next
  126. $bNext = false;
  127. if(count($aEvents) > $iPerPage) {
  128. $aEvent = array_pop($aEvents);
  129. $bNext = true;
  130. }
  131. $iEvents = count($aEvents);
  132. $sContent = $this->getEmpty($iEvents <= 0);
  133. foreach($aEvents as $aEvent) {
  134. $sEvent = $this->getPost($aEvent, $aParams);
  135. if(empty($sEvent))
  136. continue;
  137. $sContent .= $sEvent;
  138. }
  139. $iYearSel = (int)$aParams['timeline'];
  140. $iYearMin = $this->_oDb->getMaxDuration($aParams);
  141. $sBack = $this->getBack($iYearSel);
  142. $sLoadMore = $this->getLoadMore($iStart, $iPerPage, $bNext, $iYearSel, $iYearMin, $iEvents > 0);
  143. return array($sContent, $sLoadMore, $sBack);
  144. }
  145. public function getEmpty($bVisible)
  146. {
  147. return $this->parseHtmlByName('empty.html', array(
  148. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  149. 'visible' => $bVisible ? 'block' : 'none',
  150. 'content' => MsgBox(_t('_bx_timeline_txt_msg_no_results'))
  151. ));
  152. }
  153. public function getBack($iYearSel)
  154. {
  155. if($iYearSel == 0)
  156. return '';
  157. $sStylePrefix = $this->_oConfig->getPrefix('style');
  158. $sJsObject = $this->_oConfig->getJsObject('view');
  159. $iYearNow = date('Y', time());
  160. return $this->parseHtmlByName('back.html', array(
  161. 'style_prefix' => $sStylePrefix,
  162. 'href' => 'javascript:void(0)',
  163. 'title' => _t('_bx_timeline_txt_jump_to_n_year', $iYearNow),
  164. 'bx_repeat:attrs' => array(
  165. array('key' => 'onclick', 'value' => 'javascript:' . $sJsObject . '.changeTimeline(this, 0)')
  166. ),
  167. 'content' => _t('_bx_timeline_txt_jump_to_recent')
  168. ));
  169. }
  170. public function getLoadMore($iStart, $iPerPage, $bEnabled, $iYearSel, $iYearMin, $bVisible = true)
  171. {
  172. $sStylePrefix = $this->_oConfig->getPrefix('style');
  173. $sJsObject = $this->_oConfig->getJsObject('view');
  174. $sYears = '';
  175. if(!empty($iYearMin)) {
  176. $iYearMax = date('Y', time()) - 1;
  177. for($i = $iYearMax; $i >= $iYearMin; $i--)
  178. $sYears .= ($i != $iYearSel ? $this->parseHtmlByName('bx_a.html', array(
  179. 'href' => 'javascript:void(0)',
  180. 'title' => _t('_bx_timeline_txt_jump_to_n_year', $i),
  181. 'bx_repeat:attrs' => array(
  182. array('key' => 'onclick', 'value' => 'javascript:' . $sJsObject . '.changeTimeline(this, ' . $i . ')')
  183. ),
  184. 'content' => $i
  185. )) : $i) . ', ';
  186. $sYears = substr($sYears, 0, -2);
  187. }
  188. $aTmplVars = array(
  189. 'style_prefix' => $sStylePrefix,
  190. 'visible' => $bEnabled && $bVisible ? 'block' : 'none',
  191. 'bx_if:is_disabled' => array(
  192. 'condition' => !$bEnabled,
  193. 'content' => array()
  194. ),
  195. 'bx_if:show_on_click' => array(
  196. 'condition' => $bEnabled,
  197. 'content' => array(
  198. 'on_click' => 'javascript:' . $sJsObject . '.changePage(this, ' . ($iStart + $iPerPage) . ', ' . $iPerPage . ')'
  199. )
  200. ),
  201. 'bx_if:show_jump_to' => array(
  202. 'condition' => !empty($sYears),
  203. 'content' => array(
  204. 'style_prefix' => $sStylePrefix,
  205. 'years' => $sYears
  206. )
  207. )
  208. );
  209. return $this->parseHtmlByName('load_more.html', $aTmplVars);
  210. }
  211. public function getComments($sSystem, $iId)
  212. {
  213. $oModule = $this->getModule();
  214. $sStylePrefix = $this->_oConfig->getPrefix('style');
  215. $oCmts = $oModule->getCmtsObject($sSystem, $iId);
  216. if($oCmts === false)
  217. return '';
  218. $aComments = $oCmts->getCommentsBlock(0, 0, false);
  219. return $this->parseHtmlByName('comments.html', array(
  220. 'style_prefix' => $sStylePrefix,
  221. 'id' => $iId,
  222. 'content' => $aComments['content']
  223. ));
  224. }
  225. public function getShareElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  226. {
  227. $aShared = $this->_oDb->getShared($sType, $sAction, $iObjectId);
  228. if(empty($aShared) || !is_array($aShared))
  229. return '';
  230. if($this->getModule()->isAllowedShare($aShared) !== true)
  231. return '';
  232. $bShowDoShareAsButtonSmall = isset($aParams['show_do_share_as_button_small']) && $aParams['show_do_share_as_button_small'] == true;
  233. $bShowDoShareAsButton = !$bShowDoShareAsButtonSmall && isset($aParams['show_do_share_as_button']) && $aParams['show_do_share_as_button'] == true;
  234. $bShowDoShareIcon = isset($aParams['show_do_share_icon']) && $aParams['show_do_share_icon'] == true;
  235. $bShowDoShareLabel = isset($aParams['show_do_share_label']) && $aParams['show_do_share_label'] == true;
  236. $bShowCounter = isset($aParams['show_counter']) && $aParams['show_counter'] === true;
  237. $sDoShare = '';
  238. if($bShowDoShareIcon)
  239. $sDoShare .= $this->parseHtmlByName('bx_icon.html', array('name' => 'share'));
  240. if($bShowDoShareLabel)
  241. $sDoShare .= ($sDoShare != '' ? ' ' : '') . _t('_bx_timeline_txt_do_share');
  242. $sDoShare = $this->parseHtmlByName('bx_a.html', array(
  243. 'href' => 'javascript:void(0)',
  244. 'title' => _t('_bx_timeline_txt_do_share'),
  245. 'bx_repeat:attrs' => array(
  246. array('key' => 'class', 'value' => ($bShowDoShareAsButton ? 'bx-btn' : '') . ($bShowDoShareAsButtonSmall ? 'bx-btn bx-btn-small' : '')),
  247. array('key' => 'onclick', 'value' => $this->getShareJsClick($iOwnerId, $sType, $sAction, $iObjectId))
  248. ),
  249. 'content' => $sDoShare
  250. ));
  251. $sStylePrefix = $this->_oConfig->getPrefix('style');
  252. $sStylePrefixShare = $sStylePrefix . '-share-';
  253. return $this->parseHtmlByName('share_element_block.html', array(
  254. 'style_prefix' => $sStylePrefix,
  255. 'html_id' => $this->_oConfig->getHtmlIds('share', 'main') . $aShared['id'],
  256. 'class' => ($bShowDoShareAsButton ? $sStylePrefixShare . 'button' : '') . ($bShowDoShareAsButtonSmall ? $sStylePrefixShare . 'button-small' : ''),
  257. 'count' => $aShared['shares'],
  258. 'do_share' => $sDoShare,
  259. 'bx_if:show_counter' => array(
  260. 'condition' => $bShowCounter,
  261. 'content' => array(
  262. 'style_prefix' => $sStylePrefix,
  263. 'bx_if:show_hidden' => array(
  264. 'condition' => (int)$aShared['shares'] == 0,
  265. 'content' => array()
  266. ),
  267. 'counter' => $this->getShareCounter($aShared)
  268. )
  269. ),
  270. 'script' => $this->getShareJsScript()
  271. ));
  272. }
  273. public function getShareCounter($aEvent)
  274. {
  275. $sStylePrefix = $this->_oConfig->getPrefix('style');
  276. $sJsObject = $this->_oConfig->getJsObject('share');
  277. return $this->parseHtmlByName('share_counter.html', array(
  278. 'href' => 'javascript:void(0)',
  279. 'title' => _t('_bx_timeline_txt_shared_by'),
  280. 'bx_repeat:attrs' => array(
  281. array('key' => 'id', 'value' => $this->_oConfig->getHtmlIds('share', 'counter') . $aEvent['id']),
  282. array('key' => 'class', 'value' => $sStylePrefix . '-counter'),
  283. array('key' => 'onclick', 'value' => 'javascript:' . $sJsObject . '.toggleByPopup(this, ' . $aEvent['id'] . ')')
  284. ),
  285. 'content' => !empty($aEvent['shares']) && (int)$aEvent['shares'] > 0 ? $aEvent['shares'] : ''
  286. ));
  287. }
  288. public function getSharedBy($iId)
  289. {
  290. $aTmplUsers = array();
  291. $oModule = $this->getModule();
  292. $sStylePrefix = $this->_oConfig->getPrefix('style');
  293. $aUserIds = $this->_oDb->getSharedBy($iId);
  294. foreach($aUserIds as $iUserId) {
  295. list($sUserName, $sUserUrl, $sUserIcon, $sUserUnit) = $oModule->getUserInfo($iUserId);
  296. $aTmplUsers[] = array(
  297. 'style_prefix' => $sStylePrefix,
  298. 'user_unit' => $sUserUnit
  299. );
  300. }
  301. if(empty($aTmplUsers))
  302. $aTmplUsers = MsgBox(_t('_Empty'));
  303. return $this->parseHtmlByName('share_by_list.html', array(
  304. 'style_prefix' => $sStylePrefix,
  305. 'bx_repeat:list' => $aTmplUsers
  306. ));
  307. }
  308. public function getShareJsScript()
  309. {
  310. $this->addCss(array('share.css'));
  311. $this->addJs(array('main.js', 'share.js'));
  312. return $this->getJsCode('share');
  313. }
  314. public function getShareJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  315. {
  316. $sJsObject = $this->_oConfig->getJsObject('share');
  317. $sFormat = "%s.shareItem(this, %d, '%s', '%s', %d);";
  318. $iOwnerId = !empty($iOwnerId) ? (int)$iOwnerId : $this->getModule()->getUserId(); //--- in whose timeline the content will be shared
  319. return sprintf($sFormat, $sJsObject, $iOwnerId, $sType, $sAction, (int)$iObjectId);
  320. }
  321. public function getAttachLinkForm()
  322. {
  323. $sStylePrefix = $this->_oConfig->getPrefix('style');
  324. $sJsObject = $this->_oConfig->getJsObject('post');
  325. $aForm = $this->getModule()->getFormAttachLink();
  326. return $this->parseHtmlByName('attach_link_form.html', array(
  327. 'style_prefix' => $sStylePrefix,
  328. 'js_object' => $sJsObject,
  329. 'form_id' => $aForm['form_id'],
  330. 'form' => $aForm['form'],
  331. ));
  332. }
  333. public function getAttachLinkField($iUserId)
  334. {
  335. $sStylePrefix = $this->_oConfig->getPrefix('style');
  336. $aLinks = $this->_oDb->getUnusedLinks($iUserId);
  337. $sLinks = '';
  338. foreach($aLinks as $aLink)
  339. $sLinks .= $this->getAttachLinkItem($iUserId, $aLink);
  340. return $this->parsePageByName('attach_link_form_field.html', array(
  341. 'html_id' => $this->_oConfig->getHtmlIds('post', 'attach_link_form_field'),
  342. 'style_prefix' => $sStylePrefix,
  343. 'links' => $sLinks
  344. ));
  345. }
  346. public function getAttachLinkItem($iUserId, $mixedLink)
  347. {
  348. $aLink = is_array($mixedLink) ? $mixedLink : $this->_oDb->getUnusedLinks($iUserId, (int)$mixedLink);
  349. if(empty($aLink) || !is_array($aLink))
  350. return '';
  351. $sStylePrefix = $this->_oConfig->getPrefix('style');
  352. $sJsObject = $this->_oConfig->getJsObject('post');
  353. $sLinkIdPrefix = $this->_oConfig->getHtmlIds('post', 'attach_link_item');
  354. return $this->parsePageByName('attach_link_item.html', array(
  355. 'html_id' => $sLinkIdPrefix . $aLink['id'],
  356. 'style_prefix' => $sStylePrefix,
  357. 'js_object' => $sJsObject,
  358. 'id' => $aLink['id'],
  359. 'url' => $aLink['url'],
  360. 'title' => $aLink['title'],
  361. ));
  362. }
  363. protected function _getPost($sType, $aEvent, $aBrowseParams = array())
  364. {
  365. $oModule = $this->getModule();
  366. $sStylePrefix = $this->_oConfig->getPrefix('style');
  367. $sJsObject = $this->_oConfig->getJsObject('view');
  368. list($sAuthorName, $sAuthorUrl, $sAuthorIcon) = $oModule->getUserInfo($aEvent['object_owner_id']);
  369. $bAuthorIcon = !empty($sAuthorIcon);
  370. $aTmplVarsMenuItemActions = $this->_getTmplVarsMenuItemActions($aEvent, $aBrowseParams);
  371. $aTmplVarsTimelineOwner = array();
  372. if(isset($aBrowseParams['type']) && $aBrowseParams['type'] == BX_BASE_MOD_NTFS_TYPE_CONNECTIONS)
  373. $aTmplVarsTimelineOwner = $this->_getTmplVarsTimelineOwner($aEvent);
  374. $bBrowseItem = isset($aBrowseParams['type']) && $aBrowseParams['type'] == BX_TIMELINE_TYPE_ITEM;
  375. $aTmplVars = array (
  376. 'style_prefix' => $sStylePrefix,
  377. 'js_object' => $sJsObject,
  378. 'html_id' => $this->_oConfig->getHtmlIds('view', 'item') . $aEvent['id'],
  379. 'class' => $bBrowseItem ? 'bx-tl-view-sizer' : 'bx-tl-grid-sizer',
  380. 'bx_if:show_menu_item_manage' => array(
  381. 'condition' => $oModule->getManageMenuObject($aEvent)->isVisible(),
  382. 'content' => array(
  383. 'style_prefix' => $sStylePrefix,
  384. 'js_object' => $sJsObject,
  385. 'id' => $aEvent['id'],
  386. )
  387. ),
  388. 'bx_if:show_icon' => array(
  389. 'condition' => $bAuthorIcon,
  390. 'content' => array(
  391. 'author_icon' => $sAuthorIcon
  392. )
  393. ),
  394. 'bx_if:show_icon_empty' => array(
  395. 'condition' => !$bAuthorIcon,
  396. 'content' => array()
  397. ),
  398. 'item_owner_url' => $sAuthorUrl,
  399. 'item_owner_name' => $sAuthorName,
  400. 'bx_if:show_timeline_owner' => array(
  401. 'condition' => !empty($aTmplVarsTimelineOwner),
  402. 'content' => $aTmplVarsTimelineOwner
  403. ),
  404. 'item_view_url' => $this->_oConfig->getItemViewUrl($aEvent),
  405. 'item_date' => bx_time_js($aEvent['date']),
  406. 'content' => is_string($aEvent['content']) ? $aEvent['content'] : $this->_getContent($sType, $aEvent['content'], $aBrowseParams),
  407. 'bx_if:show_menu_item_actions' => array(
  408. 'condition' => !empty($aTmplVarsMenuItemActions),
  409. 'content' => $aTmplVarsMenuItemActions
  410. ),
  411. 'comments' => $bBrowseItem ? $this->_getComments($aEvent['comments']) : '',
  412. 'votes' => $this->_getVotes($aEvent['votes'])
  413. );
  414. return $this->parseHtmlByName('item.html', $aTmplVars);
  415. }
  416. protected function _getContent($sType, $aContent, $aBrowseParams = array())
  417. {
  418. $sMethod = '_getTmplVarsContent' . ucfirst($sType);
  419. if(!method_exists($this, $sMethod))
  420. return '';
  421. $aTmplVars = $this->$sMethod($aContent, $aBrowseParams);
  422. return $this->parseHtmlByName('type_' . $sType . '.html', $aTmplVars);
  423. }
  424. protected function _getComments($aComments)
  425. {
  426. $mixedComments = $this->getModule()->getCommentsData($aComments);
  427. if($mixedComments === false)
  428. return '';
  429. list($sSystem, $iObjectId, $iCount) = $mixedComments;
  430. return $this->getComments($sSystem, $iObjectId);
  431. }
  432. protected function _getVotes($aVotes)
  433. {
  434. $oModule = $this->getModule();
  435. $mixedVotes = $oModule->getVotesData($aVotes);
  436. if($mixedVotes === false)
  437. return '';
  438. list($sSystem, $iObjectId, $iCount) = $mixedVotes;
  439. $oVote = $oModule->getVoteObject($sSystem, $iObjectId);
  440. if($oVote === false)
  441. return '';
  442. return $oVote->getJsScript();
  443. }
  444. protected function _getImagePopup()
  445. {
  446. $sViewImagePopupId = $this->_oConfig->getHtmlIds('view', 'photo_popup');
  447. $sViewImagePopupContent = $this->parseHtmlByName('popup_image.html', array(
  448. 'image_url' => ''
  449. ));
  450. bx_import('BxTemplFunctions');
  451. return BxTemplFunctions::getInstance()->transBox($sViewImagePopupId, $sViewImagePopupContent, true);
  452. }
  453. protected function _getTmplVarsMenuItemActions(&$aEvent)
  454. {
  455. bx_import('BxDolMenu');
  456. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_actions'));
  457. $oMenu->setEvent($aEvent);
  458. $sMenu = $oMenu->getCode();
  459. if(empty($sMenu))
  460. return array();
  461. return array(
  462. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  463. 'js_object' => $this->_oConfig->getJsObject('view'),
  464. 'menu_item_actions' => $sMenu
  465. );
  466. }
  467. protected function _getTmplVarsTimelineOwner(&$aEvent)
  468. {
  469. $oModule = $this->getModule();
  470. $aTmplVarsTimelineOwner = array();
  471. if((int)$aEvent['owner_id'] != (int)$aEvent['object_owner_id']) {
  472. list($sTimelineAuthorName, $sTimelineAuthorUrl) = $oModule->getUserInfo($aEvent['owner_id']);
  473. $aTmplVarsTimelineOwner = array(
  474. 'owner_url' => $sTimelineAuthorUrl,
  475. 'owner_username' => $sTimelineAuthorName,
  476. );
  477. }
  478. return $aTmplVarsTimelineOwner;
  479. }
  480. protected function _getTmplVarsContentPost($aContent, $aBrowseParams = array())
  481. {
  482. $sStylePrefix = $this->_oConfig->getPrefix('style');
  483. $sJsObject = $this->_oConfig->getJsObject('view');
  484. //--- Process Text ---//
  485. $sUrl = isset($aContent['url']) ? bx_html_attribute($aContent['url']) : '';
  486. $sTitle = $sTitleAttr = '';
  487. if(isset($aContent['title'])) {
  488. $sTitle = bx_process_output($aContent['title']);
  489. $sTitleAttr = bx_html_attribute($aContent['title']);
  490. }
  491. if(!empty($sUrl) && !empty($sTitle))
  492. $sTitle = $this->parseHtmlByName('bx_a.html', array(
  493. 'href' => $sUrl,
  494. 'title' => $sTitleAttr,
  495. 'bx_repeat:attrs' => array(
  496. array('key' => 'class', 'value' => $sStylePrefix . '-title')
  497. ),
  498. 'content' => $sTitle
  499. ));
  500. $sText = isset($aContent['text']) ? strip_tags($aContent['text'], '<p><br>') : '';
  501. $sTextMore = '';
  502. $iMaxLength = $this->_oConfig->getCharsDisplayMax();
  503. if(strlen($sText) > $iMaxLength) {
  504. $iLength = strpos($sText, ' ', $iMaxLength);
  505. $sTextMore = trim(substr($sText, $iLength));
  506. $sText = trim(substr($sText, 0, $iLength));
  507. }
  508. $sText = $this->_prepareTextForOutput($sText);
  509. $sTextMore = $this->_prepareTextForOutput($sTextMore);
  510. //--- Process Links ---//
  511. $aTmplVarsLinks = array();
  512. if(!empty($aContent['links']))
  513. foreach($aContent['links'] as $aLink)
  514. $aTmplVarsLinks[] = array(
  515. 'style_prefix' => $sStylePrefix,
  516. 'url' => $aLink['url'],
  517. 'title' => $aLink['title'],
  518. 'bx_if:show_text' => array(
  519. 'condition' => !empty($aLink['text']),
  520. 'content' => array(
  521. 'style_prefix' => $sStylePrefix,
  522. 'text' => $aLink['text']
  523. )
  524. )
  525. );
  526. //--- Process Photos ---//
  527. $aTmplVarsImages = array();
  528. if(!empty($aContent['images'])) {
  529. $bBrowseItem = isset($aBrowseParams['type']) && $aBrowseParams['type'] == BX_TIMELINE_TYPE_ITEM;
  530. foreach($aContent['images'] as $aImage) {
  531. $sImage = '';
  532. if(!empty($aImage['src']))
  533. $sImage = $this->parseHtmlByName('bx_img.html', array(
  534. 'src' => $bBrowseItem && !empty($aImage['src_orig']) ? $aImage['src_orig'] : $aImage['src'],
  535. 'bx_repeat:attrs' => array(
  536. array('key' => 'class', 'value' => $sStylePrefix . '-item-image')
  537. )
  538. ));
  539. if(!empty($sImage) && (isset($aImage['url']) || isset($aImage['onclick']))) {
  540. $aAttrs = array();
  541. if(isset($aImage['onclick']))
  542. $aAttrs[] = array('key' => 'onclick', 'value' => $aImage['onclick']);
  543. $sImage = $this->parseHtmlByName('bx_a.html', array(
  544. 'href' => isset($aImage['url']) ? $aImage['url'] : 'javascript:void(0)',
  545. 'title' => '',
  546. 'bx_repeat:attrs' => $aAttrs,
  547. 'content' => $sImage
  548. ));
  549. }
  550. $aTmplVarsImages[] = array(
  551. 'style_prefix' => $sStylePrefix,
  552. 'image' => $sImage
  553. );
  554. }
  555. }
  556. return array(
  557. 'style_prefix' => $sStylePrefix,
  558. 'bx_if:show_title' => array(
  559. 'condition' => !empty($sTitle),
  560. 'content' => array(
  561. 'style_prefix' => $sStylePrefix,
  562. 'title' => $sTitle,
  563. )
  564. ),
  565. 'bx_if:show_content' => array(
  566. 'condition' => !empty($sText),
  567. 'content' => array(
  568. 'style_prefix' => $sStylePrefix,
  569. 'item_content' => $sText,
  570. 'bx_if:show_more' => array(
  571. 'condition' => !empty($sTextMore),
  572. 'content' => array(
  573. 'style_prefix' => $sStylePrefix,
  574. 'js_object' => $sJsObject,
  575. 'item_content_more' => $sTextMore
  576. )
  577. ),
  578. )
  579. ),
  580. 'bx_if:show_links' => array(
  581. 'condition' => !empty($aTmplVarsLinks),
  582. 'content' => array(
  583. 'style_prefix' => $sStylePrefix,
  584. 'bx_repeat:links' => $aTmplVarsLinks
  585. )
  586. ),
  587. 'bx_if:show_images' => array(
  588. 'condition' => !empty($aTmplVarsImages),
  589. 'content' => array(
  590. 'style_prefix' => $sStylePrefix,
  591. 'bx_repeat:images' => $aTmplVarsImages
  592. )
  593. )
  594. );
  595. }
  596. protected function _getTmplVarsContentShare($aContent, $aBrowseParams = array())
  597. {
  598. $sStylePrefix = $this->_oConfig->getPrefix('style');
  599. $sOwnerLink = $this->parseHtmlByName('bx_a.html', array(
  600. 'href' => $aContent['owner_url'],
  601. 'title' => '',
  602. 'bx_repeat:attrs' => array(),
  603. 'content' => $aContent['owner_name']
  604. ));
  605. $sSample = _t($aContent['sample']);
  606. $sSampleLink = empty($aContent['url']) ? $sSample : $this->parseHtmlByName('bx_a.html', array(
  607. 'href' => $aContent['url'],
  608. 'title' => '',
  609. 'bx_repeat:attrs' => array(),
  610. 'content' => $sSample
  611. ));
  612. $sTitle = _t('_bx_timeline_txt_shared', $sOwnerLink, $sSampleLink);
  613. $sText = $this->_getContent($aContent['parse_type'], $aContent);
  614. return array(
  615. 'bx_if:show_title' => array(
  616. 'condition' => !empty($sTitle),
  617. 'content' => array(
  618. 'style_prefix' => $sStylePrefix,
  619. 'title' => $sTitle,
  620. )
  621. ),
  622. 'bx_if:show_content' => array(
  623. 'condition' => !empty($sText),
  624. 'content' => array(
  625. 'style_prefix' => $sStylePrefix,
  626. 'content' => $sText,
  627. )
  628. )
  629. );
  630. }
  631. protected function _getSystemData(&$aEvent)
  632. {
  633. $sHandler = $aEvent['type'] . '_' . $aEvent['action'];
  634. if(!$this->_oConfig->isHandler($sHandler))
  635. return '';
  636. $aHandler = $this->_oConfig->getHandlers($sHandler);
  637. if(!empty($aHandler['module_name']) && !empty($aHandler['module_class']) && !empty($aHandler['module_method'])) {
  638. $aEvent['js_mode'] = $this->_oConfig->getJsMode();
  639. return BxDolService::call($aHandler['module_name'], $aHandler['module_method'], array($aEvent), $aHandler['module_class']);
  640. }
  641. $sMethod = 'display' . bx_gen_method_name($aHandler['alert_unit'] . '_' . $aHandler['alert_action']);
  642. if(!method_exists($this, $sMethod))
  643. return '';
  644. return $this->$sMethod($aEvent);
  645. }
  646. protected function _getCommonData(&$aEvent)
  647. {
  648. $oModule = $this->getModule();
  649. $sJsObject = $this->_oConfig->getJsObject('view');
  650. $sPrefix = $this->_oConfig->getPrefix('common_post');
  651. $sType = str_replace($sPrefix, '', $aEvent['type']);
  652. $aResult = array(
  653. 'owner_id' => $aEvent['object_id'],
  654. 'content_type' => $sType,
  655. 'content' => array(
  656. 'sample' => '_bx_timeline_txt_sample',
  657. 'url' => $this->_oConfig->getItemViewUrl($aEvent)
  658. ), //a string to display or array to parse default template before displaying.
  659. 'votes' => '',
  660. 'comments' => '',
  661. 'title' => '', //may be empty.
  662. 'description' => '' //may be empty.
  663. );
  664. switch($sType) {
  665. case BX_TIMELINE_PARSE_TYPE_POST:
  666. if(!empty($aEvent['content']))
  667. $aResult['content'] = array_merge($aResult['content'], unserialize($aEvent['content']));
  668. $aLinks = $this->_oDb->getLinks($aEvent['id']);
  669. if(!empty($aLinks) && is_array($aLinks))
  670. foreach($aLinks as $aLink)
  671. $aResult['content']['links'][] = array(
  672. 'url' => $aLink['url'],
  673. 'title' => $aLink['title'],
  674. 'text' => $aLink['text']
  675. );
  676. $aPhotos = $this->_oDb->getPhotos($aEvent['id']);
  677. if(!empty($aPhotos) && is_array($aPhotos)) {
  678. bx_import('BxDolStorage');
  679. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage'));
  680. bx_import('BxDolTranscoderImage');
  681. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_view'));
  682. foreach($aPhotos as $iPhotoId) {
  683. $iPhotoIndex = array_search($iPhotoId, $aPhotos);
  684. $sPhotoSrcOrig = $oStorage->getFileUrlById($iPhotoId);
  685. $aResult['content']['images'][] = array(
  686. 'src' => $oTranscoder->getImageUrl($iPhotoId),
  687. 'src_orig' => $sPhotoSrcOrig,
  688. 'title' => '',
  689. 'onclick' => $sJsObject . '.showPhoto(this, \'' . $sPhotoSrcOrig . '\')'
  690. );
  691. }
  692. }
  693. break;
  694. case BX_TIMELINE_PARSE_TYPE_SHARE:
  695. if(empty($aEvent['content']))
  696. return array();
  697. $aContent = unserialize($aEvent['content']);
  698. if(!$this->_oConfig->isSystem($aContent['type'] , $aContent['action'])) {
  699. $aShared = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $aContent['object_id']));
  700. $aShared = $this->_getCommonData($aShared);
  701. }
  702. else
  703. $aShared = $this->_getSystemData($aContent);
  704. if(empty($aShared) || !is_array($aShared))
  705. return array();
  706. $aResult['content'] = array_merge($aContent, $aShared['content']);
  707. $aResult['content']['parse_type'] = !empty($aShared['content_type']) ? $aShared['content_type'] : BX_TIMELINE_PARSE_TYPE_DEFAULT;
  708. $aResult['content']['owner_id'] = $aShared['owner_id'];
  709. list($aResult['content']['owner_name'], $aResult['content']['owner_url']) = $oModule->getUserInfo($aShared['owner_id']);
  710. list($sUserName) = $oModule->getUserInfo($aEvent['object_id']);
  711. $sSample = !empty($aResult['content']['sample']) ? $aResult['content']['sample'] : '_bx_timeline_txt_sample';
  712. $aResult['title'] = _t('_bx_timeline_txt_user_shared_sample', $sUserName, $aResult['content']['owner_name'], _t($sSample));
  713. $aResult['description'] = '';
  714. break;
  715. }
  716. $sSystem = $this->_oConfig->getObject('vote');
  717. if($oModule->getVoteObject($sSystem, $aEvent['id']) !== false)
  718. $aResult['votes'] = array(
  719. 'system' => $sSystem,
  720. 'object_id' => $aEvent['id'],
  721. 'count' => $aEvent['votes']
  722. );
  723. $sSystem = $this->_oConfig->getObject('comment');
  724. if($oModule->getCmtsObject($sSystem, $aEvent['id']) !== false)
  725. $aResult['comments'] = array(
  726. 'system' => $sSystem,
  727. 'object_id' => $aEvent['id'],
  728. 'count' => $aEvent['comments']
  729. );
  730. return $aResult;
  731. }
  732. protected function _prepareTextForOutput($s)
  733. {
  734. $sHttp = '';
  735. $sPattern = $this->_oConfig->getPregPattern('url');
  736. $aMatches = array();
  737. if(preg_match($sPattern, $s, $aMatches) && empty($aMatches[1]))
  738. $sHttp = 'http://';
  739. $s = bx_process_output($s, BX_DATA_TEXT_MULTILINE);
  740. $s = preg_replace($sPattern, '<a href="' . $sHttp . '$0" target="_blank">$0</a>', $s);
  741. return $s;
  742. }
  743. }
  744. /** @} */