1274 lines
53 KiB
PHP
1274 lines
53 KiB
PHP
<?php load_theme_textdomain('twentytwelve-child', get_template_directory() . '-child/languages'); ?>
|
|
<?php
|
|
/*
|
|
add_filter('the_content', 'exif_content', 20);
|
|
|
|
function exif_content($content) {
|
|
if ( is_single() )
|
|
$content = $content . "exif";
|
|
return $content;
|
|
}
|
|
*/
|
|
|
|
/*** ***/
|
|
|
|
add_filter('the_content', 'ajoute_class_lightbox', 99);
|
|
|
|
function ajoute_class_lightbox($content) {
|
|
if(get_option('add_lightbox') == 1){
|
|
global $post;
|
|
$id = isset($post->ID) ? $post->ID : -1;
|
|
|
|
if (is_home || is_single || !is_page) {
|
|
$content = dom_swipebox($content, $id);
|
|
//$content = dom_swipebox_2($content, $id);
|
|
}
|
|
}
|
|
return $content;
|
|
}
|
|
|
|
/* automatically insert rel="lightbox[nameofpost]" to every image with no manual work.
|
|
if there are already rel="lightbox[something]" attributes, they are not clobbered.
|
|
Michael Tyson, you are a regular expressions god! - http://atastypixel.com
|
|
function jqlb_do_regexp($content, $id){
|
|
$id = esc_attr($id);
|
|
$pattern = "/(<a(?![^>]*?rel=['\"]lightbox.*)[^>]*?href=['\"][^'\"]+?\.(?:bmp|gif|jpg|jpeg|png)(\?\S{0,}){0,1}['\"][^\>]*)>/i";
|
|
$replacement = '$1 rel="lightbox['.$id.']">';
|
|
|
|
return preg_replace($pattern, $replacement, $content);
|
|
}
|
|
*/
|
|
/*** ***/
|
|
|
|
function dom_swipebox_2($content, $id) {
|
|
$id = esc_attr($id);
|
|
// Nom du script JS de lightbox
|
|
$lightbox = 'swipebox';
|
|
|
|
$content = mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8");
|
|
$html = new DOMDocument();
|
|
$html->loadHTML($content);
|
|
|
|
|
|
$root = $html->documentElement; // get the first child node (the root)
|
|
$elms = $root->getElementsByTagName("*"); // gets all elements ("*") in root
|
|
$nr_elms = $elms->length; // gets the number of elements
|
|
|
|
// loop through all elements stored in $elms
|
|
for($i = 0; $i<$nr_elms; $i++) {
|
|
$node = $elms->item($i); // gets the current node
|
|
|
|
// on recherche les liens <a href="" class="" ref=""><img src="" class=""></a>
|
|
if($node->nodeName=='a') {
|
|
$old_node = $node;
|
|
|
|
// on teste si le lien n'appartient pas à une gallery
|
|
$parent = $node->parentNode;
|
|
if ($parent->nodeName != 'dt') {
|
|
$enfants = $node->childNodes;
|
|
foreach($enfants as $enfant) {
|
|
//uniquement les liens images <a href="" class="" ref=""><img src="" class=""></a>
|
|
//et pas les liens textex <a href="" class="" ref="">bla-bla</a>
|
|
if ($enfant->nodeName == 'img') {
|
|
//On récupère l'attribut 'class' et on ajoute swipebox à sa valeur
|
|
$oldClass = $node->getAttribute('class');
|
|
if (strstr($oldClass, $lightbox) != false) $newClass = $oldClass;
|
|
else $newClass = $oldClass . ' ' . $lightbox;
|
|
$node->setAttribute('class', $newClass);
|
|
|
|
//Chaque article à sa gallery
|
|
$newRel = 'gallery-' . $id;
|
|
$node->setAttribute('rel', $newRel);
|
|
//
|
|
|
|
}
|
|
}
|
|
}
|
|
/*
|
|
else {
|
|
echo $old_node->nodeValue;
|
|
}
|
|
*/
|
|
}
|
|
}
|
|
|
|
// save the new xml content in the same file and output its structure
|
|
$newHtml = preg_replace('/^<!DOCTYPE.+?>/', '', str_replace( array('<html>', '</html>', '<body>', '</body>'), array('', '', '', ''), $html->saveHTML()));
|
|
return $newHtml;
|
|
}
|
|
|
|
/*** ***/
|
|
|
|
function dom_swipebox($content, $id) {
|
|
$id = esc_attr($id);
|
|
// Nom du script JS de lightbox
|
|
$lightbox = 'swipebox';
|
|
|
|
$content = mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8");
|
|
|
|
$html = new DOMDocument();
|
|
|
|
libxml_use_internal_errors(true);
|
|
if (strlen($content) > 1) $html->loadHTML($content);
|
|
// Autre solution: if (strlen($content) > 1) @$html->loadHTML($content);
|
|
|
|
// contact
|
|
else return $content;
|
|
// liens
|
|
|
|
//print_r($html);
|
|
|
|
// On récupère tous les nodes 'liens' <a xxx></a>
|
|
$links = $html->getElementsByTagName('a');
|
|
|
|
foreach ($links as $link) {
|
|
|
|
$parents = $link->parentNode;
|
|
foreach($parents as $parent) {
|
|
echo $parent->nodeName;
|
|
}
|
|
|
|
$enfants = $link->childNodes;
|
|
foreach($enfants as $enfant) {
|
|
// On se s'occupe uniquement que liens image
|
|
if ($enfant->nodeName == 'img') {
|
|
//On récupère l'attribut 'class' et on ajoute swipebox à sa valeur
|
|
$oldClass = $link->getAttribute('class');
|
|
if (strstr($oldClass, $lightbox) != false) $newClass = $oldClass;
|
|
else $newClass = $oldClass . ' ' . $lightbox;
|
|
$link->setAttribute('class', $newClass);
|
|
|
|
//Chaque article à sa gallery
|
|
$newRel = 'gallery-' . $id;
|
|
$link->setAttribute('rel', $newRel);
|
|
//
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
$newHtml = preg_replace('/^<!DOCTYPE.+?>/', '', str_replace( array('<html>', '</html>', '<body>', '</body>'), array('', '', '', ''), $html->saveHTML()));
|
|
return $newHtml;
|
|
}
|
|
|
|
|
|
/** Enleve les width et height attributes**/
|
|
//add_filter( 'post_thumbnail_html', 'remove_thumbnail_dimensions', 10 );
|
|
//add_filter( 'image_send_to_editor', 'remove_thumbnail_dimensions', 10 );
|
|
//function remove_thumbnail_dimensions( $html ) { $html = preg_replace( '/(width|height)=\"\d*\"\s/', "", $html ); return $html; }
|
|
/** /Enleve les width et height attributes**/
|
|
|
|
|
|
|
|
/*** Ajout d'un bouton ZP dans l'éditeur visuel (tinymce) ***/
|
|
|
|
add_action('init','add_buttons');
|
|
function add_buttons(){
|
|
if(current_user_can('edit_posts') && current_user_can('edit_pages')){
|
|
add_filter('mce_external_plugins','add_plugins');
|
|
add_filter('mce_buttons','register_buttons');
|
|
}
|
|
}
|
|
|
|
function add_plugins($plugins){
|
|
$plugins['zp'] = get_bloginfo('stylesheet_directory').'/js/zenphoto.js';
|
|
return $plugins;
|
|
}
|
|
function register_buttons($buttons){
|
|
array_push($buttons, 'zp');
|
|
return $buttons;
|
|
}
|
|
/*** /ajout bouton ZP dans l'editeur ***/
|
|
|
|
|
|
add_theme_support( 'post-thumbnails' );
|
|
add_image_size( 'similar-thumbnail', 120, 80, true );
|
|
function my_theme_setup() {
|
|
// adding a new image size
|
|
add_image_size( 'slider-thumbnail', 1200, '', true );
|
|
//add_image_size( 'similar-thumbnail', 120, 80, true );
|
|
}
|
|
|
|
/*** Register footer widgets ***/
|
|
|
|
register_sidebar( array(
|
|
'name' => __( 'Footer Widget One', 'tto' ),
|
|
'id' => 'sidebar-4',
|
|
'description' => __( 'Found at the bottom of every page (except 404s, optional homepage and full width) as the footer. Left Side.', 'tto' ),
|
|
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
|
|
'after_widget' => '</aside>',
|
|
'before_title' => '<h3 class="widget-title">',
|
|
'after_title' => '</h3>',
|
|
) );
|
|
|
|
register_sidebar( array(
|
|
'name' => __( 'Footer Widget Two', 'tto' ),
|
|
'id' => 'sidebar-5',
|
|
'description' => __( 'Found at the bottom of every page (except 404s, optional homepage and full width) as the footer. Center.', 'tto' ),
|
|
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
|
|
'after_widget' => "</aside>",
|
|
'before_title' => '<h3 class="widget-title">',
|
|
'after_title' => '</h3>',
|
|
) );
|
|
|
|
register_sidebar( array(
|
|
'name' => __( 'Footer Widget Three', 'tto' ),
|
|
'id' => 'sidebar-6',
|
|
'description' => __( 'Found at the bottom of every page (except 404s, optional homepage and full width) as the footer. Right Side.', 'tto' ),
|
|
'before_widget' => '<aside id="%1$s" class="widget %2$s">',
|
|
'after_widget' => "</aside>",
|
|
'before_title' => '<h3 class="widget-title">',
|
|
'after_title' => '</h3>',
|
|
) );
|
|
|
|
/*** /Register footer widgets ***/
|
|
|
|
/*** Supprime les fontes Google ***/
|
|
|
|
function twtwFFWD_queuing() {
|
|
wp_dequeue_style( 'twentytwelve-fonts' );
|
|
}
|
|
add_action('wp_enqueue_scripts', 'twtwFFWD_queuing', 11 );
|
|
|
|
|
|
/*** Page d'options (administration) ***/
|
|
|
|
// à l'initialisation de l'administration
|
|
// on informe WordPress des options de notre thème
|
|
|
|
add_action( 'admin_init', 'myThemeRegisterSettings' );
|
|
|
|
function myThemeRegisterSettings( ) {
|
|
register_setting( 'twentytwelve-child', 'zenphoto_url' ); // url de zenphoto
|
|
register_setting( 'twentytwelve-child', 'img_size' ); // taille des images
|
|
register_setting( 'twentytwelve-child', 'display_comment' ); // afficher les comentaires
|
|
register_setting( 'twentytwelve-child', 'description' ); // description auteur
|
|
register_setting( 'twentytwelve-child', 'similar' ); // articles similaires
|
|
register_setting( 'twentytwelve-child', 'add_lightbox' ); // ajoute la class swipebox
|
|
}
|
|
|
|
// la fonction myThemeAdminMenu( ) sera exécutée
|
|
// quand WordPress mettra en place le menu d'admin
|
|
|
|
add_action( 'admin_menu', 'myThemeAdminMenu' );
|
|
|
|
function myThemeAdminMenu( ) {
|
|
add_menu_page(
|
|
__('Twentytwelve Child options', 'twentytwelve-child' ), // le titre de la page Options de twentytwelve Child
|
|
'twentytwelve 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
|
|
);
|
|
}
|
|
|
|
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( 'twentytwelve-child' );
|
|
|
|
// URL de Zenphoto, Taille des images, Afficher les commentaires, Afficher la description de l\'auteur, Afficher les articles similaires
|
|
?>
|
|
|
|
<table class="form-table">
|
|
<tr valign="top">
|
|
<th scope="row"><label for="zenphoto_url"><?php _e('Zenphoto\'s URL', 'twentytwelve-child' ); ?></label></th>
|
|
<td><input type="text" id="zenphoto_url" name="zenphoto_url" value="<?php echo get_option( 'zenphoto_url' ); ?>" /></td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<th scope="row"><label for="img_size"><?php _e('Images size', 'twentytwelve-child' ); ?></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="display_comment"><?php _e('Display comments', 'twentytwelve-child' ); ?></label></th>
|
|
<td><input type="checkbox" id="display_comment" name="display_comment" value="1" <?php checked('1',get_option('display_comment')); ?> /></td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<th scope="row"><label for="description"><?php _e('Display author', 'twentytwelve-child' ); ?></label></th>
|
|
<td><input type="checkbox" id="description" name="description" value="1" <?php checked('1',get_option('description')); ?> /></td>
|
|
</tr>
|
|
<tr valign="top">
|
|
<th scope="row"><label for="similar"><?php _e('Display similar', 'twentytwelve-child' ); ?></label></th>
|
|
<td><input type="checkbox" id="similar" name="similar" value="1" <?php checked('1',get_option('similar')); ?> /></td>
|
|
</tr>
|
|
<tr valign="top">
|
|
<th scope="row"><label for="add_lightbox"><?php _e('Add lightbox\'s class', 'twentytwelve-child' ); ?></label></th>
|
|
<td><input type="checkbox" id="add_lightbox" name="add_lightbox" value="1" <?php checked('1',get_option('add_lightbox')); ?> /></td>
|
|
</tr>
|
|
|
|
</table>
|
|
<p class="submit">
|
|
<input type="submit" class="button-primary" value="Mettre à jour" />
|
|
</p>
|
|
</form>
|
|
</div>
|
|
<?php
|
|
}
|
|
|
|
/*** /Page d'options (administration) ***/
|
|
|
|
function touch_navigation_js() {
|
|
/* Register our script. */
|
|
//wp_register_script( 'touch_navigation', plugins_url('/jquery.touchwipe.min.js', __FILE__) );
|
|
wp_register_script( 'touch_navigation', get_bloginfo('stylesheet_directory') . '/js/jquery.touchwipe.min.js' );
|
|
|
|
if ( is_single() ) {
|
|
wp_enqueue_script(
|
|
'touch_navigation',
|
|
//plugins_url('/jquery.touchwipe.min.js', __FILE__),
|
|
get_bloginfo('stylesheet_directory') . '/js/jquery.touchwipe.min.js',
|
|
array('jquery'),
|
|
false,
|
|
true
|
|
);
|
|
}
|
|
}
|
|
|
|
function touch_navigation(){
|
|
/* only single post */
|
|
if (! is_single() )
|
|
return;
|
|
?>
|
|
<script type="text/javascript">
|
|
jQuery(document).ready(function() {
|
|
jQuery("body.single").swipe({
|
|
swipeRight:function() {
|
|
window.open( jQuery('a[rel="prev"]').attr("href"), "_self" );
|
|
return false;
|
|
},
|
|
swipeLeft:function() {
|
|
window.open( jQuery('a[rel="next"]').attr("href"), "_self" );
|
|
return false;
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
<?php
|
|
}
|
|
add_action('wp_footer', 'touch_navigation');
|
|
add_action('wp_enqueue_scripts', 'touch_navigation_js');
|
|
|
|
/***
|
|
Shortcode zenphoto
|
|
***/
|
|
|
|
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"]
|
|
//taille des photos dans Worpress, theme Twenty Ten Child : 610x406
|
|
|
|
//$zenphoto_url = "http://alubook.local/zenphoto/";
|
|
$zenphoto_url = get_option( 'zenphoto_url' );
|
|
//$size = 610;
|
|
$size = get_option( 'img_size' );
|
|
|
|
/*
|
|
<div class="wp-caption aligncenter" style="width: 620px">
|
|
|
|
<a href="http://clicclac.info/zenphoto/albums/oiseaux/heron-pourpre/2013-05-28_HeronPourpre_9795.jpg">
|
|
<img src="http://clicclac.info/zenphoto/cache/oiseaux/heron-pourpre/2013-05-28_HeronPourpre_9795_660_watermark.jpg">
|
|
</a>
|
|
|
|
<p class="wp-caption-text">T'approches pas de mon nid !!</p></div>
|
|
*/
|
|
|
|
$img = substr($atts['image'], 0, strlen($atts['image']) - 4);
|
|
|
|
if ($atts['caption'] != "") {
|
|
$zenphoto_img = '<div class="wp-caption aligncenter" style="width: 620px">';
|
|
}
|
|
//$zenphoto_img .= '<a href="' . $zenphoto_url . 'albums/' . $atts['album'] . '/' . $atts['image'] . '">';
|
|
$zenphoto_img .= '<a href="' . $zenphoto_url . 'cache/' . $atts['album'] . '/' . $img . '_FULL_watermark.jpg">';
|
|
|
|
//$zenphoto_img .= '<img src="' . $zenphoto_url . 'cache/' . $atts['album'] . '/' . substr($atts['image'], 0, strlen($atts['image']) - 4) . '_' . $size . '_watermark.jpg" title="" alt="" class="aligncenter">';
|
|
$zenphoto_img .= '<img src="' . $zenphoto_url . 'cache/' . $atts['album'] . '/' . $img . '_' . $size . '_watermark.jpg" title="' . $img . '" alt="' . $img . '" class="aligncenter">';
|
|
$zenphoto_img .= '</a>';
|
|
if ($atts['caption'] != "") {
|
|
|
|
$zenphoto_img .= '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
|
|
}
|
|
|
|
return $zenphoto_img;
|
|
}
|
|
|
|
add_shortcode( 'zenphoto', 'zenphoto_handler' );
|
|
|
|
function zenphoto_full_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"]
|
|
//taille des photos dans Worpress, theme Twenty Ten Child : 610x406
|
|
|
|
//$zenphoto_url = "http://alubook.local/zenphoto/";
|
|
$zenphoto_url = get_option( 'zenphoto_url' );
|
|
//$size = 610;
|
|
$size = get_option( 'img_size' );
|
|
|
|
/*
|
|
<div class="wp-caption aligncenter" style="width: 620px">
|
|
|
|
<a href="http://clicclac.info/zenphoto/albums/oiseaux/heron-pourpre/2013-05-28_HeronPourpre_9795.jpg">
|
|
<img src="http://clicclac.info/zenphoto/cache/oiseaux/heron-pourpre/2013-05-28_HeronPourpre_9795_660_watermark.jpg">
|
|
</a>
|
|
|
|
<p class="wp-caption-text">T'approches pas de mon nid !!</p></div>
|
|
*/
|
|
|
|
$img = substr($atts['image'], 0, strlen($atts['image']) - 4);
|
|
|
|
if ($atts['caption'] != "") {
|
|
$zenphoto_img = '<div class="wp-caption aligncenter" style="width: 620px">';
|
|
}
|
|
//$zenphoto_img .= '<a href="' . $zenphoto_url . 'albums/' . $atts['album'] . '/' . $atts['image'] . '">';
|
|
$zenphoto_img .= '<a href="' . $zenphoto_url . 'cache/' . $atts['album'] . '/' . $img . '_FULL_watermark.jpg">';
|
|
|
|
//$zenphoto_img .= '<img src="' . $zenphoto_url . 'cache/' . $atts['album'] . '/' . substr($atts['image'], 0, strlen($atts['image']) - 4) . '_' . $size . '_watermark.jpg" title="" alt="" class="aligncenter">';
|
|
$zenphoto_img .= '<img src="' . $zenphoto_url . 'cache/' . $atts['album'] . '/' . $img . '_FULL_watermark.jpg" title="' . $img . '" alt="' . $img . '" class="aligncenter">';
|
|
$zenphoto_img .= '</a>';
|
|
if ($atts['caption'] != "") {
|
|
|
|
$zenphoto_img .= '<p class="wp-caption-text">' . $atts['caption'] . '</p></div>';
|
|
}
|
|
|
|
return $zenphoto_img;
|
|
}
|
|
|
|
add_shortcode( 'zenphoto_full', 'zenphoto_full_handler' );
|
|
/*** /Shortcode zenphoto ***/
|
|
|
|
|
|
/***
|
|
SEO
|
|
***/
|
|
|
|
function meta_box_title_description() {
|
|
add_meta_box( 'parametres_seo_metabox', 'Paramètres SEO', 'parametres_seo_metabox_content', 'post', 'side', 'high' );
|
|
add_meta_box( 'parametres_seo_metabox', 'Paramètres SEO', 'parametres_seo_metabox_content', 'page', 'side', 'high' );
|
|
}
|
|
add_action( 'add_meta_boxes', 'meta_box_title_description' );
|
|
|
|
|
|
function parametres_seo_metabox_content($post) {
|
|
$val_title = get_post_meta($post->ID,'_parametres_seo_title',true);
|
|
$val_description = get_post_meta($post->ID,'_parametres_seo_description',true);
|
|
?>
|
|
<p><strong>Title</strong></p>
|
|
<input id="parametres_seo_title" name="parametres_seo_title" type="text" style="width:100%;" value="<?php echo $val_title; ?>" />
|
|
<p><strong>Meta description</strong></p>
|
|
<textarea id="parametres_seo_description" name="parametres_seo_description" style="width:100%; resize:none;"><?php echo $val_description; ?></textarea>
|
|
<?php
|
|
}
|
|
|
|
function save_parametres_seo_metabox($post_ID){
|
|
if(isset($_POST['parametres_seo_title'])){
|
|
update_post_meta($post_ID,'_parametres_seo_title', esc_html($_POST['parametres_seo_title']));
|
|
}
|
|
if(isset($_POST['parametres_seo_description'])){
|
|
update_post_meta($post_ID,'_parametres_seo_description', esc_html($_POST['parametres_seo_description']));
|
|
}
|
|
}
|
|
add_action('save_post','save_parametres_seo_metabox');
|
|
|
|
function modify_description_from_metabox() {
|
|
global $wp_query;
|
|
if ( get_post_meta($wp_query->post->ID,'_parametres_seo_description',true) ) {
|
|
echo '<meta name="description" content="';
|
|
echo get_post_meta($wp_query->post->ID,'_parametres_seo_description',true);
|
|
echo '" />';
|
|
}
|
|
}
|
|
add_action( 'wp_head', 'modify_description_from_metabox' );
|
|
|
|
function modify_title_from_metabox($title) {
|
|
global $wp_query;
|
|
if ( get_post_meta($wp_query->post->ID,'_parametres_seo_title',true) ) {
|
|
return get_post_meta($wp_query->post->ID,'_parametres_seo_title',true);
|
|
} else {
|
|
return $title;
|
|
}
|
|
}
|
|
add_filter( 'wp_title', 'modify_title_from_metabox' );
|
|
|
|
/*** /SEO ***/
|
|
|
|
|
|
/***
|
|
Fil d'arianne
|
|
***/
|
|
|
|
//Récupérer les catégories parentes
|
|
function myget_category_parents($id, $link = false,$separator ='/',$nicename = false,$visited = array()) {
|
|
$chain = '';$parent = &get_category($id);
|
|
if (is_wp_error($parent))return $parent;
|
|
if ($nicename)$name = $parent->name;
|
|
else $name = $parent->cat_name;
|
|
if ($parent->parent && ($parent->parent != $parent->term_id ) &&!in_array($parent->parent, $visited)) {
|
|
$visited[] = $parent->parent;$chain .= myget_category_parents($parent->parent, $link, $separator, $nicename, $visited );}
|
|
if ($link) $chain .= '<span typeof="v:Breadcrumb"><a href="' .get_category_link( $parent->term_id ) . '" title="' . __('View all post from ', 'twentytwelve-child' ).$parent->cat_name.'" rel="v:url" property="v:title">'.$name.'</a></span>' . $separator;
|
|
else $chain .= $name.$separator;
|
|
return $chain;
|
|
}
|
|
|
|
//Le rendu
|
|
function mybread() {
|
|
// variables gloables
|
|
global $wp_query;$ped=get_query_var('paged');$rendu = '<div id="mybread" xmlns:v="http://rdf.data-vocabulary.org/#">';
|
|
//$debutlien = '<span id="breadex">Vous êtes ici :</span> <span typeof="v:Breadcrumb"><a title="'. get_bloginfo('name') .'" id="breadh" href="'.home_url().'" rel="v:url" property="v:title">'.get_bloginfo('name') .'</a></span>';
|
|
$debutlien = '<span id="breadex">' . __('You are here', 'twentytwelve-child' ) . ' :</span> <span typeof="v:Breadcrumb"><a title="'. get_bloginfo('name') .'" id="breadh" href="'.home_url().'" rel="v:url" property="v:title">'.get_bloginfo('name') .'</a></span>';
|
|
//$debut = '<span id="breadex">Vous êtes ici :</span> <span typeof="v:Breadcrumb">Accueil de '. get_bloginfo('name') .'</span>';
|
|
$debut = '<span id="breadex">' . __('You are here', 'twentytwelve-child' ) . ' :</span> <span typeof="v:Breadcrumb">Accueil de '. get_bloginfo('name') .'</span>';
|
|
|
|
// si l'utilisateur a défini une page comme page d'accueil
|
|
if ( is_front_page() ) {$rendu .= $debut;}
|
|
|
|
// dans le cas contraire
|
|
else {
|
|
|
|
// on teste si une page a été définie comme devant afficher une liste d'article
|
|
if( get_option('show_on_front') == 'page') {
|
|
$url = urldecode(substr($_SERVER['REQUEST_URI'], 1));
|
|
$uri = $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
|
|
$posts_page_id = get_option( 'page_for_posts');
|
|
$posts_page_url = get_page_uri($posts_page_id);
|
|
$pos = strpos($uri,$posts_page_url);
|
|
if($pos !== false) {
|
|
//$rendu .= $debutlien.' » <span typeof="v:Breadcrumb">Les articles</span>';
|
|
$rendu .= $debutlien.' » <span typeof="v:Breadcrumb">' . __('Posts', 'twentytwelve-child' ) . '</span>';
|
|
}
|
|
else {$rendu .= $debutlien;}
|
|
}
|
|
|
|
//Si c'est l'accueil
|
|
elseif ( is_home()) {$rendu .= $debut;}
|
|
|
|
//pour tout le reste
|
|
else {$rendu .= $debutlien;}
|
|
|
|
// les catégories
|
|
if ( is_category() ) {
|
|
$cat_obj = $wp_query->get_queried_object();$thisCat = $cat_obj->term_id;$thisCat = get_category($thisCat);$parentCat =get_category($thisCat->parent);
|
|
if ($thisCat->parent != 0) $rendu .= " » ".myget_category_parents($parentCat, true, " » ", true);
|
|
if ($thisCat->parent == 0) $rendu .= " » ";
|
|
if ( $ped <= 1 ) {
|
|
//$rendu .= single_cat_title("", false);
|
|
$rendu .= __('Category', 'twentytwelve-child' ) . " » <b>" . single_cat_title("", false) . "</b>";
|
|
}
|
|
elseif ( $ped > 1 ) {
|
|
//$rendu .= '<span typeof="v:Breadcrumb"><a href="' .get_category_link( $thisCat ) . '" title="Voir tous les articles de '.single_cat_title("", false).'" rel="v:url" property="v:title">'.single_cat_title("", false).'</a></span>';
|
|
$rendu .= '<span typeof="v:Breadcrumb"><a href="' .get_category_link( $thisCat ) . '" title="' . __('View all post from ', 'twentytwelve-child' ).single_cat_title("", false).'" rel="v:url" property="v:title">'.single_cat_title("", false).'</a></span>';
|
|
}
|
|
}
|
|
|
|
// les auteurs
|
|
elseif ( is_author()){
|
|
//global $author;$user_info = get_userdata($author);$rendu .= " » Articles de l'auteur ".$user_info->display_name."</span>";}
|
|
global $author;$user_info = get_userdata($author);$rendu .= __(' » Articles de l\'auteur ', 'twentytwelve-child' )."<b>".$user_info->display_name."</b>";
|
|
}
|
|
|
|
// les mots clés
|
|
elseif ( is_tag()){
|
|
//$tag=single_tag_title("",FALSE);$rendu .= " » Articles sur le thème <span>".$tag."</span>";}
|
|
$tag=single_tag_title("",FALSE);$rendu .= __(' » Articles sur le thème <b>', 'twentytwelve-child' ).$tag."</b>";
|
|
}
|
|
elseif ( is_date() ) {
|
|
if ( is_day() ) {
|
|
global $wp_locale;
|
|
$rendu .= '<span typeof="v:Breadcrumb"><a href="'.get_month_link( get_query_var('year'),get_query_var('monthnum') ).'" rel="v:url" property="v:title">'.$wp_locale->get_month(get_query_var('monthnum') ).' '.get_query_var('year').'</a></span> ';
|
|
//$rendu .= " » Archives pour ".get_the_date();}
|
|
$rendu .= __(' » Archives for ', 'twentytwelve-child' ) . get_the_date();
|
|
}
|
|
else if ( is_month() ) {
|
|
//$rendu .= " » Archives pour ".single_month_title(' ',false);}
|
|
$rendu .= __(' » Archives for ', 'twentytwelve-child' ) . single_month_title(' ',false);
|
|
}
|
|
else if ( is_year() ) {
|
|
//$rendu .= " » Archives pour ".get_query_var('year');}}
|
|
$rendu .= __(' » Archives for ', 'twentytwelve-child' ) . get_query_var('year');
|
|
}
|
|
}
|
|
|
|
//les archives hors catégories
|
|
elseif ( is_archive() && !is_category()){
|
|
$posttype = get_post_type();
|
|
$tata = get_post_type_object( $posttype );
|
|
$var = '';
|
|
$the_tax = get_taxonomy( get_query_var( 'taxonomy' ) );
|
|
$titrearchive = $tata->labels->menu_name;
|
|
if (!empty($the_tax)) {
|
|
$var = $the_tax->labels->name.' ';
|
|
}
|
|
if (empty($the_tax))
|
|
{$var = $titrearchive;
|
|
}
|
|
//$rendu .= ' » Archives sur "'.$var.'"';}
|
|
$rendu .= __(' » Archives for "', 'twentytwelve-child' ) .$var.'"';
|
|
}
|
|
|
|
// La recherche
|
|
elseif ( is_search()) {
|
|
//$rendu .= " » Résultats de votre recherche <span>» ".get_search_query()."</span>";}
|
|
$rendu .= __(' » Search result <span>» ', 'twentytwelve-child' ) . get_search_query()."</span>";
|
|
}
|
|
|
|
// la page 404
|
|
elseif ( is_404()){
|
|
//$rendu .= " » 404 Page non trouvée";}
|
|
$rendu .= __(' » 404 Page not found', 'twentytwelve-child' );
|
|
}
|
|
|
|
//Un article
|
|
elseif ( is_single()){
|
|
$category = get_the_category();
|
|
$category_id = get_cat_ID( $category[0]->cat_name );
|
|
if ($category_id != 0) {
|
|
$rendu .= " » ".myget_category_parents($category_id,TRUE,' » ')."<span>".the_title('','',FALSE)."</span>";
|
|
}
|
|
elseif ($category_id == 0) {
|
|
$post_type = get_post_type();
|
|
$tata = get_post_type_object( $post_type );
|
|
$titrearchive = $tata->labels->menu_name;
|
|
$urlarchive = get_post_type_archive_link( $post_type );
|
|
$rendu .= ' » <span typeof="v:Breadcrumb"><a href="'.$urlarchive.'" title="'.$titrearchive.'" rel="v:url" property="v:title">'.$titrearchive.'</a></span> » <span>'.the_title('','',FALSE).'</span>';
|
|
}
|
|
}
|
|
|
|
//Une page
|
|
elseif ( is_page()) {
|
|
$post = $wp_query->get_queried_object();
|
|
if ( $post->post_parent == 0 ) {
|
|
$rendu .= " » ".the_title('','',FALSE)."";
|
|
}
|
|
elseif ( $post->post_parent != 0 ) {
|
|
$title = the_title('','',FALSE);$ancestors =array_reverse(get_post_ancestors($post->ID));array_push($ancestors,$post->ID);
|
|
foreach ( $ancestors as $ancestor ) {
|
|
if( $ancestor != end($ancestors) ) {
|
|
$rendu .= '» <span typeof="v:Breadcrumb"><a href="'. get_permalink($ancestor) .'" rel="v:url" property="v:title">'. strip_tags( apply_filters('single_post_title', get_the_title( $ancestor ) ) ) .'</a></span>';
|
|
}
|
|
else {$rendu .= ' » '.strip_tags(apply_filters('single_post_title',get_the_title($ancestor))).'';
|
|
}}}}
|
|
if ( $ped >= 1 ) {
|
|
$rendu .= ' (Page '.$ped.')';
|
|
}
|
|
}
|
|
$rendu .= '</div>';
|
|
echo $rendu;
|
|
}
|
|
|
|
/*** /Fil d'arianne ***/
|
|
|
|
|
|
if ( ! function_exists( 'twentytwelve_entry_meta' ) ) :
|
|
/**
|
|
* Prints HTML with meta information for current post: categories, tags, permalink, author, and date.
|
|
*
|
|
* Create your own twentytwelve_entry_meta() to override in a child theme.
|
|
*
|
|
* @since Twenty Twelve 1.0
|
|
*/
|
|
function twentytwelve_entry_meta() {
|
|
// Translators: used between list items, there is a space after the comma.
|
|
$categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );
|
|
|
|
// Translators: used between list items, there is a space after the comma.
|
|
$tag_list = get_the_tag_list( '', __( ', ', 'twentytwelve' ) );
|
|
|
|
$date = sprintf( '<time class="entry-date" datetime="%3$s">%4$s</time>',
|
|
esc_url( get_permalink() ),
|
|
esc_attr( get_the_time() ),
|
|
esc_attr( get_the_date( 'c' ) ),
|
|
esc_html( get_the_date() )
|
|
);
|
|
|
|
$author = sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
|
|
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
|
|
esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ),
|
|
get_the_author()
|
|
);
|
|
|
|
// Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author's name.
|
|
if ( $tag_list ) {
|
|
$utility_text = __( 'This entry was posted in %1$s and tagged %2$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve-child' );
|
|
} elseif ( $categories_list ) {
|
|
$utility_text = __( 'This entry was posted in %1$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve-child' );
|
|
} else {
|
|
$utility_text = __( 'This entry was posted on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve-child' );
|
|
}
|
|
|
|
printf(
|
|
$utility_text,
|
|
$categories_list,
|
|
$tag_list,
|
|
$date,
|
|
$author
|
|
);
|
|
}
|
|
endif;
|
|
|
|
function date_auteur_meta() {
|
|
// Modif pour human_time_diff
|
|
|
|
$categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );
|
|
|
|
$date = sprintf( '<time class="entry-date" datetime="%1$s">%2$s</time>',
|
|
esc_attr( get_the_date( 'c' ) ),
|
|
//esc_html( get_the_date() )
|
|
esc_html( _human_time_diff( get_the_time('U'), current_time('timestamp') ) )
|
|
);
|
|
|
|
$author = sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
|
|
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
|
|
esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ),
|
|
get_the_author()
|
|
);
|
|
/*
|
|
if ( $categories_list ) {
|
|
$utility_text = __( 'On %2$s<span class="by-author"> by %3$s</span> - %1$s', 'twentytwelve-child' );
|
|
} else {
|
|
$utility_text = __( 'On %2$s<span class="by-author"> by %3$s</span>.', 'twentytwelve-child' );
|
|
}
|
|
*/
|
|
if ( $categories_list ) {
|
|
$utility_text = __( '%2$s<span class="by-author"> by %3$s</span> - %1$s', 'twentytwelve-child' );
|
|
} else {
|
|
$utility_text = __( '%2$s<span class="by-author"> by %3$s</span>.', 'twentytwelve-child' );
|
|
}
|
|
|
|
printf(
|
|
$utility_text,
|
|
$categories_list,
|
|
$date,
|
|
$author
|
|
);
|
|
}
|
|
|
|
function date_auteur_meta_post_format() {
|
|
|
|
$categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) );
|
|
|
|
$date = sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>',
|
|
esc_url( get_permalink() ),
|
|
esc_attr( get_the_time() ),
|
|
esc_attr( get_the_date( 'c' ) ),
|
|
esc_html( get_the_date() )
|
|
);
|
|
|
|
$author = sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>',
|
|
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
|
|
esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ),
|
|
get_the_author()
|
|
);
|
|
|
|
if ( $categories_list ) {
|
|
$utility_text = __( 'On %2$s<span class="by-author"> by %3$s</span> - %1$s', 'twentytwelve-child' );
|
|
} else {
|
|
$utility_text = __( 'On %2$s<span class="by-author"> by %3$s</span>.', 'twentytwelve-child' );
|
|
}
|
|
|
|
printf(
|
|
$utility_text,
|
|
$categories_list,
|
|
$date,
|
|
$author
|
|
);
|
|
}
|
|
|
|
/***
|
|
Limite la taille du résumé à x caractères
|
|
***/
|
|
|
|
function the_excerpt_max_charlength($charlength) {
|
|
$a = "";
|
|
$excerpt = get_the_excerpt();
|
|
$charlength++;
|
|
|
|
if ( mb_strlen( $excerpt ) > $charlength ) {
|
|
$subex = mb_substr( $excerpt, 0, $charlength - 5 );
|
|
$exwords = explode( ' ', $subex );
|
|
$excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
|
|
if ( $excut < 0 ) {
|
|
$a = mb_substr( $subex, 0, $excut );
|
|
} else {
|
|
$a = $subex;
|
|
}
|
|
$a = $a . '[...]';
|
|
} else {
|
|
$a = $excerpt;
|
|
}
|
|
return $a;
|
|
}
|
|
|
|
|
|
/***
|
|
Renvoie la date de la dernière modif de l'article
|
|
***/
|
|
|
|
function twentytwelve_post_updated() {
|
|
setlocale(LC_TIME, get_locale());
|
|
$u_time = get_the_time('U');
|
|
$u_modified_time = get_the_modified_time('U');
|
|
// '%e %B %Y @ %H:%M' => 14 août 2013 @ 14:09
|
|
// '%A, %B %e %Y @ %l:%M %p' => Wednesday, August 14 2013 @ 2:09 PM
|
|
if ($u_modified_time >= $u_time + 86400) {
|
|
?>
|
|
<svg version="1.1" width="20px" height="20px" viewBox="0 0 30 30">
|
|
<path d="M17.001,15.5l-0.5-7.876c0-0.552-0.448-1-1-1c-0.552,0-1,0.448-1,1l-0.466,7.343l-3.004,1.96c-0.478,0.277-0.642,0.89-0.365,1.365c0.275,0.479,0.889,0.644,1.365,0.367l3.305-1.677C15.39,16.99,15.444,17,15.501,17C16.329,17,17.001,16.329,17.001,15.5zM18.939,21.455c-0.479,0.277-0.644,0.889-0.366,1.367c0.274,0.477,0.888,0.643,1.366,0.365c0.478-0.275,0.642-0.89,0.365-1.365C20.027,21.344,19.417,21.18,18.939,21.455zM19.938,7.813c-0.477-0.276-1.09-0.111-1.364,0.366c-0.275,0.48-0.111,1.091,0.366,1.367c0.477,0.276,1.088,0.112,1.365-0.366C20.581,8.702,20.418,8.089,19.938,7.813zM21.823,20.305c0.477,0.274,1.089,0.112,1.364-0.365c0.276-0.479,0.112-1.092-0.364-1.367c-0.48-0.275-1.093-0.111-1.367,0.365C21.182,19.416,21.344,20.029,21.823,20.305zM22.822,12.428c0.478-0.275,0.643-0.888,0.365-1.366c-0.274-0.478-0.89-0.642-1.365-0.366c-0.479,0.278-0.643,0.89-0.366,1.367S22.344,12.705,22.822,12.428zM24.378,15.5c0-0.551-0.448-1-1-1c-0.554,0.002-1.001,0.45-1.001,1c0.001,0.552,0.448,1,1.001,1C23.93,16.5,24.378,16.053,24.378,15.5zM9.546,12.062c0.275-0.478,0.111-1.089-0.366-1.366c-0.479-0.276-1.09-0.112-1.366,0.366s-0.111,1.09,0.365,1.366C8.658,12.704,9.269,12.541,9.546,12.062zM6.624,15.5c0,0.553,0.449,1,1,1c0.552,0,1-0.447,1.001-1c-0.001-0.552-0.448-0.999-1.001-1C7.071,14.5,6.624,14.948,6.624,15.5zM9.179,20.305c0.479-0.275,0.643-0.888,0.367-1.367c-0.276-0.477-0.888-0.641-1.367-0.365c-0.478,0.277-0.642,0.889-0.365,1.367C8.089,20.418,8.703,20.58,9.179,20.305zM12.062,9.545c0.479-0.276,0.642-0.888,0.366-1.366c-0.276-0.478-0.888-0.642-1.366-0.366s-0.642,0.888-0.366,1.366C10.973,9.658,11.584,9.822,12.062,9.545zM14.501,23.377c0,0.553,0.448,1,1,1c0.552,0,1-0.447,1-1s-0.448-1-1-1C14.949,22.377,14.501,22.824,14.501,23.377zM10.696,21.822c-0.275,0.479-0.111,1.09,0.366,1.365c0.478,0.276,1.091,0.11,1.365-0.365c0.277-0.479,0.113-1.09-0.365-1.367C11.584,21.18,10.973,21.344,10.696,21.822zM28.674,14.087l-3.27-1.186c0.291,1.105,0.41,2.274,0.309,3.478c-0.492,5.639-5.449,9.809-11.091,9.333c-5.639-0.495-9.809-5.45-9.333-11.09c0.494-5.641,5.449-9.812,11.089-9.335c2.428,0.212,4.567,1.266,6.194,2.833l-1.637,1.377l7.031,2.548l-1.309-7.364l-1.771,1.492c-2.133-2.151-4.996-3.597-8.25-3.877C9.346,1.67,2.926,7.072,2.297,14.364c-0.625,7.291,4.777,13.71,12.066,14.339c7.293,0.625,13.713-4.776,14.342-12.066C28.779,15.771,28.762,14.919,28.674,14.087z" />
|
|
</svg>
|
|
<?php
|
|
/*printf( __( '<div class="maj"> Article updated the %1$s at %2$s </div>', 'twentytwelve-child'),
|
|
sprintf('%1$s', get_the_modified_time('j F Y')),
|
|
sprintf('%1$s', get_the_modified_time()) */
|
|
printf( __( 'Article updated the %1$s', 'twentytwelve-child'),
|
|
sprintf('%1$s', strftime( __('%A, %B %e %Y @ %l:%M %p', 'twentytwelve-child'), $u_modified_time))
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
/***
|
|
returns the name of one random file from within a directory
|
|
content-livre.php
|
|
***/
|
|
|
|
function getRandomFile($start_dir) {
|
|
chdir($start_dir);
|
|
$dir = opendir('.');
|
|
while (($myfile = readdir($dir)) !==false) {
|
|
if ($myfile != '.' && $myfile != '..' && is_file($myfile) && $myfile != 'resource.frk') $files[] = $myfile;
|
|
}
|
|
closedir($dir);
|
|
chdir('../');
|
|
srand ((float) microtime() * 10000000);
|
|
$file = array_rand($files);
|
|
return $files[$file];
|
|
}
|
|
|
|
/*** /returns the name of one random file from within a directory ***/
|
|
|
|
/***
|
|
Shortcode pour afficher la liste des liens
|
|
[show_bookmark_image_list]
|
|
***/
|
|
|
|
function show_bookmark_list(){ ?>
|
|
<ul>
|
|
<?php
|
|
$args = array(
|
|
'title_before' => '<h3>',
|
|
'title_after' => '</h3>',
|
|
);
|
|
wp_list_bookmarks( $args ); ?>
|
|
</ul>
|
|
<?php
|
|
}
|
|
add_shortcode('show_bookmark_list', 'show_bookmark_list');
|
|
|
|
|
|
/***
|
|
Shortcode
|
|
[show_bookmark_image_list catagory_name='photographes']
|
|
***/
|
|
|
|
function show_bookmark_image_list($atts){
|
|
extract(shortcode_atts(array( 'catagory_name' => false ), $atts));
|
|
|
|
$args = array(
|
|
'orderby' => 'name',
|
|
'order' => 'ASC',
|
|
'category_name' => $catagory_name
|
|
);
|
|
|
|
if ( $catagory_name == false )
|
|
$bookmarks = get_bookmarks();
|
|
else
|
|
$bookmarks = get_bookmarks($args);
|
|
|
|
ob_start();
|
|
echo "<ul class='link-image-list'>";
|
|
foreach($bookmarks as $bookmark) {
|
|
//echo "<li><a href='".esc_url($bookmark->link_url) ."'><img src='".esc_url($bookmark->link_image)."' /></a></li>";
|
|
echo "<li><a href='".esc_url($bookmark->link_url) ."'>".$bookmark->link_name."</a></li>";
|
|
}
|
|
echo "</ul>";
|
|
$list = ob_get_clean();
|
|
return $list;
|
|
}
|
|
add_shortcode('show_bookmark_image_list', 'show_bookmark_image_list');
|
|
//end show_bookmark_image_list
|
|
|
|
|
|
/* affiche la 1ere image d'un article
|
|
1. la post_thumbail (image à la une)
|
|
2. champ personnalisé (post custom)
|
|
3. 1ere image du content
|
|
4. image par défaut
|
|
*/
|
|
function first_image($article) {
|
|
$first_img = "";
|
|
$metas = get_post_custom($article);
|
|
|
|
if (has_post_thumbnail($article)) {
|
|
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', get_the_post_thumbnail( $article ), $matches);
|
|
$first_img = $matches [1] [0];
|
|
//echo $article . " -- " . $first_img . " hpt<br><br>";
|
|
}
|
|
elseif ( isset($metas['thumb_zenphoto'][0]) ) {
|
|
$first_img = $metas['thumb_zenphoto'][0];
|
|
// http://alubook.local/zenphoto/cache/gp-france-2010/2010-05-23_gp-france-2010_5327_610_watermark.jpg
|
|
//echo $article . " -- " . $first_img . " tz<br><br>";
|
|
}
|
|
else {
|
|
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', get_the_content($article), $matches);
|
|
$first_img = $matches [1] [0];
|
|
//echo $article . " -- " . $first_img . " preg<br><br>";
|
|
if(empty($first_img)) {
|
|
//$first_img = "http://alubook.local/wordpress/wp-content/themes/twentytwelve-child/images/ampoules.jpg";
|
|
$first_img = get_bloginfo('stylesheet_directory') . "/images/ampoules.jpg";
|
|
//echo $article . " -- " . $first_img . " ampoule<br><br>";
|
|
}
|
|
}
|
|
|
|
return $first_img;
|
|
}
|
|
|
|
if ( ! function_exists( 'twentytwelve_comment' ) ) :
|
|
/**
|
|
* Template for comments and pingbacks.
|
|
*
|
|
* To override this walker in a child theme without modifying the comments template
|
|
* simply create your own twentytwelve_comment(), and that function will be used instead.
|
|
*
|
|
* Used as a callback by wp_list_comments() for displaying the comments.
|
|
*
|
|
* @since Twenty Twelve 1.0
|
|
*/
|
|
function twentytwelve_comment( $comment, $args, $depth ) {
|
|
$GLOBALS['comment'] = $comment;
|
|
switch ( $comment->comment_type ) :
|
|
case 'pingback' :
|
|
case 'trackback' :
|
|
// Display trackbacks differently than normal comments.
|
|
?>
|
|
<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>">
|
|
<p><?php _e( 'Pingback:', 'twentytwelve' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?></p>
|
|
<?php
|
|
break;
|
|
default :
|
|
// Proceed with normal comments.
|
|
global $post;
|
|
?>
|
|
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>">
|
|
<article id="comment-<?php comment_ID(); ?>" class="comment">
|
|
<header class="comment-meta comment-author vcard">
|
|
<?php
|
|
echo get_avatar( $comment, 44 );
|
|
printf( '<cite><b class="fn">%1$s</b> %2$s</cite>',
|
|
get_comment_author_link(),
|
|
// If current post author is also comment author, make it known visually.
|
|
( $comment->user_id === $post->post_author ) ? '<span>' . __( 'Post author', 'twentytwelve' ) . '</span>' : ''
|
|
);
|
|
printf( '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>',
|
|
esc_url( get_comment_link( $comment->comment_ID ) ),
|
|
get_comment_time( 'c' ),
|
|
/* translators: 1: date, 2: time */
|
|
sprintf( __( '%1$s at %2$s', 'twentytwelve' ), get_comment_date(), get_comment_time() )
|
|
);
|
|
?>
|
|
</header><!-- .comment-meta -->
|
|
|
|
<?php if ( '0' == $comment->comment_approved ) : ?>
|
|
<p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentytwelve' ); ?></p>
|
|
<?php endif; ?>
|
|
|
|
<section class="comment-content comment">
|
|
<?php comment_text(); ?>
|
|
<?php //edit_comment_link( __( 'Edit', 'twentytwelve' ), '<p class="edit-link">', '</p>' ); ?>
|
|
</section><!-- .comment-content -->
|
|
|
|
<div class="reply">
|
|
<?php edit_comment_link( __( 'Edit', 'twentytwelve' ), '', '' ); ?>
|
|
<?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'twentytwelve' ), 'after' => ' <span>↓</span>', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
|
|
</div><!-- .reply -->
|
|
</article><!-- #comment-## -->
|
|
<?php
|
|
break;
|
|
endswitch; // end comment_type check
|
|
}
|
|
endif;
|
|
|
|
|
|
function comment_form_livredor( $args = array(), $post_id = null ) {
|
|
if ( null === $post_id )
|
|
$post_id = get_the_ID();
|
|
else
|
|
$id = $post_id;
|
|
|
|
$commenter = wp_get_current_commenter();
|
|
$user = wp_get_current_user();
|
|
$user_identity = $user->exists() ? $user->display_name : '';
|
|
|
|
if ( ! isset( $args['format'] ) )
|
|
$args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml';
|
|
|
|
$req = get_option( 'require_name_email' );
|
|
$aria_req = ( $req ? " aria-required='true'" : '' );
|
|
$html5 = 'html5' === $args['format'];
|
|
$fields = array(
|
|
'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
|
|
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
|
|
'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
|
|
'<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
|
|
'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' .
|
|
'<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
|
|
);
|
|
|
|
$required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' );
|
|
$defaults = array(
|
|
'fields' => apply_filters( 'comment_form_default_fields', $fields ),
|
|
'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
|
|
'must_log_in' => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
|
|
'logged_in_as' => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
|
|
'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '</p>',
|
|
'comment_notes_after' => '<p class="form-allowed-tags">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>',
|
|
'id_form' => 'commentform',
|
|
'id_submit' => 'submit',
|
|
'title_reply' => __( 'Leave a Reply' ),
|
|
'title_reply_to' => __( 'Leave a Reply to %s' ),
|
|
'cancel_reply_link' => __( 'Cancel reply' ),
|
|
'label_submit' => __( 'Post Comment' ),
|
|
'format' => 'xhtml',
|
|
);
|
|
|
|
$args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
|
|
|
|
?>
|
|
<?php if ( comments_open( $post_id ) ) : ?>
|
|
<?php do_action( 'comment_form_before' ); ?>
|
|
<div id="respond" class="comment-respond">
|
|
<h3 id="reply-title" class="comment-reply-title"><?php comment_form_title( $args['title_reply'], $args['title_reply_to'] ); ?> <small><?php cancel_comment_reply_link( $args['cancel_reply_link'] ); ?></small></h3>
|
|
<?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?>
|
|
<?php echo $args['must_log_in']; ?>
|
|
<?php do_action( 'comment_form_must_log_in_after' ); ?>
|
|
<?php else : ?>
|
|
<form action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="comment-form"<?php echo $html5 ? ' novalidate' : ''; ?>>
|
|
<?php do_action( 'comment_form_top' ); ?>
|
|
<?php if ( is_user_logged_in() ) : ?>
|
|
<?php echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); ?>
|
|
<?php do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); ?>
|
|
<?php else : ?>
|
|
<?php echo $args['comment_notes_before']; ?>
|
|
<?php
|
|
do_action( 'comment_form_before_fields' );
|
|
foreach ( (array) $args['fields'] as $name => $field ) {
|
|
echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
|
|
}
|
|
do_action( 'comment_form_after_fields' );
|
|
?>
|
|
<?php endif; ?>
|
|
<?php echo apply_filters( 'comment_form_field_comment', $args['comment_field'] ); ?>
|
|
<?php echo $args['comment_notes_after']; ?>
|
|
<p class="form-submit">
|
|
<input name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />
|
|
<?php comment_id_fields( $post_id ); ?>
|
|
</p>
|
|
<?php do_action( 'comment_form', $post_id ); ?>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div><!-- #respond -->
|
|
<?php do_action( 'comment_form_after' ); ?>
|
|
<?php else : ?>
|
|
<?php do_action( 'comment_form_comments_closed' ); ?>
|
|
<?php endif; ?>
|
|
<?php
|
|
}
|
|
|
|
|
|
/**
|
|
* Outputs a complete commenting form for use within a template.
|
|
* Most strings and form fields may be controlled through the $args array passed
|
|
* into the function, while you may also choose to use the comment_form_default_fields
|
|
* filter to modify the array of default fields if you'd just like to add a new
|
|
* one or remove a single field. All fields are also individually passed through
|
|
* a filter of the form comment_form_field_$name where $name is the key used
|
|
* in the array of fields.
|
|
*
|
|
* @since 3.0.0
|
|
* @param array $args Options for strings, fields etc in the form
|
|
* @param mixed $post_id Post ID to generate the form for, uses the current post if null
|
|
* @return void
|
|
*/
|
|
/* si aucun commentaire => requis pour masquer le formulaire */
|
|
|
|
function no_comment_form( $args = array(), $post_id = null ) {
|
|
if ( null === $post_id )
|
|
$post_id = get_the_ID();
|
|
else
|
|
$id = $post_id;
|
|
|
|
$commenter = wp_get_current_commenter();
|
|
$user = wp_get_current_user();
|
|
$user_identity = $user->exists() ? $user->display_name : '';
|
|
|
|
if ( ! isset( $args['format'] ) )
|
|
$args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml';
|
|
|
|
$req = get_option( 'require_name_email' );
|
|
$aria_req = ( $req ? " aria-required='true'" : '' );
|
|
$html5 = 'html5' === $args['format'];
|
|
$fields = array(
|
|
'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
|
|
'<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
|
|
'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
|
|
'<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
|
|
'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' .
|
|
'<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
|
|
);
|
|
|
|
$required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' );
|
|
$defaults = array(
|
|
'fields' => apply_filters( 'comment_form_default_fields', $fields ),
|
|
'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
|
|
'must_log_in' => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
|
|
'logged_in_as' => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), get_edit_user_link(), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
|
|
'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '</p>',
|
|
'comment_notes_after' => '<p class="form-allowed-tags">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>',
|
|
'id_form' => 'commentform',
|
|
'id_submit' => 'submit',
|
|
'title_reply' => __( ' → Leave a Reply' ),
|
|
'title_reply_to' => __( 'Leave a Reply to %s' ),
|
|
'cancel_reply_link' => __( 'Cancel reply' ),
|
|
'label_submit' => __( 'Post Comment' ),
|
|
'format' => 'xhtml',
|
|
);
|
|
|
|
$args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
|
|
|
|
?>
|
|
<?php if ( comments_open( $post_id ) ) : ?>
|
|
<?php do_action( 'comment_form_before' ); ?>
|
|
<?php //echo '<span id="soumettre">Afficher</span> '; ?>
|
|
<h3 id="reply-title" class="comment-reply-title bouton"><?php comment_form_title( $args['title_reply'], $args['title_reply_to'] ); ?> <small><?php cancel_comment_reply_link( $args['cancel_reply_link'] ); ?></small></h3>
|
|
<div id="respond" class="comment-respond">
|
|
|
|
<div class="commentaires <?php if (get_option( 'display_comment' ) != ('1')) echo 'masquer'; ?>">
|
|
<?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?>
|
|
<?php echo $args['must_log_in']; ?>
|
|
<?php do_action( 'comment_form_must_log_in_after' ); ?>
|
|
<?php else : ?>
|
|
<form action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="comment-form"<?php echo $html5 ? ' novalidate' : ''; ?>>
|
|
<?php do_action( 'comment_form_top' ); ?>
|
|
<?php if ( is_user_logged_in() ) : ?>
|
|
<?php echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); ?>
|
|
<?php do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); ?>
|
|
<?php else : ?>
|
|
<?php echo $args['comment_notes_before']; ?>
|
|
<?php
|
|
do_action( 'comment_form_before_fields' );
|
|
foreach ( (array) $args['fields'] as $name => $field ) {
|
|
echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
|
|
}
|
|
do_action( 'comment_form_after_fields' );
|
|
?>
|
|
<?php endif; ?>
|
|
<?php echo apply_filters( 'comment_form_field_comment', $args['comment_field'] ); ?>
|
|
<?php echo $args['comment_notes_after']; ?>
|
|
<p class="form-submit">
|
|
<input name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />
|
|
<?php comment_id_fields( $post_id ); ?>
|
|
</p>
|
|
<?php do_action( 'comment_form', $post_id ); ?>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div><!-- #commentaires -->
|
|
</div><!-- #respond -->
|
|
<?php do_action( 'comment_form_after' ); ?>
|
|
<?php else : ?>
|
|
<?php do_action( 'comment_form_comments_closed' ); ?>
|
|
<?php endif; ?>
|
|
<?php
|
|
}
|
|
|
|
/* Remplacer le shortcode gallery
|
|
remove_shortcode('gallery', 'gallery_shortcode');
|
|
add_shortcode('gallery', 'gallery_shortcode_swipebox');
|
|
|
|
function gallery_shortcode_swipebox($attr) {
|
|
}
|
|
*/
|
|
|
|
/**
|
|
* Determines the difference between two timestamps.
|
|
*
|
|
* The difference is returned in a human readable format such as "1 hour",
|
|
* "5 mins", "2 days".
|
|
*
|
|
* @since 1.5.0
|
|
*
|
|
* @param int $from Unix timestamp from which the difference begins.
|
|
* @param int $to Optional. Unix timestamp to end the time difference. Default becomes time() if not set.
|
|
* @return string Human readable time difference.
|
|
*/
|
|
function _human_time_diff( $from, $to = '' ) {
|
|
if ( empty( $to ) )
|
|
$to = time();
|
|
|
|
$diff = (int) abs( $to - $from );
|
|
if ( $diff < HOUR_IN_SECONDS ) {
|
|
$mins = round( $diff / MINUTE_IN_SECONDS );
|
|
if ( $mins <= 1 )
|
|
$mins = 1;
|
|
/* translators: min=minute */
|
|
$since = sprintf( _n( '%s min ago', '%s mins ago', $mins, 'twentytwelve-child' ), $mins );
|
|
} elseif ( $diff < DAY_IN_SECONDS && $diff >= HOUR_IN_SECONDS ) {
|
|
$hours = round( $diff / HOUR_IN_SECONDS );
|
|
if ( $hours <= 1 )
|
|
$hours = 1;
|
|
$since = sprintf( _n( '%s hour ago', '%s hours ago', $hours, 'twentytwelve-child' ), $hours );
|
|
} elseif ( $diff < WEEK_IN_SECONDS && $diff >= DAY_IN_SECONDS ) {
|
|
$days = round( $diff / DAY_IN_SECONDS );
|
|
if ( $days <= 1 )
|
|
$days = 1;
|
|
$since = sprintf( _n( '%s day ago', '%s days ago', $days, 'twentytwelve-child' ), $days );
|
|
} elseif ( $diff < 30 * DAY_IN_SECONDS && $diff >= WEEK_IN_SECONDS ) {
|
|
$weeks = round( $diff / WEEK_IN_SECONDS );
|
|
if ( $weeks <= 1 )
|
|
$weeks = 1;
|
|
$since = sprintf( _n( '%s week ago', '%s weeks ago', $weeks, 'twentytwelve-child' ), $weeks );
|
|
} else {
|
|
/*
|
|
} elseif ( $diff < YEAR_IN_SECONDS && $diff >= 30 * DAY_IN_SECONDS ) {
|
|
$months = round( $diff / ( 30 * DAY_IN_SECONDS ) );
|
|
if ( $months <= 1 )
|
|
$months = 1;
|
|
*/
|
|
//$since = sprintf( _n( '%s month', '%s months', $months ), $months );
|
|
|
|
//$since = __('The', 'twentytwelve-child') . " " . get_the_date();
|
|
|
|
$since = sprintf( __( 'The %s', 'twentytwelve-child' ), get_the_date() );
|
|
|
|
/*
|
|
} elseif ( $diff >= YEAR_IN_SECONDS ) {
|
|
$years = round( $diff / YEAR_IN_SECONDS );
|
|
if ( $years <= 1 )
|
|
$years = 1;
|
|
$since = sprintf( _n( '%s year', '%s years', $years ), $years );*/
|
|
}
|
|
return $since;
|
|
}
|
|
|
|
?>
|