[ Index ]

MailPress 7.1

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/class/options/map/ -> MP_Map_g.class.php (source)

   1  <?php
   2  class MP_Map
   3  {
   4      const provider = 'g';
   5  
   6  	public static function print_styles() 
   7      {
   8          wp_register_style(  'mp_map',         '/' . MP_PATH . 'mp-includes/class/options/map/google/map_google.css' );
   9  
  10          return 'mp_map';
  11      }
  12  
  13  	public static function print_scripts()  
  14      {
  15          global $mp_general;
  16  
  17          $mp_mapL10n = array( 
  18              'id'            => MP_AdminPage::$get_['id'],
  19              'type'        => MP_AdminPage::map_of,
  20              'fullscreen'     => esc_js( __( 'Full screen', 'MailPress' ) ),
  21              'center'        => esc_js( __( 'Center', 'MailPress' ) ),
  22              'changemap'    => esc_js( __( 'Change map', 'MailPress' ) ),
  23              'url'            => site_url() . '/' . MP_PATH . 'mp-includes/class/options/map/google/images/',
  24          );
  25  
  26          wp_register_script( 'gmap_c', '/' . MP_PATH . 'mp-includes/class/options/map/google/markerclusterer.js', false, false, 1 );
  27          wp_register_script( 'gmap',   'https://maps.googleapis.com/maps/api/js?key=' . $mp_general['gmapkey'], array( 'gmap_c' ), false, 1 );
  28          wp_register_script( 'mp_map', '/' . MP_PATH . 'mp-includes/class/options/map/mp_map_g.js', array( 'gmap', 'schedule' ), false, 1 );
  29          wp_localize_script( 'mp_map', 'mp_mapL10n', $mp_mapL10n );
  30  
  31          return 'mp_map';
  32      }
  33  
  34  	public static function form_geotag( $options )
  35      {
  36          global $mp_general;
  37  
  38          $h = array();
  39  
  40          $mp_mapL10n = array( 
  41              'fullscreen'     => esc_js( __( 'Full screen', 'MailPress' ) ),
  42              'center'        => esc_js( __( 'Center on marker', 'MailPress' ) ), 
  43              'rgeocode'        => esc_js( __( 'Find marker address', 'MailPress' ) ), 
  44              'changemap'    => esc_js( __( 'Change map', 'MailPress' ) ),
  45           );
  46  
  47          $h['h'][] = '<link rel="stylesheet" href="' . site_url() . '/' . MP_PATH . 'mp-includes/class/options/map/google/map_google.css" type="text/css" media="all" />';
  48  
  49          if ( !isset( $options['jQuery'] ) ) $h['h'][] = '<script type="text/javascript" src="' . site_url() . '/wp-includes/js/jquery/jquery.js"></script>';
  50  
  51          if ( !isset( $options['gmap']   ) ) $h['f'][] = '<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=' . $mp_general['gmapkey'] . '"></script>';
  52          $h['f'][] = '<script type="text/javascript" src="' . site_url() . '/' . MP_PATH . 'mp-includes/class/options/map/mp_map_g_form_geotag.js"></script>';
  53  
  54          $h['f'][] = '<script type="text/javascript">';
  55          $h['f'][] = '/* <![CDATA[ */';
  56          foreach ( array( 'mp_mapL10n' => $mp_mapL10n ) as $var => $val ) $h['f'][] = "var $var = " . MP_::print_scripts_l10n_val( $val );
  57          $h['f'][] = ';';
  58          $h['f'][] = '/* ]]> */';
  59          $h['f'][] = '</script>';
  60  
  61          return $h;
  62      }
  63  
  64  	public static function get_maptype( $maptype )
  65      {
  66          $m = array(    'SATELLITE'     => 'satellite',
  67                      'HYBRID'        => 'hybrid',
  68                      'TERRAIN'        => 'terrain',
  69                      'ROADMAP'        => 'roadmap',
  70          );
  71  
  72          return ( isset( $m[$maptype] ) ) ? $m[$maptype] : $m['ROADMAP'];
  73      }
  74  
  75  	public static function get_staticmap( $ip, $args = '' )
  76      {
  77          global $mp_general;
  78  
  79          $x['geo'] = array( 'lng' => 0, 'lat' => 0 );
  80  
  81          if ( $ip )
  82          {
  83              $x  = MP_Ip::get_all( $ip );
  84  
  85              if ( !$x['geo']['lat'] && !$x['geo']['lng'] ) return array( 'src' => false, 'addr' => false );
  86          }
  87  
  88          $defaults = array (     'lng'            => $x['geo']['lng'],
  89                          'lat'            => $x['geo']['lat'],
  90                           'center_lng'    => $x['geo']['lng'],
  91                          'center_lat'    => $x['geo']['lat'], 
  92                          'zoom'        => 4, 
  93                          'bearing'        => 0,
  94                          'pitch'        => 50, 
  95                             'size'        => '300x300', 
  96                          'maptype'        => 'ROADMAP', 
  97          );
  98  
  99          $r = wp_parse_args( $args, $defaults );
 100          extract( $r );
 101  
 102          $args = array();
 103          $args['center']  = $center_lat . ',' . $center_lng;
 104          $args['zoom']    = $zoom;
 105          $args['size']    = $size;
 106          $args['maptype'] = self::get_maptype( $maptype );
 107          $args['markers'] = $lat . ',' . $lng;
 108          $args['key']     = $mp_general['gmapkey'];
 109  
 110          return add_query_arg( $args, 'https://maps.googleapis.com/maps/api/staticmap' );
 111      }
 112  
 113  	public static function get_address( $lng, $lat )
 114      {
 115          global $mp_general;
 116  
 117          $args = array();
 118          $args['latlng'] = settype( $lat, 'float' ) . ',' . settype( $lng, 'float' );
 119          $args['key'] = $mp_general['gmapkey'];
 120  
 121          $url  = add_query_arg( $args, 'https://maps.googleapis.com/maps/api/geocode/json' );
 122  
 123          $http = file_get_contents( $url );
 124          if ( !$http || empty( $http ) ) return false;
 125  
 126          $json = json_decode( $http );
 127          if ( !$json ) return false;
 128          if ( 'OK' != $json->status ) return false;
 129  
 130          if ( isset( $json->results[0] ) ) $json = $json->results[0];
 131          else return false;
 132  
 133          return ( isset( $json->formatted_address ) ) ? $json->formatted_address : '';
 134      }
 135  
 136  	public static function get_lnglat( $addr )
 137      {
 138          $count = 1;
 139          $addr = trim( $addr );
 140          $addr = str_replace( array( "\r", "\n", "\t", '  ' ), ' ', $addr );
 141          while( $count) $addr = str_replace( '  ', ' ', $addr, $count );
 142          $addr = implode( '+', explode( ' ', $addr ) );
 143  
 144          global $mp_general;
 145  
 146          $args = array();
 147          $args['address'] = $addr;
 148          $args['key'] = $mp_general['gmapkey'];
 149  
 150          $url  = add_query_arg( $args, 'https://maps.googleapis.com/maps/api/geocode/json' );
 151  
 152          $http = file_get_contents( $url );
 153          if ( !$http || empty( $http ) ) return false;
 154  
 155          $json = json_decode( $http );
 156          if ( !$json ) return false;
 157          if ( 'OK' != $json->status ) return false;
 158  
 159          if ( isset( $json->results[0] ) ) $json = $json->results[0];
 160          else return false;
 161  
 162          $a =    ( isset( $json->formatted_address ) )       ? $json->formatted_address       : '';
 163          $lat =  ( isset( $json->geometry->location->lat ) ) ? $json->geometry->location->lat : 0;
 164          $lng =  ( isset( $json->geometry->location->lng ) ) ? $json->geometry->location->lng : 0;
 165  
 166          if ( ( $lng == 0 ) && ( $lat == 0 ) ) return false;
 167  
 168          return array( 'lng' => (float) $lng, 'lat' => (float) $lat, 'addr' => $a );
 169      }
 170  }


Generated: Mon Mar 11 18:33:33 2019 Cross-referenced by PHPXref 0.7.1