@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | /** If this file is called directly, abort. */ |
4 | 4 | if (!defined('GRAVITYVIEW_DIR')) { |
5 | - exit(); |
|
5 | + exit(); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | /** |
@@ -10,17 +10,17 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class GV_License_Handler extends \GV\License_Handler |
12 | 12 | { |
13 | - /** |
|
14 | - * @param \GV\Addon_Settings $GFAddOn |
|
15 | - * |
|
16 | - * @deprecated Use \GV\License_Handler::get instead |
|
17 | - * |
|
18 | - * @return GV\License_Handler |
|
19 | - */ |
|
20 | - public static function get_instance($settings) |
|
21 | - { |
|
22 | - gravityview()->log->warning('GV_License_Handler::get_instance() is deprated in favor of \GV\License_Handler::get()'); |
|
13 | + /** |
|
14 | + * @param \GV\Addon_Settings $GFAddOn |
|
15 | + * |
|
16 | + * @deprecated Use \GV\License_Handler::get instead |
|
17 | + * |
|
18 | + * @return GV\License_Handler |
|
19 | + */ |
|
20 | + public static function get_instance($settings) |
|
21 | + { |
|
22 | + gravityview()->log->warning('GV_License_Handler::get_instance() is deprated in favor of \GV\License_Handler::get()'); |
|
23 | 23 | |
24 | - return \GV\License_Handler::get($settings); |
|
25 | - } |
|
24 | + return \GV\License_Handler::get($settings); |
|
25 | + } |
|
26 | 26 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | /** If this file is called directly, abort. */ |
4 | -if (!defined('GRAVITYVIEW_DIR')) { |
|
4 | +if ( ! defined( 'GRAVITYVIEW_DIR' ) ) { |
|
5 | 5 | exit(); |
6 | 6 | } |
7 | 7 | |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | * |
18 | 18 | * @return GV\License_Handler |
19 | 19 | */ |
20 | - public static function get_instance($settings) |
|
20 | + public static function get_instance( $settings ) |
|
21 | 21 | { |
22 | - gravityview()->log->warning('GV_License_Handler::get_instance() is deprated in favor of \GV\License_Handler::get()'); |
|
22 | + gravityview()->log->warning( 'GV_License_Handler::get_instance() is deprated in favor of \GV\License_Handler::get()' ); |
|
23 | 23 | |
24 | - return \GV\License_Handler::get($settings); |
|
24 | + return \GV\License_Handler::get( $settings ); |
|
25 | 25 | } |
26 | 26 | } |
@@ -17,8 +17,7 @@ |
||
17 | 17 | * |
18 | 18 | * @return GV\License_Handler |
19 | 19 | */ |
20 | - public static function get_instance($settings) |
|
21 | - { |
|
20 | + public static function get_instance($settings) { |
|
22 | 21 | gravityview()->log->warning('GV_License_Handler::get_instance() is deprated in favor of \GV\License_Handler::get()'); |
23 | 22 | |
24 | 23 | return \GV\License_Handler::get($settings); |
@@ -7,72 +7,72 @@ |
||
7 | 7 | */ |
8 | 8 | class GravityView_Widget_Page_Links extends \GV\Widget |
9 | 9 | { |
10 | - public $icon = 'dashicons-controls-forward'; |
|
10 | + public $icon = 'dashicons-controls-forward'; |
|
11 | 11 | |
12 | - protected $show_on_single = false; |
|
12 | + protected $show_on_single = false; |
|
13 | 13 | |
14 | - public function __construct() |
|
15 | - { |
|
16 | - $this->widget_description = __('Links to multiple pages of results.', 'gravityview'); |
|
14 | + public function __construct() |
|
15 | + { |
|
16 | + $this->widget_description = __('Links to multiple pages of results.', 'gravityview'); |
|
17 | 17 | |
18 | - $default_values = ['header' => 1, 'footer' => 1]; |
|
19 | - $settings = ['show_all' => [ |
|
20 | - 'type' => 'checkbox', |
|
21 | - 'label' => __('Show each page number', 'gravityview'), |
|
22 | - 'desc' => __('Show every page number instead of summary (eg: 1 2 3 ... 8 »)', 'gravityview'), |
|
23 | - 'value' => false, |
|
24 | - ]]; |
|
25 | - parent::__construct(__('Page Links', 'gravityview'), 'page_links', $default_values, $settings); |
|
26 | - } |
|
18 | + $default_values = ['header' => 1, 'footer' => 1]; |
|
19 | + $settings = ['show_all' => [ |
|
20 | + 'type' => 'checkbox', |
|
21 | + 'label' => __('Show each page number', 'gravityview'), |
|
22 | + 'desc' => __('Show every page number instead of summary (eg: 1 2 3 ... 8 »)', 'gravityview'), |
|
23 | + 'value' => false, |
|
24 | + ]]; |
|
25 | + parent::__construct(__('Page Links', 'gravityview'), 'page_links', $default_values, $settings); |
|
26 | + } |
|
27 | 27 | |
28 | - public function render_frontend($widget_args, $content = '', $context = '') |
|
29 | - { |
|
30 | - $gravityview_view = GravityView_View::getInstance(); |
|
28 | + public function render_frontend($widget_args, $content = '', $context = '') |
|
29 | + { |
|
30 | + $gravityview_view = GravityView_View::getInstance(); |
|
31 | 31 | |
32 | - if (!$this->pre_render_frontend()) { |
|
33 | - return; |
|
34 | - } |
|
32 | + if (!$this->pre_render_frontend()) { |
|
33 | + return; |
|
34 | + } |
|
35 | 35 | |
36 | - $atts = shortcode_atts([ |
|
37 | - 'page_size' => \GV\Utils::get($gravityview_view->paging, 'page_size'), |
|
38 | - 'total' => $gravityview_view->total_entries, |
|
39 | - 'show_all' => !empty($this->settings['show_all']['default']), |
|
40 | - 'current' => (int) \GV\Utils::_GET('pagenum', 1), |
|
41 | - ], $widget_args, 'gravityview_widget_page_links'); |
|
36 | + $atts = shortcode_atts([ |
|
37 | + 'page_size' => \GV\Utils::get($gravityview_view->paging, 'page_size'), |
|
38 | + 'total' => $gravityview_view->total_entries, |
|
39 | + 'show_all' => !empty($this->settings['show_all']['default']), |
|
40 | + 'current' => (int) \GV\Utils::_GET('pagenum', 1), |
|
41 | + ], $widget_args, 'gravityview_widget_page_links'); |
|
42 | 42 | |
43 | - $page_link_args = [ |
|
44 | - 'base' => add_query_arg('pagenum', '%#%', gv_directory_link()), |
|
45 | - 'format' => '&pagenum=%#%', |
|
46 | - 'add_args' => [], // |
|
47 | - 'prev_text' => '«', |
|
48 | - 'next_text' => '»', |
|
49 | - 'type' => 'list', |
|
50 | - 'end_size' => 1, |
|
51 | - 'mid_size' => 2, |
|
52 | - 'total' => empty($atts['page_size']) ? 0 : ceil($atts['total'] / $atts['page_size']), |
|
53 | - 'current' => $atts['current'], |
|
54 | - 'show_all' => !empty($atts['show_all']), // to be available at backoffice |
|
55 | - ]; |
|
43 | + $page_link_args = [ |
|
44 | + 'base' => add_query_arg('pagenum', '%#%', gv_directory_link()), |
|
45 | + 'format' => '&pagenum=%#%', |
|
46 | + 'add_args' => [], // |
|
47 | + 'prev_text' => '«', |
|
48 | + 'next_text' => '»', |
|
49 | + 'type' => 'list', |
|
50 | + 'end_size' => 1, |
|
51 | + 'mid_size' => 2, |
|
52 | + 'total' => empty($atts['page_size']) ? 0 : ceil($atts['total'] / $atts['page_size']), |
|
53 | + 'current' => $atts['current'], |
|
54 | + 'show_all' => !empty($atts['show_all']), // to be available at backoffice |
|
55 | + ]; |
|
56 | 56 | |
57 | - /** |
|
58 | - * @filter `gravityview_page_links_args` Filter the pagination options |
|
59 | - * |
|
60 | - * @since 1.1.4 |
|
61 | - * |
|
62 | - * @param array $page_link_args Array of arguments for the `paginate_links()` function. [Read more about `paginate_links()`](http://developer.wordpress.org/reference/functions/paginate_links/) |
|
63 | - */ |
|
64 | - $page_link_args = apply_filters('gravityview_page_links_args', $page_link_args); |
|
57 | + /** |
|
58 | + * @filter `gravityview_page_links_args` Filter the pagination options |
|
59 | + * |
|
60 | + * @since 1.1.4 |
|
61 | + * |
|
62 | + * @param array $page_link_args Array of arguments for the `paginate_links()` function. [Read more about `paginate_links()`](http://developer.wordpress.org/reference/functions/paginate_links/) |
|
63 | + */ |
|
64 | + $page_link_args = apply_filters('gravityview_page_links_args', $page_link_args); |
|
65 | 65 | |
66 | - $page_links = paginate_links($page_link_args); |
|
66 | + $page_links = paginate_links($page_link_args); |
|
67 | 67 | |
68 | - if (!empty($page_links)) { |
|
69 | - $class = !empty($widget_args['custom_class']) ? $widget_args['custom_class'] : ''; |
|
70 | - $class = gravityview_sanitize_html_class('gv-widget-page-links '.$class); |
|
71 | - echo '<div class="'.$class.'">'.$page_links.'</div>'; |
|
72 | - } else { |
|
73 | - gravityview()->log->debug('No page links; paginate_links() returned empty response.'); |
|
74 | - } |
|
75 | - } |
|
68 | + if (!empty($page_links)) { |
|
69 | + $class = !empty($widget_args['custom_class']) ? $widget_args['custom_class'] : ''; |
|
70 | + $class = gravityview_sanitize_html_class('gv-widget-page-links '.$class); |
|
71 | + echo '<div class="'.$class.'">'.$page_links.'</div>'; |
|
72 | + } else { |
|
73 | + gravityview()->log->debug('No page links; paginate_links() returned empty response.'); |
|
74 | + } |
|
75 | + } |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | new GravityView_Widget_Page_Links(); |
@@ -13,45 +13,45 @@ discard block |
||
13 | 13 | |
14 | 14 | public function __construct() |
15 | 15 | { |
16 | - $this->widget_description = __('Links to multiple pages of results.', 'gravityview'); |
|
16 | + $this->widget_description = __( 'Links to multiple pages of results.', 'gravityview' ); |
|
17 | 17 | |
18 | - $default_values = ['header' => 1, 'footer' => 1]; |
|
19 | - $settings = ['show_all' => [ |
|
18 | + $default_values = [ 'header' => 1, 'footer' => 1 ]; |
|
19 | + $settings = [ 'show_all' => [ |
|
20 | 20 | 'type' => 'checkbox', |
21 | - 'label' => __('Show each page number', 'gravityview'), |
|
22 | - 'desc' => __('Show every page number instead of summary (eg: 1 2 3 ... 8 »)', 'gravityview'), |
|
21 | + 'label' => __( 'Show each page number', 'gravityview' ), |
|
22 | + 'desc' => __( 'Show every page number instead of summary (eg: 1 2 3 ... 8 »)', 'gravityview' ), |
|
23 | 23 | 'value' => false, |
24 | - ]]; |
|
25 | - parent::__construct(__('Page Links', 'gravityview'), 'page_links', $default_values, $settings); |
|
24 | + ] ]; |
|
25 | + parent::__construct( __( 'Page Links', 'gravityview' ), 'page_links', $default_values, $settings ); |
|
26 | 26 | } |
27 | 27 | |
28 | - public function render_frontend($widget_args, $content = '', $context = '') |
|
28 | + public function render_frontend( $widget_args, $content = '', $context = '' ) |
|
29 | 29 | { |
30 | 30 | $gravityview_view = GravityView_View::getInstance(); |
31 | 31 | |
32 | - if (!$this->pre_render_frontend()) { |
|
32 | + if ( ! $this->pre_render_frontend() ) { |
|
33 | 33 | return; |
34 | 34 | } |
35 | 35 | |
36 | - $atts = shortcode_atts([ |
|
37 | - 'page_size' => \GV\Utils::get($gravityview_view->paging, 'page_size'), |
|
36 | + $atts = shortcode_atts( [ |
|
37 | + 'page_size' => \GV\Utils::get( $gravityview_view->paging, 'page_size' ), |
|
38 | 38 | 'total' => $gravityview_view->total_entries, |
39 | - 'show_all' => !empty($this->settings['show_all']['default']), |
|
40 | - 'current' => (int) \GV\Utils::_GET('pagenum', 1), |
|
41 | - ], $widget_args, 'gravityview_widget_page_links'); |
|
39 | + 'show_all' => ! empty( $this->settings[ 'show_all' ][ 'default' ] ), |
|
40 | + 'current' => (int)\GV\Utils::_GET( 'pagenum', 1 ), |
|
41 | + ], $widget_args, 'gravityview_widget_page_links' ); |
|
42 | 42 | |
43 | 43 | $page_link_args = [ |
44 | - 'base' => add_query_arg('pagenum', '%#%', gv_directory_link()), |
|
44 | + 'base' => add_query_arg( 'pagenum', '%#%', gv_directory_link() ), |
|
45 | 45 | 'format' => '&pagenum=%#%', |
46 | - 'add_args' => [], // |
|
46 | + 'add_args' => [ ], // |
|
47 | 47 | 'prev_text' => '«', |
48 | 48 | 'next_text' => '»', |
49 | 49 | 'type' => 'list', |
50 | 50 | 'end_size' => 1, |
51 | 51 | 'mid_size' => 2, |
52 | - 'total' => empty($atts['page_size']) ? 0 : ceil($atts['total'] / $atts['page_size']), |
|
53 | - 'current' => $atts['current'], |
|
54 | - 'show_all' => !empty($atts['show_all']), // to be available at backoffice |
|
52 | + 'total' => empty( $atts[ 'page_size' ] ) ? 0 : ceil( $atts[ 'total' ] / $atts[ 'page_size' ] ), |
|
53 | + 'current' => $atts[ 'current' ], |
|
54 | + 'show_all' => ! empty( $atts[ 'show_all' ] ), // to be available at backoffice |
|
55 | 55 | ]; |
56 | 56 | |
57 | 57 | /** |
@@ -61,16 +61,16 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @param array $page_link_args Array of arguments for the `paginate_links()` function. [Read more about `paginate_links()`](http://developer.wordpress.org/reference/functions/paginate_links/) |
63 | 63 | */ |
64 | - $page_link_args = apply_filters('gravityview_page_links_args', $page_link_args); |
|
64 | + $page_link_args = apply_filters( 'gravityview_page_links_args', $page_link_args ); |
|
65 | 65 | |
66 | - $page_links = paginate_links($page_link_args); |
|
66 | + $page_links = paginate_links( $page_link_args ); |
|
67 | 67 | |
68 | - if (!empty($page_links)) { |
|
69 | - $class = !empty($widget_args['custom_class']) ? $widget_args['custom_class'] : ''; |
|
70 | - $class = gravityview_sanitize_html_class('gv-widget-page-links '.$class); |
|
71 | - echo '<div class="'.$class.'">'.$page_links.'</div>'; |
|
68 | + if ( ! empty( $page_links ) ) { |
|
69 | + $class = ! empty( $widget_args[ 'custom_class' ] ) ? $widget_args[ 'custom_class' ] : ''; |
|
70 | + $class = gravityview_sanitize_html_class( 'gv-widget-page-links ' . $class ); |
|
71 | + echo '<div class="' . $class . '">' . $page_links . '</div>'; |
|
72 | 72 | } else { |
73 | - gravityview()->log->debug('No page links; paginate_links() returned empty response.'); |
|
73 | + gravityview()->log->debug( 'No page links; paginate_links() returned empty response.' ); |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | } |
@@ -11,8 +11,7 @@ discard block |
||
11 | 11 | |
12 | 12 | protected $show_on_single = false; |
13 | 13 | |
14 | - public function __construct() |
|
15 | - { |
|
14 | + public function __construct() { |
|
16 | 15 | $this->widget_description = __('Links to multiple pages of results.', 'gravityview'); |
17 | 16 | |
18 | 17 | $default_values = ['header' => 1, 'footer' => 1]; |
@@ -25,8 +24,7 @@ discard block |
||
25 | 24 | parent::__construct(__('Page Links', 'gravityview'), 'page_links', $default_values, $settings); |
26 | 25 | } |
27 | 26 | |
28 | - public function render_frontend($widget_args, $content = '', $context = '') |
|
29 | - { |
|
27 | + public function render_frontend($widget_args, $content = '', $context = '') { |
|
30 | 28 | $gravityview_view = GravityView_View::getInstance(); |
31 | 29 | |
32 | 30 | if (!$this->pre_render_frontend()) { |
@@ -9,95 +9,95 @@ |
||
9 | 9 | */ |
10 | 10 | class GravityView_Widget_Custom_Content extends \GV\Widget |
11 | 11 | { |
12 | - public $icon = 'dashicons-editor-code'; |
|
13 | - |
|
14 | - /** |
|
15 | - * Does this get displayed on a single entry? |
|
16 | - * |
|
17 | - * @var bool |
|
18 | - */ |
|
19 | - protected $show_on_single = false; |
|
20 | - |
|
21 | - public function __construct() |
|
22 | - { |
|
23 | - $this->widget_description = __('Insert custom text or HTML as a widget', 'gravityview'); |
|
24 | - |
|
25 | - $default_values = [ |
|
26 | - 'header' => 1, |
|
27 | - 'footer' => 1, |
|
28 | - ]; |
|
29 | - |
|
30 | - $settings = [ |
|
31 | - 'content' => [ |
|
32 | - 'type' => 'textarea', |
|
33 | - 'label' => __('Custom Content', 'gravityview'), |
|
34 | - 'desc' => __('Enter text or HTML. Also supports shortcodes.', 'gravityview'), |
|
35 | - 'value' => '', |
|
36 | - 'class' => 'code', |
|
37 | - 'merge_tags' => false, |
|
38 | - 'show_all_fields' => true, // Show the `{all_fields}` and `{pricing_fields}` merge tags |
|
39 | - ], |
|
40 | - 'wpautop' => [ |
|
41 | - 'type' => 'checkbox', |
|
42 | - 'label' => __('Automatically add paragraphs to content', 'gravityview'), |
|
43 | - 'tooltip' => __('Wrap each block of text in an HTML paragraph tag (recommended for text).', 'gravityview'), |
|
44 | - 'value' => '', |
|
45 | - ], |
|
46 | - 'admin_label' => [ |
|
47 | - 'type' => 'text', |
|
48 | - 'class' => 'widefat', |
|
49 | - 'label' => __('Admin Label', 'gravityview'), |
|
50 | - 'desc' => __('A label that is only shown in the GravityView View configuration screen.', 'gravityview'), |
|
51 | - 'value' => '', |
|
52 | - ], |
|
53 | - ]; |
|
54 | - |
|
55 | - parent::__construct(__('Custom Content', 'gravityview'), 'custom_content', $default_values, $settings); |
|
56 | - } |
|
57 | - |
|
58 | - public function render_frontend($widget_args, $content = '', $context = '') |
|
59 | - { |
|
60 | - if (!$this->pre_render_frontend()) { |
|
61 | - return; |
|
62 | - } |
|
63 | - |
|
64 | - if (!empty($widget_args['title'])) { |
|
65 | - echo $widget_args['title']; |
|
66 | - } |
|
67 | - |
|
68 | - // Make sure the class is loaded in DataTables |
|
69 | - if (!class_exists('GFFormDisplay')) { |
|
70 | - include_once GFCommon::get_base_path().'/form_display.php'; |
|
71 | - } |
|
72 | - |
|
73 | - $widget_args['content'] = trim(rtrim(\GV\Utils::get($widget_args, 'content'))); |
|
74 | - |
|
75 | - // No custom content |
|
76 | - if (empty($widget_args['content'])) { |
|
77 | - gravityview()->log->debug('No content.'); |
|
78 | - |
|
79 | - return; |
|
80 | - } |
|
81 | - |
|
82 | - // Add paragraphs? |
|
83 | - if (!empty($widget_args['wpautop'])) { |
|
84 | - $widget_args['content'] = wpautop($widget_args['content']); |
|
85 | - } |
|
86 | - |
|
87 | - $content = $widget_args['content']; |
|
88 | - |
|
89 | - $content = GravityView_Merge_Tags::replace_variables($content, [], [], false, true, false); |
|
90 | - |
|
91 | - // Enqueue scripts needed for Gravity Form display, if form shortcode exists. |
|
92 | - // Also runs `do_shortcode()` |
|
93 | - $content = GFCommon::gform_do_shortcode($content); |
|
94 | - |
|
95 | - // Add custom class |
|
96 | - $class = !empty($widget_args['custom_class']) ? $widget_args['custom_class'] : ''; |
|
97 | - $class = gravityview_sanitize_html_class($class); |
|
98 | - |
|
99 | - echo '<div class="gv-widget-custom-content '.$class.'">'.$content.'</div>'; |
|
100 | - } |
|
12 | + public $icon = 'dashicons-editor-code'; |
|
13 | + |
|
14 | + /** |
|
15 | + * Does this get displayed on a single entry? |
|
16 | + * |
|
17 | + * @var bool |
|
18 | + */ |
|
19 | + protected $show_on_single = false; |
|
20 | + |
|
21 | + public function __construct() |
|
22 | + { |
|
23 | + $this->widget_description = __('Insert custom text or HTML as a widget', 'gravityview'); |
|
24 | + |
|
25 | + $default_values = [ |
|
26 | + 'header' => 1, |
|
27 | + 'footer' => 1, |
|
28 | + ]; |
|
29 | + |
|
30 | + $settings = [ |
|
31 | + 'content' => [ |
|
32 | + 'type' => 'textarea', |
|
33 | + 'label' => __('Custom Content', 'gravityview'), |
|
34 | + 'desc' => __('Enter text or HTML. Also supports shortcodes.', 'gravityview'), |
|
35 | + 'value' => '', |
|
36 | + 'class' => 'code', |
|
37 | + 'merge_tags' => false, |
|
38 | + 'show_all_fields' => true, // Show the `{all_fields}` and `{pricing_fields}` merge tags |
|
39 | + ], |
|
40 | + 'wpautop' => [ |
|
41 | + 'type' => 'checkbox', |
|
42 | + 'label' => __('Automatically add paragraphs to content', 'gravityview'), |
|
43 | + 'tooltip' => __('Wrap each block of text in an HTML paragraph tag (recommended for text).', 'gravityview'), |
|
44 | + 'value' => '', |
|
45 | + ], |
|
46 | + 'admin_label' => [ |
|
47 | + 'type' => 'text', |
|
48 | + 'class' => 'widefat', |
|
49 | + 'label' => __('Admin Label', 'gravityview'), |
|
50 | + 'desc' => __('A label that is only shown in the GravityView View configuration screen.', 'gravityview'), |
|
51 | + 'value' => '', |
|
52 | + ], |
|
53 | + ]; |
|
54 | + |
|
55 | + parent::__construct(__('Custom Content', 'gravityview'), 'custom_content', $default_values, $settings); |
|
56 | + } |
|
57 | + |
|
58 | + public function render_frontend($widget_args, $content = '', $context = '') |
|
59 | + { |
|
60 | + if (!$this->pre_render_frontend()) { |
|
61 | + return; |
|
62 | + } |
|
63 | + |
|
64 | + if (!empty($widget_args['title'])) { |
|
65 | + echo $widget_args['title']; |
|
66 | + } |
|
67 | + |
|
68 | + // Make sure the class is loaded in DataTables |
|
69 | + if (!class_exists('GFFormDisplay')) { |
|
70 | + include_once GFCommon::get_base_path().'/form_display.php'; |
|
71 | + } |
|
72 | + |
|
73 | + $widget_args['content'] = trim(rtrim(\GV\Utils::get($widget_args, 'content'))); |
|
74 | + |
|
75 | + // No custom content |
|
76 | + if (empty($widget_args['content'])) { |
|
77 | + gravityview()->log->debug('No content.'); |
|
78 | + |
|
79 | + return; |
|
80 | + } |
|
81 | + |
|
82 | + // Add paragraphs? |
|
83 | + if (!empty($widget_args['wpautop'])) { |
|
84 | + $widget_args['content'] = wpautop($widget_args['content']); |
|
85 | + } |
|
86 | + |
|
87 | + $content = $widget_args['content']; |
|
88 | + |
|
89 | + $content = GravityView_Merge_Tags::replace_variables($content, [], [], false, true, false); |
|
90 | + |
|
91 | + // Enqueue scripts needed for Gravity Form display, if form shortcode exists. |
|
92 | + // Also runs `do_shortcode()` |
|
93 | + $content = GFCommon::gform_do_shortcode($content); |
|
94 | + |
|
95 | + // Add custom class |
|
96 | + $class = !empty($widget_args['custom_class']) ? $widget_args['custom_class'] : ''; |
|
97 | + $class = gravityview_sanitize_html_class($class); |
|
98 | + |
|
99 | + echo '<div class="gv-widget-custom-content '.$class.'">'.$content.'</div>'; |
|
100 | + } |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | new GravityView_Widget_Custom_Content(); |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | |
21 | 21 | public function __construct() |
22 | 22 | { |
23 | - $this->widget_description = __('Insert custom text or HTML as a widget', 'gravityview'); |
|
23 | + $this->widget_description = __( 'Insert custom text or HTML as a widget', 'gravityview' ); |
|
24 | 24 | |
25 | 25 | $default_values = [ |
26 | 26 | 'header' => 1, |
@@ -30,8 +30,8 @@ discard block |
||
30 | 30 | $settings = [ |
31 | 31 | 'content' => [ |
32 | 32 | 'type' => 'textarea', |
33 | - 'label' => __('Custom Content', 'gravityview'), |
|
34 | - 'desc' => __('Enter text or HTML. Also supports shortcodes.', 'gravityview'), |
|
33 | + 'label' => __( 'Custom Content', 'gravityview' ), |
|
34 | + 'desc' => __( 'Enter text or HTML. Also supports shortcodes.', 'gravityview' ), |
|
35 | 35 | 'value' => '', |
36 | 36 | 'class' => 'code', |
37 | 37 | 'merge_tags' => false, |
@@ -39,64 +39,64 @@ discard block |
||
39 | 39 | ], |
40 | 40 | 'wpautop' => [ |
41 | 41 | 'type' => 'checkbox', |
42 | - 'label' => __('Automatically add paragraphs to content', 'gravityview'), |
|
43 | - 'tooltip' => __('Wrap each block of text in an HTML paragraph tag (recommended for text).', 'gravityview'), |
|
42 | + 'label' => __( 'Automatically add paragraphs to content', 'gravityview' ), |
|
43 | + 'tooltip' => __( 'Wrap each block of text in an HTML paragraph tag (recommended for text).', 'gravityview' ), |
|
44 | 44 | 'value' => '', |
45 | 45 | ], |
46 | 46 | 'admin_label' => [ |
47 | 47 | 'type' => 'text', |
48 | 48 | 'class' => 'widefat', |
49 | - 'label' => __('Admin Label', 'gravityview'), |
|
50 | - 'desc' => __('A label that is only shown in the GravityView View configuration screen.', 'gravityview'), |
|
49 | + 'label' => __( 'Admin Label', 'gravityview' ), |
|
50 | + 'desc' => __( 'A label that is only shown in the GravityView View configuration screen.', 'gravityview' ), |
|
51 | 51 | 'value' => '', |
52 | 52 | ], |
53 | 53 | ]; |
54 | 54 | |
55 | - parent::__construct(__('Custom Content', 'gravityview'), 'custom_content', $default_values, $settings); |
|
55 | + parent::__construct( __( 'Custom Content', 'gravityview' ), 'custom_content', $default_values, $settings ); |
|
56 | 56 | } |
57 | 57 | |
58 | - public function render_frontend($widget_args, $content = '', $context = '') |
|
58 | + public function render_frontend( $widget_args, $content = '', $context = '' ) |
|
59 | 59 | { |
60 | - if (!$this->pre_render_frontend()) { |
|
60 | + if ( ! $this->pre_render_frontend() ) { |
|
61 | 61 | return; |
62 | 62 | } |
63 | 63 | |
64 | - if (!empty($widget_args['title'])) { |
|
65 | - echo $widget_args['title']; |
|
64 | + if ( ! empty( $widget_args[ 'title' ] ) ) { |
|
65 | + echo $widget_args[ 'title' ]; |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | // Make sure the class is loaded in DataTables |
69 | - if (!class_exists('GFFormDisplay')) { |
|
70 | - include_once GFCommon::get_base_path().'/form_display.php'; |
|
69 | + if ( ! class_exists( 'GFFormDisplay' ) ) { |
|
70 | + include_once GFCommon::get_base_path() . '/form_display.php'; |
|
71 | 71 | } |
72 | 72 | |
73 | - $widget_args['content'] = trim(rtrim(\GV\Utils::get($widget_args, 'content'))); |
|
73 | + $widget_args[ 'content' ] = trim( rtrim( \GV\Utils::get( $widget_args, 'content' ) ) ); |
|
74 | 74 | |
75 | 75 | // No custom content |
76 | - if (empty($widget_args['content'])) { |
|
77 | - gravityview()->log->debug('No content.'); |
|
76 | + if ( empty( $widget_args[ 'content' ] ) ) { |
|
77 | + gravityview()->log->debug( 'No content.' ); |
|
78 | 78 | |
79 | 79 | return; |
80 | 80 | } |
81 | 81 | |
82 | 82 | // Add paragraphs? |
83 | - if (!empty($widget_args['wpautop'])) { |
|
84 | - $widget_args['content'] = wpautop($widget_args['content']); |
|
83 | + if ( ! empty( $widget_args[ 'wpautop' ] ) ) { |
|
84 | + $widget_args[ 'content' ] = wpautop( $widget_args[ 'content' ] ); |
|
85 | 85 | } |
86 | 86 | |
87 | - $content = $widget_args['content']; |
|
87 | + $content = $widget_args[ 'content' ]; |
|
88 | 88 | |
89 | - $content = GravityView_Merge_Tags::replace_variables($content, [], [], false, true, false); |
|
89 | + $content = GravityView_Merge_Tags::replace_variables( $content, [ ], [ ], false, true, false ); |
|
90 | 90 | |
91 | 91 | // Enqueue scripts needed for Gravity Form display, if form shortcode exists. |
92 | 92 | // Also runs `do_shortcode()` |
93 | - $content = GFCommon::gform_do_shortcode($content); |
|
93 | + $content = GFCommon::gform_do_shortcode( $content ); |
|
94 | 94 | |
95 | 95 | // Add custom class |
96 | - $class = !empty($widget_args['custom_class']) ? $widget_args['custom_class'] : ''; |
|
97 | - $class = gravityview_sanitize_html_class($class); |
|
96 | + $class = ! empty( $widget_args[ 'custom_class' ] ) ? $widget_args[ 'custom_class' ] : ''; |
|
97 | + $class = gravityview_sanitize_html_class( $class ); |
|
98 | 98 | |
99 | - echo '<div class="gv-widget-custom-content '.$class.'">'.$content.'</div>'; |
|
99 | + echo '<div class="gv-widget-custom-content ' . $class . '">' . $content . '</div>'; |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 |
@@ -18,8 +18,7 @@ discard block |
||
18 | 18 | */ |
19 | 19 | protected $show_on_single = false; |
20 | 20 | |
21 | - public function __construct() |
|
22 | - { |
|
21 | + public function __construct() { |
|
23 | 22 | $this->widget_description = __('Insert custom text or HTML as a widget', 'gravityview'); |
24 | 23 | |
25 | 24 | $default_values = [ |
@@ -55,8 +54,7 @@ discard block |
||
55 | 54 | parent::__construct(__('Custom Content', 'gravityview'), 'custom_content', $default_values, $settings); |
56 | 55 | } |
57 | 56 | |
58 | - public function render_frontend($widget_args, $content = '', $context = '') |
|
59 | - { |
|
57 | + public function render_frontend($widget_args, $content = '', $context = '') { |
|
60 | 58 | if (!$this->pre_render_frontend()) { |
61 | 59 | return; |
62 | 60 | } |
@@ -16,18 +16,18 @@ |
||
16 | 16 | */ |
17 | 17 | function gravityview_register_gravityview_widgets() |
18 | 18 | { |
19 | - include_once GRAVITYVIEW_DIR.'includes/widgets/class-gravityview-widget.php'; |
|
19 | + include_once GRAVITYVIEW_DIR.'includes/widgets/class-gravityview-widget.php'; |
|
20 | 20 | |
21 | - include_once GRAVITYVIEW_DIR.'includes/widgets/search-widget/class-search-widget.php'; |
|
22 | - include_once GRAVITYVIEW_DIR.'includes/widgets/class-gravityview-widget-custom-content.php'; |
|
23 | - include_once GRAVITYVIEW_DIR.'includes/widgets/class-gravityview-widget-gravityforms.php'; |
|
24 | - include_once GRAVITYVIEW_DIR.'includes/widgets/class-gravityview-widget-page-size.php'; |
|
25 | - include_once GRAVITYVIEW_DIR.'includes/widgets/class-gravityview-widget-pagination-info.php'; |
|
26 | - include_once GRAVITYVIEW_DIR.'includes/widgets/class-gravityview-widget-page-links.php'; |
|
21 | + include_once GRAVITYVIEW_DIR.'includes/widgets/search-widget/class-search-widget.php'; |
|
22 | + include_once GRAVITYVIEW_DIR.'includes/widgets/class-gravityview-widget-custom-content.php'; |
|
23 | + include_once GRAVITYVIEW_DIR.'includes/widgets/class-gravityview-widget-gravityforms.php'; |
|
24 | + include_once GRAVITYVIEW_DIR.'includes/widgets/class-gravityview-widget-page-size.php'; |
|
25 | + include_once GRAVITYVIEW_DIR.'includes/widgets/class-gravityview-widget-pagination-info.php'; |
|
26 | + include_once GRAVITYVIEW_DIR.'includes/widgets/class-gravityview-widget-page-links.php'; |
|
27 | 27 | |
28 | - if (class_exists('GFPolls')) { |
|
29 | - include_once GRAVITYVIEW_DIR.'includes/widgets/poll/class-gravityview-widget-poll.php'; |
|
30 | - } |
|
28 | + if (class_exists('GFPolls')) { |
|
29 | + include_once GRAVITYVIEW_DIR.'includes/widgets/poll/class-gravityview-widget-poll.php'; |
|
30 | + } |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | // Load default widgets |
@@ -16,19 +16,19 @@ |
||
16 | 16 | */ |
17 | 17 | function gravityview_register_gravityview_widgets() |
18 | 18 | { |
19 | - include_once GRAVITYVIEW_DIR.'includes/widgets/class-gravityview-widget.php'; |
|
19 | + include_once GRAVITYVIEW_DIR . 'includes/widgets/class-gravityview-widget.php'; |
|
20 | 20 | |
21 | - include_once GRAVITYVIEW_DIR.'includes/widgets/search-widget/class-search-widget.php'; |
|
22 | - include_once GRAVITYVIEW_DIR.'includes/widgets/class-gravityview-widget-custom-content.php'; |
|
23 | - include_once GRAVITYVIEW_DIR.'includes/widgets/class-gravityview-widget-gravityforms.php'; |
|
24 | - include_once GRAVITYVIEW_DIR.'includes/widgets/class-gravityview-widget-page-size.php'; |
|
25 | - include_once GRAVITYVIEW_DIR.'includes/widgets/class-gravityview-widget-pagination-info.php'; |
|
26 | - include_once GRAVITYVIEW_DIR.'includes/widgets/class-gravityview-widget-page-links.php'; |
|
21 | + include_once GRAVITYVIEW_DIR . 'includes/widgets/search-widget/class-search-widget.php'; |
|
22 | + include_once GRAVITYVIEW_DIR . 'includes/widgets/class-gravityview-widget-custom-content.php'; |
|
23 | + include_once GRAVITYVIEW_DIR . 'includes/widgets/class-gravityview-widget-gravityforms.php'; |
|
24 | + include_once GRAVITYVIEW_DIR . 'includes/widgets/class-gravityview-widget-page-size.php'; |
|
25 | + include_once GRAVITYVIEW_DIR . 'includes/widgets/class-gravityview-widget-pagination-info.php'; |
|
26 | + include_once GRAVITYVIEW_DIR . 'includes/widgets/class-gravityview-widget-page-links.php'; |
|
27 | 27 | |
28 | - if (class_exists('GFPolls')) { |
|
29 | - include_once GRAVITYVIEW_DIR.'includes/widgets/poll/class-gravityview-widget-poll.php'; |
|
28 | + if ( class_exists( 'GFPolls' ) ) { |
|
29 | + include_once GRAVITYVIEW_DIR . 'includes/widgets/poll/class-gravityview-widget-poll.php'; |
|
30 | 30 | } |
31 | 31 | } |
32 | 32 | |
33 | 33 | // Load default widgets |
34 | -add_action('init', 'gravityview_register_gravityview_widgets', 11); |
|
34 | +add_action( 'init', 'gravityview_register_gravityview_widgets', 11 ); |
@@ -14,8 +14,7 @@ |
||
14 | 14 | * |
15 | 15 | * @return void |
16 | 16 | */ |
17 | -function gravityview_register_gravityview_widgets() |
|
18 | -{ |
|
17 | +function gravityview_register_gravityview_widgets() { |
|
19 | 18 | include_once GRAVITYVIEW_DIR.'includes/widgets/class-gravityview-widget.php'; |
20 | 19 | |
21 | 20 | include_once GRAVITYVIEW_DIR.'includes/widgets/search-widget/class-search-widget.php'; |
@@ -9,203 +9,203 @@ |
||
9 | 9 | */ |
10 | 10 | class GravityView_Widget_Poll extends GravityView_Widget |
11 | 11 | { |
12 | - /** |
|
13 | - * Does this get displayed on a single entry? |
|
14 | - * |
|
15 | - * @var bool |
|
16 | - */ |
|
17 | - protected $show_on_single = false; |
|
18 | - |
|
19 | - /** |
|
20 | - * @todo add support for specifying poll field to display (via AJAX in field settings) |
|
21 | - * |
|
22 | - * @since 1.8 |
|
23 | - */ |
|
24 | - public function __construct() |
|
25 | - { |
|
26 | - $this->widget_id = 'poll'; |
|
27 | - $this->widget_description = __('Displays the results of Poll Fields that exist in the form.', 'gravityview'); |
|
28 | - $this->widget_subtitle = sprintf(_x('Note: this will display poll results for %sall form entries%s, not only the entries displayed in the View.', 'The string placeholders are for emphasis HTML', 'gravityview'), '<em>', '</em>'); |
|
29 | - |
|
30 | - $default_values = [ |
|
31 | - 'header' => 1, |
|
32 | - 'footer' => 1, |
|
33 | - ]; |
|
34 | - |
|
35 | - $settings = [ |
|
36 | - 'percentages' => [ |
|
37 | - 'label' => __('Display Percentages', 'gravityview'), |
|
38 | - 'type' => 'checkbox', |
|
39 | - 'value' => true, |
|
40 | - 'tooltip' => __('Display results percentages as part of results? Supported values are: true, false. Defaults to "true".', 'gravityview'), |
|
41 | - ], |
|
42 | - 'counts' => [ |
|
43 | - 'label' => __('Display Counts', 'gravityview'), |
|
44 | - 'type' => 'checkbox', |
|
45 | - 'value' => true, |
|
46 | - 'tooltip' => __('Display number of times each choice has been selected when displaying results? Supported values are: true, false. Defaults to "true".', 'gravityview'), |
|
47 | - ], |
|
48 | - 'style' => [ |
|
49 | - 'type' => 'select', |
|
50 | - 'label' => __('Style', 'gravityview'), |
|
51 | - 'tooltip' => __('The Polls Add-On currently supports 4 built in styles: red, green, orange, blue. Defaults to "green".', 'gravityview'), |
|
52 | - 'value' => 'green', |
|
53 | - 'choices' => [ |
|
54 | - 'green' => __('Green', 'gravityview'), |
|
55 | - 'blue' => __('Blue', 'gravityview'), |
|
56 | - 'red' => __('Red', 'gravityview'), |
|
57 | - 'orange' => __('Orange', 'gravityview'), |
|
58 | - ], |
|
59 | - ], |
|
60 | - ]; |
|
61 | - |
|
62 | - if (!$this->is_registered()) { |
|
63 | - // frontend - add template path |
|
64 | - add_filter('gravityview_template_paths', [$this, 'add_template_path']); |
|
65 | - } |
|
66 | - |
|
67 | - parent::__construct(__('Poll Results', 'gravityview'), null, $default_values, $settings); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Include this extension templates path. |
|
72 | - * |
|
73 | - * @since 1.8 |
|
74 | - * |
|
75 | - * @param array $file_paths List of template paths ordered |
|
76 | - */ |
|
77 | - public function add_template_path($file_paths) |
|
78 | - { |
|
79 | - $index = 126; |
|
80 | - |
|
81 | - // Index 100 is the default GravityView template path. |
|
82 | - $file_paths[$index] = plugin_dir_path(__FILE__).'templates/'; |
|
83 | - |
|
84 | - return $file_paths; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Load the scripts and styles needed for the display of the poll widget. |
|
89 | - * |
|
90 | - * @since 1.8 |
|
91 | - */ |
|
92 | - private function enqueue_scripts_and_styles() |
|
93 | - { |
|
94 | - $GFPolls = GFPolls::get_instance(); |
|
95 | - |
|
96 | - wp_enqueue_script('gpoll_js', $GFPolls->get_base_url().'/js/gpoll.js', ['jquery'], $GFPolls->_version); |
|
97 | - |
|
98 | - $GFPolls->localize_scripts(); |
|
99 | - |
|
100 | - wp_enqueue_style('gpoll_css', $GFPolls->get_base_url().'/css/gpoll.css', null, $GFPolls->_version); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @inheritDoc |
|
105 | - * |
|
106 | - * @since 1.8 |
|
107 | - */ |
|
108 | - public function pre_render_frontend() |
|
109 | - { |
|
110 | - if (!class_exists('GFPolls')) { |
|
111 | - gravityview()->log->error('Poll Widget not displayed; the Poll Addon is not loaded'); |
|
112 | - |
|
113 | - return false; |
|
114 | - } |
|
115 | - |
|
116 | - $view = gravityview()->views->get(); |
|
117 | - |
|
118 | - $poll_fields = [$view->form->form['id'] => GFCommon::get_fields_by_type($view->form, ['poll'])]; |
|
119 | - |
|
120 | - foreach ($view->joins as $join) { |
|
121 | - $poll_fields[$join->join_on->form['id']] = GFCommon::get_fields_by_type($join->join_on->form, ['poll']); |
|
122 | - } |
|
123 | - |
|
124 | - $poll_fields = array_filter($poll_fields); |
|
125 | - |
|
126 | - if (empty($poll_fields)) { |
|
127 | - gravityview()->log->error('Poll Widget not displayed; there are no poll fields for the form'); |
|
128 | - |
|
129 | - return false; |
|
130 | - } |
|
131 | - |
|
132 | - $this->poll_fields = $poll_fields; |
|
133 | - |
|
134 | - return parent::pre_render_frontend(); |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Get the display settings for the Poll widget. |
|
139 | - * |
|
140 | - * @param array $widget_settings Settings for the Poll widget |
|
141 | - * |
|
142 | - * @return array Final poll widget settings |
|
143 | - */ |
|
144 | - public function get_frontend_settings($widget_settings) |
|
145 | - { |
|
146 | - $default_settings = [ |
|
147 | - 'field' => 0, |
|
148 | - 'style' => 'green', |
|
149 | - 'percentages' => true, |
|
150 | - 'counts' => true, |
|
151 | - ]; |
|
152 | - |
|
153 | - $settings = wp_parse_args($widget_settings, $default_settings); |
|
154 | - |
|
155 | - /** |
|
156 | - * @filter `gravityview/widget/poll/settings` Modify display settings for the poll widget |
|
157 | - * |
|
158 | - * @since 1.8 |
|
159 | - * |
|
160 | - * @param array $settings Settings with `field`, `style`, `percentages` and `counts` keys |
|
161 | - */ |
|
162 | - $settings = apply_filters('gravityview/widget/poll/settings', $settings); |
|
163 | - |
|
164 | - return $settings; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Render the widget. |
|
169 | - * |
|
170 | - * @see https://www.gravityhelp.com/documentation/article/polls-add-on/ |
|
171 | - * @since 1.8 |
|
172 | - */ |
|
173 | - public function render_frontend($widget_args, $content = '', $context = '') |
|
174 | - { |
|
175 | - if (!$this->pre_render_frontend()) { |
|
176 | - return; |
|
177 | - } |
|
12 | + /** |
|
13 | + * Does this get displayed on a single entry? |
|
14 | + * |
|
15 | + * @var bool |
|
16 | + */ |
|
17 | + protected $show_on_single = false; |
|
18 | + |
|
19 | + /** |
|
20 | + * @todo add support for specifying poll field to display (via AJAX in field settings) |
|
21 | + * |
|
22 | + * @since 1.8 |
|
23 | + */ |
|
24 | + public function __construct() |
|
25 | + { |
|
26 | + $this->widget_id = 'poll'; |
|
27 | + $this->widget_description = __('Displays the results of Poll Fields that exist in the form.', 'gravityview'); |
|
28 | + $this->widget_subtitle = sprintf(_x('Note: this will display poll results for %sall form entries%s, not only the entries displayed in the View.', 'The string placeholders are for emphasis HTML', 'gravityview'), '<em>', '</em>'); |
|
29 | + |
|
30 | + $default_values = [ |
|
31 | + 'header' => 1, |
|
32 | + 'footer' => 1, |
|
33 | + ]; |
|
34 | + |
|
35 | + $settings = [ |
|
36 | + 'percentages' => [ |
|
37 | + 'label' => __('Display Percentages', 'gravityview'), |
|
38 | + 'type' => 'checkbox', |
|
39 | + 'value' => true, |
|
40 | + 'tooltip' => __('Display results percentages as part of results? Supported values are: true, false. Defaults to "true".', 'gravityview'), |
|
41 | + ], |
|
42 | + 'counts' => [ |
|
43 | + 'label' => __('Display Counts', 'gravityview'), |
|
44 | + 'type' => 'checkbox', |
|
45 | + 'value' => true, |
|
46 | + 'tooltip' => __('Display number of times each choice has been selected when displaying results? Supported values are: true, false. Defaults to "true".', 'gravityview'), |
|
47 | + ], |
|
48 | + 'style' => [ |
|
49 | + 'type' => 'select', |
|
50 | + 'label' => __('Style', 'gravityview'), |
|
51 | + 'tooltip' => __('The Polls Add-On currently supports 4 built in styles: red, green, orange, blue. Defaults to "green".', 'gravityview'), |
|
52 | + 'value' => 'green', |
|
53 | + 'choices' => [ |
|
54 | + 'green' => __('Green', 'gravityview'), |
|
55 | + 'blue' => __('Blue', 'gravityview'), |
|
56 | + 'red' => __('Red', 'gravityview'), |
|
57 | + 'orange' => __('Orange', 'gravityview'), |
|
58 | + ], |
|
59 | + ], |
|
60 | + ]; |
|
61 | + |
|
62 | + if (!$this->is_registered()) { |
|
63 | + // frontend - add template path |
|
64 | + add_filter('gravityview_template_paths', [$this, 'add_template_path']); |
|
65 | + } |
|
66 | + |
|
67 | + parent::__construct(__('Poll Results', 'gravityview'), null, $default_values, $settings); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Include this extension templates path. |
|
72 | + * |
|
73 | + * @since 1.8 |
|
74 | + * |
|
75 | + * @param array $file_paths List of template paths ordered |
|
76 | + */ |
|
77 | + public function add_template_path($file_paths) |
|
78 | + { |
|
79 | + $index = 126; |
|
80 | + |
|
81 | + // Index 100 is the default GravityView template path. |
|
82 | + $file_paths[$index] = plugin_dir_path(__FILE__).'templates/'; |
|
83 | + |
|
84 | + return $file_paths; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Load the scripts and styles needed for the display of the poll widget. |
|
89 | + * |
|
90 | + * @since 1.8 |
|
91 | + */ |
|
92 | + private function enqueue_scripts_and_styles() |
|
93 | + { |
|
94 | + $GFPolls = GFPolls::get_instance(); |
|
95 | + |
|
96 | + wp_enqueue_script('gpoll_js', $GFPolls->get_base_url().'/js/gpoll.js', ['jquery'], $GFPolls->_version); |
|
97 | + |
|
98 | + $GFPolls->localize_scripts(); |
|
99 | + |
|
100 | + wp_enqueue_style('gpoll_css', $GFPolls->get_base_url().'/css/gpoll.css', null, $GFPolls->_version); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @inheritDoc |
|
105 | + * |
|
106 | + * @since 1.8 |
|
107 | + */ |
|
108 | + public function pre_render_frontend() |
|
109 | + { |
|
110 | + if (!class_exists('GFPolls')) { |
|
111 | + gravityview()->log->error('Poll Widget not displayed; the Poll Addon is not loaded'); |
|
112 | + |
|
113 | + return false; |
|
114 | + } |
|
115 | + |
|
116 | + $view = gravityview()->views->get(); |
|
117 | + |
|
118 | + $poll_fields = [$view->form->form['id'] => GFCommon::get_fields_by_type($view->form, ['poll'])]; |
|
119 | + |
|
120 | + foreach ($view->joins as $join) { |
|
121 | + $poll_fields[$join->join_on->form['id']] = GFCommon::get_fields_by_type($join->join_on->form, ['poll']); |
|
122 | + } |
|
123 | + |
|
124 | + $poll_fields = array_filter($poll_fields); |
|
125 | + |
|
126 | + if (empty($poll_fields)) { |
|
127 | + gravityview()->log->error('Poll Widget not displayed; there are no poll fields for the form'); |
|
128 | + |
|
129 | + return false; |
|
130 | + } |
|
131 | + |
|
132 | + $this->poll_fields = $poll_fields; |
|
133 | + |
|
134 | + return parent::pre_render_frontend(); |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Get the display settings for the Poll widget. |
|
139 | + * |
|
140 | + * @param array $widget_settings Settings for the Poll widget |
|
141 | + * |
|
142 | + * @return array Final poll widget settings |
|
143 | + */ |
|
144 | + public function get_frontend_settings($widget_settings) |
|
145 | + { |
|
146 | + $default_settings = [ |
|
147 | + 'field' => 0, |
|
148 | + 'style' => 'green', |
|
149 | + 'percentages' => true, |
|
150 | + 'counts' => true, |
|
151 | + ]; |
|
152 | + |
|
153 | + $settings = wp_parse_args($widget_settings, $default_settings); |
|
154 | + |
|
155 | + /** |
|
156 | + * @filter `gravityview/widget/poll/settings` Modify display settings for the poll widget |
|
157 | + * |
|
158 | + * @since 1.8 |
|
159 | + * |
|
160 | + * @param array $settings Settings with `field`, `style`, `percentages` and `counts` keys |
|
161 | + */ |
|
162 | + $settings = apply_filters('gravityview/widget/poll/settings', $settings); |
|
163 | + |
|
164 | + return $settings; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Render the widget. |
|
169 | + * |
|
170 | + * @see https://www.gravityhelp.com/documentation/article/polls-add-on/ |
|
171 | + * @since 1.8 |
|
172 | + */ |
|
173 | + public function render_frontend($widget_args, $content = '', $context = '') |
|
174 | + { |
|
175 | + if (!$this->pre_render_frontend()) { |
|
176 | + return; |
|
177 | + } |
|
178 | 178 | |
179 | - // Make sure the class is loaded in DataTables |
|
180 | - if (!class_exists('GFFormDisplay')) { |
|
181 | - include_once GFCommon::get_base_path().'/form_display.php'; |
|
182 | - } |
|
179 | + // Make sure the class is loaded in DataTables |
|
180 | + if (!class_exists('GFFormDisplay')) { |
|
181 | + include_once GFCommon::get_base_path().'/form_display.php'; |
|
182 | + } |
|
183 | 183 | |
184 | - $this->enqueue_scripts_and_styles(); |
|
185 | - |
|
186 | - $settings = $this->get_frontend_settings($widget_args); |
|
187 | - |
|
188 | - $percentages = empty($settings['percentages']) ? 'false' : 'true'; |
|
189 | - |
|
190 | - $counts = empty($settings['counts']) ? 'false' : 'true'; |
|
184 | + $this->enqueue_scripts_and_styles(); |
|
185 | + |
|
186 | + $settings = $this->get_frontend_settings($widget_args); |
|
187 | + |
|
188 | + $percentages = empty($settings['percentages']) ? 'false' : 'true'; |
|
189 | + |
|
190 | + $counts = empty($settings['counts']) ? 'false' : 'true'; |
|
191 | 191 | |
192 | - if (!empty($settings['field'])) { |
|
193 | - $merge_tag = sprintf('{gpoll: field="%d" style="%s" percentages="%s" counts="%s"}', $settings['field'], $settings['style'], $percentages, $counts); |
|
194 | - } else { |
|
195 | - $merge_tag = sprintf('{all_poll_results: style="%s" percentages="%s" counts="%s"}', $settings['style'], $percentages, $counts); |
|
196 | - } |
|
192 | + if (!empty($settings['field'])) { |
|
193 | + $merge_tag = sprintf('{gpoll: field="%d" style="%s" percentages="%s" counts="%s"}', $settings['field'], $settings['style'], $percentages, $counts); |
|
194 | + } else { |
|
195 | + $merge_tag = sprintf('{all_poll_results: style="%s" percentages="%s" counts="%s"}', $settings['style'], $percentages, $counts); |
|
196 | + } |
|
197 | 197 | |
198 | - $gravityview_view = GravityView_View::getInstance(); |
|
198 | + $gravityview_view = GravityView_View::getInstance(); |
|
199 | 199 | |
200 | - $gravityview_view->poll_merge_tag = $merge_tag; |
|
201 | - |
|
202 | - $gravityview_view->poll_settings = $settings; |
|
203 | - $gravityview_view->poll_fields = $this->poll_fields; |
|
204 | - |
|
205 | - $gravityview_view->render('widget', 'poll', false); |
|
200 | + $gravityview_view->poll_merge_tag = $merge_tag; |
|
201 | + |
|
202 | + $gravityview_view->poll_settings = $settings; |
|
203 | + $gravityview_view->poll_fields = $this->poll_fields; |
|
204 | + |
|
205 | + $gravityview_view->render('widget', 'poll', false); |
|
206 | 206 | |
207 | - unset($gravityview_view->poll_merge_tag, $gravityview_view->poll_settings, $gravityview_view->poll_form, $gravityview_view->poll_fields); |
|
208 | - } |
|
207 | + unset($gravityview_view->poll_merge_tag, $gravityview_view->poll_settings, $gravityview_view->poll_form, $gravityview_view->poll_fields); |
|
208 | + } |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | new GravityView_Widget_Poll(); |
@@ -24,8 +24,8 @@ discard block |
||
24 | 24 | public function __construct() |
25 | 25 | { |
26 | 26 | $this->widget_id = 'poll'; |
27 | - $this->widget_description = __('Displays the results of Poll Fields that exist in the form.', 'gravityview'); |
|
28 | - $this->widget_subtitle = sprintf(_x('Note: this will display poll results for %sall form entries%s, not only the entries displayed in the View.', 'The string placeholders are for emphasis HTML', 'gravityview'), '<em>', '</em>'); |
|
27 | + $this->widget_description = __( 'Displays the results of Poll Fields that exist in the form.', 'gravityview' ); |
|
28 | + $this->widget_subtitle = sprintf( _x( 'Note: this will display poll results for %sall form entries%s, not only the entries displayed in the View.', 'The string placeholders are for emphasis HTML', 'gravityview' ), '<em>', '</em>' ); |
|
29 | 29 | |
30 | 30 | $default_values = [ |
31 | 31 | 'header' => 1, |
@@ -34,37 +34,37 @@ discard block |
||
34 | 34 | |
35 | 35 | $settings = [ |
36 | 36 | 'percentages' => [ |
37 | - 'label' => __('Display Percentages', 'gravityview'), |
|
37 | + 'label' => __( 'Display Percentages', 'gravityview' ), |
|
38 | 38 | 'type' => 'checkbox', |
39 | 39 | 'value' => true, |
40 | - 'tooltip' => __('Display results percentages as part of results? Supported values are: true, false. Defaults to "true".', 'gravityview'), |
|
40 | + 'tooltip' => __( 'Display results percentages as part of results? Supported values are: true, false. Defaults to "true".', 'gravityview' ), |
|
41 | 41 | ], |
42 | 42 | 'counts' => [ |
43 | - 'label' => __('Display Counts', 'gravityview'), |
|
43 | + 'label' => __( 'Display Counts', 'gravityview' ), |
|
44 | 44 | 'type' => 'checkbox', |
45 | 45 | 'value' => true, |
46 | - 'tooltip' => __('Display number of times each choice has been selected when displaying results? Supported values are: true, false. Defaults to "true".', 'gravityview'), |
|
46 | + 'tooltip' => __( 'Display number of times each choice has been selected when displaying results? Supported values are: true, false. Defaults to "true".', 'gravityview' ), |
|
47 | 47 | ], |
48 | 48 | 'style' => [ |
49 | 49 | 'type' => 'select', |
50 | - 'label' => __('Style', 'gravityview'), |
|
51 | - 'tooltip' => __('The Polls Add-On currently supports 4 built in styles: red, green, orange, blue. Defaults to "green".', 'gravityview'), |
|
50 | + 'label' => __( 'Style', 'gravityview' ), |
|
51 | + 'tooltip' => __( 'The Polls Add-On currently supports 4 built in styles: red, green, orange, blue. Defaults to "green".', 'gravityview' ), |
|
52 | 52 | 'value' => 'green', |
53 | 53 | 'choices' => [ |
54 | - 'green' => __('Green', 'gravityview'), |
|
55 | - 'blue' => __('Blue', 'gravityview'), |
|
56 | - 'red' => __('Red', 'gravityview'), |
|
57 | - 'orange' => __('Orange', 'gravityview'), |
|
54 | + 'green' => __( 'Green', 'gravityview' ), |
|
55 | + 'blue' => __( 'Blue', 'gravityview' ), |
|
56 | + 'red' => __( 'Red', 'gravityview' ), |
|
57 | + 'orange' => __( 'Orange', 'gravityview' ), |
|
58 | 58 | ], |
59 | 59 | ], |
60 | 60 | ]; |
61 | 61 | |
62 | - if (!$this->is_registered()) { |
|
62 | + if ( ! $this->is_registered() ) { |
|
63 | 63 | // frontend - add template path |
64 | - add_filter('gravityview_template_paths', [$this, 'add_template_path']); |
|
64 | + add_filter( 'gravityview_template_paths', [ $this, 'add_template_path' ] ); |
|
65 | 65 | } |
66 | 66 | |
67 | - parent::__construct(__('Poll Results', 'gravityview'), null, $default_values, $settings); |
|
67 | + parent::__construct( __( 'Poll Results', 'gravityview' ), null, $default_values, $settings ); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -74,12 +74,12 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @param array $file_paths List of template paths ordered |
76 | 76 | */ |
77 | - public function add_template_path($file_paths) |
|
77 | + public function add_template_path( $file_paths ) |
|
78 | 78 | { |
79 | 79 | $index = 126; |
80 | 80 | |
81 | 81 | // Index 100 is the default GravityView template path. |
82 | - $file_paths[$index] = plugin_dir_path(__FILE__).'templates/'; |
|
82 | + $file_paths[ $index ] = plugin_dir_path( __FILE__ ) . 'templates/'; |
|
83 | 83 | |
84 | 84 | return $file_paths; |
85 | 85 | } |
@@ -93,11 +93,11 @@ discard block |
||
93 | 93 | { |
94 | 94 | $GFPolls = GFPolls::get_instance(); |
95 | 95 | |
96 | - wp_enqueue_script('gpoll_js', $GFPolls->get_base_url().'/js/gpoll.js', ['jquery'], $GFPolls->_version); |
|
96 | + wp_enqueue_script( 'gpoll_js', $GFPolls->get_base_url() . '/js/gpoll.js', [ 'jquery' ], $GFPolls->_version ); |
|
97 | 97 | |
98 | 98 | $GFPolls->localize_scripts(); |
99 | 99 | |
100 | - wp_enqueue_style('gpoll_css', $GFPolls->get_base_url().'/css/gpoll.css', null, $GFPolls->_version); |
|
100 | + wp_enqueue_style( 'gpoll_css', $GFPolls->get_base_url() . '/css/gpoll.css', null, $GFPolls->_version ); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -107,24 +107,24 @@ discard block |
||
107 | 107 | */ |
108 | 108 | public function pre_render_frontend() |
109 | 109 | { |
110 | - if (!class_exists('GFPolls')) { |
|
111 | - gravityview()->log->error('Poll Widget not displayed; the Poll Addon is not loaded'); |
|
110 | + if ( ! class_exists( 'GFPolls' ) ) { |
|
111 | + gravityview()->log->error( 'Poll Widget not displayed; the Poll Addon is not loaded' ); |
|
112 | 112 | |
113 | 113 | return false; |
114 | 114 | } |
115 | 115 | |
116 | 116 | $view = gravityview()->views->get(); |
117 | 117 | |
118 | - $poll_fields = [$view->form->form['id'] => GFCommon::get_fields_by_type($view->form, ['poll'])]; |
|
118 | + $poll_fields = [ $view->form->form[ 'id' ] => GFCommon::get_fields_by_type( $view->form, [ 'poll' ] ) ]; |
|
119 | 119 | |
120 | - foreach ($view->joins as $join) { |
|
121 | - $poll_fields[$join->join_on->form['id']] = GFCommon::get_fields_by_type($join->join_on->form, ['poll']); |
|
120 | + foreach ( $view->joins as $join ) { |
|
121 | + $poll_fields[ $join->join_on->form[ 'id' ] ] = GFCommon::get_fields_by_type( $join->join_on->form, [ 'poll' ] ); |
|
122 | 122 | } |
123 | 123 | |
124 | - $poll_fields = array_filter($poll_fields); |
|
124 | + $poll_fields = array_filter( $poll_fields ); |
|
125 | 125 | |
126 | - if (empty($poll_fields)) { |
|
127 | - gravityview()->log->error('Poll Widget not displayed; there are no poll fields for the form'); |
|
126 | + if ( empty( $poll_fields ) ) { |
|
127 | + gravityview()->log->error( 'Poll Widget not displayed; there are no poll fields for the form' ); |
|
128 | 128 | |
129 | 129 | return false; |
130 | 130 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * |
142 | 142 | * @return array Final poll widget settings |
143 | 143 | */ |
144 | - public function get_frontend_settings($widget_settings) |
|
144 | + public function get_frontend_settings( $widget_settings ) |
|
145 | 145 | { |
146 | 146 | $default_settings = [ |
147 | 147 | 'field' => 0, |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | 'counts' => true, |
151 | 151 | ]; |
152 | 152 | |
153 | - $settings = wp_parse_args($widget_settings, $default_settings); |
|
153 | + $settings = wp_parse_args( $widget_settings, $default_settings ); |
|
154 | 154 | |
155 | 155 | /** |
156 | 156 | * @filter `gravityview/widget/poll/settings` Modify display settings for the poll widget |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | * |
160 | 160 | * @param array $settings Settings with `field`, `style`, `percentages` and `counts` keys |
161 | 161 | */ |
162 | - $settings = apply_filters('gravityview/widget/poll/settings', $settings); |
|
162 | + $settings = apply_filters( 'gravityview/widget/poll/settings', $settings ); |
|
163 | 163 | |
164 | 164 | return $settings; |
165 | 165 | } |
@@ -170,29 +170,29 @@ discard block |
||
170 | 170 | * @see https://www.gravityhelp.com/documentation/article/polls-add-on/ |
171 | 171 | * @since 1.8 |
172 | 172 | */ |
173 | - public function render_frontend($widget_args, $content = '', $context = '') |
|
173 | + public function render_frontend( $widget_args, $content = '', $context = '' ) |
|
174 | 174 | { |
175 | - if (!$this->pre_render_frontend()) { |
|
175 | + if ( ! $this->pre_render_frontend() ) { |
|
176 | 176 | return; |
177 | 177 | } |
178 | 178 | |
179 | 179 | // Make sure the class is loaded in DataTables |
180 | - if (!class_exists('GFFormDisplay')) { |
|
181 | - include_once GFCommon::get_base_path().'/form_display.php'; |
|
180 | + if ( ! class_exists( 'GFFormDisplay' ) ) { |
|
181 | + include_once GFCommon::get_base_path() . '/form_display.php'; |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | $this->enqueue_scripts_and_styles(); |
185 | 185 | |
186 | - $settings = $this->get_frontend_settings($widget_args); |
|
186 | + $settings = $this->get_frontend_settings( $widget_args ); |
|
187 | 187 | |
188 | - $percentages = empty($settings['percentages']) ? 'false' : 'true'; |
|
188 | + $percentages = empty( $settings[ 'percentages' ] ) ? 'false' : 'true'; |
|
189 | 189 | |
190 | - $counts = empty($settings['counts']) ? 'false' : 'true'; |
|
190 | + $counts = empty( $settings[ 'counts' ] ) ? 'false' : 'true'; |
|
191 | 191 | |
192 | - if (!empty($settings['field'])) { |
|
193 | - $merge_tag = sprintf('{gpoll: field="%d" style="%s" percentages="%s" counts="%s"}', $settings['field'], $settings['style'], $percentages, $counts); |
|
192 | + if ( ! empty( $settings[ 'field' ] ) ) { |
|
193 | + $merge_tag = sprintf( '{gpoll: field="%d" style="%s" percentages="%s" counts="%s"}', $settings[ 'field' ], $settings[ 'style' ], $percentages, $counts ); |
|
194 | 194 | } else { |
195 | - $merge_tag = sprintf('{all_poll_results: style="%s" percentages="%s" counts="%s"}', $settings['style'], $percentages, $counts); |
|
195 | + $merge_tag = sprintf( '{all_poll_results: style="%s" percentages="%s" counts="%s"}', $settings[ 'style' ], $percentages, $counts ); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | $gravityview_view = GravityView_View::getInstance(); |
@@ -202,9 +202,9 @@ discard block |
||
202 | 202 | $gravityview_view->poll_settings = $settings; |
203 | 203 | $gravityview_view->poll_fields = $this->poll_fields; |
204 | 204 | |
205 | - $gravityview_view->render('widget', 'poll', false); |
|
205 | + $gravityview_view->render( 'widget', 'poll', false ); |
|
206 | 206 | |
207 | - unset($gravityview_view->poll_merge_tag, $gravityview_view->poll_settings, $gravityview_view->poll_form, $gravityview_view->poll_fields); |
|
207 | + unset( $gravityview_view->poll_merge_tag, $gravityview_view->poll_settings, $gravityview_view->poll_form, $gravityview_view->poll_fields ); |
|
208 | 208 | } |
209 | 209 | } |
210 | 210 |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | * @extends GravityView_Widget |
9 | 9 | */ |
10 | -class GravityView_Widget_Poll extends GravityView_Widget |
|
11 | -{ |
|
10 | +class GravityView_Widget_Poll extends GravityView_Widget { |
|
12 | 11 | /** |
13 | 12 | * Does this get displayed on a single entry? |
14 | 13 | * |
@@ -21,8 +20,7 @@ discard block |
||
21 | 20 | * |
22 | 21 | * @since 1.8 |
23 | 22 | */ |
24 | - public function __construct() |
|
25 | - { |
|
23 | + public function __construct() { |
|
26 | 24 | $this->widget_id = 'poll'; |
27 | 25 | $this->widget_description = __('Displays the results of Poll Fields that exist in the form.', 'gravityview'); |
28 | 26 | $this->widget_subtitle = sprintf(_x('Note: this will display poll results for %sall form entries%s, not only the entries displayed in the View.', 'The string placeholders are for emphasis HTML', 'gravityview'), '<em>', '</em>'); |
@@ -74,8 +72,7 @@ discard block |
||
74 | 72 | * |
75 | 73 | * @param array $file_paths List of template paths ordered |
76 | 74 | */ |
77 | - public function add_template_path($file_paths) |
|
78 | - { |
|
75 | + public function add_template_path($file_paths) { |
|
79 | 76 | $index = 126; |
80 | 77 | |
81 | 78 | // Index 100 is the default GravityView template path. |
@@ -89,8 +86,7 @@ discard block |
||
89 | 86 | * |
90 | 87 | * @since 1.8 |
91 | 88 | */ |
92 | - private function enqueue_scripts_and_styles() |
|
93 | - { |
|
89 | + private function enqueue_scripts_and_styles() { |
|
94 | 90 | $GFPolls = GFPolls::get_instance(); |
95 | 91 | |
96 | 92 | wp_enqueue_script('gpoll_js', $GFPolls->get_base_url().'/js/gpoll.js', ['jquery'], $GFPolls->_version); |
@@ -105,8 +101,7 @@ discard block |
||
105 | 101 | * |
106 | 102 | * @since 1.8 |
107 | 103 | */ |
108 | - public function pre_render_frontend() |
|
109 | - { |
|
104 | + public function pre_render_frontend() { |
|
110 | 105 | if (!class_exists('GFPolls')) { |
111 | 106 | gravityview()->log->error('Poll Widget not displayed; the Poll Addon is not loaded'); |
112 | 107 | |
@@ -141,8 +136,7 @@ discard block |
||
141 | 136 | * |
142 | 137 | * @return array Final poll widget settings |
143 | 138 | */ |
144 | - public function get_frontend_settings($widget_settings) |
|
145 | - { |
|
139 | + public function get_frontend_settings($widget_settings) { |
|
146 | 140 | $default_settings = [ |
147 | 141 | 'field' => 0, |
148 | 142 | 'style' => 'green', |
@@ -170,8 +164,7 @@ discard block |
||
170 | 164 | * @see https://www.gravityhelp.com/documentation/article/polls-add-on/ |
171 | 165 | * @since 1.8 |
172 | 166 | */ |
173 | - public function render_frontend($widget_args, $content = '', $context = '') |
|
174 | - { |
|
167 | + public function render_frontend($widget_args, $content = '', $context = '') { |
|
175 | 168 | if (!$this->pre_render_frontend()) { |
176 | 169 | return; |
177 | 170 | } |
@@ -8,11 +8,11 @@ |
||
8 | 8 | |
9 | 9 | foreach ($gravityview_view->poll_fields as $form_id => $poll_field) { |
10 | 10 | |
11 | - /** |
|
12 | - * Merge tag is already generated by the class. |
|
13 | - * Access array of settings to generate your own using the $gravityview_view->poll_settings variable. |
|
14 | - */ |
|
15 | - $merge_tag = $gravityview_view->poll_merge_tag; |
|
11 | + /** |
|
12 | + * Merge tag is already generated by the class. |
|
13 | + * Access array of settings to generate your own using the $gravityview_view->poll_settings variable. |
|
14 | + */ |
|
15 | + $merge_tag = $gravityview_view->poll_merge_tag; |
|
16 | 16 | |
17 | - echo GFCommon::replace_variables($merge_tag, GFAPI::get_form($form_id), ['id' => 0]); |
|
17 | + echo GFCommon::replace_variables($merge_tag, GFAPI::get_form($form_id), ['id' => 0]); |
|
18 | 18 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | */ |
7 | 7 | $gravityview_view = GravityView_View::getInstance(); |
8 | 8 | |
9 | -foreach ($gravityview_view->poll_fields as $form_id => $poll_field) { |
|
9 | +foreach ( $gravityview_view->poll_fields as $form_id => $poll_field ) { |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Merge tag is already generated by the class. |
@@ -14,5 +14,5 @@ discard block |
||
14 | 14 | */ |
15 | 15 | $merge_tag = $gravityview_view->poll_merge_tag; |
16 | 16 | |
17 | - echo GFCommon::replace_variables($merge_tag, GFAPI::get_form($form_id), ['id' => 0]); |
|
17 | + echo GFCommon::replace_variables( $merge_tag, GFAPI::get_form( $form_id ), [ 'id' => 0 ] ); |
|
18 | 18 | } |
@@ -7,68 +7,68 @@ |
||
7 | 7 | */ |
8 | 8 | class GravityView_Widget_Pagination_Info extends \GV\Widget |
9 | 9 | { |
10 | - public $icon = 'dashicons-info'; |
|
10 | + public $icon = 'dashicons-info'; |
|
11 | 11 | |
12 | - /** |
|
13 | - * Does this get displayed on a single entry? |
|
14 | - * |
|
15 | - * @var bool |
|
16 | - */ |
|
17 | - protected $show_on_single = false; |
|
12 | + /** |
|
13 | + * Does this get displayed on a single entry? |
|
14 | + * |
|
15 | + * @var bool |
|
16 | + */ |
|
17 | + protected $show_on_single = false; |
|
18 | 18 | |
19 | - public function __construct() |
|
20 | - { |
|
21 | - $this->widget_description = __('Summary of the number of visible entries out of the total results.', 'gravityview'); |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + $this->widget_description = __('Summary of the number of visible entries out of the total results.', 'gravityview'); |
|
22 | 22 | |
23 | - $default_values = [ |
|
24 | - 'header' => 1, |
|
25 | - 'footer' => 1, |
|
26 | - ]; |
|
23 | + $default_values = [ |
|
24 | + 'header' => 1, |
|
25 | + 'footer' => 1, |
|
26 | + ]; |
|
27 | 27 | |
28 | - $settings = []; |
|
28 | + $settings = []; |
|
29 | 29 | |
30 | - parent::__construct(__('Show Pagination Info', 'gravityview'), 'page_info', $default_values, $settings); |
|
31 | - } |
|
30 | + parent::__construct(__('Show Pagination Info', 'gravityview'), 'page_info', $default_values, $settings); |
|
31 | + } |
|
32 | 32 | |
33 | - public function render_frontend($widget_args, $content = '', $context = '') |
|
34 | - { |
|
35 | - $gravityview_view = GravityView_View::getInstance(); |
|
33 | + public function render_frontend($widget_args, $content = '', $context = '') |
|
34 | + { |
|
35 | + $gravityview_view = GravityView_View::getInstance(); |
|
36 | 36 | |
37 | - if (!$this->pre_render_frontend()) { |
|
38 | - return; |
|
39 | - } |
|
37 | + if (!$this->pre_render_frontend()) { |
|
38 | + return; |
|
39 | + } |
|
40 | 40 | |
41 | - if (!empty($widget_args['title'])) { |
|
42 | - echo $widget_args['title']; |
|
43 | - } |
|
41 | + if (!empty($widget_args['title'])) { |
|
42 | + echo $widget_args['title']; |
|
43 | + } |
|
44 | 44 | |
45 | - $pagination_counts = $gravityview_view->getPaginationCounts(); |
|
45 | + $pagination_counts = $gravityview_view->getPaginationCounts(); |
|
46 | 46 | |
47 | - $total = $first = $last = null; |
|
47 | + $total = $first = $last = null; |
|
48 | 48 | |
49 | - $output = ''; |
|
49 | + $output = ''; |
|
50 | 50 | |
51 | - if (!empty($pagination_counts)) { |
|
52 | - $first = $pagination_counts['first']; |
|
53 | - $last = $pagination_counts['last']; |
|
54 | - $total = $pagination_counts['total']; |
|
51 | + if (!empty($pagination_counts)) { |
|
52 | + $first = $pagination_counts['first']; |
|
53 | + $last = $pagination_counts['last']; |
|
54 | + $total = $pagination_counts['total']; |
|
55 | 55 | |
56 | - $class = !empty($widget_args['custom_class']) ? $widget_args['custom_class'] : ''; |
|
57 | - $class = gravityview_sanitize_html_class($class); |
|
56 | + $class = !empty($widget_args['custom_class']) ? $widget_args['custom_class'] : ''; |
|
57 | + $class = gravityview_sanitize_html_class($class); |
|
58 | 58 | |
59 | - $output = '<div class="gv-widget-pagination '.$class.'"><p>'.sprintf(__('Displaying %1$s - %2$s of %3$s', 'gravityview'), number_format_i18n($first), number_format_i18n($last), number_format_i18n($total)).'</p></div>'; |
|
60 | - } |
|
59 | + $output = '<div class="gv-widget-pagination '.$class.'"><p>'.sprintf(__('Displaying %1$s - %2$s of %3$s', 'gravityview'), number_format_i18n($first), number_format_i18n($last), number_format_i18n($total)).'</p></div>'; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @filter `gravityview_pagination_output` Modify the pagination widget output |
|
64 | - * |
|
65 | - * @param string $output HTML output |
|
66 | - * @param int $first First entry # |
|
67 | - * @param int $last Last entry # |
|
68 | - * @param int $total Total entries # |
|
69 | - */ |
|
70 | - echo apply_filters('gravityview_pagination_output', $output, $first, $last, $total); |
|
71 | - } |
|
62 | + /** |
|
63 | + * @filter `gravityview_pagination_output` Modify the pagination widget output |
|
64 | + * |
|
65 | + * @param string $output HTML output |
|
66 | + * @param int $first First entry # |
|
67 | + * @param int $last Last entry # |
|
68 | + * @param int $total Total entries # |
|
69 | + */ |
|
70 | + echo apply_filters('gravityview_pagination_output', $output, $first, $last, $total); |
|
71 | + } |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | new GravityView_Widget_Pagination_Info(); |
@@ -18,28 +18,28 @@ discard block |
||
18 | 18 | |
19 | 19 | public function __construct() |
20 | 20 | { |
21 | - $this->widget_description = __('Summary of the number of visible entries out of the total results.', 'gravityview'); |
|
21 | + $this->widget_description = __( 'Summary of the number of visible entries out of the total results.', 'gravityview' ); |
|
22 | 22 | |
23 | 23 | $default_values = [ |
24 | 24 | 'header' => 1, |
25 | 25 | 'footer' => 1, |
26 | 26 | ]; |
27 | 27 | |
28 | - $settings = []; |
|
28 | + $settings = [ ]; |
|
29 | 29 | |
30 | - parent::__construct(__('Show Pagination Info', 'gravityview'), 'page_info', $default_values, $settings); |
|
30 | + parent::__construct( __( 'Show Pagination Info', 'gravityview' ), 'page_info', $default_values, $settings ); |
|
31 | 31 | } |
32 | 32 | |
33 | - public function render_frontend($widget_args, $content = '', $context = '') |
|
33 | + public function render_frontend( $widget_args, $content = '', $context = '' ) |
|
34 | 34 | { |
35 | 35 | $gravityview_view = GravityView_View::getInstance(); |
36 | 36 | |
37 | - if (!$this->pre_render_frontend()) { |
|
37 | + if ( ! $this->pre_render_frontend() ) { |
|
38 | 38 | return; |
39 | 39 | } |
40 | 40 | |
41 | - if (!empty($widget_args['title'])) { |
|
42 | - echo $widget_args['title']; |
|
41 | + if ( ! empty( $widget_args[ 'title' ] ) ) { |
|
42 | + echo $widget_args[ 'title' ]; |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | $pagination_counts = $gravityview_view->getPaginationCounts(); |
@@ -48,15 +48,15 @@ discard block |
||
48 | 48 | |
49 | 49 | $output = ''; |
50 | 50 | |
51 | - if (!empty($pagination_counts)) { |
|
52 | - $first = $pagination_counts['first']; |
|
53 | - $last = $pagination_counts['last']; |
|
54 | - $total = $pagination_counts['total']; |
|
51 | + if ( ! empty( $pagination_counts ) ) { |
|
52 | + $first = $pagination_counts[ 'first' ]; |
|
53 | + $last = $pagination_counts[ 'last' ]; |
|
54 | + $total = $pagination_counts[ 'total' ]; |
|
55 | 55 | |
56 | - $class = !empty($widget_args['custom_class']) ? $widget_args['custom_class'] : ''; |
|
57 | - $class = gravityview_sanitize_html_class($class); |
|
56 | + $class = ! empty( $widget_args[ 'custom_class' ] ) ? $widget_args[ 'custom_class' ] : ''; |
|
57 | + $class = gravityview_sanitize_html_class( $class ); |
|
58 | 58 | |
59 | - $output = '<div class="gv-widget-pagination '.$class.'"><p>'.sprintf(__('Displaying %1$s - %2$s of %3$s', 'gravityview'), number_format_i18n($first), number_format_i18n($last), number_format_i18n($total)).'</p></div>'; |
|
59 | + $output = '<div class="gv-widget-pagination ' . $class . '"><p>' . sprintf( __( 'Displaying %1$s - %2$s of %3$s', 'gravityview' ), number_format_i18n( $first ), number_format_i18n( $last ), number_format_i18n( $total ) ) . '</p></div>'; |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | * @param int $last Last entry # |
68 | 68 | * @param int $total Total entries # |
69 | 69 | */ |
70 | - echo apply_filters('gravityview_pagination_output', $output, $first, $last, $total); |
|
70 | + echo apply_filters( 'gravityview_pagination_output', $output, $first, $last, $total ); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 |
@@ -16,8 +16,7 @@ discard block |
||
16 | 16 | */ |
17 | 17 | protected $show_on_single = false; |
18 | 18 | |
19 | - public function __construct() |
|
20 | - { |
|
19 | + public function __construct() { |
|
21 | 20 | $this->widget_description = __('Summary of the number of visible entries out of the total results.', 'gravityview'); |
22 | 21 | |
23 | 22 | $default_values = [ |
@@ -30,8 +29,7 @@ discard block |
||
30 | 29 | parent::__construct(__('Show Pagination Info', 'gravityview'), 'page_info', $default_values, $settings); |
31 | 30 | } |
32 | 31 | |
33 | - public function render_frontend($widget_args, $content = '', $context = '') |
|
34 | - { |
|
32 | + public function render_frontend($widget_args, $content = '', $context = '') { |
|
35 | 33 | $gravityview_view = GravityView_View::getInstance(); |
36 | 34 | |
37 | 35 | if (!$this->pre_render_frontend()) { |
@@ -10,2153 +10,2153 @@ discard block |
||
10 | 10 | * @copyright Copyright 2014, Katz Web Services, Inc. |
11 | 11 | */ |
12 | 12 | if (!defined('WPINC')) { |
13 | - exit; |
|
13 | + exit; |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | class GravityView_Widget_Search extends \GV\Widget |
17 | 17 | { |
18 | - public $icon = 'dashicons-search'; |
|
19 | - |
|
20 | - public static $file; |
|
21 | - public static $instance; |
|
22 | - |
|
23 | - private $search_filters = []; |
|
24 | - |
|
25 | - /** |
|
26 | - * whether search method is GET or POST ( default: GET ). |
|
27 | - * |
|
28 | - * @since 1.16.4 |
|
29 | - * |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - private $search_method = 'get'; |
|
33 | - |
|
34 | - public function __construct() |
|
35 | - { |
|
36 | - $this->widget_id = 'search_bar'; |
|
37 | - $this->widget_description = esc_html__('Search form for searching entries.', 'gravityview'); |
|
38 | - $this->widget_subtitle = ''; |
|
39 | - |
|
40 | - self::$instance = &$this; |
|
41 | - |
|
42 | - self::$file = plugin_dir_path(__FILE__); |
|
43 | - |
|
44 | - $default_values = ['header' => 0, 'footer' => 0]; |
|
45 | - |
|
46 | - $settings = [ |
|
47 | - 'search_layout' => [ |
|
48 | - 'type' => 'radio', |
|
49 | - 'full_width' => true, |
|
50 | - 'label' => esc_html__('Search Layout', 'gravityview'), |
|
51 | - 'value' => 'horizontal', |
|
52 | - 'options' => [ |
|
53 | - 'horizontal' => esc_html__('Horizontal', 'gravityview'), |
|
54 | - 'vertical' => esc_html__('Vertical', 'gravityview'), |
|
55 | - ], |
|
56 | - ], |
|
57 | - 'search_clear' => [ |
|
58 | - 'type' => 'checkbox', |
|
59 | - 'label' => __('Show Clear button', 'gravityview'), |
|
60 | - 'desc' => __('When a search is performed, display a button that removes all search values.', 'gravityview'), |
|
61 | - 'value' => true, |
|
62 | - ], |
|
63 | - 'search_fields' => [ |
|
64 | - 'type' => 'hidden', |
|
65 | - 'label' => '', |
|
66 | - 'class' => 'gv-search-fields-value', |
|
67 | - 'value' => '[{"field":"search_all","input":"input_text"}]', // Default: Search Everything text box |
|
68 | - ], |
|
69 | - 'search_mode' => [ |
|
70 | - 'type' => 'radio', |
|
71 | - 'full_width' => true, |
|
72 | - 'label' => esc_html__('Search Mode', 'gravityview'), |
|
73 | - 'desc' => __('Should search results match all search fields, or any?', 'gravityview'), |
|
74 | - 'value' => 'any', |
|
75 | - 'class' => 'hide-if-js', |
|
76 | - 'options' => [ |
|
77 | - 'any' => esc_html__('Match Any Fields', 'gravityview'), |
|
78 | - 'all' => esc_html__('Match All Fields', 'gravityview'), |
|
79 | - ], |
|
80 | - ], |
|
81 | - ]; |
|
82 | - |
|
83 | - if (!$this->is_registered()) { |
|
84 | - // frontend - filter entries |
|
85 | - add_filter('gravityview_fe_search_criteria', [$this, 'filter_entries'], 10, 3); |
|
86 | - |
|
87 | - // frontend - add template path |
|
88 | - add_filter('gravityview_template_paths', [$this, 'add_template_path']); |
|
89 | - |
|
90 | - // admin - add scripts - run at 1100 to make sure GravityView_Admin_Views::add_scripts_and_styles() runs first at 999 |
|
91 | - add_action('admin_enqueue_scripts', [$this, 'add_scripts_and_styles'], 1100); |
|
92 | - add_action('wp_enqueue_scripts', [$this, 'register_scripts']); |
|
93 | - add_filter('gravityview_noconflict_scripts', [$this, 'register_no_conflict']); |
|
94 | - |
|
95 | - // ajax - get the searchable fields |
|
96 | - add_action('wp_ajax_gv_searchable_fields', ['GravityView_Widget_Search', 'get_searchable_fields']); |
|
97 | - |
|
98 | - add_action('gravityview_search_widget_fields_after', [$this, 'add_preview_inputs']); |
|
99 | - |
|
100 | - add_filter('gravityview/api/reserved_query_args', [$this, 'add_reserved_args']); |
|
101 | - } |
|
102 | - |
|
103 | - parent::__construct(esc_html__('Search Bar', 'gravityview'), null, $default_values, $settings); |
|
104 | - |
|
105 | - // calculate the search method (POST / GET) |
|
106 | - $this->set_search_method(); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @return GravityView_Widget_Search |
|
111 | - */ |
|
112 | - public static function getInstance() |
|
113 | - { |
|
114 | - if (empty(self::$instance)) { |
|
115 | - self::$instance = new GravityView_Widget_Search(); |
|
116 | - } |
|
117 | - |
|
118 | - return self::$instance; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * @since 2.10 |
|
123 | - * |
|
124 | - * @param $args |
|
125 | - * |
|
126 | - * @return mixed |
|
127 | - */ |
|
128 | - public function add_reserved_args($args) |
|
129 | - { |
|
130 | - $args[] = 'gv_search'; |
|
131 | - $args[] = 'gv_start'; |
|
132 | - $args[] = 'gv_end'; |
|
133 | - $args[] = 'gv_id'; |
|
134 | - $args[] = 'gv_by'; |
|
135 | - $args[] = 'mode'; |
|
136 | - |
|
137 | - $get = (array) $_GET; |
|
138 | - |
|
139 | - // If the fields being searched as reserved; not to be considered user-passed variables |
|
140 | - foreach ($get as $key => $value) { |
|
141 | - if ($key !== $this->convert_request_key_to_filter_key($key)) { |
|
142 | - $args[] = $key; |
|
143 | - } |
|
144 | - } |
|
145 | - |
|
146 | - return $args; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Sets the search method to GET (default) or POST. |
|
151 | - * |
|
152 | - * @since 1.16.4 |
|
153 | - */ |
|
154 | - private function set_search_method() |
|
155 | - { |
|
156 | - /** |
|
157 | - * @filter `gravityview/search/method` Modify the search form method (GET / POST) |
|
158 | - * |
|
159 | - * @since 1.16.4 |
|
160 | - * |
|
161 | - * @param string $search_method Assign an input type according to the form field type. Defaults: `boolean`, `multi`, `select`, `date`, `text` |
|
162 | - * @param string $field_type Gravity Forms field type (also the `name` parameter of GravityView_Field classes) |
|
163 | - */ |
|
164 | - $method = apply_filters('gravityview/search/method', $this->search_method); |
|
165 | - |
|
166 | - $method = strtolower($method); |
|
167 | - |
|
168 | - $this->search_method = in_array($method, ['get', 'post']) ? $method : 'get'; |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Returns the search method. |
|
173 | - * |
|
174 | - * @since 1.16.4 |
|
175 | - * |
|
176 | - * @return string |
|
177 | - */ |
|
178 | - public function get_search_method() |
|
179 | - { |
|
180 | - return $this->search_method; |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Get the input types available for different field types. |
|
185 | - * |
|
186 | - * @since 1.17.5 |
|
187 | - * |
|
188 | - * @return array [field type name] => (array|string) search bar input types |
|
189 | - */ |
|
190 | - public static function get_input_types_by_field_type() |
|
191 | - { |
|
192 | - /** |
|
193 | - * Input Type groups. |
|
194 | - * |
|
195 | - * @see admin-search-widget.js (getSelectInput) |
|
196 | - */ |
|
197 | - $input_types = [ |
|
198 | - 'text' => ['input_text'], |
|
199 | - 'address' => ['input_text'], |
|
200 | - 'number' => ['input_text'], |
|
201 | - 'date' => ['date', 'date_range'], |
|
202 | - 'boolean' => ['single_checkbox'], |
|
203 | - 'select' => ['select', 'radio', 'link'], |
|
204 | - 'multi' => ['select', 'multiselect', 'radio', 'checkbox', 'link'], |
|
205 | - |
|
206 | - // hybrids |
|
207 | - 'created_by' => ['select', 'radio', 'checkbox', 'multiselect', 'link', 'input_text'], |
|
208 | - 'product' => ['select', 'radio', 'link', 'input_text'], |
|
209 | - ]; |
|
210 | - |
|
211 | - /** |
|
212 | - * @filter `gravityview/search/input_types` Change the types of search fields available to a field type |
|
213 | - * |
|
214 | - * @see GravityView_Widget_Search::get_search_input_labels() for the available input types |
|
215 | - * |
|
216 | - * @param array $input_types Associative array: key is field `name`, value is array of GravityView input types (note: use `input_text` for `text`) |
|
217 | - */ |
|
218 | - $input_types = apply_filters('gravityview/search/input_types', $input_types); |
|
219 | - |
|
220 | - return $input_types; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Get labels for different types of search bar inputs. |
|
225 | - * |
|
226 | - * @since 1.17.5 |
|
227 | - * |
|
228 | - * @return array [input type] => input type label |
|
229 | - */ |
|
230 | - public static function get_search_input_labels() |
|
231 | - { |
|
232 | - /** |
|
233 | - * Input Type labels l10n. |
|
234 | - * |
|
235 | - * @see admin-search-widget.js (getSelectInput) |
|
236 | - */ |
|
237 | - $input_labels = [ |
|
238 | - 'input_text' => esc_html__('Text', 'gravityview'), |
|
239 | - 'date' => esc_html__('Date', 'gravityview'), |
|
240 | - 'select' => esc_html__('Select', 'gravityview'), |
|
241 | - 'multiselect' => esc_html__('Select (multiple values)', 'gravityview'), |
|
242 | - 'radio' => esc_html__('Radio', 'gravityview'), |
|
243 | - 'checkbox' => esc_html__('Checkbox', 'gravityview'), |
|
244 | - 'single_checkbox' => esc_html__('Checkbox', 'gravityview'), |
|
245 | - 'link' => esc_html__('Links', 'gravityview'), |
|
246 | - 'date_range' => esc_html__('Date range', 'gravityview'), |
|
247 | - ]; |
|
248 | - |
|
249 | - /** |
|
250 | - * @filter `gravityview/search/input_types` Change the label of search field input types |
|
251 | - * |
|
252 | - * @param array $input_types Associative array: key is input type name, value is label |
|
253 | - */ |
|
254 | - $input_labels = apply_filters('gravityview/search/input_labels', $input_labels); |
|
255 | - |
|
256 | - return $input_labels; |
|
257 | - } |
|
258 | - |
|
259 | - public static function get_search_input_label($input_type) |
|
260 | - { |
|
261 | - $labels = self::get_search_input_labels(); |
|
262 | - |
|
263 | - return \GV\Utils::get($labels, $input_type, false); |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Add script to Views edit screen (admin). |
|
268 | - * |
|
269 | - * @param mixed $hook |
|
270 | - */ |
|
271 | - public function add_scripts_and_styles($hook) |
|
272 | - { |
|
273 | - global $pagenow; |
|
274 | - |
|
275 | - // Don't process any scripts below here if it's not a GravityView page or the widgets screen |
|
276 | - if (!gravityview()->request->is_admin($hook, 'single') && ('widgets.php' !== $pagenow)) { |
|
277 | - return; |
|
278 | - } |
|
279 | - |
|
280 | - $script_min = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
281 | - $script_source = empty($script_min) ? '/source' : ''; |
|
282 | - |
|
283 | - wp_enqueue_script('gravityview_searchwidget_admin', plugins_url('assets/js'.$script_source.'/admin-search-widget'.$script_min.'.js', __FILE__), ['jquery', 'gravityview_views_scripts'], \GV\Plugin::$version); |
|
284 | - |
|
285 | - wp_localize_script('gravityview_searchwidget_admin', 'gvSearchVar', [ |
|
286 | - 'nonce' => wp_create_nonce('gravityview_ajaxsearchwidget'), |
|
287 | - 'label_nofields' => esc_html__('No search fields configured yet.', 'gravityview'), |
|
288 | - 'label_addfield' => esc_html__('Add Search Field', 'gravityview'), |
|
289 | - 'label_label' => esc_html__('Label', 'gravityview'), |
|
290 | - 'label_searchfield' => esc_html__('Search Field', 'gravityview'), |
|
291 | - 'label_inputtype' => esc_html__('Input Type', 'gravityview'), |
|
292 | - 'label_ajaxerror' => esc_html__('There was an error loading searchable fields. Save the View or refresh the page to fix this issue.', 'gravityview'), |
|
293 | - 'input_labels' => json_encode(self::get_search_input_labels()), |
|
294 | - 'input_types' => json_encode(self::get_input_types_by_field_type()), |
|
295 | - ]); |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Add admin script to the no-conflict scripts allowlist. |
|
300 | - * |
|
301 | - * @param array $allowed Scripts allowed in no-conflict mode |
|
302 | - * |
|
303 | - * @return array Scripts allowed in no-conflict mode, plus the search widget script |
|
304 | - */ |
|
305 | - public function register_no_conflict($allowed) |
|
306 | - { |
|
307 | - $allowed[] = 'gravityview_searchwidget_admin'; |
|
308 | - |
|
309 | - return $allowed; |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * Ajax |
|
314 | - * Returns the form fields ( only the searchable ones ). |
|
315 | - * |
|
316 | - * @return void |
|
317 | - */ |
|
318 | - public static function get_searchable_fields() |
|
319 | - { |
|
320 | - if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'gravityview_ajaxsearchwidget')) { |
|
321 | - exit('0'); |
|
322 | - } |
|
323 | - |
|
324 | - $form = ''; |
|
325 | - |
|
326 | - // Fetch the form for the current View |
|
327 | - if (!empty($_POST['view_id'])) { |
|
328 | - $form = gravityview_get_form_id($_POST['view_id']); |
|
329 | - } elseif (!empty($_POST['formid'])) { |
|
330 | - $form = (int) $_POST['formid']; |
|
331 | - } elseif (!empty($_POST['template_id']) && class_exists('GravityView_Ajax')) { |
|
332 | - $form = GravityView_Ajax::pre_get_form_fields($_POST['template_id']); |
|
333 | - } |
|
334 | - |
|
335 | - // fetch form id assigned to the view |
|
336 | - $response = self::render_searchable_fields($form); |
|
337 | - |
|
338 | - exit($response); |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Generates html for the available Search Fields dropdown. |
|
343 | - * |
|
344 | - * @param int $form_id |
|
345 | - * @param string $current (for future use) |
|
346 | - * |
|
347 | - * @return string |
|
348 | - */ |
|
349 | - public static function render_searchable_fields($form_id = null, $current = '') |
|
350 | - { |
|
351 | - if (is_null($form_id)) { |
|
352 | - return ''; |
|
353 | - } |
|
354 | - |
|
355 | - // start building output |
|
356 | - |
|
357 | - $output = '<select class="gv-search-fields">'; |
|
358 | - |
|
359 | - $custom_fields = [ |
|
360 | - 'search_all' => [ |
|
361 | - 'text' => esc_html__('Search Everything', 'gravityview'), |
|
362 | - 'type' => 'text', |
|
363 | - ], |
|
364 | - 'entry_date' => [ |
|
365 | - 'text' => esc_html__('Entry Date', 'gravityview'), |
|
366 | - 'type' => 'date', |
|
367 | - ], |
|
368 | - 'entry_id' => [ |
|
369 | - 'text' => esc_html__('Entry ID', 'gravityview'), |
|
370 | - 'type' => 'text', |
|
371 | - ], |
|
372 | - 'created_by' => [ |
|
373 | - 'text' => esc_html__('Entry Creator', 'gravityview'), |
|
374 | - 'type' => 'created_by', |
|
375 | - ], |
|
376 | - 'is_starred' => [ |
|
377 | - 'text' => esc_html__('Is Starred', 'gravityview'), |
|
378 | - 'type' => 'boolean', |
|
379 | - ], |
|
380 | - ]; |
|
381 | - |
|
382 | - if (gravityview()->plugin->supports(\GV\Plugin::FEATURE_GFQUERY)) { |
|
383 | - $custom_fields['is_approved'] = [ |
|
384 | - 'text' => esc_html__('Approval Status', 'gravityview'), |
|
385 | - 'type' => 'multi', |
|
386 | - ]; |
|
387 | - } |
|
388 | - |
|
389 | - foreach ($custom_fields as $custom_field_key => $custom_field) { |
|
390 | - $output .= sprintf('<option value="%s" %s data-inputtypes="%s" data-placeholder="%s">%s</option>', $custom_field_key, selected($custom_field_key, $current, false), $custom_field['type'], self::get_field_label(['field' => $custom_field_key]), $custom_field['text']); |
|
391 | - } |
|
392 | - |
|
393 | - // Get fields with sub-inputs and no parent |
|
394 | - $fields = gravityview_get_form_fields($form_id, true, true); |
|
395 | - |
|
396 | - /** |
|
397 | - * @filter `gravityview/search/searchable_fields` Modify the fields that are displayed as searchable in the Search Bar dropdown\n |
|
398 | - * |
|
399 | - * @since 1.17 |
|
400 | - * @see gravityview_get_form_fields() Used to fetch the fields |
|
401 | - * @see GravityView_Widget_Search::get_search_input_types See this method to modify the type of input types allowed for a field |
|
402 | - * |
|
403 | - * @param array $fields Array of searchable fields, as fetched by gravityview_get_form_fields() |
|
404 | - * @param int $form_id |
|
405 | - */ |
|
406 | - $fields = apply_filters('gravityview/search/searchable_fields', $fields, $form_id); |
|
407 | - |
|
408 | - if (!empty($fields)) { |
|
409 | - $blocklist_field_types = apply_filters('gravityview_blocklist_field_types', ['fileupload', 'post_image', 'post_id', 'section'], null); |
|
410 | - |
|
411 | - foreach ($fields as $id => $field) { |
|
412 | - if (in_array($field['type'], $blocklist_field_types)) { |
|
413 | - continue; |
|
414 | - } |
|
415 | - |
|
416 | - $types = self::get_search_input_types($id, $field['type']); |
|
417 | - |
|
418 | - $output .= '<option value="'.$id.'" '.selected($id, $current, false).'data-inputtypes="'.esc_attr($types).'">'.esc_html($field['label']).'</option>'; |
|
419 | - } |
|
420 | - } |
|
421 | - |
|
422 | - $output .= '</select>'; |
|
423 | - |
|
424 | - return $output; |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Assign an input type according to the form field type. |
|
429 | - * |
|
430 | - * @see admin-search-widget.js |
|
431 | - * |
|
432 | - * @param string|int|float $field_id Gravity Forms field ID |
|
433 | - * @param string $field_type Gravity Forms field type (also the `name` parameter of GravityView_Field classes) |
|
434 | - * |
|
435 | - * @return string GV field search input type ('multi', 'boolean', 'select', 'date', 'text') |
|
436 | - */ |
|
437 | - public static function get_search_input_types($field_id = '', $field_type = null) |
|
438 | - { |
|
439 | - |
|
440 | - // @todo - This needs to be improved - many fields have . including products and addresses |
|
441 | - if (false !== strpos((string) $field_id, '.') && in_array($field_type, ['checkbox']) || in_array($field_id, ['is_fulfilled'])) { |
|
442 | - $input_type = 'boolean'; // on/off checkbox |
|
443 | - } elseif (in_array($field_type, ['checkbox', 'post_category', 'multiselect'])) { |
|
444 | - $input_type = 'multi'; //multiselect |
|
445 | - } elseif (in_array($field_type, ['select', 'radio'])) { |
|
446 | - $input_type = 'select'; |
|
447 | - } elseif (in_array($field_type, ['date']) || in_array($field_id, ['payment_date'])) { |
|
448 | - $input_type = 'date'; |
|
449 | - } elseif (in_array($field_type, ['number']) || in_array($field_id, ['payment_amount'])) { |
|
450 | - $input_type = 'number'; |
|
451 | - } elseif (in_array($field_type, ['product'])) { |
|
452 | - $input_type = 'product'; |
|
453 | - } else { |
|
454 | - $input_type = 'text'; |
|
455 | - } |
|
456 | - |
|
457 | - /** |
|
458 | - * @filter `gravityview/extension/search/input_type` Modify the search form input type based on field type |
|
459 | - * |
|
460 | - * @since 1.2 |
|
461 | - * @since 1.19.2 Added $field_id parameter |
|
462 | - * |
|
463 | - * @param string $input_type Assign an input type according to the form field type. Defaults: `boolean`, `multi`, `select`, `date`, `text` |
|
464 | - * @param string $field_type Gravity Forms field type (also the `name` parameter of GravityView_Field classes) |
|
465 | - * @param string|int|float $field_id ID of the field being processed |
|
466 | - */ |
|
467 | - $input_type = apply_filters('gravityview/extension/search/input_type', $input_type, $field_type, $field_id); |
|
468 | - |
|
469 | - return $input_type; |
|
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * Display hidden fields to add support for sites using Default permalink structure. |
|
474 | - * |
|
475 | - * @since 1.8 |
|
476 | - * |
|
477 | - * @return array Search fields, modified if not using permalinks |
|
478 | - */ |
|
479 | - public function add_no_permalink_fields($search_fields, $object, $widget_args = []) |
|
480 | - { |
|
481 | - /** @global WP_Rewrite $wp_rewrite */ |
|
482 | - global $wp_rewrite; |
|
483 | - |
|
484 | - // Support default permalink structure |
|
485 | - if (false === $wp_rewrite->using_permalinks()) { |
|
486 | - |
|
487 | - // By default, use current post. |
|
488 | - $post_id = 0; |
|
489 | - |
|
490 | - // We're in the WordPress Widget context, and an overriding post ID has been set. |
|
491 | - if (!empty($widget_args['post_id'])) { |
|
492 | - $post_id = absint($widget_args['post_id']); |
|
493 | - } |
|
494 | - // We're in the WordPress Widget context, and the base View ID should be used |
|
495 | - elseif (!empty($widget_args['view_id'])) { |
|
496 | - $post_id = absint($widget_args['view_id']); |
|
497 | - } |
|
498 | - |
|
499 | - $args = gravityview_get_permalink_query_args($post_id); |
|
500 | - |
|
501 | - // Add hidden fields to the search form |
|
502 | - foreach ($args as $key => $value) { |
|
503 | - $search_fields[] = [ |
|
504 | - 'name' => $key, |
|
505 | - 'input' => 'hidden', |
|
506 | - 'value' => $value, |
|
507 | - ]; |
|
508 | - } |
|
509 | - } |
|
510 | - |
|
511 | - return $search_fields; |
|
512 | - } |
|
513 | - |
|
514 | - /** |
|
515 | - * Get the fields that are searchable for a View. |
|
516 | - * |
|
517 | - * @since 2.0 |
|
518 | - * @since 2.0.9 Added $with_full_field parameter |
|
519 | - * |
|
520 | - * @param \GV\View|null $view |
|
521 | - * @param bool $with_full_field Return full field array, or just field ID? Default: false (just field ID) |
|
522 | - * |
|
523 | - * TODO: Move to \GV\View, perhaps? And return a Field_Collection |
|
524 | - * TODO: Use in gravityview()->request->is_search() to calculate whether a valid search |
|
525 | - * |
|
526 | - * @return array If no View, returns empty array. Otherwise, returns array of fields configured in widgets and Search Bar for a View |
|
527 | - */ |
|
528 | - private function get_view_searchable_fields($view, $with_full_field = false) |
|
529 | - { |
|
530 | - |
|
531 | - /** |
|
532 | - * Find all search widgets on the view and get the searchable fields settings. |
|
533 | - */ |
|
534 | - $searchable_fields = []; |
|
535 | - |
|
536 | - if (!$view) { |
|
537 | - return $searchable_fields; |
|
538 | - } |
|
539 | - |
|
540 | - /** |
|
541 | - * Include the sidebar Widgets. |
|
542 | - */ |
|
543 | - $widgets = (array) get_option('widget_gravityview_search', []); |
|
544 | - |
|
545 | - foreach ($widgets as $widget) { |
|
546 | - if (!empty($widget['view_id']) && $widget['view_id'] == $view->ID) { |
|
547 | - if ($_fields = json_decode($widget['search_fields'], true)) { |
|
548 | - foreach ($_fields as $field) { |
|
549 | - if (empty($field['form_id'])) { |
|
550 | - $field['form_id'] = $view->form ? $view->form->ID : 0; |
|
551 | - } |
|
552 | - $searchable_fields[] = $with_full_field ? $field : $field['field']; |
|
553 | - } |
|
554 | - } |
|
555 | - } |
|
556 | - } |
|
557 | - |
|
558 | - foreach ($view->widgets->by_id($this->get_widget_id())->all() as $widget) { |
|
559 | - if ($_fields = json_decode($widget->configuration->get('search_fields'), true)) { |
|
560 | - foreach ($_fields as $field) { |
|
561 | - if (empty($field['form_id'])) { |
|
562 | - $field['form_id'] = $view->form ? $view->form->ID : 0; |
|
563 | - } |
|
564 | - $searchable_fields[] = $with_full_field ? $field : $field['field']; |
|
565 | - } |
|
566 | - } |
|
567 | - } |
|
568 | - |
|
569 | - /** |
|
570 | - * @since 2.5.1 |
|
571 | - * @depecated 2.14 |
|
572 | - */ |
|
573 | - $searchable_fields = apply_filters_deprecated('gravityview/search/searchable_fields/whitelist', [$searchable_fields, $view, $with_full_field], '2.14', 'gravityview/search/searchable_fields/allowlist'); |
|
574 | - |
|
575 | - /** |
|
576 | - * @filter `gravityview/search/searchable_fields/allowlist` Modifies the fields able to be searched using the Search Bar |
|
577 | - * |
|
578 | - * @since 2.14 |
|
579 | - * |
|
580 | - * @param array $searchable_fields Array of GravityView-formatted fields or only the field ID? Example: [ '1.2', 'created_by' ] |
|
581 | - * @param \GV\View $view Object of View being searched. |
|
582 | - * @param bool $with_full_field Does $searchable_fields contain the full field array or just field ID? Default: false (just field ID) |
|
583 | - */ |
|
584 | - $searchable_fields = apply_filters('gravityview/search/searchable_fields/allowlist', $searchable_fields, $view, $with_full_field); |
|
585 | - |
|
586 | - return $searchable_fields; |
|
587 | - } |
|
588 | - |
|
589 | - /** --- Frontend --- */ |
|
590 | - |
|
591 | - /** |
|
592 | - * Calculate the search criteria to filter entries. |
|
593 | - * |
|
594 | - * @param array $search_criteria The search criteria |
|
595 | - * @param int $form_id The form ID |
|
596 | - * @param array $args Some args |
|
597 | - * @param bool $force_search_criteria Whether to suppress GF_Query filter, internally used in self::gf_query_filter |
|
598 | - * |
|
599 | - * @return array |
|
600 | - */ |
|
601 | - public function filter_entries($search_criteria, $form_id = null, $args = [], $force_search_criteria = false) |
|
602 | - { |
|
603 | - if (!$force_search_criteria && gravityview()->plugin->supports(\GV\Plugin::FEATURE_GFQUERY)) { |
|
604 | - /** |
|
605 | - * If GF_Query is available, we can construct custom conditions with nested |
|
606 | - * booleans on the query, giving up the old ways of flat search_criteria field_filters. |
|
607 | - */ |
|
608 | - add_action('gravityview/view/query', [$this, 'gf_query_filter'], 10, 3); |
|
609 | - |
|
610 | - return $search_criteria; // Return the original criteria, GF_Query modification kicks in later |
|
611 | - } |
|
612 | - |
|
613 | - if ('post' === $this->search_method) { |
|
614 | - $get = $_POST; |
|
615 | - } else { |
|
616 | - $get = $_GET; |
|
617 | - } |
|
618 | - |
|
619 | - $view = \GV\View::by_id(\GV\Utils::get($args, 'id')); |
|
620 | - $view_id = $view ? $view->ID : null; |
|
621 | - $form_id = $view ? $view->form->ID : null; |
|
622 | - |
|
623 | - gravityview()->log->debug('Requested $_{method}: ', ['method' => $this->search_method, 'data' => $get]); |
|
624 | - |
|
625 | - if (empty($get) || !is_array($get)) { |
|
626 | - return $search_criteria; |
|
627 | - } |
|
628 | - |
|
629 | - $get = stripslashes_deep($get); |
|
630 | - |
|
631 | - $get = gv_map_deep($get, 'rawurldecode'); |
|
632 | - |
|
633 | - // Make sure array key is set up |
|
634 | - $search_criteria['field_filters'] = \GV\Utils::get($search_criteria, 'field_filters', []); |
|
635 | - |
|
636 | - $searchable_fields = $this->get_view_searchable_fields($view); |
|
637 | - $searchable_field_objects = $this->get_view_searchable_fields($view, true); |
|
638 | - |
|
639 | - /** |
|
640 | - * @filter `gravityview/search-all-split-words` Search for each word separately or the whole phrase? |
|
641 | - * |
|
642 | - * @since 1.20.2 |
|
643 | - * |
|
644 | - * @param bool $split_words True: split a phrase into words; False: search whole word only [Default: true] |
|
645 | - */ |
|
646 | - $split_words = apply_filters('gravityview/search-all-split-words', true); |
|
647 | - |
|
648 | - /** |
|
649 | - * @filter `gravityview/search-trim-input` Remove leading/trailing whitespaces from search value |
|
650 | - * |
|
651 | - * @since 2.9.3 |
|
652 | - * |
|
653 | - * @param bool $trim_search_value True: remove whitespace; False: keep as is [Default: true] |
|
654 | - */ |
|
655 | - $trim_search_value = apply_filters('gravityview/search-trim-input', true); |
|
656 | - |
|
657 | - // add free search |
|
658 | - if (isset($get['gv_search']) && '' !== $get['gv_search'] && in_array('search_all', $searchable_fields)) { |
|
659 | - $search_all_value = $trim_search_value ? trim($get['gv_search']) : $get['gv_search']; |
|
660 | - |
|
661 | - if ($split_words) { |
|
662 | - // Search for a piece |
|
663 | - $words = explode(' ', $search_all_value); |
|
664 | - |
|
665 | - $words = array_filter($words); |
|
666 | - } else { |
|
667 | - // Replace multiple spaces with one space |
|
668 | - $search_all_value = preg_replace('/\s+/ism', ' ', $search_all_value); |
|
669 | - |
|
670 | - $words = [$search_all_value]; |
|
671 | - } |
|
672 | - |
|
673 | - foreach ($words as $word) { |
|
674 | - $search_criteria['field_filters'][] = [ |
|
675 | - 'key' => null, // The field ID to search |
|
676 | - 'value' => $word, // The value to search |
|
677 | - 'operator' => 'contains', // What to search in. Options: `is` or `contains` |
|
678 | - ]; |
|
679 | - } |
|
680 | - } |
|
681 | - |
|
682 | - // start date & end date |
|
683 | - if (in_array('entry_date', $searchable_fields)) { |
|
684 | - /** |
|
685 | - * Get and normalize the dates according to the input format. |
|
686 | - */ |
|
687 | - if ($curr_start = !empty($get['gv_start']) ? $get['gv_start'] : '') { |
|
688 | - if ($curr_start_date = date_create_from_format($this->get_datepicker_format(true), $curr_start)) { |
|
689 | - $curr_start = $curr_start_date->format('Y-m-d'); |
|
690 | - } |
|
691 | - } |
|
692 | - |
|
693 | - if ($curr_end = !empty($get['gv_start']) ? (!empty($get['gv_end']) ? $get['gv_end'] : '') : '') { |
|
694 | - if ($curr_end_date = date_create_from_format($this->get_datepicker_format(true), $curr_end)) { |
|
695 | - $curr_end = $curr_end_date->format('Y-m-d'); |
|
696 | - } |
|
697 | - } |
|
698 | - |
|
699 | - if ($view) { |
|
700 | - /** |
|
701 | - * Override start and end dates if View is limited to some already. |
|
702 | - */ |
|
703 | - if ($start_date = $view->settings->get('start_date')) { |
|
704 | - if ($start_timestamp = strtotime($curr_start)) { |
|
705 | - $curr_start = $start_timestamp < strtotime($start_date) ? $start_date : $curr_start; |
|
706 | - } |
|
707 | - } |
|
708 | - if ($end_date = $view->settings->get('end_date')) { |
|
709 | - if ($end_timestamp = strtotime($curr_end)) { |
|
710 | - $curr_end = $end_timestamp > strtotime($end_date) ? $end_date : $curr_end; |
|
711 | - } |
|
712 | - } |
|
713 | - } |
|
714 | - |
|
715 | - /** |
|
716 | - * @filter `gravityview_date_created_adjust_timezone` Whether to adjust the timezone for entries. \n |
|
717 | - * `date_created` is stored in UTC format. Convert search date into UTC (also used on templates/fields/date_created.php). \n |
|
718 | - * This is for backward compatibility before \GF_Query started to automatically apply the timezone offset. |
|
719 | - * |
|
720 | - * @since 1.12 |
|
721 | - * |
|
722 | - * @param bool $adjust_tz Use timezone-adjusted datetime? If true, adjusts date based on blog's timezone setting. If false, uses UTC setting. Default is `false`. |
|
723 | - * @param string $context Where the filter is being called from. `search` in this case. |
|
724 | - */ |
|
725 | - $adjust_tz = apply_filters('gravityview_date_created_adjust_timezone', false, 'search'); |
|
726 | - |
|
727 | - /** |
|
728 | - * Don't set $search_criteria['start_date'] if start_date is empty as it may lead to bad query results (GFAPI::get_entries). |
|
729 | - */ |
|
730 | - if (!empty($curr_start)) { |
|
731 | - $curr_start = date('Y-m-d H:i:s', strtotime($curr_start)); |
|
732 | - $search_criteria['start_date'] = $adjust_tz ? get_gmt_from_date($curr_start) : $curr_start; |
|
733 | - } |
|
734 | - |
|
735 | - if (!empty($curr_end)) { |
|
736 | - // Fast-forward 24 hour on the end time |
|
737 | - $curr_end = date('Y-m-d H:i:s', strtotime($curr_end) + DAY_IN_SECONDS); |
|
738 | - $search_criteria['end_date'] = $adjust_tz ? get_gmt_from_date($curr_end) : $curr_end; |
|
739 | - if (strpos($search_criteria['end_date'], '00:00:00')) { // See https://github.com/gravityview/GravityView/issues/1056 |
|
740 | - $search_criteria['end_date'] = date('Y-m-d H:i:s', strtotime($search_criteria['end_date']) - 1); |
|
741 | - } |
|
742 | - } |
|
743 | - } |
|
744 | - |
|
745 | - // search for a specific entry ID |
|
746 | - if (!empty($get['gv_id']) && in_array('entry_id', $searchable_fields)) { |
|
747 | - $search_criteria['field_filters'][] = [ |
|
748 | - 'key' => 'id', |
|
749 | - 'value' => absint($get['gv_id']), |
|
750 | - 'operator' => $this->get_operator($get, 'gv_id', ['='], '='), |
|
751 | - ]; |
|
752 | - } |
|
753 | - |
|
754 | - // search for a specific Created_by ID |
|
755 | - if (!empty($get['gv_by']) && in_array('created_by', $searchable_fields)) { |
|
756 | - $search_criteria['field_filters'][] = [ |
|
757 | - 'key' => 'created_by', |
|
758 | - 'value' => $get['gv_by'], |
|
759 | - 'operator' => $this->get_operator($get, 'gv_by', ['='], '='), |
|
760 | - ]; |
|
761 | - } |
|
762 | - |
|
763 | - // Get search mode passed in URL |
|
764 | - $mode = isset($get['mode']) && in_array($get['mode'], ['any', 'all']) ? $get['mode'] : 'any'; |
|
765 | - |
|
766 | - // get the other search filters |
|
767 | - foreach ($get as $key => $value) { |
|
768 | - if (0 !== strpos($key, 'filter_') && 0 !== strpos($key, 'input_')) { |
|
769 | - continue; |
|
770 | - } |
|
771 | - |
|
772 | - if (strpos($key, '|op') !== false) { |
|
773 | - continue; // This is an operator |
|
774 | - } |
|
775 | - |
|
776 | - $filter_key = $this->convert_request_key_to_filter_key($key); |
|
777 | - |
|
778 | - if ($trim_search_value) { |
|
779 | - $value = is_array($value) ? array_map('trim', $value) : trim($value); |
|
780 | - } |
|
781 | - |
|
782 | - if (gv_empty($value, false, false) || (is_array($value) && count($value) === 1 && gv_empty($value[0], false, false))) { |
|
783 | - /** |
|
784 | - * @filter `gravityview/search/ignore-empty-values` Filter to control if empty field values should be ignored or strictly matched (default: true) |
|
785 | - * |
|
786 | - * @since 2.14.2.1 |
|
787 | - * |
|
788 | - * @param bool $ignore_empty_values |
|
789 | - * @param int|null $filter_key |
|
790 | - * @param int|null $view_id |
|
791 | - * @param int|null $form_id |
|
792 | - */ |
|
793 | - $ignore_empty_values = apply_filters('gravityview/search/ignore-empty-values', true, $filter_key, $view_id, $form_id); |
|
794 | - |
|
795 | - if (is_array($value) || $ignore_empty_values) { |
|
796 | - continue; |
|
797 | - } |
|
798 | - |
|
799 | - $value = ''; |
|
800 | - } |
|
801 | - |
|
802 | - if ($form_id && '' === $value) { |
|
803 | - $field = GFAPI::get_field($form_id, $filter_key); |
|
804 | - |
|
805 | - // GF_Query casts Number field values to decimal, which may return unexpected result when the value is blank. |
|
806 | - if ($field && 'number' === $field->type) { |
|
807 | - $value = '-'.PHP_INT_MAX; |
|
808 | - } |
|
809 | - } |
|
810 | - |
|
811 | - if (!$filter = $this->prepare_field_filter($filter_key, $value, $view, $searchable_field_objects, $get)) { |
|
812 | - continue; |
|
813 | - } |
|
814 | - |
|
815 | - if (!isset($filter['operator'])) { |
|
816 | - $filter['operator'] = $this->get_operator($get, $key, ['contains'], 'contains'); |
|
817 | - } |
|
818 | - |
|
819 | - if (isset($filter[0]['value'])) { |
|
820 | - $filter[0]['value'] = $trim_search_value ? trim($filter[0]['value']) : $filter[0]['value']; |
|
821 | - |
|
822 | - $search_criteria['field_filters'] = array_merge($search_criteria['field_filters'], $filter); |
|
823 | - |
|
824 | - // if date range type, set search mode to ALL |
|
825 | - if (!empty($filter[0]['operator']) && in_array($filter[0]['operator'], ['>=', '<=', '>', '<'])) { |
|
826 | - $mode = 'all'; |
|
827 | - } |
|
828 | - } elseif (!empty($filter)) { |
|
829 | - $search_criteria['field_filters'][] = $filter; |
|
830 | - } |
|
831 | - } |
|
832 | - |
|
833 | - /** |
|
834 | - * @filter `gravityview/search/mode` Set the Search Mode (`all` or `any`) |
|
835 | - * |
|
836 | - * @since 1.5.1 |
|
837 | - * |
|
838 | - * @param string $mode Search mode (`any` vs `all`) |
|
839 | - */ |
|
840 | - $search_criteria['field_filters']['mode'] = apply_filters('gravityview/search/mode', $mode); |
|
841 | - |
|
842 | - gravityview()->log->debug('Returned Search Criteria: ', ['data' => $search_criteria]); |
|
843 | - |
|
844 | - unset($get); |
|
845 | - |
|
846 | - return $search_criteria; |
|
847 | - } |
|
848 | - |
|
849 | - /** |
|
850 | - * Filters the \GF_Query with advanced logic. |
|
851 | - * |
|
852 | - * Dropin for the legacy flat filters when \GF_Query is available. |
|
853 | - * |
|
854 | - * @param \GF_Query $query The current query object reference |
|
855 | - * @param \GV\View $this The current view object |
|
856 | - * @param \GV\Request $request The request object |
|
857 | - */ |
|
858 | - public function gf_query_filter(&$query, $view, $request) |
|
859 | - { |
|
860 | - /** |
|
861 | - * This is a shortcut to get all the needed search criteria. |
|
862 | - * We feed these into an new GF_Query and tack them onto the current object. |
|
863 | - */ |
|
864 | - $search_criteria = $this->filter_entries([], null, ['id' => $view->ID], true /** force search_criteria */); |
|
865 | - |
|
866 | - /** |
|
867 | - * Call any userland filters that they might have. |
|
868 | - */ |
|
869 | - remove_filter('gravityview_fe_search_criteria', [$this, 'filter_entries'], 10, 3); |
|
870 | - $search_criteria = apply_filters('gravityview_fe_search_criteria', $search_criteria, $view->form->ID, $view->settings->as_atts()); |
|
871 | - add_filter('gravityview_fe_search_criteria', [$this, 'filter_entries'], 10, 3); |
|
872 | - |
|
873 | - $query_class = $view->get_query_class(); |
|
874 | - |
|
875 | - if (empty($search_criteria['field_filters'])) { |
|
876 | - return; |
|
877 | - } |
|
878 | - |
|
879 | - $widgets = $view->widgets->by_id($this->widget_id); |
|
880 | - if ($widgets->count()) { |
|
881 | - $widgets = $widgets->all(); |
|
882 | - $widget = $widgets[0]; |
|
883 | - |
|
884 | - $search_fields = json_decode($widget->configuration->get('search_fields'), true); |
|
885 | - |
|
886 | - foreach ((array) $search_fields as $search_field) { |
|
887 | - if ('created_by' === $search_field['field'] && 'input_text' === $search_field['input']) { |
|
888 | - $created_by_text_mode = true; |
|
889 | - } |
|
890 | - } |
|
891 | - } |
|
892 | - |
|
893 | - $extra_conditions = []; |
|
894 | - $mode = 'any'; |
|
895 | - |
|
896 | - foreach ($search_criteria['field_filters'] as $key => &$filter) { |
|
897 | - if (!is_array($filter)) { |
|
898 | - if (in_array(strtolower($filter), ['any', 'all'])) { |
|
899 | - $mode = $filter; |
|
900 | - } |
|
901 | - continue; |
|
902 | - } |
|
903 | - |
|
904 | - // Construct a manual query for unapproved statuses |
|
905 | - if ('is_approved' === $filter['key'] && in_array(\GravityView_Entry_Approval_Status::UNAPPROVED, (array) $filter['value'])) { |
|
906 | - $_tmp_query = new $query_class($view->form->ID, [ |
|
907 | - 'field_filters' => [ |
|
908 | - [ |
|
909 | - 'operator' => 'in', |
|
910 | - 'key' => 'is_approved', |
|
911 | - 'value' => (array) $filter['value'], |
|
912 | - ], |
|
913 | - [ |
|
914 | - 'operator' => 'is', |
|
915 | - 'key' => 'is_approved', |
|
916 | - 'value' => '', |
|
917 | - ], |
|
918 | - 'mode' => 'any', |
|
919 | - ], |
|
920 | - ]); |
|
921 | - $_tmp_query_parts = $_tmp_query->_introspect(); |
|
922 | - |
|
923 | - $extra_conditions[] = $_tmp_query_parts['where']; |
|
924 | - |
|
925 | - $filter = false; |
|
926 | - continue; |
|
927 | - } |
|
928 | - |
|
929 | - // Construct manual query for text mode creator search |
|
930 | - if ('created_by' === $filter['key'] && !empty($created_by_text_mode)) { |
|
931 | - $extra_conditions[] = new GravityView_Widget_Search_Author_GF_Query_Condition($filter, $view); |
|
932 | - $filter = false; |
|
933 | - continue; |
|
934 | - } |
|
935 | - |
|
936 | - // By default, we want searches to be wildcard for each field. |
|
937 | - $filter['operator'] = empty($filter['operator']) ? 'contains' : $filter['operator']; |
|
938 | - |
|
939 | - // For multichoice, let's have an in (OR) search. |
|
940 | - if (is_array($filter['value'])) { |
|
941 | - $filter['operator'] = 'in'; // @todo what about in contains (OR LIKE chains)? |
|
942 | - } |
|
943 | - |
|
944 | - // Default form with joins functionality |
|
945 | - if (empty($filter['form_id'])) { |
|
946 | - $filter['form_id'] = $view->form ? $view->form->ID : 0; |
|
947 | - } |
|
948 | - |
|
949 | - /** |
|
950 | - * @filter `gravityview_search_operator` Modify the search operator for the field (contains, is, isnot, etc) |
|
951 | - * |
|
952 | - * @since 2.0 Added $view parameter |
|
953 | - * |
|
954 | - * @param string $operator Existing search operator |
|
955 | - * @param array $filter array with `key`, `value`, `operator`, `type` keys |
|
956 | - * @param \GV\View $view The View we're operating on. |
|
957 | - */ |
|
958 | - $filter['operator'] = apply_filters('gravityview_search_operator', $filter['operator'], $filter, $view); |
|
959 | - |
|
960 | - if ('is' !== $filter['operator'] && '' === $filter['value']) { |
|
961 | - unset($search_criteria['field_filters'][$key]); |
|
962 | - } |
|
963 | - } |
|
964 | - |
|
965 | - if (!empty($search_criteria['start_date']) || !empty($search_criteria['end_date'])) { |
|
966 | - $date_criteria = []; |
|
967 | - |
|
968 | - if (isset($search_criteria['start_date'])) { |
|
969 | - $date_criteria['start_date'] = $search_criteria['start_date']; |
|
970 | - } |
|
971 | - |
|
972 | - if (isset($search_criteria['end_date'])) { |
|
973 | - $date_criteria['end_date'] = $search_criteria['end_date']; |
|
974 | - } |
|
975 | - |
|
976 | - $_tmp_query = new $query_class($view->form->ID, $date_criteria); |
|
977 | - $_tmp_query_parts = $_tmp_query->_introspect(); |
|
978 | - $extra_conditions[] = $_tmp_query_parts['where']; |
|
979 | - } |
|
980 | - |
|
981 | - $search_conditions = []; |
|
982 | - |
|
983 | - if ($filters = array_filter($search_criteria['field_filters'])) { |
|
984 | - foreach ($filters as &$filter) { |
|
985 | - if (!is_array($filter)) { |
|
986 | - continue; |
|
987 | - } |
|
988 | - |
|
989 | - /** |
|
990 | - * Parse the filter criteria to generate the needed |
|
991 | - * WHERE condition. This is a trick to not write our own generation |
|
992 | - * code by reusing what's inside GF_Query already as they |
|
993 | - * take care of many small things like forcing numeric, etc. |
|
994 | - */ |
|
995 | - $_tmp_query = new $query_class($filter['form_id'], ['mode' => 'any', 'field_filters' => [$filter]]); |
|
996 | - $_tmp_query_parts = $_tmp_query->_introspect(); |
|
997 | - $search_condition = $_tmp_query_parts['where']; |
|
998 | - |
|
999 | - if (empty($filter['key']) && $search_condition->expressions) { |
|
1000 | - $search_conditions[] = $search_condition; |
|
1001 | - } else { |
|
1002 | - $left = $search_condition->left; |
|
1003 | - |
|
1004 | - // When casting a column value to a certain type (e.g., happens with the Number field), GF_Query_Column is wrapped in a GF_Query_Call class. |
|
1005 | - if ($left instanceof GF_Query_Call) { |
|
1006 | - try { |
|
1007 | - $reflectionProperty = new \ReflectionProperty($left, '_parameters'); |
|
1008 | - $reflectionProperty->setAccessible(true); |
|
1009 | - |
|
1010 | - $value = $reflectionProperty->getValue($left); |
|
1011 | - |
|
1012 | - if (!empty($value[0]) && $value[0] instanceof GF_Query_Column) { |
|
1013 | - $left = $value[0]; |
|
1014 | - } else { |
|
1015 | - continue; |
|
1016 | - } |
|
1017 | - } catch (ReflectionException $e) { |
|
1018 | - continue; |
|
1019 | - } |
|
1020 | - } |
|
1021 | - |
|
1022 | - $alias = $query->_alias($left->field_id, $left->source, $left->is_entry_column() ? 't' : 'm'); |
|
1023 | - |
|
1024 | - if ($view->joins && $left->field_id == GF_Query_Column::META) { |
|
1025 | - foreach ($view->joins as $_join) { |
|
1026 | - $on = $_join->join_on; |
|
1027 | - $join = $_join->join; |
|
1028 | - |
|
1029 | - $search_conditions[] = GF_Query_Condition::_or( |
|
1030 | - // Join |
|
1031 | - new GF_Query_Condition( |
|
1032 | - new GF_Query_Column(GF_Query_Column::META, $join->ID, $query->_alias(GF_Query_Column::META, $join->ID, 'm')), |
|
1033 | - $search_condition->operator, |
|
1034 | - $search_condition->right |
|
1035 | - ), |
|
1036 | - // On |
|
1037 | - new GF_Query_Condition( |
|
1038 | - new GF_Query_Column(GF_Query_Column::META, $on->ID, $query->_alias(GF_Query_Column::META, $on->ID, 'm')), |
|
1039 | - $search_condition->operator, |
|
1040 | - $search_condition->right |
|
1041 | - ) |
|
1042 | - ); |
|
1043 | - } |
|
1044 | - } else { |
|
1045 | - $search_conditions[] = new GF_Query_Condition( |
|
1046 | - new GF_Query_Column($left->field_id, $left->source, $alias), |
|
1047 | - $search_condition->operator, |
|
1048 | - $search_condition->right |
|
1049 | - ); |
|
1050 | - } |
|
1051 | - } |
|
1052 | - } |
|
1053 | - |
|
1054 | - if ($search_conditions) { |
|
1055 | - $search_conditions = [call_user_func_array('\GF_Query_Condition::'.($mode == 'all' ? '_and' : '_or'), $search_conditions)]; |
|
1056 | - } |
|
1057 | - } |
|
1058 | - |
|
1059 | - /** |
|
1060 | - * Grab the current clauses. We'll be combining them shortly. |
|
1061 | - */ |
|
1062 | - $query_parts = $query->_introspect(); |
|
1063 | - |
|
1064 | - /** |
|
1065 | - * Combine the parts as a new WHERE clause. |
|
1066 | - */ |
|
1067 | - $where = call_user_func_array('\GF_Query_Condition::_and', array_merge([$query_parts['where']], $search_conditions, $extra_conditions)); |
|
1068 | - $query->where($where); |
|
1069 | - } |
|
1070 | - |
|
1071 | - /** |
|
1072 | - * Convert $_GET/$_POST key to the field/meta ID. |
|
1073 | - * |
|
1074 | - * Examples: |
|
1075 | - * - `filter_is_starred` => `is_starred` |
|
1076 | - * - `filter_1_2` => `1.2` |
|
1077 | - * - `filter_5` => `5` |
|
1078 | - * |
|
1079 | - * @since 2.0 |
|
1080 | - * |
|
1081 | - * @param string $key $_GET/_$_POST search key |
|
1082 | - * |
|
1083 | - * @return string |
|
1084 | - */ |
|
1085 | - private function convert_request_key_to_filter_key($key) |
|
1086 | - { |
|
1087 | - $field_id = str_replace(['filter_', 'input_'], '', $key); |
|
1088 | - |
|
1089 | - // calculates field_id, removing 'filter_' and for '_' for advanced fields ( like name or checkbox ) |
|
1090 | - if (preg_match('/^[0-9_]+$/ism', $field_id)) { |
|
1091 | - $field_id = str_replace('_', '.', $field_id); |
|
1092 | - } |
|
1093 | - |
|
1094 | - return $field_id; |
|
1095 | - } |
|
1096 | - |
|
1097 | - /** |
|
1098 | - * Prepare the field filters to GFAPI. |
|
1099 | - * |
|
1100 | - * The type post_category, multiselect and checkbox support multi-select search - each value needs to be separated in an independent filter so we could apply the ANY search mode. |
|
1101 | - * |
|
1102 | - * Format searched values |
|
1103 | - * |
|
1104 | - * @param string $filter_key ID of the field, or entry meta key |
|
1105 | - * @param string $value $_GET/$_POST search value |
|
1106 | - * @param \GV\View $view The view we're looking at |
|
1107 | - * @param array[] $searchable_fields The searchable fields as configured by the widget. |
|
1108 | - * @param string[] $get The $_GET/$_POST array. |
|
1109 | - * |
|
1110 | - * @since develop Added 5th $get parameter for operator overrides. |
|
1111 | - * |
|
1112 | - * @todo Set function as private. |
|
1113 | - * |
|
1114 | - * @return array|false 1 or 2 deph levels, false if not allowed |
|
1115 | - */ |
|
1116 | - public function prepare_field_filter($filter_key, $value, $view, $searchable_fields, $get = []) |
|
1117 | - { |
|
1118 | - $key = $filter_key; |
|
1119 | - $filter_key = explode(':', $filter_key); // field_id, form_id |
|
1120 | - |
|
1121 | - $form = null; |
|
1122 | - |
|
1123 | - if (count($filter_key) > 1) { |
|
1124 | - // form is specified |
|
1125 | - list($field_id, $form_id) = $filter_key; |
|
1126 | - |
|
1127 | - if ($forms = \GV\View::get_joined_forms($view->ID)) { |
|
1128 | - if (!$form = \GV\GF_Form::by_id($form_id)) { |
|
1129 | - return false; |
|
1130 | - } |
|
1131 | - } |
|
1132 | - |
|
1133 | - // form is allowed |
|
1134 | - $found = false; |
|
1135 | - foreach ($forms as $form) { |
|
1136 | - if ($form->ID == $form_id) { |
|
1137 | - $found = true; |
|
1138 | - break; |
|
1139 | - } |
|
1140 | - } |
|
1141 | - |
|
1142 | - if (!$found) { |
|
1143 | - return false; |
|
1144 | - } |
|
1145 | - |
|
1146 | - // form is in searchable fields |
|
1147 | - $found = false; |
|
1148 | - foreach ($searchable_fields as $field) { |
|
1149 | - if ($field_id == $field['field'] && $form->ID == $field['form_id']) { |
|
1150 | - $found = true; |
|
1151 | - break; |
|
1152 | - } |
|
1153 | - } |
|
1154 | - |
|
1155 | - if (!$found) { |
|
1156 | - return false; |
|
1157 | - } |
|
1158 | - } else { |
|
1159 | - $field_id = reset($filter_key); |
|
1160 | - $searchable_fields = wp_list_pluck($searchable_fields, 'field'); |
|
1161 | - if (!in_array('search_all', $searchable_fields) && !in_array($field_id, $searchable_fields)) { |
|
1162 | - return false; |
|
1163 | - } |
|
1164 | - } |
|
1165 | - |
|
1166 | - if (!$form) { |
|
1167 | - // fallback |
|
1168 | - $form = $view->form; |
|
1169 | - } |
|
1170 | - |
|
1171 | - // get form field array |
|
1172 | - $form_field = is_numeric($field_id) ? \GV\GF_Field::by_id($form, $field_id) : \GV\Internal_Field::by_id($field_id); |
|
1173 | - |
|
1174 | - if (!$form_field) { |
|
1175 | - return false; |
|
1176 | - } |
|
1177 | - |
|
1178 | - // default filter array |
|
1179 | - $filter = [ |
|
1180 | - 'key' => $field_id, |
|
1181 | - 'value' => $value, |
|
1182 | - 'form_id' => $form->ID, |
|
1183 | - ]; |
|
1184 | - |
|
1185 | - switch ($form_field->type) { |
|
1186 | - |
|
1187 | - case 'select': |
|
1188 | - case 'radio': |
|
1189 | - $filter['operator'] = $this->get_operator($get, $key, ['is'], 'is'); |
|
1190 | - break; |
|
1191 | - |
|
1192 | - case 'post_category': |
|
1193 | - |
|
1194 | - if (!is_array($value)) { |
|
1195 | - $value = [$value]; |
|
1196 | - } |
|
1197 | - |
|
1198 | - // Reset filter variable |
|
1199 | - $filter = []; |
|
1200 | - |
|
1201 | - foreach ($value as $val) { |
|
1202 | - $cat = get_term($val, 'category'); |
|
1203 | - $filter[] = [ |
|
1204 | - 'key' => $field_id, |
|
1205 | - 'value' => esc_attr($cat->name).':'.$val, |
|
1206 | - 'operator' => $this->get_operator($get, $key, ['is'], 'is'), |
|
1207 | - ]; |
|
1208 | - } |
|
1209 | - |
|
1210 | - break; |
|
1211 | - |
|
1212 | - case 'multiselect': |
|
1213 | - |
|
1214 | - if (!is_array($value)) { |
|
1215 | - break; |
|
1216 | - } |
|
1217 | - |
|
1218 | - // Reset filter variable |
|
1219 | - $filter = []; |
|
1220 | - |
|
1221 | - foreach ($value as $val) { |
|
1222 | - $filter[] = ['key' => $field_id, 'value' => $val]; |
|
1223 | - } |
|
1224 | - |
|
1225 | - break; |
|
1226 | - |
|
1227 | - case 'checkbox': |
|
1228 | - // convert checkbox on/off into the correct search filter |
|
1229 | - if (false !== strpos($field_id, '.') && !empty($form_field->inputs) && !empty($form_field->choices)) { |
|
1230 | - foreach ($form_field->inputs as $k => $input) { |
|
1231 | - if ($input['id'] == $field_id) { |
|
1232 | - $filter['value'] = $form_field->choices[$k]['value']; |
|
1233 | - $filter['operator'] = $this->get_operator($get, $key, ['is'], 'is'); |
|
1234 | - break; |
|
1235 | - } |
|
1236 | - } |
|
1237 | - } elseif (is_array($value)) { |
|
1238 | - |
|
1239 | - // Reset filter variable |
|
1240 | - $filter = []; |
|
1241 | - |
|
1242 | - foreach ($value as $val) { |
|
1243 | - $filter[] = [ |
|
1244 | - 'key' => $field_id, |
|
1245 | - 'value' => $val, |
|
1246 | - 'operator' => $this->get_operator($get, $key, ['is'], 'is'), |
|
1247 | - ]; |
|
1248 | - } |
|
1249 | - } |
|
1250 | - |
|
1251 | - break; |
|
1252 | - |
|
1253 | - case 'name': |
|
1254 | - case 'address': |
|
1255 | - |
|
1256 | - if (false === strpos($field_id, '.')) { |
|
1257 | - $words = explode(' ', $value); |
|
1258 | - |
|
1259 | - $filters = []; |
|
1260 | - foreach ($words as $word) { |
|
1261 | - if (!empty($word) && strlen($word) > 1) { |
|
1262 | - // Keep the same key for each filter |
|
1263 | - $filter['value'] = $word; |
|
1264 | - // Add a search for the value |
|
1265 | - $filters[] = $filter; |
|
1266 | - } |
|
1267 | - } |
|
1268 | - |
|
1269 | - $filter = $filters; |
|
1270 | - } |
|
1271 | - |
|
1272 | - // State/Province should be exact matches |
|
1273 | - if ('address' === $form_field->field->type) { |
|
1274 | - $searchable_fields = $this->get_view_searchable_fields($view, true); |
|
1275 | - |
|
1276 | - foreach ($searchable_fields as $searchable_field) { |
|
1277 | - if ($form_field->ID !== $searchable_field['field']) { |
|
1278 | - continue; |
|
1279 | - } |
|
1280 | - |
|
1281 | - // Only exact-match dropdowns, not text search |
|
1282 | - if (in_array($searchable_field['input'], ['text', 'search'], true)) { |
|
1283 | - continue; |
|
1284 | - } |
|
1285 | - |
|
1286 | - $input_id = gravityview_get_input_id_from_id($form_field->ID); |
|
1287 | - |
|
1288 | - if (4 === $input_id) { |
|
1289 | - $filter['operator'] = $this->get_operator($get, $key, ['is'], 'is'); |
|
1290 | - } |
|
1291 | - } |
|
1292 | - } |
|
1293 | - |
|
1294 | - break; |
|
1295 | - |
|
1296 | - case 'payment_date': |
|
1297 | - case 'date': |
|
1298 | - |
|
1299 | - $date_format = $this->get_datepicker_format(true); |
|
1300 | - |
|
1301 | - if (is_array($value)) { |
|
1302 | - |
|
1303 | - // Reset filter variable |
|
1304 | - $filter = []; |
|
1305 | - |
|
1306 | - foreach ($value as $k => $date) { |
|
1307 | - if (empty($date)) { |
|
1308 | - continue; |
|
1309 | - } |
|
1310 | - $operator = 'start' === $k ? '>=' : '<='; |
|
1311 | - |
|
1312 | - /** |
|
1313 | - * @hack |
|
1314 | - * |
|
1315 | - * @since 1.16.3 |
|
1316 | - * Safeguard until GF implements '<=' operator |
|
1317 | - */ |
|
1318 | - if (!GFFormsModel::is_valid_operator($operator) && $operator === '<=') { |
|
1319 | - $operator = '<'; |
|
1320 | - $date = date('Y-m-d', strtotime(self::get_formatted_date($date, 'Y-m-d', $date_format).' +1 day')); |
|
1321 | - } |
|
1322 | - |
|
1323 | - $filter[] = [ |
|
1324 | - 'key' => $field_id, |
|
1325 | - 'value' => self::get_formatted_date($date, 'Y-m-d', $date_format), |
|
1326 | - 'operator' => $this->get_operator($get, $key, [$operator], $operator), |
|
1327 | - ]; |
|
1328 | - } |
|
1329 | - } else { |
|
1330 | - $date = $value; |
|
1331 | - $filter['value'] = self::get_formatted_date($date, 'Y-m-d', $date_format); |
|
1332 | - $filter['operator'] = $this->get_operator($get, $key, ['is'], 'is'); |
|
1333 | - } |
|
1334 | - |
|
1335 | - if ('payment_date' === $key) { |
|
1336 | - $filter['operator'] = 'contains'; |
|
1337 | - } |
|
1338 | - |
|
1339 | - break; |
|
1340 | - } // switch field type |
|
1341 | - |
|
1342 | - return $filter; |
|
1343 | - } |
|
1344 | - |
|
1345 | - /** |
|
1346 | - * Get the Field Format form GravityForms. |
|
1347 | - * |
|
1348 | - * @param GF_Field_Date $field The field object |
|
1349 | - * |
|
1350 | - * @since 1.10 |
|
1351 | - * |
|
1352 | - * @return string Format of the date in the database |
|
1353 | - */ |
|
1354 | - public static function get_date_field_format(GF_Field_Date $field) |
|
1355 | - { |
|
1356 | - $format = 'm/d/Y'; |
|
1357 | - $datepicker = [ |
|
1358 | - 'mdy' => 'm/d/Y', |
|
1359 | - 'dmy' => 'd/m/Y', |
|
1360 | - 'dmy_dash' => 'd-m-Y', |
|
1361 | - 'dmy_dot' => 'd.m.Y', |
|
1362 | - 'ymd_slash' => 'Y/m/d', |
|
1363 | - 'ymd_dash' => 'Y-m-d', |
|
1364 | - 'ymd_dot' => 'Y.m.d', |
|
1365 | - ]; |
|
1366 | - |
|
1367 | - if (!empty($field->dateFormat) && isset($datepicker[$field->dateFormat])) { |
|
1368 | - $format = $datepicker[$field->dateFormat]; |
|
1369 | - } |
|
1370 | - |
|
1371 | - return $format; |
|
1372 | - } |
|
1373 | - |
|
1374 | - /** |
|
1375 | - * Format a date value. |
|
1376 | - * |
|
1377 | - * @param string $value Date value input |
|
1378 | - * @param string $format Wanted formatted date |
|
1379 | - * |
|
1380 | - * @since 2.1.2 |
|
1381 | - * |
|
1382 | - * @param string $value_format The value format. Default: Y-m-d |
|
1383 | - * |
|
1384 | - * @return string |
|
1385 | - */ |
|
1386 | - public static function get_formatted_date($value = '', $format = 'Y-m-d', $value_format = 'Y-m-d') |
|
1387 | - { |
|
1388 | - $date = date_create_from_format($value_format, $value); |
|
1389 | - |
|
1390 | - if (empty($date)) { |
|
1391 | - gravityview()->log->debug('Date format not valid: {value}', ['value' => $value]); |
|
1392 | - |
|
1393 | - return ''; |
|
1394 | - } |
|
1395 | - |
|
1396 | - return $date->format($format); |
|
1397 | - } |
|
1398 | - |
|
1399 | - /** |
|
1400 | - * Include this extension templates path. |
|
1401 | - * |
|
1402 | - * @param array $file_paths List of template paths ordered |
|
1403 | - */ |
|
1404 | - public function add_template_path($file_paths) |
|
1405 | - { |
|
1406 | - |
|
1407 | - // Index 100 is the default GravityView template path. |
|
1408 | - $file_paths[102] = self::$file.'templates/'; |
|
1409 | - |
|
1410 | - return $file_paths; |
|
1411 | - } |
|
1412 | - |
|
1413 | - /** |
|
1414 | - * Check whether the configured search fields have a date field. |
|
1415 | - * |
|
1416 | - * @since 1.17.5 |
|
1417 | - * |
|
1418 | - * @param array $search_fields |
|
1419 | - * |
|
1420 | - * @return bool True: has a `date` or `date_range` field |
|
1421 | - */ |
|
1422 | - private function has_date_field($search_fields) |
|
1423 | - { |
|
1424 | - $has_date = false; |
|
1425 | - |
|
1426 | - foreach ($search_fields as $k => $field) { |
|
1427 | - if (in_array($field['input'], ['date', 'date_range', 'entry_date'])) { |
|
1428 | - $has_date = true; |
|
1429 | - break; |
|
1430 | - } |
|
1431 | - } |
|
1432 | - |
|
1433 | - return $has_date; |
|
1434 | - } |
|
1435 | - |
|
1436 | - /** |
|
1437 | - * Renders the Search Widget. |
|
1438 | - * |
|
1439 | - * @param array $widget_args |
|
1440 | - * @param string $content |
|
1441 | - * @param string|\GV\Template_Context $context |
|
1442 | - * |
|
1443 | - * @return void |
|
1444 | - */ |
|
1445 | - public function render_frontend($widget_args, $content = '', $context = '') |
|
1446 | - { |
|
1447 | - $gravityview_view = GravityView_View::getInstance(); |
|
1448 | - |
|
1449 | - if (empty($gravityview_view)) { |
|
1450 | - gravityview()->log->debug('$gravityview_view not instantiated yet.'); |
|
1451 | - |
|
1452 | - return; |
|
1453 | - } |
|
1454 | - |
|
1455 | - $view = \GV\View::by_id($gravityview_view->view_id); |
|
1456 | - |
|
1457 | - // get configured search fields |
|
1458 | - $search_fields = !empty($widget_args['search_fields']) ? json_decode($widget_args['search_fields'], true) : ''; |
|
1459 | - |
|
1460 | - if (empty($search_fields) || !is_array($search_fields)) { |
|
1461 | - gravityview()->log->debug('No search fields configured for widget:', ['data' => $widget_args]); |
|
1462 | - |
|
1463 | - return; |
|
1464 | - } |
|
1465 | - |
|
1466 | - // prepare fields |
|
1467 | - foreach ($search_fields as $k => $field) { |
|
1468 | - $updated_field = $field; |
|
1469 | - |
|
1470 | - $updated_field = $this->get_search_filter_details($updated_field, $context); |
|
1471 | - |
|
1472 | - switch ($field['field']) { |
|
1473 | - |
|
1474 | - case 'search_all': |
|
1475 | - $updated_field['key'] = 'search_all'; |
|
1476 | - $updated_field['input'] = 'search_all'; |
|
1477 | - $updated_field['value'] = $this->rgget_or_rgpost('gv_search'); |
|
1478 | - break; |
|
1479 | - |
|
1480 | - case 'entry_date': |
|
1481 | - $updated_field['key'] = 'entry_date'; |
|
1482 | - $updated_field['input'] = 'entry_date'; |
|
1483 | - $updated_field['value'] = [ |
|
1484 | - 'start' => $this->rgget_or_rgpost('gv_start'), |
|
1485 | - 'end' => $this->rgget_or_rgpost('gv_end'), |
|
1486 | - ]; |
|
1487 | - break; |
|
1488 | - |
|
1489 | - case 'entry_id': |
|
1490 | - $updated_field['key'] = 'entry_id'; |
|
1491 | - $updated_field['input'] = 'entry_id'; |
|
1492 | - $updated_field['value'] = $this->rgget_or_rgpost('gv_id'); |
|
1493 | - break; |
|
1494 | - |
|
1495 | - case 'created_by': |
|
1496 | - $updated_field['key'] = 'created_by'; |
|
1497 | - $updated_field['name'] = 'gv_by'; |
|
1498 | - $updated_field['value'] = $this->rgget_or_rgpost('gv_by'); |
|
1499 | - break; |
|
1500 | - |
|
1501 | - case 'is_approved': |
|
1502 | - $updated_field['key'] = 'is_approved'; |
|
1503 | - $updated_field['value'] = $this->rgget_or_rgpost('filter_is_approved'); |
|
1504 | - $updated_field['choices'] = self::get_is_approved_choices(); |
|
1505 | - break; |
|
1506 | - } |
|
1507 | - |
|
1508 | - $search_fields[$k] = $updated_field; |
|
1509 | - } |
|
1510 | - |
|
1511 | - gravityview()->log->debug('Calculated Search Fields: ', ['data' => $search_fields]); |
|
1512 | - |
|
1513 | - /** |
|
1514 | - * @filter `gravityview_widget_search_filters` Modify what fields are shown. The order of the fields in the $search_filters array controls the order as displayed in the search bar widget. |
|
1515 | - * |
|
1516 | - * @param array $search_fields Array of search filters with `key`, `label`, `value`, `type`, `choices` keys |
|
1517 | - * @param GravityView_Widget_Search $this Current widget object |
|
1518 | - * @param array $widget_args Args passed to this method. {@since 1.8} |
|
1519 | - * @param \GV\Template_Context $context {@since 2.0} |
|
1520 | - * |
|
1521 | - * @var array |
|
1522 | - */ |
|
1523 | - $gravityview_view->search_fields = apply_filters('gravityview_widget_search_filters', $search_fields, $this, $widget_args, $context); |
|
1524 | - |
|
1525 | - $gravityview_view->permalink_fields = $this->add_no_permalink_fields([], $this, $widget_args); |
|
1526 | - |
|
1527 | - $gravityview_view->search_layout = !empty($widget_args['search_layout']) ? $widget_args['search_layout'] : 'horizontal'; |
|
1528 | - |
|
1529 | - /** @since 1.14 */ |
|
1530 | - $gravityview_view->search_mode = !empty($widget_args['search_mode']) ? $widget_args['search_mode'] : 'any'; |
|
1531 | - |
|
1532 | - $custom_class = !empty($widget_args['custom_class']) ? $widget_args['custom_class'] : ''; |
|
1533 | - |
|
1534 | - $gravityview_view->search_class = self::get_search_class($custom_class); |
|
1535 | - |
|
1536 | - $gravityview_view->search_clear = !empty($widget_args['search_clear']) ? $widget_args['search_clear'] : false; |
|
1537 | - |
|
1538 | - if ($this->has_date_field($search_fields)) { |
|
1539 | - // enqueue datepicker stuff only if needed! |
|
1540 | - $this->enqueue_datepicker(); |
|
1541 | - } |
|
1542 | - |
|
1543 | - $this->maybe_enqueue_flexibility(); |
|
1544 | - |
|
1545 | - $gravityview_view->render('widget', 'search', false); |
|
1546 | - } |
|
1547 | - |
|
1548 | - /** |
|
1549 | - * Get the search class for a search form. |
|
1550 | - * |
|
1551 | - * @since 1.5.4 |
|
1552 | - * |
|
1553 | - * @return string Sanitized CSS class for the search form |
|
1554 | - */ |
|
1555 | - public static function get_search_class($custom_class = '') |
|
1556 | - { |
|
1557 | - $gravityview_view = GravityView_View::getInstance(); |
|
1558 | - |
|
1559 | - $search_class = 'gv-search-'.$gravityview_view->search_layout; |
|
1560 | - |
|
1561 | - if (!empty($custom_class)) { |
|
1562 | - $search_class .= ' '.$custom_class; |
|
1563 | - } |
|
1564 | - |
|
1565 | - /** |
|
1566 | - * @filter `gravityview_search_class` Modify the CSS class for the search form |
|
1567 | - * |
|
1568 | - * @param string $search_class The CSS class for the search form |
|
1569 | - */ |
|
1570 | - $search_class = apply_filters('gravityview_search_class', $search_class); |
|
1571 | - |
|
1572 | - // Is there an active search being performed? Used by fe-views.js |
|
1573 | - $search_class .= gravityview()->request->is_search() || GravityView_frontend::getInstance()->isSearch() ? ' gv-is-search' : ''; |
|
1574 | - |
|
1575 | - return gravityview_sanitize_html_class($search_class); |
|
1576 | - } |
|
1577 | - |
|
1578 | - /** |
|
1579 | - * Calculate the search form action. |
|
1580 | - * |
|
1581 | - * @since 1.6 |
|
1582 | - * |
|
1583 | - * @return string |
|
1584 | - */ |
|
1585 | - public static function get_search_form_action() |
|
1586 | - { |
|
1587 | - $gravityview_view = GravityView_View::getInstance(); |
|
1588 | - |
|
1589 | - $post_id = $gravityview_view->getPostId() ? $gravityview_view->getPostId() : $gravityview_view->getViewId(); |
|
1590 | - |
|
1591 | - $url = add_query_arg([], get_permalink($post_id)); |
|
1592 | - |
|
1593 | - /** |
|
1594 | - * @filter `gravityview/widget/search/form/action` Override the search URL. |
|
1595 | - * |
|
1596 | - * @param string $action Where the form submits to. |
|
1597 | - * |
|
1598 | - * Further parameters will be added once adhoc context is added. |
|
1599 | - * Use gravityview()->request until then. |
|
1600 | - */ |
|
1601 | - return apply_filters('gravityview/widget/search/form/action', $url); |
|
1602 | - } |
|
1603 | - |
|
1604 | - /** |
|
1605 | - * Get the label for a search form field. |
|
1606 | - * |
|
1607 | - * @param array $field Field setting as sent by the GV configuration - has `field`, `input` (input type), and `label` keys |
|
1608 | - * @param array $form_field Form field data, as fetched by `gravityview_get_field()` |
|
1609 | - * |
|
1610 | - * @return string Label for the search form |
|
1611 | - */ |
|
1612 | - private static function get_field_label($field, $form_field = []) |
|
1613 | - { |
|
1614 | - $label = \GV\Utils::_GET('label', \GV\Utils::get($field, 'label')); |
|
1615 | - |
|
1616 | - if (!$label) { |
|
1617 | - $label = isset($form_field['label']) ? $form_field['label'] : ''; |
|
1618 | - |
|
1619 | - switch ($field['field']) { |
|
1620 | - case 'search_all': |
|
1621 | - $label = __('Search Entries:', 'gravityview'); |
|
1622 | - break; |
|
1623 | - case 'entry_date': |
|
1624 | - $label = __('Filter by date:', 'gravityview'); |
|
1625 | - break; |
|
1626 | - case 'entry_id': |
|
1627 | - $label = __('Entry ID:', 'gravityview'); |
|
1628 | - break; |
|
1629 | - default: |
|
1630 | - // If this is a field input, not a field |
|
1631 | - if (strpos($field['field'], '.') > 0 && !empty($form_field['inputs'])) { |
|
1632 | - |
|
1633 | - // Get the label for the field in question, which returns an array |
|
1634 | - $items = wp_list_filter($form_field['inputs'], ['id' => $field['field']]); |
|
1635 | - |
|
1636 | - // Get the item with the `label` key |
|
1637 | - $values = wp_list_pluck($items, 'label'); |
|
1638 | - |
|
1639 | - // There will only one item in the array, but this is easier |
|
1640 | - foreach ($values as $value) { |
|
1641 | - $label = $value; |
|
1642 | - break; |
|
1643 | - } |
|
1644 | - } |
|
1645 | - } |
|
1646 | - } |
|
1647 | - |
|
1648 | - /** |
|
1649 | - * @filter `gravityview_search_field_label` Modify the label for a search field. Supports returning HTML |
|
1650 | - * |
|
1651 | - * @since 1.17.3 Added $field parameter |
|
1652 | - * |
|
1653 | - * @param string $label Existing label text, sanitized. |
|
1654 | - * @param array $form_field Gravity Forms field array, as returned by `GFFormsModel::get_field()` |
|
1655 | - * @param array $field Field setting as sent by the GV configuration - has `field`, `input` (input type), and `label` keys |
|
1656 | - */ |
|
1657 | - $label = apply_filters('gravityview_search_field_label', esc_attr($label), $form_field, $field); |
|
1658 | - |
|
1659 | - return $label; |
|
1660 | - } |
|
1661 | - |
|
1662 | - /** |
|
1663 | - * Prepare search fields to frontend render with other details (label, field type, searched values). |
|
1664 | - * |
|
1665 | - * @param array $field |
|
1666 | - * @param \GV\Context $context |
|
1667 | - * |
|
1668 | - * @return array |
|
1669 | - */ |
|
1670 | - private function get_search_filter_details($field, $context) |
|
1671 | - { |
|
1672 | - $gravityview_view = GravityView_View::getInstance(); |
|
1673 | - |
|
1674 | - $form = $gravityview_view->getForm(); |
|
1675 | - |
|
1676 | - // for advanced field ids (eg, first name / last name ) |
|
1677 | - $name = 'filter_'.str_replace('.', '_', $field['field']); |
|
1678 | - |
|
1679 | - // get searched value from $_GET/$_POST (string or array) |
|
1680 | - $value = $this->rgget_or_rgpost($name); |
|
1681 | - |
|
1682 | - // get form field details |
|
1683 | - $form_field = gravityview_get_field($form, $field['field']); |
|
1684 | - |
|
1685 | - $form_field_type = \GV\Utils::get($form_field, 'type'); |
|
1686 | - |
|
1687 | - $filter = [ |
|
1688 | - 'key' => \GV\Utils::get($field, 'field'), |
|
1689 | - 'name' => $name, |
|
1690 | - 'label' => self::get_field_label($field, $form_field), |
|
1691 | - 'input' => \GV\Utils::get($field, 'input'), |
|
1692 | - 'value' => $value, |
|
1693 | - 'type' => $form_field_type, |
|
1694 | - ]; |
|
1695 | - |
|
1696 | - // collect choices |
|
1697 | - if ('post_category' === $form_field_type && !empty($form_field['displayAllCategories']) && empty($form_field['choices'])) { |
|
1698 | - $filter['choices'] = gravityview_get_terms_choices(); |
|
1699 | - } elseif (!empty($form_field['choices'])) { |
|
1700 | - $filter['choices'] = $form_field['choices']; |
|
1701 | - } |
|
1702 | - |
|
1703 | - if ('date_range' === $field['input'] && empty($value)) { |
|
1704 | - $filter['value'] = ['start' => '', 'end' => '']; |
|
1705 | - } |
|
1706 | - |
|
1707 | - if ('created_by' === $field['field']) { |
|
1708 | - $filter['choices'] = self::get_created_by_choices($context->view); |
|
1709 | - $filter['type'] = 'created_by'; |
|
1710 | - } |
|
1711 | - |
|
1712 | - if (!empty($filter['choices'])) { |
|
1713 | - /** |
|
1714 | - * @filter `gravityview/search/sieve_choices` Only output used choices for this field. |
|
1715 | - * |
|
1716 | - * @param bool Yes or no. |
|
1717 | - * @param array $field The field configuration. |
|
1718 | - * @param \GV\Context The context. |
|
1719 | - */ |
|
1720 | - if (apply_filters('gravityview/search/sieve_choices', false, $field, $context)) { |
|
1721 | - $filter['choices'] = $this->sieve_filter_choices($filter, $context); |
|
1722 | - } |
|
1723 | - } |
|
1724 | - |
|
1725 | - /** |
|
1726 | - * @filter `gravityview/search/filter_details` Filter the output filter details for the Search widget. |
|
1727 | - * |
|
1728 | - * @param array $filter The filter details |
|
1729 | - * @param array $field The search field configuration |
|
1730 | - * @param \GV\Context The context |
|
1731 | - * |
|
1732 | - * @since develop |
|
1733 | - */ |
|
1734 | - $filter = apply_filters('gravityview/search/filter_details', $filter, $field, $context); |
|
1735 | - |
|
1736 | - return $filter; |
|
1737 | - } |
|
1738 | - |
|
1739 | - /** |
|
1740 | - * Sieve filter choices to only ones that are used. |
|
1741 | - * |
|
1742 | - * @param array $filter The filter configuration. |
|
1743 | - * @param \GV\Context $context The context |
|
1744 | - * |
|
1745 | - * @since develop |
|
1746 | - * |
|
1747 | - * @internal |
|
1748 | - * |
|
1749 | - * @return array The filter choices. |
|
1750 | - */ |
|
1751 | - private function sieve_filter_choices($filter, $context) |
|
1752 | - { |
|
1753 | - if (empty($filter['key']) || empty($filter['choices'])) { |
|
1754 | - return $filter; // @todo Populate plugins might give us empty choices |
|
1755 | - } |
|
1756 | - |
|
1757 | - // Allow only created_by and field-ids to be sieved. |
|
1758 | - if ('created_by' !== $filter['key'] && !is_numeric($filter['key'])) { |
|
1759 | - return $filter; |
|
1760 | - } |
|
1761 | - |
|
1762 | - $form_id = $context->view->form->ID; // @todo Support multiple forms (joins) |
|
1763 | - |
|
1764 | - global $wpdb; |
|
1765 | - |
|
1766 | - $entry_table_name = GFFormsModel::get_entry_table_name(); |
|
1767 | - $entry_meta_table_name = GFFormsModel::get_entry_meta_table_name(); |
|
1768 | - |
|
1769 | - $key_like = $wpdb->esc_like($filter['key']).'.%'; |
|
1770 | - |
|
1771 | - switch (\GV\Utils::get($filter, 'type')) { |
|
1772 | - case 'post_category': |
|
1773 | - $choices = $wpdb->get_col($wpdb->prepare( |
|
1774 | - "SELECT DISTINCT SUBSTRING_INDEX(meta_value, ':', 1) FROM $entry_meta_table_name WHERE (meta_key LIKE %s OR meta_key = %d) AND form_id = %d", |
|
1775 | - $key_like, |
|
1776 | - $filter['key'], |
|
1777 | - $form_id |
|
1778 | - )); |
|
1779 | - break; |
|
1780 | - case 'created_by': |
|
1781 | - $choices = $wpdb->get_col($wpdb->prepare( |
|
1782 | - "SELECT DISTINCT created_by FROM $entry_table_name WHERE form_id = %d", |
|
1783 | - $form_id |
|
1784 | - )); |
|
1785 | - break; |
|
1786 | - default: |
|
1787 | - $choices = $wpdb->get_col($wpdb->prepare( |
|
1788 | - "SELECT DISTINCT meta_value FROM $entry_meta_table_name WHERE (meta_key LIKE %s OR meta_key = %d) AND form_id = %d", |
|
1789 | - $key_like, |
|
1790 | - $filter['key'], |
|
1791 | - $form_id |
|
1792 | - )); |
|
1793 | - |
|
1794 | - if (($field = gravityview_get_field($form_id, $filter['key'])) && 'json' === $field->storageType) { |
|
1795 | - $choices = array_map('json_decode', $choices); |
|
1796 | - $_choices_array = []; |
|
1797 | - foreach ($choices as $choice) { |
|
1798 | - if (is_array($choice)) { |
|
1799 | - $_choices_array = array_merge($_choices_array, $choice); |
|
1800 | - } else { |
|
1801 | - $_choices_array[] = $choice; |
|
1802 | - } |
|
1803 | - } |
|
1804 | - $choices = array_unique($_choices_array); |
|
1805 | - } |
|
1806 | - |
|
1807 | - break; |
|
1808 | - } |
|
1809 | - |
|
1810 | - $filter_choices = []; |
|
1811 | - foreach ($filter['choices'] as $choice) { |
|
1812 | - if (in_array($choice['text'], $choices, true) || in_array($choice['value'], $choices, true)) { |
|
1813 | - $filter_choices[] = $choice; |
|
1814 | - } |
|
1815 | - } |
|
1816 | - |
|
1817 | - return $filter_choices; |
|
1818 | - } |
|
1819 | - |
|
1820 | - /** |
|
1821 | - * Calculate the search choices for the users. |
|
1822 | - * |
|
1823 | - * @param \GV\View $view The view |
|
1824 | - * |
|
1825 | - * @since develop |
|
1826 | - * @since 1.8 |
|
1827 | - * |
|
1828 | - * @return array Array of user choices (value = ID, text = display name) |
|
1829 | - */ |
|
1830 | - private static function get_created_by_choices($view) |
|
1831 | - { |
|
1832 | - |
|
1833 | - /** |
|
1834 | - * filter gravityview/get_users/search_widget. |
|
1835 | - * |
|
1836 | - * @see \GVCommon::get_users |
|
1837 | - */ |
|
1838 | - $users = GVCommon::get_users('search_widget', ['fields' => ['ID', 'display_name']]); |
|
1839 | - |
|
1840 | - $choices = []; |
|
1841 | - foreach ($users as $user) { |
|
1842 | - /** |
|
1843 | - * @filter `gravityview/search/created_by/text` Filter the display text in created by search choices |
|
1844 | - * |
|
1845 | - * @since develop |
|
1846 | - * |
|
1847 | - * @param string[in,out] The text. Default: $user->display_name |
|
1848 | - * @param \WP_User $user The user. |
|
1849 | - * @param \GV\View $view The view. |
|
1850 | - */ |
|
1851 | - $text = apply_filters('gravityview/search/created_by/text', $user->display_name, $user, $view); |
|
1852 | - $choices[] = [ |
|
1853 | - 'value' => $user->ID, |
|
1854 | - 'text' => $text, |
|
1855 | - ]; |
|
1856 | - } |
|
1857 | - |
|
1858 | - return $choices; |
|
1859 | - } |
|
1860 | - |
|
1861 | - /** |
|
1862 | - * Calculate the search checkbox choices for approval status. |
|
1863 | - * |
|
1864 | - * @since develop |
|
1865 | - * |
|
1866 | - * @return array Array of approval status choices (value = status, text = display name) |
|
1867 | - */ |
|
1868 | - private static function get_is_approved_choices() |
|
1869 | - { |
|
1870 | - $choices = []; |
|
1871 | - foreach (GravityView_Entry_Approval_Status::get_all() as $status) { |
|
1872 | - $choices[] = [ |
|
1873 | - 'value' => $status['value'], |
|
1874 | - 'text' => $status['label'], |
|
1875 | - ]; |
|
1876 | - } |
|
1877 | - |
|
1878 | - return $choices; |
|
1879 | - } |
|
1880 | - |
|
1881 | - /** |
|
1882 | - * Output the Clear Search Results button. |
|
1883 | - * |
|
1884 | - * @since 1.5.4 |
|
1885 | - */ |
|
1886 | - public static function the_clear_search_button() |
|
1887 | - { |
|
1888 | - $gravityview_view = GravityView_View::getInstance(); |
|
1889 | - |
|
1890 | - if ($gravityview_view->search_clear) { |
|
1891 | - $url = strtok(add_query_arg([]), '?'); |
|
1892 | - |
|
1893 | - echo gravityview_get_link($url, esc_html__('Clear', 'gravityview'), 'class=button gv-search-clear'); |
|
1894 | - } |
|
1895 | - } |
|
1896 | - |
|
1897 | - /** |
|
1898 | - * Based on the search method, fetch the value for a specific key. |
|
1899 | - * |
|
1900 | - * @since 1.16.4 |
|
1901 | - * |
|
1902 | - * @param string $name Name of the request key to fetch the value for |
|
1903 | - * |
|
1904 | - * @return mixed|string Value of request at $name key. Empty string if empty. |
|
1905 | - */ |
|
1906 | - private function rgget_or_rgpost($name) |
|
1907 | - { |
|
1908 | - $value = \GV\Utils::_REQUEST($name); |
|
1909 | - |
|
1910 | - $value = stripslashes_deep($value); |
|
1911 | - |
|
1912 | - $value = gv_map_deep($value, 'rawurldecode'); |
|
1913 | - |
|
1914 | - $value = gv_map_deep($value, '_wp_specialchars'); |
|
1915 | - |
|
1916 | - return $value; |
|
1917 | - } |
|
1918 | - |
|
1919 | - /** |
|
1920 | - * Require the datepicker script for the frontend GV script. |
|
1921 | - * |
|
1922 | - * @param array $js_dependencies Array of existing required scripts for the fe-views.js script |
|
1923 | - * |
|
1924 | - * @return array Array required scripts, with `jquery-ui-datepicker` added |
|
1925 | - */ |
|
1926 | - public function add_datepicker_js_dependency($js_dependencies) |
|
1927 | - { |
|
1928 | - $js_dependencies[] = 'jquery-ui-datepicker'; |
|
1929 | - |
|
1930 | - return $js_dependencies; |
|
1931 | - } |
|
1932 | - |
|
1933 | - /** |
|
1934 | - * Modify the array passed to wp_localize_script(). |
|
1935 | - * |
|
1936 | - * @param array $js_localization The data padded to the Javascript file |
|
1937 | - * @param array $view_data View data array with View settings |
|
1938 | - * |
|
1939 | - * @return array |
|
1940 | - */ |
|
1941 | - public function add_datepicker_localization($localizations = [], $view_data = []) |
|
1942 | - { |
|
1943 | - global $wp_locale; |
|
1944 | - |
|
1945 | - /** |
|
1946 | - * @filter `gravityview_datepicker_settings` Modify the datepicker settings |
|
1947 | - * |
|
1948 | - * @see http://api.jqueryui.com/datepicker/ Learn what settings are available |
|
1949 | - * @see http://www.renegadetechconsulting.com/tutorials/jquery-datepicker-and-wordpress-i18n Thanks for the helpful information on $wp_locale |
|
1950 | - * |
|
1951 | - * @param array $js_localization The data padded to the Javascript file |
|
1952 | - * @param array $view_data View data array with View settings |
|
1953 | - */ |
|
1954 | - $datepicker_settings = apply_filters('gravityview_datepicker_settings', [ |
|
1955 | - 'yearRange' => '-5:+5', |
|
1956 | - 'changeMonth' => true, |
|
1957 | - 'changeYear' => true, |
|
1958 | - 'closeText' => esc_attr_x('Close', 'Close calendar', 'gravityview'), |
|
1959 | - 'prevText' => esc_attr_x('Prev', 'Previous month in calendar', 'gravityview'), |
|
1960 | - 'nextText' => esc_attr_x('Next', 'Next month in calendar', 'gravityview'), |
|
1961 | - 'currentText' => esc_attr_x('Today', 'Today in calendar', 'gravityview'), |
|
1962 | - 'weekHeader' => esc_attr_x('Week', 'Week in calendar', 'gravityview'), |
|
1963 | - 'monthStatus' => __('Show a different month', 'gravityview'), |
|
1964 | - 'monthNames' => array_values($wp_locale->month), |
|
1965 | - 'monthNamesShort' => array_values($wp_locale->month_abbrev), |
|
1966 | - 'dayNames' => array_values($wp_locale->weekday), |
|
1967 | - 'dayNamesShort' => array_values($wp_locale->weekday_abbrev), |
|
1968 | - 'dayNamesMin' => array_values($wp_locale->weekday_initial), |
|
1969 | - // get the start of week from WP general setting |
|
1970 | - 'firstDay' => get_option('start_of_week'), |
|
1971 | - // is Right to left language? default is false |
|
1972 | - 'isRTL' => is_rtl(), |
|
1973 | - ], $view_data); |
|
1974 | - |
|
1975 | - $localizations['datepicker'] = $datepicker_settings; |
|
1976 | - |
|
1977 | - return $localizations; |
|
1978 | - } |
|
1979 | - |
|
1980 | - /** |
|
1981 | - * Register search widget scripts, including Flexibility. |
|
1982 | - * |
|
1983 | - * @see https://github.com/10up/flexibility |
|
1984 | - * @since 1.17 |
|
1985 | - * |
|
1986 | - * @return void |
|
1987 | - */ |
|
1988 | - public function register_scripts() |
|
1989 | - { |
|
1990 | - wp_register_script('gv-flexibility', plugins_url('assets/lib/flexibility/flexibility.js', GRAVITYVIEW_FILE), [], \GV\Plugin::$version, true); |
|
1991 | - } |
|
1992 | - |
|
1993 | - /** |
|
1994 | - * If the current visitor is running IE 8 or 9, enqueue Flexibility. |
|
1995 | - * |
|
1996 | - * @since 1.17 |
|
1997 | - * |
|
1998 | - * @return void |
|
1999 | - */ |
|
2000 | - private function maybe_enqueue_flexibility() |
|
2001 | - { |
|
2002 | - if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/MSIE [8-9]/', $_SERVER['HTTP_USER_AGENT'])) { |
|
2003 | - wp_enqueue_script('gv-flexibility'); |
|
2004 | - } |
|
2005 | - } |
|
2006 | - |
|
2007 | - /** |
|
2008 | - * Enqueue the datepicker script. |
|
2009 | - * |
|
2010 | - * It sets the $gravityview->datepicker_class parameter |
|
2011 | - * |
|
2012 | - * @todo Use own datepicker javascript instead of GF datepicker.js - that way, we can localize the settings and not require the changeMonth and changeYear pickers. |
|
2013 | - * |
|
2014 | - * @return void |
|
2015 | - */ |
|
2016 | - public function enqueue_datepicker() |
|
2017 | - { |
|
2018 | - $gravityview_view = GravityView_View::getInstance(); |
|
2019 | - |
|
2020 | - wp_enqueue_script('jquery-ui-datepicker'); |
|
2021 | - |
|
2022 | - add_filter('gravityview_js_dependencies', [$this, 'add_datepicker_js_dependency']); |
|
2023 | - add_filter('gravityview_js_localization', [$this, 'add_datepicker_localization'], 10, 2); |
|
2024 | - |
|
2025 | - $scheme = is_ssl() ? 'https://' : 'http://'; |
|
2026 | - wp_enqueue_style('jquery-ui-datepicker', $scheme.'ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css'); |
|
2027 | - |
|
2028 | - /** |
|
2029 | - * @filter `gravityview_search_datepicker_class` |
|
2030 | - * Modify the CSS class for the datepicker, used by the CSS class is used by Gravity Forms' javascript to determine the format for the date picker. The `gv-datepicker` class is required by the GravityView datepicker javascript. |
|
2031 | - * |
|
2032 | - * @param string $css_class CSS class to use. Default: `gv-datepicker datepicker mdy` \n |
|
2033 | - * Options are: |
|
2034 | - * - `mdy` (mm/dd/yyyy) |
|
2035 | - * - `dmy` (dd/mm/yyyy) |
|
2036 | - * - `dmy_dash` (dd-mm-yyyy) |
|
2037 | - * - `dmy_dot` (dd.mm.yyyy) |
|
2038 | - * - `ymd_slash` (yyyy/mm/dd) |
|
2039 | - * - `ymd_dash` (yyyy-mm-dd) |
|
2040 | - * - `ymd_dot` (yyyy.mm.dd) |
|
2041 | - */ |
|
2042 | - $datepicker_class = apply_filters('gravityview_search_datepicker_class', 'gv-datepicker datepicker '.$this->get_datepicker_format()); |
|
2043 | - |
|
2044 | - $gravityview_view->datepicker_class = $datepicker_class; |
|
2045 | - } |
|
2046 | - |
|
2047 | - /** |
|
2048 | - * Retrieve the datepicker format. |
|
2049 | - * |
|
2050 | - * @param bool $date_format Whether to return the PHP date format or the datpicker class name. Default: false. |
|
2051 | - * |
|
2052 | - * @see https://docs.gravityview.co/article/115-changing-the-format-of-the-search-widgets-date-picker |
|
2053 | - * |
|
2054 | - * @return string The datepicker format placeholder, or the PHP date format. |
|
2055 | - */ |
|
2056 | - private function get_datepicker_format($date_format = false) |
|
2057 | - { |
|
2058 | - $default_format = 'mdy'; |
|
2059 | - |
|
2060 | - /** |
|
2061 | - * @filter `gravityview/widgets/search/datepicker/format` |
|
2062 | - * |
|
2063 | - * @since 2.1.1 |
|
2064 | - * |
|
2065 | - * @param string $format Default: mdy |
|
2066 | - * Options are: |
|
2067 | - * - `mdy` (mm/dd/yyyy) |
|
2068 | - * - `dmy` (dd/mm/yyyy) |
|
2069 | - * - `dmy_dash` (dd-mm-yyyy) |
|
2070 | - * - `dmy_dot` (dd.mm.yyyy) |
|
2071 | - * - `ymd_slash` (yyyy/mm/dd) |
|
2072 | - * - `ymd_dash` (yyyy-mm-dd) |
|
2073 | - * - `ymd_dot` (yyyy.mm.dd) |
|
2074 | - */ |
|
2075 | - $format = apply_filters('gravityview/widgets/search/datepicker/format', $default_format); |
|
2076 | - |
|
2077 | - $gf_date_formats = [ |
|
2078 | - 'mdy' => 'm/d/Y', |
|
2079 | - |
|
2080 | - 'dmy_dash' => 'd-m-Y', |
|
2081 | - 'dmy_dot' => 'd.m.Y', |
|
2082 | - 'dmy' => 'd/m/Y', |
|
2083 | - |
|
2084 | - 'ymd_slash' => 'Y/m/d', |
|
2085 | - 'ymd_dash' => 'Y-m-d', |
|
2086 | - 'ymd_dot' => 'Y.m.d', |
|
2087 | - ]; |
|
2088 | - |
|
2089 | - if (!$date_format) { |
|
2090 | - // If the format key isn't valid, return default format key |
|
2091 | - return isset($gf_date_formats[$format]) ? $format : $default_format; |
|
2092 | - } |
|
2093 | - |
|
2094 | - // If the format key isn't valid, return default format value |
|
2095 | - return \GV\Utils::get($gf_date_formats, $format, $gf_date_formats[$default_format]); |
|
2096 | - } |
|
2097 | - |
|
2098 | - /** |
|
2099 | - * If previewing a View or page with embedded Views, make the search work properly by adding hidden fields with query vars. |
|
2100 | - * |
|
2101 | - * @since 2.2.1 |
|
2102 | - * |
|
2103 | - * @return void |
|
2104 | - */ |
|
2105 | - public function add_preview_inputs() |
|
2106 | - { |
|
2107 | - global $wp; |
|
2108 | - |
|
2109 | - if (!is_preview() || !current_user_can('publish_gravityviews')) { |
|
2110 | - return; |
|
2111 | - } |
|
2112 | - |
|
2113 | - // Outputs `preview` and `post_id` variables |
|
2114 | - foreach ($wp->query_vars as $key => $value) { |
|
2115 | - printf('<input type="hidden" name="%s" value="%s" />', esc_attr($key), esc_attr($value)); |
|
2116 | - } |
|
2117 | - } |
|
2118 | - |
|
2119 | - /** |
|
2120 | - * Get an operator URL override. |
|
2121 | - * |
|
2122 | - * @param array $get Where to look for the operator. |
|
2123 | - * @param string $key The filter key to look for. |
|
2124 | - * @param array $allowed The allowed operators (allowlist). |
|
2125 | - * @param string $default The default operator. |
|
2126 | - * |
|
2127 | - * @return string The operator. |
|
2128 | - */ |
|
2129 | - private function get_operator($get, $key, $allowed, $default) |
|
2130 | - { |
|
2131 | - $operator = \GV\Utils::get($get, "$key|op", $default); |
|
2132 | - |
|
2133 | - /** |
|
2134 | - * @depecated 2.14 |
|
2135 | - */ |
|
2136 | - $allowed = apply_filters_deprecated('gravityview/search/operator_whitelist', [$allowed, $key], '2.14', 'gravityview/search/operator_allowlist'); |
|
2137 | - |
|
2138 | - /** |
|
2139 | - * @filter `gravityview/search/operator_allowlist` An array of allowed operators for a field. |
|
2140 | - * |
|
2141 | - * @since 2.14 |
|
2142 | - * |
|
2143 | - * @param string[] An allowlist of operators. |
|
2144 | - * @param string The filter name. |
|
2145 | - */ |
|
2146 | - $allowed = apply_filters('gravityview/search/operator_allowlist', $allowed, $key); |
|
2147 | - |
|
2148 | - if (!in_array($operator, $allowed, true)) { |
|
2149 | - $operator = $default; |
|
2150 | - } |
|
2151 | - |
|
2152 | - return $operator; |
|
2153 | - } |
|
18 | + public $icon = 'dashicons-search'; |
|
19 | + |
|
20 | + public static $file; |
|
21 | + public static $instance; |
|
22 | + |
|
23 | + private $search_filters = []; |
|
24 | + |
|
25 | + /** |
|
26 | + * whether search method is GET or POST ( default: GET ). |
|
27 | + * |
|
28 | + * @since 1.16.4 |
|
29 | + * |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + private $search_method = 'get'; |
|
33 | + |
|
34 | + public function __construct() |
|
35 | + { |
|
36 | + $this->widget_id = 'search_bar'; |
|
37 | + $this->widget_description = esc_html__('Search form for searching entries.', 'gravityview'); |
|
38 | + $this->widget_subtitle = ''; |
|
39 | + |
|
40 | + self::$instance = &$this; |
|
41 | + |
|
42 | + self::$file = plugin_dir_path(__FILE__); |
|
43 | + |
|
44 | + $default_values = ['header' => 0, 'footer' => 0]; |
|
45 | + |
|
46 | + $settings = [ |
|
47 | + 'search_layout' => [ |
|
48 | + 'type' => 'radio', |
|
49 | + 'full_width' => true, |
|
50 | + 'label' => esc_html__('Search Layout', 'gravityview'), |
|
51 | + 'value' => 'horizontal', |
|
52 | + 'options' => [ |
|
53 | + 'horizontal' => esc_html__('Horizontal', 'gravityview'), |
|
54 | + 'vertical' => esc_html__('Vertical', 'gravityview'), |
|
55 | + ], |
|
56 | + ], |
|
57 | + 'search_clear' => [ |
|
58 | + 'type' => 'checkbox', |
|
59 | + 'label' => __('Show Clear button', 'gravityview'), |
|
60 | + 'desc' => __('When a search is performed, display a button that removes all search values.', 'gravityview'), |
|
61 | + 'value' => true, |
|
62 | + ], |
|
63 | + 'search_fields' => [ |
|
64 | + 'type' => 'hidden', |
|
65 | + 'label' => '', |
|
66 | + 'class' => 'gv-search-fields-value', |
|
67 | + 'value' => '[{"field":"search_all","input":"input_text"}]', // Default: Search Everything text box |
|
68 | + ], |
|
69 | + 'search_mode' => [ |
|
70 | + 'type' => 'radio', |
|
71 | + 'full_width' => true, |
|
72 | + 'label' => esc_html__('Search Mode', 'gravityview'), |
|
73 | + 'desc' => __('Should search results match all search fields, or any?', 'gravityview'), |
|
74 | + 'value' => 'any', |
|
75 | + 'class' => 'hide-if-js', |
|
76 | + 'options' => [ |
|
77 | + 'any' => esc_html__('Match Any Fields', 'gravityview'), |
|
78 | + 'all' => esc_html__('Match All Fields', 'gravityview'), |
|
79 | + ], |
|
80 | + ], |
|
81 | + ]; |
|
82 | + |
|
83 | + if (!$this->is_registered()) { |
|
84 | + // frontend - filter entries |
|
85 | + add_filter('gravityview_fe_search_criteria', [$this, 'filter_entries'], 10, 3); |
|
86 | + |
|
87 | + // frontend - add template path |
|
88 | + add_filter('gravityview_template_paths', [$this, 'add_template_path']); |
|
89 | + |
|
90 | + // admin - add scripts - run at 1100 to make sure GravityView_Admin_Views::add_scripts_and_styles() runs first at 999 |
|
91 | + add_action('admin_enqueue_scripts', [$this, 'add_scripts_and_styles'], 1100); |
|
92 | + add_action('wp_enqueue_scripts', [$this, 'register_scripts']); |
|
93 | + add_filter('gravityview_noconflict_scripts', [$this, 'register_no_conflict']); |
|
94 | + |
|
95 | + // ajax - get the searchable fields |
|
96 | + add_action('wp_ajax_gv_searchable_fields', ['GravityView_Widget_Search', 'get_searchable_fields']); |
|
97 | + |
|
98 | + add_action('gravityview_search_widget_fields_after', [$this, 'add_preview_inputs']); |
|
99 | + |
|
100 | + add_filter('gravityview/api/reserved_query_args', [$this, 'add_reserved_args']); |
|
101 | + } |
|
102 | + |
|
103 | + parent::__construct(esc_html__('Search Bar', 'gravityview'), null, $default_values, $settings); |
|
104 | + |
|
105 | + // calculate the search method (POST / GET) |
|
106 | + $this->set_search_method(); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @return GravityView_Widget_Search |
|
111 | + */ |
|
112 | + public static function getInstance() |
|
113 | + { |
|
114 | + if (empty(self::$instance)) { |
|
115 | + self::$instance = new GravityView_Widget_Search(); |
|
116 | + } |
|
117 | + |
|
118 | + return self::$instance; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * @since 2.10 |
|
123 | + * |
|
124 | + * @param $args |
|
125 | + * |
|
126 | + * @return mixed |
|
127 | + */ |
|
128 | + public function add_reserved_args($args) |
|
129 | + { |
|
130 | + $args[] = 'gv_search'; |
|
131 | + $args[] = 'gv_start'; |
|
132 | + $args[] = 'gv_end'; |
|
133 | + $args[] = 'gv_id'; |
|
134 | + $args[] = 'gv_by'; |
|
135 | + $args[] = 'mode'; |
|
136 | + |
|
137 | + $get = (array) $_GET; |
|
138 | + |
|
139 | + // If the fields being searched as reserved; not to be considered user-passed variables |
|
140 | + foreach ($get as $key => $value) { |
|
141 | + if ($key !== $this->convert_request_key_to_filter_key($key)) { |
|
142 | + $args[] = $key; |
|
143 | + } |
|
144 | + } |
|
145 | + |
|
146 | + return $args; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Sets the search method to GET (default) or POST. |
|
151 | + * |
|
152 | + * @since 1.16.4 |
|
153 | + */ |
|
154 | + private function set_search_method() |
|
155 | + { |
|
156 | + /** |
|
157 | + * @filter `gravityview/search/method` Modify the search form method (GET / POST) |
|
158 | + * |
|
159 | + * @since 1.16.4 |
|
160 | + * |
|
161 | + * @param string $search_method Assign an input type according to the form field type. Defaults: `boolean`, `multi`, `select`, `date`, `text` |
|
162 | + * @param string $field_type Gravity Forms field type (also the `name` parameter of GravityView_Field classes) |
|
163 | + */ |
|
164 | + $method = apply_filters('gravityview/search/method', $this->search_method); |
|
165 | + |
|
166 | + $method = strtolower($method); |
|
167 | + |
|
168 | + $this->search_method = in_array($method, ['get', 'post']) ? $method : 'get'; |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Returns the search method. |
|
173 | + * |
|
174 | + * @since 1.16.4 |
|
175 | + * |
|
176 | + * @return string |
|
177 | + */ |
|
178 | + public function get_search_method() |
|
179 | + { |
|
180 | + return $this->search_method; |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Get the input types available for different field types. |
|
185 | + * |
|
186 | + * @since 1.17.5 |
|
187 | + * |
|
188 | + * @return array [field type name] => (array|string) search bar input types |
|
189 | + */ |
|
190 | + public static function get_input_types_by_field_type() |
|
191 | + { |
|
192 | + /** |
|
193 | + * Input Type groups. |
|
194 | + * |
|
195 | + * @see admin-search-widget.js (getSelectInput) |
|
196 | + */ |
|
197 | + $input_types = [ |
|
198 | + 'text' => ['input_text'], |
|
199 | + 'address' => ['input_text'], |
|
200 | + 'number' => ['input_text'], |
|
201 | + 'date' => ['date', 'date_range'], |
|
202 | + 'boolean' => ['single_checkbox'], |
|
203 | + 'select' => ['select', 'radio', 'link'], |
|
204 | + 'multi' => ['select', 'multiselect', 'radio', 'checkbox', 'link'], |
|
205 | + |
|
206 | + // hybrids |
|
207 | + 'created_by' => ['select', 'radio', 'checkbox', 'multiselect', 'link', 'input_text'], |
|
208 | + 'product' => ['select', 'radio', 'link', 'input_text'], |
|
209 | + ]; |
|
210 | + |
|
211 | + /** |
|
212 | + * @filter `gravityview/search/input_types` Change the types of search fields available to a field type |
|
213 | + * |
|
214 | + * @see GravityView_Widget_Search::get_search_input_labels() for the available input types |
|
215 | + * |
|
216 | + * @param array $input_types Associative array: key is field `name`, value is array of GravityView input types (note: use `input_text` for `text`) |
|
217 | + */ |
|
218 | + $input_types = apply_filters('gravityview/search/input_types', $input_types); |
|
219 | + |
|
220 | + return $input_types; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Get labels for different types of search bar inputs. |
|
225 | + * |
|
226 | + * @since 1.17.5 |
|
227 | + * |
|
228 | + * @return array [input type] => input type label |
|
229 | + */ |
|
230 | + public static function get_search_input_labels() |
|
231 | + { |
|
232 | + /** |
|
233 | + * Input Type labels l10n. |
|
234 | + * |
|
235 | + * @see admin-search-widget.js (getSelectInput) |
|
236 | + */ |
|
237 | + $input_labels = [ |
|
238 | + 'input_text' => esc_html__('Text', 'gravityview'), |
|
239 | + 'date' => esc_html__('Date', 'gravityview'), |
|
240 | + 'select' => esc_html__('Select', 'gravityview'), |
|
241 | + 'multiselect' => esc_html__('Select (multiple values)', 'gravityview'), |
|
242 | + 'radio' => esc_html__('Radio', 'gravityview'), |
|
243 | + 'checkbox' => esc_html__('Checkbox', 'gravityview'), |
|
244 | + 'single_checkbox' => esc_html__('Checkbox', 'gravityview'), |
|
245 | + 'link' => esc_html__('Links', 'gravityview'), |
|
246 | + 'date_range' => esc_html__('Date range', 'gravityview'), |
|
247 | + ]; |
|
248 | + |
|
249 | + /** |
|
250 | + * @filter `gravityview/search/input_types` Change the label of search field input types |
|
251 | + * |
|
252 | + * @param array $input_types Associative array: key is input type name, value is label |
|
253 | + */ |
|
254 | + $input_labels = apply_filters('gravityview/search/input_labels', $input_labels); |
|
255 | + |
|
256 | + return $input_labels; |
|
257 | + } |
|
258 | + |
|
259 | + public static function get_search_input_label($input_type) |
|
260 | + { |
|
261 | + $labels = self::get_search_input_labels(); |
|
262 | + |
|
263 | + return \GV\Utils::get($labels, $input_type, false); |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Add script to Views edit screen (admin). |
|
268 | + * |
|
269 | + * @param mixed $hook |
|
270 | + */ |
|
271 | + public function add_scripts_and_styles($hook) |
|
272 | + { |
|
273 | + global $pagenow; |
|
274 | + |
|
275 | + // Don't process any scripts below here if it's not a GravityView page or the widgets screen |
|
276 | + if (!gravityview()->request->is_admin($hook, 'single') && ('widgets.php' !== $pagenow)) { |
|
277 | + return; |
|
278 | + } |
|
279 | + |
|
280 | + $script_min = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
281 | + $script_source = empty($script_min) ? '/source' : ''; |
|
282 | + |
|
283 | + wp_enqueue_script('gravityview_searchwidget_admin', plugins_url('assets/js'.$script_source.'/admin-search-widget'.$script_min.'.js', __FILE__), ['jquery', 'gravityview_views_scripts'], \GV\Plugin::$version); |
|
284 | + |
|
285 | + wp_localize_script('gravityview_searchwidget_admin', 'gvSearchVar', [ |
|
286 | + 'nonce' => wp_create_nonce('gravityview_ajaxsearchwidget'), |
|
287 | + 'label_nofields' => esc_html__('No search fields configured yet.', 'gravityview'), |
|
288 | + 'label_addfield' => esc_html__('Add Search Field', 'gravityview'), |
|
289 | + 'label_label' => esc_html__('Label', 'gravityview'), |
|
290 | + 'label_searchfield' => esc_html__('Search Field', 'gravityview'), |
|
291 | + 'label_inputtype' => esc_html__('Input Type', 'gravityview'), |
|
292 | + 'label_ajaxerror' => esc_html__('There was an error loading searchable fields. Save the View or refresh the page to fix this issue.', 'gravityview'), |
|
293 | + 'input_labels' => json_encode(self::get_search_input_labels()), |
|
294 | + 'input_types' => json_encode(self::get_input_types_by_field_type()), |
|
295 | + ]); |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Add admin script to the no-conflict scripts allowlist. |
|
300 | + * |
|
301 | + * @param array $allowed Scripts allowed in no-conflict mode |
|
302 | + * |
|
303 | + * @return array Scripts allowed in no-conflict mode, plus the search widget script |
|
304 | + */ |
|
305 | + public function register_no_conflict($allowed) |
|
306 | + { |
|
307 | + $allowed[] = 'gravityview_searchwidget_admin'; |
|
308 | + |
|
309 | + return $allowed; |
|
310 | + } |
|
311 | + |
|
312 | + /** |
|
313 | + * Ajax |
|
314 | + * Returns the form fields ( only the searchable ones ). |
|
315 | + * |
|
316 | + * @return void |
|
317 | + */ |
|
318 | + public static function get_searchable_fields() |
|
319 | + { |
|
320 | + if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'gravityview_ajaxsearchwidget')) { |
|
321 | + exit('0'); |
|
322 | + } |
|
323 | + |
|
324 | + $form = ''; |
|
325 | + |
|
326 | + // Fetch the form for the current View |
|
327 | + if (!empty($_POST['view_id'])) { |
|
328 | + $form = gravityview_get_form_id($_POST['view_id']); |
|
329 | + } elseif (!empty($_POST['formid'])) { |
|
330 | + $form = (int) $_POST['formid']; |
|
331 | + } elseif (!empty($_POST['template_id']) && class_exists('GravityView_Ajax')) { |
|
332 | + $form = GravityView_Ajax::pre_get_form_fields($_POST['template_id']); |
|
333 | + } |
|
334 | + |
|
335 | + // fetch form id assigned to the view |
|
336 | + $response = self::render_searchable_fields($form); |
|
337 | + |
|
338 | + exit($response); |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Generates html for the available Search Fields dropdown. |
|
343 | + * |
|
344 | + * @param int $form_id |
|
345 | + * @param string $current (for future use) |
|
346 | + * |
|
347 | + * @return string |
|
348 | + */ |
|
349 | + public static function render_searchable_fields($form_id = null, $current = '') |
|
350 | + { |
|
351 | + if (is_null($form_id)) { |
|
352 | + return ''; |
|
353 | + } |
|
354 | + |
|
355 | + // start building output |
|
356 | + |
|
357 | + $output = '<select class="gv-search-fields">'; |
|
358 | + |
|
359 | + $custom_fields = [ |
|
360 | + 'search_all' => [ |
|
361 | + 'text' => esc_html__('Search Everything', 'gravityview'), |
|
362 | + 'type' => 'text', |
|
363 | + ], |
|
364 | + 'entry_date' => [ |
|
365 | + 'text' => esc_html__('Entry Date', 'gravityview'), |
|
366 | + 'type' => 'date', |
|
367 | + ], |
|
368 | + 'entry_id' => [ |
|
369 | + 'text' => esc_html__('Entry ID', 'gravityview'), |
|
370 | + 'type' => 'text', |
|
371 | + ], |
|
372 | + 'created_by' => [ |
|
373 | + 'text' => esc_html__('Entry Creator', 'gravityview'), |
|
374 | + 'type' => 'created_by', |
|
375 | + ], |
|
376 | + 'is_starred' => [ |
|
377 | + 'text' => esc_html__('Is Starred', 'gravityview'), |
|
378 | + 'type' => 'boolean', |
|
379 | + ], |
|
380 | + ]; |
|
381 | + |
|
382 | + if (gravityview()->plugin->supports(\GV\Plugin::FEATURE_GFQUERY)) { |
|
383 | + $custom_fields['is_approved'] = [ |
|
384 | + 'text' => esc_html__('Approval Status', 'gravityview'), |
|
385 | + 'type' => 'multi', |
|
386 | + ]; |
|
387 | + } |
|
388 | + |
|
389 | + foreach ($custom_fields as $custom_field_key => $custom_field) { |
|
390 | + $output .= sprintf('<option value="%s" %s data-inputtypes="%s" data-placeholder="%s">%s</option>', $custom_field_key, selected($custom_field_key, $current, false), $custom_field['type'], self::get_field_label(['field' => $custom_field_key]), $custom_field['text']); |
|
391 | + } |
|
392 | + |
|
393 | + // Get fields with sub-inputs and no parent |
|
394 | + $fields = gravityview_get_form_fields($form_id, true, true); |
|
395 | + |
|
396 | + /** |
|
397 | + * @filter `gravityview/search/searchable_fields` Modify the fields that are displayed as searchable in the Search Bar dropdown\n |
|
398 | + * |
|
399 | + * @since 1.17 |
|
400 | + * @see gravityview_get_form_fields() Used to fetch the fields |
|
401 | + * @see GravityView_Widget_Search::get_search_input_types See this method to modify the type of input types allowed for a field |
|
402 | + * |
|
403 | + * @param array $fields Array of searchable fields, as fetched by gravityview_get_form_fields() |
|
404 | + * @param int $form_id |
|
405 | + */ |
|
406 | + $fields = apply_filters('gravityview/search/searchable_fields', $fields, $form_id); |
|
407 | + |
|
408 | + if (!empty($fields)) { |
|
409 | + $blocklist_field_types = apply_filters('gravityview_blocklist_field_types', ['fileupload', 'post_image', 'post_id', 'section'], null); |
|
410 | + |
|
411 | + foreach ($fields as $id => $field) { |
|
412 | + if (in_array($field['type'], $blocklist_field_types)) { |
|
413 | + continue; |
|
414 | + } |
|
415 | + |
|
416 | + $types = self::get_search_input_types($id, $field['type']); |
|
417 | + |
|
418 | + $output .= '<option value="'.$id.'" '.selected($id, $current, false).'data-inputtypes="'.esc_attr($types).'">'.esc_html($field['label']).'</option>'; |
|
419 | + } |
|
420 | + } |
|
421 | + |
|
422 | + $output .= '</select>'; |
|
423 | + |
|
424 | + return $output; |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * Assign an input type according to the form field type. |
|
429 | + * |
|
430 | + * @see admin-search-widget.js |
|
431 | + * |
|
432 | + * @param string|int|float $field_id Gravity Forms field ID |
|
433 | + * @param string $field_type Gravity Forms field type (also the `name` parameter of GravityView_Field classes) |
|
434 | + * |
|
435 | + * @return string GV field search input type ('multi', 'boolean', 'select', 'date', 'text') |
|
436 | + */ |
|
437 | + public static function get_search_input_types($field_id = '', $field_type = null) |
|
438 | + { |
|
439 | + |
|
440 | + // @todo - This needs to be improved - many fields have . including products and addresses |
|
441 | + if (false !== strpos((string) $field_id, '.') && in_array($field_type, ['checkbox']) || in_array($field_id, ['is_fulfilled'])) { |
|
442 | + $input_type = 'boolean'; // on/off checkbox |
|
443 | + } elseif (in_array($field_type, ['checkbox', 'post_category', 'multiselect'])) { |
|
444 | + $input_type = 'multi'; //multiselect |
|
445 | + } elseif (in_array($field_type, ['select', 'radio'])) { |
|
446 | + $input_type = 'select'; |
|
447 | + } elseif (in_array($field_type, ['date']) || in_array($field_id, ['payment_date'])) { |
|
448 | + $input_type = 'date'; |
|
449 | + } elseif (in_array($field_type, ['number']) || in_array($field_id, ['payment_amount'])) { |
|
450 | + $input_type = 'number'; |
|
451 | + } elseif (in_array($field_type, ['product'])) { |
|
452 | + $input_type = 'product'; |
|
453 | + } else { |
|
454 | + $input_type = 'text'; |
|
455 | + } |
|
456 | + |
|
457 | + /** |
|
458 | + * @filter `gravityview/extension/search/input_type` Modify the search form input type based on field type |
|
459 | + * |
|
460 | + * @since 1.2 |
|
461 | + * @since 1.19.2 Added $field_id parameter |
|
462 | + * |
|
463 | + * @param string $input_type Assign an input type according to the form field type. Defaults: `boolean`, `multi`, `select`, `date`, `text` |
|
464 | + * @param string $field_type Gravity Forms field type (also the `name` parameter of GravityView_Field classes) |
|
465 | + * @param string|int|float $field_id ID of the field being processed |
|
466 | + */ |
|
467 | + $input_type = apply_filters('gravityview/extension/search/input_type', $input_type, $field_type, $field_id); |
|
468 | + |
|
469 | + return $input_type; |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * Display hidden fields to add support for sites using Default permalink structure. |
|
474 | + * |
|
475 | + * @since 1.8 |
|
476 | + * |
|
477 | + * @return array Search fields, modified if not using permalinks |
|
478 | + */ |
|
479 | + public function add_no_permalink_fields($search_fields, $object, $widget_args = []) |
|
480 | + { |
|
481 | + /** @global WP_Rewrite $wp_rewrite */ |
|
482 | + global $wp_rewrite; |
|
483 | + |
|
484 | + // Support default permalink structure |
|
485 | + if (false === $wp_rewrite->using_permalinks()) { |
|
486 | + |
|
487 | + // By default, use current post. |
|
488 | + $post_id = 0; |
|
489 | + |
|
490 | + // We're in the WordPress Widget context, and an overriding post ID has been set. |
|
491 | + if (!empty($widget_args['post_id'])) { |
|
492 | + $post_id = absint($widget_args['post_id']); |
|
493 | + } |
|
494 | + // We're in the WordPress Widget context, and the base View ID should be used |
|
495 | + elseif (!empty($widget_args['view_id'])) { |
|
496 | + $post_id = absint($widget_args['view_id']); |
|
497 | + } |
|
498 | + |
|
499 | + $args = gravityview_get_permalink_query_args($post_id); |
|
500 | + |
|
501 | + // Add hidden fields to the search form |
|
502 | + foreach ($args as $key => $value) { |
|
503 | + $search_fields[] = [ |
|
504 | + 'name' => $key, |
|
505 | + 'input' => 'hidden', |
|
506 | + 'value' => $value, |
|
507 | + ]; |
|
508 | + } |
|
509 | + } |
|
510 | + |
|
511 | + return $search_fields; |
|
512 | + } |
|
513 | + |
|
514 | + /** |
|
515 | + * Get the fields that are searchable for a View. |
|
516 | + * |
|
517 | + * @since 2.0 |
|
518 | + * @since 2.0.9 Added $with_full_field parameter |
|
519 | + * |
|
520 | + * @param \GV\View|null $view |
|
521 | + * @param bool $with_full_field Return full field array, or just field ID? Default: false (just field ID) |
|
522 | + * |
|
523 | + * TODO: Move to \GV\View, perhaps? And return a Field_Collection |
|
524 | + * TODO: Use in gravityview()->request->is_search() to calculate whether a valid search |
|
525 | + * |
|
526 | + * @return array If no View, returns empty array. Otherwise, returns array of fields configured in widgets and Search Bar for a View |
|
527 | + */ |
|
528 | + private function get_view_searchable_fields($view, $with_full_field = false) |
|
529 | + { |
|
530 | + |
|
531 | + /** |
|
532 | + * Find all search widgets on the view and get the searchable fields settings. |
|
533 | + */ |
|
534 | + $searchable_fields = []; |
|
535 | + |
|
536 | + if (!$view) { |
|
537 | + return $searchable_fields; |
|
538 | + } |
|
539 | + |
|
540 | + /** |
|
541 | + * Include the sidebar Widgets. |
|
542 | + */ |
|
543 | + $widgets = (array) get_option('widget_gravityview_search', []); |
|
544 | + |
|
545 | + foreach ($widgets as $widget) { |
|
546 | + if (!empty($widget['view_id']) && $widget['view_id'] == $view->ID) { |
|
547 | + if ($_fields = json_decode($widget['search_fields'], true)) { |
|
548 | + foreach ($_fields as $field) { |
|
549 | + if (empty($field['form_id'])) { |
|
550 | + $field['form_id'] = $view->form ? $view->form->ID : 0; |
|
551 | + } |
|
552 | + $searchable_fields[] = $with_full_field ? $field : $field['field']; |
|
553 | + } |
|
554 | + } |
|
555 | + } |
|
556 | + } |
|
557 | + |
|
558 | + foreach ($view->widgets->by_id($this->get_widget_id())->all() as $widget) { |
|
559 | + if ($_fields = json_decode($widget->configuration->get('search_fields'), true)) { |
|
560 | + foreach ($_fields as $field) { |
|
561 | + if (empty($field['form_id'])) { |
|
562 | + $field['form_id'] = $view->form ? $view->form->ID : 0; |
|
563 | + } |
|
564 | + $searchable_fields[] = $with_full_field ? $field : $field['field']; |
|
565 | + } |
|
566 | + } |
|
567 | + } |
|
568 | + |
|
569 | + /** |
|
570 | + * @since 2.5.1 |
|
571 | + * @depecated 2.14 |
|
572 | + */ |
|
573 | + $searchable_fields = apply_filters_deprecated('gravityview/search/searchable_fields/whitelist', [$searchable_fields, $view, $with_full_field], '2.14', 'gravityview/search/searchable_fields/allowlist'); |
|
574 | + |
|
575 | + /** |
|
576 | + * @filter `gravityview/search/searchable_fields/allowlist` Modifies the fields able to be searched using the Search Bar |
|
577 | + * |
|
578 | + * @since 2.14 |
|
579 | + * |
|
580 | + * @param array $searchable_fields Array of GravityView-formatted fields or only the field ID? Example: [ '1.2', 'created_by' ] |
|
581 | + * @param \GV\View $view Object of View being searched. |
|
582 | + * @param bool $with_full_field Does $searchable_fields contain the full field array or just field ID? Default: false (just field ID) |
|
583 | + */ |
|
584 | + $searchable_fields = apply_filters('gravityview/search/searchable_fields/allowlist', $searchable_fields, $view, $with_full_field); |
|
585 | + |
|
586 | + return $searchable_fields; |
|
587 | + } |
|
588 | + |
|
589 | + /** --- Frontend --- */ |
|
590 | + |
|
591 | + /** |
|
592 | + * Calculate the search criteria to filter entries. |
|
593 | + * |
|
594 | + * @param array $search_criteria The search criteria |
|
595 | + * @param int $form_id The form ID |
|
596 | + * @param array $args Some args |
|
597 | + * @param bool $force_search_criteria Whether to suppress GF_Query filter, internally used in self::gf_query_filter |
|
598 | + * |
|
599 | + * @return array |
|
600 | + */ |
|
601 | + public function filter_entries($search_criteria, $form_id = null, $args = [], $force_search_criteria = false) |
|
602 | + { |
|
603 | + if (!$force_search_criteria && gravityview()->plugin->supports(\GV\Plugin::FEATURE_GFQUERY)) { |
|
604 | + /** |
|
605 | + * If GF_Query is available, we can construct custom conditions with nested |
|
606 | + * booleans on the query, giving up the old ways of flat search_criteria field_filters. |
|
607 | + */ |
|
608 | + add_action('gravityview/view/query', [$this, 'gf_query_filter'], 10, 3); |
|
609 | + |
|
610 | + return $search_criteria; // Return the original criteria, GF_Query modification kicks in later |
|
611 | + } |
|
612 | + |
|
613 | + if ('post' === $this->search_method) { |
|
614 | + $get = $_POST; |
|
615 | + } else { |
|
616 | + $get = $_GET; |
|
617 | + } |
|
618 | + |
|
619 | + $view = \GV\View::by_id(\GV\Utils::get($args, 'id')); |
|
620 | + $view_id = $view ? $view->ID : null; |
|
621 | + $form_id = $view ? $view->form->ID : null; |
|
622 | + |
|
623 | + gravityview()->log->debug('Requested $_{method}: ', ['method' => $this->search_method, 'data' => $get]); |
|
624 | + |
|
625 | + if (empty($get) || !is_array($get)) { |
|
626 | + return $search_criteria; |
|
627 | + } |
|
628 | + |
|
629 | + $get = stripslashes_deep($get); |
|
630 | + |
|
631 | + $get = gv_map_deep($get, 'rawurldecode'); |
|
632 | + |
|
633 | + // Make sure array key is set up |
|
634 | + $search_criteria['field_filters'] = \GV\Utils::get($search_criteria, 'field_filters', []); |
|
635 | + |
|
636 | + $searchable_fields = $this->get_view_searchable_fields($view); |
|
637 | + $searchable_field_objects = $this->get_view_searchable_fields($view, true); |
|
638 | + |
|
639 | + /** |
|
640 | + * @filter `gravityview/search-all-split-words` Search for each word separately or the whole phrase? |
|
641 | + * |
|
642 | + * @since 1.20.2 |
|
643 | + * |
|
644 | + * @param bool $split_words True: split a phrase into words; False: search whole word only [Default: true] |
|
645 | + */ |
|
646 | + $split_words = apply_filters('gravityview/search-all-split-words', true); |
|
647 | + |
|
648 | + /** |
|
649 | + * @filter `gravityview/search-trim-input` Remove leading/trailing whitespaces from search value |
|
650 | + * |
|
651 | + * @since 2.9.3 |
|
652 | + * |
|
653 | + * @param bool $trim_search_value True: remove whitespace; False: keep as is [Default: true] |
|
654 | + */ |
|
655 | + $trim_search_value = apply_filters('gravityview/search-trim-input', true); |
|
656 | + |
|
657 | + // add free search |
|
658 | + if (isset($get['gv_search']) && '' !== $get['gv_search'] && in_array('search_all', $searchable_fields)) { |
|
659 | + $search_all_value = $trim_search_value ? trim($get['gv_search']) : $get['gv_search']; |
|
660 | + |
|
661 | + if ($split_words) { |
|
662 | + // Search for a piece |
|
663 | + $words = explode(' ', $search_all_value); |
|
664 | + |
|
665 | + $words = array_filter($words); |
|
666 | + } else { |
|
667 | + // Replace multiple spaces with one space |
|
668 | + $search_all_value = preg_replace('/\s+/ism', ' ', $search_all_value); |
|
669 | + |
|
670 | + $words = [$search_all_value]; |
|
671 | + } |
|
672 | + |
|
673 | + foreach ($words as $word) { |
|
674 | + $search_criteria['field_filters'][] = [ |
|
675 | + 'key' => null, // The field ID to search |
|
676 | + 'value' => $word, // The value to search |
|
677 | + 'operator' => 'contains', // What to search in. Options: `is` or `contains` |
|
678 | + ]; |
|
679 | + } |
|
680 | + } |
|
681 | + |
|
682 | + // start date & end date |
|
683 | + if (in_array('entry_date', $searchable_fields)) { |
|
684 | + /** |
|
685 | + * Get and normalize the dates according to the input format. |
|
686 | + */ |
|
687 | + if ($curr_start = !empty($get['gv_start']) ? $get['gv_start'] : '') { |
|
688 | + if ($curr_start_date = date_create_from_format($this->get_datepicker_format(true), $curr_start)) { |
|
689 | + $curr_start = $curr_start_date->format('Y-m-d'); |
|
690 | + } |
|
691 | + } |
|
692 | + |
|
693 | + if ($curr_end = !empty($get['gv_start']) ? (!empty($get['gv_end']) ? $get['gv_end'] : '') : '') { |
|
694 | + if ($curr_end_date = date_create_from_format($this->get_datepicker_format(true), $curr_end)) { |
|
695 | + $curr_end = $curr_end_date->format('Y-m-d'); |
|
696 | + } |
|
697 | + } |
|
698 | + |
|
699 | + if ($view) { |
|
700 | + /** |
|
701 | + * Override start and end dates if View is limited to some already. |
|
702 | + */ |
|
703 | + if ($start_date = $view->settings->get('start_date')) { |
|
704 | + if ($start_timestamp = strtotime($curr_start)) { |
|
705 | + $curr_start = $start_timestamp < strtotime($start_date) ? $start_date : $curr_start; |
|
706 | + } |
|
707 | + } |
|
708 | + if ($end_date = $view->settings->get('end_date')) { |
|
709 | + if ($end_timestamp = strtotime($curr_end)) { |
|
710 | + $curr_end = $end_timestamp > strtotime($end_date) ? $end_date : $curr_end; |
|
711 | + } |
|
712 | + } |
|
713 | + } |
|
714 | + |
|
715 | + /** |
|
716 | + * @filter `gravityview_date_created_adjust_timezone` Whether to adjust the timezone for entries. \n |
|
717 | + * `date_created` is stored in UTC format. Convert search date into UTC (also used on templates/fields/date_created.php). \n |
|
718 | + * This is for backward compatibility before \GF_Query started to automatically apply the timezone offset. |
|
719 | + * |
|
720 | + * @since 1.12 |
|
721 | + * |
|
722 | + * @param bool $adjust_tz Use timezone-adjusted datetime? If true, adjusts date based on blog's timezone setting. If false, uses UTC setting. Default is `false`. |
|
723 | + * @param string $context Where the filter is being called from. `search` in this case. |
|
724 | + */ |
|
725 | + $adjust_tz = apply_filters('gravityview_date_created_adjust_timezone', false, 'search'); |
|
726 | + |
|
727 | + /** |
|
728 | + * Don't set $search_criteria['start_date'] if start_date is empty as it may lead to bad query results (GFAPI::get_entries). |
|
729 | + */ |
|
730 | + if (!empty($curr_start)) { |
|
731 | + $curr_start = date('Y-m-d H:i:s', strtotime($curr_start)); |
|
732 | + $search_criteria['start_date'] = $adjust_tz ? get_gmt_from_date($curr_start) : $curr_start; |
|
733 | + } |
|
734 | + |
|
735 | + if (!empty($curr_end)) { |
|
736 | + // Fast-forward 24 hour on the end time |
|
737 | + $curr_end = date('Y-m-d H:i:s', strtotime($curr_end) + DAY_IN_SECONDS); |
|
738 | + $search_criteria['end_date'] = $adjust_tz ? get_gmt_from_date($curr_end) : $curr_end; |
|
739 | + if (strpos($search_criteria['end_date'], '00:00:00')) { // See https://github.com/gravityview/GravityView/issues/1056 |
|
740 | + $search_criteria['end_date'] = date('Y-m-d H:i:s', strtotime($search_criteria['end_date']) - 1); |
|
741 | + } |
|
742 | + } |
|
743 | + } |
|
744 | + |
|
745 | + // search for a specific entry ID |
|
746 | + if (!empty($get['gv_id']) && in_array('entry_id', $searchable_fields)) { |
|
747 | + $search_criteria['field_filters'][] = [ |
|
748 | + 'key' => 'id', |
|
749 | + 'value' => absint($get['gv_id']), |
|
750 | + 'operator' => $this->get_operator($get, 'gv_id', ['='], '='), |
|
751 | + ]; |
|
752 | + } |
|
753 | + |
|
754 | + // search for a specific Created_by ID |
|
755 | + if (!empty($get['gv_by']) && in_array('created_by', $searchable_fields)) { |
|
756 | + $search_criteria['field_filters'][] = [ |
|
757 | + 'key' => 'created_by', |
|
758 | + 'value' => $get['gv_by'], |
|
759 | + 'operator' => $this->get_operator($get, 'gv_by', ['='], '='), |
|
760 | + ]; |
|
761 | + } |
|
762 | + |
|
763 | + // Get search mode passed in URL |
|
764 | + $mode = isset($get['mode']) && in_array($get['mode'], ['any', 'all']) ? $get['mode'] : 'any'; |
|
765 | + |
|
766 | + // get the other search filters |
|
767 | + foreach ($get as $key => $value) { |
|
768 | + if (0 !== strpos($key, 'filter_') && 0 !== strpos($key, 'input_')) { |
|
769 | + continue; |
|
770 | + } |
|
771 | + |
|
772 | + if (strpos($key, '|op') !== false) { |
|
773 | + continue; // This is an operator |
|
774 | + } |
|
775 | + |
|
776 | + $filter_key = $this->convert_request_key_to_filter_key($key); |
|
777 | + |
|
778 | + if ($trim_search_value) { |
|
779 | + $value = is_array($value) ? array_map('trim', $value) : trim($value); |
|
780 | + } |
|
781 | + |
|
782 | + if (gv_empty($value, false, false) || (is_array($value) && count($value) === 1 && gv_empty($value[0], false, false))) { |
|
783 | + /** |
|
784 | + * @filter `gravityview/search/ignore-empty-values` Filter to control if empty field values should be ignored or strictly matched (default: true) |
|
785 | + * |
|
786 | + * @since 2.14.2.1 |
|
787 | + * |
|
788 | + * @param bool $ignore_empty_values |
|
789 | + * @param int|null $filter_key |
|
790 | + * @param int|null $view_id |
|
791 | + * @param int|null $form_id |
|
792 | + */ |
|
793 | + $ignore_empty_values = apply_filters('gravityview/search/ignore-empty-values', true, $filter_key, $view_id, $form_id); |
|
794 | + |
|
795 | + if (is_array($value) || $ignore_empty_values) { |
|
796 | + continue; |
|
797 | + } |
|
798 | + |
|
799 | + $value = ''; |
|
800 | + } |
|
801 | + |
|
802 | + if ($form_id && '' === $value) { |
|
803 | + $field = GFAPI::get_field($form_id, $filter_key); |
|
804 | + |
|
805 | + // GF_Query casts Number field values to decimal, which may return unexpected result when the value is blank. |
|
806 | + if ($field && 'number' === $field->type) { |
|
807 | + $value = '-'.PHP_INT_MAX; |
|
808 | + } |
|
809 | + } |
|
810 | + |
|
811 | + if (!$filter = $this->prepare_field_filter($filter_key, $value, $view, $searchable_field_objects, $get)) { |
|
812 | + continue; |
|
813 | + } |
|
814 | + |
|
815 | + if (!isset($filter['operator'])) { |
|
816 | + $filter['operator'] = $this->get_operator($get, $key, ['contains'], 'contains'); |
|
817 | + } |
|
818 | + |
|
819 | + if (isset($filter[0]['value'])) { |
|
820 | + $filter[0]['value'] = $trim_search_value ? trim($filter[0]['value']) : $filter[0]['value']; |
|
821 | + |
|
822 | + $search_criteria['field_filters'] = array_merge($search_criteria['field_filters'], $filter); |
|
823 | + |
|
824 | + // if date range type, set search mode to ALL |
|
825 | + if (!empty($filter[0]['operator']) && in_array($filter[0]['operator'], ['>=', '<=', '>', '<'])) { |
|
826 | + $mode = 'all'; |
|
827 | + } |
|
828 | + } elseif (!empty($filter)) { |
|
829 | + $search_criteria['field_filters'][] = $filter; |
|
830 | + } |
|
831 | + } |
|
832 | + |
|
833 | + /** |
|
834 | + * @filter `gravityview/search/mode` Set the Search Mode (`all` or `any`) |
|
835 | + * |
|
836 | + * @since 1.5.1 |
|
837 | + * |
|
838 | + * @param string $mode Search mode (`any` vs `all`) |
|
839 | + */ |
|
840 | + $search_criteria['field_filters']['mode'] = apply_filters('gravityview/search/mode', $mode); |
|
841 | + |
|
842 | + gravityview()->log->debug('Returned Search Criteria: ', ['data' => $search_criteria]); |
|
843 | + |
|
844 | + unset($get); |
|
845 | + |
|
846 | + return $search_criteria; |
|
847 | + } |
|
848 | + |
|
849 | + /** |
|
850 | + * Filters the \GF_Query with advanced logic. |
|
851 | + * |
|
852 | + * Dropin for the legacy flat filters when \GF_Query is available. |
|
853 | + * |
|
854 | + * @param \GF_Query $query The current query object reference |
|
855 | + * @param \GV\View $this The current view object |
|
856 | + * @param \GV\Request $request The request object |
|
857 | + */ |
|
858 | + public function gf_query_filter(&$query, $view, $request) |
|
859 | + { |
|
860 | + /** |
|
861 | + * This is a shortcut to get all the needed search criteria. |
|
862 | + * We feed these into an new GF_Query and tack them onto the current object. |
|
863 | + */ |
|
864 | + $search_criteria = $this->filter_entries([], null, ['id' => $view->ID], true /** force search_criteria */); |
|
865 | + |
|
866 | + /** |
|
867 | + * Call any userland filters that they might have. |
|
868 | + */ |
|
869 | + remove_filter('gravityview_fe_search_criteria', [$this, 'filter_entries'], 10, 3); |
|
870 | + $search_criteria = apply_filters('gravityview_fe_search_criteria', $search_criteria, $view->form->ID, $view->settings->as_atts()); |
|
871 | + add_filter('gravityview_fe_search_criteria', [$this, 'filter_entries'], 10, 3); |
|
872 | + |
|
873 | + $query_class = $view->get_query_class(); |
|
874 | + |
|
875 | + if (empty($search_criteria['field_filters'])) { |
|
876 | + return; |
|
877 | + } |
|
878 | + |
|
879 | + $widgets = $view->widgets->by_id($this->widget_id); |
|
880 | + if ($widgets->count()) { |
|
881 | + $widgets = $widgets->all(); |
|
882 | + $widget = $widgets[0]; |
|
883 | + |
|
884 | + $search_fields = json_decode($widget->configuration->get('search_fields'), true); |
|
885 | + |
|
886 | + foreach ((array) $search_fields as $search_field) { |
|
887 | + if ('created_by' === $search_field['field'] && 'input_text' === $search_field['input']) { |
|
888 | + $created_by_text_mode = true; |
|
889 | + } |
|
890 | + } |
|
891 | + } |
|
892 | + |
|
893 | + $extra_conditions = []; |
|
894 | + $mode = 'any'; |
|
895 | + |
|
896 | + foreach ($search_criteria['field_filters'] as $key => &$filter) { |
|
897 | + if (!is_array($filter)) { |
|
898 | + if (in_array(strtolower($filter), ['any', 'all'])) { |
|
899 | + $mode = $filter; |
|
900 | + } |
|
901 | + continue; |
|
902 | + } |
|
903 | + |
|
904 | + // Construct a manual query for unapproved statuses |
|
905 | + if ('is_approved' === $filter['key'] && in_array(\GravityView_Entry_Approval_Status::UNAPPROVED, (array) $filter['value'])) { |
|
906 | + $_tmp_query = new $query_class($view->form->ID, [ |
|
907 | + 'field_filters' => [ |
|
908 | + [ |
|
909 | + 'operator' => 'in', |
|
910 | + 'key' => 'is_approved', |
|
911 | + 'value' => (array) $filter['value'], |
|
912 | + ], |
|
913 | + [ |
|
914 | + 'operator' => 'is', |
|
915 | + 'key' => 'is_approved', |
|
916 | + 'value' => '', |
|
917 | + ], |
|
918 | + 'mode' => 'any', |
|
919 | + ], |
|
920 | + ]); |
|
921 | + $_tmp_query_parts = $_tmp_query->_introspect(); |
|
922 | + |
|
923 | + $extra_conditions[] = $_tmp_query_parts['where']; |
|
924 | + |
|
925 | + $filter = false; |
|
926 | + continue; |
|
927 | + } |
|
928 | + |
|
929 | + // Construct manual query for text mode creator search |
|
930 | + if ('created_by' === $filter['key'] && !empty($created_by_text_mode)) { |
|
931 | + $extra_conditions[] = new GravityView_Widget_Search_Author_GF_Query_Condition($filter, $view); |
|
932 | + $filter = false; |
|
933 | + continue; |
|
934 | + } |
|
935 | + |
|
936 | + // By default, we want searches to be wildcard for each field. |
|
937 | + $filter['operator'] = empty($filter['operator']) ? 'contains' : $filter['operator']; |
|
938 | + |
|
939 | + // For multichoice, let's have an in (OR) search. |
|
940 | + if (is_array($filter['value'])) { |
|
941 | + $filter['operator'] = 'in'; // @todo what about in contains (OR LIKE chains)? |
|
942 | + } |
|
943 | + |
|
944 | + // Default form with joins functionality |
|
945 | + if (empty($filter['form_id'])) { |
|
946 | + $filter['form_id'] = $view->form ? $view->form->ID : 0; |
|
947 | + } |
|
948 | + |
|
949 | + /** |
|
950 | + * @filter `gravityview_search_operator` Modify the search operator for the field (contains, is, isnot, etc) |
|
951 | + * |
|
952 | + * @since 2.0 Added $view parameter |
|
953 | + * |
|
954 | + * @param string $operator Existing search operator |
|
955 | + * @param array $filter array with `key`, `value`, `operator`, `type` keys |
|
956 | + * @param \GV\View $view The View we're operating on. |
|
957 | + */ |
|
958 | + $filter['operator'] = apply_filters('gravityview_search_operator', $filter['operator'], $filter, $view); |
|
959 | + |
|
960 | + if ('is' !== $filter['operator'] && '' === $filter['value']) { |
|
961 | + unset($search_criteria['field_filters'][$key]); |
|
962 | + } |
|
963 | + } |
|
964 | + |
|
965 | + if (!empty($search_criteria['start_date']) || !empty($search_criteria['end_date'])) { |
|
966 | + $date_criteria = []; |
|
967 | + |
|
968 | + if (isset($search_criteria['start_date'])) { |
|
969 | + $date_criteria['start_date'] = $search_criteria['start_date']; |
|
970 | + } |
|
971 | + |
|
972 | + if (isset($search_criteria['end_date'])) { |
|
973 | + $date_criteria['end_date'] = $search_criteria['end_date']; |
|
974 | + } |
|
975 | + |
|
976 | + $_tmp_query = new $query_class($view->form->ID, $date_criteria); |
|
977 | + $_tmp_query_parts = $_tmp_query->_introspect(); |
|
978 | + $extra_conditions[] = $_tmp_query_parts['where']; |
|
979 | + } |
|
980 | + |
|
981 | + $search_conditions = []; |
|
982 | + |
|
983 | + if ($filters = array_filter($search_criteria['field_filters'])) { |
|
984 | + foreach ($filters as &$filter) { |
|
985 | + if (!is_array($filter)) { |
|
986 | + continue; |
|
987 | + } |
|
988 | + |
|
989 | + /** |
|
990 | + * Parse the filter criteria to generate the needed |
|
991 | + * WHERE condition. This is a trick to not write our own generation |
|
992 | + * code by reusing what's inside GF_Query already as they |
|
993 | + * take care of many small things like forcing numeric, etc. |
|
994 | + */ |
|
995 | + $_tmp_query = new $query_class($filter['form_id'], ['mode' => 'any', 'field_filters' => [$filter]]); |
|
996 | + $_tmp_query_parts = $_tmp_query->_introspect(); |
|
997 | + $search_condition = $_tmp_query_parts['where']; |
|
998 | + |
|
999 | + if (empty($filter['key']) && $search_condition->expressions) { |
|
1000 | + $search_conditions[] = $search_condition; |
|
1001 | + } else { |
|
1002 | + $left = $search_condition->left; |
|
1003 | + |
|
1004 | + // When casting a column value to a certain type (e.g., happens with the Number field), GF_Query_Column is wrapped in a GF_Query_Call class. |
|
1005 | + if ($left instanceof GF_Query_Call) { |
|
1006 | + try { |
|
1007 | + $reflectionProperty = new \ReflectionProperty($left, '_parameters'); |
|
1008 | + $reflectionProperty->setAccessible(true); |
|
1009 | + |
|
1010 | + $value = $reflectionProperty->getValue($left); |
|
1011 | + |
|
1012 | + if (!empty($value[0]) && $value[0] instanceof GF_Query_Column) { |
|
1013 | + $left = $value[0]; |
|
1014 | + } else { |
|
1015 | + continue; |
|
1016 | + } |
|
1017 | + } catch (ReflectionException $e) { |
|
1018 | + continue; |
|
1019 | + } |
|
1020 | + } |
|
1021 | + |
|
1022 | + $alias = $query->_alias($left->field_id, $left->source, $left->is_entry_column() ? 't' : 'm'); |
|
1023 | + |
|
1024 | + if ($view->joins && $left->field_id == GF_Query_Column::META) { |
|
1025 | + foreach ($view->joins as $_join) { |
|
1026 | + $on = $_join->join_on; |
|
1027 | + $join = $_join->join; |
|
1028 | + |
|
1029 | + $search_conditions[] = GF_Query_Condition::_or( |
|
1030 | + // Join |
|
1031 | + new GF_Query_Condition( |
|
1032 | + new GF_Query_Column(GF_Query_Column::META, $join->ID, $query->_alias(GF_Query_Column::META, $join->ID, 'm')), |
|
1033 | + $search_condition->operator, |
|
1034 | + $search_condition->right |
|
1035 | + ), |
|
1036 | + // On |
|
1037 | + new GF_Query_Condition( |
|
1038 | + new GF_Query_Column(GF_Query_Column::META, $on->ID, $query->_alias(GF_Query_Column::META, $on->ID, 'm')), |
|
1039 | + $search_condition->operator, |
|
1040 | + $search_condition->right |
|
1041 | + ) |
|
1042 | + ); |
|
1043 | + } |
|
1044 | + } else { |
|
1045 | + $search_conditions[] = new GF_Query_Condition( |
|
1046 | + new GF_Query_Column($left->field_id, $left->source, $alias), |
|
1047 | + $search_condition->operator, |
|
1048 | + $search_condition->right |
|
1049 | + ); |
|
1050 | + } |
|
1051 | + } |
|
1052 | + } |
|
1053 | + |
|
1054 | + if ($search_conditions) { |
|
1055 | + $search_conditions = [call_user_func_array('\GF_Query_Condition::'.($mode == 'all' ? '_and' : '_or'), $search_conditions)]; |
|
1056 | + } |
|
1057 | + } |
|
1058 | + |
|
1059 | + /** |
|
1060 | + * Grab the current clauses. We'll be combining them shortly. |
|
1061 | + */ |
|
1062 | + $query_parts = $query->_introspect(); |
|
1063 | + |
|
1064 | + /** |
|
1065 | + * Combine the parts as a new WHERE clause. |
|
1066 | + */ |
|
1067 | + $where = call_user_func_array('\GF_Query_Condition::_and', array_merge([$query_parts['where']], $search_conditions, $extra_conditions)); |
|
1068 | + $query->where($where); |
|
1069 | + } |
|
1070 | + |
|
1071 | + /** |
|
1072 | + * Convert $_GET/$_POST key to the field/meta ID. |
|
1073 | + * |
|
1074 | + * Examples: |
|
1075 | + * - `filter_is_starred` => `is_starred` |
|
1076 | + * - `filter_1_2` => `1.2` |
|
1077 | + * - `filter_5` => `5` |
|
1078 | + * |
|
1079 | + * @since 2.0 |
|
1080 | + * |
|
1081 | + * @param string $key $_GET/_$_POST search key |
|
1082 | + * |
|
1083 | + * @return string |
|
1084 | + */ |
|
1085 | + private function convert_request_key_to_filter_key($key) |
|
1086 | + { |
|
1087 | + $field_id = str_replace(['filter_', 'input_'], '', $key); |
|
1088 | + |
|
1089 | + // calculates field_id, removing 'filter_' and for '_' for advanced fields ( like name or checkbox ) |
|
1090 | + if (preg_match('/^[0-9_]+$/ism', $field_id)) { |
|
1091 | + $field_id = str_replace('_', '.', $field_id); |
|
1092 | + } |
|
1093 | + |
|
1094 | + return $field_id; |
|
1095 | + } |
|
1096 | + |
|
1097 | + /** |
|
1098 | + * Prepare the field filters to GFAPI. |
|
1099 | + * |
|
1100 | + * The type post_category, multiselect and checkbox support multi-select search - each value needs to be separated in an independent filter so we could apply the ANY search mode. |
|
1101 | + * |
|
1102 | + * Format searched values |
|
1103 | + * |
|
1104 | + * @param string $filter_key ID of the field, or entry meta key |
|
1105 | + * @param string $value $_GET/$_POST search value |
|
1106 | + * @param \GV\View $view The view we're looking at |
|
1107 | + * @param array[] $searchable_fields The searchable fields as configured by the widget. |
|
1108 | + * @param string[] $get The $_GET/$_POST array. |
|
1109 | + * |
|
1110 | + * @since develop Added 5th $get parameter for operator overrides. |
|
1111 | + * |
|
1112 | + * @todo Set function as private. |
|
1113 | + * |
|
1114 | + * @return array|false 1 or 2 deph levels, false if not allowed |
|
1115 | + */ |
|
1116 | + public function prepare_field_filter($filter_key, $value, $view, $searchable_fields, $get = []) |
|
1117 | + { |
|
1118 | + $key = $filter_key; |
|
1119 | + $filter_key = explode(':', $filter_key); // field_id, form_id |
|
1120 | + |
|
1121 | + $form = null; |
|
1122 | + |
|
1123 | + if (count($filter_key) > 1) { |
|
1124 | + // form is specified |
|
1125 | + list($field_id, $form_id) = $filter_key; |
|
1126 | + |
|
1127 | + if ($forms = \GV\View::get_joined_forms($view->ID)) { |
|
1128 | + if (!$form = \GV\GF_Form::by_id($form_id)) { |
|
1129 | + return false; |
|
1130 | + } |
|
1131 | + } |
|
1132 | + |
|
1133 | + // form is allowed |
|
1134 | + $found = false; |
|
1135 | + foreach ($forms as $form) { |
|
1136 | + if ($form->ID == $form_id) { |
|
1137 | + $found = true; |
|
1138 | + break; |
|
1139 | + } |
|
1140 | + } |
|
1141 | + |
|
1142 | + if (!$found) { |
|
1143 | + return false; |
|
1144 | + } |
|
1145 | + |
|
1146 | + // form is in searchable fields |
|
1147 | + $found = false; |
|
1148 | + foreach ($searchable_fields as $field) { |
|
1149 | + if ($field_id == $field['field'] && $form->ID == $field['form_id']) { |
|
1150 | + $found = true; |
|
1151 | + break; |
|
1152 | + } |
|
1153 | + } |
|
1154 | + |
|
1155 | + if (!$found) { |
|
1156 | + return false; |
|
1157 | + } |
|
1158 | + } else { |
|
1159 | + $field_id = reset($filter_key); |
|
1160 | + $searchable_fields = wp_list_pluck($searchable_fields, 'field'); |
|
1161 | + if (!in_array('search_all', $searchable_fields) && !in_array($field_id, $searchable_fields)) { |
|
1162 | + return false; |
|
1163 | + } |
|
1164 | + } |
|
1165 | + |
|
1166 | + if (!$form) { |
|
1167 | + // fallback |
|
1168 | + $form = $view->form; |
|
1169 | + } |
|
1170 | + |
|
1171 | + // get form field array |
|
1172 | + $form_field = is_numeric($field_id) ? \GV\GF_Field::by_id($form, $field_id) : \GV\Internal_Field::by_id($field_id); |
|
1173 | + |
|
1174 | + if (!$form_field) { |
|
1175 | + return false; |
|
1176 | + } |
|
1177 | + |
|
1178 | + // default filter array |
|
1179 | + $filter = [ |
|
1180 | + 'key' => $field_id, |
|
1181 | + 'value' => $value, |
|
1182 | + 'form_id' => $form->ID, |
|
1183 | + ]; |
|
1184 | + |
|
1185 | + switch ($form_field->type) { |
|
1186 | + |
|
1187 | + case 'select': |
|
1188 | + case 'radio': |
|
1189 | + $filter['operator'] = $this->get_operator($get, $key, ['is'], 'is'); |
|
1190 | + break; |
|
1191 | + |
|
1192 | + case 'post_category': |
|
1193 | + |
|
1194 | + if (!is_array($value)) { |
|
1195 | + $value = [$value]; |
|
1196 | + } |
|
1197 | + |
|
1198 | + // Reset filter variable |
|
1199 | + $filter = []; |
|
1200 | + |
|
1201 | + foreach ($value as $val) { |
|
1202 | + $cat = get_term($val, 'category'); |
|
1203 | + $filter[] = [ |
|
1204 | + 'key' => $field_id, |
|
1205 | + 'value' => esc_attr($cat->name).':'.$val, |
|
1206 | + 'operator' => $this->get_operator($get, $key, ['is'], 'is'), |
|
1207 | + ]; |
|
1208 | + } |
|
1209 | + |
|
1210 | + break; |
|
1211 | + |
|
1212 | + case 'multiselect': |
|
1213 | + |
|
1214 | + if (!is_array($value)) { |
|
1215 | + break; |
|
1216 | + } |
|
1217 | + |
|
1218 | + // Reset filter variable |
|
1219 | + $filter = []; |
|
1220 | + |
|
1221 | + foreach ($value as $val) { |
|
1222 | + $filter[] = ['key' => $field_id, 'value' => $val]; |
|
1223 | + } |
|
1224 | + |
|
1225 | + break; |
|
1226 | + |
|
1227 | + case 'checkbox': |
|
1228 | + // convert checkbox on/off into the correct search filter |
|
1229 | + if (false !== strpos($field_id, '.') && !empty($form_field->inputs) && !empty($form_field->choices)) { |
|
1230 | + foreach ($form_field->inputs as $k => $input) { |
|
1231 | + if ($input['id'] == $field_id) { |
|
1232 | + $filter['value'] = $form_field->choices[$k]['value']; |
|
1233 | + $filter['operator'] = $this->get_operator($get, $key, ['is'], 'is'); |
|
1234 | + break; |
|
1235 | + } |
|
1236 | + } |
|
1237 | + } elseif (is_array($value)) { |
|
1238 | + |
|
1239 | + // Reset filter variable |
|
1240 | + $filter = []; |
|
1241 | + |
|
1242 | + foreach ($value as $val) { |
|
1243 | + $filter[] = [ |
|
1244 | + 'key' => $field_id, |
|
1245 | + 'value' => $val, |
|
1246 | + 'operator' => $this->get_operator($get, $key, ['is'], 'is'), |
|
1247 | + ]; |
|
1248 | + } |
|
1249 | + } |
|
1250 | + |
|
1251 | + break; |
|
1252 | + |
|
1253 | + case 'name': |
|
1254 | + case 'address': |
|
1255 | + |
|
1256 | + if (false === strpos($field_id, '.')) { |
|
1257 | + $words = explode(' ', $value); |
|
1258 | + |
|
1259 | + $filters = []; |
|
1260 | + foreach ($words as $word) { |
|
1261 | + if (!empty($word) && strlen($word) > 1) { |
|
1262 | + // Keep the same key for each filter |
|
1263 | + $filter['value'] = $word; |
|
1264 | + // Add a search for the value |
|
1265 | + $filters[] = $filter; |
|
1266 | + } |
|
1267 | + } |
|
1268 | + |
|
1269 | + $filter = $filters; |
|
1270 | + } |
|
1271 | + |
|
1272 | + // State/Province should be exact matches |
|
1273 | + if ('address' === $form_field->field->type) { |
|
1274 | + $searchable_fields = $this->get_view_searchable_fields($view, true); |
|
1275 | + |
|
1276 | + foreach ($searchable_fields as $searchable_field) { |
|
1277 | + if ($form_field->ID !== $searchable_field['field']) { |
|
1278 | + continue; |
|
1279 | + } |
|
1280 | + |
|
1281 | + // Only exact-match dropdowns, not text search |
|
1282 | + if (in_array($searchable_field['input'], ['text', 'search'], true)) { |
|
1283 | + continue; |
|
1284 | + } |
|
1285 | + |
|
1286 | + $input_id = gravityview_get_input_id_from_id($form_field->ID); |
|
1287 | + |
|
1288 | + if (4 === $input_id) { |
|
1289 | + $filter['operator'] = $this->get_operator($get, $key, ['is'], 'is'); |
|
1290 | + } |
|
1291 | + } |
|
1292 | + } |
|
1293 | + |
|
1294 | + break; |
|
1295 | + |
|
1296 | + case 'payment_date': |
|
1297 | + case 'date': |
|
1298 | + |
|
1299 | + $date_format = $this->get_datepicker_format(true); |
|
1300 | + |
|
1301 | + if (is_array($value)) { |
|
1302 | + |
|
1303 | + // Reset filter variable |
|
1304 | + $filter = []; |
|
1305 | + |
|
1306 | + foreach ($value as $k => $date) { |
|
1307 | + if (empty($date)) { |
|
1308 | + continue; |
|
1309 | + } |
|
1310 | + $operator = 'start' === $k ? '>=' : '<='; |
|
1311 | + |
|
1312 | + /** |
|
1313 | + * @hack |
|
1314 | + * |
|
1315 | + * @since 1.16.3 |
|
1316 | + * Safeguard until GF implements '<=' operator |
|
1317 | + */ |
|
1318 | + if (!GFFormsModel::is_valid_operator($operator) && $operator === '<=') { |
|
1319 | + $operator = '<'; |
|
1320 | + $date = date('Y-m-d', strtotime(self::get_formatted_date($date, 'Y-m-d', $date_format).' +1 day')); |
|
1321 | + } |
|
1322 | + |
|
1323 | + $filter[] = [ |
|
1324 | + 'key' => $field_id, |
|
1325 | + 'value' => self::get_formatted_date($date, 'Y-m-d', $date_format), |
|
1326 | + 'operator' => $this->get_operator($get, $key, [$operator], $operator), |
|
1327 | + ]; |
|
1328 | + } |
|
1329 | + } else { |
|
1330 | + $date = $value; |
|
1331 | + $filter['value'] = self::get_formatted_date($date, 'Y-m-d', $date_format); |
|
1332 | + $filter['operator'] = $this->get_operator($get, $key, ['is'], 'is'); |
|
1333 | + } |
|
1334 | + |
|
1335 | + if ('payment_date' === $key) { |
|
1336 | + $filter['operator'] = 'contains'; |
|
1337 | + } |
|
1338 | + |
|
1339 | + break; |
|
1340 | + } // switch field type |
|
1341 | + |
|
1342 | + return $filter; |
|
1343 | + } |
|
1344 | + |
|
1345 | + /** |
|
1346 | + * Get the Field Format form GravityForms. |
|
1347 | + * |
|
1348 | + * @param GF_Field_Date $field The field object |
|
1349 | + * |
|
1350 | + * @since 1.10 |
|
1351 | + * |
|
1352 | + * @return string Format of the date in the database |
|
1353 | + */ |
|
1354 | + public static function get_date_field_format(GF_Field_Date $field) |
|
1355 | + { |
|
1356 | + $format = 'm/d/Y'; |
|
1357 | + $datepicker = [ |
|
1358 | + 'mdy' => 'm/d/Y', |
|
1359 | + 'dmy' => 'd/m/Y', |
|
1360 | + 'dmy_dash' => 'd-m-Y', |
|
1361 | + 'dmy_dot' => 'd.m.Y', |
|
1362 | + 'ymd_slash' => 'Y/m/d', |
|
1363 | + 'ymd_dash' => 'Y-m-d', |
|
1364 | + 'ymd_dot' => 'Y.m.d', |
|
1365 | + ]; |
|
1366 | + |
|
1367 | + if (!empty($field->dateFormat) && isset($datepicker[$field->dateFormat])) { |
|
1368 | + $format = $datepicker[$field->dateFormat]; |
|
1369 | + } |
|
1370 | + |
|
1371 | + return $format; |
|
1372 | + } |
|
1373 | + |
|
1374 | + /** |
|
1375 | + * Format a date value. |
|
1376 | + * |
|
1377 | + * @param string $value Date value input |
|
1378 | + * @param string $format Wanted formatted date |
|
1379 | + * |
|
1380 | + * @since 2.1.2 |
|
1381 | + * |
|
1382 | + * @param string $value_format The value format. Default: Y-m-d |
|
1383 | + * |
|
1384 | + * @return string |
|
1385 | + */ |
|
1386 | + public static function get_formatted_date($value = '', $format = 'Y-m-d', $value_format = 'Y-m-d') |
|
1387 | + { |
|
1388 | + $date = date_create_from_format($value_format, $value); |
|
1389 | + |
|
1390 | + if (empty($date)) { |
|
1391 | + gravityview()->log->debug('Date format not valid: {value}', ['value' => $value]); |
|
1392 | + |
|
1393 | + return ''; |
|
1394 | + } |
|
1395 | + |
|
1396 | + return $date->format($format); |
|
1397 | + } |
|
1398 | + |
|
1399 | + /** |
|
1400 | + * Include this extension templates path. |
|
1401 | + * |
|
1402 | + * @param array $file_paths List of template paths ordered |
|
1403 | + */ |
|
1404 | + public function add_template_path($file_paths) |
|
1405 | + { |
|
1406 | + |
|
1407 | + // Index 100 is the default GravityView template path. |
|
1408 | + $file_paths[102] = self::$file.'templates/'; |
|
1409 | + |
|
1410 | + return $file_paths; |
|
1411 | + } |
|
1412 | + |
|
1413 | + /** |
|
1414 | + * Check whether the configured search fields have a date field. |
|
1415 | + * |
|
1416 | + * @since 1.17.5 |
|
1417 | + * |
|
1418 | + * @param array $search_fields |
|
1419 | + * |
|
1420 | + * @return bool True: has a `date` or `date_range` field |
|
1421 | + */ |
|
1422 | + private function has_date_field($search_fields) |
|
1423 | + { |
|
1424 | + $has_date = false; |
|
1425 | + |
|
1426 | + foreach ($search_fields as $k => $field) { |
|
1427 | + if (in_array($field['input'], ['date', 'date_range', 'entry_date'])) { |
|
1428 | + $has_date = true; |
|
1429 | + break; |
|
1430 | + } |
|
1431 | + } |
|
1432 | + |
|
1433 | + return $has_date; |
|
1434 | + } |
|
1435 | + |
|
1436 | + /** |
|
1437 | + * Renders the Search Widget. |
|
1438 | + * |
|
1439 | + * @param array $widget_args |
|
1440 | + * @param string $content |
|
1441 | + * @param string|\GV\Template_Context $context |
|
1442 | + * |
|
1443 | + * @return void |
|
1444 | + */ |
|
1445 | + public function render_frontend($widget_args, $content = '', $context = '') |
|
1446 | + { |
|
1447 | + $gravityview_view = GravityView_View::getInstance(); |
|
1448 | + |
|
1449 | + if (empty($gravityview_view)) { |
|
1450 | + gravityview()->log->debug('$gravityview_view not instantiated yet.'); |
|
1451 | + |
|
1452 | + return; |
|
1453 | + } |
|
1454 | + |
|
1455 | + $view = \GV\View::by_id($gravityview_view->view_id); |
|
1456 | + |
|
1457 | + // get configured search fields |
|
1458 | + $search_fields = !empty($widget_args['search_fields']) ? json_decode($widget_args['search_fields'], true) : ''; |
|
1459 | + |
|
1460 | + if (empty($search_fields) || !is_array($search_fields)) { |
|
1461 | + gravityview()->log->debug('No search fields configured for widget:', ['data' => $widget_args]); |
|
1462 | + |
|
1463 | + return; |
|
1464 | + } |
|
1465 | + |
|
1466 | + // prepare fields |
|
1467 | + foreach ($search_fields as $k => $field) { |
|
1468 | + $updated_field = $field; |
|
1469 | + |
|
1470 | + $updated_field = $this->get_search_filter_details($updated_field, $context); |
|
1471 | + |
|
1472 | + switch ($field['field']) { |
|
1473 | + |
|
1474 | + case 'search_all': |
|
1475 | + $updated_field['key'] = 'search_all'; |
|
1476 | + $updated_field['input'] = 'search_all'; |
|
1477 | + $updated_field['value'] = $this->rgget_or_rgpost('gv_search'); |
|
1478 | + break; |
|
1479 | + |
|
1480 | + case 'entry_date': |
|
1481 | + $updated_field['key'] = 'entry_date'; |
|
1482 | + $updated_field['input'] = 'entry_date'; |
|
1483 | + $updated_field['value'] = [ |
|
1484 | + 'start' => $this->rgget_or_rgpost('gv_start'), |
|
1485 | + 'end' => $this->rgget_or_rgpost('gv_end'), |
|
1486 | + ]; |
|
1487 | + break; |
|
1488 | + |
|
1489 | + case 'entry_id': |
|
1490 | + $updated_field['key'] = 'entry_id'; |
|
1491 | + $updated_field['input'] = 'entry_id'; |
|
1492 | + $updated_field['value'] = $this->rgget_or_rgpost('gv_id'); |
|
1493 | + break; |
|
1494 | + |
|
1495 | + case 'created_by': |
|
1496 | + $updated_field['key'] = 'created_by'; |
|
1497 | + $updated_field['name'] = 'gv_by'; |
|
1498 | + $updated_field['value'] = $this->rgget_or_rgpost('gv_by'); |
|
1499 | + break; |
|
1500 | + |
|
1501 | + case 'is_approved': |
|
1502 | + $updated_field['key'] = 'is_approved'; |
|
1503 | + $updated_field['value'] = $this->rgget_or_rgpost('filter_is_approved'); |
|
1504 | + $updated_field['choices'] = self::get_is_approved_choices(); |
|
1505 | + break; |
|
1506 | + } |
|
1507 | + |
|
1508 | + $search_fields[$k] = $updated_field; |
|
1509 | + } |
|
1510 | + |
|
1511 | + gravityview()->log->debug('Calculated Search Fields: ', ['data' => $search_fields]); |
|
1512 | + |
|
1513 | + /** |
|
1514 | + * @filter `gravityview_widget_search_filters` Modify what fields are shown. The order of the fields in the $search_filters array controls the order as displayed in the search bar widget. |
|
1515 | + * |
|
1516 | + * @param array $search_fields Array of search filters with `key`, `label`, `value`, `type`, `choices` keys |
|
1517 | + * @param GravityView_Widget_Search $this Current widget object |
|
1518 | + * @param array $widget_args Args passed to this method. {@since 1.8} |
|
1519 | + * @param \GV\Template_Context $context {@since 2.0} |
|
1520 | + * |
|
1521 | + * @var array |
|
1522 | + */ |
|
1523 | + $gravityview_view->search_fields = apply_filters('gravityview_widget_search_filters', $search_fields, $this, $widget_args, $context); |
|
1524 | + |
|
1525 | + $gravityview_view->permalink_fields = $this->add_no_permalink_fields([], $this, $widget_args); |
|
1526 | + |
|
1527 | + $gravityview_view->search_layout = !empty($widget_args['search_layout']) ? $widget_args['search_layout'] : 'horizontal'; |
|
1528 | + |
|
1529 | + /** @since 1.14 */ |
|
1530 | + $gravityview_view->search_mode = !empty($widget_args['search_mode']) ? $widget_args['search_mode'] : 'any'; |
|
1531 | + |
|
1532 | + $custom_class = !empty($widget_args['custom_class']) ? $widget_args['custom_class'] : ''; |
|
1533 | + |
|
1534 | + $gravityview_view->search_class = self::get_search_class($custom_class); |
|
1535 | + |
|
1536 | + $gravityview_view->search_clear = !empty($widget_args['search_clear']) ? $widget_args['search_clear'] : false; |
|
1537 | + |
|
1538 | + if ($this->has_date_field($search_fields)) { |
|
1539 | + // enqueue datepicker stuff only if needed! |
|
1540 | + $this->enqueue_datepicker(); |
|
1541 | + } |
|
1542 | + |
|
1543 | + $this->maybe_enqueue_flexibility(); |
|
1544 | + |
|
1545 | + $gravityview_view->render('widget', 'search', false); |
|
1546 | + } |
|
1547 | + |
|
1548 | + /** |
|
1549 | + * Get the search class for a search form. |
|
1550 | + * |
|
1551 | + * @since 1.5.4 |
|
1552 | + * |
|
1553 | + * @return string Sanitized CSS class for the search form |
|
1554 | + */ |
|
1555 | + public static function get_search_class($custom_class = '') |
|
1556 | + { |
|
1557 | + $gravityview_view = GravityView_View::getInstance(); |
|
1558 | + |
|
1559 | + $search_class = 'gv-search-'.$gravityview_view->search_layout; |
|
1560 | + |
|
1561 | + if (!empty($custom_class)) { |
|
1562 | + $search_class .= ' '.$custom_class; |
|
1563 | + } |
|
1564 | + |
|
1565 | + /** |
|
1566 | + * @filter `gravityview_search_class` Modify the CSS class for the search form |
|
1567 | + * |
|
1568 | + * @param string $search_class The CSS class for the search form |
|
1569 | + */ |
|
1570 | + $search_class = apply_filters('gravityview_search_class', $search_class); |
|
1571 | + |
|
1572 | + // Is there an active search being performed? Used by fe-views.js |
|
1573 | + $search_class .= gravityview()->request->is_search() || GravityView_frontend::getInstance()->isSearch() ? ' gv-is-search' : ''; |
|
1574 | + |
|
1575 | + return gravityview_sanitize_html_class($search_class); |
|
1576 | + } |
|
1577 | + |
|
1578 | + /** |
|
1579 | + * Calculate the search form action. |
|
1580 | + * |
|
1581 | + * @since 1.6 |
|
1582 | + * |
|
1583 | + * @return string |
|
1584 | + */ |
|
1585 | + public static function get_search_form_action() |
|
1586 | + { |
|
1587 | + $gravityview_view = GravityView_View::getInstance(); |
|
1588 | + |
|
1589 | + $post_id = $gravityview_view->getPostId() ? $gravityview_view->getPostId() : $gravityview_view->getViewId(); |
|
1590 | + |
|
1591 | + $url = add_query_arg([], get_permalink($post_id)); |
|
1592 | + |
|
1593 | + /** |
|
1594 | + * @filter `gravityview/widget/search/form/action` Override the search URL. |
|
1595 | + * |
|
1596 | + * @param string $action Where the form submits to. |
|
1597 | + * |
|
1598 | + * Further parameters will be added once adhoc context is added. |
|
1599 | + * Use gravityview()->request until then. |
|
1600 | + */ |
|
1601 | + return apply_filters('gravityview/widget/search/form/action', $url); |
|
1602 | + } |
|
1603 | + |
|
1604 | + /** |
|
1605 | + * Get the label for a search form field. |
|
1606 | + * |
|
1607 | + * @param array $field Field setting as sent by the GV configuration - has `field`, `input` (input type), and `label` keys |
|
1608 | + * @param array $form_field Form field data, as fetched by `gravityview_get_field()` |
|
1609 | + * |
|
1610 | + * @return string Label for the search form |
|
1611 | + */ |
|
1612 | + private static function get_field_label($field, $form_field = []) |
|
1613 | + { |
|
1614 | + $label = \GV\Utils::_GET('label', \GV\Utils::get($field, 'label')); |
|
1615 | + |
|
1616 | + if (!$label) { |
|
1617 | + $label = isset($form_field['label']) ? $form_field['label'] : ''; |
|
1618 | + |
|
1619 | + switch ($field['field']) { |
|
1620 | + case 'search_all': |
|
1621 | + $label = __('Search Entries:', 'gravityview'); |
|
1622 | + break; |
|
1623 | + case 'entry_date': |
|
1624 | + $label = __('Filter by date:', 'gravityview'); |
|
1625 | + break; |
|
1626 | + case 'entry_id': |
|
1627 | + $label = __('Entry ID:', 'gravityview'); |
|
1628 | + break; |
|
1629 | + default: |
|
1630 | + // If this is a field input, not a field |
|
1631 | + if (strpos($field['field'], '.') > 0 && !empty($form_field['inputs'])) { |
|
1632 | + |
|
1633 | + // Get the label for the field in question, which returns an array |
|
1634 | + $items = wp_list_filter($form_field['inputs'], ['id' => $field['field']]); |
|
1635 | + |
|
1636 | + // Get the item with the `label` key |
|
1637 | + $values = wp_list_pluck($items, 'label'); |
|
1638 | + |
|
1639 | + // There will only one item in the array, but this is easier |
|
1640 | + foreach ($values as $value) { |
|
1641 | + $label = $value; |
|
1642 | + break; |
|
1643 | + } |
|
1644 | + } |
|
1645 | + } |
|
1646 | + } |
|
1647 | + |
|
1648 | + /** |
|
1649 | + * @filter `gravityview_search_field_label` Modify the label for a search field. Supports returning HTML |
|
1650 | + * |
|
1651 | + * @since 1.17.3 Added $field parameter |
|
1652 | + * |
|
1653 | + * @param string $label Existing label text, sanitized. |
|
1654 | + * @param array $form_field Gravity Forms field array, as returned by `GFFormsModel::get_field()` |
|
1655 | + * @param array $field Field setting as sent by the GV configuration - has `field`, `input` (input type), and `label` keys |
|
1656 | + */ |
|
1657 | + $label = apply_filters('gravityview_search_field_label', esc_attr($label), $form_field, $field); |
|
1658 | + |
|
1659 | + return $label; |
|
1660 | + } |
|
1661 | + |
|
1662 | + /** |
|
1663 | + * Prepare search fields to frontend render with other details (label, field type, searched values). |
|
1664 | + * |
|
1665 | + * @param array $field |
|
1666 | + * @param \GV\Context $context |
|
1667 | + * |
|
1668 | + * @return array |
|
1669 | + */ |
|
1670 | + private function get_search_filter_details($field, $context) |
|
1671 | + { |
|
1672 | + $gravityview_view = GravityView_View::getInstance(); |
|
1673 | + |
|
1674 | + $form = $gravityview_view->getForm(); |
|
1675 | + |
|
1676 | + // for advanced field ids (eg, first name / last name ) |
|
1677 | + $name = 'filter_'.str_replace('.', '_', $field['field']); |
|
1678 | + |
|
1679 | + // get searched value from $_GET/$_POST (string or array) |
|
1680 | + $value = $this->rgget_or_rgpost($name); |
|
1681 | + |
|
1682 | + // get form field details |
|
1683 | + $form_field = gravityview_get_field($form, $field['field']); |
|
1684 | + |
|
1685 | + $form_field_type = \GV\Utils::get($form_field, 'type'); |
|
1686 | + |
|
1687 | + $filter = [ |
|
1688 | + 'key' => \GV\Utils::get($field, 'field'), |
|
1689 | + 'name' => $name, |
|
1690 | + 'label' => self::get_field_label($field, $form_field), |
|
1691 | + 'input' => \GV\Utils::get($field, 'input'), |
|
1692 | + 'value' => $value, |
|
1693 | + 'type' => $form_field_type, |
|
1694 | + ]; |
|
1695 | + |
|
1696 | + // collect choices |
|
1697 | + if ('post_category' === $form_field_type && !empty($form_field['displayAllCategories']) && empty($form_field['choices'])) { |
|
1698 | + $filter['choices'] = gravityview_get_terms_choices(); |
|
1699 | + } elseif (!empty($form_field['choices'])) { |
|
1700 | + $filter['choices'] = $form_field['choices']; |
|
1701 | + } |
|
1702 | + |
|
1703 | + if ('date_range' === $field['input'] && empty($value)) { |
|
1704 | + $filter['value'] = ['start' => '', 'end' => '']; |
|
1705 | + } |
|
1706 | + |
|
1707 | + if ('created_by' === $field['field']) { |
|
1708 | + $filter['choices'] = self::get_created_by_choices($context->view); |
|
1709 | + $filter['type'] = 'created_by'; |
|
1710 | + } |
|
1711 | + |
|
1712 | + if (!empty($filter['choices'])) { |
|
1713 | + /** |
|
1714 | + * @filter `gravityview/search/sieve_choices` Only output used choices for this field. |
|
1715 | + * |
|
1716 | + * @param bool Yes or no. |
|
1717 | + * @param array $field The field configuration. |
|
1718 | + * @param \GV\Context The context. |
|
1719 | + */ |
|
1720 | + if (apply_filters('gravityview/search/sieve_choices', false, $field, $context)) { |
|
1721 | + $filter['choices'] = $this->sieve_filter_choices($filter, $context); |
|
1722 | + } |
|
1723 | + } |
|
1724 | + |
|
1725 | + /** |
|
1726 | + * @filter `gravityview/search/filter_details` Filter the output filter details for the Search widget. |
|
1727 | + * |
|
1728 | + * @param array $filter The filter details |
|
1729 | + * @param array $field The search field configuration |
|
1730 | + * @param \GV\Context The context |
|
1731 | + * |
|
1732 | + * @since develop |
|
1733 | + */ |
|
1734 | + $filter = apply_filters('gravityview/search/filter_details', $filter, $field, $context); |
|
1735 | + |
|
1736 | + return $filter; |
|
1737 | + } |
|
1738 | + |
|
1739 | + /** |
|
1740 | + * Sieve filter choices to only ones that are used. |
|
1741 | + * |
|
1742 | + * @param array $filter The filter configuration. |
|
1743 | + * @param \GV\Context $context The context |
|
1744 | + * |
|
1745 | + * @since develop |
|
1746 | + * |
|
1747 | + * @internal |
|
1748 | + * |
|
1749 | + * @return array The filter choices. |
|
1750 | + */ |
|
1751 | + private function sieve_filter_choices($filter, $context) |
|
1752 | + { |
|
1753 | + if (empty($filter['key']) || empty($filter['choices'])) { |
|
1754 | + return $filter; // @todo Populate plugins might give us empty choices |
|
1755 | + } |
|
1756 | + |
|
1757 | + // Allow only created_by and field-ids to be sieved. |
|
1758 | + if ('created_by' !== $filter['key'] && !is_numeric($filter['key'])) { |
|
1759 | + return $filter; |
|
1760 | + } |
|
1761 | + |
|
1762 | + $form_id = $context->view->form->ID; // @todo Support multiple forms (joins) |
|
1763 | + |
|
1764 | + global $wpdb; |
|
1765 | + |
|
1766 | + $entry_table_name = GFFormsModel::get_entry_table_name(); |
|
1767 | + $entry_meta_table_name = GFFormsModel::get_entry_meta_table_name(); |
|
1768 | + |
|
1769 | + $key_like = $wpdb->esc_like($filter['key']).'.%'; |
|
1770 | + |
|
1771 | + switch (\GV\Utils::get($filter, 'type')) { |
|
1772 | + case 'post_category': |
|
1773 | + $choices = $wpdb->get_col($wpdb->prepare( |
|
1774 | + "SELECT DISTINCT SUBSTRING_INDEX(meta_value, ':', 1) FROM $entry_meta_table_name WHERE (meta_key LIKE %s OR meta_key = %d) AND form_id = %d", |
|
1775 | + $key_like, |
|
1776 | + $filter['key'], |
|
1777 | + $form_id |
|
1778 | + )); |
|
1779 | + break; |
|
1780 | + case 'created_by': |
|
1781 | + $choices = $wpdb->get_col($wpdb->prepare( |
|
1782 | + "SELECT DISTINCT created_by FROM $entry_table_name WHERE form_id = %d", |
|
1783 | + $form_id |
|
1784 | + )); |
|
1785 | + break; |
|
1786 | + default: |
|
1787 | + $choices = $wpdb->get_col($wpdb->prepare( |
|
1788 | + "SELECT DISTINCT meta_value FROM $entry_meta_table_name WHERE (meta_key LIKE %s OR meta_key = %d) AND form_id = %d", |
|
1789 | + $key_like, |
|
1790 | + $filter['key'], |
|
1791 | + $form_id |
|
1792 | + )); |
|
1793 | + |
|
1794 | + if (($field = gravityview_get_field($form_id, $filter['key'])) && 'json' === $field->storageType) { |
|
1795 | + $choices = array_map('json_decode', $choices); |
|
1796 | + $_choices_array = []; |
|
1797 | + foreach ($choices as $choice) { |
|
1798 | + if (is_array($choice)) { |
|
1799 | + $_choices_array = array_merge($_choices_array, $choice); |
|
1800 | + } else { |
|
1801 | + $_choices_array[] = $choice; |
|
1802 | + } |
|
1803 | + } |
|
1804 | + $choices = array_unique($_choices_array); |
|
1805 | + } |
|
1806 | + |
|
1807 | + break; |
|
1808 | + } |
|
1809 | + |
|
1810 | + $filter_choices = []; |
|
1811 | + foreach ($filter['choices'] as $choice) { |
|
1812 | + if (in_array($choice['text'], $choices, true) || in_array($choice['value'], $choices, true)) { |
|
1813 | + $filter_choices[] = $choice; |
|
1814 | + } |
|
1815 | + } |
|
1816 | + |
|
1817 | + return $filter_choices; |
|
1818 | + } |
|
1819 | + |
|
1820 | + /** |
|
1821 | + * Calculate the search choices for the users. |
|
1822 | + * |
|
1823 | + * @param \GV\View $view The view |
|
1824 | + * |
|
1825 | + * @since develop |
|
1826 | + * @since 1.8 |
|
1827 | + * |
|
1828 | + * @return array Array of user choices (value = ID, text = display name) |
|
1829 | + */ |
|
1830 | + private static function get_created_by_choices($view) |
|
1831 | + { |
|
1832 | + |
|
1833 | + /** |
|
1834 | + * filter gravityview/get_users/search_widget. |
|
1835 | + * |
|
1836 | + * @see \GVCommon::get_users |
|
1837 | + */ |
|
1838 | + $users = GVCommon::get_users('search_widget', ['fields' => ['ID', 'display_name']]); |
|
1839 | + |
|
1840 | + $choices = []; |
|
1841 | + foreach ($users as $user) { |
|
1842 | + /** |
|
1843 | + * @filter `gravityview/search/created_by/text` Filter the display text in created by search choices |
|
1844 | + * |
|
1845 | + * @since develop |
|
1846 | + * |
|
1847 | + * @param string[in,out] The text. Default: $user->display_name |
|
1848 | + * @param \WP_User $user The user. |
|
1849 | + * @param \GV\View $view The view. |
|
1850 | + */ |
|
1851 | + $text = apply_filters('gravityview/search/created_by/text', $user->display_name, $user, $view); |
|
1852 | + $choices[] = [ |
|
1853 | + 'value' => $user->ID, |
|
1854 | + 'text' => $text, |
|
1855 | + ]; |
|
1856 | + } |
|
1857 | + |
|
1858 | + return $choices; |
|
1859 | + } |
|
1860 | + |
|
1861 | + /** |
|
1862 | + * Calculate the search checkbox choices for approval status. |
|
1863 | + * |
|
1864 | + * @since develop |
|
1865 | + * |
|
1866 | + * @return array Array of approval status choices (value = status, text = display name) |
|
1867 | + */ |
|
1868 | + private static function get_is_approved_choices() |
|
1869 | + { |
|
1870 | + $choices = []; |
|
1871 | + foreach (GravityView_Entry_Approval_Status::get_all() as $status) { |
|
1872 | + $choices[] = [ |
|
1873 | + 'value' => $status['value'], |
|
1874 | + 'text' => $status['label'], |
|
1875 | + ]; |
|
1876 | + } |
|
1877 | + |
|
1878 | + return $choices; |
|
1879 | + } |
|
1880 | + |
|
1881 | + /** |
|
1882 | + * Output the Clear Search Results button. |
|
1883 | + * |
|
1884 | + * @since 1.5.4 |
|
1885 | + */ |
|
1886 | + public static function the_clear_search_button() |
|
1887 | + { |
|
1888 | + $gravityview_view = GravityView_View::getInstance(); |
|
1889 | + |
|
1890 | + if ($gravityview_view->search_clear) { |
|
1891 | + $url = strtok(add_query_arg([]), '?'); |
|
1892 | + |
|
1893 | + echo gravityview_get_link($url, esc_html__('Clear', 'gravityview'), 'class=button gv-search-clear'); |
|
1894 | + } |
|
1895 | + } |
|
1896 | + |
|
1897 | + /** |
|
1898 | + * Based on the search method, fetch the value for a specific key. |
|
1899 | + * |
|
1900 | + * @since 1.16.4 |
|
1901 | + * |
|
1902 | + * @param string $name Name of the request key to fetch the value for |
|
1903 | + * |
|
1904 | + * @return mixed|string Value of request at $name key. Empty string if empty. |
|
1905 | + */ |
|
1906 | + private function rgget_or_rgpost($name) |
|
1907 | + { |
|
1908 | + $value = \GV\Utils::_REQUEST($name); |
|
1909 | + |
|
1910 | + $value = stripslashes_deep($value); |
|
1911 | + |
|
1912 | + $value = gv_map_deep($value, 'rawurldecode'); |
|
1913 | + |
|
1914 | + $value = gv_map_deep($value, '_wp_specialchars'); |
|
1915 | + |
|
1916 | + return $value; |
|
1917 | + } |
|
1918 | + |
|
1919 | + /** |
|
1920 | + * Require the datepicker script for the frontend GV script. |
|
1921 | + * |
|
1922 | + * @param array $js_dependencies Array of existing required scripts for the fe-views.js script |
|
1923 | + * |
|
1924 | + * @return array Array required scripts, with `jquery-ui-datepicker` added |
|
1925 | + */ |
|
1926 | + public function add_datepicker_js_dependency($js_dependencies) |
|
1927 | + { |
|
1928 | + $js_dependencies[] = 'jquery-ui-datepicker'; |
|
1929 | + |
|
1930 | + return $js_dependencies; |
|
1931 | + } |
|
1932 | + |
|
1933 | + /** |
|
1934 | + * Modify the array passed to wp_localize_script(). |
|
1935 | + * |
|
1936 | + * @param array $js_localization The data padded to the Javascript file |
|
1937 | + * @param array $view_data View data array with View settings |
|
1938 | + * |
|
1939 | + * @return array |
|
1940 | + */ |
|
1941 | + public function add_datepicker_localization($localizations = [], $view_data = []) |
|
1942 | + { |
|
1943 | + global $wp_locale; |
|
1944 | + |
|
1945 | + /** |
|
1946 | + * @filter `gravityview_datepicker_settings` Modify the datepicker settings |
|
1947 | + * |
|
1948 | + * @see http://api.jqueryui.com/datepicker/ Learn what settings are available |
|
1949 | + * @see http://www.renegadetechconsulting.com/tutorials/jquery-datepicker-and-wordpress-i18n Thanks for the helpful information on $wp_locale |
|
1950 | + * |
|
1951 | + * @param array $js_localization The data padded to the Javascript file |
|
1952 | + * @param array $view_data View data array with View settings |
|
1953 | + */ |
|
1954 | + $datepicker_settings = apply_filters('gravityview_datepicker_settings', [ |
|
1955 | + 'yearRange' => '-5:+5', |
|
1956 | + 'changeMonth' => true, |
|
1957 | + 'changeYear' => true, |
|
1958 | + 'closeText' => esc_attr_x('Close', 'Close calendar', 'gravityview'), |
|
1959 | + 'prevText' => esc_attr_x('Prev', 'Previous month in calendar', 'gravityview'), |
|
1960 | + 'nextText' => esc_attr_x('Next', 'Next month in calendar', 'gravityview'), |
|
1961 | + 'currentText' => esc_attr_x('Today', 'Today in calendar', 'gravityview'), |
|
1962 | + 'weekHeader' => esc_attr_x('Week', 'Week in calendar', 'gravityview'), |
|
1963 | + 'monthStatus' => __('Show a different month', 'gravityview'), |
|
1964 | + 'monthNames' => array_values($wp_locale->month), |
|
1965 | + 'monthNamesShort' => array_values($wp_locale->month_abbrev), |
|
1966 | + 'dayNames' => array_values($wp_locale->weekday), |
|
1967 | + 'dayNamesShort' => array_values($wp_locale->weekday_abbrev), |
|
1968 | + 'dayNamesMin' => array_values($wp_locale->weekday_initial), |
|
1969 | + // get the start of week from WP general setting |
|
1970 | + 'firstDay' => get_option('start_of_week'), |
|
1971 | + // is Right to left language? default is false |
|
1972 | + 'isRTL' => is_rtl(), |
|
1973 | + ], $view_data); |
|
1974 | + |
|
1975 | + $localizations['datepicker'] = $datepicker_settings; |
|
1976 | + |
|
1977 | + return $localizations; |
|
1978 | + } |
|
1979 | + |
|
1980 | + /** |
|
1981 | + * Register search widget scripts, including Flexibility. |
|
1982 | + * |
|
1983 | + * @see https://github.com/10up/flexibility |
|
1984 | + * @since 1.17 |
|
1985 | + * |
|
1986 | + * @return void |
|
1987 | + */ |
|
1988 | + public function register_scripts() |
|
1989 | + { |
|
1990 | + wp_register_script('gv-flexibility', plugins_url('assets/lib/flexibility/flexibility.js', GRAVITYVIEW_FILE), [], \GV\Plugin::$version, true); |
|
1991 | + } |
|
1992 | + |
|
1993 | + /** |
|
1994 | + * If the current visitor is running IE 8 or 9, enqueue Flexibility. |
|
1995 | + * |
|
1996 | + * @since 1.17 |
|
1997 | + * |
|
1998 | + * @return void |
|
1999 | + */ |
|
2000 | + private function maybe_enqueue_flexibility() |
|
2001 | + { |
|
2002 | + if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/MSIE [8-9]/', $_SERVER['HTTP_USER_AGENT'])) { |
|
2003 | + wp_enqueue_script('gv-flexibility'); |
|
2004 | + } |
|
2005 | + } |
|
2006 | + |
|
2007 | + /** |
|
2008 | + * Enqueue the datepicker script. |
|
2009 | + * |
|
2010 | + * It sets the $gravityview->datepicker_class parameter |
|
2011 | + * |
|
2012 | + * @todo Use own datepicker javascript instead of GF datepicker.js - that way, we can localize the settings and not require the changeMonth and changeYear pickers. |
|
2013 | + * |
|
2014 | + * @return void |
|
2015 | + */ |
|
2016 | + public function enqueue_datepicker() |
|
2017 | + { |
|
2018 | + $gravityview_view = GravityView_View::getInstance(); |
|
2019 | + |
|
2020 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
2021 | + |
|
2022 | + add_filter('gravityview_js_dependencies', [$this, 'add_datepicker_js_dependency']); |
|
2023 | + add_filter('gravityview_js_localization', [$this, 'add_datepicker_localization'], 10, 2); |
|
2024 | + |
|
2025 | + $scheme = is_ssl() ? 'https://' : 'http://'; |
|
2026 | + wp_enqueue_style('jquery-ui-datepicker', $scheme.'ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css'); |
|
2027 | + |
|
2028 | + /** |
|
2029 | + * @filter `gravityview_search_datepicker_class` |
|
2030 | + * Modify the CSS class for the datepicker, used by the CSS class is used by Gravity Forms' javascript to determine the format for the date picker. The `gv-datepicker` class is required by the GravityView datepicker javascript. |
|
2031 | + * |
|
2032 | + * @param string $css_class CSS class to use. Default: `gv-datepicker datepicker mdy` \n |
|
2033 | + * Options are: |
|
2034 | + * - `mdy` (mm/dd/yyyy) |
|
2035 | + * - `dmy` (dd/mm/yyyy) |
|
2036 | + * - `dmy_dash` (dd-mm-yyyy) |
|
2037 | + * - `dmy_dot` (dd.mm.yyyy) |
|
2038 | + * - `ymd_slash` (yyyy/mm/dd) |
|
2039 | + * - `ymd_dash` (yyyy-mm-dd) |
|
2040 | + * - `ymd_dot` (yyyy.mm.dd) |
|
2041 | + */ |
|
2042 | + $datepicker_class = apply_filters('gravityview_search_datepicker_class', 'gv-datepicker datepicker '.$this->get_datepicker_format()); |
|
2043 | + |
|
2044 | + $gravityview_view->datepicker_class = $datepicker_class; |
|
2045 | + } |
|
2046 | + |
|
2047 | + /** |
|
2048 | + * Retrieve the datepicker format. |
|
2049 | + * |
|
2050 | + * @param bool $date_format Whether to return the PHP date format or the datpicker class name. Default: false. |
|
2051 | + * |
|
2052 | + * @see https://docs.gravityview.co/article/115-changing-the-format-of-the-search-widgets-date-picker |
|
2053 | + * |
|
2054 | + * @return string The datepicker format placeholder, or the PHP date format. |
|
2055 | + */ |
|
2056 | + private function get_datepicker_format($date_format = false) |
|
2057 | + { |
|
2058 | + $default_format = 'mdy'; |
|
2059 | + |
|
2060 | + /** |
|
2061 | + * @filter `gravityview/widgets/search/datepicker/format` |
|
2062 | + * |
|
2063 | + * @since 2.1.1 |
|
2064 | + * |
|
2065 | + * @param string $format Default: mdy |
|
2066 | + * Options are: |
|
2067 | + * - `mdy` (mm/dd/yyyy) |
|
2068 | + * - `dmy` (dd/mm/yyyy) |
|
2069 | + * - `dmy_dash` (dd-mm-yyyy) |
|
2070 | + * - `dmy_dot` (dd.mm.yyyy) |
|
2071 | + * - `ymd_slash` (yyyy/mm/dd) |
|
2072 | + * - `ymd_dash` (yyyy-mm-dd) |
|
2073 | + * - `ymd_dot` (yyyy.mm.dd) |
|
2074 | + */ |
|
2075 | + $format = apply_filters('gravityview/widgets/search/datepicker/format', $default_format); |
|
2076 | + |
|
2077 | + $gf_date_formats = [ |
|
2078 | + 'mdy' => 'm/d/Y', |
|
2079 | + |
|
2080 | + 'dmy_dash' => 'd-m-Y', |
|
2081 | + 'dmy_dot' => 'd.m.Y', |
|
2082 | + 'dmy' => 'd/m/Y', |
|
2083 | + |
|
2084 | + 'ymd_slash' => 'Y/m/d', |
|
2085 | + 'ymd_dash' => 'Y-m-d', |
|
2086 | + 'ymd_dot' => 'Y.m.d', |
|
2087 | + ]; |
|
2088 | + |
|
2089 | + if (!$date_format) { |
|
2090 | + // If the format key isn't valid, return default format key |
|
2091 | + return isset($gf_date_formats[$format]) ? $format : $default_format; |
|
2092 | + } |
|
2093 | + |
|
2094 | + // If the format key isn't valid, return default format value |
|
2095 | + return \GV\Utils::get($gf_date_formats, $format, $gf_date_formats[$default_format]); |
|
2096 | + } |
|
2097 | + |
|
2098 | + /** |
|
2099 | + * If previewing a View or page with embedded Views, make the search work properly by adding hidden fields with query vars. |
|
2100 | + * |
|
2101 | + * @since 2.2.1 |
|
2102 | + * |
|
2103 | + * @return void |
|
2104 | + */ |
|
2105 | + public function add_preview_inputs() |
|
2106 | + { |
|
2107 | + global $wp; |
|
2108 | + |
|
2109 | + if (!is_preview() || !current_user_can('publish_gravityviews')) { |
|
2110 | + return; |
|
2111 | + } |
|
2112 | + |
|
2113 | + // Outputs `preview` and `post_id` variables |
|
2114 | + foreach ($wp->query_vars as $key => $value) { |
|
2115 | + printf('<input type="hidden" name="%s" value="%s" />', esc_attr($key), esc_attr($value)); |
|
2116 | + } |
|
2117 | + } |
|
2118 | + |
|
2119 | + /** |
|
2120 | + * Get an operator URL override. |
|
2121 | + * |
|
2122 | + * @param array $get Where to look for the operator. |
|
2123 | + * @param string $key The filter key to look for. |
|
2124 | + * @param array $allowed The allowed operators (allowlist). |
|
2125 | + * @param string $default The default operator. |
|
2126 | + * |
|
2127 | + * @return string The operator. |
|
2128 | + */ |
|
2129 | + private function get_operator($get, $key, $allowed, $default) |
|
2130 | + { |
|
2131 | + $operator = \GV\Utils::get($get, "$key|op", $default); |
|
2132 | + |
|
2133 | + /** |
|
2134 | + * @depecated 2.14 |
|
2135 | + */ |
|
2136 | + $allowed = apply_filters_deprecated('gravityview/search/operator_whitelist', [$allowed, $key], '2.14', 'gravityview/search/operator_allowlist'); |
|
2137 | + |
|
2138 | + /** |
|
2139 | + * @filter `gravityview/search/operator_allowlist` An array of allowed operators for a field. |
|
2140 | + * |
|
2141 | + * @since 2.14 |
|
2142 | + * |
|
2143 | + * @param string[] An allowlist of operators. |
|
2144 | + * @param string The filter name. |
|
2145 | + */ |
|
2146 | + $allowed = apply_filters('gravityview/search/operator_allowlist', $allowed, $key); |
|
2147 | + |
|
2148 | + if (!in_array($operator, $allowed, true)) { |
|
2149 | + $operator = $default; |
|
2150 | + } |
|
2151 | + |
|
2152 | + return $operator; |
|
2153 | + } |
|
2154 | 2154 | } // end class |
2155 | 2155 | |
2156 | 2156 | new GravityView_Widget_Search(); |
2157 | 2157 | |
2158 | 2158 | if (!gravityview()->plugin->supports(\GV\Plugin::FEATURE_GFQUERY)) { |
2159 | - return; |
|
2159 | + return; |
|
2160 | 2160 | } |
2161 | 2161 | |
2162 | 2162 | /** |
@@ -2164,54 +2164,54 @@ discard block |
||
2164 | 2164 | */ |
2165 | 2165 | class GravityView_Widget_Search_Author_GF_Query_Condition extends \GF_Query_Condition |
2166 | 2166 | { |
2167 | - public function __construct($filter, $view) |
|
2168 | - { |
|
2169 | - $this->value = $filter['value']; |
|
2170 | - $this->view = $view; |
|
2171 | - } |
|
2172 | - |
|
2173 | - public function sql($query) |
|
2174 | - { |
|
2175 | - global $wpdb; |
|
2176 | - |
|
2177 | - $user_meta_fields = [ |
|
2178 | - 'nickname', 'first_name', 'last_name', |
|
2179 | - ]; |
|
2180 | - |
|
2181 | - /** |
|
2182 | - * @filter `gravityview/widgets/search/created_by/user_meta_fields` Filter the user meta fields to search. |
|
2183 | - * |
|
2184 | - * @param array The user meta fields. |
|
2185 | - * @param \GV\View $view The view. |
|
2186 | - */ |
|
2187 | - $user_meta_fields = apply_filters('gravityview/widgets/search/created_by/user_meta_fields', $user_meta_fields, $this->view); |
|
2188 | - |
|
2189 | - $user_fields = [ |
|
2190 | - 'user_nicename', 'user_login', 'display_name', 'user_email', |
|
2191 | - ]; |
|
2192 | - |
|
2193 | - /** |
|
2194 | - * @filter `gravityview/widgets/search/created_by/user_fields` Filter the user fields to search. |
|
2195 | - * |
|
2196 | - * @param array The user fields. |
|
2197 | - * @param \GV\View $view The view. |
|
2198 | - */ |
|
2199 | - $user_fields = apply_filters('gravityview/widgets/search/created_by/user_fields', $user_fields, $this->view); |
|
2200 | - |
|
2201 | - $conditions = []; |
|
2202 | - |
|
2203 | - foreach ($user_fields as $user_field) { |
|
2204 | - $conditions[] = $wpdb->prepare("`u`.`$user_field` LIKE %s", '%'.$wpdb->esc_like($this->value).'%'); |
|
2205 | - } |
|
2206 | - |
|
2207 | - foreach ($user_meta_fields as $meta_field) { |
|
2208 | - $conditions[] = $wpdb->prepare('(`um`.`meta_key` = %s AND `um`.`meta_value` LIKE %s)', $meta_field, '%'.$wpdb->esc_like($this->value).'%'); |
|
2209 | - } |
|
2210 | - |
|
2211 | - $conditions = '('.implode(' OR ', $conditions).')'; |
|
2212 | - |
|
2213 | - $alias = $query->_alias(null); |
|
2214 | - |
|
2215 | - return "(EXISTS (SELECT 1 FROM $wpdb->users u LEFT JOIN $wpdb->usermeta um ON u.ID = um.user_id WHERE (u.ID = `$alias`.`created_by` AND $conditions)))"; |
|
2216 | - } |
|
2167 | + public function __construct($filter, $view) |
|
2168 | + { |
|
2169 | + $this->value = $filter['value']; |
|
2170 | + $this->view = $view; |
|
2171 | + } |
|
2172 | + |
|
2173 | + public function sql($query) |
|
2174 | + { |
|
2175 | + global $wpdb; |
|
2176 | + |
|
2177 | + $user_meta_fields = [ |
|
2178 | + 'nickname', 'first_name', 'last_name', |
|
2179 | + ]; |
|
2180 | + |
|
2181 | + /** |
|
2182 | + * @filter `gravityview/widgets/search/created_by/user_meta_fields` Filter the user meta fields to search. |
|
2183 | + * |
|
2184 | + * @param array The user meta fields. |
|
2185 | + * @param \GV\View $view The view. |
|
2186 | + */ |
|
2187 | + $user_meta_fields = apply_filters('gravityview/widgets/search/created_by/user_meta_fields', $user_meta_fields, $this->view); |
|
2188 | + |
|
2189 | + $user_fields = [ |
|
2190 | + 'user_nicename', 'user_login', 'display_name', 'user_email', |
|
2191 | + ]; |
|
2192 | + |
|
2193 | + /** |
|
2194 | + * @filter `gravityview/widgets/search/created_by/user_fields` Filter the user fields to search. |
|
2195 | + * |
|
2196 | + * @param array The user fields. |
|
2197 | + * @param \GV\View $view The view. |
|
2198 | + */ |
|
2199 | + $user_fields = apply_filters('gravityview/widgets/search/created_by/user_fields', $user_fields, $this->view); |
|
2200 | + |
|
2201 | + $conditions = []; |
|
2202 | + |
|
2203 | + foreach ($user_fields as $user_field) { |
|
2204 | + $conditions[] = $wpdb->prepare("`u`.`$user_field` LIKE %s", '%'.$wpdb->esc_like($this->value).'%'); |
|
2205 | + } |
|
2206 | + |
|
2207 | + foreach ($user_meta_fields as $meta_field) { |
|
2208 | + $conditions[] = $wpdb->prepare('(`um`.`meta_key` = %s AND `um`.`meta_value` LIKE %s)', $meta_field, '%'.$wpdb->esc_like($this->value).'%'); |
|
2209 | + } |
|
2210 | + |
|
2211 | + $conditions = '('.implode(' OR ', $conditions).')'; |
|
2212 | + |
|
2213 | + $alias = $query->_alias(null); |
|
2214 | + |
|
2215 | + return "(EXISTS (SELECT 1 FROM $wpdb->users u LEFT JOIN $wpdb->usermeta um ON u.ID = um.user_id WHERE (u.ID = `$alias`.`created_by` AND $conditions)))"; |
|
2216 | + } |
|
2217 | 2217 | } |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | * |
10 | 10 | * @copyright Copyright 2014, Katz Web Services, Inc. |
11 | 11 | */ |
12 | -if (!defined('WPINC')) { |
|
12 | +if ( ! defined( 'WPINC' ) ) { |
|
13 | 13 | exit; |
14 | 14 | } |
15 | 15 | |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | public static $file; |
21 | 21 | public static $instance; |
22 | 22 | |
23 | - private $search_filters = []; |
|
23 | + private $search_filters = [ ]; |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * whether search method is GET or POST ( default: GET ). |
@@ -34,30 +34,30 @@ discard block |
||
34 | 34 | public function __construct() |
35 | 35 | { |
36 | 36 | $this->widget_id = 'search_bar'; |
37 | - $this->widget_description = esc_html__('Search form for searching entries.', 'gravityview'); |
|
37 | + $this->widget_description = esc_html__( 'Search form for searching entries.', 'gravityview' ); |
|
38 | 38 | $this->widget_subtitle = ''; |
39 | 39 | |
40 | 40 | self::$instance = &$this; |
41 | 41 | |
42 | - self::$file = plugin_dir_path(__FILE__); |
|
42 | + self::$file = plugin_dir_path( __FILE__ ); |
|
43 | 43 | |
44 | - $default_values = ['header' => 0, 'footer' => 0]; |
|
44 | + $default_values = [ 'header' => 0, 'footer' => 0 ]; |
|
45 | 45 | |
46 | 46 | $settings = [ |
47 | 47 | 'search_layout' => [ |
48 | 48 | 'type' => 'radio', |
49 | 49 | 'full_width' => true, |
50 | - 'label' => esc_html__('Search Layout', 'gravityview'), |
|
50 | + 'label' => esc_html__( 'Search Layout', 'gravityview' ), |
|
51 | 51 | 'value' => 'horizontal', |
52 | 52 | 'options' => [ |
53 | - 'horizontal' => esc_html__('Horizontal', 'gravityview'), |
|
54 | - 'vertical' => esc_html__('Vertical', 'gravityview'), |
|
53 | + 'horizontal' => esc_html__( 'Horizontal', 'gravityview' ), |
|
54 | + 'vertical' => esc_html__( 'Vertical', 'gravityview' ), |
|
55 | 55 | ], |
56 | 56 | ], |
57 | 57 | 'search_clear' => [ |
58 | 58 | 'type' => 'checkbox', |
59 | - 'label' => __('Show Clear button', 'gravityview'), |
|
60 | - 'desc' => __('When a search is performed, display a button that removes all search values.', 'gravityview'), |
|
59 | + 'label' => __( 'Show Clear button', 'gravityview' ), |
|
60 | + 'desc' => __( 'When a search is performed, display a button that removes all search values.', 'gravityview' ), |
|
61 | 61 | 'value' => true, |
62 | 62 | ], |
63 | 63 | 'search_fields' => [ |
@@ -69,38 +69,38 @@ discard block |
||
69 | 69 | 'search_mode' => [ |
70 | 70 | 'type' => 'radio', |
71 | 71 | 'full_width' => true, |
72 | - 'label' => esc_html__('Search Mode', 'gravityview'), |
|
73 | - 'desc' => __('Should search results match all search fields, or any?', 'gravityview'), |
|
72 | + 'label' => esc_html__( 'Search Mode', 'gravityview' ), |
|
73 | + 'desc' => __( 'Should search results match all search fields, or any?', 'gravityview' ), |
|
74 | 74 | 'value' => 'any', |
75 | 75 | 'class' => 'hide-if-js', |
76 | 76 | 'options' => [ |
77 | - 'any' => esc_html__('Match Any Fields', 'gravityview'), |
|
78 | - 'all' => esc_html__('Match All Fields', 'gravityview'), |
|
77 | + 'any' => esc_html__( 'Match Any Fields', 'gravityview' ), |
|
78 | + 'all' => esc_html__( 'Match All Fields', 'gravityview' ), |
|
79 | 79 | ], |
80 | 80 | ], |
81 | 81 | ]; |
82 | 82 | |
83 | - if (!$this->is_registered()) { |
|
83 | + if ( ! $this->is_registered() ) { |
|
84 | 84 | // frontend - filter entries |
85 | - add_filter('gravityview_fe_search_criteria', [$this, 'filter_entries'], 10, 3); |
|
85 | + add_filter( 'gravityview_fe_search_criteria', [ $this, 'filter_entries' ], 10, 3 ); |
|
86 | 86 | |
87 | 87 | // frontend - add template path |
88 | - add_filter('gravityview_template_paths', [$this, 'add_template_path']); |
|
88 | + add_filter( 'gravityview_template_paths', [ $this, 'add_template_path' ] ); |
|
89 | 89 | |
90 | 90 | // admin - add scripts - run at 1100 to make sure GravityView_Admin_Views::add_scripts_and_styles() runs first at 999 |
91 | - add_action('admin_enqueue_scripts', [$this, 'add_scripts_and_styles'], 1100); |
|
92 | - add_action('wp_enqueue_scripts', [$this, 'register_scripts']); |
|
93 | - add_filter('gravityview_noconflict_scripts', [$this, 'register_no_conflict']); |
|
91 | + add_action( 'admin_enqueue_scripts', [ $this, 'add_scripts_and_styles' ], 1100 ); |
|
92 | + add_action( 'wp_enqueue_scripts', [ $this, 'register_scripts' ] ); |
|
93 | + add_filter( 'gravityview_noconflict_scripts', [ $this, 'register_no_conflict' ] ); |
|
94 | 94 | |
95 | 95 | // ajax - get the searchable fields |
96 | - add_action('wp_ajax_gv_searchable_fields', ['GravityView_Widget_Search', 'get_searchable_fields']); |
|
96 | + add_action( 'wp_ajax_gv_searchable_fields', [ 'GravityView_Widget_Search', 'get_searchable_fields' ] ); |
|
97 | 97 | |
98 | - add_action('gravityview_search_widget_fields_after', [$this, 'add_preview_inputs']); |
|
98 | + add_action( 'gravityview_search_widget_fields_after', [ $this, 'add_preview_inputs' ] ); |
|
99 | 99 | |
100 | - add_filter('gravityview/api/reserved_query_args', [$this, 'add_reserved_args']); |
|
100 | + add_filter( 'gravityview/api/reserved_query_args', [ $this, 'add_reserved_args' ] ); |
|
101 | 101 | } |
102 | 102 | |
103 | - parent::__construct(esc_html__('Search Bar', 'gravityview'), null, $default_values, $settings); |
|
103 | + parent::__construct( esc_html__( 'Search Bar', 'gravityview' ), null, $default_values, $settings ); |
|
104 | 104 | |
105 | 105 | // calculate the search method (POST / GET) |
106 | 106 | $this->set_search_method(); |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | */ |
112 | 112 | public static function getInstance() |
113 | 113 | { |
114 | - if (empty(self::$instance)) { |
|
114 | + if ( empty( self::$instance ) ) { |
|
115 | 115 | self::$instance = new GravityView_Widget_Search(); |
116 | 116 | } |
117 | 117 | |
@@ -125,21 +125,21 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @return mixed |
127 | 127 | */ |
128 | - public function add_reserved_args($args) |
|
128 | + public function add_reserved_args( $args ) |
|
129 | 129 | { |
130 | - $args[] = 'gv_search'; |
|
131 | - $args[] = 'gv_start'; |
|
132 | - $args[] = 'gv_end'; |
|
133 | - $args[] = 'gv_id'; |
|
134 | - $args[] = 'gv_by'; |
|
135 | - $args[] = 'mode'; |
|
130 | + $args[ ] = 'gv_search'; |
|
131 | + $args[ ] = 'gv_start'; |
|
132 | + $args[ ] = 'gv_end'; |
|
133 | + $args[ ] = 'gv_id'; |
|
134 | + $args[ ] = 'gv_by'; |
|
135 | + $args[ ] = 'mode'; |
|
136 | 136 | |
137 | - $get = (array) $_GET; |
|
137 | + $get = (array)$_GET; |
|
138 | 138 | |
139 | 139 | // If the fields being searched as reserved; not to be considered user-passed variables |
140 | - foreach ($get as $key => $value) { |
|
141 | - if ($key !== $this->convert_request_key_to_filter_key($key)) { |
|
142 | - $args[] = $key; |
|
140 | + foreach ( $get as $key => $value ) { |
|
141 | + if ( $key !== $this->convert_request_key_to_filter_key( $key ) ) { |
|
142 | + $args[ ] = $key; |
|
143 | 143 | } |
144 | 144 | } |
145 | 145 | |
@@ -161,11 +161,11 @@ discard block |
||
161 | 161 | * @param string $search_method Assign an input type according to the form field type. Defaults: `boolean`, `multi`, `select`, `date`, `text` |
162 | 162 | * @param string $field_type Gravity Forms field type (also the `name` parameter of GravityView_Field classes) |
163 | 163 | */ |
164 | - $method = apply_filters('gravityview/search/method', $this->search_method); |
|
164 | + $method = apply_filters( 'gravityview/search/method', $this->search_method ); |
|
165 | 165 | |
166 | - $method = strtolower($method); |
|
166 | + $method = strtolower( $method ); |
|
167 | 167 | |
168 | - $this->search_method = in_array($method, ['get', 'post']) ? $method : 'get'; |
|
168 | + $this->search_method = in_array( $method, [ 'get', 'post' ] ) ? $method : 'get'; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -195,17 +195,17 @@ discard block |
||
195 | 195 | * @see admin-search-widget.js (getSelectInput) |
196 | 196 | */ |
197 | 197 | $input_types = [ |
198 | - 'text' => ['input_text'], |
|
199 | - 'address' => ['input_text'], |
|
200 | - 'number' => ['input_text'], |
|
201 | - 'date' => ['date', 'date_range'], |
|
202 | - 'boolean' => ['single_checkbox'], |
|
203 | - 'select' => ['select', 'radio', 'link'], |
|
204 | - 'multi' => ['select', 'multiselect', 'radio', 'checkbox', 'link'], |
|
198 | + 'text' => [ 'input_text' ], |
|
199 | + 'address' => [ 'input_text' ], |
|
200 | + 'number' => [ 'input_text' ], |
|
201 | + 'date' => [ 'date', 'date_range' ], |
|
202 | + 'boolean' => [ 'single_checkbox' ], |
|
203 | + 'select' => [ 'select', 'radio', 'link' ], |
|
204 | + 'multi' => [ 'select', 'multiselect', 'radio', 'checkbox', 'link' ], |
|
205 | 205 | |
206 | 206 | // hybrids |
207 | - 'created_by' => ['select', 'radio', 'checkbox', 'multiselect', 'link', 'input_text'], |
|
208 | - 'product' => ['select', 'radio', 'link', 'input_text'], |
|
207 | + 'created_by' => [ 'select', 'radio', 'checkbox', 'multiselect', 'link', 'input_text' ], |
|
208 | + 'product' => [ 'select', 'radio', 'link', 'input_text' ], |
|
209 | 209 | ]; |
210 | 210 | |
211 | 211 | /** |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * |
216 | 216 | * @param array $input_types Associative array: key is field `name`, value is array of GravityView input types (note: use `input_text` for `text`) |
217 | 217 | */ |
218 | - $input_types = apply_filters('gravityview/search/input_types', $input_types); |
|
218 | + $input_types = apply_filters( 'gravityview/search/input_types', $input_types ); |
|
219 | 219 | |
220 | 220 | return $input_types; |
221 | 221 | } |
@@ -235,15 +235,15 @@ discard block |
||
235 | 235 | * @see admin-search-widget.js (getSelectInput) |
236 | 236 | */ |
237 | 237 | $input_labels = [ |
238 | - 'input_text' => esc_html__('Text', 'gravityview'), |
|
239 | - 'date' => esc_html__('Date', 'gravityview'), |
|
240 | - 'select' => esc_html__('Select', 'gravityview'), |
|
241 | - 'multiselect' => esc_html__('Select (multiple values)', 'gravityview'), |
|
242 | - 'radio' => esc_html__('Radio', 'gravityview'), |
|
243 | - 'checkbox' => esc_html__('Checkbox', 'gravityview'), |
|
244 | - 'single_checkbox' => esc_html__('Checkbox', 'gravityview'), |
|
245 | - 'link' => esc_html__('Links', 'gravityview'), |
|
246 | - 'date_range' => esc_html__('Date range', 'gravityview'), |
|
238 | + 'input_text' => esc_html__( 'Text', 'gravityview' ), |
|
239 | + 'date' => esc_html__( 'Date', 'gravityview' ), |
|
240 | + 'select' => esc_html__( 'Select', 'gravityview' ), |
|
241 | + 'multiselect' => esc_html__( 'Select (multiple values)', 'gravityview' ), |
|
242 | + 'radio' => esc_html__( 'Radio', 'gravityview' ), |
|
243 | + 'checkbox' => esc_html__( 'Checkbox', 'gravityview' ), |
|
244 | + 'single_checkbox' => esc_html__( 'Checkbox', 'gravityview' ), |
|
245 | + 'link' => esc_html__( 'Links', 'gravityview' ), |
|
246 | + 'date_range' => esc_html__( 'Date range', 'gravityview' ), |
|
247 | 247 | ]; |
248 | 248 | |
249 | 249 | /** |
@@ -251,16 +251,16 @@ discard block |
||
251 | 251 | * |
252 | 252 | * @param array $input_types Associative array: key is input type name, value is label |
253 | 253 | */ |
254 | - $input_labels = apply_filters('gravityview/search/input_labels', $input_labels); |
|
254 | + $input_labels = apply_filters( 'gravityview/search/input_labels', $input_labels ); |
|
255 | 255 | |
256 | 256 | return $input_labels; |
257 | 257 | } |
258 | 258 | |
259 | - public static function get_search_input_label($input_type) |
|
259 | + public static function get_search_input_label( $input_type ) |
|
260 | 260 | { |
261 | 261 | $labels = self::get_search_input_labels(); |
262 | 262 | |
263 | - return \GV\Utils::get($labels, $input_type, false); |
|
263 | + return \GV\Utils::get( $labels, $input_type, false ); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | /** |
@@ -268,31 +268,31 @@ discard block |
||
268 | 268 | * |
269 | 269 | * @param mixed $hook |
270 | 270 | */ |
271 | - public function add_scripts_and_styles($hook) |
|
271 | + public function add_scripts_and_styles( $hook ) |
|
272 | 272 | { |
273 | 273 | global $pagenow; |
274 | 274 | |
275 | 275 | // Don't process any scripts below here if it's not a GravityView page or the widgets screen |
276 | - if (!gravityview()->request->is_admin($hook, 'single') && ('widgets.php' !== $pagenow)) { |
|
276 | + if ( ! gravityview()->request->is_admin( $hook, 'single' ) && ( 'widgets.php' !== $pagenow ) ) { |
|
277 | 277 | return; |
278 | 278 | } |
279 | 279 | |
280 | - $script_min = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min'; |
|
281 | - $script_source = empty($script_min) ? '/source' : ''; |
|
282 | - |
|
283 | - wp_enqueue_script('gravityview_searchwidget_admin', plugins_url('assets/js'.$script_source.'/admin-search-widget'.$script_min.'.js', __FILE__), ['jquery', 'gravityview_views_scripts'], \GV\Plugin::$version); |
|
284 | - |
|
285 | - wp_localize_script('gravityview_searchwidget_admin', 'gvSearchVar', [ |
|
286 | - 'nonce' => wp_create_nonce('gravityview_ajaxsearchwidget'), |
|
287 | - 'label_nofields' => esc_html__('No search fields configured yet.', 'gravityview'), |
|
288 | - 'label_addfield' => esc_html__('Add Search Field', 'gravityview'), |
|
289 | - 'label_label' => esc_html__('Label', 'gravityview'), |
|
290 | - 'label_searchfield' => esc_html__('Search Field', 'gravityview'), |
|
291 | - 'label_inputtype' => esc_html__('Input Type', 'gravityview'), |
|
292 | - 'label_ajaxerror' => esc_html__('There was an error loading searchable fields. Save the View or refresh the page to fix this issue.', 'gravityview'), |
|
293 | - 'input_labels' => json_encode(self::get_search_input_labels()), |
|
294 | - 'input_types' => json_encode(self::get_input_types_by_field_type()), |
|
295 | - ]); |
|
280 | + $script_min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
|
281 | + $script_source = empty( $script_min ) ? '/source' : ''; |
|
282 | + |
|
283 | + wp_enqueue_script( 'gravityview_searchwidget_admin', plugins_url( 'assets/js' . $script_source . '/admin-search-widget' . $script_min . '.js', __FILE__ ), [ 'jquery', 'gravityview_views_scripts' ], \GV\Plugin::$version ); |
|
284 | + |
|
285 | + wp_localize_script( 'gravityview_searchwidget_admin', 'gvSearchVar', [ |
|
286 | + 'nonce' => wp_create_nonce( 'gravityview_ajaxsearchwidget' ), |
|
287 | + 'label_nofields' => esc_html__( 'No search fields configured yet.', 'gravityview' ), |
|
288 | + 'label_addfield' => esc_html__( 'Add Search Field', 'gravityview' ), |
|
289 | + 'label_label' => esc_html__( 'Label', 'gravityview' ), |
|
290 | + 'label_searchfield' => esc_html__( 'Search Field', 'gravityview' ), |
|
291 | + 'label_inputtype' => esc_html__( 'Input Type', 'gravityview' ), |
|
292 | + 'label_ajaxerror' => esc_html__( 'There was an error loading searchable fields. Save the View or refresh the page to fix this issue.', 'gravityview' ), |
|
293 | + 'input_labels' => json_encode( self::get_search_input_labels() ), |
|
294 | + 'input_types' => json_encode( self::get_input_types_by_field_type() ), |
|
295 | + ] ); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
@@ -302,9 +302,9 @@ discard block |
||
302 | 302 | * |
303 | 303 | * @return array Scripts allowed in no-conflict mode, plus the search widget script |
304 | 304 | */ |
305 | - public function register_no_conflict($allowed) |
|
305 | + public function register_no_conflict( $allowed ) |
|
306 | 306 | { |
307 | - $allowed[] = 'gravityview_searchwidget_admin'; |
|
307 | + $allowed[ ] = 'gravityview_searchwidget_admin'; |
|
308 | 308 | |
309 | 309 | return $allowed; |
310 | 310 | } |
@@ -317,25 +317,25 @@ discard block |
||
317 | 317 | */ |
318 | 318 | public static function get_searchable_fields() |
319 | 319 | { |
320 | - if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'gravityview_ajaxsearchwidget')) { |
|
321 | - exit('0'); |
|
320 | + if ( ! isset( $_POST[ 'nonce' ] ) || ! wp_verify_nonce( $_POST[ 'nonce' ], 'gravityview_ajaxsearchwidget' ) ) { |
|
321 | + exit( '0' ); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | $form = ''; |
325 | 325 | |
326 | 326 | // Fetch the form for the current View |
327 | - if (!empty($_POST['view_id'])) { |
|
328 | - $form = gravityview_get_form_id($_POST['view_id']); |
|
329 | - } elseif (!empty($_POST['formid'])) { |
|
330 | - $form = (int) $_POST['formid']; |
|
331 | - } elseif (!empty($_POST['template_id']) && class_exists('GravityView_Ajax')) { |
|
332 | - $form = GravityView_Ajax::pre_get_form_fields($_POST['template_id']); |
|
327 | + if ( ! empty( $_POST[ 'view_id' ] ) ) { |
|
328 | + $form = gravityview_get_form_id( $_POST[ 'view_id' ] ); |
|
329 | + } elseif ( ! empty( $_POST[ 'formid' ] ) ) { |
|
330 | + $form = (int)$_POST[ 'formid' ]; |
|
331 | + } elseif ( ! empty( $_POST[ 'template_id' ] ) && class_exists( 'GravityView_Ajax' ) ) { |
|
332 | + $form = GravityView_Ajax::pre_get_form_fields( $_POST[ 'template_id' ] ); |
|
333 | 333 | } |
334 | 334 | |
335 | 335 | // fetch form id assigned to the view |
336 | - $response = self::render_searchable_fields($form); |
|
336 | + $response = self::render_searchable_fields( $form ); |
|
337 | 337 | |
338 | - exit($response); |
|
338 | + exit( $response ); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | /** |
@@ -346,9 +346,9 @@ discard block |
||
346 | 346 | * |
347 | 347 | * @return string |
348 | 348 | */ |
349 | - public static function render_searchable_fields($form_id = null, $current = '') |
|
349 | + public static function render_searchable_fields( $form_id = null, $current = '' ) |
|
350 | 350 | { |
351 | - if (is_null($form_id)) { |
|
351 | + if ( is_null( $form_id ) ) { |
|
352 | 352 | return ''; |
353 | 353 | } |
354 | 354 | |
@@ -358,40 +358,40 @@ discard block |
||
358 | 358 | |
359 | 359 | $custom_fields = [ |
360 | 360 | 'search_all' => [ |
361 | - 'text' => esc_html__('Search Everything', 'gravityview'), |
|
361 | + 'text' => esc_html__( 'Search Everything', 'gravityview' ), |
|
362 | 362 | 'type' => 'text', |
363 | 363 | ], |
364 | 364 | 'entry_date' => [ |
365 | - 'text' => esc_html__('Entry Date', 'gravityview'), |
|
365 | + 'text' => esc_html__( 'Entry Date', 'gravityview' ), |
|
366 | 366 | 'type' => 'date', |
367 | 367 | ], |
368 | 368 | 'entry_id' => [ |
369 | - 'text' => esc_html__('Entry ID', 'gravityview'), |
|
369 | + 'text' => esc_html__( 'Entry ID', 'gravityview' ), |
|
370 | 370 | 'type' => 'text', |
371 | 371 | ], |
372 | 372 | 'created_by' => [ |
373 | - 'text' => esc_html__('Entry Creator', 'gravityview'), |
|
373 | + 'text' => esc_html__( 'Entry Creator', 'gravityview' ), |
|
374 | 374 | 'type' => 'created_by', |
375 | 375 | ], |
376 | 376 | 'is_starred' => [ |
377 | - 'text' => esc_html__('Is Starred', 'gravityview'), |
|
377 | + 'text' => esc_html__( 'Is Starred', 'gravityview' ), |
|
378 | 378 | 'type' => 'boolean', |
379 | 379 | ], |
380 | 380 | ]; |
381 | 381 | |
382 | - if (gravityview()->plugin->supports(\GV\Plugin::FEATURE_GFQUERY)) { |
|
383 | - $custom_fields['is_approved'] = [ |
|
384 | - 'text' => esc_html__('Approval Status', 'gravityview'), |
|
382 | + if ( gravityview()->plugin->supports( \GV\Plugin::FEATURE_GFQUERY ) ) { |
|
383 | + $custom_fields[ 'is_approved' ] = [ |
|
384 | + 'text' => esc_html__( 'Approval Status', 'gravityview' ), |
|
385 | 385 | 'type' => 'multi', |
386 | 386 | ]; |
387 | 387 | } |
388 | 388 | |
389 | - foreach ($custom_fields as $custom_field_key => $custom_field) { |
|
390 | - $output .= sprintf('<option value="%s" %s data-inputtypes="%s" data-placeholder="%s">%s</option>', $custom_field_key, selected($custom_field_key, $current, false), $custom_field['type'], self::get_field_label(['field' => $custom_field_key]), $custom_field['text']); |
|
389 | + foreach ( $custom_fields as $custom_field_key => $custom_field ) { |
|
390 | + $output .= sprintf( '<option value="%s" %s data-inputtypes="%s" data-placeholder="%s">%s</option>', $custom_field_key, selected( $custom_field_key, $current, false ), $custom_field[ 'type' ], self::get_field_label( [ 'field' => $custom_field_key ] ), $custom_field[ 'text' ] ); |
|
391 | 391 | } |
392 | 392 | |
393 | 393 | // Get fields with sub-inputs and no parent |
394 | - $fields = gravityview_get_form_fields($form_id, true, true); |
|
394 | + $fields = gravityview_get_form_fields( $form_id, true, true ); |
|
395 | 395 | |
396 | 396 | /** |
397 | 397 | * @filter `gravityview/search/searchable_fields` Modify the fields that are displayed as searchable in the Search Bar dropdown\n |
@@ -403,19 +403,19 @@ discard block |
||
403 | 403 | * @param array $fields Array of searchable fields, as fetched by gravityview_get_form_fields() |
404 | 404 | * @param int $form_id |
405 | 405 | */ |
406 | - $fields = apply_filters('gravityview/search/searchable_fields', $fields, $form_id); |
|
406 | + $fields = apply_filters( 'gravityview/search/searchable_fields', $fields, $form_id ); |
|
407 | 407 | |
408 | - if (!empty($fields)) { |
|
409 | - $blocklist_field_types = apply_filters('gravityview_blocklist_field_types', ['fileupload', 'post_image', 'post_id', 'section'], null); |
|
408 | + if ( ! empty( $fields ) ) { |
|
409 | + $blocklist_field_types = apply_filters( 'gravityview_blocklist_field_types', [ 'fileupload', 'post_image', 'post_id', 'section' ], null ); |
|
410 | 410 | |
411 | - foreach ($fields as $id => $field) { |
|
412 | - if (in_array($field['type'], $blocklist_field_types)) { |
|
411 | + foreach ( $fields as $id => $field ) { |
|
412 | + if ( in_array( $field[ 'type' ], $blocklist_field_types ) ) { |
|
413 | 413 | continue; |
414 | 414 | } |
415 | 415 | |
416 | - $types = self::get_search_input_types($id, $field['type']); |
|
416 | + $types = self::get_search_input_types( $id, $field[ 'type' ] ); |
|
417 | 417 | |
418 | - $output .= '<option value="'.$id.'" '.selected($id, $current, false).'data-inputtypes="'.esc_attr($types).'">'.esc_html($field['label']).'</option>'; |
|
418 | + $output .= '<option value="' . $id . '" ' . selected( $id, $current, false ) . 'data-inputtypes="' . esc_attr( $types ) . '">' . esc_html( $field[ 'label' ] ) . '</option>'; |
|
419 | 419 | } |
420 | 420 | } |
421 | 421 | |
@@ -434,21 +434,21 @@ discard block |
||
434 | 434 | * |
435 | 435 | * @return string GV field search input type ('multi', 'boolean', 'select', 'date', 'text') |
436 | 436 | */ |
437 | - public static function get_search_input_types($field_id = '', $field_type = null) |
|
437 | + public static function get_search_input_types( $field_id = '', $field_type = null ) |
|
438 | 438 | { |
439 | 439 | |
440 | 440 | // @todo - This needs to be improved - many fields have . including products and addresses |
441 | - if (false !== strpos((string) $field_id, '.') && in_array($field_type, ['checkbox']) || in_array($field_id, ['is_fulfilled'])) { |
|
441 | + if ( false !== strpos( (string)$field_id, '.' ) && in_array( $field_type, [ 'checkbox' ] ) || in_array( $field_id, [ 'is_fulfilled' ] ) ) { |
|
442 | 442 | $input_type = 'boolean'; // on/off checkbox |
443 | - } elseif (in_array($field_type, ['checkbox', 'post_category', 'multiselect'])) { |
|
443 | + } elseif ( in_array( $field_type, [ 'checkbox', 'post_category', 'multiselect' ] ) ) { |
|
444 | 444 | $input_type = 'multi'; //multiselect |
445 | - } elseif (in_array($field_type, ['select', 'radio'])) { |
|
445 | + } elseif ( in_array( $field_type, [ 'select', 'radio' ] ) ) { |
|
446 | 446 | $input_type = 'select'; |
447 | - } elseif (in_array($field_type, ['date']) || in_array($field_id, ['payment_date'])) { |
|
447 | + } elseif ( in_array( $field_type, [ 'date' ] ) || in_array( $field_id, [ 'payment_date' ] ) ) { |
|
448 | 448 | $input_type = 'date'; |
449 | - } elseif (in_array($field_type, ['number']) || in_array($field_id, ['payment_amount'])) { |
|
449 | + } elseif ( in_array( $field_type, [ 'number' ] ) || in_array( $field_id, [ 'payment_amount' ] ) ) { |
|
450 | 450 | $input_type = 'number'; |
451 | - } elseif (in_array($field_type, ['product'])) { |
|
451 | + } elseif ( in_array( $field_type, [ 'product' ] ) ) { |
|
452 | 452 | $input_type = 'product'; |
453 | 453 | } else { |
454 | 454 | $input_type = 'text'; |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | * @param string $field_type Gravity Forms field type (also the `name` parameter of GravityView_Field classes) |
465 | 465 | * @param string|int|float $field_id ID of the field being processed |
466 | 466 | */ |
467 | - $input_type = apply_filters('gravityview/extension/search/input_type', $input_type, $field_type, $field_id); |
|
467 | + $input_type = apply_filters( 'gravityview/extension/search/input_type', $input_type, $field_type, $field_id ); |
|
468 | 468 | |
469 | 469 | return $input_type; |
470 | 470 | } |
@@ -476,31 +476,31 @@ discard block |
||
476 | 476 | * |
477 | 477 | * @return array Search fields, modified if not using permalinks |
478 | 478 | */ |
479 | - public function add_no_permalink_fields($search_fields, $object, $widget_args = []) |
|
479 | + public function add_no_permalink_fields( $search_fields, $object, $widget_args = [ ] ) |
|
480 | 480 | { |
481 | 481 | /** @global WP_Rewrite $wp_rewrite */ |
482 | 482 | global $wp_rewrite; |
483 | 483 | |
484 | 484 | // Support default permalink structure |
485 | - if (false === $wp_rewrite->using_permalinks()) { |
|
485 | + if ( false === $wp_rewrite->using_permalinks() ) { |
|
486 | 486 | |
487 | 487 | // By default, use current post. |
488 | 488 | $post_id = 0; |
489 | 489 | |
490 | 490 | // We're in the WordPress Widget context, and an overriding post ID has been set. |
491 | - if (!empty($widget_args['post_id'])) { |
|
492 | - $post_id = absint($widget_args['post_id']); |
|
491 | + if ( ! empty( $widget_args[ 'post_id' ] ) ) { |
|
492 | + $post_id = absint( $widget_args[ 'post_id' ] ); |
|
493 | 493 | } |
494 | 494 | // We're in the WordPress Widget context, and the base View ID should be used |
495 | - elseif (!empty($widget_args['view_id'])) { |
|
496 | - $post_id = absint($widget_args['view_id']); |
|
495 | + elseif ( ! empty( $widget_args[ 'view_id' ] ) ) { |
|
496 | + $post_id = absint( $widget_args[ 'view_id' ] ); |
|
497 | 497 | } |
498 | 498 | |
499 | - $args = gravityview_get_permalink_query_args($post_id); |
|
499 | + $args = gravityview_get_permalink_query_args( $post_id ); |
|
500 | 500 | |
501 | 501 | // Add hidden fields to the search form |
502 | - foreach ($args as $key => $value) { |
|
503 | - $search_fields[] = [ |
|
502 | + foreach ( $args as $key => $value ) { |
|
503 | + $search_fields[ ] = [ |
|
504 | 504 | 'name' => $key, |
505 | 505 | 'input' => 'hidden', |
506 | 506 | 'value' => $value, |
@@ -525,43 +525,43 @@ discard block |
||
525 | 525 | * |
526 | 526 | * @return array If no View, returns empty array. Otherwise, returns array of fields configured in widgets and Search Bar for a View |
527 | 527 | */ |
528 | - private function get_view_searchable_fields($view, $with_full_field = false) |
|
528 | + private function get_view_searchable_fields( $view, $with_full_field = false ) |
|
529 | 529 | { |
530 | 530 | |
531 | 531 | /** |
532 | 532 | * Find all search widgets on the view and get the searchable fields settings. |
533 | 533 | */ |
534 | - $searchable_fields = []; |
|
534 | + $searchable_fields = [ ]; |
|
535 | 535 | |
536 | - if (!$view) { |
|
536 | + if ( ! $view ) { |
|
537 | 537 | return $searchable_fields; |
538 | 538 | } |
539 | 539 | |
540 | 540 | /** |
541 | 541 | * Include the sidebar Widgets. |
542 | 542 | */ |
543 | - $widgets = (array) get_option('widget_gravityview_search', []); |
|
544 | - |
|
545 | - foreach ($widgets as $widget) { |
|
546 | - if (!empty($widget['view_id']) && $widget['view_id'] == $view->ID) { |
|
547 | - if ($_fields = json_decode($widget['search_fields'], true)) { |
|
548 | - foreach ($_fields as $field) { |
|
549 | - if (empty($field['form_id'])) { |
|
550 | - $field['form_id'] = $view->form ? $view->form->ID : 0; |
|
543 | + $widgets = (array)get_option( 'widget_gravityview_search', [ ] ); |
|
544 | + |
|
545 | + foreach ( $widgets as $widget ) { |
|
546 | + if ( ! empty( $widget[ 'view_id' ] ) && $widget[ 'view_id' ] == $view->ID ) { |
|
547 | + if ( $_fields = json_decode( $widget[ 'search_fields' ], true ) ) { |
|
548 | + foreach ( $_fields as $field ) { |
|
549 | + if ( empty( $field[ 'form_id' ] ) ) { |
|
550 | + $field[ 'form_id' ] = $view->form ? $view->form->ID : 0; |
|
551 | 551 | } |
552 | - $searchable_fields[] = $with_full_field ? $field : $field['field']; |
|
552 | + $searchable_fields[ ] = $with_full_field ? $field : $field[ 'field' ]; |
|
553 | 553 | } |
554 | 554 | } |
555 | 555 | } |
556 | 556 | } |
557 | 557 | |
558 | - foreach ($view->widgets->by_id($this->get_widget_id())->all() as $widget) { |
|
559 | - if ($_fields = json_decode($widget->configuration->get('search_fields'), true)) { |
|
560 | - foreach ($_fields as $field) { |
|
561 | - if (empty($field['form_id'])) { |
|
562 | - $field['form_id'] = $view->form ? $view->form->ID : 0; |
|
558 | + foreach ( $view->widgets->by_id( $this->get_widget_id() )->all() as $widget ) { |
|
559 | + if ( $_fields = json_decode( $widget->configuration->get( 'search_fields' ), true ) ) { |
|
560 | + foreach ( $_fields as $field ) { |
|
561 | + if ( empty( $field[ 'form_id' ] ) ) { |
|
562 | + $field[ 'form_id' ] = $view->form ? $view->form->ID : 0; |
|
563 | 563 | } |
564 | - $searchable_fields[] = $with_full_field ? $field : $field['field']; |
|
564 | + $searchable_fields[ ] = $with_full_field ? $field : $field[ 'field' ]; |
|
565 | 565 | } |
566 | 566 | } |
567 | 567 | } |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | * @since 2.5.1 |
571 | 571 | * @depecated 2.14 |
572 | 572 | */ |
573 | - $searchable_fields = apply_filters_deprecated('gravityview/search/searchable_fields/whitelist', [$searchable_fields, $view, $with_full_field], '2.14', 'gravityview/search/searchable_fields/allowlist'); |
|
573 | + $searchable_fields = apply_filters_deprecated( 'gravityview/search/searchable_fields/whitelist', [ $searchable_fields, $view, $with_full_field ], '2.14', 'gravityview/search/searchable_fields/allowlist' ); |
|
574 | 574 | |
575 | 575 | /** |
576 | 576 | * @filter `gravityview/search/searchable_fields/allowlist` Modifies the fields able to be searched using the Search Bar |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | * @param \GV\View $view Object of View being searched. |
582 | 582 | * @param bool $with_full_field Does $searchable_fields contain the full field array or just field ID? Default: false (just field ID) |
583 | 583 | */ |
584 | - $searchable_fields = apply_filters('gravityview/search/searchable_fields/allowlist', $searchable_fields, $view, $with_full_field); |
|
584 | + $searchable_fields = apply_filters( 'gravityview/search/searchable_fields/allowlist', $searchable_fields, $view, $with_full_field ); |
|
585 | 585 | |
586 | 586 | return $searchable_fields; |
587 | 587 | } |
@@ -598,43 +598,43 @@ discard block |
||
598 | 598 | * |
599 | 599 | * @return array |
600 | 600 | */ |
601 | - public function filter_entries($search_criteria, $form_id = null, $args = [], $force_search_criteria = false) |
|
601 | + public function filter_entries( $search_criteria, $form_id = null, $args = [ ], $force_search_criteria = false ) |
|
602 | 602 | { |
603 | - if (!$force_search_criteria && gravityview()->plugin->supports(\GV\Plugin::FEATURE_GFQUERY)) { |
|
603 | + if ( ! $force_search_criteria && gravityview()->plugin->supports( \GV\Plugin::FEATURE_GFQUERY ) ) { |
|
604 | 604 | /** |
605 | 605 | * If GF_Query is available, we can construct custom conditions with nested |
606 | 606 | * booleans on the query, giving up the old ways of flat search_criteria field_filters. |
607 | 607 | */ |
608 | - add_action('gravityview/view/query', [$this, 'gf_query_filter'], 10, 3); |
|
608 | + add_action( 'gravityview/view/query', [ $this, 'gf_query_filter' ], 10, 3 ); |
|
609 | 609 | |
610 | 610 | return $search_criteria; // Return the original criteria, GF_Query modification kicks in later |
611 | 611 | } |
612 | 612 | |
613 | - if ('post' === $this->search_method) { |
|
613 | + if ( 'post' === $this->search_method ) { |
|
614 | 614 | $get = $_POST; |
615 | 615 | } else { |
616 | 616 | $get = $_GET; |
617 | 617 | } |
618 | 618 | |
619 | - $view = \GV\View::by_id(\GV\Utils::get($args, 'id')); |
|
619 | + $view = \GV\View::by_id( \GV\Utils::get( $args, 'id' ) ); |
|
620 | 620 | $view_id = $view ? $view->ID : null; |
621 | 621 | $form_id = $view ? $view->form->ID : null; |
622 | 622 | |
623 | - gravityview()->log->debug('Requested $_{method}: ', ['method' => $this->search_method, 'data' => $get]); |
|
623 | + gravityview()->log->debug( 'Requested $_{method}: ', [ 'method' => $this->search_method, 'data' => $get ] ); |
|
624 | 624 | |
625 | - if (empty($get) || !is_array($get)) { |
|
625 | + if ( empty( $get ) || ! is_array( $get ) ) { |
|
626 | 626 | return $search_criteria; |
627 | 627 | } |
628 | 628 | |
629 | - $get = stripslashes_deep($get); |
|
629 | + $get = stripslashes_deep( $get ); |
|
630 | 630 | |
631 | - $get = gv_map_deep($get, 'rawurldecode'); |
|
631 | + $get = gv_map_deep( $get, 'rawurldecode' ); |
|
632 | 632 | |
633 | 633 | // Make sure array key is set up |
634 | - $search_criteria['field_filters'] = \GV\Utils::get($search_criteria, 'field_filters', []); |
|
634 | + $search_criteria[ 'field_filters' ] = \GV\Utils::get( $search_criteria, 'field_filters', [ ] ); |
|
635 | 635 | |
636 | - $searchable_fields = $this->get_view_searchable_fields($view); |
|
637 | - $searchable_field_objects = $this->get_view_searchable_fields($view, true); |
|
636 | + $searchable_fields = $this->get_view_searchable_fields( $view ); |
|
637 | + $searchable_field_objects = $this->get_view_searchable_fields( $view, true ); |
|
638 | 638 | |
639 | 639 | /** |
640 | 640 | * @filter `gravityview/search-all-split-words` Search for each word separately or the whole phrase? |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | * |
644 | 644 | * @param bool $split_words True: split a phrase into words; False: search whole word only [Default: true] |
645 | 645 | */ |
646 | - $split_words = apply_filters('gravityview/search-all-split-words', true); |
|
646 | + $split_words = apply_filters( 'gravityview/search-all-split-words', true ); |
|
647 | 647 | |
648 | 648 | /** |
649 | 649 | * @filter `gravityview/search-trim-input` Remove leading/trailing whitespaces from search value |
@@ -652,26 +652,26 @@ discard block |
||
652 | 652 | * |
653 | 653 | * @param bool $trim_search_value True: remove whitespace; False: keep as is [Default: true] |
654 | 654 | */ |
655 | - $trim_search_value = apply_filters('gravityview/search-trim-input', true); |
|
655 | + $trim_search_value = apply_filters( 'gravityview/search-trim-input', true ); |
|
656 | 656 | |
657 | 657 | // add free search |
658 | - if (isset($get['gv_search']) && '' !== $get['gv_search'] && in_array('search_all', $searchable_fields)) { |
|
659 | - $search_all_value = $trim_search_value ? trim($get['gv_search']) : $get['gv_search']; |
|
658 | + if ( isset( $get[ 'gv_search' ] ) && '' !== $get[ 'gv_search' ] && in_array( 'search_all', $searchable_fields ) ) { |
|
659 | + $search_all_value = $trim_search_value ? trim( $get[ 'gv_search' ] ) : $get[ 'gv_search' ]; |
|
660 | 660 | |
661 | - if ($split_words) { |
|
661 | + if ( $split_words ) { |
|
662 | 662 | // Search for a piece |
663 | - $words = explode(' ', $search_all_value); |
|
663 | + $words = explode( ' ', $search_all_value ); |
|
664 | 664 | |
665 | - $words = array_filter($words); |
|
665 | + $words = array_filter( $words ); |
|
666 | 666 | } else { |
667 | 667 | // Replace multiple spaces with one space |
668 | - $search_all_value = preg_replace('/\s+/ism', ' ', $search_all_value); |
|
668 | + $search_all_value = preg_replace( '/\s+/ism', ' ', $search_all_value ); |
|
669 | 669 | |
670 | - $words = [$search_all_value]; |
|
670 | + $words = [ $search_all_value ]; |
|
671 | 671 | } |
672 | 672 | |
673 | - foreach ($words as $word) { |
|
674 | - $search_criteria['field_filters'][] = [ |
|
673 | + foreach ( $words as $word ) { |
|
674 | + $search_criteria[ 'field_filters' ][ ] = [ |
|
675 | 675 | 'key' => null, // The field ID to search |
676 | 676 | 'value' => $word, // The value to search |
677 | 677 | 'operator' => 'contains', // What to search in. Options: `is` or `contains` |
@@ -680,34 +680,34 @@ discard block |
||
680 | 680 | } |
681 | 681 | |
682 | 682 | // start date & end date |
683 | - if (in_array('entry_date', $searchable_fields)) { |
|
683 | + if ( in_array( 'entry_date', $searchable_fields ) ) { |
|
684 | 684 | /** |
685 | 685 | * Get and normalize the dates according to the input format. |
686 | 686 | */ |
687 | - if ($curr_start = !empty($get['gv_start']) ? $get['gv_start'] : '') { |
|
688 | - if ($curr_start_date = date_create_from_format($this->get_datepicker_format(true), $curr_start)) { |
|
689 | - $curr_start = $curr_start_date->format('Y-m-d'); |
|
687 | + if ( $curr_start = ! empty( $get[ 'gv_start' ] ) ? $get[ 'gv_start' ] : '' ) { |
|
688 | + if ( $curr_start_date = date_create_from_format( $this->get_datepicker_format( true ), $curr_start ) ) { |
|
689 | + $curr_start = $curr_start_date->format( 'Y-m-d' ); |
|
690 | 690 | } |
691 | 691 | } |
692 | 692 | |
693 | - if ($curr_end = !empty($get['gv_start']) ? (!empty($get['gv_end']) ? $get['gv_end'] : '') : '') { |
|
694 | - if ($curr_end_date = date_create_from_format($this->get_datepicker_format(true), $curr_end)) { |
|
695 | - $curr_end = $curr_end_date->format('Y-m-d'); |
|
693 | + if ( $curr_end = ! empty( $get[ 'gv_start' ] ) ? ( ! empty( $get[ 'gv_end' ] ) ? $get[ 'gv_end' ] : '' ) : '' ) { |
|
694 | + if ( $curr_end_date = date_create_from_format( $this->get_datepicker_format( true ), $curr_end ) ) { |
|
695 | + $curr_end = $curr_end_date->format( 'Y-m-d' ); |
|
696 | 696 | } |
697 | 697 | } |
698 | 698 | |
699 | - if ($view) { |
|
699 | + if ( $view ) { |
|
700 | 700 | /** |
701 | 701 | * Override start and end dates if View is limited to some already. |
702 | 702 | */ |
703 | - if ($start_date = $view->settings->get('start_date')) { |
|
704 | - if ($start_timestamp = strtotime($curr_start)) { |
|
705 | - $curr_start = $start_timestamp < strtotime($start_date) ? $start_date : $curr_start; |
|
703 | + if ( $start_date = $view->settings->get( 'start_date' ) ) { |
|
704 | + if ( $start_timestamp = strtotime( $curr_start ) ) { |
|
705 | + $curr_start = $start_timestamp < strtotime( $start_date ) ? $start_date : $curr_start; |
|
706 | 706 | } |
707 | 707 | } |
708 | - if ($end_date = $view->settings->get('end_date')) { |
|
709 | - if ($end_timestamp = strtotime($curr_end)) { |
|
710 | - $curr_end = $end_timestamp > strtotime($end_date) ? $end_date : $curr_end; |
|
708 | + if ( $end_date = $view->settings->get( 'end_date' ) ) { |
|
709 | + if ( $end_timestamp = strtotime( $curr_end ) ) { |
|
710 | + $curr_end = $end_timestamp > strtotime( $end_date ) ? $end_date : $curr_end; |
|
711 | 711 | } |
712 | 712 | } |
713 | 713 | } |
@@ -722,64 +722,64 @@ discard block |
||
722 | 722 | * @param bool $adjust_tz Use timezone-adjusted datetime? If true, adjusts date based on blog's timezone setting. If false, uses UTC setting. Default is `false`. |
723 | 723 | * @param string $context Where the filter is being called from. `search` in this case. |
724 | 724 | */ |
725 | - $adjust_tz = apply_filters('gravityview_date_created_adjust_timezone', false, 'search'); |
|
725 | + $adjust_tz = apply_filters( 'gravityview_date_created_adjust_timezone', false, 'search' ); |
|
726 | 726 | |
727 | 727 | /** |
728 | 728 | * Don't set $search_criteria['start_date'] if start_date is empty as it may lead to bad query results (GFAPI::get_entries). |
729 | 729 | */ |
730 | - if (!empty($curr_start)) { |
|
731 | - $curr_start = date('Y-m-d H:i:s', strtotime($curr_start)); |
|
732 | - $search_criteria['start_date'] = $adjust_tz ? get_gmt_from_date($curr_start) : $curr_start; |
|
730 | + if ( ! empty( $curr_start ) ) { |
|
731 | + $curr_start = date( 'Y-m-d H:i:s', strtotime( $curr_start ) ); |
|
732 | + $search_criteria[ 'start_date' ] = $adjust_tz ? get_gmt_from_date( $curr_start ) : $curr_start; |
|
733 | 733 | } |
734 | 734 | |
735 | - if (!empty($curr_end)) { |
|
735 | + if ( ! empty( $curr_end ) ) { |
|
736 | 736 | // Fast-forward 24 hour on the end time |
737 | - $curr_end = date('Y-m-d H:i:s', strtotime($curr_end) + DAY_IN_SECONDS); |
|
738 | - $search_criteria['end_date'] = $adjust_tz ? get_gmt_from_date($curr_end) : $curr_end; |
|
739 | - if (strpos($search_criteria['end_date'], '00:00:00')) { // See https://github.com/gravityview/GravityView/issues/1056 |
|
740 | - $search_criteria['end_date'] = date('Y-m-d H:i:s', strtotime($search_criteria['end_date']) - 1); |
|
737 | + $curr_end = date( 'Y-m-d H:i:s', strtotime( $curr_end ) + DAY_IN_SECONDS ); |
|
738 | + $search_criteria[ 'end_date' ] = $adjust_tz ? get_gmt_from_date( $curr_end ) : $curr_end; |
|
739 | + if ( strpos( $search_criteria[ 'end_date' ], '00:00:00' ) ) { // See https://github.com/gravityview/GravityView/issues/1056 |
|
740 | + $search_criteria[ 'end_date' ] = date( 'Y-m-d H:i:s', strtotime( $search_criteria[ 'end_date' ] ) - 1 ); |
|
741 | 741 | } |
742 | 742 | } |
743 | 743 | } |
744 | 744 | |
745 | 745 | // search for a specific entry ID |
746 | - if (!empty($get['gv_id']) && in_array('entry_id', $searchable_fields)) { |
|
747 | - $search_criteria['field_filters'][] = [ |
|
746 | + if ( ! empty( $get[ 'gv_id' ] ) && in_array( 'entry_id', $searchable_fields ) ) { |
|
747 | + $search_criteria[ 'field_filters' ][ ] = [ |
|
748 | 748 | 'key' => 'id', |
749 | - 'value' => absint($get['gv_id']), |
|
750 | - 'operator' => $this->get_operator($get, 'gv_id', ['='], '='), |
|
749 | + 'value' => absint( $get[ 'gv_id' ] ), |
|
750 | + 'operator' => $this->get_operator( $get, 'gv_id', [ '=' ], '=' ), |
|
751 | 751 | ]; |
752 | 752 | } |
753 | 753 | |
754 | 754 | // search for a specific Created_by ID |
755 | - if (!empty($get['gv_by']) && in_array('created_by', $searchable_fields)) { |
|
756 | - $search_criteria['field_filters'][] = [ |
|
755 | + if ( ! empty( $get[ 'gv_by' ] ) && in_array( 'created_by', $searchable_fields ) ) { |
|
756 | + $search_criteria[ 'field_filters' ][ ] = [ |
|
757 | 757 | 'key' => 'created_by', |
758 | - 'value' => $get['gv_by'], |
|
759 | - 'operator' => $this->get_operator($get, 'gv_by', ['='], '='), |
|
758 | + 'value' => $get[ 'gv_by' ], |
|
759 | + 'operator' => $this->get_operator( $get, 'gv_by', [ '=' ], '=' ), |
|
760 | 760 | ]; |
761 | 761 | } |
762 | 762 | |
763 | 763 | // Get search mode passed in URL |
764 | - $mode = isset($get['mode']) && in_array($get['mode'], ['any', 'all']) ? $get['mode'] : 'any'; |
|
764 | + $mode = isset( $get[ 'mode' ] ) && in_array( $get[ 'mode' ], [ 'any', 'all' ] ) ? $get[ 'mode' ] : 'any'; |
|
765 | 765 | |
766 | 766 | // get the other search filters |
767 | - foreach ($get as $key => $value) { |
|
768 | - if (0 !== strpos($key, 'filter_') && 0 !== strpos($key, 'input_')) { |
|
767 | + foreach ( $get as $key => $value ) { |
|
768 | + if ( 0 !== strpos( $key, 'filter_' ) && 0 !== strpos( $key, 'input_' ) ) { |
|
769 | 769 | continue; |
770 | 770 | } |
771 | 771 | |
772 | - if (strpos($key, '|op') !== false) { |
|
772 | + if ( strpos( $key, '|op' ) !== false ) { |
|
773 | 773 | continue; // This is an operator |
774 | 774 | } |
775 | 775 | |
776 | - $filter_key = $this->convert_request_key_to_filter_key($key); |
|
776 | + $filter_key = $this->convert_request_key_to_filter_key( $key ); |
|
777 | 777 | |
778 | - if ($trim_search_value) { |
|
779 | - $value = is_array($value) ? array_map('trim', $value) : trim($value); |
|
778 | + if ( $trim_search_value ) { |
|
779 | + $value = is_array( $value ) ? array_map( 'trim', $value ) : trim( $value ); |
|
780 | 780 | } |
781 | 781 | |
782 | - if (gv_empty($value, false, false) || (is_array($value) && count($value) === 1 && gv_empty($value[0], false, false))) { |
|
782 | + if ( gv_empty( $value, false, false ) || ( is_array( $value ) && count( $value ) === 1 && gv_empty( $value[ 0 ], false, false ) ) ) { |
|
783 | 783 | /** |
784 | 784 | * @filter `gravityview/search/ignore-empty-values` Filter to control if empty field values should be ignored or strictly matched (default: true) |
785 | 785 | * |
@@ -790,43 +790,43 @@ discard block |
||
790 | 790 | * @param int|null $view_id |
791 | 791 | * @param int|null $form_id |
792 | 792 | */ |
793 | - $ignore_empty_values = apply_filters('gravityview/search/ignore-empty-values', true, $filter_key, $view_id, $form_id); |
|
793 | + $ignore_empty_values = apply_filters( 'gravityview/search/ignore-empty-values', true, $filter_key, $view_id, $form_id ); |
|
794 | 794 | |
795 | - if (is_array($value) || $ignore_empty_values) { |
|
795 | + if ( is_array( $value ) || $ignore_empty_values ) { |
|
796 | 796 | continue; |
797 | 797 | } |
798 | 798 | |
799 | 799 | $value = ''; |
800 | 800 | } |
801 | 801 | |
802 | - if ($form_id && '' === $value) { |
|
803 | - $field = GFAPI::get_field($form_id, $filter_key); |
|
802 | + if ( $form_id && '' === $value ) { |
|
803 | + $field = GFAPI::get_field( $form_id, $filter_key ); |
|
804 | 804 | |
805 | 805 | // GF_Query casts Number field values to decimal, which may return unexpected result when the value is blank. |
806 | - if ($field && 'number' === $field->type) { |
|
807 | - $value = '-'.PHP_INT_MAX; |
|
806 | + if ( $field && 'number' === $field->type ) { |
|
807 | + $value = '-' . PHP_INT_MAX; |
|
808 | 808 | } |
809 | 809 | } |
810 | 810 | |
811 | - if (!$filter = $this->prepare_field_filter($filter_key, $value, $view, $searchable_field_objects, $get)) { |
|
811 | + if ( ! $filter = $this->prepare_field_filter( $filter_key, $value, $view, $searchable_field_objects, $get ) ) { |
|
812 | 812 | continue; |
813 | 813 | } |
814 | 814 | |
815 | - if (!isset($filter['operator'])) { |
|
816 | - $filter['operator'] = $this->get_operator($get, $key, ['contains'], 'contains'); |
|
815 | + if ( ! isset( $filter[ 'operator' ] ) ) { |
|
816 | + $filter[ 'operator' ] = $this->get_operator( $get, $key, [ 'contains' ], 'contains' ); |
|
817 | 817 | } |
818 | 818 | |
819 | - if (isset($filter[0]['value'])) { |
|
820 | - $filter[0]['value'] = $trim_search_value ? trim($filter[0]['value']) : $filter[0]['value']; |
|
819 | + if ( isset( $filter[ 0 ][ 'value' ] ) ) { |
|
820 | + $filter[ 0 ][ 'value' ] = $trim_search_value ? trim( $filter[ 0 ][ 'value' ] ) : $filter[ 0 ][ 'value' ]; |
|
821 | 821 | |
822 | - $search_criteria['field_filters'] = array_merge($search_criteria['field_filters'], $filter); |
|
822 | + $search_criteria[ 'field_filters' ] = array_merge( $search_criteria[ 'field_filters' ], $filter ); |
|
823 | 823 | |
824 | 824 | // if date range type, set search mode to ALL |
825 | - if (!empty($filter[0]['operator']) && in_array($filter[0]['operator'], ['>=', '<=', '>', '<'])) { |
|
825 | + if ( ! empty( $filter[ 0 ][ 'operator' ] ) && in_array( $filter[ 0 ][ 'operator' ], [ '>=', '<=', '>', '<' ] ) ) { |
|
826 | 826 | $mode = 'all'; |
827 | 827 | } |
828 | - } elseif (!empty($filter)) { |
|
829 | - $search_criteria['field_filters'][] = $filter; |
|
828 | + } elseif ( ! empty( $filter ) ) { |
|
829 | + $search_criteria[ 'field_filters' ][ ] = $filter; |
|
830 | 830 | } |
831 | 831 | } |
832 | 832 | |
@@ -837,11 +837,11 @@ discard block |
||
837 | 837 | * |
838 | 838 | * @param string $mode Search mode (`any` vs `all`) |
839 | 839 | */ |
840 | - $search_criteria['field_filters']['mode'] = apply_filters('gravityview/search/mode', $mode); |
|
840 | + $search_criteria[ 'field_filters' ][ 'mode' ] = apply_filters( 'gravityview/search/mode', $mode ); |
|
841 | 841 | |
842 | - gravityview()->log->debug('Returned Search Criteria: ', ['data' => $search_criteria]); |
|
842 | + gravityview()->log->debug( 'Returned Search Criteria: ', [ 'data' => $search_criteria ] ); |
|
843 | 843 | |
844 | - unset($get); |
|
844 | + unset( $get ); |
|
845 | 845 | |
846 | 846 | return $search_criteria; |
847 | 847 | } |
@@ -855,60 +855,60 @@ discard block |
||
855 | 855 | * @param \GV\View $this The current view object |
856 | 856 | * @param \GV\Request $request The request object |
857 | 857 | */ |
858 | - public function gf_query_filter(&$query, $view, $request) |
|
858 | + public function gf_query_filter( &$query, $view, $request ) |
|
859 | 859 | { |
860 | 860 | /** |
861 | 861 | * This is a shortcut to get all the needed search criteria. |
862 | 862 | * We feed these into an new GF_Query and tack them onto the current object. |
863 | 863 | */ |
864 | - $search_criteria = $this->filter_entries([], null, ['id' => $view->ID], true /** force search_criteria */); |
|
864 | + $search_criteria = $this->filter_entries( [ ], null, [ 'id' => $view->ID ], true /** force search_criteria */ ); |
|
865 | 865 | |
866 | 866 | /** |
867 | 867 | * Call any userland filters that they might have. |
868 | 868 | */ |
869 | - remove_filter('gravityview_fe_search_criteria', [$this, 'filter_entries'], 10, 3); |
|
870 | - $search_criteria = apply_filters('gravityview_fe_search_criteria', $search_criteria, $view->form->ID, $view->settings->as_atts()); |
|
871 | - add_filter('gravityview_fe_search_criteria', [$this, 'filter_entries'], 10, 3); |
|
869 | + remove_filter( 'gravityview_fe_search_criteria', [ $this, 'filter_entries' ], 10, 3 ); |
|
870 | + $search_criteria = apply_filters( 'gravityview_fe_search_criteria', $search_criteria, $view->form->ID, $view->settings->as_atts() ); |
|
871 | + add_filter( 'gravityview_fe_search_criteria', [ $this, 'filter_entries' ], 10, 3 ); |
|
872 | 872 | |
873 | 873 | $query_class = $view->get_query_class(); |
874 | 874 | |
875 | - if (empty($search_criteria['field_filters'])) { |
|
875 | + if ( empty( $search_criteria[ 'field_filters' ] ) ) { |
|
876 | 876 | return; |
877 | 877 | } |
878 | 878 | |
879 | - $widgets = $view->widgets->by_id($this->widget_id); |
|
880 | - if ($widgets->count()) { |
|
879 | + $widgets = $view->widgets->by_id( $this->widget_id ); |
|
880 | + if ( $widgets->count() ) { |
|
881 | 881 | $widgets = $widgets->all(); |
882 | - $widget = $widgets[0]; |
|
882 | + $widget = $widgets[ 0 ]; |
|
883 | 883 | |
884 | - $search_fields = json_decode($widget->configuration->get('search_fields'), true); |
|
884 | + $search_fields = json_decode( $widget->configuration->get( 'search_fields' ), true ); |
|
885 | 885 | |
886 | - foreach ((array) $search_fields as $search_field) { |
|
887 | - if ('created_by' === $search_field['field'] && 'input_text' === $search_field['input']) { |
|
886 | + foreach ( (array)$search_fields as $search_field ) { |
|
887 | + if ( 'created_by' === $search_field[ 'field' ] && 'input_text' === $search_field[ 'input' ] ) { |
|
888 | 888 | $created_by_text_mode = true; |
889 | 889 | } |
890 | 890 | } |
891 | 891 | } |
892 | 892 | |
893 | - $extra_conditions = []; |
|
893 | + $extra_conditions = [ ]; |
|
894 | 894 | $mode = 'any'; |
895 | 895 | |
896 | - foreach ($search_criteria['field_filters'] as $key => &$filter) { |
|
897 | - if (!is_array($filter)) { |
|
898 | - if (in_array(strtolower($filter), ['any', 'all'])) { |
|
896 | + foreach ( $search_criteria[ 'field_filters' ] as $key => &$filter ) { |
|
897 | + if ( ! is_array( $filter ) ) { |
|
898 | + if ( in_array( strtolower( $filter ), [ 'any', 'all' ] ) ) { |
|
899 | 899 | $mode = $filter; |
900 | 900 | } |
901 | 901 | continue; |
902 | 902 | } |
903 | 903 | |
904 | 904 | // Construct a manual query for unapproved statuses |
905 | - if ('is_approved' === $filter['key'] && in_array(\GravityView_Entry_Approval_Status::UNAPPROVED, (array) $filter['value'])) { |
|
906 | - $_tmp_query = new $query_class($view->form->ID, [ |
|
905 | + if ( 'is_approved' === $filter[ 'key' ] && in_array( \GravityView_Entry_Approval_Status::UNAPPROVED, (array)$filter[ 'value' ] ) ) { |
|
906 | + $_tmp_query = new $query_class( $view->form->ID, [ |
|
907 | 907 | 'field_filters' => [ |
908 | 908 | [ |
909 | 909 | 'operator' => 'in', |
910 | 910 | 'key' => 'is_approved', |
911 | - 'value' => (array) $filter['value'], |
|
911 | + 'value' => (array)$filter[ 'value' ], |
|
912 | 912 | ], |
913 | 913 | [ |
914 | 914 | 'operator' => 'is', |
@@ -917,33 +917,33 @@ discard block |
||
917 | 917 | ], |
918 | 918 | 'mode' => 'any', |
919 | 919 | ], |
920 | - ]); |
|
920 | + ] ); |
|
921 | 921 | $_tmp_query_parts = $_tmp_query->_introspect(); |
922 | 922 | |
923 | - $extra_conditions[] = $_tmp_query_parts['where']; |
|
923 | + $extra_conditions[ ] = $_tmp_query_parts[ 'where' ]; |
|
924 | 924 | |
925 | 925 | $filter = false; |
926 | 926 | continue; |
927 | 927 | } |
928 | 928 | |
929 | 929 | // Construct manual query for text mode creator search |
930 | - if ('created_by' === $filter['key'] && !empty($created_by_text_mode)) { |
|
931 | - $extra_conditions[] = new GravityView_Widget_Search_Author_GF_Query_Condition($filter, $view); |
|
930 | + if ( 'created_by' === $filter[ 'key' ] && ! empty( $created_by_text_mode ) ) { |
|
931 | + $extra_conditions[ ] = new GravityView_Widget_Search_Author_GF_Query_Condition( $filter, $view ); |
|
932 | 932 | $filter = false; |
933 | 933 | continue; |
934 | 934 | } |
935 | 935 | |
936 | 936 | // By default, we want searches to be wildcard for each field. |
937 | - $filter['operator'] = empty($filter['operator']) ? 'contains' : $filter['operator']; |
|
937 | + $filter[ 'operator' ] = empty( $filter[ 'operator' ] ) ? 'contains' : $filter[ 'operator' ]; |
|
938 | 938 | |
939 | 939 | // For multichoice, let's have an in (OR) search. |
940 | - if (is_array($filter['value'])) { |
|
941 | - $filter['operator'] = 'in'; // @todo what about in contains (OR LIKE chains)? |
|
940 | + if ( is_array( $filter[ 'value' ] ) ) { |
|
941 | + $filter[ 'operator' ] = 'in'; // @todo what about in contains (OR LIKE chains)? |
|
942 | 942 | } |
943 | 943 | |
944 | 944 | // Default form with joins functionality |
945 | - if (empty($filter['form_id'])) { |
|
946 | - $filter['form_id'] = $view->form ? $view->form->ID : 0; |
|
945 | + if ( empty( $filter[ 'form_id' ] ) ) { |
|
946 | + $filter[ 'form_id' ] = $view->form ? $view->form->ID : 0; |
|
947 | 947 | } |
948 | 948 | |
949 | 949 | /** |
@@ -955,34 +955,34 @@ discard block |
||
955 | 955 | * @param array $filter array with `key`, `value`, `operator`, `type` keys |
956 | 956 | * @param \GV\View $view The View we're operating on. |
957 | 957 | */ |
958 | - $filter['operator'] = apply_filters('gravityview_search_operator', $filter['operator'], $filter, $view); |
|
958 | + $filter[ 'operator' ] = apply_filters( 'gravityview_search_operator', $filter[ 'operator' ], $filter, $view ); |
|
959 | 959 | |
960 | - if ('is' !== $filter['operator'] && '' === $filter['value']) { |
|
961 | - unset($search_criteria['field_filters'][$key]); |
|
960 | + if ( 'is' !== $filter[ 'operator' ] && '' === $filter[ 'value' ] ) { |
|
961 | + unset( $search_criteria[ 'field_filters' ][ $key ] ); |
|
962 | 962 | } |
963 | 963 | } |
964 | 964 | |
965 | - if (!empty($search_criteria['start_date']) || !empty($search_criteria['end_date'])) { |
|
966 | - $date_criteria = []; |
|
965 | + if ( ! empty( $search_criteria[ 'start_date' ] ) || ! empty( $search_criteria[ 'end_date' ] ) ) { |
|
966 | + $date_criteria = [ ]; |
|
967 | 967 | |
968 | - if (isset($search_criteria['start_date'])) { |
|
969 | - $date_criteria['start_date'] = $search_criteria['start_date']; |
|
968 | + if ( isset( $search_criteria[ 'start_date' ] ) ) { |
|
969 | + $date_criteria[ 'start_date' ] = $search_criteria[ 'start_date' ]; |
|
970 | 970 | } |
971 | 971 | |
972 | - if (isset($search_criteria['end_date'])) { |
|
973 | - $date_criteria['end_date'] = $search_criteria['end_date']; |
|
972 | + if ( isset( $search_criteria[ 'end_date' ] ) ) { |
|
973 | + $date_criteria[ 'end_date' ] = $search_criteria[ 'end_date' ]; |
|
974 | 974 | } |
975 | 975 | |
976 | - $_tmp_query = new $query_class($view->form->ID, $date_criteria); |
|
976 | + $_tmp_query = new $query_class( $view->form->ID, $date_criteria ); |
|
977 | 977 | $_tmp_query_parts = $_tmp_query->_introspect(); |
978 | - $extra_conditions[] = $_tmp_query_parts['where']; |
|
978 | + $extra_conditions[ ] = $_tmp_query_parts[ 'where' ]; |
|
979 | 979 | } |
980 | 980 | |
981 | - $search_conditions = []; |
|
981 | + $search_conditions = [ ]; |
|
982 | 982 | |
983 | - if ($filters = array_filter($search_criteria['field_filters'])) { |
|
984 | - foreach ($filters as &$filter) { |
|
985 | - if (!is_array($filter)) { |
|
983 | + if ( $filters = array_filter( $search_criteria[ 'field_filters' ] ) ) { |
|
984 | + foreach ( $filters as &$filter ) { |
|
985 | + if ( ! is_array( $filter ) ) { |
|
986 | 986 | continue; |
987 | 987 | } |
988 | 988 | |
@@ -992,58 +992,58 @@ discard block |
||
992 | 992 | * code by reusing what's inside GF_Query already as they |
993 | 993 | * take care of many small things like forcing numeric, etc. |
994 | 994 | */ |
995 | - $_tmp_query = new $query_class($filter['form_id'], ['mode' => 'any', 'field_filters' => [$filter]]); |
|
995 | + $_tmp_query = new $query_class( $filter[ 'form_id' ], [ 'mode' => 'any', 'field_filters' => [ $filter ] ] ); |
|
996 | 996 | $_tmp_query_parts = $_tmp_query->_introspect(); |
997 | - $search_condition = $_tmp_query_parts['where']; |
|
997 | + $search_condition = $_tmp_query_parts[ 'where' ]; |
|
998 | 998 | |
999 | - if (empty($filter['key']) && $search_condition->expressions) { |
|
1000 | - $search_conditions[] = $search_condition; |
|
999 | + if ( empty( $filter[ 'key' ] ) && $search_condition->expressions ) { |
|
1000 | + $search_conditions[ ] = $search_condition; |
|
1001 | 1001 | } else { |
1002 | 1002 | $left = $search_condition->left; |
1003 | 1003 | |
1004 | 1004 | // When casting a column value to a certain type (e.g., happens with the Number field), GF_Query_Column is wrapped in a GF_Query_Call class. |
1005 | - if ($left instanceof GF_Query_Call) { |
|
1005 | + if ( $left instanceof GF_Query_Call ) { |
|
1006 | 1006 | try { |
1007 | - $reflectionProperty = new \ReflectionProperty($left, '_parameters'); |
|
1008 | - $reflectionProperty->setAccessible(true); |
|
1007 | + $reflectionProperty = new \ReflectionProperty( $left, '_parameters' ); |
|
1008 | + $reflectionProperty->setAccessible( true ); |
|
1009 | 1009 | |
1010 | - $value = $reflectionProperty->getValue($left); |
|
1010 | + $value = $reflectionProperty->getValue( $left ); |
|
1011 | 1011 | |
1012 | - if (!empty($value[0]) && $value[0] instanceof GF_Query_Column) { |
|
1013 | - $left = $value[0]; |
|
1012 | + if ( ! empty( $value[ 0 ] ) && $value[ 0 ] instanceof GF_Query_Column ) { |
|
1013 | + $left = $value[ 0 ]; |
|
1014 | 1014 | } else { |
1015 | 1015 | continue; |
1016 | 1016 | } |
1017 | - } catch (ReflectionException $e) { |
|
1017 | + } catch ( ReflectionException $e ) { |
|
1018 | 1018 | continue; |
1019 | 1019 | } |
1020 | 1020 | } |
1021 | 1021 | |
1022 | - $alias = $query->_alias($left->field_id, $left->source, $left->is_entry_column() ? 't' : 'm'); |
|
1022 | + $alias = $query->_alias( $left->field_id, $left->source, $left->is_entry_column() ? 't' : 'm' ); |
|
1023 | 1023 | |
1024 | - if ($view->joins && $left->field_id == GF_Query_Column::META) { |
|
1025 | - foreach ($view->joins as $_join) { |
|
1024 | + if ( $view->joins && $left->field_id == GF_Query_Column::META ) { |
|
1025 | + foreach ( $view->joins as $_join ) { |
|
1026 | 1026 | $on = $_join->join_on; |
1027 | 1027 | $join = $_join->join; |
1028 | 1028 | |
1029 | - $search_conditions[] = GF_Query_Condition::_or( |
|
1029 | + $search_conditions[ ] = GF_Query_Condition::_or( |
|
1030 | 1030 | // Join |
1031 | 1031 | new GF_Query_Condition( |
1032 | - new GF_Query_Column(GF_Query_Column::META, $join->ID, $query->_alias(GF_Query_Column::META, $join->ID, 'm')), |
|
1032 | + new GF_Query_Column( GF_Query_Column::META, $join->ID, $query->_alias( GF_Query_Column::META, $join->ID, 'm' ) ), |
|
1033 | 1033 | $search_condition->operator, |
1034 | 1034 | $search_condition->right |
1035 | 1035 | ), |
1036 | 1036 | // On |
1037 | 1037 | new GF_Query_Condition( |
1038 | - new GF_Query_Column(GF_Query_Column::META, $on->ID, $query->_alias(GF_Query_Column::META, $on->ID, 'm')), |
|
1038 | + new GF_Query_Column( GF_Query_Column::META, $on->ID, $query->_alias( GF_Query_Column::META, $on->ID, 'm' ) ), |
|
1039 | 1039 | $search_condition->operator, |
1040 | 1040 | $search_condition->right |
1041 | 1041 | ) |
1042 | 1042 | ); |
1043 | 1043 | } |
1044 | 1044 | } else { |
1045 | - $search_conditions[] = new GF_Query_Condition( |
|
1046 | - new GF_Query_Column($left->field_id, $left->source, $alias), |
|
1045 | + $search_conditions[ ] = new GF_Query_Condition( |
|
1046 | + new GF_Query_Column( $left->field_id, $left->source, $alias ), |
|
1047 | 1047 | $search_condition->operator, |
1048 | 1048 | $search_condition->right |
1049 | 1049 | ); |
@@ -1051,8 +1051,8 @@ discard block |
||
1051 | 1051 | } |
1052 | 1052 | } |
1053 | 1053 | |
1054 | - if ($search_conditions) { |
|
1055 | - $search_conditions = [call_user_func_array('\GF_Query_Condition::'.($mode == 'all' ? '_and' : '_or'), $search_conditions)]; |
|
1054 | + if ( $search_conditions ) { |
|
1055 | + $search_conditions = [ call_user_func_array( '\GF_Query_Condition::' . ( $mode == 'all' ? '_and' : '_or' ), $search_conditions ) ]; |
|
1056 | 1056 | } |
1057 | 1057 | } |
1058 | 1058 | |
@@ -1064,8 +1064,8 @@ discard block |
||
1064 | 1064 | /** |
1065 | 1065 | * Combine the parts as a new WHERE clause. |
1066 | 1066 | */ |
1067 | - $where = call_user_func_array('\GF_Query_Condition::_and', array_merge([$query_parts['where']], $search_conditions, $extra_conditions)); |
|
1068 | - $query->where($where); |
|
1067 | + $where = call_user_func_array( '\GF_Query_Condition::_and', array_merge( [ $query_parts[ 'where' ] ], $search_conditions, $extra_conditions ) ); |
|
1068 | + $query->where( $where ); |
|
1069 | 1069 | } |
1070 | 1070 | |
1071 | 1071 | /** |
@@ -1082,13 +1082,13 @@ discard block |
||
1082 | 1082 | * |
1083 | 1083 | * @return string |
1084 | 1084 | */ |
1085 | - private function convert_request_key_to_filter_key($key) |
|
1085 | + private function convert_request_key_to_filter_key( $key ) |
|
1086 | 1086 | { |
1087 | - $field_id = str_replace(['filter_', 'input_'], '', $key); |
|
1087 | + $field_id = str_replace( [ 'filter_', 'input_' ], '', $key ); |
|
1088 | 1088 | |
1089 | 1089 | // calculates field_id, removing 'filter_' and for '_' for advanced fields ( like name or checkbox ) |
1090 | - if (preg_match('/^[0-9_]+$/ism', $field_id)) { |
|
1091 | - $field_id = str_replace('_', '.', $field_id); |
|
1090 | + if ( preg_match( '/^[0-9_]+$/ism', $field_id ) ) { |
|
1091 | + $field_id = str_replace( '_', '.', $field_id ); |
|
1092 | 1092 | } |
1093 | 1093 | |
1094 | 1094 | return $field_id; |
@@ -1113,65 +1113,65 @@ discard block |
||
1113 | 1113 | * |
1114 | 1114 | * @return array|false 1 or 2 deph levels, false if not allowed |
1115 | 1115 | */ |
1116 | - public function prepare_field_filter($filter_key, $value, $view, $searchable_fields, $get = []) |
|
1116 | + public function prepare_field_filter( $filter_key, $value, $view, $searchable_fields, $get = [ ] ) |
|
1117 | 1117 | { |
1118 | 1118 | $key = $filter_key; |
1119 | - $filter_key = explode(':', $filter_key); // field_id, form_id |
|
1119 | + $filter_key = explode( ':', $filter_key ); // field_id, form_id |
|
1120 | 1120 | |
1121 | 1121 | $form = null; |
1122 | 1122 | |
1123 | - if (count($filter_key) > 1) { |
|
1123 | + if ( count( $filter_key ) > 1 ) { |
|
1124 | 1124 | // form is specified |
1125 | - list($field_id, $form_id) = $filter_key; |
|
1125 | + list( $field_id, $form_id ) = $filter_key; |
|
1126 | 1126 | |
1127 | - if ($forms = \GV\View::get_joined_forms($view->ID)) { |
|
1128 | - if (!$form = \GV\GF_Form::by_id($form_id)) { |
|
1127 | + if ( $forms = \GV\View::get_joined_forms( $view->ID ) ) { |
|
1128 | + if ( ! $form = \GV\GF_Form::by_id( $form_id ) ) { |
|
1129 | 1129 | return false; |
1130 | 1130 | } |
1131 | 1131 | } |
1132 | 1132 | |
1133 | 1133 | // form is allowed |
1134 | 1134 | $found = false; |
1135 | - foreach ($forms as $form) { |
|
1136 | - if ($form->ID == $form_id) { |
|
1135 | + foreach ( $forms as $form ) { |
|
1136 | + if ( $form->ID == $form_id ) { |
|
1137 | 1137 | $found = true; |
1138 | 1138 | break; |
1139 | 1139 | } |
1140 | 1140 | } |
1141 | 1141 | |
1142 | - if (!$found) { |
|
1142 | + if ( ! $found ) { |
|
1143 | 1143 | return false; |
1144 | 1144 | } |
1145 | 1145 | |
1146 | 1146 | // form is in searchable fields |
1147 | 1147 | $found = false; |
1148 | - foreach ($searchable_fields as $field) { |
|
1149 | - if ($field_id == $field['field'] && $form->ID == $field['form_id']) { |
|
1148 | + foreach ( $searchable_fields as $field ) { |
|
1149 | + if ( $field_id == $field[ 'field' ] && $form->ID == $field[ 'form_id' ] ) { |
|
1150 | 1150 | $found = true; |
1151 | 1151 | break; |
1152 | 1152 | } |
1153 | 1153 | } |
1154 | 1154 | |
1155 | - if (!$found) { |
|
1155 | + if ( ! $found ) { |
|
1156 | 1156 | return false; |
1157 | 1157 | } |
1158 | 1158 | } else { |
1159 | - $field_id = reset($filter_key); |
|
1160 | - $searchable_fields = wp_list_pluck($searchable_fields, 'field'); |
|
1161 | - if (!in_array('search_all', $searchable_fields) && !in_array($field_id, $searchable_fields)) { |
|
1159 | + $field_id = reset( $filter_key ); |
|
1160 | + $searchable_fields = wp_list_pluck( $searchable_fields, 'field' ); |
|
1161 | + if ( ! in_array( 'search_all', $searchable_fields ) && ! in_array( $field_id, $searchable_fields ) ) { |
|
1162 | 1162 | return false; |
1163 | 1163 | } |
1164 | 1164 | } |
1165 | 1165 | |
1166 | - if (!$form) { |
|
1166 | + if ( ! $form ) { |
|
1167 | 1167 | // fallback |
1168 | 1168 | $form = $view->form; |
1169 | 1169 | } |
1170 | 1170 | |
1171 | 1171 | // get form field array |
1172 | - $form_field = is_numeric($field_id) ? \GV\GF_Field::by_id($form, $field_id) : \GV\Internal_Field::by_id($field_id); |
|
1172 | + $form_field = is_numeric( $field_id ) ? \GV\GF_Field::by_id( $form, $field_id ) : \GV\Internal_Field::by_id( $field_id ); |
|
1173 | 1173 | |
1174 | - if (!$form_field) { |
|
1174 | + if ( ! $form_field ) { |
|
1175 | 1175 | return false; |
1176 | 1176 | } |
1177 | 1177 | |
@@ -1182,28 +1182,28 @@ discard block |
||
1182 | 1182 | 'form_id' => $form->ID, |
1183 | 1183 | ]; |
1184 | 1184 | |
1185 | - switch ($form_field->type) { |
|
1185 | + switch ( $form_field->type ) { |
|
1186 | 1186 | |
1187 | 1187 | case 'select': |
1188 | 1188 | case 'radio': |
1189 | - $filter['operator'] = $this->get_operator($get, $key, ['is'], 'is'); |
|
1189 | + $filter[ 'operator' ] = $this->get_operator( $get, $key, [ 'is' ], 'is' ); |
|
1190 | 1190 | break; |
1191 | 1191 | |
1192 | 1192 | case 'post_category': |
1193 | 1193 | |
1194 | - if (!is_array($value)) { |
|
1195 | - $value = [$value]; |
|
1194 | + if ( ! is_array( $value ) ) { |
|
1195 | + $value = [ $value ]; |
|
1196 | 1196 | } |
1197 | 1197 | |
1198 | 1198 | // Reset filter variable |
1199 | - $filter = []; |
|
1199 | + $filter = [ ]; |
|
1200 | 1200 | |
1201 | - foreach ($value as $val) { |
|
1202 | - $cat = get_term($val, 'category'); |
|
1203 | - $filter[] = [ |
|
1201 | + foreach ( $value as $val ) { |
|
1202 | + $cat = get_term( $val, 'category' ); |
|
1203 | + $filter[ ] = [ |
|
1204 | 1204 | 'key' => $field_id, |
1205 | - 'value' => esc_attr($cat->name).':'.$val, |
|
1206 | - 'operator' => $this->get_operator($get, $key, ['is'], 'is'), |
|
1205 | + 'value' => esc_attr( $cat->name ) . ':' . $val, |
|
1206 | + 'operator' => $this->get_operator( $get, $key, [ 'is' ], 'is' ), |
|
1207 | 1207 | ]; |
1208 | 1208 | } |
1209 | 1209 | |
@@ -1211,39 +1211,39 @@ discard block |
||
1211 | 1211 | |
1212 | 1212 | case 'multiselect': |
1213 | 1213 | |
1214 | - if (!is_array($value)) { |
|
1214 | + if ( ! is_array( $value ) ) { |
|
1215 | 1215 | break; |
1216 | 1216 | } |
1217 | 1217 | |
1218 | 1218 | // Reset filter variable |
1219 | - $filter = []; |
|
1219 | + $filter = [ ]; |
|
1220 | 1220 | |
1221 | - foreach ($value as $val) { |
|
1222 | - $filter[] = ['key' => $field_id, 'value' => $val]; |
|
1221 | + foreach ( $value as $val ) { |
|
1222 | + $filter[ ] = [ 'key' => $field_id, 'value' => $val ]; |
|
1223 | 1223 | } |
1224 | 1224 | |
1225 | 1225 | break; |
1226 | 1226 | |
1227 | 1227 | case 'checkbox': |
1228 | 1228 | // convert checkbox on/off into the correct search filter |
1229 | - if (false !== strpos($field_id, '.') && !empty($form_field->inputs) && !empty($form_field->choices)) { |
|
1230 | - foreach ($form_field->inputs as $k => $input) { |
|
1231 | - if ($input['id'] == $field_id) { |
|
1232 | - $filter['value'] = $form_field->choices[$k]['value']; |
|
1233 | - $filter['operator'] = $this->get_operator($get, $key, ['is'], 'is'); |
|
1229 | + if ( false !== strpos( $field_id, '.' ) && ! empty( $form_field->inputs ) && ! empty( $form_field->choices ) ) { |
|
1230 | + foreach ( $form_field->inputs as $k => $input ) { |
|
1231 | + if ( $input[ 'id' ] == $field_id ) { |
|
1232 | + $filter[ 'value' ] = $form_field->choices[ $k ][ 'value' ]; |
|
1233 | + $filter[ 'operator' ] = $this->get_operator( $get, $key, [ 'is' ], 'is' ); |
|
1234 | 1234 | break; |
1235 | 1235 | } |
1236 | 1236 | } |
1237 | - } elseif (is_array($value)) { |
|
1237 | + } elseif ( is_array( $value ) ) { |
|
1238 | 1238 | |
1239 | 1239 | // Reset filter variable |
1240 | - $filter = []; |
|
1240 | + $filter = [ ]; |
|
1241 | 1241 | |
1242 | - foreach ($value as $val) { |
|
1243 | - $filter[] = [ |
|
1242 | + foreach ( $value as $val ) { |
|
1243 | + $filter[ ] = [ |
|
1244 | 1244 | 'key' => $field_id, |
1245 | 1245 | 'value' => $val, |
1246 | - 'operator' => $this->get_operator($get, $key, ['is'], 'is'), |
|
1246 | + 'operator' => $this->get_operator( $get, $key, [ 'is' ], 'is' ), |
|
1247 | 1247 | ]; |
1248 | 1248 | } |
1249 | 1249 | } |
@@ -1253,16 +1253,16 @@ discard block |
||
1253 | 1253 | case 'name': |
1254 | 1254 | case 'address': |
1255 | 1255 | |
1256 | - if (false === strpos($field_id, '.')) { |
|
1257 | - $words = explode(' ', $value); |
|
1256 | + if ( false === strpos( $field_id, '.' ) ) { |
|
1257 | + $words = explode( ' ', $value ); |
|
1258 | 1258 | |
1259 | - $filters = []; |
|
1260 | - foreach ($words as $word) { |
|
1261 | - if (!empty($word) && strlen($word) > 1) { |
|
1259 | + $filters = [ ]; |
|
1260 | + foreach ( $words as $word ) { |
|
1261 | + if ( ! empty( $word ) && strlen( $word ) > 1 ) { |
|
1262 | 1262 | // Keep the same key for each filter |
1263 | - $filter['value'] = $word; |
|
1263 | + $filter[ 'value' ] = $word; |
|
1264 | 1264 | // Add a search for the value |
1265 | - $filters[] = $filter; |
|
1265 | + $filters[ ] = $filter; |
|
1266 | 1266 | } |
1267 | 1267 | } |
1268 | 1268 | |
@@ -1270,23 +1270,23 @@ discard block |
||
1270 | 1270 | } |
1271 | 1271 | |
1272 | 1272 | // State/Province should be exact matches |
1273 | - if ('address' === $form_field->field->type) { |
|
1274 | - $searchable_fields = $this->get_view_searchable_fields($view, true); |
|
1273 | + if ( 'address' === $form_field->field->type ) { |
|
1274 | + $searchable_fields = $this->get_view_searchable_fields( $view, true ); |
|
1275 | 1275 | |
1276 | - foreach ($searchable_fields as $searchable_field) { |
|
1277 | - if ($form_field->ID !== $searchable_field['field']) { |
|
1276 | + foreach ( $searchable_fields as $searchable_field ) { |
|
1277 | + if ( $form_field->ID !== $searchable_field[ 'field' ] ) { |
|
1278 | 1278 | continue; |
1279 | 1279 | } |
1280 | 1280 | |
1281 | 1281 | // Only exact-match dropdowns, not text search |
1282 | - if (in_array($searchable_field['input'], ['text', 'search'], true)) { |
|
1282 | + if ( in_array( $searchable_field[ 'input' ], [ 'text', 'search' ], true ) ) { |
|
1283 | 1283 | continue; |
1284 | 1284 | } |
1285 | 1285 | |
1286 | - $input_id = gravityview_get_input_id_from_id($form_field->ID); |
|
1286 | + $input_id = gravityview_get_input_id_from_id( $form_field->ID ); |
|
1287 | 1287 | |
1288 | - if (4 === $input_id) { |
|
1289 | - $filter['operator'] = $this->get_operator($get, $key, ['is'], 'is'); |
|
1288 | + if ( 4 === $input_id ) { |
|
1289 | + $filter[ 'operator' ] = $this->get_operator( $get, $key, [ 'is' ], 'is' ); |
|
1290 | 1290 | } |
1291 | 1291 | } |
1292 | 1292 | } |
@@ -1296,15 +1296,15 @@ discard block |
||
1296 | 1296 | case 'payment_date': |
1297 | 1297 | case 'date': |
1298 | 1298 | |
1299 | - $date_format = $this->get_datepicker_format(true); |
|
1299 | + $date_format = $this->get_datepicker_format( true ); |
|
1300 | 1300 | |
1301 | - if (is_array($value)) { |
|
1301 | + if ( is_array( $value ) ) { |
|
1302 | 1302 | |
1303 | 1303 | // Reset filter variable |
1304 | - $filter = []; |
|
1304 | + $filter = [ ]; |
|
1305 | 1305 | |
1306 | - foreach ($value as $k => $date) { |
|
1307 | - if (empty($date)) { |
|
1306 | + foreach ( $value as $k => $date ) { |
|
1307 | + if ( empty( $date ) ) { |
|
1308 | 1308 | continue; |
1309 | 1309 | } |
1310 | 1310 | $operator = 'start' === $k ? '>=' : '<='; |
@@ -1315,25 +1315,25 @@ discard block |
||
1315 | 1315 | * @since 1.16.3 |
1316 | 1316 | * Safeguard until GF implements '<=' operator |
1317 | 1317 | */ |
1318 | - if (!GFFormsModel::is_valid_operator($operator) && $operator === '<=') { |
|
1318 | + if ( ! GFFormsModel::is_valid_operator( $operator ) && $operator === '<=' ) { |
|
1319 | 1319 | $operator = '<'; |
1320 | - $date = date('Y-m-d', strtotime(self::get_formatted_date($date, 'Y-m-d', $date_format).' +1 day')); |
|
1320 | + $date = date( 'Y-m-d', strtotime( self::get_formatted_date( $date, 'Y-m-d', $date_format ) . ' +1 day' ) ); |
|
1321 | 1321 | } |
1322 | 1322 | |
1323 | - $filter[] = [ |
|
1323 | + $filter[ ] = [ |
|
1324 | 1324 | 'key' => $field_id, |
1325 | - 'value' => self::get_formatted_date($date, 'Y-m-d', $date_format), |
|
1326 | - 'operator' => $this->get_operator($get, $key, [$operator], $operator), |
|
1325 | + 'value' => self::get_formatted_date( $date, 'Y-m-d', $date_format ), |
|
1326 | + 'operator' => $this->get_operator( $get, $key, [ $operator ], $operator ), |
|
1327 | 1327 | ]; |
1328 | 1328 | } |
1329 | 1329 | } else { |
1330 | 1330 | $date = $value; |
1331 | - $filter['value'] = self::get_formatted_date($date, 'Y-m-d', $date_format); |
|
1332 | - $filter['operator'] = $this->get_operator($get, $key, ['is'], 'is'); |
|
1331 | + $filter[ 'value' ] = self::get_formatted_date( $date, 'Y-m-d', $date_format ); |
|
1332 | + $filter[ 'operator' ] = $this->get_operator( $get, $key, [ 'is' ], 'is' ); |
|
1333 | 1333 | } |
1334 | 1334 | |
1335 | - if ('payment_date' === $key) { |
|
1336 | - $filter['operator'] = 'contains'; |
|
1335 | + if ( 'payment_date' === $key ) { |
|
1336 | + $filter[ 'operator' ] = 'contains'; |
|
1337 | 1337 | } |
1338 | 1338 | |
1339 | 1339 | break; |
@@ -1351,7 +1351,7 @@ discard block |
||
1351 | 1351 | * |
1352 | 1352 | * @return string Format of the date in the database |
1353 | 1353 | */ |
1354 | - public static function get_date_field_format(GF_Field_Date $field) |
|
1354 | + public static function get_date_field_format( GF_Field_Date $field ) |
|
1355 | 1355 | { |
1356 | 1356 | $format = 'm/d/Y'; |
1357 | 1357 | $datepicker = [ |
@@ -1364,8 +1364,8 @@ discard block |
||
1364 | 1364 | 'ymd_dot' => 'Y.m.d', |
1365 | 1365 | ]; |
1366 | 1366 | |
1367 | - if (!empty($field->dateFormat) && isset($datepicker[$field->dateFormat])) { |
|
1368 | - $format = $datepicker[$field->dateFormat]; |
|
1367 | + if ( ! empty( $field->dateFormat ) && isset( $datepicker[ $field->dateFormat ] ) ) { |
|
1368 | + $format = $datepicker[ $field->dateFormat ]; |
|
1369 | 1369 | } |
1370 | 1370 | |
1371 | 1371 | return $format; |
@@ -1383,17 +1383,17 @@ discard block |
||
1383 | 1383 | * |
1384 | 1384 | * @return string |
1385 | 1385 | */ |
1386 | - public static function get_formatted_date($value = '', $format = 'Y-m-d', $value_format = 'Y-m-d') |
|
1386 | + public static function get_formatted_date( $value = '', $format = 'Y-m-d', $value_format = 'Y-m-d' ) |
|
1387 | 1387 | { |
1388 | - $date = date_create_from_format($value_format, $value); |
|
1388 | + $date = date_create_from_format( $value_format, $value ); |
|
1389 | 1389 | |
1390 | - if (empty($date)) { |
|
1391 | - gravityview()->log->debug('Date format not valid: {value}', ['value' => $value]); |
|
1390 | + if ( empty( $date ) ) { |
|
1391 | + gravityview()->log->debug( 'Date format not valid: {value}', [ 'value' => $value ] ); |
|
1392 | 1392 | |
1393 | 1393 | return ''; |
1394 | 1394 | } |
1395 | 1395 | |
1396 | - return $date->format($format); |
|
1396 | + return $date->format( $format ); |
|
1397 | 1397 | } |
1398 | 1398 | |
1399 | 1399 | /** |
@@ -1401,11 +1401,11 @@ discard block |
||
1401 | 1401 | * |
1402 | 1402 | * @param array $file_paths List of template paths ordered |
1403 | 1403 | */ |
1404 | - public function add_template_path($file_paths) |
|
1404 | + public function add_template_path( $file_paths ) |
|
1405 | 1405 | { |
1406 | 1406 | |
1407 | 1407 | // Index 100 is the default GravityView template path. |
1408 | - $file_paths[102] = self::$file.'templates/'; |
|
1408 | + $file_paths[ 102 ] = self::$file . 'templates/'; |
|
1409 | 1409 | |
1410 | 1410 | return $file_paths; |
1411 | 1411 | } |
@@ -1419,12 +1419,12 @@ discard block |
||
1419 | 1419 | * |
1420 | 1420 | * @return bool True: has a `date` or `date_range` field |
1421 | 1421 | */ |
1422 | - private function has_date_field($search_fields) |
|
1422 | + private function has_date_field( $search_fields ) |
|
1423 | 1423 | { |
1424 | 1424 | $has_date = false; |
1425 | 1425 | |
1426 | - foreach ($search_fields as $k => $field) { |
|
1427 | - if (in_array($field['input'], ['date', 'date_range', 'entry_date'])) { |
|
1426 | + foreach ( $search_fields as $k => $field ) { |
|
1427 | + if ( in_array( $field[ 'input' ], [ 'date', 'date_range', 'entry_date' ] ) ) { |
|
1428 | 1428 | $has_date = true; |
1429 | 1429 | break; |
1430 | 1430 | } |
@@ -1442,73 +1442,73 @@ discard block |
||
1442 | 1442 | * |
1443 | 1443 | * @return void |
1444 | 1444 | */ |
1445 | - public function render_frontend($widget_args, $content = '', $context = '') |
|
1445 | + public function render_frontend( $widget_args, $content = '', $context = '' ) |
|
1446 | 1446 | { |
1447 | 1447 | $gravityview_view = GravityView_View::getInstance(); |
1448 | 1448 | |
1449 | - if (empty($gravityview_view)) { |
|
1450 | - gravityview()->log->debug('$gravityview_view not instantiated yet.'); |
|
1449 | + if ( empty( $gravityview_view ) ) { |
|
1450 | + gravityview()->log->debug( '$gravityview_view not instantiated yet.' ); |
|
1451 | 1451 | |
1452 | 1452 | return; |
1453 | 1453 | } |
1454 | 1454 | |
1455 | - $view = \GV\View::by_id($gravityview_view->view_id); |
|
1455 | + $view = \GV\View::by_id( $gravityview_view->view_id ); |
|
1456 | 1456 | |
1457 | 1457 | // get configured search fields |
1458 | - $search_fields = !empty($widget_args['search_fields']) ? json_decode($widget_args['search_fields'], true) : ''; |
|
1458 | + $search_fields = ! empty( $widget_args[ 'search_fields' ] ) ? json_decode( $widget_args[ 'search_fields' ], true ) : ''; |
|
1459 | 1459 | |
1460 | - if (empty($search_fields) || !is_array($search_fields)) { |
|
1461 | - gravityview()->log->debug('No search fields configured for widget:', ['data' => $widget_args]); |
|
1460 | + if ( empty( $search_fields ) || ! is_array( $search_fields ) ) { |
|
1461 | + gravityview()->log->debug( 'No search fields configured for widget:', [ 'data' => $widget_args ] ); |
|
1462 | 1462 | |
1463 | 1463 | return; |
1464 | 1464 | } |
1465 | 1465 | |
1466 | 1466 | // prepare fields |
1467 | - foreach ($search_fields as $k => $field) { |
|
1467 | + foreach ( $search_fields as $k => $field ) { |
|
1468 | 1468 | $updated_field = $field; |
1469 | 1469 | |
1470 | - $updated_field = $this->get_search_filter_details($updated_field, $context); |
|
1470 | + $updated_field = $this->get_search_filter_details( $updated_field, $context ); |
|
1471 | 1471 | |
1472 | - switch ($field['field']) { |
|
1472 | + switch ( $field[ 'field' ] ) { |
|
1473 | 1473 | |
1474 | 1474 | case 'search_all': |
1475 | - $updated_field['key'] = 'search_all'; |
|
1476 | - $updated_field['input'] = 'search_all'; |
|
1477 | - $updated_field['value'] = $this->rgget_or_rgpost('gv_search'); |
|
1475 | + $updated_field[ 'key' ] = 'search_all'; |
|
1476 | + $updated_field[ 'input' ] = 'search_all'; |
|
1477 | + $updated_field[ 'value' ] = $this->rgget_or_rgpost( 'gv_search' ); |
|
1478 | 1478 | break; |
1479 | 1479 | |
1480 | 1480 | case 'entry_date': |
1481 | - $updated_field['key'] = 'entry_date'; |
|
1482 | - $updated_field['input'] = 'entry_date'; |
|
1483 | - $updated_field['value'] = [ |
|
1484 | - 'start' => $this->rgget_or_rgpost('gv_start'), |
|
1485 | - 'end' => $this->rgget_or_rgpost('gv_end'), |
|
1481 | + $updated_field[ 'key' ] = 'entry_date'; |
|
1482 | + $updated_field[ 'input' ] = 'entry_date'; |
|
1483 | + $updated_field[ 'value' ] = [ |
|
1484 | + 'start' => $this->rgget_or_rgpost( 'gv_start' ), |
|
1485 | + 'end' => $this->rgget_or_rgpost( 'gv_end' ), |
|
1486 | 1486 | ]; |
1487 | 1487 | break; |
1488 | 1488 | |
1489 | 1489 | case 'entry_id': |
1490 | - $updated_field['key'] = 'entry_id'; |
|
1491 | - $updated_field['input'] = 'entry_id'; |
|
1492 | - $updated_field['value'] = $this->rgget_or_rgpost('gv_id'); |
|
1490 | + $updated_field[ 'key' ] = 'entry_id'; |
|
1491 | + $updated_field[ 'input' ] = 'entry_id'; |
|
1492 | + $updated_field[ 'value' ] = $this->rgget_or_rgpost( 'gv_id' ); |
|
1493 | 1493 | break; |
1494 | 1494 | |
1495 | 1495 | case 'created_by': |
1496 | - $updated_field['key'] = 'created_by'; |
|
1497 | - $updated_field['name'] = 'gv_by'; |
|
1498 | - $updated_field['value'] = $this->rgget_or_rgpost('gv_by'); |
|
1496 | + $updated_field[ 'key' ] = 'created_by'; |
|
1497 | + $updated_field[ 'name' ] = 'gv_by'; |
|
1498 | + $updated_field[ 'value' ] = $this->rgget_or_rgpost( 'gv_by' ); |
|
1499 | 1499 | break; |
1500 | 1500 | |
1501 | 1501 | case 'is_approved': |
1502 | - $updated_field['key'] = 'is_approved'; |
|
1503 | - $updated_field['value'] = $this->rgget_or_rgpost('filter_is_approved'); |
|
1504 | - $updated_field['choices'] = self::get_is_approved_choices(); |
|
1502 | + $updated_field[ 'key' ] = 'is_approved'; |
|
1503 | + $updated_field[ 'value' ] = $this->rgget_or_rgpost( 'filter_is_approved' ); |
|
1504 | + $updated_field[ 'choices' ] = self::get_is_approved_choices(); |
|
1505 | 1505 | break; |
1506 | 1506 | } |
1507 | 1507 | |
1508 | - $search_fields[$k] = $updated_field; |
|
1508 | + $search_fields[ $k ] = $updated_field; |
|
1509 | 1509 | } |
1510 | 1510 | |
1511 | - gravityview()->log->debug('Calculated Search Fields: ', ['data' => $search_fields]); |
|
1511 | + gravityview()->log->debug( 'Calculated Search Fields: ', [ 'data' => $search_fields ] ); |
|
1512 | 1512 | |
1513 | 1513 | /** |
1514 | 1514 | * @filter `gravityview_widget_search_filters` Modify what fields are shown. The order of the fields in the $search_filters array controls the order as displayed in the search bar widget. |
@@ -1520,29 +1520,29 @@ discard block |
||
1520 | 1520 | * |
1521 | 1521 | * @var array |
1522 | 1522 | */ |
1523 | - $gravityview_view->search_fields = apply_filters('gravityview_widget_search_filters', $search_fields, $this, $widget_args, $context); |
|
1523 | + $gravityview_view->search_fields = apply_filters( 'gravityview_widget_search_filters', $search_fields, $this, $widget_args, $context ); |
|
1524 | 1524 | |
1525 | - $gravityview_view->permalink_fields = $this->add_no_permalink_fields([], $this, $widget_args); |
|
1525 | + $gravityview_view->permalink_fields = $this->add_no_permalink_fields( [ ], $this, $widget_args ); |
|
1526 | 1526 | |
1527 | - $gravityview_view->search_layout = !empty($widget_args['search_layout']) ? $widget_args['search_layout'] : 'horizontal'; |
|
1527 | + $gravityview_view->search_layout = ! empty( $widget_args[ 'search_layout' ] ) ? $widget_args[ 'search_layout' ] : 'horizontal'; |
|
1528 | 1528 | |
1529 | 1529 | /** @since 1.14 */ |
1530 | - $gravityview_view->search_mode = !empty($widget_args['search_mode']) ? $widget_args['search_mode'] : 'any'; |
|
1530 | + $gravityview_view->search_mode = ! empty( $widget_args[ 'search_mode' ] ) ? $widget_args[ 'search_mode' ] : 'any'; |
|
1531 | 1531 | |
1532 | - $custom_class = !empty($widget_args['custom_class']) ? $widget_args['custom_class'] : ''; |
|
1532 | + $custom_class = ! empty( $widget_args[ 'custom_class' ] ) ? $widget_args[ 'custom_class' ] : ''; |
|
1533 | 1533 | |
1534 | - $gravityview_view->search_class = self::get_search_class($custom_class); |
|
1534 | + $gravityview_view->search_class = self::get_search_class( $custom_class ); |
|
1535 | 1535 | |
1536 | - $gravityview_view->search_clear = !empty($widget_args['search_clear']) ? $widget_args['search_clear'] : false; |
|
1536 | + $gravityview_view->search_clear = ! empty( $widget_args[ 'search_clear' ] ) ? $widget_args[ 'search_clear' ] : false; |
|
1537 | 1537 | |
1538 | - if ($this->has_date_field($search_fields)) { |
|
1538 | + if ( $this->has_date_field( $search_fields ) ) { |
|
1539 | 1539 | // enqueue datepicker stuff only if needed! |
1540 | 1540 | $this->enqueue_datepicker(); |
1541 | 1541 | } |
1542 | 1542 | |
1543 | 1543 | $this->maybe_enqueue_flexibility(); |
1544 | 1544 | |
1545 | - $gravityview_view->render('widget', 'search', false); |
|
1545 | + $gravityview_view->render( 'widget', 'search', false ); |
|
1546 | 1546 | } |
1547 | 1547 | |
1548 | 1548 | /** |
@@ -1552,14 +1552,14 @@ discard block |
||
1552 | 1552 | * |
1553 | 1553 | * @return string Sanitized CSS class for the search form |
1554 | 1554 | */ |
1555 | - public static function get_search_class($custom_class = '') |
|
1555 | + public static function get_search_class( $custom_class = '' ) |
|
1556 | 1556 | { |
1557 | 1557 | $gravityview_view = GravityView_View::getInstance(); |
1558 | 1558 | |
1559 | - $search_class = 'gv-search-'.$gravityview_view->search_layout; |
|
1559 | + $search_class = 'gv-search-' . $gravityview_view->search_layout; |
|
1560 | 1560 | |
1561 | - if (!empty($custom_class)) { |
|
1562 | - $search_class .= ' '.$custom_class; |
|
1561 | + if ( ! empty( $custom_class ) ) { |
|
1562 | + $search_class .= ' ' . $custom_class; |
|
1563 | 1563 | } |
1564 | 1564 | |
1565 | 1565 | /** |
@@ -1567,12 +1567,12 @@ discard block |
||
1567 | 1567 | * |
1568 | 1568 | * @param string $search_class The CSS class for the search form |
1569 | 1569 | */ |
1570 | - $search_class = apply_filters('gravityview_search_class', $search_class); |
|
1570 | + $search_class = apply_filters( 'gravityview_search_class', $search_class ); |
|
1571 | 1571 | |
1572 | 1572 | // Is there an active search being performed? Used by fe-views.js |
1573 | 1573 | $search_class .= gravityview()->request->is_search() || GravityView_frontend::getInstance()->isSearch() ? ' gv-is-search' : ''; |
1574 | 1574 | |
1575 | - return gravityview_sanitize_html_class($search_class); |
|
1575 | + return gravityview_sanitize_html_class( $search_class ); |
|
1576 | 1576 | } |
1577 | 1577 | |
1578 | 1578 | /** |
@@ -1588,7 +1588,7 @@ discard block |
||
1588 | 1588 | |
1589 | 1589 | $post_id = $gravityview_view->getPostId() ? $gravityview_view->getPostId() : $gravityview_view->getViewId(); |
1590 | 1590 | |
1591 | - $url = add_query_arg([], get_permalink($post_id)); |
|
1591 | + $url = add_query_arg( [ ], get_permalink( $post_id ) ); |
|
1592 | 1592 | |
1593 | 1593 | /** |
1594 | 1594 | * @filter `gravityview/widget/search/form/action` Override the search URL. |
@@ -1598,7 +1598,7 @@ discard block |
||
1598 | 1598 | * Further parameters will be added once adhoc context is added. |
1599 | 1599 | * Use gravityview()->request until then. |
1600 | 1600 | */ |
1601 | - return apply_filters('gravityview/widget/search/form/action', $url); |
|
1601 | + return apply_filters( 'gravityview/widget/search/form/action', $url ); |
|
1602 | 1602 | } |
1603 | 1603 | |
1604 | 1604 | /** |
@@ -1609,35 +1609,35 @@ discard block |
||
1609 | 1609 | * |
1610 | 1610 | * @return string Label for the search form |
1611 | 1611 | */ |
1612 | - private static function get_field_label($field, $form_field = []) |
|
1612 | + private static function get_field_label( $field, $form_field = [ ] ) |
|
1613 | 1613 | { |
1614 | - $label = \GV\Utils::_GET('label', \GV\Utils::get($field, 'label')); |
|
1614 | + $label = \GV\Utils::_GET( 'label', \GV\Utils::get( $field, 'label' ) ); |
|
1615 | 1615 | |
1616 | - if (!$label) { |
|
1617 | - $label = isset($form_field['label']) ? $form_field['label'] : ''; |
|
1616 | + if ( ! $label ) { |
|
1617 | + $label = isset( $form_field[ 'label' ] ) ? $form_field[ 'label' ] : ''; |
|
1618 | 1618 | |
1619 | - switch ($field['field']) { |
|
1619 | + switch ( $field[ 'field' ] ) { |
|
1620 | 1620 | case 'search_all': |
1621 | - $label = __('Search Entries:', 'gravityview'); |
|
1621 | + $label = __( 'Search Entries:', 'gravityview' ); |
|
1622 | 1622 | break; |
1623 | 1623 | case 'entry_date': |
1624 | - $label = __('Filter by date:', 'gravityview'); |
|
1624 | + $label = __( 'Filter by date:', 'gravityview' ); |
|
1625 | 1625 | break; |
1626 | 1626 | case 'entry_id': |
1627 | - $label = __('Entry ID:', 'gravityview'); |
|
1627 | + $label = __( 'Entry ID:', 'gravityview' ); |
|
1628 | 1628 | break; |
1629 | 1629 | default: |
1630 | 1630 | // If this is a field input, not a field |
1631 | - if (strpos($field['field'], '.') > 0 && !empty($form_field['inputs'])) { |
|
1631 | + if ( strpos( $field[ 'field' ], '.' ) > 0 && ! empty( $form_field[ 'inputs' ] ) ) { |
|
1632 | 1632 | |
1633 | 1633 | // Get the label for the field in question, which returns an array |
1634 | - $items = wp_list_filter($form_field['inputs'], ['id' => $field['field']]); |
|
1634 | + $items = wp_list_filter( $form_field[ 'inputs' ], [ 'id' => $field[ 'field' ] ] ); |
|
1635 | 1635 | |
1636 | 1636 | // Get the item with the `label` key |
1637 | - $values = wp_list_pluck($items, 'label'); |
|
1637 | + $values = wp_list_pluck( $items, 'label' ); |
|
1638 | 1638 | |
1639 | 1639 | // There will only one item in the array, but this is easier |
1640 | - foreach ($values as $value) { |
|
1640 | + foreach ( $values as $value ) { |
|
1641 | 1641 | $label = $value; |
1642 | 1642 | break; |
1643 | 1643 | } |
@@ -1654,7 +1654,7 @@ discard block |
||
1654 | 1654 | * @param array $form_field Gravity Forms field array, as returned by `GFFormsModel::get_field()` |
1655 | 1655 | * @param array $field Field setting as sent by the GV configuration - has `field`, `input` (input type), and `label` keys |
1656 | 1656 | */ |
1657 | - $label = apply_filters('gravityview_search_field_label', esc_attr($label), $form_field, $field); |
|
1657 | + $label = apply_filters( 'gravityview_search_field_label', esc_attr( $label ), $form_field, $field ); |
|
1658 | 1658 | |
1659 | 1659 | return $label; |
1660 | 1660 | } |
@@ -1667,49 +1667,49 @@ discard block |
||
1667 | 1667 | * |
1668 | 1668 | * @return array |
1669 | 1669 | */ |
1670 | - private function get_search_filter_details($field, $context) |
|
1670 | + private function get_search_filter_details( $field, $context ) |
|
1671 | 1671 | { |
1672 | 1672 | $gravityview_view = GravityView_View::getInstance(); |
1673 | 1673 | |
1674 | 1674 | $form = $gravityview_view->getForm(); |
1675 | 1675 | |
1676 | 1676 | // for advanced field ids (eg, first name / last name ) |
1677 | - $name = 'filter_'.str_replace('.', '_', $field['field']); |
|
1677 | + $name = 'filter_' . str_replace( '.', '_', $field[ 'field' ] ); |
|
1678 | 1678 | |
1679 | 1679 | // get searched value from $_GET/$_POST (string or array) |
1680 | - $value = $this->rgget_or_rgpost($name); |
|
1680 | + $value = $this->rgget_or_rgpost( $name ); |
|
1681 | 1681 | |
1682 | 1682 | // get form field details |
1683 | - $form_field = gravityview_get_field($form, $field['field']); |
|
1683 | + $form_field = gravityview_get_field( $form, $field[ 'field' ] ); |
|
1684 | 1684 | |
1685 | - $form_field_type = \GV\Utils::get($form_field, 'type'); |
|
1685 | + $form_field_type = \GV\Utils::get( $form_field, 'type' ); |
|
1686 | 1686 | |
1687 | 1687 | $filter = [ |
1688 | - 'key' => \GV\Utils::get($field, 'field'), |
|
1688 | + 'key' => \GV\Utils::get( $field, 'field' ), |
|
1689 | 1689 | 'name' => $name, |
1690 | - 'label' => self::get_field_label($field, $form_field), |
|
1691 | - 'input' => \GV\Utils::get($field, 'input'), |
|
1690 | + 'label' => self::get_field_label( $field, $form_field ), |
|
1691 | + 'input' => \GV\Utils::get( $field, 'input' ), |
|
1692 | 1692 | 'value' => $value, |
1693 | 1693 | 'type' => $form_field_type, |
1694 | 1694 | ]; |
1695 | 1695 | |
1696 | 1696 | // collect choices |
1697 | - if ('post_category' === $form_field_type && !empty($form_field['displayAllCategories']) && empty($form_field['choices'])) { |
|
1698 | - $filter['choices'] = gravityview_get_terms_choices(); |
|
1699 | - } elseif (!empty($form_field['choices'])) { |
|
1700 | - $filter['choices'] = $form_field['choices']; |
|
1697 | + if ( 'post_category' === $form_field_type && ! empty( $form_field[ 'displayAllCategories' ] ) && empty( $form_field[ 'choices' ] ) ) { |
|
1698 | + $filter[ 'choices' ] = gravityview_get_terms_choices(); |
|
1699 | + } elseif ( ! empty( $form_field[ 'choices' ] ) ) { |
|
1700 | + $filter[ 'choices' ] = $form_field[ 'choices' ]; |
|
1701 | 1701 | } |
1702 | 1702 | |
1703 | - if ('date_range' === $field['input'] && empty($value)) { |
|
1704 | - $filter['value'] = ['start' => '', 'end' => '']; |
|
1703 | + if ( 'date_range' === $field[ 'input' ] && empty( $value ) ) { |
|
1704 | + $filter[ 'value' ] = [ 'start' => '', 'end' => '' ]; |
|
1705 | 1705 | } |
1706 | 1706 | |
1707 | - if ('created_by' === $field['field']) { |
|
1708 | - $filter['choices'] = self::get_created_by_choices($context->view); |
|
1709 | - $filter['type'] = 'created_by'; |
|
1707 | + if ( 'created_by' === $field[ 'field' ] ) { |
|
1708 | + $filter[ 'choices' ] = self::get_created_by_choices( $context->view ); |
|
1709 | + $filter[ 'type' ] = 'created_by'; |
|
1710 | 1710 | } |
1711 | 1711 | |
1712 | - if (!empty($filter['choices'])) { |
|
1712 | + if ( ! empty( $filter[ 'choices' ] ) ) { |
|
1713 | 1713 | /** |
1714 | 1714 | * @filter `gravityview/search/sieve_choices` Only output used choices for this field. |
1715 | 1715 | * |
@@ -1717,8 +1717,8 @@ discard block |
||
1717 | 1717 | * @param array $field The field configuration. |
1718 | 1718 | * @param \GV\Context The context. |
1719 | 1719 | */ |
1720 | - if (apply_filters('gravityview/search/sieve_choices', false, $field, $context)) { |
|
1721 | - $filter['choices'] = $this->sieve_filter_choices($filter, $context); |
|
1720 | + if ( apply_filters( 'gravityview/search/sieve_choices', false, $field, $context ) ) { |
|
1721 | + $filter[ 'choices' ] = $this->sieve_filter_choices( $filter, $context ); |
|
1722 | 1722 | } |
1723 | 1723 | } |
1724 | 1724 | |
@@ -1731,7 +1731,7 @@ discard block |
||
1731 | 1731 | * |
1732 | 1732 | * @since develop |
1733 | 1733 | */ |
1734 | - $filter = apply_filters('gravityview/search/filter_details', $filter, $field, $context); |
|
1734 | + $filter = apply_filters( 'gravityview/search/filter_details', $filter, $field, $context ); |
|
1735 | 1735 | |
1736 | 1736 | return $filter; |
1737 | 1737 | } |
@@ -1748,14 +1748,14 @@ discard block |
||
1748 | 1748 | * |
1749 | 1749 | * @return array The filter choices. |
1750 | 1750 | */ |
1751 | - private function sieve_filter_choices($filter, $context) |
|
1751 | + private function sieve_filter_choices( $filter, $context ) |
|
1752 | 1752 | { |
1753 | - if (empty($filter['key']) || empty($filter['choices'])) { |
|
1753 | + if ( empty( $filter[ 'key' ] ) || empty( $filter[ 'choices' ] ) ) { |
|
1754 | 1754 | return $filter; // @todo Populate plugins might give us empty choices |
1755 | 1755 | } |
1756 | 1756 | |
1757 | 1757 | // Allow only created_by and field-ids to be sieved. |
1758 | - if ('created_by' !== $filter['key'] && !is_numeric($filter['key'])) { |
|
1758 | + if ( 'created_by' !== $filter[ 'key' ] && ! is_numeric( $filter[ 'key' ] ) ) { |
|
1759 | 1759 | return $filter; |
1760 | 1760 | } |
1761 | 1761 | |
@@ -1766,51 +1766,51 @@ discard block |
||
1766 | 1766 | $entry_table_name = GFFormsModel::get_entry_table_name(); |
1767 | 1767 | $entry_meta_table_name = GFFormsModel::get_entry_meta_table_name(); |
1768 | 1768 | |
1769 | - $key_like = $wpdb->esc_like($filter['key']).'.%'; |
|
1769 | + $key_like = $wpdb->esc_like( $filter[ 'key' ] ) . '.%'; |
|
1770 | 1770 | |
1771 | - switch (\GV\Utils::get($filter, 'type')) { |
|
1771 | + switch ( \GV\Utils::get( $filter, 'type' ) ) { |
|
1772 | 1772 | case 'post_category': |
1773 | - $choices = $wpdb->get_col($wpdb->prepare( |
|
1773 | + $choices = $wpdb->get_col( $wpdb->prepare( |
|
1774 | 1774 | "SELECT DISTINCT SUBSTRING_INDEX(meta_value, ':', 1) FROM $entry_meta_table_name WHERE (meta_key LIKE %s OR meta_key = %d) AND form_id = %d", |
1775 | 1775 | $key_like, |
1776 | - $filter['key'], |
|
1776 | + $filter[ 'key' ], |
|
1777 | 1777 | $form_id |
1778 | - )); |
|
1778 | + ) ); |
|
1779 | 1779 | break; |
1780 | 1780 | case 'created_by': |
1781 | - $choices = $wpdb->get_col($wpdb->prepare( |
|
1781 | + $choices = $wpdb->get_col( $wpdb->prepare( |
|
1782 | 1782 | "SELECT DISTINCT created_by FROM $entry_table_name WHERE form_id = %d", |
1783 | 1783 | $form_id |
1784 | - )); |
|
1784 | + ) ); |
|
1785 | 1785 | break; |
1786 | 1786 | default: |
1787 | - $choices = $wpdb->get_col($wpdb->prepare( |
|
1787 | + $choices = $wpdb->get_col( $wpdb->prepare( |
|
1788 | 1788 | "SELECT DISTINCT meta_value FROM $entry_meta_table_name WHERE (meta_key LIKE %s OR meta_key = %d) AND form_id = %d", |
1789 | 1789 | $key_like, |
1790 | - $filter['key'], |
|
1790 | + $filter[ 'key' ], |
|
1791 | 1791 | $form_id |
1792 | - )); |
|
1793 | - |
|
1794 | - if (($field = gravityview_get_field($form_id, $filter['key'])) && 'json' === $field->storageType) { |
|
1795 | - $choices = array_map('json_decode', $choices); |
|
1796 | - $_choices_array = []; |
|
1797 | - foreach ($choices as $choice) { |
|
1798 | - if (is_array($choice)) { |
|
1799 | - $_choices_array = array_merge($_choices_array, $choice); |
|
1792 | + ) ); |
|
1793 | + |
|
1794 | + if ( ( $field = gravityview_get_field( $form_id, $filter[ 'key' ] ) ) && 'json' === $field->storageType ) { |
|
1795 | + $choices = array_map( 'json_decode', $choices ); |
|
1796 | + $_choices_array = [ ]; |
|
1797 | + foreach ( $choices as $choice ) { |
|
1798 | + if ( is_array( $choice ) ) { |
|
1799 | + $_choices_array = array_merge( $_choices_array, $choice ); |
|
1800 | 1800 | } else { |
1801 | - $_choices_array[] = $choice; |
|
1801 | + $_choices_array[ ] = $choice; |
|
1802 | 1802 | } |
1803 | 1803 | } |
1804 | - $choices = array_unique($_choices_array); |
|
1804 | + $choices = array_unique( $_choices_array ); |
|
1805 | 1805 | } |
1806 | 1806 | |
1807 | 1807 | break; |
1808 | 1808 | } |
1809 | 1809 | |
1810 | - $filter_choices = []; |
|
1811 | - foreach ($filter['choices'] as $choice) { |
|
1812 | - if (in_array($choice['text'], $choices, true) || in_array($choice['value'], $choices, true)) { |
|
1813 | - $filter_choices[] = $choice; |
|
1810 | + $filter_choices = [ ]; |
|
1811 | + foreach ( $filter[ 'choices' ] as $choice ) { |
|
1812 | + if ( in_array( $choice[ 'text' ], $choices, true ) || in_array( $choice[ 'value' ], $choices, true ) ) { |
|
1813 | + $filter_choices[ ] = $choice; |
|
1814 | 1814 | } |
1815 | 1815 | } |
1816 | 1816 | |
@@ -1827,7 +1827,7 @@ discard block |
||
1827 | 1827 | * |
1828 | 1828 | * @return array Array of user choices (value = ID, text = display name) |
1829 | 1829 | */ |
1830 | - private static function get_created_by_choices($view) |
|
1830 | + private static function get_created_by_choices( $view ) |
|
1831 | 1831 | { |
1832 | 1832 | |
1833 | 1833 | /** |
@@ -1835,10 +1835,10 @@ discard block |
||
1835 | 1835 | * |
1836 | 1836 | * @see \GVCommon::get_users |
1837 | 1837 | */ |
1838 | - $users = GVCommon::get_users('search_widget', ['fields' => ['ID', 'display_name']]); |
|
1838 | + $users = GVCommon::get_users( 'search_widget', [ 'fields' => [ 'ID', 'display_name' ] ] ); |
|
1839 | 1839 | |
1840 | - $choices = []; |
|
1841 | - foreach ($users as $user) { |
|
1840 | + $choices = [ ]; |
|
1841 | + foreach ( $users as $user ) { |
|
1842 | 1842 | /** |
1843 | 1843 | * @filter `gravityview/search/created_by/text` Filter the display text in created by search choices |
1844 | 1844 | * |
@@ -1848,8 +1848,8 @@ discard block |
||
1848 | 1848 | * @param \WP_User $user The user. |
1849 | 1849 | * @param \GV\View $view The view. |
1850 | 1850 | */ |
1851 | - $text = apply_filters('gravityview/search/created_by/text', $user->display_name, $user, $view); |
|
1852 | - $choices[] = [ |
|
1851 | + $text = apply_filters( 'gravityview/search/created_by/text', $user->display_name, $user, $view ); |
|
1852 | + $choices[ ] = [ |
|
1853 | 1853 | 'value' => $user->ID, |
1854 | 1854 | 'text' => $text, |
1855 | 1855 | ]; |
@@ -1867,11 +1867,11 @@ discard block |
||
1867 | 1867 | */ |
1868 | 1868 | private static function get_is_approved_choices() |
1869 | 1869 | { |
1870 | - $choices = []; |
|
1871 | - foreach (GravityView_Entry_Approval_Status::get_all() as $status) { |
|
1872 | - $choices[] = [ |
|
1873 | - 'value' => $status['value'], |
|
1874 | - 'text' => $status['label'], |
|
1870 | + $choices = [ ]; |
|
1871 | + foreach ( GravityView_Entry_Approval_Status::get_all() as $status ) { |
|
1872 | + $choices[ ] = [ |
|
1873 | + 'value' => $status[ 'value' ], |
|
1874 | + 'text' => $status[ 'label' ], |
|
1875 | 1875 | ]; |
1876 | 1876 | } |
1877 | 1877 | |
@@ -1887,10 +1887,10 @@ discard block |
||
1887 | 1887 | { |
1888 | 1888 | $gravityview_view = GravityView_View::getInstance(); |
1889 | 1889 | |
1890 | - if ($gravityview_view->search_clear) { |
|
1891 | - $url = strtok(add_query_arg([]), '?'); |
|
1890 | + if ( $gravityview_view->search_clear ) { |
|
1891 | + $url = strtok( add_query_arg( [ ] ), '?' ); |
|
1892 | 1892 | |
1893 | - echo gravityview_get_link($url, esc_html__('Clear', 'gravityview'), 'class=button gv-search-clear'); |
|
1893 | + echo gravityview_get_link( $url, esc_html__( 'Clear', 'gravityview' ), 'class=button gv-search-clear' ); |
|
1894 | 1894 | } |
1895 | 1895 | } |
1896 | 1896 | |
@@ -1903,15 +1903,15 @@ discard block |
||
1903 | 1903 | * |
1904 | 1904 | * @return mixed|string Value of request at $name key. Empty string if empty. |
1905 | 1905 | */ |
1906 | - private function rgget_or_rgpost($name) |
|
1906 | + private function rgget_or_rgpost( $name ) |
|
1907 | 1907 | { |
1908 | - $value = \GV\Utils::_REQUEST($name); |
|
1908 | + $value = \GV\Utils::_REQUEST( $name ); |
|
1909 | 1909 | |
1910 | - $value = stripslashes_deep($value); |
|
1910 | + $value = stripslashes_deep( $value ); |
|
1911 | 1911 | |
1912 | - $value = gv_map_deep($value, 'rawurldecode'); |
|
1912 | + $value = gv_map_deep( $value, 'rawurldecode' ); |
|
1913 | 1913 | |
1914 | - $value = gv_map_deep($value, '_wp_specialchars'); |
|
1914 | + $value = gv_map_deep( $value, '_wp_specialchars' ); |
|
1915 | 1915 | |
1916 | 1916 | return $value; |
1917 | 1917 | } |
@@ -1923,9 +1923,9 @@ discard block |
||
1923 | 1923 | * |
1924 | 1924 | * @return array Array required scripts, with `jquery-ui-datepicker` added |
1925 | 1925 | */ |
1926 | - public function add_datepicker_js_dependency($js_dependencies) |
|
1926 | + public function add_datepicker_js_dependency( $js_dependencies ) |
|
1927 | 1927 | { |
1928 | - $js_dependencies[] = 'jquery-ui-datepicker'; |
|
1928 | + $js_dependencies[ ] = 'jquery-ui-datepicker'; |
|
1929 | 1929 | |
1930 | 1930 | return $js_dependencies; |
1931 | 1931 | } |
@@ -1938,7 +1938,7 @@ discard block |
||
1938 | 1938 | * |
1939 | 1939 | * @return array |
1940 | 1940 | */ |
1941 | - public function add_datepicker_localization($localizations = [], $view_data = []) |
|
1941 | + public function add_datepicker_localization( $localizations = [ ], $view_data = [ ] ) |
|
1942 | 1942 | { |
1943 | 1943 | global $wp_locale; |
1944 | 1944 | |
@@ -1951,28 +1951,28 @@ discard block |
||
1951 | 1951 | * @param array $js_localization The data padded to the Javascript file |
1952 | 1952 | * @param array $view_data View data array with View settings |
1953 | 1953 | */ |
1954 | - $datepicker_settings = apply_filters('gravityview_datepicker_settings', [ |
|
1954 | + $datepicker_settings = apply_filters( 'gravityview_datepicker_settings', [ |
|
1955 | 1955 | 'yearRange' => '-5:+5', |
1956 | 1956 | 'changeMonth' => true, |
1957 | 1957 | 'changeYear' => true, |
1958 | - 'closeText' => esc_attr_x('Close', 'Close calendar', 'gravityview'), |
|
1959 | - 'prevText' => esc_attr_x('Prev', 'Previous month in calendar', 'gravityview'), |
|
1960 | - 'nextText' => esc_attr_x('Next', 'Next month in calendar', 'gravityview'), |
|
1961 | - 'currentText' => esc_attr_x('Today', 'Today in calendar', 'gravityview'), |
|
1962 | - 'weekHeader' => esc_attr_x('Week', 'Week in calendar', 'gravityview'), |
|
1963 | - 'monthStatus' => __('Show a different month', 'gravityview'), |
|
1964 | - 'monthNames' => array_values($wp_locale->month), |
|
1965 | - 'monthNamesShort' => array_values($wp_locale->month_abbrev), |
|
1966 | - 'dayNames' => array_values($wp_locale->weekday), |
|
1967 | - 'dayNamesShort' => array_values($wp_locale->weekday_abbrev), |
|
1968 | - 'dayNamesMin' => array_values($wp_locale->weekday_initial), |
|
1958 | + 'closeText' => esc_attr_x( 'Close', 'Close calendar', 'gravityview' ), |
|
1959 | + 'prevText' => esc_attr_x( 'Prev', 'Previous month in calendar', 'gravityview' ), |
|
1960 | + 'nextText' => esc_attr_x( 'Next', 'Next month in calendar', 'gravityview' ), |
|
1961 | + 'currentText' => esc_attr_x( 'Today', 'Today in calendar', 'gravityview' ), |
|
1962 | + 'weekHeader' => esc_attr_x( 'Week', 'Week in calendar', 'gravityview' ), |
|
1963 | + 'monthStatus' => __( 'Show a different month', 'gravityview' ), |
|
1964 | + 'monthNames' => array_values( $wp_locale->month ), |
|
1965 | + 'monthNamesShort' => array_values( $wp_locale->month_abbrev ), |
|
1966 | + 'dayNames' => array_values( $wp_locale->weekday ), |
|
1967 | + 'dayNamesShort' => array_values( $wp_locale->weekday_abbrev ), |
|
1968 | + 'dayNamesMin' => array_values( $wp_locale->weekday_initial ), |
|
1969 | 1969 | // get the start of week from WP general setting |
1970 | - 'firstDay' => get_option('start_of_week'), |
|
1970 | + 'firstDay' => get_option( 'start_of_week' ), |
|
1971 | 1971 | // is Right to left language? default is false |
1972 | 1972 | 'isRTL' => is_rtl(), |
1973 | - ], $view_data); |
|
1973 | + ], $view_data ); |
|
1974 | 1974 | |
1975 | - $localizations['datepicker'] = $datepicker_settings; |
|
1975 | + $localizations[ 'datepicker' ] = $datepicker_settings; |
|
1976 | 1976 | |
1977 | 1977 | return $localizations; |
1978 | 1978 | } |
@@ -1987,7 +1987,7 @@ discard block |
||
1987 | 1987 | */ |
1988 | 1988 | public function register_scripts() |
1989 | 1989 | { |
1990 | - wp_register_script('gv-flexibility', plugins_url('assets/lib/flexibility/flexibility.js', GRAVITYVIEW_FILE), [], \GV\Plugin::$version, true); |
|
1990 | + wp_register_script( 'gv-flexibility', plugins_url( 'assets/lib/flexibility/flexibility.js', GRAVITYVIEW_FILE ), [ ], \GV\Plugin::$version, true ); |
|
1991 | 1991 | } |
1992 | 1992 | |
1993 | 1993 | /** |
@@ -1999,8 +1999,8 @@ discard block |
||
1999 | 1999 | */ |
2000 | 2000 | private function maybe_enqueue_flexibility() |
2001 | 2001 | { |
2002 | - if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/MSIE [8-9]/', $_SERVER['HTTP_USER_AGENT'])) { |
|
2003 | - wp_enqueue_script('gv-flexibility'); |
|
2002 | + if ( isset( $_SERVER[ 'HTTP_USER_AGENT' ] ) && preg_match( '/MSIE [8-9]/', $_SERVER[ 'HTTP_USER_AGENT' ] ) ) { |
|
2003 | + wp_enqueue_script( 'gv-flexibility' ); |
|
2004 | 2004 | } |
2005 | 2005 | } |
2006 | 2006 | |
@@ -2017,13 +2017,13 @@ discard block |
||
2017 | 2017 | { |
2018 | 2018 | $gravityview_view = GravityView_View::getInstance(); |
2019 | 2019 | |
2020 | - wp_enqueue_script('jquery-ui-datepicker'); |
|
2020 | + wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
2021 | 2021 | |
2022 | - add_filter('gravityview_js_dependencies', [$this, 'add_datepicker_js_dependency']); |
|
2023 | - add_filter('gravityview_js_localization', [$this, 'add_datepicker_localization'], 10, 2); |
|
2022 | + add_filter( 'gravityview_js_dependencies', [ $this, 'add_datepicker_js_dependency' ] ); |
|
2023 | + add_filter( 'gravityview_js_localization', [ $this, 'add_datepicker_localization' ], 10, 2 ); |
|
2024 | 2024 | |
2025 | 2025 | $scheme = is_ssl() ? 'https://' : 'http://'; |
2026 | - wp_enqueue_style('jquery-ui-datepicker', $scheme.'ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css'); |
|
2026 | + wp_enqueue_style( 'jquery-ui-datepicker', $scheme . 'ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/themes/smoothness/jquery-ui.css' ); |
|
2027 | 2027 | |
2028 | 2028 | /** |
2029 | 2029 | * @filter `gravityview_search_datepicker_class` |
@@ -2039,7 +2039,7 @@ discard block |
||
2039 | 2039 | * - `ymd_dash` (yyyy-mm-dd) |
2040 | 2040 | * - `ymd_dot` (yyyy.mm.dd) |
2041 | 2041 | */ |
2042 | - $datepicker_class = apply_filters('gravityview_search_datepicker_class', 'gv-datepicker datepicker '.$this->get_datepicker_format()); |
|
2042 | + $datepicker_class = apply_filters( 'gravityview_search_datepicker_class', 'gv-datepicker datepicker ' . $this->get_datepicker_format() ); |
|
2043 | 2043 | |
2044 | 2044 | $gravityview_view->datepicker_class = $datepicker_class; |
2045 | 2045 | } |
@@ -2053,7 +2053,7 @@ discard block |
||
2053 | 2053 | * |
2054 | 2054 | * @return string The datepicker format placeholder, or the PHP date format. |
2055 | 2055 | */ |
2056 | - private function get_datepicker_format($date_format = false) |
|
2056 | + private function get_datepicker_format( $date_format = false ) |
|
2057 | 2057 | { |
2058 | 2058 | $default_format = 'mdy'; |
2059 | 2059 | |
@@ -2072,7 +2072,7 @@ discard block |
||
2072 | 2072 | * - `ymd_dash` (yyyy-mm-dd) |
2073 | 2073 | * - `ymd_dot` (yyyy.mm.dd) |
2074 | 2074 | */ |
2075 | - $format = apply_filters('gravityview/widgets/search/datepicker/format', $default_format); |
|
2075 | + $format = apply_filters( 'gravityview/widgets/search/datepicker/format', $default_format ); |
|
2076 | 2076 | |
2077 | 2077 | $gf_date_formats = [ |
2078 | 2078 | 'mdy' => 'm/d/Y', |
@@ -2086,13 +2086,13 @@ discard block |
||
2086 | 2086 | 'ymd_dot' => 'Y.m.d', |
2087 | 2087 | ]; |
2088 | 2088 | |
2089 | - if (!$date_format) { |
|
2089 | + if ( ! $date_format ) { |
|
2090 | 2090 | // If the format key isn't valid, return default format key |
2091 | - return isset($gf_date_formats[$format]) ? $format : $default_format; |
|
2091 | + return isset( $gf_date_formats[ $format ] ) ? $format : $default_format; |
|
2092 | 2092 | } |
2093 | 2093 | |
2094 | 2094 | // If the format key isn't valid, return default format value |
2095 | - return \GV\Utils::get($gf_date_formats, $format, $gf_date_formats[$default_format]); |
|
2095 | + return \GV\Utils::get( $gf_date_formats, $format, $gf_date_formats[ $default_format ] ); |
|
2096 | 2096 | } |
2097 | 2097 | |
2098 | 2098 | /** |
@@ -2106,13 +2106,13 @@ discard block |
||
2106 | 2106 | { |
2107 | 2107 | global $wp; |
2108 | 2108 | |
2109 | - if (!is_preview() || !current_user_can('publish_gravityviews')) { |
|
2109 | + if ( ! is_preview() || ! current_user_can( 'publish_gravityviews' ) ) { |
|
2110 | 2110 | return; |
2111 | 2111 | } |
2112 | 2112 | |
2113 | 2113 | // Outputs `preview` and `post_id` variables |
2114 | - foreach ($wp->query_vars as $key => $value) { |
|
2115 | - printf('<input type="hidden" name="%s" value="%s" />', esc_attr($key), esc_attr($value)); |
|
2114 | + foreach ( $wp->query_vars as $key => $value ) { |
|
2115 | + printf( '<input type="hidden" name="%s" value="%s" />', esc_attr( $key ), esc_attr( $value ) ); |
|
2116 | 2116 | } |
2117 | 2117 | } |
2118 | 2118 | |
@@ -2126,14 +2126,14 @@ discard block |
||
2126 | 2126 | * |
2127 | 2127 | * @return string The operator. |
2128 | 2128 | */ |
2129 | - private function get_operator($get, $key, $allowed, $default) |
|
2129 | + private function get_operator( $get, $key, $allowed, $default ) |
|
2130 | 2130 | { |
2131 | - $operator = \GV\Utils::get($get, "$key|op", $default); |
|
2131 | + $operator = \GV\Utils::get( $get, "$key|op", $default ); |
|
2132 | 2132 | |
2133 | 2133 | /** |
2134 | 2134 | * @depecated 2.14 |
2135 | 2135 | */ |
2136 | - $allowed = apply_filters_deprecated('gravityview/search/operator_whitelist', [$allowed, $key], '2.14', 'gravityview/search/operator_allowlist'); |
|
2136 | + $allowed = apply_filters_deprecated( 'gravityview/search/operator_whitelist', [ $allowed, $key ], '2.14', 'gravityview/search/operator_allowlist' ); |
|
2137 | 2137 | |
2138 | 2138 | /** |
2139 | 2139 | * @filter `gravityview/search/operator_allowlist` An array of allowed operators for a field. |
@@ -2143,9 +2143,9 @@ discard block |
||
2143 | 2143 | * @param string[] An allowlist of operators. |
2144 | 2144 | * @param string The filter name. |
2145 | 2145 | */ |
2146 | - $allowed = apply_filters('gravityview/search/operator_allowlist', $allowed, $key); |
|
2146 | + $allowed = apply_filters( 'gravityview/search/operator_allowlist', $allowed, $key ); |
|
2147 | 2147 | |
2148 | - if (!in_array($operator, $allowed, true)) { |
|
2148 | + if ( ! in_array( $operator, $allowed, true ) ) { |
|
2149 | 2149 | $operator = $default; |
2150 | 2150 | } |
2151 | 2151 | |
@@ -2155,7 +2155,7 @@ discard block |
||
2155 | 2155 | |
2156 | 2156 | new GravityView_Widget_Search(); |
2157 | 2157 | |
2158 | -if (!gravityview()->plugin->supports(\GV\Plugin::FEATURE_GFQUERY)) { |
|
2158 | +if ( ! gravityview()->plugin->supports( \GV\Plugin::FEATURE_GFQUERY ) ) { |
|
2159 | 2159 | return; |
2160 | 2160 | } |
2161 | 2161 | |
@@ -2164,13 +2164,13 @@ discard block |
||
2164 | 2164 | */ |
2165 | 2165 | class GravityView_Widget_Search_Author_GF_Query_Condition extends \GF_Query_Condition |
2166 | 2166 | { |
2167 | - public function __construct($filter, $view) |
|
2167 | + public function __construct( $filter, $view ) |
|
2168 | 2168 | { |
2169 | - $this->value = $filter['value']; |
|
2169 | + $this->value = $filter[ 'value' ]; |
|
2170 | 2170 | $this->view = $view; |
2171 | 2171 | } |
2172 | 2172 | |
2173 | - public function sql($query) |
|
2173 | + public function sql( $query ) |
|
2174 | 2174 | { |
2175 | 2175 | global $wpdb; |
2176 | 2176 | |
@@ -2184,7 +2184,7 @@ discard block |
||
2184 | 2184 | * @param array The user meta fields. |
2185 | 2185 | * @param \GV\View $view The view. |
2186 | 2186 | */ |
2187 | - $user_meta_fields = apply_filters('gravityview/widgets/search/created_by/user_meta_fields', $user_meta_fields, $this->view); |
|
2187 | + $user_meta_fields = apply_filters( 'gravityview/widgets/search/created_by/user_meta_fields', $user_meta_fields, $this->view ); |
|
2188 | 2188 | |
2189 | 2189 | $user_fields = [ |
2190 | 2190 | 'user_nicename', 'user_login', 'display_name', 'user_email', |
@@ -2196,21 +2196,21 @@ discard block |
||
2196 | 2196 | * @param array The user fields. |
2197 | 2197 | * @param \GV\View $view The view. |
2198 | 2198 | */ |
2199 | - $user_fields = apply_filters('gravityview/widgets/search/created_by/user_fields', $user_fields, $this->view); |
|
2199 | + $user_fields = apply_filters( 'gravityview/widgets/search/created_by/user_fields', $user_fields, $this->view ); |
|
2200 | 2200 | |
2201 | - $conditions = []; |
|
2201 | + $conditions = [ ]; |
|
2202 | 2202 | |
2203 | - foreach ($user_fields as $user_field) { |
|
2204 | - $conditions[] = $wpdb->prepare("`u`.`$user_field` LIKE %s", '%'.$wpdb->esc_like($this->value).'%'); |
|
2203 | + foreach ( $user_fields as $user_field ) { |
|
2204 | + $conditions[ ] = $wpdb->prepare( "`u`.`$user_field` LIKE %s", '%' . $wpdb->esc_like( $this->value ) . '%' ); |
|
2205 | 2205 | } |
2206 | 2206 | |
2207 | - foreach ($user_meta_fields as $meta_field) { |
|
2208 | - $conditions[] = $wpdb->prepare('(`um`.`meta_key` = %s AND `um`.`meta_value` LIKE %s)', $meta_field, '%'.$wpdb->esc_like($this->value).'%'); |
|
2207 | + foreach ( $user_meta_fields as $meta_field ) { |
|
2208 | + $conditions[ ] = $wpdb->prepare( '(`um`.`meta_key` = %s AND `um`.`meta_value` LIKE %s)', $meta_field, '%' . $wpdb->esc_like( $this->value ) . '%' ); |
|
2209 | 2209 | } |
2210 | 2210 | |
2211 | - $conditions = '('.implode(' OR ', $conditions).')'; |
|
2211 | + $conditions = '(' . implode( ' OR ', $conditions ) . ')'; |
|
2212 | 2212 | |
2213 | - $alias = $query->_alias(null); |
|
2213 | + $alias = $query->_alias( null ); |
|
2214 | 2214 | |
2215 | 2215 | return "(EXISTS (SELECT 1 FROM $wpdb->users u LEFT JOIN $wpdb->usermeta um ON u.ID = um.user_id WHERE (u.ID = `$alias`.`created_by` AND $conditions)))"; |
2216 | 2216 | } |
@@ -31,8 +31,7 @@ discard block |
||
31 | 31 | */ |
32 | 32 | private $search_method = 'get'; |
33 | 33 | |
34 | - public function __construct() |
|
35 | - { |
|
34 | + public function __construct() { |
|
36 | 35 | $this->widget_id = 'search_bar'; |
37 | 36 | $this->widget_description = esc_html__('Search form for searching entries.', 'gravityview'); |
38 | 37 | $this->widget_subtitle = ''; |
@@ -109,8 +108,7 @@ discard block |
||
109 | 108 | /** |
110 | 109 | * @return GravityView_Widget_Search |
111 | 110 | */ |
112 | - public static function getInstance() |
|
113 | - { |
|
111 | + public static function getInstance() { |
|
114 | 112 | if (empty(self::$instance)) { |
115 | 113 | self::$instance = new GravityView_Widget_Search(); |
116 | 114 | } |
@@ -125,8 +123,7 @@ discard block |
||
125 | 123 | * |
126 | 124 | * @return mixed |
127 | 125 | */ |
128 | - public function add_reserved_args($args) |
|
129 | - { |
|
126 | + public function add_reserved_args($args) { |
|
130 | 127 | $args[] = 'gv_search'; |
131 | 128 | $args[] = 'gv_start'; |
132 | 129 | $args[] = 'gv_end'; |
@@ -151,8 +148,7 @@ discard block |
||
151 | 148 | * |
152 | 149 | * @since 1.16.4 |
153 | 150 | */ |
154 | - private function set_search_method() |
|
155 | - { |
|
151 | + private function set_search_method() { |
|
156 | 152 | /** |
157 | 153 | * @filter `gravityview/search/method` Modify the search form method (GET / POST) |
158 | 154 | * |
@@ -175,8 +171,7 @@ discard block |
||
175 | 171 | * |
176 | 172 | * @return string |
177 | 173 | */ |
178 | - public function get_search_method() |
|
179 | - { |
|
174 | + public function get_search_method() { |
|
180 | 175 | return $this->search_method; |
181 | 176 | } |
182 | 177 | |
@@ -187,8 +182,7 @@ discard block |
||
187 | 182 | * |
188 | 183 | * @return array [field type name] => (array|string) search bar input types |
189 | 184 | */ |
190 | - public static function get_input_types_by_field_type() |
|
191 | - { |
|
185 | + public static function get_input_types_by_field_type() { |
|
192 | 186 | /** |
193 | 187 | * Input Type groups. |
194 | 188 | * |
@@ -227,8 +221,7 @@ discard block |
||
227 | 221 | * |
228 | 222 | * @return array [input type] => input type label |
229 | 223 | */ |
230 | - public static function get_search_input_labels() |
|
231 | - { |
|
224 | + public static function get_search_input_labels() { |
|
232 | 225 | /** |
233 | 226 | * Input Type labels l10n. |
234 | 227 | * |
@@ -256,8 +249,7 @@ discard block |
||
256 | 249 | return $input_labels; |
257 | 250 | } |
258 | 251 | |
259 | - public static function get_search_input_label($input_type) |
|
260 | - { |
|
252 | + public static function get_search_input_label($input_type) { |
|
261 | 253 | $labels = self::get_search_input_labels(); |
262 | 254 | |
263 | 255 | return \GV\Utils::get($labels, $input_type, false); |
@@ -268,8 +260,7 @@ discard block |
||
268 | 260 | * |
269 | 261 | * @param mixed $hook |
270 | 262 | */ |
271 | - public function add_scripts_and_styles($hook) |
|
272 | - { |
|
263 | + public function add_scripts_and_styles($hook) { |
|
273 | 264 | global $pagenow; |
274 | 265 | |
275 | 266 | // Don't process any scripts below here if it's not a GravityView page or the widgets screen |
@@ -302,8 +293,7 @@ discard block |
||
302 | 293 | * |
303 | 294 | * @return array Scripts allowed in no-conflict mode, plus the search widget script |
304 | 295 | */ |
305 | - public function register_no_conflict($allowed) |
|
306 | - { |
|
296 | + public function register_no_conflict($allowed) { |
|
307 | 297 | $allowed[] = 'gravityview_searchwidget_admin'; |
308 | 298 | |
309 | 299 | return $allowed; |
@@ -315,8 +305,7 @@ discard block |
||
315 | 305 | * |
316 | 306 | * @return void |
317 | 307 | */ |
318 | - public static function get_searchable_fields() |
|
319 | - { |
|
308 | + public static function get_searchable_fields() { |
|
320 | 309 | if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'gravityview_ajaxsearchwidget')) { |
321 | 310 | exit('0'); |
322 | 311 | } |
@@ -346,8 +335,7 @@ discard block |
||
346 | 335 | * |
347 | 336 | * @return string |
348 | 337 | */ |
349 | - public static function render_searchable_fields($form_id = null, $current = '') |
|
350 | - { |
|
338 | + public static function render_searchable_fields($form_id = null, $current = '') { |
|
351 | 339 | if (is_null($form_id)) { |
352 | 340 | return ''; |
353 | 341 | } |
@@ -434,8 +422,7 @@ discard block |
||
434 | 422 | * |
435 | 423 | * @return string GV field search input type ('multi', 'boolean', 'select', 'date', 'text') |
436 | 424 | */ |
437 | - public static function get_search_input_types($field_id = '', $field_type = null) |
|
438 | - { |
|
425 | + public static function get_search_input_types($field_id = '', $field_type = null) { |
|
439 | 426 | |
440 | 427 | // @todo - This needs to be improved - many fields have . including products and addresses |
441 | 428 | if (false !== strpos((string) $field_id, '.') && in_array($field_type, ['checkbox']) || in_array($field_id, ['is_fulfilled'])) { |
@@ -476,8 +463,7 @@ discard block |
||
476 | 463 | * |
477 | 464 | * @return array Search fields, modified if not using permalinks |
478 | 465 | */ |
479 | - public function add_no_permalink_fields($search_fields, $object, $widget_args = []) |
|
480 | - { |
|
466 | + public function add_no_permalink_fields($search_fields, $object, $widget_args = []) { |
|
481 | 467 | /** @global WP_Rewrite $wp_rewrite */ |
482 | 468 | global $wp_rewrite; |
483 | 469 | |
@@ -525,8 +511,7 @@ discard block |
||
525 | 511 | * |
526 | 512 | * @return array If no View, returns empty array. Otherwise, returns array of fields configured in widgets and Search Bar for a View |
527 | 513 | */ |
528 | - private function get_view_searchable_fields($view, $with_full_field = false) |
|
529 | - { |
|
514 | + private function get_view_searchable_fields($view, $with_full_field = false) { |
|
530 | 515 | |
531 | 516 | /** |
532 | 517 | * Find all search widgets on the view and get the searchable fields settings. |
@@ -598,8 +583,7 @@ discard block |
||
598 | 583 | * |
599 | 584 | * @return array |
600 | 585 | */ |
601 | - public function filter_entries($search_criteria, $form_id = null, $args = [], $force_search_criteria = false) |
|
602 | - { |
|
586 | + public function filter_entries($search_criteria, $form_id = null, $args = [], $force_search_criteria = false) { |
|
603 | 587 | if (!$force_search_criteria && gravityview()->plugin->supports(\GV\Plugin::FEATURE_GFQUERY)) { |
604 | 588 | /** |
605 | 589 | * If GF_Query is available, we can construct custom conditions with nested |
@@ -736,7 +720,8 @@ discard block |
||
736 | 720 | // Fast-forward 24 hour on the end time |
737 | 721 | $curr_end = date('Y-m-d H:i:s', strtotime($curr_end) + DAY_IN_SECONDS); |
738 | 722 | $search_criteria['end_date'] = $adjust_tz ? get_gmt_from_date($curr_end) : $curr_end; |
739 | - if (strpos($search_criteria['end_date'], '00:00:00')) { // See https://github.com/gravityview/GravityView/issues/1056 |
|
723 | + if (strpos($search_criteria['end_date'], '00:00:00')) { |
|
724 | +// See https://github.com/gravityview/GravityView/issues/1056 |
|
740 | 725 | $search_criteria['end_date'] = date('Y-m-d H:i:s', strtotime($search_criteria['end_date']) - 1); |
741 | 726 | } |
742 | 727 | } |
@@ -855,8 +840,7 @@ discard block |
||
855 | 840 | * @param \GV\View $this The current view object |
856 | 841 | * @param \GV\Request $request The request object |
857 | 842 | */ |
858 | - public function gf_query_filter(&$query, $view, $request) |
|
859 | - { |
|
843 | + public function gf_query_filter(&$query, $view, $request) { |
|
860 | 844 | /** |
861 | 845 | * This is a shortcut to get all the needed search criteria. |
862 | 846 | * We feed these into an new GF_Query and tack them onto the current object. |
@@ -1082,8 +1066,7 @@ discard block |
||
1082 | 1066 | * |
1083 | 1067 | * @return string |
1084 | 1068 | */ |
1085 | - private function convert_request_key_to_filter_key($key) |
|
1086 | - { |
|
1069 | + private function convert_request_key_to_filter_key($key) { |
|
1087 | 1070 | $field_id = str_replace(['filter_', 'input_'], '', $key); |
1088 | 1071 | |
1089 | 1072 | // calculates field_id, removing 'filter_' and for '_' for advanced fields ( like name or checkbox ) |
@@ -1113,8 +1096,7 @@ discard block |
||
1113 | 1096 | * |
1114 | 1097 | * @return array|false 1 or 2 deph levels, false if not allowed |
1115 | 1098 | */ |
1116 | - public function prepare_field_filter($filter_key, $value, $view, $searchable_fields, $get = []) |
|
1117 | - { |
|
1099 | + public function prepare_field_filter($filter_key, $value, $view, $searchable_fields, $get = []) { |
|
1118 | 1100 | $key = $filter_key; |
1119 | 1101 | $filter_key = explode(':', $filter_key); // field_id, form_id |
1120 | 1102 | |
@@ -1351,8 +1333,7 @@ discard block |
||
1351 | 1333 | * |
1352 | 1334 | * @return string Format of the date in the database |
1353 | 1335 | */ |
1354 | - public static function get_date_field_format(GF_Field_Date $field) |
|
1355 | - { |
|
1336 | + public static function get_date_field_format(GF_Field_Date $field) { |
|
1356 | 1337 | $format = 'm/d/Y'; |
1357 | 1338 | $datepicker = [ |
1358 | 1339 | 'mdy' => 'm/d/Y', |
@@ -1383,8 +1364,7 @@ discard block |
||
1383 | 1364 | * |
1384 | 1365 | * @return string |
1385 | 1366 | */ |
1386 | - public static function get_formatted_date($value = '', $format = 'Y-m-d', $value_format = 'Y-m-d') |
|
1387 | - { |
|
1367 | + public static function get_formatted_date($value = '', $format = 'Y-m-d', $value_format = 'Y-m-d') { |
|
1388 | 1368 | $date = date_create_from_format($value_format, $value); |
1389 | 1369 | |
1390 | 1370 | if (empty($date)) { |
@@ -1401,8 +1381,7 @@ discard block |
||
1401 | 1381 | * |
1402 | 1382 | * @param array $file_paths List of template paths ordered |
1403 | 1383 | */ |
1404 | - public function add_template_path($file_paths) |
|
1405 | - { |
|
1384 | + public function add_template_path($file_paths) { |
|
1406 | 1385 | |
1407 | 1386 | // Index 100 is the default GravityView template path. |
1408 | 1387 | $file_paths[102] = self::$file.'templates/'; |
@@ -1419,8 +1398,7 @@ discard block |
||
1419 | 1398 | * |
1420 | 1399 | * @return bool True: has a `date` or `date_range` field |
1421 | 1400 | */ |
1422 | - private function has_date_field($search_fields) |
|
1423 | - { |
|
1401 | + private function has_date_field($search_fields) { |
|
1424 | 1402 | $has_date = false; |
1425 | 1403 | |
1426 | 1404 | foreach ($search_fields as $k => $field) { |
@@ -1442,8 +1420,7 @@ discard block |
||
1442 | 1420 | * |
1443 | 1421 | * @return void |
1444 | 1422 | */ |
1445 | - public function render_frontend($widget_args, $content = '', $context = '') |
|
1446 | - { |
|
1423 | + public function render_frontend($widget_args, $content = '', $context = '') { |
|
1447 | 1424 | $gravityview_view = GravityView_View::getInstance(); |
1448 | 1425 | |
1449 | 1426 | if (empty($gravityview_view)) { |
@@ -1552,8 +1529,7 @@ discard block |
||
1552 | 1529 | * |
1553 | 1530 | * @return string Sanitized CSS class for the search form |
1554 | 1531 | */ |
1555 | - public static function get_search_class($custom_class = '') |
|
1556 | - { |
|
1532 | + public static function get_search_class($custom_class = '') { |
|
1557 | 1533 | $gravityview_view = GravityView_View::getInstance(); |
1558 | 1534 | |
1559 | 1535 | $search_class = 'gv-search-'.$gravityview_view->search_layout; |
@@ -1582,8 +1558,7 @@ discard block |
||
1582 | 1558 | * |
1583 | 1559 | * @return string |
1584 | 1560 | */ |
1585 | - public static function get_search_form_action() |
|
1586 | - { |
|
1561 | + public static function get_search_form_action() { |
|
1587 | 1562 | $gravityview_view = GravityView_View::getInstance(); |
1588 | 1563 | |
1589 | 1564 | $post_id = $gravityview_view->getPostId() ? $gravityview_view->getPostId() : $gravityview_view->getViewId(); |
@@ -1609,8 +1584,7 @@ discard block |
||
1609 | 1584 | * |
1610 | 1585 | * @return string Label for the search form |
1611 | 1586 | */ |
1612 | - private static function get_field_label($field, $form_field = []) |
|
1613 | - { |
|
1587 | + private static function get_field_label($field, $form_field = []) { |
|
1614 | 1588 | $label = \GV\Utils::_GET('label', \GV\Utils::get($field, 'label')); |
1615 | 1589 | |
1616 | 1590 | if (!$label) { |
@@ -1667,8 +1641,7 @@ discard block |
||
1667 | 1641 | * |
1668 | 1642 | * @return array |
1669 | 1643 | */ |
1670 | - private function get_search_filter_details($field, $context) |
|
1671 | - { |
|
1644 | + private function get_search_filter_details($field, $context) { |
|
1672 | 1645 | $gravityview_view = GravityView_View::getInstance(); |
1673 | 1646 | |
1674 | 1647 | $form = $gravityview_view->getForm(); |
@@ -1748,8 +1721,7 @@ discard block |
||
1748 | 1721 | * |
1749 | 1722 | * @return array The filter choices. |
1750 | 1723 | */ |
1751 | - private function sieve_filter_choices($filter, $context) |
|
1752 | - { |
|
1724 | + private function sieve_filter_choices($filter, $context) { |
|
1753 | 1725 | if (empty($filter['key']) || empty($filter['choices'])) { |
1754 | 1726 | return $filter; // @todo Populate plugins might give us empty choices |
1755 | 1727 | } |
@@ -1827,8 +1799,7 @@ discard block |
||
1827 | 1799 | * |
1828 | 1800 | * @return array Array of user choices (value = ID, text = display name) |
1829 | 1801 | */ |
1830 | - private static function get_created_by_choices($view) |
|
1831 | - { |
|
1802 | + private static function get_created_by_choices($view) { |
|
1832 | 1803 | |
1833 | 1804 | /** |
1834 | 1805 | * filter gravityview/get_users/search_widget. |
@@ -1865,8 +1836,7 @@ discard block |
||
1865 | 1836 | * |
1866 | 1837 | * @return array Array of approval status choices (value = status, text = display name) |
1867 | 1838 | */ |
1868 | - private static function get_is_approved_choices() |
|
1869 | - { |
|
1839 | + private static function get_is_approved_choices() { |
|
1870 | 1840 | $choices = []; |
1871 | 1841 | foreach (GravityView_Entry_Approval_Status::get_all() as $status) { |
1872 | 1842 | $choices[] = [ |
@@ -1883,8 +1853,7 @@ discard block |
||
1883 | 1853 | * |
1884 | 1854 | * @since 1.5.4 |
1885 | 1855 | */ |
1886 | - public static function the_clear_search_button() |
|
1887 | - { |
|
1856 | + public static function the_clear_search_button() { |
|
1888 | 1857 | $gravityview_view = GravityView_View::getInstance(); |
1889 | 1858 | |
1890 | 1859 | if ($gravityview_view->search_clear) { |
@@ -1903,8 +1872,7 @@ discard block |
||
1903 | 1872 | * |
1904 | 1873 | * @return mixed|string Value of request at $name key. Empty string if empty. |
1905 | 1874 | */ |
1906 | - private function rgget_or_rgpost($name) |
|
1907 | - { |
|
1875 | + private function rgget_or_rgpost($name) { |
|
1908 | 1876 | $value = \GV\Utils::_REQUEST($name); |
1909 | 1877 | |
1910 | 1878 | $value = stripslashes_deep($value); |
@@ -1923,8 +1891,7 @@ discard block |
||
1923 | 1891 | * |
1924 | 1892 | * @return array Array required scripts, with `jquery-ui-datepicker` added |
1925 | 1893 | */ |
1926 | - public function add_datepicker_js_dependency($js_dependencies) |
|
1927 | - { |
|
1894 | + public function add_datepicker_js_dependency($js_dependencies) { |
|
1928 | 1895 | $js_dependencies[] = 'jquery-ui-datepicker'; |
1929 | 1896 | |
1930 | 1897 | return $js_dependencies; |
@@ -1938,8 +1905,7 @@ discard block |
||
1938 | 1905 | * |
1939 | 1906 | * @return array |
1940 | 1907 | */ |
1941 | - public function add_datepicker_localization($localizations = [], $view_data = []) |
|
1942 | - { |
|
1908 | + public function add_datepicker_localization($localizations = [], $view_data = []) { |
|
1943 | 1909 | global $wp_locale; |
1944 | 1910 | |
1945 | 1911 | /** |
@@ -1985,8 +1951,7 @@ discard block |
||
1985 | 1951 | * |
1986 | 1952 | * @return void |
1987 | 1953 | */ |
1988 | - public function register_scripts() |
|
1989 | - { |
|
1954 | + public function register_scripts() { |
|
1990 | 1955 | wp_register_script('gv-flexibility', plugins_url('assets/lib/flexibility/flexibility.js', GRAVITYVIEW_FILE), [], \GV\Plugin::$version, true); |
1991 | 1956 | } |
1992 | 1957 | |
@@ -1997,8 +1962,7 @@ discard block |
||
1997 | 1962 | * |
1998 | 1963 | * @return void |
1999 | 1964 | */ |
2000 | - private function maybe_enqueue_flexibility() |
|
2001 | - { |
|
1965 | + private function maybe_enqueue_flexibility() { |
|
2002 | 1966 | if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/MSIE [8-9]/', $_SERVER['HTTP_USER_AGENT'])) { |
2003 | 1967 | wp_enqueue_script('gv-flexibility'); |
2004 | 1968 | } |
@@ -2013,8 +1977,7 @@ discard block |
||
2013 | 1977 | * |
2014 | 1978 | * @return void |
2015 | 1979 | */ |
2016 | - public function enqueue_datepicker() |
|
2017 | - { |
|
1980 | + public function enqueue_datepicker() { |
|
2018 | 1981 | $gravityview_view = GravityView_View::getInstance(); |
2019 | 1982 | |
2020 | 1983 | wp_enqueue_script('jquery-ui-datepicker'); |
@@ -2053,8 +2016,7 @@ discard block |
||
2053 | 2016 | * |
2054 | 2017 | * @return string The datepicker format placeholder, or the PHP date format. |
2055 | 2018 | */ |
2056 | - private function get_datepicker_format($date_format = false) |
|
2057 | - { |
|
2019 | + private function get_datepicker_format($date_format = false) { |
|
2058 | 2020 | $default_format = 'mdy'; |
2059 | 2021 | |
2060 | 2022 | /** |
@@ -2102,8 +2064,7 @@ discard block |
||
2102 | 2064 | * |
2103 | 2065 | * @return void |
2104 | 2066 | */ |
2105 | - public function add_preview_inputs() |
|
2106 | - { |
|
2067 | + public function add_preview_inputs() { |
|
2107 | 2068 | global $wp; |
2108 | 2069 | |
2109 | 2070 | if (!is_preview() || !current_user_can('publish_gravityviews')) { |
@@ -2126,8 +2087,7 @@ discard block |
||
2126 | 2087 | * |
2127 | 2088 | * @return string The operator. |
2128 | 2089 | */ |
2129 | - private function get_operator($get, $key, $allowed, $default) |
|
2130 | - { |
|
2090 | + private function get_operator($get, $key, $allowed, $default) { |
|
2131 | 2091 | $operator = \GV\Utils::get($get, "$key|op", $default); |
2132 | 2092 | |
2133 | 2093 | /** |
@@ -2164,14 +2124,12 @@ discard block |
||
2164 | 2124 | */ |
2165 | 2125 | class GravityView_Widget_Search_Author_GF_Query_Condition extends \GF_Query_Condition |
2166 | 2126 | { |
2167 | - public function __construct($filter, $view) |
|
2168 | - { |
|
2127 | + public function __construct($filter, $view) { |
|
2169 | 2128 | $this->value = $filter['value']; |
2170 | 2129 | $this->view = $view; |
2171 | 2130 | } |
2172 | 2131 | |
2173 | - public function sql($query) |
|
2174 | - { |
|
2132 | + public function sql($query) { |
|
2175 | 2133 | global $wpdb; |
2176 | 2134 | |
2177 | 2135 | $user_meta_fields = [ |
@@ -10,9 +10,9 @@ discard block |
||
10 | 10 | |
11 | 11 | // Make sure that there are choices to display |
12 | 12 | if (empty($search_field['choices'])) { |
13 | - gravityview()->log->debug('search-field-multiselect.php - No choices for field'); |
|
13 | + gravityview()->log->debug('search-field-multiselect.php - No choices for field'); |
|
14 | 14 | |
15 | - return; |
|
15 | + return; |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | /** |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | <select name="<?php echo esc_attr($search_field['name']); ?>[]" id="search-box-<?php echo esc_attr($search_field['name']); ?>" multiple> |
35 | 35 | <option value="" <?php gv_selected('', $search_field['value'], true); ?>><?php echo esc_html($default_option); ?></option> |
36 | 36 | <?php |
37 | - foreach ($search_field['choices'] as $choice) { ?> |
|
37 | + foreach ($search_field['choices'] as $choice) { ?> |
|
38 | 38 | <option value="<?php echo esc_attr($choice['value']); ?>" <?php gv_selected($choice['value'], $search_field['value'], true); ?>><?php echo esc_html($choice['text']); ?></option> |
39 | 39 | <?php } ?> |
40 | 40 | </select> |
@@ -9,8 +9,8 @@ discard block |
||
9 | 9 | $search_field = $gravityview_view->search_field; |
10 | 10 | |
11 | 11 | // Make sure that there are choices to display |
12 | -if (empty($search_field['choices'])) { |
|
13 | - gravityview()->log->debug('search-field-multiselect.php - No choices for field'); |
|
12 | +if ( empty( $search_field[ 'choices' ] ) ) { |
|
13 | + gravityview()->log->debug( 'search-field-multiselect.php - No choices for field' ); |
|
14 | 14 | |
15 | 15 | return; |
16 | 16 | } |
@@ -23,19 +23,19 @@ discard block |
||
23 | 23 | * @param string $default_option Default: `—` (—) |
24 | 24 | * @param string $field_type Field type: "select" or "multiselect" |
25 | 25 | */ |
26 | -$default_option = apply_filters('gravityview/extension/search/select_default', '—', 'multiselect'); |
|
26 | +$default_option = apply_filters( 'gravityview/extension/search/select_default', '—', 'multiselect' ); |
|
27 | 27 | |
28 | 28 | ?> |
29 | 29 | <div class="gv-search-box gv-search-field-multiselect"> |
30 | - <?php if (!gv_empty($search_field['label'], false, false)) { ?> |
|
31 | - <label for="search-box-<?php echo esc_attr($search_field['name']); ?>"><?php echo esc_html($search_field['label']); ?></label> |
|
30 | + <?php if ( ! gv_empty( $search_field[ 'label' ], false, false ) ) { ?> |
|
31 | + <label for="search-box-<?php echo esc_attr( $search_field[ 'name' ] ); ?>"><?php echo esc_html( $search_field[ 'label' ] ); ?></label> |
|
32 | 32 | <?php } ?> |
33 | 33 | <p> |
34 | - <select name="<?php echo esc_attr($search_field['name']); ?>[]" id="search-box-<?php echo esc_attr($search_field['name']); ?>" multiple> |
|
35 | - <option value="" <?php gv_selected('', $search_field['value'], true); ?>><?php echo esc_html($default_option); ?></option> |
|
34 | + <select name="<?php echo esc_attr( $search_field[ 'name' ] ); ?>[]" id="search-box-<?php echo esc_attr( $search_field[ 'name' ] ); ?>" multiple> |
|
35 | + <option value="" <?php gv_selected( '', $search_field[ 'value' ], true ); ?>><?php echo esc_html( $default_option ); ?></option> |
|
36 | 36 | <?php |
37 | - foreach ($search_field['choices'] as $choice) { ?> |
|
38 | - <option value="<?php echo esc_attr($choice['value']); ?>" <?php gv_selected($choice['value'], $search_field['value'], true); ?>><?php echo esc_html($choice['text']); ?></option> |
|
37 | + foreach ( $search_field[ 'choices' ] as $choice ) { ?> |
|
38 | + <option value="<?php echo esc_attr( $choice[ 'value' ] ); ?>" <?php gv_selected( $choice[ 'value' ], $search_field[ 'value' ], true ); ?>><?php echo esc_html( $choice[ 'text' ] ); ?></option> |
|
39 | 39 | <?php } ?> |
40 | 40 | </select> |
41 | 41 | </p> |