[ Index ]

MailPress 7.1

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

title

Body

[close]

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

   1  <?php
   2  class MP_Map
   3  {
   4      const provider = 'h';
   5  
   6  	public static function print_styles() 
   7      {
   8          wp_register_style(  'here',         'https://js.api.here.com/v3/3.0/mapsjs-ui.css' );
   9          wp_register_style(  'mp_map',         '/' . MP_PATH . 'mp-includes/class/options/map/here/map_here.css', array( 'here' ) );
  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              'app_id'          => $mp_general['here_id'],
  25              'app_code'        => $mp_general['here_code'],
  26          );
  27  
  28          wp_register_script( 'here_core', 'https://js.api.here.com/v3/3.0/mapsjs-core.js', false, false, 1 );
  29          wp_register_script( 'here_serv', 'https://js.api.here.com/v3/3.0/mapsjs-service.js', array( 'here_core' ), false, 1 );
  30          wp_register_script( 'here_ui',   'https://js.api.here.com/v3/3.0/mapsjs-ui.js', array( 'here_serv' ), false, 1 );
  31          wp_register_script( 'here_evts',  'https://js.api.here.com/v3/3.0/mapsjs-mapevents.js', array( 'here_ui' ), false, 1 );
  32          wp_register_script( 'here_c',    'https://js.api.here.com/v3/3.0/mapsjs-clustering.js', array( 'here_evts' ), false, 1 );
  33  
  34          wp_register_script( 'mp_map',         '/' . MP_PATH . 'mp-includes/class/options/map/mp_map_h.js', array( 'here_c', 'schedule' ), false, 1 );
  35          wp_localize_script( 'mp_map', 'mp_mapL10n', $mp_mapL10n );
  36  
  37          return 'mp_map';
  38      }
  39  
  40  	public static function form_geotag( $options )
  41      {
  42          global $mp_general;
  43  
  44          $h = array();
  45  
  46          $mp_mapL10n = array(
  47              'fullscreen'     => esc_js( __( 'Full screen', 'MailPress' ) ),
  48              'center'        => esc_js( __( 'Center on marker', 'MailPress' ) ), 
  49              'rgeocode'        => esc_js( __( 'Find marker address', 'MailPress' ) ), 
  50              'changemap'    => esc_js( __( 'Change map', 'MailPress' ) ),
  51              'app_id'          => $mp_general['here_id'],
  52              'app_code'        => $mp_general['here_code'],
  53           );
  54  
  55          $h['h'][] = '<link rel="stylesheet" href="https://js.api.here.com/v3/3.0/mapsjs-ui.css"          type="text/css" media="all" />';
  56          $h['h'][] = '<link rel="stylesheet" href="' . site_url() . '/' . MP_PATH . 'mp-includes/class/options/map/here/map_here.css" type="text/css" media="all" />';
  57  
  58          if ( !isset( $options['jQuery'] ) ) $h['h'][] = '<script type="text/javascript" src="' . site_url() . '/wp-includes/js/jquery/jquery.js"></script>';
  59  
  60          if ( !isset( $options['gmap'] ) ) 
  61          {
  62              $h['f'][] = '<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-core.js"></script>';
  63              $h['f'][] = '<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-service.js"></script>';
  64              $h['f'][] = '<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-ui.js"></script>';
  65              $h['f'][] = '<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js"></script>';
  66          }
  67  
  68          $h['f'][] = '<script type="text/javascript" src="' . site_url() . '/' . MP_PATH . 'mp-includes/class/options/map/mp_map_h_form_geotag.js"></script>';
  69  
  70          $h['f'][] = '<script type="text/javascript">';
  71          $h['f'][] = '/* <![CDATA[ */';
  72          foreach ( array( 'mp_mapL10n' => $mp_mapL10n ) as $var => $val ) $h['f'][] = "var $var = " . MP_::print_scripts_l10n_val( $val );
  73          $h['f'][] = ';';
  74          $h['f'][] = '/* ]]> */';
  75          $h['f'][] = '</script>';
  76  
  77          return $h;    
  78      }
  79  
  80  	public static function get_maptype( $maptype )
  81      {
  82          $m = array(    'SATELLITE'     => 1,
  83                      'HYBRID'        => 3,
  84                      'TERRAIN'        => 2,
  85                      'ROADMAP'        => 0,
  86          );
  87  
  88          return ( isset( $m[$maptype] ) ) ? $m[$maptype] : $m['ROADMAP'];
  89      }
  90  
  91  	public static function get_staticmap( $ip, $args = '' )  
  92      {
  93          global $mp_general;
  94  
  95          $x['geo'] = array( 'lng' => 0, 'lat' => 0 );
  96  
  97          if ( $ip )
  98          {
  99              $x  = MP_Ip::get_all( $ip );
 100  
 101              if ( !$x['geo']['lat'] && !$x['geo']['lng'] ) return array( 'src' => false, 'addr' => false );
 102          }
 103  
 104          $defaults = array (     'lng'            => $x['geo']['lng'],
 105                          'lat'            => $x['geo']['lat'],
 106                           'center_lng'    => $x['geo']['lng'],
 107                          'center_lat'    => $x['geo']['lat'], 
 108                          'zoom'        => 4, 
 109                             'size'        => '300x300', 
 110                          'maptype'        => 'ROADMAP', 
 111          );
 112  
 113          $r = wp_parse_args( $args, $defaults );
 114          extract( $r );
 115  
 116          $wh = explode( 'x', $size);
 117          $w = $wh[0];
 118          $h = $wh[1];
 119  
 120          $m = $lat . ',' . $lng;
 121          $c = $center_lat . ',' . $center_lng;
 122  
 123          $url  = 'https://image.maps.api.here.com/mia/1.6/mapview';
 124  
 125          $args = array();
 126          $args['c'] = $c;
 127          $args['z'] = $zoom;
 128          $args['w'] = $w;
 129          $args['h'] = $h;
 130          $args['t'] = self::get_maptype( $maptype );
 131          $args['poi'] = $m;
 132          $args['poithm'] = 0;
 133          $args['app_id']  = $mp_general['here_id'];
 134          $args['app_code']= $mp_general['here_code'];
 135  
 136          return add_query_arg( $args, $url );
 137      }
 138  
 139  	public static function get_address( $lng, $lat )
 140      {
 141          global $mp_general;
 142  
 143          $HTTP_USER_AGENT = filter_input( INPUT_SERVER, 'HTTP_USER_AGENT' );
 144  
 145          $args = array();
 146          $args['prox'] = $lat . ',' . $lng . ',0';
 147          $args['mode'] = 'retrieveAddresses';
 148          $args['maxresults'] = 1;
 149          $args['app_id']  = $mp_general['here_id'];
 150          $args['app_code']= $mp_general['here_code'];
 151  
 152          $url  = add_query_arg( $args, 'https://reverse.geocoder.api.here.com/6.2/reversegeocode.json' );
 153  
 154          $http = wp_remote_retrieve_body( wp_remote_get( $url, array( 'user-agent' => $HTTP_USER_AGENT ) ) );
 155          if ( !$http || empty( $http ) ) return false;
 156  
 157          $json = json_decode( $http );
 158  
 159          if ( isset( $json->Response->View[0]->Result[0]->Location ) ) $json = $json->Response->View[0]->Result[0]->Location;
 160          else return false;
 161  
 162          return ( isset( $json->Address->Label ) ) ? $json->Address->Label : '';
 163      }
 164  
 165  	public static function get_lnglat( $addr )
 166      {
 167          $HTTP_USER_AGENT = filter_input( INPUT_SERVER, 'HTTP_USER_AGENT' );
 168  
 169          $count = 1;
 170          $addr = trim( $addr );
 171          $addr = str_replace( array( "\r", "\n", "\t", ',', '.', '  ' ), ' ', $addr );
 172          while( $count) $addr = str_replace( '  ', ' ', $addr, $count );
 173          $addr = implode( '+', explode( ' ', $addr ) );
 174  
 175          global $mp_general;
 176  
 177          $args = array();
 178          $args['searchtext'] = $addr;
 179          $args['maxresults'] = 1;
 180          $args['app_id']  = $mp_general['here_id'];
 181          $args['app_code']= $mp_general['here_code'];
 182  
 183          $url  = add_query_arg( $args, 'https://geocoder.api.here.com/6.2/geocode.json' );
 184  
 185          $http = wp_remote_retrieve_body( wp_remote_get( $url, array( 'user-agent' => $HTTP_USER_AGENT ) ) );
 186          if ( !$http || empty( $http ) ) return false;
 187  
 188          $json = json_decode( $http );
 189  
 190          if ( isset( $json->Response->View[0]->Result[0]->Location ) ) $json = $json->Response->View[0]->Result[0]->Location;
 191          else return false;
 192  
 193          $a =    ( isset( $json->Address->Label ) )             ? $json->Address->Label             : '';
 194          $lat =  ( isset( $json->DisplayPosition->Latitude ) )  ? $json->DisplayPosition->Latitude  : 0;
 195          $lng =  ( isset( $json->DisplayPosition->Longitude ) ) ? $json->DisplayPosition->Longitude : 0;
 196  
 197          if ( ( $lng == 0 ) && ( $lat == 0 ) ) return false;
 198  
 199          return array( 'lng' => (float) $lng, 'lat' => (float) $lat, 'addr' => $a );
 200      }
 201  }


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