BxTimelineTemplate.php 32 KB

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