]*>(.*?)\<\/div>/'; //ok
preg_match_all($pattern, $content, $matches, PREG_SET_ORDER);
// Pour tous les DIV (attachment) on cherche les
for ($i = 0; $i <= (count($matches) - 1); $i++) {
$pattern2 = '/]*href=\"([^\"]*)\"[^>]*>(.*)<\/a>/siU';
preg_match_all($pattern2, $matches[$i][0] , $matches2, PREG_SET_ORDER);
array_push($matches3, array($matches2[0][1], $matches[$i][0]));
$court = $matches2[0][1];
$pid = "";
if (substr_count($court, "wordpress") > 0) {
$meta = creator_get_exif( $court );
//var_dump($meta);
/*
//var_dump($matches2);
$attach = $matches[$i][2];
$pid = $attach;
//$attribut = wp_prepare_attachment_for_js( $image->ID );
$attribut = wp_prepare_attachment_for_js( $attach );
//var_dump($attribut);
//$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_thumb_ZP_wiki = '
';
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));
*/
}
elseif (substr_count($court, "zenphoto") > 0) {
$img = explode("/", $court);
$zp_image = end($img);
$zp_album = prev($img);
$img_thumb_ZP_wiki = thumb_ZP_wiki($zp_image, $zp_album);
$meta = zp_query_exif( $zp_image );
$zenphoto_coord = true;
}
$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));
if ($zenphoto_coord == true) {
array_push($coord, array($meta['latitude'], $meta['longitude'], $fichier, $pid, $meta['caption'], $img_thumb_ZP_wiki));
}
}
} // for
} // ($display_exif == true)
$pattern2 = '/]*href=\"([^\"]*)\"[^>]*>(.*)<\/a>/siU';
preg_match_all($pattern2, $content , $matches4, PREG_SET_ORDER);
for ($i = 0; $i <= (count($matches4) - 1); $i++) {
$ancien = $matches4[$i][0];
$court = $matches4[$i][1];
// si source wordpress
if (substr_count($ancien, "wordpress") > 0) {
/*
$patternWP = '#wp-image-[0-9]{1,4}#';
if (preg_match($patternWP, $ancien, $matches5) === 1) {
$attachment = substr($matches5[0],9);
*/
// si $court est déjà dans $matches3 (si l'image est déjà dans un DIV)
if (in_multiarray($court, $matches3) == false) {
$meta = creator_get_exif( $court );
$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);
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));
}
} // if in_multiarray
} //if wordpress
// si source zenphoto
elseif ((substr_count($ancien, 'zenphoto') != 0) and (substr_count($ancien, '
]*href=\"([^\"]*)\"[^>]*>(.*)<\/a>/siU';
preg_match($patternZP, $ancien , $matches2);
$img = explode("/", $matches2[1]);
$zp_image = end($img);
$zp_album = prev($img);
var_dump($zp_image, $zp_album);
$img_thumb_ZP_wiki = thumb_ZP_wiki($zp_image, $zp_album);
var_dump($img_thumb_ZP_wiki);
$meta = zp_query_exif( $zp_image );
$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);
$exifs = "";
if (($meta['longitude'] != "") && ($meta['latitude'] != "")) {
if ($meta['caption'] != "") $fichier = $meta['caption'];
else if ($meta['title'] != "") $fichier = $meta['title'];
else $fichier = end(explode("/", $court));
$pid = "";
echo "fichier: " . $fichier;
array_push($coord, array($meta['latitude'], $meta['longitude'], $fichier, $pid, $meta['caption'], $img_thumb_ZP_wiki));
}
} // if in_multiarray
} // else zenphoto
// Autres sources que WP et ZP
elseif ((substr_count($ancien, 'jpg') > 0) and (substr_count($ancien, 'flickr') == 0)) {
//echo "court2: " . $court . "
";
//echo "long2: " . $ancien . "
";
//$meta = creator_get_exif( $court );
// si $court est déjà dans $matches3 (si l'image est déjà dans un DIV)
/*
if (in_multiarray($court, $matches3) == false) {
$meta = creator_get_exif( $court );
//preprint($meta);
$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
return $content;
}
add_action('the_content','addexif');
/*
* img_wp_exif: crée la chaine d'affichages des exifs et des données GPS
*
*entree $exif_array (tableau avec tous les exifs
*retourne array($exifInfo, $exifGPS, $geo_link):
* -$exifInfo: chaine qui affiche les exifs
* -$exifGPS: données gps pour $exifInfo
* -$geo_link: image globe avec lien vers googlemaps.com
*
* functions.php - flickr_handler() add_exif()
*/
function img_wp_exif( $exif_array ) {
/*
Array
(
[aperture] => 10
[credit] =>
[camera] => Canon EOS 5D Mark III
[caption] =>
[created_timestamp] => 1454520944
[copyright] =>
[focal_length] => 118
[iso] => 800
[shutter_speed] => 1/200
[title] => Etang des Fontaines
[orientation] => 1
[latitude] => 47.109745
[longitude] => 5.0787033333333
[keywords] => Array
(
[0] => Etang
[1] => coucher de soleil
)
[latitudeRef] => N
[longitudeRef] => E
[altitude] => 206.5042
)
*/
$exifInfo = "";
$exifGPS = "";
$geo_link = "";
// Si données GPS:
if ($exif_array['aperture'] != "") {
// bloc exif (avec icones)
$exifInfo .= "
" . date(__("F j, Y, g:i a",'CreatorThemeRes-child'),$exif_array['created_timestamp']) . "";
$exifInfo .= "
" . $exif_array['camera'] . "";
$exifInfo .= "
" . $exif_array['shutter_speed'] . "";
$exifInfo .= "
" . $exif_array['aperture'] . "";
$exifInfo .= "
" . $exif_array['iso'] . "";
$exifInfo .= "
";
$exifInfo .= (($exif_array['lens'] != "") ? $exif_array['lens'] : $exif_array['focal_length']);
$exifInfo .= "";
/*
// lien exif (texte)
$exifInfo = "";
$exifInfo = __('The','CreatorThemeRes-child') . " " . date(__("F j, Y, g:i a",'CreatorThemeRes-child'),$exif_array['created_timestamp']);
$exifInfo .= ' - ' . $exif_array['shutter_speed'];
$exifInfo .= '
' . __(' at ','CreatorThemeRes-child') . "f/" . $exif_array['aperture'];
$exifInfo .= ' - ' .$exif_array['iso'].' ISO - ';
$exifInfo .= (($exif_array['lens'] != "") ? __('Lens: ','CreatorThemeRes-child') . $exif_array['lens'] : __('Focal: ','CreatorThemeRes-child') . $exif_array['focal_length'] . "mm");
*/
}
// Si données GPS:
if ($exif_array['latitude'] != "") {
// lien lat/long/alt (avec icones)
$exifGPS .= "
" . $exif_array['latitude'] . "";
$exifGPS .= "
" . $exif_array['longitude'] . "";
$exifGPS .= "
" . $exif_array['altitude'] . "";
// lien lat/long/alt (texte)
//$exifGPS .= __('Latitude: ','CreatorThemeRes-child') . $exif_array['latitude'] . __(' Longitude: ','CreatorThemeRes-child') . $exif_array['longitude'] . __(' Altitude: ','CreatorThemeRes-child') . number_format($exif_array['altitude']) . 'm';
//lien vers Googlemaps (globe)
$geo_link = '
';
//$geo_link .= '
';
$geo_link .= '
';
$geo_link .= '';
}
return array($exifInfo, $exifGPS, $geo_link);
}
/*
* creator_get_exif: récupère les exifs (et données GPS) pour les images WP
*
* entree $file (str)
* retourne $meta (array)
*
* functions.php - add_exif()
*/
function creator_get_exif( $file ) {
/*
if ( ! file_exists( $file ) ) {
echo "pas de fichier";
return false;
}
*/
//echo "file: " . $file . "
";
list( , , $sourceImageType ) = getimagesize( $file );
/*
* EXIF contains a bunch of data we'll probably never need formatted in ways
* that are difficult to use. We'll normalize it and just extract the fields
* that are likely to be useful. Fractions and numbers are converted to
* floats, dates to unix timestamps, and everything else to strings.
*/
$meta = array(
'aperture' => 0,
'credit' => '',
'camera' => '',
'caption' => '',
'created_timestamp' => 0,
'copyright' => '',
'focal_length' => 0,
'iso' => 0,
'shutter_speed' => 0,
'title' => '',
'orientation' => 0,
'latitude' => 0,
'longitude' => 0,
'latitude' => 0,
'altitude' => 0,
'lens' => '',
'keywords' => array(),
);
$iptc = array();
/*
* Read IPTC first, since it might contain data not available in exif such
* as caption, description etc.
*/
if ( is_callable( 'iptcparse' ) ) {
getimagesize( $file, $info );
if ( ! empty( $info['APP13'] ) ) {
$iptc = iptcparse( $info['APP13'] );
//preprint($iptc);
// Headline, "A brief synopsis of the caption."
if ( ! empty( $iptc['2#105'][0] ) ) {
$meta['title'] = trim( $iptc['2#105'][0] );
/*
* Title, "Many use the Title field to store the filename of the image,
* though the field may be used in many ways."
*/
} elseif ( ! empty( $iptc['2#005'][0] ) ) {
$meta['title'] = trim( $iptc['2#005'][0] );
}
if ( ! empty( $iptc['2#120'][0] ) ) { // description / legacy caption
$caption = trim( $iptc['2#120'][0] );
mbstring_binary_safe_encoding();
$caption_length = strlen( $caption );
reset_mbstring_encoding();
if ( empty( $meta['title'] ) && $caption_length < 80 ) {
// Assume the title is stored in 2:120 if it's short.
$meta['title'] = $caption;
}
$meta['caption'] = $caption;
}
if ( ! empty( $iptc['2#110'][0] ) ) // credit
$meta['credit'] = trim( $iptc['2#110'][0] );
elseif ( ! empty( $iptc['2#080'][0] ) ) // creator / legacy byline
$meta['credit'] = trim( $iptc['2#080'][0] );
// 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] );
if ( ! empty( $iptc['2#025'][0] ) ) { // keywords array
$meta['keywords'] = array_values( $iptc['2#025'] );
}
}
}
//if ( is_callable( 'exif_read_data' ) && in_array( $sourceImageType, apply_filters( 'wp_read_image_metadata_types', array( IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM ) ) ) ) {
if ( is_callable( 'exif_read_data' )) {
$exif = @exif_read_data( $file );
//preprint($exif);
if ( ! empty( $exif['ImageDescription'] ) ) {
mbstring_binary_safe_encoding();
$description_length = strlen( $exif['ImageDescription'] );
reset_mbstring_encoding();
if ( empty( $meta['title'] ) && $description_length < 80 ) {
// Assume the title is stored in ImageDescription
$meta['title'] = trim( $exif['ImageDescription'] );
}
if ( empty( $meta['caption'] ) && ! empty( $exif['COMPUTED']['UserComment'] ) ) {
$meta['caption'] = trim( $exif['COMPUTED']['UserComment'] );
}
if ( empty( $meta['caption'] ) ) {
$meta['caption'] = trim( $exif['ImageDescription'] );
}
} elseif ( empty( $meta['caption'] ) && ! empty( $exif['Comments'] ) ) {
$meta['caption'] = trim( $exif['Comments'] );
}
if ( empty( $meta['credit'] ) ) {
if ( ! empty( $exif['Artist'] ) ) {
$meta['credit'] = trim( $exif['Artist'] );
} elseif ( ! empty($exif['Author'] ) ) {
$meta['credit'] = trim( $exif['Author'] );
}
}
if ( empty( $meta['copyright'] ) && ! empty( $exif['Copyright'] ) ) {
$meta['copyright'] = trim( $exif['Copyright'] );
}
if ( ! empty( $exif['FNumber'] ) ) {
$meta['aperture'] = "f/" . round( geo_frac2dec( $exif['FNumber'] ), 2 );
}
if ( ! empty( $exif['Model'] ) ) {
$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'];
}
if ( ! empty( $exif['FocalLength'] ) ) {
$meta['focal_length'] = (string) geo_frac2dec( $exif['FocalLength'] ) . " mm";
}
if ( ! empty( $exif['ISOSpeedRatings'] ) ) {
$meta['iso'] = is_array( $exif['ISOSpeedRatings'] ) ? reset( $exif['ISOSpeedRatings'] ) : $exif['ISOSpeedRatings'];
$meta['iso'] = trim( $meta['iso'] );
}
if ( ! empty( $exif['ExposureTime'] ) ) {
//$meta['shutter_speed'] = (string) wp_exif_frac2dec( $exif['ExposureTime'] );
$meta['shutter_speed'] = $exif['ExposureTime'];
}
if ( ! empty( $exif['Orientation'] ) ) {
$meta['orientation'] = $exif['Orientation'];
}
if ( ! empty( $exif['GPSLatitude'] ) ) {
$lat = gps($exif['GPSLatitude'], trim( $exif['GPSLatitudeRef'] ));
$meta['latitude'] = number_format($lat, 6);
}
if ( ! empty( $exif['GPSLongitude'] ) ) {
$long = gps($exif['GPSLongitude'], trim( $exif['GPSLongitudeRef'] ));
$meta['longitude'] = number_format($long, 6);
}
/*
if ( ! empty( $exif['GPSLatitudeRef'] ) ) {
$meta['latitudeRef'] = trim( $exif['GPSLatitudeRef'] );
}
if ( ! empty( $exif['GPSLongitudeRef'] ) ) {
$meta['longitudeRef'] = trim( $exif['GPSLongitudeRef'] );
}
*/
if ( ! empty( $exif['GPSAltitude'] ) ) {
$meta['altitude'] = number_format(geo_frac2dec($exif['GPSAltitude']));
}
if ( ! empty( $exif['UndefinedTag:0xA434'] ) ) {
$meta['lens'] = trim($exif['UndefinedTag:0xA434']);
}
// [UndefinedTag:0xA434] => 10.0-22.0 mm
// [UndefinedTag:0xA434] => EF500mm f/4L IS USM +1.4x
}
foreach ( array( 'title', 'caption', 'credit', 'copyright', 'camera', 'iso' ) as $key ) {
if ( $meta[ $key ] && ! seems_utf8( $meta[ $key ] ) ) {
$meta[ $key ] = utf8_encode( $meta[ $key ] );
}
}
foreach ( $meta['keywords'] as $key => $keyword ) {
if ( ! seems_utf8( $keyword ) ) {
$meta['keywords'][ $key ] = utf8_encode( $keyword );
}
}
//$meta = wp_kses_post_deep( $meta );
/**
* Filters the array of meta data read from an image's exif data.
*
* @since 2.5.0
* @since 4.4.0 The `$iptc` parameter was added.
*
* @param array $meta Image meta data.
* @param string $file Path to image file.
* @param int $sourceImageType Type of image.
* @param array $iptc IPTC data.
*/
//return apply_filters( 'wp_read_image_metadata', $meta, $file, $sourceImageType, $iptc );
return $meta;
}
/*
* Convertisseurs de valeurs GPS (latitude, longitude, altitude (+Ref))
*
* geo_frac2dec() - functions.php: creator_get_exif() geo_single_fracs2dec()
* gps() - functions.php: add_class_lightbox() creator_get_exif() - tpl-carte.php
* geo_single_fracs2dec() -
* ctc_exif_date2ts() - functions.php: creator_get_exif()
*/
function geo_single_fracs2dec($fracs) {
return geo_frac2dec($fracs[0]) +
geo_frac2dec($fracs[1]) / 60 +
geo_frac2dec($fracs[2]) / 3600;
}
function geo_frac2dec($str) {
@list( $n, $d ) = explode( '/', $str );
if ( !empty($d) )
return $n / $d;
return $str;
}
function gps($coordinate, $hemisphere) {
for ($i = 0; $i < 3; $i++) {
$part = explode('/', $coordinate[$i]);
if (count($part) == 1) {
$coordinate[$i] = $part[0];
} else if (count($part) == 2) {
$coordinate[$i] = floatval($part[0])/floatval($part[1]);
} else {
$coordinate[$i] = 0;
}
}
list($degrees, $minutes, $seconds) = $coordinate;
$sign = ($hemisphere == 'W' || $hemisphere == 'S') ? -1 : 1;
return $sign * ($degrees + $minutes/60 + $seconds/3600);
}
// 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; //
/*
* mapgallery: affiche la galerie sur la Page Map
*
* entree $attr (array) shortcode gallery
* retourne $output (str)
*
* tpl-carte.php
*/
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 = "
";
//"
";
//$gallery_div = "";
$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 = "
" . wp_get_attachment_image($id, $attr['size'], false, $attr ) . "";
} 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 = "
";
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 .= '
';
}
}
if ( ! $html5 && $columns > 0 && $i % $columns !== 0 ) {
$output .= '
';
}
$output .= "
\n";
return $output;
}
remove_shortcode('gallery', 'gallery_shortcode');
add_shortcode('gallery', 'creator_gallery_shortcode');
/**
* Builds the Gallery shortcode output. (*** Modifié pour ajouter des liens vers lightbox***)
*
* This implements the functionality of the Gallery Shortcode for displaying
* WordPress images on a post.
*
* @since 2.5.0
*
* @staticvar int $instance
*
* @param array $attr {
* Attributes of the gallery shortcode.
*
* @type string $order Order of the images in the gallery. Default 'ASC'. Accepts 'ASC', 'DESC'.
* @type string $orderby The field to use when ordering the images. Default 'menu_order ID'.
* Accepts any valid SQL ORDERBY statement.
* @type int $id Post ID.
* @type string $itemtag HTML tag to use for each image in the gallery.
* Default 'dl', or 'figure' when the theme registers HTML5 gallery support.
* @type string $icontag HTML tag to use for each image's icon.
* Default 'dt', or 'div' when the theme registers HTML5 gallery support.
* @type string $captiontag HTML tag to use for each image's caption.
* Default 'dd', or 'figcaption' when the theme registers HTML5 gallery support.
* @type int $columns Number of columns of images to display. Default 3.
* @type string|array $size Size of the images to display. Accepts any valid image size, or an array of width
* and height values in pixels (in that order). Default 'thumbnail'.
* @type string $ids A comma-separated list of IDs of attachments to display. Default empty.
* @type string $include A comma-separated list of IDs of attachments to include. Default empty.
* @type string $exclude A comma-separated list of IDs of attachments to exclude. Default empty.
* @type string $link What to link each image to. Default empty (links to the attachment page).
* Accepts 'file', 'none'.
* }
* @return string HTML content to display gallery.
*/
function creator_gallery_shortcode( $attr ) {
$post = get_post();
static $instance = 0;
$instance++;
if ( ! empty( $attr['ids'] ) ) {
// 'ids' is explicitly ordered, unless you specify otherwise.
if ( empty( $attr['orderby'] ) ) {
$attr['orderby'] = 'post__in';
}
$attr['include'] = $attr['ids'];
}
/**
* Filters the default gallery shortcode output.
*
* If the filtered output isn't empty, it will be used instead of generating
* the default gallery template.
*
* @since 2.5.0
* @since 4.2.0 The `$instance` parameter was added.
*
* @see gallery_shortcode()
*
* @param string $output The gallery output. Default empty.
* @param array $attr Attributes of the gallery shortcode.
* @param int $instance Unique numeric ID of this gallery shortcode instance.
*/
$output = apply_filters( 'post_gallery', '', $attr, $instance );
if ( $output != '' ) {
return $output;
}
$html5 = current_theme_supports( 'html5', 'gallery' );
$atts = shortcode_atts( array(
'order' => 'ASC',
'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, 'gallery' );
$id = intval( $atts['id'] );
if ( ! empty( $atts['include'] ) ) {
$_attachments = get_posts( array( 'include' => $atts['include'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
$attachments = array();
foreach ( $_attachments as $key => $val ) {
$attachments[$val->ID] = $_attachments[$key];
}
} elseif ( ! empty( $atts['exclude'] ) ) {
$attachments = get_children( array( 'post_parent' => $id, 'exclude' => $atts['exclude'], 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
} else {
$attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $atts['order'], 'orderby' => $atts['orderby'] ) );
}
if ( empty( $attachments ) ) {
return '';
}
if ( is_feed() ) {
$output = "\n";
foreach ( $attachments as $att_id => $attachment ) {
$output .= wp_get_attachment_link( $att_id, $atts['size'], true ) . "\n";
}
return $output;
}
$itemtag = tag_escape( $atts['itemtag'] );
$captiontag = tag_escape( $atts['captiontag'] );
$icontag = tag_escape( $atts['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';
}
$columns = intval( $atts['columns'] );
$itemwidth = $columns > 0 ? floor(100/$columns) : 100;
$float = is_rtl() ? 'right' : 'left';
$selector = "gallery-{$instance}";
$gallery_style = '';
/**
* Filters whether to print default gallery styles.
*
* @since 3.1.0
*
* @param bool $print Whether to print default gallery styles.
* Defaults to false if the theme supports HTML5 galleries.
* Otherwise, defaults to true.
*/
if ( apply_filters( 'use_default_gallery_style', ! $html5 ) ) {
$gallery_style = "
\n\t\t";
}
$size_class = sanitize_html_class( $atts['size'] );
$gallery_div = "";
/**
* Filters the default gallery shortcode CSS styles.
*
* @since 2.5.0
*
* @param string $gallery_style Default CSS styles and opening HTML div container
* for the gallery shortcode output.
*/
$output = apply_filters( 'gallery_style', $gallery_style . $gallery_div );
$selecteur = dess_setting('dess_lightbox_select');
$i = 0;
foreach ( $attachments as $id => $attachment ) {
$attr = ( trim( $attachment->post_excerpt ) ) ? array( 'aria-describedby' => "$selector-$id" ) : '';
if ( ! empty( $atts['link'] ) && 'file' === $atts['link'] ) {
//$image_output = wp_get_attachment_link( $id, $atts['size'], false, false, false, $attr );
//$image_output = "
" . wp_get_attachment_image($id, $atts['size'], false, $attr ) . "";
$image_output = "
" . wp_get_attachment_image($id, $atts['size'], false, $attr ) . "";
} elseif ( ! empty( $atts['link'] ) && 'none' === $atts['link'] ) {
$image_output = wp_get_attachment_image( $id, $atts['size'], false, $attr );
} else {
$image_output = wp_get_attachment_link( $id, $atts['size'], true, false, false, $attr );
}
$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'>";
$output .= "
<{$icontag} class='gallery-icon {$orientation}'>
$image_output
{$icontag}>";
if ( $captiontag && trim($attachment->post_excerpt) ) {
$output .= "
<{$captiontag} class='wp-caption-text gallery-caption' id='$selector-$id'>
" . wptexturize($attachment->post_excerpt) . "
{$captiontag}>";
}
$output .= "{$itemtag}>";
if ( ! $html5 && $columns > 0 && ++$i % $columns == 0 ) {
$output .= '
';
}
}
if ( ! $html5 && $columns > 0 && $i % $columns !== 0 ) {
$output .= "
";
}
$output .= "
\n";
return $output;
}
/*
* childtheme_customize_register(): modifie la page des options du thème child
*
* entree
* retourne
*
*
*/
//http://cssmary.com/wordpress/customizer-api-child-theme/
function childtheme_customize_register( $wp_customize ) {
// remove settings
$remove_socials = array('google-plus','instagram','pinterest','linkedin');
for($i=0;$iremove_setting( 'dess_'.$remove_socials[$i] );
$wp_customize->remove_control( 'dess_'.$remove_socials[$i] );
}
$wp_customize->remove_setting( 'dess_hoursup' );
$wp_customize->remove_control( 'dess_hoursup' );
$wp_customize->remove_setting( 'dess_tel' );
$wp_customize->remove_control( 'dess_tel' );
// add settings
$add_socials = array('500px','flickr','rss','mail');
for($i=0;$iadd_setting('dess_'.$add_socials[$i], array(
'capability' => 'edit_theme_options',
'type' => 'theme_mod',
'sanitize_callback' => 'dess_sanitize_url',
));
$wp_customize->add_control(new WP_Customize_Control($wp_customize, 'dess_'.$add_socials[$i], array(
'settings' => 'dess_'.$add_socials[$i],
'label' => $name.' URL',
'section' => 'sm_section',
'type' => 'text',
)));
}
$wp_customize->get_setting( 'dess_rss' )->default = get_bloginfo('rss2_url');
// new section
$wp_customize->add_section('settings_section', array(
'title' => __('Settings','creator'),
'capability' => 'edit_theme_options',
'description' => __('Theme settings','CreatorThemeRes-child')
)
);
// new options
$wp_customize->add_setting('dess_zenphoto', array(
'capability' => 'edit_theme_options',
'type' => 'theme_mod',
'sanitize_callback' => 'dess_sanitize_html',
));
$wp_customize->add_control(new WP_Customize_Control($wp_customize, 'dess_zenphoto', array(
'settings' => 'dess_zenphoto',
'label' => __('Zenphoto path','CreatorThemeRes-child'),
'section' => 'settings_section',
'type' => 'text',
)));
$wp_customize->add_setting('dess_zp_size', array(
'capability' => 'edit_theme_options',
'type' => 'theme_mod',
'sanitize_callback' => 'dess_sanitize_html',
));
$wp_customize->add_control(new WP_Customize_Control($wp_customize, 'dess_zp_size', array(
'settings' => 'dess_zp_size',
'label' => __('Zenphoto image size (px)','CreatorThemeRes-child'),
'section' => 'settings_section',
'type' => 'text',
)));
$wp_customize->add_setting('dess_social_size', array(
'capability' => 'edit_theme_options',
'type' => 'theme_mod',
'sanitize_callback' => 'dess_sanitize_html',
));
$wp_customize->add_control(new WP_Customize_Control($wp_customize, 'dess_social_size', array(
'settings' => 'dess_social_size',
'label' => __('Socials icons size (16 or 32px)','CreatorThemeRes-child'),
'section' => 'settings_section',
'type' => 'text',
)));
$wp_customize->add_setting('dess_lightbox_select', array(
'capability' => 'edit_theme_options',
'type' => 'theme_mod',
'sanitize_callback' => 'dess_sanitize_html',
));
$wp_customize->add_control(new WP_Customize_Control($wp_customize, 'dess_lightbox_select', array(
'settings' => 'dess_lightbox_select',
'label' => __('Lightbox selector (class="xxx")','CreatorThemeRes-child'),
'section' => 'settings_section',
'type' => 'text',
)));
$wp_customize->add_setting( 'dess_lightbox_choice', array(
'default' => 'b',
) );
$wp_customize->add_control(new WP_Customize_Control($wp_customize, 'dess_lightbox_choice', array(
'label' => __('Choice of lightbox','CreatorThemeRes-child'),
'section' => 'settings_section',
'settings' => 'dess_lightbox_choice',
'type' => 'radio',
'choices' => array(
'a' => 'Meow box',
'b' => 'Colorbox',
'c' => 'Featherlight',
),
)));
$wp_customize->add_setting( 'dess_display_exif', array(
'default' => 'trlue',
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
) );
$wp_customize->add_control( 'dess_display_exif', array(
'settings' => 'dess_display_exif',
'label' => __('Display EXIFs','CreatorThemeRes-child'),
'section' => 'settings_section',
'type' => 'checkbox',
) );
$wp_customize->add_setting( 'dess_display_gps', array(
'default' => 'false',
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
) );
$wp_customize->add_control( 'dess_display_gps', array(
'settings' => 'dess_display_gps',
'label' => __('Display Geo datas','CreatorThemeRes-child'),
'section' => 'settings_section',
'type' => 'checkbox',
) );
$wp_customize->add_setting( 'dess_display_meta', array(
'default' => 'false',
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
) );
$wp_customize->add_control( 'dess_display_meta', array(
'settings' => 'dess_display_meta',
'label' => __('Display meta (single)','CreatorThemeRes-child'),
'section' => 'settings_section',
'type' => 'checkbox',
) );
}
add_action( 'customize_register', 'childtheme_customize_register', 12);
/*
function choice_a_callback( $control ) {
if ( $control->manager->get_setting('dess_lightbox_choice')->value() == 'a' ) {
return true;
} else {
return false;
}
}
function choice_b_callback( $control ) {
if ( $control->manager->get_setting('dess_lightbox_choice')->value() == 'b' ) {
return true;
} else {
return false;
}
}
function choice_c_callback( $control ) {
if ( $control->manager->get_setting('dess_lightbox_choice')->value() == 'c' ) {
return true;
} else {
return false;
}
}
*/
/*
* show_bookmark_list(): SHORCODE modifie la liste des liens (wp_list_bookmarks())
*
*/
function show_bookmark_list(){ ?>
'',
'title_after' => '
',
);
wp_list_bookmarks( $args ); ?>
'opensearch',
//'search' => $query,
'format' => 'json',
'profile' => 'strict' //strict, normal, *fuzzy*, classic
);
$fields_string = "";
foreach($fields as $key=>$value) {
$fields_string .= $key.'='.$value.'&';
}
/* nettoyage expressions à rechercher */
/**/
echo "requete avant clean_req_wiki
";
var_dump($query);
$wiki = clean_req_wiki($query);
//$wiki = $query;
/**/
echo "requete apres clean_req_wiki
";
var_dump($wiki);
/* constructions des requetes */
foreach ($wiki as &$val) {
//$val = $url . "?" . $fields_string . "search=" . str_replace(" ", "_", trim($val));
$val = $url . "?" . $fields_string . "search=" . $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, $wiki[$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);
/* OK Remplace les entrées vides par ""
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
*/
echo "retour de la requete
";
var_dump($obj);
for ($a = 0; $a < count($obj); $a++){
/*
$req = str_replace("_", " ", $obj[$a][0]);
$req = " " . $req . " ";
*/
$req = $query[$a];
/*
if (is_array($obj[$a])) {
for ($b = 0; $b < count($obj[$a]); $b++){
if (empty($obj[$a][$b])) {
$obj[$a][$b][0] = "";
}
} //for
} //if
*/
foreach ($obj[$a][2] as $key => $val) {
//if (stripos(substr($val, 0, 50), $req) !== false) echo "matche $key";
//echo "nettoyage du retour de la requete
";
//var_dump($val, $req);
if (stripos(substr($val, 0, 50), $req) === false) {
unset($obj[$a][1][$key]);
unset($obj[$a][3][$key]);
unset($obj[$a][2][$key]);
}
}
} //for
if (count($erreur) > 0) var_dump($erreur);
//echo "retour de la function multicurl
";
//var_dump($obj);
return $obj;
}
/*
* safe_array_access(): recherche et récupère des infos sur Wikipedia
*
* entree $query (array) (tableau contenant les données à rechercher sur wikipedia (1 entrée/image))
* retourne $obj (array)
*
* single.php - tpl-carte.php
*/
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);
}
/*
* clean_req_wiki(): nettoie la requete pour Wikipedia
*
* entree $req (array) (tableau contenant les données à rechercher sur wikipedia (1 entrée/image))
* retourne $q (array) (supprime les tags, les articles en début d'expression, les accents, trim , remplace les " " par "_"
*
* functions.php - fmulticurl()
*/
function clean_req_wiki ($req) {
$v = array();
foreach($req as $val) {
//echo $val . " - ";
$z = strip_tags($val);
//$y= supp_article($z);
$y= supprime_article($z);
$x = str_to_noaccent($y);
//$w = addslashes($x); // mets pont d'arcole avant pont d'arc
//$v = strtolower($w);
$v = str_replace(" ", "_", $x);
$q[] = trim($v);
}
echo "
";
return $q;
}
/*
* str_to_noaccent(): remplace les lettres accentuées par leur équivalent sans accent
*
* entree $str (str)
* retourne $str (str)
*
* functions.php - clean_req_wiki()
*/
function str_to_noaccent($str) {
$str = preg_replace('#Ç#', 'C', $str);
$str = preg_replace('#ç#', 'c', $str);
$str = preg_replace('#è|é|ê|ë#', 'e', $str);
$str = preg_replace('#È|É|Ê|Ë#', 'E', $str);
$str = preg_replace('#à|á|â|ã|ä|å#', 'a', $str);
$str = preg_replace('#@|À|Á|Â|Ã|Ä|Å#', 'A', $str);
$str = preg_replace('#ì|í|î|ï#', 'i', $str);
$str = preg_replace('#Ì|Í|Î|Ï#', 'I', $str);
$str = preg_replace('#ð|ò|ó|ô|õ|ö#', 'o', $str);
$str = preg_replace('#Ò|Ó|Ô|Õ|Ö#', 'O', $str);
$str = preg_replace('#ù|ú|û|ü#', 'u', $str);
$str = preg_replace('#Ù|Ú|Û|Ü#', 'U', $str);
$str = preg_replace('#ý|ÿ#', 'y', $str);
$str = preg_replace('#Ý#', 'Y', $str);
return ($str);
}
/*
* supprime_article(): supprime les articles en début d'expression
*
*
* entree $str (str)
* retourne $m (str)
*
* functions.php - clean_req_wiki()
*/
function supprime_article($str) {
//supprime les articles en début de chaine
//supprime expressions entre parentheses
$pattern = "#^(le|la|les|un|une|du|de|des|ce|ces|cette|cet)\s#mUis";
$pattern2 = "#^([l|d|s|t]')#mUis";
$pattern3 = "#\\([^)]*\\)#";
$k = preg_replace($pattern, " ", $str);
$l = preg_replace($pattern2, " ", $k);
$m = preg_replace($pattern3, "", $l);
return trim($m);
}
function preprint($s, $return=false) {
$x = "";
$x .= print_r($s, 1);
$x .= "";
if ($return) return $x;
else print $x;
}
?>