PluginProbe
Clicky Analytics / trunk
Clicky Analytics vtrunk
trunk 1.1 1.1.1 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5 1.5.1 1.5.2 1.6 1.6.1 All 40 releases
clicky-analytics / config.php

config.php in Clicky Analytics trunk, at config.php

277 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Author: Alin Marcu
4 * Author URI: https://deconf.com
5 * Copyright 2013 Alin Marcu
6 * License: GPLv2 or later
7 * License URI: http://www.gnu.org/licenses/gpl-2.0.html
8 */
9
10 // Exit if accessed directly
11 if ( ! defined( 'ABSPATH' ) )
12 exit();
13
14 if ( ! class_exists( 'CAWP_Config' ) ) {
15
16 final class CAWP_Config {
17
18 public $options;
19
20 public function __construct() {
21 global $wp_version;
22
23 /**
24 * Get plugin options
25 */
26 $this->get_plugin_options();
27 /**
28 * Provide language packs for all available Network languages
29 */
30 if ( is_multisite() ) {
31 add_filter( 'plugins_update_check_locales', array( $this, 'translation_updates' ), 10, 1 );
32 }
33 /**
34 * Clear expired cache using WP Cron
35 */
36 if ( ! wp_next_scheduled( 'cawp_expired_cache_hook' ) ) {
37
38 /**
39 * WP < 5.3.0 compatibility
40 */
41 if ( version_compare( $wp_version, '5.3.0', '>=' ) ) {
42 $datetime = new DateTime( 'tomorrow', new DateTimeZone(wp_timezone_string()) );
43 } else {
44 $datetime = new DateTime( 'tomorrow', new DateTimeZone( CAWP_Tools::timezone_string()) );
45 }
46 $timestamp = $datetime->getTimestamp();
47
48 wp_schedule_event($timestamp, 'daily', 'cawp_expired_cache_hook');
49
50 }
51
52 add_action ( 'cawp_expired_cache_hook', array( $this, 'delete_expired_cache' ) );
53
54 }
55
56 public function delete_expired_cache (){
57 CAWP_Tools::delete_expired_cache();
58 }
59
60 /**
61 * Helper function to update language packs for an entire network
62 */
63 public function translation_updates( $locales ) {
64 $languages = get_available_languages();
65 return array_values( $languages );
66 }
67
68 /**
69 * Validates options before storing
70 */
71 private function validate_data( $options ) {
72 /* @formatter:off */
73 $numerics = array( 'dashboard_widget',
74 'frontend_item_reports',
75 'backend_item_reports',
76 'cachetime',
77 'tracking',
78 'track_username',
79 'track_email',
80 'track_youtube',
81 'track_html5',
82 );
83 foreach ( $numerics as $key ) {
84 if ( isset( $options[$key] ) ) {
85 $options[$key] = (int) $options[$key];
86 }
87 }
88
89 $texts = array( 'sitekey',
90 'siteid',
91 'maps_api_key',
92 'theme_color',
93 'track_outbound',
94 );
95 foreach ( $texts as $key ) {
96 if ( isset( $options[$key] ) ) {
97 $options[$key] = sanitize_text_field( $options[$key] );
98 }
99 }
100 /* @formatter:on */
101
102 return $options;
103 }
104
105 /**
106 * Helper function to store options
107 */
108 public function set_plugin_options() {
109
110 $options = $this->options;
111
112 update_option( 'cawp_options', json_encode( $this->validate_data( $options ) ) );
113
114 }
115
116 /**
117 * Retrieve plugin options
118 */
119 private function get_plugin_options() {
120
121 if ( ! get_option( 'cawp_options' ) ) {
122 CAWP_Install::install();
123 }
124 $this->options = (array) json_decode( get_option( 'cawp_options' ) );
125 // Maintain Compatibility
126 $this->maintain_compatibility();
127
128 }
129
130 /**
131 * Helps maintaining backwards compatibility
132 */
133 private function maintain_compatibility() {
134 $flag = false;
135
136 $prevver = get_option( 'cawp_version' );
137 if ( $prevver && CAWP_CURRENT_VERSION != $prevver ) {
138 $flag = true;
139 update_option( 'cawp_version', CAWP_CURRENT_VERSION );
140 update_option( 'cawp_got_updated', true );
141 CAWP_Tools::clear_cache();
142 CAWP_Tools::delete_cache( 'capi_errors' );
143 }
144
145 if ( get_option( 'ca_sitekey' ) ){
146 $this->options['sitekey'] = get_option( 'ca_sitekey' );
147 delete_option( 'ca_sitekey' );
148 $flag = true;
149 };
150
151 if ( get_option( 'ca_siteid' ) ){
152 $this->options['siteid'] = get_option( 'ca_siteid' );
153 delete_option( 'ca_siteid' );
154 $flag = true;
155 };
156
157 if ( get_option( 'ca_track_email' ) ){
158 $this->options['track_email'] = get_option( 'ca_track_email' );
159 delete_option( 'ca_track_email' );
160 $flag = true;
161 };
162
163 if ( get_option( 'ca_track_username' ) ){
164 $this->options['track_username'] = get_option( 'ca_track_username' );
165 delete_option( 'ca_track_username' );
166 $flag = true;
167 };
168
169 if ( get_option( 'ca_track_youtube' ) ){
170 $this->options['track_youtube'] = get_option( 'ca_track_youtube' );
171 delete_option( 'ca_track_youtube' );
172 $flag = true;
173 };
174
175 if ( get_option( 'ca_track_html5' ) ){
176 $this->options['track_html5'] = get_option( 'ca_track_html5' );
177 delete_option( 'ca_track_html5' );
178 $flag = true;
179 };
180
181 if ( get_option( 'ca_tracking' ) ){
182 $this->options['tracking'] = get_option( 'ca_tracking' );
183 delete_option( 'ca_tracking' );
184 $flag = true;
185 };
186
187 if ( get_option( 'ca_access' ) ){
188 $this->options['access_back'] = get_option( 'ca_access' );
189 $this->options['access_front'] = get_option( 'ca_access' );
190 delete_option( 'ca_access' );
191 $flag = true;
192 };
193
194 if ( get_option( 'ca_disabledashboard' ) ){
195 $this->options['dashboard_widget'] = get_option( 'ca_disabledashboard' );
196 delete_option( 'ca_disabledashboard' );
197 $flag = true;
198 };
199
200 if ( get_option( 'ca_frontend' ) ){
201 $this->options['frontend_item_reports'] = get_option( 'ca_frontend' );
202 delete_option( 'ca_frontend' );
203 $flag = true;
204 };
205
206 if ( get_option( 'ca_track_olp' ) ){
207 $this->options['track_outbound'] = get_option( 'ca_track_olp' );
208 delete_option( 'ca_track_olp' );
209 $flag = true;
210 };
211
212 if ( get_option( 'ca_pgd' ) ){
213 delete_option( 'ca_pgd' );
214 delete_option( 'ca_rd' );
215 delete_option( 'ca_sd' );
216 };
217
218 if ( ! isset( $this->options['theme_color'] ) ) {
219 $this->options['theme_color'] = '#2c5fb2';
220 $flag = true;
221 }
222
223 /* @formatter:off */
224 $zeros = array( 'backend_item_reports',
225 );
226 foreach ( $zeros as $key ) {
227 if ( ! isset( $this->options[$key] ) ) {
228 $this->options[$key] = 0;
229 $flag = true;
230 }
231 }
232
233 $unsets = array( 'ca_cachetime',
234 );
235 foreach ( $unsets as $key ) {
236 if ( isset( $this->options[$key] ) ) {
237 unset( $this->options[$key] );
238 $flag = true;
239 }
240 }
241
242 $empties = array( 'maps_api_key',
243 );
244 foreach ( $empties as $key ) {
245 if ( ! isset( $this->options[$key] ) ) {
246 $this->options[$key] = '';
247 $flag = true;
248 }
249 }
250
251 $ones = array();
252 foreach ( $ones as $key ) {
253 if ( ! isset( $this->options[$key] ) ) {
254 $this->options[$key] = 1;
255 $flag = true;
256 }
257 }
258
259 $arrays = array( 'access_front',
260 'access_back',
261 );
262 foreach ( $arrays as $key ) {
263 if ( ! is_array( $this->options[$key] ) ) {
264 $this->options[$key] = array();
265 $flag = true;
266 }
267 }
268 /* @formatter:on */
269
270 if ( $flag ) {
271 $this->set_plugin_options();
272 }
273 }
274 }
275 }
276
277