agm_settings_init(); } /* * Register our short-code [ank_google_map] */ add_shortcode('ank_google_map', array($this, 'agm_do_shortCode')); }/*end constructor*/ private function agm_settings_page_url() { return add_query_arg('page', AGM_PLUGIN_SLUG, 'options-general.php'); } 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_plugin_meta_links($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_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' => '', 'map_type' => 1, 'marker_on' => '1', 'marker_title' => 'We are 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', 'plugin_ver' => AGM_PLUGIN_VERSION, ); /* * save default settings to wp_options table * */ add_option('ank_google_map', $new_options); } 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) { /* * Decide some options here */ $w_unit = ($options["div_width_unit"] === 1) ? 'px' : '%'; $b_color=($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 */ ?> function Load_agm_Map() { var cn = new google.maps.LatLng(); var op = { center: cn, zoom: , mapTypeId: google.maps.MapTypeId.}; var map = new google.maps.Map(agm_div, op); var mk = new google.maps.Marker({ agm_marker_url($options['marker_color']).'",'; } ?> position: cn, map: map , title: "" }); var iw = new google.maps.InfoWindow({content: ""}); google.maps.event.addListener(map, 'click', function () { iw.close(); }); google.maps.event.addListener(mk, "click", function () { iw.open(map, mk); mk.setAnimation(null); }); window.setTimeout(function () { iw.open(map, mk); mk.setAnimation(null); }, 2000); var rT; google.maps.event.addDomListener(window, 'resize', function () { if (rT) { clearTimeout(rT); } rT = window.setTimeout(function () { map.setCenter(cn); }, 300); }); } var agm_div = document.getElementById("agm_map_canvas"); if (agm_div) { if (typeof google == "object") { google.maps.event.addDomListener(window, "load", Load_agm_Map) } else { agm_div.innerHTML = '

Failed to load Google Map.
Please try again.

'; agm_div.style.height="auto"; } } 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_create_js_file() { /*write js to a file*/ $file_name = __DIR__.'/agm-user-js.js'; $data=$this->agm_build_js(); $handle = fopen($file_name, 'w'); if($handle){ if(!fwrite($handle, $data)){ //could not write file @fclose($handle); return false; }else{ //success @fclose($handle); return true; } }else{ //could not open handle return false; } } function agm_do_shortCode($params) { /* We accept one parameter in short-code * [ank_google_map css_fix=0] will disable css-fixes * Lets Merge user parameters with default */ $params=shortcode_atts(array( 'css_fix'=>1, /* 1=apply css fix(default), 0=don't apply css fix */ ),$params); ob_start();/* ob_start is here for a reason */ $options = get_option('ank_google_map'); if($params['css_fix']==1){ /* ==write css fixes if== */ $this->agm_write_css(); } /* ==write html always== */ $this->agm_write_html($options); /* ==enqueue google map api always ==*/ $lang_code=(esc_attr($options['map_lang_code'])==='')? '' : '?language='.esc_attr($options['map_lang_code']); wp_enqueue_script('agm-google-map-api',"//maps.googleapis.com/maps/api/js".$lang_code,array(),null,true); /*enqueue our main js here*/ if(!file_exists(__DIR__.'/agm-user-js.js')){ /*file not found,try to create js file */ $this->agm_create_js_file(); } /* unique file version, every time the file get modified */ $file_ver=esc_attr(filemtime(__DIR__.'/agm-user-js.js')); wp_enqueue_script('agm-user-script',plugins_url('agm-user-js.js',__FILE__),array('agm-google-map-api'),$file_ver,true); return ob_get_clean(); } } /*end class ank_google_map*/ /*Init class */ if(!isset($Ank_Google_Map_Obj)){ $Ank_Google_Map_Obj=new Ank_Google_Map(); } } /*end if class exists*/ //load only to wp-admin area if (isset($Ank_Google_Map_Obj)&& is_admin() ) { /* Include Options Page */ require(trailingslashit(dirname(__FILE__)) . "agm_options_page.php"); /*Init option page class class */ if(!isset($Ank_Google_Map_Option_Page_Obj)){ $Ank_Google_Map_Option_Page_Obj=new Ank_Google_Map_Option_Page(); } } /* * use [ank_google_map] short code (default) * OR * use [ank_google_map css_fix=0] to disable css fixes */ ?>