Reinstall silverbook
This commit is contained in:
678
functions.php
678
functions.php
@@ -1,5 +1,6 @@
|
||||
<?php load_theme_textdomain('twentyten-child', get_template_directory() . '-child/languages'); ?>
|
||||
<?php
|
||||
// absent sur clicclac.info, présent en local
|
||||
$serial = "89f6e92540a8a80bd28cc2630c0ae022";
|
||||
update_option( 'wr2x_pro', array( 'subscr_id' => $serial ) );
|
||||
update_option( 'wr2x_pro_status', _( "Your subscription is manually enabled." ) );
|
||||
@@ -13,74 +14,164 @@ add_filter('sanitize_file_name', 'remove_accents' );
|
||||
add_filter( 'auto_update_plugin', '__return_true' );
|
||||
add_filter( 'auto_update_theme', '__return_true' );
|
||||
|
||||
// à l'initialisation de l'administration
|
||||
// on informe WordPress des options de notre thème
|
||||
|
||||
add_action( 'admin_init', 'myThemeRegisterSettings' );
|
||||
|
||||
function myThemeRegisterSettings( ) {
|
||||
register_setting( 'twentyten-child', 'zenphoto_url' ); // couleur de fond
|
||||
register_setting( 'twentyten-child', 'img_size' ); // couleur du texte
|
||||
register_setting( 'twentyten-child', 'guestbook_comment' ); // commentaires
|
||||
function google_jquery() {
|
||||
if (!is_admin()) {
|
||||
wp_deregister_script('jquery');
|
||||
//wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js', false, '3.1.1');
|
||||
wp_register_script('jquery', get_stylesheet_directory_uri() . '/js/jquery.min.js', false, '3.3.1');
|
||||
wp_enqueue_script('jquery');
|
||||
}
|
||||
}
|
||||
add_action('init', 'google_jquery');
|
||||
|
||||
// la fonction myThemeAdminMenu( ) sera exécutée
|
||||
// quand WordPress mettra en place le menu d'admin
|
||||
function enqueue_my_scripts() {
|
||||
//wp_enqueue_script('google-maps', '//maps.googleapis.com/maps/api/js?key=AIzaSyB7cAx3NSH4dPM3Sx2oQeud7Zr-KaGXmLk&callback=initMap', array(), '3', true);
|
||||
//wp_enqueue_script('google-maps', '//maps.googleapis.com/maps/api/js?key=AIzaSyB7cAx3NSH4dPM3Sx2oQeud7Zr-KaGXmLk&callback=MapApiLoaded', array(), '3', true);
|
||||
//wp_enqueue_script('google-jsapi','https://www.google.com/jsapi');
|
||||
|
||||
add_action( 'admin_menu', 'myThemeAdminMenu' );
|
||||
wp_enqueue_script( 'child', get_stylesheet_directory_uri() . '/js/child.js', '', '',false );
|
||||
}
|
||||
add_action( 'wp_enqueue_scripts', 'enqueue_my_scripts' );
|
||||
|
||||
function myThemeAdminMenu( ) {
|
||||
add_menu_page(
|
||||
'Options de Twentyten Child', // le titre de la page
|
||||
'Twentyten Child', // le nom de la page dans le menu d'admin
|
||||
'administrator', // le rôle d'utilisateur requis pour voir cette page
|
||||
'my-theme-page', // un identifiant unique de la page
|
||||
'myThemeSettingsPage' // le nom d'une fonction qui affichera la page
|
||||
// Settings
|
||||
|
||||
//http://cssmary.com/wordpress/customizer-api-child-theme/
|
||||
function childtheme_customize_register( $wp_customize ) {
|
||||
|
||||
// add settings
|
||||
$add_socials = array('500px','flickr','rss','mail');
|
||||
for($i=0;$i<count($add_socials);$i++) {
|
||||
$name = str_replace('-',' ',ucfirst($add_socials[$i]));
|
||||
$wp_customize->add_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','twentyten-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 (end with /)','twentyten-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)','twentyten-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)','twentyten-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")','twentyten-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','twentyten-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','twentyten-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','twentyten-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)','twentyten-child'),
|
||||
'section' => 'settings_section',
|
||||
'type' => 'checkbox',
|
||||
) );
|
||||
|
||||
}
|
||||
add_action( 'customize_register', 'childtheme_customize_register', 12);
|
||||
|
||||
function theme_setting($name, $default = false) {
|
||||
return get_theme_mod( $name, $default );
|
||||
}
|
||||
|
||||
|
||||
// La page des settings
|
||||
|
||||
function myThemeSettingsPage( ) {
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h2>Options de mon thème</h2>
|
||||
|
||||
<form method="post" action="options.php">
|
||||
<?php
|
||||
// cette fonction ajoute plusieurs champs cachés au formulaire
|
||||
// pour vous faciliter le travail.
|
||||
// elle prend en paramètre le nom du groupe d'options
|
||||
// que nous avons défini plus haut.
|
||||
|
||||
settings_fields( 'twentyten-child' );
|
||||
?>
|
||||
|
||||
<table class="form-table">
|
||||
<tr valign="top">
|
||||
<th scope="row"><label for="zenphoto_url">URL de Zenphoto</label></th>
|
||||
<td><input type="text" id="zenphoto_url" name="zenphoto_url" size="30" value="<?php echo get_option( 'zenphoto_url' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr valign="top">
|
||||
<th scope="row"><label for="img_size">Taille des images</label></th>
|
||||
<td><input type="text" id="img_size" name="img_size" class="small-text" value="<?php echo get_option( 'img_size' ); ?>" /></td>
|
||||
</tr>
|
||||
|
||||
<tr valign="top">
|
||||
<th scope="row"><label for="guestbook_comment">Répondre aux commentaires du livre d'or</label></th>
|
||||
<td><input type="checkbox" id="guestbook_comment" name="guestbook_comment" value="1" <?php checked( '1', get_option( 'guestbook_comment' ) ); ?> /> <?php echo get_option( 'guestbook_comment' ); ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p class="submit">
|
||||
<input type="submit" class="button-primary" value="Mettre à jour" />
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
function dess_sanitize_html($value){
|
||||
return wp_filter_post_kses($value);
|
||||
}
|
||||
function dess_sanitize_text($value){
|
||||
return sanitize_text_field($value);
|
||||
}
|
||||
function dess_sanitize_url($value) {
|
||||
return esc_url_raw($value);
|
||||
}
|
||||
|
||||
|
||||
/* Affichage des array() */
|
||||
|
||||
@@ -120,45 +211,142 @@ function register_buttons($buttons){
|
||||
function zenphoto_handler($atts, $content=null) {
|
||||
|
||||
//utilise le cacheManager de zenphoto (extensions/utilitaires/cacheManager)
|
||||
//utilisation: [zenphoto album="lievres" image="2008-08-18_Lievre_8927.jpg"]
|
||||
// [zenphoto album="sports-mecaniques/gp-france" image="2010-05-23_gp-france-2010_5321.jpg"]
|
||||
// ** Utilisation **
|
||||
//
|
||||
// [zenphoto album="lievres" image="2008-08-18_Lievre_8927.jpg" folder="false"]
|
||||
// [zenphoto album="sports-mecaniques/gp-france" image="2010-05-23_gp-france-2010_5321.jpg" folder="false"]
|
||||
// Folder = false: liens vers l'image, affiche l'image
|
||||
// Folder = true: liens vers l'album, affiche l'image
|
||||
//
|
||||
// [zenphoto album="lievres"](3)
|
||||
// Liens vers album, affiche la 1ere image de l'album
|
||||
//
|
||||
//taille des photos dans Worpress, theme Twenty Ten Child : 610x406
|
||||
|
||||
/*
|
||||
print_r($atts);
|
||||
echo "<br />";
|
||||
*/
|
||||
/*
|
||||
Array (
|
||||
[album] => sports-mecaniques/24H-Mans-2016
|
||||
[image] => 2016-04-10_24H-Mans_9717.jpg
|
||||
[folder] => false
|
||||
)
|
||||
*/
|
||||
|
||||
$host = (($_SERVER['HTTPS'] != "") ? "https" : "http") . '://' . $_SERVER['HTTP_HOST'] . '/zenphoto/';
|
||||
$selector = theme_setting('dess_lightbox_select');
|
||||
$zenphoto_url = theme_setting('dess_zenphoto');
|
||||
$size = theme_setting('dess_zp_size');
|
||||
|
||||
$zenphoto_url2 = get_option( 'zenphoto_url' );
|
||||
//echo $zenphoto_url2 . "<br>";
|
||||
//preprint($zenphoto_url2);
|
||||
//echo substr_count($zenphoto_url2, "https");
|
||||
//echo $_SERVER['HTTPS'];
|
||||
$album = ! empty( $atts['album'] ) ? $atts['album'] : '';
|
||||
$album = filter_var($album, FILTER_SANITIZE_STRING);
|
||||
|
||||
if (substr_count($zenphoto_url2, "https") == 1) {
|
||||
//echo "toto";
|
||||
$zenphoto_url = (($_SERVER['HTTPS'] != "") ? substr_replace($zenphoto_url2, 'https', 0, 4) : $zenphoto_url2);
|
||||
}
|
||||
$zenphoto_url = $host;
|
||||
//echo $zenphoto_url;
|
||||
$image = ! empty( $atts['image'] ) ? $atts['image'] : '';
|
||||
$image = filter_var($image, FILTER_SANITIZE_STRING);
|
||||
|
||||
$size = get_option( 'img_size' );
|
||||
$folder = false;
|
||||
$caption = ! empty( $atts['caption'] ) ? $atts['caption'] : '';
|
||||
$caption = filter_var($caption, FILTER_SANITIZE_STRING);
|
||||
|
||||
$folder = ! empty( $atts['folder'] ) ? $atts['folder'] : '';
|
||||
$folder = filter_var($folder, FILTER_VALIDATE_BOOLEAN);
|
||||
|
||||
$rnd = rand (1000, 9999);
|
||||
|
||||
$filename = "";
|
||||
$zenphoto_img = "";
|
||||
//preprint($atts);
|
||||
$a = $atts['image'];
|
||||
$b = zp_query($a); // ligne 808
|
||||
|
||||
if (isset($atts['folder'])) {
|
||||
if ($atts['folder'] == "true") $folder = true;
|
||||
}
|
||||
|
||||
$img = substr($atts['image'], 0, strlen($atts['image']) - 4);
|
||||
//echo dirname(__FILE__);
|
||||
//echo __FILE__;
|
||||
|
||||
$filename = $zenphoto_url . 'cache/' . $atts['album'] . '/' . urlencode($img) . '_' . $size . '_watermark.jpg';
|
||||
$zp_size = getimagesize(htmlentities($filename));
|
||||
// require ($_SERVER["DOCUMENT_ROOT"]."/path/to/file.php");
|
||||
|
||||
//if ($folder == false) $zenphoto_link = '<a rel="lightbox" href="' . $zenphoto_url . 'albums/' . $atts['album'] . '/' . $atts['image'] . '">';
|
||||
if ($folder == false) $zenphoto_link = '<a data-rel="lightbox-0" href="' . $zenphoto_url . 'albums/' . $atts['album'] . '/' . $atts['image'] . '">';
|
||||
else $zenphoto_link = '<a href="' . $zenphoto_url . $atts['album'] . '">';
|
||||
//require(dirname(__FILE__) . '/Connections/cnx.php');
|
||||
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());
|
||||
exit();
|
||||
}
|
||||
|
||||
// Trouver l'ID de l'album
|
||||
|
||||
$album_id_query = "SELECT `id` FROM `" . $zp_prefix . "albums` WHERE `folder` = '" . $album . "'";
|
||||
if ($result = $mysqli->query($album_id_query)) {
|
||||
if ($mysqli->affected_rows != 0) {
|
||||
$row = $result->fetch_row();
|
||||
$album_id = $row[0];
|
||||
}
|
||||
else {
|
||||
_e("Unknow album.", 'twentyten-child' );
|
||||
}
|
||||
$result->close();
|
||||
}
|
||||
|
||||
$img_query = "SELECT `desc`, `title`, `filename` FROM `" . $zp_prefix . "images` WHERE `albumid` = '" . $album_id . "'";
|
||||
if ($result = $mysqli->query($img_query)) {
|
||||
if ($mysqli->affected_rows != 0) {
|
||||
$capt = $result->fetch_row();
|
||||
}
|
||||
else {
|
||||
_e("Unknow image.", 'twentyten-child' );
|
||||
}
|
||||
$result->close();
|
||||
}
|
||||
|
||||
|
||||
//echo "image1: " . $image . "<br />";
|
||||
|
||||
|
||||
// (3) Si juste un album est donné, on cherche l'image la plus récente de l'album
|
||||
|
||||
if (($album != "") && ($image == "")) {
|
||||
|
||||
// Trouver le filename de la plus récente image de l'album
|
||||
|
||||
$img_album_query = "SELECT `filename` FROM `" . $zp_prefix . "images` WHERE `albumid` = '" . $album_id . "' ORDER BY `id` DESC LIMIT 1";
|
||||
if ($result = $mysqli->query($img_album_query)) {
|
||||
if ($mysqli->affected_rows != 0) {
|
||||
$row = $result->fetch_row();
|
||||
$img_album = $row[0];
|
||||
}
|
||||
else {
|
||||
_e("Unknow image.", 'twentyten-child' );
|
||||
}
|
||||
$result->close();
|
||||
}
|
||||
|
||||
echo "img_album: " . $img_album . "<br />";
|
||||
|
||||
$image = $img_album;
|
||||
$folder = true;
|
||||
} // album != ""
|
||||
|
||||
//echo "image2: " . $image . "<br />";
|
||||
|
||||
if ($capt[0] != "") $title = $capt[0];
|
||||
elseif ($capt[1] != "") $title = $capt[1];
|
||||
elseif ($capt[2] != "") $title = $capt[2];
|
||||
|
||||
$img = substr($image, 0, strlen($image) - 4);
|
||||
|
||||
//echo "img: " . $img . "<br />";
|
||||
|
||||
$filename = $zenphoto_url . 'cache/' . $atts['album'] . '/' . urlencode($img) . '_' . $size . '_watermark.jpg';
|
||||
|
||||
//echo "filename: " . $filename . "<br /><br />";
|
||||
|
||||
$zp_size = getimagesize(htmlentities($filename));
|
||||
|
||||
if ($folder === false) {
|
||||
$zenphoto_link = '<a data-rel="lightbox-0" href="' . $zenphoto_url . 'albums/' . $atts['album'] . '/' . $image . '">';
|
||||
}
|
||||
else {
|
||||
$zenphoto_link = '<a href="' . $zenphoto_url . $atts['album'] . '">';
|
||||
}
|
||||
|
||||
$zenphoto_img .= $zenphoto_link;
|
||||
$zenphoto_img .= '<picture data-picture data-alt="">
|
||||
<!--[if IE 9]><video style="display: none;"><![endif]-->
|
||||
@@ -185,6 +373,7 @@ function zenphoto_handler($atts, $content=null) {
|
||||
|
||||
add_shortcode( 'zenphoto', 'zenphoto_handler' );
|
||||
|
||||
// include
|
||||
|
||||
|
||||
/* NON UTILISE */
|
||||
@@ -835,6 +1024,7 @@ function zp_query($zpimage) {
|
||||
$exif = array();
|
||||
require('../Connections/cnx.php');
|
||||
|
||||
|
||||
$mysqli = new mysqli($dbhost, $dbuser, $dbpassword, $dbtable);
|
||||
|
||||
if (mysqli_connect_errno()) {
|
||||
@@ -1046,6 +1236,318 @@ function ListeExifZP($meta){
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* fmulticurl(): 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 fmulticurl($query) {
|
||||
|
||||
$url = "https://fr.wikipedia.org/w/api.php";
|
||||
$erreur = array();
|
||||
|
||||
/* contruction de la requete opensearch */
|
||||
|
||||
$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.'&';
|
||||
}
|
||||
|
||||
/* nettoyage expressions à rechercher */
|
||||
/*
|
||||
echo "requete avant clean_req_wiki<br>";
|
||||
var_dump($query);
|
||||
*/
|
||||
$wiki = clean_req_wiki($query);
|
||||
//$wiki = $query;
|
||||
|
||||
/*
|
||||
echo "requete apres clean_req_wiki<br>";
|
||||
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<br>";
|
||||
//var_dump($obj);
|
||||
|
||||
for ($a = 0; $a < count($obj); $a++){
|
||||
/*
|
||||
$req = str_replace("_", " ", $obj[$a][0]);
|
||||
$req = " " . $req . " ";
|
||||
*/
|
||||
$req = $query[$a];
|
||||
$req = " " . $req . " ";
|
||||
|
||||
/*
|
||||
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 "<b>matche $key</b>";
|
||||
//echo "nettoyage du retour de la requete<br>";
|
||||
$l = substr($val, 0, 50);
|
||||
|
||||
|
||||
//var_dump($req, $val, $l);
|
||||
|
||||
if (stripos(substr($val, 0, 50), $req) === false) {
|
||||
//echo "on supprime<br>";
|
||||
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<br>";
|
||||
//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) {
|
||||
$q = array();
|
||||
$pat = "#_([^)]*)_#";
|
||||
|
||||
foreach($req as $val) {
|
||||
|
||||
$z = strip_tags($val);
|
||||
/*
|
||||
$fichier = preg_match($pat, $z, $match1);
|
||||
if ($fichier === 1) $h = $match1[1];
|
||||
else $h = $z;
|
||||
*/
|
||||
|
||||
//$y= supp_article($z);
|
||||
$y= supprime_article($z);
|
||||
|
||||
$x = str_to_noaccent($y);
|
||||
|
||||
//$v = strtolower($w);
|
||||
|
||||
$v = str_replace(" ", "_", $x);
|
||||
|
||||
$q[] = trim($v);
|
||||
|
||||
}
|
||||
|
||||
return $q;
|
||||
}
|
||||
|
||||
|
||||
function clean_photo_name($str) {
|
||||
$pat = "#_([^)]*)_#";
|
||||
|
||||
$fichier = preg_match($pat, $str, $match1);
|
||||
if ($fichier === 1) $h = $match1[1];
|
||||
else $h = $z;
|
||||
|
||||
return $h;
|
||||
}
|
||||
|
||||
function supp_entre_parenth($str) {
|
||||
$pattern3 = "#\\([^)]*\\)#";
|
||||
|
||||
$m = preg_replace($pattern3, "", $str);
|
||||
return $m;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
return trim($l);
|
||||
|
||||
//$m = preg_replace($pattern3, "", $l);
|
||||
//return trim($m);
|
||||
}
|
||||
|
||||
/*
|
||||
add_filter('the_content', 'exif_content', 20);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user