/class.bcn_widget.php

  1. <?php 
  2. /**  
  3. Copyright 2009-2016 John Havlik (email : john.havlik@mtekk.us) 
  4.   
  5. This program is free software; you can redistribute it and/or modify 
  6. it under the terms of the GNU General Public License as published by 
  7. the Free Software Foundation; either version 2 of the License, or 
  8. (at your option) any later version. 
  9.   
  10. This program is distributed in the hope that it will be useful,  
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of 
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
  13. GNU General Public License for more details. 
  14.   
  15. You should have received a copy of the GNU General Public License 
  16. along with this program; if not, write to the Free Software 
  17. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 
  18. */ 
  19. require_once(dirname(__FILE__) . '/includes/block_direct_access.php'); 
  20. class bcn_widget extends WP_Widget 
  21. const version = '5.5.0'; 
  22. protected $defaults = array('title' => '', 'pretext' => '', 'type' => 'microdata', 'linked' => true, 'reverse' => false, 'front' => false); 
  23. //Default constructor 
  24. function __construct() 
  25. //@see https://core.trac.wordpress.org/ticket/10527 
  26. if(!is_textdomain_loaded('breadcrumb-navxt')) 
  27. load_plugin_textdomain('breadcrumb-navxt', false, 'breadcrumb-navxt/languages'); 
  28. $ops = array('classname' => 'widget_breadcrumb_navxt', 'description' => __('Adds a breadcrumb trail to your sidebar', 'breadcrumb-navxt')); 
  29. parent::__construct('bcn_widget', 'Breadcrumb NavXT', $ops); 
  30. function widget($args, $instance) 
  31. //Make sure we grab defaults in the case of out of date instance settings being sent 
  32. $instance = wp_parse_args((array) $instance, $this->defaults); 
  33. $instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); 
  34. $instance['pretext'] = apply_filters('widget_text', $instance['pretext'], $instance); 
  35. //A bit of a hack but we need the DB settings to know if we should exit early 
  36. $opt = get_option('bcn_options'); 
  37. //If we are on the front page and don't display on the front, return early 
  38. if($instance['front'] && is_front_page() && !(is_paged() && $opt['bpaged_display'])) 
  39. return; 
  40. //Manditory before widget junk 
  41. echo $args['before_widget']; 
  42. if(!empty($instance['title'])) 
  43. echo $args['before_title'] . $instance['title'] . $args['after_title']; 
  44. //We'll want to switch between the two breadcrumb output types 
  45. if($instance['type'] == 'list') 
  46. //Display the list output breadcrumb 
  47. echo $instance['pretext'] . '<ol class="breadcrumb_trail breadcrumbs">'; 
  48. bcn_display_list(false, $instance['linked'], $instance['reverse']); 
  49. echo '</ol>'; 
  50. else if($instance['type'] == 'microdata') 
  51. echo '<div class="breadcrumbs" vocab="http://schema.org/" typeof="BreadcrumbList">' . $instance['pretext']; 
  52. //Display the regular output breadcrumb 
  53. bcn_display(false, $instance['linked'], $instance['reverse']); 
  54. echo '</div>'; 
  55. else if($instance['type'] == 'plain') 
  56. //Display the pretext 
  57. echo $instance['pretext']; 
  58. //Display the regular output breadcrumb 
  59. bcn_display(false, $instance['linked'], $instance['reverse']); 
  60. else 
  61. //If we recieved a type that is not of the built in displays, it must be relegated to an extension plugin 
  62. do_action('bcn_widget_display_trail', $instance); 
  63. //Manditory after widget junk 
  64. echo $args['after_widget']; 
  65. function update($new_instance, $old_instance) 
  66. //Filter out anything that could be invalid 
  67. $old_instance['title'] = strip_tags($new_instance['title']); 
  68. $old_instance['pretext'] = strip_tags($new_instance['pretext']); 
  69. $old_instance['type'] = strip_tags($new_instance['type']); 
  70. $old_instance['linked'] = isset($new_instance['linked']); 
  71. $old_instance['reverse'] = isset($new_instance['reverse']); 
  72. $old_instance['front'] = isset($new_instance['front']); 
  73. return $old_instance; 
  74. function form($instance) 
  75. $instance = wp_parse_args((array) $instance, $this->defaults);?> 
  76. <p> 
  77. <label for="<?php echo $this->get_field_id('title'); ?>"> <?php _e('Title:', 'breadcrumb-navxt'); ?></label> 
  78. <input class="widefat" type="text" name="<?php echo $this->get_field_name('title'); ?>" id="<?php echo $this->get_field_id('title'); ?>" value="<?php echo esc_attr($instance['title']);?>" /> 
  79. </p> 
  80. <p> 
  81. <label for="<?php echo $this->get_field_id('pretext'); ?>"> <?php _e('Text to show before the trail:', 'breadcrumb-navxt'); ?></label> 
  82. <input class="widefat" type="text" name="<?php echo $this->get_field_name('pretext'); ?>" id="<?php echo $this->get_field_id('pretext'); ?>" value="<?php echo esc_attr($instance['pretext']);?>" /> 
  83. </p> 
  84. <p> 
  85. <label for="<?php echo $this->get_field_id('type'); ?>"> <?php _e('Output trail as:', 'breadcrumb-navxt'); ?></label> 
  86. <select name="<?php echo $this->get_field_name('type'); ?>" id="<?php echo $this->get_field_id('type'); ?>"> 
  87. <option value="list" <?php selected('list', $instance['type']);?>><?php _e('List', 'breadcrumb-navxt'); ?></option> 
  88. <option value="microdata" <?php selected('microdata', $instance['type']);?>><?php _e('Google (RDFa) Breadcrumbs', 'breadcrumb-navxt'); ?></option> 
  89. <option value="plain" <?php selected('plain', $instance['type']);?>><?php _e('Plain', 'breadcrumb-navxt'); ?></option> 
  90. <?php do_action('bcn_widget_display_types', $instance);?> 
  91. </select> 
  92. </p> 
  93. <p> 
  94. <input class="checkbox" type="checkbox" name="<?php echo $this->get_field_name('linked'); ?>" id="<?php echo $this->get_field_id('linked'); ?>" value="true" <?php checked(true, $instance['linked']);?> /> 
  95. <label for="<?php echo $this->get_field_id('linked'); ?>"> <?php _e('Link the breadcrumbs', 'breadcrumb-navxt'); ?></label><br /> 
  96. <input class="checkbox" type="checkbox" name="<?php echo $this->get_field_name('reverse'); ?>" id="<?php echo $this->get_field_id('reverse'); ?>" value="true" <?php checked(true, $instance['reverse']);?> /> 
  97. <label for="<?php echo $this->get_field_id('reverse'); ?>"> <?php _e('Reverse the order of the trail', 'breadcrumb-navxt'); ?></label><br /> 
  98. <input class="checkbox" type="checkbox" name="<?php echo $this->get_field_name('front'); ?>" id="<?php echo $this->get_field_id('front'); ?>" value="true" <?php checked(true, $instance['front']);?> /> 
  99. <label for="<?php echo $this->get_field_id('front'); ?>"> <?php _e('Hide the trail on the front page', 'breadcrumb-navxt'); ?></label><br /> 
  100. </p> 
  101. <?php 
.