Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if ( !function_exists('cgmp_autoimage_shortcode_handler') ):
- function cgmp_autoimage_shortcode_handler($attr, $content = null, $code = null) {
- if (is_admin() || is_feed()) {
- return;
- }
- global $post;
- $args = array(
- 'post_type' => 'attachment',
- 'post_parent' => $post->ID
- );
- $attachments = get_posts( $args );
- $list_coord_gps="";
- if ( $attachments ) {
- foreach ( $attachments as $attachment ) {
- $image_attributes = wp_get_attachment_image_src($attachment->ID,'full');
- $image_thumbnail = wp_get_attachment_image_src($attachment->ID,'thumbnail');
- // from http://stackoverflow.com/questions/2526304/php-extract-gps-exif-data
- $exif = exif_read_data($image_attributes[0], 0, false);
- if ( $exif ) {
- $gps['LatDegree']=$exif["GPSLatitude"][0];
- $gps['LatMinute']=$exif["GPSLatitude"][1];
- $gps['LatSeconds']=$exif["GPSLatitude"][2];
- $gps['LongDegree']=$exif["GPSLongitude"][0];
- $gps['LongMinute']=$exif["GPSLongitude"][1];
- $gps['LongSeconds']=$exif["GPSLongitude"][2];
- //get the Hemisphere multiplier
- $LatM = 1;
- $LongM = 1;
- if($exif["GPSLatitudeRef"] == 'S')
- {
- $LatM = -1;
- }
- if($exif["GPSLongitudeRef"] == 'W')
- {
- $LongM = -1;
- }
- //convert strings to numbers
- foreach($gps as $key => $value)
- {
- $pos = strpos($value, '/');
- if($pos !== false)
- {
- $temp = explode('/',$value);
- $gps[$key] = $temp[0] / $temp[1];
- }
- }
- //calculate the decimal degree
- $result['latitude'] = $LatM * ($gps['LatDegree'] + ($gps['LatMinute'] / 60) + ($gps['LatSeconds'] / 3600));
- $result['longitude'] = $LongM * ($gps['LongDegree'] + ($gps['LongMinute'] / 60) + ($gps['LongSeconds'] / 3600));
- if( $result['latitude'] && $result['longitude'] ) {
- // Store image data
- if (!isset($nbimages)){
- $nbimages=1;
- }else{
- $nbimages++;
- }
- $tab_coord_gps[$nbimages]['date']=$exif["DateTime"];
- $tab_coord_gps[$nbimages]['latlong']=$result['latitude'].",".$result['longitude'];
- $tab_coord_gps[$nbimages]['marker']="1-default.png";
- $tab_coord_gps[$nbimages]['thumb'].="#@$image_thumbnail[0]#@";
- }
- }
- }
- // Sort photos by date
- foreach($tab_coord_gps as $c=>$key) {
- $sort_date[] = $key['date'];
- }
- array_multisort($sort_date, SORT_ASC, $tab_coord_gps);
- // Prepare string for addmarkerlist
- $nbimages=1;
- foreach($tab_coord_gps as $img)
- {
- if (!empty($list_coord_gps)){
- $list_coord_gps.="|";
- $nbimages++;
- }
- $list_coord_gps.=$img['latlong'];
- $list_coord_gps.="{}".$img['marker'];
- $list_coord_gps.="{}Image n°".$nbimages."#-";
- $list_coord_gps.=$img['thumb'];
- $date=date_create_from_format('Y:m:d H:i:s', $img['date']);
- $list_coord_gps.="#-".date_format($date,'d/m/Y H:i:s');
- $list_coord_gps.="#-#*".$img['latlong']."#*";
- }
- $shortcode_attribs = shortcode_atts(array(
- 'latitude' => 0,
- 'longitude' => 0,
- 'zoom' => '12',
- 'width' => 600,
- 'height' => 500,
- 'maptype' => 'terrain',
- 'maptypecontrol' => 'true',
- 'pancontrol' => 'false',
- 'addresscontent' => '',
- 'zoomcontrol' => 'true',
- 'scalecontrol' => 'true',
- 'streetviewcontrol' => 'true',
- 'scrollwheelcontrol' => 'false',
- 'showbike' => 'false',
- 'bubbleautopan' => 'true',
- 'showtraffic' => 'false',
- 'showpanoramio' => 'false',
- 'addmarkerlist' => $list_coord_gps,
- 'kml' => '',
- 'directionhint' => 'false',
- 'mapalign' => 'center',
- 'panoramiouid' => '',
- 'addmarkermashup' => 'false',
- 'language' => 'default',
- 'poweredby' => 'true',
- 'draggable' => 'true',
- 'tiltfourtyfive' => 'false',
- 'addmarkermashupbubble' => 'false'), $attr);
- return "<br style=\"clear: both;\" /><br><br>".cgmp_shortcode_googlemap_handler($shortcode_attribs);
- }else{
- return;
- }
- }
- endif;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement