function processEvent(&$event)
 {
     //perform actions
     $topic_id = $event['event_param'];
     $db =& $this->_getDB();
     require 'conf/' . $_SERVER['HTTP_HOST'] . '.conf.php';
     $topic = $db->GetRow("select topic_title,forum_id,topic_time from geobb_topics where topic_id='{$topic_id}' and forum_id = {$CONF['forum_gridsquare']}");
     //get title of topic
     $title = strtoupper(trim($topic['topic_title']));
     //see if title matches a grid reference
     $gridsquare = new GridSquare();
     if ($gridsquare->setGridRef($title)) {
         $gridsquare_id = $gridsquare->gridsquare_id;
         //set up mapping
         if ($gridsquare_id > 0) {
             $this->processor->trace("Mapping {$gridsquare_id} to topic {$topic_id} ({$title})");
             $db->Execute("replace into gridsquare_topic(gridsquare_id,topic_id,forum_id,last_post) " . "values ({$gridsquare_id}, {$topic_id}, {$topic['forum_id']}, '{$topic['topic_time']}')");
             //delete any smarty caches for this square
             $images = $db->getCol("select gridimage_id from gridimage where gridsquare_id = {$gridsquare_id}");
             $smarty = new GeographPage();
             foreach ($images as $gridimage_id) {
                 //clear any caches involving this photo
                 $ab = floor($gridimage_id / 10000);
                 $smarty->clear_cache(null, "img{$ab}|{$gridimage_id}");
             }
         }
     }
     //return true to signal completed processing
     //return false to have another attempt later
     return true;
 }
 public function processQuery()
 {
     $q = $this->q;
     if (preg_match('/^([a-zA-Z]{1,3}) +(\\d{1,5})(\\.\\d*|) +(\\d{1,5})(\\.*\\d*|)/', $q, $matches) && $matches[1] != 'tp') {
         $square = new GridSquare();
         $grid_ok = $square->setByFullGridRef($matches[0], true);
         if ($grid_ok) {
             $gr = $square->grid_reference;
             $e = $square->nateastings;
             $n = $square->natnorthings;
             $q = preg_replace("/{$matches[0]}\\s*/", '', $q);
         } else {
             $r = "\t--invalid Grid Ref--";
         }
     } else {
         if (preg_match('/^([a-zA-Z]{1,3})(\\d{2,10})\\b/', $q, $matches) && $matches[1] != 'tp') {
             $square = new GridSquare();
             $grid_ok = $square->setByFullGridRef($matches[0], true);
             if ($grid_ok) {
                 $gr = $square->grid_reference;
                 $e = $square->nateastings;
                 $n = $square->natnorthings;
                 $q = preg_replace("/{$matches[0]}\\s*/", '', $q);
             } else {
                 $r = "\t--invalid Grid Ref--";
             }
         }
     }
     $qo = $q;
     if (strlen($qo) > 64) {
         $qo = '--complex query--';
     }
     if ($r) {
         //Handle Error
     } elseif (!empty($e)) {
         //Location search
         require_once 'geograph/conversions.class.php';
         $conv = new Conversions();
         $e = floor($e / 1000);
         $n = floor($n / 1000);
         $grs = array();
         for ($x = $e - 2; $x <= $e + 2; $x++) {
             for ($y = $n - 2; $y <= $n + 2; $y++) {
                 list($gr2, $len) = $conv->national_to_gridref($x * 1000, $y * 1000, 4, $square->reference_index, false);
                 $grs[] = $gr2;
             }
         }
         if (strpos($q, '~') === 0) {
             $q = preg_replace('/^\\~/', '', $q);
             $q = "(" . str_replace(" ", " | ", $q) . ") (" . join(" | ", $grs) . ")";
         } else {
             $q .= " (" . join(" | ", $grs) . ")";
         }
         $qo .= " near {$gr}";
     }
     $this->q = $q;
     $this->qoutput = $qo;
 }
Esempio n. 3
0
function urlMaker($text, $wrap)
{
    $text = str_replace("\n", " \n ", $text);
    $words = explode(' ', $text);
    require_once 'geograph/gridsquare.class.php';
    $g_square = new GridSquare();
    $prefixes = $g_square->getGridPrefixes();
    for ($i = 0; $i < sizeof($words); $i++) {
        $word = $words[$i];
        //Trim below is necessary is the tag is placed at the begin of string
        $c = 0;
        $host = "http:\\/\\/" . str_replace('.', '\\.', $_SERVER['HTTP_HOST']);
        $words[$i] = preg_replace("/(^|\\[){$host}\\/photo\\/(\\d+)/", '\\1[[\\2]]', $words[$i]);
        $words[$i] = preg_replace("/(^|\\[){$host}\\/view\\.php\\?id=(\\d+)/", '\\1[[\\2]]', $words[$i]);
        $words[$i] = preg_replace("/^{$host}\\/gridref\\/([STNH]?[A-Z]{1}\\d{2,10}|[A-Z]{3}\\d{2,10})/", '[[\\1]]', $words[$i]);
        $words[$i] = preg_replace("/^(\\!?)([STNH]?[A-Z]{1}|[A-Z]{3})(\\d{2,10})([^\\w]?)\$/e", '((!"$1"&&strlen("$3")%2==0&&$prefixes["$2"])?"[[$2$3]]":"$2$3")."$4"', $words[$i]);
        //todo? strip the ! even if wont fire for another reason eg [b]on the !B5467[/b]
        if ($word != $words[$i]) {
        } elseif (strtolower(substr($words[$i], 0, strlen($_SERVER['HTTP_HOST']) + 24)) == 'http://' . $_SERVER['HTTP_HOST'] . '/mapbrowse.php?t=') {
            $c = 1;
            $word = '<a href=\\"' . trim($words[$i]) . '\\" target=\\"_new\\" rel=\\"nofollow\\">Geograph Map</a>';
        } elseif (strtolower(substr($words[$i], 0, 7)) == 'http://') {
            $c = 1;
            $word = '<a href=\\"' . trim($words[$i]) . '\\" target=\\"_new\\" rel=\\"nofollow\\">' . trim($word) . '</a>';
        } elseif (strtolower(substr($words[$i], 0, 8)) == 'https://') {
            $c = 1;
            $word = '<a href=\\"' . trim($words[$i]) . '\\" target=\\"_new\\" rel=\\"nofollow\\">' . trim($word) . '</a>';
        } elseif (strtolower(substr($words[$i], 0, 6)) == 'ftp://') {
            $c = 1;
            $word = '<a href=\\"' . trim($words[$i]) . '\\" target=\\"_new\\" rel=\\"nofollow\\">' . trim($word) . '</a>';
        } elseif (strtolower(substr($words[$i], 0, 4)) == 'ftp.') {
            $c = 1;
            $word = '<a href=\\"ftp://' . trim($words[$i]) . '\\" target=\\"_new\\" rel=\\"nofollow\\">' . trim($word) . '</a>';
        } elseif (strtolower(substr($words[$i], 0, 4)) == 'www.') {
            $c = 1;
            $word = '<a href="http://' . trim($words[$i]) . '\\" target=\\"_new\\" rel=\\"nofollow\\">' . trim($word) . '</a>';
        } elseif (strtolower(substr($words[$i], 0, 7)) == 'mailto:') {
            $c = 1;
            $word = '<a href=\\"' . trim($words[$i]) . '\\" rel=\\"nofollow\\">' . trim($word) . '</a>';
        }
        if ($c == 1) {
            $words[$i] = $word;
        }
        //$words[$i]=str_replace ("\n ", "\n", $words[$i]);
    }
    $ret = str_replace(" \n ", "\n", implode(' ', $words));
    return $ret;
}
Esempio n. 4
0
        $image->imageclass = strip_tags(trim(stripslashes($_POST['imageclassother'])));
    }
    if (isset($_POST['imagetakenYear'])) {
        $image->imagetaken = sprintf("%04d-%02d-%02d", $_POST['imagetakenYear'], $_POST['imagetakenMonth'], $_POST['imagetakenDay']);
    }
    $image->use6fig = !empty($_POST['use6fig']);
    if (!empty($_POST['grid_reference'])) {
        $image->grid_square = new GridSquare();
        $image->grid_square->setByFullGridRef($_POST['grid_reference']);
        $image->grid_reference = $image->grid_square->grid_reference;
        $image->natgrlen = $image->grid_square->natgrlen;
        $image->nateastings = $image->grid_square->nateastings;
        $image->natnorthings = $image->grid_square->natnorthings;
    }
    if (!empty($_POST['photographer_gridref'])) {
        $viewpoint = new GridSquare();
        $ok = $viewpoint->setByFullGridRef($_POST['photographer_gridref'], true);
        $image->viewpoint_eastings = $viewpoint->nateastings;
        $image->viewpoint_northings = $viewpoint->natnorthings;
        $image->viewpoint_grlen = $viewpoint->natgrlen;
    }
    $image->view_direction = intval(strip_tags(trim(stripslashes($_POST['view_direction']))));
    $image->fullpath = "/submit.php?preview=" . strip_tags(trim(stripslashes($_POST['upload_id'])));
    if (!empty($_POST['spelling'])) {
        require_once "3rdparty/spellchecker.class.php";
        ?>
	<style type="text/css">
		body { font-family:Georgia, Verdana, Arial, serif; }
		u { color:red }
		u span { color:black } 
		p { background-color:#eeeeee; border:1px solid gray; padding:10px }
 /**
  * Given index of a mosaic image, and a pixel position on that image handle a zoom
  * If the zoom level is 2, this needs to perform a redirect to the gridsquare page
  * otherwise, it reconfigures the instance for the zoomed in map
  * @access public
  */
 function zoomIn($i, $j, $x, $y)
 {
     //so where did we click?
     list($clickx, $clicky) = $this->getClickCoordinates($i, $j, $x, $y);
     $zoomindex = array_search($this->pixels_per_km, $this->scales);
     if ($zoomindex === FALSE) {
         $zoomindex = 0;
     }
     $zoomindex++;
     if ($zoomindex > count($this->scales) || $this->pixels_per_km > 40) {
         //we're going to zoom into a grid square
         $square = new GridSquare();
         if ($square->loadFromPosition($clickx, $clicky)) {
             $images = $square->getImages(false, '', 'order by moderation_status+0 desc,seq_no limit 2');
             //if the image count is 1, we'll go straight to the image
             if (count($images) == 1) {
                 $url = "http://" . $_SERVER['HTTP_HOST'] . '/photo/' . $images[0]->gridimage_id;
             } else {
                 //lets go to the grid reference
                 $url = "http://" . $_SERVER['HTTP_HOST'] . '/gridref/' . $square->grid_reference;
             }
         } else {
             require_once 'geograph/conversions.class.php';
             $conv = new Conversions();
             list($gr, $len) = $conv->internal_to_gridref($clickx, $clicky, 0);
             $url = "http://" . $_SERVER['HTTP_HOST'] . '/gridref/' . $gr;
         }
         header("Location:{$url}");
         exit;
     } else {
         $scale = $this->scales[$zoomindex];
     }
     //store the clicked position to make a better estimate at the required grid
     $this->old_centrex = $clickx;
     $this->old_centrey = $clicky;
     //size of new map in km
     $mapw = $this->image_w / $scale;
     $maph = $this->image_h / $scale;
     //here's the perfect origin
     $bestoriginx = $clickx - $mapw / 2;
     $bestoriginy = $clicky - $maph / 2;
     $this->setScale($scale);
     $this->setMosaicFactor(2);
     $this->setAlignedOrigin($bestoriginx, $bestoriginy);
 }
Esempio n. 6
0
$smarty->assign('google_maps_api_key', $CONF['google_maps_api_key']);
if (isset($_REQUEST['inner'])) {
    $cacheid = 'iframe';
    $smarty->assign('inner', 1);
} else {
    $cacheid = '';
}
if (isset($_REQUEST['picasa'])) {
    $cacheid .= 'picasa';
    $smarty->assign('picasa', 1);
} elseif (isset($_REQUEST['submit2'])) {
    $cacheid .= 'submit2';
    $smarty->assign('submit2', 1);
}
if (!empty($_REQUEST['grid_reference'])) {
    $square = new GridSquare();
    $ok = $square->setByFullGridRef($_REQUEST['grid_reference']);
    if ($ok) {
        $smarty->assign('grid_reference', $grid_reference = $_REQUEST['grid_reference']);
        $smarty->assign('success', 1);
    } else {
        $smarty->assign('errormsg', $square->errormsg);
    }
}
$smarty->assign('lat0', $CONF['gmcentre'][0]);
$smarty->assign('lon0', $CONF['gmcentre'][1]);
$smarty->assign('latmin', $CONF['gmlatrange'][0][0]);
$smarty->assign('latmax', $CONF['gmlatrange'][0][1]);
$smarty->assign('lonmin', $CONF['gmlonrange'][0][0]);
$smarty->assign('lonmax', $CONF['gmlonrange'][0][1]);
$smarty->display('submitmap.tpl', $cacheid);
 function getSQLParts()
 {
     global $CONF;
     extract($this->sql, EXTR_PREFIX_ALL ^ EXTR_REFS, 'sql');
     if (!empty($_GET['BBOX'])) {
         //we need to turn this off as it will break the caching of number of results!
         $CONF['search_count_first_page'] = 0;
         list($west, $south, $east, $north) = explode(',', trim(str_replace('e ', 'e+', $_GET['BBOX'])));
         if (!empty($_GET['LOOKAT'])) {
             // calculate the approx center of the view -- note that this is innaccurate if the user is not looking straight down
             $clong = ($east - $west) / 2 + $west;
             $clat = ($north - $south) / 2 + $south;
             list($long, $lat) = preg_split('/,|\\s/', str_replace('e ', 'e+', $_GET['LOOKAT']));
             $uplat = ($clat + $north) / 2.0;
             $lolat = ($south + $clat) / 2.0;
             //is the lookat point outside the central square of the BBOX (hence large tilt)
             if ($lat > $uplat) {
                 $diflat = $north - $lat;
             } elseif ($lat < $lolat) {
                 $diflat = $lat - $south;
             }
             $uplong = ($clong + $east) / 2.0;
             $lolong = ($west + $clong) / 2.0;
             if ($long > $uplong) {
                 $diflong = $east - $long;
             } elseif ($long < $lolong) {
                 $diflong = $long - $west;
             }
             //find a suitable 'distance' from an edge
             $dif = abs(max($diflat, $diflong));
             //if we have an off center view create a new square and recenter it 'in the foreground'
             if ($dif) {
                 function interpolate_part($one, $two, $fraction)
                 {
                     $big = $two - $one;
                     $small = $fraction * $big;
                     return $one + $small;
                 }
                 $linelength = sqrt(pow($lat - $clat, 2) + pow($long - $clong, 2));
                 $fraction = $dif / $linelength;
                 //find the point on the line between the lookat and the center point
                 $nlat = interpolate_part($lat, $clat, $fraction);
                 $nlong = interpolate_part($long, $clong, $fraction);
                 //and recenter the 'square' on that new point
                 $south = $nlat - $dif;
                 $north = $nlat + $dif;
                 $west = $nlong - $dif;
                 $east = $nlong + $dif;
             }
         }
         $rectangle = "'POLYGON(({$west} {$south},{$east} {$south},{$east} {$north},{$west} {$north},{$west} {$south}))'";
         $sql_where = "CONTAINS(GeomFromText({$rectangle}),point_ll)";
         $this->sphinx['impossible']++;
         //todo we might be able to transform it to a set of GR's?
     } else {
         $sql_where = '';
     }
     $x = $this->x;
     $y = $this->y;
     if (!empty($x) && !empty($y)) {
         if ($this->limit8 && $this->limit8 < 2000 && $this->limit8 > -2000) {
             //2000 is a special value for effectivly unlimted!
             $d = abs(intval($this->limit8));
             if ($sql_where) {
                 $sql_where .= ' and ';
             }
             if ($this->limit8 == 1) {
                 $sql_where .= "CONTAINS( GeomFromText('POINT({$x} {$y})'),point_xy )";
             } else {
                 $left = $x - $d;
                 $right = $x + $d - 1;
                 $top = $y + $d - 1;
                 $bottom = $y - $d;
                 $rectangle = "'POLYGON(({$left} {$bottom},{$right} {$bottom},{$right} {$top},{$left} {$top},{$left} {$bottom}))'";
                 $sql_where .= "CONTAINS(GeomFromText({$rectangle}),point_xy)";
                 if ($this->limit8 > 0) {
                     //shame cant use dist_sqd in the next line!
                     $sql_where .= " and ((gs.x - {$x}) * (gs.x - {$x}) + (gs.y - {$y}) * (gs.y - {$y})) < " . $d * $d;
                 }
             }
         }
         if ($this->limit8 && $this->limit8 <= 20 && $this->limit8 > -20) {
             //possible, but calculate it JIT
             $this->sphinx['x'] = $x;
             $this->sphinx['y'] = $y;
             $this->sphinx['d'] = $this->limit8;
             $this->sphinx['sort'] = "@geodist ASC, @relevance DESC, @id DESC";
         } else {
             $this->sphinx['impossible']++;
         }
         if ($this->limit8 == 1) {
             $sql_fields .= ", 0 as dist_sqd";
         } else {
             //not using "power(gs.x -$x,2) * power( gs.y -$y,2)" beucause is testing could be upto 2 times slower!
             $sql_fields .= ", ((gs.x - {$x}) * (gs.x - {$x}) + (gs.y - {$y}) * (gs.y - {$y})) as dist_sqd";
             $sql_order = ' dist_sqd ';
         }
     }
     if (($x == 0 && $y == 0 || $this->limit8) && $this->orderby) {
         switch ($this->orderby) {
             case 'random':
                 $sql_order = ' crc32(concat("' . $this->crt_timestamp_ts . '",gi.gridimage_id)) ';
                 $this->sphinx['compatible_order'] = 0;
                 $this->sphinx['sort'] = "@random";
                 break;
             case 'dist_sqd':
                 break;
             case 'relevance':
                 $sql_order = '';
                 $this->sphinx['sort'] = "@relevance DESC, @id DESC";
                 break;
             case 'imagetaken':
                 if ($sql_where) {
                     $sql_where .= ' and ';
                 }
                 $sql_where .= "imagetaken NOT LIKE '0000-%'";
                 //falls though...
             //falls though...
             default:
                 $sql_order = preg_replace('/[^\\w,\\(\\)]+/', ' ', $this->orderby);
                 switch (str_replace(' desc', '', $this->orderby)) {
                     case 'gridimage_id':
                     case 'submitted':
                         $this->sphinx['sort'] = '@id';
                         break;
                     case 'x':
                         $this->sphinx['compatible_order'] = 0;
                         $this->sphinx['sort'] = 'wgs84_long';
                         break;
                     case 'y':
                         $this->sphinx['compatible_order'] = 0;
                         $this->sphinx['sort'] = 'wgs84_lat';
                         break;
                     case 'imagetaken':
                         $this->sphinx['compatible_order'] = 0;
                         $this->sphinx['sort'] = 'takendays';
                         break;
                     case 'realname':
                     case 'title':
                     case 'imageclass':
                     case 'grid_reference':
                     default:
                         $this->sphinx['impossible']++;
                 }
                 if (!$this->sphinx['impossible'] && preg_match('/ desc$/', $this->orderby)) {
                     $this->sphinx['sort'] .= " DESC";
                 } else {
                     $this->sphinx['sort'] .= " ASC";
                 }
         }
         $sql_order = preg_replace('/^submitted/', 'gridimage_id', $sql_order);
     } elseif (empty($this->sphinx['sort']) || $this->sphinx['sort'] != "@geodist ASC, @relevance DESC, @id DESC") {
         //sphinx undefined is 'relevence' where mysql undefined is table order
         $this->sphinx['compatible_order'] = 0;
     }
     if ($this->breakby) {
         if (preg_match('/imagetaken_(year|month|decade)$/', $this->breakby) && strpos($sql_order, 'imagetaken') === FALSE) {
             switch ($this->breakby) {
                 case 'imagetaken_month':
                     $breakby = "SUBSTRING(imagetaken,1,7)";
                     break;
                 case 'imagetaken_year':
                     $breakby = "SUBSTRING(imagetaken,1,4)";
                     break;
                 case 'imagetaken_decade':
                     $breakby = "SUBSTRING(imagetaken,1,3)";
                     break;
             }
         } else {
             $breakby = preg_replace('/_(year|month|decade)$/', '', $this->breakby);
         }
         $breakby = preg_replace('/^submitted/', 'gridimage_id', $breakby);
         if (strpos($sql_order, ' desc') !== FALSE) {
             $breakby .= ' desc';
             $sorder2 = " DESC";
         } else {
             $sorder2 = " ASC";
         }
         switch (str_replace(' desc', '', $breakby)) {
             case 'gridimage_id':
             case 'submitted':
                 $sorder = '@id';
                 break;
             case 'x':
                 $this->sphinx['compatible_order'] = 0;
                 $sorder = 'wgs84_long';
                 break;
             case 'y':
                 $this->sphinx['compatible_order'] = 0;
                 $sorder = 'wgs84_lat';
                 break;
             case 'imagetaken':
                 $this->sphinx['compatible_order'] = 0;
                 $sorder = 'takendays';
                 break;
             case 'imageclass':
                 $sorder = 'classcrc';
                 break;
             case 'realname':
             case 'title':
             case 'grid_reference':
             default:
                 $this->sphinx['impossible']++;
         }
         if ($breakby != $sql_order && !preg_match('/^(\\w+)\\+$/i', $this->breakby)) {
             $sql_order = $breakby . ($sql_order ? ", {$sql_order}" : '');
             $this->sphinx['sort'] = "{$sorder} {$sorder2}" . ($this->sphinx['sort'] ? ", {$this->sphinx['sort']}" : '');
         }
     }
     $sql_where_start = $sql_where;
     $this->getSQLPartsFromText($this->searchtext);
     if (!empty($this->limit1)) {
         if ($sql_where) {
             $sql_where .= ' and ';
         }
         if (strpos($this->limit1, '!') === 0) {
             $sql_where .= 'gi.user_id != ' . preg_replace('/^!/', '', $this->limit1);
         } else {
             $sql_where .= 'gi.user_id = ' . $this->limit1;
         }
         $this->sphinx['filters']['user_id'] = $this->limit1;
     }
     if (!empty($this->limit2)) {
         if ($sql_where) {
             $sql_where .= ' and ';
         }
         $statuslist = "'" . implode("','", explode(',', $this->limit2)) . "'";
         $sql_where .= "moderation_status in ({$statuslist}) ";
         if ($this->limit2 == 'geograph') {
             $this->sphinx['filters']['status'] = $this->limit2;
         } elseif ($this->limit2 == 'accepted') {
             $this->sphinx['filters']['status'] = 'supplemental';
         }
     }
     if (!empty($this->limit3)) {
         if ($sql_where) {
             $sql_where .= ' and ';
         }
         $sql_where .= "imageclass = '" . addslashes($this->limit3 == '-' ? '' : $this->limit3) . "' ";
         //todo tags tags tags
         if ($this->limit3 == '-') {
             $this->sphinx['impossible']++;
         } else {
             #$this->sphinx['filters']['imageclass'] = "\"".$this->limit3."\"";
             $db = $this->_getDB();
             $this->sphinx['filters']['classcrc'] = array($db->GetOne('select crc32(' . $db->Quote($this->limit3) . ')'));
         }
     }
     if (!empty($this->limit4)) {
         if ($sql_where) {
             $sql_where .= ' and ';
         }
         $sql_where .= 'gs.reference_index = ' . $this->limit4 . ' ';
         if (empty($this->sphinx['d'])) {
             //no point adding this filter if querying on location!
             $square = new GridSquare();
             $prefixes = $square->getGridPrefixes($this->limit4);
             $this->sphinx['filters']['myriad'] = "(" . implode(' | ', $prefixes) . ")";
         }
     }
     if (!empty($this->limit5)) {
         if ($sql_where) {
             $sql_where .= ' and ';
         }
         $db = $this->_getDB();
         $prefix = $db->GetRow('select * from gridprefix where prefix=' . $db->Quote($this->limit5) . ' limit 1');
         $left = $prefix['origin_x'];
         $right = $prefix['origin_x'] + $prefix['width'] - 1;
         $top = $prefix['origin_y'] + $prefix['height'] - 1;
         $bottom = $prefix['origin_y'];
         $rectangle = "'POLYGON(({$left} {$bottom},{$right} {$bottom},{$right} {$top},{$left} {$top},{$left} {$bottom}))'";
         $sql_where .= "CONTAINS(GeomFromText({$rectangle}),point_xy)";
         if (empty($this->limit4)) {
             $sql_where .= ' and gs.reference_index = ' . $prefix['reference_index'] . ' ';
         }
         $this->sphinx['filters']['myriad'] = $this->limit5;
     }
     if (!empty($this->limit6)) {
         if ($sql_where) {
             $sql_where .= ' and ';
         }
         $dates = explode('^', $this->limit6);
         //if a 'to' search then we must make blank bits match the end!
         list($y, $m, $d) = explode('-', $dates[1]);
         if ($y > 0) {
             if ($m == 0) {
                 $m = 12;
             }
             if ($d == 0) {
                 $d = date('t', mktime(0, 0, 0, $m, 1, $y));
             }
             $dates[1] = "{$y}-{$m}-{$d}";
         }
         if ($dates[0]) {
             if (preg_match("/0{4}-([01]?[1-9]+|10)-/", $dates[0]) > 0) {
                 //month only
                 list($y, $m, $d) = explode('-', $dates[0]);
                 $sql_where .= "MONTH(submitted) = {$m} ";
                 $this->sphinx['impossible']++;
             } elseif (preg_match("/0{4}-0{2}-([01]?[1-9]+|10)/", $dates[0]) > 0) {
                 //day only ;)
                 list($y, $m, $d) = explode('-', $dates[0]);
                 $sql_where .= "submitted > DATE_SUB(NOW(),INTERVAL {$d} DAY)";
                 $this->sphinx['filters']['submitted'] = array(time() - 86400 * $d, time());
             } elseif ($dates[1]) {
                 if ($dates[0] == $dates[1]) {
                     //both the same
                     $sql_where .= "submitted LIKE '" . $dates[0] . "%' ";
                     $this->sphinx['filters']['submitted'] = array(strtotime($dates[0]), strtotime($dates[0] . " 23:59:59"));
                 } else {
                     //between
                     $sql_where .= "submitted BETWEEN '" . $dates[0] . "' AND DATE_ADD('" . $dates[1] . "',INTERVAL 1 DAY) ";
                     $this->sphinx['filters']['submitted'] = array(strtotime($dates[0]), strtotime($dates[1] . " 23:59:59"));
                 }
             } else {
                 //from
                 $sql_where .= "submitted >= '" . $dates[0] . "' ";
                 $this->sphinx['filters']['submitted'] = array(strtotime($dates[0]), time());
             }
         } else {
             //to
             $sql_where .= "submitted <= '" . $dates[1] . "' ";
             $this->sphinx['filters']['submitted'] = array(strtotime("2005-01-01"), strtotime($dates[1] . " 23:59:59"));
         }
     }
     if (!empty($this->limit7)) {
         if ($sql_where) {
             $sql_where .= ' and ';
         }
         $dates = explode('^', $this->limit7);
         $same = $dates[0] == $dates[1];
         //if a 'to' search then we must make blank bits match the end!
         list($y1, $m1, $d1) = explode('-', $dates[1]);
         if ($y1 > 0) {
             if ($m1 == 0) {
                 $m1 = 12;
             }
             if ($d1 == 0) {
                 $d1 = date('t', mktime(0, 0, 0, $m1, 1, $y1));
             }
             $dates[1] = sprintf('%04d-%02d-%02d', $y1, $m1, $d1);
         }
         if ($dates[0]) {
             list($y, $m, $d) = explode('-', $dates[0]);
             $days0 = $this->toDays($dates[0]);
             if (preg_match("/0{4}-([01]?[1-9]+|10)-/", $dates[0]) > 0) {
                 //month only
                 $sql_where .= "MONTH(imagetaken) = {$m} ";
                 $this->sphinx['impossible']++;
             } elseif (preg_match("/0{4}-0{2}-([01]?[1-9]+|10)/", $dates[0]) > 0) {
                 //day only ;)
                 $sql_where .= "imagetaken > DATE_SUB(NOW(),INTERVAL {$d} DAY)";
                 $start = $this->toDays("DATE_SUB(NOW(),INTERVAL {$d} DAY)");
                 $now = $this->toDays('NOW()');
                 $this->sphinx['filters']['takendays'] = array($start, $now);
             } elseif ($dates[1]) {
                 if ($same) {
                     //both the same
                     if ($m == 0) {
                         $sql_where .= "imagetaken LIKE '{$y}%' ";
                         $this->sphinx['filters']['takenyear'] = $y;
                     } elseif ($d == 0) {
                         $sql_where .= "imagetaken LIKE '" . sprintf('%04d-%02d', $y, $m) . "%' ";
                         $this->sphinx['filters']['takenmonth'] = sprintf('%04d%02d', $y, $m);
                     } else {
                         $sql_where .= "imagetaken LIKE '" . $dates[0] . "' ";
                         $this->sphinx['filters']['takenday'] = str_replace('-', '', $dates[0]);
                     }
                 } else {
                     //between
                     $sql_where .= "imagetaken BETWEEN '" . $dates[0] . "' AND '" . $dates[1] . "' ";
                     $days1 = $this->toDays($dates[1]);
                     $this->sphinx['filters']['takendays'] = array($days0, $days1);
                 }
             } else {
                 //from
                 $sql_where .= "imagetaken >= '" . $dates[0] . "' ";
                 $now = $this->toDays('NOW()');
                 $this->sphinx['filters']['takendays'] = array($days0, $now);
             }
         } else {
             //to
             $sql_where .= "imagetaken != '0000-00-00' AND imagetaken <= '" . $dates[1] . "' ";
             $days1 = $this->toDays($dates[1]);
             $this->sphinx['filters']['takendays'] = array(1, $days1);
             //1 is just so doesnt match 0
         }
     }
     if (!empty($this->limit9)) {
         if ($this->limit9 > 1) {
             if ($sql_where) {
                 $sql_where .= ' and ';
             }
             $sql_where .= "topic_id = {$this->limit9} ";
         }
         $sql_from .= " INNER JOIN gridimage_post gp ON(gi.gridimage_id=gp.gridimage_id) ";
         $this->sphinx['impossible']++;
     }
     if (!empty($this->limit10)) {
         if ($sql_where) {
             $sql_where .= ' and ';
         }
         $sql_where .= "route_id = {$this->limit10} and ftf=1 ";
         $sql_from .= " INNER JOIN route_item r ON(grid_reference=r.gridref) ";
         $this->sphinx['impossible']++;
     }
     if ($sql_where_start != $sql_where) {
         $this->issubsetlimited = true;
     }
     if (!empty($_GET['debug'])) {
         print "<pre>";
         print_r($this->sql);
         print_r($this->sphinx);
         print "</pre>";
     }
 }
Esempio n. 8
0
         }
     } else {
         $smarty->assign('errormsg', $square->errormsg);
     }
 }
 if (!empty($_REQUEST['step'])) {
     $step = intval($_REQUEST['step']);
 }
 if (empty($_REQUEST['grid_reference']) && $step == 2) {
     $step = 1;
 }
 if ($step == 2) {
     require_once 'geograph/rastermap.class.php';
     $rastermap = new RasterMap($square, true);
     if (isset($_POST['photographer_gridref'])) {
         $square2 = new GridSquare();
         $ok = $square2->setByFullGridRef($_POST['photographer_gridref'], false, false, true);
         $rastermap->addViewpoint($square2->reference_index, $square2->nateastings, $square2->natnorthings, $square2->natgrlen, $_POST['view_direction']);
     } elseif (isset($_POST['view_direction']) && strlen($_POST['view_direction']) && $_POST['view_direction'] != -1) {
         $rastermap->addViewDirection($_POST['view_direction']);
     }
     $smarty->assign_by_ref('rastermap', $rastermap);
     $smarty->assign_by_ref('square', $square);
     $smarty->assign('reference_index', $square->reference_index);
     require_once 'geograph/conversions.class.php';
     $conv = new Conversions();
     list($lat, $long) = $conv->gridsquare_to_wgs84($square);
     $smarty->assign('lat', $lat);
     $smarty->assign('long', $long);
     $rastermap->addLatLong($lat, $long);
     $dirs = array(-1 => '');
Esempio n. 9
0
    $recordSet =& $db->Execute($sql);
    while (!$recordSet->EOF) {
        $tiles += $mosaic->expirePosition($recordSet->fields['x'], $recordSet->fields['y'], 0, true);
        print "tiles = {$tiles}<br/>";
        flush();
        $count++;
        $recordSet->MoveNext();
    }
    $recordSet->Close();
    print "<h2>All Done</h2>";
    print "Squares done = {$count}<br/>";
    print "Tiles deleted = {$tiles}";
    flush();
    exit;
} elseif (isset($_GET['gridref'])) {
    $square = new GridSquare();
    $ok = $square->validGridRef($_GET['gridref']);
    if ($ok) {
        $gridref = $_GET['gridref'];
        $smarty->assign_by_ref('gridref', $gridref);
        $smarty->assign('showinfo', 1);
        //can we find a square?
        $sq = $db->GetRow("select * from gridsquare where grid_reference='{$gridref}'");
        if (count($sq)) {
            $smarty->assign('percent_land', $sq['percent_land']);
        }
        //update?
        if (isset($_GET['save'])) {
            $percent = intval($_GET['percent_land']);
            if (count($sq)) {
                //update existing square
Esempio n. 10
0
require_once 'geograph/kmlfile2.class.php';
require_once 'geograph/gridimage.class.php';
require_once 'geograph/gridsquare.class.php';
require_once 'geograph/map.class.php';
if (!isLocalIPAddress()) {
    init_session();
    $USER->mustHavePerm("admin");
}
$db = NewADOConnection($GLOBALS['DSN']);
if (!$db) {
    die('Database connection failed');
}
require_once 'geograph/conversions.class.php';
$conv = new Conversions();
$gr = $_GET['gr'];
$square = new GridSquare();
$grid_ok = $square->setByFullGridRef($gr);
$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");
$links = new kmlPrimative('Folder');
$links->setItem('name', 'Next Level...');
$prefix = $db->GetRow('select * from gridprefix where prefix=' . $db->Quote($square->gridsquare) . ' limit 1');
$left = $prefix['origin_x'] + intval($square->eastings / 5) * 5;
$right = $left + 5 - 1;
$bottom = $prefix['origin_y'] + intval($square->northings / 5) * 5;
$top = $bottom + 5 - 1;
$rectangle = "'POLYGON(({$left} {$bottom},{$right} {$bottom},{$right} {$top},{$left} {$top},{$left} {$bottom}))'";
 /**
  * Updates a given field of the image, holding it for moderation if necessary
  * A series of calls to this function should be followed up with a call
  * to commit(), which persist the ticket and any unmoderated changes
  * @access public
  */
 function updateField($fieldname, $oldvalue, $newvalue, $moderated)
 {
     $ok = true;
     //no change?
     if ($oldvalue == $newvalue) {
         return $ok;
     }
     if (!$moderated) {
         //make the changes right away...
         $img =& $this->_getImage();
         if ($fieldname == "grid_reference") {
             $err = "";
             $ok = $img->reassignGridsquare($newvalue, $err);
             if ($ok) {
                 $this->commit_count++;
             } else {
                 die("Sorry, wasn't expecting reassignGridsquare to fail ({$err}) please contact us for assistance");
             }
         } elseif ($fieldname == "photographer_gridref") {
             //need to parse value for nat coords
             $sq = new GridSquare();
             if ($sq->setByFullGridRef($newvalue, true, true, true)) {
                 $img->viewpoint_eastings = $sq->nateastings;
                 $img->viewpoint_northings = $sq->natnorthings;
                 $img->viewpoint_grlen = $sq->natgrlen;
                 $img->viewpoint_refindex = $sq->reference_index;
                 $this->commit_count++;
             } elseif (empty($newvalue)) {
                 // we are setting to 'blank'
                 $img->viewpoint_eastings = 0;
                 $img->viewpoint_northings = 0;
                 $img->viewpoint_grlen = 0;
                 $img->viewpoint_refindex = 0;
                 $this->commit_count++;
             }
         } else {
             $img->{$fieldname} = $newvalue;
             //we'll do this commit later
             $this->commit_count++;
         }
         $status = "immediate";
         $approver_id = $this->user_id;
         $img->title = combineTexts($img->title1, $img->title2);
         $img->comment = combineTexts($img->comment1, $img->comment2);
     } else {
         $status = "pending";
         $approver_id = 0;
     }
     //have we already got a change record?
     $found = false;
     foreach ($this->changes as $c) {
         if ($c['field'] == $fieldname) {
             $found = true;
         }
     }
     if (!$found) {
         //create a change record
         $change = array("field" => $fieldname, "oldvalue" => $oldvalue, "newvalue" => $newvalue, "status" => $status, "approver_id" => $approver_id);
         $this->changes[] = $change;
     }
 }
Esempio n. 12
0
require_once 'geograph/kmlfile2.class.php';
require_once 'geograph/gridimage.class.php';
require_once 'geograph/gridsquare.class.php';
require_once 'geograph/map.class.php';
if (!isLocalIPAddress()) {
    init_session();
    $USER->mustHavePerm("admin");
}
$db = NewADOConnection($GLOBALS['DSN']);
if (!$db) {
    die('Database connection failed');
}
require_once 'geograph/conversions.class.php';
$conv = new Conversions();
$gr = $_GET['gr'];
$square = new GridSquare();
$grid_ok = $square->setByFullGridRef($gr);
$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");
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']) {
Esempio n. 13
0
        $minx = $prefix['origin_x'];
        $maxx = $prefix['origin_x'] + $prefix['width'] - 1;
        $miny = $prefix['origin_y'];
        $maxy = $prefix['origin_y'] + $prefix['height'] - 1;
        $crit = "map_x between {$minx} and {$maxx} and " . "map_y between {$miny} and {$maxy} and " . "pixels_per_km >= 40 and " . "((map_x-{$prefix['origin_x']}) mod 5) != 0 and " . "((map_y-{$prefix['origin_y']}) mod 5) != 0";
        $count = $mosaic->deleteBySql($crit, $dummy, $basemap);
        print "Deleted {$count}<br>";
        flush();
        $total += $count;
        list($usec, $sec) = explode(' ', microtime());
        $GLOBALS['STARTTIME'] = (double) $usec + (double) $sec;
    }
    print "<h2>Total: {$total}</h2>";
    exit;
} elseif (isset($_POST['inv'])) {
    $square = new GridSquare();
    require_once 'geograph/mapmosaic.class.php';
    $mosaic = new GeographMapMosaic();
    $smarty->display('_std_begin.tpl');
    echo "<h3><a href=\"recreatemaps.php\">&lt;&lt;</a> Invalidating Maps...</h3>";
    flush();
    $squares = explode(",", $_POST['gridref']);
    $user_id = intval($_POST['user_id']);
    if ($user_id > 0) {
        $and_crit = " and (type_or_user = {$user_id} or type_or_user = 0)";
    } else {
        $and_crit = " and type_or_user = 0";
    }
    $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
    $basemap = isset($_POST['base']);
    foreach ($squares as $gridref) {
Esempio n. 14
0
 //lets add an overview map too
 $overview = new GeographMapMosaic('overview');
 $overview->assignToSmarty($smarty, 'overview');
 $stats = array();
 foreach ($CONF['references_all'] as $ri => $rname) {
     $stats[$ri] = array();
 }
 foreach ($CONF['references'] as $ri => $rname) {
     $letterlength = $CONF['gridpreflen'][$ri];
     $newstats = $db->CacheGetRow(3 * 3600, "select \n\t\t\tcount(*) as squares_total,\n\t\t\tsum(imagecount) as images_total,\n\t\t\tsum(imagecount > 0) as squares_submitted,\n\t\t\tcount(distinct concat(substring(grid_reference,1," . ($letterlength + 1) . "),substring(grid_reference," . ($letterlength + 3) . ",1))) as tenk_total\n\t\tfrom gridsquare \n\t\twhere reference_index = {$ri} and percent_land > 0");
     $stats[$ri] = array_merge($stats[$ri], $newstats);
     $newstats = $db->CacheGetRow(3 * 3600, "select \n\t\t\tcount(*) as geographs_submitted,\n\t\t\tcount(distinct substring(grid_reference,1,{$letterlength})) as grid_submitted,\n\t\t\tcount(distinct concat(substring(grid_reference,1," . ($letterlength + 1) . "),substring(grid_reference," . ($letterlength + 3) . ",1))) as tenk_submitted,\n\t\t\tavg( x ) as x,\n\t\t\tavg( y ) as y\n\t\tfrom gridsquare \n\t\twhere reference_index = {$ri} and percent_land > 0 and has_geographs > 0");
     $stats[$ri] = array_merge($stats[$ri], $newstats);
     $stats[$ri] += array('images_thisweek' => $db->CacheGetOne(3 * 3600, "select count(*) from gridimage_search where reference_index = {$ri} and (unix_timestamp(now())-unix_timestamp(submitted))<604800"));
     $stats[$ri] += array("grid_total" => $db->CacheGetOne(24 * 3600, "select count(*) from gridprefix where reference_index = {$ri} and landcount > 0"));
     $censquare = new GridSquare();
     $ok = $censquare->loadFromPosition(intval($stats[$ri]['x']), intval($stats[$ri]['y']));
     if ($ok) {
         $stats[$ri] += array("centergr" => $censquare->grid_reference);
         //find a possible place within 35km
         $stats[$ri] += array("place" => $censquare->findNearestPlace(35000));
         $stats[$ri] += array("marker" => $overview->getSquarePoint($censquare));
     } else {
         $stats[$ri] += array("centergr" => 'unknown');
     }
 }
 foreach (array('images_total', 'images_thisweek', 'squares_total', 'squares_submitted', 'tenk_total', 'tenk_submitted', 'geographs_submitted', 'grid_submitted', 'grid_total') as $name) {
     $sum = 0;
     foreach ($CONF['references'] as $ri => $rname) {
         $sum += $stats[$ri][$name];
     }
Esempio n. 15
0
 /**
  * update user profile
  * profile array should contain website, nickname, realname flag. A
  * public_email entry, if present, will cause the public_email flag
  * to be set. The idea is to simply pass the $_POST array - all values
  * are checked for validity
  */
 function updateProfile(&$profile, &$errors)
 {
     global $CONF, $MESSAGES;
     $db = $this->_getDB();
     $ok = true;
     $profile['realname'] = stripslashes($profile['realname']);
     $profile['nickname'] = stripslashes($profile['nickname']);
     $profile['website'] = stripslashes($profile['website']);
     $profile['oldpassword'] = stripslashes($profile['oldpassword']);
     $profile['password1'] = stripslashes($profile['password1']);
     $profile['password2'] = stripslashes($profile['password2']);
     // valid homesquare?
     $profile['grid_reference'] = stripslashes($profile['grid_reference']);
     $gridreference = '';
     $gs = new GridSquare();
     if (strlen($profile['grid_reference'])) {
         $gsok = $gs->setByFullGridRef($profile['grid_reference']);
         if (!$gsok) {
             $ok = false;
             $errors['grid_reference'] = $gs->errormsg;
         }
     }
     if (strlen($profile['realname'])) {
         if (!isValidRealName($profile['realname'])) {
             $ok = false;
             $errors['realname'] = $MESSAGES['class_user']['name_chars'];
         }
     } else {
         $ok = false;
         $errors['realname'] = $MESSAGES['class_user']['realname'];
     }
     if (strlen($profile['website']) && !isValidURL($profile['website'])) {
         //can we fix it?
         if (isValidURL("http://" . $profile['website'])) {
             $profile['website'] = "http://" . $profile['website'];
         } else {
             $ok = false;
             $errors['website'] = $MESSAGES['class_user']['website'];
         }
     }
     //unique nickname, since you can log in with it
     if (isValidRealName($profile['nickname'])) {
         //lets be sure it's unique
         $sql = 'select * from user where nickname=' . $db->Quote(stripslashes($profile['nickname'])) . " and user_id<>{$this->user_id} limit 1";
         $r = $db->GetRow($sql);
         if (count($r)) {
             $ok = false;
             $errors['nickname'] = $MESSAGES['class_user']['nickname_in_use'];
         }
         //todo check seperate table
     } else {
         $ok = false;
         $errors['nickname'] = $MESSAGES['class_user']['name_chars'];
     }
     if (strlen($profile['password1'])) {
         if (hash_hmac('md5', $profile['oldpassword'], $this->salt) != $this->password) {
             $ok = false;
             $errors['oldpassword'] = $MESSAGES['class_user']['oldpassword'];
         } elseif ($profile['password1'] != $profile['password2']) {
             $ok = false;
             $errors['password2'] = $MESSAGES['class_user']['password2'];
         } else {
             $salt = $this->randomSalt(8);
             $password = hash_hmac('md5', $profile['password1'], $salt);
         }
     } else {
         $password = $this->password;
         $salt = $this->salt;
     }
     //attempting to change email address?
     if ($profile['email'] != $this->email) {
         if (isValidEmailAddress($profile['email'])) {
             $errors['general'] = sprintf($MESSAGES['class_user']['mail_change'], $profile['email']);
             $ok = false;
             //we need to send the user an email with a confirmation link
             //so we put the information into a table
             $db->Execute("insert into user_emailchange " . "(user_id, oldemail,newemail,requested,status)" . "values(?,?,?,now(), 'pending')", array($this->user_id, $this->email, $profile['email']));
             $id = $db->Insert_ID();
             $url = "http://" . $_SERVER['HTTP_HOST'] . '/reg/m' . $id . '/' . substr(md5('m' . $id . $CONF['register_confirmation_secret']), 0, 16);
             $mail_body = $MESSAGES['class_user']['mailbody_mail_change'];
             $mail_subject = $MESSAGES['class_user']['mailsubject_mail_change'];
             $msg = sprintf($mail_body, $_SERVER['HTTP_HOST'], $profile['email'], $url);
             $sub = sprintf($mail_subject, $_SERVER['HTTP_HOST']);
             @mail($profile['email'], mb_encode_mimeheader($CONF['mail_subjectprefix'] . $sub, $CONF['mail_charset'], $CONF['mail_transferencoding']), $msg, "From: Geograph <{$CONF['mail_from']}>\n" . "MIME-Version: 1.0\n" . "Content-Type: text/plain; {$CONF['mail_charset']}\n" . "Content-Disposition: inline\n" . "Content-Transfer-Encoding: 8bit", is_null($CONF['mail_envelopefrom']) ? null : "-f {$CONF['mail_envelopefrom']}");
         } else {
             $errors['email'] = $MESSAGES['class_user']['new_email_invalid'];
             $ok = false;
         }
     }
     if ($ok) {
         //about box is always public - col to be removed
         $profile['public_about'] = 1;
         $profile['use_age_group'] = 0;
         //age info is useless to others, nice for us, no need
         //to give use a public option
         if ($this->realname != $profile['realname']) {
             $db->Execute(sprintf("insert into user_change set \n\t\t\t\t\tuser_id = %d,\n\t\t\t\t\tfield = 'realname',\n\t\t\t\t\tvalue = %s\n\t\t\t\t\t", $this->user_id, $db->Quote($profile['realname'])));
         }
         if ($this->nickname != $profile['nickname']) {
             $db->Execute(sprintf("insert into user_change set \n\t\t\t\t\tuser_id = %d,\n\t\t\t\t\tfield = 'nickname',\n\t\t\t\t\tvalue = %s\n\t\t\t\t\t", $this->user_id, $db->Quote($profile['nickname'])));
         }
         $sql = sprintf("update user set \n\t\t\t\trealname=%s,\n\t\t\t\tnickname=%s,\n\t\t\t\twebsite=%s,\n\t\t\t\tpublic_email=%d,\n\t\t\t\tsearch_results=%d,\n\t\t\t\tslideshow_delay=%d,\n\t\t\t\tabout_yourself=%s,\n\t\t\t\tpublic_about=%d,\n\t\t\t\tage_group=%d,\n\t\t\t\tuse_age_group=%d,\n\t\t\t\thome_gridsquare=%s,\n\t\t\t\tticket_public=%s,\n\t\t\t\tcalendar_public=%s,\n\t\t\t\tticket_option=%s,\n\t\t\t\tmessage_sig=%s,\n\t\t\t\tupload_size=%d,\n\t\t\t\tclear_exif=%d,\n\t\t\t\tsalt=%s,\n\t\t\t\tpassword=%s\n\t\t\t\twhere user_id=%d", $db->Quote($profile['realname']), $db->Quote($profile['nickname']), $db->Quote($profile['website']), empty($profile['public_email']) ? 0 : 1, $profile['search_results'], $profile['slideshow_delay'], $db->Quote(strip_tags(stripslashes($profile['about_yourself']))), $profile['public_about'] ? 1 : 0, $profile['age_group'], $profile['use_age_group'] ? 1 : 0, $gs->gridsquare_id, $db->Quote($profile['ticket_public']), $db->Quote($profile['calendar_public']), $db->Quote($profile['ticket_option']), $db->Quote(stripslashes($profile['message_sig'])), intval($profile['upload_size']), $profile['clear_exif'] ? 1 : 0, $db->Quote($salt), $db->Quote($password), $this->user_id);
         if ($db->Execute($sql) === false) {
             $errors['general'] = $MESSAGES['class_user']['error_dbupdate'] . $db->ErrorMsg();
             $ok = false;
         } else {
             //hurrah - it's all good - lets update ourself..
             //update gridimage_search too
             if ($this->realname != stripslashes($profile['realname'])) {
                 $sql = "update gridimage_search set realname=" . $db->Quote(stripslashes($profile['realname'])) . " where user_id = {$this->user_id}";
                 $db->Execute($sql);
             }
             $this->realname = $profile['realname'];
             $this->nickname = $profile['nickname'];
             $this->password = $password;
             $this->salt = $salt;
             $this->website = $profile['website'];
             $this->public_email = isset($profile['public_email']) ? 1 : 0;
             if (isset($profile['sortBy'])) {
                 $this->sortBy = stripslashes($profile['sortBy']);
             }
             $this->search_results = stripslashes($profile['search_results']);
             $this->slideshow_delay = stripslashes($profile['slideshow_delay']);
             $this->about_yourself = stripslashes($profile['about_yourself']);
             $this->public_about = stripslashes($profile['public_about']);
             $this->age_group = stripslashes($profile['age_group']);
             $this->use_age_group = stripslashes($profile['use_age_group']);
             $this->grid_reference = $gs->grid_reference;
             $this->calendar_public = stripslashes($profile['calendar_public']);
             $this->ticket_public = stripslashes($profile['ticket_public']);
             $this->ticket_option = stripslashes($profile['ticket_option']);
             $this->message_sig = stripslashes($profile['message_sig']);
             $this->upload_size = intval($profile['upload_size']);
             $this->clear_exif = !empty($profile['clear_exif']);
             $this->_forumUpdateProfile();
             $this->_forumLogin();
             if (!empty($profile['ticket_public_change'])) {
                 $sql = sprintf("update gridimage_ticket set `public`=%s where user_id = %d", $db->Quote($profile['ticket_public_change']), $this->user_id);
                 if ($db->Execute($sql) === false) {
                     $errors['general'] = $MESSAGES['class_user']['error_dbupdate'] . $db->ErrorMsg();
                     $ok = false;
                 }
             }
         }
     }
     return $ok;
 }
 /**
  * commit the upload process
  */
 function commit($method = '', $skip_cleanup = false)
 {
     global $USER, $CONF, $memcache;
     if ($this->validUploadId($this->upload_id)) {
         $uploadfile = $this->_pendingJPEG($this->upload_id);
         if (!file_exists($uploadfile)) {
             return "Upload image not found";
         }
     } else {
         return "Must assign upload id";
     }
     if (!is_object($this->square)) {
         return "Must assign square";
     }
     $viewpoint = new GridSquare();
     if ($this->viewpoint_gridreference) {
         $ok = $viewpoint->setByFullGridRef($this->viewpoint_gridreference, true, true, true);
     }
     //get sequence number
     $mkey = $this->square->gridsquare_id;
     $seq_no =& $memcache->name_get('sid', $mkey);
     if (empty($seq_no) && !empty($CONF['use_insertionqueue'])) {
         $seq_no = $this->db->GetOne("select max(seq_no) from gridimage_queue where gridsquare_id={$this->square->gridsquare_id}");
     }
     if (empty($seq_no)) {
         $seq_no = $this->db->GetOne("select max(seq_no) from gridimage where gridsquare_id={$this->square->gridsquare_id}");
     }
     $seq_no = max($seq_no + 1, 0);
     $memcache->name_set('sid', $mkey, $seq_no, false, $memcache->period_long);
     //ftf is zero under image is moderated
     $ftf = 0;
     //get the exif data and set orientation
     $this->reReadExifFile();
     if (!empty($CONF['use_insertionqueue'])) {
         $table = "gridimage_queue";
     } else {
         $table = "gridimage";
     }
     //create record
     // nateasting/natnorthings will only have values if getNatEastings has been called (in this case because setByFullGridRef has been called IF an exact location is specifed)
     $sql = sprintf("insert into {$table} (" . "gridsquare_id, seq_no, user_id, ftf," . "moderation_status,title,comment,title2,comment2,nateastings,natnorthings,natgrlen,imageclass,imagetaken," . "submitted,viewpoint_eastings,viewpoint_northings,viewpoint_grlen,view_direction,use6fig,user_status,realname,reference_index,viewpoint_refindex) values " . "(%d,%d,%d,%d," . "'pending',%s,%s,%s,%s,%d,%d,'%d',%s,%s," . "now(),%d,%d,'%d',%d,%d,%s,%s,'%d','%d')", $this->square->gridsquare_id, $seq_no, $USER->user_id, $ftf, $this->db->Quote($this->title), $this->db->Quote($this->comment), $this->db->Quote($this->title2), $this->db->Quote($this->comment2), $this->square->nateastings, $this->square->natnorthings, $this->square->natgrlen, $this->db->Quote($this->imageclass), $this->db->Quote($this->imagetaken), $viewpoint->nateastings, $viewpoint->natnorthings, $viewpoint->natgrlen, $this->view_direction, $this->use6fig, $this->db->Quote($this->user_status), $this->db->Quote($this->realname), $this->square->reference_index, $viewpoint->reference_index);
     $this->db->Query($sql);
     //get the id
     $gridimage_id = $this->db->Insert_ID();
     //save the exif
     $sql = sprintf("insert into gridimage_exif (" . "gridimage_id,exif) values " . "(%d,%s)", $gridimage_id, $this->db->Quote($exif));
     $this->db->Query($sql);
     //copy image to correct area
     $src = $this->_pendingJPEG($this->upload_id);
     $image = new GridImage();
     $image->gridimage_id = $gridimage_id;
     $image->user_id = $USER->user_id;
     if ($this->clearexif && $CONF['exiftooldir'] !== '') {
         $cmd = sprintf("\"%sexiftool\" -overwrite_original -all= \"%s\" > /dev/null 2>&1", $CONF['exiftooldir'], $src);
         passthru($cmd);
     }
     $storedoriginal = false;
     if ($ok = $image->storeImage($src)) {
         $orginalfile = $this->_originalJPEG($this->upload_id);
         if (file_exists($orginalfile) && $this->largestsize && $this->largestsize > $CONF['img_max_size']) {
             if ($this->switchxy) {
                 list($oheight, $owidth, $otype, $oattr) = getimagesize($orginalfile);
             } else {
                 list($owidth, $oheight, $otype, $oattr) = getimagesize($orginalfile);
             }
             list($destwidth, $destheight, $destdim, $changedim) = $this->_new_size($owidth, $oheight, $this->largestsize);
             $this->_downsizeFile($orginalfile, $destdim);
             if ($this->clearexif && $CONF['exiftooldir'] !== '') {
                 $cmd = sprintf("\"%sexiftool\" -overwrite_original -all= \"%s\" > /dev/null 2>&1", $CONF['exiftooldir'], $orginalfile);
                 passthru($cmd);
             }
             $storedoriginal = $image->storeOriginal($orginalfile);
         }
         if (!$skip_cleanup) {
             $this->cleanUp();
         }
     }
     //fire an event
     require_once 'geograph/event.class.php';
     new Event(EVENT_NEWPHOTO, $gridimage_id . ',' . $USER->user_id . ',' . $storedoriginal);
     #//assign the snippets now we know the real id.
     #$gid = crc32($this->upload_id)+4294967296;
     #$gid += $USER->user_id * 4294967296;
     #
     #$this->db->Execute($sql = "UPDATE gridimage_snippet SET gridimage_id = $gridimage_id WHERE gridimage_id = ".$gid);
     $this->gridimage_id = $gridimage_id;
     #if (!empty($method)) {
     #	if (!empty($GLOBALS['STARTTIME'])) {
     #
     #		list($usec, $sec) = explode(' ',microtime());
     #		$endtime = ((float)$usec + (float)$sec);
     #		$timetaken = $endtime - $GLOBALS['STARTTIME'];
     #
     #		$this->db->Execute("INSERT INTO submission_method SET gridimage_id = $gridimage_id,method='$method',timetaken=$timetaken");
     #	} else {
     #		$this->db->Execute("INSERT INTO submission_method SET gridimage_id = $gridimage_id,method='$method'");
     #	}
     #}
 }
Esempio n. 17
0
 if (!empty($_GET['submittedyear'])) {
     if (!$db) {
         $db = NewADOConnection($GLOBALS['DSN']);
     }
     $custom_where .= " and submitted LIKE " . $db->Quote($_GET['submittedyear'] . "%");
     $date = getFormattedDate($_GET['submittedyear']);
     $filtered_title .= " Submitted in {$date}";
 }
 if (isset($_GET['direction']) && strlen($_GET['direction'])) {
     $direction = intval($_GET['direction']);
     $custom_where .= " and view_direction = {$direction}";
     $view_direction = $direction % 90 == 0 ? strtoupper(heading_string($direction)) : ucwords(heading_string($direction));
     $filtered_title .= " Looking {$view_direction}";
 }
 if (!empty($_GET['viewpoint'])) {
     $viewpoint_square = new GridSquare();
     if ($_GET['viewpoint'] == '-') {
         $custom_where .= " and viewpoint_eastings = 0";
         $filtered_title = "photographer position unspecified";
     } elseif ($viewpoint_square->setByFullGridRef($_GET['viewpoint'], true, true)) {
         $e = intval($viewpoint_square->nateastings / 1000);
         $n = intval($viewpoint_square->natnorthings / 1000);
         $custom_where .= " and viewpoint_eastings DIV 1000 = {$e} AND viewpoint_northings DIV 1000 = {$n}";
         $filtered_title .= " Taken in " . $viewpoint_square->grid_reference;
     }
 }
 if (!empty($_GET['centi'])) {
     if ($_GET['centi'] == 'unspecified') {
         $custom_where .= " and nateastings = 0";
     } else {
         if ($_GET['centi'] == 'X') {
     $image->_initFromArray($recordSet->fields);
     $square = $image->grid_square;
     $extra = ",upd_timestamp = '{$recordSet->fields['upd_timestamp']}'";
     if (!isset($square->nateastings)) {
         $square->getNatEastings();
     }
     //to optimise the query, we scan a square centred on the
     //the required point
     $radius = 30000;
     $places = $square->findNearestPlace($radius);
     $pid = $places['pid'];
 } else {
     $gid = $recordSet->fields['gridsquare_id'];
     #$from_stratch = 1;
     if ($from_stratch || $recordSet->fields['reference_index'] == 2) {
         $square = new GridSquare();
         #$square->_initFromArray($recordSet->fields);
         //store cols as members
         foreach ($recordSet->fields as $name => $value) {
             if (!is_numeric($name)) {
                 $square->{$name} = $value;
             }
         }
         $square->_storeGridRef($square->grid_reference);
         $extra = "";
         if (!isset($square->nateastings)) {
             $square->getNatEastings();
         }
         //to optimise the query, we scan a square centred on the
         //the required point
         $radius = 100000;
Esempio n. 19
0
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
require_once 'geograph/global.inc.php';
require_once 'geograph/gridimage.class.php';
require_once 'geograph/gridsquare.class.php';
require_once 'geograph/map.class.php';
require_once 'geograph/mapmosaic.class.php';
require_once 'geograph/image.inc.php';
init_session();
$smarty = new GeographPage();
$db = NewADOConnection($GLOBALS['DSN']);
if (isset($_POST['inv'])) {
    $square = new GridSquare();
    $grid_ok = $square->setGridRef($_POST['gridref']);
    if ($grid_ok) {
        $x = $square->x;
        $y = $square->y;
        require_once 'geograph/mapmosaic.class.php';
        $mosaic = new GeographMapMosaic();
        $mosaic->expirePosition($x, $y);
        $smarty->assign('gridref', $_POST['gridref']);
    } else {
        $smarty->assign('errormsg', $square->errormsg);
    }
}
$smarty->assign('invalid_maps', $db->GetOne("select count(*) from mapcache where age > 0 and type_or_user >= 0"));
$smarty->display('recreatemaps.tpl');
        }
    }
    $loads = explode(" ", $buffer);
    $load = (double) $loads[0];
    if ($load > $threshold) {
        $CONF['disable_discuss_thumbs'] = true;
    }
}
if (!empty($CONF['disable_discuss_thumbs'])) {
    $gridThumbs = "<h4 style=\"color:red\">During times of heavy load we limit the display of thumbnails in the posts.<br/>Sorry for the loss of this feature.</h4>";
} else {
    if ($gridref || $forum == $CONF['forum_gridsquare'] && ($gridref = $topicName)) {
        require_once 'geograph/gridimage.class.php';
        require_once 'geograph/gridsquare.class.php';
        $smarty = new GeographPage();
        $square = new GridSquare();
        $grid_ok = $square->setGridRef($gridref);
        if ($grid_ok) {
            //find a possible place within 25km
            $smarty->assign('place', $square->findNearestPlace(75000));
            if ($square->imagecount) {
                //todo use smarty caching
                //what style should we use?
                $style = $USER->getStyle();
                $smarty->assign('maincontentclass', 'content_photo' . $style);
                $smarty->assign('backgroundcolor', $style);
                $images = $square->getImages();
                $smarty->assign_by_ref('images', $images);
            }
            $smarty->assign('gridref', $gridref);
            $gridThumbs = $smarty->fetch("_discuss_gridref_cell.tpl");
Esempio n. 21
0
 #location
 if (preg_match('/^([a-zA-Z]{1,3}) +(\\d{1,5})(\\.\\d*|) +(\\d{1,5})(\\.*\\d*|)/', $q, $matches) && $matches[1] != 'tp') {
     $square = new GridSquare();
     $grid_ok = $square->setByFullGridRef($matches[0], true);
     if ($grid_ok) {
         $gr = $square->grid_reference;
         $e = $square->nateastings;
         $n = $square->natnorthings;
         $q = preg_replace("/{$matches[0]}\\s*/", '', $q);
     } else {
         $r = "\t--invalid Grid Ref--";
         $nocache = 1;
     }
 } else {
     if (preg_match('/^([a-zA-Z]{1,3})(\\d{2,10})\\b/', $q, $matches) && $matches[1] != 'tp') {
         $square = new GridSquare();
         $grid_ok = $square->setByFullGridRef($matches[0], true);
         if ($grid_ok) {
             $gr = $square->grid_reference;
             $e = $square->nateastings;
             $n = $square->natnorthings;
             $q = preg_replace("/{$matches[0]}\\s*/", '', $q);
         } else {
             $r = "\t--invalid Grid Ref--";
             $nocache = 1;
         }
     }
 }
 if (preg_match('/\\bp(age|)(\\d+)\\s*$/', $q, $m)) {
     $offset = min(max((intval($m[2]) - 1) * 25, 0), 984);
     $q = preg_replace('/\\bp(age|)\\d+\\s*$/', '', $q);
 function combineTiles(&$gr, $path = false)
 {
     global $CONF, $USER;
     if (is_string($gr)) {
         $square = new GridSquare();
         if (!$square->setByFullGridRef($gr)) {
             return false;
         }
     } else {
         //already a gridsquare object
         $square &= $gr;
     }
     $ll = $square->gridsquare;
     $service = 'OS50k-source';
     $tilewidth = $this->tilewidth[$service];
     list($source, $dummy) = explode('-', $service);
     $outputwidth = $this->tilewidth['OS50k'];
     //this isn't STRICTLY needed as getOSGBStorePath does the same floor, but do so in case we do exact calculations
     $east = floor($this->nateastings / 1000) * 1000;
     $nort = floor($this->natnorthings / 1000) * 1000;
     if (strlen($CONF['imagemagick_path'])) {
         $tilelist = array();
         $c = 0;
         $found = 0;
         foreach (range($nort + 1000, $nort - 1000, -1000) as $n) {
             foreach (range($east - 1000, $east + 1000, 1000) as $e) {
                 $newpath = $this->getOSGBStorePath($service, $e, $n);
                 if (file_exists($newpath)) {
                     $tilelist[] = $newpath;
                     $found = 1;
                 } else {
                     $tilelist[] = $CONF['rastermap'][$source]['path'] . $this->epoch . '/' . "blank{$tilewidth}.png";
                     if (!empty($_GET['debug']) && $USER->hasPerm('admin')) {
                         print "{$newpath} not found<br/>\n";
                     }
                 }
                 $c++;
             }
         }
         if (!$found) {
             if (!empty($_GET['debug']) && $USER->hasPerm('admin')) {
                 print "No content tiles found<br/>\n";
             }
             return false;
         }
         if (!$path) {
             $path = $this->getOSGBStorePath('OS50k', $east, $nort, true);
         }
         $cmd = sprintf('%s"%smontage" -geometry +0+0 %s -tile 3x3 png:- | "%sconvert" - -crop %ldx%ld+%ld+%ld +repage -thumbnail %ldx%ld -colors 128 -font "%s" -fill "#eeeeff" -draw "roundRectangle 6,230 155,243 3,3" -fill "#000066" -pointsize 10 -draw "text 10,240 \'© Crown Copyright %s\'" -colors 128 -depth 8 -type Palette png:%s', isset($_GET['nice']) ? 'nice ' : '', $CONF['imagemagick_path'], implode(' ', $tilelist), $CONF['imagemagick_path'], $tilewidth * 2, $tilewidth * 2, $tilewidth / 2, $tilewidth / 2, $outputwidth, $outputwidth, $CONF['imagemagick_font'], $CONF['OS_licence'], $path);
         if (isset($_ENV["OS"]) && strpos($_ENV["OS"], 'Windows') !== FALSE) {
             $cmd = str_replace('/', '\\', $cmd);
         }
         exec($cmd);
         if (!empty($_GET['debug']) && $USER->hasPerm('admin')) {
             print "<pre>{$cmd}</pre>";
         }
         if (file_exists($path)) {
             return true;
         } else {
             return false;
         }
     } else {
         //generate resized image
         die("gd not implemented!");
     }
 }
Esempio n. 23
0
while (!$recordSet->EOF) {
    $item = new FeedItem();
    $item->title = date('d/m/Y: ', strtotime($recordSet->fields['created'])) . $recordSet->fields['title'];
    //htmlspecialchars is called on link so dont use &amp;
    $item->link = "http://{$_SERVER['HTTP_HOST']}/events/event.php?id={$recordSet->fields['geoevent_id']}";
    $item->guid = $item->link;
    $description = $recordSet->fields['description'];
    if (strlen($description) > 160) {
        $description = substr($description, 0, 157) . "...";
    }
    $description .= "<br/><br/><a href=\"{$item->link}\">More details of this event</a>";
    $item->description = $description;
    $item->date = strtotime($recordSet->fields['created']);
    $item->author = $recordSet->fields['realname'];
    if (($format == 'KML' || $format == 'GeoRSS' || $format == 'GPX') && $recordSet->fields['gridsquare_id']) {
        $gridsquare = new GridSquare();
        $grid_ok = $gridsquare->loadFromId($recordSet->fields['gridsquare_id']);
        if ($grid_ok) {
            list($item->lat, $item->long) = $conv->internal_to_wgs84($recordSet->fields['x'], $recordSet->fields['y']);
        }
        $rss->addItem($item);
    } elseif ($format != 'KML') {
        $rss->addItem($item);
    }
    $recordSet->MoveNext();
}
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// always modified
header("Cache-Control: no-store, no-cache, must-revalidate");
Esempio n. 24
0
 $type = isset($_REQUEST['type']) ? stripslashes($_REQUEST['type']) : 'few';
 switch ($type) {
     case 'with':
         $typename = 'with';
         $crit = 'imagecount>0';
         break;
     case 'few':
         $typename = 'with few';
         $crit = 'imagecount<2 and (percent_land > 0 || imagecount>1)';
         break;
     default:
         $type = $typename = 'without';
         $crit = 'imagecount=0 and percent_land > 0';
         break;
 }
 $square = new GridSquare();
 if (!empty($_REQUEST['ll']) && preg_match("/\\b(-?\\d+\\.?\\d*)[, ]+(-?\\d+\\.?\\d*)\\b/", $_REQUEST['ll'], $ll)) {
     $conv = new Conversions();
     list($x, $y, $reference_index) = $conv->wgs84_to_internal($ll[1], $ll[2]);
     $grid_ok = $square->loadFromPosition($x, $y, true);
 } else {
     $grid_ok = $square->setByFullGridRef($_REQUEST['gridref']);
 }
 if ($grid_ok) {
     $template = 'gpx_download_gpx.tpl';
     $cacheid = $square->grid_reference . '-' . $type . '-' . $d;
     //regenerate?
     if (!$smarty->is_cached($template, $cacheid)) {
         $searchdesc = "squares within {$d}km of {$square->grid_reference} {$typename} photographs";
         $x = $square->x;
         $y = $square->y;
Esempio n. 25
0
require_once 'geograph/kmlfile2.class.php';
require_once 'geograph/gridimage.class.php';
require_once 'geograph/gridsquare.class.php';
require_once 'geograph/map.class.php';
if (!isLocalIPAddress()) {
    init_session();
    $USER->mustHavePerm("admin");
}
$db = NewADOConnection($GLOBALS['DSN']);
if (!$db) {
    die('Database connection failed');
}
require_once 'geograph/conversions.class.php';
$conv = new Conversions();
$gr = $_GET['gr'];
$square = new GridSquare();
$grid_ok = $square->setByFullGridRef($gr);
$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");
$links = new kmlPrimative('Folder');
$links->setItem('name', 'Next Level...');
$prefix = $db->GetRow('select * from gridprefix where prefix=' . $db->Quote($square->gridsquare) . ' limit 1');
$left = $prefix['origin_x'] + intval($square->eastings / 20) * 20;
$right = $left + 20 - 1;
$bottom = $prefix['origin_y'] + intval($square->northings / 20) * 20;
$top = $bottom + 20 - 1;
$rectangle = "'POLYGON(({$left} {$bottom},{$right} {$bottom},{$right} {$top},{$left} {$top},{$left} {$bottom}))'";
Esempio n. 26
0
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
require_once 'geograph/global.inc.php';
require_once 'geograph/gridsquare.class.php';
init_session();
$smarty = new GeographPage();
if (isset($_GET['gridref'])) {
    $square = new GridSquare();
    $ok = $square->setByFullGridRef($_GET['gridref'], false, true);
    if ($ok || $square->x && strlen($square->grid_reference) > 4) {
        $gridref = $square->grid_reference;
        $smarty->assign_by_ref('gridref', $gridref);
        $smarty->assign('showinfo', 1);
        $isadmin = $USER->hasPerm('moderator') || $USER->hasPerm('mapmod') ? 1 : 0;
        $smarty->assign_by_ref('isadmin', $isadmin);
        $db = NewADOConnection($GLOBALS['DSN']);
        $smarty->assign('check_count', -2);
        //can we find a square?
        $sq = $db->GetRow("select * from gridsquare where grid_reference='{$gridref}' limit 1");
        if (count($sq)) {
            $smarty->assign('percent_land', $sq['percent_land']);
            if ($count = $db->GetOne("select count(*) from mapfix_log where gridsquare_id='{$sq['gridsquare_id']}'")) {
                $smarty->assign('check_count', $count);
Esempio n. 27
0
    if (count($page) && ($page['user_id'] == $USER->user_id || $USER->hasPerm('moderator'))) {
        $smarty->assign($page);
        $smarty->assign('id', $page['geoevent_id']);
    } else {
        $template = 'static_404.tpl';
    }
}
if ($template != 'static_404.tpl' && isset($_POST) && isset($_POST['submit'])) {
    $errors = array();
    $_POST['event_date'] = sprintf("%04d-%02d-%02d", $_POST['event_dateYear'], $_POST['event_dateMonth'], $_POST['event_dateDay']);
    $_POST['event_time'] = $_POST['event_date'];
    $_POST['title'] = preg_replace('/[^\\w-\\., ]+/', '', trim($_POST['title']));
    if ($_POST['title'] == "New Event") {
        $errors['title'] = "Please give a meaningful title";
    }
    $gs = new GridSquare();
    if (!empty($_POST['grid_reference'])) {
        if ($gs->setByFullGridRef($_POST['grid_reference'])) {
            $_POST['gridsquare_id'] = $gs->gridsquare_id;
        } else {
            $errors['grid_reference'] = $gs->errormsg;
        }
    }
    $updates = array();
    foreach (array('url', 'title', 'description', 'event_time', 'gridsquare_id', 'gridimage_id') as $key) {
        if ($page[$key] != $_POST[$key]) {
            $updates[] = "`{$key}` = " . $db->Quote($_POST[$key]);
            $smarty->assign($key, $_POST[$key]);
        } elseif (empty($_POST[$key]) && $key != 'url' && $key != 'gridimage_id') {
            $errors[$key] = "missing required info";
        }
}
require_once 'geograph/conversions.class.php';
$conv = new Conversions();
$gr = $_GET['gr'];
preg_match('/^([A-Z]{1,3})(\\d\\d)(\\d|_)(\\d\\d)(\\d|_)$/', strtoupper($gr), $matches);
if ($matches[3] == '_') {
    $sql_where = " and nateastings = 0";
    $gr2 = $matches[1] . $matches[2] . $matches[4];
} else {
    $sql_where = " and nateastings != 0";
    //to stop XX0XX0 matching 4fig GRs
    $sql_where .= " and ((nateastings div 100) mod 10) = " . $matches[3];
    $sql_where .= " and ((natnorthings div 100) mod 10) = " . $matches[5];
    $gr2 = $gr;
}
$square = new GridSquare();
$grid_ok = $square->setByFullGridRef($gr2);
$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;
Esempio n. 29
0
    $mtime = strtotime($page['update_time']);
    //can't use IF_MODIFIED_SINCE for logged in users as has no concept as uniqueness
    customCacheControl($mtime, $cacheid, $USER->user_id == 0);
} else {
    $template = 'static_404.tpl';
}
if (!$smarty->is_cached($template, $cacheid)) {
    if (count($page)) {
        $CONF['global_thumb_limit'] *= 2;
        $CONF['post_thumb_limit'] *= 2;
        $smarty->assign($page);
        if (!empty($page['extract'])) {
            $smarty->assign('meta_description', "User contributed article about, " . $page['extract']);
        }
        if (!empty($page['gridsquare_id'])) {
            $square = new GridSquare();
            $square->loadFromId($page['gridsquare_id']);
            $smarty->assign('grid_reference', $square->grid_reference);
            require_once 'geograph/conversions.class.php';
            $conv = new Conversions();
            list($lat, $long) = $conv->gridsquare_to_wgs84($square);
            $smarty->assign('lat', $lat);
            $smarty->assign('long', $long);
        }
        if (preg_match('/\\bgeograph\\b/i', $page['category_name'])) {
            $db->Execute("set @last=0");
            $users = $db->getAll("select realname,modifier,update_time,if(approved = @last,1,0) as same,@last := approved \r\n\t\t\tfrom article_revisions \r\n\t\t\tleft join user on (article_revisions.modifier = user.user_id)\r\n\t\t\twhere article_id = {$page['article_id']}");
            $arr = array();
            foreach ($users as $idx => $row) {
                if ($row['same'] == 1 && $row['modifier'] != $page['user_id'] && !isset($arr[$row['modifier']])) {
                    $arr[$row['modifier']] = "<a href=\"/profile/{$row['modifier']}\">" . htmlentities2($row['realname']) . "</a>";
Esempio n. 30
0
     $rss->description = 'Latest Geograph Topics';
     $rss->syndicationURL = "http://{$_SERVER['HTTP_HOST']}/discuss/syndicator.php?format={$format}&amp;sortBy=1" . $synd;
     $sql_order = 'geobb_topics.topic_id DESC';
     $sql_join = "topic_last_post_id=geobb_posts.post_id";
 } else {
     $rss->title = "Geograph.org.uk Forum {$title} :: Latest Discussions";
     $rss->description = 'Latest Geograph Discussions';
     $rss->syndicationURL = "http://{$_SERVER['HTTP_HOST']}/discuss/syndicator.php?format={$format}" . $synd;
     $sql_order = '`topic_last_post_id` DESC';
     $sql_join = "topic_last_post_id=geobb_posts.post_id";
 }
 if ($opt_gridref) {
     $rss->description .= " near " . $_REQUEST['gridref'];
     $rss->syndicationURL .= "{$amp};gridref=" . $_REQUEST['gridref'];
     $sql_where = " INNER JOIN gridsquare AS gs ON(topic_title = grid_reference) " . $sql_where;
     $square = new GridSquare();
     $grid_ok = $square->setByFullGridRef($_REQUEST['gridref']);
     if (!$grid_ok) {
         die("invalid gridsquare");
     }
     $d = 20;
     $x = $square->x;
     $y = $square->y;
     $left = $x - $d;
     $right = $x + $d - 1;
     $top = $y + $d - 1;
     $bottom = $y - $d;
     $rectangle = "'POLYGON(({$left} {$bottom},{$right} {$bottom},{$right} {$top},{$left} {$top},{$left} {$bottom}))'";
     $sql_where .= " AND CONTAINS(GeomFromText({$rectangle}),point_xy)";
     if ($d < 50) {
         //shame cant use dist_sqd in the next line!