BxTimelineTemplate.php 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup Timeline Timeline
  7. * @ingroup UnaModules
  8. *
  9. * @{
  10. */
  11. class BxTimelineTemplate extends BxBaseModNotificationsTemplate
  12. {
  13. protected static $_sTmplContentItemItem;
  14. protected static $_sTmplContentItemOutline;
  15. protected static $_sTmplContentItemTimeline;
  16. protected static $_sTmplContentItemSearch;
  17. protected static $_sTmplContentTypePost;
  18. protected static $_sTmplContentTypeRepost;
  19. protected $_bShowTimelineDividers;
  20. function __construct(&$oConfig, &$oDb)
  21. {
  22. parent::__construct($oConfig, $oDb);
  23. $this->_bShowTimelineDividers = false;
  24. }
  25. public function getCss($bDynamic = false)
  26. {
  27. $mixedResult = parent::getCss($bDynamic);
  28. $mixedResult .= $this->addCss(array(
  29. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'flickity/|flickity.css',
  30. BX_DIRECTORY_PATH_PLUGINS_PUBLIC . 'emoji/css/|emoji.css',
  31. 'jquery-ui/jquery-ui.css',
  32. 'cmts.css',
  33. 'post.css',
  34. 'repost.css',
  35. ), $bDynamic);
  36. if($bDynamic)
  37. return $mixedResult;
  38. }
  39. public function getJs($bDynamic = false)
  40. {
  41. $mixedResult = parent::getJs($bDynamic);
  42. $mixedResult .= $this->addJs(array(
  43. 'jquery-ui/jquery-ui.custom.min.js',
  44. 'jquery.form.min.js',
  45. 'jquery.ba-resize.min.js',
  46. 'emoji/js/util.js',
  47. 'emoji/js/config.js',
  48. 'emoji/js/emoji-picker.js',
  49. 'autosize.min.js',
  50. 'masonry.pkgd.min.js',
  51. 'modernizr.min.js',
  52. 'flickity/flickity.pkgd.min.js',
  53. 'emoji/js/jquery.emojiarea.js',
  54. 'embedly-player.min.js',
  55. 'BxDolCmts.js',
  56. 'post.js',
  57. 'repost.js',
  58. ), $bDynamic);
  59. if($bDynamic)
  60. return $mixedResult;
  61. }
  62. public function getPostBlock($iOwnerId, $aParams = array())
  63. {
  64. $aForm = $this->getModule()->getFormPost($aParams);
  65. return $this->parseHtmlByName('block_post.html', array (
  66. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  67. 'js_object' => $this->_oConfig->getJsObject('post'),
  68. 'js_content' => $this->getJsCode('post', array(
  69. 'sVideosAutoplay' => $this->_oConfig->getVideosAutoplay(),
  70. 'oRequestParams' => array(
  71. 'type' => isset($aParams['type']) ? $aParams['type'] : BX_TIMELINE_TYPE_DEFAULT,
  72. 'owner_id' => $iOwnerId
  73. )
  74. )),
  75. 'form' => $aForm['form']
  76. ));
  77. }
  78. public function getViewBlock($aParams)
  79. {
  80. $oModule = $this->getModule();
  81. //--- Add live update
  82. $oModule->actionResumeLiveUpdate($aParams['type'], $aParams['owner_id']);
  83. $sServiceCall = BxDolService::getSerializedService($this->_oConfig->getName(), 'get_live_updates', array($aParams['type'], $aParams['owner_id'], $oModule->getUserId(), '{count}', '{init}'));
  84. $sLiveUpdatesCode = BxDolLiveUpdates::getInstance()->add($this->_oConfig->getLiveUpdateKey($aParams['type'], $aParams['owner_id']), 1, $sServiceCall);
  85. //--- Add live update
  86. list($sContent, $sLoadMore, $sBack, $sEmpty) = $this->getPosts($aParams);
  87. return $sLiveUpdatesCode . $this->parseHtmlByName('block_view.html', array(
  88. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  89. 'html_id' => $this->_oConfig->getHtmlIds('view', 'main_' . $aParams['view']),
  90. 'view' => $aParams['view'],
  91. 'back' => $sBack,
  92. 'empty' => $sEmpty,
  93. 'content' => $sContent,
  94. 'load_more' => $sLoadMore,
  95. 'show_more' => $this->_getShowMore($aParams),
  96. 'view_image_popup' => $this->_getImagePopup($aParams),
  97. 'js_content' => $this->getJsCode('view', array(
  98. 'sVideosAutoplay' => $this->_oConfig->getVideosAutoplay(),
  99. 'oRequestParams' => array(
  100. 'type' => $aParams['type'],
  101. 'owner_id' => $aParams['owner_id'],
  102. 'start' => $aParams['start'],
  103. 'per_page' => $aParams['per_page'],
  104. 'filter' => $aParams['filter'],
  105. 'modules' => $aParams['modules'],
  106. 'timeline' => $aParams['timeline'],
  107. )
  108. )) . $this->getJsCode('repost')
  109. ));
  110. }
  111. public function getSearchBlock($sContent)
  112. {
  113. $oModule = $this->getModule();
  114. $aParams = $oModule->getParams(BX_TIMELINE_VIEW_SEARCH);
  115. return $this->parseHtmlByName('block_search.html', array(
  116. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  117. 'html_id' => $this->_oConfig->getHtmlIds('view', 'main_' . $aParams['view']),
  118. 'view' => $aParams['view'],
  119. 'content' => $sContent,
  120. 'view_image_popup' => $this->_getImagePopup($aParams),
  121. 'js_content' => $this->getJsCode('view', array(
  122. 'oRequestParams' => array(
  123. 'type' => $aParams['type'],
  124. 'owner_id' => $aParams['owner_id'],
  125. 'start' => $aParams['start'],
  126. 'per_page' => $aParams['per_page'],
  127. 'filter' => $aParams['filter'],
  128. 'modules' => $aParams['modules'],
  129. 'timeline' => $aParams['timeline'],
  130. )
  131. ))
  132. ));
  133. }
  134. public function getItemBlock($iId)
  135. {
  136. $CNF = $this->_oConfig->CNF;
  137. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  138. if(empty($aEvent))
  139. return array('content' => MsgBox(_t('_Empty')), 'designbox_id' => 13);
  140. $iProfile = (int)$aEvent[$CNF['FIELD_OWNER_ID']];
  141. if(!empty($iProfile)) {
  142. $oProfile = BxDolProfile::getInstance($iProfile);
  143. if(!$oProfile)
  144. return array('content' => MsgBox(_t('_Empty')), 'designbox_id' => 13);
  145. $mixedResult = $oProfile->checkAllowedProfileView();
  146. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  147. return array('content' => MsgBox($mixedResult), 'designbox_id' => 13);
  148. }
  149. $aParams = array(
  150. 'view' => BX_TIMELINE_VIEW_ITEM,
  151. 'type' => BX_TIMELINE_TYPE_ITEM
  152. );
  153. $sContent = $this->getPost($aEvent, $aParams);
  154. $oModule = $this->getModule();
  155. if($oModule->isAllowedViewCounter($aEvent) !== true)
  156. return array('content' => MsgBox(_t('_Access denied')), 'designbox_id' => 13);
  157. if(!$this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  158. $mixedViews = $oModule->getViewsData($aEvent['views']);
  159. if($mixedViews !== false) {
  160. list($sSystem, $iObjectId) = $mixedViews;
  161. $oModule->getViewObject($sSystem, $iObjectId)->doView();
  162. }
  163. }
  164. list($sAuthorName) = $oModule->getUserInfo($aEvent['object_owner_id']);
  165. $oTemplate = BxDolTemplate::getInstance();
  166. $oTemplate->setPageHeader(strip_tags($sAuthorName . ' ' . _t($aEvent['sample_action'], _t($aEvent['sample']))));
  167. $oTemplate->setPageDescription(strip_tags($aEvent['title']));
  168. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  169. if($oMetatags)
  170. $oMetatags->addPageMetaInfo($aEvent[$CNF['FIELD_ID']]);
  171. $sReferrer = '';
  172. if(isset($_SERVER['HTTP_REFERER']) && mb_stripos($_SERVER['HTTP_REFERER'], BX_DOL_URL_ROOT) === 0)
  173. $sReferrer = $_SERVER['HTTP_REFERER'];
  174. else
  175. $sReferrer = BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink($this->_oConfig->CNF['URL_HOME']);
  176. return array('content' => $this->parseHtmlByName('block_item.html', array(
  177. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  178. 'html_id' => $this->_oConfig->getHtmlIds('view', 'main_item'),
  179. 'content' => $sContent,
  180. 'view_image_popup' => $this->_getImagePopup($aParams),
  181. 'js_content' => $this->getJsCode('view', array(
  182. 'sReferrer' => $sReferrer
  183. )) . $this->getJsCode('repost')
  184. )));
  185. }
  186. /**
  187. * Get event's content.
  188. * @param integer $iId - event ID.
  189. * @param string $sMode - 'photo' is only one mode which is available for now.
  190. */
  191. public function getItemBlockContent($iId, $sMode) {
  192. $CNF = $this->_oConfig->CNF;
  193. $sStylePrefix = $this->_oConfig->getPrefix('style');
  194. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  195. if(empty($aEvent))
  196. return '';
  197. $aTmplVars = array(
  198. 'style_prefix' => $sStylePrefix,
  199. 'bx_if:show_image' => array(
  200. 'condition' => false,
  201. 'content' => array()
  202. )
  203. );
  204. switch($sMode) {
  205. case 'photo':
  206. $aTmplVars['bx_if:show_image']['condition'] = true;
  207. $aTmplVars['bx_if:show_image']['content'] = array(
  208. 'style_prefix' => $sStylePrefix,
  209. 'src' => base64_decode(bx_process_input(bx_get('src'))),
  210. );
  211. break;
  212. }
  213. return $this->parseHtmlByName('block_item_content.html', $aTmplVars);
  214. }
  215. public function getItemBlockInfo($iId) {
  216. $CNF = $this->_oConfig->CNF;
  217. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  218. if(empty($aEvent))
  219. return '';
  220. $aResult = $this->getData($aEvent);
  221. if($aResult === false)
  222. return '';
  223. list($sAuthorName, $sAuthorUrl, $sAuthorIcon, $sAuthorUnit) = $this->getModule()->getUserInfo($aResult['owner_id']);
  224. return $this->parseHtmlByName('block_item_info.html', array(
  225. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  226. 'author' => $sAuthorUnit
  227. ));
  228. }
  229. public function getItemBlockComments($iId) {
  230. $CNF = $this->_oConfig->CNF;
  231. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  232. if(empty($aEvent))
  233. return '';
  234. $aResult = $this->getData($aEvent);
  235. if($aResult === false)
  236. return '';
  237. return $this->_getComments($aResult['comments']);
  238. }
  239. public function getUnit(&$aEvent, $aBrowseParams = array())
  240. {
  241. $oModule = $this->getModule();
  242. if(empty($aBrowseParams) || !is_array($aBrowseParams))
  243. $aBrowseParams = $oModule->getParams(BX_TIMELINE_VIEW_SEARCH);
  244. return $this->getPost($aEvent, $aBrowseParams);
  245. }
  246. public function getPost(&$aEvent, $aBrowseParams = array())
  247. {
  248. $oPrivacy = BxDolPrivacy::getObjectInstance($this->_oConfig->getObject('privacy_view'));
  249. if($oPrivacy) {
  250. $oPrivacy->setTableFieldAuthor($this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? 'owner_id' : 'object_id');
  251. if(!$oPrivacy->check($aEvent['id']))
  252. return '';
  253. }
  254. $aResult = $this->getData($aEvent, $aBrowseParams);
  255. if($aResult === false)
  256. return '';
  257. $aEvent['object_owner_id'] = $aResult['owner_id'];
  258. $aEvent['icon'] = !empty($aResult['icon']) ? $aResult['icon'] : '';
  259. $aEvent['sample'] = !empty($aResult['sample']) ? $aResult['sample'] : '_bx_timeline_txt_sample';
  260. $aEvent['sample_action'] = !empty($aResult['sample_action']) ? $aResult['sample_action'] : '_bx_timeline_txt_added_sample';
  261. $aEvent['content'] = $aResult['content'];
  262. $aEvent['views'] = $aResult['views'];
  263. $aEvent['votes'] = $aResult['votes'];
  264. $aEvent['scores'] = $aResult['scores'];
  265. $aEvent['reports'] = $aResult['reports'];
  266. $aEvent['comments'] = $aResult['comments'];
  267. $sType = !empty($aResult['content_type']) ? $aResult['content_type'] : BX_TIMELINE_PARSE_TYPE_DEFAULT;
  268. return $this->_getPost($sType, $aEvent, $aBrowseParams);
  269. }
  270. public function getPosts($aParams)
  271. {
  272. $bViewTimeline = $aParams['view'] == BX_TIMELINE_VIEW_TIMELINE;
  273. $iStart = $aParams['start'];
  274. $iPerPage = $aParams['per_page'];
  275. $aParamsDb = $aParams;
  276. //--- Check for Previous
  277. $iDays = -1;
  278. $bPrevious = false;
  279. if($iStart - 1 >= 0) {
  280. $aParamsDb['start'] -= 1;
  281. $aParamsDb['per_page'] += 1;
  282. $bPrevious = true;
  283. }
  284. //--- Check for Next
  285. $aParamsDb['per_page'] += 1;
  286. $aEvents = $this->_oDb->getEvents($aParamsDb);
  287. //--- Check for Previous
  288. if($bPrevious) {
  289. $aEvent = array_shift($aEvents);
  290. $iDays = (int)$aEvent['days'];
  291. }
  292. //--- Check for Next
  293. $bNext = false;
  294. if(count($aEvents) > $iPerPage) {
  295. $aEvent = array_pop($aEvents);
  296. $bNext = true;
  297. }
  298. $sContent = '';
  299. $sContent .= $this->getSizer($aParams);
  300. $iEvents = count($aEvents);
  301. if($bViewTimeline && $iEvents <= 0)
  302. $sContent .= $this->getDividerToday();
  303. $bFirst = true;
  304. foreach($aEvents as $aEvent) {
  305. $sEvent = $this->getPost($aEvent, $aParams);
  306. $bEvent = !empty($sEvent);
  307. if(!$bEvent)
  308. continue;
  309. if($bViewTimeline && $bFirst) {
  310. $sContent .= $this->getDividerToday($aEvent);
  311. $bFirst = false;
  312. }
  313. $sContent .= $bViewTimeline && $bEvent ? $this->getDivider($iDays, $aEvent) : '';
  314. $sContent .= $sEvent;
  315. }
  316. $sBack = $this->getBack($aParams);
  317. $sLoadMore = $this->getLoadMore($aParams, $bNext, $iEvents > 0);
  318. $sEmpty = $this->getEmpty($iEvents <= 0);
  319. return array($sContent, $sLoadMore, $sBack, $sEmpty);
  320. }
  321. public function getEmpty($bVisible)
  322. {
  323. return $this->parseHtmlByName('empty.html', array(
  324. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  325. 'visible' => $bVisible ? 'block' : 'none',
  326. 'content' => MsgBox(_t('_bx_timeline_txt_msg_no_results'))
  327. ));
  328. }
  329. public function getDivider(&$iDays, &$aEvent)
  330. {
  331. if(!$this->_bShowTimelineDividers || $iDays == $aEvent['days'])
  332. return '';
  333. $iDays = $aEvent['days'];
  334. $iDaysAgo = (int)$aEvent['ago_days'];
  335. if($aEvent['today'] == $aEvent['days'] || (($aEvent['today'] - $aEvent['days']) == 1 && $iDaysAgo == 0))
  336. return '';
  337. return $this->parseHtmlByName('divider.html', array(
  338. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  339. 'type' => 'common',
  340. 'bx_if:show_hidden' => array(
  341. 'condition' => false,
  342. 'content' => array()
  343. ),
  344. 'content' => bx_time_js($aEvent['date'])
  345. ));
  346. }
  347. public function getDividerToday($aEvent = array())
  348. {
  349. if(!$this->_bShowTimelineDividers)
  350. return '';
  351. $bToday = !empty($aEvent) && ($aEvent['today'] == $aEvent['days'] || (($aEvent['today'] - $aEvent['days']) == 1 && (int)$aEvent['ago_days'] == 0));
  352. return $this->parseHtmlByName('divider.html', array(
  353. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  354. 'type' => 'today',
  355. 'bx_if:show_hidden' => array(
  356. 'condition' => !$bToday,
  357. 'content' => array()
  358. ),
  359. 'content' => _t('_bx_timeline_txt_today')
  360. ));
  361. }
  362. public function getSizer($aParams)
  363. {
  364. if($aParams['view'] != BX_TIMELINE_VIEW_OUTLINE)
  365. return '';
  366. return $this->parseHtmlByName('sizer_' . $aParams['view'] . '.html', array(
  367. 'style_prefix' => $this->_oConfig->getPrefix('style')
  368. ));
  369. }
  370. public function getBack($aParams)
  371. {
  372. $iYearSel = (int)$aParams['timeline'];
  373. if($iYearSel == 0)
  374. return '';
  375. $sStylePrefix = $this->_oConfig->getPrefix('style');
  376. $sJsObject = $this->_oConfig->getJsObject('view');
  377. $iYearNow = date('Y', time());
  378. return $this->parseHtmlByName('back.html', array(
  379. 'style_prefix' => $sStylePrefix,
  380. 'content' => $this->parseLink('javascript:void(0)', _t('_bx_timeline_txt_jump_to_recent'), array(
  381. 'title' => _t('_bx_timeline_txt_jump_to_n_year', $iYearNow),
  382. 'onclick' => 'javascript:' . $sJsObject . '.changeTimeline(this, 0)'
  383. ))
  384. ));
  385. }
  386. public function getLoadMore($aParams, $bEnabled, $bVisible = true)
  387. {
  388. $iStart = $aParams['start'];
  389. $iPerPage = $aParams['per_page'];
  390. $iYearSel = (int)$aParams['timeline'];
  391. $iYearMin = $this->_oDb->getMaxDuration($aParams);
  392. $sStylePrefix = $this->_oConfig->getPrefix('style');
  393. $sJsObject = $this->_oConfig->getJsObject('view');
  394. $sYears = '';
  395. if(!empty($iYearMin)) {
  396. $iYearMax = date('Y', time()) - 1;
  397. for($i = $iYearMax; $i >= $iYearMin; $i--)
  398. $sYears .= ($i != $iYearSel ? $this->parseLink('javascript:void(0)', $i, array(
  399. 'title' => _t('_bx_timeline_txt_jump_to_n_year', $i),
  400. 'onclick' => 'javascript:' . $sJsObject . '.changeTimeline(this, ' . $i . ')'
  401. )) : $i) . ', ';
  402. $sYears = substr($sYears, 0, -2);
  403. }
  404. $aTmplVars = array(
  405. 'style_prefix' => $sStylePrefix,
  406. 'visible' => ($aParams['view'] == BX_TIMELINE_VIEW_TIMELINE && $bVisible) || ($aParams['view'] == BX_TIMELINE_VIEW_OUTLINE && $bEnabled && $bVisible) ? 'block' : 'none',
  407. 'bx_if:is_disabled' => array(
  408. 'condition' => !$bEnabled,
  409. 'content' => array()
  410. ),
  411. 'bx_if:show_on_click' => array(
  412. 'condition' => $bEnabled,
  413. 'content' => array(
  414. 'on_click' => 'javascript:' . $sJsObject . '.changePage(this, ' . ($iStart + $iPerPage) . ', ' . $iPerPage . ')'
  415. )
  416. ),
  417. 'bx_if:show_jump_to' => array(
  418. 'condition' => !empty($sYears),
  419. 'content' => array(
  420. 'style_prefix' => $sStylePrefix,
  421. 'years' => $sYears
  422. )
  423. )
  424. );
  425. return $this->parseHtmlByName('load_more.html', $aTmplVars);
  426. }
  427. public function getComments($sSystem, $iId, $bDynamic = false)
  428. {
  429. $oModule = $this->getModule();
  430. $sStylePrefix = $this->_oConfig->getPrefix('style');
  431. $oCmts = $oModule->getCmtsObject($sSystem, $iId);
  432. if($oCmts === false)
  433. return '';
  434. $aComments = $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'dynamic_mode' => $bDynamic));
  435. return $this->parseHtmlByName('comments.html', array(
  436. 'style_prefix' => $sStylePrefix,
  437. 'id' => $iId,
  438. 'content' => $aComments['content']
  439. ));
  440. }
  441. public function getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  442. {
  443. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  444. if(empty($aReposted) || !is_array($aReposted))
  445. return '';
  446. $oModule = $this->getModule();
  447. $bDisabled = $oModule->isAllowedRepost($aReposted) !== true || $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $oModule->getUserId());
  448. if($bDisabled && (int)$aReposted['reposts'] == 0)
  449. return '';
  450. $sStylePrefix = $this->_oConfig->getPrefix('style');
  451. $sStylePrefixRepost = $sStylePrefix . '-repost-';
  452. $bDynamicMode = isset($aParams['dynamic_mode']) && $aParams['dynamic_mode'] === true;
  453. $bShowDoRepostAsButtonSmall = isset($aParams['show_do_repost_as_button_small']) && $aParams['show_do_repost_as_button_small'] == true;
  454. $bShowDoRepostAsButton = !$bShowDoRepostAsButtonSmall && isset($aParams['show_do_repost_as_button']) && $aParams['show_do_repost_as_button'] == true;
  455. $bShowDoRepostImage = isset($aParams['show_do_repost_image']) && $aParams['show_do_repost_image'] == true && !empty($aParams['image_do_repost']);
  456. $bShowDoRepostIcon = isset($aParams['show_do_repost_icon']) && $aParams['show_do_repost_icon'] == true && !empty($aParams['icon_do_repost']);
  457. $bShowDoRepostText = isset($aParams['show_do_repost_text']) && $aParams['show_do_repost_text'] == true && !empty($aParams['text_do_repost']);
  458. $bShowCounter = isset($aParams['show_counter']) && $aParams['show_counter'] === true;
  459. //--- Do repost link ---//
  460. $sClass = $sStylePrefixRepost . 'do-repost';
  461. if($bShowDoRepostAsButton)
  462. $sClass .= ' bx-btn';
  463. else if($bShowDoRepostAsButtonSmall)
  464. $sClass .= ' bx-btn bx-btn-small';
  465. $sOnClick = '';
  466. if(!$bDisabled) {
  467. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  468. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  469. $aRepostedData = $this->_getCommonData($aReposted);
  470. $sOnClick = $this->_getRepostJsClick($iOwnerId, $aRepostedData['content']['type'], $aRepostedData['content']['action'], $aRepostedData['content']['object_id']);
  471. }
  472. else
  473. $sOnClick = $this->_getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  474. }
  475. else
  476. $sClass .= $bShowDoRepostAsButton || $bShowDoRepostAsButtonSmall ? ' bx-btn-disabled' : ' ' . $sStylePrefixRepost . 'disabled';
  477. $aOnClickAttrs = array(
  478. 'title' => _t('_bx_timeline_txt_do_repost')
  479. );
  480. if(!empty($sClass))
  481. $aOnClickAttrs['class'] = $sClass;
  482. if(!empty($sOnClick))
  483. $aOnClickAttrs['onclick'] = $sOnClick;
  484. //--- Do repost label ---//
  485. $sMethodDoRepostLabel = '';
  486. $sTemplateDoRepostLabel = '';
  487. if(!empty($aParams['template_do_repost_label'])) {
  488. $sMethodDoRepostLabel = 'parseHtmlByContent';
  489. $sTemplateDoRepostLabel = $aParams['template_do_repost_label'];
  490. }
  491. else {
  492. $sMethodDoRepostLabel = 'parseHtmlByName';
  493. $sTemplateDoRepostLabel = $aParams['template_do_repost_label_name'];
  494. }
  495. $sDoRepost = $this->$sMethodDoRepostLabel($sTemplateDoRepostLabel, array(
  496. 'bx_if:show_image' => array(
  497. 'condition' => $bShowDoRepostImage,
  498. 'content' => array(
  499. 'src' => $this->getIconUrl($aParams['image_do_repost'])
  500. )
  501. ),
  502. 'bx_if:show_icon' => array(
  503. 'condition' => $bShowDoRepostIcon,
  504. 'content' => array(
  505. 'name' => $aParams['icon_do_repost']
  506. )
  507. ),
  508. 'bx_if:show_text' => array(
  509. 'condition' => $bShowDoRepostText,
  510. 'content' => array(
  511. 'text' => _t($aParams['text_do_repost'])
  512. )
  513. )
  514. ));
  515. return $this->parseHtmlByName('repost_element_block.html', array(
  516. 'style_prefix' => $sStylePrefix,
  517. 'html_id' => $this->_oConfig->getHtmlIds('repost', 'main') . $aReposted['id'],
  518. 'class' => ($bShowDoRepostAsButton ? $sStylePrefixRepost . 'button' : '') . ($bShowDoRepostAsButtonSmall ? $sStylePrefixRepost . 'button-small' : ''),
  519. 'count' => $aReposted['reposts'],
  520. 'do_repost' => $this->parseLink('javascript:void(0)', $sDoRepost, $aOnClickAttrs),
  521. 'bx_if:show_counter' => array(
  522. 'condition' => $bShowCounter,
  523. 'content' => array(
  524. 'style_prefix' => $sStylePrefix,
  525. 'bx_if:show_hidden' => array(
  526. 'condition' => (int)$aReposted['reposts'] == 0,
  527. 'content' => array()
  528. ),
  529. 'counter' => $this->getRepostCounter($aReposted, $aParams)
  530. )
  531. ),
  532. 'script' => $this->getRepostJsScript($bDynamicMode)
  533. ));
  534. }
  535. public function getRepostCounter($aEvent, $aParams = array())
  536. {
  537. $sStylePrefix = $this->_oConfig->getPrefix('style');
  538. $sJsObject = $this->_oConfig->getJsObject('repost');
  539. $bShowDoRepostAsButtonSmall = isset($aParams['show_do_repost_as_button_small']) && $aParams['show_do_repost_as_button_small'] == true;
  540. $bShowDoRepostAsButton = !$bShowDoRepostAsButtonSmall && isset($aParams['show_do_repost_as_button']) && $aParams['show_do_repost_as_button'] == true;
  541. $sClass = $sStylePrefix . '-repost-counter';
  542. if($bShowDoRepostAsButtonSmall)
  543. $sClass .= ' bx-btn-small-height';
  544. if($bShowDoRepostAsButton)
  545. $sClass .= ' bx-btn-height';
  546. return $this->parseLink('javascript:void(0)', !empty($aEvent['reposts']) && (int)$aEvent['reposts'] > 0 ? $aEvent['reposts'] : '', array(
  547. 'id' => $this->_oConfig->getHtmlIds('repost', 'counter') . $aEvent['id'],
  548. 'class' => $sClass,
  549. 'title' => _t('_bx_timeline_txt_reposted_by'),
  550. 'onclick' => 'javascript:' . $sJsObject . '.toggleByPopup(this, ' . $aEvent['id'] . ')'
  551. ));
  552. }
  553. public function getRepostedBy($iId)
  554. {
  555. $aTmplUsers = array();
  556. $oModule = $this->getModule();
  557. $sStylePrefix = $this->_oConfig->getPrefix('style');
  558. $aUserIds = $this->_oDb->getRepostedBy($iId);
  559. foreach($aUserIds as $iUserId) {
  560. list($sUserName, $sUserUrl, $sUserIcon, $sUserUnit) = $oModule->getUserInfo($iUserId);
  561. $aTmplUsers[] = array(
  562. 'style_prefix' => $sStylePrefix,
  563. 'user_unit' => $sUserUnit
  564. );
  565. }
  566. if(empty($aTmplUsers))
  567. $aTmplUsers = MsgBox(_t('_Empty'));
  568. return $this->parseHtmlByName('repost_by_list.html', array(
  569. 'style_prefix' => $sStylePrefix,
  570. 'bx_repeat:list' => $aTmplUsers
  571. ));
  572. }
  573. public function getRepostJsScript($bDynamicMode = false)
  574. {
  575. $sCode = $this->getJsCode('repost', array(), array('mask' => '{object} = new {class}({params});', 'wrap' => false));
  576. if($bDynamicMode) {
  577. $sJsObject = $this->_oConfig->getJsObject('repost');
  578. $sCode = "var " . $sJsObject . " = null;
  579. $.getScript('" . bx_js_string($this->getJsUrl('main.js'), BX_ESCAPE_STR_APOS) . "', function(data, textStatus, jqxhr) {
  580. $.getScript('" . bx_js_string($this->getJsUrl('repost.js'), BX_ESCAPE_STR_APOS) . "', function(data, textStatus, jqxhr) {
  581. bx_get_style('" . bx_js_string($this->getCssUrl('repost.css'), BX_ESCAPE_STR_APOS) . "');
  582. " . $sCode . "
  583. });
  584. }); ";
  585. }
  586. else {
  587. $sCode = "var " . $sCode;
  588. $this->addCss(array('repost.css'));
  589. $this->addJs(array('main.js', 'repost.js'));
  590. }
  591. return $this->_wrapInTagJsCode($sCode);
  592. }
  593. public function getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  594. {
  595. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  596. if(empty($aReposted) || !is_array($aReposted))
  597. return '';
  598. $sResult = '';
  599. $sCommonPrefix = $this->_oConfig->getPrefix('common_post');
  600. if(str_replace($sCommonPrefix, '', $sType) == BX_TIMELINE_PARSE_TYPE_REPOST) {
  601. $aRepostedData = $this->_getCommonData($aReposted);
  602. $sResult = $this->_getRepostJsClick($iOwnerId, $aRepostedData['content']['type'], $aRepostedData['content']['action'], $aRepostedData['content']['object_id']);
  603. }
  604. else
  605. $sResult = $this->_getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  606. return $sResult;
  607. }
  608. public function getAttachLinkForm()
  609. {
  610. $sStylePrefix = $this->_oConfig->getPrefix('style');
  611. $sJsObject = $this->_oConfig->getJsObject('post');
  612. $aForm = $this->getModule()->getFormAttachLink();
  613. return $this->parseHtmlByName('attach_link_form.html', array(
  614. 'style_prefix' => $sStylePrefix,
  615. 'js_object' => $sJsObject,
  616. 'form_id' => $aForm['form_id'],
  617. 'form' => $aForm['form'],
  618. ));
  619. }
  620. public function getAttachLinkField($iUserId)
  621. {
  622. $sStylePrefix = $this->_oConfig->getPrefix('style');
  623. $aLinks = $this->_oDb->getUnusedLinks($iUserId);
  624. $sLinks = '';
  625. foreach($aLinks as $aLink)
  626. $sLinks .= $this->getAttachLinkItem($iUserId, $aLink);
  627. return $this->parseHtmlByName('attach_link_form_field.html', array(
  628. 'html_id' => $this->_oConfig->getHtmlIds('post', 'attach_link_form_field'),
  629. 'style_prefix' => $sStylePrefix,
  630. 'links' => $sLinks
  631. ));
  632. }
  633. public function getAttachLinkItem($iUserId, $mixedLink)
  634. {
  635. $aLink = is_array($mixedLink) ? $mixedLink : $this->_oDb->getUnusedLinks($iUserId, (int)$mixedLink);
  636. if(empty($aLink) || !is_array($aLink))
  637. return '';
  638. $sStylePrefix = $this->_oConfig->getPrefix('style');
  639. $sJsObject = $this->_oConfig->getJsObject('post');
  640. $sLinkIdPrefix = $this->_oConfig->getHtmlIds('post', 'attach_link_item');
  641. $bTmplVarsEmbed = false;
  642. $aTmplVarsEmbed = array();
  643. $oEmbed = BxDolEmbed::getObjectInstance();
  644. if($oEmbed) {
  645. $bTmplVarsEmbed = true;
  646. $aTmplVarsEmbed = array(
  647. 'style_prefix' => $sStylePrefix,
  648. 'embed' => $oEmbed->getLinkHTML($aLink['url'], $aLink['title'], 300),
  649. );
  650. }
  651. else {
  652. $aLinkAttrs = array(
  653. 'title' => bx_html_attribute($aLink['title'])
  654. );
  655. if(!$this->_oConfig->isEqualUrls(BX_DOL_URL_ROOT, $aLink['url'])) {
  656. $aLinkAttrs['target'] = '_blank';
  657. if($this->_oDb->getParam('sys_add_nofollow') == 'on')
  658. $aLinkAttrs['rel'] = 'nofollow';
  659. }
  660. $sThumbnail = "";
  661. if((int)$aLink['media_id'] != 0)
  662. $sThumbnail = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_preview'))->getFileUrl($aLink['media_id']);
  663. $aTmplVarsEmbed = array(
  664. 'style_prefix' => $sStylePrefix,
  665. 'bx_if:show_thumbnail' => array(
  666. 'condition' => !empty($sThumbnail),
  667. 'content' => array(
  668. 'style_prefix' => $sStylePrefix,
  669. 'thumbnail' => $sThumbnail
  670. )
  671. ),
  672. 'url' => $aLink['url'],
  673. 'link' => $this->parseLink($aLink['url'], $aLink['title'], $aLinkAttrs)
  674. );
  675. }
  676. return $this->parseHtmlByName('attach_link_item.html', array(
  677. 'html_id' => $sLinkIdPrefix . $aLink['id'],
  678. 'style_prefix' => $sStylePrefix,
  679. 'js_object' => $sJsObject,
  680. 'id' => $aLink['id'],
  681. 'bx_if:show_embed_outer' => array(
  682. 'condition' => $bTmplVarsEmbed,
  683. 'content' => $aTmplVarsEmbed
  684. ),
  685. 'bx_if:show_embed_inner' => array(
  686. 'condition' => !$bTmplVarsEmbed,
  687. 'content' => $aTmplVarsEmbed
  688. ),
  689. ));
  690. }
  691. public function getData(&$aEvent, $aBrowseParams = array())
  692. {
  693. $aResult = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $this->_getSystemData($aEvent, $aBrowseParams) : $this->_getCommonData($aEvent, $aBrowseParams);
  694. if(empty($aResult) || empty($aResult['owner_id']) || empty($aResult['content']))
  695. return false;
  696. list($sUserName) = $this->getModule()->getUserInfo($aResult['owner_id']);
  697. $sSample = !empty($aResult['sample']) ? $aResult['sample'] : '_bx_timeline_txt_sample';
  698. if(empty($aEvent['title']) || empty($aEvent['description'])) {
  699. $sTitle = !empty($aResult['title']) ? $this->_oConfig->getTitle($aResult['title']) : _t($sSample);
  700. $sDescription = !empty($aResult['description']) ? $aResult['description'] : _t('_bx_timeline_txt_user_added_sample', $sUserName, _t($sSample));
  701. if($sDescription == '' && !empty($aResult['content']['text']))
  702. $sDescription = $aResult['content']['text'];
  703. $this->_oDb->updateEvent(array(
  704. 'title' => bx_process_input(strip_tags($sTitle)),
  705. 'description' => bx_process_input(strip_tags($sDescription))
  706. ), array('id' => $aEvent['id']));
  707. }
  708. return $aResult;
  709. }
  710. public function getVideo(&$aEvent, &$aVideo)
  711. {
  712. $sVideoId = $this->_oConfig->getHtmlIds('view', 'video') . $aEvent['id'] . '-' . $aVideo['id'];
  713. return $this->parseHtmlByName('video_player.html', array(
  714. 'player' => BxTemplFunctions::getInstance()->videoPlayer($aVideo['src_poster'], $aVideo['src_mp4'], $aVideo['src_webm'], array('id' => $sVideoId)),
  715. 'html_id' => $sVideoId
  716. ));
  717. }
  718. public function getItemIcon($bT, $bL, $bP, $bV)
  719. {
  720. $sResult = '';
  721. if($bT && !$bL && !$bP && !$bV)
  722. $sResult = 'far file-alt';
  723. else if(!$bT && $bL && !$bP && !$bV)
  724. $sResult = 'link';
  725. else if(!$bT && !$bL && $bP && !$bV)
  726. $sResult = 'far image';
  727. else if(!$bT && !$bL && !$bP && $bV)
  728. $sResult = 'film';
  729. else
  730. $sResult = 'far file';
  731. return '<i class="sys-icon ' . $sResult . '"></i>';
  732. }
  733. function getLiveUpdateNotification($sType, $iOwnerId, $iProfileId, $iCountOld = 0, $iCountNew = 0)
  734. {
  735. $oModule = $this->getModule();
  736. $iCount = (int)$iCountNew - (int)$iCountOld;
  737. if($iCount < 0)
  738. return '';
  739. $iCountMax = $this->_oConfig->getLiveUpdateLength();
  740. if($iCount > $iCountMax)
  741. $iCount = $iCountMax;
  742. $aParams = $oModule->getParams(BX_TIMELINE_VIEW_DEFAULT, $sType, $iOwnerId, 0, $iCount, BX_TIMELINE_FILTER_OTHER_VIEWER);
  743. $aEvents = $this->_oDb->getEvents($aParams);
  744. if(empty($aEvents) || !is_array($aEvents))
  745. return '';
  746. $sJsObject = $this->_oConfig->getJsObject('view');
  747. $sStylePrefix = $this->_oConfig->getPrefix('style');
  748. $aEvents = array_reverse($aEvents);
  749. $iEvents = count($aEvents);
  750. $aTmplVarsItems = array();
  751. foreach($aEvents as $iIndex => $aEvent) {
  752. $aData = $this->getData($aEvent);
  753. if($aData === false)
  754. continue;
  755. $iEventId = $aEvent['id'];
  756. $iEventAuthorId = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $aEvent['owner_id'] : $aEvent['object_id'];
  757. list($sAuthorName, $sAuthorLink, $sAuthorIcon, $sAuthorUnit) = $oModule->getUserInfo($iEventAuthorId);
  758. $bAuthorIcon = !empty($sAuthorIcon);
  759. $sShowOnClick = "javascript:" . $sJsObject . ".goTo(this, 'timeline-event-" . $iEventId . "', '" . $iEventId . "');";
  760. $aTmplVarsItems[] = array(
  761. 'bx_if:show_as_hidden' => array(
  762. 'condition' => $iIndex < ($iEvents - 1),
  763. 'content' => array(),
  764. ),
  765. 'item' => $this->parseHtmlByName('live_update_notification.html', array(
  766. 'style_prefix' => $sStylePrefix,
  767. 'onclick_show' => $sShowOnClick,
  768. 'author_link' => $sAuthorLink,
  769. 'author_title' => bx_html_attribute($sAuthorName),
  770. 'author_name' => $sAuthorName,
  771. 'bx_if:show_icon' => array(
  772. 'condition' => $bAuthorIcon,
  773. 'content' => array(
  774. 'author_icon' => $sAuthorIcon
  775. )
  776. ),
  777. 'bx_if:show_icon_empty' => array(
  778. 'condition' => !$bAuthorIcon,
  779. 'content' => array()
  780. ),
  781. 'text' => _t($aData['sample_action'], _t($aData['sample'])),
  782. )),
  783. 'bx_if:show_previous' => array(
  784. 'condition' => $iIndex > 0,
  785. 'content' => array(
  786. 'onclick_previous' => $sJsObject . '.previousLiveUpdate(this)'
  787. )
  788. ),
  789. 'onclick_close' => $sJsObject . '.hideLiveUpdate(this)'
  790. );
  791. }
  792. return $this->parseHtmlByName('popup_chain.html', array(
  793. 'html_id' => $this->_oConfig->getHtmlIds('view', 'live_update_popup') . $sType,
  794. 'bx_repeat:items' => $aTmplVarsItems
  795. ));
  796. }
  797. protected function _getPost($sType, $aEvent, $aBrowseParams = array())
  798. {
  799. $CNF = &$this->_oConfig->CNF;
  800. $oModule = $this->getModule();
  801. $sStylePrefix = $this->_oConfig->getPrefix('style');
  802. $sJsObject = $this->_oConfig->getJsObject('view');
  803. list($sAuthorName, $sAuthorUrl, $sAuthorIcon, $sAuthorUnit, $sAuthorUnitShort) = $oModule->getUserInfo($aEvent['object_owner_id']);
  804. $bAuthorIcon = !empty($sAuthorIcon);
  805. $aTmplVarsNote = $this->_getTmplVarsNote($aEvent);
  806. $aTmplVarsMenuItemActions = $this->_getTmplVarsMenuItemActions($aEvent, $aBrowseParams);
  807. $aTmplVarsOwnerActions = $this->_getTmplVarsOwnerActions($aEvent);
  808. $bTmplVarsOwnerActions = !empty($aTmplVarsOwnerActions);
  809. $aTmplVarsTimelineOwner = $this->_getTmplVarsTimelineOwner($aEvent);
  810. $bViewItem = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_ITEM;
  811. $bViewOutline = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_OUTLINE;
  812. $bPinned = (int)$aEvent['pinned'] > 0;
  813. $bPromoted = (int)$aEvent['promoted'] > 0;
  814. $sClass = $sStylePrefix . '-view-sizer';
  815. if($bViewOutline) {
  816. $sClass = $sStylePrefix . '-grid-item-sizer';
  817. if($bPinned || $bPromoted) {
  818. $sClass .= ' ' . $sStylePrefix . '-gis';
  819. if($bPinned)
  820. $sClass .= '-pnd';
  821. if($bPromoted)
  822. $sClass .= '-pmd';
  823. }
  824. }
  825. if(!empty($aBrowseParams['blink']) && in_array($aEvent['id'], $aBrowseParams['blink']))
  826. $sClass .= ' ' . $sStylePrefix . '-blink';
  827. if($bPinned)
  828. $sClass .= ' ' . $sStylePrefix . '-pinned';
  829. if($bPromoted)
  830. $sClass .= ' ' . $sStylePrefix . '-promoted';
  831. $sClassOwner = $bTmplVarsOwnerActions ? $sStylePrefix . '-io-with-actions' : '';
  832. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  833. $sLocation = $oMetatags->locationsString($aEvent['id']);
  834. $aTmplVars = array (
  835. 'style_prefix' => $sStylePrefix,
  836. 'js_object' => $sJsObject,
  837. 'html_id' => $this->_oConfig->getHtmlIds('view', 'item_' . $aBrowseParams['view']) . $aEvent['id'],
  838. 'class' => $sClass,
  839. 'class_owner' => $sClassOwner,
  840. 'class_content' => $bViewItem ? 'bx-def-color-bg-block' : 'bx-def-color-bg-box',
  841. 'id' => $aEvent['id'],
  842. 'bx_if:show_note' => array(
  843. 'condition' => !empty($aTmplVarsNote),
  844. 'content' => $aTmplVarsNote
  845. ),
  846. 'bx_if:show_owner_icon' => array(
  847. 'condition' => $bAuthorIcon,
  848. 'content' => array(
  849. 'owner_icon' => $sAuthorIcon
  850. )
  851. ),
  852. 'bx_if:show_owner_icon_empty' => array(
  853. 'condition' => !$bAuthorIcon,
  854. 'content' => array()
  855. ),
  856. 'bx_if:show_owner_actions' => array(
  857. 'condition' => $bTmplVarsOwnerActions,
  858. 'content' => $aTmplVarsOwnerActions
  859. ),
  860. 'item_icon' => !empty($aEvent['icon']) ? $aEvent['icon'] : $CNF['ICON'],
  861. 'item_owner_url' => $sAuthorUrl,
  862. 'item_owner_title' => bx_html_attribute($sAuthorName),
  863. 'item_owner_name' => $sAuthorName,
  864. 'item_owner_unit' => $sAuthorUnitShort,
  865. 'item_owner_action' => _t($aEvent['sample_action'], _t($aEvent['sample'])),
  866. 'bx_if:show_timeline_owner' => array(
  867. 'condition' => !empty($aTmplVarsTimelineOwner),
  868. 'content' => $aTmplVarsTimelineOwner
  869. ),
  870. 'item_view_url' => $this->_oConfig->getItemViewUrl($aEvent),
  871. 'item_date' => bx_time_js($aEvent['date']),
  872. 'bx_if:show_pinned' => array(
  873. 'condition' => $bPinned,
  874. 'content' => array(
  875. 'style_prefix' => $sStylePrefix,
  876. )
  877. ),
  878. 'bx_if:show_hot' => array(
  879. 'condition' => isset($aBrowseParams['hot']) && is_array($aBrowseParams['hot']) && in_array($aEvent['id'], $aBrowseParams['hot']),
  880. 'content' => array(
  881. 'style_prefix' => $sStylePrefix,
  882. )
  883. ),
  884. 'content' => is_string($aEvent['content']) ? $aEvent['content'] : $this->_getContent($sType, $aEvent, $aBrowseParams),
  885. 'bx_if:show_location' => array(
  886. 'condition' => !empty($sLocation),
  887. 'content' => array(
  888. 'style_prefix' => $sStylePrefix,
  889. 'location' => $sLocation
  890. )
  891. ),
  892. 'bx_if:show_menu_item_actions' => array(
  893. 'condition' => !empty($aTmplVarsMenuItemActions),
  894. 'content' => $aTmplVarsMenuItemActions
  895. ),
  896. 'comments' => '',
  897. );
  898. $sVariable = '_sTmplContentItem' . bx_gen_method_name($aBrowseParams['view']);
  899. if(empty(self::$$sVariable))
  900. self::$$sVariable = $this->getHtml('item_' . $aBrowseParams['view'] . '.html');
  901. return $this->parseHtmlByContent(self::$$sVariable, $aTmplVars);
  902. }
  903. protected function _getContent($sType, $aEvent, $aBrowseParams = array())
  904. {
  905. $sMethod = '_getTmplVarsContent' . ucfirst($sType);
  906. if(!method_exists($this, $sMethod))
  907. return '';
  908. $sVariable = '_sTmplContentType' . bx_gen_method_name($sType);
  909. if(empty(self::$$sVariable))
  910. self::$$sVariable = $this->getHtml('type_' . $sType . '.html');
  911. return $this->parseHtmlByContent(self::$$sVariable, $this->$sMethod($aEvent, $aBrowseParams));
  912. }
  913. protected function _getComments($aComments)
  914. {
  915. $mixedComments = $this->getModule()->getCommentsData($aComments);
  916. if($mixedComments === false)
  917. return '';
  918. list($sSystem, $iObjectId, $iCount) = $mixedComments;
  919. return $this->getComments($sSystem, $iObjectId);
  920. }
  921. protected function _getShowMore($aParams)
  922. {
  923. return $this->parseHtmlByName('show_more.html', array(
  924. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  925. 'js_object' => $this->_oConfig->getJsObject('view'),
  926. ));
  927. }
  928. protected function _getImagePopup($aParams)
  929. {
  930. $sViewImagePopupId = $this->_oConfig->getHtmlIds('view', 'photo_popup_' . $aParams['view']);
  931. $sViewImagePopupContent = $this->parseHtmlByName('popup_image.html', array(
  932. 'image_url' => ''
  933. ));
  934. return BxTemplFunctions::getInstance()->transBox($sViewImagePopupId, $sViewImagePopupContent, true);
  935. }
  936. protected function _getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  937. {
  938. $sJsObject = $this->_oConfig->getJsObject('repost');
  939. $sFormat = "%s.repostItem(this, %d, '%s', '%s', %d);";
  940. $iOwnerId = !empty($iOwnerId) ? (int)$iOwnerId : $this->getModule()->getUserId(); //--- in whose timeline the content will be reposted
  941. return sprintf($sFormat, $sJsObject, $iOwnerId, $sType, $sAction, (int)$iObjectId);
  942. }
  943. protected function _getTmplVarsMenuItemActions(&$aEvent, $aBrowseParams = array())
  944. {
  945. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_actions'));
  946. $oMenu->setEvent($aEvent);
  947. $oMenu->setView($aBrowseParams['view']);
  948. $oMenu->setDynamicMode(isset($aBrowseParams['dynamic_mode']) && $aBrowseParams['dynamic_mode'] === true);
  949. $sMenu = $oMenu->getCode();
  950. if(empty($sMenu))
  951. return array();
  952. return array(
  953. 'style_prefix' => $this->_oConfig->getPrefix('style'),
  954. 'js_object' => $this->_oConfig->getJsObject('view'),
  955. 'menu_item_actions' => $sMenu
  956. );
  957. }
  958. protected function _getTmplVarsTimelineOwner(&$aEvent)
  959. {
  960. $iOwnerId = (int)$aEvent['owner_id'];
  961. if($iOwnerId == 0 || $iOwnerId == (int)$aEvent['object_owner_id'])
  962. return array();
  963. $sStylePrefix = $this->_oConfig->getPrefix('style');
  964. $iUser = bx_get_logged_profile_id();
  965. $oModule = $this->getModule();
  966. list($sTaName, $sTaUrl, $sTaThumb, $sTaUnit, $sTaUnitWoInfo) = $oModule->getUserInfo($aEvent['owner_id']);
  967. $sTaType = $oModule->getObjectUser($aEvent['owner_id'])->getModule();
  968. $aTmplVarsActions = array();
  969. if(!empty($iUser) && !empty($aEvent['owner_id']) && $iUser != $aEvent['owner_id']) {
  970. $sConnection = $this->_oConfig->getObject('conn_subscriptions');
  971. if(BxDolConnection::getObjectInstance($sConnection)->checkAllowedConnect($iUser, $aEvent['owner_id']) === CHECK_ACTION_RESULT_ALLOWED) {
  972. $sContent = _t('_sys_menu_item_title_sm_subscribe');
  973. $aTmplVarsActions[] = array(
  974. 'href' => "javascript:void(0)",
  975. 'onclick' => "bx_conn_action(this, '" . $sConnection . "', 'add', '" . $aEvent['owner_id'] . "')",
  976. 'title' => bx_html_attribute($sContent),
  977. 'content' => $sContent,
  978. 'icon' => 'check'
  979. );
  980. }
  981. }
  982. return array(
  983. 'style_prefix' => $sStylePrefix,
  984. 'owner_type' => _t('_' . $sTaType),
  985. 'owner_url' => $sTaUrl,
  986. 'owner_username' => $sTaName,
  987. 'owner_thumb' => $sTaThumb,
  988. 'owner_unit' => $sTaUnit,
  989. 'owner_unit_wo_info' => $sTaUnitWoInfo,
  990. 'bx_if:show_timeline_owner_actions' => array(
  991. 'condition' => !empty($aTmplVarsActions),
  992. 'content' => array(
  993. 'style_prefix' => $sStylePrefix,
  994. 'bx_repeat:timeline_owner_actions' => $aTmplVarsActions
  995. )
  996. )
  997. );
  998. }
  999. protected function _getTmplVarsContentPost(&$aEvent, $aBrowseParams = array())
  1000. {
  1001. $aContent = &$aEvent['content'];
  1002. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1003. $sJsObject = $this->_oConfig->getJsObject('view');
  1004. $bViewItem = isset($aBrowseParams['view']) && $aBrowseParams['view'] == BX_TIMELINE_VIEW_ITEM;
  1005. //--- Process Raw ---//
  1006. $sRaw = isset($aContent['raw']) ? $aContent['raw'] : '';
  1007. //--- Process Text ---//
  1008. $sUrl = isset($aContent['url']) ? bx_html_attribute($aContent['url']) : '';
  1009. $sTitle = '';
  1010. if(isset($aContent['title']))
  1011. $sTitle = bx_process_output($aContent['title']);
  1012. if(!empty($sUrl) && !empty($sTitle))
  1013. $sTitle = $this->parseLink($sUrl, $sTitle, array(
  1014. 'class' => $sStylePrefix . '-title',
  1015. 'title' => $sTitle
  1016. ));
  1017. $sText = isset($aContent['text']) ? $aContent['text'] : '';
  1018. $sText = $this->_prepareTextForOutput($sText, $aEvent['id']);
  1019. //--- Process Links ---//
  1020. $bAddNofollow = $this->_oDb->getParam('sys_add_nofollow') == 'on';
  1021. $aTmplVarsLinks = array();
  1022. if(!empty($aContent['links']))
  1023. foreach($aContent['links'] as $aLink) {
  1024. $bTmplVarsEmbed = false;
  1025. $aTmplVarsEmbed = array();
  1026. $oEmbed = BxDolEmbed::getObjectInstance();
  1027. if ($oEmbed) {
  1028. $bTmplVarsEmbed = true;
  1029. $aTmplVarsEmbed = array(
  1030. 'style_prefix' => $sStylePrefix,
  1031. 'embed' => $oEmbed->getLinkHTML($aLink['url'], $aLink['title']),
  1032. );
  1033. }
  1034. else {
  1035. $aLinkAttrs = array(
  1036. 'title' => $aLink['title']
  1037. );
  1038. if(!$this->_oConfig->isEqualUrls(BX_DOL_URL_ROOT, $aLink['url'])) {
  1039. $aLinkAttrs['target'] = '_blank';
  1040. if($bAddNofollow)
  1041. $aLinkAttrs['rel'] = 'nofollow';
  1042. }
  1043. $sLinkAttrs = '';
  1044. foreach($aLinkAttrs as $sKey => $sValue)
  1045. $sLinkAttrs .= ' ' . $sKey . '="' . bx_html_attribute($sValue) . '"';
  1046. $aTmplVarsEmbed = array(
  1047. 'bx_if:show_thumbnail' => array(
  1048. 'condition' => !empty($aLink['thumbnail']),
  1049. 'content' => array(
  1050. 'style_prefix' => $sStylePrefix,
  1051. 'thumbnail' => $aLink['thumbnail'],
  1052. 'link' => !empty($aLink['url']) ? $aLink['url'] : 'javascript:void(0)',
  1053. 'attrs' => $sLinkAttrs
  1054. )
  1055. ),
  1056. 'link' => !empty($aLink['url']) ? $aLink['url'] : 'javascript:void(0)',
  1057. 'attrs' => $sLinkAttrs,
  1058. 'content' => $aLink['title'],
  1059. 'bx_if:show_text' => array(
  1060. 'condition' => !empty($aLink['text']),
  1061. 'content' => array(
  1062. 'style_prefix' => $sStylePrefix,
  1063. 'text' => $aLink['text']
  1064. )
  1065. )
  1066. );
  1067. }
  1068. $aTmplVarsLinks[] = array(
  1069. 'style_prefix' => $sStylePrefix,
  1070. 'bx_if:show_embed_outer' => array(
  1071. 'condition' => $bTmplVarsEmbed,
  1072. 'content' => $aTmplVarsEmbed
  1073. ),
  1074. 'bx_if:show_embed_inner' => array(
  1075. 'condition' => !$bTmplVarsEmbed,
  1076. 'content' => $aTmplVarsEmbed
  1077. )
  1078. );
  1079. }
  1080. //--- Process Photos ---//
  1081. $sImagesDisplay = '';
  1082. $aTmplVarsImages = array();
  1083. if(!empty($aContent['images'])) {
  1084. $sImageSrcKey = '';
  1085. $sImageSrcKeyDefault = 'src';
  1086. if(count($aContent['images']) == 1) {
  1087. $sImagesDisplay = 'single';
  1088. $sImageSrcKey = $bViewItem ? 'src_orig' : 'src_medium';
  1089. }
  1090. else {
  1091. $sImagesDisplay = 'gallery';
  1092. $sImageSrcKey = 'src';
  1093. }
  1094. foreach($aContent['images'] as $aImage) {
  1095. $sImageSrc = !empty($aImage[$sImageSrcKey]) ? $aImage[$sImageSrcKey] : $aImage[$sImageSrcKeyDefault];
  1096. if(empty($sImageSrc))
  1097. continue;
  1098. $sImage = $this->parseImage($sImageSrc, array(
  1099. 'class' => $sStylePrefix . '-item-image'
  1100. ));
  1101. $aAttrs = array();
  1102. if(isset($aImage['onclick']))
  1103. $aAttrs['onclick'] = $aImage['onclick'];
  1104. else if(!$bViewItem && !empty($aImage['src_orig']))
  1105. $aAttrs['onclick'] = 'return ' . $sJsObject . '.showItem(this, \'' . $aEvent['id'] . '\', \'photo\', ' . json_encode(array('src' => base64_encode($aImage['src_orig']))) . ')';
  1106. $sImage = $this->parseLink(isset($aImage['url']) ? $aImage['url'] : 'javascript:void(0)', $sImage, $aAttrs);
  1107. $aTmplVarsImages[] = array(
  1108. 'style_prefix' => $sStylePrefix,
  1109. 'image' => $sImage
  1110. );
  1111. }
  1112. //--- Add Meta Image when Item is viewed on a separate page ---//
  1113. if($bViewItem && !empty($aContent['images'][0]['src']))
  1114. BxDolTemplate::getInstance()->addPageMetaImage($aContent['images'][0]['src']);
  1115. }
  1116. //--- Process Videos ---//
  1117. $sVap = $this->_oConfig->getVideosAutoplay();
  1118. $sVapId = $this->_oConfig->getHtmlIds('view', 'video_iframe') . $aEvent['id'] . '-';
  1119. $sVapSrc = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'video/' . $aEvent['id'] . '/';
  1120. $aTmplVarsVideos = array();
  1121. if(!empty($aContent['videos']))
  1122. foreach($aContent['videos'] as $iVideo => $aVideo)
  1123. if($sVap == BX_TIMELINE_VAP_OFF)
  1124. $aTmplVarsVideos[] = array(
  1125. 'style_prefix' => $sStylePrefix,
  1126. 'video' => BxTemplFunctions::getInstance()->videoPlayer($aVideo['src_poster'], $aVideo['src_mp4'], $aVideo['src_webm'])
  1127. );
  1128. else
  1129. $aTmplVarsVideos[] = array(
  1130. 'style_prefix' => $sStylePrefix,
  1131. 'video' => $this->parseHtmlByName('video_iframe.html', array(
  1132. 'style_prefix' => $sStylePrefix,
  1133. 'html_id' => $sVapId . $iVideo,
  1134. 'src' => $sVapSrc . $iVideo . '/'
  1135. ))
  1136. );
  1137. return array(
  1138. 'style_prefix' => $sStylePrefix,
  1139. 'bx_if:show_title' => array(
  1140. 'condition' => !empty($sTitle),
  1141. 'content' => array(
  1142. 'style_prefix' => $sStylePrefix,
  1143. 'title' => $sTitle,
  1144. )
  1145. ),
  1146. 'bx_if:show_content' => array(
  1147. 'condition' => !empty($sText),
  1148. 'content' => array(
  1149. 'style_prefix' => $sStylePrefix,
  1150. 'item_content' => $sText
  1151. )
  1152. ),
  1153. 'bx_if:show_content_raw' => array(
  1154. 'condition' => !empty($sRaw),
  1155. 'content' => array(
  1156. 'item_content_raw' => $sRaw
  1157. )
  1158. ),
  1159. 'bx_if:show_links' => array(
  1160. 'condition' => !empty($aTmplVarsLinks),
  1161. 'content' => array(
  1162. 'style_prefix' => $sStylePrefix,
  1163. 'bx_repeat:links' => $aTmplVarsLinks
  1164. )
  1165. ),
  1166. 'bx_if:show_images' => array(
  1167. 'condition' => !empty($aTmplVarsImages),
  1168. 'content' => array(
  1169. 'style_prefix' => $sStylePrefix,
  1170. 'images_display' => $sImagesDisplay,
  1171. 'bx_repeat:images' => $aTmplVarsImages
  1172. )
  1173. ),
  1174. 'bx_if:show_videos' => array(
  1175. 'condition' => !empty($aTmplVarsVideos),
  1176. 'content' => array(
  1177. 'style_prefix' => $sStylePrefix,
  1178. 'bx_repeat:videos' => $aTmplVarsVideos
  1179. )
  1180. )
  1181. );
  1182. }
  1183. protected function _getTmplVarsContentRepost(&$aEvent, $aBrowseParams = array())
  1184. {
  1185. $aContent = &$aEvent['content'];
  1186. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1187. $sOwnerLink = $this->parseLink($aContent['owner_url'], $aContent['owner_name']);
  1188. $sSample = _t($aContent['sample']);
  1189. $sSampleLink = empty($aContent['url']) ? $sSample : $this->parseLink($aContent['url'], $sSample);
  1190. $sTitle = _t('_bx_timeline_txt_reposted', $sOwnerLink, $sSampleLink);
  1191. $sText = $this->_getContent($aContent['parse_type'], $aEvent);
  1192. return array(
  1193. 'bx_if:show_title' => array(
  1194. 'condition' => !empty($sTitle),
  1195. 'content' => array(
  1196. 'style_prefix' => $sStylePrefix,
  1197. 'title' => $sTitle,
  1198. )
  1199. ),
  1200. 'bx_if:show_content' => array(
  1201. 'condition' => !empty($sText),
  1202. 'content' => array(
  1203. 'style_prefix' => $sStylePrefix,
  1204. 'content' => $sText,
  1205. )
  1206. )
  1207. );
  1208. }
  1209. protected function _getTmplVarsNote(&$aEvent)
  1210. {
  1211. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1212. $iUser = bx_get_logged_profile_id();
  1213. $iOwner = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $aEvent['owner_id'] : $aEvent['object_id'];
  1214. $aTmplVars = array();
  1215. if(!empty($aEvent['promoted']) && $iUser != $iOwner) {
  1216. $sConnection = $this->_oConfig->getObject('conn_subscriptions');
  1217. $oConnection = BxDolConnection::getObjectInstance($sConnection);
  1218. if(!$oConnection->isConnected($iUser, $iOwner))
  1219. $aTmplVars = array(
  1220. 'style_prefix' => $sStylePrefix,
  1221. 'bx_if:show_note_color' => array(
  1222. 'condition' => false,
  1223. 'content' => array(
  1224. 'item_note_color' => 'red1',
  1225. )
  1226. ),
  1227. 'item_note' => _t('_bx_timeline_txt_promoted')
  1228. );
  1229. }
  1230. return $aTmplVars;
  1231. }
  1232. protected function _getTmplVarsOwnerActions(&$aEvent)
  1233. {
  1234. $sStylePrefix = $this->_oConfig->getPrefix('style');
  1235. $iUser = bx_get_logged_profile_id();
  1236. $iOwner = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? $aEvent['object_owner_id'] : $aEvent['object_id'];
  1237. $aTmplVarsActions = array();
  1238. if(!empty($iUser) && !empty($iOwner) && $iUser != $iOwner) {
  1239. $sConnection = $this->_oConfig->getObject('conn_subscriptions');
  1240. if(BxDolConnection::getObjectInstance($sConnection)->checkAllowedConnect($iUser, $iOwner) === CHECK_ACTION_RESULT_ALLOWED) {
  1241. $sContent = _t('_sys_menu_item_title_sm_subscribe');
  1242. $aTmplVarsActions[] = array(
  1243. 'href' => "javascript:void(0)",
  1244. 'onclick' => "bx_conn_action(this, '" . $sConnection . "', 'add', '" . $iOwner . "')",
  1245. 'title' => bx_html_attribute($sContent),
  1246. 'content' => $sContent,
  1247. 'icon' => 'check'
  1248. );
  1249. }
  1250. }
  1251. return array(
  1252. 'style_prefix' => $sStylePrefix,
  1253. 'bx_repeat:owner_actions' => $aTmplVarsActions
  1254. );
  1255. }
  1256. protected function _getSystemData(&$aEvent, $aBrowseParams = array())
  1257. {
  1258. $mixedResult = $this->_oConfig->getSystemData($aEvent, $aBrowseParams);
  1259. if($mixedResult === false) {
  1260. $sMethod = 'display' . bx_gen_method_name($aEvent['type'] . '_' . $aEvent['action']);
  1261. if(method_exists($this, $sMethod))
  1262. $mixedResult = $this->$sMethod($aEvent);
  1263. }
  1264. if($mixedResult === false)
  1265. return '';
  1266. $this->_preparetDataActions($aEvent, $mixedResult);
  1267. return $mixedResult;
  1268. }
  1269. protected function _getCommonData(&$aEvent, $aBrowseParams = array())
  1270. {
  1271. $CNF = $this->_oConfig->CNF;
  1272. $oModule = $this->getModule();
  1273. $sJsObject = $this->_oConfig->getJsObject('view');
  1274. $sPrefix = $this->_oConfig->getPrefix('common_post');
  1275. $sType = str_replace($sPrefix, '', $aEvent['type']);
  1276. $aResult = array(
  1277. 'owner_id' => $aEvent['object_id'],
  1278. 'icon' => $CNF['ICON'],
  1279. 'sample' => '_bx_timeline_txt_sample_with_article',
  1280. 'sample_wo_article' => '_bx_timeline_txt_sample',
  1281. 'sample_action' => '_bx_timeline_txt_added_sample',
  1282. 'content_type' => $sType,
  1283. 'content' => array(
  1284. 'sample' => '_bx_timeline_txt_sample_with_article',
  1285. 'sample_wo_article' => '_bx_timeline_txt_sample',
  1286. 'sample_action' => '_bx_timeline_txt_added_sample',
  1287. 'url' => $this->_oConfig->getItemViewUrl($aEvent)
  1288. ), //a string to display or array to parse default template before displaying.
  1289. 'views' => '',
  1290. 'votes' => '',
  1291. 'scores' => '',
  1292. 'reports' => '',
  1293. 'comments' => '',
  1294. 'title' => $aEvent['title'], //may be empty.
  1295. 'description' => $aEvent['description'] //may be empty.
  1296. );
  1297. switch($sType) {
  1298. case BX_TIMELINE_PARSE_TYPE_POST:
  1299. if(!empty($aEvent['content']))
  1300. $aResult['content'] = array_merge($aResult['content'], unserialize($aEvent['content']));
  1301. $aLinks = $this->_oDb->getLinks($aEvent['id']);
  1302. if(!empty($aLinks) && is_array($aLinks))
  1303. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_preview'));
  1304. foreach($aLinks as $aLink)
  1305. $aResult['content']['links'][] = array(
  1306. 'url' => $aLink['url'],
  1307. 'title' => $aLink['title'],
  1308. 'text' => $aLink['text'],
  1309. 'thumbnail' => (int)$aLink['media_id'] != 0 ? $oTranscoder->getFileUrl($aLink['media_id']) : ''
  1310. );
  1311. $aPhotos = $this->_oDb->getMedia(BX_TIMELINE_MEDIA_PHOTO, $aEvent['id']);
  1312. if(!empty($aPhotos) && is_array($aPhotos)) {
  1313. $oTranscoder = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_view'));
  1314. $oTranscoderMedium = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_medium'));
  1315. $oTranscoderBig = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_big'));
  1316. foreach($aPhotos as $iPhotoId) {
  1317. $sPhotoSrc = $oTranscoder->getFileUrl($iPhotoId);
  1318. $sPhotoSrcMedium = $oTranscoderMedium->getFileUrl($iPhotoId);
  1319. $sPhotoSrcBig = $oTranscoderBig->getFileUrl($iPhotoId);
  1320. if(empty($sPhotoSrcMedium) && !empty($sPhotoSrc))
  1321. $sPhotoSrcMedium = $sPhotoSrc;
  1322. if(empty($sPhotoSrcBig) && !empty($sPhotoSrcMedium))
  1323. $sPhotoSrcBig = $sPhotoSrcMedium;
  1324. $aResult['content']['images'][] = array(
  1325. 'src' => $sPhotoSrc,
  1326. 'src_medium' => $sPhotoSrcMedium,
  1327. 'src_orig' => $sPhotoSrcBig,
  1328. );
  1329. }
  1330. }
  1331. $aVideos = $this->_oDb->getMedia(BX_TIMELINE_MEDIA_VIDEO, $aEvent['id']);
  1332. if(!empty($aVideos) && is_array($aVideos)) {
  1333. $oTranscoderPoster = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_poster'));
  1334. $oTranscoderMp4 = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_mp4'));
  1335. $oTranscoderWebm = BxDolTranscoderVideo::getObjectInstance($this->_oConfig->getObject('transcoder_videos_webm'));
  1336. foreach($aVideos as $iVideoId) {
  1337. $aResult['content']['videos'][$iVideoId] = array(
  1338. 'id' => $iVideoId,
  1339. 'src_poster' => $oTranscoderPoster->getFileUrl($iVideoId),
  1340. 'src_mp4' => $oTranscoderMp4->getFileUrl($iVideoId),
  1341. 'src_webm' => $oTranscoderWebm->getFileUrl($iVideoId),
  1342. );
  1343. }
  1344. }
  1345. break;
  1346. case BX_TIMELINE_PARSE_TYPE_REPOST:
  1347. if(empty($aEvent['content']))
  1348. return array();
  1349. $aContent = unserialize($aEvent['content']);
  1350. if(!$this->_oConfig->isSystem($aContent['type'] , $aContent['action'])) {
  1351. $aReposted = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $aContent['object_id']));
  1352. $aReposted = $this->_getCommonData($aReposted, $aBrowseParams);
  1353. }
  1354. else
  1355. $aReposted = $this->_getSystemData($aContent, $aBrowseParams);
  1356. if(empty($aReposted) || !is_array($aReposted))
  1357. return array();
  1358. $aResult['content'] = array_merge($aContent, $aReposted['content']);
  1359. $aResult['content']['parse_type'] = !empty($aReposted['content_type']) ? $aReposted['content_type'] : BX_TIMELINE_PARSE_TYPE_DEFAULT;
  1360. $aResult['content']['owner_id'] = $aReposted['owner_id'];
  1361. list($aResult['content']['owner_name'], $aResult['content']['owner_url']) = $oModule->getUserInfo($aReposted['owner_id']);
  1362. if(!empty($aReposted['sample']))
  1363. $aResult['content']['sample'] = $aReposted['sample'];
  1364. if(!empty($aReposted['sample_wo_article']))
  1365. $aResult['content']['sample'] = $aReposted['sample_wo_article'];
  1366. list($sUserName) = $oModule->getUserInfo($aEvent['object_id']);
  1367. $aResult['title'] = _t('_bx_timeline_txt_user_repost', $sUserName, _t($aResult['content']['sample']));
  1368. $aResult['description'] = _t('_bx_timeline_txt_user_reposted_user_sample', $sUserName, $aResult['content']['owner_name'], _t($aResult['content']['sample']));
  1369. break;
  1370. }
  1371. $this->_preparetDataActions($aEvent, $aResult);
  1372. return $aResult;
  1373. }
  1374. protected function _preparetDataActions(&$aEvent, &$aResult)
  1375. {
  1376. if(empty($aEvent) || !is_array($aEvent) || empty($aEvent['id']))
  1377. return;
  1378. $oModule = $this->getModule();
  1379. $sSystem = $this->_oConfig->getObject('view');
  1380. if(empty($aResult['views']) && $oModule->getViewObject($sSystem, $aEvent['id']) !== false)
  1381. $aResult['views'] = array(
  1382. 'system' => $sSystem,
  1383. 'object_id' => $aEvent['id'],
  1384. 'count' => $aEvent['views']
  1385. );
  1386. $sSystem = $this->_oConfig->getObject('vote');
  1387. if(empty($aResult['votes']) && $oModule->getVoteObject($sSystem, $aEvent['id']) !== false)
  1388. $aResult['votes'] = array(
  1389. 'system' => $sSystem,
  1390. 'object_id' => $aEvent['id'],
  1391. 'count' => $aEvent['votes']
  1392. );
  1393. $sSystem = $this->_oConfig->getObject('score');
  1394. if(empty($aResult['scores']) && $oModule->getScoreObject($sSystem, $aEvent['id']) !== false)
  1395. $aResult['scores'] = array(
  1396. 'system' => $sSystem,
  1397. 'object_id' => $aEvent['id'],
  1398. 'score' => $aEvent['score']
  1399. );
  1400. $sSystem = $this->_oConfig->getObject('report');
  1401. if(empty($aResult['reports']) && $oModule->getReportObject($sSystem, $aEvent['id']) !== false)
  1402. $aResult['reports'] = array(
  1403. 'system' => $sSystem,
  1404. 'object_id' => $aEvent['id'],
  1405. 'count' => $aEvent['reports']
  1406. );
  1407. $sSystem = $this->_oConfig->getObject('comment');
  1408. if(empty($aResult['comments']) && $oModule->getCmtsObject($sSystem, $aEvent['id']) !== false)
  1409. $aResult['comments'] = array(
  1410. 'system' => $sSystem,
  1411. 'object_id' => $aEvent['id'],
  1412. 'count' => $aEvent['comments']
  1413. );
  1414. }
  1415. protected function _prepareTextForOutput($s, $iEventId = 0)
  1416. {
  1417. $s = bx_process_output($s, BX_DATA_HTML);
  1418. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  1419. $s = $oMetatags->metaParse($iEventId, $s);
  1420. return $s;
  1421. }
  1422. }
  1423. /** @} */