/**
  * Get the request token from Google Analytics
  *
  * @param WP_Gdata $gdata
  *
  * @return array
  */
 protected function get_request_token($gdata)
 {
     $oauth_callback = add_query_arg(array('ga_oauth_callback' => 1), menu_page_url('yst_ga_settings', false));
     $request_token = $gdata->get_request_token($oauth_callback);
     return $request_token;
 }
        function config_page()
        {
            $options = get_option($this->optionname);
            if (isset($options['msg'])) {
                echo $options['msg'];
            }
            $options['msg'] = '';
            update_option($this->optionname, $options);
            if (!isset($options['uastring'])) {
                $options = $this->set_defaults();
            }
            $modules = array();
            if (!isset($options['manual_uastring'])) {
                $options['manual_uastring'] = '';
            }
            ?>
		<div class="wrap">
		<a href="http://yoast.com/">
			<div id="yoast-icon"
				 style="background: url(<?php 
            echo $this->plugin_url;
            ?>
images/ga-icon-32x32.png) no-repeat;"
				 class="icon32"><br/></div>
		</a>

		<h2><?php 
            _e("Google Analytics for WordPress Configuration");
            ?>
</h2>

		<div class="postbox-container" style="width:65%;">
		<div class="metabox-holder">
		<div class="meta-box-sortables">
		<form action="<?php 
            echo $this->plugin_options_url();
            ?>
" method="post" id="analytics-conf">
		<input type="hidden" name="plugin" value="google-analytics-for-wordpress"/>
			<?php 
            wp_nonce_field('analyticspp-config');
            if (empty($options['uastring']) && empty($options['ga_token'])) {
                $query = $this->plugin_options_url() . '&reauth=true';
                $line = 'Please authenticate with Google Analytics to retrieve your tracking code:<br/><br/> <a class="button-primary" href="' . $query . '">Click here to authenticate with Google</a><br/><br/><strong>Note</strong>: if you have multiple Google accounts, you\'ll want to switch to the right account first, since Google doesn\'t let you switch accounts on the authentication screen.';
            } else {
                if (isset($options['ga_token']) && !empty($options['ga_token'])) {
                    $token = $options['ga_token'];
                    require_once plugin_dir_path(__FILE__) . 'xmlparser.php';
                    if (file_exists(ABSPATH . 'wp-includes/class-http.php')) {
                        require_once ABSPATH . 'wp-includes/class-http.php';
                    }
                    if (!isset($options['ga_api_responses'][$token])) {
                        $options['ga_api_responses'] = array();
                        if ($oauth = $options['gawp_oauth']) {
                            if (isset($oauth['params']['oauth_token'], $oauth['params']['oauth_token_secret'])) {
                                $options['gawp_oauth']['access_token'] = array('oauth_token' => base64_decode($oauth['params']['oauth_token']), 'oauth_token_secret' => base64_decode($oauth['params']['oauth_token_secret']));
                                unset($options['gawp_oauth']['params']);
                                update_option($this->optionname, $options);
                            }
                        }
                        $args = array('scope' => 'https://www.google.com/analytics/feeds/', 'xoauth_displayname' => 'Google Analytics for WordPress by Yoast');
                        $access_token = $options['gawp_oauth']['access_token'];
                        $gdata = new WP_Gdata($args, $access_token['oauth_token'], $access_token['oauth_token_secret']);
                        $response = $gdata->get('https://www.google.com/analytics/feeds/accounts/default');
                        $http_code = wp_remote_retrieve_response_code($response);
                        $response = wp_remote_retrieve_body($response);
                        if ($http_code == 200) {
                            $options['ga_api_responses'][$token] = array('response' => array('code' => $http_code), 'body' => $response);
                            $options['ga_token'] = $token;
                            update_option('Yoast_Google_Analytics', $options);
                        }
                    }
                    if (isset($options['ga_api_responses'][$token]) && is_array($options['ga_api_responses'][$token]) && $options['ga_api_responses'][$token]['response']['code'] == 200) {
                        $arr = yoast_xml2array($options['ga_api_responses'][$token]['body']);
                        $ga_accounts = array();
                        if (isset($arr['feed']['entry'][0])) {
                            foreach ($arr['feed']['entry'] as $site) {
                                $ua = $site['dxp:property']['3_attr']['value'];
                                $account = $site['dxp:property']['1_attr']['value'];
                                if (!isset($ga_accounts[$account]) || !is_array($ga_accounts[$account])) {
                                    $ga_accounts[$account] = array();
                                }
                                $ga_accounts[$account][$site['title']] = $ua;
                            }
                        } else {
                            $ua = $arr['feed']['entry']['dxp:property']['3_attr']['value'];
                            $account = $arr['feed']['entry']['dxp:property']['1_attr']['value'];
                            $title = $arr['feed']['entry']['title'];
                            if (!isset($ga_accounts[$account]) || !is_array($ga_accounts[$account])) {
                                $ga_accounts[$account] = array();
                            }
                            $ga_accounts[$account][$title] = $ua;
                        }
                        $select1 = '<select style="width:150px;" name="ga_account" id="ga_account">';
                        $select1 .= "\t<option></option>\n";
                        $select2 = '<select style="width:150px;" name="uastring" id="uastring_sel">';
                        $i = 1;
                        $currentua = '';
                        if (!empty($options['uastring'])) {
                            $currentua = $options['uastring'];
                        }
                        foreach ($ga_accounts as $account => $val) {
                            $accountsel = false;
                            foreach ($val as $title => $ua) {
                                $sel = selected($ua, $currentua, false);
                                if (!empty($sel)) {
                                    $accountsel = true;
                                }
                                $select2 .= "\t" . '<option class="sub_' . $i . '" ' . $sel . ' value="' . $ua . '">' . $title . ' - ' . $ua . '</option>' . "\n";
                            }
                            $select1 .= "\t" . '<option ' . selected($accountsel, true, false) . ' value="' . $i . '">' . $account . '</option>' . "\n";
                            $i++;
                        }
                        $select1 .= '</select>';
                        $select2 .= '</select>';
                        $line = '<input type="hidden" name="ga_token" value="' . $token . '"/>';
                        $line .= 'Please select the correct Analytics profile to track:<br/>';
                        $line .= '<table class="form_table">';
                        $line .= '<tr><th width="15%">Account:</th><td width="85%">' . $select1 . '</td></tr>';
                        $line .= '<tr><th>Profile:</th><td>' . $select2 . '</td></tr>';
                        $line .= '</table>';
                        $try = 1;
                        if (isset($_GET['try'])) {
                            $try = $_GET['try'] + 1;
                        }
                        if ($i == 1 && $try < 4 && isset($_GET['token'])) {
                            $line .= '<script type="text/javascript">
													window.location="' . $this->plugin_options_url() . '&switchua=1&token=' . $token . '&try=' . $try . '";
												</script>';
                        }
                        $line .= 'Please note that if you have several profiles of the same website, it doesn\'t matter which profile you select, and in fact another profile might show as selected later. You can check whether they\'re profiles for the same site by checking if they have the same UA code. If that\'s true, tracking will be correct.<br/>';
                        $line .= '<br/>Refresh this listing or switch to another account: ';
                    } else {
                        $line = 'Unfortunately, an error occurred while connecting to Google, please try again:';
                    }
                    $query = $this->plugin_options_url() . '&reauth=true';
                    $line .= '<a class="button" href="' . $query . '">Re-authenticate with Google</a>';
                } else {
                    $line = '<input id="uastring" name="uastring" type="text" size="20" maxlength="40" value="' . $options['uastring'] . '"/><br/><a href="' . $this->plugin_options_url() . '&amp;switchua=1">Select another Analytics Profile &raquo;</a>';
                }
            }
            $line = '<div id="uastring_automatic">' . $line . '</div><div style="display:none;" id="uastring_manual">Manually enter your UA code: <input id="uastring" name="uastring_man" type="text" size="20" maxlength="40" value="' . $options['uastring'] . '"/></div>';
            $rows = array();
            $content = '';
            $rows[] = array('id' => 'uastring', 'label' => 'Analytics Profile', 'desc' => '<input type="checkbox" name="manual_uastring" ' . checked($options['manual_uastring'], true, false) . ' id="switchtomanual"/> <label for="switchtomanual">Manually enter your UA code</label>', 'content' => $line);
            $temp_content = $this->select('position', array('header' => 'In the header (default)', 'manual' => 'Insert manually'));
            if ($options['theme_updated'] && $options['position'] == 'manual') {
                $temp_content .= '<input type="hidden" name="theme_updated" value="off"/>';
                echo '<div id="message" class="updated" style="background-color:lightgreen;border-color:green;"><p><strong>Notice:</strong> You switched your theme, please make sure your Google Analytics tracking is still ok. Save your settings to make sure Google Analytics gets loaded properly.</p></div>';
                remove_action('admin_footer', array(&$this, 'theme_switch_warning'));
            }
            $desc = '<div id="position_header">The header is by far the best spot to place the tracking code. If you\'d rather place the code manually, switch to manual placement. For more info <a href="http://yoast.com/wordpress/google-analytics/manual-placement/">read this page</a>.</div>';
            $desc .= '<div id="position_manual"><a href="http://yoast.com/wordpress/google-analytics/manual-placement/">Follow the instructions here</a> to choose the location for your tracking code manually.</div>';
            $rows[] = array('id' => 'position', 'label' => 'Where should the tracking code be placed', 'desc' => $desc, 'content' => $temp_content);
            $rows[] = array('id' => 'trackoutbound', 'label' => 'Track outbound clicks &amp; downloads', 'desc' => 'Clicks &amp; downloads will be tracked as events, you can find these under Content &raquo; Event Tracking in your Google Analytics reports.', 'content' => $this->checkbox('trackoutbound'));
            $rows[] = array('id' => 'advancedsettings', 'label' => 'Show advanced settings', 'desc' => 'Only adviced for advanced users who know their way around Google Analytics', 'content' => $this->checkbox('advancedsettings'));
            $rows[] = array('id' => 'yoast_tracking', 'label' => 'Allow tracking of anonymous data', 'desc' => 'By allowing us to track anonymous data we can better help you, because we know with which WordPress configurations, themes and plugins we should test. No personal data will be submitted.', 'content' => $this->checkbox('yoast_tracking'));
            $this->postbox('gasettings', 'Google Analytics Settings', $this->form_table($rows) . $this->save_button());
            $rows = array();
            $pre_content = '<p>Google Analytics allows you to save up to 5 custom variables on each page, and this plugin helps you make the most use of these! Check which custom variables you\'d like the plugin to save for you below. Please note that these will only be saved when they are actually available.</p><p>If you want to start using these custom variables, go to Visitors &raquo; Custom Variables in your Analytics reports.</p>';
            $rows[] = array('id' => 'cv_loggedin', 'label' => 'Logged in Users', 'desc' => 'Allows you to easily remove logged in users from your reports, or to segment by different user roles. The users primary role will be logged.', 'content' => $this->checkbox('cv_loggedin'));
            $rows[] = array('id' => 'cv_post_type', 'label' => 'Post type', 'desc' => 'Allows you to see pageviews per post type, especially useful if you use multiple custom post types.', 'content' => $this->checkbox('cv_post_type'));
            $rows[] = array('id' => 'cv_authorname', 'label' => 'Author Name', 'desc' => 'Allows you to see pageviews per author.', 'content' => $this->checkbox('cv_authorname'));
            $rows[] = array('id' => 'cv_tags', 'label' => 'Tags', 'desc' => 'Allows you to see pageviews per tags using advanced segments.', 'content' => $this->checkbox('cv_tags'));
            $rows[] = array('id' => 'cv_year', 'label' => 'Publication year', 'desc' => 'Allows you to see pageviews per year of publication, showing you if your old posts still get traffic.', 'content' => $this->checkbox('cv_year'));
            $rows[] = array('id' => 'cv_category', 'label' => 'Single Category', 'desc' => 'Allows you to see pageviews per category, works best when each post is in only one category.', 'content' => $this->checkbox('cv_category'));
            $rows[] = array('id' => 'cv_all_categories', 'label' => 'All Categories', 'desc' => 'Allows you to see pageviews per category using advanced segments, should be used when you use multiple categories per post.', 'content' => $this->checkbox('cv_all_categories'));
            $modules['Custom Variables'] = 'customvarsettings';
            $this->postbox('customvarsettings', 'Custom Variables Settings', $pre_content . $this->form_table($rows) . $this->save_button());
            $rows = array();
            $rows[] = array('id' => 'ignore_userlevel', 'label' => 'Ignore users', 'desc' => 'Users of the role you select and higher will be ignored, so if you select Editor, all Editors and Administrators will be ignored.', 'content' => $this->select('ignore_userlevel', array('11' => 'Ignore no-one', '8' => 'Administrator', '5' => 'Editor', '2' => 'Author', '1' => 'Contributor', '0' => 'Subscriber (ignores all logged in users)')));
            $rows[] = array('id' => 'outboundpageview', 'label' => 'Track outbound clicks as pageviews', 'desc' => 'You do not need to enable this to enable outbound click tracking, this changes the default behavior of tracking clicks as events to tracking them as pageviews. This is therefore not recommended, as this would skew your statistics, but <em>is</em> sometimes necessary when you need to set outbound clicks as goals.', 'content' => $this->checkbox('outboundpageview'));
            $rows[] = array('id' => 'downloadspageview', 'label' => 'Track downloads as pageviews', 'desc' => 'Not recommended, as this would skew your statistics, but it does make it possible to track downloads as goals.', 'content' => $this->checkbox('downloadspageview'));
            $rows[] = array('id' => 'dlextensions', 'label' => 'Extensions of files to track as downloads', 'content' => $this->textinput('dlextensions'));
            if ($options['outboundpageview']) {
                $rows[] = array('id' => 'trackprefix', 'label' => 'Prefix to use in Analytics before the tracked pageviews', 'desc' => 'This prefix is used before all pageviews, they are then segmented automatically after that. If nothing is entered here, <code>/yoast-ga/</code> is used.', 'content' => $this->textinput('trackprefix'));
            }
            $rows[] = array('id' => 'domainorurl', 'label' => 'Track full URL of outbound clicks or just the domain', 'content' => $this->select('domainorurl', array('domain' => 'Just the domain', 'url' => 'Track the complete URL')));
            $rows[] = array('id' => 'domain', 'label' => 'Subdomain Tracking', 'desc' => 'This allows you to set the domain that\'s set by <a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setDomainName"><code>setDomainName</code></a> for tracking subdomains, if empty this will not be set.', 'content' => $this->textinput('domain'));
            $rows[] = array('id' => 'trackcrossdomain', 'label' => 'Enable Cross Domain Tracking', 'desc' => 'This allows you to enable <a href="http://code.google.com/apis/analytics/docs/tracking/gaTrackingSite.html">Cross-Domain Tracking</a> for this site.  When endabled <code>_setAllowLinker:</code> will be enabled if it is not already.', 'content' => $this->checkbox('trackcrossdomain'));
            $rows[] = array('id' => 'primarycrossdomain', 'label' => 'Cross-Domain Tracking, Primary Domain', 'desc' => 'Set the primary domain used in <a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setDomainName"><code>setDomainName</code></a> for cross domain tracking (eg. <code>example-petstore.com</code> ), if empty this will default to your configured Home URL.', 'content' => $this->textinput('primarycrossdomain'));
            $rows[] = array('id' => 'othercrossdomains', 'label' => 'Cross-Domain Tracking, Other Domains', 'desc' => 'All links to these domains will have the <a href="http://code.google.com/apis/analytics/docs/tracking/gaTrackingSite.html#multipleDomains"><code>_link</code></a> code automatically attached.  Separate domains/sub-domains with commas (eg. <code>dogs.example-petstore.com, cats.example-petstore.com</code>)', 'content' => $this->textinput('othercrossdomains'));
            $rows[] = array('id' => 'customcode', 'label' => 'Custom Code', 'desc' => 'Not for the average user: this allows you to add a line of code, to be added before the <code>trackPageview</code> call.', 'content' => $this->textinput('customcode'));
            $rows[] = array('id' => 'trackadsense', 'label' => 'Track AdSense', 'desc' => 'This requires integration of your Analytics and AdSense account, for help, <a href="http://google.com/support/analytics/bin/answer.py?answer=92625">look here</a>.', 'content' => $this->checkbox('trackadsense'));
            $rows[] = array('id' => 'gajslocalhosting', 'label' => 'Host ga.js locally', 'content' => $this->checkbox('gajslocalhosting') . '<div id="localhostingbox">
											You have to provide a URL to your ga.js file:
											<input type="text" name="gajsurl" size="30" value="' . $options['gajsurl'] . '"/>
										</div>', 'desc' => 'For some reasons you might want to use a locally hosted ga.js file, or another ga.js file, check the box and then please enter the full URL including http here.');
            $rows[] = array('id' => 'extrase', 'label' => 'Track extra Search Engines', 'content' => $this->checkbox('extrase') . '<div id="extrasebox">
											You can provide a custom URL to the extra search engines file if you want:
											<input type="text" name="extraseurl" size="30" value="' . $options['extraseurl'] . '"/>
										</div>');
            $rows[] = array('id' => 'rsslinktagging', 'label' => 'Tag links in RSS feed with campaign variables', 'desc' => 'Do not use this feature if you use FeedBurner, as FeedBurner can do this automatically, and better than this plugin can. Check <a href="http://www.google.com/support/feedburner/bin/answer.py?hl=en&amp;answer=165769">this help page</a> for info on how to enable this feature in FeedBurner.', 'content' => $this->checkbox('rsslinktagging'));
            $rows[] = array('id' => 'trackregistration', 'label' => 'Add tracking to the login and registration forms', 'content' => $this->checkbox('trackregistration'));
            $rows[] = array('id' => 'trackcommentform', 'label' => 'Add tracking to the comment forms', 'content' => $this->checkbox('trackcommentform'));
            $rows[] = array('id' => 'allowanchor', 'label' => 'Use # instead of ? for Campaign tracking', 'desc' => 'This adds a <code><a href="http://code.google.com/apis/analytics/docs/gaJSApiCampaignTracking.html#_gat.GA_Tracker_._setAllowAnchor">_setAllowAnchor</a></code> call to your tracking code, and makes RSS link tagging use a # as well.', 'content' => $this->checkbox('allowanchor'));
            $rows[] = array('id' => 'allowlinker', 'label' => 'Add <code>_setAllowLinker</code>', 'desc' => 'This adds a <code><a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setAllowLinker">_setAllowLinker</a></code> call to your tracking code,  allowing you to use <code>_link</code> and related functions.', 'content' => $this->checkbox('allowlinker'));
            $rows[] = array('id' => 'allowhash', 'label' => 'Set <code>_setAllowHash</code> to false', 'desc' => 'This sets <code><a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setAllowHash">_setAllowHash</a></code> to false, allowing you to track subdomains etc.', 'content' => $this->checkbox('allowhash'));
            $rows[] = array('id' => 'anonymizeip', 'label' => 'Anonymize IP\'s', 'desc' => 'This adds <code><a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApi_gat.html#_gat._anonymizeIp">_anonymizeIp</a></code>, telling Google Analytics to anonymize the information sent by the tracker objects by removing the last octet of the IP address prior to its storage.', 'content' => $this->checkbox('anonymizeip'));
            $modules['Advanced Settings'] = 'advancedgasettings';
            $this->postbox('advancedgasettings', 'Advanced Settings', $this->form_table($rows) . $this->save_button());
            $rows = array();
            $rows[] = array('id' => 'internallink', 'label' => 'Internal links to track as outbound', 'desc' => 'If you want to track all internal links that begin with <code>/out/</code>, enter <code>/out/</code> in the box above. If you have multiple prefixes you can separate them with comma\'s: <code>/out/,/recommends/</code>', 'content' => $this->textinput('internallink'));
            $rows[] = array('id' => 'internallinklabel', 'label' => 'Label to use', 'desc' => 'The label to use for these links, this will be added to where the click came from, so if the label is "aff", the label for a click from the content of an article becomes "outbound-article-aff".', 'content' => $this->textinput('internallinklabel'));
            $modules['Internal Link Tracking'] = 'internallinktracking';
            $this->postbox('internallinktracking', 'Internal Links to Track as Outbound', $this->form_table($rows) . $this->save_button());
            /*									if (class_exists('RGForms') && GFCommon::$version >= '1.3.11') {
            									   $pre_content = 'This plugin can automatically tag your Gravity Forms to track form submissions as either events or pageviews';
            									   $rows = array();
            									   $rows[] = array(
            										   'id' => 'taggfsubmit',
            										   'label' => 'Tag Gravity Forms',
            										   'content' => $this->checkbox('taggfsubmit'),
            									   );
            									   $rows[] = array(
            										   'id' => 'gfsubmiteventpv',
            										   'label' => 'Tag Gravity Forms as',
            										   'content' => '<select name="gfsubmiteventpv">
            										   <option value="events" '.selected($options['gfsubmiteventpv'],'events',false).'>Events</option>
            										   <option value="pageviews" '.selected($options['gfsubmiteventpv'],'pageviews',false).'>Pageviews</option>
            										   </select>',
            									   );
            									   $this->postbox('gravityforms','Gravity Forms Settings',$pre_content.$this->form_table($rows).$this->save_button());
            									   $modules['Gravity Forms'] = 'gravityforms';
            								   }
            								   */
            if (defined('WPSC_VERSION')) {
                $pre_content = 'The WordPress e-Commerce plugin has been detected. This plugin can automatically add transaction tracking for you. To do that, <a href="http://yoast.com/wordpress/google-analytics/enable-ecommerce/">enable e-commerce for your reports in Google Analytics</a> and then check the box below.';
                $rows = array();
                $rows[] = array('id' => 'wpec_tracking', 'label' => 'Enable transaction tracking', 'content' => $this->checkbox('wpec_tracking'));
                $this->postbox('wpecommerce', 'WordPress e-Commerce Settings', $pre_content . $this->form_table($rows) . $this->save_button());
                $modules['WordPress e-Commerce'] = 'wpecommerce';
            }
            global $Shopp;
            if (isset($Shopp)) {
                $pre_content = 'The Shopp e-Commerce plugin has been detected. This plugin can automatically add transaction tracking for you. To do that, <a href="http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&amp;answer=55528">enable e-commerce for your reports in Google Analytics</a> and then check the box below.';
                $rows = array();
                $rows[] = array('id' => 'shopp_tracking', 'label' => 'Enable transaction tracking', 'content' => $this->checkbox('shopp_tracking'));
                $this->postbox('shoppecommerce', 'Shopp e-Commerce Settings', $pre_content . $this->form_table($rows) . $this->save_button());
                $modules['Shopp'] = 'shoppecommerce';
            }
            $pre_content = '<p>If you want to confirm that tracking on your blog is working as it should, enable this option and check the console in <a href="http://getfirebug.com/">Firebug</a> (for Firefox), <a href="http://getfirebug.com/firebuglite">Firebug Lite</a> (for other browsers) or Chrome &amp; Safari\'s Web Inspector. Be absolutely sure to disable debugging afterwards, as it is slower than normal tracking.</p><p><strong>Note</strong>: the debugging and firebug scripts are only loaded for admins.</p>';
            $rows = array();
            $rows[] = array('id' => 'debug', 'label' => 'Enable debug mode', 'content' => $this->checkbox('debug'));
            $rows[] = array('id' => 'firebuglite', 'label' => 'Enable Firebug Lite', 'content' => $this->checkbox('firebuglite'));
            $this->postbox('debugmode', 'Debug Mode', $pre_content . $this->form_table($rows) . $this->save_button());
            $modules['Debug Mode'] = 'debugmode';
            ?>
		</form>
		<form action="<?php 
            echo $this->plugin_options_url();
            ?>
" method="post"
			  onsubmit="javascript:return(confirm('Do you really want to reset all settings?'));">
			<input type="hidden" name="reset" value="true"/>
			<input type="hidden" name="plugin" value="google-analytics-for-wordpress"/>

			<div class="submit"><input type="submit" value="Reset All Settings &raquo;"/></div>
		</form>
		</div>
		</div>
		</div>
		<div class="postbox-container side" style="width:20%;">
			<div class="metabox-holder">
				<div class="meta-box-sortables">
					<?php 
            if (count($modules) > 0) {
                $this->postbox('toc', 'List of Available Modules', $this->toc($modules));
            }
            $this->postbox('donate', '<strong class="red">' . __('Help Spread the Word!') . '</strong>', '<p><strong>' . __('Want to help make this plugin even better? All donations are used to improve this plugin, so donate $20, $50 or $100 now!') . '</strong></p><form style="width:160px;margin:0 auto;" action="https://www.paypal.com/cgi-bin/webscr" method="post">
						<input type="hidden" name="cmd" value="_s-xclick">
						<input type="hidden" name="hosted_button_id" value="FW9FK4EBZ9FVJ">
						<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit">
						<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
						</form>' . '<p>' . __('Or you could:') . '</p>' . '<ul>' . '<li><a href="http://wordpress.org/extend/plugins/google-analytics-for-wordpress/">' . __('Rate the plugin 5★ on WordPress.org') . '</a></li>' . '<li><a href="http://wordpress.org/tags/google-analytics-for-wordpress">' . __('Help out other users in the forums') . '</a></li>' . '<li>' . sprintf(__('Blog about it & link to the %1$splugin page%2$s'), '<a href="http://yoast.com/wordpress/google-analytics/#utm_source=wpadmin&utm_medium=sidebanner&utm_term=link&utm_campaign=wpgaplugin">', '</a>') . '</li>');
            $this->postbox('sitereview', '<strong>' . __('Want to Improve your Site?') . '</strong>', '<p>' . sprintf(__('If you want to improve your site, but don\'t know where to start, you should order a %1$swebsite review%2$s from Yoast!'), '<a href="http://yoast.com/hire-me/website-review/#utm_source=wpadmin&utm_medium=sidebanner&utm_term=link&utm_campaign=wpgaplugin">', '</a>') . '</p>' . '<p>' . __('The results of this review contain a full report of improvements for your site, encompassing my findings for improvements in different key areas such as SEO to Usability to Site Speed & more.') . '</p>' . '<p><a class="button-secondary" href="http://yoast.com/hire-me/website-review/#utm_source=wpadmin&utm_medium=sidebanner&utm_term=button&utm_campaign=wpgaplugin">' . __('Click here to read more &raquo;') . '</a></p>');
            $this->plugin_support();
            $this->news();
            ?>
				</div>
				<br/><br/><br/>
			</div>
		</div>
		</div>
		<?php 
        }
 /**
  * Get the Google Analytics profiles which are in this google account
  *
  * @return array
  * @todo OAuth connection to Google.com?
  */
 public function get_profiles()
 {
     $option_name = 'yst_ga_api';
     $options = get_option($option_name);
     $return = array();
     if (!empty($options['ga_token'])) {
         $args = array('scope' => 'https://www.googleapis.com/auth/analytics.readonly', 'xoauth_displayname' => 'Google Analytics for WordPress by Yoast');
         $access_token = $options['ga_oauth']['access_token'];
         $gdata = new WP_Gdata($args, $access_token['oauth_token'], $access_token['oauth_token_secret']);
         $response = $gdata->get('https://www.googleapis.com/analytics/v2.4/management/accounts/~all/webproperties/~all/profiles');
         $http_code = wp_remote_retrieve_response_code($response);
         $response = wp_remote_retrieve_body($response);
         if ($http_code == 200) {
             $options['ga_api_response'] = array('response' => array('code' => $http_code), 'body' => $response);
             update_option($option_name, $options);
         } else {
             return $return;
         }
         try {
             $xml_reader = new SimpleXMLElement($options['ga_api_response']['body']);
             if (!empty($xml_reader->entry)) {
                 $ga_accounts = array();
                 // Check whether the feed output is the new one, first set, or the old one, second set.
                 if ($xml_reader->link['href'] == 'https://www.googleapis.com/analytics/v2.4/management/accounts/~all/webproperties/~all/profiles') {
                     foreach ($xml_reader->entry as $entry) {
                         $ns = $entry->getNamespaces(true);
                         $properties = $entry->children($ns['dxp'])->property;
                         if (isset($properties[1]->attributes()->value)) {
                             $ua = (string) trim($properties[1]->attributes()->value);
                         }
                         if (isset($properties[2]->attributes()->value)) {
                             $title = (string) trim($properties[2]->attributes()->value);
                         }
                         if (!empty($ua) && !empty($title)) {
                             $ga_accounts[] = array('ua' => $ua, 'title' => $title);
                         }
                     }
                 } else {
                     if ($xml_reader->link['href'] == 'https://www.google.com/analytics/feeds/accounts/default') {
                         foreach ($xml_reader->entry as $entry) {
                             $ns = $entry->getNamespaces(true);
                             $properties = $entry->children($ns['dxp'])->property;
                             if (isset($properties[3]->attributes()->value)) {
                                 $ua = (string) trim($properties[3]->attributes()->value);
                             }
                             if (isset($properties[2]->attributes()->value)) {
                                 $title = (string) trim($properties[2]->attributes()->value);
                             }
                             if (!empty($ua) && !empty($title)) {
                                 $ga_accounts[] = array('ua' => $ua, 'title' => $title);
                             }
                         }
                     }
                 }
                 if (is_array($ga_accounts)) {
                     usort($ga_accounts, array($this, 'sort_profiles'));
                 }
                 foreach ($ga_accounts as $key => $ga_account) {
                     $return[] = array('id' => $ga_account['ua'], 'name' => $ga_account['title'] . ' (' . $ga_account['ua'] . ')');
                 }
             }
         } catch (Exception $e) {
         }
     }
     return $return;
 }