PluginProbe
QuadMenu – Mega Menu / 1.8.4
QuadMenu – Mega Menu v1.8.4
3.3.7 3.3.6 trunk 1.8.4 1.8.5 1.8.7 1.8.8 1.8.9 1.9.0 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 All 87 releases
quadmenu / lib / ReduxCore / core / newsflash.php

newsflash.php in QuadMenu – Mega Menu 1.8.4, at lib/ReduxCore/core/newsflash.php

127 lines 5.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Added by KP on March 31, 2015. So, if something is buggered, it's probably my bad! ;-)
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 if ( ! class_exists( 'reduxNewsflash' ) ) {
10 class reduxNewsflash {
11 private $parent = null;
12 private $notice_data = '';
13 private $server_file = '';
14 private $interval = 3;
15 private $cookie_id = '';
16
17 public function __construct( $parent, $params ) {
18 // set parent object
19 $this->parent = $parent;
20
21 if ( ! is_admin() ) {
22 return;
23 }
24
25 $this->server_file = $params['server_file'];
26 $this->interval = isset( $params['interval'] ) ? $params['interval'] : 3;
27 $this->cookie_id = isset( $params['cookie_id'] ) ? $params['cookie_id'] : $parent->args['opt_name'] . '_blast';
28
29 $this->notice_data = get_option( 'r_notice_data', '' );
30
31 $fname = Redux_Functions::bub( 'get_notice_json', $parent->args['opt_name'] );
32 $mname = Redux_Functions::yo( 'display_message', $parent->args['opt_name'] );
33
34 // if notice data is empty
35 if ( empty( $this->notice_data ) ) {
36 // get notice data from server and create cache data
37 $this->$fname();
38 } else {
39 // check expiry time
40 if ( ! isset( $_COOKIE[ $this->cookie_id ] ) ) {
41 // expired! get notice data from server
42 $this->$fname();
43 }
44 }
45
46 // set the admin notice msg
47 $this->$mname();
48 }
49
50 private function bub() {
51 $this->notice_data = '';
52 }
53
54 private function get_notice_json() {
55
56 // get notice data from server
57 $data = @wp_remote_get( $this->server_file, array( 'sslverify' => false ) );
58
59 if ( isset( $data ) && ! empty( $data ) && ! is_wp_error( $data ) && $data['response']['code'] == 200 ) {
60 $data = $data['body'];
61 // if some data exists
62 if ( $data != '' || ! empty( $data ) ) {
63
64 if ( ! empty( $this->notice_data ) ) {
65 if ( strcmp( $data, $this->notice_data ) == 0 ) {
66 // set new cookie for interval value
67 Redux_Functions::setCookie( $this->cookie_id, time(), time() + ( 86400 * $this->interval ), '/' );
68
69 // bail out
70 return;
71 }
72 }
73
74 update_option( 'r_notice_data', $data );
75 $this->notice_data = $data;
76
77 // set cookie for three day expiry
78 setcookie( $this->cookie_id, time(), time() + ( 86400 * $this->interval ), '/' );
79
80 // set unique key for dismiss meta key
81 update_option( $this->cookie_id, time() );
82 }
83 }
84 }
85
86 private function display_message() {
87 // Notice data exists?
88 if ( ! empty( $this->notice_data ) ) {
89 // decode json string
90 $data = (Array) json_decode( $this->notice_data );
91 // must be array and not empty
92 if ( is_array( $data ) && ! empty( $data ) ) {
93
94 // No message means nothing to display.
95 if ( ! isset( $data['message'] ) || $data['message'] == '' || empty( $data['message'] ) ) {
96 return;
97 }
98
99 // validate data
100 $data['type'] = isset( $data['type'] ) && $data['type'] != '' ? $data['type'] : 'updated';
101 $data['title'] = isset( $data['title'] ) && $data['title'] != '' ? $data['title'] : '';
102
103 if ( $data['type'] == 'redux-message' ) {
104 $data['type'] = 'updated redux-message';
105 }
106
107 $data['color'] = isset( $data['color'] ) ? $data['color'] : '#00A2E3';
108
109 // get unique meta key
110 $key = get_option( $this->cookie_id );
111
112 $notice_data = array(
113 'parent' => $this->parent,
114 'type' => $data['type'],
115 'msg' => $data['title'] . $data['message'],
116 'id' => $this->cookie_id . '_' . $key,
117 'dismiss' => true,
118 'color' => $data['color']
119 );
120
121 Redux_Admin_Notices::set_notice($notice_data);
122 }
123 }
124 }
125 }
126 }
127