Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -rupN wordpress-seo-orig/frontend/class-breadcrumbs.php wordpress-seo/frontend/class-breadcrumbs.php
- --- wordpress-seo-orig/frontend/class-breadcrumbs.php 2012-06-15 05:24:48.000000000 -0300
- +++ wordpress-seo/frontend/class-breadcrumbs.php 2012-06-21 13:53:34.917656300 -0300
- @@ -116,34 +116,48 @@ class WPSEO_Breadcrumbs {
- $on_front = get_option('show_on_front');
- $blog_page = get_option('page_for_posts');
- $sep = ( isset($opt['breadcrumbs-sep']) && $opt['breadcrumbs-sep'] != '' ) ? $opt['breadcrumbs-sep'] : '»';
- - $home = ( isset($opt['breadcrumbs-home']) && $opt['breadcrumbs-home'] != '' ) ? $opt['breadcrumbs-home'] : __('Home','wordpress-seo');
- + $hometitle = ( isset($opt['breadcrumbs-home']) && $opt['breadcrumbs-home'] != '' ) ? $opt['breadcrumbs-home'] : __('Home','wordpress-seo');
- + // This doesn't seem to be used:
- $selmenu = ( isset($opt['breadcrumbs-selectedmenu']) && $opt['breadcrumbs-selectedmenu'] != '' ) ? $opt['breadcrumbs-selectedmenu'] : 0;
- + $breadcrumb_array = array();
- if ( "page" == $on_front && 'post' == get_post_type() ) {
- - $homelink = '<a href="'.get_permalink(get_option('page_on_front')).'">'.$home.'</a>';
- - $bloglink = $homelink;
- - if ( $blog_page && ( !isset($opt['breadcrumbs-blog-remove']) || !$opt['breadcrumbs-blog-remove'] ) )
- - $bloglink = $homelink.' '.$sep.' <a href="'.get_permalink($blog_page).'">'.$this->get_bc_title($blog_page).'</a>';
- + $homeurl = get_permalink(get_option('page_on_front'));
- } else {
- - $homelink = '<a href="'.get_bloginfo('url').'">'.$home.'</a>';
- - $bloglink = $homelink;
- + $homeurl = get_bloginfo('url');
- }
- - if ( ( $on_front == "page" && is_front_page() ) || ( $on_front == "posts" && is_home() ) ) {
- - $output = $this->bold_or_not($home);
- + if ( $on_front == "page" && is_front_page() ) {
- + $breadcrumb_array[] = array( 'title' => $hometitle, 'url' => '', 'class' => '', 'type' => 'home', 'ID' => null );
- + } else if ( $on_front == "posts" && is_home() ) {
- + $breadcrumb_array[] = array( 'title' => $hometitle, 'url' => '', 'class' => '', 'type' => 'home', 'ID' => null );
- } else if ( $on_front == "page" && is_home() ) {
- - $output = $homelink.' '.$sep.' '.$this->bold_or_not( $this->get_bc_title($blog_page) );
- + $breadcrumb_array[] = array( 'title' => $hometitle, 'url' => $homeurl, 'class' => '', 'type' => 'home', 'ID' => null );
- + $breadcrumb_array[] = array( 'title' => $this->get_bc_title($blog_page), 'url' => '', 'class' => '', 'type' => get_post_type($blog_page), 'ID' => (int) $blog_page );
- } else if ( is_singular() ) {
- - $output = $bloglink.' '.$sep.' ';
- + $breadcrumb_array[] = array( 'title' => $hometitle, 'url' => $homeurl, 'class' => '', 'type' => 'home', 'ID' => null );
- +
- + if ( $blog_page && 'page' == $on_front && 'post' == get_post_type() && ( !isset($opt['breadcrumbs-blog-remove']) || !$opt['breadcrumbs-blog-remove'] ) ) {
- + $breadcrumb_array[] = array( 'title' => $this->get_bc_title($blog_page), 'url' => get_permalink($blog_page), 'class' => '', 'type' => get_post_type($blog_page), 'ID' => (int) $blog_page );
- + }
- + // This doesn't seem to be used:
- if( isset($opt['breadcrumbs-menus']) && $opt['breadcrumbs-menus'] = 'on'){
- $use_menu = $this->in_menu( $selmenu );
- }
- if ( function_exists('bbp_body_class') && count( bbp_body_class( array() ) ) > 1 ) {
- remove_filter('bbp_get_breadcrumb','__return_false');
- - $output .= bbp_get_breadcrumb( ' '.$sep.' ' );
- + $bbp_bc_array = explode( ';;;;;', bbp_get_breadcrumb( ';;;;;' ) );
- + if ( !empty($bbp_bc_array[0]) ) {
- + foreach ( $bbp_bc_array as $bbp_bc ) {
- + if ( preg_match( '/(<(a .*href="(?P<url>.*?)"( .*class="(?P<class>.*?)")?.*?)>)?(?P<title>.*)/', trim($bbp_bc), $bbp_pc_results ) ) {
- + $breadcrumb_array[] = array ( 'title' => trim(strip_tags($bbp_pc_results['title'])), 'url' => $bbp_pc_results['url'], 'class' => $bbp_pc_results['class'], 'type' => 'bbpress', 'ID' => null );
- + }
- + }
- + }
- add_filter('bbp_get_breadcrumb','__return_false');
- } else if( isset( $use_menu ) && $use_menu ){
- + // This whole block doesn't seem to be used:
- $trail = $this->get_menu_trail();
- $trail = array_reverse ( $trail );
- $trailposts = array();
- @@ -152,169 +166,230 @@ class WPSEO_Breadcrumbs {
- }
- for($t = 0; $t < count($trail); $t++){
- $bctitle = ( get_the_title( $trail[$t] ) == '' ) ? get_the_title( $trailposts[$t] ) : get_the_title( $trail[$t] );
- - $output .= '<a href="' . get_permalink( $trailposts[$t] ) . '">' . $bctitle .'</a> ' . $sep . ' ';
- + $breadcrumb_array[] = array( 'title' => $bctitle, 'url' => get_permalink( $trailposts[$t] ), 'class' => '', 'type' => get_post_type( $trailposts[$t] ), 'ID' => (int) $trailposts[$t] );
- }
- - $output .= $this->bold_or_not( $this->get_bc_title( $post->ID ) );
- + $breadcrumb_array[] = array( 'title' => $this->get_bc_title( $post->ID ), 'url' => '', 'class' => '', 'type' => get_post_type( $post->ID ), 'ID' => (int) $post->ID );
- } else {
- -
- $post_type = get_post_type();
- if ( function_exists('get_post_type_archive_link') && get_post_type_archive_link( $post_type ) ) {
- if ( isset($options['bctitle-ptarchive-'.$post_type]) && '' != $options['bctitle-ptarchive-'.$post_type] ) {
- $archive_title = $options['bctitle-ptarchive-'.$post_type];
- } else {
- $post_type_obj = get_post_type_object( $post_type );
- - $archive_title = $post_type_obj->labels->menu_name;
- + //$archive_title = $post_type_obj->labels->menu_name;
- + $archive_title = $post_type_obj->labels->name;
- }
- - $output .= '<a href="'.get_post_type_archive_link( $post_type ).'">'.$archive_title.'</a> ' . $sep . ' ';
- + $breadcrumb_array[] = array( 'title' => $archive_title, 'url' => get_post_type_archive_link( $post_type ), 'class' => '', 'type' => $post_type, 'ID' => null );
- }
- -
- +
- if ( 0 == $post->post_parent ) {
- if ( isset( $opt['post_types-'.$post->post_type.'-maintax'] ) && $opt['post_types-'.$post->post_type.'-maintax'] != '0' ) {
- $main_tax = $opt['post_types-'.$post->post_type.'-maintax'];
- - $terms = wp_get_object_terms( $post->ID, $main_tax );
- - if ( is_taxonomy_hierarchical($main_tax) && $terms[0]->parent != 0 ) {
- - $parents = $this->get_term_parents($terms[0], $main_tax);
- - $parents = array_reverse($parents);
- - foreach($parents as $parent) {
- - $bctitle = wpseo_get_term_meta( $parent, $main_tax, 'bctitle' );
- - if (!$bctitle)
- - $bctitle = $parent->name;
- - $output .= '<a href="'.get_term_link( $parent, $main_tax ).'">'.$bctitle.'</a> '.$sep.' ';
- - }
- - }
- + $terms = wp_get_object_terms( $post->ID, $main_tax, apply_filters( 'wp_seo_get_bc_taxonomy_args', array( 'orderby' => 'term_order' ) ) );
- if ( count($terms) > 0 ) {
- + if ( is_taxonomy_hierarchical($main_tax) && $terms[0]->parent != 0 ) {
- + $parents = $this->get_term_parents($terms[0], $main_tax);
- + $parents = array_reverse($parents);
- + foreach($parents as $parent) {
- + $bctitle = wpseo_get_term_meta( $parent, $main_tax, 'bctitle' );
- + if (!$bctitle) {
- + $bctitle = $parent->name;
- + }
- + $breadcrumb_array[] = array( 'title' => $bctitle, 'url' => get_term_link( $parent, $main_tax ), 'class' => '', 'type' => $main_tax, 'ID' => (int) $parent->term_id );
- + }
- + }
- $bctitle = wpseo_get_term_meta( $terms[0], $main_tax, 'bctitle' );
- - if (!$bctitle)
- + if (!$bctitle) {
- $bctitle = $terms[0]->name;
- - $output .= '<a href="'.get_term_link($terms[0], $main_tax).'">'.$bctitle.'</a> '.$sep.' ';
- + }
- + $breadcrumb_array[] = array( 'title' => $bctitle, 'url' => get_term_link($terms[0], $main_tax), 'class' => '', 'type' => $main_tax, 'ID' => (int) $terms[0]->term_id );
- }
- }
- - $output .= $this->bold_or_not( $this->get_bc_title( $post->ID ) );
- + $breadcrumb_array[] = array( 'title' => $this->get_bc_title( $post->ID ), 'url' => '', 'class' => '', 'type' => $post_type, 'ID' => (int) $post->ID );
- } else {
- if (isset($post->ancestors)) {
- - if (is_array($post->ancestors))
- + if (is_array($post->ancestors)) {
- $ancestors = array_values($post->ancestors);
- - else
- - $ancestors = array($post->ancestors);
- + } else {
- + $ancestors = array($post->ancestors);
- + }
- } else {
- $ancestors = array($post->post_parent);
- }
- - // Reverse the order so it's oldest to newest
- - $ancestors = array_reverse( apply_filters( 'wp_seo_get_bc_ancestors', $ancestors ) );
- -
- + $ancestors = array_reverse( $ancestors ); // Reverse the order so it's oldest to newest
- foreach ( $ancestors as $ancestor ) {
- - $output .= '<a href="'.get_permalink($ancestor).'">'.$this->get_bc_title( $ancestor ).'</a> '.$sep.' ';
- + $breadcrumb_array[] = array( 'title' => $this->get_bc_title( $ancestor ), 'url' => get_permalink($ancestor), 'class' => '', 'type' => get_post_type($ancestor), 'ID' => (int) $ancestor );
- }
- - $output .= $this->bold_or_not( $this->get_bc_title( $post->ID ) );
- - }
- + $breadcrumb_array[] = array( 'title' => $this->get_bc_title( $post->ID ), 'url' => '', 'class' => '', 'type' => $post_type, 'ID' => (int) $post->ID );
- + }
- }
- } else {
- - if (! is_404() ) {
- - $output = $bloglink.' '.$sep.' ';
- - } else {
- - $output = $homelink.' '.$sep.' ';
- + $breadcrumb_array[] = array( 'title' => $hometitle, 'url' => $homeurl, 'class' => '', 'type' => 'home', 'ID' => null );
- + if ( !is_404() && $blog_page && 'page' == $on_front && 'post' == get_post_type() && ( !isset($opt['breadcrumbs-blog-remove']) || !$opt['breadcrumbs-blog-remove'] ) ) {
- + $breadcrumb_array[] = array( 'title' => $this->get_bc_title($blog_page), 'url' => get_permalink($blog_page), 'class' => '', 'type' => get_post_type($blog_page), 'ID' => (int) $blog_page );
- }
- -
- - if ( function_exists('is_post_type_archive') && is_post_type_archive() ) {
- + if ( function_exists('is_post_type_archive') && is_post_type_archive() && get_post_type() ) {
- $post_type = get_post_type();
- if ( isset($options['bctitle-ptarchive-'.$post_type]) && '' != $options['bctitle-ptarchive-'.$post_type] ) {
- $archive_title = $options['bctitle-ptarchive-'.$post_type];
- } else {
- $post_type_obj = get_post_type_object( $post_type );
- - $archive_title = $post_type_obj->labels->menu_name;
- + //$archive_title = $post_type_obj->labels->menu_name;
- + $archive_title = $post_type_obj->labels->name;
- }
- - $output .= $this->bold_or_not( $archive_title );
- + $breadcrumb_array[] = array( 'title' => $archive_title, 'url' => '', 'class' => '', 'type' => $post_type, 'ID' => null );
- } else if ( is_tax() || is_tag() || is_category() ) {
- $term = $wp_query->get_queried_object();
- if ( isset($options['taxonomy-'.$term->taxonomy.'-ptparent']) && $options['taxonomy-'.$term->taxonomy.'-ptparent'] != '' ) {
- $post_type = $options['taxonomy-'.$term->taxonomy.'-ptparent'];
- - if ( 'post' == $post_type && get_option('show_on_front') == 'page' ) {
- - $posts_page = get_option('page_for_posts');
- - if ( $posts_page ) {
- - $output .= '<a href="'.get_permalink( $posts_page ).'">'.$this->get_bc_title( $posts_page ).'</a> '.$sep.' ';
- - }
- + if ( $blog_page && 'post' == $post_type && 'page' == $on_front ) {
- + $breadcrumb_array[] = array( 'title' => $this->get_bc_title($blog_page), 'url' => get_permalink($blog_page), 'class' => '', 'type' => $post_type, 'ID' => $blog_page );
- } else {
- if ( isset($options['bctitle-ptarchive-'.$post_type]) && '' != $options['bctitle-ptarchive-'.$post_type] ) {
- $archive_title = $options['bctitle-ptarchive-'.$post_type];
- } else {
- $post_type_obj = get_post_type_object( $post_type );
- - $archive_title = $post_type_obj->labels->menu_name;
- + //$archive_title = $post_type_obj->labels->menu_name;
- + $archive_title = $post_type_obj->labels->name;
- }
- - $output .= '<a href="'.get_post_type_archive_link( $post_type ).'">'.$archive_title.'</a> '.$sep.' ';
- + $breadcrumb_array[] = array( 'title' => $archive_title, 'url' => get_post_type_archive_link( $post_type ), 'class' => '', 'type' => $post_type, 'ID' => null );
- }
- }
- -
- +
- if ( is_taxonomy_hierarchical($term->taxonomy) && $term->parent != 0 ) {
- $parents = $this->get_term_parents($term, $term->taxonomy);
- $parents = array_reverse( $parents );
- foreach($parents as $parent) {
- $bctitle = wpseo_get_term_meta( $parent, $term->taxonomy, 'bctitle' );
- - if (!$bctitle)
- + if (!$bctitle) {
- $bctitle = $parent->name;
- - $output .= '<a href="'.get_term_link( $parent, $term->taxonomy ).'">'.$bctitle.'</a> '.$sep.' ';
- + }
- + $breadcrumb_array[] = array( 'title' => $bctitle, 'url' => get_term_link( $parent, $term->taxonomy ), 'class' => '', 'type' => $parent->taxonomy, 'ID' => (int) $parent->term_id );
- }
- }
- $bctitle = wpseo_get_term_meta( $term, $term->taxonomy, 'bctitle' );
- - if (!$bctitle)
- + if (!$bctitle) {
- $bctitle = $term->name;
- + }
- - if ($paged)
- - $output .= $this->bold_or_not('<a href="'.get_term_link( $term, $term->taxonomy ).'">'.$bctitle.'</a>');
- - else
- - $output .= $this->bold_or_not($bctitle);
- + if ($paged) {
- + $breadcrumb_array[] = array( 'title' => $bctitle, 'url' => get_term_link( $term, $term->taxonomy ), 'class' => '', 'type' => $term->taxonomy, 'ID' => (int) $term->term_id );
- + } else {
- + $breadcrumb_array[] = array( 'title' => $bctitle, 'url' => '', 'class' => '', 'type' => $term->taxonomy, 'ID' => (int) $term->term_id );
- + }
- } else if ( is_date() ) {
- - if ( isset($opt['breadcrumbs-archiveprefix']) )
- + if ( isset($opt['breadcrumbs-archiveprefix']) ) {
- $bc = $opt['breadcrumbs-archiveprefix'];
- - else
- + } else {
- $bc = __('Archives for','wordpress-seo');
- + }
- if ( is_day() ) {
- global $wp_locale;
- - $output .= '<a href="'.get_month_link( get_query_var('year'), get_query_var('monthnum') ).'">'.$wp_locale->get_month( get_query_var('monthnum') ).' '.get_query_var('year').'</a> '.$sep.' ';
- - $output .= $this->bold_or_not( $bc." ".get_the_date() );
- + $breadcrumb_array[] = array( 'title' => $wp_locale->get_month( get_query_var('monthnum') ).' '.get_query_var('year'), 'url' => get_month_link( get_query_var('year'), get_query_var('monthnum') ), 'class' => '', 'type' => 'date', 'ID' => null );
- + $breadcrumb_array[] = array( 'title' => $bc." ".get_the_date(), 'url' => '', 'class' => '', 'type' => 'date', 'ID' => null );
- } else if ( is_month() ) {
- - $output .= $this->bold_or_not( $bc." ".single_month_title(' ',false) );
- + $breadcrumb_array[] = array( 'title' => $bc." ".single_month_title(' ',false), 'url' => '', 'class' => '', 'type' => 'date', 'ID' => null );
- } else if ( is_year() ) {
- - $output .= $this->bold_or_not( $bc." ".get_query_var('year') );
- + $breadcrumb_array[] = array( 'title' => $bc." ".get_query_var('year'), 'url' => '', 'class' => '', 'type' => 'date', 'ID' => null );
- }
- } elseif ( is_author() ) {
- - if ( isset($opt['breadcrumbs-archiveprefix']) )
- + if ( isset($opt['breadcrumbs-archiveprefix']) ) {
- $bc = $opt['breadcrumbs-archiveprefix'];
- - else
- + } else {
- $bc = __('Archives for','wordpress-seo');
- + }
- $user = $wp_query->get_queried_object();
- - $output .= $this->bold_or_not($bc." ".$user->display_name);
- + $breadcrumb_array[] = array( 'title' => $bc." ".$user->display_name, 'url' => '', 'class' => '', 'type' => 'author', 'ID' => $user->ID );
- } elseif ( is_search() ) {
- - if ( isset($opt['breadcrumbs-searchprefix']) && $opt['breadcrumbs-searchprefix'] != '' )
- + if ( isset($opt['breadcrumbs-searchprefix']) && $opt['breadcrumbs-searchprefix'] != '' ) {
- $bc = $opt['breadcrumbs-searchprefix'];
- - else
- + } else {
- $bc = __('You searched for','wordpress-seo');
- - $output .= $this->bold_or_not($bc.' "'.stripslashes(strip_tags(get_search_query())).'"');
- + }
- + $breadcrumb_array[] = array( 'title' => $bc.' "'.stripslashes(strip_tags(get_search_query())).'"', 'url' => '', 'class' => '', 'type' => 'search', 'ID' => null );
- } elseif ( isset( $wp_query->query_vars['bbp_topic_tag'] ) ) {
- remove_filter('bbp_get_breadcrumb','__return_false');
- - $output .= bbp_get_breadcrumb( ' '.$sep.' ' );
- + $bbp_bc_array = explode( ';;;;;', bbp_get_breadcrumb( ';;;;;' ) );
- + if ( !empty($bbp_bc_array[0]) ) {
- + foreach ( $bbp_bc_array as $bbp_bc ) {
- + if ( preg_match( '/(<(a .*href="(?P<url>.*?)"( .*class="(?P<class>.*?)")?.*?)>)?(?P<title>.*)/', trim($bbp_bc), $bbp_pc_results ) ) {
- + $breadcrumb_array[] = array ( 'title' => trim(strip_tags($bbp_pc_results['title'])), 'url' => $bbp_pc_results['url'], 'class' => $bbp_pc_results['class'], 'type' => 'bbpress', 'ID' => null );
- + }
- + }
- + }
- add_filter('bbp_get_breadcrumb','__return_false');
- } elseif ( is_404() ) {
- - if ( isset($opt['breadcrumbs-404crumb']) && $opt['breadcrumbs-404crumb'] != '' )
- + if ( isset($opt['breadcrumbs-404crumb']) && $opt['breadcrumbs-404crumb'] != '' ) {
- $crumb404 = $opt['breadcrumbs-404crumb'];
- - else
- + } else {
- $crumb404 = __('Error 404: Page not found','wordpress-seo');
- - $output .= $this->bold_or_not($crumb404);
- + }
- + $breadcrumb_array[] = array ( 'title' => $crumb404, 'url' => '', 'class' => '', 'type' => '404-not-found', 'ID' => null );
- }
- }
- - if ( isset($opt['breadcrumbs-prefix']) && $opt['breadcrumbs-prefix'] != "" ) {
- - $output = $opt['breadcrumbs-prefix']." ".$output;
- + $breadcrumb_array = apply_filters( 'wp_seo_get_bc_ancestors', $breadcrumb_array );
- +
- + $output = '';
- + if ( !empty($breadcrumb_array) ) {
- + $output .= $prefix;
- + if ( isset($opt['breadcrumbs-prefix']) && $opt['breadcrumbs-prefix'] != "" ) {
- + $output .= $opt['breadcrumbs-prefix'].' ';
- + }
- +
- + $breadcrumb_total = count( $breadcrumb_array ) - 1; // Since arrays start at 0.
- + for ( $i = 0 ; $i <= $breadcrumb_total ; $i++ ) {
- + $breadcrumb = $breadcrumb_array[$i];
- +
- + $pre_out = $post_out = '';
- + $mid_out = $breadcrumb['title'];
- +
- + // We don't want search engines displaying the home link in the snippet breadcrumb. Also,
- + // a breadcrumb DIV for the very last item (the current page) is ignored. So we deal with
- + // the special cases:
- + if ( ( $i == 0 && $breadcrumb['type'] != 'home' ) || ( $i > 0 && $i < $breadcrumb_total ) ) {
- + $pre_out .= '<div';
- + if ( ( $i == 1 && $breadcrumb_array[0]['type'] != 'home' ) || $i > 1 ) {
- + $pre_out .= ' itemprop="child"';
- + }
- + $pre_out .= ' itemscope itemtype="http://data-vocabulary.org/Breadcrumb" style="display: inline;">';
- + $mid_out = '<span itemprop="title">'.$mid_out.'</span>';
- + $suffix = '</div>'.$suffix;
- + }
- +
- + if ( $breadcrumb['url'] ) {
- + $pre_out .= '<a href="'.esc_url($breadcrumb['url']).'"';
- + if ( $breadcrumb['class'] ) {
- + $pre_out .= ' class="'.esc_attr($breadcrumb['class']).'"';
- + }
- + if ( $i == 0 && $breadcrumb['type'] != 'home' ) {
- + $pre_out .= ' itemprop="url"';
- + }
- + $pre_out .= '>';
- + $post_out .= '</a>';
- + }
- +
- + if ( $i < $breadcrumb_total ) {
- + $post_out .= ' '.$sep.' ';
- + } else {
- + $mid_out = $this->bold_or_not( $mid_out );
- + }
- +
- + $output .= $pre_out.$mid_out.$post_out;
- + }
- + $output .= $suffix;
- }
- +
- if ($display) {
- - echo $prefix.$output.$suffix;
- + echo $output;
- return true;
- } else {
- - return $prefix.$output.$suffix;
- + return $output;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement