PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.60
Timetics – Appointment Booking Calendar & Scheduling v1.0.60
1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 All 62 releases
timetics / utils / notice / notice.php

notice.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.60, at utils/notice/notice.php

512 lines 12.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedNamespaceFound -- Third-party vendor library, namespace cannot be changed
3 namespace Oxaim\Libs;
4
5 defined( 'ABSPATH' ) || exit;
6
7 if(!class_exists('\Oxaim\Libs\Notice')):
8
9 class Notice{
10
11 /**
12 * scripts version
13 *
14 * @var string
15 */
16 protected $script_version = '2.1.1';
17
18 /**
19 * Unique ID to identify each notice
20 *
21 * @var string
22 */
23 protected $notice_id;
24
25 /**
26 * Plugin text-domain
27 *
28 * @var string
29 */
30 protected $text_domain;
31
32
33 /**
34 * Unique ID
35 *
36 * @var string
37 */
38 protected $unique_id;
39
40
41 /**
42 * Notice div container's class
43 *
44 * @var string
45 */
46 protected $class;
47
48
49 /**
50 * Single button's data
51 *
52 * @var array
53 */
54 protected $button;
55
56
57 /**
58 * Size class
59 *
60 * @var array
61 */
62 protected $size;
63
64
65 /**
66 * List of all buttons with it's config data
67 *
68 * @var array
69 */
70 protected $buttons;
71
72 /**
73 * Notice title
74 *
75 * @var string
76 */
77 protected $title;
78
79
80 /**
81 * Notice message
82 *
83 * @var string
84 */
85 protected $message;
86
87 /**
88 * Left logo
89 *
90 * @var string
91 */
92 protected $logo;
93 /**
94 * Container gutter
95 *
96 * @var string
97 */
98 protected $gutter;
99
100 /**
101 * Left logo style
102 *
103 * @var string
104 */
105 protected $logo_style;
106
107
108 /**
109 * Left logo style
110 *
111 * @var string
112 */
113 protected $dismissible;
114
115 protected $expired_time;
116
117
118
119 /**
120 * html markup for notice
121 *
122 * @var string
123 */
124 protected $html;
125
126
127
128 /**
129 * get_version
130 *
131 * @return string
132 */
133 public function get_version(){
134 return $this->script_version;
135 }
136
137 /**
138 * get_script_location
139 *
140 * @return string
141 */
142 public function get_script_location(){
143 return __FILE__;
144 }
145
146 // config
147
148 /**
149 * Configures all setter variables
150 *
151 * @param string $prefix
152 * @return void
153 */
154 public function config($text_domain = '', $unique_id = ''){
155 $this->text_domain = $text_domain;
156
157 $this->unique_id = $unique_id;
158
159 $this->notice_id = $text_domain . '-' . $unique_id;
160
161 $this->dismissible = false; // false, user, global
162
163 $this->expired_time = 1;
164
165 $this->html = '';
166
167 $this->title = '';
168
169 $this->message = '';
170
171 $this->class = '';
172
173 $this->gutter = true;
174
175 $this->logo = '';
176
177 $this->logo_style = '';
178
179 $this->size = [ ];
180
181 $this->button = [
182 'default_class' => 'button',
183 'class' => 'button-secondary ', // button-primary button-secondary button-small button-large button-link
184 'text' => 'Button',
185 'url' => '#',
186 'icon' => ''
187 ];
188
189 $this->buttons = [];
190
191 return $this;
192 }
193
194 // setters begin
195
196 /**
197 * Adds classes to the container
198 *
199 * @param string $classname
200 * @return void
201 */
202 public function set_class($classname = ''){
203 $this->class .= $classname;
204
205 return $this;
206 }
207
208 public function set_type($type = ''){
209 $this->class .= ' notice-' . $type;
210
211 return $this;
212 }
213
214 public function set_button($button = []){
215 $button = array_merge($this->button, $button);
216 $this->buttons[] = $button;
217
218 return $this;
219 }
220
221 public function set_id($id){
222 $this->notice_id = $id;
223 return $this;
224 }
225
226 public function set_title($title = ''){
227 $this->title .= $title;
228
229 return $this;
230 }
231
232 public function set_message($message = ''){
233 $this->message .= $message;
234
235 return $this;
236 }
237
238 public function set_gutter($gutter = true){
239 $this->gutter .= $gutter;
240 $this->class .= ($gutter === true ? '' : ' no-gutter');
241
242 return $this;
243 }
244
245 public function set_logo($logo = '', $logo_style = ""){
246 $this->logo = $logo;
247
248 $this->logo_style = $logo_style;
249
250 return $this;
251 }
252
253 public function set_html($html = ''){
254 $this->html .= $html;
255
256 return $this;
257 }
258
259 // setters ends
260
261
262 // group getter
263 public function get_data(){
264 return [
265 'message' => $this->message,
266 'title' => $this->title,
267 'buttons' => $this->buttons,
268 'class' => $this->class,
269 'html' => $this->html,
270 ];
271 }
272
273
274
275
276 public function call(){
277 add_action( 'admin_notices', [$this, 'get_notice'] );
278 }
279
280 public function get_notice(){
281 // dismissible conditions
282 if ( 'user' === $this->dismissible) {
283 $expired = get_user_meta( get_current_user_id(), $this->notice_id, true );
284 } elseif ( 'global' === $this->dismissible ) {
285 $expired = get_transient( $this->notice_id );
286 }else{
287 $expired = '';
288 }
289
290 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Vendor library global variable
291 global $oxaim_lib_notice_list;
292
293 if(!isset($oxaim_lib_notice_list[$this->notice_id])){
294 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- Vendor library global variable usage
295 $oxaim_lib_notice_list[$this->notice_id] = __FILE__;
296
297 // is transient expired?
298 if ( false === $expired || empty( $expired ) ) {
299 $this->generate_html();
300 }
301 }
302 }
303
304 public function set_dismiss($scope = 'global', $time = (3600 * 24 * 7)){
305 $this->dismissible = $scope;
306 $this->expired_time = $time;
307
308 return $this;
309 }
310
311 public function generate_html() {
312
313 ?>
314 <div
315 id="<?php echo esc_attr($this->notice_id); ?>"
316 class="notice wpmet-notice notice-<?php echo esc_attr($this->notice_id . ' ' .$this->class); ?> <?php echo (false === $this->dismissible ? '' : 'is-dismissible') ;?>"
317
318 expired_time="<?php echo esc_attr( $this->expired_time ); ?>"
319 dismissible="<?php echo esc_attr( $this->dismissible ); ?>"
320 >
321 <?php if(!empty($this->logo)):?>
322 <img class="notice-logo" style="<?php echo esc_attr($this->logo_style); ?>" src="<?php echo esc_url($this->logo);?>" />
323 <?php endif; ?>
324
325 <div class="notice-right-container <?php echo (empty($this->logo) ? 'notice-container-full-width' : ''); ?>">
326
327 <?php if(empty($this->html)): ?>
328 <?php echo esc_html( empty($this->title ) ? '' : sprintf('<div class="notice-main-title notice-vert-space">%s</div>', esc_html( $this->title ) )); ?>
329
330 <div class="notice-message notice-vert-space">
331 <?php echo wp_kses( $this->message, 'post' );?>
332 </div>
333
334 <?php if(!empty($this->buttons)): ?>
335 <div class="button-container notice-vert-space">
336 <?php foreach($this->buttons as $button): ?>
337 <a id="<?php echo esc_attr( !isset($button['id']) ? '' : $button['id'] ); ?>" href="<?php echo esc_url($button['url']); ?>" class="wpmet-notice-button <?php echo esc_attr($button['class']); ?>">
338 <?php if(!empty($button['icon'])) :?>
339 <i class="notice-icon <?php echo esc_attr($button['icon']); ?>"></i>
340 <?php endif; ?>
341 <?php echo esc_html($button['text']);?>
342 </a>
343 &nbsp;
344 <?php endforeach; ?>
345 </div>
346 <?php endif;?>
347
348 <?php else:?>
349 <?php echo wp_kses( $this->html, 'post' ); ?>
350 <?php endif;?>
351
352 </div>
353
354 <?php if(false !== $this->dismissible): ?>
355 <button type="button" class="notice-dismiss">
356 <span class="screen-reader-text">x</span>
357 </button>
358 <?php endif;?>
359
360 <div style="clear:both"></div>
361
362 </div>
363 <?php
364 }
365
366 public static function init(){
367 add_action( 'wp_ajax_wpmet-notices', [ __CLASS__, 'dismiss_ajax_call' ] );
368 add_action( 'admin_head', [ __CLASS__, 'enqueue_scripts' ] );
369 }
370
371 public static function dismiss_ajax_call() {
372 $post_arr = filter_input_array( INPUT_POST, FILTER_SANITIZE_STRING );
373 $notice_id = ( isset( $post_arr['notice_id'] ) ) ? $post_arr['notice_id'] : '';
374 $dismissible = ( isset( $post_arr['dismissible'] ) ) ? $post_arr['dismissible'] : '';
375 $expired_time = ( isset( $post_arr['expired_time'] ) ) ? $post_arr['expired_time'] : '';
376
377 if ( ! empty( $notice_id ) ) {
378 if ( 'user' === $dismissible ) {
379 update_user_meta( get_current_user_id(), $notice_id, true );
380 } else {
381 set_transient( $notice_id, true, $expired_time );
382 }
383
384 wp_send_json_success();
385 }
386
387 wp_send_json_error();
388 }
389
390 public static function enqueue_scripts() {
391 echo "
392 <script>
393 jQuery(document).ready(function ($) {
394 $( '.wpmet-notice.is-dismissible' ).on( 'click', '.notice-dismiss', function() {
395
396 _this = $( this ).parents('.wpmet-notice').eq(0);
397 var notice_id = _this.attr( 'id' ) || '';
398 var expired_time = _this.attr( 'expired_time' ) || '';
399 var dismissible = _this.attr( 'dismissible' ) || '';
400 var x = $( this ).attr('class');
401
402 _this.hide();
403
404 $.ajax({
405 url: ajaxurl,
406 type: 'POST',
407 data: {
408 action : 'wpmet-notices',
409 notice_id : notice_id,
410 dismissible : dismissible,
411 expired_time : expired_time,
412 },
413 });
414 });
415 });
416 </script>
417 <style>
418 .wpmet-notice{
419 background-color: transparent;
420 margin: 10px 40px 0 20px;
421 padding: 0!important;
422 display: flex;
423 flex-direction: row;
424 justify-content: flex-start;
425 align-items: center;
426 }
427
428 .wpmet-notice .notice-right-container{
429 margin: .7rem .8rem .8rem;
430 }
431
432 .notice-container-full-width{
433 width:100%!important;
434 }
435
436 .notice-container-full-width img {
437 max-width: 100%;
438 border-radius: 6px;
439 }
440
441 .wpmet-notice.no-gutter{
442 padding: 0!important;
443 border-width: 0!important;
444 }
445 .wpmet-notice.no-gutter .notice-right-container{
446 padding: 0!important;
447 margin: 0!important;
448 }
449
450 .notice-right-container .notice-vert-space{
451 margin-bottom: .8rem;
452 }
453
454 .notice-right-container .notice-vert-space:last-child,
455 .notice-right-container .notice-vert-space:only-child{
456 margin-bottom: 0;
457 }
458
459 .wpmet-notice .notice-logo{
460 padding: 3px;
461 max-width: 110px;
462 max-height: 110px;
463 }
464
465 .wpmet-notice-button {
466 text-decoration:none;
467 }
468
469 .wpmet-notice-button > i{
470 margin-right: 3px;
471 }
472
473 .wpmet-notice-button .notice-icon{
474 display:inline-block;
475 }
476
477 .wpmet-notice-button .notice-icon:before{
478 vertical-align: middle!important;
479 margin-top: -1px;
480 }
481
482 .wpmet-notice .notice-main-title{
483 color: #1d2327;
484 font-size: 1.2rem;
485 }
486
487 </style>
488 ";
489 }
490
491
492 private static $instance;
493
494 /**
495 * Method: instance -> Return Notice module class instance
496 *
497 * @param string|null $text_domain
498 * @param string|null $unique_id
499 * @return mixed
500 */
501 public static function instance($text_domain = null, $unique_id = null) {
502 if($text_domain == null){
503 return false;
504 }
505
506 self::$instance = new self();
507
508 return self::$instance->config($text_domain, (is_null($unique_id) ? uniqid() : $unique_id));
509 }
510 }
511
512 endif;