コード例 #1
0
 public static function unserializeRoamingStatus($json = null)
 {
     if ($json === null) {
         $json = file_get_contents("php://input");
     }
     return Conversions::createFromJSON('infobip\\models\\TerminalRoamingStatusNotification', $json);
 }
コード例 #2
0
 public function __construct($array = null, $success = true)
 {
     if (!$success) {
         $this->exception = new SmsException($array);
     } else {
         if ($array) {
             Logs::warn('Constructor with JSON params in ' . get_class($this) . ' is deprecated, use Conversions utility class!');
             Conversions::fillFromJSON($this, $array, !$success);
         }
     }
 }
コード例 #3
0
function __convert_inbound_sms_messages($object, $jsonData)
{
    $messages = Utils::getArrayValue($jsonData, 'inboundSMSMessageList.inboundSMSMessage', array());
    $object->inboundSMSMessage = array();
    foreach ($messages as $message) {
        $object->inboundSMSMessage[] = Conversions::createFromJSON('InboundSmsMessage', $message, false);
    }
    $object->numberOfMessagesInThisBatch = Utils::getArrayValue($jsonData, 'inboundSMSMessageList.numberOfMessagesInThisBatch', 0);
    $object->totalNumberOfPendingMessages = Utils::getArrayValue($jsonData, 'inboundSMSMessageList.totalNumberOfPendingMessages', 0);
    $object->callbackData = Utils::getArrayValue($jsonData, 'inboundSMSMessageList.callbackData');
}
コード例 #4
0
 public function __construct($arrayOrJson = null, $success = true)
 {
     // TODO: Remove this and use only the Conversions class
     if (!$success) {
         $this->exception = new SmsException($arrayOrJson);
     } else {
         if ($arrayOrJson) {
             Logs::warn('Constructor with JSON params in ' . get_class($this) . ' is deprecated, use Conversions utility class!');
             Conversions::fillFromJSON($this, $arrayOrJson, !$success);
         }
     }
 }
コード例 #5
0
ファイル: Stats.php プロジェクト: andelux/landingpages
 /**
  * Register conversion
  *
  * @param $conversion_type
  *
  * @throws \Exception
  */
 public function conversion($conversion_type)
 {
     $id = self::getVisitId();
     // Get the visit info & record conversion type
     $visit = new Visits();
     $visit->saveConversion($id, $conversion_type);
     $template = $visit->getData('template');
     $variation = $visit->getData('variation');
     // Load stats info about template/variation
     $this->load(array('template' => $template, 'variation' => $variation));
     // Increment conversions counter
     $conversions = intval($this->getData('conversions')) + 1;
     $this->setData('conversions', $conversions);
     // Get current views
     $views = intval($this->getViews());
     $this->save();
     // Update conversion info, recalculating conversion rate & conversions counter (about conversion type)
     $conversions = new Conversions();
     $conversions->updateConversion($template, $variation, $conversion_type, $views);
 }
コード例 #6
0
ファイル: article.php プロジェクト: s-a-r-id/geograph-project
    $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>";
                }
            }
            $str = preg_replace('/, ([^\\,]*?)$/', ' and $1', implode(', ', $arr));
            $smarty->assign('moreCredits', $str);
コード例 #7
0
 /**
  * Gets the average reported wave direction
  *
  * @access public
  * @param integer $dir Degree of direction
  * @return array If reported returns degree/compass direction
  */
 function getMeanWaveDirection($dir)
 {
     $ary = array("degree" => "", "compass" => "");
     if ($dir != "MM") {
         $ary['degree'] = $dir;
         $ary['compass'] = Conversions::getCompassDirection($dir);
     }
     return $ary;
 }
コード例 #8
0
 /**
  * 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);
 }
コード例 #9
0
ファイル: object.php プロジェクト: kelvinmbwilo/cervical
 public function convertFromJson($object, $json)
 {
     $values = Utils::getArrayValue($json, $this->jsonFieldName);
     if (!is_array($values)) {
         Logs::warn('Looking for array (', $this->jsonFieldName, '), but found:', $values);
         return null;
     }
     $result = array();
     foreach ($values as $value) {
         $result[] = Conversions::createFromJSON($this->className, $value, false);
     }
     $fieldName = $this->objectFieldName;
     $object->{$fieldName} = $result;
 }
コード例 #10
0
<?php

require_once 'oneapi/client.php';
$json = '{"deliveryReceiptSubscription":{"callbackReference":{"callbackData":null,"notifyURL":"http://192.168.10.111/save_requests"},"resourceURL":"http://oneapi.infobip.com/1/smsmessaging/outbound/subscriptions/q1id6ksfc8"}}';
class TestClass_32749789 extends AbstractObject
{
    public $subscriptionId;
    public function __construct()
    {
        parent::__construct();
    }
}
Models::register('TestClass_32749789', new SubscriptionIdFieldConversionRule('subscriptionId', 'deliveryReceiptSubscription.resourceURL'));
$object = Conversions::createFromJSON('TestClass_32749789', $json, false);
assert($object);
assert($object->subscriptionId == 'q1id6ksfc8');
コード例 #11
0
ファイル: pi-h.php プロジェクト: jonlynch/pi-h
$raspberypi_stream = "tcp://localhost:30003";
//go and get the helicopter hex ids and mrmap ids
$json = file_get_contents('http://api.wmrt.org.uk/helicopter-callsigns');
$helicopters_array = json_decode($json);
$helicopters = [];
foreach ($helicopters_array as $helicopter_object) {
    $helicopters[$helicopter_object->local_name] = $helicopter_object->id;
}
if (count($helicopters) < 1) {
    die(date("Y-m-d H:i:s") . ' - unable to get list of helicopters shutting down' . PHP_EOL);
} else {
    echo date("Y-m-d H:i:s") . ' - pi-h started, ' . count($helicopters) . ' aircraft to be tracked.' . PHP_EOL;
}
$sent = [];
//need to convert from lat long to british national grid
$converter = new Conversions();
// This script runs for 24 hours.
// There should be a cron job to restart it if it is not running.
$end_time = time() + 24 * 60 * 60;
//connect to the stream from the raspberypi
$fp = stream_socket_client($raspberypi_stream, $errno, $errstr, 30);
if (!$fp) {
    die(date("Y-m-d H:i:s") . " - unable to connect to DUMP1090, shutting down." . PHP_EOL);
} else {
    //forever
    while (!feof($fp) and time() < $end_time) {
        //fetch a line of data
        $line = fgets($fp, 1024);
        $parts = explode(',', $line);
        //check if it is a helicopter
        if (!isset($parts[4]) || !array_key_exists($parts[4], $helicopters)) {
コード例 #12
0
ファイル: gpx.php プロジェクト: s-a-r-id/geograph-project
         $top = $y + $d;
         $bottom = $y - $d;
         $rectangle = "'POLYGON(({$left} {$bottom},{$right} {$bottom},{$right} {$top},{$left} {$top},{$left} {$bottom}))'";
         $sql_where .= "CONTAINS(GeomFromText({$rectangle}),point_xy)";
         //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;
         $sql_fields .= ", ((gs.x - {$x}) * (gs.x - {$x}) + (gs.y - {$y}) * (gs.y - {$y})) as dist_sqd";
         $sql_order = ' dist_sqd ';
         $sql = "SELECT grid_reference,x,y,imagecount {$sql_fields}\n\t\t\t\tFROM gridsquare gs\n\t\t\t\tWHERE {$sql_where}\n\t\t\t\tORDER BY {$sql_order}";
         $db = NewADOConnection($GLOBALS['DSN']);
         if (!$db) {
             die('Database connection failed');
         }
         $data = $db->getAll($sql);
         require_once 'geograph/conversions.class.php';
         $conv = new Conversions();
         foreach ($data as $q => $row) {
             list($data[$q]['lat'], $data[$q]['long']) = $conv->internal_to_wgs84($row['x'], $row['y']);
         }
         $smarty->assign_by_ref('data', $data);
         $smarty->assign_by_ref('searchdesc', $searchdesc);
     }
     header("Content-type: application/octet-stream");
     header("Content-Disposition: attachment; filename=\"Geograph-{$cacheid}.gpx\"");
     customExpiresHeader(3600 * 24 * 14, true);
     $smarty->display($template, $cacheid);
     exit;
 } else {
     init_session();
     //preserve the input at least
     $smarty->assign('gridref', stripslashes($_REQUEST['gridref']));
コード例 #13
0
ファイル: index.php プロジェクト: s-a-r-id/geograph-project
    $cacheid = 'mapper';
}
$smarty = new GeographPage();
if (isset($_REQUEST['centi'])) {
    $smarty->assign('centi', 1);
    $smarty->assign('extra', 'centi');
    $cacheid .= '|centi';
}
if (isset($_REQUEST['inner'])) {
    $template = 'mapper_iframe.tpl';
} else {
    $template = 'mapper.tpl';
}
if (!$smarty->is_cached($template, $cacheid)) {
    require_once 'geograph/conversions.class.php';
    $conv = new Conversions();
    $mapw = $mosaic->image_w / $mosaic->pixels_per_km / 2;
    list($e, $n) = $conv->internal_to_national($mosaic->map_x + $mapw, $mosaic->map_y + $mapw, 1);
    $smarty->assign('e', $e - 500);
    //remove centering
    $smarty->assign('n', $n - 500);
    switch ($mosaic->pixels_per_km) {
        case 1:
            $z = 0;
            break;
            //there isnt a direct equiv
        //there isnt a direct equiv
        case 4:
            $z = 0;
            break;
            //	case ??: $z = 1; break;
コード例 #14
0
ファイル: compare.php プロジェクト: s-a-r-id/geograph-project
    if ($USER->user_id) {
        $where = "user_id = ?";
        $a = array($USER->user_id);
    } else {
        $where = "user_id = 0 and `ipaddr` = INET_ATON(?) AND `ua` = ?";
        $a = array(getRemoteIP(), $_SERVER['HTTP_USER_AGENT']);
    }
    $pair = $db->getRow("\r\n\t\tSELECT p.compare_pair_id,gridimage_id1,gridimage_id2\r\n\t\tFROM compare_pair p\r\n\t\tLEFT JOIN compare_done d ON (p.compare_pair_id = d.compare_pair_id AND {$where})\r\n\t\tWHERE status != 'rejected' AND d.compare_pair_id IS NULL", $a);
}
if (!empty($pair['compare_pair_id'])) {
    $smarty->assign('pair_id', $pair['compare_pair_id']);
    $token = new Token();
    $token->setValue("p", $pair['compare_pair_id']);
    $smarty->assign('token', $token->getToken());
    require_once 'geograph/conversions.class.php';
    $conv = new Conversions();
    $image1 = new GridImage($pair['gridimage_id1']);
    if ($image1->moderation_status != 'rejected') {
        $rastermap1 = new RasterMap($image1->grid_square);
        if ($image1->view_direction > -1) {
            $smarty->assign('view_direction1', $image1->view_direction % 90 == 0 ? strtoupper(heading_string($image1->view_direction)) : ucwords(heading_string($image1->view_direction)));
        }
        list($lat, $long) = $conv->gridsquare_to_wgs84($image1->grid_square);
        $smarty->assign('lat1', $lat);
        $smarty->assign('long1', $long);
        list($latdm, $longdm) = $conv->wgs84_to_friendly($lat, $long);
        $smarty->assign('latdm1', $latdm);
        $smarty->assign('longdm1', $longdm);
        $smarty->assign_by_ref('image1', $image1);
        $smarty->assign_by_ref('rastermap1', $rastermap1);
    }
コード例 #15
0
 * 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';
init_session();
$USER->mustHavePerm("admin");
$smarty = new GeographPage();
$db = NewADOConnection($GLOBALS['DSN']);
$db2 = NewADOConnection($GLOBALS['DSN']);
require_once 'geograph/conversions.class.php';
$conv = new Conversions();
//this takes a long time, so we output a header first of all
$smarty->display('_std_begin.tpl');
?>
<h2>gridimage_search Rebuild Tool</h2>
<form action="buildgridimage_search.php" method="post">
<input type="checkbox" id="recreate" name="recreate" value="1" disabled>
<label for="recreate">Recreate entire gridimage_search table from gridimage table</label> THIS IS TOO DANGEROUS - disabled for your own safety<br>
&nbsp;<input type="checkbox" id="use_new" name="use_new" value="1" checked="checked">
<label for="use_new">Use multi-stage copy (recommended on a live site)</label><br>
<br>
<br>-and/or-<br>
<br>
<input type="checkbox" id="update" name="update" value="1"> <label for="update">Update lat/long values in gridimage_search</label><br>
<br><br>
<input type="submit" name="go" value="Start">
コード例 #16
0
 * 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/kmlfile.class.php';
require_once 'geograph/kmlfile2.class.php';
require_once 'geograph/conversions.class.php';
if (!isLocalIPAddress()) {
    init_session();
    $USER->mustHavePerm("admin");
}
$conv = new Conversions();
$db = NewADOConnection($GLOBALS['DSN']);
if (!$db) {
    die('Database connection failed');
}
$kml = new kmlFile();
$kml->atom = true;
$stylefile = "http://{$CONF['KML_HOST']}/kml/style.kmz";
$kml->filename = "Geograph-Members.kml";
$folder = $kml->addChild('Document');
$folder->setItem('name', "Geograph British Isles Members");
$users = $db->GetAssoc("select\r\n\t\tuser.user_id,nickname,user.realname,images,gs.x,gs.y,gs.reference_index\r\n\t\tfrom user\r\n\t\t\tleft join user_stat using (user_id)\r\n\t\t\tinner join gridsquare gs on (home_gridsquare = gridsquare_id)\r\n\t\torder by realname");
foreach ($users as $user_id => $user) {
    list($wgs84_lat, $wgs84_long) = $conv->internal_to_wgs84($user['x'], $user['y']);
    $point = new kmlPoint($wgs84_lat, $wgs84_long);
    $placemark = new kmlPlacemark($user_id, $user['realname'] . ' :: ' . $user['images'], $point);
コード例 #17
0
 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);
 } else {
     $offset = 0;
 }
 $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) . ")";
     }
コード例 #18
0
ファイル: index.php プロジェクト: s-a-r-id/geograph-project
$cacheid = $USER->hasPerm('basic') ? $USER->user_id : 0;
$isadmin = $USER->hasPerm('moderator') ? 1 : 0;
$smarty->assign_by_ref('isadmin', $isadmin);
$template = 'events.tpl';
if ($isadmin) {
    if (!empty($_GET['id']) && preg_match('/^\\d+$/', $_GET['id'])) {
        $db = NewADOConnection($GLOBALS['DSN']);
        $a = intval($_GET['approve']);
        $sql = "UPDATE geoevent SET approved = {$a} WHERE id = " . $db->Quote($_GET['id']);
        $db->Execute($sql);
        $smarty->clear_cache($template, $cacheid);
    }
}
if (!$smarty->is_cached($template, $cacheid)) {
    $smarty->assign('google_maps_api_key', $CONF['google_maps_api_key']);
    $db = NewADOConnection($GLOBALS['DSN']);
    $prev_fetch_mode = $ADODB_FETCH_MODE;
    $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
    $list = $db->getAll("\r\n\tselect geoevent.*,\r\n\t\trealname,\r\n\t\t(event_time > now()) as future,\r\n\t\tgrid_reference,x,y,\r\n\t\tsum(type='attend') as attendees\r\n\tfrom geoevent \r\n\t\tinner join user using (user_id)\r\n\t\tinner join gridsquare using (gridsquare_id)\r\n\t\tleft join geoevent_attendee using (geoevent_id)\r\n\twhere ((approved = 1) \r\n\t\tor user.user_id = {$USER->user_id}\r\n\t\tor ({$isadmin} and approved != -1)\r\n\t\t) and (event_time > date_sub(now(),interval 1 month) )\r\n\tgroup by geoevent_id\r\n\torder by future desc,event_time");
    $conv = new Conversions();
    $f = 0;
    foreach ($list as $i => $row) {
        if ($row['future']) {
            $f++;
        }
        list($list[$i]['wgs84_lat'], $list[$i]['wgs84_long']) = $conv->internal_to_wgs84($row['x'], $row['y']);
    }
    $smarty->assign('future', $f);
    $smarty->assign_by_ref('list', $list);
}
$smarty->display($template, $cacheid);
コード例 #19
0
}
$rss->title = 'Geograph Events';
$rss->link = "http://{$_SERVER['HTTP_HOST']}/article/";
$rss->description = "Upcoming Geograph British Isles Events";
if (empty($_GET['admin'])) {
    $isadmin = 0;
    $rss->syndicationURL = "http://{$_SERVER['HTTP_HOST']}/events/syndicator.php?format={$format}";
} else {
    $isadmin = 1;
    $rss->title = 'Geograph Pending Articles';
    $rss->syndicationURL = "http://{$_SERVER['HTTP_HOST']}/article/syndicator.php?format={$format}&amp;admin=1";
}
if ($format == 'KML' || $format == 'GeoRSS' || $format == 'GPX') {
    require_once 'geograph/conversions.class.php';
    require_once 'geograph/gridsquare.class.php';
    $conv = new Conversions();
    $rss->geo = true;
}
$db = NewADOConnection($GLOBALS['DSN']);
$sql = "select geoevent.*,\r\n\trealname,\r\n\t(event_time > now()) as future,\r\n\tgrid_reference,x,y\r\nfrom geoevent \r\n\tinner join user using (user_id)\r\n\tinner join gridsquare using (gridsquare_id)\r\nwhere (approved = 1 and event_time > now())\r\n\tor ({$isadmin} and approved != -1)\r\norder by event_time desc";
$recordSet =& $db->Execute($sql);
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) . "...";
    }
コード例 #20
0
<?php

require_once 'oneapi/client.php';
$json = '{"requestError":{"serviceException":{"text":"Request URI missing required component(s): ","messageId":"SVC0002","variables":[""]},"policyException":null}}';
$smsException = Conversions::createFromJSON('SmsException', $json, false);
assert($smsException);
assert($smsException->messageId == 'SVC0002');
assert($smsException->text == 'Request URI missing required component(s): ');
コード例 #21
0
ファイル: tile.php プロジェクト: s-a-r-id/geograph-project
    if ($rastermap->setToken($_GET['r'])) {
        if (isset($_GET['debug'])) {
            print $rastermap->getOSGBStorePath($rastermap->service, 0, 0, false);
        }
        if (isset($_GET['refresh']) && $_GET['refresh'] == 2 && $USER->hasPerm('admin')) {
            $rastermap->caching = false;
        }
        $rastermap->returnImage();
    }
    exit;
    /**************************
    * Mapper Tiles
    */
} elseif (isset($_GET['e']) && isset($_GET['n'])) {
    require_once 'geograph/conversions.class.php';
    $conv = new Conversions();
    /**************************
     * Debug Tiles
     */
    if (false) {
        ###############
        $w = 250;
        $img = imagecreate($w, $w);
        imagecolorallocate($img, 0, 0, 0);
        $colMarker = imagecolorallocate($img, 255, 255, 255);
        imagerectangle($img, 1, 1, $w, $w, $colMarker);
        imagestring($img, 1, 2, 2, $_GET['b'], $colMarker);
        $b = explode(',', $_GET['b']);
        $s = intval(($b[2] - $b[0]) / 1000);
        imagestring($img, 1, 20, 20, "{$s} km", $colMarker);
        imagestring($img, 1, 50, 50, "z=" . $_GET['z'], $colMarker);
コード例 #22
0
require_once 'geograph/global.inc.php';
require_once 'geograph/kmlfile.class.php';
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'];
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 = '';
コード例 #23
0
require_once 'geograph/global.inc.php';
require_once 'geograph/kmlfile.class.php';
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;
コード例 #24
0
<?php

require_once 'oneapi/client.php';
$json = '{"deliveryInfoList":{"deliveryInfo":[{"address":"38598123456","deliveryStatus":"DeliveredToTerminal"}],"resourceURL":"http://oneapi.infobip.com/1/smsmessaging/outbound/TODO/requests/ih5k7mm6dy/deliveryInfos"}}';
$deliveryInfoList = Conversions::createFromJSON('DeliveryInfoList', $json, false);
assert($deliveryInfoList);
assert(sizeof($deliveryInfoList->deliveryInfo) == 1);
assert($deliveryInfoList->deliveryInfo[0]->deliveryStatus == 'DeliveredToTerminal');
コード例 #25
0
 function _set($val)
 {
     $ary['year'] = $val[1];
     // YYYY
     $ary['month'] = $val[2];
     // MM
     $ary['day'] = $val[3];
     // DD
     $ary['hour'] = $val[4];
     // hh
     $ary['min'] = $val[5];
     // mm
     $ary['timestamp'] = mktime($val[4], $val[5], 0, $val[2], $val[3], $val[1]);
     $ary['wind_direction'] = Conversions::getWindDirection($val[6]);
     // WD
     $ary['wind_speed'] = Conversions::getWindSpeed($val[7]);
     // WSPD
     $ary['gusts'] = Conversions::getWindSpeed($val[8]);
     // GST
     $ary['wave_height'] = Conversions::getWaveHeight($val[9]);
     // WVHT
     $ary['dominant_wave_period'] = Conversions::getWavePeriod($val[10]);
     // DPD
     $ary['avg_wave_period'] = Conversions::getWavePeriod($val[11]);
     // APD
     $ary['mean_wave_direction'] = Conversions::getMeanWaveDirection($val[12]);
     // MWD
     $ary['barometer'] = Conversions::getBarometer($val[13]);
     // BARO
     $ary['air_temp'] = Conversions::getTemp($val[14]);
     // ATMP
     $ary['water_temp'] = Conversions::getTemp($val[15]);
     // WTMP
     $ary['dewpoint'] = Conversions::getTemp($val[16]);
     // DEWP
     $ary['visibility'] = Conversions::getVisibility($val[17]);
     // VIS
     $ary['pressure_tendency'] = Conversions::getPressureTrend($val[18]);
     // PTDY
     $ary['tide'] = Conversions::getTide(str_replace("|", "", $val[19]));
     // TIDE
     return $ary;
 }
コード例 #26
0
 function findPlacename($placename)
 {
     global $places;
     //only way to get the array into the compare functions
     global $USER;
     global $CONF, $memcache;
     $mkey = strtolower(trim($placename)) . '.v5';
     //need to invalidate the whole cache.
     //fails quickly if not using memcached!
     $places =& $memcache->name_get('g', $mkey);
     if ($places) {
         return $places;
     }
     $db = $this->_getDB();
     $ismore = 0;
     $placename = str_replace('?', '', $placename, $ismore);
     $places = array();
     if (is_numeric($placename)) {
         if ($placename > 10000000) {
             $places = $db->GetAll("select name as full_name,'PPL' as dsg, e, n, reference_index,'' as adm1_name from loc_towns where id=" . $db->Quote($placename - 10000000));
         } elseif ($placename > 1000000) {
             $places = $db->GetAll("select `def_nam` as full_name,'PPL' as dsg,`east` as e,`north` as n,1 as reference_index,`full_county` as adm1_name from os_gaz where seq=" . $db->Quote($placename - 1000000));
         } else {
             $places = $db->GetAll("select full_name,dsg,e,n,loc_placenames.reference_index,loc_adm1.name as adm1_name from loc_placenames left join loc_adm1 on (loc_placenames.adm1 = loc_adm1.adm1 and  loc_adm1.country = loc_placenames.country) where id=" . $db->Quote($placename));
         }
     } elseif (!$ismore) {
         list($placename, $county) = preg_split('/\\s*,\\s*/', $placename);
         if (!empty($county)) {
             $qcount = $db->Quote($county);
             $places = $db->GetAll("select `def_nam` as full_name,'PPL' as dsg,`east` as e,`north` as n,1 as reference_index,`full_county` as adm1_name,code_name as dsg_name,(seq + 1000000) as id,km_ref as gridref from os_gaz inner join os_gaz_code using (f_code) where def_nam=" . $db->Quote($placename) . " and (full_county = {$qcount} OR hcounty = {$qcount})");
         } else {
             $qplacename = $db->Quote($placename);
             $sql_where = "def_nam={$qplacename}";
             $sql_where2 = "full_name={$qplacename}";
             if (strpos($placename, ' ') !== FALSE) {
                 $county = $db->getOne("select `name` from os_gaz_county where {$qplacename} LIKE CONCAT('%',name)");
                 if (!empty($county)) {
                     $qcount = $db->Quote($county);
                     $placename = preg_replace("/\\s+{$county}/i", '', $placename);
                     $qplacename = $db->Quote($placename);
                     $sql_where .= " or (def_nam={$qplacename} and full_county = {$qcount})";
                     $sql_where2 .= " or full_name={$qplacename}";
                     //we cant search easily on county here!
                 }
             }
             //todo need to 'union'  with other gazetterr! (as if one match in each then will no work!)
             $places = $db->GetAll("select `def_nam` as full_name,'PPL' as dsg,`east` as e,`north` as n,1 as reference_index,`full_county` as adm1_name,code_name as dsg_name,(seq + 1000000) as id,km_ref as gridref from os_gaz inner join os_gaz_code using (f_code) where {$sql_where}");
             if (count($places) == 0) {
                 $places = $db->GetAll("select full_name,dsg,e,n,reference_index,id,loc_dsg.name as dsg_name from loc_placenames inner join loc_dsg on (loc_placenames.dsg = loc_dsg.code) where full_name={$qplacename}");
                 if ($c = count($places)) {
                     require_once 'geograph/conversions.class.php';
                     $conv = new Conversions();
                     foreach ($places as $id => $row) {
                         if (empty($row['gridref'])) {
                             list($places[$id]['gridref'], ) = $conv->national_to_gridref($row['e'], $row['n'], 4, $row['reference_index']);
                         }
                         $places[$id]['full_name'] = _utf8_decode($row['full_name']);
                     }
                 }
             }
         }
     }
     if (count($places) == 1) {
         #we done!
     } else {
         $limit = strlen($placename) > 3 ? 60 : 20;
         $limi2 = 40;
         if ($USER->registered) {
             $limit *= 2;
             $limi2 *= 2;
         }
         //starts with (both gaz's)
         $places = $db->GetAll($sql = "\r\n\t\t\t(select\r\n\t\t\t\t(seq + 1000000) as id,\r\n\t\t\t\t`def_nam` as full_name,\r\n\t\t\t\t'PPL' as dsg,`east` as e,`north` as n,\r\n\t\t\t\tcode_name as dsg_name,\r\n\t\t\t\t1 as reference_index,\r\n\t\t\t\t`full_county` as adm1_name,\r\n\t\t\t\t`hcounty` as hist_county,\r\n\t\t\t\tkm_ref as gridref\r\n\t\t\tfrom \r\n\t\t\t\tos_gaz\r\n\t\t\t\tinner join os_gaz_code using (f_code)\r\n\t\t\twhere\r\n\t\t\t\tos_gaz.f_code IN ('C','T','O') AND\r\n\t\t\t\t`def_nam` LIKE " . $db->Quote($placename . '%') . "\r\n\t\t\tlimit {$limit}) UNION\r\n\t\t\t(select \r\n\t\t\t\tid, \r\n\t\t\t\tfull_name,\r\n\t\t\t\tdsg,e,n,\r\n\t\t\t\tloc_dsg.name as dsg_name,\r\n\t\t\t\tloc_placenames.reference_index,\r\n\t\t\t\tloc_adm1.name as adm1_name,\r\n\t\t\t\t'' as hist_county,\r\n\t\t\t\t'' as gridref\r\n\t\t\tfrom \r\n\t\t\t\tloc_placenames\r\n\t\t\t\tinner join loc_dsg on (loc_placenames.dsg = loc_dsg.code) \r\n\t\t\t\tleft join loc_adm1 on (loc_placenames.adm1 = loc_adm1.adm1 and  loc_adm1.country = loc_placenames.country)\r\n\t\t\twhere\r\n\t\t\t\tdsg LIKE 'PPL%' AND loc_placenames.reference_index != 1 AND\r\n\t\t\t\tfull_name LIKE " . $db->Quote($placename . '%') . "\r\n\t\t\tgroup by gns_ufi\r\n\t\t\tLIMIT {$limit})");
         if (isset($_GET['debug'])) {
             print "<pre>{$sql}</pre>count = " . count($places) . "<hr>";
         }
         if (count($places) < 10 || $ismore) {
             //sounds like (OS)
             $places = array_merge($places, $db->GetAll("\r\n\t\t\t\tselect\r\n\t\t\t\t\t(seq + 1000000) as id,\r\n\t\t\t\t\t`def_nam` as full_name,\r\n\t\t\t\t\t'PPL' as dsg,`east` as e,`north` as n,\r\n\t\t\t\t\tcode_name as dsg_name,\r\n\t\t\t\t\t1 as reference_index,\r\n\t\t\t\t\t`full_county` as adm1_name,\r\n\t\t\t\t\t`hcounty` as hist_county,\r\n\t\t\t\t\tkm_ref as gridref\r\n\t\t\t\tfrom \r\n\t\t\t\t\tos_gaz\r\n\t\t\t\t\tinner join os_gaz_code using (f_code)\r\n\t\t\t\twhere\r\n\t\t\t\t\tos_gaz.f_code IN ('C','T','O') AND\r\n\t\t\t\t\tdef_nam_soundex = SOUNDEX(" . $db->Quote($placename) . ") AND\r\n\t\t\t\t\tdef_nam NOT LIKE " . $db->Quote($placename . '%') . "\r\n\t\t\t\tlimit {$limi2}"));
             if (isset($_GET['debug'])) {
                 print "<pre>{$sql}</pre>count = " . count($places) . "<hr>";
             }
         }
         if (count($places) < 10 || $ismore) {
             //contains (OS)
             $places = array_merge($places, $db->GetAll($sql = "\r\n\t\t\t\tselect\r\n\t\t\t\t\t(seq + 1000000) as id,\r\n\t\t\t\t\t`def_nam` as full_name,\r\n\t\t\t\t\t'PPL' as dsg,`east` as e,`north` as n,\r\n\t\t\t\t\tcode_name as dsg_name,\r\n\t\t\t\t\t1 as reference_index,\r\n\t\t\t\t\t`full_county` as adm1_name,\r\n\t\t\t\t\t`hcounty` as hist_county,\r\n\t\t\t\t\tkm_ref as gridref\r\n\t\t\t\tfrom \r\n\t\t\t\t\tos_gaz\r\n\t\t\t\t\tinner join os_gaz_code using (f_code)\r\n\t\t\t\twhere\r\n\t\t\t\t\tos_gaz.f_code IN ('C','T','O') AND\r\n\t\t\t\t\t`def_nam` LIKE " . $db->Quote('%' . $placename . '%') . " AND\r\n\t\t\t\t\t`def_nam` NOT LIKE " . $db->Quote($placename . '%') . "\r\n\t\t\t\tlimit {$limi2}"));
             if (isset($_GET['debug'])) {
                 print "{$limi2}<pre>{$sql}</pre>count = " . count($places) . "<hr>";
             }
         }
         if (count($places) < 10 || $ismore) {
             //search the widest possible
             $places2 = $db->GetAll($sql = "\r\n\t\t\t\t(select\r\n\t\t\t\t\t(seq + 1000000) as id,\r\n\t\t\t\t\t`def_nam` as full_name,\r\n\t\t\t\t\t'PPL' as dsg,`east` as e,`north` as n,\r\n\t\t\t\t\tcode_name as dsg_name,\r\n\t\t\t\t\t1 as reference_index,\r\n\t\t\t\t\t`full_county` as adm1_name,\r\n\t\t\t\t\t`hcounty` as hist_county,\r\n\t\t\t\t\tkm_ref as gridref\r\n\t\t\t\tfrom \r\n\t\t\t\t\tos_gaz\r\n\t\t\t\t\tinner join os_gaz_code using (f_code)\r\n\t\t\t\twhere\r\n\t\t\t\t\tos_gaz.f_code NOT IN ('C','T','O') AND\r\n\t\t\t\t\t( `def_nam` LIKE " . $db->Quote('%' . $placename . '%') . "\r\n\t\t\t\t\tOR def_nam_soundex = SOUNDEX(" . $db->Quote($placename) . ") )\r\n\t\t\t\torder by \r\n\t\t\t\t\tdef_nam = " . $db->Quote($placename) . " desc,\r\n\t\t\t\t\tdef_nam_soundex = SOUNDEX(" . $db->Quote($placename) . ") desc\r\n\t\t\t\tlimit {$limi2}) UNION\r\n\t\t\t\t(select \r\n\t\t\t\t\tid, \r\n\t\t\t\t\tfull_name,\r\n\t\t\t\t\tdsg,e,n,\r\n\t\t\t\t\tloc_dsg.name as dsg_name,\r\n\t\t\t\t\tloc_placenames.reference_index,\r\n\t\t\t\t\tloc_adm1.name as adm1_name,\r\n\t\t\t\t\t'' as hist_county,\r\n\t\t\t\t\t'' as gridref\r\n\t\t\t\tfrom \r\n\t\t\t\t\tloc_placenames\r\n\t\t\t\t\tinner join loc_dsg on (loc_placenames.dsg = loc_dsg.code) \r\n\t\t\t\t\tleft join loc_adm1 on (loc_placenames.adm1 = loc_adm1.adm1 and  loc_adm1.country = loc_placenames.country)\r\n\t\t\t\twhere\r\n\t\t\t\t\tfull_name LIKE " . $db->Quote('%' . $placename . '%') . "\r\n\t\t\t\t\tOR full_name_soundex = SOUNDEX(" . $db->Quote($placename) . ")\r\n\t\t\t\tgroup by gns_ufi\r\n\t\t\t\torder by \r\n\t\t\t\t\tfull_name = " . $db->Quote($placename) . " desc,\r\n\t\t\t\t\tfull_name_soundex = SOUNDEX(" . $db->Quote($placename) . ") desc\r\n\t\t\t\tLIMIT {$limi2})");
             if (isset($_GET['debug'])) {
                 print "<pre>{$sql}</pre>count2 = " . count($places2) . "<hr>";
             }
             if (count($places2)) {
                 if (count($places)) {
                     foreach ($places2 as $i2 => $place2) {
                         $found = 0;
                         $look = str_replace("-", ' ', $place2['full_name']);
                         foreach ($places as $i => $place) {
                             if ($place['full_name'] == $look && $place['reference_index'] == $place2['reference_index'] && ($d = pow($place['e'] - $place2['e'], 2) + pow($place['n'] - $place2['n'], 2)) && $d < 5000 * 5000) {
                                 $found = 1;
                                 break;
                             }
                         }
                         if (!$found) {
                             array_push($places, $place2);
                         }
                     }
                 } else {
                     $places =& $places2;
                 }
             }
         }
         # loc_towns
         if (count($places) < 10 || $ismore) {
             //search the widest possible
             //km_ref as gridref
             //county from loc_hier?
             //	`full_county` as adm1_name,
             $places2 = $db->GetAll($sql = "\r\n\t\t\t\tselect\r\n\t\t\t\t\t(id + 10000000) as id,\r\n\t\t\t\t\tname as full_name,\r\n\t\t\t\t\t'PPL' as dsg, e, n,\r\n\t\t\t\t\t'' as dsg_name,\r\n\t\t\t\t\treference_index,\r\n\t\t\t\t\t'' as adm1_name,\r\n\t\t\t\t\t'' as hist_county,\r\n\t\t\t\t\t'' as gridref\r\n\t\t\t\tfrom \r\n\t\t\t\t\tloc_towns\r\n\t\t\t\twhere\r\n\t\t\t\t\t( name LIKE " . $db->Quote('%' . $placename . '%') . "\r\n\t\t\t\t\tOR name SOUNDS LIKE " . $db->Quote($placename) . ")\r\n\t\t\t\torder by \r\n\t\t\t\t\tname = " . $db->Quote($placename) . " desc,\r\n\t\t\t\t\tname SOUNDS LIKE " . $db->Quote($placename) . " desc\r\n\t\t\t\tlimit {$limi2}");
             if (isset($_GET['debug'])) {
                 print "<pre>{$sql}</pre>count2 = " . count($places2) . "<hr>";
             }
             if (count($places2)) {
                 if (count($places)) {
                     foreach ($places2 as $i2 => $place2) {
                         $found = 0;
                         $look = str_replace("-", ' ', $place2['full_name']);
                         foreach ($places as $i => $place) {
                             if ($place['full_name'] == $look && $place['reference_index'] == $place2['reference_index'] && ($d = pow($place['e'] - $place2['e'], 2) + pow($place['n'] - $place2['n'], 2)) && $d < 5000 * 5000) {
                                 $found = 1;
                                 break;
                             }
                         }
                         if (!$found) {
                             array_push($places, $place2);
                         }
                     }
                 } else {
                     $places =& $places2;
                 }
             }
         }
         if ($c = count($places)) {
             require_once 'geograph/conversions.class.php';
             $conv = new Conversions();
             foreach ($places as $id => $row) {
                 if (empty($row['gridref'])) {
                     list($places[$id]['gridref'], ) = $conv->national_to_gridref($row['e'], $row['n'], 4, $row['reference_index']);
                 }
                 $places[$id]['full_name'] = _utf8_decode($row['full_name']);
             }
             if ($c > 14) {
                 $placename = strtolower($placename);
                 foreach ($places as $id => $row) {
                     $p1 = strtolower($row['full_name']);
                     if (strpos($p1, $placename) === FALSE && levenshtein(strtolower($p1), $placename) > strlen($row['full_name']) / 2) {
                         unset($places[$id]);
                     }
                 }
             }
         }
     }
     //fails quickly if not using memcached!
     $memcache->name_set('g', $mkey, $places, $memcache->compress, $memcache->period_long);
     return $places;
 }
コード例 #27
0
 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);
     }
 }
コード例 #28
0
ファイル: browse.php プロジェクト: s-a-r-id/geograph-project
     if ($CONF['forums']) {
         $square->assignDiscussionToSmarty($smarty);
     }
     if (!empty($CONF['sphinx_host'])) {
         //look for images from here...
         $sphinx = new sphinxwrapper();
         if (!isset($viewpoint_count) && ($viewpoint_count = $sphinx->countImagesViewpoint($square->nateastings, $square->natnorthings, $square->reference_index, $square->grid_reference))) {
             $smarty->assign('viewpoint_count', $viewpoint_count);
             #$smarty->assign('viewpoint_query', $sphinx->q);
         }
         if (!isset($mention_count) && ($mention_count = $sphinx->countQuery("{$square->grid_reference} -grid_reference:{$square->grid_reference}", "_images"))) {
             $smarty->assign('mention_count', $mention_count);
         }
     }
     if ($square->natspecified && $square->natgrlen >= 6) {
         $conv = new Conversions('');
         list($gr6, $len) = $conv->national_to_gridref($square->getNatEastings(), $square->getNatNorthings(), 6, $square->reference_index, false);
         $smarty->assign('gridref6', $gr6);
     }
 } else {
     $smarty->assign('errormsg', $square->errormsg);
     //includes a closest match?
     if (is_object($square->nearest)) {
         $smarty->assign('nearest_distance', $square->nearest->distance);
         $smarty->assign('nearest_gridref', $square->nearest->grid_reference);
         if (!empty($square->x) && !empty($square->y) && $square->nearest->distance < 15) {
             //we where still able to work out the location, so
             //get a token to show a suroudding geograph map
             $mosaic = new GeographMapMosaic();
             $smarty->assign('map_token', $mosaic->getGridSquareToken($square));
         }
コード例 #29
0
    function _plotPlacenames(&$img, $scanleft, $scanbottom, $scanright, $scantop, $bottom, $left)
    {
        $db =& $this->_getDB();
        $black = imagecolorallocate($img, 0, 64, 0);
        require_once 'geograph/conversions.class.php';
        $conv = new Conversions();
        if (!$this->reference_index) {
            $this->getGridRef(-1, -1);
            if (!$this->reference_index) {
                $this->getGridRef(-1, -1);
                $this->reference_index = 1;
            }
        }
        $reference_index = $this->reference_index;
        $gridcol = imagecolorallocate($img, 109, 186, 178);
        list($natleft, $natbottom) = $conv->internal_to_national($scanleft, $scanbottom, $reference_index);
        list($natright, $nattop) = $conv->internal_to_national($scanright, $scantop, $reference_index);
        if ($this->pixels_per_km < 1) {
            $div = 500000;
            //1 per 500k square
            $crit = "s = '1' AND";
            $cityfont = 3;
        } elseif ($this->pixels_per_km == 1) {
            $div = 100000;
            $crit = "(s = '1' OR s = '2') AND";
            $cityfont = 3;
        } elseif ($this->pixels_per_km == 4) {
            $div = 30000;
            #	$crit = "(s = '1' OR s = '2') AND";
            $cityfont = 3;
        } else {
            $div = 10000;
            $cityfont = 3;
        }
        $intleft = $scanleft * 1000;
        $intright = $scanright * 1000;
        $intbottom = $scanbottom * 1000;
        $inttop = $scantop * 1000;
        $rectangle = "'POLYGON(({$natleft} {$natbottom},{$natright} {$natbottom},{$natright} {$nattop},{$natleft} {$nattop},{$natleft} {$natbottom}))'";
        $rectanglexy = "'POLYGON(({$intleft} {$intbottom},{$intright} {$intbottom},{$intright} {$inttop},{$intleft} {$inttop},{$intleft} {$intbottom}))'";
        if ($reference_index == 1 || $reference_index == 2 && $this->pixels_per_km == 1 || $reference_index >= 3) {
            //$countries = "'EN','WA','SC'";
            $sql = <<<END
SELECT name,e,n,s,quad,reference_index
FROM loc_towns
WHERE 
 {$crit}
CONTAINS( GeomFromText({$rectanglexy}),\tpoint_xy) 
ORDER BY s
END;
            #GROUP BY FLOOR(e/$div),FLOOR(n/$div)
        } else {
            $countries = "'NI','RI'";
            $div *= 1.5;
            //becuase the irish data is more dence
            $sql = <<<END
SELECT e,n,full_name as name,reference_index
FROM loc_placenames
INNER JOIN `loc_wikipedia` ON ( full_name = text ) 
WHERE dsg = 'PPL' AND
loc_wikipedia.country IN ({$countries}) AND 
CONTAINS( GeomFromText({$rectangle}),\tpoint_en) 
GROUP BY gns_ufi
ORDER BY RAND()
END;
        }
        $squares = array();
        $recordSet =& $db->Execute($sql);
        while (!$recordSet->EOF) {
            $e = $recordSet->fields['e'];
            $n = $recordSet->fields['n'];
            $str = floor($e / $div) . ' ' . floor($n / $div * 1.4);
            if (!$squares[$str]) {
                // || $recordSet->fields['s'] ==1) {
                $squares[$str]++;
                list($x, $y) = $conv->national_to_internal($e, $n, $recordSet->fields['reference_index']);
                $imgx1 = ($x - $left) * $this->pixels_per_km;
                $imgy1 = $this->image_h - ($y - $bottom + 1) * $this->pixels_per_km;
                if ($this->pixels_per_km <= 4) {
                    imagefilledrectangle($img, $imgx1 - 1, $imgy1 - 2, $imgx1 + 1, $imgy1 + 2, $black);
                    imagefilledrectangle($img, $imgx1 - 2, $imgy1 - 1, $imgx1 + 2, $imgy1 + 1, $black);
                }
                $font = $recordSet->fields['s'] == 1 ? $cityfont : 2;
                $img1 = $this->_posText($imgx1, $imgy1, $font, $recordSet->fields['name'], $recordSet->fields['quad']);
                if (count($img1)) {
                    imageGlowString($img, $font, $img1[0], $img1[1], $recordSet->fields['name'], $gridcol);
                }
            }
            $recordSet->MoveNext();
        }
        if ($_GET['d']) {
            exit;
        }
        $recordSet->Close();
    }
コード例 #30
0
require_once 'geograph/gridsquare.class.php';
init_session();
$smarty = new GeographPage();
$type = isset($_GET['type']) && preg_match('/^\\w+$/', $_GET['type']) ? $_GET['type'] : 'center';
$template = 'explore_counties.tpl';
$cacheid = 'explore|counties' . $type;
$smarty->cache_lifetime = 3600 * 24;
//24hr cache
if (!$smarty->is_cached($template, $cacheid)) {
    $db = NewADOConnection($GLOBALS['DSN']);
    if (!$db) {
        die('Database connection failed');
    }
    #$db->debug = true;
    require_once 'geograph/conversions.class.php';
    $conv = new Conversions();
    if ($type == 'center') {
        $smarty->assign("page_title", "Ceremonial County Centre Points");
        $smarty->assign("start_info", "See <a href=\"#notes\">bottom</a> of page for clarification of Ceremonial or Geographic Counties as used on this page");
        $smarty->assign("extra_info", "<a name=\"notes\"/>* this pages uses counties from 1995, making them now known as  <a href=\"http://en.wikipedia.org/wiki/Ceremonial_counties_of_England\">Ceremonial or Geographic Counties</a> and for some unknown reason Northern Ireland is just one entity. Furthermore only counties that happen to have their calculated 'centre of bounding box' on land will be included in this list (eg Cornwall doesn't), see blue triangles on this <a href=\"http://www.deformedweb.co.uk/trigs/map.cgi?w=600&amp;b=500&amp;e=400000&amp;n=400000&amp;x=d&amp;l=0&amp;hg=1&amp;x=c\">map</a>.");
        $counties = $db->GetAll("select * from loc_counties where n > 0 order by reference_index,n");
    } elseif ($type == 'pre74') {
        $smarty->assign("page_title", "Historic County (Pre 1974) Centre Points");
        $smarty->assign("start_info", "These are approximate centres for counties pre 1974 re-shuffle");
        $counties = $db->GetAll("select * from loc_counties_pre74 where n > 0 order by reference_index,n");
    } elseif ($type == 'modern') {
        $smarty->assign("page_title", "Modern Administrative County Centre Points");
        $smarty->assign("start_info", "These are approximate centres for modern administrative counties.");
        $smarty->assign("extra_info", "<div class=\"copyright\">Great Britain locations based upon Ordnance Survey&reg 1:50 000 Scale Gazetteer with the permission of Ordnance Survey on behalf of The Controller of Her Majesty's Stationery Office, &copy; Crown copyright. Educational licence 100045616.</div>");
        $counties = $db->GetAll("select * from os_gaz_county where n > 0 and name not like 'XX%' order by reference_index,n");
    } elseif ($type == 'capital') {