require_once( "./conf.php" );
$symbol_width = 18;
$height = 24;
$lc = "";
function prepare_time_header($date){
$result = "";
$result = substr($date,5,2)."-".substr($date,8,2)."-".substr($date,0,4);
return $result;
}
function get_remain_time($date){
//return $date;
$result = array();
//$date = strtotime("30 October 2009");
$year = substr($date, 0, 4);
$month = substr($date, 5, 2);
$day = substr($date, 8, 2);
$h = substr($date, 11, 2);
$m = substr($date, 14, 2);
$date = mktime($h, $m, 0, $month, $day, $year);
//echo $year."-".$month."-".$day." ".$h.":".$m."
";
$sec=$date - time();
//echo $sec."
";
//echo $date."
";
//echo time()."
";
$days=floor(($date - time()) /86400);
$h1=floor(($date - time()) /3600);
$m1=floor(($date - time()) /60);
$hour=floor($sec/60/60 - $days*24);
$hours=floor($sec/60/60);
$min=floor($sec/60 - $hours*60);
/*
switch( substr( $days, -1, 1 )) {
case 1:
$o='�������';
break;
case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 0: $o='��������';
break;
}
*/
switch(substr($days, -1, 1)){
case 1: $d='day';
break;
case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 0: $d='days';
break;
}
switch(substr($hour, -1, 1)) {
case 1: $h='hour';
break;
case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 0: $h='hours';
break;
default:
$h='hours';
break;
}
switch(substr($min, -1, 1)) {
case 1: $m='min';
break;
case 2: case 3: case 4: $m='min';
break;
case 5: case 6: case 7: case 8: case 9: case 0: $m='min';
break;
}
//if ($sec>0) $result .= 'Remain ';
//if ($days>0) $result .= $days.' '.$d.' ';
//if ($h1>0) $result .= $hour.' '.$h;
//if ($m1>0) $result .= ' '.$min.' '.$m;
//if ($sec<0) echo ("Time was spent!!!");
//echo $result;
$result['d'] = "00";
if ($days>0) $result['d'] = $days;
$result['h'] = "00";
if ($h1>0) $result['h'] = $hour;
$result['m'] = "00";
if ($m1>0) $result['m'] = $min;
return $result;
}
function get_left_start_position($length){
global $bolNoFuture;
$nRet = (92 - 10*$length)/2;
if( $bolNoFuture ) {
return ( 70 - $length ) / 2;
}
if( $nRet < 5 ) {
$nRet = 5;
}
return $nRet;
}
function get_right_start_position($length){
global $bolNoFuture;
if( $bolNoFuture )
return 170 + ( 70 - $length ) / 2;
return 236+(92 - 10*$length)/2;
}
function get_vertical_start_position($length, $fontsize ){
$fontcoef = $fontsize >= 9 ? ( $length < 6 ? 10 : 9 ) : 9;
$phraseWidth = $length * $fontcoef;
return round(( 160 - $phraseWidth ) / 2 );
/*
$nCoef = $length > 17 ? 8.3 : ( $length > 10 ? 9.9 : 10 );
$nOut = round( 160 - $nCoef * $length );
if( $length < 13 )
$nOut /= 2;
if( $nOut < 5 ) {
$nOut = 3;
}
return $nOut;*/
}
function get_number($score){
$score = "".$score;
if (strlen($score) ==1 ) $score = "0".$score;
return $score;
}
function get_short_name($name){
global $dbe;
$sname = "";
$r = $wpdb->get_row("SELECT * FROM `f_nba` WHERE `AwayTeamFullName` = '".$name."' OR `HomeTeamFullName` = '".$name."' LIMIT 0,1");
if (count( (array) $r) >0){
if ($r['AwayTeamFullName'] == $name) $sname = $r['AwayTeamName'];
if ($r['HomeTeamFullName'] == $name) $sname = $r['HomeTeamName'];
}
return $sname;
}
// Create background
$image = imagecreatetruecolor(160, 250);
//Create background headers
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
$gray = imagecolorallocate($image, 27, 27, 27);
$blue = imagecolorallocate($image, 0, 102, 153);
$bgtxtcolor = imagecolorallocate($image, 14, 26, 42);
$bgtimecolor = imagecolorallocate($image, 100, 0, 6);
// Border
imagefilledrectangle( $image, 1, 1, 159, 249, $white );
imagepolygon($image, array (1, 1, 1, 249, 159, 249, 159, 1 ), 4, $black);
imagepolygon($image, array (2, 2, 2, 248, 158, 248, 158, 2 ), 4, $black);
imagepolygon($image, array (3, 3, 3, 247, 157, 247, 157, 3 ), 4, $black);
$date = "";
$at = "";
$ht = "";
$date = "";
$time = "";
$gmt = "";
$dd = "00";
$mm = "00";
$hh = "00";
$bolNoFuture = false;
if( RQ('at') /*&& RQ('ht')*/) {
global $wpdb;
list( $sAway, $sHome ) = decode_team_names();
$sDate = date( 'Y-m-d H:i:s' );
$sSport = RQ('sport');
$sAddSql = " tea1.te_full_name = '" . $sAway . "'" . ( $sHome ? " AND tea2.te_full_name = '" . $sHome . "'" : '' );
$sSport = str_replace( '_', ' ', $sSport );
if ($sSport == 'wc2014') {
$sAddSql = ' ( ' . $sAddSql . " ) OR ( tea2.te_full_name = '" . $sAway . "'" .
( $sHome ? " AND tea1.te_full_name = '" . $sHome . "'" : "" ). " ) " ;
$sSport = 'world_cup_2014';
}
$sQ = "SELECT gms.*,
tea1.te_name as aw, tea2.te_name as ht ,
tea1.te_full_name as awf, tea2.te_full_name as htf ,
tea1.te_logo as awl, tea2.te_logo as htl
FROM `em_games` gms
LEFT JOIN em_teams tea1 ON tea1.te_id = gm_away_team
LEFT JOIN em_teams tea2 ON tea2.te_id = gm_home_team
LEFT JOIN em_sports ON sp_id = gm_sport
WHERE ( $sAddSql ) AND sp_name LIKE '$sSport' AND gm_date >= '$sDate'
ORDER BY gm_date ASC";
//AND `te_full_name` = '$sHome'
$aRes = $wpdb->get_row( $sQ );
if( empty( $aRes )) {
$bolNoFuture = true;
$sQ = "SELECT gms.*,
tea1.te_name as aw, tea2.te_name as ht ,
tea1.te_full_name as awf, tea2.te_full_name as htf ,
tea1.te_logo as awl, tea2.te_logo as htl
FROM `em_games` gms
LEFT JOIN em_teams tea1 ON tea1.te_id = gm_away_team
LEFT JOIN em_teams tea2 ON tea2.te_id = gm_home_team
LEFT JOIN em_sports ON sp_id = gm_sport
WHERE ( $sAddSql ) AND sp_name LIKE '$sSport'
ORDER BY gm_date DESC";
$aRes = $wpdb->get_row( $sQ );
$gmt = '';
} else {
$gmt = $aRes->gm_date;
}
$at = $aRes->aw;
$atf = $aRes->awf;
$ht = $aRes->ht;
$htf = $aRes->htf;
$sAwayLogo = $aRes->awl;
$sHomeLogo = $aRes->htl;
list( $date, $time) = explode( ' ', $aRes->gm_date );
$bSwitchTeams = false;
if( preg_replace( '@[^a-z]@simU', '_', $atf ) != RQ('at')) {
$bSwitchTeams = true;
$sHomeTemp = $ht;
$ht = $at;
$at = $sHomeTemp;
$sHomeFTemp = $htf;
$htf = $atf;
$atf = $sHomeFTemp;
$sALogoTemp = $sAwayLogo;
$sAwayLogo = $sHomeLogo;
$sHomeLogo = $sALogoTemp;
}
//$at = get_short_name($at);
//$ht = get_short_name($ht);
}
/*
if (RQ("gid") != ""){
$r = $wpdb->get_row("SELECT * FROM f_nba WHERE game_id=".RQ("gid"));
$at = $r['AwayTeamName'];
$ht = $r['HomeTeamName'];
$date = $r['sc_date'];
$time = $r['sc_time'];
$gmt = $r['gmt_date'];
}
*/
if ($at != "" /*&& $ht != ""*/ && $at != $ht) {
// Blue Polygon
//imagefilledrectangle ($image, 85, 4, 244, 63, $blue);
imagefilledrectangle ($image, 4, 84, 156, 168, $blue);
// AT Polygon
imagefilledrectangle ($image, 1, 4, 329, 23, $black);
// HT Polygon
imagefilledrectangle ($image, 1, 229, 158, 248, $black);
$sImages = str_replace( 'images', $sSport . '/images', DIR_IMAGES );
//if ($date != ""){
if ( $gmt > date( 'Y-m-d H:i:s')) {
// Timer Polygon
imagefilledrectangle ($image, 6, 96, 154, 129, $gray);
// Text Labels
imagettftext ($image, 8, 0, 14, 94, $white, getcwd() . DIR_FONTS."/verdana.ttf", "COUNTDOWN TO GAME");
$game_time = prepare_time_header($date);
// imagettftext ($image, 10, 0, 110, 34, $bgtimecolor, getcwd() . DIR_FONTS."/verdana.ttf", $game_time);
imagettftext ($image, 8, 0, 11, 140, $white, getcwd() . DIR_FONTS."/verdana.ttf", "NEXT GAME: ".$game_time);
imagettftext ($image, 7, 0, 17, 128, $white, getcwd() . DIR_FONTS."/verdana.ttf", "Days");
imagettftext ($image, 7, 0, 73, 128, $white, getcwd() . DIR_FONTS."/verdana.ttf", "Hrs");
imagettftext ($image, 7, 0, 124, 128, $white, getcwd() . DIR_FONTS."/verdana.ttf", "Mins");
//imagettftext ($image, 7, 0, 265, 48, $white, getcwd() . DIR_FONTS."/verdana.ttf", "SS");
// $time_left = get_left_string($gmt);
// imagettftext ($image, 10, 0, 90, 54, $bgtimecolor, getcwd() . DIR_FONTS."/verdana.ttf", $time_left);
$remain = get_remain_time($gmt);
$dd = get_number($remain['d']);
$hh = get_number($remain['h']);
$mm = get_number($remain['m']);
if (strlen($dd) > 2){
write_numbers($dd, 54, 24, 8, 97 , 0, 0, 54, 24, 100, $lc);
} else {
write_numbers($dd, 36, 24, 8, 97 , 0, 0, 36, 24, 100, $lc);
$blank_img_name = $sImages . '/blank_g.png';
$blank_img = imagecreatefrompng($blank_img_name);
imagecopymerge($image, $blank_img, 44, 97, 0, 0, 18, 24, 100);
}
write_numbers($hh, 36, 24, 62, 97, 0, 0, 36, 24, 100, $lc);
$dot_img_name = $sImages . '/dot_g.png';
$dot_img = @imagecreatefrompng($dot_img_name);
imagecopymerge($image, $dot_img, 98, 97, 0, 0, 18, 24, 100);
//echo ".".$mm.".";
write_numbers($mm, 36, 24, 116, 97, 0, 0, 36, 24, 100, $lc);
} else {
/*imagettftext ($image, 8, 0, 23, 104, $white, getcwd() . DIR_FONTS."/verdana.ttf", "No games scheduled");
imagettftext ($image, 8, 0, 13, 117, $white, getcwd() . DIR_FONTS."/verdana.ttf", "between selected teams");
imagettftext ($image, 8, 0, 39, 130, $white, getcwd() . DIR_FONTS."/verdana.ttf", "for this season");*/
}
$header = get_widget_header($at, $ht);
$fFontSize = get_length( $at ) > 15 ? 8.3 : 9.0;
$atfix = str_ireplace( 'Bosnia and ', 'bosnia-', $at );
$atfix = crop_team_name( $atfix );
$htfix = str_ireplace( 'Bosnia and ', 'bosnia-', $ht );
$htfix = crop_team_name( $htfix );
imagettftext ($image, $fFontSize, 0, get_vertical_start_position(strlen(trim($atfix)), $fFontSize ), 17, $white, getcwd() . DIR_FONTS."/atderek.ttf", strtoupper($atfix));
$fFontSize = get_length( $ht ) > 15 ? 8.3 : 9.0;
imagettftext ($image, $fFontSize, 0, get_vertical_start_position(strlen(trim($htfix)), $fFontSize), 244, $white, getcwd() . DIR_FONTS."/atderek.ttf", strtoupper( $htfix));
//imagettftext ($image, 11, 0, 155, 11, $white, getcwd() . DIR_FONTS."/atderek.ttf", "vs");
$last_game = get_last_result( RQ('sport'), $at, $ht);
if( $bSwitchTeams ) {
$last_game = get_last_result( $sSport, $ht, $at);
$sAScore = $last_game['a_score'];
$last_game['a_score'] = $last_game['h_score'];
$last_game['h_score'] = $sAScore;
}
if ($last_game['date'] != "0000-00-00") {
// White Polygon
$scoreWidth = 36;
$awayX = 11;
$homeX = 113;
$lastGameX = 52;
$nDeltaY = $bolNoFuture ? -29 : 0;
$nLastGameDeltaY = 0;
if( $last_game['a_score'] > 99 || $last_game['h_score'] > 99 ) {
$last_game['a_score'] = sprintf('%03d', $last_game['a_score'] );
$last_game['h_score'] = sprintf('%03d', $last_game['h_score'] );
$scoreWidth = 54;
$awayX -= 7;
$homeX -= 9;
//$lastGameX = 52;
$nDeltaY -= 7;
$nLastGameDeltaY += 23;
}
imagefilledrectangle ($image, 47, 145 + $nDeltaY + $nLastGameDeltaY, 112, 164 + $nDeltaY+ $nLastGameDeltaY, $white);
//imagettftext ($image, 22, 0, 150, 42, $bgtxtcolor, getcwd() . DIR_FONTS."/verdana.ttf", $last_game['score']);
//imagettftext ($image, 8, 0, 96, 46, $gray, getcwd() . DIR_FONTS."/verdana.ttf", "LAST SCORE:".$last_game['date']);
imagettftext ($image, 7, 0, $lastGameX, 154 + $nDeltaY + $nLastGameDeltaY, $black, getcwd() . DIR_FONTS."/verdana.ttf", "LAST GAME");
imagettftext ($image, 7, 0, $lastGameX, 163 + $nDeltaY + $nLastGameDeltaY, $black, getcwd() . DIR_FONTS."/verdana.ttf", $last_game['date']);
write_numbers($last_game['a_score'], $scoreWidth, 24, $awayX, 143 + $nDeltaY, 0, 0, $scoreWidth, 24, 100, $lc);
write_numbers($last_game['h_score'], $scoreWidth, 24, $homeX, 143 + $nDeltaY, 0, 0, $scoreWidth, 24, 100, $lc);
//$dot_img_name = "images/dot_g.png";
//$dot_img = @imagecreatefrompng($dot_img_name);
//imagecopymerge($image, $dot_img, 155, 13, 0, 0, 18, 24, 100);
} else {
// White Polygon
/*imagefilledrectangle ($image, 22, 145, 137, 164, $white);
imagettftext ($image, 7, 0, 33, 154, $black, getcwd() . DIR_FONTS."/verdana.ttf", "No previous games " ) ;//found");
imagettftext ($image, 7, 0, 37, 163, $black, getcwd() . DIR_FONTS."/verdana.ttf", "between teams"); //selected */
}
if ($at != ""){
$img_name = $sImages . "/team_logos/" . $sAwayLogo;
if (!$sAwayLogo || !file_exists($img_name)) {
$img_name = $sImages . "/team_logos/" . NO_LOGO_IMAGE;
}
$at_logo_type = false != stristr( $img_name, '.jpg' ) ? 'jpg' : 'png';
switch( $at_logo_type ) {
case 'png':
$at_logo = imagecreatefrompng( $img_name );
$dest_img = imagecreatetruecolor( 60, 60 );
$whitecolor = imagecolorallocatealpha($dest_img, 255, 255, 255, 255);
imagesavealpha($dest_img, true);
imagefill( $dest_img, 0, 0, $whitecolor);
imagecopyresampled($dest_img, $at_logo, 0 , 0 , 0, 0, 60, 60, 60, 60 );
$at_logo = $dest_img;
break;
default;
$at_logo = imagecreatefromjpeg( $img_name );
break;
}
imagecopymerge($image, $at_logo, 50, 24, 0, 0, 60, 60, 100);
}
if ($ht != ""){
//$img_name = $sImages . "/team_logos/" . 'ball.jpg';
$img_name = $sImages . "/team_logos/" . $sHomeLogo;
if (!$sHomeLogo || !file_exists($img_name)) {
$img_name = $sImages . "/team_logos/" . NO_LOGO_IMAGE;
}
//echo $img_name;
$ht_logo_type = false != stristr( $img_name, '.jpg' ) ? 'jpg' : 'png';
switch( $ht_logo_type ) {
case 'png':
$ht_logo = imagecreatefrompng( $img_name );
$dest_img = imagecreatetruecolor( 60, 60 );
$whitecolor = imagecolorallocate( $dest_img, 255, 255, 255 );
imagefill( $dest_img, 0, 0, $whitecolor);
imagecopyresampled($dest_img, $ht_logo, 0 , 0 , 0, 0, 60, 60, 60, 60 );
$ht_logo = $dest_img;
break;
default;
$ht_logo = imagecreatefromjpeg( $img_name );
break;
}
imagecopymerge($image, $ht_logo, 50, 169, 0, 0, 60, 60, 100);
}
} else {
imagettftext ($image, 40, 0, 35, 110, $black, getcwd() . DIR_FONTS."/verdana.ttf", "NO");
imagettftext ($image, 40, 0, 2, 160, $black, getcwd() . DIR_FONTS."/verdana.ttf", "GAME");
}
// Display
//write_to_log('b7c');
write_to_log_base( $sSport, 'b7c', RQi('vers') );
/*
*/
header("Content-type: image/png");
imagepng($image);
/* */
?>