'widget_google_stats', 'description' => __("Displays Stat Info From Google Analytics", 'google-analyticator') ); $control_ops = array('width' => 400, 'height' => 400); $this->WP_Widget('googlestats', __('Google Analytics Stats', 'google-analyticator'), $widget_ops, $control_ops); } function widget($args, $instance) { extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']); $acnt = $instance['account']; $timeFrame = empty($instance['timeFrame']) ? '1' : $instance['timeFrame']; $pageBg = empty($instance['pageBg']) ? 'fff' : $instance['pageBg']; $widgetBg = empty($instance['widgetBg']) ? '999' : $instance['widgetBg']; $innerBg = empty($instance['innerBg']) ? 'fff' : $instance['innerBg']; $font = empty($instance['font']) ? '333' : $instance['font']; $line1 = empty($instance['line1']) ? 'Unique' : $instance['line1']; $line2 = empty($instance['line2']) ? 'Visitors' : $instance['line2']; # Before the widget echo $before_widget; # The title if ( $title ) echo $before_title . $title . $after_title; # Make the stats chicklet echo ''; $this->initiateBackground($pageBg, $font); $this->beginWidget($font, $widgetBg); $this->widgetInfo($this->getUniqueVisitors($acnt, $timeFrame), $line1, $line2, $innerBg, $font); $this->endWidget(); # After the widget echo $after_widget; } function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = strip_tags(stripslashes($new_instance['title'])); $instance['account'] = strip_tags(stripslashes($new_instance['account'])); $instance['timeFrame'] = strip_tags(stripslashes($new_instance['timeFrame'])); $instance['pageBg'] = strip_tags(stripslashes($new_instance['pageBg'])); $instance['widgetBg'] = strip_tags(stripslashes($new_instance['widgetBg'])); $instance['innerBg'] = strip_tags(stripslashes($new_instance['innerBg'])); $instance['font'] = strip_tags(stripslashes($new_instance['font'])); $instance['line1'] = strip_tags(stripslashes($new_instance['line1'])); $instance['line2'] = strip_tags(stripslashes($new_instance['line2'])); return $instance; } function form($instance) { //Defaults $instance = wp_parse_args( (array) $instance, array('title'=>'', 'account'=>'', 'timeFrame'=>'1', 'pageBg'=>'fff', 'widgetBg'=>'999', 'innerBg'=>'fff', 'font'=>'333', 'line1'=>'Unique', 'line2'=>'Visitors') ); $title = htmlspecialchars($instance['title']); $acnt = htmlspecialchars($instance['account']); $timeFrame = htmlspecialchars($instance['timeFrame']); $pageBg = htmlspecialchars($instance['pageBg']); $widgetBg = htmlspecialchars($instance['widgetBg']); $innerBg = htmlspecialchars($instance['innerBg']); $font = htmlspecialchars($instance['font']); $line1 = htmlspecialchars($instance['line1']); $line2 = htmlspecialchars($instance['line2']); $accounts = array(); # Get the current memory limit $current_mem_limit = substr(ini_get('memory_limit'), 0, -1); # Check if this limit is less than 96M, if so, increase it if ( $current_mem_limit < 96 || $current_mem_limit == '' ) { if ( function_exists('memory_get_usage') ) @ini_set('memory_limit', '96M'); } # Get the class for interacting with the Google Analytics require_once('class.analytics.stats.php'); # Create a new Gdata call $stats = new GoogleAnalyticsStats(); # Check if Google sucessfully logged in $login = $stats->checkLogin(); # Get a list of accounts $accounts = $stats->getAnalyticsAccounts(); # Output the options echo '
'; # The list of accounts echo ''; # Time frame echo ''; # Page background echo ''; # Widget background echo ''; # Inner background echo ''; # Font color echo ''; # Text line 1 echo ''; # Text line 2 echo ''; } /** * This function is used to display the background color behind the widget. This is necessary * for the Google Analytics text to have the same background color as the page. * * @param $font_color - Hexadecimal value for the font color used within the Widget (does not effect "Powered By Google Analytics Text"). This effects border color as well. * @param $page_background_color - Hexadecimal value for the page background color * @return void **/ function initiateBackground($page_background_color = 'FFF', $font_color = '000') { echo ''. $visitor_count . ' | ';
echo '' . $line_one . ' ' . $line_two . ' | ';
}
/**
* The function is used strictly for visual appearance. It also displays the Google Analytics text.
*
* @return void
**/
function endWidget()
{
// This closes off the widget.
echo '