[ Index ]

MailPress 7.1

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

title

Body

[close]

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

   1  <?php
   2  class MP_Map
   3  {
   4      const provider = 'b';
   5  
   6  	public static function print_styles() 
   7      {
   8          wp_register_style(  'mp_map',         '/' . MP_PATH . 'mp-includes/class/options/map/bing/map_bing.css' );
   9  
  10          return 'mp_map';
  11      }
  12  
  13  	public static function print_scripts()  
  14      {
  15          add_action( 'admin_footer', array( __CLASS__, 'admin_footer' ), 99);
  16  
  17          global $mp_general;
  18  
  19          $mp_mapL10n = array( 
  20              'id'            => MP_AdminPage::$get_['id'],
  21              'type'        => MP_AdminPage::map_of,
  22              'fullscreen'     => esc_js( __( 'Full screen', 'MailPress' ) ),
  23              'center'        => esc_js( __( 'Center', 'MailPress' ) ),
  24              'changemap'    => esc_js( __( 'Change map', 'MailPress' ) ),
  25              'bmapkey'        => $mp_general['bmapkey'],
  26          );
  27  
  28          wp_register_script( 'mp_map', '/' . MP_PATH . 'mp-includes/class/options/map/mp_map_b.js', array( 'schedule' ), false, 1 );
  29          wp_localize_script( 'mp_map', 'mp_mapL10n', $mp_mapL10n );
  30  
  31          return 'mp_map';
  32      }
  33  
  34  	public static function admin_footer()  
  35      {
  36          $h = array();
  37          $h[] = '';
  38  
  39          $h = array_merge( $h, self::get_bing_scripts() );
  40  
  41          echo implode( "\r\n", $h );
  42      }
  43  
  44  	public static function get_bing_scripts()  
  45      {
  46          global $mp_general;
  47  
  48          $callback = 'MicroSoftBing';
  49          $src = 'https://www.bing.com/api/maps/mapcontrol';
  50  
  51          $args = array();
  52          $args['callback'] = $callback;
  53          $args['key'] = $mp_general['bmapkey'];
  54  
  55          $src  = add_query_arg( $args, $src );
  56  
  57          $h = array();
  58  
  59          $h[] = '<script type="text/javascript"> function ' . $callback . '() { for (var i in MAILPRESS_data) new mp_map_bing(MAILPRESS_data[i]); } </script>';
  60          $h[] = '<script type="text/javascript" src="' . $src . '" async defer></script>';
  61  
  62          return $h;
  63      }
  64  
  65  	public static function form_geotag( $options )
  66      {
  67          global $mp_general;
  68  
  69          $h = array();
  70  
  71          $mp_mapL10n = array( 
  72              'fullscreen'     => esc_js( __( 'Full screen', 'MailPress' ) ),
  73              'center'        => esc_js( __( 'Center on marker', 'MailPress' ) ), 
  74              'rgeocode'        => esc_js( __( 'Find marker address', 'MailPress' ) ), 
  75              'changemap'    => esc_js( __( 'Change map', 'MailPress' ) ),
  76           );
  77  
  78          $callback = 'MicroSoftBing';
  79          $src = 'https://www.bing.com/api/maps/mapcontrol';
  80  
  81          $args = array();
  82          $args['callback'] = $callback;
  83          $args['key'] = $mp_general['bmapkey'];
  84  
  85          $src  = add_query_arg( $args, $src );
  86  
  87          $h['h'][] = '<link rel="stylesheet" href="' . site_url() . '/' . MP_PATH . 'mp-includes/class/options/map/bing/map_bing.css" type="text/css" media="all" />';
  88  
  89          if ( !isset( $options['jQuery'] ) ) $h['h'][] = '<script type="text/javascript" src="' . site_url() . '/wp-includes/js/jquery/jquery.js"></script>';
  90  
  91          if ( !isset( $options['gmap'] ) )   foreach( self::get_bing_scripts() as $s ) $h['f'][] = $s;
  92          $h['f'][] = '<script type="text/javascript" src="' . site_url() . '/' . MP_PATH . 'mp-includes/class/options/map/mp_map_b_form_geotag.js"></script>';
  93  
  94          $h['f'][] = '<script type="text/javascript">';
  95          $h['f'][] = '/* <![CDATA[ */';
  96          foreach ( array( 'mp_mapL10n' => $mp_mapL10n ) as $var => $val ) $h['f'][] = "var $var = " . MP_::print_scripts_l10n_val( $val );
  97          $h['f'][] = ';';
  98          $h['f'][] = '/* ]]> */';
  99          $h['f'][] = '</script>';
 100  
 101          return $h;
 102      }
 103  
 104  	public static function get_maptype( $maptype )
 105      {
 106          $m = array(    'SATELLITE'     => 'Aerial',
 107                      'HYBRID'        => 'AerialWithLabels',
 108                      'TERRAIN'        => 'CanvasLight',
 109                      'ROADMAP'        => 'Road',
 110          );
 111  
 112          return ( isset( $m[$maptype] ) ) ? $m[$maptype] : $m['ROADMAP'];
 113      }
 114  
 115  	public static function get_staticmap( $ip, $args = '' )
 116      {
 117          global $mp_general;
 118  
 119          $x['geo'] = array( 'lng' => 0, 'lat' => 0 );
 120  
 121          if ( $ip )
 122          {
 123              $x  = MP_Ip::get_all( $ip );
 124  
 125              if ( !$x['geo']['lat'] && !$x['geo']['lng'] ) return array( 'src' => false, 'addr' => false );
 126          }
 127  
 128          $defaults = array (     'lng'            => $x['geo']['lng'],
 129                          'lat'            => $x['geo']['lat'],
 130                           'center_lng'    => $x['geo']['lng'],
 131                          'center_lat'    => $x['geo']['lat'], 
 132                          'zoom'        => 4, 
 133                             'size'        => '300x300', 
 134                          'maptype'        => 'ROADMAP',
 135                          'format'        => 'png',
 136                          'key'            => $mp_general['bmapkey'],
 137          );
 138  
 139          $r = wp_parse_args( $args, $defaults );
 140          extract( $r );
 141  
 142          $url  = '';
 143          $url .= 'https://dev.virtualearth.net/REST/V1/Imagery/Map/';
 144          $url .= self::get_maptype( $maptype ) . '/';
 145          $url .= $center_lat . ',' . $center_lng  . '/';
 146          $url .= $zoom;
 147  
 148          $args = array();
 149          $args['mapSize'] = str_replace( 'x', ',', $size );
 150          $args['format'] = 'png';
 151          $args['pushpin'] = $lat . ',' . $lng  ;
 152          $args['key']     = $mp_general['bmapkey'];
 153  
 154          return add_query_arg( $args, $url );
 155      }
 156  
 157  	public static function get_address( $lng, $lat )
 158      {
 159          global $mp_general;
 160  
 161          $HTTP_USER_AGENT = filter_input( INPUT_SERVER, 'HTTP_USER_AGENT' );
 162  
 163          $url = 'http://dev.virtualearth.net/REST/v1/Locations/' . $lat . ',' . $lng;
 164  
 165          $args = array();
 166          $args['key'] = $mp_general['bmapkey'];
 167  
 168          $url  = add_query_arg( $args, $url );
 169  
 170          $http = wp_remote_retrieve_body( wp_remote_get( $url, array( 'user-agent' => $HTTP_USER_AGENT ) ) );
 171          if ( !$http || empty( $http ) ) return false;
 172  
 173          $json = json_decode( $http );
 174  
 175          if ( isset( $json->resourceSets[0]->resources[0] ) ) $json = $json->resourceSets[0]->resources[0];
 176          else return false;
 177  
 178          return ( isset( $json->name ) ) ? $json->name : '';
 179      }
 180  
 181  	public static function get_lnglat( $addr )
 182      {
 183          $HTTP_USER_AGENT = filter_input( INPUT_SERVER, 'HTTP_USER_AGENT' );
 184  
 185          $count = 1;
 186          $addr = trim( $addr );
 187          $addr = str_replace( array( "\r", "\n", "\t", '  ' ), ' ', $addr );
 188          while( $count) $addr = str_replace( '  ', ' ', $addr, $count );
 189          $addr = implode( '+', explode( ' ', $addr ) );
 190  
 191          global $mp_general;
 192  
 193          $args = array();
 194          $args['q'] = $addr;
 195          $args['maxResults'] = 1;
 196          $args['key'] = $mp_general['bmapkey'];
 197  
 198          $url  = add_query_arg( $args, 'http://dev.virtualearth.net/REST/v1/Locations' );
 199  
 200          $http = wp_remote_retrieve_body( wp_remote_get( $url, array( 'user-agent' => $HTTP_USER_AGENT ) ) );
 201          if ( !$http || empty( $http ) ) return false;
 202  
 203          $json = json_decode( $http );
 204  
 205          if ( isset( $json->resourceSets[0]->resources[0] ) ) $json = $json->resourceSets[0]->resources[0];
 206          else return false;
 207  
 208          $a =    ( isset( $json->name ) )                  ? $json->name                  : '';
 209          $lat =  ( isset( $json->point->coordinates[0] ) ) ? $json->point->coordinates[0] : 0;
 210          $lng =  ( isset( $json->point->coordinates[1] ) ) ? $json->point->coordinates[1] : 0;
 211  
 212          if ( ( $lng == 0 ) && ( $lat == 0 ) ) return false;
 213  
 214          return array( 'lng' => (float) $lng, 'lat' => (float) $lat, 'addr' => $a );
 215      }
 216  }


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