Q: Why not just add the Performancing Metrics code to my blog myself?
A: If you change your style or template, you'll have to manually insert the code every time. With the plugin, it stays with you whenever you make changes. With the plugin, you'll get better detection for your stats as well as other features (soon you'll be able to view your blog's stats directly in your Dashboard!) If you already inserted the default Metrics tracking code in your template, remove it before using this plugin. Your metrics will be inaccurate if you do not remove it.
And should you be talking about wordpress.com ... you can't use the plugin there. Maybe in the future.
Submitted by Paul Drago on August 21, 2006 - 4:53am.
last time I checked wordpress was always free. If you mean hosted on wordpress.com then I couldn'te tell you. but so long as you can add the JS into the body tag you should be fine.
Submitted by mandrill on October 13, 2006 - 3:53pm.
A mirror for the plugin would be of great use, According to the blurb on the link to it the site's been down since August, is it possible that someone just forgot to update the link? Or has daveried.net dissappeared?
This is the pmetrics.php file to be saved in wp-content/plugins.
DON´T use plugin AND inserted code. It produces errors.
Copy text between ===== lines to wordpad and save as pmetrics.php. FTP it to your site.
==========================
<?php /* WordPress Info ------------------------------------------------------------------------------- Plugin Name: PMetrics Plugin URI: http://davereid.net/projects/wordpress/pmetrics/ Description: Adds Performancing Metrics code to each blog page automatically. Includes a sidebar widget. Version: 0.3.1 Author: Dave Reid Author URI: http://davereid.net/
Installation ------------------------------------------------------------------------------- 1. Upload/copy this file (pmetrics.php) into the plugins directory of your WordPress installation (wp-content/plugins). 2. Log in to WordPress administration. 3. Click Plugins from the main menu. 4. Scroll to find PMetrics and click Activate to enable this plugin.
License ------------------------------------------------------------------------------- Copyright (C) 2006 Dave Reid (dave@davereid.net)
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any other version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
The license is also available at: http://opensource.org/licenses/gpl-license.php
var $_name = 'pmetrics'; var $_version = '0.3.1'; var $_domain = NULL; var $_options = array(); var $_options_changed = array(); var $_curl_version = NULL; var $_url_website = 'http://davereid.net/projects/wordpress/pmetrics/'; var $_url_options = 'options-general.php?page='; var $_url_update = 'http://davereid.net/projects/wordpress/update.php'; var $_url_metrics = 'http://performancing.com/metrics/'; var $_url_api = 'http://performancing.com/perfstats/api.php';
// ------------------------------------------------------------------------ function PMetrics() { $this->load_options(); $this->is_curl_enabled();
// If the users has opted out of detailed information, do not include if (!$this->get_option('update_optout')) { $data['wordpress'] = get_bloginfo('version'); //$data['blog'] = get_bloginfo('name'); $data['url'] = get_bloginfo('url'); $data['php'] = PHP_VERSION; //phpversion(); $data['curl'] = $this->_curl_version; $data['server'] = $_SERVER['SERVER_SOFTWARE']; //$data['auth'] = $this->get_option('account_auth'); } return $data; }
// If using the auto update and it's not been one week since the last // update check, return the cached latest version. if ($auto_update && time() < $this->get_option('update_check_next')) { return $this->get_option('update_version'); }
// Get the latest version from the update server through cURL $version = $this->_version; $curl_data = $this->do_curl($this->_url_update, $this->get_update_data(), TRUE); if ($this->handle_curl_error($curl_data)) { $version = NULL; } else { $version = trim($curl_data['content']); }
if (empty($version)) { $msg = 'Error performing update check (probably server error).'; if (!$auto_update && !$silent) $this->show_message($msg); $version = NULL; }
// If using the auto update, increment the next update time to one week // and cache the version if ($this->get_option('update_enabled')) { $this->set_option('update_check_next', strtotime('+1 week')); $this->set_option('update_version', $version); $this->
a) put the PMetrics
a) put the PMetrics Javascript call into the footer template
OR
b) use the WordPress plugin mentioned in the PFF handbook
were is the footer? were is
were is the footer?
were is that plugin?
Just some plugin tip
Just some plugin tip ...
http://performancing.com/metrics/start
http://performancing.com/metrics/handbook
http://performancing.com/metrics/handbook/apps
Finally ...
http://davereid.net/projects/wordpress/pmetrics/
And should you be talking about wordpress.com ... you can't use the plugin there. Maybe in the future.
http://davereid.net/projects/
http://davereid.net/projects/wordpress/pmetrics/ That is the metrics plugin
as for the footer...go to presentation, edit theme, click footer....
i use the free wordpress...
i use the free wordpress... does it works with that?
the free?
last time I checked wordpress was always free. If you mean hosted on wordpress.com then I couldn'te tell you. but so long as you can add the JS into the body tag you should be fine.
Wordpress.com does not allow
Wordpress.com does not allow javascript so js based services are not possible on there
Widget
Anyone has the widget available ?
The site is down since end of august !
Glenn
i would need the plugin as well..
any mirror up with the plugin?
Me too for the plugin
A mirror for the plugin would be of great use, According to the blurb on the link to it the site's been down since August, is it possible that someone just forgot to update the link? Or has daveried.net dissappeared?
This is the plugin:
This is the pmetrics.php file to be saved in wp-content/plugins.
DON´T use plugin AND inserted code. It produces errors.
Copy text between ===== lines to wordpad and save as pmetrics.php. FTP it to your site.
==========================
<?php
/*
WordPress Info
-------------------------------------------------------------------------------
Plugin Name: PMetrics
Plugin URI: http://davereid.net/projects/wordpress/pmetrics/
Description: Adds Performancing Metrics code to each blog page automatically. Includes a sidebar widget.
Version: 0.3.1
Author: Dave Reid
Author URI: http://davereid.net/
Installation
-------------------------------------------------------------------------------
1. Upload/copy this file (pmetrics.php) into the plugins directory of your
WordPress installation (wp-content/plugins).
2. Log in to WordPress administration.
3. Click Plugins from the main menu.
4. Scroll to find PMetrics and click Activate to enable this plugin.
License
-------------------------------------------------------------------------------
Copyright (C) 2006 Dave Reid (dave@davereid.net)
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any other
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
The license is also available at:
http://opensource.org/licenses/gpl-license.php
-------------------------------------------------------------------------------
*/
class PMetrics {
var $_name = 'pmetrics';
var $_version = '0.3.1';
var $_domain = NULL;
var $_options = array();
var $_options_changed = array();
var $_curl_version = NULL;
var $_url_website = 'http://davereid.net/projects/wordpress/pmetrics/';
var $_url_options = 'options-general.php?page=';
var $_url_update = 'http://davereid.net/projects/wordpress/update.php';
var $_url_metrics = 'http://performancing.com/metrics/';
var $_url_api = 'http://performancing.com/perfstats/api.php';
// ------------------------------------------------------------------------
function PMetrics() {
$this->load_options();
$this->is_curl_enabled();
$this->_domain = $_SERVER['HTTP_HOST'];
$this->_url_options = ($this->is_admin_page() ? '' : 'wp-admin/') . $this->_url_options . basename(__FILE__);
$this->_url_metrics .= urlencode($this->_domain);
// Add hooks
add_action('admin_menu', array(&$this, 'add_admin_pages'));
add_action('wp_footer', array(&$this, 'get_code'));
// Options page style hook
if ($this->is_pmetrics_page()) {
add_action('admin_head', array(&$this, 'show_style'));
}
// Sidebar style hook
if ($this->get_option('sidebar_enabled')) {
add_action('wp_head', array(&$this, 'show_sidebar_style'));
add_action('plugins_loaded', array(&$this, 'register_widget'));
}
// Meta information hook
if ($this->get_option('meta')) {
add_action('wp_meta', array(&$this, 'do_meta'));
}
// Autoupdate hook for WordPress >= 2.0.2
if ($this->get_option('update_enabled') && version_compare(get_bloginfo('version'), '2.0.2', '>=')) {
add_action('admin_notices', array(&$this, 'do_update'), 10, 0);
}
}
// ------------------------------------------------------------------------
function add_admin_pages() {
// Add PMetrics options subpage
if (function_exists('add_options_page')) {
add_options_page('PMetrics Options', 'PMetrics', 8, basename(__FILE__), array(&$this, 'show_options_page'));
}
}
// ------------------------------------------------------------------------
function register_widget() {
if (function_exists('register_sidebar_widget')) {
register_sidebar_widget('PMetrics', array(&$this, 'do_widget'), 'pm_stats');
//register_widget_control('PMetrics', array(&$this, 'do_widget_options')/*, 300, 150*/);
}
}
// ------------------------------------------------------------------------
// OPTION FUNCTIONS
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
function load_options() {
//First use default values
$this->_options = array();
$this->_options['ignore_users'] = TRUE;
$this->_options['ignore_user_level'] = 8;
$this->_options['valid_code'] = TRUE;
$this->_options['update_enabled'] = $this->is_curl_enabled();
$this->_options['update_check_next'] = 0;
$this->_options['update_optout'] = FALSE;
$this->_options['update_version'] = 0;
$this->_options['account_username'] = '';
$this->_options['account_password'] = '';
$this->_options['account_auth'] = NULL;
$this->_options['sidebar_enabled'] = TRUE;
$this->_options['sidebar_title'] = 'Performancing Metrics';
$this->_options['sidebar_public'] = TRUE;
$this->_options['meta'] = FALSE;
$this->_options['stats'] = array();
// Then overwrite with stored vales, adding default values not already
// present in stored vales.
$stored_options = get_option('pmetrics_options');
if (is_array($stored_options)) {
foreach ($stored_options as $k => $v) {
if (array_key_exists($k, $this->_options)) {
$this->_options[$k] = $v;
}
}
} else {
update_option('pmetrics_options', $this->_options);
}
$this->reset_options_changed();
}
// ------------------------------------------------------------------------
function save_options() {
return update_option('pmetrics_options', $this->_options);
}
// ------------------------------------------------------------------------
function get_option($key) {
//$key = $this->std_option($key);
if (array_key_exists($key, $this->_options)) {
return $this->_options[$key];
}
return NULL;
}
// ------------------------------------------------------------------------
function set_option($key, $value) {
if (!isset($this->_options[$key]) || $this->_options[$key] !== $value) {
$this->_options[$key] = $value;
$this->_options_changed[$key] = TRUE;
}
}
// ------------------------------------------------------------------------
function reset_options_changed() {
$this->_options_changed = array();
}
// ------------------------------------------------------------------------
function is_option_changed($key) {
return (array_key_exists($key, $this->_options_changed));
}
// ------------------------------------------------------------------------
// OTHER FUNCTIONS
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
function is_curl_enabled() {
if (!isset($this->_curl_version)) {
if (extension_loaded('curl') && function_exists('curl_init') && function_exists('curl_version')) {
$ch = curl_init();
$curlv = curl_version();
curl_close($ch);
if (is_array($curlv)) {
$this->_curl_version = $curlv['version'];
} elseif (preg_match('/\\blibcurl[\\/ ]([\\d\\.]+)\\b/i', $curlv, $matches) > 0) {
$this->_curl_version = $matches[1];
} else {
$this->_curl_version = $curlv;
}
} else {
$this->_curl_version = FALSE;
}
}
return (bool) $this->_curl_version;
}
// ------------------------------------------------------------------------
function is_admin_page() {
return strpos(strtolower($_SERVER['SCRIPT_URI']), strtolower(get_settings('siteurl')) . '/wp-admin' !== FALSE);
}
// ------------------------------------------------------------------------
function is_pmetrics_page() {
return (isset($_GET['page']) && $_GET['page'] === basename(__FILE__));
//return (strpos(strtolower($_SERVER['REQUEST_URI']), strtolower('page=' . basename(__FILE__))) !== FALSE);
}
// ------------------------------------------------------------------------
function is_stats_shown() {
return ($this->get_option('sidebar_enabled') || $this->get_option('meta'));
}
// ------------------------------------------------------------------------
function is_widgets_enabled() {
return (function_exists('register_sidebar_widget'));
}
// ------------------------------------------------------------------------
function show_message($msg, $type = 'updated', $fade = TRUE) {
if ($type == 'error') $msg = '<strong>' . $msg . '</strong>';
echo '<div id="message" class="' . $type . ($fade ? ' fade' : '') . '">';
echo '<p>' . $msg . '</p></div>';
}
// ------------------------------------------------------------------------
function get_code($return = FALSE) {
$ignore = FALSE;
global $userdata;
//get_currentuserinfo();
if (isset($userdata) && $this->get_option('ignore_users') && $userdata->user_level > $this->get_option('ignore_user_level')) {
$ignore = TRUE;
}
$valid = $this->get_option('valid_code');
$code = '';
if ($ignore) {
$code .= "\n<!--\nIgnoring PMetrics tracking\n";
} else {
$code .= "\n<script type=\"text/javascript\">\n";
if ($valid) {
//$code .= "<!--//--><![CDATA[//><!--\n";
$code .= "//<![CDATA[\n";
} else {
$code .= "<!--\n";
}
}
if (!$ignore && isset($userdata)) {
$code .= "z_user_name=\"" . $userdata->user_login . "\";\n";
$code .= "z_user_email=\"" . $userdata->user_email . "\";\n";
}
$pm_category = '';
$pm_temp_title = trim(wp_title('', false));
if (is_home()) {
$pm_title = 'Homepage';
} elseif (is_archive()) {
$pm_title = 'Archives - ';
//$pm_category = 'Archives';
if (is_category()) {
$pm_title .= 'Category - ' . $pmetrics_temp_title;
//$pm_category .= ' - Category';
} elseif (is_author()) {
$pm_title .= 'Author - ' . $pmetrics_temp_title;
//$pm_category .= ' - Author';
} elseif (is_date()) {
$pm_title .= 'Date - ';
//$pm_category .= ' - Date';
if (is_day()) {
$pm_title .= the_date('F jS, Y', '', '', false);
} elseif (is_month()) {
$pm_title .= the_date('F, Y', '', '', false);
} elseif (is_year()) {
$pm_title .= the_date('Y', '', '', false);
}
} else {
$pm_title .= $pm_temp_title;
}
} elseif (function_exists('is_tag') && function_exists('UTW_ShowCurrentTagSet') && is_tag()) {
$pm_title .= 'Tag - ';
ob_start();
UTW_ShowCurrentTagSet('tagsettextonly');
$pm_title .= ob_get_contents();
ob_end_clean();
//$pm_category .= 'Tag';
} elseif (is_page()) {
$pm_title = 'Page - ' . $pm_temp_title;
//$pm_category = 'Page';
} elseif (is_search()) {
global $s;
$pm_title = 'Search - ' . $s; //htmlspecialchars?
//$pm_category = 'Search';
} elseif (is_404()) {
$pm_title = 'Error - 404';
//$pm_category = 'Error';
} elseif (is_single()) {
$c = get_the_category();
$pm_title = $pm_temp_title;
$pm_category = $c[0]->cat_name;
}
$code .= "z_post_title=\"" . $pm_title . "\";\n";
$code .= "z_post_category=\"" . $pm_category . "\";\n";
$code .= "z_plugin=\"pmetrics-" . $this->_version . "\";\n";
if ($ignore) {
$code .= "-->\n";
} else {
if ($valid) {
$code .= "//]]>\n";
//$code .= "//--><!]]>";
} else {
$code .= "-->\n";
}
$code .= "</script>\n";
if ($valid) {
$code .= "<img id=\"stats_script\" src=\"http://metrics.performancing.com/null\" width=\"0\" height=\"0\" style=\"display: none;\" alt=\"\" />\n";
}
$code .= "<script" . ($valid ? '' : ' id="stats_script"') . " type=\"text/javascript\" src=\"http://metrics.performancing.com/wp.js\"></script>\n";
}
// Return or output code
if ($return) {
return $output;
} else {
echo $code;
}
}
// ------------------------------------------------------------------------
// cURL Functions
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
function data_encode($data, $keyprefix = '', $keypostfix = '') {
assert(is_array($data));
$vars = null;
foreach ($data as $key => $value) {
if (is_array($value)) {
$vars .= $this->data_encode($value, $keyprefix . $key . $keypostfix . urlencode('['), urlencode(']'));
} else {
$vars .= $keyprefix . $key . $keypostfix . '=' . urlencode($value) . '&';
}
}
return substr($vars, 0, -1);
}
// ------------------------------------------------------------------------
function do_curl($url, $vars = NULL, $post = FALSE, $timeout = 10, $header = FALSE) {
if (!$this->is_curl_enabled()) {
return NULL;
}
// Initiate cURL and set options
$ch = curl_init();
//curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HEADER, $header);
// Encode data for POST or GET form, then set url
if (isset($vars) && !empty($vars)) {
$vars = $this->data_encode($vars);
if ($post) {
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
} else {
//curl_setopt($ch, CURLOPT_GET, TRUE);
$lastchr = substr($url, -1);
if ($lastchr === '?' || $lastchr === '&') {
$url .= $vars;
} elseif (strrchr($url, '?') === FALSE) {
$url .= '?' . $vars;
} else {
$url .= '&' . $vars;
}
}
}
curl_setopt($ch, CURLOPT_URL, $url);
// Execute cURL connection and grab all data, errors and info
$curl_data = array(
'content' => trim(curl_exec($ch)),
'errorno' => curl_errno($ch),
'error' => curl_error($ch),
'info' => curl_getinfo($ch),
);
// Close cURL connections and return collected data
curl_close($ch);
return $curl_data;
}
// ------------------------------------------------------------------------
function handle_curl_error(&$curl_data, $silent = FALSE) {
$msg = '';
if ($this->_curl_version === NULL || empty($curl_data) || !is_array($curl_data)) {
$msg = 'cURL must be enabled for this to work.';
} elseif ($curl_data['errorno'] != CURLE_OK) {
$msg = 'cURL Error ' . $curl_data['errorno'] . ': ' . $curl_data['error'];
} else {
return FALSE;
}
if (!$silent) $this->show_message($msg, 'error');
return TRUE;
}
// ------------------------------------------------------------------------
// API Stats Functions
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
function GetElementByName(&$xml, $start, $end) {
//global $pos;
$startpos = strpos($xml, $start);
if ($startpos === FALSE) {
return FALSE;
}
$endpos = strpos($xml, $end);
$endpos = $endpos + strlen($end);
//$pos = $endpos;
$endpos = $endpos - $startpos;
$endpos = $endpos - strlen($end);
$tag = substr($xml, $startpos, $endpos);
$tag = substr($tag, strlen($start));
return $tag;
}
// ------------------------------------------------------------------------
function handle_api_error(&$curl_data, $silent = TRUE) {
if ($this->handle_curl_error($curl_data, $silent)) {
return TRUE;
} elseif ($error = (int) $this->GetElementByName($curl_data['content'], '<error>', '</error>')) {
switch ($error) {
case 502:
$msg = 'Authentication of your Performancing Metrics account was denied. Please make sure that your entered username and password are correct.';
if (!$silent) $this->show_message($msg, 'error');
$this->set_option('account_auth', NULL);
$this->save_options();
break;
default:
$msg = 'An unknown error has occurred while authenticating your Performancing account.';
if (!$silent) $this->show_message($msg, 'error');
break;
}
return TRUE;
} else {
return FALSE;
}
}
// ------------------------------------------------------------------------
function do_api_auth($silent = TRUE) {
$auth = $this->get_option('account_auth');
if (empty($auth)) {
$params = array (
'action' => 'getauth',
'uid' => $this->get_option('account_username'),
'pwd' => $this->get_option('account_password'),
);
$curl_data = $this->do_curl($this->_url_api, $params);
if ($this->handle_api_error($curl_data, $silent)) {
return FALSE;
//$auth = NULL;
} else {
$auth = $this->GetElementByName($curl_data['content'], '<auth>', '</auth>');
//$uid = $this->GetElementByName($curl_data['content'], '<uid>', '</uid>');
$this->set_option('account_auth', $auth);
$this->save_options();
}
}
return $auth;
}
// ------------------------------------------------------------------------
function get_api_data($date, $type, $d1 = NULL, $d2 = NULL) {
$type_values = array(
'visits' => 'getvisitorstats',
'posts' => 'getpoststats',
'refs' => 'getrefstats',
'outbound' => 'getoutboundstats',
);
assert(isset($type_values[$type]));
$this->do_api_auth();
$params = array (
'auth' => $this->get_option('account_auth'),
'blog_domain' => $this->_domain,
'action' => $type_values[$type],
);
if ($date === 'total') {
$params['m'] = 'date_range';
$params['d1'] = '2000-01-01';
$params['d2'] = '2020-01-01';
} elseif ($date !== 'custom') {
$params['m'] = $date;
} else {
$params['m'] = (empty($d2) ? 'single_date' : 'date_range');
$params['d1'] = $d1;
if (!empty($d2)) $params['d2'] = $d2;
}
$curl_data = $this->do_curl($this->_url_api, $params);
if ($this->handle_api_error($curl_data, TRUE)) {
return NULL;
} else {
return $this->parse_api_data($curl_data['content'], $type);
}
}
// ------------------------------------------------------------------------
function parse_api_data($data, $type) {
$temp = array();
switch ($type) {
case 'visits':
$temp['visits'] = $this->GetElementByName($data, '<Visits>', '</Visits>');
$temp['visits_average_per_day'] = $this->GetElementByName($data, '<AverageVisitsPerDay>', '</AverageVisitsPerDay>');
$temp['visits_average_length'] = $this->GetElementByName($data, '<AverageVisitLength>', '</AverageVisitLength>');
$temp['visists_repeat'] = $this->GetElementByName($data, '<RepeatVisitors>', '</RepeatVisitors>');
//$stats['visits_chart'] = $this->GetElementByName($data, '<ChartURL>', '</ChartURL>');
break;
case 'posts':
break;
case 'refs':
break;
case 'outbound':
break;
default:
$temp = NULL;
}
return $temp;
}
// ------------------------------------------------------------------------
function fetch_stats($force = FALSE, $date = 'all', $type = 'all', $d1 = NULL, $d2 = NULL) {
$time = time();
$time_parts = getdate($time);
$date_values = array(
'today' => strtotime('+15 minutes', $time),
'yesterday' => mktime(0, 0, 0, $time_parts['mon'], $time_parts['mday'] + 1),
'this_week' => strtotime('+15 minutes', $time),
'last_week' => strtotime('next Sunday', $time),
'this_month' => strtotime('+15 minutes', $time),
'last_month' => mktime(0, 0, 0, $time_parts['mon'] + 1),
'total' => strtotime('+15 minutes', $time),
//'custom' => NULL,
);
$type_values = array('visits', /*'posts', 'refs', 'outbound'*/);
$stats =& $this->get_option('stats');
$this->check_stats_expired($stats, $time);
$new_stats = array();
foreach($date_values as $d => $k) {
if (($date == 'all' && $d != 'custom') || $date == $d || (is_array($date) && in_array($d, $date))) {
foreach($type_values as $t) {
if ($type == 'all' || $type == $t || (is_array($type) && in_array($t, $type))) {
if (!$force && isset($stats[$d])) {
$new_stats[$d] = $stats[$d];
} else {
$api_data = $this->get_api_data($d, $t);
if (empty($api_data)) {
return NULL;
}
$new_stats[$d] = $api_data;
$new_stats[$d]['expires'] = $date_values[$d];
$new_stats[$d]['fetched'] = $time;
$stats[$d] = $new_stats[$d];
}
}
}
}
}
//ksort($stats);
$this->set_option('stats', $stats);
$this->save_options();
return $new_stats;
}
// ------------------------------------------------------------------------
function get_stats($date = 'today', $type = 'visits', $d1 = NULL, $d2 = NULL) {
$stats = $this->fetch_stats(FALSE, $date, $type, $d1, $d2);
if ($date == 'all') {
return $stats;
} else {
return $stats[$date];
}
}
// ------------------------------------------------------------------------
function check_stats_expired(&$stats, $time) {
assert(is_array($stats));
foreach($stats as $stats_type => $stats_value) {
if (isset($stats_value['expires']) && $time > $stats_value['expires']) {
unset($stats[$stats_type]);
}
}
}
// ------------------------------------------------------------------------
// UPDATE & AUTOUPDATE
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
function get_update_data() {
$data = array (
'plugin' => $this->_name,
'version' => $this->_version,
);
// If the users has opted out of detailed information, do not include
if (!$this->get_option('update_optout')) {
$data['wordpress'] = get_bloginfo('version');
//$data['blog'] = get_bloginfo('name');
$data['url'] = get_bloginfo('url');
$data['php'] = PHP_VERSION; //phpversion();
$data['curl'] = $this->_curl_version;
$data['server'] = $_SERVER['SERVER_SOFTWARE'];
//$data['auth'] = $this->get_option('account_auth');
}
return $data;
}
// ------------------------------------------------------------------------
function do_update($auto_update = TRUE, $silent = FALSE) {
assert(!$auto_update || ($auto_update && $this->get_option('update_enabled')));
// If using the auto update and it's not been one week since the last
// update check, return the cached latest version.
if ($auto_update && time() < $this->get_option('update_check_next')) {
return $this->get_option('update_version');
}
// Get the latest version from the update server through cURL
$version = $this->_version;
$curl_data = $this->do_curl($this->_url_update, $this->get_update_data(), TRUE);
if ($this->handle_curl_error($curl_data)) {
$version = NULL;
} else {
$version = trim($curl_data['content']);
}
if (empty($version)) {
$msg = 'Error performing update check (probably server error).';
if (!$auto_update && !$silent) $this->show_message($msg);
$version = NULL;
}
// If using the auto update, increment the next update time to one week
// and cache the version
if ($this->get_option('update_enabled')) {
$this->set_option('update_check_next', strtotime('+1 week'));
$this->set_option('update_version', $version);
$this->