[ Index ]

MailPress 7.1

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

title

Body

[close]

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

   1  <?php
   2  class MP_Map
   3  {
   4      const provider = 'm';
   5  
   6  	public static function print_styles() 
   7      {
   8          wp_register_style(  'mapbox',         'https://api.tiles.mapbox.com/mapbox-gl-js/v0.52.0/mapbox-gl.css' );
   9          wp_register_style(  'mp_map',         '/' . MP_PATH . 'mp-includes/class/options/map/mapbox/map_mapbox.css', array( 'mapbox' ) );
  10  
  11          return 'mp_map';
  12      }
  13  
  14  	public static function print_scripts()  
  15      {
  16          global $mp_general;
  17  
  18          $mp_mapL10n = array( 
  19              'id'            => MP_AdminPage::$get_['id'],
  20              'type'        => MP_AdminPage::map_of,
  21              'fullscreen'     => esc_js( __( 'Full screen', 'MailPress' ) ),
  22              'center'        => esc_js( __( 'Center', 'MailPress' ) ),
  23              'changemap'    => esc_js( __( 'Change map', 'MailPress' ) ),
  24              'mapboxtoken'    => $mp_general['mapboxtoken'],
  25          );
  26  
  27          wp_register_script( 'mapbox',         'https://api.tiles.mapbox.com/mapbox-gl-js/v0.52.0/mapbox-gl.js', false, false, 1 );
  28          wp_register_script( 'mp_map',         '/' . MP_PATH . 'mp-includes/class/options/map/mp_map_m.js', array( 'mapbox', '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              'mapboxtoken'    => $mp_general['mapboxtoken'],
  46           );
  47  
  48          $h['h'][] = '<link rel="stylesheet" href="https://api.tiles.mapbox.com/mapbox-gl-js/v0.52.0/mapbox-gl.css" type="text/css" media="all" />';
  49          $h['h'][] = '<link rel="stylesheet" href="' . site_url() . '/' . MP_PATH . 'mp-includes/class/options/map/mapbox/map_mapbox.css" type="text/css" media="all" />';
  50  
  51          if ( !isset( $options['jQuery'] ) ) $h['h'][] = '<script type="text/javascript" src="' . site_url() . '/wp-includes/js/jquery/jquery.js"></script>';
  52  
  53          if ( !isset( $options['gmap'] ) ) 
  54          {
  55              $h['f'][] = '<script type="text/javascript" src="https://api.tiles.mapbox.com/mapbox-gl-js/v0.52.0/mapbox-gl.js"></script>';
  56              $h['f'][] = '<script type="text/javascript" src="https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v3.1.0/mapbox-gl-geocoder.min.js"></script>';
  57          }
  58  
  59          $h['f'][] = '<script type="text/javascript" src="' . site_url() . '/' . MP_PATH . 'mp-includes/class/options/map/mp_map_m_form_geotag.js"></script>';
  60  
  61          $h['f'][] = '<script type="text/javascript">';
  62          $h['f'][] = '/* <![CDATA[ */';
  63          foreach ( array( 'mp_mapL10n' => $mp_mapL10n ) as $var => $val ) $h['f'][] = "var $var = " . MP_::print_scripts_l10n_val( $val );
  64          $h['f'][] = ';';
  65          $h['f'][] = '/* ]]> */';
  66          $h['f'][] = '</script>';
  67  
  68          return $h;
  69      }
  70  
  71  	public static function get_maptype( $maptype )
  72      {
  73          $m = array(    'SATELLITE'     => 'satellite-v9',
  74                      'HYBRID'        => 'satellite-streets-v11',
  75                      'TERRAIN'        => 'outdoors-v11',
  76                      'ROADMAP'        => 'streets-v11',
  77          );
  78  
  79          return ( isset( $m[$maptype] ) ) ? $m[$maptype] : $m['ROADMAP'];
  80      }
  81  
  82  	public static function get_staticmap( $ip, $args = '' )  
  83      {
  84          global $mp_general;
  85  
  86          $x['geo'] = array( 'lng' => 0, 'lat' => 0 );
  87  
  88          if ( $ip )
  89          {
  90              $x  = MP_Ip::get_all( $ip );
  91  
  92              if ( !$x['geo']['lat'] && !$x['geo']['lng'] ) return array( 'src' => false, 'addr' => false );
  93          }
  94  
  95          $defaults = array (     'lng'            => $x['geo']['lng'],
  96                          'lat'            => $x['geo']['lat'],
  97                           'center_lng'    => $x['geo']['lng'],
  98                          'center_lat'    => $x['geo']['lat'], 
  99                          'zoom'        => 4, 
 100                          'bearing'        => 0,
 101                          'pitch'        => 0, 
 102                             'size'        => '300x300', 
 103                          'maptype'        => 'ROADMAP', 
 104          );
 105  
 106          $r = wp_parse_args( $args, $defaults );
 107          extract( $r );
 108  
 109          $m = $lng . ',' . $lat;
 110          $c = $center_lng . ',' . $center_lat;
 111  
 112          $src  = 'https://api.mapbox.com/styles/v1/mapbox/' . self::get_maptype( $maptype ) . '/static/';
 113  
 114          $src .= 'pin-l+39C';                // marker icon + color
 115          $src .= '(' . $m . ')';             // marker pos
 116  
 117          $src .= '/' . $c . ',';            // center
 118          $src .= $zoom . ',';                // zoom 
 119          $src .= $bearing . ',';            // bearing (rotation)
 120          $src .= $pitch;                    // pitch   (perspective effect)
 121          $src .= '/' . $size;                // size
 122  
 123          $src .= '?access_token=' . $mp_general['mapboxtoken'];
 124  
 125          return $src;
 126      }
 127  
 128  	public static function get_address( $lng, $lat )
 129      {
 130          global $mp_general;
 131  
 132          $HTTP_USER_AGENT = filter_input( INPUT_SERVER, 'HTTP_USER_AGENT' );
 133  
 134          $args = array();
 135          $args['access_token'] = $mp_general['mapboxtoken'];
 136  
 137          $url  = add_query_arg( $args, 'https://api.mapbox.com/geocoding/v5/mapbox.places/' . $lng . ',' . $lat .'.json' );
 138  
 139          $http = wp_remote_retrieve_body( wp_remote_get( $url, array( 'user-agent' => $HTTP_USER_AGENT ) ) );
 140          if ( !$http || empty( $http ) ) return false;
 141  
 142          $json = json_decode( $http );
 143  
 144          if ( isset( $json->features[0] ) ) $json = $json->features[0];
 145          else return false;
 146  
 147          return ( isset( $json->place_name ) ) ? $json->place_name : '';
 148      }
 149  
 150  	public static function get_lnglat( $addr )
 151      {
 152          $HTTP_USER_AGENT = filter_input( INPUT_SERVER, 'HTTP_USER_AGENT' );
 153  
 154          $count = 1;
 155          $addr = trim( $addr );
 156          $addr = str_replace( array( "\r", "\n", "\t", ',', '.', '  ' ), ' ', $addr );
 157          while( $count) $addr = str_replace( '  ', ' ', $addr, $count );
 158          $addr = implode( '+', explode( ' ', $addr ) );
 159  
 160          global $mp_general;
 161  
 162          $args = array();
 163          $args['access_token'] = $mp_general['mapboxtoken'];
 164  
 165          $url = add_query_arg( $args, 'https://api.mapbox.com/geocoding/v5/mapbox.places/' . $addr . '.json' );
 166  
 167          $http = wp_remote_retrieve_body( wp_remote_get( $url, array( 'user-agent' => $HTTP_USER_AGENT ) ) );
 168          if ( !$http || empty( $http ) ) return false;
 169  
 170          $json = json_decode( $http );
 171  
 172          if ( isset( $json->features[0] ) ) $json = $json->features[0];
 173          else return false;
 174  
 175          $a =    ( isset( $json->place_name ) )               ? $json->place_name               : '';
 176          $lat =  ( isset( $json->geometry->coordinates[1] ) ) ? $json->geometry->coordinates[1] : 0;
 177          $lng =  ( isset( $json->geometry->coordinates[0] ) ) ? $json->geometry->coordinates[0] : 0;
 178  
 179          if ( ( $lng == 0 ) && ( $lat == 0 ) ) return false;
 180  
 181          return array( 'lng' => (float) $lng, 'lat' => (float) $lat, 'addr' => $a );
 182      }
 183  }


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