| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPPIZZA_MARKUP_NAVIGATION Class |
| 4 |
* |
| 5 |
* @package WPPIZZA |
| 6 |
* @subpackage WPPizza Navigation |
| 7 |
* @copyright Copyright (c) 2015, Oliver Bach |
| 8 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 9 |
* @since 3.0 |
| 10 |
* |
| 11 |
*/ |
| 12 |
if ( ! defined( 'ABSPATH' ) ) exit;/*Exit if accessed directly*/ |
| 13 |
|
| 14 |
/* ================================================================================================================================= * |
| 15 |
* |
| 16 |
* |
| 17 |
* |
| 18 |
* CLASS - WPPIZZA_MARKUP_NAVIGATION |
| 19 |
* |
| 20 |
* |
| 21 |
* |
| 22 |
* ================================================================================================================================= */ |
| 23 |
|
| 24 |
class WPPIZZA_MARKUP_NAVIGATION{ |
| 25 |
|
| 26 |
/****************************************************************************** |
| 27 |
* |
| 28 |
* |
| 29 |
* [construct] |
| 30 |
* |
| 31 |
* |
| 32 |
*******************************************************************************/ |
| 33 |
function __construct() { |
| 34 |
} |
| 35 |
|
| 36 |
/****************************************************************************** |
| 37 |
* |
| 38 |
* |
| 39 |
* [methods] |
| 40 |
* |
| 41 |
* |
| 42 |
*******************************************************************************/ |
| 43 |
/*************************************** |
| 44 |
[apply attributes] |
| 45 |
***************************************/ |
| 46 |
function attributes($atts = null){ |
| 47 |
global $wppizza_options, $wp_query; |
| 48 |
|
| 49 |
extract(shortcode_atts(array('title' => ''), $atts)); |
| 50 |
$child_of=0; |
| 51 |
/*if only getting categories of a particular parent*/ |
| 52 |
if(isset($atts['parent'])){ |
| 53 |
$query=get_term_by('slug', $atts['parent'], WPPIZZA_TAXONOMY); |
| 54 |
if($query){ |
| 55 |
$child_of=$query->term_id; |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
$args = array( |
| 60 |
'taxonomy' => WPPIZZA_TAXONOMY, |
| 61 |
'orderby' => 'name', |
| 62 |
'show_count' => 0, // 1 for yes, 0 for no |
| 63 |
'pad_counts' => 0, // 1 for yes, 0 for no |
| 64 |
'hierarchical' => 1, // 1 for yes, 0 for no |
| 65 |
'title_li' => $title, |
| 66 |
'depth' => 0, |
| 67 |
'exclude' => (isset($atts['exclude'])) ? $atts['exclude'] : '' , |
| 68 |
'child_of' => $child_of, |
| 69 |
'show_option_none' => empty($atts['as_dropdown']) ? __('Nothing here', 'wppizza' ) : $wppizza_options['localization']['widget_navigation_dropdown_placeholder'] , |
| 70 |
'hide_empty' => 1, |
| 71 |
'echo' => 0 , // keep as variable |
| 72 |
'walker' => ( !empty($atts['as_dropdown']) ? new WPPIZZA_Walker_CategoryDropdown() : new WPPIZZA_Walker_Category() ),/* set (filterable) walkers for dropdown or (current dummy) for normal list*/ |
| 73 |
'current_category' => (isset($wp_query->query_vars['term']) ? $wp_query->query_vars['term'] : '' ), //added in 3.19.3 as custom arg |
| 74 |
); |
| 75 |
|
| 76 |
/***add a filter if required*****/ |
| 77 |
$args = apply_filters('wppizza_filter_navigation_widget_arguments', $args, $atts); |
| 78 |
|
| 79 |
/**get markup**/ |
| 80 |
$markup = $this->get_markup($args, $atts); |
| 81 |
return $markup; |
| 82 |
|
| 83 |
} |
| 84 |
|
| 85 |
/*************************************** |
| 86 |
[markup] |
| 87 |
***************************************/ |
| 88 |
function get_markup($args, $atts){ |
| 89 |
static $unique_id=0; $unique_id++; |
| 90 |
/* |
| 91 |
TODO make sure |
| 92 |
add_filter('terms_clauses', array($this,'wppizza_term_filter'), '', 1); |
| 93 |
is applied here from somewhere, probably global filters |
| 94 |
*/ |
| 95 |
|
| 96 |
/********************* |
| 97 |
set id |
| 98 |
*********************/ |
| 99 |
$id = ''.WPPIZZA_PREFIX.'-categories-'.$unique_id; |
| 100 |
|
| 101 |
/********************* |
| 102 |
set classes |
| 103 |
*********************/ |
| 104 |
$class = array(); |
| 105 |
$class[] = ''.WPPIZZA_PREFIX.'-categories'; |
| 106 |
if(!empty($atts['as_dropdown'])){ |
| 107 |
$class[] = ''.WPPIZZA_PREFIX.'-dd-categories'; |
| 108 |
} |
| 109 |
|
| 110 |
/* |
| 111 |
allow class filtering |
| 112 |
implode for output |
| 113 |
*/ |
| 114 |
$class = apply_filters('wppizza_filter_navigation_widget_class', $class, $atts, $unique_id); |
| 115 |
$class = trim(implode(' ', $class)); |
| 116 |
|
| 117 |
|
| 118 |
/********************* |
| 119 |
get markup |
| 120 |
*********************/ |
| 121 |
$markup = array(); |
| 122 |
|
| 123 |
|
| 124 |
/* |
| 125 |
as list |
| 126 |
*/ |
| 127 |
if(empty($atts['as_dropdown'])){ |
| 128 |
if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/global/navigation.list.php')){ |
| 129 |
require(WPPIZZA_TEMPLATE_DIR.'/markup/global/navigation.list.php'); |
| 130 |
}else{ |
| 131 |
require(WPPIZZA_PATH.'templates/markup/global/navigation.list.php'); |
| 132 |
} |
| 133 |
|
| 134 |
/**filterable**/ |
| 135 |
$markup = apply_filters('wppizza_filter_navigation_widget_markup', $markup, $atts, $unique_id); |
| 136 |
} |
| 137 |
|
| 138 |
/* |
| 139 |
as dropdown - using WPPIZZA_Walker_CategoryDropdown to redirect on change with links |
| 140 |
*/ |
| 141 |
if(!empty($atts['as_dropdown'])){ |
| 142 |
if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/global/navigation.dropdown.php')){ |
| 143 |
require(WPPIZZA_TEMPLATE_DIR.'/markup/global/navigation.dropdown.php'); |
| 144 |
}else{ |
| 145 |
require(WPPIZZA_PATH.'templates/markup/global/navigation.dropdown.php'); |
| 146 |
} |
| 147 |
/**filterable**/ |
| 148 |
$markup = apply_filters('wppizza_filter_navigation_widget_dropdown_markup', $markup, $atts, $unique_id); |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
/*implode for output after filter ()*/ |
| 153 |
$markup = trim(implode(PHP_EOL, $markup)); |
| 154 |
|
| 155 |
return $markup; |
| 156 |
} |
| 157 |
|
| 158 |
} |
| 159 |
?> |