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();
    }
Ejemplo n.º 2
0
require_once 'functions.php';
if (!current_user_can('manage_options')) {
    return;
}
if (isset($_REQUEST['Clear'])) {
    ga_dash_clear_cache();
    ?>
<div class="updated"><p><strong><?php 
    _e('Cleared Cache.', 'ga-dash');
    ?>
</strong></p></div>  
	<?php 
}
if (isset($_REQUEST['Reset'])) {
    ga_dash_reset_token();
    ?>
<div class="updated"><p><strong><?php 
    _e('Token Reseted.', 'ga-dash');
    ?>
</strong></p></div>  
	<?php 
} else {
    if (ga_dash_safe_get('ga_dash_hidden') == 'Y') {
        //Form data sent
        $apikey = ga_dash_safe_get('ga_dash_apikey');
        if ($apikey) {
            update_option('ga_dash_apikey', sanitize_text_field($apikey));
        }
        $clientid = ga_dash_safe_get('ga_dash_clientid');
        if ($clientid) {