PluginProbe ʕ •ᴥ•ʔ
Independent Analytics – WordPress Analytics Plugin / 2.14.8
Independent Analytics – WordPress Analytics Plugin v2.14.8
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 3 months ago Admin_Page 3 months ago Click_Tracking 5 months ago ColumnOptions 6 months ago Cron 9 months ago Custom_WordPress_Columns 8 months ago Data_Pruning 5 months ago Date_Picker 3 months ago Date_Range 5 months ago Ecommerce 5 months ago Email_Reports 3 months ago Examiner 3 months ago Favicon 5 months ago Form_Submissions 5 months ago Integrations 3 months ago Interval 1 year ago Journey 5 months ago Migrations 5 months ago Models 5 months ago Overview 3 months ago Public_API 5 months ago Rows 3 months ago Statistics 3 months ago Tables 3 months ago Utils 5 months ago Views 5 months ago WooCommerceOrderMetaBox 5 months ago ActivationLifecycle.php 3 months ago Admin_Bar_Stats.php 3 months ago Appearance.php 1 year ago Campaign_Builder.php 3 months ago Capability_Manager.php 3 months ago Chart.php 3 months ago Chart_Data.php 1 year ago Click_Tracking.php 3 months ago ComplianzIntegration.php 3 months ago Cron_Job.php 5 months ago Cron_Manager.php 5 months ago Current_Traffic_Finder.php 1 year ago Dashboard_Options.php 6 months ago Dashboard_Widget.php 2 years ago Database.php 8 months ago Database_Manager.php 5 months ago Empty_Report_Option.php 2 years ago Env.php 6 months ago Examiner_Config.php 11 months ago FetchFaviconsJob.php 5 months ago Filters.php 3 months ago Geo_Database_Health_Check_Job.php 9 months ago Geo_Database_Manager.php 6 months ago Geoposition.php 1 year ago Icon_Directory.php 6 months ago Icon_Directory_Factory.php 2 years ago Illuminate_Builder.php 10 months ago Independent_Analytics.php 5 months ago Interrupt.php 3 months ago Known_Referrers.php 6 months ago MainWP.php 1 year ago Map.php 9 months ago Map_Data.php 1 year ago Migration_Fixer_Job.php 5 months ago Patch.php 1 year ago Payload_Validator.php 9 months ago Plugin_Conflict_Detector.php 6 months ago Plugin_Group.php 6 months ago Plugin_Group_Option.php 2 years ago Query.php 1 year ago Query_Taps.php 3 months ago Quick_Stats.php 3 months ago REST_API.php 3 months ago Real_Time.php 3 months ago Report.php 1 year ago Report_Finder.php 6 months ago Report_Options_Parser.php 9 months ago Resource_Identifier.php 9 months ago Settings.php 3 months ago Sort_Configuration.php 9 months ago Tables.php 8 months ago Track_Resource_Changes.php 1 year ago View_Counter.php 6 months ago Views_Over_Time_Finder.php 1 year ago VisitorSaltRefreshInterval.php 6 months ago WP_Option_Cache_Bust.php 2 years ago
Filters.php
290 lines
1 <?php
2
3 namespace IAWP;
4
5 use IAWP\Tables\Columns\Column;
6 use IAWP\Utils\Format;
7 use IAWP\Utils\Security;
8 /** @internal */
9 class Filters
10 {
11 public function get_filters_html(array $columns) : string
12 {
13 $options = \IAWP\Dashboard_Options::getInstance();
14 \ob_start();
15 ?>
16 <div class="modal-parent filters"
17 data-controller="filters"
18 data-filters-filters-value="<?php
19 echo \esc_attr(\json_encode($options->raw_filters()));
20 ?>"
21 data-filters-filter-logic-value="<?php
22 echo Security::attr($options->filter_logic());
23 ?>"
24 >
25 <span class="dashicons dashicons-filter"></span>
26 <div id="filter-condition-buttons" data-filters-target="conditionButtons" class="filter-condition-buttons">
27 <?php
28 echo $this->condition_buttons_html($options->filters());
29 ?>
30 </div>
31 <button id="filters-button" class="filters-button"
32 data-action="filters#toggleModal"
33 data-filters-target="modalButton"
34 >
35 <span class="iawp-label"><?php
36 \esc_html_e('+ Add Filter', 'independent-analytics');
37 ?></span>
38 </button>
39 <div id="modal-filters"
40 class="iawp-modal large"
41 data-filters-target="modal"
42 >
43 <div class="modal-inner">
44 <?php
45 $select = '<select name="filter_logic" data-filters-target="filterLogic" id="filter_logic" data-action="filters#changeFilterLogic">
46 <option value="and" ' . ($options->filter_logic() === 'and' ? 'selected' : '') . '>' . \esc_html__('all', 'independent-analytics') . '</option>
47 <option value="or" ' . ($options->filter_logic() === 'or' ? 'selected' : '') . '>' . \esc_html__('any', 'independent-analytics') . '</option>
48 </select>';
49 ?>
50 <div class="title-small filter-title">
51 <?php
52 \printf(\__('If %s of the conditions apply', 'independent-analytics'), $select);
53 ?>
54 <span data-filters-target="spinner" class="dashicons dashicons-update iawp-spin hidden"></span>
55 </div>
56 <div id="filters" data-filters-target="filters" class="filters" data-filters="[]">
57 </div>
58 <template data-filters-target="blueprint">
59 <?php
60 echo $this->get_condition_html($columns);
61 ?>
62 </template>
63 <div>
64 <button id="add-condition" class="iawp-text-button"
65 data-action="filters#addCondition"
66 >
67 <?php
68 \esc_html_e('+ Add another condition', 'independent-analytics');
69 ?>
70 </button>
71 </div>
72 <div class="actions">
73 <button id="filters-apply" class="iawp-button purple"
74 data-action="filters#apply"
75 >
76 <?php
77 \esc_html_e('Apply', 'independent-analytics');
78 ?>
79 </button>
80 <button id="filters-reset" class="iawp-button ghost-purple"
81 data-action="filters#reset"
82 data-filters-target="reset"
83 disabled
84 >
85 <?php
86 \esc_html_e('Reset', 'independent-analytics');
87 ?>
88 </button>
89 </div>
90 </div>
91 </div>
92 </div><?php
93 $html = \ob_get_contents();
94 \ob_end_clean();
95 return $html;
96 }
97 public function get_condition_html(array $columns)
98 {
99 \ob_start();
100 ?>
101 <div class="condition" data-filters-target="condition">
102 <div class="input-group">
103 <div>
104 <?php
105 echo self::get_inclusion_selects();
106 ?>
107 </div>
108 <div>
109 <?php
110 self::get_column_select($columns);
111 ?>
112 </div>
113 <div class="operator-select-container">
114 <?php
115 echo self::get_all_operator_selects();
116 ?>
117 </div>
118 <div class="operand-field-container">
119 <?php
120 echo self::get_all_operand_fields($columns);
121 ?>
122 </div>
123 </div>
124 <button class="delete-button" data-action="filters#removeCondition">
125 <span class="dashicons dashicons-no"></span></button>
126 </div>
127 <?php
128 $html = \ob_get_contents();
129 \ob_end_clean();
130 return $html;
131 }
132 public function condition_buttons_html(array $filters) : string
133 {
134 \ob_start();
135 for ($i = 0; $i < \count($filters); $i++) {
136 if ($i == 2) {
137 ?>
138 <button class="filters-condition-button"
139 data-action="filters#toggleModal"
140 data-filters-target="modalButton"><?php
141 \printf(\esc_html__('+%d More', 'independent-analytics'), \count($filters) - 2);
142 ?></button><?php
143 break;
144 }
145 ?>
146 <button class="filters-condition-button"
147 data-action="filters#toggleModal"
148 data-filters-target="modalButton"><?php
149 echo \wp_kses_post($filters[$i]->html_description());
150 ?></button>
151 <?php
152 }
153 $html = \ob_get_contents();
154 \ob_end_clean();
155 return $html;
156 }
157 private function get_inclusion_selects()
158 {
159 $html = '<select class="filters-include" data-filters-target="inclusion">';
160 $html .= '<option value="include">' . \esc_html__('Include', 'independent-analytics') . '</option>';
161 $html .= '<option value="exclude">' . \esc_html__('Exclude', 'independent-analytics') . '</option>';
162 $html .= '</select>';
163 return $html;
164 }
165 /**
166 * @param Column[] $columns
167 *
168 * @return void
169 */
170 private function get_column_select(array $columns)
171 {
172 $plugin_groups = \IAWP\Plugin_Group::get_plugin_groups();
173 $column_sections = [];
174 foreach ($columns as $column) {
175 $plugin_group_id = $column->plugin_group();
176 $section_name = '';
177 $plugin_group = null;
178 foreach ($plugin_groups as $a_plugin_group) {
179 if ($a_plugin_group->id() === $plugin_group_id) {
180 $section_name = $a_plugin_group->name();
181 $plugin_group = $a_plugin_group;
182 }
183 }
184 if (!$plugin_group->has_active_group_plugins()) {
185 continue;
186 }
187 if (!\is_null($column->plugin_group_header())) {
188 $section_name = $plugin_group->name() . ' - ' . $column->plugin_group_header();
189 }
190 if (!\array_key_exists($section_name, $column_sections)) {
191 $column_sections[$section_name] = ['plugin_group' => $plugin_group, 'columns' => []];
192 }
193 \array_push($column_sections[$section_name]['columns'], $column);
194 }
195 echo \IAWPSCOPED\iawp_render('partials.filter-column-select', ['column_sections' => $column_sections]);
196 }
197 private function get_all_operator_selects()
198 {
199 $html = '';
200 foreach (self::get_data_types() as $data_type) {
201 $html .= '<select data-filters-target="operator" data-type="' . \esc_attr($data_type) . '" data-testid="' . \esc_attr($data_type) . '-operator">';
202 foreach (self::get_operators($data_type) as $key => $value) {
203 $html .= '<option value="' . \esc_attr($key) . '">' . \esc_html($value) . '</option>';
204 }
205 $html .= '</select>';
206 }
207 return $html;
208 }
209 private function get_all_operand_fields(array $columns)
210 {
211 $html = '';
212 foreach ($columns as $column) {
213 switch ($column->type()) {
214 case 'string':
215 $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()) . '" />';
216 break;
217 case 'int':
218 $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()) . '" />';
219 break;
220 case 'date':
221 $html .= '<input type="text"
222 data-filters-target="operand"
223 data-action="keydown->filters#operandKeyDown filters#operandChange"
224 data-column="' . \esc_attr($column->id()) . '"
225 data-controller="easepick"
226 data-css="' . \esc_url(\IAWPSCOPED\iawp_url_to('dist/styles/easepick/datepicker.css')) . '" data-dow="' . \absint(\IAWPSCOPED\iawp()->get_option('iawp_dow', 1)) . '"
227 data-format="' . \esc_attr(Format::date_for_javascript()) . '"
228 data-testid="' . \esc_attr($column->id()) . '-operand" />';
229 break;
230 case 'select':
231 $html .= '<select data-filters-target="operand" data-column="' . \esc_attr($column->id()) . '" data-testid="' . \esc_attr($column->id()) . '-operand">';
232 $html .= $this->get_select_options($column);
233 $html .= '</select>';
234 break;
235 }
236 }
237 return $html;
238 }
239 private function get_select_options(Column $column) : string
240 {
241 $html = '';
242 $parents = [];
243 $children_by_parent_id = [];
244 foreach ($column->options()->all() as $option) {
245 if ($option->is_parent()) {
246 $parents[] = $option;
247 continue;
248 }
249 if (!\array_key_exists($option->parent_id, $children_by_parent_id)) {
250 $children_by_parent_id[$option->parent_id] = [];
251 }
252 $children_by_parent_id[$option->parent_id][] = $option;
253 }
254 $has_nesting = \count($children_by_parent_id) > 0;
255 foreach ($parents as $parent) {
256 if ($has_nesting) {
257 $html .= '<optgroup label="' . \esc_attr($parent->label) . '">';
258 }
259 $html .= '<option value="' . \esc_attr($parent->id) . '">' . \esc_html($parent->label) . '</option>';
260 if (\array_key_exists($parent->id, $children_by_parent_id)) {
261 foreach ($children_by_parent_id[$parent->id] as $child) {
262 $html .= '<option value="' . \esc_attr($child->id) . '">' . \esc_html($child->label) . '</option>';
263 }
264 }
265 if ($has_nesting) {
266 $html .= '</optgroup>';
267 }
268 }
269 return $html;
270 }
271 private function get_data_types()
272 {
273 return ['string', 'int', 'date', 'select'];
274 }
275 private function get_operators(string $data_type)
276 {
277 if ($data_type == 'string') {
278 return ['contains' => \esc_html__('Contains', 'independent-analytics'), 'exact' => \esc_html__('Exactly matches', 'independent-analytics')];
279 } elseif ($data_type == 'int') {
280 return ['greater' => \esc_html__('Greater than', 'independent-analytics'), 'lesser' => \esc_html__('Less than', 'independent-analytics'), 'equal' => \esc_html__('Equal to', 'independent-analytics')];
281 } elseif ($data_type == 'select') {
282 return ['is' => \esc_html__('Is', 'independent-analytics'), 'isnt' => \esc_html__('Isn\'t', 'independent-analytics')];
283 } elseif ($data_type == 'date') {
284 return ['before' => \esc_html__('Before', 'independent-analytics'), 'after' => \esc_html__('After', 'independent-analytics'), 'on' => \esc_html__('On', 'independent-analytics')];
285 } else {
286 return null;
287 }
288 }
289 }
290