<?php
/*
Plugin Name: My breadcrumb  
Description: Fil d'Ariane pour les articles et les pages 
Version: 1.0 
License: GPLv2 

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

Copyright {année} {mon_nom} (email : {mon_email}) 
*/

if (!class_exists("My_Breadcrumb")) {
  class My_Breadcrumb{  
          public static function fil_ariane(){
              global $post;       
            
              if (!is_front_page()) {     
                $fil = '<div id="fil">Vous êtes ici : ';  
                $fil.= '<a href="'.get_bloginfo('wpurl').'">';  
                $fil.= get_bloginfo('name');  
                $fil.= '</a> > ';
                        
                $parents = array_reverse(get_ancestors($post->ID,'page')); 
                  
                  foreach($parents as $parent){   
                    $fil.='<a href="'.get_permalink($parent).'">';   
                    $fil.= get_the_title($parent);   
                    $fil.= '</a> > ';   
                  } 
                      
                $fil.= $post->post_title;   
                
                $fil.= '</div>';   
              }             
            return $fil;  
          }
          public static function add_css(){     
            wp_register_style('my_breadcrumb', plugins_url('style.css', __FILE__));
            wp_enqueue_style('my_breadcrumb'); 
          }          
          public static function breadcrumb_page_content(){
            ?>
                 		<div class="wrap">
                      <h2>My breadcrumb (fil d'Ariane)</h2>
                      <h3>Installation et utilisation</h3>
                      <div>
                      Pour utiliser l'extension :
                      <ul>
                          <li>1/ Téléchargez le dossier de l'extension dans le répertoire wp-content/plugins.</li>
                          <li>2/ Activez l'extension.</li>
                          <li>3/ Insérez la méthode php : <input type="text" value="$My_Breadcrumb=new My_Breadcrumb;   echo $My_Breadcrumb->fil_ariane();" size="40" readonly="readonly" /> dans les fichiers PHP de votre thème, <br />ou utilisez le shortcode : <input type="text" value="[mybreadcrumb]" readonly="readonly" /></li>
                      </ul>
                      </div>
                    </div>  
          <?php
          }
          public static function breadcrumb_menu() {
            if (function_exists('add_options_page')) {
            add_options_page('breadcrumb', 'my breadcrumb', 'administrator', 'breadcrumb', array('My_Breadcrumb','breadcrumb_page_content'));
            }
          }  
  
  }//fin de class
}//fin if class
  
           
if(class_exists("My_Breadcrumb")){  
    $inst_My_Breadcrumb = new My_Breadcrumb();  
}  
  
if(isset($inst_My_Breadcrumb)){ 
  add_action('admin_menu', array($inst_My_Breadcrumb, 'breadcrumb_menu'));
  add_action( 'wp_enqueue_scripts', array($inst_My_Breadcrumb,'add_css') );
}
if(function_exists('add_shortcode')){  
  add_shortcode('mybreadcrumb',array('My_Breadcrumb','fil_ariane')); 
}
?>