<?php
/*
Plugin Name: Simple Breadcrumb Navigation
Plugin URI: http://www.kriesi.at/archives/wordpress-plugin-simple-breadcrumb-navigation
Description: A simple and very lightweight breadcrumb navigation that covers nested pages and categories
Version: 1
Author: Christian "Kriesi" Budschedl
Author URI: http://www.kriesi.at/
*/

/*
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 3 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, see <http://www.gnu.org/licenses/>.
*/

/*
This plugin have been modified for compability with the theme.
*/

class simple_breadcrumb{
	var $options;
	
function simple_breadcrumb(){
	$this->options = array( 	//change this array if you want another output scheme
	'before' => '',
	'after' => '',
	'delimiter' => ''
	);
	
	$markup = $this->options['before'].$this->options['delimiter'].$this->options['after'];
	
	global $post;
	echo '<ul class="breadcrumbs"><li><a href="'.home_url().'">';
	_e('Home page','framework');
	echo "</a></li>";
	if(!is_front_page()){echo $markup;}
			
	$output = $this->simple_breadcrumb_case($post);
	
	echo "<li><span class='current'>";
	if ( is_page() || is_single()) {
	the_title();
	}else{
	echo $output;
	}
	echo " </span></li></ul>";
}



	
function simple_breadcrumb_case($der_post){
	global $data;
	$md_blog_title =  $data['md_default_banner_text'];
	$md_portfolio_page_title =  $data['md_portfolio_page_title'];
	$md_portfolio_page_url =  get_permalink($data['md_portfolio_page_url_select']);
	
	$md_404_title = __('404 - Page not found','framework');
	$md_search_page_title = __('Search result','framework');
	
	
	global $post, $blog_page;
	$markup = $this->options['before'].$this->options['delimiter'].$this->options['after'];
	if (is_page()){
		 if($der_post->post_parent) {
			 $my_query = get_post($der_post->post_parent);			 
			 $this->simple_breadcrumb_case($my_query);
			 $link = '<li><a href="';
			 $link .= get_permalink($my_query->ID);
			 $link .= '">';
			 $link .= ''. get_the_title($my_query->ID) . '</a></li>'. $markup;
			 echo $link;
		  }	
	return;			 	
	} 
			

	
	if(is_single()){
		
		$category = get_the_category();
		if (is_attachment()){
		
			$my_query = get_post($der_post->post_parent);			 
			$category = get_the_category($my_query->ID);
			$ID = $category[0]->cat_ID;

			echo get_category_parents($ID, TRUE, $markup, FALSE );
			previous_post_link("%link $markup");
			
		
		}
		
		
		elseif(is_singular('portfolio')){
			$link = '<li><a href="';
			
			$link .= $md_portfolio_page_url;
			$link .= '">';
			$link .= ''. $md_portfolio_page_title . '</a></li>'. $markup;
			echo $link;
		}
		else{
			 $link = '<li><a href="';
			 
			 $page_for_posts_id = get_option('page_for_posts'); //saved by wordpress.
			 $md_blog_page_link = get_permalink($page_for_posts_id);
			 
			 $link .= $md_blog_page_link;
			 $link .= '">';
			 $link .= ''. $md_blog_title . '</a></li>'. $markup;
			 echo $link;
			
			}
		
		
	return;
	}
	
	
	
	if(is_category()){
		$category = get_the_category(); 
		$i = $category[0]->cat_ID;
		$parent = $category[0]-> category_parent;
		
		if($parent > 0 && $category[0]->cat_name == single_cat_title("", false)){
			echo '<li>' . get_category_parents($parent, TRUE, $markup, FALSE).'</li>';
		}
	return single_cat_title('',FALSE);
	}
	
	
	if(is_author()){
		$curauth = get_user_by('slug', get_query_var('author_name'));
		return __("Author: ","framework").$curauth->nickname;
	}
	if(is_tag()){ return __("Tag: ","framework").single_tag_title('',FALSE); }
	
	if(is_404()){ return $md_404_title; }
	
	if(is_home()){ return $md_blog_title; }
	
	
	
	
	if(is_search()){ return $md_search_page_title; }	
	
	if(is_year()){ return get_the_time('Y'); }
	
	if(is_month()){
	$md_year = get_the_time('Y');
	echo "<li><a href='".get_year_link($md_year)."'>".$md_year."</a></li>".$markup;
	return get_the_time('F'); }
	
	if(is_day() || is_time()){ 
	$md_year = get_the_time('Y');
	$md_month = get_the_time('m');
	$md_month_display = get_the_time('F');
	echo "<li><a href='".get_year_link($md_year)."'>".$md_year."</a></li>".$markup;
	echo "<li><a href='".get_month_link($md_year, $md_month)."'>".$md_month_display."</a></li>".$markup;

	return get_the_time('jS (l)'); }
	
	}

}
?>