[ Index ]

MailPress 7.1

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

title

Body

[close]

/mp-includes/class/options/form/field_types/geotag/ -> geotag.php (source)

   1  <?php
   2  class MP_Form_field_type_geotag extends MP_form_field_type_
   3  {
   4      var $file        = __FILE__;
   5  
   6      var $id        = 'geotag';
   7  
   8      var $category     = 'composite';
   9  
  10      var $order        = 100;
  11  
  12  	function get_name( $field )
  13      {
  14          $this->field = $field;
  15          return ( isset( $this->field->settings['options']['is'] ) ) ? $this->prefix . '[' . $this->field->form_id . ']['. $this->field->id . '][' . $this->field->settings['options']['is'] . ']' : $this->prefix . '[' . $this->field->form_id . ']['. $this->field->id . ']';
  16      }
  17  
  18  	function get_id( $field )
  19      {
  20          $this->field = $field;
  21          return ( isset( $this->field->settings['options']['is'] ) ) ? $this->prefix .       $this->field->form_id .  '_'. $this->field->id .  '_' . $this->field->settings['options']['is']       : $this->prefix .       $this->field->form_id .  '_'. $this->field->id;
  22      }
  23  
  24  	function submitted( $field )
  25      {
  26          $this->field = $field;
  27  
  28          $options = $this->field->settings['googlemap'];
  29  
  30          $value = $this->get_value();
  31  
  32          $required     = ( isset( $this->field->settings['controls']['required'] ) && $this->field->settings['controls']['required'] );
  33          $empty     = ( empty( $value['lat'] ) || empty( $value['lng'] ) );
  34          $geotag_ok     = true;
  35  
  36          if ( $required && $empty )
  37          {
  38              $this->field->submitted['on_error'] = 1;
  39              return $this->field;
  40          }
  41  
  42          if ( isset( $options['lat_lng'] ) && !isset( $options['lat_lng_disabled'] ) ) if ( ( $value['lat'] != ( string )( float )$value['lat'] ) || ( $value['lng'] != ( string )( float )$value['lng'] ) ) $geotag_ok = false;
  43  
  44          if ( !$geotag_ok )
  45          {
  46              $this->field->submitted['on_error'] = 2;
  47              return $this->field;
  48          }
  49  
  50          $width  = ( float ) $this->field->settings['googlemap']['width'];
  51          $height = ( float ) $this->field->settings['googlemap']['height'];
  52          if ( $width  > 640 ) $width  = 640;
  53          if ( $height > 640 ) $height = 640;
  54  
  55          $args = array (     'lng'            => $value['lng'],
  56                          'lat'            => $value['lat'],
  57                           'center_lng'    => $value['center_lng'],
  58                          'center_lat'    => $value['center_lat'], 
  59                          'zoom'        => $value['zoomlevel'], 
  60                             'size'        => $width . 'x' . $height, 
  61                          'maptype'        => $value['maptype'], 
  62          );
  63          $value['reverse_geocoding'] = MP_Map::get_address( $value['lng'], $value['lat'] );
  64  
  65          $this->field->submitted['value'] = $value;
  66          $this->field->submitted['text']  = '';
  67          $this->field->submitted['text']  = 'lat : ' . $value['lat'] . ' lng : ' . $value['lng'] . "<br />\n\r";
  68          $this->field->submitted['text'] .= __( 'Reverse geocoding :', 'MailPress' ) . ' ' . ( ( !empty( $value['reverse_geocoding'] ) ) ? $value['reverse_geocoding'] : '<small>[<i>' . __( 'empty', 'MailPress' ) . '</i>]</small>' ) . "<br />\n\r";
  69          if ( isset( $value['geocode'] ) ) $this->field->submitted['text'] .= ( ( !empty( $value['geocode'] ) ) ? 'geocode : ' . $value['geocode'] : '<small>[<i>' . __( 'empty', 'MailPress' ) . '</i>]</small>' ) . "<br />\n\r";
  70  
  71          $this->field->submitted['map']   =  MP_Map::get_staticmap( false, $args );
  72  
  73          return $this->field;
  74      }
  75  
  76  	function attributes_filter( $no_reset )
  77      {
  78          $xlatlng = MP_Ip::get_current_latlng();
  79  
  80          $options = $this->field->settings['googlemap'];
  81  
  82          $options['lat'] = $options['center_lat'] = ( $xlatlng ) ? ( float ) trim( $xlatlng['lat'] ) : ( float ) trim( $options['lat'] );
  83          $options['lng'] = $options['center_lng'] = ( $xlatlng ) ? ( float ) trim( $xlatlng['lng'] ) : ( float ) trim( $options['lng'] );
  84  
  85          if ( isset( $options['geocode'] ) ) $options['geocode_value'] = MP_Map::get_address( $options['lng'], $options['lat'] );
  86          $this->field->settings['googlemap'] = $options;
  87  
  88          if ( !$no_reset ) return;
  89  
  90          $post_ = $this->get_value();
  91          $options['lat']         = ( float ) $post_['lat'];
  92          $options['lng']         = ( float ) $post_['lng'];
  93          $options['center_lat']     = ( float ) $post_['center_lat'];
  94          $options['center_lng']     = ( float ) $post_['center_lng'];
  95          $options['zoomlevel']     = $post_['zoomlevel'];
  96          $options['maptype']         = $post_['maptype'];
  97  
  98          if ( isset( $options['geocode'] ) ) $options['geocode_value'] =  esc_attr( $post_['geocode'] );
  99          
 100          $this->field->settings['googlemap'] = $options;
 101  
 102          $this->attributes_filter_css();
 103      }
 104  
 105  	function build_tag()
 106      {
 107          $options = $this->field->settings['googlemap'];
 108      //map
 109          $this->field->settings['options']['is'] = 'map';
 110          $id_map    = $this->get_id( $this->field );
 111          $style    = ' style="overflow:hidden;width:' . trim( $options['width'] ) . ';height:' . trim( $options['height'] ) . ';"';
 112          $tag_map    = '<div id="' . $id_map . '"' . $style . '></div>';
 113          $tag_map  .= "\r\n";
 114          //zoomlevel
 115              $this->field->settings['attributes']['type'] = 'hidden';
 116  
 117              $this->field->settings['attributes']['value'] = $options['zoomlevel'];
 118              $this->field->settings['options']['is'] = 'zoomlevel';
 119              $tag_map .= parent::build_tag();
 120          //maptype
 121              $this->field->settings['attributes']['value'] = $options['maptype'];
 122              $this->field->settings['options']['is'] = 'maptype';
 123              $tag_map .= parent::build_tag();
 124          //center_lat
 125              $this->field->settings['attributes']['value'] = $options['center_lat'];
 126              $this->field->settings['options']['is'] = 'center_lat';
 127              $tag_map .= parent::build_tag();
 128          //center_lng
 129              $this->field->settings['attributes']['value'] = $options['center_lng'];
 130              $this->field->settings['options']['is'] = 'center_lng';
 131              $tag_map .= parent::build_tag();
 132  
 133      // lat, lng
 134          $tag_lat = $tag_lng = $id_lat_d = $id_lng_d = '';
 135          $this->field->type = 'text';
 136          if ( isset( $options['lat_lng'] ) )
 137          {
 138              if ( !isset( $options['lat_lng_disabled'] ) )
 139              {
 140                  // lat lng text
 141                  $this->field->settings['attributes']['type'] = 'text';
 142                  $this->field->settings['attributes']['size']  = $options['lat_lng_size'];
 143                  $this->field->settings['attributes']['value'] = $options['lat'];
 144  
 145                  $this->field->settings['options']['is'] = 'lat';
 146                  $id_lat    = $this->get_id( $this->field );
 147                  $tag_lat    = parent::build_tag();
 148  
 149                  $this->field->settings['attributes']['value'] = $options['lng'];
 150  
 151                  $this->field->settings['options']['is'] = 'lng';
 152                  $id_lng    = $this->get_id( $this->field );
 153                  $tag_lng    = parent::build_tag();
 154              }
 155              else
 156              {
 157                  // lat lng text             id et name differents
 158                  $this->field->settings['attributes']['type'] = 'text';
 159                  $this->field->settings['attributes']['size']  = $options['lat_lng_size'];
 160                  $this->field->settings['attributes']['value'] = $options['lat'];
 161                  $this->field->settings['attributes']['disabled'] = 'disabled';
 162  
 163                  $this->field->settings['options']['is'] = 'lat_d';
 164                  $id_lat_d    = $this->get_id( $this->field );
 165                  $tag_lat    = parent::build_tag();
 166  
 167                  $this->field->settings['attributes']['value'] = $options['lng'];
 168  
 169                  $this->field->settings['options']['is'] = 'lng_d';
 170                  $id_lng_d    = $this->get_id( $this->field );
 171                  $tag_lng    = parent::build_tag();
 172  
 173                  // lat lng hidden
 174                  unset( $this->field->settings['attributes']['disabled'], $this->field->settings['attributes']['size'] );
 175  
 176                  $this->field->settings['attributes']['type'] = 'hidden';
 177                  $this->field->settings['attributes']['value'] = $options['lat'];
 178  
 179                  $this->field->settings['options']['is'] = 'lat';
 180                  $id_lat    = $this->get_id( $this->field );
 181                  $tag_map .= parent::build_tag();
 182  
 183                  $this->field->settings['attributes']['value'] = $options['lng'];
 184  
 185                  $this->field->settings['options']['is'] = 'lng';
 186                  $id_lng    = $this->get_id( $this->field );
 187                  $tag_map .= parent::build_tag();
 188              }
 189          }
 190          else
 191          {
 192              // lat lng hidden
 193              unset( $this->field->settings['attributes']['disabled'], $this->field->settings['attributes']['size'] );
 194  
 195              $this->field->settings['attributes']['type'] = 'hidden';
 196              $this->field->settings['attributes']['value'] = $options['lat'];
 197  
 198              $this->field->settings['options']['is'] = 'lat';
 199              $id_lat    = $this->get_id( $this->field );
 200              $tag_map .= parent::build_tag();
 201  
 202  
 203              $this->field->settings['attributes']['value'] = $options['lng'];
 204  
 205              $this->field->settings['options']['is'] = 'lng';
 206              $id_lng    = $this->get_id( $this->field );
 207              $tag_map .= parent::build_tag();
 208          }
 209  
 210      // geocode
 211          $id_geocode = $tag_geocode = $id_geocode_button    = $tag_geocode_button = '';
 212          if ( isset( $options['geocode'] ) ) 
 213          {
 214          // input text
 215              unset( $this->field->settings['attributes']['disabled'] );
 216  
 217              $this->field->settings['attributes']['type']  = 'text';
 218              $this->field->settings['attributes']['size']  = $options['geocode_size'];
 219              $this->field->settings['attributes']['value'] = ( isset( $options['geocode_value'] ) ) ? $options['geocode_value'] : '';
 220  
 221              $this->field->settings['options']['is'] = 'geocode';
 222              $id_geocode        = $this->get_id( $this->field );
 223              $tag_geocode    = parent::build_tag();
 224  
 225          // button
 226              $this->field->type = 'button';
 227              unset( $this->field->settings['attributes']['size'] );
 228  
 229              $this->field->settings['attributes']['type'] = 'button';
 230              $this->field->settings['attributes']['value'] = $options['geocode_button'];
 231  
 232              $this->field->settings['options']['is'] = 'geocode_button';
 233              $id_geocode_button    = $this->get_id( $this->field );
 234              $tag_geocode_button    = parent::build_tag();
 235          }
 236  
 237      // css & javascript
 238                  $scripts = array();
 239          if ( !defined( 'MP_FORM_GEOTAG' ) )
 240          {
 241              global $mp_general;
 242              define ( 'MP_FORM_GEOTAG', true );
 243              $scripts = MP_Map::form_geotag( $options );
 244          }
 245  
 246          $x = array();
 247          $x['form'] = $this->field->form_id; $x['field'] = $this->field->id;
 248          foreach ( array( 'lat', 'lng', 'center_lat', 'center_lng', 'maptype', 'zoomlevel', 'zoom', 'changemap', 'center', 'lat_lng', 'lat_lng_disabled', 'rgeocode' ) as $opt ) $x[$opt] = ( isset( $options[$opt] ) ) ? $options[$opt] : '0';
 249          $m = array( 'mp_field_type_geotag_' . $this->field->form_id .  '_'. $this->field->id => $x );
 250          $scripts['f'][] = '<script type="text/javascript">' . "\n" . '/* <![CDATA[ */';
 251          foreach ( $m as $var => $val ) $scripts['f'][] = "var $var = " . MP_::print_scripts_l10n_val( $val, true );
 252          $scripts['f'][] = ";\njQuery( document ).ready( function() { var mp_form_" . $this->field->form_id . '_' . $this->field->id  . " = new mp_field_type_geotag( mp_field_type_geotag_" . $this->field->form_id .  '_'. $this->field->id . " ); } );\n/* ]]> */\n</script>";
 253  
 254          foreach( array( 'h' => 'header', 'f' => 'footer' ) as $k => $v )
 255          {
 256              if ( isset( $scripts[$k] ) )
 257              {
 258                  array_unshift( $scripts[$k], "<!-- start $v -->" );
 259                  array_push(    $scripts[$k], "<!-- end $v -->" );
 260              }
 261              else
 262              {
 263                  $scripts[$k][] = "<!-- no $v -->";
 264              }
 265              $$v = "\r\n" . implode( "\r\n", $scripts[$k] ) . "\r\n";
 266          }
 267  
 268      //end
 269          $this->field->type = $this->id;
 270  
 271          $sf  = '';
 272          $sf  = ( isset( $options['lat_lng'] ) ) ? 'latlng' : '';
 273          $sf .= ( isset( $options['geocode'] ) ) ? ( ( empty( $sf ) ) ? 'geocode' : '_geocode' ) : '';
 274          if ( empty( $sf ) ) $sf = 'alone';
 275  
 276          $form_formats['alone']        =  '{{map}}';
 277          $form_formats['latlng']        =  '{{map}}lat:{{lat}}&#160;lng:{{lng}}';
 278          $form_formats['geocode']        =  '{{map}}{{geocode}}&#160;{{geocode_button}}';
 279          $form_formats['latlng_geocode']    =  '{{map}}lat:{{lat}}&#160;lng:{{lng}}<br />{{geocode}}&#160;{{geocode_button}}';
 280  
 281          $form_formats = $this->get_formats( $form_formats );
 282  
 283          $search[] = '{{map}}';            $replace[] = '%1$s';
 284          $search[] = '{{id_map}}';            $replace[] = '%2$s';
 285          $search[] = '{{lat}}';             $replace[] = '%3$s';
 286          $search[] = '{{id_lat}}';             $replace[] = '%4$s';
 287          $search[] = '{{lng}}';             $replace[] = '%5$s';
 288          $search[] = '{{id_lng}}';            $replace[] = '%6$s';
 289          $search[] = '{{geocode}}';            $replace[] = '%7$s';
 290          $search[] = '{{id_geocode}}';        $replace[] = '%8$s';
 291          $search[] = '{{geocode_button}}';    $replace[] = '%9$s';
 292          $search[] = '{{id_geocode_button}}';    $replace[] = '%10$s';
 293             $search[] = '{{id_lat_dis}}';        $replace[] = '%11$s';
 294          $search[] = '{{id_lng_dis}}';        $replace[] = '%12$s';
 295  
 296          $html = str_replace( $search, $replace, $form_formats[$sf] );
 297          return $header . sprintf( $html, $tag_map, $id_map, $tag_lat, $id_lat, $tag_lng, $id_lng, $tag_geocode, $id_geocode, $tag_geocode_button, $id_geocode_button, $id_lat_d, $id_lng_d ) . $footer;
 298      }
 299  }
 300  new MP_Form_field_type_geotag( __( 'Geotag', 'MailPress' ) );


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