$emblemwidth = 18; $imgwidth = $box['width'] + $emblemwidth + 7; $imgheight = 24; $im = imagecreatetruecolor($imgwidth, $imgheight); imagealphablending($im, true); $transcolor = imagecolorallocate($im, 0xff, 0xff, 0xff); $badgecolor = imagecolorallocate($im, 0x33, 0x33, 0x33); $color = imagecolorallocate($im, 0xff, 0xff, 0xff); $emblemcolor = imagecolorallocate($im, $r, $g, $b); imagefill($im, 0, 0, $transcolor); imagefillroundedrect($im, 0, 0, $imgwidth - 1, $imgheight - 1, 5, $badgecolor); // draw emblem $r = 7; $x = 10; $y = $imgheight / 2; imagefilledellipseaa($im, $x, $y, $r, $r, $emblemcolor); // draw text $x = $emblemwidth; $y = $size / 2 + $imgheight / 2; imagettftext($im, $size, $angle, $x, $y, $color, $font, $text); // output header('Content-type: image/png'); imagepng($im); ////////////////// // Parses a color value to an array. function color2rgb($color) { $rgb = array(); $rgb[] = 0xff & $color >> 16; $rgb[] = 0xff & $color >> 8; $rgb[] = 0xff & $color >> 0;
function generate() { $regioncache = KB_CACHEDIR . '/img/map/' . KB_SITE . '_' . $this->regionid_ . '_' . $this->imgwidth_ . '.png'; $is_cached = 0; //INIT $title_caption = $this->regname_; if (file_exists($regioncache)) { $cfgttl = '6'; $ttyl_sec = $cfgttl * 3600; $ttl = filemtime($regioncache) + $ttyl_sec; if ($ttl <= time()) { $is_cached = 0; unlink($regioncache); unlink($regioncache . ".txt"); } else { $img = imagecreatefrompng($regioncache); $is_cached = 1; } } if ($is_cached == 0) { $sql = 'SELECT sys.sys_x, sys.sys_y, sys.sys_z, sys.sys_sec, sys.sys_id, sys.sys_name, sys.sys_id, sjp.sjp_to, con.con_id, con.con_name, reg.reg_id, reg.reg_name, reg.reg_x, reg.reg_z FROM kb3_systems sys LEFT JOIN kb3_system_jumps sjp ON sys.sys_id = sjp.sjp_from JOIN kb3_constellations con ON con.con_id = sys.sys_con_id JOIN kb3_regions reg ON reg.reg_id = con.con_reg_id'; if ($this->mode_ == "sys") { $sql .= " and reg.reg_id = '" . $this->regionid_ . "'"; } else { $sql .= " and reg.reg_id = " . $this->regionid2_; } $qry = new DBQuery(); $qry->execute($sql) or die($qry->getErrorMsg()); if (!$img) { $img = imagecreatetruecolor($this->imgwidth_, $this->imgheight_); } $white = imagecolorallocate($img, 255, 255, 255); $red = imagecolorallocate($img, 255, 0, 0); if (config::get('map_act_cl_bg')) { $bcolor = explode(",", config::get('map_act_cl_bg')); mapview::setbgcolor($bcolor[0], $bcolor[1], $bcolor[2]); } $bgcolor = imagecolorallocate($img, $this->bgcolor_[0], $this->bgcolor_[1], $this->bgcolor_[2]); imagefilledrectangle($img, 0, 0, $this->imgwidth_, $this->imgheight_, $bgcolor); $color = $white; $fov = 0; //INIT $i = 0; $minx = 0; $minz = 0; $maxx = 0; $maxz = 0; $mini = 0; $maxi = 0; $pi = 0; $sc = 0; $systems = array(); while ($row = $qry->getRow()) { $i = $row['sys_id']; $systems[] = $i; if ($i < $mini || $mini == 0) { $mini = $i; } if ($i > $maxi || $maxi == 0) { $maxi = $i; } $x = $row['sys_x'] * $this->ly_; $z = $row['sys_z'] * $this->ly_; if ($x < $minx || $minx == 0) { $minx = $x; } if ($x > $maxx || $maxx == 0) { $maxx = $x; } if ($z < $minz || $minz == 0) { $minz = $z; } if ($z > $maxz || $maxz == 0) { $maxz = $z; } $sys[$i][0] = $x; $sys[$i][1] = $z; if ($i == $pi || $pi == 0) { $sys[$i][2][$sc] = $row['sjp_to']; $sys[$i][3] = $sc++; } else { $sc = 0; } $sys[$i][4] = $row['sys_id']; $sys[$i][5] = $row['sys_name']; $sys[$i][6] = $row['sys_sec']; $sys[$i][7] = $row['con_id']; $sys[$i][8] = $row['con_name']; $sys[$i][9] = $row['reg_id']; $sys[$i][10] = $row['reg_name']; $pi = $i; } $dx = abs($maxx - $minx); $dz = abs($maxz - $minz); $xscale = 1 / ($dx / ($this->imgwidth_ - $this->offset_ * 2)); $yscale = 1 / ($dz / ($this->imgheight_ - $this->offset_ * 2)); // draw lines if ($this->showlines_) { if (config::get('map_act_cl_line')) { $lcolor = explode(",", config::get('map_act_cl_line')); mapview::setlinecolor($lcolor[0], $lcolor[1], $lcolor[2]); } foreach ($systems as $n) { $px = $this->offset_ + ($sys[$n][0] - $minx) * $xscale; $py = $this->offset_ + ($sys[$n][1] - $minz) * $yscale; $line_col = imagecolorallocate($img, $this->linecolor_[0], $this->linecolor_[1], $this->linecolor_[2]); for ($m = 0; $m <= $sys[$n][3]; $m++) { $sys_to = $sys[$n][2][$m]; if ($sys[$sys_to][4] != "") { $px_to = $this->offset_ + ($sys[$sys_to][0] - $minx) * $xscale; $py_to = $this->offset_ + ($sys[$sys_to][1] - $minz) * $yscale; imageline($img, $px, $py, $px_to, $py_to, $line_col); } } $n++; } } //---------------------------------------------- // draw systems //---------------------------------------------- foreach ($systems as $n) { if (config::get('map_act_cl_normal')) { $scolor = explode(",", config::get('map_act_cl_normal')); mapview::setnormalcolor($scolor[0], $scolor[1], $scolor[2]); } $px = round($this->offset_ + ($sys[$n][0] - $minx) * $xscale); $py = round($this->offset_ + ($sys[$n][1] - $minz) * $yscale); $color = imagecolorallocate($img, $this->normalcolor_[0], $this->normalcolor_[1], $this->normalcolor_[2]); imagefilledellipseaa($img, $px, $py, 4, 4, $color); //gm this is the white system dot, shrunkg it down from 6x6 size $n++; } imagepng($img, $regioncache); $fp = fopen($regioncache . ".txt", "w"); // writting offset data into file if ($fp) { // This step is needed cause when the image is cached only 1 system is queried from the DB // therefor it is impossible to calculcate the offset again. fwrite($fp, $maxx . "\n" . $minx . "\n" . $maxz . "\n" . $minz); } fclose($fp); } //--------------------------------------------------------------------------------------- //System Highlight starts here //--------------------------------------------------------------------------------------- if ($this->mode_ == "sys") { $sql = "SELECT sys.sys_x, sys.sys_y, sys.sys_z, sys.sys_sec, sys.sys_id, sys.sys_name, sys.sys_id\n\t\t\t\t\tFROM kb3_systems sys\n\t\t\t\t\tWHERE sys.sys_id = '" . $this->systemid_ . "'"; $qry = new DBQuery(); $qry->execute($sql) or die($qry->getErrorMsg()); $fov = 0; //INIT $row = $qry->getRow(); $x = $row['sys_x'] * $this->ly_; $z = $row['sys_z'] * $this->ly_; $sys[0] = $x; $sys[1] = $z; $sys[4] = $row['sys_id']; $sys[5] = $row['sys_name']; $sys[6] = $row['sys_sec']; $fp = fopen($regioncache . ".txt", "r"); // getting offset data from file if ($fp == FALSE) { echo "failt to open {$regioncache}"; exit; } $maxx = fgets($fp); $minx = fgets($fp); $maxz = fgets($fp); $minz = fgets($fp); fclose($fp); $dx = abs($maxx - $minx); $dz = abs($maxz - $minz); $xscale = 1 / ($dx / ($this->imgwidth_ - $this->offset_ * 2)); $yscale = 1 / ($dz / ($this->imgheight_ - $this->offset_ * 2)); $px = round($this->offset_ + ($sys[0] - $minx) * $xscale); $py = round($this->offset_ + ($sys[1] - $minz) * $yscale); if (config::get('map_act_cl_hl2')) { $hscolor = explode(",", config::get('map_act_cl_hl2')); $color = imagecolorallocate($img, $hscolor[0], $hscolor[1], $hscolor[2]); } else { $color = imagecolorallocate($img, '255', '0', '0'); } $tlen = 5 * strlen($sys[5]); if ($px + $tlen > $this->imgwidth_ - 20) { $sx = $px - $tlen; } else { $sx = $px + 5; } if ($py + 5 > $this->imgheight_ - 20) { $sy = $py - 5; } else { $sy = $py + 5; } imagestring($img, 1, $sx, $sy, $sys[5], $color); imagefilledellipseaa($img, $px, $py, 6, 6, $color); } //--------------------------------------------------------------------------------------- // Activity starts here //--------------------------------------------------------------------------------------- if ($this->mode_ == "activity") { $kills = 0; //INIT $overall_kill = 0; $color = imagecolorallocate($img, $this->normalcolor_[0], $this->normalcolor_[1], $this->normalcolor_[2]); $paint_name = config::get('map_act_shownames'); $sql2 = "SELECT sys.sys_name, sys.sys_x, sys.sys_y, sys.sys_z, sys.sys_sec, sys.sys_id, count( DISTINCT kll.kll_id ) AS kills\n\t\t\t\tFROM kb3_systems sys, kb3_kills kll, kb3_inv_detail inv, kb3_constellations con, kb3_regions reg\n\t\t\t\tWHERE kll.kll_system_id = sys.sys_id\n\t\t\t\tAND inv.ind_kll_id = kll.kll_id"; if (count(config::get('cfg_allianceid'))) { $orargs[] = 'inv.ind_all_id IN (' . implode(",", config::get('cfg_allianceid')) . ") "; } if (count(config::get('cfg_corpid'))) { $orargs[] = 'inv.ind_crp_id IN (' . implode(",", config::get('cfg_corpid')) . ") "; } if (count(config::get('cfg_pilotid'))) { $orargs[] = 'inv.ind_plt_id IN (' . implode(",", config::get('cfg_pilotid')) . ") "; } $sql2 .= " AND (" . implode(" OR ", $orargs) . ")"; if (isset($this->week_)) { $sql2 .= " and date_format( kll.kll_timestamp, \"%u\" ) = " . $this->week_; } if (isset($this->month_)) { $sql2 .= " and date_format( kll.kll_timestamp, \"%m\" ) = " . $this->month_; } $sql2 .= " AND date_format( kll.kll_timestamp, \"%Y\" ) = " . $this->year_ . "\n\t\t\t\t\tAND con.con_id = sys.sys_con_id\n\t\t\t\t\tAND reg.reg_id = con.con_reg_id\n\t\t\t\t\tAND reg.reg_id =" . $this->regionid2_ . "\n\t\t\t\t\tGROUP BY sys.sys_name\n\t\t\t\t\tORDER BY kills desc"; $qry2 = new DBQuery(); $qry2->execute($sql2) or die($qry2->getErrorMsg()); while ($row2 = $qry2->getRow()) { $kills = $row2['kills']; $overall_kill = $overall_kill + $kills; //OFFSET CALCULATION $x = $row2['sys_x'] * $this->ly_; $z = $row2['sys_z'] * $this->ly_; $sys[0] = $x; $sys[1] = $z; $sys[4] = $row2['sys_id']; $sys[5] = $row2['sys_name']; $sys[6] = $row2['sys_sec']; $fp = fopen($regioncache . ".txt", "r"); // getting offset data from file $maxx = fgets($fp); $minx = fgets($fp); $maxz = fgets($fp); $minz = fgets($fp); fclose($fp); $dx = abs($maxx - $minx); $dz = abs($maxz - $minz); $xscale = 1 / ($dx / ($this->imgwidth_ - $this->offset_ * 2)); $yscale = 1 / ($dz / ($this->imgheight_ - $this->offset_ * 2)); $px = round($this->offset_ + ($sys[0] - $minx) * $xscale); $py = round($this->offset_ + ($sys[1] - $minz) * $yscale); if ($kills == 1) { // If there is only one kill we use normal highlight color $ratio = 1; if (config::get('map_act_cl_hl')) { $hscolor = explode(",", config::get('map_act_cl_hl')); $color = imagecolorallocate($img, $hscolor[0], $hscolor[1], $hscolor[2]); } else { $color = imagecolorallocate($img, '255', '209', '57'); } } else { //more then one kill... $ratio = $kills + 5; // ...then we add a bit to the ratio if (config::get('map_act_cl_hl2')) { // Set the color to Highlight 2 and the sphere color with alpha $hscolor = explode(",", config::get('map_act_cl_hl2')); $color = imagecolorallocate($img, $hscolor[0], $hscolor[1], $hscolor[2]); $color4 = imagecolorresolvealpha($img, $hscolor[0], $hscolor[1], $hscolor[2], '117'); } else { $color = imagecolorallocate($img, '255', '0', '0'); $color4 = imagecolorresolvealpha($img, 255, 0, 0, 117); } } if ($ratio > 100) { //now we limit the max-size of the sphere so it doesnt grow to big $ratio = 100; } imagefilledellipse($img, $px, $py, $ratio, $ratio, $color4); //paint the sphere -- can not use AA function cause it doesnt work with alpha imagefilledellipseaa($img, $px, $py, 6, 6, $color); // use AA function to paint the system dot if ($ratio > 10) { // extend the sphere $ratio2 = $ratio - 10; imagefilledellipse($img, $px, $py, $ratio2, $ratio2, $color4); } if ($ratio > 20) { // add another inner layer to the sphere, if it gets big enough $ratio3 = $ratio - 20; imagefilledellipse($img, $px, $py, $ratio3, $ratio3, $color4); } if ($paint_name == 1) { $tlen = 5 * strlen($sys[5]); if ($px + $tlen > $this->imgwidth_ - 20) { $sx = $px - $tlen; } else { $sx = $px + 5; } if ($py + 5 > $this->imgheight_ - 20) { $sy = $py - 5; } else { $sy = $py + 5; } imagestring($img, 1, $sx, $sy, $sys[5], $color); } } } //--------------------------------------------------------------------------------------- // Ship / Faction starts here //--------------------------------------------------------------------------------------- if ($this->mode_ == "ship" || $this->mode_ == "faction") { $kills = 0; //INIT $overall_kill = 0; $color = imagecolorallocate($img, $this->normalcolor_[0], $this->normalcolor_[1], $this->normalcolor_[2]); $paint_name = config::get('map_act_shownames'); $sql2 = 'select sys.sys_x, sys.sys_y, sys.sys_z, sys.sys_sec, sys.sys_id, sys.sys_name, sys.sys_id, con.con_id, con.con_name, reg.reg_id, reg.reg_name, reg.reg_x, reg.reg_z from kb3_systems sys, kb3_constellations con, kb3_regions reg where con.con_id = sys.sys_con_id and reg.reg_id = con.con_reg_id'; $sql2 .= " and reg.reg_id = " . $this->regionid2_; $xml_kills = $this->update_kill_cache(); $qry2 = new DBQuery(); $qry2->execute($sql2) or die($qry2->getErrorMsg()); while ($row2 = $qry2->getRow()) { $paint = 0; foreach ($xml_kills as $key => $value) { if ($row2['sys_id'] == $key) { $kills = $value; $paint = 1; } } if ($paint == 1) { $overall_kill = $overall_kill + $kills; //OFFSET CALCULATION $x = $row2['sys_x'] * $this->ly_; $z = $row2['sys_z'] * $this->ly_; $sys[0] = $x; $sys[1] = $z; $sys[4] = $row2['sys_id']; $sys[5] = $row2['sys_name']; $sys[6] = $row2['sys_sec']; $fp = fopen($regioncache . ".txt", "r"); // getting offset data from file $maxx = fgets($fp); $minx = fgets($fp); $maxz = fgets($fp); $minz = fgets($fp); fclose($fp); $dx = abs($maxx - $minx); $dz = abs($maxz - $minz); $xscale = 1 / ($dx / ($this->imgwidth_ - $this->offset_ * 2)); $yscale = 1 / ($dz / ($this->imgheight_ - $this->offset_ * 2)); $px = round($this->offset_ + ($sys[0] - $minx) * $xscale); $py = round($this->offset_ + ($sys[1] - $minz) * $yscale); if ($kills == 1) { // If there is only one kill we use normal highlight color $ratio = 1; if (config::get('map_act_cl_hl')) { $hscolor = explode(",", config::get('map_act_cl_hl')); $color = imagecolorallocate($img, $hscolor[0], $hscolor[1], $hscolor[2]); } else { $color = imagecolorallocate($img, '255', '209', '57'); } } else { //more then one kill... $ratio = $kills + 5; // ...then we add a bit to the ratio if (config::get('map_act_cl_hl2')) { // Set the color to Highlight 2 and the sphere color with alpha $hscolor = explode(",", config::get('map_act_cl_hl2')); $color = imagecolorallocate($img, $hscolor[0], $hscolor[1], $hscolor[2]); $color4 = imagecolorresolvealpha($img, $hscolor[0], $hscolor[1], $hscolor[2], '117'); } else { $color = imagecolorallocate($img, '255', '0', '0'); $color4 = imagecolorresolvealpha($img, 255, 0, 0, 117); } } if ($ratio > 100) { //now we limit the max-size of the sphere so it doesnt grow to big $ratio = 100; } imagefilledellipse($img, $px, $py, $ratio, $ratio, $color4); //paint the sphere -- can not use AA function cause it doesnt work with alpha imagefilledellipseaa($img, $px, $py, 6, 6, $color); // use AA function to paint the system dot if ($ratio > 10) { // extend the sphere $ratio2 = $ratio - 10; imagefilledellipse($img, $px, $py, $ratio2, $ratio2, $color4); } if ($ratio > 20) { // add another inner layer to the sphere, if it gets big enough $ratio3 = $ratio - 20; imagefilledellipse($img, $px, $py, $ratio3, $ratio3, $color4); } if ($paint_name == 1) { $tlen = 5 * strlen($sys[5]); if ($px + $tlen > $this->imgwidth_ - 20) { $sx = $px - $tlen; } else { $sx = $px + 5; } if ($py + 5 > $this->imgheight_ - 20) { $sy = $py - 5; } else { $sy = $py + 5; } imagestring($img, 1, $sx, $sy, $sys[5] . '(' . $kills . ')', $color); } } } } //--------------------------------------------------------------------------------------- // Activity end here //--------------------------------------------------------------------------------------- // Draw the region name and total kill count. if (config::get('map_act_cl_capt')) { $scolor = explode(",", config::get('map_act_cl_capt')); mapview::setcaptcolor($scolor[0], $scolor[1], $scolor[2]); } $captioncolor = imagecolorallocate($img, $this->captioncolor_[0], $this->captioncolor_[1], $this->captioncolor_[2]); switch ($this->mode_) { case "ship": case "faction": $title_kill = "Total Kills in the last hour: " . $overall_kill; break; case "activity": if (isset($this->week_)) { $title_kill = "Total Kills in Week " . $this->week_ . ": " . $overall_kill; } if (isset($this->month_)) { $title_kill = "Total Kills in " . date('F', mktime(0, 1, 0, $this->month_, 1, $this->year_)) . ": " . $overall_kill; } break; default: $title_kill = ''; break; } $str_loc = $this->imgheight_ - 10; imagestring($img, 1, 2, $str_loc, $title_kill, $captioncolor); imagestring($img, 1, 2, 2, $title_caption, $captioncolor); if ($this->mode_ == 'ship' || $this->mode_ == 'faction') { clearstatcache(); $filetime = filemtime($this->killcache); $stringpos = $this->imgwidth_ - strlen("Data from: " . date("G:i Y-m-d", $filetime)) * 5 - 5; imagestring($img, 1, $stringpos, 2, "Data from: " . date("G:i Y-m-d", $filetime), $captioncolor); } header("Content-type: image/png"); imagepng($img); }