[ Index ]

MailPress 7.1

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

title

Body

[close]

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

   1  <?php
   2  class MP_Map
   3  {
   4      const provider = 'o';
   5  
   6  	public static function print_styles() 
   7      {
   8          wp_register_style(  'leaflet',         '/' . MP_PATH . 'mp-includes/class/options/map/leaflet/leaflet.css' );
   9          wp_register_style(  'leaflet_mc',     '/' . MP_PATH . 'mp-includes/class/options/map/leaflet/leaflet.markercluster.css' );
  10          wp_register_style(  'mp_map',         '/' . MP_PATH . 'mp-includes/class/options/map/leaflet/map_leaflet.css', array( 'leaflet', 'leaflet_mc' ) );
  11  
  12          return 'mp_map';
  13      }
  14  
  15  	public static function print_scripts()  
  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          );
  24  
  25          wp_register_script( 'leaflet',         '/' . MP_PATH . 'mp-includes/class/options/map/leaflet/leaflet.js', false, false, 1 );
  26          wp_register_script( 'leaflet_c',     '/' . MP_PATH . 'mp-includes/class/options/map/leaflet/leaflet.markercluster.js', array( 'leaflet' ), false, 1 );
  27          wp_register_script( 'mp_map',         '/' . MP_PATH . 'mp-includes/class/options/map/mp_map_o.js', array( 'leaflet_c', 'schedule' ), false, 1 );
  28          wp_localize_script( 'mp_map', 'mp_mapL10n', $mp_mapL10n );
  29  
  30          return 'mp_map';
  31      }
  32  
  33  	public static function form_geotag( $options )
  34      {
  35          $h = array();
  36  
  37          $mp_mapL10n = array( 
  38              'fullscreen'     => esc_js( __( 'Full screen', 'MailPress' ) ),
  39              'center'        => esc_js( __( 'Center on marker', 'MailPress' ) ), 
  40              'rgeocode'        => esc_js( __( 'Find marker address', 'MailPress' ) ), 
  41              'changemap'    => esc_js( __( 'Change map', 'MailPress' ) ),
  42              'url'            => admin_url( 'admin-ajax.php' ),
  43          );
  44  
  45          $h['h'][] = '<link rel="stylesheet" href="' . site_url() . '/' . MP_PATH . 'mp-includes/class/options/map/leaflet/leaflet.css"     type="text/css" media="all" />';
  46          $h['h'][] = '<link rel="stylesheet" href="' . site_url() . '/' . MP_PATH . 'mp-includes/class/options/map/leaflet/map_leaflet.css" type="text/css" media="all" />';
  47  
  48          if ( !isset( $options['jQuery'] ) ) $h['h'][] = '<script type="text/javascript" src="' . site_url() . '/wp-includes/js/jquery/jquery.js"></script>';
  49  
  50          if ( !isset( $options['gmap']   ) ) $h['f'][] = '<script type="text/javascript" src="' . site_url() . '/' . MP_PATH . 'mp-includes/class/options/map/leaflet/leaflet.js"></script>';
  51          $h['f'][] = '<script type="text/javascript" src="' . site_url() . '/' . MP_PATH . 'mp-includes/class/options/map/mp_map_o_form_geotag.js"></script>';
  52  
  53          $h['f'][] = '<script type="text/javascript">';
  54          $h['f'][] = '/* <![CDATA[ */';
  55          foreach ( array( 'mp_mapL10n' => $mp_mapL10n ) as $var => $val ) $h['f'][] = "var $var = " . MP_::print_scripts_l10n_val( $val );
  56          $h['f'][] = ';';
  57          $h['f'][] = '/* ]]> */';
  58          $h['f'][] = '</script>';
  59  
  60          return $h;
  61      }
  62  
  63  	public static function get_maptype( $maptype )
  64      {
  65          $m = array(    'ROADMAP'        => 'osmarenderer',
  66          );
  67  
  68          return ( isset( $m[$maptype] ) ) ? $m[$maptype] : $m['ROADMAP'];
  69      }
  70  
  71  	public static function get_staticmap( $ip, $args = '' )  
  72      {
  73          $x['geo'] = array( 'lng' => 0, 'lat' => 0 );
  74  
  75          if ( $ip )
  76          {
  77              $x  = MP_Ip::get_all( $ip );
  78  
  79              if ( !$x['geo']['lat'] && !$x['geo']['lng'] ) return array( 'src' => false, 'addr' => false );
  80          }
  81  
  82          $defaults = array (     'lng'            => $x['geo']['lng'],
  83                          'lat'            => $x['geo']['lat'],
  84                           'center_lng'    => $x['geo']['lng'],
  85                          'center_lat'    => $x['geo']['lat'], 
  86                          'zoom'        => 4, 
  87                          'bearing'        => 0,
  88                          'pitch'        => 50, 
  89                             'size'        => '300x300', 
  90                          'maptype'        => 'ROADMAP', 
  91          );
  92  
  93          $r = wp_parse_args( $args, $defaults );
  94          extract( $r );
  95  
  96          $m = $lat . ',' . $lng;
  97          $c = $center_lat . ',' . $center_lng;
  98  
  99          $args = array();
 100          $args['center']  = $c;
 101          $args['zoom']    = $zoom;
 102          $args['size']    = $size;
 103          $args['maptype'] = 'osmarenderer';
 104          $args['markers'] = $m . ',lightblue1';
 105  
 106          return add_query_arg( $args, 'https://staticmap.openstreetmap.de/staticmap.php' );
 107      }
 108  
 109  	public static function get_address( $lng, $lat )
 110      {
 111          $HTTP_USER_AGENT = filter_input( INPUT_SERVER, 'HTTP_USER_AGENT' );
 112  
 113          $args = array();
 114          $args['format']  = 'jsonv2';
 115          $args['addressdetails'] = 0;
 116          $args['lat'] = $lat;
 117          $args['lon'] = $lng;
 118  
 119          $url  = add_query_arg( $args, 'https://nominatim.openstreetmap.org/reverse' );
 120  
 121          $http = wp_remote_retrieve_body( wp_remote_get( $url, array( 'user-agent' => $HTTP_USER_AGENT ) ) );
 122          if ( !$http || empty( $http ) ) return false;
 123  
 124          $json = json_decode( $http );
 125          if ( !$json ) return false;
 126  
 127          return ( isset( $json->display_name ) ) ? $json->display_name : false;
 128      }
 129  
 130  	public static function get_lnglat( $addr )
 131      {
 132          $count = 1;
 133          $addr = trim( $addr );
 134          $addr = str_replace( array( "\r", "\n", "\t", ',', '.', '  ' ), ' ', $addr );
 135          while( $count) $addr = str_replace( '  ', ' ', $addr, $count );
 136          $addr = implode( '+', explode( ' ', $addr ) );
 137  
 138          $HTTP_USER_AGENT = filter_input( INPUT_SERVER, 'HTTP_USER_AGENT' );
 139  
 140          $args = array();
 141          $args['format'] = 'jsonv2';
 142          $args['addressdetails'] = 0;
 143          $args['limit'] = 1;
 144          $args['q'] = $addr;
 145  
 146          $url  = add_query_arg( $args, 'https://nominatim.openstreetmap.org/search' );
 147  
 148          $http = wp_remote_retrieve_body( wp_remote_get( $url, array( 'user-agent' => $HTTP_USER_AGENT ) ) );
 149          if ( !$http || empty( $http ) ) return false;
 150  
 151          $json = json_decode( $http );
 152          if ( !$json ) return false;
 153  
 154          if ( isset( $json[0] ) ) $json = $json[0];
 155          else return false;
 156          
 157          $a =    ( isset( $json->display_name ) ) ? $json->display_name : '';
 158          $lat =  ( isset( $json->lat ) )          ? $json->lat          : 0;
 159          $lng =  ( isset( $json->lon ) )          ? $json->lon          : 0;
 160  
 161          if ( ( $lng == 0 ) && ( $lat == 0 ) ) return false;
 162  
 163          return array( 'lng' => (float) $lng, 'lat' => (float) $lat, 'addr' => $a );
 164      }
 165  }


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