private function maintain_compatibility() { if (GADWP_CURRENT_VERSION != get_option('gadwp_version')) { include_once $this->plugin_path . '/tools/tools.php'; $tools = new GADASH_Tools(); $tools->ga_dash_clear_cache(); delete_transient('gadash_lasterror'); update_option('gadwp_version', GADWP_CURRENT_VERSION); if (is_multisite()) { // Cleanup errors on the entire network foreach (wp_get_sites(array('limit' => apply_filters('gadwp_sites_limit', 100))) as $blog) { switch_to_blog($blog['blog_id']); delete_transient('ga_dash_gapi_errors'); restore_current_blog(); } } else { delete_transient('ga_dash_gapi_errors'); } } if (!isset($this->options['ga_enhanced_links'])) { $this->options['ga_enhanced_links'] = 0; } if (!isset($this->options['ga_enhanced_network'])) { $this->options['ga_dash_network'] = 0; } if (!isset($this->options['ga_enhanced_excludesa'])) { $this->options['ga_dash_excludesa'] = 0; } if (!isset($this->options['ga_dash_remarketing'])) { $this->options['ga_dash_remarketing'] = 0; } if (!isset($this->options['ga_dash_adsense'])) { $this->options['ga_dash_adsense'] = 0; } if (!isset($this->options['ga_speed_samplerate'])) { $this->options['ga_speed_samplerate'] = 1; } if (!isset($this->options['ga_event_bouncerate'])) { $this->options['ga_event_bouncerate'] = 0; } if (!is_array($this->options['ga_dash_access_front']) or empty($this->options['ga_dash_access_front'])) { $this->options['ga_dash_access_front'] = array(); $this->options['ga_dash_access_front'][] = 'administrator'; } if (!is_array($this->options['ga_dash_access_back']) or empty($this->options['ga_dash_access_back'])) { $this->options['ga_dash_access_back'] = array(); $this->options['ga_dash_access_back'][] = 'administrator'; } if (!is_array($this->options['ga_track_exclude'])) { $this->options['ga_track_exclude'] = array(); } if (!isset($this->options['ga_crossdomain_tracking'])) { $this->options['ga_crossdomain_tracking'] = 0; } if (!isset($this->options['ga_crossdomain_list'])) { $this->options['ga_crossdomain_list'] = ''; } if (!isset($this->options['ga_author_dimindex'])) { $this->options['ga_author_dimindex'] = 0; } if (!isset($this->options['ga_category_dimindex'])) { $this->options['ga_category_dimindex'] = 0; } if (!isset($this->options['ga_user_dimindex'])) { $this->options['ga_user_dimindex'] = 0; } if (!isset($this->options['ga_pubyear_dimindex'])) { $this->options['ga_pubyear_dimindex'] = 0; } if (!isset($this->options['ga_event_affiliates'])) { $this->options['ga_event_affiliates'] = '/out/'; } if (!isset($this->options['ga_aff_tracking'])) { $this->options['ga_aff_tracking'] = 0; } if (!isset($this->options['ga_hash_tracking'])) { $this->options['ga_hash_tracking'] = 0; } if (isset($this->options['ga_tracking_code'])) { unset($this->options['ga_tracking_code']); } }
<?php } self::output_sidebar(); } // Network Settings public static function general_settings_network() { global $GADASH_Config; global $wp_version; /* * Include Tools */ include_once $GADASH_Config->plugin_path . '/tools/tools.php'; $tools = new GADASH_Tools(); if (!current_user_can('manage_network_options')) { return; } $options = self::set_get_options('network'); /* * Include GAPI */ echo '<div id="gapi-warning" class="updated"><p>' . __('Loading the required libraries. If this results in a blank screen or a fatal error, try this solution:', "ga-dash") . ' <a href="https://deconf.com/ask/question/ga-dashboard-absolutely-empty-general-settings#answer-770">Library conflicts between WordPress plugins</a></p></div>'; include_once $GADASH_Config->plugin_path . '/tools/gapi.php'; global $GADASH_GAPI; echo '<script type="text/javascript">jQuery("#gapi-warning").hide()</script>'; if (isset($_POST['ga_dash_code'])) { if (!stripos('x' . $_POST['ga_dash_code'], 'UA-', 1) == 1) { try { $GADASH_GAPI->client->authenticate($_POST['ga_dash_code']); $GADASH_Config->options['ga_dash_token'] = $GADASH_GAPI->client->getAccessToken(); $google_token = json_decode($GADASH_GAPI->client->getAccessToken()); $GADASH_Config->options['ga_dash_refresh_token'] = $google_token->refresh_token; $GADASH_Config->set_plugin_options(true); $message = "<div class='updated'><p>" . __("Plugin authorization succeeded.", 'ga-dash') . "</p></div>"; $options = self::set_get_options('network'); if (is_multisite()) { // Cleanup errors on the entire network foreach (wp_get_sites(array('limit' => apply_filters('gadwp_sites_limit', 100))) as $blog) { switch_to_blog($blog['blog_id']); delete_transient('ga_dash_gapi_errors'); restore_current_blog(); } } else { delete_transient('ga_dash_gapi_errors'); } } catch (Google_IO_Exception $e) { set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e), $GADASH_GAPI->error_timeout); return false; } catch (Google_Service_Exception $e) { set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()), $GADASH_GAPI->error_timeout); set_transient('ga_dash_gapi_errors', $e->getErrors(), $GADASH_GAPI->error_timeout); return $e->getCode(); } catch (Exception $e) { set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e) . "\nResponseHttpCode:" . $e->getCode(), $GADASH_GAPI->error_timeout); $GADASH_GAPI->ga_dash_reset_token(false); } } else { $message = "<div class='error'><p>" . __("The access code is <strong>NOT</strong> your <strong>Tracking ID</strong> (UA-XXXXX-X). Try again, and use the red link to get your access code", 'ga-dash') . ".</p></div>"; } } if (isset($_POST['Refresh'])) { if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) { $GADASH_Config->options['ga_dash_profile_list'] = ''; $message = "<div class='updated'><p>" . __("Properties refreshed.", 'ga-dash') . "</p></div>"; $options = self::set_get_options('network'); } else { $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>"; } } if ($GADASH_Config->options['ga_dash_token'] and $GADASH_GAPI->client->getAccessToken()) { if ($GADASH_Config->options['ga_dash_profile_list']) { $profiles = $GADASH_Config->options['ga_dash_profile_list']; } else { $profiles = $GADASH_GAPI->refresh_profiles(); } if ($profiles) { $GADASH_Config->options['ga_dash_profile_list'] = $profiles; if (isset($GADASH_Config->options['ga_dash_tableid_jail']) and !$GADASH_Config->options['ga_dash_tableid_jail']) { $profile = $tools->guess_default_domain($profiles); $GADASH_Config->options['ga_dash_tableid_jail'] = $profile; $GADASH_Config->options['ga_dash_tableid'] = $profile; } $GADASH_Config->set_plugin_options(true); $options = self::set_get_options('network'); } } if (isset($_POST['Clear'])) { if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) { $tools->ga_dash_clear_cache(); $message = "<div class='updated'><p>" . __("Cleared Cache.", 'ga-dash') . "</p></div>"; } else { $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>"; } } if (isset($_POST['Reset'])) { if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) { $GADASH_GAPI->ga_dash_reset_token(true); $tools->ga_dash_clear_cache(); $message = "<div class='updated'><p>" . __("Token Reseted and Revoked.", 'ga-dash') . "</p></div>"; $options = self::set_get_options('Reset'); } else { $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>"; } } if (isset($_POST['options']['ga_dash_hidden']) and !isset($_POST['Clear']) and !isset($_POST['Reset']) and !isset($_POST['Refresh'])) { $message = "<div class='updated'><p>" . __("Settings saved.", 'ga-dash') . "</p></div>"; if (!(isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form'))) { $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>"; } } if (isset($_POST['Hide'])) { if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) { $message = "<div class='updated'><p>" . __("All other domains/properties were removed.", 'ga-dash') . "</p></div>"; $lock_profile = $tools->get_selected_profile($GADASH_Config->options['ga_dash_profile_list'], $GADASH_Config->options['ga_dash_tableid_jail']); $GADASH_Config->options['ga_dash_profile_list'] = array($lock_profile); $options = self::set_get_options('network'); } else { $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>"; } } ?> <div class="wrap"> <?php echo "<h2>" . __("Google Analytics Settings", 'ga-dash') . "</h2>"; ?> <hr> </div> <div id="poststuff"> <div id="post-body" class="metabox-holder columns-2"> <div id="post-body-content"> <div class="settings-wrapper"> <div class="inside"> <?php if ($GADASH_GAPI->gapi_errors_handler()) { $message = "<div class='error'><p>" . __("Something went wrong, check", 'ga-dash') . " <a href='" . menu_page_url('gadash_errors_debugging', false) . "'>" . __('Errors & Debug', 'ga-dash') . "</a> " . __('or', 'ga-dash') . " <a href='" . menu_page_url('gadash_settings', false) . "'>" . __('auhorize the plugin', 'ga-dash') . "</a>.</p></div>"; } if (isset($_POST['Authorize'])) { $tools->ga_dash_clear_cache(); $GADASH_GAPI->token_request(); echo "<div class='updated'><p>" . __("Use the red link (see below) to generate and get your access code!", 'ga-dash') . "</p></div>"; } else { if (isset($message)) { echo $message; } ?> <form name="ga_dash_form" method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?> "> <input type="hidden" name="options[ga_dash_hidden]" value="Y"> <?php wp_nonce_field('gadash_form', 'gadash_security'); ?> <table class="options"> <tr> <td colspan="2"><?php echo "<h2>" . __("Network Setup", 'ga-dash') . "</h2>"; ?> </td> </tr> <tr> <td colspan="2" class="title"> <div class="onoffswitch"> <input type="checkbox" name="options[ga_dash_network]" value="1" class="onoffswitch-checkbox" id="ga_dash_network" <?php checked($options['ga_dash_network'], 1); ?> onchange="this.form.submit()"> <label class="onoffswitch-label" for="ga_dash_network"> <div class="onoffswitch-inner"></div> <div class="onoffswitch-switch"></div> </label> </div> <div class="switch-desc"><?php _e(" use a single Google Analytics account for the entire network", 'ga-dash'); ?> </div> </td> </tr> <?php if ($options['ga_dash_network']) { //Network Mode check ?> <tr> <td colspan="2"><hr></td> </tr> <tr> <td colspan="2"><?php echo "<h2>" . __("Plugin Authorization", 'ga-dash') . "</h2>"; ?> </td> </tr> <tr> <td colspan="2" class="info"> <?php echo __("You should watch the", 'ga-dash') . " <a href='https://deconf.com/google-analytics-dashboard-wordpress/' target='_blank'>" . __("video", 'ga-dash') . "</a> " . __("and read this", 'ga-dash') . " <a href='https://deconf.com/google-analytics-dashboard-wordpress/' target='_blank'>" . __("tutorial", 'ga-dash') . "</a> " . __("before proceeding to authorization. This plugin requires a properly configured Google Analytics account", 'ga-dash') . "!"; ?> </td> </tr> <?php if (!$options['ga_dash_token'] or $options['ga_dash_userapi']) { ?> <tr> <td colspan="2" class="info"><input name="options[ga_dash_userapi]" type="checkbox" id="ga_dash_userapi" value="1" <?php checked($options['ga_dash_userapi'], 1); ?> onchange="this.form.submit()" /><?php _e(" use your own API Project credentials", 'ga-dash'); ?> </td> </tr> <?php } if ($options['ga_dash_userapi']) { ?> <tr> <td class="title"><label for="options[ga_dash_apikey]"><?php _e("API Key:", 'ga-dash'); ?> </label> </td> <td><input type="text" name="options[ga_dash_apikey]" value="<?php echo esc_attr($options['ga_dash_apikey']); ?> " size="40" required="required"></td> </tr> <tr> <td class="title"><label for="options[ga_dash_clientid]"><?php _e("Client ID:", 'ga-dash'); ?> </label> </td> <td><input type="text" name="options[ga_dash_clientid]" value="<?php echo esc_attr($options['ga_dash_clientid']); ?> " size="40" required="required"></td> </tr> <tr> <td class="title"><label for="options[ga_dash_clientsecret]"><?php _e("Client Secret:", 'ga-dash'); ?> </label> </td> <td><input type="text" name="options[ga_dash_clientsecret]" value="<?php echo esc_attr($options['ga_dash_clientsecret']); ?> " size="40" required="required"> <input type="hidden" name="options[ga_dash_hidden]" value="Y"> <?php wp_nonce_field('gadash_form', 'gadash_security'); ?> </td> </tr> <?php } ?> <?php if ($options['ga_dash_token']) { ?> <tr> <td colspan="2"><input type="submit" name="Reset" class="button button-secondary" value="<?php _e("Clear Authorization", 'ga-dash'); ?> " /> <input type="submit" name="Clear" class="button button-secondary" value="<?php _e("Clear Cache", 'ga-dash'); ?> " /> <input type="submit" name="Refresh" class="button button-secondary" value="<?php _e("Refresh Properties", 'ga-dash'); ?> " /></td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td colspan="2"><?php echo "<h2>" . __("Properties/Views Settings", 'ga-dash') . "</h2>"; ?> </td> </tr> <?php if (isset($options['ga_dash_tableid_network'])) { $options['ga_dash_tableid_network'] = json_decode(json_encode($options['ga_dash_tableid_network']), FALSE); } foreach (wp_get_sites(array('limit' => apply_filters('gadwp_sites_limit', 100))) as $blog) { ?> <tr> <td class="title-select"><label for="ga_dash_tableid_network"><?php echo '<strong>' . $blog['domain'] . $blog['path'] . '</strong>: '; ?> </label></td> <td><select id="ga_dash_tableid_network" <?php disabled(is_array($options['ga_dash_profile_list']), false); ?> name="options[ga_dash_tableid_network][<?php echo $blog['blog_id']; ?> ]"> <?php if (is_array($options['ga_dash_profile_list'])) { foreach ($options['ga_dash_profile_list'] as $items) { if ($items[3]) { echo '<option value="' . esc_attr($items[1]) . '" ' . selected($items[1], isset($options['ga_dash_tableid_network']->{$blog}['blog_id']) ? $options['ga_dash_tableid_network']->{$blog}['blog_id'] : ''); echo ' title="' . __("View Name:", 'ga-dash') . ' ' . esc_attr($items[0]) . '">' . $tools->ga_dash_get_profile_domain($items[3]) . ' ⇒ ' . esc_attr($items[0]) . '</option>'; } } } else { echo '<option value="">' . __("Property not found", 'ga-dash') . '</option>'; } ?> </select><br /></td> </tr> <?php } ?> <tr> <td colspan="2"><hr><?php echo "<h2>" . __("Exclude Tracking", 'ga-dash') . "</h2>"; ?> </td> </tr> <tr> <td colspan="2" class="title"> <div class="onoffswitch"> <input type="checkbox" name="options[ga_dash_excludesa]" value="1" class="onoffswitch-checkbox" id="ga_dash_excludesa"<?php checked($options['ga_dash_excludesa'], 1); ?> "> <label class="onoffswitch-label" for="ga_dash_excludesa"> <div class="onoffswitch-inner"></div> <div class="onoffswitch-switch"></div> </label> </div> <div class="switch-desc"><?php _e(" exclude Super Admin tracking for the entire network", 'ga-dash'); ?> </div> </td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td colspan="2" class="submit"><input type="submit" name="Submit" class="button button-primary" value="<?php _e('Save Changes', 'ga-dash'); ?> " /></td> </tr> <?php } else { ?> <tr> <td colspan="2"><hr></td> </tr> <tr> <td colspan="2"><input type="submit" name="Authorize" class="button button-secondary" id="authorize" value="<?php _e("Authorize Plugin", 'ga-dash'); ?> " /> <input type="submit" name="Clear" class="button button-secondary" value="<?php _e("Clear Cache", 'ga-dash'); ?> " /></td> </tr> <?php } //Network Mode check ?> <tr> <td colspan="2"><hr></td> </tr> </table> </form> <?php self::output_sidebar(); return;
public static function general_settings_network() { global $GADASH_Config; global $wp_version; /* * Include Tools */ include_once $GADASH_Config->plugin_path . '/tools/tools.php'; $tools = new GADASH_Tools(); if (!current_user_can('manage_network_options')) { return; } $options = self::set_get_options('network'); /* * Include GAPI */ include_once $GADASH_Config->plugin_path . '/tools/gapi.php'; global $GADASH_GAPI; if (isset($_POST['ga_dash_code'])) { try { $GADASH_GAPI->client->authenticate($_POST['ga_dash_code']); $GADASH_Config->options['ga_dash_token'] = $GADASH_GAPI->client->getAccessToken(); $google_token = json_decode($GADASH_GAPI->client->getAccessToken()); $GADASH_Config->options['ga_dash_refresh_token'] = $google_token->refresh_token; $GADASH_Config->set_plugin_options(true); $message = "<div class='updated'><p><strong>" . __("Plugin authorization succeeded.", 'ga-dash') . "</strong></p></div>"; $options = self::set_get_options('network'); } catch (Google_IO_Exception $e) { update_option('gadash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e)); return false; } catch (Exception $e) { update_option('gadash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e) . "\nResponseHttpCode:" . $e->getCode()); $GADASH_GAPI->ga_dash_reset_token(false); } } if (isset($_POST['Refresh'])) { if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) { $GADASH_Config->options['ga_dash_profile_list'] = ''; $message = "<div class='updated'><p><strong>" . __("Properties refreshed.", 'ga-dash') . "</strong></p></div>"; $options = self::set_get_options('network'); } else { $message = "<div class='error'><p><strong>" . __("Cheating Huh?", 'ga-dash') . "</strong></p></div>"; } } if (function_exists('curl_version')) { if ($GADASH_GAPI->client->getAccessToken()) { if ($GADASH_Config->options['ga_dash_profile_list']) { $profiles = $GADASH_Config->options['ga_dash_profile_list']; } else { $profiles = $GADASH_GAPI->refresh_profiles(); } if ($profiles) { $GADASH_Config->options['ga_dash_profile_list'] = $profiles; if (isset($GADASH_Config->options['ga_dash_tableid_jail']) and !$GADASH_Config->options['ga_dash_tableid_jail']) { $profile = $tools->guess_default_domain($profiles); $GADASH_Config->options['ga_dash_tableid_jail'] = $profile; $GADASH_Config->options['ga_dash_tableid'] = $profile; } $GADASH_Config->set_plugin_options(true); $options = self::set_get_options('network'); } } } if (isset($_POST['Clear'])) { if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) { $tools->ga_dash_clear_cache(); $message = "<div class='updated'><p><strong>" . __("Cleared Cache.", 'ga-dash') . "</strong></p></div>"; } else { $message = "<div class='error'><p><strong>" . __("Cheating Huh?", 'ga-dash') . "</strong></p></div>"; } } if (isset($_POST['Reset'])) { if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) { $GADASH_GAPI->ga_dash_reset_token(true); $tools->ga_dash_clear_cache(); $message = "<div class='updated'><p><strong>" . __("Token Reseted and Revoked.", 'ga-dash') . "</strong></p></div>"; $options = self::set_get_options('Reset'); } else { $message = "<div class='error'><p><strong>" . __("Cheating Huh?", 'ga-dash') . "</strong></p></div>"; } } if (isset($_POST['Log'])) { $message = "<div class='updated'><p><strong>" . __("Dumping log data.", 'ga-dash') . "</strong></p></div>"; } if (isset($_POST['options']['ga_dash_hidden']) and !isset($_POST['Clear']) and !isset($_POST['Reset']) and !isset($_POST['Log']) and !isset($_POST['Refresh'])) { $message = "<div class='updated'><p><strong>" . __("Options saved.", 'ga-dash') . "</strong></p></div>"; if (!(isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form'))) { $message = "<div class='error'><p><strong>" . __("Cheating Huh?", 'ga-dash') . "</strong></p></div>"; } } if (isset($_POST['Hide'])) { if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) { $message = "<div class='updated'><p><strong>" . __("All other domains/properties were removed.", 'ga-dash') . "</strong></p></div>"; $lock_profile = $tools->get_selected_profile($GADASH_Config->options['ga_dash_profile_list'], $GADASH_Config->options['ga_dash_tableid_jail']); $GADASH_Config->options['ga_dash_profile_list'] = array($lock_profile); $options = self::set_get_options('network'); } else { $message = "<div class='error'><p><strong>" . __("Cheating Huh?", 'ga-dash') . "</strong></p></div>"; } } if (!function_exists('curl_version')) { $message = "<div class='error'><p><strong>" . __("PHP CURL is required. Please install/enable PHP CURL!", 'ga-dash') . "</strong></p></div>"; } ?> <div class="wrap"> <?php echo "<h2>" . __("Google Analytics Settings", 'ga-dash') . "</h2>"; ?> <hr> </div> <div id="poststuff"> <div id="post-body" class="metabox-holder columns-2"> <div id="post-body-content"> <div class="settings-wrapper"> <div class="inside"> <?php if (isset($_POST['Authorize'])) { $tools->ga_dash_clear_cache(); $GADASH_GAPI->token_request(); } else { if (isset($message)) { echo $message; } ?> <form name="ga_dash_form" method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?> "> <input type="hidden" name="options[ga_dash_hidden]" value="Y"> <?php wp_nonce_field('gadash_form', 'gadash_security'); ?> <table class="options"> <tr> <td colspan="2"><?php echo "<h2>" . __("Network Setup", 'ga-dash') . "</h2>"; ?> </td> </tr> <tr> <td colspan="2" class="title"> <div class="onoffswitch"> <input type="checkbox" name="options[ga_dash_network]" value="1" class="onoffswitch-checkbox" id="ga_dash_network" <?php checked($options['ga_dash_network'], 1); ?> onchange="this.form.submit()"> <label class="onoffswitch-label" for="ga_dash_network"> <div class="onoffswitch-inner"></div> <div class="onoffswitch-switch"></div> </label> </div> <div class="switch-desc"><?php _e(" use a single Google Analytics account for the entire network", 'ga-dash'); ?> </div> </td> </tr> <?php if ($options['ga_dash_network']) { //Network Mode check ?> <tr> <td colspan="2"><hr></td> </tr> <tr> <td colspan="2"><?php echo "<h2>" . __("Plugin Authorization", 'ga-dash') . "</h2>"; ?> </td> </tr> <tr> <td colspan="2" class="info"> <?php echo __("You should watch the", 'ga-dash') . " <a href='https://deconf.com/google-analytics-dashboard-wordpress/' target='_blank'>" . __("video", 'ga-dash') . "</a> " . __("and read this", 'ga-dash') . " <a href='https://deconf.com/google-analytics-dashboard-wordpress/' target='_blank'>" . __("tutorial", 'ga-dash') . "</a> " . __("before proceeding to authorization. This plugin requires a properly configured Google Analytics account", 'ga-dash') . "!"; ?> </td> </tr> <?php if (!$options['ga_dash_token'] or $options['ga_dash_userapi']) { ?> <tr> <td colspan="2" class="info"><input name="options[ga_dash_userapi]" type="checkbox" id="ga_dash_userapi" value="1" <?php checked($options['ga_dash_userapi'], 1); ?> onchange="this.form.submit()" /><?php _e(" use your own API Project credentials", 'ga-dash'); ?> </td> </tr> <?php } if ($options['ga_dash_userapi']) { ?> <tr> <td class="title"><label for="options[ga_dash_apikey]"><?php _e("API Key:", 'ga-dash'); ?> </label> </td> <td><input type="text" name="options[ga_dash_apikey]" value="<?php echo esc_attr($options['ga_dash_apikey']); ?> " size="40"></td> </tr> <tr> <td class="title"><label for="options[ga_dash_clientid]"><?php _e("Client ID:", 'ga-dash'); ?> </label> </td> <td><input type="text" name="options[ga_dash_clientid]" value="<?php echo esc_attr($options['ga_dash_clientid']); ?> " size="40"></td> </tr> <tr> <td class="title"><label for="options[ga_dash_clientsecret]"><?php _e("Client Secret:", 'ga-dash'); ?> </label> </td> <td><input type="text" name="options[ga_dash_clientsecret]" value="<?php echo esc_attr($options['ga_dash_clientsecret']); ?> " size="40"> <input type="hidden" name="options[ga_dash_hidden]" value="Y"> <?php wp_nonce_field('gadash_form', 'gadash_security'); ?> </td> </tr> <?php } ?> <?php if ($options['ga_dash_token']) { ?> <tr> <td colspan="2"><input type="submit" name="Reset" class="button button-secondary" value="<?php _e("Clear Authorization", 'ga-dash'); ?> " /> <input type="submit" name="Clear" class="button button-secondary" value="<?php _e("Clear Cache", 'ga-dash'); ?> " /> <input type="submit" name="Refresh" class="button button-secondary" value="<?php _e("Refresh Properties", 'ga-dash'); ?> " /></td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td colspan="2"><?php echo "<h2>" . __("Properties/Views Settings", 'ga-dash') . "</h2>"; ?> </td> </tr> <?php if (isset($options['ga_dash_tableid_network'])) { $options['ga_dash_tableid_network'] = json_decode(json_encode($options['ga_dash_tableid_network']), FALSE); } foreach (wp_get_sites() as $blog) { ?> <tr> <td class="title-select"><label for="ga_dash_tableid_network"><?php echo '<strong>' . $blog['domain'] . $blog['path'] . '</strong>: '; ?> </label></td> <td><select id="ga_dash_tableid_network" name="options[ga_dash_tableid_network][<?php echo $blog['blog_id']; ?> ]"> <?php foreach ($options['ga_dash_profile_list'] as $items) { if ($items[3]) { echo '<option value="' . esc_attr($items[1]) . '" ' . selected($items[1], isset($options['ga_dash_tableid_network']->{$blog}['blog_id']) ? $options['ga_dash_tableid_network']->{$blog}['blog_id'] : ''); echo ' title="' . __("View Name:", 'ga-dash') . ' ' . esc_attr($items[0]) . '">' . $tools->ga_dash_get_profile_domain($items[3]) . ' ⇒ ' . esc_attr($items[0]) . '</option>'; } } ?> </select><br /></td> </tr> <?php } ?> <tr> <td colspan="2"><hr></td> </tr> <tr> <td class="debugging"><?php echo "<h2>" . __("Debugging Data", 'ga-dash') . "</h2></td>" . '<td><a href="#" id="show_hide" class="show_hide">Show Log</a>'; ?> </td> </tr> <tr> <td colspan="2"> <div class="log_data"> <?php echo '<pre class="log_data">************************************* Start Log *************************************<br/><br/>'; $anonim = $GADASH_Config->options; $anonim['wp_version'] = $wp_version; $anonim['gadwp_version'] = GADWP_CURRENT_VERSION; if ($anonim['ga_dash_token']) { $anonim['ga_dash_token'] = 'HIDDEN'; } if ($anonim['ga_dash_refresh_token']) { $anonim['ga_dash_refresh_token'] = 'HIDDEN'; } if ($anonim['ga_dash_clientid']) { $anonim['ga_dash_clientid'] = 'HIDDEN'; } if ($anonim['ga_dash_clientsecret']) { $anonim['ga_dash_clientsecret'] = 'HIDDEN'; } if ($anonim['ga_dash_apikey']) { $anonim['ga_dash_apikey'] = 'HIDDEN'; } print_r($anonim); echo '<br/>Last Error: '; echo esc_html(print_r(get_option('gadash_lasterror', 'N/A'), true)); echo '<br/><br/>************************************* End Log *************************************</pre>'; ?> </div> </td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td colspan="2" class="submit"><input type="submit" name="Submit" class="button button-primary" value="<?php _e('Update Options', 'ga-dash'); ?> " /></td> </tr> <?php } else { ?> <tr> <td colspan="2"><hr></td> </tr> <tr> <td colspan="2"><input type="submit" name="Authorize" class="button button-secondary" id="authorize" value="<?php _e("Authorize Plugin", 'ga-dash'); ?> " <?php echo !function_exists('curl_version') ? 'disabled="disabled"' : ''; ?> /> <input type="submit" name="Clear" class="button button-secondary" value="<?php _e("Clear Cache", 'ga-dash'); ?> " /></td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td class="debugging"><?php echo "<h2>" . __("Debugging Data", 'ga-dash') . "</h2></td>" . '<td><a href="#" id="show_hide" class="show_hide">Show Log</a>'; ?> </td> </tr> <tr> <td colspan="2"> <div class="log_data"> <?php echo '<pre class="log_data">************************************* Start Log *************************************<br/><br/>'; $anonim = $GADASH_Config->options; $anonim['wp_version'] = $wp_version; $anonim['gadwp_version'] = GADWP_CURRENT_VERSION; if ($anonim['ga_dash_token']) { $anonim['ga_dash_token'] = 'HIDDEN'; } if ($anonim['ga_dash_refresh_token']) { $anonim['ga_dash_refresh_token'] = 'HIDDEN'; } if ($anonim['ga_dash_clientid']) { $anonim['ga_dash_clientid'] = 'HIDDEN'; } if ($anonim['ga_dash_clientsecret']) { $anonim['ga_dash_clientsecret'] = 'HIDDEN'; } if ($anonim['ga_dash_apikey']) { $anonim['ga_dash_apikey'] = 'HIDDEN'; } echo esc_html(print_r($anonim, true)); echo '<br/>Last Error: '; echo esc_html(print_r(get_option('gadash_lasterror', 'N/A'), true)); echo '<br/><br/>************************************* End Log *************************************</pre>'; ?> </div> </td> </tr> <?php } //Network Mode check ?> <tr> <td colspan="2"><hr></td> </tr> </table> </form> <?php self::output_sidebar(); return; } ?> </table> </form> <?php } self::output_sidebar(); }
public static function general_settings() { global $GADASH_Config; /* * Include Tools */ include_once $GADASH_Config->plugin_path . '/tools/tools.php'; $tools = new GADASH_Tools(); if (!current_user_can('manage_options')) { return; } $options = self::set_get_options('general'); /* * Include GAPI */ include_once $GADASH_Config->plugin_path . '/tools/gapi.php'; global $GADASH_GAPI; if (isset($_REQUEST['ga_dash_code'])) { try { $GADASH_GAPI->client->authenticate($_REQUEST['ga_dash_code']); $GADASH_Config->options['ga_dash_token'] = $GADASH_GAPI->client->getAccessToken(); $google_token = json_decode($GADASH_GAPI->client->getAccessToken()); $GADASH_Config->options['ga_dash_refresh_token'] = $google_token->refresh_token; $GADASH_Config->set_plugin_options(); $message = "<div class='updated'><p><strong>" . __("Plugin authorization succeeded.", 'ga-dash') . "</strong></p></div>"; $options = self::set_get_options('general'); } catch (Google_IOException $e) { update_option('gadash_lasterror', esc_html($e)); return false; } catch (Exception $e) { update_option('gadash_lasterror', esc_html($e)); ga_dash_reset_token(false); } } if (function_exists('curl_version')) { if ($GADASH_GAPI->client->getAccessToken()) { if ($GADASH_Config->options['ga_dash_profile_list']) { $profiles = $GADASH_Config->options['ga_dash_profile_list']; } else { $profiles = $GADASH_GAPI->refresh_profiles(); } if ($profiles) { $GADASH_Config->options['ga_dash_profile_list'] = $profiles; if (!$GADASH_Config->options['ga_dash_tableid_jail']) { $profile = $tools->guess_default_domain($profiles); $GADASH_Config->options['ga_dash_tableid_jail'] = $profile; $GADASH_Config->options['ga_dash_tableid'] = $profile; } $GADASH_Config->set_plugin_options(); $options = self::set_get_options('general'); } } } if (isset($_REQUEST['Clear'])) { $tools->ga_dash_clear_cache(); $message = "<div class='updated'><p><strong>" . __("Cleared Cache.", 'ga-dash') . "</strong></p></div>"; } if (isset($_REQUEST['Reset'])) { $GADASH_GAPI->ga_dash_reset_token(true); $tools->ga_dash_clear_cache(); $message = "<div class='updated'><p><strong>" . __("Token Reseted and Revoked.", 'ga-dash') . "</strong></p></div>"; $options = self::set_get_options('Reset'); } if (isset($_REQUEST['Log'])) { $message = "<div class='updated'><p><strong>" . __("Dumping log data.", 'ga-dash') . "</strong></p></div>"; } if (isset($_REQUEST['options']['ga_dash_hidden']) and !isset($_REQUEST['Clear']) and !isset($_REQUEST['Reset']) and !isset($_REQUEST['Log'])) { $message = "<div class='updated'><p><strong>" . __("Options saved.", 'ga-dash') . "</strong></p></div>"; } if (isset($_REQUEST['Hide'])) { $message = "<div class='updated'><p><strong>" . __("All other domains/properties were removed.", 'ga-dash') . "</strong></p></div>"; $lock_profile = $tools->get_selected_profile($GADASH_Config->options['ga_dash_profile_list'], $GADASH_Config->options['ga_dash_tableid_jail']); $GADASH_Config->options['ga_dash_profile_list'] = array($lock_profile); $options = self::set_get_options('general'); } if (!function_exists('curl_version')) { $message = "<div class='error'><p><strong>" . __("CURL is required. Please install/enable CURL!", 'ga-dash') . "</strong></p></div>"; } ?> <div class="wrap"> <?php echo "<h2>" . __("Google Analytics Settings", 'ga-dash') . "</h2>"; ?> <hr> </div> <div id="poststuff"> <div id="post-body" class="metabox-holder columns-2"> <div id="post-body-content"> <div class="settings-wrapper"> <div class="inside"> <?php if (isset($_REQUEST['Authorize'])) { $tools->ga_dash_clear_cache(); $GADASH_GAPI->token_request(); } else { if (isset($message)) { echo $message; } ?> <form name="ga_dash_form" method="post" action="<?php echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']); ?> "> <input type="hidden" name="options[ga_dash_hidden]" value="Y"> <table class="options"> <tr> <td colspan="2"><?php echo "<h2>" . __("Plugin Authorization", 'ga-dash') . "</h2>"; ?> </td> </tr> <tr> <td colspan="2" class="info"> <?php echo __("You should watch the", 'ga-dash') . " <a href='http://deconf.com/google-analytics-dashboard-wordpress/' target='_blank'>" . __("video", 'ga-dash') . "</a> " . __("and read this", 'ga-dash') . " <a href='http://deconf.com/google-analytics-dashboard-wordpress/' target='_blank'>" . __("tutorial", 'ga-dash') . "</a> " . __("before proceeding to authorization. This plugin requires a properly configured Google Analytics account", 'ga-dash') . "!"; ?> </td> </tr> <?php if (!$options['ga_dash_token'] or $options['ga_dash_userapi']) { ?> <tr> <td colspan="2" class="info"><input name="options[ga_dash_userapi]" type="checkbox" id="ga_dash_userapi" value="1" <?php checked($options['ga_dash_userapi'], 1); ?> onchange="this.form.submit()" /><?php _e(" use your own API Project credentials", 'ga-dash'); ?> </td> </tr> <?php } if ($options['ga_dash_userapi']) { ?> <tr> <td class="title"><label for="options[ga_dash_apikey]"><?php _e("API Key:", 'ga-dash'); ?> </label> </td> <td><input type="text" name="options[ga_dash_apikey]" value="<?php echo $options['ga_dash_apikey']; ?> " size="40"></td> </tr> <tr> <td class="title"><label for="options[ga_dash_clientid]"><?php _e("Client ID:", 'ga-dash'); ?> </label> </td> <td><input type="text" name="options[ga_dash_clientid]" value="<?php echo $options['ga_dash_clientid']; ?> " size="40"> </td> </tr> <tr> <td class="title"><label for="options[ga_dash_clientsecret]"><?php _e("Client Secret:", 'ga-dash'); ?> </label> </td> <td><input type="text" name="options[ga_dash_clientsecret]" value="<?php echo $options['ga_dash_clientsecret']; ?> " size="40"> <input type="hidden" name="options[ga_dash_hidden]" value="Y"> </td> </tr> <?php } ?> <?php if ($options['ga_dash_token']) { ?> <tr> <td colspan="2"><input type="submit" name="Reset" class="button button-secondary" value="<?php _e("Clear Authorization", 'ga-dash'); ?> " /> <input type="submit" name="Clear" class="button button-secondary" value="<?php _e("Clear Cache", 'ga-dash'); ?> " /></td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td colspan="2"><?php echo "<h2>" . __("General Settings", 'ga-dash') . "</h2>"; ?> </td> </tr> <tr> <td class="title"><label for="ga_dash_tableid_jail"><?php _e("Select Domain: ", 'ga-dash'); ?> </label></td> <td><select id="ga_dash_tableid_jail" name="options[ga_dash_tableid_jail]"> <?php foreach ($options['ga_dash_profile_list'] as $items) { if ($items[3]) { echo '<option value="' . $items[1] . '" ' . selected($items[1], $options['ga_dash_tableid_jail']); echo ' title="' . __("View Name:", 'ga-dash') . ' ' . $items[0] . '">' . $tools->ga_dash_get_profile_domain($items[3]) . '</option>'; } } ?> </select> <?php if (count($options['ga_dash_profile_list']) > 1) { _e("and/or hide all other domains", 'ga-dash'); ?> <input type="submit" name="Hide" class="button button-secondary" value="<?php _e("Hide Now", 'ga-dash'); ?> " /> <?php } ?> </td> </tr> <?php if ($options['ga_dash_tableid_jail']) { ?> <tr> <td class="title"></td> <td><?php $profile_info = $tools->get_selected_profile($GADASH_Config->options['ga_dash_profile_list'], $GADASH_Config->options['ga_dash_tableid_jail']); echo '<pre>' . __("View Name:", 'ga-dash') . "\t" . $profile_info[0] . "<br />" . __("Tracking ID:", 'ga-dash') . "\t" . $profile_info[2] . "<br />" . __("Default URL:", 'ga-dash') . "\t" . $profile_info[3] . "<br />" . __("Time Zone:", 'ga-dash') . "\t" . $profile_info[5] . '</pre>'; ?> </td> </tr> <?php } ?> <tr> <td class="title"><label for="ga_dash_style"><?php _e("Theme Color: ", 'ga-dash'); ?> </label></td> <td><input type="text" id="ga_dash_style" class="ga_dash_style" name="options[ga_dash_style]" value="<?php echo $options['ga_dash_style']; ?> " size="10"></td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td colspan="2"><?php echo __('A new frontend widget is available! To enable it, go to', 'ga-dash') . ' <a href="widgets.php">' . __('Appearance -> Widgets') . '</a> ' . __('and look for Google Analytics Dashboard.', 'ga-dash') . ' ' . ''; ?> </td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td class="debugging"><?php echo "<h2>" . __("Debugging Data", 'ga-dash') . "</h2></td>" . '<td><a href="#" id="show_hide" class="show_hide">Show Log</a>'; ?> </td> </tr> <tr> <td colspan="2"> <div class="log_data"> <?php echo '<pre class="log_data">************************************* Start Log *************************************<br/><br/>'; $anonim = $GADASH_Config->options; if ($anonim['ga_dash_token']) { $anonim['ga_dash_token'] = 'HIDDEN'; } if ($anonim['ga_dash_refresh_token']) { $anonim['ga_dash_refresh_token'] = 'HIDDEN'; } if ($anonim['ga_dash_clientid']) { $anonim['ga_dash_clientid'] = 'HIDDEN'; } if ($anonim['ga_dash_clientsecret']) { $anonim['ga_dash_clientsecret'] = 'HIDDEN'; } if ($anonim['ga_dash_apikey']) { $anonim['ga_dash_apikey'] = 'HIDDEN'; } print_r($anonim); echo '<br/>Last Error: '; print_r(get_option('gadash_lasterror', 'N/A')); echo '<br/><br/>************************************* End Log *************************************</pre>'; ?> </div> </td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td colspan="2" class="submit"><input type="submit" name="Submit" class="button button-primary" value="<?php _e('Update Options', 'ga-dash'); ?> " /></td> </tr> <?php } else { ?> <tr> <td colspan="2"><hr></td> </tr> <tr> <td colspan="2"><input type="submit" name="Authorize" class="button button-secondary" id="authorize" value="<?php _e("Authorize Plugin", 'ga-dash'); ?> " <?php echo !function_exists('curl_version') ? 'disabled' : ''; ?> /> <input type="submit" name="Clear" class="button button-secondary" value="<?php _e("Clear Cache", 'ga-dash'); ?> " /> </td> </tr> <tr> <td colspan="2"><hr></td> </tr> <tr> <td class="debugging"><?php echo "<h2>" . __("Debugging Data", 'ga-dash') . "</h2></td>" . '<td><a href="#" id="show_hide" class="show_hide">Show Log</a>'; ?> </td> </tr> <tr> <td colspan="2"> <div class="log_data"> <?php echo '<pre class="log_data">************************************* Start Log *************************************<br/><br/>'; $anonim = $GADASH_Config->options; if ($anonim['ga_dash_token']) { $anonim['ga_dash_token'] = 'HIDDEN'; } if ($anonim['ga_dash_refresh_token']) { $anonim['ga_dash_refresh_token'] = 'HIDDEN'; } if ($anonim['ga_dash_clientid']) { $anonim['ga_dash_clientid'] = 'HIDDEN'; } if ($anonim['ga_dash_clientsecret']) { $anonim['ga_dash_clientsecret'] = 'HIDDEN'; } if ($anonim['ga_dash_apikey']) { $anonim['ga_dash_apikey'] = 'HIDDEN'; } print_r($anonim); echo '<br/>Last Error: '; print_r(get_option('gadash_lasterror', 'N/A')); echo '<br/><br/>************************************* End Log *************************************</pre>'; ?> </div> </td> </tr> <tr> <td colspan="2"><hr></td> </tr> </table> </form> <?php self::output_sidebar(); return; } ?> </table> </form> <?php } self::output_sidebar(); }
private function maintain_compatibility() { if (GADWP_CURRENT_VERSION != get_option('gadwp_version')) { include_once $this->plugin_path . '/tools/tools.php'; $tools = new GADASH_Tools(); $tools->ga_dash_clear_cache(); update_option('gadwp_version', GADWP_CURRENT_VERSION); } if (!isset($this->options['ga_enhanced_links'])) { $this->options['ga_enhanced_links'] = 0; } if (!isset($this->options['ga_enhanced_network'])) { $this->options['ga_dash_network'] = 0; } if (!isset($this->options['ga_dash_remarketing'])) { $this->options['ga_dash_remarketing'] = 0; } if (!isset($this->options['ga_dash_adsense'])) { $this->options['ga_dash_adsense'] = 0; } if (!isset($this->options['ga_speed_samplerate'])) { $this->options['ga_speed_samplerate'] = 1; } if (!isset($this->options['ga_event_bouncerate'])) { $this->options['ga_event_bouncerate'] = 0; } if (!is_array($this->options['ga_dash_access_front']) or empty($this->options['ga_dash_access_front'])) { $this->options['ga_dash_access_front'] = array(); $this->options['ga_dash_access_front'][] = 'administrator'; } if (!is_array($this->options['ga_dash_access_back']) or empty($this->options['ga_dash_access_back'])) { $this->options['ga_dash_access_back'] = array(); $this->options['ga_dash_access_back'][] = 'administrator'; } if (!is_array($this->options['ga_track_exclude'])) { $this->options['ga_track_exclude'] = array(); } if (!isset($this->options['ga_crossdomain_tracking'])) { $this->options['ga_crossdomain_tracking'] = 0; } if (!isset($this->options['ga_crossdomain_list'])) { $this->options['ga_crossdomain_list'] = ''; } if (!isset($this->options['ga_author_dimindex'])) { $this->options['ga_author_dimindex'] = 0; } if (!isset($this->options['ga_category_dimindex'])) { $this->options['ga_category_dimindex'] = 0; } if (!isset($this->options['ga_user_dimindex'])) { $this->options['ga_user_dimindex'] = 0; } if (!isset($this->options['ga_pubyear_dimindex'])) { $this->options['ga_pubyear_dimindex'] = 0; } if (!isset($this->options['ga_event_affiliates'])) { $this->options['ga_event_affiliates'] = '/out/'; } if (!isset($this->options['ga_aff_tracking'])) { $this->options['ga_aff_tracking'] = 0; } if (isset($this->options['ga_tracking_code'])) { unset($this->options['ga_tracking_code']); } }