コード例 #1
0
 /**
  * The enhanced default constructor, ends up setting all parameters via the set_ functions
  *  
  * @param string $title (optional) The title of the breadcrumb
  * @param string $template (optional) The html template for the breadcrumb
  * @param string $type (optional) The breadcrumb type
  * @param string $url (optional) The url the breadcrumb links to
  */
 public function __construct($title = '', $template = '', array $type = array(), $url = '', $id = NULL)
 {
     //Filter allowed_html array to allow others to add acceptable tags
     $this->allowed_html = apply_filters('bcn_allowed_html', wp_kses_allowed_html('post'));
     //The breadcrumb type
     $this->type = $type;
     //Set the resource id
     $this->set_id($id);
     //Set the title
     $this->set_title($title);
     //Set the default anchorless templates value
     $this->template_no_anchor = bcn_breadcrumb::default_template_no_anchor;
     //If we didn't get a good template, use a default template
     if ($template == NULL) {
         $this->set_template(bcn_breadcrumb::get_default_template());
     } else {
         //Loose comparison, evaluates to true if URL is '' or NULL
         if ($url == NULL) {
             $this->template_no_anchor = wp_kses(apply_filters('bcn_breadcrumb_template_no_anchor', $template, $this->type, $this->id), $this->allowed_html);
             $this->set_template(bcn_breadcrumb::get_default_template());
         } else {
             $this->set_template($template);
         }
     }
     //Always NULL if unlinked
     $this->set_url($url);
 }
コード例 #2
0
 /**
  * Outputs the breadcrumb trail
  * 
  * @since  3.2.0
  * @param  (bool)   $return Whether to return or echo the trail.
  * @param  (bool)   $linked Whether to allow hyperlinks in the trail or not.
  * @param  (bool)	$reverse Whether to reverse the output or not.
  */
 function display_list($return = false, $linked = true, $reverse = false)
 {
     //Grab the current settings from the db
     $this->breadcrumb_trail->opt = $this->get_option('bcn_options');
     //Generate the breadcrumb trail
     $this->breadcrumb_trail->fill();
     return $this->breadcrumb_trail->display_list($return, $linked, $reverse);
 }
コード例 #3
0
 public function __construct()
 {
     //@see https://core.trac.wordpress.org/ticket/10527
     if (!is_textdomain_loaded('breadcrumb-navxt')) {
         load_plugin_textdomain('breadcrumb-navxt', false, 'breadcrumb-navxt/languages');
     }
     $this->trail =& $this->breadcrumbs;
     //Initilize with default option values
     $this->opt = array('bmainsite_display' => true, 'Hmainsite_template' => bcn_breadcrumb::get_default_template(), 'Hmainsite_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor, 'bhome_display' => true, 'Hhome_template' => bcn_breadcrumb::get_default_template(), 'Hhome_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor, 'bblog_display' => true, 'Hblog_template' => bcn_breadcrumb::get_default_template(), 'Hblog_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor, 'hseparator' => ' &gt; ', 'blimit_title' => false, 'amax_title_length' => 20, 'bcurrent_item_linked' => false, 'Hpost_page_template' => bcn_breadcrumb::get_default_template(), 'Hpost_page_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor, 'apost_page_root' => get_option('page_on_front'), 'Hpaged_template' => __('<span property="itemListElement" typeof="ListItem"><span property="name">Page %htitle%</span><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'), 'bpaged_display' => false, 'Hpost_post_template' => bcn_breadcrumb::get_default_template(), 'Hpost_post_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor, 'apost_post_root' => get_option('page_for_posts'), 'bpost_post_taxonomy_display' => true, 'Spost_post_taxonomy_type' => 'category', 'Hpost_attachment_template' => bcn_breadcrumb::get_default_template(), 'Hpost_attachment_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor, 'H404_template' => bcn_breadcrumb::default_template_no_anchor, 'S404_title' => __('404', 'breadcrumb-navxt'), 'Hsearch_template' => __('<span property="itemListElement" typeof="ListItem"><span property="name">Search results for &#39;<a property="item" typeof="WebPage" title="Go to the first page of search results for %title%." href="%link%" class="%type%">%htitle%</a>&#39;</span><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'), 'Hsearch_template_no_anchor' => __('<span property="itemListElement" typeof="ListItem"><span property="name">Search results for &#39;%htitle%&#39;</span><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'), 'Htax_post_tag_template' => __('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to the %title% tag archives." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'), 'Htax_post_tag_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor, 'Htax_post_format_template' => __('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to the %title% archives." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'), 'Htax_post_format_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor, 'Hauthor_template' => __('<span property="itemListElement" typeof="ListItem"><span property="name">Articles by: <a title="Go to the first page of posts by %title%." href="%link%" class="%type%">%htitle%</a>', 'breadcrumb-navxt'), 'Hauthor_template_no_anchor' => __('<span property="itemListElement" typeof="ListItem"><span property="name">Articles by: %htitle%</span><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'), 'Sauthor_name' => 'display_name', 'Htax_category_template' => __('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to the %title% category archives." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'), 'Htax_category_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor, 'Hdate_template' => __('<span property="itemListElement" typeof="ListItem"><a property="item" typeof="WebPage" title="Go to the %title% archives." href="%link%" class="%type%"><span property="name">%htitle%</span></a><meta property="position" content="%position%"></span>', 'breadcrumb-navxt'), 'Hdate_template_no_anchor' => bcn_breadcrumb::default_template_no_anchor);
 }
コード例 #4
0
 /**
  * Outputs the breadcrumb trail
  * 
  * @since  3.8.0
  * @param bool $return Whether to return data or to echo it.
  * @param bool $linked[optional] Whether to allow hyperlinks in the trail or not.
  * @param string $tag[optional] The tag to use for the nesting
  * @param string $mode[optional] Whether to follow the rdfa or Microdata format
  */
 function display_nested($return = false, $linked = true, $tag = 'span', $mode = 'rdfa')
 {
     //First make sure our defaults are safe
     $this->find_posttypes($this->breadcrumb_trail->opt);
     $this->find_taxonomies($this->breadcrumb_trail->opt);
     //Grab the current settings from the db
     $this->breadcrumb_trail->opt = wp_parse_args($this->get_option('bcn_options'), $this->breadcrumb_trail->opt);
     //Generate the breadcrumb trail
     $this->breadcrumb_trail->fill();
     return $this->breadcrumb_trail->display_nested($return, $linked, $tag, $mode);
 }
コード例 #5
0
 /**
  * widget
  *
  * The sidebar widget 
  */
 function widget($args)
 {
     extract($args);
     //Manditory before widget junk
     echo $before_widget;
     //Display the breadcrumb trial
     if ($this->breadcrumb_trail->trail[0] != NULL) {
         $this->breadcrumb_trail->display();
     } else {
         $this->display();
     }
     //Manditory after widget junk
     echo $after_widget;
 }
コード例 #6
0
 /**
  * Places settings into $opts array, if missing, for the registered post types
  * 
  * @param array $opts
  */
 static function find_posttypes(&$opts)
 {
     global $wp_post_types, $wp_taxonomies;
     //Loop through all of the post types in the array
     foreach ($wp_post_types as $post_type) {
         //We only want custom post types
         if (!$post_type->_builtin) {
             //If the post type does not have settings in the options array yet, we need to load some defaults
             if (!isset($opts['Hpost_' . $post_type->name . '_template']) || !$post_type->hierarchical && !isset($opts['Spost_' . $post_type->name . '_taxonomy_type'])) {
                 //Add the necessary option array members
                 $opts['Hpost_' . $post_type->name . '_template'] = bcn_breadcrumb::get_default_template();
                 $opts['Hpost_' . $post_type->name . '_template_no_anchor'] = bcn_breadcrumb::default_template_no_anchor;
                 if ($post_type->has_archive == true || is_string($post_type->has_archive)) {
                     $opts['bpost_' . $post_type->name . '_archive_display'] = true;
                 } else {
                     $opts['bpost_' . $post_type->name . '_archive_display'] = false;
                 }
                 //Default to not showing a post_root
                 $opts['apost_' . $post_type->name . '_root'] = 0;
                 //Default to not displaying a taxonomy
                 $opts['bpost_' . $post_type->name . '_taxonomy_display'] = false;
                 //Loop through all of the possible taxonomies
                 foreach ($wp_taxonomies as $taxonomy) {
                     //Check for non-public taxonomies
                     if (!apply_filters('bcn_show_tax_private', $taxonomy->public, $taxonomy->name)) {
                         continue;
                     }
                     //Activate the first taxonomy valid for this post type and exit the loop
                     if ($taxonomy->object_type == $post_type->name || in_array($post_type->name, $taxonomy->object_type)) {
                         $opts['bpost_' . $post_type->name . '_taxonomy_display'] = true;
                         $opts['Spost_' . $post_type->name . '_taxonomy_type'] = $taxonomy->name;
                         break;
                     }
                 }
                 //If there are no valid taxonomies for this type, we default to not displaying taxonomies for this post type
                 if (!isset($opts['Spost_' . $post_type->name . '_taxonomy_type'])) {
                     $opts['Spost_' . $post_type->name . '_taxonomy_type'] = 'date';
                 }
             }
         }
     }
 }
コード例 #7
0
 /**
  * Upgrades input options array, sets to $this->opt
  * 
  * @param array $opts
  * @param string $version the version of the passed in options
  */
 function opts_upgrade($opts, $version)
 {
     global $wp_post_types, $wp_taxonomies;
     //If our version is not the same as in the db, time to update
     if (version_compare($version, $this::version, '<')) {
         //Upgrading to 3.8.1
         if (version_compare($version, '3.8.1', '<')) {
             $opts['post_page_root'] = get_option('page_on_front');
             $opts['post_post_root'] = get_option('page_for_posts');
         }
         //Upgrading to 4.0
         if (version_compare($version, '4.0.0', '<')) {
             //Only migrate if we haven't migrated yet
             if (isset($opts['current_item_linked'])) {
                 //Loop through the old options, migrate some of them
                 foreach ($opts as $option => $value) {
                     //Handle all of our boolean options first, they're real easy, just add a 'b'
                     if (strpos($option, 'display') > 0 || $option == 'current_item_linked') {
                         $this->breadcrumb_trail->opt['b' . $option] = $value;
                     } else {
                         if (strpos($option, 'anchor') > 0) {
                             $parts = explode('_', $option);
                             //Do excess slash removal sanitation
                             $this->breadcrumb_trail->opt['H' . $parts[0] . '_template'] = $value . '%htitle%</a>';
                         } else {
                             if ($option == 'max_title_length' || $option == 'post_post_root' || $option == 'post_page_root') {
                                 $this->breadcrumb_trail->opt['a' . $option] = $value;
                             } else {
                                 if (strpos($option, 'prefix') === false && strpos($option, 'suffix') === false) {
                                     $this->breadcrumb_trail->opt['S' . $option] = $value;
                                 }
                             }
                         }
                     }
                 }
             }
             //Add in the new settings for CPTs introduced in 4.0
             foreach ($wp_post_types as $post_type) {
                 //We only want custom post types
                 if (!$post_type->_builtin) {
                     //Add in the archive_display option
                     $this->breadcrumb_trail->opt['bpost_' . $post_type->name . '_archive_display'] = $post_type->has_archive;
                 }
             }
             $opts = $this->breadcrumb_trail->opt;
         }
         if (version_compare($version, '4.0.1', '<')) {
             if (isset($opts['Hcurrent_item_template_no_anchor'])) {
                 unset($opts['Hcurrent_item_template_no_anchor']);
             }
             if (isset($opts['Hcurrent_item_template'])) {
                 unset($opts['Hcurrent_item_template']);
             }
         }
         //Upgrading to 4.3.0
         if (version_compare($version, '4.3.0', '<')) {
             //Removed home_title
             if (isset($opts['Shome_title'])) {
                 unset($opts['Shome_title']);
             }
             //Removed mainsite_title
             if (isset($opts['Smainsite_title'])) {
                 unset($opts['Smainsite_title']);
             }
         }
         //Upgrading to 5.1.0
         if (version_compare($version, '5.1.0', '<')) {
             foreach ($wp_taxonomies as $taxonomy) {
                 //If we have the old options style for it, update
                 if ($taxonomy->name !== 'post_format' && isset($opts['H' . $taxonomy->name . '_template'])) {
                     //Migrate to the new setting name
                     $opts['Htax_' . $taxonomy->name . '_template'] = $opts['H' . $taxonomy->name . '_template'];
                     $opts['Htax_' . $taxonomy->name . '_template_no_anchor'] = $opts['H' . $taxonomy->name . '_template_no_anchor'];
                     //Clean up old settings
                     unset($opts['H' . $taxonomy->name . '_template']);
                     unset($opts['H' . $taxonomy->name . '_template_no_anchor']);
                 }
             }
         }
         //Upgrading to 5.4.0
         if (version_compare($version, '5.4.0', '<')) {
             //Migrate users to schema.org breadcrumbs for author and search if still on the defaults for posts
             if ($opts['Hpost_post_template'] === bcn_breadcrumb::get_default_template() && $opts['Hpost_post_template_no_anchor'] === bcn_breadcrumb::default_template_no_anchor) {
                 if ($opts['Hpaged_template'] === 'Page %htitle%') {
                     $opts['Hpaged_template'] = $this->opt['Hpaged_template'];
                 }
                 if ($opts['Hsearch_template'] === 'Search results for &#39;<a title="Go to the first page of search results for %title%." href="%link%" class="%type%">%htitle%</a>&#39;' || $opts['Hsearch_template'] === 'Search results for &#039;<a title="Go to the first page of search results for %title%." href="%link%" class="%type%">%htitle%</a>&#039;') {
                     $opts['Hsearch_template'] = $this->opt['Hsearch_template'];
                 }
                 if ($opts['Hsearch_template_no_anchor'] === 'Search results for &#39;%htitle%&#39;' || $opts['Hsearch_template_no_anchor'] === 'Search results for &#039;%htitle%&#039;') {
                     $opts['Hsearch_template_no_anchor'] = $this->opt['Hsearch_template_no_anchor'];
                 }
                 if ($opts['Hauthor_template'] === 'Articles by: <a title="Go to the first page of posts by %title%." href="%link%" class="%type%">%htitle%</a>') {
                     $opts['Hauthor_template'] = $this->opt['Hauthor_template'];
                 }
                 if ($opts['Hauthor_template_no_anchor'] === 'Articles by: %htitle%') {
                     $opts['Hauthor_template_no_anchor'] = $this->opt['Hauthor_template_no_anchor'];
                 }
             }
         }
         //Upgrading to 5.5.0
         if (version_compare($version, '5.5.0', '<')) {
             //Translate the old 'page' taxonomy type to BCN_POST_PARENT
             if ($this->opt['Spost_post_taxonomy_type'] === 'page') {
                 $this->opt['Spost_post_taxonomy_type'] = 'BCN_POST_PARENT';
             }
             if (!isset($this->opt['Spost_post_taxonomy_referer'])) {
                 $this->opt['bpost_post_taxonomy_referer'] = false;
             }
             //Loop through all of the post types in the array
             foreach ($wp_post_types as $post_type) {
                 //Check for non-public CPTs
                 if (!apply_filters('bcn_show_cpt_private', $post_type->public, $post_type->name)) {
                     continue;
                 }
                 //We only want custom post types
                 if (!$post_type->_builtin) {
                     //Translate the old 'page' taxonomy type to BCN_POST_PARENT
                     if ($this->opt['Spost_' . $post_type->name . '_taxonomy_type'] === 'page') {
                         $this->opt['Spost_' . $post_type->name . '_taxonomy_type'] = 'BCN_POST_PARENT';
                     }
                     //Translate the old 'date' taxonomy type to BCN_DATE
                     if ($this->opt['Spost_' . $post_type->name . '_taxonomy_type'] === 'date') {
                         $this->opt['Spost_' . $post_type->name . '_taxonomy_type'] = 'BCN_DATE';
                     }
                     if (!isset($this->opt['Spost_' . $post_type->name . '_taxonomy_referer'])) {
                         $this->opt['bpost_' . $post_type->name . '_taxonomy_referer'] = false;
                     }
                 }
             }
         }
         //S
         //Set the max title length to 20 if we are not limiting the title and the length was 0
         if (!$opts['blimit_title'] && $opts['amax_title_length'] == 0) {
             $opts['amax_title_length'] = 20;
         }
     }
     //Save the passed in opts to the object's option array
     $this->opt = $opts;
     //End with resetting up the options
     breadcrumb_navxt::setup_options($this->opt);
 }