/** * render the the special Random Thumbnail Map (in its many variations) * @access private */ function _renderRandomGeographMap() { $root =& $_SERVER['DOCUMENT_ROOT']; //first of all, generate or pull in a cached based map $basemap = $this->getBaseMapFilename(); if ($this->caching && @file_exists($root . $basemap)) { //load it up! $img = imagecreatefromgd($root . $basemap); } else { //we need to generate a basemap $img =& $this->_createBasemap($root . $basemap); } $target = $this->getImageFilename(); $colMarker = imagecolorallocate($img, 255, 0, 0); $colBorder = imagecolorallocate($img, 255, 255, 255); //figure out what we're mapping in internal coords $db =& $this->_getDB(); $dbImg = NewADOConnection($GLOBALS['DSN']); $left = $this->map_x; $bottom = $this->map_y; $right = $left + floor($this->image_w / $this->pixels_per_km) - 1; $top = $bottom + floor($this->image_h / $this->pixels_per_km) - 1; //size of a marker in pixels $markerpixels = 5; //size of marker in km $markerkm = ceil($markerpixels / $this->pixels_per_km); //we scan for images a little over the edges so that if //an image lies on a mosaic edge, we still plot the point //on both mosaics $overscan = $markerkm; $scanleft = $left - $overscan; $scanright = $right + $overscan; $scanbottom = $bottom - $overscan; $scantop = $top + $overscan; //plot grid square? if ($this->pixels_per_km >= 0) { $this->_plotGridLines($img, $scanleft, $scanbottom, $scanright, $scantop, $bottom, $left); } $imagemap = fopen($root . $target . ".html", "w"); fwrite($imagemap, "<map name=\"imagemap\">\n"); $rectangle = "'POLYGON(({$scanleft} {$scanbottom},{$scanright} {$scanbottom},{$scanright} {$scantop},{$scanleft} {$scantop},{$scanleft} {$scanbottom}))'"; if ($this->type_or_user < -2000) { if ($this->type_or_user < -2007) { $sql = "select x,y,gi.gridimage_id from gridimage_search gi\n\t\t\twhere \n\t\t\tCONTAINS( GeomFromText({$rectangle}),\tpoint_xy) and imagetaken = '" . $this->type_or_user * -1 . "-12-25'\n\t\t\tand( gi.imageclass LIKE '%christmas%') \n\t\t\torder by rand()"; } else { $sql = "select x,y,gi.gridimage_id from gridimage_search gi\n\t\t\twhere \n\t\t\tCONTAINS( GeomFromText({$rectangle}),\tpoint_xy) and imagetaken = '" . $this->type_or_user * -1 . "-12-25'\n\t\t\t order by ( (gi.title LIKE '%xmas%' OR gi.comment LIKE '%xmas%' OR gi.imageclass LIKE '%xmas%') OR (gi.title LIKE '%christmas%' OR gi.comment LIKE '%christmas%' OR gi.imageclass LIKE '%christmas%') ), rand()"; } } elseif (1) { $sql = "select x,y,gi.gridimage_id from gridimage_search gi\n\t\t\twhere \n\t\t\tCONTAINS( GeomFromText({$rectangle}),\tpoint_xy)\n\t\t\tand seq_no = 1 group by FLOOR(x/10),FLOOR(y/10) order by rand() limit 600"; #inner join gridimage_post gp on (gi.gridimage_id = gp.gridimage_id and gp.topic_id = 1006) } elseif (1) { $sql = "select x,y,gi.gridimage_id from gridimage_search gi\n\t\t\twhere gridimage_id in (80343,74737,74092,84274,80195,48940,46618,73778,47029,82007,39195,76043,57771,28998,18548,12818,7932,81438,16764,84846,73951,79510,15544,73752,86199,4437,87278,53119,29003,36991,74330,29732,16946,10613,87284,52195,41935,26237,30008,10252,62365,83753,67060,34453,20760,26759,59465,118,12449,4455,46898,12805,87014,401,36956,8098,44193,63206,42732,26145,86473,17469,3323,26989,3324,40212,63829,30948,165,41865,36605,25736,68318,26849,51771,30986,27174,37470,31098,65191,44406,82224,71627,22968,59008,35468,7507,53228,80854,10669,47604,75018,42649,9271,1658,11741,60793,78903,22198,7586,88164,12818,14981,21794,74790,3386,40974,72850,77652,47982,39894,38897,25041,81392,63186,81974,41373,86365,44388,80376,13506,42984,45159,14837,71377,35108,84318,84422,36640,2179,22317,5324,32506,20690,71588,85859,50813,19358,84848,18141,78772,21074,13903,39376,45795,88385,55327,907,37266,82510,78594,17708,84855,7175,85453,23513,18493,68120,26201,18508,32531,84327,88204,55537,41942,47117,22922,22315,46412,88542,46241,67475,63752,63511,98) order by rand()"; } else { $sql = "select x,y,grid_reference from gridsquare where \n\t\t\tCONTAINS( GeomFromText({$rectangle}),\tpoint_xy)\n\t\t\tand imagecount>0 group by FLOOR(x/30),FLOOR(y/30) order by rand() limit 500"; } $usercount = array(); $recordSet =& $db->Execute($sql); $lines = array(); while (!$recordSet->EOF) { $gridx = $recordSet->fields[0]; $gridy = $recordSet->fields[1]; $imgx1 = ($gridx - $left) * $this->pixels_per_km; $imgy1 = $this->image_h - ($gridy - $bottom + 1) * $this->pixels_per_km; $photopixels = 40; $imgx1 = round($imgx1) - 0.5 * $photopixels; $imgy1 = round($imgy1) - 0.5 * $photopixels; $imgx2 = $imgx1 + $photopixels; $imgy2 = $imgy1 + $photopixels; $gridimage_id = $recordSet->fields[2]; $sql = "select * from gridimage_search where gridimage_id='{$gridimage_id}' and moderation_status<>'rejected' limit 1"; //echo "$sql\n"; $rec = $dbImg->GetRow($sql); if (count($rec)) { $gridimage = new GridImage(); $gridimage->fastInit($rec); $photo = $gridimage->getSquareThumb($photopixels); if (!is_null($photo)) { imagecopy($img, $photo, $imgx1, $imgy1, 0, 0, $photopixels, $photopixels); imagedestroy($photo); imagerectangle($img, $imgx1, $imgy1, $imgx2, $imgy2, $colBorder); $lines[] = "<area shape=\"rect\" coords=\"{$imgx1},{$imgy1},{$imgx2},{$imgy2}\" href=\"/photo/{$rec['gridimage_id']}\" title=\"" . htmlentities("{$rec['grid_reference']} : {$rec['title']} by {$rec['realname']}") . "\">"; } $usercount[$rec['realname']]++; } $recordSet->MoveNext(); } $recordSet->Close(); fwrite($imagemap, implode("\n", array_reverse($lines))); fwrite($imagemap, "</map>\n"); fclose($imagemap); $h = fopen("imagemap.csv", 'w'); foreach ($usercount as $user => $uses) { fwrite($h, "{$user},{$uses}\n"); } fclose($h); if (preg_match('/jpg/', $target)) { imagejpeg($img, $root . $target); } else { imagepng($img, $root . $target); } imagedestroy($img); }