PluginProbe
Clicky Analytics / 2.2
Clicky Analytics v2.2
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 2.2, at config.php

252 lines 6.0 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 /**
22 * Get plugin options
23 */
24 $this->get_plugin_options();
25 /**
26 * Provide language packs for all available Network languages
27 */
28 if ( is_multisite() ) {
29 add_filter( 'plugins_update_check_locales', array( $this, 'translation_updates' ), 10, 1 );
30 }
31 }
32
33 /**
34 * Helper function to update language packs for an entire network
35 */
36 public function translation_updates( $locales ) {
37 $languages = get_available_languages();
38 return array_values( $languages );
39 }
40
41 /**
42 * Validates options before storing
43 */
44 private function validate_data( $options ) {
45 /* @formatter:off */
46 $numerics = array( 'dashboard_widget',
47 'frontend_item_reports',
48 'backend_item_reports',
49 'cachetime',
50 'tracking',
51 'track_username',
52 'track_email',
53 'track_youtube',
54 'track_html5',
55 );
56 foreach ( $numerics as $key ) {
57 if ( isset( $options[$key] ) ) {
58 $options[$key] = (int) $options[$key];
59 }
60 }
61
62 $texts = array( 'sitekey',
63 'siteid',
64 'maps_api_key',
65 'theme_color',
66 'track_outbound',
67 );
68 foreach ( $texts as $key ) {
69 if ( isset( $options[$key] ) ) {
70 $options[$key] = sanitize_text_field( $options[$key] );
71 }
72 }
73 /* @formatter:on */
74
75 return $options;
76 }
77
78 /**
79 * Helper function to store options
80 */
81 public function set_plugin_options() {
82
83 $options = $this->options;
84
85 update_option( 'cawp_options', json_encode( $this->validate_data( $options ) ) );
86
87 }
88
89 /**
90 * Retrieve plugin options
91 */
92 private function get_plugin_options() {
93
94 if ( ! get_option( 'cawp_options' ) ) {
95 CAWP_Install::install();
96 }
97 $this->options = (array) json_decode( get_option( 'cawp_options' ) );
98 // Maintain Compatibility
99 $this->maintain_compatibility();
100
101 }
102
103 /**
104 * Helps maintaining backwards compatibility
105 */
106 private function maintain_compatibility() {
107 $flag = false;
108
109 CAWP_Tools::delete_expired_cache();
110
111 $prevver = get_option( 'cawp_version' );
112 if ( $prevver && CAWP_CURRENT_VERSION != $prevver ) {
113 $flag = true;
114 update_option( 'cawp_version', CAWP_CURRENT_VERSION );
115 update_option( 'cawp_got_updated', true );
116 CAWP_Tools::clear_cache();
117 CAWP_Tools::delete_cache( 'capi_errors' );
118 }
119
120 if ( get_option( 'ca_sitekey' ) ){
121 $this->options['sitekey'] = get_option( 'ca_sitekey' );
122 delete_option( 'ca_sitekey' );
123 $flag = true;
124 };
125
126 if ( get_option( 'ca_siteid' ) ){
127 $this->options['siteid'] = get_option( 'ca_siteid' );
128 delete_option( 'ca_siteid' );
129 $flag = true;
130 };
131
132 if ( get_option( 'ca_track_email' ) ){
133 $this->options['track_email'] = get_option( 'ca_track_email' );
134 delete_option( 'ca_track_email' );
135 $flag = true;
136 };
137
138 if ( get_option( 'ca_track_username' ) ){
139 $this->options['track_username'] = get_option( 'ca_track_username' );
140 delete_option( 'ca_track_username' );
141 $flag = true;
142 };
143
144 if ( get_option( 'ca_track_youtube' ) ){
145 $this->options['track_youtube'] = get_option( 'ca_track_youtube' );
146 delete_option( 'ca_track_youtube' );
147 $flag = true;
148 };
149
150 if ( get_option( 'ca_track_html5' ) ){
151 $this->options['track_html5'] = get_option( 'ca_track_html5' );
152 delete_option( 'ca_track_html5' );
153 $flag = true;
154 };
155
156 if ( get_option( 'ca_tracking' ) ){
157 $this->options['tracking'] = get_option( 'ca_tracking' );
158 delete_option( 'ca_tracking' );
159 $flag = true;
160 };
161
162 if ( get_option( 'ca_access' ) ){
163 $this->options['access_back'] = get_option( 'ca_access' );
164 $this->options['access_front'] = get_option( 'ca_access' );
165 delete_option( 'ca_access' );
166 $flag = true;
167 };
168
169 if ( get_option( 'ca_disabledashboard' ) ){
170 $this->options['dashboard_widget'] = get_option( 'ca_disabledashboard' );
171 delete_option( 'ca_disabledashboard' );
172 $flag = true;
173 };
174
175 if ( get_option( 'ca_frontend' ) ){
176 $this->options['frontend_item_reports'] = get_option( 'ca_frontend' );
177 delete_option( 'ca_frontend' );
178 $flag = true;
179 };
180
181 if ( get_option( 'ca_track_olp' ) ){
182 $this->options['track_outbound'] = get_option( 'ca_track_olp' );
183 delete_option( 'ca_track_olp' );
184 $flag = true;
185 };
186
187 if ( get_option( 'ca_pgd' ) ){
188 delete_option( 'ca_pgd' );
189 delete_option( 'ca_rd' );
190 delete_option( 'ca_sd' );
191 };
192
193 if ( ! isset( $this->options['theme_color'] ) ) {
194 $this->options['theme_color'] = '#2c5fb2';
195 $flag = true;
196 }
197
198 /* @formatter:off */
199 $zeros = array( 'backend_item_reports',
200 );
201 foreach ( $zeros as $key ) {
202 if ( ! isset( $this->options[$key] ) ) {
203 $this->options[$key] = 0;
204 $flag = true;
205 }
206 }
207
208 $unsets = array( 'ca_cachetime',
209 );
210 foreach ( $unsets as $key ) {
211 if ( isset( $this->options[$key] ) ) {
212 unset( $this->options[$key] );
213 $flag = true;
214 }
215 }
216
217 $empties = array( 'maps_api_key',
218 );
219 foreach ( $empties as $key ) {
220 if ( ! isset( $this->options[$key] ) ) {
221 $this->options[$key] = '';
222 $flag = true;
223 }
224 }
225
226 $ones = array();
227 foreach ( $ones as $key ) {
228 if ( ! isset( $this->options[$key] ) ) {
229 $this->options[$key] = 1;
230 $flag = true;
231 }
232 }
233
234 $arrays = array( 'access_front',
235 'access_back',
236 );
237 foreach ( $arrays as $key ) {
238 if ( ! is_array( $this->options[$key] ) ) {
239 $this->options[$key] = array();
240 $flag = true;
241 }
242 }
243 /* @formatter:on */
244
245 if ( $flag ) {
246 $this->set_plugin_options();
247 }
248 }
249 }
250 }
251
252