Skip to content
This repository
tree: 0aed9a4b9c
Fetching contributors…

Cannot retrieve contributors at this time

file 231 lines (205 sloc) 13.713 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
<?php

/**
* WP Geo Settings
*/
class WPGeo_Settings {

/**
* Constructor
*/
function WPGeo_Settings() {
$this->register_settings();
$this->filter_plugin_action_links();
}

/**
* Settings API
*/
function register_settings() {

// General Settings
add_settings_section( 'wpgeo_general', __( 'General Settings', 'wp-geo' ), array( $this, 'wp_mailfrom_settings_section' ), 'wp_geo_options' );
add_settings_field( 'google_api_key', __( 'Google API Key', 'wp-geo' ), array( $this, 'google_api_key_field' ), 'wp_geo_options', 'wpgeo_general' );
add_settings_field( 'google_map_type', __( 'Map Type', 'wp-geo' ), array( $this, 'google_map_type_field' ), 'wp_geo_options', 'wpgeo_general' );
  add_settings_field( 'show_post_map', __( 'Show Post Map', 'wp-geo' ), array( $this, 'show_post_map_field' ), 'wp_geo_options', 'wpgeo_general' );
  add_settings_field( 'default_map_location', __( 'Default Map Location', 'wp-geo' ), array( $this, 'default_map_location_field' ), 'wp_geo_options', 'wpgeo_general' );
  add_settings_field( 'default_map_width', __( 'Default Map Width', 'wp-geo' ), array( $this, 'default_map_width_field' ), 'wp_geo_options', 'wpgeo_general' );
  add_settings_field( 'default_map_height', __( 'Default Map Height', 'wp-geo' ), array( $this, 'default_map_height_field' ), 'wp_geo_options', 'wpgeo_general' );
  add_settings_field( 'default_map_zoom', __( 'Default Map Zoom', 'wp-geo' ), array( $this, 'default_map_zoom_field' ), 'wp_geo_options', 'wpgeo_general' );
  add_settings_field( 'default_map_controls', __( 'Default Map Controls', 'wp-geo' ), array( $this, 'default_map_controls_field' ), 'wp_geo_options', 'wpgeo_general' );
  add_settings_field( 'default_post_options', __( 'Default Post Options', 'wp-geo' ), array( $this, 'default_post_options_field' ), 'wp_geo_options', 'wpgeo_general' );
  add_settings_field( 'show_polylines', __( 'Polylines', 'wp-geo' ), array( $this, 'show_polylines_field' ), 'wp_geo_options', 'wpgeo_general' );
  add_settings_field( 'polyline_colour', __( 'Polyline Colour', 'wp-geo' ), array( $this, 'polyline_colour_field' ), 'wp_geo_options', 'wpgeo_general' );
  add_settings_field( 'show_maps_on', __( 'Show Maps On', 'wp-geo' ), array( $this, 'show_maps_on_field' ), 'wp_geo_options', 'wpgeo_general' );
  add_settings_field( 'feeds', __( 'Feeds', 'wp-geo' ), array( $this, 'feeds_field' ), 'wp_geo_options', 'wpgeo_general' );
 
  // Register Settings
  register_setting( 'wp_geo_options', 'wp_geo_options' );
}

/**
* Mail From Settings Section
*/
function wp_mailfrom_settings_section() {
echo '<p>'
. sprintf( __( "For more information and documentation about this plugin please visit the <a %s>WP Geo Plugin</a> home page.", 'wp-geo' ), 'href="http://www.benhuson.co.uk/wordpress-plugins/wp-geo/"' ) . '<br />'
. sprintf( __( "If you experience any problems/bugs with the plugin, please <a %s>log it here</a>.", 'wp-geo' ), 'href="http://code.google.com/p/wp-geo/issues/list"' ) .
'</p>';
}

/**
* Google API Key Field
*/
function google_api_key_field() {
$options = get_option( 'wp_geo_options' );
echo '<input name="wp_geo_options[google_api_key]" type="text" id="google_api_key" value="' . $options['google_api_key'] . '" class="regular-text" />';
}

/**
* Google Map Type Field
*/
function google_map_type_field() {
global $wpgeo;
$options = get_option( 'wp_geo_options' );
echo $wpgeo->google_map_types( 'menu', $options['google_map_type'], array( 'id' => 'google_map_type', 'name' => 'wp_geo_options[google_map_type]' ) );
}

/**
* Show Post Map Field
*/
function show_post_map_field() {
global $wpgeo;
$options = get_option( 'wp_geo_options' );
echo $wpgeo->post_map_menu( 'menu', $options['show_post_map'], array( 'id' => 'show_post_map', 'name' => 'wp_geo_options[show_post_map]' ) ) . '<br />';
echo $wpgeo->options_checkbox( 'wp_geo_options[show_maps_on_excerpts]', 'Y', $options['show_maps_on_excerpts'], false, 'show_maps_on_excerpts' ) . ' ' . __( 'Show on excerpts', 'wp-geo' );
}

/**
* Default Map Location Field
*/
function default_map_location_field() {
$options = get_option( 'wp_geo_options' );
echo __( 'When creating a new post, the map will default to focussing on this area for you to position a marker.', 'wp-geo' ) . '<br />';
echo '<label for="default_map_latitude" style="width:70px; display:inline-block;">' . __( 'Latitude', 'wp-geo' ) . '</label> <input name="wp_geo_options[default_map_latitude]" type="text" id="default_map_latitude" value="' . $options['default_map_latitude'] . '" size="25" /><br />';
echo '<label for="default_map_longitude" style="width:70px; display:inline-block;">' . __( 'Longitude', 'wp-geo' ) . '</label> <input name="wp_geo_options[default_map_longitude]" type="text" id="default_map_longitude" value="' . $options['default_map_longitude'] . '" size="25" />';
}

/**
* Default Map Width Field
*/
function default_map_width_field() {
$options = get_option( 'wp_geo_options' );
echo '<input name="wp_geo_options[default_map_width]" type="text" id="default_map_width" value="' . $options['default_map_width'] . '" size="10" />';
}

/**
* Default Map Height Field
*/
function default_map_height_field() {
$options = get_option( 'wp_geo_options' );
echo '<input name="wp_geo_options[default_map_height]" type="text" id="default_map_height" value="' . $options['default_map_height'] . '" size="10" />';
}

/**
* Default Map Height Field
*/
function default_map_zoom_field() {
global $wpgeo;
$options = get_option( 'wp_geo_options' );
echo $wpgeo->selectMapZoom( 'menu', $options['default_map_zoom'], array( 'id' => 'default_map_zoom', 'name' => 'wp_geo_options[default_map_zoom]' ) );
}

/**
* Default Map Controls Field
*/
function default_map_controls_field() {
global $wpgeo;
$options = get_option( 'wp_geo_options' );
echo $wpgeo->selectMapControl( 'menu', $options['default_map_control'], array( 'id' => 'default_map_control', 'name' => 'wp_geo_options[default_map_control]' ) ). '<br />';
echo '<p style="margin:1em 0 0 0;"><strong>' . __( 'Map Type Controls', 'wp-geo' ) . '</strong></p>';
echo '<p style="margin:0;">' . __( 'You must select at least 2 map types for the control to show.', 'wp-geo' ) . '</p>';
echo $wpgeo->options_checkbox( 'wp_geo_options[show_map_type_normal]', 'Y', $options['show_map_type_normal'], false, 'show_map_type_normal' ) . ' ' . __( 'Normal map', 'wp-geo' ) . '<br />';
echo $wpgeo->options_checkbox( 'wp_geo_options[show_map_type_satellite]', 'Y', $options['show_map_type_satellite'], false, 'show_map_type_satellite' ) . ' ' . __( 'Satellite (photographic map)', 'wp-geo' ) . '<br />';
echo $wpgeo->options_checkbox( 'wp_geo_options[show_map_type_hybrid]', 'Y', $options['show_map_type_hybrid'], false, 'show_map_type_hybrid' ) . ' ' . __( 'Hybrid (photographic map with normal features)', 'wp-geo' ) . '<br />';
echo $wpgeo->options_checkbox( 'wp_geo_options[show_map_type_physical]', 'Y', $options['show_map_type_physical'], false, 'show_map_type_physical' ) . ' ' . __( 'Physical (terrain map)', 'wp-geo' ) . '<br />';
echo '<p style="margin:1em 0 0 0;"><strong>' . __( 'Other Controls', 'wp-geo' ) . '</strong></p>';
echo $wpgeo->options_checkbox( 'wp_geo_options[show_map_scale]', 'Y', $options['show_map_scale'], false, 'show_map_scale' ) . ' ' . __( 'Show map scale', 'wp-geo' ) . '<br />';
echo $wpgeo->options_checkbox( 'wp_geo_options[show_map_overview]', 'Y', $options['show_map_overview'], false, 'show_map_overview' ) . ' ' . __( 'Show collapsible overview map (in the corner of the map)', 'wp-geo' );
}

/**
* Default Post Options Field
*/
function default_post_options_field() {
global $wpgeo;
$options = get_option( 'wp_geo_options' );
echo $wpgeo->options_checkbox( 'wp_geo_options[save_post_zoom]', 'Y', $options['save_post_zoom'], false, 'save_post_zoom' ) . ' ' . __( 'Save custom map zoom for this post', 'wp-geo' ) . '<br />';
echo $wpgeo->options_checkbox( 'wp_geo_options[save_post_map_type]', 'Y', $options['save_post_map_type'], false, 'save_post_map_type' ) . ' ' . __( 'Save custom map type for this post', 'wp-geo' ) . '<br />';
echo $wpgeo->options_checkbox( 'wp_geo_options[save_post_centre_point]', 'Y', $options['save_post_centre_point'], false, 'save_post_centre_point' ) . ' ' . __( 'Save map centre point for this post', 'wp-geo' );

}

/**
* Show Polylines Field
*/
function show_polylines_field() {
global $wpgeo;
$options = get_option( 'wp_geo_options' );
echo $wpgeo->options_checkbox( 'wp_geo_options[show_polylines]', 'Y', $options['show_polylines'], false, 'show_polylines' ) . ' ' . __( 'Show polylines (to connect multiple points on a single map)', 'wp-geo' );

}

/**
* Polyline Colour Field
*/
function polyline_colour_field() {
$options = get_option( 'wp_geo_options' );
echo '<input name="wp_geo_options[polyline_colour]" type="text" id="polyline_colour" value="' . $options['polyline_colour'] . '" size="7" />';
}

/**
* Show Maps On Field
*/
function show_maps_on_field() {
global $wpgeo;
$options = get_option( 'wp_geo_options' );
echo $wpgeo->options_checkbox( 'wp_geo_options[show_maps_on_pages]', 'Y', $options['show_maps_on_pages'], false, 'show_maps_on_pages' ) . ' ' . __( 'Pages', 'wp-geo' ) . '<br />';
echo $wpgeo->options_checkbox( 'wp_geo_options[show_maps_on_posts]', 'Y', $options['show_maps_on_posts'], false, 'show_maps_on_posts' ) . ' ' . __( 'Posts (single posts)', 'wp-geo' ) . '<br />';
echo $wpgeo->options_checkbox( 'wp_geo_options[show_maps_on_home]', 'Y', $options['show_maps_on_home'], false, 'show_maps_on_home' ) . ' ' . __( 'Posts home page', 'wp-geo' ) . '<br />';
echo $wpgeo->options_checkbox( 'wp_geo_options[show_maps_in_datearchives]', 'Y', $options['show_maps_in_datearchives'], false, 'show_maps_in_datearchives' ) . ' ' . __( 'Posts in date archives', 'wp-geo' ) . '<br />';
echo $wpgeo->options_checkbox( 'wp_geo_options[show_maps_in_categoryarchives]', 'Y', $options['show_maps_in_categoryarchives'], false, 'show_maps_in_categoryarchives' ) . ' ' . __( 'Posts in category archives', 'wp-geo' ) . '<br />';
echo $wpgeo->options_checkbox( 'wp_geo_options[show_maps_in_tagarchives]', 'Y', $options['show_maps_in_tagarchives'], false, 'show_maps_in_tagarchives' ) . ' ' . __( 'Posts in tag archives', 'wp-geo' ) . '<br />';
echo $wpgeo->options_checkbox( 'wp_geo_options[show_maps_in_taxarchives]', 'Y', $options['show_maps_in_taxarchives'], false, 'show_maps_in_taxarchives' ) . ' ' . __( 'Posts in taxonomy archives', 'wp-geo' ) . '<br />';
echo $wpgeo->options_checkbox( 'wp_geo_options[show_maps_in_authorarchives]', 'Y', $options['show_maps_in_authorarchives'], false, 'show_maps_in_authorarchives' ) . ' ' . __( 'Posts in author archives', 'wp-geo' ) . '<br />';
echo $wpgeo->options_checkbox( 'wp_geo_options[show_maps_in_searchresults]', 'Y', $options['show_maps_in_searchresults'], false, 'show_maps_in_searchresults' ) . ' ' . __( 'Search Results', 'wp-geo' ) . '<br />';

// Custom Post Types
// Only works in WordPress 3.0+
if ( function_exists( 'get_post_types' ) && function_exists( 'post_type_supports' ) ) {
$custom_post_type_checkboxes = '';
$post_types = get_post_types( array( '_builtin' => false ), 'objects' );
foreach ( $post_types as $post_type ) {
if ( post_type_supports( $post_type->query_var, 'wpgeo' )) {
$custom_post_type_checkboxes .= $wpgeo->options_checkbox( 'wp_geo_options[show_maps_on_customposttypes][' . $post_type->query_var . ']', 'Y', 'Y', true ) . ' ' . __( $post_type->label, 'wp-geo' ) . '<br />';
} elseif ( $post_type->show_ui ) {
$custom_post_type_checkbox_value = isset( $options['show_maps_on_customposttypes'][$post_type->query_var] ) ? $options['show_maps_on_customposttypes'][$post_type->query_var] : '';
$custom_post_type_checkboxes .= $wpgeo->options_checkbox( 'wp_geo_options[show_maps_on_customposttypes][' . $post_type->query_var . ']', 'Y', $custom_post_type_checkbox_value, false ) . ' ' . __( $post_type->label, 'wp-geo' ) . '<br />';
}
}
if ( ! empty( $custom_post_type_checkboxes ) ) {
echo '<strong>Custom Post Types</strong><br />' . $custom_post_type_checkboxes;
}
}
}

/**
* Feeds Field
*/
function feeds_field() {
global $wpgeo;
$options = get_option( 'wp_geo_options' );
echo $wpgeo->options_checkbox( 'wp_geo_options[add_geo_information_to_rss]', 'Y', $options['add_geo_information_to_rss'], false, 'add_geo_information_to_rss' ) . ' ' . __( 'Add geographic information', 'wp-geo' );
}

/**
* Filter Plugin Action Links
*/
function filter_plugin_action_links() {
add_filter( 'plugin_action_links', array( $this, 'wpgeo_filter_plugin_action_links' ), 10, 2 );
}

/**
* Based on the Sociable plugin, this adds a 'Settings' option
* to the entry on the WP Plugins page.
*
* @param array $links The array of links displayed by the plugins page
* @param string $file The current plugin being filtered.
* @return array Array of links.
*/
function wpgeo_filter_plugin_action_links( $links, $file ) {
if ( $file == 'wp-geo/wp-geo.php' ) {
$settings_link = '<a href="' . admin_url( 'options-general.php?page=wp-geo/includes/wp-geo.php' ) . '">' . __( 'Settings', 'wp-geo' ) . '</a>';
if ( ! in_array( $settings_link, $links ) )
array_unshift( $links, $settings_link );
}
return $links;
}

}

?>
Something went wrong with that request. Please try again.