Licensed under the GNU General Public License, Copyright 2005 Will Read. Version: 0.2 Author: Will Read (will@read.name) Author URI: http://www.will.read.name/ WordPress Version Required: 1.5 Credits: Based off of Owen Winkler's Geo Plug-in http://www.asymptomatic.net */ /* PostLocation - Attaches address information to posts. Copyright (c) 2005 Will Read This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 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 */ /* INSTRUCTIONS: Drop this file into your WordPress plugins directory, and then Activate it on the Plugins tab of the WordPress admin console. See http://dev.wp-plugins.org/wiki/PostLocation for more detailed installation instructions and usage information. */ class PostLocation /** * Provide a namespace for our plugin */ { function options_page_postlocation() /** * Short Description for the Function, one line, end w/ period. * * Long description for the Function. * * @return mixed Description */ { if(isset($_REQUEST['deleteid'])) { $postlocations = get_settings('post_locations'); unset($postlocations[$_REQUEST['deleteid']]); update_option('post_locations', $postlocations); } if(isset($_POST['Options'])) { $use_post_positions = $_POST['use_post_positions'] == 1 ? 1 : 0; $use_default_postlocation = $_POST['use_default_postlocation'] == 1 ? 1 : 0; update_option('use_post_positions', $use_post_positions); update_option('use_default_postlocation', $use_default_postlocation); update_option('default_postlocation_location', $_POST['default_postlocation_location']); update_option('default_postlocation_street', $_POST['default_postlocation_street']); update_option('default_postlocation_city', $_POST['default_postlocation_city']); update_option('default_postlocation_state', $_POST['default_postlocation_state']); update_option('default_postlocation_zip', $_POST['default_postlocation_zip']); update_option('default_postlocation_country', $_POST['default_postlocation_country']); echo '

' . __('Options updated.', 'PostLocation') . '

'; } if(isset($_POST['Submit']) || isset($_POST['Add'])) { $postlocations = get_settings('post_locations'); foreach($postlocations as $name => $address) { $postlocations[$name] = "{$_POST['location'][$name]},{$_POST['street'][$name]},{$_POST['city'][$name]},{$_POST['state'][$name]},{$_POST['zip'][$name]},{$_POST['country'][$name]}"; } if(isset($_POST['new_location']) && ($_POST['new_location'] != '')) { $postlocations[$_POST['new_location']] = "{$_POST['new_location']},{$_POST['new_street']},{$_POST['new_city']},{$_POST['new_state']},{$_POST['new_zip']},{$_POST['new_country']}"; } update_option('post_locations', $postlocations); echo '

' . __('Locations updated.', 'PostLocation') . '

'; } else { PostLocation::add_options(); } $use_post_positions = get_settings('use_post_positions'); $use_default_postlocation = get_settings('use_default_postlocation'); $default_postlocation_location = get_settings('default_postlocation_location'); $default_postlocation_street = get_settings('default_postlocation_street'); $default_postlocation_city = get_settings('default_postlocation_city'); $default_postlocation_state = get_settings('default_postlocation_state'); $default_postlocation_zip = get_settings('default_postlocation_zip'); $default_postlocation_country = get_settings('default_postlocation_country'); $ck_use_post_positions = $use_post_positions == 1 ? ' checked="checked"' : ''; $ck_use_default_postlocation[intval($use_default_postlocation)] = ' checked="checked"'; $postlocations = get_settings('post_locations'); if(!is_array($postlocations)) $postlocations = array(); //Option Page Presentation echo '

' . __('Post Location Manager', 'PostLocation') . '

' . __('Post Tracking Features', 'PostLocation') . ': Enable
' . __('When no location is specified', 'PostLocation') . ':


,

'; echo '

' . __('Preset Locations', 'PostLocation') . '

'; foreach($postlocations as $name => $address) { list($location, $street, $city, $state, $zip, $country) = split(',', $address); $alternate = $alternate == ''? ' class="alternate"' : ''; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; echo " "; echo ""; } echo '
'.__('Location Name', 'PostLocation').' '.__('Street', 'PostLocation').' '.__('City', 'PostLocation').' '.__('State', 'PostLocation').' '.__('Zip', 'PostLocation').' '.__('Country', 'PostLocation').' '.__('Action', 'PostLocation').'
Delete · " . get_map_url('GoogleMaps', 'Map ') . "
'.__('New Location', 'PostLocation').':
'; ?>
»" />
' . __('Location', 'PostLocation') . ''; list($location, $street, $city, $state, $zip, $country) = split(',', get_post_meta($postdata->ID, '_post_location', true)); echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ''; echo ''; } function admin_head($not_used) /** * Short Description for the Function, one line, end w/ period. * * Long description for the Function. * * @param $not_used Description */ { if(strstr($_SERVER['REQUEST_URI'], 'post.php')) { echo ' '; } } function update_post($id) /** * Short Description for the Function, one line, end w/ period. * * Long description for the Function. * * @param $id Description */ { delete_post_meta($id, '_post_location'); add_post_meta($id, '_post_location', $_POST['post_location'] . ',' . $_POST['post_street'] . ',' . $_POST['post_city'] . ',' . $_POST['post_state'] . ',' . $_POST['post_zip'] . ',' . $_POST['post_country']); } function wp_head($not_used) /** * Short Description for the Function, one line, end w/ period. * * Long description for the Function. * * @param $not_used Description */ { global $wp_query; if(!get_settings('use_post_positions')) return; list($location, $street, $city, $state, $zip, $country) = split(',', get_post_meta($wp_query->post->ID, '_post_location', true)); if(is_single() && ($location != '') && ($street != '') && ($city != '') && ($state != '') && ($zip != '') && ($country != '')) { $title = convert_chars(strip_tags(get_bloginfo("name")))." - ".$wp_query->post->post_title; } else if(get_settings('use_default_postlocation')) { // send the default here $title = convert_chars(strip_tags(get_bloginfo("name"))); $location = get_settings('default_postlocation_location'); $street = get_settings('default_postlocation_street'); $city = get_settings('default_postlocation_city'); $state = get_settings('default_postlocation_state'); $zip = get_settings('default_postlocation_zip'); $country = get_settings('default_postlocation_country'); } else { return; } echo "\n"; } function logErrors($msg) /** * Short Description for the Function, one line, end w/ period. * * Long description for the Function. * * @return bool Always true * @param $msg Description */ { $fp = fopen("../asy.log","a+"); fwrite($fp, "\n\n".date("Y-m-d H:i:s - ").$msg); fclose($fp); return true; } function admin_menu($not_used) /** * Short Description for the Function, one line, end w/ period. * * Long description for the Function. * * @param $not_used Description */ { add_options_page(__('Post Location Manager', 'PostLocation'), __('Location Info', 'PostLocation'), 5, 'postlocation.php'); } } // End class PostLocation // Note the array as the second parameter for calling static methods on our nice, safe object namespace // For instance, array('PostLocation', 'edit_form_advanced') calls PostLocation::edit_form_advanced() add_action('edit_form_advanced', array('PostLocation', 'edit_form_advanced')); add_action('admin_head', array('PostLocation', 'admin_head')); add_action('wp_head', array('PostLocation', 'wp_head')); add_action('edit_post', array('PostLocation', 'update_post')); add_action('edit_post', array('PostLocation', 'update_post')); add_action('publish_post', array('PostLocation', 'update_post')); add_action('admin_menu', array('PostLocation', 'admin_menu')); add_action('options_page_postlocation', array('PostLocation', 'options_page_postlocation')); function get_Location() { global $post; get_settings('post_locations'); list($location, $street, $city, $state, $zip, $country) = split(',', get_post_meta($post->ID, '_post_location', true)); if ($location != '') { return trim($location); } else if(get_settings('use_default_postlocation')) { return trim(get_settings('default_postlocation_location')); } return NULL; } function get_Street() { global $post; list($location, $street, $city, $state, $zip, $country) = split(',', get_post_meta($post->ID, '_post_location', true)); if ($street != '') { return trim($street); } else if(get_settings('use_default_postlocation')) { return trim(get_settings('default_postlocation_street')); } return ''; } function get_City() { global $post; list($location, $street, $city, $state, $zip, $country) = split(',', get_post_meta($post->ID, '_post_location', true)); if ($city != '') { return trim($city); } else if(get_settings('use_default_postlocation')) { return trim(get_settings('default_postlocation_city')); } return ''; } function get_State() { global $post; list($location, $street, $city, $state, $zip, $country) = split(',', get_post_meta($post->ID, '_post_location', true)); if ($state != '') { return trim($state); } else if(get_settings('use_default_postlocation')) { return trim(get_settings('default_postlocation_state')); } return ''; } function get_Zip() { global $post; list($location, $street, $city, $state, $zip, $country) = split(',', get_post_meta($post->ID, '_post_location', true)); if ($zip != '') { return trim($zip); } else if(get_settings('use_default_postlocation')) { return trim(get_settings('default_postlocation_zip')); } return ''; } function get_Country() { global $post; list($location, $street, $city, $state, $zip, $country) = split(',', get_post_meta($post->ID, '_post_location', true)); if ($country != '') { return trim($country); } else if(get_settings('use_default_postlocation')) { return trim(get_settings('default_postlocation_country')); } return ''; } function the_Location() { if(get_settings('use_post_positions')) { echo get_Location(); } } function the_Street() { if(get_settings('use_post_positions')) { echo get_Street(); } } function the_City() { if(get_settings('use_post_positions')) { echo get_City(); } }function the_State() { if(get_settings('use_post_positions')) { echo get_State(); } } function the_Zip() { if(get_settings('use_post_positions')) { echo get_Zip(); } } function the_Country() { if(get_settings('use_post_positions')) { echo get_Country(); } } function postLocation_PopUpScript() /** * Short Description for the Function, one line, end w/ period. * * Long description for the Function. * * @return string Description */ { echo " "; } function map_urls($street = '', $city = '', $state = '', $zip = '', $country = '') /** * Short Description for the Function, one line, end w/ period. * * Long description for the Function. * * @return array Description */ { $street = ($street == ''? get_Street() : $street); $city = ($city == ''? get_City() : $city); $state = ($state == ''? get_State() : $state); $zip = ($zip == ''? get_Zip() : $zip); $country = (substr(($country == ''? get_Country() : $country),0,2)); $ary = array ( 'MapQuest' => array("http://www.mapquest.com/maps/map.adp?address={$street}&city={$city}&state={$state}&zipcode={$zip}&country={$country}&cid=lfmaplink", __('MapQuest', 'PostLocation')), 'GoogleMaps' => array("http://maps.google.com/maps?q={$street}%2C{$city}%20{$state}%20{$zip}%20{$country}", __('GoogleMap', 'PostLocation')), 'YahooMaps' => array("http://us.rd.yahoo.com/maps/us/insert/Tmap/extmap/*-http://maps.yahoo.com/maps_result?addr={$street}&csz={$city}%2C+{$state}+{$zip}&country={$country}", __('YahooMaps', 'PostLocation')) ); return $ary; } function postLocation_UrlPopNav() /** * Short Description for the Function, one line, end w/ period. * * Long description for the Function. * */ { $sites = get_urls(); echo '
\n\n
'."\n"; } function get_map_link($index, $preText = '', $street = '', $city = '', $state = '', $zip = '', $country = '') /** * Returns a URL for the indexed site at the given address. * * Long description for the Function. * * @param $index The associative index of the URL array to return. * @param $lat Optional latitude for the URL, if not specified then the current is used. * @param $lon Optional longitude for the URL, if not specified then the current is used. * @param $preText Optional text you would like to appear before the link * * @return string The URL of the requested site. */ { $street = $street == ''? get_Street() : $street; $city = $city == ''? get_City() : $city; $state = $state == ''? get_State() : $state; $zip = $zip == ''? get_Zip() : $zip; $country = $country == ''? get_Country() : $country; $urls = map_urls($street, $city, $state, $zip, $country); if(count(get_Location()) > 0) { return $preText . '' . get_Location() . ''; } else { return NULL; } } ?>