BxTimelineTemplate.php 55 KB

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