PluginProbe
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts / 2.3.1
Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts v2.3.1
2.7.7 2.7.6 2.7.5 2.7.4 trunk 1.3 2.0.4 2.0.6 2.1.91 2.2.4 2.2.7 2.2.9 2.3.1 2.3.10 2.4.10 2.4.2 2.4.4 2.4.5 2.4.6 2.4.7 2.4.8 2.4.9 2.6.0 2.6.1 2.7.0 All 28 releases
insert-php / admin / metaboxes / view-options.php

view-options.php in Woody Code Snippets – Insert PHP, CSS, JS, and Header/Footer Scripts 2.3.1, at admin/metaboxes/view-options.php

482 lines 21.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 class WINP_ViewOptionsMetaBox extends WINP_MetaBox {
8
9 /**
10 * {@inheritDoc}
11 *
12 * @var string
13 */
14 public $title;
15
16 /**
17 * {@inheritDoc}
18 *
19 * @var string
20 */
21 public $priority = 'core';
22
23 /**
24 * {@inheritDoc}
25 *
26 * @var string
27 */
28 public $css_class = 'factory-bootstrap-423 factory-fontawesome-000';
29
30 /**
31 * WINP_ViewOptionsMetaBox constructor.
32 *
33 * @param Wbcr_Factory422_Plugin $plugin
34 */
35 public function __construct( Wbcr_Factory422_Plugin $plugin ) {
36 parent::__construct( $plugin );
37
38 $this->title = __( 'Conditional execution logic for the snippet', 'insert-php' );
39 }
40
41 /**
42 * {@inheritDoc}
43 *
44 * @param Wbcr_Factory422_ScriptList $scripts A set of scripts to include.
45 * @param Wbcr_Factory422_StyleList $styles A set of style to include.
46 *
47 * @return void
48 */
49 public function configure( $scripts, $styles ) {
50 $styles->add( WINP_PLUGIN_URL . '/admin/assets/css/view-opt.css' );
51 $scripts->add( WINP_PLUGIN_URL . '/admin/assets/js/view-opt.js' );
52 }
53
54 /**
55 * {@inheritDoc}
56 *
57 * Мы переписываем родительский метод затем, чтобы удалить лишние nonce fields
58 *
59 * @author Alexander Kovalev <alex.kovalevv@gmail.com>
60 * @since 2.2.6 Добавлен
61 */
62 public function show() {
63 ob_start();
64 $this->print_conditions_markup();
65 $content = ob_get_clean();
66
67 echo $content;
68 }
69
70 /**
71 * Генерирует и печает html разметку для работы с условной логикой
72 *
73 * @since 2.2.6 Изменил имя метода, добавил nonce field wbcr_inp_snippet_conditions_metabox_nonce
74 */
75 private function print_conditions_markup() {
76 $post_id = get_the_ID();
77
78 // filter parameters
79 $grouped_filter_params = [
80 [
81 'id' => 'user',
82 'title' => __( 'User', 'insert-php' ),
83 'items' => [
84 [
85 'id' => 'user-role',
86 'title' => __( 'Role', 'insert-php' ),
87 'type' => 'select',
88 'values' => [
89 'type' => 'ajax',
90 'action' => 'wbcr_inp_ajax_get_user_roles'
91 ],
92 'description' => __( 'A role of the user who views your website. The role "guest" is applied to unregistered users.', 'insert-php' )
93 ],
94 [
95 'id' => 'user-registered',
96 'title' => __( 'Registration Date', 'insert-php' ),
97 'type' => 'date',
98 'description' => __( 'The date when the user who views your website was registered. For unregistered users this date always equals to 1 Jan 1970.', 'insert-php' )
99 ],
100 /*array(
101 'id' => 'user-mobile',
102 'title' => __('Mobile Device', 'insert-php'),
103 'type' => 'select',
104 'values' => array(
105 array('value' => 'yes', 'title' => __('Yes', 'insert-php')),
106 array('value' => 'no', 'title' => __('No', 'insert-php'))
107 ),
108 'description' => __('Determines whether the user views your website from mobile device or not.', 'insert-php')
109 ),*/
110 [
111 'id' => 'user-cookie-name',
112 'title' => __( 'Cookie Name', 'insert-php' ),
113 'type' => 'text',
114 'onlyEquals' => true,
115 'description' => __( 'Determines whether the user\'s browser has a cookie with a given name.', 'insert-php' )
116 ]
117 ]
118 ],
119 [
120 'id' => 'location',
121 'title' => __( 'Location', 'insert-php' ),
122 'items' => [
123 [
124 'id' => 'location-page',
125 'title' => __( 'Current Page', 'insert-php' ),
126 'type' => 'text',
127 'description' => __( 'An URL of the current page where a user who views your website is located.', 'insert-php' )
128 ],
129 [
130 'id' => 'location-referrer',
131 'title' => __( 'Current Referrer', 'insert-php' ),
132 'type' => 'text',
133 'description' => __( 'A referrer URL which has brought a user to the current page.', 'insert-php' )
134 ],
135 [
136 'id' => 'location-post-type',
137 'title' => __( 'Post type', 'insert-php' ),
138 'type' => 'select',
139 'values' => [
140 'type' => 'ajax',
141 'action' => 'wbcr_inp_ajax_get_post_types'
142 ],
143 'description' => __( 'A post type of the current page.', 'insert-php' )
144 ],
145 [
146 'id' => 'location-taxonomy',
147 'title' => __( 'Taxonomy', 'insert-php' ),
148 'type' => 'select',
149 'values' => [
150 'type' => 'ajax',
151 'action' => 'wbcr_inp_ajax_get_taxonomies'
152 ],
153 'description' => __( 'A taxonomy of the current page.', 'insert-php' )
154 ],
155 [
156 'id' => 'location-some-page',
157 'title' => __( 'Page', 'insert-php' ),
158 'type' => 'select',
159 'values' => [
160 'type' => 'ajax',
161 'action' => 'wbcr_inp_ajax_get_page_list'
162 ],
163 'description' => __( 'List of specific pages.', 'insert-php' )
164 ]
165 ]
166 ],
167 [
168 'id' => 'technology',
169 'title' => __( 'Technology', 'insert-php' ) . ' (PRO)',
170 'items' => [
171 [
172 'id' => 'technology-addblocker',
173 'title' => __( 'Addblocker', 'insert-php' ),
174 'type' => 'disabled',
175 'description' => __( 'Determines whether the user use Addblocker on website.', 'insert-php' ),
176 ],
177 [
178 'id' => 'technology-browser',
179 'title' => __( 'Browser', 'insert-php' ),
180 'type' => 'disabled',
181 'description' => __( 'Determines whether the user use selected browser.', 'insert-php' ),
182 ],
183 [
184 'id' => 'technology-use-cookie',
185 'title' => __( 'Use cookie', 'insert-php' ),
186 'type' => 'disabled',
187 'description' => __( 'Determines whether the user use cookie on website.', 'insert-php' ),
188 ],
189 [
190 'id' => 'technology-use-javascript',
191 'title' => __( 'Use javascript', 'insert-php' ),
192 'type' => 'disabled',
193 'description' => __( 'Determines whether the user use javascript on website.', 'insert-php' ),
194 ],
195 [
196 'id' => 'technology-operating-system',
197 'title' => __( 'Operating system', 'insert-php' ),
198 'type' => 'disabled',
199 'description' => __( 'Determines whether the user use selected OS.', 'insert-php' ),
200 ],
201 [
202 'id' => 'technology-device-type',
203 'title' => __( 'Device type', 'insert-php' ),
204 'type' => 'disabled',
205 'description' => __( 'Determines whether the user use selected device type.', 'insert-php' ),
206 ],
207 ],
208 ],
209 [
210 'id' => 'auditory',
211 'title' => __( 'Auditory', 'insert-php' ) . ' (PRO)',
212 'items' => [
213 [
214 'id' => 'auditory-country',
215 'title' => __( 'User country', 'insert-php' ),
216 'type' => 'disabled',
217 'description' => __( 'Geolocation', 'insert-php' ),
218 ],
219 [
220 'id' => 'auditory-viewing',
221 'title' => __( 'Viewing depth', 'insert-php' ),
222 'type' => 'disabled',
223 'description' => __( 'The number of pages viewed by the user per session', 'insert-php' ),
224 ],
225 [
226 'id' => 'auditory-attendance',
227 'title' => __( 'Attendance by time of day', 'insert-php' ),
228 'type' => 'disabled',
229 'description' => __( 'The time interval during which the user entered', 'insert-php' ),
230 ],
231 [
232 'id' => 'auditory-visits',
233 'title' => __( 'Total number of visits', 'insert-php' ),
234 'type' => 'disabled',
235 'description' => __( 'The total number of sessions opened by the user', 'insert-php' ),
236 ],
237 ],
238 ],
239 ];
240
241 $grouped_filter_params = apply_filters( 'wbcr/inp/visibility/filter_params', $grouped_filter_params );
242
243 $filterParams = [];
244 foreach ( (array) $grouped_filter_params as $filter_group ) {
245 $filterParams = array_merge( $filterParams, $filter_group['items'] );
246 }
247
248 // templates
249 $templates = [
250 [
251 'id' => 'hide_for_members',
252 'title' => __( '[Hide For Members]: Show the locker only for guests', 'insert-php' ),
253 'filter' => [
254 'type' => 'showif',
255 'conditions' => [
256 [
257 'type' => 'condition',
258 'param' => 'user-role',
259 'operator' => 'equals',
260 'value' => 'guest'
261 ]
262 ]
263 ]
264 ],
265 [
266 'id' => 'mobile',
267 'title' => __( '[Hide On Mobile]: Hide the locker on mobile devices', 'insert-php' ),
268 'filter' => [
269 'type' => 'hideif',
270 'conditions' => [
271 [
272 'type' => 'condition',
273 'param' => 'user-mobile',
274 'operator' => 'equals',
275 'value' => 'yes'
276 ]
277 ]
278 ]
279 ],
280 [
281 'id' => 'delayed_lock',
282 'title' => __( '[Delayed Lock]: Show the locker only in posts older than 5 days', 'insert-php' ),
283 'filter' => [
284 'type' => 'showif',
285 'conditions' => [
286 [
287 'type' => 'condition',
288 'param' => 'post-published',
289 'operator' => 'older',
290 'value' => [
291 'type' => 'relative',
292 'unitsCount' => 5,
293 'units' => 'days'
294 ]
295 ]
296 ]
297 ]
298 ]
299 ];
300
301 $templates = apply_filters( 'wbcr/inp/visibility/filter_templates', $templates );
302 ?>
303 <div class="factory-fontawesome-000 winp-advanded-options">
304 <div class="winp-empty" id="winp-advanced-visability-options">
305 <script>
306 window.winp = window.winp || {};
307 window.winp.filtersParams = <?php echo json_encode( $filterParams ) ?>;
308 window.winp.templates = <?php echo json_encode( $templates ) ?>;
309 </script>
310 <div class="winp-editor-wrap">
311 <div class="winp-when-empty">
312 <?php _e( 'No filters specified. <a href="#" class="winp-add-filter">Click here</a> to add one.', 'insert-php' ) ?>
313 </div>
314 <div class="winp-filters"></div>
315 </div>
316 <div class="winp-filter winp-template">
317 <div class="winp-point"></div>
318 <div class="winp-head">
319 <div class="winp-left">
320 <span style="margin-left: 0;">
321 <strong><?php _e( 'Show IF', 'insert-php' ) ?>:</strong>
322 </span>
323 <select class="winp-filter-type">
324 <option value="showif"><?php _e( 'Display On IF', 'insert-php' ); ?></option>
325 <option value="hideif"><?php _e( 'Do Not Display IF', 'insert-php' ); ?></option>
326 </select>
327 <span><?php _e( 'or', 'insert-php' ) ?></span>
328 <a href="#" class="button btn-remove-filter">x</a>
329 </div>
330 <?php /*
331 <div class="winp-templates winp-right">
332 <span><strong><?php _e('Template', 'insert-php') ?></strong></span>
333 <select class="winp-select-template">
334 <option><?php _e('- select a template -', 'insert-php') ?></option>
335 <?php foreach($templates as $template) { ?>
336 <option value="<?php echo $template['id'] ?>"><?php echo $template['title'] ?></option>
337 <?php } ?>
338 </select>
339 <a href="#" class="button winp-btn-apply-template"><?php _e('Apply', 'insert-php') ?></a>
340 </div>
341 */ ?>
342 </div>
343 <div class="winp-box">
344 <div class="winp-when-empty">
345 <?php _e( 'No conditions specified. <a href="#" class="winp-link-add">Click here</a> to add one.', 'insert-php' ) ?>
346 </div>
347 <div class="winp-conditions"></div>
348 </div>
349 </div>
350 <div class="winp-scope winp-template">
351 <div class="winp-and"><span><?php _e( 'and', 'insert-php' ) ?></span></div>
352 </div>
353 <div class="winp-condition winp-template">
354 <div class="winp-or"><?php _e( 'or', 'insert-php' ) ?></div>
355 <span class="winp-params">
356 <select class="winp-param-select">
357 <?php if ( ! empty( $grouped_filter_params ) ): ?>
358 <?php foreach ( (array) $grouped_filter_params as $filterParam ) { ?>
359 <optgroup label="<?php echo $filterParam['title'] ?>">
360 <?php foreach ( $filterParam['items'] as $param ) { ?>
361 <option value="<?php echo $param['id'] ?>"<?php echo 'disabled' == $param['type'] ? ' disabled' : '' ?>>
362 <?php echo $param['title'] ?>
363 </option>
364 <?php } ?>
365 </optgroup>
366 <?php } ?>
367 <?php endif; ?>
368 </select>
369 <i class="winp-hint">
370 <span class="winp-hint-icon"></span>
371 <span class="winp-hint-content"></span>
372 </i>
373 </span>
374 <span class="winp-operators">
375 <select class="winp-operator-select">
376 <option value="equals"><?php _e( 'Equals', 'insert-php' ) ?></option>
377 <option value="notequal"><?php _e( 'Doesn\'t Equal', 'insert-php' ) ?></option>
378 <option value="greater"><?php _e( 'Greater Than', 'insert-php' ) ?></option>
379 <option value="less"><?php _e( 'Less Than', 'insert-php' ) ?></option>
380 <option value="older"><?php _e( 'Older Than', 'insert-php' ) ?></option>
381 <option value="younger"><?php _e( 'Younger Than', 'insert-php' ) ?></option>
382 <option value="contains"><?php _e( 'Contains', 'insert-php' ) ?></option>
383 <option value="notcontain"><?php _e( 'Doesn\'t Сontain', 'insert-php' ) ?></option>
384 <option value="between"><?php _e( 'Between', 'insert-php' ) ?></option>
385 </select>
386 </span>
387 <span class="winp-value"></span>
388 <span class="winp-controls">
389 <div class="button-group">
390 <a href="#" class="button button-sm button-default winp-btn-remove">-</a>
391 <a href="#" class="button button-sm button-default winp-btn-or"><?php _e( 'OR', 'insert-php' ) ?></a>
392 <a href="#" class="button button-sm button-default winp-btn-and"><?php _e( 'AND', 'insert-php' ) ?></a>
393 </div>
394 </span>
395 </div>
396 <div class="winp-date-control winp-relative winp-template">
397 <div class="winp-inputs">
398 <div class="winp-between-date">
399 <div class="winp-absolute-date">
400 <span class="winp-label"> <?php _e( 'from', 'insert-php' ) ?> </span>
401 <div class="winp-date-control winp-date-start" data-date="today">
402 <input size="16" type="text" readonly="readonly" class="winp-date-value-start" data-date="today"/>
403 <i class="fa fa-calendar"></i>
404 </div>
405 <span class="winp-label"> <?php _e( 'to', 'insert-php' ) ?> </span>
406 <div class="winp-date-control winp-date-end" data-date="today">
407 <input size="16" type="text" readonly="readonly" class="winp-date-value-end" data-date="today"/>
408 <i class="fa fa-calendar"></i>
409 </div>
410 </div>
411 <div class="winp-relative-date">
412 <span class="winp-label"> <?php _e( 'older than', 'insert-php' ) ?> </span>
413 <input type="text" class="winp-date-value winp-date-value-start" value="1"/>
414 <select class="winp-date-start-units">
415 <option value="seconds"><?php _e( 'Second(s)', 'insert-php' ) ?></option>
416 <option value="minutes"><?php _e( 'Minutes(s)', 'insert-php' ) ?></option>
417 <option value="hours"><?php _e( 'Hours(s)', 'insert-php' ) ?></option>
418 <option value="days"><?php _e( 'Day(s)', 'insert-php' ) ?></option>
419 <option value="weeks"><?php _e( 'Week(s)', 'insert-php' ) ?></option>
420 <option value="months"><?php _e( 'Month(s)', 'insert-php' ) ?></option>
421 <option value="years"><?php _e( 'Year(s)', 'insert-php' ) ?></option>
422 </select>
423 <span class="winp-label"> <?php _e( ', younger than', 'insert-php' ) ?> </span>
424 <input type="text" class="winp-date-value winp-date-value-end" value="2"/>
425 <select class="winp-date-end-units">
426 <option value="seconds"><?php _e( 'Second(s)', 'insert-php' ) ?></option>
427 <option value="minutes"><?php _e( 'Minutes(s)', 'insert-php' ) ?></option>
428 <option value="hours"><?php _e( 'Hours(s)', 'insert-php' ) ?></option>
429 <option value="days"><?php _e( 'Day(s)', 'insert-php' ) ?></option>
430 <option value="weeks"><?php _e( 'Week(s)', 'insert-php' ) ?></option>
431 <option value="months"><?php _e( 'Month(s)', 'insert-php' ) ?></option>
432 <option value="years"><?php _e( 'Year(s)', 'insert-php' ) ?></option>
433 </select>
434 </div>
435 </div>
436 <div class="winp-solo-date">
437 <div class="winp-absolute-date">
438 <div class="winp-date-control" data-date="today">
439 <input size="16" type="text" class="winp-date-value" readonly="readonly" data-date="today"/>
440 <i class="fa fa-calendar"></i>
441 </div>
442 </div>
443 <div class="winp-relative-date">
444 <input type="text" class="winp-date-value" value="1"/>
445 <select class="winp-date-value-units">
446 <option value="seconds"><?php _e( 'Second(s)', 'insert-php' ) ?></option>
447 <option value="minutes"><?php _e( 'Minutes(s)', 'insert-php' ) ?></option>
448 <option value="hours"><?php _e( 'Hours(s)', 'insert-php' ) ?></option>
449 <option value="days"><?php _e( 'Day(s)', 'insert-php' ) ?></option>
450 <option value="weeks"><?php _e( 'Week(s)', 'insert-php' ) ?></option>
451 <option value="months"><?php _e( 'Month(s)', 'insert-php' ) ?></option>
452 <option value="years"><?php _e( 'Year(s)', 'insert-php' ) ?></option>
453 </select>
454 </div>
455 </div>
456 </div>
457 <div class="winp-switcher">
458 <label><input type="radio" checked="checked" value="relative"/>
459 <span><?php _e( 'relative', 'insert-php' ) ?></span></label>
460 <label><input type="radio" value="absolute"/>
461 <span><?php _e( 'absolute', 'insert-php' ) ?></span>
462 </label>
463 </div>
464 </div>
465 <!--div class="wrap">
466 <button type="button" class="button button-default winp-add-filter winp-btn-left">
467 <?php //_e('Add new condition', 'insert-php')
468 ?>
469 </button>
470 </div-->
471 <?php $changed_filters = get_post_meta( $post_id, WINP_Plugin::app()->getPrefix() . 'changed_filters', true ); ?>
472 <input id="winp_changed_filters" name="wbcr_inp_changed_filters" value="<?php echo empty( $changed_filters ) ? 0 : 1 ?>" type="hidden"/>
473 <input id="winp_visibility_filters" name="wbcr_inp_snippet_filters"
474 value='<?php echo json_encode( get_post_meta( $post_id, WINP_Plugin::app()->getPrefix() . 'snippet_filters' ) ) ?>'
475 type="hidden"/>
476 <?php wp_nonce_field( 'wbcr_inp_snippet_' . $post_id . '_conditions_metabox', 'wbcr_inp_snippet_conditions_metabox_nonce' ) ?>
477 </div>
478 </div>
479 <?php
480 }
481
482 }