PageRenderTime 30ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/com_joomleague/components/com_joomleague/helpers/html.php

https://gitlab.com/julienv/joomleague
PHP | 561 lines | 436 code | 44 blank | 81 comment | 86 complexity | dcdda66b7586afc3736412f3ad225b7e MD5 | raw file
  1. <?php
  2. /**
  3. * @copyright Copyright (C) 2006-2014 joomleague.at. All rights reserved.
  4. * @license GNU/GPL,see LICENSE.php
  5. * Joomla! is free software. This version may have been modified pursuant
  6. * to the GNU General Public License,and as distributed it includes or
  7. * is derivative of works licensed under the GNU General Public License or
  8. * other free or open source software licenses.
  9. * See COPYRIGHT.php for copyright notices and details.
  10. */
  11. // Check to ensure this file is included in Joomla!
  12. defined('_JEXEC') or die('Restricted access');
  13. /**
  14. * provides html code snippets for the views
  15. * @author julienV
  16. */
  17. class JoomleagueHelperHtml {
  18. /**
  19. * Return formatted match time
  20. *
  21. * @param object $game
  22. * @param array $config
  23. * @param array $overallconfig
  24. * @param object $project
  25. * @return string html
  26. */
  27. public static function showMatchTime(&$game, &$config, &$overallconfig, &$project)
  28. // overallconfig could be deleted here and replaced below by config as both array were merged in view.html.php
  29. {
  30. $output='';
  31. if (!isset($overallconfig['time_format'])) {
  32. $overallconfig['time_format']='H:i';
  33. }
  34. $timeSuffix=JText::_('COM_JOOMLEAGUE_GLOBAL_CLOCK');
  35. if ($timeSuffix=='COM_JOOMLEAGUE_GLOBAL_CLOCK') {
  36. $timeSuffix='%1$s&nbsp;h';
  37. }
  38. if ($game->match_date)
  39. {
  40. $matchTime = JoomleagueHelper::getMatchTime($game, $overallconfig['time_format']);
  41. if ($config['show_time_suffix'] == 1)
  42. {
  43. $output .= sprintf($timeSuffix,$matchTime);
  44. }
  45. else
  46. {
  47. $output .= $matchTime;
  48. }
  49. $config['mark_now_playing']=(isset($config['mark_now_playing'])) ? $config['mark_now_playing'] : 0;
  50. if ($config['mark_now_playing'])
  51. {
  52. $totalMatchDuration = ($project->halftime * ($project->game_parts - 1)) + $project->game_regular_time;
  53. if ($project->allow_add_time == 1 && ($game->team1_result == $game->team2_result))
  54. {
  55. $totalMatchDuration += $project->add_time;
  56. }
  57. $project_tz = new DateTimeZone($game->timezone);
  58. $startTimestamp = JoomleagueHelper::getMatchStartTimestamp($game);
  59. $startTime = new DateTime($startTimestamp, $project_tz);
  60. $endTime = new DateTime($startTimestamp, $project_tz);
  61. $endTime->add(new DateInterval('PT'.$totalMatchDuration.'M'));
  62. $now = new DateTime('now', $project_tz);
  63. if ($now >= $startTime && $now <= $endTime)
  64. {
  65. $match_begin=$output.' ';
  66. $title=str_replace('%STARTTIME%',$match_begin,trim(htmlspecialchars($config['mark_now_playing_alt_text'])));
  67. $title=str_replace('%ACTUALTIME%',self::mark_now_playing($thistime,$match_stamp,$config,$project),$title);
  68. $styletext='';
  69. if (isset($config['mark_now_playing_blink']) && $config['mark_now_playing_blink'])
  70. {
  71. $styletext=' style="text-decoration:blink"';
  72. }
  73. $output='<b><i><acronym title="'.$title.'"'.$styletext.'>';
  74. $output .= $config['mark_now_playing_text'];
  75. $output .= '</acronym></i></b>';
  76. }
  77. }
  78. }
  79. else
  80. {
  81. $matchTime='--&nbsp;:&nbsp;--';
  82. if ($config['show_time_suffix'])
  83. {
  84. $output .= sprintf($timeSuffix,$matchTime);
  85. }
  86. else
  87. {
  88. $output .= $matchTime;
  89. }
  90. }
  91. return $output;
  92. }
  93. /**
  94. * prints teams names and divisions...
  95. *
  96. * @param object $hometeam
  97. * @param object $guestteam
  98. * @param array $config
  99. * @return string html
  100. */
  101. public function showDivisonRemark(&$hometeam,&$guestteam,&$config)
  102. {
  103. $output='';
  104. if ($config['switch_home_guest']) {
  105. $tmpteam =& $hometeam; $hometeam =& $guestteam; $guestteam =& $tmpteam;
  106. }
  107. if ((isset($hometeam) && $hometeam->division_id > 0) && (isset($guestteam) && $guestteam->division_id > 0))
  108. {
  109. //TO BE FIXED: Where is spacer defined???
  110. if (! isset($config['spacer'])) {
  111. $config['spacer']='/';
  112. }
  113. $nametype='division_'.$config['show_division_name'];
  114. if ($config['show_division_link'])
  115. {
  116. $link=JoomleagueHelperRoute::getRankingRoute($this->project->id,null,null,null,0,$hometeam->division_id);
  117. $output .= JHtml::link($link,$hometeam->$nametype);
  118. }
  119. else
  120. {
  121. $output .= $hometeam->$nametype;
  122. }
  123. if ($hometeam->division_id != $guestteam->division_id)
  124. {
  125. $output .= $config['spacer'];
  126. if ($config['show_division_link'] == 1)
  127. {
  128. $link=JoomleagueHelperRoute::getRankingRoute($this->project->id,null,null,null,0,$guestteam->division_id);
  129. $output .= JHtml::link($link,$guestteam->$nametype);
  130. }
  131. else
  132. {
  133. $output .= $guestteam->$nametype;
  134. }
  135. }
  136. }
  137. else
  138. {
  139. $output .= '&nbsp;';
  140. }
  141. return $output;
  142. }
  143. /**
  144. * Shows matchday title
  145. *
  146. * @param string $title
  147. * @param int $current_round
  148. * @param array $config
  149. * @param int $mode
  150. * @return string html
  151. */
  152. public function showMatchdaysTitle($title, $current_round, &$config, $mode=0)
  153. {
  154. $projectid = JRequest::getInt('p',0);
  155. echo ($title != '') ? $title.' - ' : $title;
  156. if ($current_round > 0)
  157. {
  158. $thisround = JTable::getInstance('Round','Table');
  159. $thisround->load($current_round);
  160. if ($config['type_section_heading'] == 1 && $thisround->name != '')
  161. {
  162. if ($mode == 1)
  163. {
  164. $link=JoomleagueHelperRoute::getRankingRoute($projectid,$thisround->id);
  165. echo JHtml::link($link,$thisround->name);
  166. }
  167. else
  168. {
  169. echo $thisround->name;
  170. }
  171. }
  172. elseif ($thisround->roundcode > 0)
  173. {
  174. echo ' '.JText::sprintf('COM_JOOMLEAGUE_RESULTS_MATCHDAY', $thisround->roundcode).'&nbsp;';
  175. }
  176. if ($config['show_rounds_dates'] == 1)
  177. {
  178. echo " (";
  179. if (! strstr($thisround->round_date_first,"0000-00-00"))
  180. {
  181. echo JHtml::date($thisround->round_date_first .' UTC',
  182. 'COM_JOOMLEAGUE_GLOBAL_CALENDAR_DATE',
  183. JoomleagueHelper::getTimezone($this->project, $this->overallconfig));
  184. }
  185. if (($thisround->round_date_last != $thisround->round_date_first) &&
  186. (! strstr($thisround->round_date_last,"0000-00-00")))
  187. {
  188. echo " - ".JHtml::date($thisround->round_date_last .' UTC',
  189. 'COM_JOOMLEAGUE_GLOBAL_CALENDAR_DATE',
  190. JoomleagueHelper::getTimezone($this->project, $this->overallconfig));
  191. }
  192. echo ")";
  193. }
  194. }
  195. }
  196. public function getRoundSelectNavigation($form)
  197. {
  198. $rounds = $this->get('RoundOptions');
  199. $division = JRequest::getInt('division',0);
  200. if($form){
  201. $currenturl=JoomleagueHelperRoute::getResultsRoute($this->project->slug, $this->roundid, $division);
  202. $options=array();
  203. foreach ($rounds as $r)
  204. {
  205. $link=JoomleagueHelperRoute::getResultsRoute($this->project->slug, $r->value, $division);
  206. $options[]=JHtml::_('select.option', $link, $r->text);
  207. }
  208. } else {
  209. $currenturl=JoomleagueHelperRoute::getResultsRoute($this->project->slug, $this->roundid, $division);
  210. $options=array();
  211. foreach ($rounds as $r)
  212. {
  213. $link=JoomleagueHelperRoute::getResultsRoute($this->project->slug, $r->value, $division);
  214. $options[]=JHtml::_('select.option', $link, $r->text);
  215. }
  216. }
  217. return JHtml::_('select.genericlist',$options,'select-round','onchange="joomleague_changedoc(this);"','value','text',$currenturl);
  218. }
  219. /**
  220. * display match playground
  221. *
  222. * @param object $game
  223. */
  224. public function showMatchPlayground(&$game)
  225. {
  226. if (($this->config['show_playground'] || $this->config['show_playground_alert']) && isset($game->playground_id))
  227. {
  228. if (empty($game->playground_id)){
  229. $game->playground_id=$this->teams[$game->projectteam1_id]->standard_playground;
  230. }
  231. if (empty($game->playground_id))
  232. {
  233. $cinfo = JTable::getInstance('Club','Table');
  234. $cinfo->load($this->teams[$game->projectteam1_id]->club_id);
  235. $game->playground_id=$cinfo->standard_playground;
  236. $this->teams[$game->projectteam1_id]->standard_playground=$cinfo->standard_playground;
  237. }
  238. if (!$this->config['show_playground'] && $this->config['show_playground_alert'])
  239. {
  240. if ($this->teams[$game->projectteam1_id]->standard_playground==$game->playground_id)
  241. {
  242. echo '-';
  243. return '';
  244. }
  245. }
  246. $boldStart = '';
  247. $boldEnd = '';
  248. $toolTipTitle = JText::_('COM_JOOMLEAGUE_PLAYGROUND_MATCH');
  249. $toolTipText = '';
  250. $playgroundID = $this->teams[$game->projectteam1_id]->standard_playground;
  251. if (($this->config['show_playground_alert']) && ($this->teams[$game->projectteam1_id]->standard_playground!=$game->playground_id))
  252. {
  253. $boldStart = '<b style="color:red; ">';
  254. $boldEnd = '</b>';
  255. $toolTipTitle = JText::_('COM_JOOMLEAGUE_PLAYGROUND_NEW');
  256. $playgroundID = $this->teams[$game->projectteam1_id]->standard_playground;
  257. }
  258. $pginfo = JTable::getInstance('Playground','Table');
  259. $pginfo->load($game->playground_id);
  260. $toolTipText .= $pginfo->name.'&lt;br /&gt;';
  261. $toolTipText .= $pginfo->address.'&lt;br /&gt;';
  262. $toolTipText .= $pginfo->zipcode.' '.$pginfo->city. '&lt;br /&gt;';
  263. $link=JoomleagueHelperRoute::getPlaygroundRoute($this->project->id,$game->playground_id);
  264. $playgroundName=($this->config['show_playground_name'] == 'name') ? $pginfo->name : $pginfo->short_name;
  265. ?>
  266. <span class='hasTip'
  267. title='<?php echo $toolTipTitle; ?> :: <?php echo $toolTipText; ?>'>
  268. <?php echo JHtml::link($link,$boldStart.$playgroundName.$boldEnd); ?> </span>
  269. <?php
  270. }
  271. }
  272. /**
  273. * mark currently playing game
  274. *
  275. * @param int $thistime
  276. * @param int $match_stamp
  277. * @param array $config
  278. * @param object $project
  279. * @return string
  280. */
  281. public function mark_now_playing($thistime,$match_stamp,&$config,&$project)
  282. {
  283. $whichpart=1;
  284. $gone_since_begin=intval(($thistime - $match_stamp)/60);
  285. $parts_time=intval($project->game_regular_time / $project->game_parts);
  286. if ($project->allow_add_time) {
  287. $overtime=1;
  288. }else{$overtime=0;
  289. }
  290. $temptext=JText::_('COM_JOOMLEAGUE_RESULTS_LIVE_WRONG');
  291. for ($temp_count=1; $temp_count <= $project->game_parts+$overtime; $temp_count++)
  292. {
  293. $this_part_start=(($temp_count-1) * ($project->halftime + $parts_time));
  294. $this_part_end=$this_part_start + $parts_time;
  295. $next_part_start=$this_part_end + $project->halftime;
  296. if ($gone_since_begin >= $this_part_start && $gone_since_begin <= $this_part_end)
  297. {
  298. $temptext=str_replace('%PART%',$temp_count,trim(htmlspecialchars($config['mark_now_playing_alt_actual_time'])));
  299. $temptext=str_replace('%MINUTE%',($gone_since_begin+1 - ($temp_count-1)*$project->halftime),$temptext);
  300. break;
  301. }
  302. elseif ($gone_since_begin > $this_part_end && $gone_since_begin < $next_part_start)
  303. {
  304. $temptext=str_replace('%PART%',$temp_count,trim(htmlspecialchars($config['mark_now_playing_alt_actual_break'])));
  305. break;
  306. }
  307. }
  308. return $temptext;
  309. }
  310. /**
  311. * return thumb up/down image url if team won/loss
  312. *
  313. * @param object $game
  314. * @param int $projectteam_id
  315. * @param array attributes
  316. * @return string image html code
  317. */
  318. public function getThumbUpDownImg($game, $projectteam_id, $attributes = null)
  319. {
  320. $res = JoomleagueHelper::getTeamMatchResult($game, $projectteam_id);
  321. if ($res === false) {
  322. return false;
  323. }
  324. if ($res == 0)
  325. {
  326. $img = 'media/com_joomleague/jl_images/draw.png';
  327. $alt = JText::_('COM_JOOMLEAGUE_GLOBAL_DRAW');
  328. $title = $alt;
  329. }
  330. else if ($res < 0)
  331. {
  332. $img = 'media/com_joomleague/jl_images/thumbs_down.png';
  333. $alt = JText::_('COM_JOOMLEAGUE_GLOBAL_LOST');
  334. $title = $alt;
  335. }
  336. else
  337. {
  338. $img = 'media/com_joomleague/jl_images/thumbs_up.png';
  339. $alt = JText::_('COM_JOOMLEAGUE_GLOBAL_WON');
  340. $title = $alt;
  341. }
  342. // default title attribute, if not specified in passed attributes
  343. $def_attribs = array('title' => $title);
  344. if ($attributes) {
  345. $attributes = array_merge($def_attribs, $attributes);
  346. }
  347. else {
  348. $attributes = $def_attribs;
  349. }
  350. return JHtml::image($img, $alt, $attributes);
  351. }
  352. /**
  353. * return thumb up/down image as link with score as title
  354. *
  355. * @param object $game
  356. * @param int $projectteam_id
  357. * @param array attributes
  358. * @return string linked image html code
  359. */
  360. public static function getThumbScore($game, $projectteam_id, $attributes = null)
  361. {
  362. if (!$img = self::getThumbUpDownImg($game, $projectteam_id, $attributes = null)) {
  363. return false;
  364. }
  365. $txt = $teams[$game->projectteam1_id]->name.' - '.$teams[$game->projectteam2_id]->name.' '.$game->team1_result.' - '. $game->team2_result;
  366. $attribs = array('title' => $txt);
  367. if (is_array($attributes)) {
  368. $attribs = array_merge($attributes, $attribs);
  369. }
  370. $url = JRoute::_(JoomleagueHelperRoute::getMatchReportRoute($game->project_slug, $game->slug));
  371. return JHtml::link($url, $img);
  372. }
  373. /**
  374. * return up/down image for ranking
  375. *
  376. * @param object $team (rank)
  377. * @param object $previous (rank)
  378. * @param int $ptid
  379. * @return string image html code
  380. */
  381. public function getLastRankImg($team,$previous,$ptid,$attributes = null)
  382. {
  383. if ( isset( $previous[$ptid]->rank ) )
  384. {
  385. $imgsrc = 'media/com_joomleague/jl_images/';
  386. if ( ( $team->rank == $previous[$ptid]->rank ) || ( $previous[$ptid]->rank == "" ) )
  387. {
  388. $imgsrc .= "same.png";
  389. $alt = JText::_('COM_JOOMLEAGUE_RANKING_SAME');
  390. $title = $alt;
  391. }
  392. elseif ( $team->rank < $previous[$ptid]->rank )
  393. {
  394. $imgsrc .= "up.png";
  395. $alt = JText::_('COM_JOOMLEAGUE_RANKING_UP');
  396. $title = $alt;
  397. }
  398. elseif ( $team->rank > $previous[$ptid]->rank )
  399. {
  400. $imgsrc .= "down.png";
  401. $alt = JText::_('COM_JOOMLEAGUE_RANKING_DOWN');
  402. $title = $alt;
  403. }
  404. $def_attribs = array('title' => $title);
  405. if ($attributes) {
  406. $attributes = array_merge($def_attribs, $attributes);
  407. }
  408. else {
  409. $attributes = $def_attribs;
  410. }
  411. return JHtml::image($imgsrc,$alt,$attributes);
  412. }
  413. }
  414. public static function printColumnHeadingSort( $columnTitle, $paramName, $config = null, $default="DESC" )
  415. {
  416. $output = "";
  417. $img='';
  418. if ( $config['column_sorting'] || $config == null)
  419. {
  420. $params = array(
  421. "option" => "com_joomleague",
  422. "view" => JRequest::getVar("view", "ranking"),
  423. "p" => JRequest::getInt( "p", 0 ),
  424. "r" => JRequest::getInt( "r", 0 ),
  425. "type" => JRequest::getVar( "type", "" ) );
  426. if ( JRequest::getVar( 'order', '' ) == $paramName )
  427. {
  428. $params["order"] = $paramName;
  429. $params["dir"] = ( JRequest::getVar( 'dir', '') == 'ASC' ) ? 'DESC' : 'ASC';
  430. $imgname = 'sort'.(JRequest::getVar( 'dir', '') == 'ASC' ? "02" :"01" ).'.gif';
  431. $img = JHtml::image(
  432. 'media/com_joomleague/jl_images/' . $imgname,
  433. $params["dir"] );
  434. }
  435. else
  436. {
  437. $params["order"] = $paramName;
  438. $params["dir"] = $default;
  439. }
  440. $query = JUri::buildQuery( $params );
  441. echo JHtml::link(
  442. JRoute::_( "index.php?".$query ),
  443. JText::_($columnTitle),
  444. array( "class" => "jl_rankingheader" ) ).$img;
  445. }
  446. else
  447. {
  448. echo JText::_($columnTitle);
  449. }
  450. }
  451. public static function nextLastPages( $url, $text, $maxentries, $limitstart = 0, $limit = 10 )
  452. {
  453. $latestlimitstart = 0;
  454. if ( intval( $limitstart - $limit ) > 0 )
  455. {
  456. $latestlimitstart = intval( $limitstart - $limit );
  457. }
  458. $nextlimitstart = 0;
  459. if ( ( $limitstart + $limit ) < $maxentries )
  460. {
  461. $nextlimitstart = $limitstart + $limit;
  462. }
  463. $lastlimitstart = ( $maxentries - ( $maxentries % $limit ) );
  464. if ( ( $maxentries % $limit ) == 0 )
  465. {
  466. $lastlimitstart = ( $maxentries - ( $maxentries % $limit ) - $limit );
  467. }
  468. echo '<center>';
  469. echo '<table style="width: 50%; align: center;" cellspacing="0" cellpadding="0" border="0">';
  470. echo '<tr>';
  471. echo '<td style="width: 10%; text-align: left;" nowrap="nowrap">';
  472. if ( $limitstart > 0 )
  473. {
  474. $query = JUri::buildQuery(
  475. array(
  476. "limit" => $limit,
  477. "limitstart" => 0 ) );
  478. echo JHtml::link( $url.$query, '&lt;&lt;&lt;' );
  479. echo '&nbsp;&nbsp;&nbsp';
  480. $query = JUri::buildQuery(
  481. array(
  482. "limit" => $limit,
  483. "limitstart" => $latestlimitstart ) );
  484. echo JHtml::link( $url.$query, '&lt;&lt;' );
  485. echo '&nbsp;&nbsp;&nbsp;';
  486. }
  487. echo '</td>';
  488. echo '<td style="text-align: center;" nowrap="nowrap">';
  489. $players_to = $maxentries;
  490. if ( ( $limitstart + $limit ) < $maxentries )
  491. {
  492. $players_to = ( $limitstart + $limit );
  493. }
  494. echo sprintf( $text, $maxentries, ($limitstart+1).' - '.$players_to );
  495. echo '</td>';
  496. echo '<td style="width: 10%; text-align: right;" nowrap="nowrap">';
  497. if ( $nextlimitstart > 0 )
  498. {
  499. echo '&nbsp;&nbsp;&nbsp;';
  500. $query = JUri::buildQuery(
  501. array(
  502. "limit" => $limit,
  503. "limitstart" => $nextlimitstart ) );
  504. echo JHtml::link( $url.$query, '&gt;&gt;' );
  505. echo '&nbsp;&nbsp;&nbsp';
  506. $query = JUri::buildQuery(
  507. array(
  508. "limit" => $limit,
  509. "limitstart" => $lastlimitstart ) );
  510. echo JHtml::link( $url.$query, '&gt;&gt;&gt;' );
  511. }
  512. echo '</td>';
  513. echo '</tr>';
  514. echo '</table>';
  515. echo '</center>';
  516. }
  517. }