| 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 |
//@formatter:off |
| 10 |
// Exit if accessed directly |
| 11 |
if ( ! defined( 'ABSPATH' ) ) { |
| 12 |
exit(); |
| 13 |
} |
| 14 |
|
| 15 |
use Google\Service\Exception as GoogleServiceException; |
| 16 |
|
| 17 |
final class CAWP_Settings { |
| 18 |
|
| 19 |
private static function update_options( $who ) { |
| 20 |
$cawp = CAWP(); |
| 21 |
$options = $cawp->config->options; // Get current options |
| 22 |
if ( isset( $_POST['options']['cawp_hidden'] ) && isset( $_POST['options'] ) && ( isset( $_POST['cawp_security'] ) && wp_verify_nonce( $_POST['cawp_security'], 'cawp_form' ) ) ) { |
| 23 |
$new_options = $_POST['options']; |
| 24 |
if ( 'settings' == $who ) { |
| 25 |
$options['backend_item_reports'] = 0; |
| 26 |
$options['dashboard_widget'] = 0; |
| 27 |
$options['track_username'] = 0; |
| 28 |
$options['track_email'] = 0; |
| 29 |
$options['track_youtube'] = 0; |
| 30 |
$options['track_html5'] = 0; |
| 31 |
$options['track_outbound'] = 0; |
| 32 |
$options['tracking'] = 1; |
| 33 |
if ( empty( $new_options['access_back'] ) ) { |
| 34 |
$new_options['access_back'][] = 'administrator'; |
| 35 |
} |
| 36 |
$options['frontend_item_reports'] = 0; |
| 37 |
if ( empty( $new_options['access_front'] ) ) { |
| 38 |
$new_options['access_front'][] = 'administrator'; |
| 39 |
} |
| 40 |
} else if ( 'setup' == $who ) { |
| 41 |
$options['sitekey'] = ''; |
| 42 |
$options['siteid'] = ''; |
| 43 |
} |
| 44 |
|
| 45 |
$options = array_merge( $options, $new_options ); |
| 46 |
$cawp->config->options = $options; |
| 47 |
$cawp->config->set_plugin_options(); |
| 48 |
} |
| 49 |
return $options; |
| 50 |
} |
| 51 |
|
| 52 |
private static function navigation_tabs( $tabs ) { |
| 53 |
echo '<h2 class="nav-tab-wrapper">'; |
| 54 |
foreach ( $tabs as $tab => $name ) { |
| 55 |
echo "<a class='nav-tab' id='tab-$tab' href='#top#cawp-$tab'>$name</a>"; |
| 56 |
} |
| 57 |
echo '</h2>'; |
| 58 |
} |
| 59 |
|
| 60 |
public static function settings() { |
| 61 |
|
| 62 |
$cawp = CAWP(); |
| 63 |
|
| 64 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 65 |
return; |
| 66 |
} |
| 67 |
$options = self::update_options( 'settings' ); |
| 68 |
if ( isset( $_POST['options']['cawp_hidden'] ) ) { |
| 69 |
$message = "<div class='updated' id='cawp-autodismiss'><p>" . __( "Settings saved.", 'clicky-analytics' ) . "</p></div>"; |
| 70 |
if ( ! ( isset( $_POST['cawp_security'] ) && wp_verify_nonce( $_POST['cawp_security'], 'cawp_form' ) ) ) { |
| 71 |
$message = "<div class='error' id='cawp-autodismiss'><p>" . __( "You don’t have permission to do this.", 'clicky-analytics' ) . "</p></div>"; |
| 72 |
} |
| 73 |
} |
| 74 |
if ( ! $cawp->config->options['sitekey'] || ! $cawp->config->options['siteid'] ) { |
| 75 |
$message = sprintf( '<div class="error"><p>%s</p></div>', sprintf( __( 'Something went wrong, check %1$s or %2$s.', 'clicky-analytics' ), sprintf( '<a href="%1$s">%2$s</a>', menu_page_url( 'cawp_errors_debugging', false ), __( 'Debug', 'clicky-analytics' ) ), sprintf( '<a href="%1$s">%2$s</a>', menu_page_url( 'cawp_setup', false ), __( 'enter the credentials', 'clicky-analytics' ) ) ) ); |
| 76 |
} |
| 77 |
?> |
| 78 |
<form name="cawp_form" method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>"> |
| 79 |
<div class="wrap"> |
| 80 |
<?php echo "<h2>" . __( "Clicky Analytics - Settings", 'clicky-analytics' ) . "</h2>"; ?><hr> |
| 81 |
</div> |
| 82 |
<div id="poststuff" class="cawp"> |
| 83 |
<div id="post-body" class="metabox-holder columns-2"> |
| 84 |
<div id="post-body-content"> |
| 85 |
<div class="settings-wrapper"> |
| 86 |
<div class="inside"> |
| 87 |
<?php if (isset($message)) echo $message; ?> |
| 88 |
<table class="cawp-settings-options"> |
| 89 |
<tr> |
| 90 |
<td colspan="2"><?php echo "<h2>" . __( "Tracking Code Settings", 'clicky-analytics' ) . "</h2>"; ?></td> |
| 91 |
</tr> |
| 92 |
<tr> |
| 93 |
<tr> |
| 94 |
<td class="cawp-settings-title"> |
| 95 |
<label for="site_jail"><?php _e("Tracking Code:", 'clicky-analytics' ); ?></label> |
| 96 |
</td> |
| 97 |
<td> |
| 98 |
<select id="tracking" name="options[tracking]"> |
| 99 |
<option value="1" <?php selected( 1, $options['tracking'] ); ?> title="Enabled"> |
| 100 |
<?php _e( "Enabled", 'clicky-analytics' )?> |
| 101 |
</option> |
| 102 |
<option value="0" <?php selected( 0, $options['tracking'] ); ?> title="Disabled"> |
| 103 |
<?php _e( "Disabled", 'clicky-analytics' )?> |
| 104 |
</option> |
| 105 |
</select> |
| 106 |
</td> |
| 107 |
</tr> |
| 108 |
|
| 109 |
<td colspan="2" class="cawp-settings-title"> |
| 110 |
<div class="cawp-togglegroup"> |
| 111 |
<input type="checkbox" name="options[track_username]" value="1" id="track_username" <?php checked( $options['track_username'], 1 ); ?>> |
| 112 |
<label for="track_username"> |
| 113 |
<?php _e ( "track usernames", 'clicky-analytics' );?> |
| 114 |
</label> |
| 115 |
<div class="cawp-onoffswitch pull-right" aria-hidden="true"> |
| 116 |
<div class="cawp-onoffswitch-label"> |
| 117 |
<div class="cawp-onoffswitch-inner"></div> |
| 118 |
<div class="cawp-onoffswitch-switch"></div> |
| 119 |
</div> |
| 120 |
</div> |
| 121 |
</div> |
| 122 |
</td> |
| 123 |
</tr> |
| 124 |
<tr> |
| 125 |
<td colspan="2" class="cawp-settings-title"> |
| 126 |
<div class="cawp-togglegroup"> |
| 127 |
<input type="checkbox" name="options[track_email]" value="1" id="track_email" <?php checked( $options['track_email'], 1 ); ?>> |
| 128 |
<label for="track_email"> |
| 129 |
<?php _e ( "track emails", 'clicky-analytics' );?> |
| 130 |
</label> |
| 131 |
<div class="cawp-onoffswitch pull-right" aria-hidden="true"> |
| 132 |
<div class="cawp-onoffswitch-label"> |
| 133 |
<div class="cawp-onoffswitch-inner"></div> |
| 134 |
<div class="cawp-onoffswitch-switch"></div> |
| 135 |
</div> |
| 136 |
</div> |
| 137 |
</div> |
| 138 |
</td> |
| 139 |
</tr> |
| 140 |
<tr> |
| 141 |
<td colspan="2" class="cawp-settings-title"> |
| 142 |
<div class="cawp-togglegroup"> |
| 143 |
<input type="checkbox" name="options[track_youtube]" value="1" id="track_youtube" <?php checked( $options['track_youtube'], 1 ); ?>> |
| 144 |
<label for="track_youtube"> |
| 145 |
<?php _e ( "track YouTube videos", 'clicky-analytics' );?> |
| 146 |
</label> |
| 147 |
<div class="cawp-onoffswitch pull-right" aria-hidden="true"> |
| 148 |
<div class="cawp-onoffswitch-label"> |
| 149 |
<div class="cawp-onoffswitch-inner"></div> |
| 150 |
<div class="cawp-onoffswitch-switch"></div> |
| 151 |
</div> |
| 152 |
</div> |
| 153 |
</div> |
| 154 |
</td> |
| 155 |
</tr> |
| 156 |
<tr> |
| 157 |
<td colspan="2" class="cawp-settings-title"> |
| 158 |
<div class="cawp-togglegroup"> |
| 159 |
<input type="checkbox" name="options[track_html5]" value="1" id="track_html5" <?php checked( $options['track_html5'], 1 ); ?>> |
| 160 |
<label for="track_html5"> |
| 161 |
<?php _e ( "track HTML5 videos", 'clicky-analytics' );?> |
| 162 |
</label> |
| 163 |
<div class="cawp-onoffswitch pull-right" aria-hidden="true"> |
| 164 |
<div class="cawp-onoffswitch-label"> |
| 165 |
<div class="cawp-onoffswitch-inner"></div> |
| 166 |
<div class="cawp-onoffswitch-switch"></div> |
| 167 |
</div> |
| 168 |
</div> |
| 169 |
</div> |
| 170 |
</td> |
| 171 |
</tr> |
| 172 |
<tr> |
| 173 |
<td colspan="2" class="cawp-settings-title"> |
| 174 |
<?php echo __("Outboung links pattern:", 'clicky-analytics'); ?> |
| 175 |
<input type="text" style="text-align: left;" name="options[track_outbound]" value="<?php echo esc_attr($options['track_outbound']); ?>" size="20"> |
| 176 |
</td> |
| 177 |
</tr> |
| 178 |
<tr> |
| 179 |
<td colspan="2"> |
| 180 |
<hr> |
| 181 |
</td> |
| 182 |
</tr> |
| 183 |
<tr> |
| 184 |
<td colspan="2"><?php echo "<h2>" . __( "Backend Permissions", 'clicky-analytics' ) . "</h2>"; ?></td> |
| 185 |
</tr> |
| 186 |
<tr> |
| 187 |
<td class="roles cawp-settings-title"> |
| 188 |
<label for="access_back"><?php _e("Show stats to:", 'clicky-analytics' ); ?> |
| 189 |
</label> |
| 190 |
</td> |
| 191 |
<td class="cawp-settings-roles"> |
| 192 |
<table> |
| 193 |
<tr> |
| 194 |
<?php if ( ! isset( $wp_roles ) ) : ?> |
| 195 |
<?php $wp_roles = new WP_Roles(); ?> |
| 196 |
<?php endif; ?> |
| 197 |
<?php $i = 0; ?> |
| 198 |
<?php foreach ( $wp_roles->role_names as $role => $name ) : ?> |
| 199 |
<?php if ( 'subscriber' != $role ) : ?> |
| 200 |
<?php $i++; ?> |
| 201 |
<td> |
| 202 |
<label> |
| 203 |
<input type="checkbox" name="options[access_back][]" value="<?php echo $role; ?>" <?php if ( in_array($role,$options['access_back']) || 'administrator' == $role ) echo 'checked="checked"'; if ( 'administrator' == $role ) echo 'disabled="disabled"';?> /> <?php echo $name; ?> |
| 204 |
</label> |
| 205 |
</td> |
| 206 |
<?php endif; ?> |
| 207 |
<?php if ( 0 == $i % 4 ) : ?> |
| 208 |
</tr> |
| 209 |
<tr> |
| 210 |
<?php endif; ?> |
| 211 |
<?php endforeach; ?> |
| 212 |
</table> |
| 213 |
</td> |
| 214 |
</tr> |
| 215 |
<tr style="display: none;"> |
| 216 |
<td colspan="2" class="cawp-settings-title"> |
| 217 |
<div class="cawp-togglegroup"> |
| 218 |
<input type="checkbox" name="options[backend_item_reports]" value="1" id="backend_item_reports" <?php checked( $options['backend_item_reports'], 1 ); ?>> |
| 219 |
<label for="backend_item_reports"> |
| 220 |
<?php _e ( "enable reports on Posts List and Pages List", 'clicky-analytics' );?> |
| 221 |
</label> |
| 222 |
<div class="cawp-onoffswitch pull-right" aria-hidden="true"> |
| 223 |
<div class="cawp-onoffswitch-label"> |
| 224 |
<div class="cawp-onoffswitch-inner"></div> |
| 225 |
<div class="cawp-onoffswitch-switch"></div> |
| 226 |
</div> |
| 227 |
</div> |
| 228 |
</div> |
| 229 |
</td> |
| 230 |
</tr> |
| 231 |
<tr> |
| 232 |
<td colspan="2" class="cawp-settings-title"> |
| 233 |
<div class="cawp-togglegroup"> |
| 234 |
<input type="checkbox" name="options[dashboard_widget]" value="1" id="dashboard_widget" <?php checked( $options['dashboard_widget'], 1 ); ?>> |
| 235 |
<label for="dashboard_widget"> |
| 236 |
<?php _e ( "enable the reports widget on main dashboard", 'clicky-analytics' );?> |
| 237 |
</label> |
| 238 |
<div class="cawp-onoffswitch pull-right" aria-hidden="true"> |
| 239 |
<div class="cawp-onoffswitch-label"> |
| 240 |
<div class="cawp-onoffswitch-inner"></div> |
| 241 |
<div class="cawp-onoffswitch-switch"></div> |
| 242 |
</div> |
| 243 |
</div> |
| 244 |
</div> |
| 245 |
</td> |
| 246 |
</tr> |
| 247 |
<tr> |
| 248 |
<td colspan="2"><?php echo "<h2>" . __( "Frontend Permissions", 'clicky-analytics' ) . "</h2>"; ?></td> |
| 249 |
</tr> |
| 250 |
<tr> |
| 251 |
<td class="roles cawp-settings-title"> |
| 252 |
<label for="access_front"><?php _e("Show stats to:", 'clicky-analytics' ); ?> |
| 253 |
</label> |
| 254 |
</td> |
| 255 |
<td class="cawp-settings-roles"> |
| 256 |
<table> |
| 257 |
<tr> |
| 258 |
<?php if ( ! isset( $wp_roles ) ) : ?> |
| 259 |
<?php $wp_roles = new WP_Roles(); ?> |
| 260 |
<?php endif; ?> |
| 261 |
<?php $i = 0; ?> |
| 262 |
<?php foreach ( $wp_roles->role_names as $role => $name ) : ?> |
| 263 |
<?php if ( 'subscriber' != $role ) : ?> |
| 264 |
<?php $i++; ?> |
| 265 |
<td> |
| 266 |
<label> |
| 267 |
<input type="checkbox" name="options[access_front][]" value="<?php echo $role; ?>" <?php if ( in_array($role,$options['access_front']) || 'administrator' == $role ) echo 'checked="checked"'; if ( 'administrator' == $role ) echo 'disabled="disabled"';?> /><?php echo $name; ?> |
| 268 |
</label> |
| 269 |
</td> |
| 270 |
<?php endif; ?> |
| 271 |
<?php if ( 0 == $i % 4 ) : ?> |
| 272 |
</tr> |
| 273 |
<tr> |
| 274 |
<?php endif; ?> |
| 275 |
<?php endforeach; ?> |
| 276 |
</table> |
| 277 |
</td> |
| 278 |
</tr> |
| 279 |
<tr> |
| 280 |
<td colspan="2" class="cawp-settings-title"> |
| 281 |
<div class="cawp-togglegroup"> |
| 282 |
<input type="checkbox" name="options[frontend_item_reports]" value="1" id="frontend_item_reports" <?php checked( $options['frontend_item_reports'], 1 ); ?>> |
| 283 |
<label for="frontend_item_reports"> |
| 284 |
<?php echo " ".__("enable the reports widget on frontend admin bar", 'clicky-analytics' );?> |
| 285 |
</label> |
| 286 |
<div class="cawp-onoffswitch pull-right" aria-hidden="true"> |
| 287 |
<div class="cawp-onoffswitch-label"> |
| 288 |
<div class="cawp-onoffswitch-inner"></div> |
| 289 |
<div class="cawp-onoffswitch-switch"></div> |
| 290 |
</div> |
| 291 |
</div> |
| 292 |
</div> |
| 293 |
</td> |
| 294 |
</tr> |
| 295 |
<tr> |
| 296 |
<td colspan="2"> |
| 297 |
<hr><?php echo "<h2>" . __( "Google Maps API", 'clicky-analytics' ) . "</h2>"; ?></td> |
| 298 |
</tr> |
| 299 |
<tr> |
| 300 |
<td colspan="2" class="cawp-settings-title"> |
| 301 |
<?php echo __("Maps API Key:", 'clicky-analytics'); ?> |
| 302 |
<input type="text" style="text-align: center;" name="options[maps_api_key]" value="<?php echo esc_attr($options['maps_api_key']); ?>" size="50"> |
| 303 |
</td> |
| 304 |
</tr> |
| 305 |
<tr> |
| 306 |
<td colspan="2"> |
| 307 |
<hr> |
| 308 |
</td> |
| 309 |
</tr> |
| 310 |
<tr> |
| 311 |
<td colspan="2" class="submit"> |
| 312 |
<input type="submit" name="Submit" class="button button-primary" value="<?php _e('Save Changes', 'clicky-analytics' ) ?>" /> |
| 313 |
</td> |
| 314 |
</tr> |
| 315 |
</table> |
| 316 |
<input type="hidden" name="options[cawp_hidden]" value="Y"> |
| 317 |
<?php wp_nonce_field('cawp_form','cawp_security'); ?> |
| 318 |
</form> |
| 319 |
<?php |
| 320 |
CAWP_Tools::load_view( 'admin/views/settings-sidebar.php', array() ); |
| 321 |
} |
| 322 |
|
| 323 |
public static function errors_debugging() { |
| 324 |
$cawp = CAWP(); |
| 325 |
|
| 326 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 327 |
return; |
| 328 |
} |
| 329 |
|
| 330 |
$anonim = CAWP_Tools::anonymize_options( $cawp->config->options ); |
| 331 |
|
| 332 |
$options = self::update_options( 'frontend' ); |
| 333 |
if ( ! $cawp->config->options['sitekey'] || ! $cawp->config->options['siteid'] ) { |
| 334 |
$message = sprintf( '<div class="error"><p>%s</p></div>', sprintf( __( 'Something went wrong, check %1$s or %2$s.', 'clicky-analytics' ), sprintf( '<a href="%1$s">%2$s</a>', menu_page_url( 'cawp_errors_debugging', false ), __( 'Debug', 'clicky-analytics' ) ), sprintf( '<a href="%1$s">%2$s</a>', menu_page_url( 'cawp_setup', false ), __( 'enter the credentials', 'clicky-analytics' ) ) ) ); |
| 335 |
} |
| 336 |
?> |
| 337 |
<div class="wrap"> |
| 338 |
<?php echo "<h2>" . __( "Clicky Analytics - Debug", 'clicky-analytics' ) . "</h2>"; ?> |
| 339 |
</div> |
| 340 |
<div id="poststuff" class="cawp"> |
| 341 |
<div id="post-body" class="metabox-holder columns-2"> |
| 342 |
<div id="post-body-content"> |
| 343 |
<div class="settings-wrapper"> |
| 344 |
<div class="inside"> |
| 345 |
<?php if (isset($message)) echo $message; ?> |
| 346 |
<?php $tabs = array( 'errors' => __( "Errors", 'clicky-analytics' ), 'config' => __( "Plugin Settings", 'clicky-analytics' ), 'sysinfo' => __( "System", 'clicky-analytics' ) ); ?> |
| 347 |
<?php self::navigation_tabs( $tabs ); ?> |
| 348 |
<div id="cawp-errors"> |
| 349 |
<table class="cawp-settings-logdata"> |
| 350 |
<tr> |
| 351 |
<td> |
| 352 |
<?php echo "<h2>" . __( "Detected Errors", 'clicky-analytics' ) . "</h2>"; ?> |
| 353 |
</td> |
| 354 |
</tr> |
| 355 |
<tr> |
| 356 |
<td> |
| 357 |
<?php $errors_count = CAWP_Tools::get_cache( 'errors_count' ); ?> |
| 358 |
<pre class="cawp-settings-logdata"><?php echo '<span>' . __("Count: ", 'clicky-analytics') . '</span>' . (int)$errors_count;?></pre> |
| 359 |
<?php $error = CAWP_Tools::get_cache( 'capi_errors' ) ?> |
| 360 |
<?php $error_code = isset( $error[0] ) ? $error[0] : 'None' ?> |
| 361 |
<?php $error_reason = ( isset( $error[1] ) && !empty($error[1]) ) ? print_r( $error[1], true) : 'None' ?> |
| 362 |
<?php $error_details = isset( $error[2] ) ? print_r( $error[2], true) : 'None' ?> |
| 363 |
<pre class="cawp-settings-logdata"><?php echo '<span>' . __("Error Code: ", 'clicky-analytics') . '</span>' . esc_html( $error_code );?></pre> |
| 364 |
<pre class="cawp-settings-logdata"><?php echo '<span>' . __("Error Reason: ", 'clicky-analytics') . '</span>' . "\n" . esc_html( $error_reason );?></pre> |
| 365 |
<?php $error_details = str_replace( 'Deconf_', 'Google_', $error_details); ?> |
| 366 |
<pre class="cawp-settings-logdata"><?php echo '<span>' . __("Error Details: ", 'clicky-analytics') . '</span>' . "\n" . esc_html( $error_details );?></pre> |
| 367 |
<br /> |
| 368 |
<hr> |
| 369 |
</td> |
| 370 |
</tr> |
| 371 |
<tr> |
| 372 |
<td> |
| 373 |
<?php echo "<h2>" . __( "Sampled Data", 'clicky-analytics' ) . "</h2>"; ?> |
| 374 |
</td> |
| 375 |
</tr> |
| 376 |
<tr> |
| 377 |
<td> |
| 378 |
<?php $sampling = CAWP_TOOLS::get_cache( 'sampleddata' ); ?> |
| 379 |
<?php if ( $sampling ) :?> |
| 380 |
<?php printf( __( "Last Detected on %s.", 'clicky-analytics' ), '<strong>'. $sampling['date'] . '</strong>' );?> |
| 381 |
<br /> |
| 382 |
<?php printf( __( "The report was based on %s of sessions.", 'clicky-analytics' ), '<strong>'. $sampling['percent'] . '</strong>' );?> |
| 383 |
<br /> |
| 384 |
<?php printf( __( "Sessions ratio: %s.", 'clicky-analytics' ), '<strong>'. $sampling['sessions'] . '</strong>' ); ?> |
| 385 |
<?php else :?> |
| 386 |
<?php _e( "None", 'clicky-analytics' ); ?> |
| 387 |
<?php endif;?> |
| 388 |
</td> |
| 389 |
</tr> |
| 390 |
</table> |
| 391 |
</div> |
| 392 |
<div id="cawp-config"> |
| 393 |
<table class="cawp-settings-options"> |
| 394 |
<tr> |
| 395 |
<td><?php echo "<h2>" . __( "Plugin Configuration", 'clicky-analytics' ) . "</h2>"; ?></td> |
| 396 |
</tr> |
| 397 |
<tr> |
| 398 |
<td> |
| 399 |
<pre class="cawp-settings-logdata"><?php echo esc_html(print_r($anonim, true));?></pre> |
| 400 |
<br /> |
| 401 |
<hr> |
| 402 |
</td> |
| 403 |
</tr> |
| 404 |
</table> |
| 405 |
</div> |
| 406 |
<div id="cawp-sysinfo"> |
| 407 |
<table class="cawp-settings-options"> |
| 408 |
<tr> |
| 409 |
<td><?php echo "<h2>" . __( "System Information", 'clicky-analytics' ) . "</h2>"; ?></td> |
| 410 |
</tr> |
| 411 |
<tr> |
| 412 |
<td> |
| 413 |
<pre class="cawp-settings-logdata"><?php echo esc_html(CAWP_Tools::system_info());?></pre> |
| 414 |
<br /> |
| 415 |
<hr> |
| 416 |
</td> |
| 417 |
</tr> |
| 418 |
</table> |
| 419 |
</div> |
| 420 |
<?php |
| 421 |
CAWP_Tools::load_view( 'admin/views/settings-sidebar.php', array() ); |
| 422 |
} |
| 423 |
|
| 424 |
public static function setup() { |
| 425 |
$cawp = CAWP(); |
| 426 |
|
| 427 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 428 |
return; |
| 429 |
} |
| 430 |
$options = self::update_options( 'setup' ); |
| 431 |
printf( '<div id="capi-warning" class="updated"><p>%1$s <a href="https://deconf.com/clicky-analytics-dashboard-wordpress/">%2$s</a></p></div>', __( 'Loading the required libraries. If this results in a blank screen or a fatal error, try this solution:', 'clicky-analytics' ), __( 'Library conflicts between WordPress plugins', 'clicky-analytics' ) ); |
| 432 |
if ( null === $cawp->capi_controller ) { |
| 433 |
$cawp->capi_controller = new CAWP_CAPI_Controller(); |
| 434 |
} |
| 435 |
echo '<script type="text/javascript">jQuery("#capi-warning").hide()</script>'; |
| 436 |
|
| 437 |
if ( isset( $_POST['Clear'] ) ) { |
| 438 |
if ( isset( $_POST['cawp_security'] ) && wp_verify_nonce( $_POST['cawp_security'], 'cawp_form' ) ) { |
| 439 |
CAWP_Tools::clear_cache(); |
| 440 |
$message = "<div class='updated' id='cawp-autodismiss'><p>" . __( "Cleared Cache.", 'clicky-analytics' ) . "</p></div>"; |
| 441 |
} else { |
| 442 |
$message = "<div class='error' id='cawp-autodismiss'><p>" . __( "You don’t have permission to do this.", 'clicky-analytics' ) . "</p></div>"; |
| 443 |
} |
| 444 |
} |
| 445 |
|
| 446 |
if ( isset( $_POST['Reset_Err'] ) ) { |
| 447 |
if ( isset( $_POST['cawp_security'] ) && wp_verify_nonce( $_POST['cawp_security'], 'cawp_form' ) ) { |
| 448 |
|
| 449 |
if ( CAWP_Tools::get_cache( 'capi_errors' ) ) { |
| 450 |
|
| 451 |
$info = CAWP_Tools::system_info(); |
| 452 |
$info .= 'CAWP Version: ' . CAWP_CURRENT_VERSION; |
| 453 |
|
| 454 |
$sep = "\n---------------------------\n"; |
| 455 |
$error_report = $sep . print_r( CAWP_Tools::get_cache( 'capi_errors' ), true ); |
| 456 |
$error_report .= $sep . CAWP_Tools::get_cache( 'errors_count' ); |
| 457 |
$error_report .= $sep . $info; |
| 458 |
|
| 459 |
$error_report = urldecode( $error_report ); |
| 460 |
|
| 461 |
$url = CAWP_ENDPOINT_URL . 'cawp-report.php'; |
| 462 |
/* @formatter:off */ |
| 463 |
$response = wp_remote_post( $url, array( |
| 464 |
'method' => 'POST', |
| 465 |
'timeout' => 45, |
| 466 |
'redirection' => 5, |
| 467 |
'httpversion' => '1.0', |
| 468 |
'blocking' => true, |
| 469 |
'headers' => array(), |
| 470 |
'body' => array( 'error_report' => $error_report ), |
| 471 |
'cookies' => array() |
| 472 |
) |
| 473 |
); |
| 474 |
} |
| 475 |
|
| 476 |
/* @formatter:on */ |
| 477 |
CAWP_Tools::delete_cache( 'capi_errors' ); |
| 478 |
delete_option( 'cawp_got_updated' ); |
| 479 |
$message = "<div class='updated' id='cawp-autodismiss'><p>" . __( "All errors reseted.", 'clicky-analytics' ) . "</p></div>"; |
| 480 |
} else { |
| 481 |
$message = "<div class='error' id='cawp-autodismiss'><p>" . __( "You don’t have permission to do this.", 'clicky-analytics' ) . "</p></div>"; |
| 482 |
} |
| 483 |
} |
| 484 |
|
| 485 |
if ( isset( $_POST['options']['cawp_hidden'] ) && ! isset( $_POST['Reset_Err'] ) && ! isset( $_POST['Clear'] ) ) { |
| 486 |
$message = "<div class='updated' id='cawp-autodismiss'><p>" . __( "Settings saved.", 'clicky-analytics' ) . "</p></div>"; |
| 487 |
if ( ! ( isset( $_POST['cawp_security'] ) && wp_verify_nonce( $_POST['cawp_security'], 'cawp_form' ) ) ) { |
| 488 |
$message = "<div class='error' id='cawp-autodismiss'><p>" . __( "You don’t have permission to do this.", 'clicky-analytics' ) . "</p></div>"; |
| 489 |
} |
| 490 |
} |
| 491 |
?> |
| 492 |
<div class="wrap"> |
| 493 |
<?php echo "<h2>" . __( "Clicky Analytics - Setup", 'clicky-analytics' ) . "</h2>"; ?> |
| 494 |
<hr> |
| 495 |
</div> |
| 496 |
<div id="poststuff" class="cawp"> |
| 497 |
<div id="post-body" class="metabox-holder columns-2"> |
| 498 |
<div id="post-body-content"> |
| 499 |
<div class="settings-wrapper"> |
| 500 |
<div class="inside"> |
| 501 |
<?php if ( $cawp->capi_controller->capi_errors_handler() ) : ?> |
| 502 |
<?php $message = sprintf( '<div class="error"><p>%s</p></div>', sprintf( __( 'Something went wrong, check %1$s or %2$s.', 'clicky-analytics' ), sprintf( '<a href="%1$s">%2$s</a>', menu_page_url( 'cawp_errors_debugging', false ), __( 'Debug', 'clicky-analytics' ) ), sprintf( '<a href="%1$s">%2$s</a>', menu_page_url( 'cawp_setup', false ), __( 'authorize the plugin', 'clicky-analytics' ) ) ) );?> |
| 503 |
<?php endif;?> |
| 504 |
<?php if ( isset( $message ) ) :?> |
| 505 |
<?php echo $message;?> |
| 506 |
<?php endif; ?> |
| 507 |
<form name="cawp_form" method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>"> |
| 508 |
<input type="hidden" name="options[cawp_hidden]" value="Y"> |
| 509 |
<?php wp_nonce_field('cawp_form','cawp_security'); ?> |
| 510 |
<table class="cawp-settings-options"> |
| 511 |
<tr> |
| 512 |
<td colspan="2"> |
| 513 |
<?php echo "<h2>" . __( "Clicky Analytics Credentials", 'clicky-analytics' ) . "</h2>";?> |
| 514 |
</td> |
| 515 |
</tr> |
| 516 |
<tr> |
| 517 |
<td colspan="2" class="cawp-settings-info"> |
| 518 |
<?php printf(__('You need to create a %1$s and follow %2$s before proceeding to authorization.', 'clicky-analytics'), sprintf('<a href="%1$s" target="_blank">%2$s</a>', 'https://deconf.com/go/clicky/', __("Clicky Analytics account", 'clicky-analytics')), sprintf('<a href="%1$s" target="_blank">%2$s</a>', 'https://deconf.com/clicky-analytics-dashboard-wordpress/', __("this tutorial", 'clicky-analytics')));?> |
| 519 |
</td> |
| 520 |
<tr> |
| 521 |
<td class="cawp-settings-title"> |
| 522 |
<?php echo __("Site ID:", 'clicky-analytics'); ?> |
| 523 |
</td> |
| 524 |
<td> |
| 525 |
<input type="text" style="text-align: left;" name="options[siteid]" value="<?php echo esc_attr($options['siteid']); ?>" size="30"> |
| 526 |
</td> |
| 527 |
</tr> |
| 528 |
<tr> |
| 529 |
<td class="cawp-settings-title"> |
| 530 |
<?php echo __("Site Key:", 'clicky-analytics'); ?> |
| 531 |
</td> |
| 532 |
<td> |
| 533 |
<input type="text" style="text-align: left;" name="options[sitekey]" value="<?php echo esc_attr($options['sitekey']); ?>" size="30"> |
| 534 |
</td> |
| 535 |
</tr> |
| 536 |
<tr> |
| 537 |
<td colspan="2"> |
| 538 |
<input type="submit" name="Clear" class="button button-secondary" value="<?php _e( "Clear Cache", 'clicky-analytics' ); ?>" /> |
| 539 |
<input type="submit" name="Reset_Err" class="button button-secondary" value="<?php _e( "Report & Reset Errors", 'clicky-analytics' ); ?>" /> |
| 540 |
</td> |
| 541 |
</tr> |
| 542 |
<tr> |
| 543 |
<td colspan="2"> |
| 544 |
</td> |
| 545 |
</tr> |
| 546 |
<tr> |
| 547 |
<td colspan="2"> |
| 548 |
<hr><?php echo "<h2>" . __( "Appearance", 'clicky-analytics' ) . "</h2>"; ?></td> |
| 549 |
</tr> |
| 550 |
<tr> |
| 551 |
<td class="cawp-settings-title"> |
| 552 |
<label for="theme_color"><?php _e("Chart Color:", 'clicky-analytics' ); ?></label> |
| 553 |
</td> |
| 554 |
<td> |
| 555 |
<input type="text" id="theme_color" class="theme_color" name="options[theme_color]" value="<?php echo esc_attr($options['theme_color']); ?>" size="10"> |
| 556 |
</td> |
| 557 |
</tr> |
| 558 |
<tr> |
| 559 |
<td colspan="2"> |
| 560 |
</td> |
| 561 |
</tr> |
| 562 |
<tr> |
| 563 |
<td colspan="2" class="submit"> |
| 564 |
<input type="submit" name="Submit" class="button button-primary" value="<?php _e('Save Changes', 'clicky-analytics' ) ?>" /> |
| 565 |
</td> |
| 566 |
</tr> |
| 567 |
</table> |
| 568 |
</form> |
| 569 |
<?php CAWP_Tools::load_view( 'admin/views/settings-sidebar.php', array() ); ?> |
| 570 |
<?php return; ?> |
| 571 |
</table> |
| 572 |
</form> |
| 573 |
<?php |
| 574 |
|
| 575 |
CAWP_Tools::load_view( 'admin/views/settings-sidebar.php', array() ); |
| 576 |
} |
| 577 |
} |
| 578 |
|