Added:
/trunk/plugin/wp-exhibit-geocode.php
Modified:
/trunk/plugin/configurator/configurator.js.php
/trunk/plugin/configurator/exhibit-configurator.php
/trunk/plugin/configurator/exhibit-inputbox-view-map.php
/trunk/plugin/head-datasources.php
/trunk/plugin/model/view.php
/trunk/plugin/wp-exhibit-activation-tools.php
/trunk/plugin/wp-exhibit-admin-options.php
/trunk/plugin/wp-exhibit-geocoder.php
/trunk/plugin/wp-exhibit-save-post.php
=======================================
--- /dev/null
+++ /trunk/plugin/wp-exhibit-geocode.php Wed Mar 30 12:05:17 2011
@@ -0,0 +1,23 @@
+<?php
+ob_start();
+$root = dirname(dirname(dirname(dirname(__FILE__))));
+ if (file_exists($root.'/wp-load.php')) {
+ // WP 2.6
+ require_once($root.'/wp-load.php');
+ } else {
+ // Before 2.6
+ require_once($root.'/wp-config.php');
+ }
+ob_end_clean(); //Ensure we don't have output from other plugins.
+
+require_once('wp-exhibit-geocoder.php');
+if(isset($_GET['exhibit-id'])) {
+ header('Content-type: application/json');
+ echo WpExhibitGeocoder::json_for($_GET['exhibit-id']);
+} else if (isset($_POST['exhibitid']) and isset($_POST['datumids']) and
isset($_POST['addresses'])) {
+ WpExhibitGeocoder::batch_add($_POST['exhibitid'], $_POST['addressField'],
$_POST['datumids'], $_POST['addresses']);
+} else {
+ print_r($_POST);
+}
+
+?>
=======================================
--- /trunk/plugin/configurator/configurator.js.php Thu Feb 24 05:13:21 2011
+++ /trunk/plugin/configurator/configurator.js.php Wed Mar 30 12:05:17 2011
@@ -142,7 +142,6 @@
for (var key in props) {
prop_choice = prop_choice + "<option value='" + key + "'>" + key
+ "</option>";
}
-
SimileAjax.jQuery('.alltypebox').html(type_choice);
SimileAjax.jQuery('.allpropbox').html(prop_choice);
}
@@ -151,5 +150,6 @@
db = Exhibit.Database.create();
db.loadDataLinks(ex_data_types_changed);
}
+
EOF
?>
=======================================
--- /trunk/plugin/configurator/exhibit-configurator.php Thu Feb 24 05:13:21
2011
+++ /trunk/plugin/configurator/exhibit-configurator.php Wed Mar 30 12:05:17
2011
@@ -68,6 +68,7 @@
});
jQuery(document).ready(function(){
function postExhibit(e) {
+ debugger;
var paste_exhibit = false;
var paste_footnotes = false;
@@ -78,14 +79,36 @@
paste_exhibit = true;
paste_footnotes = true;
}
+
jQuery.post("<?php bloginfo('wpurl'); ?>/wp-admin/admin-ajax.php",
jQuery("#exhibit-config-form").serialize(),
function(data) {
+ if(geocodeFields.length != 0) {
+ for(key in geocodeFields) {
+ var itemProps = getItemProps(geocodeFields[key]);
+ //these are the arrays to post to wp-exhibit-geocode.php
+ var addresses = Array();
+ var datumIds = Array();
+ var i = 0;
+ for(key2 in itemProps) {
+ addresses[i] = itemProps[key2];
+ datumIds[i] = key2;
+ i++;
+ }
+ try {
+ jQuery.post(<? echo("'$exhibituri/wp-exhibit-geocode.php'"); ?>,
+ {'exhibitid': data, 'datumids[]': datumIds, 'addresses[]':
addresses, 'addressField': geocodeFields[key]});
+ } catch(e) {
+ console.log(e);
+ }
+ }
+ }
var win = window.dialogArguments || opener || parent || top;
win.set_post_exhibit(data);
win.add_exhibit_token_and_exit();
+
});
-
+
}
jQuery('#save_btn').bind("click", postExhibit);
@@ -99,9 +122,29 @@
});
remove_callbacks = new Array();
db = Exhibit.Database.create();
-
+
ex_load_links();
});
+
+ //print item properties (for debugging)
+ function printItemProps(propertyName) {
+ var props = getItemProps(propertyName);
+ for(key in props) {
+ alert(key + "->" + props[key]);
+ }
+ }
+
+ function getItemProps(propertyName) {
+ var ret = new Array();
+ var items = db.getAllItems();
+ items.visit(function(item) {
+ var obj = db.getObject(item, propertyName);
+ if(obj != null) {
+ ret[item] = obj;
+ }
+ });
+ return ret;
+ }
</script>
<?php
}
@@ -119,6 +162,7 @@
* @param unknown_type $content_func
*/
function datapress_iframe($content_func /* ... */) {
+
if (!$guessurl = site_url())
$guessurl = wp_guess_url();
$baseuri = $guessurl;
=======================================
--- /trunk/plugin/configurator/exhibit-inputbox-view-map.php Wed Feb 23
18:53:11 2011
+++ /trunk/plugin/configurator/exhibit-inputbox-view-map.php Wed Mar 30
12:05:17 2011
@@ -8,7 +8,7 @@
<tr>
<td><i>Location field</i></td>
<td><select id="exhibit-views-maps-field" class="allpropbox"></select>
contains a
- <select id="exhibit-views-maps-fieldtype"><option selected
value="latlng">Lat,Lng</select>
+ <select id="exhibit-views-maps-locationtype"><option selected
value="latlng">Lat,Lng</option><option
value="address">Address</option></select>
</td>
<td></td>
</tr>
@@ -45,13 +45,13 @@
<p align="right"><a href="#" class="addlink"
onclick="submit_view_map_facet(); return false">Add Map</a></p>
<script type="text/JavaScript">
-
+var geocodeFields = Array();
function submit_view_map_facet() {
var label = jQuery('#exhibit-views-maps-label').val();
var kind = 'view-map';
var field = jQuery('#exhibit-views-maps-field').val();
var coderfield = jQuery('#exhibit-views-maps-coderfield').val();
- var locationtype = jQuery('#exhibit-views-maps-fieldtype').val();
+ var locationtype = jQuery('#exhibit-views-maps-locationtype').val();
var extra_attributes =
jQuery('#exhibit-views-maps-extra-attributes').val();
var icon = jQuery('#exhibit-views-maps-icon').val();
var bw = jQuery('#exhibit-views-maps-bubblewidth').val();
@@ -71,7 +71,6 @@
coderfield: coderfield,
locationtype: locationtype
};
-
if (extra_attributes != null) {
params['extra_attributes'] = extra_attributes;
}
@@ -87,6 +86,11 @@
editable: true,
tabid: "exhibit-views-maps"
};
+ //if the user selected "address", then geocode
+ if(locationtype == 'address') {
+ geocodeFields.push(field);
+ }
+
addExhibitElementLink("views-list", "Map: " + label, 'view', params,
editinfo);
=======================================
--- /trunk/plugin/head-datasources.php Thu Mar 19 13:04:50 2009
+++ /trunk/plugin/head-datasources.php Wed Mar 30 12:05:17 2011
@@ -1,4 +1,9 @@
<?php
+ if (!$guessurl = site_url())
+ $guessurl = wp_guess_url();
+ $baseuri = $guessurl;
+ $exhibituri = $baseuri . '/wp-content/plugins/datapress';
+require_once('wp-exhibit-geocoder.php');
global $exhibits_to_show;
if (isset($exhibits_to_show) && (count($exhibits_to_show) > 0)) {
@@ -6,6 +11,9 @@
foreach($exhibit_to_show->get('datasources') as $datasource) {
echo($datasource->htmlContent() . "\n");
}
+
if(WpExhibitGeocoder::doesExhibitContainGeocodedData($exhibit_to_show->get('id')))
{
+ echo("<link href='$exhibituri/wp-exhibit-geocode.php?exhibit-id=" .
$exhibit_to_show->get('id') . "' type='application/json' rel='exhibit/data'
alt='geocoded_data' />\n");
+ }
}
}
?>
=======================================
--- /trunk/plugin/model/view.php Thu Feb 24 05:13:21 2011
+++ /trunk/plugin/model/view.php Wed Mar 30 12:05:17 2011
@@ -86,15 +86,14 @@
function htmlContent() {
$kind = $this->get('kind');
$label = $this->get('label');
-
$klass = $this->get('klass');
$collection_insert = '';
- if ($klass != NULL) {
+ /*if ($klass != NULL) {
$collection_insert = "ex:collectionID='collection_$klass'";
}
else {
$collection_insert = "ex:collectionID='auto_union'";
- }
+ }*/
if ($kind == "view-tile") {
// Todo: add the actual date and time stuff
@@ -158,7 +157,10 @@
if ($this->get('extra_attributes') != NULL) {
$inner .= " " . $this->get('extra_attributes') . " ";
}
-
+ //This case will handle if we are using geocoded data.
+ if($locationtype == 'address') {
+ $field = $field . '_generatedLatLng';
+ }
// NOTE: There is currently no nocderfeld thing being put in here.
$ret = "<div ex:role='view' ex:viewClass='Map' ex:label='$label'
$collection_insert ex:latlng='.$field' ex:bubbleWidth='$bw'
ex:bubbleHeight='$bh' ex:shapeWidth='$mw' ex:shapeHeight='$mh' $inner
></div>";
return $ret;
=======================================
--- /trunk/plugin/wp-exhibit-activation-tools.php Wed Feb 16 13:05:22 2011
+++ /trunk/plugin/wp-exhibit-activation-tools.php Wed Mar 30 12:05:17 2011
@@ -61,6 +61,7 @@
address TEXT,
lat FLOAT,
lng FLOAT,
+ addressField varchar(255),
PRIMARY KEY (id)
)
";
=======================================
--- /trunk/plugin/wp-exhibit-geocoder.php Wed Feb 16 13:03:50 2011
+++ /trunk/plugin/wp-exhibit-geocoder.php Wed Mar 30 12:05:17 2011
@@ -1,45 +1,112 @@
<?php
+require_once('wp-exhibit-config.php');
class WpExhibitGeocoder {
-
- // Note: to get the google map API key, do this:
- // $google_map_api_key = get_option( 'google_map_api_key' );
-
- // If you need a separate key, other than this one, grep the project
for google_map_api_key to see
- // how we created an option form to add it
-
- // Perform the geocoding for a batch of items
- static function batch_add($exhibit_id, $datum_ids, $addresses) {
+ // Perform the geocoding for a batch of items. Returns false if
+ // $datum_ids and $addresses are a different size.
+ static function batch_add($exhibit_id, $address_field, $datum_ids,
$addresses) {
+ if(count($datum_ids) == count($addresses)) {
+ for($i = 0; $i < count($datum_ids); $i++) {
+ WpExhibitGeocoder::lookup($exhibit_id, $address_field, $datum_ids[$i],
$addresses[$i]);
+ }
+ return true;
+ } else {
+ return false;
+ }
}
- // Perform the geocoding for a single item
+ // Returns true if the Exhibit contains any geocoded data, false
otherwise.
static function doesExhibitContainGeocodedData($exhibit_id) {
- // Returns BOOL
- }
-
- static function lookup($exhibit_id, $datum_id, $address) {
- /*
- * If in database, reutrn lat,lng from database
- * Else, geocode; save to db, lookup from db
- */
- }
-
+ global $wpdb;
+ $table = WpExhibitConfig::table_name(WpExhibitConfig::$GEOCODE_TABLE_KEY);
+ $query = "SELECT count(*) from $table WHERE exhibit_id = %d";
+ $query = $wpdb->prepare($query, $exhibit_id);
+ $row = $wpdb->get_row($query, ARRAY_N);
+ if($row != NULL) {
+ return $row[0] > 0;
+ }
+ return false;
+ }
+ //look up the lat and lng for a given exhibit, data set, and address.
+ //If not found, geocode and store in table
+ static function lookup($exhibit_id, $address_field, $datum_id,
$address) {
+ global $wpdb;
+ $table =
WpExhibitConfig::table_name(WpExhibitConfig::$GEOCODE_TABLE_KEY);
+ $query = "SELECT lat, lng FROM $table WHERE exhibit_id = %d AND
addressField = %s AND datum_id = %d AND address = %s";
+ $query = $wpdb->prepare($query, $exhibit_id, $address_field,
$datum_id, $address);
+ $row = $wpdb->get_row($query, ARRAY_A);
+ if($row != NULL) {
+ return array($row['lat'], $row['lng']);
+ }
+ else {
+ try {
+ $geo_results = json_decode(WpExhibitGeocoder::geocode($address), true);
+ $latlng = $geo_results['results'][0]['geometry']['location'];
+ if($latlng['lat'] == 0 && $latlng['lng'] == 0)
+ return false;
+ $query = "INSERT INTO $table(lat, lng, exhibit_id, addressField,
datum_id, address) VALUES(%f, %f, %d, %s, %s, %s)";
+ $query = $wpdb->prepare($query, $latlng['lat'], $latlng['lng'],
$exhibit_id, $address_field, $datum_id, $address);
+ $wpdb->query($query);
+ } catch(Exception $e) {
+ print $e;
+ return null;
+ }
+ return $latlng;
+ }
+ }
+ //Look up single address using Google Geocoding API
+ //returns JSON. For full contents of the JSON, check Google's
documentation.
static function geocode($address) {
+ $address = urlencode($address);
+ $request =
file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=$address&sensor=false");
+ return $request;
}
- static function save($exhibit_id, $datum_id, $address) {
- }
// Pring out a data file for an exhibit
static function json_for($exhibit_id) {
- // look up all points for the exhibit
- // write out tuples <datum_id, latlng>
- }
-
- static function say_hello() {
- }
+ global $wpdb;
+ $table =
WpExhibitConfig::table_name(WpExhibitConfig::$GEOCODE_TABLE_KEY);
+ $query = "SELECT lat, lng, addressField, datum_id FROM $table WHERE
exhibit_id = %d";
+ $query = $wpdb->prepare($query, $exhibit_id);
+ $data = $wpdb->get_results($query, ARRAY_A);
+ $latlngs = array();
+ foreach ($data as $row) {
+ $latlngs['items'][] = array('id' => $row['datum_id'],
$row['addressField'] . '_generatedLatLng' => $row['lat'] . ',' .
$row['lng']);
+ }
+ $latlng_json = json_encode($latlngs);
+
+ return $latlng_json;
+ }
+
+ static function test() {
+ $address_ids = array('1856 E Shelby St., Seattle, WA 98112',
+ '1600 Amphitheatre Parkway, Mountain View, CA',
+ '3 Ames Street, Cambridge, MA',
+ '77 Massachusetts Avenue, Cambridge, MA',
+ 'One Microsoft Way, Redmond, WA',
+ 'blashsdlkfjsdjfds');
+
+ $ex_id = 1;
+ $dat_ids = array(1, 2, 3, 4, 5, 6);
+ $address_ids = WpExhibitGeocoder::batch_add($ex_id, $dat_ids,
$address_ids);
+
+ if(WpExhibitGeocoder::doesExhibitContainGeocodedData($ex_id)) {
+ // print WpExhibitGeocoder::json_for($ex_id);
+ }
+ //else echo "doesn't contain data";
+ }
+ static function make_json() {
+ $address_ids = array('1856 E Shelby St., Seattle, WA 98112',
+ '1600 Amphitheatre Parkway, Mountain View, CA',
+ '3 Ames Street, Cambridge, MA',
+ '77 Massachusetts Avenue, Cambridge, MA',
+ 'One Microsoft Way, Redmond, WA',);
+ $json = array('items'=>array('address'=>$address_ids[0]));
+ print json_encode($json);
+ }
+
}
-WpExhibitGeocoder::say_hello()
?>
=======================================
--- /trunk/plugin/wp-exhibit-save-post.php Mon Mar 30 14:33:31 2009
+++ /trunk/plugin/wp-exhibit-save-post.php Wed Mar 30 12:05:17 2011
@@ -1,5 +1,6 @@
<?php
require_once('wp-exhibit-config.php');
+require('wp-exhibit-geocoder.php');
class SaveExhibitPost {
function save($ex_post_id) {
@@ -21,8 +22,6 @@
// There was an association. Upate it
$assoc = $wpdb->query("UPDATE $table SET postid =
$ex_post_id, exhibitid = $ex_exhibit_id WHERE postid = $ex_post_id ;",
ARRAY_A);
}
-
-
// $ex_exhibit = new WpPostExhibit();