| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) { |
| 3 |
die('-1'); |
| 4 |
} |
| 5 |
|
| 6 |
class QuadMenuItemSearch extends QuadMenuItem { |
| 7 |
|
| 8 |
protected $type = 'search'; |
| 9 |
var $instance = 0; |
| 10 |
|
| 11 |
function init() { |
| 12 |
$this->item->url = ''; |
| 13 |
$this->item->title = ''; |
| 14 |
$this->has_children = false; |
| 15 |
$this->has_placeholder = (bool) $this->item->placeholder; |
| 16 |
|
| 17 |
$this->item->placeholder = $this->has_placeholder ? $this->item->placeholder : esc_html__('Search', 'quadmenu'); |
| 18 |
} |
| 19 |
|
| 20 |
function get_start_el() { |
| 21 |
|
| 22 |
$item_output = ''; |
| 23 |
|
| 24 |
$this->add_item_classes(); |
| 25 |
|
| 26 |
$this->add_item_classes_prefix(); |
| 27 |
|
| 28 |
$this->add_item_classes_quadmenu(); |
| 29 |
|
| 30 |
$id = $this->get_item_id(); |
| 31 |
|
| 32 |
$class = $this->get_item_classes(); |
| 33 |
|
| 34 |
$item_output .= '<li' . $id . $class . '>'; |
| 35 |
|
| 36 |
$this->add_link_atts(); |
| 37 |
|
| 38 |
$this->add_link_atts_toggle(); |
| 39 |
|
| 40 |
$item_output .= $this->form(); |
| 41 |
|
| 42 |
return $item_output; |
| 43 |
} |
| 44 |
|
| 45 |
function get_search_toggle() { |
| 46 |
$item_output = $this->get_link(); |
| 47 |
$item_output .= $this->get_dropdown_wrap_start(); |
| 48 |
$item_output .= $this->get_search_embed(); |
| 49 |
$item_output .= $this->get_dropdown_wrap_end(); |
| 50 |
return $item_output; |
| 51 |
} |
| 52 |
|
| 53 |
function form() { |
| 54 |
|
| 55 |
$this->instance = rand(); |
| 56 |
|
| 57 |
ob_start(); |
| 58 |
?> |
| 59 |
|
| 60 |
<form role="search" method="get" id="searchform_<?php echo esc_attr($this->instance); ?>" action="<?php echo esc_url(home_url('/')); ?>"> |
| 61 |
<span class="quadmenu-item-content"> |
| 62 |
<?php echo $this->get_icon(); ?> |
| 63 |
<input type="text" id="s_<?php echo esc_attr($this->instance); ?>" name="s" value="<?php echo esc_attr(get_search_query()); ?>" placeholder="<?php echo esc_html($this->item->placeholder); ?>" /> |
| 64 |
<?php |
| 65 |
foreach ((array) $this->item->search as $search) : |
| 66 |
if ($search != ''): |
| 67 |
?> |
| 68 |
<input type="hidden" name="post_type" value="<?php echo esc_attr($search); ?>"> |
| 69 |
<?php endif; |
| 70 |
endforeach; |
| 71 |
?> |
| 72 |
</form> |
| 73 |
<?php |
| 74 |
return ob_get_clean(); |
| 75 |
} |
| 76 |
|
| 77 |
} |
| 78 |
|