GeoMashup
[ class tree: GeoMashup ] [ index: GeoMashup ] [ all elements ]

Source for file edit-form.php

Documentation is available at edit-form.php

  1. <?php
  2. /**
  3.  * A function wrapper for the location editor HTML.
  4.  *
  5.  * @package GeoMashup
  6.  */
  7.  
  8. /**
  9.  * Print the Geo Mashup location editor HTML for an object.
  10.  *
  11.  * Goals for this interface are to make it usable for any kind of locatable
  12.  * object, to be usable without javascript, functional on the front end or admin,
  13.  * and eventually adaptable to editing multiple locations for an object.
  14.  *
  15.  * It's assumed this will go inside an existing form for editing the object,
  16.  * such as the WordPress admin post edit form.
  17.  *
  18.  * @since 1.2
  19.  * @see geo-mashup-ui-managers.php
  20.  * @see geo-mashup-location-editor.js
  21.  * @uses edit-form.css
  22.  * @access public
  23.  *
  24.  * @param string $object_name The type of object, e.g. 'post', 'user', etc.
  25.  * @param string $object_id The ID of the object being edited.
  26.  * @param string $ui_manager Optionally the name of UI Manager class to use for AJAX operations.
  27.  */
  28. function geo_mashup_edit_form$object_name$object_id$ui_manager '' {
  29.     global $geo_mashup_options;
  30.  
  31.     $help_class 'geo-mashup-js';
  32.     $add_input_style 'style="display:none;"';
  33.     $update_input_style $delete_input_style '';
  34.     $coordinate_string '';
  35.  
  36.     // Load any existing location for the object
  37.     $location GeoMashupDB::get_object_location$object_name$object_id );
  38.     if empty$location ) ) {
  39.         $location GeoMashupDB::blank_object_location();
  40.         $help_class '';
  41.         $add_input_style '';
  42.         $update_input_style $delete_input_style 'style="display:none;"';
  43.     else {
  44.         $coordinate_string $location->lat ',' $location->lng;
  45.     }
  46.  
  47.     $post_location_name $location->saved_name;
  48.     $kml_url '';
  49.  
  50.     // Set a Geo date default when needed & possible
  51.     $date_missing empty$location->geo_date || '0000-00-00 00:00:00' == $location->geo_date );
  52.     if 'post' == $object_name{
  53.         if $date_missing {
  54.  
  55.             // Geo date defaults to post date
  56.             $post get_post$object_id );
  57.             $location->geo_date $post->post_date;
  58.             if !empty$location->id ) ) {
  59.                 GeoMashupDB::set_object_location$object_name$object_id$location->idfalse$location->geo_date );
  60.             }
  61.  
  62.         }
  63.  
  64.         // For posts, look for a KML attachment
  65.         $kml_urls GeoMashup::get_kml_attachment_urls$object_id );
  66.         if (count($kml_urls)>0{
  67.             $kml_url array_pop($kml_urls);
  68.         }
  69.  
  70.     else if 'user' == $object_name && $date_missing {
  71.  
  72.         // Geo date defaults to registration date
  73.         $user get_userdata$object_id );
  74.         $location->geo_date $user->user_registered;
  75.         if !empty$location->id ) ) {
  76.             GeoMashupDB::set_object_location$object_name$object_id$location->idfalse$location->geo_date );
  77.         }
  78.  
  79.     else if 'comment' == $object_name && $date_missing {
  80.  
  81.         // Geo date defaults to comment date
  82.         $comment get_comment$object_id );
  83.         $location->geo_date $comment->comment_date;
  84.         if !empty$location->id ) ) {
  85.             GeoMashupDB::set_object_location$object_name$object_id$location->idfalse$location->geo_date );
  86.         }
  87.  
  88.     }    
  89.     if empty$location->geo_date ) ) {
  90.         $location_datetime mktime();
  91.     else {
  92.         $location_datetime strtotime$location->geo_date );
  93.     }
  94.     $location_date date'M j, Y'$location_datetime );
  95.     $location_hour date'G'$location_datetime );
  96.     $location_minute date'i'$location_datetime );
  97.  
  98.     // Load saved locations
  99.     $saved_locations GeoMashupDB::get_saved_locations);
  100.     $saved_location_options array();
  101.     if empty$saved_locations ) ) {
  102.         foreach $saved_locations as $saved_location {
  103.             $escaped_name str_replacearray"\r\n""\r""\n" )''$saved_location->saved_name );
  104.             if $saved_location->id != $location->id 
  105.                 $selected '';
  106.             else
  107.                 $selected ' selected="selected"';
  108.             $saved_location_options['<option value="' esc_attr$saved_location->id '|' $saved_location->lat '|' .
  109.                 $saved_location->lng '|' $saved_location->address '"' $selected '>' esc_html$escaped_name '</option>';
  110.         }
  111.     }
  112.     $saved_location_options implode''$saved_location_options );
  113.  
  114.     $nonce wp_create_nonce('geo-mashup-edit');
  115.  
  116.     $static_maps_base_url 'http://maps.google.com/maps/api/staticmap?sensor=false&amp;key=' .
  117.         $geo_mashup_options->get'overall''google_key' );
  118. ?>
  119.     <div id="geo_mashup_location_editor">
  120.     <div id="geo_mashup_ajax_message" class="geo-mashup-js ui-state-highlight"></div>
  121.     <input id="geo_mashup_nonce" name="geo_mashup_nonce" type="hidden" value="<?php echo $nonce?>" />
  122.     <input id="geo_mashup_changed" name="geo_mashup_changed" type="hidden" value="" />
  123.     <?php ob_start()?>
  124.     <table id="geo-mashup-location-table">
  125.         <thead class="ui-widget-header">
  126.         <tr>
  127.             <th><?php _e'Address''GeoMashup' )?></th>
  128.             <th><?php _e'Saved Name''GeoMashup' )?></th>
  129.             <th><?php _e'Geo Date''GeoMashup' )?></th>
  130.         </tr>
  131.         </thead>
  132.         <tbody class="ui-widget-content">
  133.         <tr id="geo_mashup_display" class="geo-mashup-display-row">
  134.             <td class="geo-mashup-info">
  135.                 <div class="geo-mashup-address"><?php echo esc_html$location->address )?></div>
  136.                 <div class="geo-mashup-coordinates"><?php echo esc_attr$coordinate_string )?></div>
  137.             </td>
  138.             <td id="geo_mashup_saved_name_ui">
  139.                 <input id="geo_mashup_location_name" name="geo_mashup_location_name" size="50" type="text" value="<?php echo esc_attr$post_location_name )?>" />
  140.             </td>
  141.             <td id="geo_mashup_date_ui">
  142.                 <input id="geo_mashup_date" name="geo_mashup_date" type="text" size="20" value="<?php echo esc_attr$location_date )?>" /><br />
  143.                 @
  144.                 <input id="geo_mashup_hour" name="geo_mashup_hour" type="text" size="2" maxlength="2" value="<?php echo esc_attr$location_hour )?>" />
  145.                 :
  146.                 <input id="geo_mashup_minute" name="geo_mashup_minute" type="text" size="2" maxlength="2" value="<?php echo esc_attr$location_minute )?>" />
  147.             </td>
  148.             <td id="geo_mashup_ajax_buttons">
  149.             </td>
  150.  
  151.         </tr>
  152.         </tbody>
  153.     </table>
  154.     <?php $location_table_html ob_get_clean()?>
  155.     <?php ob_start()?>
  156.     <div id="geo_mashup_map" class="geo-mashup-js">
  157.         <?php _e('Loading Google map. Check Geo Mashup options if the map fails to load.''GeoMashup')?>
  158.     </div>
  159.     <?php if empty$location->id ) ) ?>
  160.     <noscript>
  161.         <div id="geo_mashup_static_map">
  162.             <img src="<?php echo $static_maps_base_url?>&amp;size=400x300&amp;zoom=4&amp;markers=size:small|color:green|<?php echo esc_attr$location->lat ',' $location->lng )?>
  163.                 alt="<?php _e'Location Map Image''GeoMashup' )?>" />
  164.         </div>
  165.     </noscript>
  166.     <?php endif?>
  167.     <?php $map_html ob_get_clean()?>
  168.     <?php ob_start()?>
  169.     <label for="geo_mashup_search"><?php _e('Find a new location:''GeoMashup')?>
  170.     <input    id="geo_mashup_search" name="geo_mashup_search" type="text" size="35" />
  171.     </label>
  172.  
  173.     <?php _e'or select from''GeoMashup' )?> 
  174.     <select id="geo_mashup_select" name="geo_mashup_select"> 
  175.         <option value=""><?php _e('[Saved Locations]','GeoMashup')?></option>
  176.         <?php echo $saved_location_options?>
  177.     </select>
  178.     <?php $search_html ob_get_clean()?>
  179.  
  180.     <?php echo empty$location->id $search_html $map_html $location_table_html $location_table_html $map_html $search_html?>
  181.  
  182.     <input id="geo_mashup_ui_manager" name="geo_mashup_ui_manager" type="hidden" value="<?php echo $ui_manager?>" />
  183.     <input id="geo_mashup_object_id" name="geo_mashup_object_id" type="hidden" value="<?php echo $object_id?>" />
  184.     <input id="geo_mashup_no_js" name="geo_mashup_no_js" type="hidden" value="true" />
  185.     <input id="geo_mashup_location_id" name="geo_mashup_location_id" type="hidden" value="<?php echo esc_attr$location->id )?>" />
  186.     <input id="geo_mashup_location" name="geo_mashup_location" type="hidden" value="<?php echo esc_attr$coordinate_string )?>" />
  187.     <input id="geo_mashup_geoname" name="geo_mashup_geoname" type="hidden" value="<?php echo esc_attr$location->geoname )?>" />
  188.     <input id="geo_mashup_address" name="geo_mashup_address" type="hidden" value="<?php echo esc_attr$location->address )?>" />
  189.     <input id="geo_mashup_postal_code" name="geo_mashup_postal_code" type="hidden" value="<?php echo esc_attr$location->postal_code )?>" />
  190.     <input id="geo_mashup_country_code" name="geo_mashup_country_code" type="hidden" value="<?php echo esc_attr$location->country_code )?>" />
  191.     <input id="geo_mashup_admin_code" name="geo_mashup_admin_code" type="hidden" value="<?php echo esc_attr$location->admin_code )?>" />
  192.     <input id="geo_mashup_admin_name" name="geo_mashup_admin_name" type="hidden" value="" />
  193.     <input id="geo_mashup_kml_url" name="geo_mashup_kml_url" type="hidden" value="<?php echo $kml_url?>" />
  194.     <input id="geo_mashup_sub_admin_code" name="geo_mashup_sub_admin_code" type="hidden" value="<?php echo esc_attr$location->sub_admin_code )?>" />
  195.     <input id="geo_mashup_sub_admin_name" name="geo_mashup_sub_admin_name" type="hidden" value="" />
  196.     <input id="geo_mashup_locality_name" name="geo_mashup_locality_name" type="hidden" value="<?php echo esc_attr$location->locality_name )?>" />
  197.     <div id="geo_mashup_submit" class="submit">
  198.         <input id="geo_mashup_add_location" name="geo_mashup_add_location" type="submit" <?php echo $add_input_style?> value="<?php _e'Add Location''GeoMashup' )?>" />
  199.         <input id="geo_mashup_delete_location" name="geo_mashup_delete_location" type="submit" <?php echo $delete_input_style?> value="<?php _e'Delete''GeoMashup' )?>" />
  200.         <input id="geo_mashup_update_location" name="geo_mashup_update_location" type="submit" <?php echo $update_input_style?> value="<?php _e'Save''GeoMashup' )?>" />
  201.     </div>
  202.     <div id="geo-mashup-inline-help-link-wrap" class="geo-mashup-js">
  203.         <a href="#geo-mashup-inline-help" id="geo-mashup-inline-help-link"><?php _e('help''GeoMashup')?><span class="ui-icon ui-icon-triangle-1-s"></span></a>
  204.     </div>
  205.     <div id="geo-mashup-inline-help" class="<?php echo $help_class?> ui-widget-content">
  206.         <p><?php _e'<em>Saved Name</em> is an optional name you may use to add entries to the Saved Locations menu.''GeoMashup' )?></p>
  207.         <p><?php _e'<em>Geo Date</em> associates a date (most formats work) and time with a location. Leave the default value if uncertain.''GeoMashup' )?></p>
  208.         <div class="geo-mashup-js">
  209.             <p><?php _e('Put a green pin at a new location. There are many ways to do it:''GeoMashup')?></p>
  210.             <ul>
  211.                 <li><?php _e('Search for a location name.''GeoMashup')?></li>
  212.                 <li><?php _e('For multiple search results, mouse over pins to see location names, and click a result pin to select that location.''GeoMashup')?></li>
  213.                 <li><?php _e('Search for a decimal latitude and longitude separated by a comma, like <em>40.123,-105.456</em>. Seven decimal places are stored. Negative latitude is used for the southern hemisphere, and negative longitude for the western hemisphere.''GeoMashup')?></li> 
  214.                 <li><?php _e('Search for a street address, like <em>123 main st, anytown, acity</em>.''GeoMashup')?></li>
  215.                 <li><?php _e('Click on the location. Zoom in if necessary so you can refine the location by dragging it or clicking a new location.''GeoMashup')?></li>
  216.             </ul>
  217.             <p><?php _e('To execute a search, type search text into the Find Location box and hit the enter key. If you type a name next to "Save As", the location will be saved under that name and added to the Saved Locations dropdown list.''GeoMashup')?></p>
  218.             <p><?php _e('To remove the location (green pin), clear the search box and hit the enter key.''GeoMashup')?></p>
  219.             <p><?php _e('When you are satisfied with the location, save or update.''GeoMashup')?></p>
  220.         </div>
  221.         <noscript>
  222.             <div>
  223.                 <p><?php _e'To add or update location choose a saved location, or find a new location using one of these formats:''GeoMashup' )?></p>
  224.                 <ul>
  225.                     <li><?php _e('A place name like <em>Yellowstone National Park</em>''GeoMashup')?></li>
  226.                     <li><?php _e('A decimal latitude and longitude, like <em>40.123,-105.456</em>.''GeoMashup')?></li> 
  227.                     <li><?php _e('A full or partial street address, like <em>123 main st, anytown, acity 12345 USA</em>.''GeoMashup')?></li>
  228.                 </ul>
  229.                 <p><?php _e'When you save or update, the closest match available will be saved as the location.''GeoMashup' )?></p>
  230.             </div>
  231.         </noscript>
  232.  
  233.     </div>
  234.     </div><!-- id="geo_mashup_location_editor" -->
  235. <?php
  236. }
  237. ?>

Documentation generated on Sat, 09 Jul 2011 21:54:31 -0700 by phpDocumentor 1.4.3