Exemple #1
0
 private function maintain_compatibility()
 {
     if (GADWP_CURRENT_VERSION != get_option('gadwp_version')) {
         $tools = new GADASH_Tools();
         $tools->clear_cache();
         delete_transient('ga_dash_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');
         }
     }
     $flag = false;
     if (!isset($this->options['ga_enhanced_links'])) {
         $this->options['ga_enhanced_links'] = 0;
         $flag = true;
     }
     if (!isset($this->options['ga_enhanced_network'])) {
         $this->options['ga_dash_network'] = 0;
         $flag = true;
     }
     if (!isset($this->options['ga_enhanced_excludesa'])) {
         $this->options['ga_dash_excludesa'] = 0;
         $flag = true;
     }
     if (!isset($this->options['ga_dash_remarketing'])) {
         $this->options['ga_dash_remarketing'] = 0;
         $flag = true;
     }
     if (!isset($this->options['ga_dash_adsense'])) {
         $this->options['ga_dash_adsense'] = 0;
         $flag = true;
     }
     if (!isset($this->options['ga_speed_samplerate'])) {
         $this->options['ga_speed_samplerate'] = 1;
         $flag = true;
     }
     if (!isset($this->options['automatic_updates_minorversion'])) {
         $this->options['automatic_updates_minorversion'] = 1;
         $flag = true;
     }
     if (!isset($this->options['ga_event_bouncerate'])) {
         $this->options['ga_event_bouncerate'] = 0;
         $flag = true;
     }
     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';
         $flag = true;
     }
     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';
         $flag = true;
     }
     if (!is_array($this->options['ga_track_exclude'])) {
         $this->options['ga_track_exclude'] = array();
         $flag = true;
     }
     if (!isset($this->options['ga_crossdomain_tracking'])) {
         $this->options['ga_crossdomain_tracking'] = 0;
         $flag = true;
     }
     if (!isset($this->options['ga_crossdomain_list'])) {
         $this->options['ga_crossdomain_list'] = '';
         $flag = true;
     }
     if (!isset($this->options['ga_author_dimindex'])) {
         $this->options['ga_author_dimindex'] = 0;
         $flag = true;
     }
     if (!isset($this->options['ga_category_dimindex'])) {
         $this->options['ga_category_dimindex'] = 0;
         $flag = true;
     }
     if (!isset($this->options['ga_user_dimindex'])) {
         $this->options['ga_user_dimindex'] = 0;
         $flag = true;
     }
     if (!isset($this->options['ga_pubyear_dimindex'])) {
         $this->options['ga_pubyear_dimindex'] = 0;
         $flag = true;
     }
     if (!isset($this->options['ga_event_affiliates'])) {
         $this->options['ga_event_affiliates'] = '/out/';
         $flag = true;
     }
     if (!isset($this->options['ga_aff_tracking'])) {
         $this->options['ga_aff_tracking'] = 0;
         $flag = true;
     }
     if (!isset($this->options['ga_hash_tracking'])) {
         $this->options['ga_hash_tracking'] = 0;
         $flag = true;
     }
     if (!isset($this->options['item_reports'])) {
         $this->options['item_reports'] = 1;
         $flag = true;
     }
     if (!isset($this->options['dashboard_widget'])) {
         $this->options['dashboard_widget'] = 1;
         $flag = true;
     }
     if (isset($this->options['ga_tracking_code'])) {
         unset($this->options['ga_tracking_code']);
         $flag = true;
     }
     if (isset($this->options['ga_dash_jailadmins'])) {
         if (isset($this->options['ga_dash_jailadmins'])) {
             // invert disable with enable and change option name
             $this->options['switch_profile'] = 0;
             unset($this->options['ga_dash_jailadmins']);
             $flag = true;
         } else {
             $this->options['switch_profile'] = 1;
             unset($this->options['ga_dash_jailadmins']);
             $flag = true;
         }
     }
     if ($flag) {
         $this->set_plugin_options(false);
     }
 }
<?php 
        }
        self::output_sidebar();
    }
    // Network Settings
    public static function general_settings_network()
    {
        global $GADASH_Config;
        global $wp_version;
        $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/error-codes-in-google-analytics-dashboard-for-wordpress/?utm_source=gadwp_config&utm_medium=link&utm_content=general_screen&utm_campaign=gadwp">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->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->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->reset_token(true);
                $tools->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) . "'>" . __('authorize the plugin', 'ga-dash') . "</a>.</p></div>";
        }
        if (isset($_POST['Authorize'])) {
            $tools->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]) . '">' . esc_html($tools->strip_protocol($items[3])) . ' &#8658; ' . esc_attr($items[0]) . '</option>';
                                }
                            }
                        } else {
                            echo '<option value="">' . __("Property not found", 'ga-dash') . '</option>';
                        }
                        ?>
								</select><br /></td>
																	</tr>
							<?php 
                    }
                    ?>
                    												<tr>
																		<td colspan="2"><?php 
                    echo "<h2>" . __("Automatic Updates", 'ga-dash') . "</h2>";
                    ?>
</td>
																	</tr>
																	<tr>
																		<td colspan="2" class="title">
																			<div class="onoffswitch">
																				<input type="checkbox"
																					name="options[automatic_updates_minorversion]"
																					value="1" class="onoffswitch-checkbox"
																					id="automatic_updates_minorversion"
																					<?php 
                    checked($options['automatic_updates_minorversion'], 1);
                    ?>
>
																				<label class="onoffswitch-label"
																					for="automatic_updates_minorversion">
																					<div class="onoffswitch-inner"></div>
																					<div class="onoffswitch-switch"></div>
																				</label>
																			</div>
																			<div class="switch-desc"><?php 
                    echo " " . __("automatic updates for minor versions (security and maintenance releases only)", 'ga-dash');
                    ?>
</div>
																		</td>
																	</tr>
																	<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;