Skip to content

Instantly share code, notes, and snippets.

@seyfro
Created November 5, 2010 09:15
Show Gist options
  • Save seyfro/663861 to your computer and use it in GitHub Desktop.
Save seyfro/663861 to your computer and use it in GitHub Desktop.
Webservice for Wikitude/Wordpress-Integration #augmented-reality
<?php
/*
Name: Wikitude-Webservice for WordPress
Description: Provides a webservice for the augmented-reality-browser Wikitude (http://www.wikitude.org)
Requirements: self hosted WordPress and plugin WP-Geo (http://www.wpgeo.com/)
Webservice documentation URI: http://www.ihrwebprofi.at/wikitude-wordpress
Author: Robert Harm
Author URI: http://www.harm.co.at
Version: 1.0
Last Update: 23.10.2010
License: Creative Commons Attribution 3.0 Austria Licence (http://creativecommons.org/licenses/by/3.0/at/deed.en_GB)
*/
/***********************************/
/*Configuration */
/***********************************/
//database connection - can be found in WordPress config file /wp-config.php too
$DB_HOST = "localhost"; // REQUIRED - database host, in most cases localhost
$DB_NAME = ""; // REQUIRED - name of your wordpress database
$DB_USER = ""; // REQUIRED - mysql-username for accessing the database
$DB_PASSWORD = ""; // REQUIRED - password for accessing the database
$DB_PREFIX = "wp_"; // REQUIRED - wordpress-table-prefix - wp_ is standard
//Wikitude parameters - referencing documents:
//ARML Specification for Wikitude 4 (http://www.openarml.org/wikitude4.html)
//Wikitude Webservice Documentation (http://wikitude.me/assets/WikitudeWebservice.pdf)
$arprovider = "robertharm-places-vienna"; //REQUIRED - no spaces/special characters , identifies the content provider or content channel. Must be unique across all providers
$arname = "My favorite places in Vienna"; //REQUIRED - name of the content provider. This name will be used to display the content provider in the settings and bookmarks menu of the browser
$ardescription = "My favorite places in Vienna you should visit"; //optional - description of a content provider that provides additional information about the content displayed
$wtproviderurl = "http://[LINK TO YOUR SITE]"; //optional - link to the content provider
$wttags = "Vienna,photos,sightseeing"; //optional - comma separated list of keywords that characterize the content provider
$wtlogo = "http://[LINK TO YOUR LOGO].png"; //optional - logo displayed on the left bottom corner on Wikitude when an icon is selected - 96x96 pixel, transparent PNG
$wticon = "http://[LINK TO YOUR ICON].png"; //optional - the icons are displayed in the cam view of Wikitude to indicate a point of interest (POI) - 32x32 pixel, transparent PNG
$wtthumbnail = "http://[LINK TO YOUR THUMBNAIL].png"; // optional - leave empty if not used; Specific POI image that is displayed in the bubble. This could be for instance a hotel picture for a hotel booking content provider - 64x64 pixel, PNG
$wtemail = ""; //optional - displayed on each POI; used for sending an email directly from Wikitude
$wtphone = ""; //optional - example: +4312345 - when a phone number is given, Wikitude displays a "call me" button in the bubble; same phone number for each POI!
$wtattachment = ""; //optional - displayed on each POI; can be a link to a resource (image, PDF file...). You could use this to issue coupons or vouchers for potential clients that found you via Wikitude.
$radiusSet = "50000"; //REQUIRED - retrieve POIs (Points of Interests) from database within this search radius in meters from the current location of the Wikitude user
$maxNumerofPoisSet = "50"; //REQUIRED - used if Wikitude doesnt pass the variable maxNumberofPois - 50 is the maximum recommended
$latStandard = "48.209206"; //optional - for testing/debug: standard-latitude for calling webservice without parameters
$lonStandard = "16.372778"; //optional - for testing/debug: standard-longitude for calling webservice without parameters
/*********************************/
/*No need to edit below this line*/
/*********************************/
// variables for tables with custom prefix for SQL-Queries
$tabpostmeta = $DB_PREFIX . 'postmeta';
$tabposts = $DB_PREFIX . 'posts';
/* soak in the passed variable or use our own */
$maxNumberOfPois = isset($_GET['maxNumberOfPois']) ? intval($_GET['maxNumberOfPois']) : $maxNumerofPoisSet;
$latUser = isset($_GET['latitude']) ? floatval($_GET['latitude']) : $latStandard;
$lonUser = isset($_GET['longitude']) ? floatval($_GET['longitude']) : $lonStandard;
$radius = $radiusSet;
$distanceLLA = 0.01 * $radius / 1112;
$boundingBoxLatitude1 = $latUser - $distanceLLA;
$boundingBoxLatitude2 = $latUser + $distanceLLA;
$boundingBoxLongitude1 = $lonUser - $distanceLLA;
$boundingBoxLongitude2 = $lonUser + $distanceLLA;
/* connect to the db */
$link = mysql_connect($DB_HOST,$DB_USER,$DB_PASSWORD) or die('Cannot connect to the Database');
mysql_select_db($DB_NAME,$link) or die('Cannot select the Database');
isset($_GET['searchterm']) ? $searchterm = mysql_real_escape_string($_GET['searchterm']) : $searchterm = NULL;
/* grab the POIs from the db */
if ($searchterm != NULL)
{
$query = "SELECT
p.ID AS id,
p.post_title AS name,
p.post_content AS description,
concat(pm1.meta_value,',',pm2.meta_value) AS adress,
p.guid AS url,
concat(pm1.meta_value,',',pm2.meta_value) AS coordinates
FROM $tabposts p
INNER JOIN $tabpostmeta pm1 ON p.ID = pm1.post_id AND pm1.meta_key = '_wp_geo_longitude'
INNER JOIN $tabpostmeta pm2 ON p.ID = pm2.post_id AND pm2.meta_key = '_wp_geo_latitude'
WHERE pm2.meta_value BETWEEN '$boundingBoxLatitude1'
AND '$boundingBoxLatitude2'
AND pm1.meta_value BETWEEN '$boundingBoxLongitude1'
AND '$boundingBoxLongitude2'
AND p.post_status= 'publish'
AND (p.post_title like '%$searchterm%' OR p.post_content like '%$searchterm%')
limit $maxNumberOfPois";
}
else
{
$query = "SELECT
p.ID AS id,
p.post_title AS name,
p.post_content AS description,
concat(pm1.meta_value,',',pm2.meta_value) AS adress,
p.guid AS url,
concat(pm1.meta_value,',',pm2.meta_value) AS coordinates
FROM $tabposts p
INNER JOIN $tabpostmeta pm1 ON p.ID = pm1.post_id AND pm1.meta_key = '_wp_geo_longitude'
INNER JOIN $tabpostmeta pm2 ON p.ID = pm2.post_id AND pm2.meta_key = '_wp_geo_latitude'
WHERE pm2.meta_value BETWEEN '$boundingBoxLatitude1'
AND '$boundingBoxLatitude2'
AND pm1.meta_value BETWEEN '$boundingBoxLongitude1'
AND '$boundingBoxLongitude2'
AND p.post_status= 'publish'
limit $maxNumberOfPois";
}
$result = mysql_query($query,$link) or die('Errant query: '.$query);
/* start output */
header('Content-type: text/xml; charset=utf-8');
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<a name="2.0"><kml xmlns="http://www.opengis.net/kml/2.2" xmlns:ar="http://www.openarml.org/arml/1.0" xmlns:wikitude="http://www.openarml.org/wikitude/1.0" xmlns:wikitudeInternal="http://www.openarml.org/wikitudeInternal/1.0">';
echo '<Document>';
echo '<ar:provider id="'.$arprovider.'">';
echo '<ar:name><![CDATA['.$arname.']]></ar:name>';
echo '<ar:description><![CDATA['.$ardescription.']]></ar:description>';
echo '<wikitude:providerUrl><![CDATA['.$wtproviderurl.']]></wikitude:providerUrl>';
echo '<wikitude:tags><![CDATA['.$wttags.']]></wikitude:tags>';
echo '<wikitude:logo><![CDATA['.$wtlogo.']]></wikitude:logo>';
echo '<wikitude:icon><![CDATA['.$wticon.']]></wikitude:icon>';
echo '</ar:provider>';
while($value = mysql_fetch_assoc($result)) {
if(is_array($value)) {
echo '<Placemark id=\''.$value['id'].'\'>';
echo '<ar:provider><![CDATA['.utf8_encode($arprovider).']]></ar:provider>';
echo '<name><![CDATA['.utf8_encode($value['name']).']]></name>';
echo '<description><![CDATA['.utf8_encode(strip_tags($value['description'])).']]></description>';
echo '<wikitude:info>';
echo '<wikitude:thumbnail><![CDATA['.utf8_encode($wtthumbnail).']]></wikitude:thumbnail>';
echo '<wikitude:phone><![CDATA['.utf8_encode($wtphone).']]></wikitude:phone>';
echo '<wikitude:url><![CDATA['.utf8_encode($value['url']).']]></wikitude:url>';
echo '<wikitude:email><![CDATA['.utf8_encode($wtemail).']]></wikitude:email>';
echo '<wikitude:address><![CDATA['.utf8_encode($value['adress']).']]></wikitude:address>';
echo '<wikitude:attachment><![CDATA['.utf8_encode($wtattachment).']]></wikitude:attachment>';
echo '</wikitude:info>';
echo '<Point>';
echo '<coordinates><![CDATA['.$value['coordinates'].']]></coordinates>';
echo '</Point>';
echo '</Placemark>';
}
}
echo '</Document>';
echo '</kml>';
echo '</a>';
/* disconnect from the db */
@mysql_close($link);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment