Flickr
-shortcode flickr (avec exif et geodata)
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
||||
/.settings
|
||||
/.buildpath
|
||||
/.project
|
||||
/-child
|
||||
|
||||
235
functions.php
235
functions.php
@@ -385,8 +385,73 @@ function date_archive ($chaine) {
|
||||
|
||||
|
||||
function flickr_handler($atts, $content=null) {
|
||||
// flickr = pas d'exifs
|
||||
|
||||
global $coord;
|
||||
$api_key = "3884af4190ac97a95fd4777dba0d9f21";
|
||||
|
||||
extract(shortcode_atts(array(
|
||||
"pid" => $atts[0],
|
||||
"version"=>"Medium 800", //setting default value
|
||||
"caption"=>"", //setting default value
|
||||
"url"=>""
|
||||
), $atts));
|
||||
if($url != ""){
|
||||
$e=explode("/",$url);
|
||||
$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/"]
|
||||
|
||||
[flickr pid="27868468454"]
|
||||
|
||||
[flickr pid="27868468454" version="Small"]
|
||||
*/
|
||||
|
||||
switch (strtolower($version)) {
|
||||
case "square":
|
||||
$img_sd = "Square";
|
||||
$img_hd = "Large Square";
|
||||
break;
|
||||
case "large square":
|
||||
$img_sd = "Square";
|
||||
$img_hd = "Large Square";
|
||||
break;
|
||||
case "small":
|
||||
$img_sd = "Small";
|
||||
$img_hd = "Medium";
|
||||
break;
|
||||
case "small 320":
|
||||
$img_sd = "Small 320";
|
||||
$img_hd = "Medium 640";
|
||||
break;
|
||||
case "medium":
|
||||
$img_sd = "Medium";
|
||||
$img_hd = "Large";
|
||||
break;
|
||||
case "medium 640":
|
||||
$img_sd = "Small 320";
|
||||
$img_hd = "Medium 640";
|
||||
break;
|
||||
case "medium 800":
|
||||
$img_sd = "Medium 800";
|
||||
$img_hd = "Large 1600";
|
||||
break;
|
||||
case "large":
|
||||
$img_sd = "Medium";
|
||||
$img_hd = "Large";
|
||||
break;
|
||||
case "large 1600":
|
||||
$img_sd = "Medium 800";
|
||||
$img_hd = "Large 1600";
|
||||
break;
|
||||
}
|
||||
|
||||
//echo $img_sd . " - ". $img_hd . "<br>";
|
||||
/*
|
||||
$link = ! empty( $atts['link'] ) ? $atts['link'] : '';
|
||||
$link = filter_var($link, FILTER_SANITIZE_URL);
|
||||
|
||||
@@ -407,33 +472,161 @@ function flickr_handler($atts, $content=null) {
|
||||
$lb = ! empty( $atts['lb'] ) ? $atts['lb'] : '';
|
||||
$lb = filter_var($lb, FILTER_SANITIZE_STRING);
|
||||
$info = array();
|
||||
*/
|
||||
|
||||
|
||||
// 1220 -610
|
||||
$lb = toBool($lb);
|
||||
$rnd = rand (1000, 9999);
|
||||
$selector = dess_setting('dess_lightbox_select');
|
||||
|
||||
$flickr_size = getimagesize(htmlentities($small), $info);
|
||||
if (isset($info["APP13"])) {
|
||||
$iptc = iptcparse($info["APP13"]);
|
||||
//var_dump($iptc);
|
||||
}
|
||||
//else echo "no info !!";
|
||||
|
||||
$links = (($caption != "") ? '<div id="flickr_' . $rnd . '" style="width: ' . ($flickr_size[0] + 10) . 'px" class="wp-caption aligncenter">' : '');
|
||||
|
||||
$links .= '<a href="' . $link . '" class="' . (($lb == true) ? $selector : '') . '">';
|
||||
$links .= '<picture data-picture data-alt="">';
|
||||
$links .= '<!--[if IE 9]><video style="display: none;"><![endif]-->';
|
||||
//$link .= '<source class="image_standard" srcset="' . $atts['small'] . ', ' . $atts['big'] . ' 2x">';
|
||||
$links .= '<source class="image_standard" srcset="' . $small . (($big != "") ? ', ' . $big . ' 2x' : '') . '">';
|
||||
$links .= '<source class="image_medium" srcset="" media="(max-width: 767px)">';
|
||||
$links .= '<source class="image_small" srcset="" media="(max-width: 767px)">';
|
||||
$links .= '<!--[if IE 9]></video><![endif]-->';
|
||||
$links .= '<img class="aligncenter" srcset="' . $small . '" ' . $flickr_size[3] . ' alt="' . $alt . '" />';
|
||||
$links .= '</picture></a>';
|
||||
$url1 = 'https://api.flickr.com/services/rest/?method=flickr.photos.getSizes';
|
||||
$url1 .= '&api_key='.$api_key;
|
||||
$url1 .= '&photo_id='.$pid;
|
||||
$url1 .= '&format=json';
|
||||
$url1 .= '&nojsoncallback=1';
|
||||
|
||||
$result = file_get_contents($url1);
|
||||
$response = json_decode($result, true);
|
||||
//preprint($response);
|
||||
|
||||
$taille = $response['sizes']['size'];
|
||||
|
||||
foreach ($taille as $val) {
|
||||
if ($val['label'] == $img_sd) {
|
||||
$mediumSRC = $val['source'];
|
||||
$w_mediumSRC = $val['width'];
|
||||
$h_mediumSRC = $val['height'];
|
||||
}
|
||||
if ($val['label'] == $img_hd) {
|
||||
$largeSRC = $val['source'];
|
||||
$w_largeSRC = $val['width'];
|
||||
$h_largeSRC = $val['height'];
|
||||
}
|
||||
}
|
||||
|
||||
/* Info de l'image */
|
||||
|
||||
$url2 = 'https://api.flickr.com/services/rest/?method=flickr.photos.getInfo';
|
||||
$url2 .= '&api_key='.$api_key;
|
||||
$url2 .= '&photo_id='.$pid;
|
||||
$url2 .= '&format=json';
|
||||
$url2 .= '&nojsoncallback=1';
|
||||
|
||||
$result2 = file_get_contents($url2);
|
||||
$response2 = json_decode($result2, true);
|
||||
//var_dump($response2);
|
||||
|
||||
$title = $response2['photo']['title']['_content'];
|
||||
$date = $response2['photo']['dates']['taken'];
|
||||
$lat = $response2['photo']['location']['latitude'];
|
||||
$long = $response2['photo']['location']['longitude'];
|
||||
$tag = $response2['photo']['tags']['tag'];
|
||||
$desc = $response2['photo']['description']['_content'];
|
||||
$copy = $response2['photo']['owner']['username'];
|
||||
|
||||
$tags = array();
|
||||
foreach ($tag as $val) {
|
||||
//$i = $val['_content'];
|
||||
$i = $val['raw'];
|
||||
$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';
|
||||
$url3 .= '&api_key='.$api_key;
|
||||
$url3 .= '&photo_id='.$pid;
|
||||
$url3 .= '&format=json';
|
||||
$url3 .= '&nojsoncallback=1';
|
||||
|
||||
$result3 = file_get_contents($url3);
|
||||
$response3 = json_decode($result3, true);
|
||||
|
||||
$exif = $response3['photo']['exif'];
|
||||
//preprint($exif);
|
||||
|
||||
$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'];
|
||||
$meta['credit'] = $copy;
|
||||
if ($val['tag'] == 'Model') $meta['camera'] = $val['raw']['_content'];
|
||||
//if ($val['tag'] == 'xxx') $meta['caption'] = $val['raw']['_content'];
|
||||
if ($val['tag'] == 'DateTimeOriginal') $meta['created_timestamp'] = strtotime($val['raw']['_content']);
|
||||
//if ($val['tag'] == 'xxx') $meta['copyright'] = $val['raw']['_content'];
|
||||
if ($val['tag'] == 'FocalLength') $meta['focal_length'] = $val['raw']['_content'];
|
||||
if ($val['tag'] == 'ISO') $meta['iso'] = $val['raw']['_content'];
|
||||
if ($val['tag'] == 'ExposureTime') $meta['shutter_speed'] = $val['raw']['_content'];
|
||||
//if ($val['tag'] == 'xxx') $meta['title'] = $val['raw']['_content'];
|
||||
$meta['title'] = $title;
|
||||
if ($val['tag'] == 'Orientation') $meta['orientation'] = $val['raw']['_content'];
|
||||
$meta['latitude'] = $lat;
|
||||
$meta['longitude'] = $long;
|
||||
$meta['keywords'] = $tags;
|
||||
//$meta['latitudeRef']
|
||||
//$meta['longitudeRef']
|
||||
//$meta['altitude']
|
||||
$meta['medium'] = $mediumSRC;
|
||||
$meta['large'] = $largeSRC;
|
||||
|
||||
}
|
||||
|
||||
//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>";
|
||||
|
||||
/*
|
||||
$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'];
|
||||
//else $fichier = end(explode("/", $court));
|
||||
array_push($coord, array($meta['latitude'], $meta['longitude'], $fichier));
|
||||
}
|
||||
|
||||
|
||||
return $links;
|
||||
}
|
||||
@@ -715,7 +908,7 @@ Array
|
||||
}
|
||||
$meta['keywords'] = $tags;
|
||||
}
|
||||
|
||||
//preprint($meta);
|
||||
return $meta;
|
||||
}
|
||||
|
||||
@@ -1001,7 +1194,7 @@ xdebug_start_trace('/Users/bruno/Sites', XDEBUG_TRACE_COMPUTERIZED);
|
||||
// Autres sources que WP et ZP
|
||||
elseif (substr_count($ancien, 'jpg') > 0) {
|
||||
|
||||
echo "court2: " . $court . "<br>";
|
||||
//echo "court2: " . $court . "<br>";
|
||||
$meta = creator_get_exif( $court );
|
||||
//$flk_size = getimagesize(htmlentities($filename3));
|
||||
/*
|
||||
@@ -1041,7 +1234,7 @@ add_action('the_content','addexif');
|
||||
|
||||
|
||||
function img_wp_exif( $exif_array ) {
|
||||
|
||||
//preprint($exif_array);
|
||||
/*
|
||||
Array
|
||||
(
|
||||
|
||||
@@ -16,10 +16,14 @@ get_header();
|
||||
<?php
|
||||
$coord = array();
|
||||
|
||||
the_content();
|
||||
the_content();
|
||||
|
||||
//preprint($coord);
|
||||
?>
|
||||
|
||||
<?php //echo '<div id="map" style="display: ' . ((count($coord) > 0) ? "block" : "none") . ';"></div>'; ?>
|
||||
|
||||
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
|
||||
Reference in New Issue
Block a user