Changeset 648734
- Timestamp:
- 01/06/2013 03:03:28 PM (13 years ago)
- Location:
- fi-geolocation/trunk
- Files:
-
- 4 deleted
- 2 edited
-
css (deleted)
-
fi-geolocation.php (modified) (1 diff)
-
images (deleted)
-
js (deleted)
-
languages (deleted)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
fi-geolocation/trunk/fi-geolocation.php
r647542 r648734 1 1 <?php 2 2 /* 3 Plugin Name: Geolocation by FranceImage 4 Plugin URI: http://franceimage.com/ 5 Description: Attach geolocation data to post 6 Version: 1.1.0 7 Author: FranceImage 8 Author URI: http://franceimage.com/ 3 Plugin Name: Geolocation 4 Plugin URI: http://wordpress.org/ 5 Description: Sorry, discontinued 6 Version: 1.2.0 9 7 */ 10 11 class Fi_geolocation {12 static $plugin;13 var $options;14 15 16 function __construct() {17 Fi_geolocation::$plugin = $this;18 add_action('init', array(&$this, 'init'));19 }20 21 22 function init() {23 $this->options = new Fi_options();24 25 $lang = substr(get_bloginfo('language'), 0, 2);26 $sensor = 'false';27 if(is_admin() && $this->options->use_location_sensor == 'yes') {28 $sensor = 'true';29 }30 31 wp_register_script('googleapi', "http://www.google.com/jsapi", false, false, true);32 wp_register_script('googlemap', "http://maps.google.com/maps/api/js?sensor=$sensor&language=$lang", false, false, true);33 wp_register_script('fi-googlemap-center', plugins_url(plugin_basename(dirname(__FILE__))) . '/js/map_center.js', array('googlemap'), false, true);34 wp_register_script('fi-settings', plugins_url(plugin_basename(dirname(__FILE__))) . '/js/settings.js', array('jquery', 'googlemap', 'fi-googlemap-center'), false, true);35 wp_register_script('fi-geolocation-form', plugins_url(plugin_basename(dirname(__FILE__))) . '/js/geolocation-form.js', array('jquery', 'googlemap'), false, true);36 wp_register_script('fi-geolocation-showme-where', plugins_url(plugin_basename(dirname(__FILE__))) . '/js/showme-where.js', array('jquery', 'googlemap'), false, true);37 wp_register_script('fi-geolocation-archive-map', plugins_url(plugin_basename(dirname(__FILE__))) . '/js/archive-map.js', array('jquery', 'googlemap'), false, true);38 wp_register_style('fi-geolocation-style', plugins_url(plugin_basename(dirname(__FILE__))) . '/css/style.css');39 }40 }41 42 43 /**44 *45 * Options46 *47 */48 class Fi_options {49 var $values = array(50 'config_version' => 1,51 52 /* posttypes we support */53 'posttypes' => 'post,page',54 55 /* allow detection of author position */56 'use_location_sensor' => 'no',57 58 /* metadata keys */59 'postmeta_lat' => 'geo_latitude',60 'postmeta_lng' => 'geo_longitude',61 'postmeta_zoom' => 'geo_zoom',62 'postmeta_name' => 'geo_address',63 'postmeta_public' => 'geo_public',64 'postmeta_enabled' => 'geo_enabled',65 66 /* default map */67 'default_map_lat' => 34.3,68 'default_map_lng' => -38,69 'default_map_zoom' => 1,70 'default_map_width' => '450px',71 'default_map_height' => '200px',72 73 /* default behaviour when showing post location */74 'default_showme_position' => 'after_content', // 'before_content', 'after_content', '' (when '', we rely on shortcodes)75 'default_showme_trigger' => 'link_hover', // 'link_hover', 'link_click', 'map'76 'default_showme_text' => 'Where is #GEO_ADDRESS ?', // placeholders '#GEO_ADDRESS', '#POST_TITLE'77 'default_showme_zoom' => 'default', // 'default', 'metadata'78 'default_popup_position' => 'right', // 'below', 'above', 'left', 'right' (position of the map popped up when hovering or clicking the showme_where link)79 80 /* default behaviour for archive maps */81 'archive_map_lat' => 34.3,82 'archive_map_lng' => -38,83 'archive_map_zoom' => 1,84 'archive_map_width' => '100%',85 'archive_map_height' => '300px',86 'markers_limit' => 50,87 'archive_home' => 'yes',88 'archive_author' => 'yes',89 'archive_taxonomy' => 'yes',90 'include_taxonomies' => '',91 'exclude_taxonomies' => '',92 'include_authors' => '',93 'exclude_authors' => '',94 );95 96 97 function __construct() {98 // read options from db (create them if they don't exist in db)99 foreach($this->values AS $key => $value) {100 if(get_option('fi_' . $key)) {101 $this->values[$key] = get_option('fi_' . $key);102 }103 else {104 update_option('fi_' . $key, $this->values[$key]);105 }106 }107 }108 109 110 public function __set($name, $value) {111 }112 113 114 public function __get($name) {115 return $this->values[$name];116 }117 118 119 function register_settings() {120 foreach($this->values AS $key => $value) {121 register_setting('fi-geolocation-settings', 'fi_' . $key);122 }123 }124 125 126 function settings_fields() {127 settings_fields('fi-geolocation-settings');128 }129 130 131 function render_radio($name, $options) {132 $option = get_option($name);133 134 foreach($options as $value => $text): ?>135 <input id="<?php echo esc_attr($name) ?>_<?php echo esc_attr($value); ?>" name="<?php echo esc_attr($name) ?>" type="radio" value="<?php echo esc_attr($value); ?>" <?php if($option == $value) echo "checked='checked'"; ?> />136 137 <?php138 echo $text;139 endforeach;140 }141 142 143 function render_single_post_options() {144 $default_showme_position = array(145 'before_content' => __('Before content', 'fi-geolocation'),146 'after_content' => __('After content', 'fi-geolocation'),147 'none' => __('None', 'fi-geolocation')148 );149 150 $default_showme_trigger = array(151 'link_hover' => __('Link to hover', 'fi-geolocation'),152 'link_click' => __('Link to click', 'fi-geolocation'),153 'map' => __('Map', 'fi-geolocation')154 );155 156 $default_popup_position = array(157 'left' => __('Left', 'fi-geolocation'),158 'right' => __('Right', 'fi-geolocation'),159 'above' => __('Above', 'fi-geolocation'),160 'below' => __('Below', 'fi-geolocation')161 );162 163 $default_showme_zoom = array(164 'default' => __('Default map zoom', 'fi-geolocation'),165 'metadata' => __('Zoom from metadata', 'fi-geolocation')166 );167 ?>168 169 <tr>170 <th><label for='fi_default_map_width'><?php _e('Default map width', 'fi-geolocation'); ?></label></th>171 <td>172 <input id="fi_default_map_width" name="fi_default_map_width" type="text" value="<?php echo esc_attr(get_option('fi_default_map_width')); ?>" />173 </td>174 </tr>175 <tr><td></td><td><em><?php _e('Examples: 250px, 100%', 'fi-geolocation'); ?></em></td></tr>176 177 178 <tr>179 <th><label for='fi_default_map_height'><?php _e('Default map heigth', 'fi-geolocation'); ?></label></th>180 <td>181 <input id="fi_default_map_height" name="fi_default_map_height" type="text" value="<?php echo esc_attr(get_option('fi_default_map_height')); ?>" />182 </td>183 </tr>184 <tr><td></td><td><em><?php _e('Examples: 250px, 100%', 'fi-geolocation'); ?></em></td></tr>185 186 187 <tr>188 <th><label for='fi_default_showme_position'><?php _e('Display geolocation', 'fi-geolocation'); ?></label></th>189 <td>190 <?php $this->render_radio('fi_default_showme_position', $default_showme_position); ?>191 </td>192 </tr>193 <tr><td></td><td><em><?php _e('Note that you can use [geolocation] shortcode. This has precedence over this setting', 'fi-geolocation'); ?></em></td></tr>194 195 196 <tr>197 <th><label for='fi_default_showme_trigger'><?php _e('Display geolocation as', 'fi-geolocation'); ?></label></th>198 <td>199 <?php $this->render_radio('fi_default_showme_trigger', $default_showme_trigger); ?>200 </td>201 </tr>202 203 204 <tr>205 <th><label for='fi_default_showme_text'><?php _e('Use this text for links', 'fi-geolocation'); ?></label></th>206 <td>207 <input id="fi_default_showme_text" name="fi_default_showme_text" type="text" size=100 value="<?php echo esc_attr(get_option('fi_default_showme_text')); ?>" />208 </td>209 </tr>210 <tr><td></td><td><em><?php _e('Free text - You can use following place holders: #GEO_ADDRESS and #POST_TITLE', 'fi-geolocation'); ?></em></td></tr>211 212 213 <tr>214 <th><label for='fi_default_showme_zoom'><?php _e('Display geolocation zoom', 'fi-geolocation'); ?></label></th>215 <td>216 <?php $this->render_radio('fi_default_showme_zoom', $default_showme_zoom); ?>217 </td>218 </tr>219 <tr><td></td><td><em><?php _e('Zoom level when showing a location', 'fi-geolocation'); ?></em></td></tr>220 221 222 <tr>223 <th><label for='fi_default_popup_position'><?php _e('Popup map position', 'fi-geolocation'); ?></label></th>224 <td>225 <?php $this->render_radio('fi_default_popup_position', $default_popup_position); ?>226 </td>227 </tr>228 <tr><td></td><td><em><?php _e('Relative to the mouse when clicking or hovering', 'fi-geolocation'); ?></em></td></tr>229 230 231 <tr>232 <th><label for='fi_default_map'><?php _e('Default map', 'fi-geolocation'); ?></label></th>233 <td class='map_wrapper'>234 <input id="fi_default_map_lat" name="fi_default_map_lat" type="hidden" value="<?php echo esc_attr(get_option('fi_default_map_lat')); ?>" />235 <input id="fi_default_map_lng" name="fi_default_map_lng" type="hidden" value="<?php echo esc_attr(get_option('fi_default_map_lng')); ?>" />236 <input id="fi_default_map_zoom" name="fi_default_map_zoom" type="hidden" value="<?php echo esc_attr(get_option('fi_default_map_zoom')); ?>" />237 <div id="fi_default_map"></div>238 </td>239 </tr>240 <tr><td></td><td><em><?php _e('The zoom level of this map will be used to display maps in your posts', 'fi-geolocation'); ?></em></td></tr>241 242 <?php243 }244 245 246 function render_archives_options() {247 $yes_no_options = array(248 'yes' => __('Yes', 'fi-geolocation'),249 'no' => __('No', 'fi-geolocation')250 );251 252 ?>253 <tr>254 <th><label for='fi_archive_map_width'><?php _e('Default map width', 'fi-geolocation'); ?></label></th>255 <td>256 <input id="fi_archive_map_width" name="fi_archive_map_width" type="text" value="<?php echo esc_attr(get_option('fi_archive_map_width')); ?>" />257 </td>258 </tr>259 <tr><td></td><td><em><?php _e('Examples: 250px, 100%', 'fi-geolocation'); ?></em></td></tr>260 261 262 <tr>263 <th><label for='fi_archive_map_height'><?php _e('Default map heigth', 'fi-geolocation'); ?></label></th>264 <td>265 <input id="fi_archive_map_height" name="fi_archive_map_height" type="text" value="<?php echo esc_attr(get_option('fi_archive_map_height')); ?>" />266 </td>267 </tr>268 <tr><td></td><td><em><?php _e('Examples: 250px, 100%', 'fi-geolocation'); ?></em></td></tr>269 270 <tr>271 <th><label for='fi_archive_map'><?php _e('Default map', 'fi-geolocation'); ?></label></th>272 <td class='map_wrapper'>273 <input id="fi_archive_map_lat" name="fi_archive_map_lat" type="hidden" value="<?php echo esc_attr(get_option('fi_archive_map_lat')); ?>" />274 <input id="fi_archive_map_lng" name="fi_archive_map_lng" type="hidden" value="<?php echo esc_attr(get_option('fi_archive_map_lng')); ?>" />275 <input id="fi_archive_map_zoom" name="fi_archive_map_zoom" type="hidden" value="<?php echo esc_attr(get_option('fi_archive_map_zoom')); ?>" />276 <div id="fi_archive_map"></div>277 </td>278 </tr>279 <tr><td></td><td><em><?php _e('The zoom level of this map will be used to display maps in your posts', 'fi-geolocation'); ?></em></td></tr>280 281 282 <tr>283 <th><label for='fi_markers_limit'><?php _e('Markers limit', 'fi-geolocation'); ?></label></th>284 <td>285 <input id="fi_markers_limit" name="fi_markers_limit" type="text" value="<?php echo esc_attr(get_option('fi_markers_limit')); ?>" />286 </td>287 </tr>288 <tr><td></td><td><em><?php _e('Maximum number of markers displayed on the map', 'fi-geolocation'); ?></em></td></tr>289 290 291 <tr>292 <th><label for='fi_archive_home'><?php _e('Show on blog home', 'fi-geolocation'); ?></label></th>293 <td>294 <?php $this->render_radio('fi_archive_home', $yes_no_options); ?>295 </td>296 </tr>297 298 299 <tr>300 <th><label for='fi_archive_author'><?php _e('Show on author archives', 'fi-geolocation'); ?></label></th>301 <td>302 <?php $this->render_radio('fi_archive_author', $yes_no_options); ?>303 </td>304 </tr>305 306 <!--307 <tr>308 <th><label for='fi_include_authors'><?php _e('Include authors', 'fi-geolocation'); ?></label></th>309 <td>310 <input id="fi_include_authors" name="fi_include_authors" type="text" size=100 value="<?php echo esc_attr(get_option('fi_include_authors')); ?>" />311 </td>312 </tr>313 <tr><td></td><td><em><?php _e('Comma separated list of identifiers. If not empty, a map will be shown only for these authors', 'fi-geolocation'); ?></em></td></tr>314 315 316 <tr>317 <th><label for='fi_exclude_authors'><?php _e('Exclude authors', 'fi-geolocation'); ?></label></th>318 <td>319 <input id="fi_exclude_authors" name="fi_exclude_authors" type="text" size=100 value="<?php echo esc_attr(get_option('fi_exclude_authors')); ?>" />320 </td>321 </tr>322 <tr><td></td><td><em><?php _e('Comma separated list of identifiers. If not empty, a map will be shown for all authors except these', 'fi-geolocation'); ?></em></td></tr>323 -->324 325 <tr>326 <th><label for='fi_archive_taxonomy'><?php _e('Show on taxonomy archives', 'fi-geolocation'); ?></label></th>327 <td>328 <?php $this->render_radio('fi_archive_taxonomy', $yes_no_options); ?>329 </td>330 </tr>331 <tr><td></td><td><em><?php _e('Categories, tags and custom taxonomies', 'fi-geolocation'); ?></em></td></tr>332 333 <!--334 <tr>335 <th><label for='fi_include_taxonomies'><?php _e('Include taxonomies', 'fi-geolocation'); ?></label></th>336 <td>337 <input id="fi_include_taxonomies" name="fi_include_taxonomies" type="text" size=100 value="<?php echo esc_attr(get_option('fi_include_taxonomies')); ?>" />338 </td>339 </tr>340 <tr><td></td><td><em><?php _e('Comma separated list of identifiers. If not empty, a map will be shown only for these taxonomies', 'fi-geolocation'); ?></em></td></tr>341 342 343 <tr>344 <th><label for='fi_exclude_taxonomies'><?php _e('Exclude taxonomies', 'fi-geolocation'); ?></label></th>345 <td>346 <input id="fi_exclude_taxonomies" name="fi_exclude_taxonomies" type="text" size=100 value="<?php echo esc_attr(get_option('fi_exclude_taxonomies')); ?>" />347 </td>348 </tr>349 <tr><td></td><td><em><?php _e('Comma separated list of identifiers. If not empty, a map will be shown for all taxonomies except these', 'fi-geolocation'); ?></em></td></tr>350 -->351 352 <?php353 }354 355 356 function render_general_options() {357 $use_location_sensor_options = array(358 'yes' => __('Yes', 'fi-geolocation'),359 'no' => __('No', 'fi-geolocation')360 );361 362 363 ?>364 <tr>365 <th><label for='fi_use_location_sensor'><?php _e('Enable location sensor', 'fi-geolocation'); ?></label></th>366 <td>367 <?php $this->render_radio('fi_use_location_sensor', $use_location_sensor_options); ?>368 </td>369 </tr>370 <tr><td></td><td><em><?php _e('If set to yes, you will be able to use your current location as the post location', 'fi-geolocation'); ?></em></td></tr>371 372 <tr>373 <th><label for='fi_posttypes'><?php _e('Post types', 'fi-geolocation'); ?></label></th>374 <td>375 <input id="fi_posttypes" name="fi_posttypes" type="text" size=100 value="<?php echo esc_attr(get_option('fi_posttypes')); ?>" />376 </td>377 </tr>378 <tr><td></td><td><em><?php _e('Post types eligible for geolocation (comma separated)', 'fi-geolocation'); ?></em></td></tr>379 380 381 <?php382 }383 384 385 function render_advanced_options() {386 ?>387 388 <tr>389 <th><label for='fi_postmeta_lat'><?php _e('latitude meta', 'fi-geolocation'); ?></label></th>390 <td>391 <input id="fi_postmeta_lat" name="fi_postmeta_lat" type="text" value="<?php echo esc_attr(get_option('fi_postmeta_lat')); ?>" />392 </td>393 </tr>394 <tr><td></td><td><em><?php _e('Name of latitude metadata', 'fi-geolocation'); ?></em></td></tr>395 396 <tr>397 <th><label for='fi_postmeta_lng'><?php _e('longitude meta', 'fi-geolocation'); ?></label></th>398 <td>399 <input id="fi_postmeta_lng" name="fi_postmeta_lng" type="text" value="<?php echo esc_attr(get_option('fi_postmeta_lng')); ?>" />400 </td>401 </tr>402 <tr><td></td><td><em><?php _e('Name of longitude metadata', 'fi-geolocation'); ?></em></td></tr>403 404 <tr>405 <th><label for='fi_postmeta_zoom'><?php _e('zoom meta', 'fi-geolocation'); ?></label></th>406 <td>407 <input id="fi_postmeta_zoom" name="fi_postmeta_zoom" type="text" value="<?php echo esc_attr(get_option('fi_postmeta_zoom')); ?>" />408 </td>409 </tr>410 <tr><td></td><td><em><?php _e('Name of zoom metadata', 'fi-geolocation'); ?></em></td></tr>411 412 <tr>413 <th><label for='fi_postmeta_name'><?php _e('address meta', 'fi-geolocation'); ?></label></th>414 <td>415 <input id="fi_postmeta_name" name="fi_postmeta_name" type="text" value="<?php echo esc_attr(get_option('fi_postmeta_name')); ?>" />416 </td>417 </tr>418 <tr><td></td><td><em><?php _e('Name of address metadata', 'fi-geolocation'); ?></em></td></tr>419 420 421 <?php422 }423 424 425 }426 427 428 /**429 *430 * Back-end431 *432 */433 class Fi_geolocation_backend extends Fi_geolocation {434 435 function init() {436 parent::init();437 add_action('admin_init', array(&$this, 'admin_init'));438 add_action('admin_menu', array(&$this, 'admin_menu'));439 add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));440 add_action('save_post', array(&$this, 'save_post'));441 }442 443 444 function admin_init() {445 $this->options->register_settings();446 }447 448 449 function admin_menu() {450 if(function_exists('add_meta_box')) {451 $supported = explode(',', $this->options->posttypes);452 foreach ($supported AS $posttype) {453 add_meta_box('fi-geolocation-meta', __('Geolocation', 'fi-geolocation'), array(&$this, 'display_geolocation_form'), $posttype, 'advanced');454 }455 }456 457 add_options_page(__('Geolocation Settings', 'fi-geolocation'), __('Geolocation', 'fi-geolocation'), 'manage_options', 'fi-geolocation-config', array(&$this, "settings"));458 }459 460 461 function admin_enqueue_scripts() {462 }463 464 465 function save_post($post_id) {466 if (wp_is_post_revision($post_id)) {467 return;468 }469 470 if(empty($_POST['fi_geo_lat']) || empty($_POST['fi_geo_lng']) || empty($_POST['fi_geo_zoom']) ) {471 return;472 }473 474 // Check authorization, permissions, autosave, etc475 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)476 return $post_id;477 478 if(!empty($_POST['post_type']) && 'page' == $_POST['post_type'] ) {479 if(!current_user_can('edit_page', $post_id))480 return $post_id;481 } else {482 if(!current_user_can('edit_post', $post_id))483 return $post_id;484 }485 486 $pattern = '/^(\-)?(\d{1,3})\.(\d{1,6})/';487 preg_match($pattern, $_POST['fi_geo_lat'], $matches);488 $latitude = $matches[0];489 preg_match($pattern, $_POST['fi_geo_lng'], $matches);490 $longitude = $matches[0];491 $zoom = intval($_POST['fi_geo_zoom']);492 $name = empty($_POST['fi_geo_name']) ? '' : $_POST['fi_geo_name'];493 if($latitude != '' && $longitude != '' && $zoom != 0) {494 update_post_meta($post_id, $this->options->postmeta_lat, $latitude);495 update_post_meta($post_id, $this->options->postmeta_lng, $longitude);496 update_post_meta($post_id, $this->options->postmeta_zoom, $zoom);497 update_post_meta($post_id, $this->options->postmeta_name, $name);498 update_post_meta($post_id, $this->options->postmeta_public, true); // compatibility with Geolocation plugin499 }500 else {501 delete_post_meta($post_id, $this->options->postmeta_lat);502 delete_post_meta($post_id, $this->options->postmeta_lng);503 delete_post_meta($post_id, $this->options->postmeta_zoom);504 delete_post_meta($post_id, $this->options->postmeta_name);505 }506 }507 508 509 function display_geolocation_form() {510 if($this->options->use_location_sensor == 'yes') {511 wp_enqueue_script('googleapi');512 }513 wp_enqueue_script('fi-geolocation-form');514 515 global $post;516 $post_id = $post->ID;517 518 $lat = get_post_meta($post_id, $this->options->postmeta_lat, true);519 $lng = get_post_meta($post_id, $this->options->postmeta_lng, true);520 $zoom = get_post_meta($post_id, $this->options->postmeta_zoom, true);521 $name = get_post_meta($post_id, $this->options->postmeta_name, true);522 $show_marker = 1;523 524 // default if void525 if($lat =='' || $lng == '' || $zoom == '') {526 $lat = $this->options->default_map_lat;527 $lng = $this->options->default_map_lng;528 $zoom = $this->options->default_map_zoom;529 $show_marker = 0;530 }531 532 echo '533 <input name="fi_geo_marker" id="fi_geo_show_marker" type="hidden" value="' . $show_marker . '"/>534 <input name="fi_geo_lat" id="fi_geo_lat" type="hidden" value="' . $lat . '" />535 <input name="fi_geo_lng" id="fi_geo_lng" type="hidden" value="' . $lng . '" />536 <input name="fi_geo_zoom" id="fi_geo_zoom" type="hidden" value="' . $zoom . '" />537 <table class="form-table">538 <tr>539 <th style="width: 140px;">' . __('Search for a location', 'fi-geolocation') . '</th>540 <td><input name="fi_geo_search" id="fi_geo_search" type="text" value="" style="width: 100%; margin-right: 10px;" />541 <input type="button" id="fi_geo_search_button" name="fi_geo_search_button" value="' . __('Search', 'fi-geolocation') . '" class="button" />542 <input type="button" id="fi_geo_my_location_button" name="fi_geo_my_location_button" value="' . __('Set to my location', 'fi-geolocation') . '" class="button" style="visibility: hidden" /></td>543 </tr>544 <tr>545 <td colspan="2">546 <div id="fi_geo_map" style="height:400px; width:100%; padding:0px; margin:0px;"></div>547 </td>548 </tr>549 <tr>550 <th style="width: 140px;">' . __('Location name', 'fi-geolocation') . '</th>551 <td><input name="fi_geo_name" id="fi_geo_name" type="text" value="' . $name .'" style="width: 100%; margin-right: 10px;" />552 </td>553 </tr>554 <tr>555 <td><input type="button" id="fi_geo_clear_button" name="geotag_clear_button" value="' . __('Clear', 'fi-geolocation') . '" class="button" /></td>556 </tr>557 </table>';558 }559 560 561 function settings()562 {563 wp_enqueue_script('fi-settings');564 wp_enqueue_style( 'fi-geolocation-style');565 566 ?>567 <div class="wrap fi-geolocation">568 <div id="icon-options-general" class="icon32"><br /></div>569 <h2><?php _e('Geolocation Config', 'fi-geolocation'); ?></h2>570 571 <form action="options.php" method="post">572 <?php $this->options->settings_fields(); ?>573 574 <h3><?php _e('Single posts', 'fi-geolocation'); ?></h3>575 <table>576 <?php $this->options->render_single_post_options(); ?>577 <tr>578 <td colspan="2">579 <input type="submit" name="Submit" value="<?php _e('Save changes', 'fi-geolocation'); ?>" class="button-primary"/>580 </td>581 </tr>582 </table>583 584 <h3><?php _e('Archives', 'fi-geolocation'); ?></h3>585 <table>586 <?php $this->options->render_archives_options(); ?>587 <tr>588 <td colspan="2">589 <input type="submit" name="Submit" value="<?php _e('Save changes', 'fi-geolocation'); ?>" class="button-primary"/>590 </td>591 </tr>592 </table>593 594 <h3><?php _e('General settings', 'fi-geolocation'); ?></h3>595 <table>596 <?php $this->options->render_general_options(); ?>597 <tr>598 <td colspan="2">599 <input type="submit" name="Submit" value="<?php _e('Save changes', 'fi-geolocation'); ?>" class="button-primary"/>600 </td>601 </tr>602 </table>603 604 <h3><?php _e('Advanced settings', 'fi-geolocation'); ?></h3>605 <table>606 <?php $this->options->render_advanced_options(); ?>607 <tr>608 <td colspan="2">609 <input type="submit" name="Submit" value="<?php _e('Save changes', 'fi-geolocation'); ?>" class="button-primary"/>610 </td>611 </tr>612 </table>613 614 </form>615 </div>616 <?php617 }618 619 }620 621 622 /**623 *624 * Front-end625 *626 */627 class Fi_geolocation_frontend extends Fi_geolocation {628 var $has_showme_where = false;629 var $has_shortcode = 0;630 var $has_archive_map = false;631 632 function init() {633 parent::init();634 add_shortcode('geolocation', array(&$this,'geolocation_shortcode'));635 add_action('wp_footer', array(&$this, 'showme_config'));636 add_action('loop_start', array(&$this, 'automatic_archive_map'));637 add_filter('the_content', array(&$this, 'automatic_showme_where'), 99); // priority is low (we want shortcodes to be handled first)638 add_filter('em_events_output', array(&$this, 'em_events_output'), 10, 3);639 }640 641 642 function automatic_archive_map() {643 if((is_category() || is_tag() || is_tax()) && $this->options->archive_taxonomy == 'yes'644 || is_author() && $this->options->archive_author == 'yes'645 || is_home() && $this->options->archive_home == 'yes') {646 647 if(!$this->has_archive_map) {648 echo $this->get_archive_map();649 }650 }651 }652 653 654 function get_archive_map() {655 $this->has_archive_map = true;656 return '<div class="fi-archive-map" style="margin:auto;margin-bottom:20px;width:'.$this->options->archive_map_width.';height:'.$this->options->archive_map_height.'" coords="'.$this->options->archive_map_lat.','.$this->options->archive_map_lng.','.$this->options->archive_map_zoom.'"></div>';657 }658 659 /**660 * Integration with http://wordpress.org/extend/plugins/events-manager/661 */662 function em_events_output($output, $events, $args) {663 $this->has_showme_where = true;664 return $output;665 }666 667 668 function automatic_showme_where($content) {669 global $post;670 if($this->has_shortcode == $post->ID) {671 return $content;672 }673 674 switch ($this->options->default_showme_position) {675 case 'before_content':676 return $this->get_showme_where() . $content;677 case 'after_content':678 return $content . $this->get_showme_where();679 default:680 return $content;681 }682 }683 684 685 function get_showme_where() {686 $ret = '';687 688 global $post;689 690 $lat = get_post_meta($post->ID, $this->options->postmeta_lat, true);691 $lng = get_post_meta($post->ID, $this->options->postmeta_lng, true);692 $zoom = get_post_meta($post->ID, $this->options->postmeta_zoom, true);693 $name = get_post_meta($post->ID, $this->options->postmeta_name, true);694 695 $title = str_replace('#GEO_ADDRESS', $name, $this->options->default_showme_text);696 $title = str_replace('#POST_TITLE', $post->post_title, $title);697 698 699 if ($lat != '' && $lng != '' && $zoom != '' && !is_feed() && in_array(get_post_type($post), explode(',', $this->options->posttypes))) {700 if($this->options->default_showme_trigger == 'link_hover' || $this->options->default_showme_trigger == 'link_click') {701 $ret = '<p><a class="fi-showme-where-link" id="fi-showme-where-' . $post->ID .'" coords="'.$lat.','.$lng.','.$zoom.'" href="#fi-showme-where-popup">'.$title.'</a></p>';702 }703 if($this->options->default_showme_trigger == 'map') {704 $ret = '<div class="fi-showme-where-static" id="fi-showme-where-' . $post->ID .'" style="width:'.$this->options->default_map_width.';height:'.$this->options->default_map_height.'" coords="'.$lat.','.$lng.','.$zoom.'"></div>';705 }706 707 $this->has_showme_where = true;708 }709 710 return $ret;711 }712 713 714 function showme_config() {715 if($this->has_showme_where) {716 wp_enqueue_script('fi-geolocation-showme-where');717 wp_enqueue_style( 'fi-geolocation-style');718 719 echo '720 <div id="fi-showme-where-popup" style="width:'.$this->options->default_map_width.';height:'.$this->options->default_map_height.';position:absolute;visibility:hidden;top:0;left:0;z-index:9999" coords="'.$this->options->default_map_lat.','.$this->options->default_map_lng.','.$this->options->default_map_zoom.'"></div>721 <script type="text/javascript">722 var fi_popup_position=\'' . $this->options->default_popup_position . '\';723 var fi_showme_trigger=\'' . $this->options->default_showme_trigger . '\';724 var fi_showme_zoom=\'' . $this->options->default_showme_zoom . '\';725 var fi_site_url=\'' . site_url('/') . '\';726 </script>727 ';728 }729 730 if($this->has_archive_map) {731 wp_enqueue_script('fi-geolocation-archive-map');732 wp_enqueue_style( 'fi-geolocation-style');733 // TODO:734 // - enqueue a (dummy) script to get archive locations735 // - when script is loaded, get data from transient var736 echo '737 <script type="text/javascript">738 var fi_locations_in_archive=' . $this->get_locations_in_archive() . ';739 </script>740 ';741 }742 }743 744 745 function get_locations_in_archive() {746 // http://codex.wordpress.org/Class_Reference/wpdb747 global $wpdb, $wp_query;748 $queried_object = $wp_query->get_queried_object();749 750 $and_join = '';751 $and_where = '';752 753 if(is_home()) {754 $and_where .= ' AND p.post_type=\'post\'';755 }756 757 if(is_author()) {758 $and_where .= ' AND p.post_author=' . $queried_object->ID;759 }760 761 // TODO: find a more generic way for any taxonomy762 if(is_category() || is_tag() || is_tax()) {763 $and_join .= 'JOIN '.$wpdb->prefix.'term_relationships tr ON tr.object_id = t1.post_id';764 $and_where .= ' AND tr.term_taxonomy_id=' . $queried_object->term_id;765 }766 767 768 $query_places = "SELECT t1.meta_value AS lat, t2.meta_value AS lng, t1.post_id AS id, p.post_title AS title769 FROM " . $wpdb->prefix . "postmeta t1770 INNER JOIN " . $wpdb->prefix . "postmeta t2 ON t1.post_id = t2.post_id771 INNER JOIN " . $wpdb->prefix . "posts p ON p.ID = t1.post_id772 ".$and_join."773 WHERE p.post_status='publish'" . $and_where . "774 AND t1.meta_key = '".$this->options->postmeta_lat."'775 AND t2.meta_key = '".$this->options->postmeta_lng."'776 ORDER BY p.ID DESC777 LIMIT ".$this->options->markers_limit.";";778 $results = $wpdb->get_results($query_places);779 $json_places = 'false';780 if($results) {781 $json_places = json_encode($results);782 }783 return $json_places;784 }785 786 787 function geolocation_shortcode() {788 global $post;789 $this->has_shortcode = $post->ID;790 return $this->get_showme_where();791 }792 793 }794 795 796 /**797 * Init798 */799 if(is_admin()) {800 new Fi_geolocation_backend();801 }802 else {803 new Fi_geolocation_frontend();804 }805 load_plugin_textdomain( 'fi-geolocation', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); -
fi-geolocation/trunk/readme.txt
r647542 r648734 5 5 Requires at least: 3.0.0 6 6 Tested up to: 3.5.0 7 Stable tag: 1. 1.07 Stable tag: 1.2.0 8 8 9 Attach geographic data to your content and display it on a map for your site/blog visitors. 9 Sorry, discontinued 10 10 11 11 12 12 == Description == 13 Ideal for travel blogs, touristic sites, local news, anything dealing with geolocated content.14 15 * Current version of the plugin is shown [here](http://franceimage.com/wp-plugins/fi-geolocation/).16 * Experimenting future features is happening [here](http://franceimage.com/net/places-to-visit-in-france/).17 18 = New feature =19 20 * Insert maps showing geolocated posts on blog home, author page, tag, category and event custom taxonomy pages.21 22 = A better Geolocation plugin =23 24 * Configure the text of the link showing the map.25 * Enter the location text manually.26 * Can display a permanent map instead of a link to hover.27 * No inline javascript, resource loaded only when needed.28 * Internationalized.29 13 30 14 31 15 == Installation == 32 16 33 1. Upload the `fi-geolocation` directory to the `/wp-content/plugins/` directory.34 2. Activate the plugin through the 'Plugins' menu in WordPress.35 3. Modify the settings as needed on the Settings > Geolocation page.36 17 37 18 == Screenshots == 38 19 39 1. Popup map with geolocation data 20 40 21 41 22 == Changelog == 42 23 43 = 1.1.0 = 44 * Automatic insertion of archive maps (list of geolocated posts) 45 46 = 1.0.5 = 47 * Prepare integration with Events Manager plugin 48 * Show googlemap when click on popped map 49 * Some bug fixes 50 51 = 1.0.4 = 52 * Bug fix: test $_POST data to prevent notices when DEBUG is true 53 54 = 1.0.3 = 55 * Change default settings 56 * Make geolocation map zoom configurable (either default zoom or zoom from post meta) 57 * Test presence of specific div to display map (fi-showme-where-target-{post_id}) 58 * Use fi prefix everywhere (js and css) 59 * Register script in init hook instead of plugin constructor 60 61 = 1.0.2 = 62 * When location sensor is enabled, use a button in post form to set location (instead of doing it automatically) 63 * Add a few hints in setting page 64 65 = 1.0.1 = 66 * Modify readme.txt 67 * Add a description for default map in settings 68 69 = 1.0.0 = 70 * Initial release. 71 72 73 74 75 76 77 78 79 80 24 = 1.2.0 = 25 * Discontinued, waiting for removal from directory
Note: See TracChangeset
for help on using the changeset viewer.