section add_action( 'wp_head', array( &$this, 'wp_head' ) ); // Extra content just before add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); // RSS tagging add_filter( 'the_permalink_rss', array( &$this, 'the_permalink_rss' ) ); add_filter( 'the_content', array( &$this, 'the_content' ) ); } // Initialize plugin function init() { if ( function_exists( 'load_plugin_textdomain' ) ) { load_plugin_textdomain( 'google-integration-toolkit', PLUGINDIR.'/'.dirname(plugin_basename(__FILE__)) ); } } // Plugin initialization - admin function admin_init() { require_once( dirname( __FILE__ ) . '/git-admin.php' ); $this->admin = new GoogleIntegrationToolkitAdmin(); } // Add Admin menu option function admin_menu() { $file = __FILE__; // hack for 1.5 global $wp_version; if ( '1.5' == substr( $wp_version, 0, 3 ) ) { $file = 'google-integration-toolkit/google-integration-toolkit.php'; } // admin_init is called later, so need to use proxy method here add_submenu_page( 'options-general.php', 'Google Integration Toolkit', 'Google Integration Toolkit', 10, $file, array( $this, 'options_panel' ) ); } // Check if $this->admin is initialized function check_admin_helper() { if ( !$this->admin ) { wp_die( ''. __('Fatal Google Integration Toolkit error: $this->admin is not initialized!', 'google-integration-toolkit').'' ); } } // Handle options panel function options_panel() { $this->check_admin_helper(); $this->admin->options_panel(); } // URL handler for GWT verification function status_header( $status_header, $header ) { if ( ( $header == 404 ) && ( get_option( 'git_gwt_mode' ) == 'file' ) ) { $filename = get_option( 'git_gwt_filename' ); if ( $filename != '' ) { // Extract root dir from blog url $root = '/'; if ( preg_match( '#http://[^/]+(.+)#', get_option( 'url' ), $matches ) ) { $root = $matches[1]; } // Make sure it ends with slash if ( $root[ strlen($root) - 1 ] != '/' ) { $root .= '/'; } // Check if request is for GWT verification file if ( $root.$filename == $_SERVER['REQUEST_URI'] ) { wp_die( 'Welcome, Google!', '200 OK', array( 'response' => 200 ) ); exit(); } } } return $status_header; } // Extra entries in section function wp_head() { // Google Webmasters Tools if ( get_option( 'git_gwt_mode' ) == 'meta' ) { $meta = get_option( 'git_gwt_meta' ); if ( $meta != '' ) { echo '', "\n"; } } // Google Analytics integration with Google AdSense $analytics_id = get_option( 'git_analytics_id' ); if ( ( $analytics_id != '' ) && get_option( 'git_analytics_adsense' ) ) { echo << window.google_analytics_uacct = "$analytics_id"; EOT; } } // Extra content just before function wp_footer() { $analytics_id = get_option( 'git_analytics_id' ); if ( $analytics_id != '' ) { echo << var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); EOT; } } // Add tags to the rss links function tag_rss_link( $link, $use_hash ) { $tag = 'utm_source='.get_option( 'git_rss_tag_source' ) .'&utm_medium='.get_option( 'git_rss_tag_medium' ) .'&utm_campaign='.get_option( 'git_rss_tag_campaign' ); if ( $use_hash ) { return $link.'#'.$tag; } elseif ( strpos( $link, '?' ) === false ) { return $link.'?'.$tag; } else { return $link.'&'.$tag; } } // RSS tagging - tag links in RSS function the_permalink_rss( $link ) { if ( get_option( 'git_rss_tagging' ) ) { return $this->tag_rss_link( $link, true ); } else { return $link; } } // Helper function for tagging links in RSS - tag links in text function update_rss_link( $matches ) { $url = $matches[2]; if ( preg_match( '/^https?:/', $url ) ) { // Tag links from this blog only $blogurl = get_option( 'url' ); if ( substr( $url, 0, strlen( $blogurl ) ) == $blogurl ) { return $matches[1].$this->tag_rss_link( $url, true ); } else { return $matches[1].$url; } } else { return $matches[1].$this->tag_rss_link( $url, true ); } } // RSS tagging - tag links in RSS' text function the_content( $content ) { if ( is_feed() && get_option( 'git_rss_tagging' ) ) { $content = preg_replace_callback( '/(<\s*a\s[^>]*?\bhref\s*=\s*")([^"]+)/', array( &$this, 'update_rss_link' ), $content ); } return $content; } } add_option( 'git_gwt_mode', 'meta' ); // GWT: add meta tag ('meta') or use file ('file') add_option( 'git_gwt_meta', '' ); // GWT ID add_option( 'git_gwt_filename', '' ); // GWT FileName add_option( 'git_analytics_id', '' ); // Analytics ID add_option( 'git_analytics_adsense', true ); // Enable Analytics-AdSense integration add_option( 'git_rss_tagging', true ); // Enable RSS links tagging add_option( 'git_rss_tag_source', 'feed' ); // RSS tags - Campaign Source add_option( 'git_rss_tag_medium', 'feed' ); // RSS tags - Campaign Medium add_option( 'git_rss_tag_campaign', 'feed' ); // RSS tags - Campaign Name $wp_google_integration_toolkit = new GoogleIntegrationToolkit(); } ?>