settings menu->ank google map
*/
add_action('admin_menu', array($this, 'agm_settings_menu'));
/*
* Additional link
*/
add_filter('plugin_row_meta', array($this, 'agm_set_plugin_meta'), 10, 2);
/*
* Save settings if first time
*/
if (false == get_option('ank_google_map')) {
$this->agm_settings_init();
}
/*
* Register our short-code [ank_google_map]
*/
add_shortcode('ank_google_map', array($this, 'agm_shortCode'));
/*
* Some (Notice) text on top of option page
*/
add_action('admin_notices', array($this, 'agm_notice'));
/*add custom screen options panel wp v3.0+*/
add_filter('screen_settings', array($this,'agm_screen_options'),10,2);
/* register ajax save function */
add_action('wp_ajax_save_settings-'.AGM_PLUGIN_SLUG, array(&$this, 'agm_save_screen_options'));
}/*end constructor*/
private function agm_settings_page_url()
{
return add_query_arg('page', AGM_PLUGIN_SLUG, 'options-general.php');
}
function agm_settings_menu()
{
$page_hook_suffix =add_submenu_page('options-general.php', 'Ank Google Map', 'Ank Google Map', 'manage_options', AGM_PLUGIN_SLUG, array($this, 'agm_settings_page'));
/*
* load color picker on plugin options page only
*/
add_action('admin_print_scripts-'. $page_hook_suffix, array($this, 'agm_add_color_picker'));
/*
* add help drop down menu on option page wp v3.3+
*/
if ( version_compare( $GLOBALS['wp_version'], '3.3', '>=' ) ) {
add_action( "load-$page_hook_suffix", array( $this, 'agm_help_menu' ) );
}
}
function agm_plugin_actions_links($links, $file)
{
static $plugin;
$plugin = plugin_basename(__FILE__);
if ($file == $plugin && current_user_can('manage_options')) {
array_unshift(
$links,
sprintf('%s', esc_attr($this->agm_settings_page_url()), __('Settings'))
);
}
return $links;
}
function agm_set_plugin_meta($links,$file)
{
/*
* additional link on plugin list page
*/
static $plugin;
$plugin = plugin_basename( __FILE__ );
if ( $file == $plugin ) {
$links[] = 'Read Me';
$links[] = 'GitHub';
}
return $links;
}
function agm_settings_page()
{
/*
* get settings page from this separate file
*/
if(is_file(__DIR__.'/agm_options_page.php')){
require('agm_options_page.php');
}else{
wp_die(__('A required file not found on server. Reinstall this plugin.
If problem persist, contact plugin developer.'));
}
}
/*
* Add a help tab at top of plugin option page
*/
public static function agm_help_menu()
{
/*get current screen obj*/
$curr_screen = get_current_screen();
$curr_screen->add_help_tab(
array(
'id' => 'agm-overview',
'title' => 'Overview',
'content' =>'
Thanks for using "Ank Google Map"
'.
'This plugin allows you to put a custom Google Map on your website. Just configure options below and '.
'save your settings. Copy/paste [ank_google_map] short-code on your page/post/widget to view your map.
'
)
);
$curr_screen->add_help_tab(
array(
'id' => 'agm-troubleshoot',
'title' => 'Troubleshoot',
'content' =>'Things to remember
'.
'
- If you are using a cache/performance plugin, you need to flush/delete your site cache after saving settings here.
- Only one map is supported at this time. Don't put short-code twice on the same page.
- Only one marker supported at this time, Marker will be positioned at the center of your map.
- Info Window needs marker to be enabled first.
'
)
);
$curr_screen->add_help_tab(
array(
'id' => 'agm-more-info',
'title' => 'More',
'content' =>'Need more information ?
'.
'A brief FAQ is available on plugin's official website.'.
'OR click here for more.
'.
'You can report a bug at plugin's GitHub page.'.
'I will try to reply as soon as possible.
'
)
);
/*help sidebar links */
$curr_screen->set_help_sidebar(
'Quick Links
' .
'Plugin FAQ
' .
'Plugin Home
'
);
}
function agm_notice()
{
/*
* Print notice text on top of our option page only
*/
$dir = is_rtl() ? 'left' : 'right';
if(strpos( get_current_screen()->id, AGM_PLUGIN_SLUG ) !== false)
echo "Explore More, Just click here ⟹
";
}
function agm_screen_options($current, $screen)
{
/*
* @source http://www.w-shadow.com/blog/2010/06/29/adding-stuff-to-wordpress-screen-options/
*/
if(strpos( $screen->id, AGM_PLUGIN_SLUG ) !== false){
$options= get_option('ank_google_map');
$current.='Text Editor Options
';
$current.='';
}
return $current;
}
function agm_save_screen_options()
{
if(isset($_POST['action'])&&$_POST['action']==='save_settings-'.AGM_PLUGIN_SLUG){
/*
* WP inbuilt form security check
*/
check_ajax_referer('save_settings-'.AGM_PLUGIN_SLUG,'_wpnonce-'.AGM_PLUGIN_SLUG);
$options = get_option('ank_google_map');
$options['te_meta_1']=(isset($_POST['agm_load_editor']))?'1':'0';
$options['te_meta_2']=(isset($_POST['agm_load_media']))?'1':'0';
$options['te_meta_3']=(isset($_POST['agm_load_teeny']))?'1':'0';
update_option('ank_google_map', $options);
die('1');
}
}
function agm_get_editor($content,$load,$media,$teeny)
{
/**
* decide if browser support editor or not
*/
if ( user_can_richedit() && $load==='1') {
$teeny=($teeny=='1')? true:false;
$media=($media=='1')? true:false;
wp_editor( $content,'agm-info-editor',
array(
'media_buttons' => $media,
'textarea_name' => 'info_text',
'textarea_rows' => 5,
'teeny' => $teeny,
'quicktags' =>true
) );
} else {
/*
* else Show normal text-area to user
*/
echo '';
}
}
function agm_settings_init()
{
/*
* these are default settings
* save settings in array for faster access
*/
$new_options = array(
'div_width' => '100',
'div_width_unit' => 2,
'div_height' => '300',
'div_border_color' => '#ccc',
'map_Lat' => '29.453182059948965',
'map_Lng' => '77.7068350911577',
'map_zoom' => 2,
'map_control_1' => '0',
'map_control_2' => '0',
'map_control_3' => '0',
'map_control_4' => '0',
'map_control_5' => '0',
'map_lang_code' => 'en',
'map_type' => 1,
'marker_on' => '1',
'marker_title' => 'I am here',
'marker_anim' => 1,
'marker_color' => 1,
'info_on' => '1',
'info_text' => 'Your Destination',
'info_state' => '0',
'te_meta_1' => '1' ,
'te_meta_2' => '0',
'te_meta_3' => '0'
);
/*
* save default settings to wp_options table
*
*/
add_option('ank_google_map', $new_options);
}
function agm_add_color_picker()
{
/*
* Add the color picker js + css file (for settings page only)
* Available for wp v3.5+ only
*/
if(version_compare($GLOBALS['wp_version'],3.5)>=0){
wp_enqueue_style('wp-color-picker');
wp_enqueue_script('wp-color-picker');
}
}
function agm_marker_url($id)
{
/**
* We depends on Google server for maker images
* @source http://ex-ample.blogspot.in/2011/08/all-url-of-markers-used-by-google-maps.html
*/
$path=array(
/* 1 is reserved for default */
'2'=>'https://maps.gstatic.com/intl/en_us/mapfiles/marker.png',
'3'=>'https://maps.gstatic.com/intl/en_us/mapfiles/marker_black.png',
'4'=>'https://maps.gstatic.com/intl/en_us/mapfiles/marker_grey.png',
'5'=>'https://maps.gstatic.com/intl/en_us/mapfiles/marker_orange.png',
'6'=>'https://maps.gstatic.com/intl/en_us/mapfiles/marker_white.png',
'7'=>'https://maps.gstatic.com/intl/en_us/mapfiles/marker_yellow.png',
'8'=>'https://maps.gstatic.com/intl/en_us/mapfiles/marker_purple.png',
'9'=>'https://maps.gstatic.com/intl/en_us/mapfiles/marker_green.png',
);
if(array_key_exists($id,$path)){
return $path[$id];
}else{
return false;
}
}
/* ********* front end started ********* */
function agm_write_html()
{
$options = get_option('ank_google_map');
/*
* Decide some options here
*/
$w_unit = ($options["div_width_unit"] === 1) ? 'px' : '%';
$b_color=(esc_attr($options["div_border_color"])==='')? '' : 'border:1px solid '.esc_attr($options["div_border_color"]);
echo '';
}
function agm_write_css(){
/*
* Special fixes for google map controls.
* They may appear incorrectly due to theme style
*/
echo "";
}
function agm_write_js()
{
$options = get_option('ank_google_map');
/*
* Decide some options here
*/
$mapType = 'ROADMAP';
if ($options['map_type'] === 1) {
$mapType = 'ROADMAP';
} elseif ($options['map_type'] === 2) {
$mapType = 'SATELLITE';
} elseif ($options['map_type'] === 3) {
$mapType = 'HYBRID';
} elseif ($options['map_type'] === 4) {
$mapType = 'TERRAIN';
}
$marker_anim = 'DROP';
if ($options['marker_on'] === '1') {
if ($options['marker_anim'] == 2) {
$marker_anim = 'BOUNCE';
} elseif ($options['marker_anim'] == 3) {
$marker_anim = 'DROP';
}
}
/*
* let browser+google decide the map language if no lang code specified by user
*/
$lang_code=(esc_attr($options['map_lang_code'])==='')? '' : '?language='.esc_attr($options['map_lang_code']);
?>
agm_trim_js(ob_get_clean());
}
function agm_trim_js($buffer)
{
/*we don't try to remove comments- can cause malfunction*/
/* remove tabs, spaces, newlines, etc. */
$buffer = str_replace(array("\r\n", "\r", "\t", "\n", ' ', ' ', ' '), '', $buffer);
/* remove other spaces before/after ) */
$buffer = preg_replace(array('(( )+\))', '(\)( )+)'), ')', $buffer);
return $buffer;
}
function agm_shortCode($params)
{
/*
* We accept two parameters in our short-code
* [ank_google_map css_fix=0] will disable css-fixes
* [ank_google_map js_order=0] will load map's js before other js files
*/
/*
* Merge user parameters with default
*/
$params=shortcode_atts(array(
'css_fix'=>1, /* 1=apply css fix, 0=don't apply css fix */
'js_order'=>1 /* 1=lowest priority, 0=normal priority*/
),$params);
ob_start();/* ob_start is here for a reason */
if($params['css_fix']==1){
/* ==write css fixes== */
$this->agm_write_css();
}
/* ==write html== */
$this->agm_write_html();
/* == decide priority of js code in footer == */
$js_priority=100;/*default,keep lower priority*/
if($params['js_order']==0){
/* Note: Enqueued scripts are executed at priority level 20.
The higher the number, the lower the priority
*/
$js_priority=19;
}
/*
* put js at footer, also prevent duplicate inclusion
*/
add_action('wp_footer', array($this, 'agm_write_js'),$js_priority);
return ob_get_clean();
}
} /*end class ank_google_map*/
} /*end if class exists*/
if ( class_exists( 'Ank_Google_Map' ) ) {
/*Init class */
if(!isset($Ank_Google_Map_Obj)){
$Ank_Google_Map_Obj=new Ank_Google_Map();
}
}
/*
* use [ank_google_map] short code (default)
* OR
* use [ank_google_map css_fix=0] to disable writing of css-fixes
* OR
* use [ank_google_map js_order=0] to load map's js before other js files
*/
?>