Files
twentyten-child/exclus/_loop-attachment.php
2016-10-20 18:12:00 +02:00

254 lines
10 KiB
PHP

<?php
/**
* The loop that displays an attachment.
*
* The loop displays the posts and the post content. See
* http://codex.wordpress.org/The_Loop to understand it and
* http://codex.wordpress.org/Template_Tags to understand
* the tags used in it.
*
* This can be overridden in child themes with loop-attachment.php.
*
* @package WordPress
* @subpackage Twenty_Ten
* @since Twenty Ten 1.2
*/
?>
<?php
// return geo exif in a nice form
/*
function geo_frac2dec($str) {
@list( $n, $d ) = explode( '/', $str );
if ( !empty($d) )
return $n / $d;
return $str;
}
function geo_pretty_fracs2dec($fracs) {
return geo_frac2dec($fracs[0]) . '&deg; ' .
geo_frac2dec($fracs[1]) . '&prime; ' .
geo_frac2dec($fracs[2]) . '&Prime; ';
}
function geo_single_fracs2dec($fracs) {
return geo_frac2dec($fracs[0]) +
geo_frac2dec($fracs[1]) / 60 +
geo_frac2dec($fracs[2]) / 3600;
}
*/
?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<?php if ( ! empty( $post->post_parent ) ) : ?>
<div id="nav-above" class="navigation">
<div class="nav-previous"><a href="<?php echo get_permalink( $post->post_parent ); ?>" title="<?php esc_attr( printf( __( 'Return to %s', 'twentyten' ), get_the_title( $post->post_parent ) ) ); ?>" rel="gallery"><?php
/* translators: %s - title of parent post */
printf( __( '<span class="meta-nav">&larr;</span> %s', 'twentyten' ), get_the_title( $post->post_parent ) );
?></a></div>
</div><!-- #nav-above -->
<?php endif; ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-meta">
<?php
printf( __( '%1$s', 'twentyten-child' ),
sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><span class="entry-date">%3$s</span></a>',
get_permalink(),
esc_attr( get_the_time() ),
get_the_date()
)
);
if ( wp_attachment_is_image() ) {
echo ' <span class="meta-sep">|</span> ';
$metadata = wp_get_attachment_metadata();
printf( __( 'Full size is %s pixels', 'twentyten' ),
sprintf( '<a href="%1$s" title="%2$s">%3$s &times; %4$s</a>',
wp_get_attachment_url(),
esc_attr( __( 'Link to full-size image', 'twentyten' ) ),
$metadata['width'],
$metadata['height']
)
);
}
?>
<?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="meta-sep">|</span> <span class="edit-link">', '</span>' ); ?>
</div><!-- .entry-meta -->
<div class="entry-content">
<div class="entry-attachment">
<?php if ( wp_attachment_is_image() ) :
$attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) );
foreach ( $attachments as $k => $attachment ) {
if ( $attachment->ID == $post->ID )
break;
}
$k++;
// If there is more than 1 image attachment in a gallery
if ( count( $attachments ) > 1 ) {
if ( isset( $attachments[ $k ] ) )
// get the URL of the next image attachment
$next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
else
// or get the URL of the first image attachment
$next_attachment_url = get_attachment_link( $attachments[ 0 ]->ID );
} else {
// or, if there's only 1 image attachment, get the URL of the image
$next_attachment_url = wp_get_attachment_url();
}
?>
<p class="attachment"><a href="<?php echo $next_attachment_url; ?>" title="<?php echo esc_attr( get_the_title() ); ?>" rel="attachment"><?php
$attachment_width = apply_filters( 'twentyten_attachment_size', 900 );
$attachment_height = apply_filters( 'twentyten_attachment_height', 900 );
echo wp_get_attachment_image( $post->ID, array( $attachment_width, $attachment_height ) ); // filterable image width with, essentially, no limit for image height.
?></a></p>
<?php else : ?>
<a href="<?php echo wp_get_attachment_url(); ?>" title="<?php echo esc_attr( get_the_title() ); ?>" rel="attachment"><?php echo basename( get_permalink() ); ?></a>
<?php endif; ?>
<!-- .entry-attachment -->
<div class="entry-caption"><?php if ( !empty( $post->post_excerpt ) ) the_excerpt(); ?>
</div><!-- .entry-caption -->
<div class="droite" onclick="toggleExif(<?php echo $attachment->ID; ?>);">Voir les Exif</div>
<?php //print_r($metadata); ?>
<?php
/*
if ($metadata['image_meta']['latitude'])
$latitude = $metadata['image_meta']['latitude'];
if ($metadata['image_meta']['longitude'])
$longitude = $metadata['image_meta']['longitude'];
if ($metadata['image_meta']['latitude_ref'])
$lat_ref = $metadata['image_meta']['latitude_ref'];
if ($metadata['image_meta']['longitude_ref'])
$lng_ref = $metadata['image_meta']['longitude_ref'];
$lat = geo_single_fracs2dec($latitude);
$lng = geo_single_fracs2dec($longitude);
if ($lat_ref == 'S') { $neg_lat = '-'; } else { $neg_lat = ''; }
if ($lng_ref == 'W') { $neg_lng = '-'; } else { $neg_lng = ''; }
//$start_geo_link = '<a href="http://maps.google.com/maps?q=' . $neg_lat . number_format($lat,6) . '+' . $neg_lng . number_format($lng, 6) . '&amp;z=11">';
$start_geo_link = '<a href="http://maps.google.com/maps?q=' . $neg_lat . number_format($lat,6) . '+' . $neg_lng . number_format($lng, 6) . '&amp;z=11">';
$jquery_geo_link = 'http://maps.google.com/maps?q=' . $neg_lat . number_format($lat,6) . '+' . $neg_lng . number_format($lng, 6) . '&amp;z=11';
$end_geo_link = '</a>';
// Aperture
if (!empty($metadata['image_meta']['aperture']))
$exif_list .= $before_item . __('Aperture', 'twentyten-child') . $sep . "f/" . $metadata['image_meta']['aperture'] . $after_item;
// Shutter speed
if (!empty($metadata['image_meta']['shutter_speed'])) {
$exif_list .= $before_item . __('Shutter speed', 'twentyten-child') . $sep;
if ((1 / $metadata['image_meta']['shutter_speed']) > 1) {
$exif_list .= "1/";
if ((number_format((1 / $metadata['image_meta']['shutter_speed']), 1)) == 1.3
or number_format((1 / $metadata['image_meta']['shutter_speed']), 1) == 1.5
or number_format((1 / $metadata['image_meta']['shutter_speed']), 1) == 1.6
or number_format((1 / $metadata['image_meta']['shutter_speed']), 1) == 2.5) {
$exif_list .= number_format((1 / $metadata['image_meta']['shutter_speed']), 1, '.', '') . " s" . $after_item;
}
else {
$exif_list .= number_format((1 / $metadata['image_meta']['shutter_speed']), 0, '.', '') . " s" . $after_item;
}
}
else
$exif_list .= $metadata['image_meta']['shutter_speed']." s" . $after_item;
}
}
// Focal length
if (!empty($metadata['image_meta']['focal_length']))
$exif_list .= $before_item . __('Focal length', 'twentyten-child') . $sep . $metadata['image_meta']['focal_length'] . " mm" . $after_item;
// Camera
if (!empty($metadata['image_meta']['camera']))
$exif_list .= $before_item . __('Camera', 'twentyten-child') . $sep . $metadata['image_meta']['camera'] . $after_item;
// Creation time
if (!empty($metadata['image_meta']['created_timestamp']))
$exif_list .= $before_item . __('Taken', 'twentyten-child') . $sep . date('j F, Y',$metadata['image_meta']['created_timestamp']) . $after_item;
// Latitude and Longtitude
if ($latitude != 0 && $longitude != 0)
//affichage dans un cadre map caché
//$exif_list .= $before_item . '<div onclick="toggleExif(\'map\');" ><image src="' . get_stylesheet_directory_uri() . '/images/monde.png" width="16" height="16" /></div>' . $after_item;
$exif_list .= $before_item . '<image onclick="toggleExif(\'map\');" src="' . get_stylesheet_directory_uri() . '/images/monde.png" width="16" height="16" />' . $after_item;
// jquery
//$exif_list .= $before_item . '<a id="map_link" href="#"><image src="' . get_stylesheet_directory_uri() . '/images/monde.png" width="16" height="16" /></a>' . $after_item;
//affichage map dans nouvelle fenetre
//$exif_list .= $before_item . $start_geo_link . '<image src="' . get_stylesheet_directory_uri() . '/images/monde.png" width="16" height="16" />' . $end_geo_link . $after_item;
*/
$before_block = '<div class="bloc_exif" id="' . $attachment->ID . '"><ul>';
$after_block = '</ul></div><!-- .bloc_exif -->';
$liste_exif = $before_block;
$attach = $attachment->ID;
// ListeExif renvoie 3 paramètres dans un tableau:
// -les exifs sous forme de liste
// -latitude et longitude pour le javascript
// -le caption ou le nom du fichier pour l'infoWindow
list($exif_list, $gm_lat, $gm_lng, $title_marker) = ListeExif($metadata, $attach);
$liste_exif .= $exif_list;
$liste_exif .= $after_block;
echo $liste_exif;
?>
<div id="map<?php echo $attach; ?>" class="" style="display: block;"></div>
<script type="text/javascript">
var contentString = "<?php echo $title_marker; ?>";
var curr_infw;
var latlng = new google.maps.LatLng(<?php echo $gm_lat; ?>, <?php echo $gm_lng; ?>);
var myOptions = {
/* http://code.google.com/intl/fr/apis/maps/documentation/javascript/reference.html#MapOptions */
zoom: 11,
center: latlng,
scrollwheel: true,
scaleControl: false,
disableDefaultUI: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map<?php echo $attach; ?>"), myOptions);
</script>
</div><!-- .entry-attachment -->
<!--p>Description</p-->
<?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'twentyten' ) ); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php previous_image_link( false ); ?></div>
<div class="nav-next"><?php next_image_link( false ); ?></div>
</div><!-- #nav-below -->
</div><!-- .entry-content -->
<div class="entry-utility">
<?php twentyten_posted_in(); ?>
<?php edit_post_link( __( 'Edit', 'twentyten' ), ' <span class="edit-link">', '</span>' ); ?>
</div><!-- .entry-utility -->
</div><!-- #post-## -->
<?php comments_template(); ?>
<?php endwhile; // end of the loop. ?>