Ejemplo n.º 1
0
$html = '';
$kml = new kmlFile();
$kml->atom = true;
$stylefile = "http://{$CONF['KML_HOST']}/kml/style.kmz";
$folder = $kml->addChild('Document');
$folder->setItem('name', "{$gr} :: Geograph SuperLayer");
$sql_where = "gridsquare_id={$square->gridsquare_id}" . $sql_where;
$photos = $db->GetAll($sql = "select \r\n\tgridimage_id,title,title2,gi.realname as credit_realname,if(gi.realname!='',gi.realname,user.realname) as realname,user.user_id,comment,nateastings,natnorthings,natgrlen,view_direction\r\n\tfrom gridimage gi\r\n\t\t inner join user using(user_id)\r\n\twhere {$sql_where}\r\n\torder by null");
foreach ($photos as $id => $entry) {
    $title = combineTexts($entry['title'], $entry['title2']);
    if ($entry['nateastings']) {
        if ($entry['natgrlen'] == 6) {
            $entry['nateastings'] += 50;
            $entry['natnorthings'] += 50;
        }
        list($wgs84_lat, $wgs84_long) = $conv->national_to_wgs84($entry['nateastings'], $entry['natnorthings'], $square->reference_index);
    } else {
        list($wgs84_lat, $wgs84_long) = $conv->internal_to_wgs84($square->x, $square->y, $square->reference_index);
    }
    $point = new kmlPoint($wgs84_lat, $wgs84_long);
    $placemark = new kmlPlacemark_Photo($entry['gridimage_id'], $square->grid_reference . ' :: ' . $title, $point);
    $placemark->useHoverStyle();
    $image = new GridImage();
    $image->fastInit($entry);
    $placemark->useCredit($image->realname, "http://{$_SERVER['HTTP_HOST']}/photo/" . $image->gridimage_id);
    $html .= getHtmlLinkP($placemark->link, $square->grid_reference . ' :: ' . $title . ' by ' . $image->realname);
    $linkTag = "<a href=\"" . $placemark->link . "\">";
    $details = $image->getThumbnail(120, 120, 2);
    $thumb = $details['server'] . $details['url'];
    $thumbTag = $details['html'];
    $description = $linkTag . $thumbTag . "</a><br/>" . GeographLinks($image->comment) . " (" . $linkTag . "view full size</a>)" . "<br/><br/> &copy; Copyright <a title=\"view user profile\" href=\"http://" . $_SERVER['HTTP_HOST'] . $image->profile_link . "\">" . $image->realname . "</a> and licensed for reuse under this <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-sa/2.0/\">Creative Commons Licence</a><br/><br/>";
 public function setSpatial($data)
 {
     require_once 'geograph/conversions.class.php';
     $conv = new Conversions();
     list($e, $n, $reference_index) = $conv->internal_to_national($data['x'], $data['y'], 0);
     $e = floor($e / 1000);
     $n = floor($n / 1000);
     $grs = array();
     list($gr2, $len) = $conv->national_to_gridref($e * 1000, $n * 1000, 4, $reference_index, false);
     if ($data['d'] == 1) {
         $this->filters['grid_reference'] = $gr2;
     } elseif ($data['d'] < 10) {
         #$grs[] = $gr2;
         for ($x = $e - $data['d']; $x <= $e + $data['d']; $x++) {
             for ($y = $n - $data['d']; $y <= $n + $data['d']; $y++) {
                 list($gr2, $len) = $conv->national_to_gridref($x * 1000, $y * 1000, 4, $reference_index, false);
                 $grs[] = $gr2;
             }
         }
         $this->filters['grid_reference'] = "(" . join(" | ", $grs) . ")";
     } else {
         #$this->filters['grid_reference'] = $gr2;
         $d = intval($data['d'] / 10) * 10;
         for ($x = $e - $d; $x <= $e + $d; $x += 10) {
             for ($y = $n - $d; $y <= $n + $d; $y += 10) {
                 list($gr2, $len) = $conv->national_to_gridref($x * 1000, $y * 1000, 2, $reference_index, false);
                 $grs[] = $gr2;
             }
         }
         $this->filters['hectad'] = "(" . join(" | ", $grs) . ")";
     }
     if ($data['d'] > 1) {
         list($lat, $long) = $conv->national_to_wgs84($e * 1000 + 500, $n * 1000 + 500, $reference_index);
         $cl = $this->_getClient();
         $cl->SetGeoAnchor('wgs84_lat', 'wgs84_long', deg2rad($lat), deg2rad($long));
         $cl->SetFilterFloatRange('@geodist', 0.0, floatval($data['d'] * 1000));
     } else {
         $this->sort = preg_replace('/@geodist \\w+,?\\s*/', '', $this->sort);
     }
 }
Ejemplo n.º 3
0
            $filename = preg_replace('/[^\\w-\\.,]+/', '', $filename);
            $lastmod = filemtime($_SERVER['DOCUMENT_ROOT'] . $filepath);
            header("Content-Type: image/jpeg");
            header("Content-Disposition: attachment; filename=\"{$filename}\"");
            customExpiresHeader(86400, true);
            customCacheControl($lastmod, $image->gridimage_id);
            readfile($_SERVER['DOCUMENT_ROOT'] . $filepath);
            exit;
        }
        $smarty->assign_by_ref('msg', $msg);
        require_once 'geograph/conversions.class.php';
        $conv = new Conversions();
        list($lat, $long) = $conv->gridsquare_to_wgs84($image->grid_square);
        $smarty->assign('lat', $lat);
        $smarty->assign('long', $long);
        list($latdm, $longdm) = $conv->wgs84_to_friendly($lat, $long);
        $smarty->assign('latdm', $latdm);
        $smarty->assign('longdm', $longdm);
        if (!empty($image->viewpoint_northings)) {
            list($lat, $long) = $conv->national_to_wgs84($image->viewpoint_eastings, $image->viewpoint_northings, $image->grid_square->reference_index);
            $smarty->assign('photographer_lat', $lat);
            $smarty->assign('photographer_long', $long);
        }
    }
    $smarty->assign_by_ref('image', $image);
} else {
    header("HTTP/1.0 404 Not Found");
    header("Status: 404 Not Found");
    $template = "static_404.tpl";
}
$smarty->display($template);
        $db->Execute("INSERT INTO gridimage_search\n\t\t\tSELECT gridimage_id, gi.user_id, moderation_status, title, title2, submitted, imageclass, imagetaken, upd_timestamp, x, y, gs.grid_reference, gi.realname!='' as credit_realname,if(gi.realname!='',gi.realname,user.realname) as realname,reference_index,comment,comment2,0,0,ftf,seq_no,point_xy,GeomFromText('POINT(0 0)')\n\t\t\tFROM gridimage AS gi\n\t\t\tINNER JOIN gridsquare AS gs\n\t\t\tUSING ( gridsquare_id )\n\t\t\tINNER JOIN user ON ( gi.user_id = user.user_id )\n\t\t\tWHERE moderation_status in ('accepted','geograph') ");
    }
    echo "<h3>Rebuild completed</h3>";
    if (!isset($_POST['update'])) {
        print "<h3>It is now recommended to update the Lat/Long</h3>";
    }
}
if (!empty($_POST['update'])) {
    echo "<h3>Updating Lat/Long</h3>";
    flush();
    $start = time();
    $recordSet =& $db->Execute("select gridimage_id,x,y,reference_index,nateastings,natnorthings\n\t\tfrom gridimage\n\t\tINNER JOIN gridsquare AS gs USING ( gridsquare_id )\n\t\twhere moderation_status in ('accepted','geograph')");
    $count = 0;
    while (!$recordSet->EOF) {
        $image = $recordSet->fields;
        if ($image['nateastings']) {
            list($lat, $long) = $conv->national_to_wgs84($image['nateastings'], $image['natnorthings'], $image['reference_index']);
        } else {
            list($lat, $long) = $conv->internal_to_wgs84($image['x'], $image['y'], $image['reference_index']);
        }
        $db2->Execute("UPDATE LOW_PRIORITY gridimage_search SET wgs84_lat = {$lat}, wgs84_long = {$long},point_ll = GeomFromText('POINT({$long} {$lat})') WHERE gridimage_id = " . $image['gridimage_id']);
        if (++$count % 500 == 0) {
            printf("done %d at <b>%d</b> seconds<br/>", $count, time() - $start);
            flush();
        }
        $recordSet->MoveNext();
    }
    echo "<p>Lat/Long update complete</p>";
}
$smarty->display('_std_end.tpl');
exit;
Ejemplo n.º 5
0
$stylefile = "http://{$CONF['KML_HOST']}/kml/style.kmz";
$folder = $kml->addChild('Document');
$folder->setItem('name', "{$gr} :: Geograph SuperLayer");
if ($square->imagecount > 20) {
    $sql_where = "gridsquare_id={$square->gridsquare_id}";
    $ri = $square->reference_index;
    $links = new kmlPrimative('Folder');
    $links->setItem('name', 'Next Level...');
    $most = $db->GetAll("select \r\n\tgridimage_id,nateastings,natnorthings,count(*) as c\r\n\tfrom gridimage \r\n\twhere {$sql_where}\r\n\tgroup by nateastings div 100,natnorthings div 100 \r\n\torder by null");
    foreach ($most as $id => $entry) {
        if ($entry['nateastings']) {
            $e = ($e2 = intval($entry['nateastings'] / 100)) * 100;
            $n = ($n2 = intval($entry['natnorthings'] / 100)) * 100;
            $e2 = $e2 % 10;
            $n2 = $n2 % 10;
            list($wgs84_lat, $wgs84_long) = $conv->national_to_wgs84($e + 50, $n + 50, $ri);
            $entry['hunk_square'] = $square->gridsquare . $square->eastings . $e2 . $square->northings . $n2;
            $name = "{$entry['hunk_square']} :: {$entry['c']} images";
        } else {
            //should be only one of these!
            $e = $square->getNatEastings();
            $n = $square->getNatNorthings();
            list($wgs84_lat, $wgs84_long) = $conv->national_to_wgs84($e, $n, $ri);
            $entry['hunk_square'] = $square->gridsquare . $square->eastings . '_' . $square->northings . '_';
            $name = "{$square->grid_reference} :: {$entry['c']} images";
        }
        $c = $entry['c'] > 20 ? 20 : ($entry['c'] > 4 ? 10 : $entry['c']);
        $point = new kmlPoint($wgs84_lat, $wgs84_long);
        $placemark = new kmlPlacemark($entry['hunk_square'], $name, $point);
        $placemark->useHoverStyle('p' . $c);
        $folder->addChild($placemark);
Ejemplo n.º 6
0
     $details = $image->getThumbnail(120, 120, 2);
     $thumb = $details['server'] . $details['url'];
     $thumbTag = $details['html'];
     $description = $linkTag . $thumbTag . "</a><br/>" . GeographLinks($image->comment) . " (" . $linkTag . "view full size</a>)" . "<br/><br/> &copy; Copyright <a title=\"view user profile\" href=\"http://" . $_SERVER['HTTP_HOST'] . $image->profile_link . "\">" . $image->realname . "</a> and licensed for reuse under this <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-sa/2.0/\">Creative Commons Licence</a><br/><br/>";
     $placemark->setItemCDATA('description', $description);
     //yes that is uppercase S!
     $placemark->setItemCDATA('Snippet', strip_tags($description));
     $placemark->setItem('visibility', 1);
     $placemark->useImageAsIcon($thumb);
     if (!empty($image->imagetaken) && strpos($image->imagetaken, '-00') === FALSE) {
         $placemark->setTimeStamp(str_replace('-00', '', $image->imagetaken));
     }
     $different_square_true = intval($image->nateastings / 1000) != intval($image->viewpoint_eastings / 1000) || intval($image->natnorthings / 1000) != intval($image->viewpoint_northings / 1000);
     $show_viewpoint = intval($image->viewpoint_grlen) > 4 || $different_square_true && $image->viewpoint_grlen == '4';
     if ($image->viewpoint_eastings && $show_viewpoint) {
         list($line['eLat'], $line['eLong']) = $conv->national_to_wgs84($image->viewpoint_eastings, $image->viewpoint_northings, $image->grid_square->reference_index);
         $point2 = new kmlPoint($line['eLat'], $line['eLong']);
         if ($version42plus) {
             $placemark->addPhotographerPhoto($point2, $image->view_direction, $image->realname, $image->_getFullpath(true, true));
         } else {
             $placemark->addPhotographerPoint($point2, $image->view_direction, $image->realname);
         }
     } elseif (isset($image->view_direction) && strlen($image->view_direction) && $image->view_direction != -1) {
         $placemark->addViewDirection($image->view_direction);
     }
     $kml->outputKML();
 } else {
     header("HTTP/1.0 404 Not Found");
     header("Status: 404 Not Found");
 }
 exit;
Ejemplo n.º 7
0
        $rastermap = new RasterMap($square, false, $square->natspecified);
        $rastermap->service = 'Google';
        $rastermap->addLatLong($lat, $long);
        $smarty->assign_by_ref('rastermap', $rastermap);
        $blocks = array();
        $db = NewADOConnection($GLOBALS['DSN']);
        if (!$db) {
            die('Database connection failed');
        }
        $rows = $db->cacheGetAll(3600, "SELECT \r\n\t\tnateastings,natnorthings,viewpoint_eastings,viewpoint_northings,count(*) as c\r\n\t\tfrom gridimage\r\n\t\twhere gridsquare_id = {$square->gridsquare_id} and moderation_status in ('geograph','accepted') \r\n\t\t\tand nateastings > 0 and viewpoint_eastings > 0 and viewpoint_grlen != '4'\r\n\t\tgroup by nateastings DIV 100,natnorthings DIV 100,viewpoint_eastings DIV 100, viewpoint_northings DIV 100");
        function quant($i)
        {
            return floor($i / 100) * 100 + 50;
        }
        foreach ($rows as $row) {
            list($lat1, $long1) = $conv->national_to_wgs84(quant($row['nateastings']), quant($row['natnorthings']), $square->reference_index);
            list($lat2, $long2) = $conv->national_to_wgs84(quant($row['viewpoint_eastings']), quant($row['viewpoint_northings']), $square->reference_index);
            $blocks[] = "var ppoint = new GLatLng({$lat2},{$long2});";
            $blocks[] = "bounds.extend(ppoint);";
            $blocks[] = "map.addOverlay(new GPolygon([new GLatLng({$lat1},{$long1}),ppoint], \"#FF0000\", 1, 0.7, \"#00FF00\", 0.5));\n";
            $blocks[] = "\r\n\t\t\tvar iconOptions = {};\r\n\t\t\ticonOptions.width = 16;\r\n\t\t\ticonOptions.height = 16;\r\n\t\t\ticonOptions.primaryColor = \"#FF0000\";\r\n\t\t\ticonOptions.label = \"{$row['c']}\";\r\n\t\t\ticonOptions.labelSize = 0;\r\n\t\t\ticonOptions.labelColor = \"#000000\";\r\n\t\t\ticonOptions.shape = \"circle\";\r\n\t\t\tvar icon = MapIconMaker.createFlatIcon(iconOptions);";
            $blocks[] = "map.addOverlay(new GMarker(ppoint, icon));\n";
            $blocks[] = "\r\n\t\t\tvar iconOptions = {};\r\n\t\t\ticonOptions.width = 10;\r\n\t\t\ticonOptions.height = 10;\r\n\t\t\ticonOptions.primaryColor = \"#FF0000\";\r\n\t\t\ticonOptions.label = \"\";\r\n\t\t\ticonOptions.labelSize = 0;\r\n\t\t\ticonOptions.labelColor = \"#000000\";\r\n\t\t\ticonOptions.shape = \"roundrect\";\r\n\t\t\tvar icon = MapIconMaker.createFlatIcon(iconOptions);";
            $blocks[] = "map.addOverlay(new GMarker(new GLatLng({$lat1},{$long1}), icon));\n";
        }
        $smarty->assign('groups', count($rows));
        $smarty->assign_by_ref('blocks', $blocks);
    } else {
        $smarty->assign('errormsg', $square->errormsg);
    }
} else {
Ejemplo n.º 8
0
 /**
  *
  */
 function setByFullGridRef($gridreference, $setnatfor4fig = false, $allowzeropercent = false, $recalc = false)
 {
     global $CONF, $MESSAGES;
     $matches = array();
     $isfour = false;
     if (preg_match("/\\b([a-zA-Z]{1,3}) ?(\\d{1,5})[ \\.](\\d{1,5})\\b/", $gridreference, $matches) and strlen($matches[2]) == strlen($matches[3])) {
         list($prefix, $e, $n) = array($matches[1], $matches[2], $matches[3]);
         $length = strlen($matches[2]);
         $natgrlen = $length * 2;
     } elseif (preg_match("/\\b([a-zA-Z]{1,3}) ?(\\d{0,10})\\b/", $gridreference, $matches) and strlen($matches[2]) % 2 == 0) {
         $natgrlen = strlen($matches[2]);
         $length = $natgrlen / 2;
         list($prefix, $e, $n) = array($matches[1], substr($matches[2], 0, $length), substr($matches[2], -$length));
     }
     if (!empty($prefix)) {
         $gridref = sprintf("%s%02d%02d", strtoupper($prefix), intval($e / 1000), intval($n / 1000));
         $ok = false;
         if ($recalc) {
             $db =& $this->_getDB();
             $prefix = strtoupper($prefix);
             $sql = "select * from gridprefix where prefix='{$prefix}' limit 1";
             $row = $db->GetRow($sql);
             if (count($row)) {
                 require_once 'geograph/conversions.class.php';
                 $conv = new Conversions();
                 $ri = $row['reference_index'];
                 $fe = intval($e) + ($row['origin_x'] - $CONF['origins'][$ri][0]) * 1000;
                 $fn = intval($n) + ($row['origin_y'] - $CONF['origins'][$ri][1]) * 1000;
                 $latlong = $conv->national_to_wgs84($fe, $fn, $ri);
                 if (count($latlong)) {
                     $enr = $conv->wgs84_to_national($latlong[0], $latlong[1]);
                     if (count($enr)) {
                         $ri2 = $enr[2];
                         $fe2 = $enr[0];
                         $fn2 = $enr[1];
                         if ($ri2 != $ri) {
                             // we got a new ri
                             if ($length == 1) {
                                 $shift = 5000;
                             } elseif ($length == 0) {
                                 $shift = 50000;
                             } else {
                                 $shift = 0;
                             }
                             $e2 = round($enr[0], $length - 5) + $shift;
                             $n2 = round($enr[1], $length - 5) + $shift;
                             $x = floor($e2 / 1000) + $CONF['origins'][$ri2][0];
                             $y = floor($n2 / 1000) + $CONF['origins'][$ri2][1];
                             $ok = $this->loadFromPosition($x, $y);
                             if ($ok) {
                                 $prefix = $this->gridsquare;
                                 $e = sprintf("%05d", $e2 % 100000);
                                 $n = sprintf("%05d", $n2 % 100000);
                                 $gridref = $this->grid_reference;
                             }
                         }
                     }
                 }
             }
         }
         if (!$ok) {
             $ok = $this->_setGridRef($gridref, $allowzeropercent);
         }
         if ($ok && (!$isfour || $setnatfor4fig)) {
             //we could be reassigning the square!
             unset($this->nateastings);
             //use this function to work out the major easting/northing then convert to our exact values
             $eastings = $this->getNatEastings();
             $northings = $this->getNatNorthings();
             $emajor = floor($eastings / 100000);
             $nmajor = floor($northings / 100000);
             $this->nateastings = $emajor . sprintf("%05d", $e);
             $this->natnorthings = $nmajor . sprintf("%05d", $n);
             $this->natgrlen = $natgrlen;
             $this->precision = pow(10, 6 - $natgrlen / 2) / 10;
         } else {
             $this->precision = 1000;
         }
     } else {
         $ok = false;
         $this->_error(sprintf($MESSAGES['class_gridsquare']['gridref_invalid'], htmlentities($gridreference)));
     }
     return $ok;
 }
Ejemplo n.º 9
0
 /**
  * Saves update tables based on gridimage
  */
 function updateCachedTables()
 {
     $db =& $this->_getDB();
     //quick sanity check
     if (!$this->gridimage_id) {
         die("no gridimage_id supplied to updateCachedTables");
     }
     if ($this->moderation_status == 'rejected' || $this->moderation_status == 'pending') {
         $sql = "DELETE FROM gridimage_search WHERE gridimage_id = '{$this->gridimage_id}'";
         $db->Execute($sql);
         $db->Execute("DELETE FROM wordnet1 WHERE gid = {$this->gridimage_id}");
         $db->Execute("DELETE FROM wordnet2 WHERE gid = {$this->gridimage_id}");
         $db->Execute("DELETE FROM wordnet3 WHERE gid = {$this->gridimage_id}");
     } elseif ($this->moderation_status) {
         require_once 'geograph/conversions.class.php';
         $conv = new Conversions();
         if (isset($this->newsq)) {
             $square = $this->newsq;
         } else {
             $square = $this->grid_square;
         }
         if (!$square) {
             die("ERROR: no square known in updateCachedTables");
         }
         if ($square->nateastings) {
             list($lat, $long) = $conv->national_to_wgs84($square->nateastings, $square->natnorthings, $square->reference_index);
         } else {
             list($lat, $long) = $conv->internal_to_wgs84($square->x, $square->y, $square->reference_index);
         }
         $sql = "REPLACE INTO gridimage_search\n\t\t\tSELECT gridimage_id,gi.user_id,moderation_status,title,title2,submitted,imageclass,imagetaken,upd_timestamp,x,y,gs.grid_reference,gi.realname!='' as credit_realname,if(gi.realname!='',gi.realname,user.realname) as realname,gs.reference_index,comment,comment2,{$lat},{$long},ftf,seq_no,point_xy,GeomFromText('POINT({$long} {$lat})')\n\t\t\tFROM gridimage AS gi INNER JOIN gridsquare AS gs USING(gridsquare_id)\n\t\t\tINNER JOIN user ON(gi.user_id=user.user_id)\n\t\t\tWHERE gridimage_id = '{$this->gridimage_id}'";
         $db->Execute($sql);
         $row =& $db->GetRow("select recent_id from gridimage_recent where gridimage_id={$this->gridimage_id} limit 1");
         if ($row !== false && count($row)) {
             $recent_id = $row['recent_id'];
             $sql = "REPLACE INTO gridimage_recent\n\t\t\t\tSELECT gridimage_id,gi.user_id,moderation_status,title,title2,submitted,imageclass,imagetaken,upd_timestamp,x,y,gs.grid_reference,gi.realname!='' as credit_realname,if(gi.realname!='',gi.realname,user.realname) as realname,gs.reference_index,comment,comment2,{$lat},{$long},ftf,seq_no,point_xy,GeomFromText('POINT({$long} {$lat})'),{$recent_id}\n\t\t\t\tFROM gridimage AS gi INNER JOIN gridsquare AS gs USING(gridsquare_id)\n\t\t\t\tINNER JOIN user ON(gi.user_id=user.user_id)\n\t\t\t\tWHERE gridimage_id = '{$this->gridimage_id}'";
             $db->Execute($sql);
         }
     } else {
         //fall back if we dont know the moduration status then lets load it and start again!
         $this->loadFromId($this->gridimage_id);
         return $this->updateCachedTables();
     }
 }