Files
twentyten-child/loop-single.php
2019-08-17 16:54:13 +02:00

562 lines
20 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
$coord = array();
$compt_marker = 0;
$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][0] = $gm_lat;
$coord[$j][1] = $gm_lng;
$coord[$j][2] = $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][0] = $gm_lat;
$coord[$j][1] = $gm_lng;
$coord[$j][2] = str_replace("'", "\'", $title_marker);
$j++;
}
/*
locations[0] => $coord[2] => Titre (court) *
locations[1] => $coord[4] => Description (long)
locations[2] => $coord[0] => Latitude *
locations[3] => $coord[1] => Longitude *
locations[4] => $coord[5] => <img "letrine">
locations[5] => $coord[8] => Texte Wikipedia
locations[6] => $coord[9] => Liens vers Wikipedia
$coord[3] => attachment
$coord[6] => requete wiki ->
$coord[7] => <- requete wiki
*/
//$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;
//var_dump($coord);
?>
<?php //echo '<div id="map" style="display: ' . ((count($coord) > 0) ? "block" : "none") . ';"></div>';
//var_dump($coord);
if (count($coord) > 0) {
$b = array();
// Avec tous les titres, on crée la requete pour Wikipédia
for ($a = 0; $a < count($coord); $a++){
$short = $coord[$a][6]; // Titre
/*
Flickr: 2016-01-07_Renard_2905
WP:
ZP:
*/
$b[] = $short;
}
var_dump($b);
//echo "coord avant requete Wikipedia";
//var_dump($coord);
$wiki = fmulticurl($b);
//var_dump($wiki);
//On rajoute à $coord les données récupérées sur Wikipédia
if (count($coord) == count($wiki)) {
for ($c = 0; $c < count($wiki); $c++){
// [0] 1ere réponse, la plus pertinante
//array_push($coord[$c], $lettrine, $wiki[$c][1][0], $wiki[$c][2][0], $wiki[$c][3][0]);
// Requete - Texte Wikipedia - Url Wikipedia
array_push($coord[$c], $wiki[$c][1][0], $wiki[$c][2][0], $wiki[$c][3][0]);
//array_push($coord[$c], $wiki[$c][2][0], $wiki[$c][3][0]);
}
}
//echo "coord après requete Wikipedia";
//var_dump($coord);
?>
<script type="text/javascript">
jQuery(document).ready(function ($) { // wait until the document is ready
data = false;
$('button#showmap').click(function(){
if (data == false) {
/**/
$.ajax({
url: "http://maps.googleapis.com/maps/api/js?key=AIzaSyB7cAx3NSH4dPM3Sx2oQeud7Zr-KaGXmLk&sensor=false&callback=MapApiLoaded",
dataType: "script",
timeout:8000,
success: function(data) {
//alert('Success occured');
// Run the code here that needs
// to access the data returned
data = true;
return data;
},
error: function() {
alert('Error occured');
}
});
}
$( "#locations" ).toggle( "fast");
$( "button#hidemap" ).show();
$( "button#showmap" ).hide();
$( "i.ion-ios-location" ).show();
}); // button#showmap
$('button#hidemap').click(function(){
$( "#locations" ).toggle( "fast");
$( "button#hidemap" ).hide();
$( "button#showmap" ).show();
$( "i.ion-ios-location" ).hide();
data = true;
});
}); // jQuery
var map;
var markers = [];
var cnt;
var locations = [
<?php
$j = (count($coord) - 1);
for ($i = 0; $i <= $j; $i++) {
echo "['<h1>" . addslashes($coord[$i][2]) . "</h1>','<p>" . addslashes($coord[$i][4]) . "</p>', " . $coord[$i][0] . ", " . $coord[$i][1] . ",'" . addslashes($coord[$i][5]) . "','" . addslashes($coord[$i][8]) . "','" . $coord[$i][9] . "']" . (($i<$j) ? "," : "")."\r\n";
//echo "['<h1>" . addslashes($coord[$i][2]) . "</h1>','<p>" . addslashes($coord[$i][4]) . "</p>', " . $coord[$i][0] . ", " . $coord[$i][1] . ",'" . addslashes($coord[$i][5]) . "','" . (($coord[$i][8] != "") ? addslashes($coord[$i][8]) : addslashes($coord[$i][4])) . "','" . $coord[$i][9] . "']" . (($i<$j) ? "," : "")."\r\n";
}
(($coord[$i][8] != "") ? addslashes($coord[$i][8]) : addslashes($coord[$i][4]))
//array_push($coord, array($meta['latitude'], $meta['longitude'], $caption, $pid, $description, $img_thumb_ZP_wiki, $requete_wiki));
// locations[0] => $coord[2] => Titre (court)
// locations[1] => $coord[4] => Description (long)
// locations[2] => $coord[0] => Latitude
// locations[3] => $coord[1] => Longitude
// locations[4] => $coord[5] => <img "letrine">
// locations[5] => $coord[8] => Texte Wikipedia
// locations[6] => $coord[9] => Liens vers Wikipedia
// $coord[3] => attachment
// $coord[6] => requete wiki ->
// $coord[7] => <- requete wiki
?>
];
var wikiLink = '';
var contenuInfoBulle = [];
function MapApiLoaded() {
// Setup the different icons and shadows
var iconURLPrefix = 'https://maps.google.com/mapfiles/ms/icons/';
var root = location.protocol + '//' + location.host;
var wikiImg = root + '/wordpress/wp-content/themes/CreatorThemeRes-child/images/wikipedia.png';
var wikiUrl = '<img src=\"' + wikiImg + '\" width=\"32\" height=\"32\" class=\"wiki\" />';
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;
// Create google map
map = new google.maps.Map($('#gmap')[0], {
zoom:8,
mapTypeId:google.maps.MapTypeId.ROADMAP,
panControl:false,
streetViewControl:false,
mapTypeControl:true
});
infowindow = new google.maps.InfoWindow();
var bounds = new google.maps.LatLngBounds();
var iconCounter = 0;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][2], locations[i][3]),
map: map,
icon: icons[iconCounter],
title: locations[i][0]
});
markers.push(marker);
if (locations[i][6] != '') {
wikiLink = '<a href=\"' + locations[i][6] + '\" title=\"Plus sur Wikipedia...\">' + wikiUrl + '</a>';
}
contenuInfoBulle[i] = locations[i][0] + locations[i][4] + locations[i][1] + locations[i][5] + '<br />' + wikiLink;
/*
locations[0] => $coord[2] => Titre (court)
locations[4] => $coord[5] => <img "letrine">
locations[1] => $coord[4] => Description (long)
locations[5] => $coord[8] => Texte Wikipedia
locations[6] => $coord[9] => Liens vers Wikipedia
*/
var zoom = 1;
a = map.getZoom();
bounds.extend(marker.position);
// add the double-click event listener
google.maps.event.addListener(marker, 'dblclick', function() {
map.panTo(this.getPosition());
//map.setZoom(9);
if (zoom == 1) {
if (map.getZoom() < (a + 6)) {
map.setZoom(map.getZoom() + 2);
}
else zoom = 0;
}
else if (zoom == 0) {
if (map.getZoom() >= a) {
map.setZoom(map.getZoom() - 2);
}
else zoom = 1;
}
});
/*https://www.touraineverte.fr/google-maps-api-version-3/exemple-tutoriel-infobulles-infowindows/ajouter-infowindow-infobulle-marqueur-defaut-api-google-maps-version-3.html*/
/*
var contenuInfoBulle = '<h1>Cité Royale de Loches</h1>' +
'<h2>Royale et imprenable</h2>' +
'<img id="lettrineImage" src="https://static.touraineverte.fr/googlemapsapiversion3/photo_monument-loches.jpg" title="La cité royale de Loches" />' +
'<p>Remontez le temps pour découvrir l\'une des plus belles cités fortifiées de France.</p>' +
'<p>Le <b>DONJON</b>, haut de 36 mètres, a été construit par un comte d\'Anjou, Foulques Nerra, au début du XIe siècle. S\'il figure parmi les plus imposants de son époque en Europe, il est aussi l\'un des mieux conservés. Modèle d\'architecture militaire, il est transformé en prison royale par Louis XI.</p>' +
'<p>Le <b>LOGIS ROYAL</b> se trouve à proximité. Ce joyau de la Renaissance française, haut lieu de l\'Histoire de France, a été une résidence de prédilection de la dynastie des Valois. Sa façade ouverte en terrasse domine la ville et la vallée de l\'Indre. Le logis a accueilli notamment Jeanne d\'Arc, Agnès Sorel et Anne de Bretagne. Pour en savoir plus : <a href="http://www.cg37.fr/index.php?media=106" title="La cité royale de Loches" target="_parent">La cité royale de Loches</a></p>';
*/
/*
<h1>Titre</h1> =>
<h2>Sous-titre</h2>
Lettrine image
<p>Description</p>
*/
google.maps.event.addListener(marker, 'mousemove', (function (marker, i) {
return function () {
/*
var wikiLink = ''
if (locations[i][6] != '') {
wikiLink = '<a href=\"' + locations[i][6] + '\" title=\"Plus sur Wikipedia...\">' + wikiUrl + '</a>';
}
var contenuInfoBulle = locations[i][0] + locations[i][4] + locations[i][1] + locations[i][5] + '<br />' + wikiLink;
*/
infowindow.setContent(contenuInfoBulle[i]);
infowindow.open(map, marker);
}
})(marker, i));
iconCounter++;
if (iconCounter >= iconsLength) {
iconCounter = 0;
}
} // for
map.fitBounds(bounds);
} //MapApiLoaded
function jumpToMarker(cnt){
map.panTo(markers[cnt].getPosition());
if (map.getZoom() < 15) {
map.setZoom(a + 4);
}
setTimeout(function() {
infowindow.setContent(contenuInfoBulle[cnt]);
infowindow.open(map, markers[cnt]);
}, 300);
} //jumpToMarker
</script>
<div id="locations">
<?php
$j = (count($coord) - 1);
echo "<div id='center_marker'><ul class='list_marker'>";
for ($i = 0; $i <= $j; $i++) {
//<a href="javascript:void(0);" onclick="jumpToMarker(4)" class="button3">PontDArc</a>
echo "<li><i class='ion-ios-location'></i><a href='#gmap' onclick='jumpToMarker(" . $i . ")'>" . $coord[$i][2] . "</a></li>";
}
echo "</ul></div>";
?>
<div id="gmap" style="width: 800px; height: 600px; border:1px solid #999;" class="aligncenter"></div>
</div>
<button type="button" id="showmap"><?php _e('Show map','CreatorThemeRes-child'); ?></button>
<button type="button" id="hidemap"><?php _e('Hide map','CreatorThemeRes-child'); ?></button>
<?php
}
?>
<?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. ?>