diff --git a/functions.php b/functions.php index c438926..de0768b 100644 --- a/functions.php +++ b/functions.php @@ -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 != "") ? '
' : ''); + + $links .= (($url != "") ? '' : ''); + $links .= '' . $title . ''; + $links .= (($url != "") ? '' : ''); + + $links .= (($caption != "") ? '

' . $caption . '

' : ''); + + //$links .= (($display_exif == true) ? "
" . $exif_array[0] . (($display_gps == true) ? $exif_array[2] : '') . "
" : ''); + + 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 . "
"; -// 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 . "
"; /* $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,47 +636,26 @@ function flickr_handler($atts, $content=null) { } - //preprint($exifs); -/* - $meta = zp_query_exif( $zp_image ); - $exif_array = img_wp_exif( $meta ); - $exifs = "
" . $exif_array[0] . (($display_gps == true) ? $exif_array[2] : '') . "
"; -*/ - //$meta = zp_query_exif( $zp_image ); //745 $meta['keywords'] => $exif_array = img_wp_exif( $meta ); //1214 - //echo "exif_array"; - //preprint($exif_array); - $links = (($caption != "") ? '
' : ''); $links .= ''; $links .= '' . $img . ''; - //$links .= 'srcset="' . $small . ', " ' . $flickr_size[3] . ' 2x" alt="' . $img . '" />'; - $links .= 'srcset="' . $mediumSRC . ', ' . $largeSRC . ' 2x' . '" alt="' . $title . '" />'; - + $links .= 'srcset="' . $mediumSRC . ', ' . $largeSRC . ' 2x' . '" alt="' . $title . '" />'; $links .= ''; $links .= (($caption != "") ? '

' . $caption . '

' : ''); - $links .= "
" . $exif_array[0] . (($display_gps == true) ? $exif_array[2] : '') . "
"; - -/* - $exif_array = img_wp_exif( $meta ); - $exifs = "
" . $exif_array[0] . (($display_gps == true) ? $exif_array[2] : '') . "
"; - $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']; - //else $fichier = end(explode("/", $court)); - array_push($coord, array($meta['latitude'], $meta['longitude'], $fichier)); - } + $links .= (($display_exif == true) ? "
" . $exif_array[0] . (($display_gps == true) ? $exif_array[2] : '') . "
" : ''); + if (($meta['longitude'] != "") && ($meta['latitude'] != "")) { + if ($meta['caption'] != "") $fichier = $meta['caption']; + else if ($meta['title'] != "") $fichier = $meta['title']; + //else $fichier = end(explode("/", $court)); + array_push($coord, array($meta['latitude'], $meta['longitude'], $fichier)); + } return $links; } @@ -657,22 +686,18 @@ function zenphoto_handler($atts, $content=null) { $caption = ! empty( $atts['caption'] ) ? $atts['caption'] : ''; $caption = filter_var($caption, FILTER_SANITIZE_STRING); - //echo "album: " . $album . " image: " . $image . "
"; - $rnd = rand (1000, 9999); //$size = 610; $folder = false; - //echo "folder1: " . $folder . "
"; $zenphoto_img = ""; // Si ALBUM mais pas IMAGE //echo "album2: " . $album . " image2: " . $image . "
"; //if (($album != "") && ($image == "")) { - require('../Connections/cnx.php'); - + require('../Connections/cnx.php'); $mysqli = new mysqli($dbhost, $dbuser, $dbpassword, $dbtable); if (mysqli_connect_errno()) { @@ -738,16 +763,6 @@ function zenphoto_handler($atts, $content=null) { else $zenphoto_link = ''; $zenphoto_img .= $zenphoto_link; - /* - $zenphoto_img .= ' - - - - - - - '; - */ $zenphoto_img .= '' . $img . ''; @@ -804,9 +819,9 @@ Array - [13] => a:1:{s:5:"fr_FR";s:24:"2014-10-21_PontDArc_0406";} *title* [14] => *EXIFLensType* - [15] => EF17-40mm f/4L USM *EXIFLensInfo* - - [16] => 1: Normal (0 degr�) *EXIFOrientation* + - [16] => 1: Normal (0 degr�) *EXIFOrientation* - [17] => Bruno Pesenti *credit* - - [18] => bruno@clicclac.info *copyright* + - [18] => bruno@clicclac.info *copyright* - [19] => *id* ) */ @@ -1075,10 +1090,11 @@ xdebug_start_trace('/Users/bruno/Sites', XDEBUG_TRACE_COMPUTERIZED); // `1049` //$pattern = '/
]*>(.*?)\<\/div>/'; - $pattern = '/
]*>(.*?)\<\/div>/'; + //$pattern = '#((?:]+>\s*)?]+>(?:\s*)?)(.*)#is'; + $pattern = '/
]*>(.*?)\<\/div>/'; //ok //$pattern = '/
]*>(.*?)\<\/div>/'; preg_match_all($pattern, $content, $matches, PREG_SET_ORDER); - //var_dump($matches); + //preprint($matches); /* echo "matches[0][0]"; //
...
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 . "
"; - $meta = creator_get_exif( $court ); -//$flk_size = getimagesize(htmlentities($filename3)); + //echo "long2: " . $ancien . "
"; + //$meta = creator_get_exif( $court ); + + // si $court est déjà dans $matches3 (si l'image est déjà dans un DIV) /* - Flicker (portrait): - + if (in_multiarray($court, $matches3) == false) { + $meta = creator_get_exif( $court ); + //preprint($meta); - Flicker (paysage) vautour avec branche: - - - 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 = "
" . $exif_array[0] . (($display_gps == true) ? $exif_array[2] : '') . "
"; + //$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("/>", "class='aligncenter' style='width: " . (($portrait === false) ? "610" : "408") . "px;' />", $ancien) . "\r\n"; //$anc = str_replace("/>", "class='aligncenter' />", $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 . "
"; + echo "file: " . $file . "
"; 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 = " + \n\t\t"; + //} + echo $gallery_style; + + //$ids = implode(',',$attr['ids']); // '70,69,68,67' + + $gallery_div = "'; + if (count($coord) > 0) { + + //var_dump($coord); + ?> @@ -192,13 +196,15 @@ get_header(); echo "
"; ?> -
+
- + '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); + ?> + +
+
+
+ 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 = '' . $attribut['alt'] . ''; + $thumbnail = '\"''; + //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; + + ?> + + + 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 '\"cascade\"' (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); + + ?> + + +
+ +
+ +
"; + ?> + +
+ + + + + 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) +*/ + + + + + ?> + +
+
+
+ + \ No newline at end of file