Files
twentyten-child/loop-single.php
2016-10-20 18:12:00 +02:00

379 lines
13 KiB
PHP

<?php
/**
* The loop that displays a single post.
*
* 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-single.php.
*
* @package WordPress
* @subpackage Twenty_Ten
* @since Twenty Ten 1.2
*/
?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div id="nav-above" class="navigation">
<div class="nav-previous"><?php previous_post_link( '%link', '<span class="meta-nav">' . _x( '&larr;', 'Previous post link', 'twentyten' ) . '</span> %title' ); ?></div>
<div class="nav-next"><?php next_post_link( '%link', '%title <span class="meta-nav">' . _x( '&rarr;', 'Next post link', 'twentyten' ) . '</span>' ); ?></div>
</div><!-- #nav-above -->
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="entry-title"><?php the_title(); ?></h1>
<div class="entry-meta">
<?php //twentyten_posted_on(); ?>
<?php RelativeTime(); ?>
</div><!-- .entry-meta -->
<div class="entry-content">
<?php //the_content(); ?>
<?php
$content = apply_filters('the_content', get_the_content());
$content = str_replace(']]>', ']]&gt;', $content);
// retina 2x
if (function_exists( ' wr2x_init' ) ) $pattern = '/<img[^>]* src=\"([^\"]*)\"[^>]*>/Ui';
// sans retina
else $pattern = '/<img[^>]*src=\"?([^\"]*)\"?([^>]*alt=\"?([^\"]*)\"?)?[^>]*>/Ui';
preg_match_all($pattern, $content , $matches, PREG_SET_ORDER);
//$x = count($matches);
//echo "matches wp: " . $x;
//$pattern2 = '/<img[^>]* srcset=\"([^\"]*)\"[^>]*>/Ui';
$pattern2 = '/<a\s[^>]*href=\"([^\"]*)\"[^>]*>(.*)<\/a>/siU';
//$pattern2 = '/<img[^>]* src=\"([^\"]*)\"[^>]*>/Ui';
preg_match_all($pattern2, $content , $matches, PREG_SET_ORDER);
//preprint($matches);
/*
echo "matches2 zp: " . (count($matches) - $x);
for ($i = 0; $i <= (count($matches) - 1); $i++) {
//echo "<b>" . $i . $matches[$i][0] . "</b><br />";
echo "<b>" . $i . $matches[$i][1] . "</b><br />-----------------------------------------------<br />";
}
echo "--------------------------------------------";*/
$coord = array();
$j = 0;
$portrait = false;
$new_img = "";
for ($i = 0; $i <= (count($matches) - 1); $i++) {
$ancien = $matches[$i][0];
//echo $ancien;
if (substr_count($ancien, 'wordpress') != 0) {
$patternWP = '#wp-image-[0-9]{1,4}#';
if (preg_match($patternWP, $ancien, $matches2) === 1) {
$attachment = substr($matches2[0],9);
//$new_img = $ancien . '</a>' . "\r\n" . '<div class="droite" onclick="toggleExif(' . $i . ');">Voir les Exifs</div>'."\r\n";
//echo "ancien wp: " . $ancien;
//echo $ancien;
//$ancien2 = str_replace("rel=\"", "rel=\"lightbox ", $ancien);
$ancien2 = str_replace("<a href=", "<a class=\"swipebox\" href=", $ancien);
//echo $ancien2;
$new_img = $ancien2 . "\r\n";
$new_img .= '<div class="droite" onclick="toggleExif(' . $i . ');">Voir les Exifs</div>'."\r\n";
$new_img .= '<div class="bloc_exif" id="' . $i .'">'."\r\n";
$new_img .= '<ul class="exif" id="bloc_exif' . $i . '">'."\r\n";
$metadata = wp_get_attachment_metadata($attachment);
list($exif_list, $gm_lat, $gm_lng, $title_marker) = ListeExif($metadata, $attachment, $i);
if ($gm_lat != "") {
$coord[$j]['lat'] = $gm_lat;
$coord[$j]['lng'] = $gm_lng;
$coord[$j]['mark'] = $title_marker;
$j++;
}
$new_img .= $exif_list;
$new_img .= '</ul></div>'."\r\n";
}
}
// elseif (substr_count($ancien, 'zenphoto') != 0) {
elseif ((substr_count($ancien, 'zenphoto') != 0) and (substr_count($ancien, '<img') != 0)){
//echo "ancien zp: " . $ancien;
//$patternZP = '/<img[^>]* srcset=\"([^\"]*)\"[^>]*>/Ui';
$patternZP = '/<a\s[^>]*href=\"([^\"]*)\"[^>]*>(.*)<\/a>/siU';
preg_match($patternZP, $ancien , $matches2);
$img = explode("/", $matches2[1]);
$zp_image = end($img);
$zp_album = prev($img);
//echo $zp_image;
$meta = zp_query($zp_image);
//preprint($meta);
list($exif_list, $gm_lat, $gm_lng, $title_marker) = ListeExifZP($meta);
if ($gm_lat != "") {
$coord[$j]['lat'] = $gm_lat;
$coord[$j]['lng'] = $gm_lng;
$coord[$j]['mark'] = str_replace("'", "\'", $title_marker);
$j++;
}
//$new_img = $ancien . '</a>' . "\r\n";
$new_img = $ancien . "\r\n";
// $caption .= '<p class="wp-caption-text aligncenter" style="width:' . $zp_size[0] . 'px">';
$new_img .= ($title_marker != "") ? ('<p class="wp-caption-text aligncenter">' . $title_marker . '</p>') : "" . "\r\n";
//$new_img .= '<p class="wp-caption-text">' . $title_marker . '</p>' . "\r\n";
$new_img .= '<div class="droite" onclick="toggleExif(' . $i . ');">Voir les Exifs</div>'."\r\n";
$new_img .= '<div class="bloc_exif" id="' . $i .'">'."\r\n";
$new_img .= '<ul class="exif" id="bloc_exif' . $i . '">'."\r\n";
$new_img .= $exif_list;
$new_img .= '</ul></div>'."\r\n";
}
else {
// Autres sources que WP et ZP
//<a href="https://flic.kr/p/DPRf6e"><img src="https://farm2.staticflickr.com/1544/24826683615_3967bc60d2_c.jpg" /></a>
//echo $ancien;
if (substr_count($ancien, " portrait") != 0) {
$ancien2 = str_replace(" portrait", " ", $ancien);
$portrait = true;
}
else {
$portrait = false;
}
//$anc = str_replace("/></a>", "class='aligncenter' style='width: " . (($portrait === false) ? "610" : "408") . "px;' /></a>", $ancien);
//$new_img = $anc . "\r\n";
}
$content = str_replace($ancien, $new_img, $content);
//echo $content;
}
echo $content;
//preprint($coord);
?>
<a name="carte"></a><p>&nbsp;</p>
<!--div id="map_canvas1" ></div>
<div id="map_canvas2" ></div>
<div id="map_canvas3" ></div>
<div id="map_canvas4" ></div>
<div id="map_canvas5" ></div>
<div id="map_canvas6" ></div-->
<?php
echo '<div id="map" style="display: ' . ((count($coord) > 0) ? "block" : "none") . ';"></div>';
?>
<script>
// Define your locations: HTML content for the info window, latitude, longitude
var locations = [
<?php
$j = (count($coord) - 1);
for ($i = 0; $i <= $j; $i++) {
//echo "['" . $coord[$i]['mark'] . "', " . $coord[$i]['lat'] . ", " . $coord[$i]['lng'] . ", " . (intval($i) + 1) . "]" . (($i<$j) ? "," : "")."\r\n";
echo "['<h4>" . $coord[$i]['mark'] . "</h4>', " . $coord[$i]['lat'] . ", " . $coord[$i]['lng'] . "]" . (($i<$j) ? "," : "")."\r\n";
}
?>
];
// Setup the different icons and shadows
var iconURLPrefix = 'http://maps.google.com/mapfiles/ms/icons/';
var icons = [
iconURLPrefix + 'red-dot.png',
iconURLPrefix + 'green-dot.png',
iconURLPrefix + 'blue-dot.png',
iconURLPrefix + 'orange-dot.png',
iconURLPrefix + 'purple-dot.png',
iconURLPrefix + 'pink-dot.png',
iconURLPrefix + 'yellow-dot.png'
]
var iconsLength = icons.length;
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(-37.92, 151.25),
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
streetViewControl: false,
panControl: false,
zoomControlOptions: {
position: google.maps.ControlPosition.LEFT_BOTTOM
}
});
var infowindow = new google.maps.InfoWindow({
maxWidth: 200
});
var markers = new Array();
var iconCounter = 0;
// Add the markers and infowindows to the map
for (var i = 0; i < locations.length; i++) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
icon: icons[iconCounter]
});
markers.push(marker);
infoBubble = new InfoBubble({
map: map,
content: '',
/*content: '<div class="mylabel">The label</div>',
position: new google.maps.LatLng(-32.0, 149.0),*/
shadowStyle: 0,
padding: 5,
backgroundColor: 'rgb(230,230,230)',
borderRadius: 5,
arrowSize: 10,
borderWidth: 1,
borderColor: '#2c2c2c',
disableAutoPan: true,
hideCloseButton: true,
arrowPosition: 30,
backgroundClassName: 'transparent',
disableAnimation: true,
arrowStyle: 2
});
/*var contentString = '<div style="width: 94.2%; padding-left:10px; height: 25px;float: left;color: #FFF;background: #ed1e79;line-height: 25px;border-radius:5px 5px 0px 0px;">'
contentString += '<strong><b>"You feild"</b></strong></div>'*/
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
/*infowindow.setContent(locations[i][0]);
infowindow.setContent(contentString);
infowindow.open(map, marker);*/
infoBubble.setContent(locations[i][0]);
infoBubble.open(map, marker);
}
})(marker, i));
iconCounter++;
// We only have a limited number of possible icon colors, so we may have to restart the counter
if(iconCounter >= iconsLength) {
iconCounter = 0;
}
}
function autoCenter() {
// Create a new viewpoint bound
var bounds = new google.maps.LatLngBounds();
// Go through each...
for (var i = 0; i < markers.length; i++) {
bounds.extend(markers[i].position);
}
// Fit these bounds to the map
map.fitBounds(bounds);
}
autoCenter();
</script>
<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<?php if ( get_the_author_meta( 'description' ) ) : // If a user has filled out their description, show a bio on their entries ?>
<div id="entry-author-info">
<div id="author-avatar">
<?php echo get_avatar( get_the_author_meta( 'user_email' ), apply_filters( 'twentyten_author_bio_avatar_size', 60 ) ); ?>
</div><!-- #author-avatar -->
<div id="author-description">
<h2><?php printf( __( 'About %s', 'twentyten-child' ), get_the_author() ); ?></h2>
<?php the_author_meta( 'description' ); ?>
<div id="author-link">
<a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>" rel="author">
<?php printf( __( 'View all posts by %s <span class="meta-nav">&rarr;</span>', 'twentyten-child' ), get_the_author() ); ?>
</a>
</div><!-- #author-link -->
</div><!-- #author-description -->
</div><!-- #entry-author-info -->
<?php endif; ?>
<!-- rajout -->
<div id="related">
<?php //for use in the loop, list 5 post titles related to first tag on current post
$backup = $post; // backup the current object
$tags = wp_get_post_tags($post->ID);
$tagIDs = array();
if ($tags) {
$tagcount = count($tags);
for ($i = 0; $i < $tagcount; $i++) {
$tagIDs[$i] = $tags[$i]->term_id;
}
$args=array(
'tag__in' => $tagIDs,
'post__not_in' => array($post->ID),
'showposts'=>-1,
'ignore_sticky_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
_e('Related articles:', 'twentyten-child' );
?>
<br/>
<ul class="related">
<?php
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a> (<?php the_date("F Y"); ?>)</li>
<?php endwhile;
?></ul><?php
}
else { ?>
<!--h3>No related posts found!</h3-->
<?php }
}
$post = $backup; // copy it back
wp_reset_query(); // to use the original query again
?>
<?php twentyten_post_updated(); ?>
</div><!-- #related -->
<!-- /rajout -->
<div class="entry-utility">
<?php twentyten_posted_in(); ?>
<?php edit_post_link( __( 'Edit', 'twentyten-child' ), '<span class="edit-link">', '</span>' ); ?>
</div><!-- .entry-utility -->
</div><!-- #post-## -->
<div id="nav-below" class="navigation">
<div class="nav-previous"><?php previous_post_link( '%link', '<span class="meta-nav">' . _x( '&larr;', 'Previous post link', 'twentyten' ) . '</span> %title' ); ?></div>
<div class="nav-next"><?php next_post_link( '%link', '%title <span class="meta-nav">' . _x( '&rarr;', 'Next post link', 'twentyten' ) . '</span>' ); ?></div>
</div><!-- #nav-below -->
<?php comments_template( '', true ); ?>
<?php endwhile; // end of the loop. ?>