web/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php
changeset 136 bde1974c263b
equal deleted inserted replaced
135:53cff4b4a802 136:bde1974c263b
       
     1 <?php
       
     2 /*
       
     3 Plugin Name: Ultimate Google Analytics
       
     4 Plugin URI: http://www.oratransplant.nl/uga
       
     5 Description: Enable Google Analytics on your blog. Has options to also track external links, mailto links and links to downloads on your own site. Check <a href="http://www.oratransplant.nl/uga/#versions">http://www.oratransplant.nl/uga/#versions</a> for version updates
       
     6 Version: 1.6.0
       
     7 Author: Wilfred van der Deijl
       
     8 Author URI: http://www.oratransplant.nl/about
       
     9 */
       
    10 
       
    11 /*  Copyright 2006-2008 Wilfred van der Deijl  (email : wilfred _at_ vanderdeijl.com)
       
    12 
       
    13     This program is free software; you can redistribute it and/or modify
       
    14     it under the terms of the GNU General Public License as published by
       
    15     the Free Software Foundation; either version 2 of the License, or
       
    16     (at your option) any later version.
       
    17 
       
    18     This program is distributed in the hope that it will be useful,
       
    19     but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    20     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    21     GNU General Public License for more details.
       
    22 
       
    23     You should have received a copy of the GNU General Public License
       
    24     along with this program; if not, write to the Free Software
       
    25     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    26 */
       
    27 
       
    28 /*
       
    29   Version History
       
    30     + = new/improved feature
       
    31     ! = fixed bug
       
    32     - = removed feature
       
    33   
       
    34   version 0.1
       
    35     Initial version
       
    36     
       
    37   version 0.2
       
    38     !: Prevent two consecutive forward slashes in the virtual path for a 
       
    39        download link if the URL for the link started with a forward slash
       
    40        (e.g. /files/picture.jps would becomde /downloads//files/picture.jpg)
       
    41     +: Default value for internal hostnames is no longer just the hostname
       
    42        of the current webserver. If this hostnames starts with www. the
       
    43        name without www is also added to the internal hostnames
       
    44        (e.g. "www.oratransplant.nl,oratransplant.nl")
       
    45     +: Renamed track_user to uga_track_user so all functions are prefixed
       
    46        with uga to lower the chances of a naming conflict with another
       
    47        plugin    
       
    48     +: Small HTML comment is placed before the Google Analytics tracker
       
    49        to show it was inserted by the Ultimate Google Analytics plugin
       
    50     +: Debugging has been added and can be enabled/disabled from the 
       
    51        Options page. It is disabled by default. If enabled, all debugging
       
    52        info will be added as HTML comment in the footer of the page   
       
    53        
       
    54   version 1.0
       
    55     +: Added filter to process links in the footer of a comment showing
       
    56        the link to an author. This enables tracking of these outbound links
       
    57        as well
       
    58     +: Added phps as an extension for download tracking. Existing 
       
    59        installations of Ultimate Google Analytics will not be affected.
       
    60        This only applies to the default settings on a fresh install.
       
    61     +: If debugging is disabled an empty dummy function is created for
       
    62        debugging to improve performance
       
    63     +: Added "secret" option to force debugging directly to the output
       
    64        stream and not rely on WordPress actions being called. This can
       
    65        be helpfull when using a WordPress theme that does not call the
       
    66        actions as it shoud  
       
    67     +: If content filtering is enabled, also add the filter for outbound, 
       
    68        mailto and download tracking to the "the_excerpt" filter for pages 
       
    69        showing only an excerpt and not the full article
       
    70     !: The "Enable Tracker" option was not saved to the database. Disabling
       
    71        the checkbox had no effect
       
    72     +: Created a new function uga_set_option to save options to the database
       
    73     +: The plugin now detects if the wp_footer action hook is called. Some
       
    74        WordPress themes out there do not call this hook as they should.
       
    75        If UGA detects this action cannot be hooked, the Google Analytics
       
    76        code is added to the <head> section. This can delay the loading of
       
    77        your pages (see http://www.websiteoptimization.com/speed/tweak/delay/)
       
    78        When the tracker is in the head section the page will not be rendered
       
    79        by your browser until the script is executed. That is why Ultimate
       
    80        Google Analytics will place the tracker at the end of the <body> 
       
    81        section whenever possible.
       
    82 
       
    83   version 1.1
       
    84     !: The first page that is requested after some other user requested a
       
    85        feed had the tracker code in the header in stead of the footer, even
       
    86        if the Theme does support the footer action hook.
       
    87     !: Corrected two typing errors in debug output
       
    88     
       
    89   version 1.2
       
    90     !: If a page was requested that did not call both the header and the 
       
    91        footer hook, UGA would conclude that the footer hook is not implemented
       
    92        in your template. UGA would then revert to using the header hook to
       
    93        put the tracking javascript. On the next page request that does
       
    94        call both the head and footer hook, UGA would detect this and switch
       
    95        back to putting the tracking code in footer.
       
    96        On my blog this happened with the statistics page produced by 
       
    97        wp-stattraq. That page doesn't call either the head or footer hooked.
       
    98        Before v1.2 UGA would just look if the footer was called and draw 
       
    99        conclusions from that. Now UGA checks execution of both the
       
   100        header and footer hook. If none of these are executed it doesn't
       
   101        switch its behaviour. It only switches to head if a page is requested
       
   102        that does call the wp_head but does not call wp_footer
       
   103     !: In the admin page, there was no space between "checked" and the closing
       
   104        /> for all checkboxes. Apparently this caused problems when using
       
   105        Safari
       
   106        
       
   107   version 1.3
       
   108     !: Another bugfix for a situation where the tracker code would sometimes
       
   109        be inserted in the header. Will I ever get this right? :-(
       
   110        This could occur when you're using a favicon.ico in your pages that
       
   111        does not actually exist
       
   112     +: Added check for updates in the options page
       
   113     
       
   114   version 1.4
       
   115     +: Add a comment in the generated HTML to indicate the Google Analytics
       
   116        JavaScript was suppressed because a logged on user is requesting the
       
   117        page. This prevents misunderstanding where people would think the
       
   118        UGA plugin isn't working
       
   119        
       
   120   version 1.5
       
   121     !: Minor changes to the regular expressions. The old expressions could
       
   122        wrongfully match in some rare cases
       
   123     +: Download links using relative URLs are now rewritten to absolute URLs
       
   124        in the urchinTracker. This makes sure that two different relative
       
   125        URLs leading to the same file do get counted as the same file being
       
   126        downloaded.
       
   127     +: Configuration now starts with a very basic/simple screen and most
       
   128        options are tucked away behind an "Advanced" button
       
   129        
       
   130   version 1.5.1
       
   131     !: Removed the usage of a PHP session to store whether the advanced
       
   132        or basic configuration should be shown. Now storing as a parameter
       
   133        in the database
       
   134 
       
   135   version 1.5.2
       
   136     +: Added option to reset to factory settings. This can be used in the
       
   137        rare case that the settings array in the MySQL database is corrupted
       
   138        
       
   139   version 1.5.3
       
   140     !: Call load_plugin_textdomain from the init hook, not from the main 
       
   141        code. See http://www.oratransplant.nl/uga/#comment-40300 for more
       
   142        information. Without this fix, Ultimate Google Analytics is not
       
   143        compatible with the Gengo plugin.
       
   144 
       
   145   version 1.6.0
       
   146     +: Using the new Google Analytics tracking code (ga.js not urchin.js)
       
   147 
       
   148 */
       
   149 
       
   150 // constants
       
   151 define('uga_version', '1.6.0', true);
       
   152 
       
   153 // Uncomment the following line to force debugging regardless setting in
       
   154 // the Control Panel. With this forced debugging, the info will be written
       
   155 // directly to the HTML and the plugin will not rely on any WordPress hooks
       
   156 // This can break your HTML code
       
   157 // define('uga_force_debug', 'enabled', true);
       
   158 
       
   159 // add debugging statement to the debug info
       
   160 // function is an empty dummy function is debugging is disabled
       
   161 $uga_options = get_option('ultimate_ga_options'); 
       
   162 $uga_debug_enabled=$uga_options['debug'];
       
   163 if (defined('uga_force_debug')) {
       
   164   // force debugging
       
   165   function uga_debug($message) {
       
   166     global $uga_debug;
       
   167     $uga_debug .= "$message\n";
       
   168     echo "<!-- \nUGA_DEBUG: $message\n -->";
       
   169   }
       
   170 } else if ($uga_debug_enabled) {
       
   171   // normal debugging is enabled
       
   172   function uga_debug($message) {
       
   173     global $uga_debug;
       
   174     $uga_debug .= "$message\n";
       
   175   }
       
   176 } else {
       
   177   // no debugging
       
   178   function uga_debug($message) {
       
   179   }
       
   180 }
       
   181 
       
   182 // set an Ultimate GA option in the options table of WordPress
       
   183 function uga_set_option($option_name, $option_value) {
       
   184   uga_debug ("Start uga_set_option: $option_name, $option_value");
       
   185   // first get the existing options in the database
       
   186   $uga_options = get_option('ultimate_ga_options');
       
   187   // set the value
       
   188   $uga_options[$option_name] = $option_value;
       
   189   // write the new options to the database
       
   190   update_option('ultimate_ga_options', $uga_options);
       
   191   uga_debug ('End uga_set_option');
       
   192 }
       
   193 
       
   194 // get an Ultimate GA option from the WordPress options database table
       
   195 // if the option does not exist (yet), the default value is returned
       
   196 function uga_get_option($option_name) {
       
   197   uga_debug("Start uga_get_option: $option_name");
       
   198 
       
   199   // get options from the database
       
   200   $uga_options = get_option('ultimate_ga_options'); 
       
   201   uga_debug('uga_options: '.var_export($uga_options,true));
       
   202   
       
   203   if (!$uga_options || !array_key_exists($option_name, $uga_options)) {
       
   204     // no options in database yet, or not this specific option 
       
   205     // create default options array
       
   206     uga_debug('Constructing default options array');
       
   207     $uga_default_options=array();
       
   208     $uga_default_options['internal_domains']  = $_SERVER['SERVER_NAME'];
       
   209     if (preg_match('@www\.(.*)@i', $uga_default_options['internal_domains'], $parts)>=1) {
       
   210       $uga_default_options['internal_domains'] .= ','.$parts[1];
       
   211     }
       
   212     $uga_default_options['account_id']             = 'UA-XXXXXX-X';  
       
   213     $uga_default_options['enable_tracker']         = true;  
       
   214     $uga_default_options['track_adm_pages']        = false;  
       
   215     $uga_default_options['ignore_users']           = true;  
       
   216     $uga_default_options['max_user_level']         = 8;  
       
   217   
       
   218     $uga_default_options['footer_hooked']          = false; // assume the worst
       
   219     $uga_default_options['filter_content']         = true;  
       
   220     $uga_default_options['filter_comments']        = true;  
       
   221     $uga_default_options['filter_comment_authors'] = true;  
       
   222     $uga_default_options['track_ext_links']        = true;  
       
   223     $uga_default_options['prefix_ext_links']       = '/outgoing/';  
       
   224     $uga_default_options['track_files']            = true;  
       
   225     $uga_default_options['prefix_file_links']      = '/downloads/';  
       
   226     $uga_default_options['track_extensions']       = 'gif,jpg,jpeg,bmp,png,pdf,mp3,wav,phps,zip,gz,tar,rar,jar,exe,pps,ppt,xls,doc';  
       
   227     $uga_default_options['track_mail_links']       = true;  
       
   228     $uga_default_options['prefix_mail_links']      = '/mailto/';  
       
   229     $uga_default_options['debug']                  = false;  
       
   230     $uga_default_options['check_updates']          = true;  
       
   231     $uga_default_options['version_sent']           = '';  
       
   232     $uga_default_options['advanced_config']        = false;  
       
   233     uga_debug('uga_default_options: '.var_export($uga_default_options,true));
       
   234     // add default options to the database (if options already exist, 
       
   235     // add_option does nothing
       
   236     add_option('ultimate_ga_options', $uga_default_options, 
       
   237                'Settings for Ultimate Google Analytics plugin');
       
   238 
       
   239     // return default option if option is not in the array in the database
       
   240     // this can happen if a new option was added to the array in an upgrade
       
   241     // and the options haven't been changed/saved to the database yet
       
   242     $result = $uga_default_options[$option_name];
       
   243 
       
   244   } else {
       
   245     // option found in database
       
   246     $result = $uga_options[$option_name];
       
   247   }
       
   248   
       
   249   uga_debug("Ending uga_get_option: $option_name ($result)");
       
   250   return $result;
       
   251 }
       
   252 
       
   253 // function to check for updates
       
   254 function uga_check_updates($echo) {
       
   255   // prepare for making HTTP connection
       
   256   $crlf = "\r\n";
       
   257   $host = 'www.oratransplant.nl';
       
   258   if ($_SERVER['SERVER_NAME']==$host) {
       
   259     // overrule IP address for www.oratransplant.nl server itself
       
   260     $host = $_SERVER['SERVER_ADDR'];
       
   261   }
       
   262   // open socket connection to oratransplant.nl server (timeout after 3 seconds)
       
   263   $handle = fsockopen($host, 80, $error, $err_message, 3);
       
   264   if (!$handle) {
       
   265     if ($echo) {
       
   266       echo __('Unable to get latest version', 'uga')." ($err_message)";
       
   267     }
       
   268   } else {
       
   269     // build HTTP/1.0 request string
       
   270     $req = 'GET http://'.$host.'/uga_version.php?version='.urlencode(uga_version)
       
   271              . '&siteurl='.urlencode(get_option('siteurl')).' HTTP/1.0' . $crlf
       
   272              . 'Host: '.$host. $crlf
       
   273              . $crlf;
       
   274     // send request to server and receive response
       
   275     fwrite($handle, $req);
       
   276     while(!feof($handle))
       
   277       $response .= fread($handle, 1024);
       
   278     fclose($handle);
       
   279     // remove headers from the response
       
   280     $splitter = $crlf.$crlf.'Latest version: ';
       
   281     $pos = strpos($response, $splitter);
       
   282     if ($pos === false) {
       
   283       // no split between headers and body found
       
   284       if ($echo) {
       
   285         _e('Invalid response from server', 'uga');
       
   286       }
       
   287     } else {
       
   288       $body = substr($response, $pos + strlen($splitter));
       
   289       if ($body==uga_version) {
       
   290         if ($echo) {
       
   291           echo __('You are running the latest version', 'uga'). ' ('.uga_version.')';
       
   292         }
       
   293       } else {
       
   294         if ($echo) {
       
   295           _e ('You are running version', 'uga');
       
   296           echo ' '.uga_version.'. ';
       
   297           echo '<strong><span style="font-size:135%;"><a target="_blank" href="http://www.oratransplant.nl/uga/#versions">';
       
   298           _e ('Version', 'uga');
       
   299           echo " $body ";
       
   300           _e ('is available', 'uga');
       
   301           echo '</a></span></strong>';
       
   302         }
       
   303       }
       
   304     }      
       
   305   }
       
   306 }
       
   307 
       
   308 // function that is added as an Action to ADMIN_MENU
       
   309 // it adds an option subpage to the options menu in WordPress administration
       
   310 function uga_admin() {
       
   311   uga_debug('Start uga_admin');
       
   312   if (function_exists('add_options_page')) {
       
   313     uga_debug('Adding options page');
       
   314     add_options_page('Ultimate Google Analytics' /* page title */, 
       
   315                      'Ultimate GA' /* menu title */, 
       
   316                      8 /* min. user level */, 
       
   317                      basename(__FILE__) /* php file */ , 
       
   318                      'uga_options' /* function for subpanel */);
       
   319   }
       
   320   uga_debug('End uga_admin');
       
   321 }
       
   322 
       
   323 // displays options subpage to set options for Ultimate GA and save any
       
   324 // changes to these options back to the database
       
   325 function uga_options() {
       
   326   uga_debug('Start uga_options');
       
   327   if (isset($_POST['advanced_options'])) {
       
   328     uga_set_option('advanced_config', true);
       
   329   }
       
   330   if (isset($_POST['simple_options'])) {
       
   331     uga_set_option('advanced_config', false);
       
   332   }
       
   333   if (isset($_POST['factory_settings'])) {
       
   334     $uga_factory_options = array();
       
   335     update_option('ultimate_ga_options', $uga_factory_options);
       
   336     ?><div class="updated"><p><strong><?php _e('Factory settings restored, remember to set Account ID', 'uga')?></strong></p></div><?php
       
   337   }
       
   338   if (isset($_POST['info_update'])) {
       
   339     uga_debug('Saving posted options: '.var_export($_POST, true));
       
   340     ?><div class="updated"><p><strong><?php 
       
   341     // process submitted form
       
   342     $uga_options = get_option('ultimate_ga_options');
       
   343     $uga_options['account_id']             = $_POST['account_id'];
       
   344     $uga_options['internal_domains']       = $_POST['internal_domains'];
       
   345     $uga_options['max_user_level']         = $_POST['max_user_level'];
       
   346     $uga_options['prefix_ext_links']       = $_POST['prefix_ext_links'];
       
   347     $uga_options['prefix_mail_links']      = $_POST['prefix_mail_links'];
       
   348     $uga_options['prefix_file_links']      = $_POST['prefix_file_links'];
       
   349     $uga_options['track_extensions']       = $_POST['track_extensions'];
       
   350 
       
   351     $uga_options['enable_tracker']         = ($_POST['enable_tracker']=="true"          ? true : false);
       
   352     $uga_options['filter_content']         = ($_POST['filter_content']=="true"          ? true : false);
       
   353     $uga_options['filter_comments']        = ($_POST['filter_comments']=="true"         ? true : false);
       
   354     $uga_options['filter_comment_authors'] = ($_POST['filter_comment_authors']=="true"  ? true : false);
       
   355     $uga_options['track_adm_pages']        = ($_POST['track_adm_pages']=="true"         ? true : false);
       
   356     $uga_options['track_ext_links']        = ($_POST['track_ext_links']=="true"         ? true : false);
       
   357     $uga_options['track_mail_links']       = ($_POST['track_mail_links']=="true"        ? true : false);
       
   358     $uga_options['track_files']            = ($_POST['track_files']=="true"             ? true : false);
       
   359     $uga_options['ignore_users']           = ($_POST['ignore_users']=="true"            ? true : false);
       
   360     $uga_options['debug']                  = ($_POST['debug']=="true"                   ? true : false);
       
   361     $uga_options['check_updates']          = ($_POST['check_updates']=="true"           ? true : false);
       
   362     update_option('ultimate_ga_options', $uga_options);
       
   363     
       
   364     // add/remove filter immediately for admin page currently being rendered
       
   365     if (uga_get_option('track_adm_pages')) {
       
   366       add_action('admin_footer', 'uga_adm_footer_track');
       
   367     } else {
       
   368       remove_action('admin_footer', 'uga_adm_footer_track');
       
   369     }
       
   370     
       
   371     _e('Options saved', 'uga')
       
   372     ?></strong></p></div><?php
       
   373 	} 
       
   374 	
       
   375 	// show options form with current values
       
   376 	uga_debug('Showing options page with UGA options');
       
   377 	?>
       
   378 <div class=wrap>
       
   379   <form method="post">
       
   380     <h2>Ultimate Google Analytics</h2>
       
   381     <fieldset class="options" name="general">
       
   382       <legend><?php _e('General settings', 'uga') ?></legend>
       
   383       <table width="100%" cellspacing="2" cellpadding="5" class="editform">
       
   384         <tr>
       
   385           <th nowrap valign="top" width="33%"><?php _e('Account ID', 'uga') ?></th>
       
   386           <td><input name="account_id" type="text" id="account_id" value="<?php echo uga_get_option('account_id'); ?>" size="50" />
       
   387             <br />Enter your Google Analytics account ID. Google Analytics supplies you with a snippet of JavaScript to put on
       
   388             your webpage. In this JavaScript you can see your account ID in a format like UA-999999-9. There is no need to actually
       
   389             include this JavaScript yourself on any page. That is all handled by Ultimate Google Analytics.
       
   390           </td>
       
   391         </tr>
       
   392         <tr>
       
   393           <th nowrap valign="top" width="33%"><?php _e('Check for updates', 'uga') ?></th>
       
   394           <td><input type="checkbox" name="check_updates" id="check_updates" value="true" <?php if (uga_get_option('check_updates')) echo "checked"; ?> />
       
   395             <br />Check for updates to the Ultimate Google Analytics plugin
       
   396             <?php if (uga_get_option('check_updates')) { echo "<br /><strong>Result</strong>: "; uga_check_updates(true); } ?>
       
   397           </td>
       
   398         </tr>
       
   399         <tr>
       
   400           <th nowrap valign="top" width="33%"><?php _e('Enable tracker', 'uga') ?></th>
       
   401           <td><input type="checkbox" name="enable_tracker" id="enable_tracker" value="true" <?php if (uga_get_option('enable_tracker')) echo "checked"; ?> />
       
   402             <br />By unchecking this checkbox no JavaScript will be included on the page. It is basically the
       
   403             same as disabling the whole plugin
       
   404           </td>
       
   405         </tr>
       
   406         <tr<?php if (!uga_get_option('advanced_config')) echo ' style="display:none;"'; ?>>
       
   407           <th nowrap valign="top" width="33%"><?php _e('Track admin pages', 'uga') ?></th>
       
   408           <td><input type="checkbox" name="track_adm_pages" id="track_adm_pages" value="true" <?php if (uga_get_option('track_adm_pages')) echo "checked"; ?> />
       
   409             <br />Enable or disable the inclusion of Google Analytics tracking on the admin pages of Wordpress.
       
   410           </td>
       
   411         </tr>
       
   412         <tr<?php if (!uga_get_option('advanced_config')) echo ' style="display:none;"'; ?>>
       
   413           <th nowrap valign="top" width="33%"><?php _e('Ignore logged on users', 'uga') ?></th>
       
   414           <td><input type="checkbox" name="ignore_users" id="ignore_users" value="true" <?php if (uga_get_option('ignore_users')) echo "checked"; ?> />
       
   415             of level <input name="max_user_level" type="text" id="max_user_level" value="<?php echo uga_get_option('max_user_level'); ?>" size="2" /> and above
       
   416             <br />Check this checkbox and specify a user level to ignore users of a particular level or above. For such users the
       
   417               Google Analytics JavaScript will not be included in the page
       
   418           </td>
       
   419         </tr>
       
   420         <tr<?php if (!uga_get_option('advanced_config')) echo ' style="display:none;"'; ?>>
       
   421           <th nowrap valign="top" width="33%"><?php _e('Enable debugging', 'uga') ?></th>
       
   422           <td><input type="checkbox" name="debug" id="debug" value="true" <?php if (uga_get_option('debug')) echo "checked"; ?> />
       
   423             <br />Enable or disable debugging info. If enabled, UGA debugging is written as HTML comments
       
   424               to the page being rendered.
       
   425           </td>
       
   426         </tr>
       
   427       </table>
       
   428     </fieldset>
       
   429     
       
   430     <fieldset class="options" name="external" <?php if (!uga_get_option('advanced_config')) echo ' style="display:none;"'; ?>>
       
   431       <legend><?php _e('Links tracking', 'uga') ?></legend>
       
   432       <table width="100%" cellspacing="2" cellpadding="5" class="editform" <?php if (!uga_get_option('advanced_config')) echo ' style="display:none;"'; ?>>
       
   433         <tr>
       
   434           <th nowrap valign="top" width="33%"><?php _e('Filter content', 'uga') ?></th>
       
   435           <td><input type="checkbox" name="filter_content" id="filter_content" value="true" <?php if (uga_get_option('filter_content')) echo "checked"; ?> />
       
   436             <br />Enable or disable tracking of links in the content of your articles. Which type(s) of links
       
   437             should be tracked can be selected with the other options. If you plan to disable all of them, you
       
   438             are better of disabling the entire filtering to save performance.
       
   439           </td>
       
   440         </tr>
       
   441         <tr>
       
   442           <th nowrap valign="top" width="33%"><?php _e('Filter comments', 'uga') ?></th>
       
   443           <td><input type="checkbox" name="filter_comments" id="filter_comments" value="true" <?php if (uga_get_option('filter_comments')) echo "checked"; ?> />
       
   444             <br />Enable or disable tracking of links in the comments. Which type(s) of links
       
   445             should be tracked can be selected with the other options. If you plan to disable all of them, you
       
   446             are better of disabling the entire filtering to save performance.
       
   447           </td>
       
   448         </tr>
       
   449         <tr>
       
   450           <th nowrap valign="top" width="33%"><?php _e('Filter comment author links', 'uga') ?></th>
       
   451           <td><input type="checkbox" name="filter_comment_authors" id="filter_comment_authors" value="true" <?php if (uga_get_option('filter_comment_authors')) echo "checked"; ?> />
       
   452             <br />Enable or disable tracking of links in the comments footer showing the author. 
       
   453               If you plan to disable all filters, you are better of disabling the entire filtering to save performance.
       
   454           </td>
       
   455         </tr>
       
   456 
       
   457         <tr>
       
   458           <th nowrap valign="top" width="33%"><?php _e('Track external links', 'uga') ?></th>
       
   459           <td><input type="checkbox" name="track_ext_links" id="track_ext_links" value="true" <?php if (uga_get_option('track_ext_links')) echo "checked"; ?> />
       
   460             and prefix with <input name="prefix_ext_links" type="text" id="prefix_ext_links" value="<?php echo uga_get_option('prefix_ext_links'); ?>" size="40" />
       
   461             <br />Include code to track links to external sites and specify what prefix should be used in the
       
   462               tracking URL. This groups all your external links in a separate directory when looking at your
       
   463               Google Analytics stats
       
   464           </td>
       
   465         </tr>
       
   466         <tr>
       
   467           <th nowrap valign="top" width="33%"><?php _e('Internal host(s)', 'uga') ?></th>
       
   468           <td><input name="internal_domains" type="text" id="internal_domains" value="<?php echo uga_get_option('internal_domains'); ?>" size="50" />
       
   469             <br />Hostname(s) that are considered internal links. Links to these hosts are not tagged as external link.
       
   470               You can specify multiple hostnames separated by commas. This list of internal hostnames is also used
       
   471               for tagging download links (see below). Download links have to be of a specified file type and it has
       
   472               to an internal link. An internal link can either be a relative link (without a hostname) or a link that starts 
       
   473               with any of the specified internal hostnames.
       
   474           </td>
       
   475         </tr>
       
   476         <tr>
       
   477           <th nowrap valign="top" width="33%"><?php _e('Track download links', 'uga') ?></th>
       
   478           <td><input type="checkbox" name="track_files" id="track_files" value="true" <?php if (uga_get_option('track_files')) echo "checked"; ?> />
       
   479             and prefix with <input name="prefix_file_links" type="text" id="prefix_file_links" value="<?php echo uga_get_option('prefix_file_links'); ?>" size="40" />
       
   480             <br />Include code to track internal (within your own site) links to certain file types and specify what prefix should be used in the
       
   481               tracking URL. This groups all your file links in a separate directory when looking at your
       
   482               Google Analytics stats
       
   483           </td>
       
   484         </tr>
       
   485         <tr>
       
   486           <th nowrap valign="top" width="33%"><?php _e('File extensions to track', 'uga') ?></th>
       
   487           <td><input name="track_extensions" type="text" id="track_extensions" value="<?php echo uga_get_option('track_extensions'); ?>" size="50" />
       
   488             <br />Specify which file extensions you want to check when download link tracking is enabled.
       
   489           </td>
       
   490         </tr>
       
   491         <tr>
       
   492           <th nowrap valign="top" width="33%"><?php _e('Track mailto: links', 'uga') ?></th>
       
   493           <td><input type="checkbox" name="track_mail_links" id="track_mail_links" value="true" <?php if (uga_get_option('track_mail_links')) echo "checked"; ?> />
       
   494             and prefix with <input name="prefix_mail_links" type="text" id="prefix_mail_links" value="<?php echo uga_get_option('prefix_mail_links'); ?>" size="40" />
       
   495             <br />Include code to track mailto: links to email addresses and specify what prefix should be used in the
       
   496               tracking URL. This groups all your mail links in a separate directory when looking at your
       
   497               Google Analytics stats
       
   498           </td>
       
   499         </tr>
       
   500       </table>
       
   501     </fieldset>
       
   502     
       
   503     <div class="submit">
       
   504 <?php if (uga_get_option('advanced_config')) { ?>
       
   505       <input type="submit" name="simple_options" value="<?php _e('Simple configuration', 'uga') ?>" />
       
   506       <input type="submit" name="factory_settings" value="<?php _e('Factory settings', 'uga') ?>" />
       
   507 <?php } else { ?>
       
   508       <input type="submit" name="advanced_options" value="<?php _e('Advanced configuration', 'uga') ?>" />
       
   509 <?php } ?>
       
   510       <input type="submit" name="info_update" value="<?php _e('Update options', 'uga') ?>" />
       
   511 	  </div>
       
   512   </form>
       
   513 </div><?php
       
   514   uga_debug('End uga_options');
       
   515 }
       
   516 
       
   517 // returns true if current user has to be tracked by UGA
       
   518 // return false if user does not have to be tracked. This is the case when
       
   519 // the 'ignore_users' option is enabled and the current userlevel is
       
   520 // equal or higher than the set limit.
       
   521 function uga_track_user() {
       
   522   global $user_level;
       
   523   uga_debug('Start uga_track_user');
       
   524   if (!user_level) {
       
   525     // user nog logged on -> track
       
   526     uga_debug('User not logged on');
       
   527     $result = true;
       
   528   } else {
       
   529     // user logged on
       
   530     if (uga_get_option('ignore_users') && 
       
   531         $user_level>=uga_get_option('max_user_level')) {
       
   532       // ignore user because of userlevel
       
   533       uga_debug("Not tracking user with level $user_level");
       
   534       $result = false;
       
   535     } else {
       
   536       uga_debug("Tracking user with level $user_level");
       
   537       $result = true;
       
   538     }
       
   539   }
       
   540   uga_debug("Ending uga_track_user: $result");
       
   541   return $result;
       
   542 }
       
   543 
       
   544 // returns true if a URL is internal. This is the case when a URL is
       
   545 // starts with any of the defined internal hostnames
       
   546 // The input URL has to be stripped of any protocol:// before calling this
       
   547 // function 
       
   548 function uga_is_url_internal($url) {
       
   549   // check if the URL starts with any of the "internal" hostnames
       
   550   uga_debug("Start uga_is_url_internal: $url");
       
   551   $url=strtolower($url);
       
   552   $internal=false;
       
   553   $internals=explode(',', uga_get_option('internal_domains'));
       
   554   foreach ($internals as $hostname) {
       
   555     uga_debug("Checking hostname $hostname");
       
   556     $hostname=strtolower($hostname);
       
   557     if (substr($url, 0, strlen($hostname))==$hostname) {
       
   558       // URL starts with hostname of this website
       
   559       uga_debug('Match found, url is internal');
       
   560       $internal=true;
       
   561     }
       
   562   }
       
   563   uga_debug("Ending uga_is_url_internal: $internal");
       
   564   return $internal;
       
   565 }
       
   566 
       
   567 // strips the hostname from the beginning of a URL. The URL already has
       
   568 // to be stripped of any "protocol://" before calling this function
       
   569 function uga_remove_hostname($url) {
       
   570   // removes hostname (including first /) from URL
       
   571   // result never starts with a /
       
   572   uga_debug("Start uga_remove_hostname: $url");
       
   573   $pos=strpos($url, '/');
       
   574   $result='';
       
   575   if ($pos===false) {
       
   576     // url is only a hostname
       
   577     uga_debug('URL just hostname, return empty string');
       
   578     $result='';
       
   579   } else {
       
   580     uga_debug('Stripping everything up until and including first /');
       
   581     $result=substr($url, $pos+1);
       
   582   }
       
   583   uga_debug("Ending uga_remove_hostname: $result");
       
   584   return $result;
       
   585 }
       
   586 
       
   587 // returns the trackerString for a mailto: link
       
   588 // will return an empty string when mailto: tracking is disabled
       
   589 function uga_track_mailto($mailto) {
       
   590   // return tracker string for mailto: link
       
   591   uga_debug("Start uga_track_mailto: $mailto");
       
   592   $tracker='';
       
   593   if (uga_get_option('track_mail_links')) {
       
   594     $tracker=uga_get_option('prefix_mail_links').$mailto;
       
   595   }        
       
   596   uga_debug("Ending uga_track_mailto: $tracker");
       
   597   return $tracker;
       
   598 }
       
   599 
       
   600 // returns the trackerString for an internal download link
       
   601 // will return an empty string if this feature is disabled
       
   602 function uga_track_internal_url($url, $relative) {
       
   603   // return tracker string for internal URL
       
   604   // absolute url starts with hostname
       
   605   uga_debug("Start uga_track_internal_url: $url, $relative");
       
   606   $tracker='';
       
   607   if (uga_get_option('track_files')) {
       
   608     // check for specific file extensions on local site
       
   609     uga_debug('Tracking files enabled');
       
   610     if (strpos($url,'?') !== false) {
       
   611       // remove query parameters from URL
       
   612       $url=substr($url, 0, strpos($url, '?'));
       
   613       uga_debug("Removed query params from url: $url");
       
   614     }
       
   615     // check file extension
       
   616     $exts=explode(',', uga_get_option('track_extensions'));
       
   617     foreach ($exts as $ext) {
       
   618       uga_debug("Checking file extension $ext");
       
   619       if (substr($url, -strlen($ext)-1) == ".$ext") {
       
   620         // file extension found
       
   621         uga_debug('File extension found');
       
   622         if ($relative) {
       
   623           uga_debug('Relative URL');
       
   624           if (substr($url, 0, 1)=='/') {
       
   625             // relative URL starts with / (root)
       
   626             // remove starting slash as the prexif that will be appended
       
   627             // already ends with /
       
   628             $url=substr($url, 1);
       
   629             uga_debug("Removed starting slash from url: $url");
       
   630           } else {
       
   631             // relative URL does not start with / (root)
       
   632             // rewrite to URL that starts from root
       
   633             uga_debug("Rewriting relative url: $url");
       
   634             $base_dir=$_SERVER['REQUEST_URI'];  // URI of currently requested page
       
   635             uga_debug("Request URI: $base_dir");
       
   636             if (strpos($base_dir,'?')) {
       
   637               // strip query parameters
       
   638               $base_dir=substr($base_dir, 0, strpos($base_dir,'?'));
       
   639             }
       
   640             if ('/'!=substr($base_dir, -1, 1)) {
       
   641               // strip file name from base-URL
       
   642               $base_dir=substr($base_dir, 0, strrpos($base_dir,'/')+1);
       
   643             }
       
   644             //$url=print_r($_SERVER,true).$base_dir;
       
   645             $url=substr($base_dir.$url, 1);
       
   646             uga_debug("Rewrote url to absolute: $url");
       
   647           }
       
   648           $tracker=uga_get_option('prefix_file_links').$url;
       
   649         } else {
       
   650           uga_debug('Absolute URL, remove hostname from URL');
       
   651           // remove hostname from url
       
   652           $tracker=uga_get_option('prefix_file_links').uga_remove_hostname($url);
       
   653         }
       
   654       }
       
   655     }
       
   656   }
       
   657   
       
   658   uga_debug("Ending uga_track_internal_url: $tracker");
       
   659   return $tracker;
       
   660 
       
   661 }
       
   662 
       
   663 // returns the trackerString for an external link
       
   664 // will return an empty string if this feature is disabled
       
   665 function uga_track_external_url($url) {
       
   666   // return tracker string for external URL
       
   667   // url is everything after the protocol:// (e.g. www.host.com/dir/file?param)
       
   668   uga_debug("Start uga_track_external_url: $url");
       
   669   $tracker='';
       
   670   if (uga_get_option('track_ext_links')) {
       
   671     uga_debug('Tracking external links enabled');
       
   672     $tracker=uga_get_option('prefix_ext_links').$url;
       
   673   }
       
   674   uga_debug("Ending uga_track_external_url: $url");
       
   675   return $tracker;
       
   676 }
       
   677 
       
   678 // returns the trackerString for an internal/external link
       
   679 // will return an empy string if tracking for this type of URL is disabled
       
   680 function uga_track_full_url($url) {
       
   681   // url is everything after the protocol:// (e.g. www.host.com/dir/file?param)
       
   682   uga_debug("Start uga_track_full_url: $url");
       
   683 
       
   684   // check if the URL starts with any of the "internal" hostnames
       
   685   $tracker = '';
       
   686   if (uga_is_url_internal($url)) {
       
   687     uga_debug('Get tracker for internal URL');
       
   688     $tracker = uga_track_internal_url($url, false);
       
   689   } else {
       
   690     uga_debug('Get tracker for external URL');
       
   691     $tracker = uga_track_external_url($url);
       
   692   }
       
   693   uga_debug("Ending uga_track_full_url: $tracker");
       
   694   return $tracker;
       
   695 }
       
   696 
       
   697 // returns a (possibly modified) <a>...</a> link with onClick event
       
   698 // added if tracking for this type of link is enabled
       
   699 // this function is used as callback function in a preg_replace_callback
       
   700 function uga_preg_callback($match) {
       
   701   uga_debug("Start uga_preg_callback: $match");
       
   702 
       
   703   // $match[0] is the complete match
       
   704   $before_href=1; // text between "<a" and "href"
       
   705   $after_href=3;  // text between the "href" attribute and the closing ">"
       
   706   $href_value=2;  // value of the href attribute
       
   707   $a_content=4;   // text between <a> and </a> tags
       
   708 
       
   709   $result = $match[0];
       
   710   
       
   711   // determine (if any) tracker string
       
   712   $tracker='';
       
   713   // disect target URL (1=protocol, 2=location) to determine type of URL
       
   714   if (preg_match('@^([a-z]+)://(.*)@i', trim($match[$href_value]), $target) > 0) {
       
   715     // URL with protocol and :// disected 
       
   716     uga_debug('Get tracker for full url');
       
   717     $tracker = uga_track_full_url($target[2]);
       
   718   } else if (preg_match('@^(mailto):(.*)@i', trim($match[$href_value]), $target) > 0) {
       
   719     // mailto: link found
       
   720     uga_debug('Get tracker for mailto: link');
       
   721     $tracker = uga_track_mailto($target[2]);
       
   722   } else {
       
   723     // relative URL
       
   724     uga_debug('Get tracker for relative (and thus internal) url');
       
   725     $tracker = uga_track_internal_url(trim($match[$href_value]), true);
       
   726   }
       
   727 
       
   728   if ($tracker) {
       
   729     // add onClick attribute to the A tag
       
   730     uga_debug("Adding onclick attribute for $tracker");
       
   731     $onClick="javascript:pageTracker._trackPageview('$tracker');";
       
   732     $result=preg_replace('@<a\s([^>]*?)href@i', // '@<a(.*)href@i', 
       
   733                          '<a onclick="'.$onClick.'" $1 href', 
       
   734                          $result);
       
   735   }
       
   736 
       
   737   uga_debug("Ending uga_preg_callback: $result");
       
   738   return $result;
       
   739 
       
   740 }
       
   741 
       
   742 // returns true if we're currently building a feed
       
   743 function uga_in_feed() {
       
   744   global $doing_rss;
       
   745   uga_debug('Start uga_in_feed');
       
   746   if (is_feed() || $doing_rss) {
       
   747     $result = true;
       
   748   } else {
       
   749     $result = false;
       
   750   }
       
   751   uga_debug("Ending uga_in_feed: $result");
       
   752   return $result;
       
   753 }
       
   754 
       
   755 // filter function used as filter on content and/or comments
       
   756 // will add onClick tracking JavaScript to any link that required tracking
       
   757 function uga_filter($content) {
       
   758   uga_debug("Start uga_filter: $content");
       
   759   if (!uga_in_feed() && uga_track_user()) {
       
   760     // $pattern = '<a(.*?)href\s*=\s*[\'"](.*?)[\'"]([^>]*)>(.*?)<\s*/a\s*>';
       
   761     $pattern = '<a\s([^>]*?)href\s*=\s*[\'"](.*?)[\'"]([^>]*)>(.*?)</a\s*>';
       
   762     uga_debug("Calling preg_replace_callback: $pattern");
       
   763     $content = preg_replace_callback('@'.$pattern.'@i', 'uga_preg_callback', $content);
       
   764   }
       
   765   uga_debug("Ending uga_filter: $content");
       
   766   return $content;
       
   767 }
       
   768 
       
   769 // insert a snippet of HTML in either the header or the footer of the page
       
   770 // we prefer to put this in the footer, but if the wp_footer() hook is not
       
   771 // called by the template, we'll use the header
       
   772 function uga_insert_html_once($location, $html) {
       
   773   uga_debug("Start uga_insert_html_once: $location, $html");
       
   774   global $uga_header_hooked;
       
   775   global $uga_footer_hooked;
       
   776   global $uga_html_inserted;
       
   777   uga_debug("Footer hooked: $uga_footer_hooked");
       
   778   uga_debug("HTML inserted: $uga_html_inserted");
       
   779   
       
   780   if ('head'==$location) {
       
   781     // header
       
   782     uga_debug('Location is HEAD');
       
   783     // notify uga_shutdown that the header hook got executed
       
   784     $uga_header_hooked = true;
       
   785     if (!uga_get_option('footer_hooked')) {
       
   786       // only insert the HTML if the footer is not hooked
       
   787       uga_debug('Inserting HTML since footer is not hooked');
       
   788       echo $html;
       
   789       $uga_html_inserted=true;
       
   790     }
       
   791   } else if ('footer'==$location) {
       
   792     // footer
       
   793     uga_debug('Location is FOOTER');
       
   794     // notify uga_shutdown that the footer hook got executed
       
   795     $uga_footer_hooked = true;
       
   796     if (!$uga_html_inserted) {
       
   797       // insert the HTML if it is not yet inserted by the HEAD filter
       
   798       uga_debug('Inserting HTML');
       
   799       echo $html;
       
   800     }
       
   801   } else if ('adm_footer'==$location) {
       
   802     // footer of admin page
       
   803     uga_debug('Location is ADM_FOOTER');
       
   804     if (!$uga_html_inserted) {
       
   805       // insert the HTML if it is not yet inserted by the HEAD filter
       
   806       uga_debug('Inserting HTML');
       
   807       echo $html;
       
   808     }
       
   809   }
       
   810   uga_debug('End uga_insert_html');
       
   811 }
       
   812 
       
   813 // return snippet of HTML to insert in the page to activate Google Analytics
       
   814 function uga_get_tracker() {
       
   815   uga_debug('Start uga_get_tracker');
       
   816   $result='';
       
   817   if (!uga_in_feed()) {
       
   818     if (uga_track_user()) {
       
   819       // add tracker JavaScript to the page
       
   820       $result='
       
   821 <!-- tracker added by Ultimate Google Analytics plugin v'.uga_version.': http://www.oratransplant.nl/uga -->
       
   822 <script type="text/javascript">
       
   823 var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
       
   824 document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));
       
   825 </script>
       
   826 <script type="text/javascript">
       
   827 var pageTracker = _gat._getTracker("'.uga_get_option('account_id').'");
       
   828 pageTracker._initData();
       
   829 pageTracker._trackPageview();
       
   830 </script>
       
   831 ';
       
   832     } else {
       
   833       // logged on user not tracked
       
   834       $result='
       
   835 <!-- tracker not added by Ultimate Google Analytics plugin v'.uga_version.': http://www.oratransplant.nl/uga -->
       
   836 <!-- tracker is not added for a logged on user of this level -->
       
   837 ';
       
   838     }
       
   839   }
       
   840   uga_debug("Ending uga_get_tracker: $result");
       
   841   return $result;
       
   842 }
       
   843 
       
   844 // Hook function for wp_head action to (possibly) include the GA tracker
       
   845 function uga_wp_head_track($dummy) {
       
   846   uga_debug("Start uga_wp_head_track: $dummy");
       
   847   uga_insert_html_once('head', uga_get_tracker());
       
   848   uga_debug("Ending uga_wp_head_track: $dummy");
       
   849   return $dummy;
       
   850 }
       
   851 
       
   852 // Hook function for wp_footer action to (possibly) include the GA tracker
       
   853 function uga_wp_footer_track($dummy) {
       
   854   uga_debug("Start uga_wp_footer_track: $dummy");
       
   855   uga_insert_html_once('footer', uga_get_tracker());
       
   856   uga_debug("Ending uga_wp_footer_track: $dummy");
       
   857   return $dummy;
       
   858 }
       
   859 
       
   860 // Hook function for admin_footer action to (possibly) include the GA tracker
       
   861 function uga_adm_footer_track($dummy) {
       
   862   uga_debug("Start uga_adm_footer_track: $dummy");
       
   863   uga_insert_html_once('adm_footer', uga_get_tracker());
       
   864   uga_debug("Ending uga_adm_footer_track: $dummy");
       
   865   return $dummy;
       
   866 }
       
   867 
       
   868 // Hook function for init action to do some initialization
       
   869 function uga_init() {
       
   870   uga_debug("Start uga_init");
       
   871   // load texts for localization
       
   872   load_plugin_textdomain('uga');
       
   873   uga_debug("Ending uga_init");
       
   874 }
       
   875 
       
   876 // Hook function called during shutdown (end of page)
       
   877 // this determines if the wp_footer hooks executed. If not, UGA is configured
       
   878 // to insert its HTML in the header and not the footer
       
   879 // It also adds the debug-info as HTML comments if debugging is enabled
       
   880 function uga_shutdown() {
       
   881   uga_debug('Start uga_shutdown');
       
   882   global $uga_header_hooked;
       
   883   global $uga_footer_hooked;
       
   884 
       
   885   if (is_404()) {
       
   886     // do not set the flag when building a 404 page. This can lead to problems
       
   887     // with a non-existing favicon.ico. In that case the header is executed
       
   888     // but the footer is not. We do not want this to lead to flipping the flag
       
   889     uga_debug('Building 404 page, not setting footer_hooked flag');
       
   890   } else if (uga_in_feed()) {
       
   891     uga_debug('Building feed, not setting footer_hooked flag');
       
   892   } else if (!uga_track_user()) {
       
   893     uga_debug('Not tracking this user, not setting footer_hooked flag');
       
   894   } else {
       
   895     // determine appropriate value of footer_hooked flag
       
   896     if (!$uga_footer_hooked && !$uga_header_hooked) {
       
   897       // both the header and the footer hook did not execute
       
   898       // probably building some special page (e.g. wp-stattraq reports page)
       
   899       // do not change the flag to indicate whether the footer is hooked
       
   900       uga_debug('Header and footer hook were not executed');
       
   901     } else if ($uga_footer_hooked) {
       
   902       // footer hooks executed
       
   903       uga_debug('Footer hook was executed');
       
   904       if (!uga_get_option('footer_hooked')) {
       
   905         uga_debug('Changing footer_hooked option to true');
       
   906         uga_set_option('footer_hooked', true);
       
   907       }
       
   908     } else {
       
   909       // footer hook did not execute , but header hook did
       
   910       uga_debug('Footer hook was not executed, but header hook did');
       
   911       if (uga_get_option('footer_hooked')) {
       
   912         uga_debug('Changing footer_hooked option to false');
       
   913         uga_set_option('footer_hooked', false);
       
   914       }
       
   915     }
       
   916   }
       
   917 
       
   918   // write the debug info
       
   919   if (uga_get_option('debug')) {
       
   920     global $uga_debug;
       
   921     echo "\n<!-- \n$uga_debug -->";  
       
   922   }
       
   923   uga_debug('End uga_shutdown');
       
   924 }
       
   925 
       
   926 // **************
       
   927 // initialization
       
   928 
       
   929 uga_debug('Ultimate Google Analytics initialization');
       
   930 
       
   931 if (uga_get_option('check_updates') && uga_get_option('version_sent')!=uga_version) {
       
   932   // this version has not been checked yet
       
   933   uga_debug('Phone home with version number');
       
   934   uga_set_option('version_sent', uga_version);
       
   935   uga_check_updates(false);
       
   936 }
       
   937 
       
   938 // assume both header and footer are not hooked
       
   939 global $uga_header_hooked;
       
   940 global $uga_footer_hooked;
       
   941 $uga_header_hooked=false;
       
   942 $uga_footer_hooked=false;
       
   943 
       
   944 // add UGA Options page to the Option menu
       
   945 add_action('admin_menu', 'uga_admin');
       
   946 
       
   947 // add filters if enabled
       
   948 if (uga_get_option('enable_tracker') && uga_get_option('filter_content')) {
       
   949   uga_debug('Adding the_content and the_excerpt filters');
       
   950   add_filter('the_content', 'uga_filter', 50);
       
   951   add_filter('the_excerpt', 'uga_filter', 50);
       
   952 }
       
   953 if (uga_get_option('enable_tracker') && uga_get_option('filter_comments')) {
       
   954   uga_debug('Adding comment_text filter');
       
   955   add_filter('comment_text', 'uga_filter', 50);
       
   956 }
       
   957 if (uga_get_option('enable_tracker') && uga_get_option('filter_comment_authors')) {
       
   958   uga_debug('Adding get_comment_author_link filter');
       
   959   add_filter('get_comment_author_link', 'uga_filter', 50);
       
   960 }
       
   961 
       
   962 // add actions if enabled
       
   963 if (uga_get_option('enable_tracker')) {
       
   964   uga_debug('Adding wp_head and wp_footer action hooks for tracker');
       
   965   add_action('wp_head',   'uga_wp_head_track');
       
   966   add_action('wp_footer', 'uga_wp_footer_track');
       
   967 }
       
   968 if (uga_get_option('track_adm_pages')) {
       
   969   uga_debug('Adding admin_footer action hook for tracker');
       
   970   add_action('admin_footer', 'uga_adm_footer_track');
       
   971 }
       
   972 uga_debug('Adding init action hook');
       
   973 add_action('init', 'uga_init');
       
   974 uga_debug('Adding shutdown action hook for debugging and notice if wp_footer is hooked');
       
   975 add_action('shutdown', 'uga_shutdown');
       
   976 
       
   977 ?>