• Resolved alm06130

    (@alm06130)


    Was bored to adjust map position each time: modify default values in osm-config.php, but overwritten by updates-> I suggest some modifications:

    in osm-config.php:

    define ("OSM_default_lat",  apply_filters('get_osm_default_lat', get_option("osm_default_lat",43.758629))); 
    define ("OSM_default_lon",  apply_filters('get_osm_default_lon', get_option("osm_default_lon",6.924225)));
    define ("OSM_default_zoom", apply_filters('get_osm_default_zoom', get_option("osm_default_zoom",11)));

    This permits to adjust default position and zoom from wp options, filtered if needed.

    In osm-options.php (some corrections, missing form tag, sanitized values):

    <form method="post">   
    <table>
     <tr> <h3>  PHP Interface setting:</h3> </tr>
     <tr>
      <td><label for="osm_zoom_level"><?php _e('Map Zoomlevel for the PHP Link (1-17)','OSM') ?>:</label></td>
      <td><input type="text" name="osm_zoom_level" value="<?php echo esc_attr($osm_zoom_level) ?>" /></td>
     </tr>
     <tr>
      <td><label for="osm_zoom_level"><?php _e('Default Latitude for maps','OSM') ?>:</label></td>
      <td><input type="text" name="osm_default_lat" value="<?php echo esc_attr($osm_default_lat) ?>" /></td>
     </tr>
     <tr>
      <td><label for="osm_zoom_level"><?php _e('Default Longitude for maps','OSM') ?>:</label></td>
      <td><input type="text" name="osm_default_lon" value="<?php echo esc_attr($osm_default_lon) ?>" /></td>
     </tr>
     <tr>
      <td><label for="osm_zoom_level"><?php _e('Default Zoom Level for maps','OSM') ?>:</label></td>
      <td><input type="text" name="osm_default_zoom" value="<?php echo esc_attr($osm_default_zoom) ?>" /></td>
     </tr>
    </table>
    <div class="submit"><input type="submit" name="Options" value="<?php _e('Update Options','OSM') ?> &raquo;" /></div>
    </form>

    This display form with settings for lon, lat, and zoom

    In osm.php, function option_page_osm:

      static function options_page_osm()
      {
          
        // 0 = no error;
        // 1 = error occured
        $Option_Error = 0;
        if(isset($_POST['Options'])){
    
          // get the zoomlevel for the external link
          // and inform the user if the level was out of range
          // update_option('osm_custom_field',$_POST['osm_custom_field']);
    
          if ($_POST['osm_zoom_level'] >= ZOOM_LEVEL_MIN && $_POST['osm_zoom_level'] <= ZOOM_LEVEL_MAX){
            update_option('osm_zoom_level',$_POST['osm_zoom_level']);
          }
          else {
            $Option_Error = 1;
            Osm::traceText(DEBUG_ERROR, "e_zoomlevel_range");
          }
        }
        else{
    	  //add_option('osm_custom_field', 0);
    	  add_option('osm_zoom_level', 0);
        }
    
        // name of the custom field to store Long and Lat
        // for the geodata of the post
        $osm_custom_field  = get_option('osm_custom_field','OSM_geo_data');
        // zoomlevel for the link the OSM page
        $osm_zoom_level    = get_option('osm_zoom_level','7');
               
        //default map values 
        $osm_default_lat=get_option('osm_default_lat',OSM_default_lat);  
        $osm_default_lon=get_option('osm_default_lon',OSM_default_lon);  
        $osm_default_zoom=get_option('osm_default_zoom',OSM_default_zoom); 
        // update default maps values
        if (isset($_POST['osm_default_lat'])) {
            $temp_lat=(float) $_POST['osm_default_lat'];
            if ($temp_lat>LAT_MAX || $temp_lat<LAT_MIN) {
              $Option_Error = 1;
              Osm::traceText(DEBUG_ERROR, "e_default_lat_range");   
            } else {
              $osm_default_lat=$temp_lat;   
              update_option('osm_default_lat',$temp_lat);  
            }
        } 
        if (isset($_POST['osm_default_lon'])) {
            $temp_lon=(float) $_POST['osm_default_lon'];
            if ($temp_lon>LON_MAX || $temp_lon<LON_MIN) {
              $Option_Error = 1;
              Osm::traceText(DEBUG_ERROR, "e_default_lon_range");   
            } else {
              $osm_default_lon=$temp_lon;   
              update_option('osm_default_lon',$temp_lon);  
            }
         } 
        if (isset($_POST['osm_default_zoom'])) {
            $temp_zoom=(int) $_POST['osm_default_zoom'];
            if ($temp_zoom>19 || $temp_zoom<1) {
              $Option_Error = 1;
              Osm::traceText(DEBUG_ERROR, "e_default_zoom_range");   
            } else {
              $osm_default_zoom=$temp_zoom;
              update_option('osm_default_zoom',$temp_zoom);  
            }
         } 
         // Let the user know whether all was fine or not
         if ($Option_Error  == 0){
            Osm::traceText(DEBUG_INFO, "i_options_updated");
         }
         else {
            Osm::traceText(DEBUG_ERROR, "e_options_not_updated");
         }
    
        include('osm-options.php');
      }

    This validate form submit

    Hope this can help

    Thanks again for this plugin
    alain

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author MiKa

    (@photoweblog)

    Hello alain,

    thanks!!!
    We will consider it at the next update.

    Br, MiKa

    Plugin Author MiKa

    (@photoweblog)

    We put it in the last version – thanks for your work!!!
    Br, MiKa
    BTW: Rating is welcome as well ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Suggestion: add default values for maps in settings’ is closed to new replies.