PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.7.0
Independent Analytics – WordPress Analytics Plugin v2.7.0
2.15.5 2.15.4 2.15.3 2.15.2 2.15.1 2.15.0 2.14.10 trunk 1.1 1.10 1.10.1 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.17.1 1.17.2 1.17.3 1.17.4 1.18 1.18.1 1.19.0 1.19.1 1.2 1.20.0 1.21.0 1.22.0 1.22.1 1.23.0 1.23.1 1.24.0 1.24.1 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.28.1 1.28.2 1.28.3 1.29.0 1.3 1.30.0 1.30.1 1.4 1.5 1.6 1.7 1.8 1.9 2.0.0 2.0.1 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.10 2.11.2 2.11.3 2.11.4 2.11.5 2.11.6 2.11.7 2.11.8 2.11.9 2.12.0 2.12.1 2.12.2 2.13.1 2.13.2 2.13.5 2.13.6 2.14.0 2.14.1 2.14.2 2.14.4 2.14.6 2.14.7 2.14.8 2.14.9 2.2.0 2.2.1 2.3.1 2.3.2 2.4.2 2.4.3 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.6.3 2.6.4 2.7.0 2.7.1 2.7.2 2.7.3 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7
independent-analytics / IAWP / Filters.php
independent-analytics / IAWP Last commit date
AJAX 2 years ago Admin_Page 2 years ago Custom_WordPress_Columns 2 years ago Data_Pruning 2 years ago Date_Range 2 years ago Email_Reports 2 years ago Filter_Lists 2 years ago Form_Submissions 2 years ago Interval 2 years ago Menu_Bar_Stats 2 years ago Migrations 2 years ago Models 2 years ago Public_API 2 years ago Rows 2 years ago Statistics 2 years ago Tables 2 years ago Utils 2 years ago Campaign_Builder.php 2 years ago Capability_Manager.php 2 years ago Chart.php 2 years ago Chart_Geo.php 2 years ago Cron_Manager.php 2 years ago Current_Traffic_Finder.php 2 years ago Dashboard_Options.php 2 years ago Dashboard_Widget.php 2 years ago Database.php 2 years ago Database_Manager.php 2 years ago Empty_Report_Option.php 2 years ago Env.php 2 years ago Filters.php 2 years ago Geo_Database_Background_Job.php 2 years ago Geo_Database_Manager.php 2 years ago Geoposition.php 2 years ago Icon_Directory.php 2 years ago Icon_Directory_Factory.php 2 years ago Illuminate_Builder.php 2 years ago Independent_Analytics.php 2 years ago Interrupt.php 2 years ago Known_Referrers.php 2 years ago Patch.php 2 years ago Plugin_Conflict_Detector.php 2 years ago Plugin_Group.php 2 years ago Plugin_Group_Option.php 2 years ago Query.php 2 years ago Query_Taps.php 2 years ago Quick_Stats.php 2 years ago REST_API.php 2 years ago Real_Time.php 2 years ago Report.php 2 years ago Report_Finder.php 2 years ago Report_Options_Parser.php 2 years ago Resource_Identifier.php 2 years ago Settings.php 2 years ago Sort_Configuration.php 2 years ago Track_Resource_Changes.php 2 years ago View.php 2 years ago View_Counter.php 2 years ago Visitors_Over_Time_Finder.php 2 years ago WP_Option_Cache_Bust.php 2 years ago WooCommerce_Order.php 2 years ago WooCommerce_Referrer_Meta_Box.php 2 years ago
Filters.php
247 lines
1 <?php
2
3 namespace IAWP;
4
5 use IAWP\Tables\Columns\Column;
6 use IAWP\Utils\WordPress_Site_Date_Format_Pattern;
7 /** @internal */
8 class Filters
9 {
10 public function get_filters_html(array $columns) : string
11 {
12 $opts = \IAWP\Dashboard_Options::getInstance();
13 \ob_start();
14 ?>
15 <div class="modal-parent filters"
16 data-controller="filters"
17 data-filters-filters-value="<?php
18 echo \esc_attr(\json_encode($opts->filters()));
19 ?>"
20 >
21 <span class="dashicons dashicons-filter"></span>
22 <div id="filter-condition-buttons" data-filters-target="conditionButtons" class="filter-condition-buttons">
23 <?php
24 echo $this->condition_buttons_html($opts->filters());
25 ?>
26 </div>
27 <button id="filters-button" class="filters-button"
28 data-action="filters#toggleModal"
29 data-filters-target="modalButton"
30 >
31 <span class="iawp-label"><?php
32 \esc_html_e('+ Add Filter', 'independent-analytics');
33 ?></span>
34 </button>
35 <div id="modal-filters"
36 class="iawp-modal large"
37 data-filters-target="modal"
38 >
39 <div class="modal-inner">
40 <div class="title-small"><?php
41 \esc_html_e('Filters', 'independent-analytics');
42 ?></div>
43 <div id="filters" data-filters-target="filters" class="filters" data-filters="[]">
44 </div>
45 <template data-filters-target="blueprint">
46 <?php
47 echo $this->get_condition_html($columns);
48 ?>
49 </template>
50 <div>
51 <button id="add-condition" class="iawp-text-button"
52 data-action="filters#addCondition"
53 >
54 <?php
55 \esc_html_e('+ Add another condition', 'independent-analytics');
56 ?>
57 </button>
58 </div>
59 <div class="actions">
60 <button id="filters-apply" class="iawp-button purple"
61 data-action="filters#apply"
62 >
63 <?php
64 \esc_html_e('Apply', 'independent-analytics');
65 ?>
66 </button>
67 <button id="filters-reset" class="iawp-button ghost-purple"
68 data-action="filters#reset"
69 data-filters-target="reset"
70 disabled
71 >
72 <?php
73 \esc_html_e('Reset', 'independent-analytics');
74 ?>
75 </button>
76 </div>
77 </div>
78 </div>
79 </div><?php
80 $html = \ob_get_contents();
81 \ob_end_clean();
82 return $html;
83 }
84 public function get_condition_html(array $columns)
85 {
86 \ob_start();
87 ?>
88 <div class="condition" data-filters-target="condition">
89 <div class="input-group">
90 <div>
91 <?php
92 echo self::get_inclusion_selects();
93 ?>
94 </div>
95 <div>
96 <?php
97 self::get_column_select($columns);
98 ?>
99 </div>
100 <div class="operator-select-container">
101 <?php
102 echo self::get_all_operator_selects();
103 ?>
104 </div>
105 <div class="operand-field-container">
106 <?php
107 echo self::get_all_operand_fields($columns);
108 ?>
109 </div>
110 </div>
111 <button class="delete-button" data-action="filters#removeCondition">
112 <span class="dashicons dashicons-no"></span></button>
113 </div>
114 <?php
115 $html = \ob_get_contents();
116 \ob_end_clean();
117 return $html;
118 }
119 public function condition_buttons_html(array $filters) : string
120 {
121 \ob_start();
122 for ($i = 0; $i < \count($filters); $i++) {
123 if ($i == 2) {
124 ?>
125 <button class="filters-condition-button"
126 data-action="filters#toggleModal"
127 data-filters-target="modalButton"><?php
128 \printf(\esc_html__('+%d More', 'independent-analytics'), \count($filters) - 2);
129 ?></button><?php
130 break;
131 }
132 ?>
133 <button class="filters-condition-button"
134 data-action="filters#toggleModal"
135 data-filters-target="modalButton"><?php
136 echo \wp_kses_post($filters[$i]->html_description());
137 ?></button>
138 <?php
139 }
140 $html = \ob_get_contents();
141 \ob_end_clean();
142 return $html;
143 }
144 private function get_inclusion_selects()
145 {
146 $html = '<select class="filters-include" data-filters-target="inclusion">';
147 $html .= '<option value="include">' . \esc_html__('Include', 'independent-analytics') . '</option>';
148 $html .= '<option value="exclude">' . \esc_html__('Exclude', 'independent-analytics') . '</option>';
149 $html .= '</select>';
150 return $html;
151 }
152 /**
153 * @param Column[] $columns
154 *
155 * @return void
156 */
157 private function get_column_select(array $columns)
158 {
159 $plugin_groups = \IAWP\Plugin_Group::get_plugin_groups();
160 $column_sections = [];
161 foreach ($columns as $column) {
162 $plugin_group_id = $column->plugin_group();
163 $section_name = '';
164 $plugin_group = null;
165 foreach ($plugin_groups as $a_plugin_group) {
166 if ($a_plugin_group->id() === $plugin_group_id) {
167 $section_name = $a_plugin_group->name();
168 $plugin_group = $a_plugin_group;
169 }
170 }
171 if (!$plugin_group->has_active_group_plugins()) {
172 continue;
173 }
174 if (!\is_null($column->plugin_group_header())) {
175 $section_name = $plugin_group->name() . ' - ' . $column->plugin_group_header();
176 }
177 if (!\array_key_exists($section_name, $column_sections)) {
178 $column_sections[$section_name] = ['plugin_group' => $plugin_group, 'columns' => []];
179 }
180 \array_push($column_sections[$section_name]['columns'], $column);
181 }
182 echo \IAWPSCOPED\iawp_blade()->run('partials.filter-column-select', ['column_sections' => $column_sections]);
183 }
184 private function get_all_operator_selects()
185 {
186 $html = '';
187 foreach (self::get_data_types() as $data_type) {
188 $html .= '<select data-filters-target="operator" data-type="' . \esc_attr($data_type) . '" data-testid="' . \esc_attr($data_type) . '-operator">';
189 foreach (self::get_operators($data_type) as $key => $value) {
190 $html .= '<option value="' . \esc_attr($key) . '">' . \esc_html($value) . '</option>';
191 }
192 $html .= '</select>';
193 }
194 return $html;
195 }
196 private function get_all_operand_fields(array $columns)
197 {
198 $html = '';
199 foreach ($columns as $column) {
200 switch ($column->type()) {
201 case 'string':
202 $html .= '<input data-filters-target="operand" data-action="keydown->filters#operandKeyDown filters#operandChange" data-column="' . \esc_attr($column->id()) . '" type="text" data-testid="' . \esc_attr($column->id()) . '-operand" placeholder="' . \esc_attr($column->filter_placeholder()) . '" />';
203 break;
204 case 'int':
205 $html .= '<input data-filters-target="operand" data-action="keydown->filters#operandKeyDown filters#operandChange" data-column="' . \esc_attr($column->id()) . '" type="number" data-testid="' . \esc_attr($column->id()) . '-operand" placeholder="' . \esc_attr($column->filter_placeholder()) . '" />';
206 break;
207 case 'date':
208 $html .= '<input type="text"
209 data-filters-target="operand"
210 data-action="keydown->filters#operandKeyDown filters#operandChange"
211 data-column="' . \esc_attr($column->id()) . '"
212 data-controller="easepick"
213 data-css="' . \esc_url(\IAWPSCOPED\iawp_url_to('dist/styles/easepick/datepicker.css')) . '" data-dow="' . \absint(\IAWPSCOPED\iawp()->get_option('iawp_dow', 1)) . '"
214 data-format="' . \esc_attr(WordPress_Site_Date_Format_Pattern::for_javascript()) . '"
215 data-testid="' . \esc_attr($column->id()) . '-operand" />';
216 break;
217 case 'select':
218 $html .= '<select data-filters-target="operand" data-column="' . \esc_attr($column->id()) . '" data-testid="' . \esc_attr($column->id()) . '-operand">';
219 foreach ($column->options() as $option) {
220 $html .= '<option value="' . \esc_attr($option[0]) . '">' . \esc_html($option[1]) . '</option>';
221 }
222 $html .= '</select>';
223 break;
224 }
225 }
226 return $html;
227 }
228 private function get_data_types()
229 {
230 return ['string', 'int', 'date', 'select'];
231 }
232 private function get_operators(string $data_type)
233 {
234 if ($data_type == 'string') {
235 return ['contains' => \esc_html__('Contains', 'independent-analytics'), 'exact' => \esc_html__('Exactly matches', 'independent-analytics')];
236 } elseif ($data_type == 'int') {
237 return ['greater' => \esc_html__('Greater than', 'independent-analytics'), 'lesser' => \esc_html__('Less than', 'independent-analytics'), 'equal' => \esc_html__('Equal to', 'independent-analytics')];
238 } elseif ($data_type == 'select') {
239 return ['is' => \esc_html__('Is', 'independent-analytics'), 'isnt' => \esc_html__('Isn\'t', 'independent-analytics')];
240 } elseif ($data_type == 'date') {
241 return ['before' => \esc_html__('Before', 'independent-analytics'), 'after' => \esc_html__('After', 'independent-analytics'), 'on' => \esc_html__('On', 'independent-analytics')];
242 } else {
243 return null;
244 }
245 }
246 }
247