PluginProbe
WPPizza – A Restaurant Plugin / 3.20
WPPizza – A Restaurant Plugin v3.20
trunk 2.16.11.28 3.19 3.19.1 3.19.2 3.19.3 3.19.4 3.19.5 3.19.6 3.19.7 3.19.7.1 3.19.7.2 3.19.7.3 3.19.7.4 3.19.8 3.19.8.1 3.19.8.2 3.19.8.3 3.19.9 3.20 3.20.1
wppizza / classes / markup / search.php

search.php in WPPizza – A Restaurant Plugin 3.20, at classes/markup/search.php

147 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPPIZZA_MARKUP_SEARCH Class
4 *
5 * @package WPPIZZA
6 * @subpackage WPPizza Search
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_SEARCH
19 *
20 *
21 *
22 * ================================================================================================================================= */
23
24 class WPPIZZA_MARKUP_SEARCH{
25 /* to pass onto get_search_form filter */
26 private $shortcode_attributes = array();
27
28 /******************************************************************************
29 *
30 *
31 * [construct]
32 *
33 *
34 *******************************************************************************/
35 function __construct() {
36
37 }
38
39 /******************************************************************************
40 *
41 *
42 * [methods]
43 *
44 *
45 *******************************************************************************/
46 /***************************************
47 [apply attributes]
48 ***************************************/
49 function attributes($atts=null){
50 $this->shortcode_attributes = $atts;
51 /**get markup**/
52 $markup = $this->get_markup($atts);
53 return $markup;
54 }
55
56 /***************************************
57 [markup]
58 ***************************************/
59 function get_markup($atts){
60 static $unique_id=0;$unique_id++;
61 /**only display for logged in users**/
62 if(!empty($atts['loggedinonly']) && !is_user_logged_in()){
63 return;
64 }
65 /*********************
66 set unique id
67 *********************/
68 $id = WPPIZZA_PREFIX.'-search-'.$unique_id;
69
70 /*********************
71 set classes
72 *********************/
73 $class= array();
74 $class[] = WPPIZZA_PREFIX.'-search';
75 if(!empty($atts['class'])){
76 $class[] = esc_html($atts['class']);
77 }
78 $class = trim(implode(' ', $class));
79
80 /*********************
81 add/remove filter search vars
82 add hidden wppizza input elm
83 remove filter search vars
84 reset to original or we will always have the post_type appended to the serach form once it has been run
85 *********************/
86 add_filter( 'get_search_form', array( $this, 'searchvars' ));
87 $searchform = get_search_form(false);
88 remove_filter( 'get_search_form', array( $this, 'searchvars' ));
89
90 /*********************
91 ini markup array
92 *********************/
93 $markup = array();
94 /*********************
95 get markup
96 *********************/
97 if(file_exists( WPPIZZA_TEMPLATE_DIR . '/markup/global/search.php')){
98 require(WPPIZZA_TEMPLATE_DIR.'/markup/global/search.php');
99 }else{
100 require(WPPIZZA_PATH.'templates/markup/global/search.php');
101 }
102 /*********************
103 apply filter if required and implode for output
104 *********************/
105 $markup = apply_filters('wppizza_filter_search_widget_markup', $markup, $atts, $unique_id);
106 $markup = trim(implode('', $markup));
107
108 return $markup;
109 }
110
111
112
113
114 /***************************************
115 [add set search variables]
116 ***************************************/
117 function searchvars( $markup ) {
118 global $wppizza_options;
119 $atts = $this->shortcode_attributes;
120 if(!empty($atts['include'])){
121 $val=$atts['include'];// note: even if other , comma separated, custom_post_type is set in widget, only registered post types will be included
122 $inc=explode(",", $atts['include']);
123
124 if(in_array(WPPIZZA_POST_TYPE, $inc)){
125 /**if we have set another permalink for single mnu items, rewrite this here so the query finds wppizza after all**/
126 if($wppizza_options['settings']['single_item_permalink_rewrite']!=''){
127 $key = array_search(WPPIZZA_POST_TYPE, $inc);
128 $inc[$key]=$wppizza_options['settings']['single_item_permalink_rewrite'];
129 $val=implode(",",$inc);
130 }
131 $hidden_wppizza_search_variables='<input type="hidden" name="post_type" value="'.$val.'" />'.PHP_EOL.'</form';/*leave form tag open here to allow for spaces**/
132
133 $markup = str_ireplace('</form', $hidden_wppizza_search_variables, $markup);
134 }else{
135 /**
136 even if we do not have wppizza menu items enabled in the widget, add hidden values (post types) anyway
137 (could be part of the if() above, but for sanity put it into the "else" here )
138 **/
139 $hidden_wppizza_search_variables='<input type="hidden" name="post_type" value="'.$val.'" />'.PHP_EOL.'</form';/*leave form tag open here to allow for spaces**/
140 $markup = str_ireplace('</form', $hidden_wppizza_search_variables, $markup);
141 }
142
143 }
144 return $markup;
145 }
146 }
147 ?>