-galerie
-fmulticurl()
-infobox avec vignette, texte et lien wikipedia
+
-bouton shotcode flickr
-bugfixes
This commit is contained in:
2017-02-23 21:01:44 +01:00
parent eae1e44c01
commit edcfd078cf
6 changed files with 948 additions and 114 deletions

View File

@@ -108,14 +108,14 @@ function custom_class( $classes ) {
}
return $classes;
}
/**/
// Bouton Shortcode Zenphoto dans l'éditeur
// Bouton Shortcode zenphoto dans l'éditeur
function register_button( $buttons ) {
function register_button_zp( $buttons ) {
array_push( $buttons, "|", "zenphoto" );
return $buttons;
}
function add_plugin( $plugin_array ) {
function add_plugin_zp( $plugin_array ) {
$plugin_array['zenphoto'] = get_stylesheet_directory_uri() . '/js/short-zenphoto.js';
return $plugin_array;
}
@@ -126,13 +126,36 @@ function my_zenphoto_button() {
}
if ( get_user_option('rich_editing') == 'true' ) {
add_filter( 'mce_external_plugins', 'add_plugin' );
add_filter( 'mce_buttons', 'register_button' );
add_filter( 'mce_external_plugins', 'add_plugin_zp' );
add_filter( 'mce_buttons', 'register_button_zp' );
}
}
add_action('init', 'my_zenphoto_button');
// Bouton Shortcode Flickr dans l'éditeur
function register_button_flk( $buttons ) {
array_push( $buttons, "|", "flickr" );
return $buttons;
}
function add_plugin_flk( $plugin_array ) {
$plugin_array['flickr'] = get_stylesheet_directory_uri() . '/js/short-flickr.js';
return $plugin_array;
}
function my_flickr_button() {
if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) {
return;
}
if ( get_user_option('rich_editing') == 'true' ) {
add_filter( 'mce_external_plugins', 'add_plugin_flk' );
add_filter( 'mce_buttons', 'register_button_flk' );
}
}
add_action('init', 'my_flickr_button');
function RelativeTime() {
@@ -383,11 +406,56 @@ function date_archive ($chaine) {
return $chaine;
}
/* Images externes (pas de Retina) */
function picture_handler($atts, $content=null) {
global $coord;
$display_exif = dess_setting('dess_display_exif');
$display_gps = dess_setting('dess_display_gps');
extract(shortcode_atts(array(
"image" => $atts[0],
"url"=>"", //setting default value
"caption"=>"" //setting default value
), $atts));
/*
[picture image="http://www.photo-nature-21.fr/Benelux/2008-10-18_Bouquetin_9965.jpg" url="http://www.photo-nature-21.fr/Benelux/2008-10-18_Bouquetin_9965.jpg" caption="Bouquetin"]
*/
/*
Pas d'exifs pour les images distantes.
$pict_size = getimagesize(htmlentities($image));
$meta = creator_get_exif( $image ); // l 1323
preprint($meta);
$exif_array = img_wp_exif( $meta ); // l 1240
preprint($exif_array);*/
$links = (($caption != "") ? '<div id="pictures_' . $rnd . '" style="width: ' . ($pict_size[0] + 10) . 'px" class="wp-caption aligncenter">' : '');
$links .= (($url != "") ? '<a href="' . $url . '" class="' . (($lb == true) ? $selector : '') . '"title="' . $title . '">' : '');
$links .= '<img class="';
$links .= (($caption == "") ? 'aligncenter size-medium"' : '"');
$links .= 'src="' . $image . '" alt="' . $title . '" />';
$links .= (($url != "") ? '</a>' : '');
$links .= (($caption != "") ? '<p class="wp-caption-text">' . $caption . '</p></div>' : '');
//$links .= (($display_exif == true) ? "<div class='image-exif'>" . $exif_array[0] . (($display_gps == true) ? $exif_array[2] : '') . "</div>" : '');
return $links;
}
add_shortcode( 'picture', 'picture_handler' );
function flickr_handler($atts, $content=null) {
global $coord;
$api_key = "3884af4190ac97a95fd4777dba0d9f21";
$display_exif = dess_setting('dess_display_exif');
$display_gps = dess_setting('dess_display_gps');
extract(shortcode_atts(array(
"pid" => $atts[0],
@@ -400,9 +468,6 @@ function flickr_handler($atts, $content=null) {
$pid=$e[5];
}
//echo $pid . " - ". $version . " - ". $caption . " - ". $url . "<br>";
// 27868468454 - Medium - - https://www.flickr.com/photos/funnymac/27868468454/
/*
[flickr url="https://www.flickr.com/photos/funnymac/27868468454/"]
@@ -450,7 +515,6 @@ function flickr_handler($atts, $content=null) {
break;
}
//echo $img_sd . " - ". $img_hd . "<br>";
/*
$link = ! empty( $atts['link'] ) ? $atts['link'] : '';
$link = filter_var($link, FILTER_SANITIZE_URL);
@@ -474,14 +538,13 @@ function flickr_handler($atts, $content=null) {
$info = array();
*/
/* lb ???? */
// 1220 -610
$lb = toBool($lb);
$rnd = rand (1000, 9999);
$selector = dess_setting('dess_lightbox_select');
$url1 = 'https://api.flickr.com/services/rest/?method=flickr.photos.getSizes';
$url1 .= '&api_key='.$api_key;
$url1 .= '&photo_id='.$pid;
@@ -490,7 +553,6 @@ function flickr_handler($atts, $content=null) {
$result = file_get_contents($url1);
$response = json_decode($result, true);
//preprint($response);
$taille = $response['sizes']['size'];
@@ -517,7 +579,6 @@ function flickr_handler($atts, $content=null) {
$result2 = file_get_contents($url2);
$response2 = json_decode($result2, true);
//var_dump($response2);
$title = $response2['photo']['title']['_content'];
$date = $response2['photo']['dates']['taken'];
@@ -534,16 +595,6 @@ function flickr_handler($atts, $content=null) {
$tags[] = utf8_encode(ucfirst($i));
}
$img = array(
'medium' => $mediumSRC,
'large' => $largeSRC
//'titre' => $title,
//'date' => $date,
//'latitude' => $lat,
//'longitude' => $long,
//'tags' => $tags
);
/* EXIF */
$url3 = 'https://api.flickr.com/services/rest/?method=flickr.photos.getExif';
@@ -560,7 +611,6 @@ function flickr_handler($atts, $content=null) {
$meta = array();
foreach ($exif as $val) {
//preprint($val);
if ($val['tag'] == 'FNumber') $meta['aperture'] = $val['raw']['_content'];
//if ($val['tag'] == 'xxx') $meta['credit'] = $val['raw']['_content'];
@@ -586,40 +636,20 @@ function flickr_handler($atts, $content=null) {
}
//preprint($exifs);
/*
$meta = zp_query_exif( $zp_image );
$exif_array = img_wp_exif( $meta );
$exifs = "<div class='image-exif rouge'>" . $exif_array[0] . (($display_gps == true) ? $exif_array[2] : '') . "</div>";
*/
//$meta = zp_query_exif( $zp_image ); //745 $meta['keywords'] =>
$exif_array = img_wp_exif( $meta ); //1214
//echo "exif_array";
//preprint($exif_array);
$links = (($caption != "") ? '<div id="flickr_' . $rnd . '" style="width: ' . ($w_mediumSRC + 10) . 'px" class="wp-caption aligncenter">' : '');
$links .= '<a href="' . $largeSRC . '" class="' . (($lb == true) ? $selector : '') . '"title="' . $title . '">';
$links .= '<img class="';
$links .= (($caption == "") ? 'aligncenter size-medium"' : '"');
//$links .= 'srcset="' . $zenphoto_url . 'cache/' . $album . '/' . $img . ' _' . $size . '_watermark.jpg, ' . $zenphoto_url . 'albums/' . $album . '/'. $image . ' 2x" alt="' . $img . '" />';
//$links .= 'srcset="' . $small . ', " ' . $flickr_size[3] . ' 2x" alt="' . $img . '" />';
$links .= 'srcset="' . $mediumSRC . ', ' . $largeSRC . ' 2x' . '" alt="' . $title . '" />';
$links .= '</a>';
$links .= (($caption != "") ? '<p class="wp-caption-text">' . $caption . '</p></div>' : '');
$links .= "<div class='image-exif'>" . $exif_array[0] . (($display_gps == true) ? $exif_array[2] : '') . "</div>";
$links .= (($display_exif == true) ? "<div class='image-exif'>" . $exif_array[0] . (($display_gps == true) ? $exif_array[2] : '') . "</div>" : '');
/*
$exif_array = img_wp_exif( $meta );
$exifs = "<div class='image-exif'>" . $exif_array[0] . (($display_gps == true) ? $exif_array[2] : '') . "</div>";
$content = str_replace($matches[$i][0], $matches[$i][0] . $exifs, $content);
$matches2 = array();
*/
if (($meta['longitude'] != "") && ($meta['latitude'] != "")) {
if ($meta['caption'] != "") $fichier = $meta['caption'];
else if ($meta['title'] != "") $fichier = $meta['title'];
@@ -627,7 +657,6 @@ function flickr_handler($atts, $content=null) {
array_push($coord, array($meta['latitude'], $meta['longitude'], $fichier));
}
return $links;
}
add_filter( 'the_content', 'do_shortcode');
@@ -657,14 +686,11 @@ function zenphoto_handler($atts, $content=null) {
$caption = ! empty( $atts['caption'] ) ? $atts['caption'] : '';
$caption = filter_var($caption, FILTER_SANITIZE_STRING);
//echo "album: " . $album . " image: " . $image . "<br>";
$rnd = rand (1000, 9999);
//$size = 610;
$folder = false;
//echo "folder1: " . $folder . "<br>";
$zenphoto_img = "";
// Si ALBUM mais pas IMAGE
@@ -673,7 +699,6 @@ function zenphoto_handler($atts, $content=null) {
//if (($album != "") && ($image == "")) {
require('../Connections/cnx.php');
$mysqli = new mysqli($dbhost, $dbuser, $dbpassword, $dbtable);
if (mysqli_connect_errno()) {
printf("Échec de la connexion : %s\n", mysqli_connect_error());
@@ -738,16 +763,6 @@ function zenphoto_handler($atts, $content=null) {
else $zenphoto_link = '<a href="' . $zenphoto_url . $album . '">';
$zenphoto_img .= $zenphoto_link;
/*
$zenphoto_img .= '<picture data-picture data-alt="">
<!--[if IE 9]><video style="display: none;"><![endif]-->
<source class="image_standard" srcset="' . $zenphoto_url . 'cache/' . $album . '/' . $img . '_' . $size . '_watermark.jpg, ' . $zenphoto_url . 'cache/' . $album . '/' . $img . '_FULL' . '_watermark.jpg 2x">
<source class="image_medium" srcset="" media="(max-width: 767px)">
<source class="image_small" srcset="" media="(max-width: 767px)">
<!--[if IE 9]></video><![endif]-->
<img class="aligncenter" srcset="' . $zenphoto_url . 'cache/' . $album . '/' . $img . '_' . $size . '_watermark.jpg" ' . $zp_size[3] . 'alt="' . $img . '" />
</picture>';
*/
$zenphoto_img .= '<img class="';
$zenphoto_img .= (($caption == "") ? 'aligncenter size-medium"' : '"');
$zenphoto_img .= 'srcset="' . $zenphoto_url . 'cache/' . $album . '/' . $img . ' _' . $size . '_watermark.jpg, ' . $zenphoto_url . 'albums/' . $album . '/'. $image . ' 2x" alt="' . $img . '" />';
@@ -1075,10 +1090,11 @@ xdebug_start_trace('/Users/bruno/Sites', XDEBUG_TRACE_COMPUTERIZED);
// `1049`
//$pattern = '/<div id=[^>]*>(.*?)\<\/div>/';
$pattern = '/<div id=\"(zp|attachment)_?([^\"]*)\"?[^>]*>(.*?)\<\/div>/';
//$pattern = '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is';
$pattern = '/<div id=\"(zp|attachment)_?([^\"]*)\"?[^>]*>(.*?)\<\/div>/'; //ok
//$pattern = '/<div id=\"attachment_?([^\"]*)\"?[^>]*>(.*?)\<\/div>/';
preg_match_all($pattern, $content, $matches, PREG_SET_ORDER);
//var_dump($matches);
//preprint($matches);
/*
echo "matches[0][0]"; //<div id="attachment_1049">...</div>
echo "matches[0][1]"; // 1114
@@ -1192,37 +1208,31 @@ xdebug_start_trace('/Users/bruno/Sites', XDEBUG_TRACE_COMPUTERIZED);
} // else zenphoto
// Autres sources que WP et ZP
elseif (substr_count($ancien, 'jpg') > 0) {
elseif ((substr_count($ancien, 'jpg') > 0) and (substr_count($ancien, 'flickr') == 0)) {
//echo "court2: " . $court . "<br>";
$meta = creator_get_exif( $court );
//$flk_size = getimagesize(htmlentities($filename3));
//echo "long2: " . $ancien . "<br>";
//$meta = creator_get_exif( $court );
// si $court est déjà dans $matches3 (si l'image est déjà dans un DIV)
/*
Flicker (portrait):
<a href="https://flic.kr/p/Cn2dTd"><img src="https://farm2.staticflickr.com/1704/23866728514_76a72305a9_c.jpg" portrait /></a>
if (in_multiarray($court, $matches3) == false) {
$meta = creator_get_exif( $court );
//preprint($meta);
Flicker (paysage) vautour avec branche:
<a href="https://flic.kr/p/DPRf6e"><img src="https://farm2.staticflickr.com/1544/24826683615_3967bc60d2_c.jpg" /></a>
1600x1066 https://www.flickr.com/photos/funnymac/24826683615/sizes/o/
https://c2.staticflickr.com/2/1544/24826683615_c42292df06_o.jpg
BBCODE [url=https://flic.kr/p/DPRf6e][img]https://c1.staticflickr.com/2/1544/24826683615_558bff1744_h.jpg[/img][/url]
800x533 https://www.flickr.com/photos/funnymac/24826683615/sizes/c/
https://c2.staticflickr.com/2/1544/24826683615_3967bc60d2_c.jpg
$atts['link'] = $link;
$atts['small'] = $small;
$atts['big'] = $big;
$exif_array = img_wp_exif( $meta );
$exifs = "<div class='image-exif'>" . $exif_array[0] . (($display_gps == true) ? $exif_array[2] : '') . "</div>";
//$content = str_replace($matches4[$i][0], $matches4[$i][0] . $exifs, $content);
$string = substr_replace($matches4[$i][0], $matches4[$i][0] . $exifs, -6, 0);
//echo $string;
}
*/
//$anc = str_replace("/></a>", "class='aligncenter' style='width: " . (($portrait === false) ? "610" : "408") . "px;' /></a>", $ancien) . "\r\n";
//$anc = str_replace("/></a>", "class='aligncenter' /></a>", $ancien) . "\r\n";
} // else
$exif = "";
} // for
@@ -1234,7 +1244,6 @@ add_action('the_content','addexif');
function img_wp_exif( $exif_array ) {
//preprint($exif_array);
/*
Array
(
@@ -1324,7 +1333,7 @@ function creator_get_exif( $file ) {
return false;
}
*/
//echo "file: " . $file . "<br>";
echo "file: " . $file . "<br>";
list( , , $sourceImageType ) = getimagesize( $file );
@@ -1364,6 +1373,7 @@ function creator_get_exif( $file ) {
if ( ! empty( $info['APP13'] ) ) {
$iptc = iptcparse( $info['APP13'] );
preprint($iptc);
// Headline, "A brief synopsis of the caption."
if ( ! empty( $iptc['2#105'][0] ) ) {
@@ -1396,8 +1406,10 @@ function creator_get_exif( $file ) {
elseif ( ! empty( $iptc['2#080'][0] ) ) // creator / legacy byline
$meta['credit'] = trim( $iptc['2#080'][0] );
if ( ! empty( $iptc['2#055'][0] ) && ! empty( $iptc['2#060'][0] ) ) // created date and time
// created date and time
if ( ! empty( $iptc['2#055'][0] ) && ! empty( $iptc['2#060'][0] ) ) {
$meta['created_timestamp'] = strtotime( $iptc['2#055'][0] . ' ' . $iptc['2#060'][0] );
}
if ( ! empty( $iptc['2#116'][0] ) ) // copyright
$meta['copyright'] = trim( $iptc['2#116'][0] );
@@ -1412,7 +1424,7 @@ function creator_get_exif( $file ) {
if ( is_callable( 'exif_read_data' )) {
$exif = @exif_read_data( $file );
//preprint($exif);
preprint($exif);
if ( ! empty( $exif['ImageDescription'] ) ) {
mbstring_binary_safe_encoding();
@@ -1453,8 +1465,10 @@ function creator_get_exif( $file ) {
$meta['camera'] = trim( $exif['Model'] );
}
if ( empty( $meta['created_timestamp'] ) && ! empty( $exif['DateTimeDigitized'] ) ) {
//if ( ! empty( $exif['DateTimeDigitized'] ) ) {
$meta['created_timestamp'] = ctc_exif_date2ts( $exif['DateTimeDigitized'] );
//$meta['created_timestamp'] = wp_exif_date2ts( $exif['DateTimeDigitized'] );
$meta['created_timestamp'] = $exif['DateTimeDigitized'];
//$meta['created_timestamp'] = $exif['DateTimeDigitized'];
}
if ( ! empty( $exif['FocalLength'] ) ) {
$meta['focal_length'] = (string) geo_frac2dec( $exif['FocalLength'] ) . " mm";
@@ -1560,6 +1574,150 @@ function gps($coordinate, $hemisphere) {
}
function mapgallery( $attr ) {
/*
$atts = shortcode_atts( array(
'order' => 'ASC',
'ids' => '',
'orderby' => 'menu_order ID',
'id' => $post ? $post->ID : 0,
'itemtag' => $html5 ? 'figure' : 'dl',
'icontag' => $html5 ? 'div' : 'dt',
'captiontag' => $html5 ? 'figcaption' : 'dd',
'columns' => 3,
'size' => 'thumbnail',
'include' => '',
'exclude' => '',
'link' => ''
), $attr, 'mapgallery' );
*/
//$columns = $attr['columns'];
$size_class = $attr['size'];
//$itemtag = $attr['itemtag'];
//$icontag = $attr['icontag'];
//$captiontag = $attr['captiontag'];
$link = $attr['link'];
$itemtag = tag_escape( $attr['itemtag'] );
$captiontag = tag_escape( $attr['captiontag'] );
$icontag = tag_escape( $attr['icontag'] );
$valid_tags = wp_kses_allowed_html( 'post' );
if ( ! isset( $valid_tags[ $itemtag ] ) ) {
$itemtag = 'dl';
}
if ( ! isset( $valid_tags[ $captiontag ] ) ) {
$captiontag = 'dd';
}
if ( ! isset( $valid_tags[ $icontag ] ) ) {
$icontag = 'dt';
}
$instance = 1;
$columns = intval( $attr['columns'] );
$itemwidth = $columns > 0 ? floor(100/$columns) : 100;
$float = is_rtl() ? 'right' : 'left';
$selector = "gallery-{$instance}";
$selecteur = dess_setting('dess_lightbox_select');
//if ( apply_filters( 'use_default_gallery_style', ! $html5 ) ) {
$gallery_style = "
<style type='text/css'>
#{$selector} {
margin: auto;
}
#{$selector} .gallery-item {
float: {$float};
margin-top: 10px;
text-align: center;
width: {$itemwidth}%;
}
#{$selector} img {
border: 2px solid #cfcfcf;
}
#{$selector} .gallery-caption {
margin-left: 0;
}
/* see gallery_shortcode() in wp-includes/media.php */
</style>\n\t\t";
//}
echo $gallery_style;
//$ids = implode(',',$attr['ids']); // '70,69,68,67'
$gallery_div = "<div id='$selector' class='gallery galleryid-map gallery-columns-{$columns} gallery-size-{$size_class}'>";
//"<div id='gallery-1' class='gallery galleryid-27 gallery-columns-3 gallery-size-thumbnail'><dl class='gallery-item'>";
//$gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>";
$output .= $gallery_div;
$gallery_div .= "<{$itemtag} class='gallery-item'>";
$i = 0;
foreach ( $attr['ids'] as $id ) {//
$attribut = wp_prepare_attachment_for_js( $id );
/*
'description' => string 'Description' (length=11)
'caption' => string 'Cascades de la Pleureuse et de la Sauffaz' (length=41)
*/
$image_meta = wp_get_attachment_metadata( $id );
$orientation = '';
if ( isset( $image_meta['height'], $image_meta['width'] ) ) {
$orientation = ( $image_meta['height'] > $image_meta['width'] ) ? 'portrait' : 'landscape';
}
$output .= "<{$itemtag} class='gallery-item'>";
if ( ! empty( $attr['link'] ) && 'file' === $attr['link'] ) {
// lien vers l'image
$image_output = "<a href='" . wp_get_attachment_url( $id ) . "' class='{$selecteur}'> " . wp_get_attachment_image($id, $attr['size'], false, $attr ) . "</a>";
} elseif ( ! empty( $attr['link'] ) && 'none' === $attr['link'] ) {
// pas de lien - juste la vignette
$image_output = wp_get_attachment_image( $id, $attr['size'], false, $attr );
} else {
// lien vers la page attachment
$image_output = wp_get_attachment_link( $id, $attr['size'], true, false, false, $attr );
}
$output .= "<{$icontag} class='gallery-icon {$orientation}'>$image_output</{$icontag}>";
/*
if ( $captiontag && trim($attribut['caption']) ) {
$output .= "
<{$captiontag} class='wp-caption-text gallery-caption' id='$selector-$id'>
" . wptexturize($attribut['caption']) . "
</{$captiontag}>";
}
*/
$cible = "<a href='javascript:void(0);' class='cible' onclick='jumpToMarker(" . $i . ")'><i class='ion-ios-location'></i></a>";
if ( $captiontag && trim($attribut['caption']) ) {
$output .= "
<{$captiontag} class='wp-caption-text gallery-caption' id='$selector-$id'>
" . wptexturize($attribut['caption']) . "
$cible</{$captiontag}>";
}
$output .= "</{$itemtag}>";
if ( ! $html5 && $columns > 0 && ++$i % $columns == 0 ) {
$output .= '<br style="clear: both" />';
}
}
if ( ! $html5 && $columns > 0 && $i % $columns !== 0 ) {
$output .= '<br style="clear: both" />';
}
$output .= "
</div>\n";
return $output;
}
remove_shortcode('gallery', 'gallery_shortcode');
add_shortcode('gallery', 'creator_gallery_shortcode');
@@ -1740,7 +1898,7 @@ function creator_gallery_shortcode( $attr ) {
*/
$output = apply_filters( 'gallery_style', $gallery_style . $gallery_div );
$selector = dess_setting('dess_lightbox_select');
$selecteur = dess_setting('dess_lightbox_select');
$i = 0;
foreach ( $attachments as $id => $attachment ) {
@@ -1749,7 +1907,7 @@ function creator_gallery_shortcode( $attr ) {
if ( ! empty( $atts['link'] ) && 'file' === $atts['link'] ) {
//$image_output = wp_get_attachment_link( $id, $atts['size'], false, false, false, $attr );
//$image_output = "<a href='" . wp_get_attachment_url( $id ) . "'> " . wp_get_attachment_image($id, $atts['size'], false, $attr ) . "</a>";
$image_output = "<a href='" . wp_get_attachment_url( $id ) . "' class='{$selector}'> " . wp_get_attachment_image($id, $atts['size'], false, $attr ) . "</a>";
$image_output = "<a href='" . wp_get_attachment_url( $id ) . "' class='{$selecteur}'> " . wp_get_attachment_image($id, $atts['size'], false, $attr ) . "</a>";
} elseif ( ! empty( $atts['link'] ) && 'none' === $atts['link'] ) {
$image_output = wp_get_attachment_image( $id, $atts['size'], false, $attr );
} else {
@@ -2211,6 +2369,103 @@ function pa_the_post_thumbnail_exif_data($content) {
}
}
function fmulticurl($query) {
$url = "https://fr.wikipedia.org/w/api.php";
$erreur = array();
$fields = array(
'action' => 'opensearch',
//'search' => $query,
'format' => 'json',
'profile' => 'strict' //strict, normal, *fuzzy*, classic
);
$fields_string = "";
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
foreach ($query as &$val) {
$val = $url . "?" . $fields_string . "search=" . str_replace(" ", "_", trim($val));
}
//create the multiple cURL handle
$mh = curl_multi_init();
$nbr = count($query);
// set URL and options
for($x = 0; $x < $nbr; $x++){
$ch[$x] = curl_init();
curl_setopt($ch[$x], CURLOPT_URL, $query[$x]);
//curl_setopt($ch[$x], CURLOPT_POST, 1);// set post data to true
//curl_setopt($ch[$x], CURLOPT_POSTFIELDS, $fields); // post data
curl_setopt($ch[$x], CURLOPT_HEADER, 0);
curl_setopt($ch[$x], CURLOPT_USERAGENT, 'ClicBot/1.0 (https://clicclac.info/; contact@clicclac.info)');
curl_setopt($ch[$x], CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch[$x], CURLOPT_SSL_VERIFYPEER, false);
curl_multi_add_handle($mh,$ch[$x]);
}
$running = null;
do {
curl_multi_exec($mh, $running);
} while ($running);
for($x = 0; $x < $nbr; $x++){
$result = curl_multi_getcontent($ch[$x]);
$obj[]= json_decode($result, true);
//get info about the request
// $error = curl_getinfo($ch[$x], CURLINFO_HTTP_CODE);
// if($error != 200){
if (curl_errno($ch[$x])) {
$erreur[] = array("Url" =>curl_getinfo($ch[$x], CURLINFO_EFFECTIVE_URL), "error_info" => curl_getinfo($ch[$x]));
}
//error handling
/*
200 : succès de la requête ;
301 et 302 : redirection, respectivement permanente et temporaire ;
401 : utilisateur non authentifié ;
403 : accès refusé ;
404 : page non trouvée ;
500 et 503 : erreur serveur.
*/
curl_multi_remove_handle($mh, $ch[$x]);
curl_close($ch[$x]);
}
curl_multi_close($mh);
for ($a = 0; $a < count($obj); $a++){
if (is_array($obj[$a])) {
for ($b = 0; $b < count($obj[$a]); $b++){
if (empty($obj[$a][$b])) {
$obj[$a][$b][0] = "";
}
}
} //if
} //for
if (count($erreur) > 0) var_dump($erreur);
return $obj;
}
/*
function wp_exif_frac2dec($str) {
@list( $n, $d ) = explode( '/', $str );
@@ -2218,12 +2473,31 @@ function wp_exif_frac2dec($str) {
return $n / $d;
return $str;
}
function wp_exif_date2ts($str) {
*/
// wp_exif_date2ts
if ( ! function_exists( 'wp_exif_date2ts' ) ) :
function ctc_exif_date2ts($str) {
@list( $date, $time ) = explode( ' ', trim($str) );
@list( $y, $m, $d ) = explode( ':', $date );
return strtotime( "{$y}-{$m}-{$d} {$time}" );
}
*/
endif; //
function safe_array_access($ar){
$numargs = func_num_args();
$arg_list = func_get_args();
$aritterator = $ar;
for($i = 1; $i < $numargs; $i++){
if (isset($aritterator[$arg_list[$i]]) || array_key_exists($arg_list[$i], $aritterator)){
$aritterator = $aritterator[$arg_list[$i]];
}else{
return(false);
}
}
return($aritterator);
}
?>

49
js/short-flickr.js Normal file
View File

@@ -0,0 +1,49 @@
(function() {
tinymce.create('tinymce.plugins.flickr', {
init : function(ed, url) {
ed.addButton('flickr', {
title : 'Add Flickr Shortcode',
image : url+'/flickr.png',
onclick : function() {
/*
[flickr url="https://www.flickr.com/photos/funnymac/27868468454/"]
[flickr pid="27868468454" caption="Volpe di Paradisio"]
[flickr pid="27868468454" version="Small"]
*/
var pid = prompt("Image Id", "");
if (pid == null || pid == ''){
var url = prompt("URL image", "");
}
var version = prompt("Taille", "");
var caption = prompt("Titre", "");
/**/
if (pid != null && pid != ''){
//if (album != null && album != '')
ed.execCommand('mceInsertContent', false, '[flickr pid="'+pid+'" version="'+version+'" caption="'+caption+'"]');
}
else if (url != null && url != ''){
//if (album != null && album != '')
ed.execCommand('mceInsertContent', false, '[flickr url="'+url+'" version="'+version+'" caption="'+caption+'"]');
}
}
});
},
createControl : function(n, cm) {
return null;
},
getInfo : function() {
return {
longname : "Flickr Shortcode",
author : 'Bruno',
authorurl : 'https://clicclac.info',
infourl : 'https://clicclac.info/wordpress/',
version : "1.0"
};
}
});
tinymce.PluginManager.add('flickr', tinymce.plugins.flickr);
})();

View File

@@ -3,7 +3,7 @@
init : function(ed, url) {
ed.addButton('zenphoto', {
title : 'Add Zenphoto Shortcode',
image : url+'/recentpostsbutton.png',
image : url+'/zenphoto.png',
onclick : function() {
var album = prompt("Album", "");
var image = prompt("Image", "");

View File

@@ -21,7 +21,11 @@ get_header();
//preprint($coord);
?>
<?php //echo '<div id="map" style="display: ' . ((count($coord) > 0) ? "block" : "none") . ';"></div>'; ?>
<?php //echo '<div id="map" style="display: ' . ((count($coord) > 0) ? "block" : "none") . ';"></div>';
if (count($coord) > 0) {
//var_dump($coord);
?>
@@ -192,13 +196,15 @@ get_header();
echo "</ul></div>";
?>
<div id="gmap" style="width: 950px; height: 400px; border:1px solid black;" class="aligncenter"></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

View File

@@ -162,12 +162,26 @@ input.search-field {
margin-right: 16px;
font-size: 10px;
}
.cible i.ion-ios-location {
display: none;
color: green;
padding: 3px;
}
.cible i.ion-ios-location:hover {
color: #00b701;
}
div#locations {
display: none;
}
button#hidemap {
display: none;
margin-bottom: 24px;
margin-top: 32px;
}
button#showmap {
margin-bottom: 24px;
margin-top: 32px;
}
div#center_marker {
width: 100%;
@@ -177,6 +191,23 @@ ul.list_marker {
padding-left: 0;
margin: 2px auto;
}
/**/
ul.list_marker a {
text-decoration: none;
color: green;
}
ul.list_marker a:hover {
color: #00b701;
}
ul.list_marker li {
color: green !important;
}
ul.list_marker li:hover {
color: #00b701 !important;
font-weight: bold;
}
.list_marker li {
display: inline;
font-size: 10px;
@@ -185,21 +216,56 @@ ul.list_marker {
list-style-image: none;
text-align: center;
}
.list_marker li:hover {
font-weight: bold;
}
/* googlempa */
.infowindow, .gm-style-iw {
color: #5f5f5f;
font: normal normal 12px "Lucida Grande", Lucida, Verdana, sans-serif;
}
.infowindow, .gm-style-iw a {
color: black;
text-decoration: underline;
}
.infowindow, .gm-style-iw img {
margin-top: 8px;
margin-left: 8px;
}
#lettrineImage{
float: left;
width: 220px;
height: 163px;
margin: 0 1em 1em 0;
}
#map {
width: 600px;
height: 400px;
display: none;
margin: 5em auto;
}
#gmap h1{
font-family: Arial, Helvetica, sans-serif;
font-size: 1.6em;
font-style: italic;
font-weight: bold;
color:#267AA8;
text-align:center;
}
#gmap h2{
margin-bottom:1em;
font-family: Arial, Helvetica, sans-serif;
font-size: 1.3em;
font-style: normal;
font-weight: bold;
color:#FF9900;
text-align:center;
}
#gmap p{
font: 1em "Helvetica Neue", Arial, Helvetica, Geneva, sans-serif;
}
/* Single */
.zenphoto {

439
tpl-carte.php Executable file
View File

@@ -0,0 +1,439 @@
<?php
/**
* Template Name: Carte
*/
//http://www.wpbeginner.com/wp-themes/how-to-get-all-post-attachments-in-wordpress-except-for-featured-image/
//http://wordpress.stackexchange.com/questions/61393/get-images-attached-to-post
//http://wordpress.stackexchange.com/questions/11662/get-all-images-in-media-gallery
get_header();
$query_images_args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_status' => 'inherit',
'posts_per_page' => - 1,
//'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
);
$query_images = new WP_Query($query_images_args);
//var_dump($query_images);
?>
<div class="content">
<div class="container">
<div class="post_content">
<?php
// Récupération de tous les attachments
$images = array();
$coord = array();
$exifs = array();
foreach ( $query_images->posts as $image ) {
$images = wp_get_attachment_url( $image->ID );
//var_dump($images);
$attribut = wp_prepare_attachment_for_js( $image->ID );
//var_dump($attribut);
$photo = wp_get_attachment_metadata( $image->ID );
$exifs = $photo['image_meta'];
if ((safe_array_access($exifs, 'latitude')) && (safe_array_access($exifs, 'longitude'))) {
//if ((isset($exifs['latitude'])) && (isset($exifs['longitude']))) {
$lat = gps($exifs['latitude'], trim($exifs['latitude_ref']));
$long = gps($exifs['longitude'], trim($exifs['longitude_ref']));
/**/
$attach = $attribut['id'];
$caption = "";
$capt = $attribut['caption'];
$title = $attribut['title'];
$alt = $attribut['alt'];
$image = $attribut['url'];
$description = $attribut['description'];
$thumbnail = $attribut['sizes']['thumbnail'];
//$thumbnail = '<img src="' . $thumbnail['url'] . '" alt="' . $attribut['alt'] . '" height="' . $thumbnail['height'] . '" width="' . $thumbnail['width'] . '" />';
$thumbnail = '<img id=\"lettrineImage\" src=\"' . $thumbnail['url'] . '\" alt=\"' . $attribut['alt'] . '\" height=\"' . $thumbnail['height'] . '\" width=\"' . $thumbnail['width'] . '\" />';
//echo $thumbnail;
/*
array (size=4)
'thumbnail' =>
array (size=4)
'height' => int 200
'width' => int 200
'url' => string 'http://macbook-pro.local/wordpress/wp-content/uploads/2017/01/2016-06-24_LaPleureuse-LaSauffaz_0729-200x200.jpg' (length=111)
'orientation' => string 'landscape' (length=9)
*/
// ??????
$gallery[] = $attach;
if ($capt != "") $caption = $capt;
elseif ($title != "") $caption = $title;
// On crée le tableau $coord qui regroupe toutes les données pour le waypoint (lat,long, titre, n° attachment, description, vignette)
array_push($coord, array(number_format($lat, 6), number_format($long, 6), $caption, $attach, $description, $thumbnail));
} //if
} //foreach
// On crée la galerie
$html5 = current_theme_supports( 'html5', 'gallery' );
$html5 = false;
$galerie = array(
'ids' => $gallery,
'itemtag' => $html5 ? 'figure' : 'dl',
'icontag' => $html5 ? 'div' : 'dt',
'captiontag' => $html5 ? 'figcaption' : 'dd',
'columns' => 3,
'size' => 'thumbnail',
'link' => 'file' // file - none - ''
//'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
);
$gal = mapgallery($galerie);
echo $gal;
?>
<?php
// Affichage de la Carte
if (count($coord) > 0) {
//var_dump($coord);
/*
0 =>
array (size=6)
0 => string '46.012405' (length=9)
1 => string '6.758742' (length=8)
2 => string 'Cascades de la Pleureuse et de la Sauffaz' (length=41)
3 => int 70
4 => string 'Description' (length=11)
5 => string '<img id=\"lettrineImage\" src=\"http://macbook-pro.local/wordpress/wp-content/uploads/2017/01/2016-06-24_LaPleureuse-LaSauffaz_0729-200x200.jpg\" alt=\"cascade\" height=\"200\" width=\"200\" />' (length=193)
*/
$b = array();
// Avec tous les titres, on crée la requete pour Wikipédia
for ($a = 0; $a < count($coord); $a++){
$short = $coord[$a][2]; // Titre
$b[] = $short;
}
$wiki = fmulticurl($b);
//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++){
array_push($coord[$c], $wiki[$c][1][0], $wiki[$c][2][0], $wiki[$c][3][0]);
}
}
//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) {
// 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>" . $coord[$i][2] . "</h1>','<p>" . $coord[$i][4] . "</p>', " . $coord[$i][0] . ", " . $coord[$i][1] . ",'" . $coord[$i][5] . "']" . (($i<$j) ? "," : "")."\r\n";
echo "['<h1>" . $coord[$i][2] . "</h1>','<p>" . $coord[$i][4] . "</p>', " . $coord[$i][0] . ", " . $coord[$i][1] . ",'" . $coord[$i][5] . "','" . $coord[$i][7] . "','" . $coord[$i][8] . "']" . (($i<$j) ? "," : "")."\r\n";
}
//array_push($coord, array(number_format($lat, 6), number_format($long, 6), $caption, $attach, $description, $thumbnail));
/*
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">
$coord[3] => attachment
locations[5] => $coord[7] => Texte Wikipedia
locations[6] => $coord[8] => Liens vers Wikipedia
*/
?>
];
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);
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 contenuInfoBulle = locations[i][0] + locations[i][4] + locations[i][1];
//var contenuInfoBulle = locations[i][0] + '<a href=\"' + locations[i][6] + '\">' + locations[i][4] + locations[i][5] + '</a>';
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][5] + '<br />' + wikiLink;
/*
locations[0] => $coord[2] => Titre (court)
locations[4] => $coord[5] => <img "letrine">
locations[1] => $coord[4] => Description (long)
locations[5] => $coord[7] => Texte Wikipedia
locations[6] => $coord[8] => Liens vers Wikipedia
*/
infowindow.setContent(contenuInfoBulle);
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(locations[cnt][0]);*/
infowindow.setContent(contenuInfoBulle);
infowindow.open(map, markers[cnt]);
}, 300);
} //jumpToMarker
</script>
<div id="locations">
<div id="gmap" style="width: 800px; height: 400px; border:1px solid #999;" class="aligncenter"></div>
<?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='javascript:void(0);' onclick='jumpToMarker(" . $i . ")'>" . $coord[$i][2] . "</a></li>";
}
echo "</ul></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
} // if count
/*
$photo
array (size=5)
'width' => int 1600
'height' => int 1067
'file' => string '2017/01/2016-06-24_LaPleureuse-LaSauffaz_0729.jpg' (length=49)
'sizes' =>
array (size=3)
'thumbnail' =>
array (size=4)
'file' => string '2016-06-24_LaPleureuse-LaSauffaz_0729-200x200.jpg' (length=49)
'width' => int 200
'height' => int 200
'mime-type' => string 'image/jpeg' (length=10)
'medium' =>
array (size=4)
'file' => string '2016-06-24_LaPleureuse-LaSauffaz_0729-800x534.jpg' (length=49)
'width' => int 800
'height' => int 534
'mime-type' => string 'image/jpeg' (length=10)
'large' =>
array (size=4)
'file' => string '2016-06-24_LaPleureuse-LaSauffaz_0729-1180x787.jpg' (length=50)
'width' => int 1180
'height' => int 787
'mime-type' => string 'image/jpeg' (length=10)
'image_meta' =>
array (size=16)
'aperture' => string '14' (length=2)
'credit' => string '' (length=0)
'camera' => string 'Canon EOS 5D Mark III' (length=21)
'caption' => string '' (length=0)
'created_timestamp' => string '1466758515' (length=10)
'copyright' => string '' (length=0)
'focal_length' => string '17' (length=2)
'iso' => string '100' (length=3)
'shutter_speed' => string '0.04' (length=4)
'title' => string '' (length=0)
'orientation' => string '1' (length=1)
'keywords' =>
array (size=5)
0 => string 'France' (length=6)
1 => string 'Haute-Savoie' (length=12)
2 => string 'Rhone-Alpes' (length=11)
3 => string 'cascade de la Pleureuse' (length=23)
4 => string 'cascade de la Sauffaz' (length=21)
'latitude' =>
array (size=3)
0 => string '46/1' (length=4)
1 => string '7443/10000' (length=10)
2 => string '0/1' (length=3)
'latitude_ref' => string 'N' (length=1)
'longitude' =>
array (size=3)
0 => string '6/1' (length=3)
1 => string '455245/10000' (length=12)
2 => string '0/1' (length=3)
'longitude_ref' => string 'E' (length=1)
*/
?>
</div>
</div>
</div>
<?php
get_footer('page');
?>