1
0
Fork 0

some doc and cleanup stuff

Dieser Commit ist enthalten in:
oldperl 2011-12-17 15:26:24 +00:00
Ursprung e400b059d8
Commit b90587fef1
3 geänderte Dateien mit 271 neuen und 225 gelöschten Zeilen

Datei anzeigen

@ -10,189 +10,188 @@ Plugin URI: https://github.com/meglio/wp-upgrademe
if (!class_exists('Upgrademe')) { if (!class_exists('Upgrademe')) {
class Upgrademe class Upgrademe {
{ /**
/** * Stores parsed and validated data returned by unofficial APIs.
* Stores parsed and validated data returned by unofficial APIs. * @var array
* @var array */
*/ private static $data;
private static $data;
private static $WP_FILTER_PREFIX = 'wpFilter_'; private static $WP_FILTER_PREFIX = 'wpFilter_';
public static function register() public static function register()
{ {
$r = new ReflectionClass(__CLASS__); $r = new ReflectionClass(__CLASS__);
$methods = $r->getMethods(ReflectionMethod::IS_PUBLIC); $methods = $r->getMethods(ReflectionMethod::IS_PUBLIC);
foreach($methods as $m) foreach($methods as $m)
{ {
/** @var ReflectionMethod $m */ /** @var ReflectionMethod $m */
if ($m->isStatic() && strpos($m->getName(), self::$WP_FILTER_PREFIX) === 0) { if ($m->isStatic() && strpos($m->getName(), self::$WP_FILTER_PREFIX) === 0) {
add_filter(substr($m->getName(), strlen(self::$WP_FILTER_PREFIX)), array(get_class(), $m->getName()), add_filter(substr($m->getName(), strlen(self::$WP_FILTER_PREFIX)), array(get_class(), $m->getName()),
10, $m->getNumberOfParameters()); 10, $m->getNumberOfParameters());
} }
} }
} }
public static function wpFilter_http_response($response, $args, $url) public static function wpFilter_http_response($response, $args, $url)
{ {
# Control recursion # Control recursion
static $recursion = false; static $recursion = false;
if ($recursion) if ($recursion)
return $response; return $response;
if (empty($response) || !is_array($response) || !isset($response['body'])) if (empty($response) || !is_array($response) || !isset($response['body']))
return $response; return $response;
# Guess if it's time to take action # Guess if it's time to take action
if ($url == 'http://api.wordpress.org/plugins/update-check/1.0/') if ($url == 'http://api.wordpress.org/plugins/update-check/1.0/')
$showTime = true; $showTime = true;
# Prevent failures if WordPress changes url for updates; we will detect if it still contains "update-check" token # Prevent failures if WordPress changes url for updates; we will detect if it still contains "update-check" token
# and called from withing wp_update_plugins() function # and called from withing wp_update_plugins() function
elseif (stripos($url, 'update-check') !== false) elseif (stripos($url, 'update-check') !== false)
{ {
$showTime = false; $showTime = false;
$trace = debug_backtrace(false); $trace = debug_backtrace(false);
foreach($trace as $t) foreach($trace as $t)
# http request made from within wp_update_plugins # http request made from within wp_update_plugins
if (isset($t['function']) && $t['function'] == 'wp_update_plugins') if (isset($t['function']) && $t['function'] == 'wp_update_plugins')
{ {
$showTime = true; $showTime = true;
break; break;
} }
unset($trace, $t); unset($trace, $t);
} }
else else
$showTime = false; $showTime = false;
if (!$showTime) if (!$showTime)
return $response; return $response;
# Loop over plugins who provided <pluginName>_upgrademe() function and use returned url to request for up-to-date version signature. # Loop over plugins who provided <pluginName>_upgrademe() function and use returned url to request for up-to-date version signature.
# Collect retrieved (only valid) data into $upgrademe # Collect retrieved (only valid) data into $upgrademe
$plugins = get_plugins(); $plugins = get_plugins();
$upgrademe = array(); $upgrademe = array();
foreach($plugins as $file => $info) foreach($plugins as $file => $info)
{ {
# Get url if function exists # Get url if function exists
$slugName = str_replace('-', '_', basename($file, '.php')); $slugName = str_replace('-', '_', basename($file, '.php'));
# Request latest version signature from custom url (non-WP plugins repository api) && validate response variables # Request latest version signature from custom url (non-WP plugins repository api) && validate response variables
$recursion = true; $recursion = true;
$vars = self::loadPluginData($slugName); $vars = self::loadPluginData($slugName);
$recursion = false; $recursion = false;
if (empty($vars)) if (empty($vars))
continue; continue;
$upgrademe[$file] = $vars; $upgrademe[$file] = $vars;
} }
if (!count($upgrademe)) if (!count($upgrademe))
return $response; return $response;
$body = $response['body']; $body = $response['body'];
if (!empty($body)) if (!empty($body))
$body = unserialize($body); $body = unserialize($body);
if (empty($body)) if (empty($body))
$body = array(); $body = array();
foreach($upgrademe as $file => $upgradeVars) foreach($upgrademe as $file => $upgradeVars)
{ {
# Do not override data returned by official WP plugins repository API # Do not override data returned by official WP plugins repository API
if (isset($body[$file])) if (isset($body[$file]))
continue; continue;
# If new version is different then current one, only then add info # If new version is different then current one, only then add info
if (!isset($plugins[$file]['Version']) || $plugins[$file]['Version'] == $upgradeVars['new_version']) if (!isset($plugins[$file]['Version']) || $plugins[$file]['Version'] == $upgradeVars['new_version'])
continue; continue;
$upgradeInfo = new stdClass(); $upgradeInfo = new stdClass();
$upgradeInfo->id = $upgradeVars['id']; $upgradeInfo->id = $upgradeVars['id'];
$upgradeInfo->slug = $upgradeVars['slug']; $upgradeInfo->slug = $upgradeVars['slug'];
$upgradeInfo->new_version = $upgradeVars['new_version']; $upgradeInfo->new_version = $upgradeVars['new_version'];
$upgradeInfo->url = $upgradeVars['url']; $upgradeInfo->url = $upgradeVars['url'];
$upgradeInfo->package = $upgradeVars['package']; $upgradeInfo->package = $upgradeVars['package'];
$body[$file] = $upgradeInfo; $body[$file] = $upgradeInfo;
} }
$response['body'] = serialize($body); $response['body'] = serialize($body);
return $response; return $response;
} }
public static function wpFilter_plugins_api($value, $action, $args) public static function wpFilter_plugins_api($value, $action, $args)
{ {
// If for some reason value available already, do not change it // If for some reason value available already, do not change it
if (!empty($value)) if (!empty($value))
return $value; return $value;
if ($action != 'plugin_information' || !is_object($args) || !isset($args->slug) || empty($args->slug)) if ($action != 'plugin_information' || !is_object($args) || !isset($args->slug) || empty($args->slug))
return $value; return $value;
$vars = self::loadPluginData($args->slug); $vars = self::loadPluginData($args->slug);
if (empty($vars)) if (empty($vars))
return $value; return $value;
return (object)$vars['info']; return (object)$vars['info'];
} }
public static function wpFilter_http_request_args($args, $url) public static function wpFilter_http_request_args($args, $url)
{ {
if (strpos($url, 'wp-upgrademe') === false || !is_array($args)) if (strpos($url, 'wp-upgrademe') === false || !is_array($args))
return $args; return $args;
$args['sslverify'] = false; $args['sslverify'] = false;
return $args; return $args;
} }
private static function loadPluginData($slug) private static function loadPluginData($slug)
{ {
if (isset(self::$data[$slug])) if (isset(self::$data[$slug]))
return self::$data[$slug]; return self::$data[$slug];
$funcName = $slug.'_upgrademe'; $funcName = $slug.'_upgrademe';
if (!function_exists($funcName)) if (!function_exists($funcName))
return self::$data[$slug] = null; return self::$data[$slug] = null;
$upgradeUrl = filter_var(call_user_func($funcName), FILTER_VALIDATE_URL); $upgradeUrl = filter_var(call_user_func($funcName), FILTER_VALIDATE_URL);
if (empty($upgradeUrl)) if (empty($upgradeUrl))
return self::$data[$slug] = null; return self::$data[$slug] = null;
# Request latest version signature from custom url (non-WP plugins repository api) && validate response variables # Request latest version signature from custom url (non-WP plugins repository api) && validate response variables
$r = wp_remote_post($upgradeUrl, array('method' => 'POST', 'timeout' => 4, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, $r = wp_remote_post($upgradeUrl, array('method' => 'POST', 'timeout' => 4, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true,
'headers' => array(), 'body' => null, 'cookies' => array(), 'sslverify' => false)); 'headers' => array(), 'body' => null, 'cookies' => array(), 'sslverify' => false));
if( is_wp_error($r) || !isset($r['body']) || empty($r['body'])) if( is_wp_error($r) || !isset($r['body']) || empty($r['body']))
return self::$data[$slug] = null; return self::$data[$slug] = null;
$vars = json_decode($r['body'], true); $vars = json_decode($r['body'], true);
if (empty($vars) || !is_array($vars) || count($vars) > 4 if (empty($vars) || !is_array($vars) || count($vars) > 4
|| !isset($vars['new_version']) || !isset($vars['url']) || !isset($vars['package']) || !isset($vars['info'])) || !isset($vars['new_version']) || !isset($vars['url']) || !isset($vars['package']) || !isset($vars['info']))
return self::$data[$slug] = null; return self::$data[$slug] = null;
# 2 147 483 648 - max int32 # 2 147 483 648 - max int32
# 16 777 215 - ffffff = max possible value of 6-letters hex # 16 777 215 - ffffff = max possible value of 6-letters hex
# 50 000 000 - reasonable offset # 50 000 000 - reasonable offset
# Finally generate ID between 50 000 000 and 66 777 215 # Finally generate ID between 50 000 000 and 66 777 215
$vars['id'] = 50000000 + hexdec(substr(md5($slug), 1, 6)); $vars['id'] = 50000000 + hexdec(substr(md5($slug), 1, 6));
$vars['slug'] = $slug; $vars['slug'] = $slug;
# Sanitize variables of "info" # Sanitize variables of "info"
if (!is_array($vars['info'])) if (!is_array($vars['info']))
$vars['info'] = array(); $vars['info'] = array();
$info = array(); $info = array();
foreach($vars['info'] as $key => $val) foreach($vars['info'] as $key => $val)
{ {
if (!in_array($key, array('name','slug','version','author','author_profile','contributors','requires','tested', if (!in_array($key, array('name','slug','version','author','author_profile','contributors','requires','tested',
'compatibility','rating','rating','num_ratings','downloaded','last_updated','added','homepage', 'compatibility','rating','rating','num_ratings','downloaded','last_updated','added','homepage',
'sections','download_link','tags'))) 'sections','download_link','tags')))
continue; continue;
$info[$key] = $val; $info[$key] = $val;
} }
$info['slug'] = $slug; $info['slug'] = $slug;
$info['version'] = $vars['new_version']; $info['version'] = $vars['new_version'];
$info['download_link'] = $vars['url']; $info['download_link'] = $vars['url'];
$vars['info'] = $info; $vars['info'] = $info;
return self::$data[$slug] = $vars; return self::$data[$slug] = $vars;
} }
} }
Upgrademe::register(); Upgrademe::register();
} # class_exists() } # class_exists()

Datei anzeigen

@ -4,7 +4,7 @@
* *
* @package SemmelstatzR * @package SemmelstatzR
* @version $Rev$ * @version $Rev$
* @since 1.0.0 Beta * @since 1.0.0
* @author SEM-Team * @author SEM-Team
* @copyright (c)2011 SEM-Team * @copyright (c)2011 SEM-Team
* @link http://sourceforge.net/projects/semmelstatz/ * @link http://sourceforge.net/projects/semmelstatz/
@ -69,7 +69,7 @@
} }
} }
### Auslesen der höchsten Post-ID ### Auslesen der h<EFBFBD>chsten Post-ID
function sem_getMaxPostID() { function sem_getMaxPostID() {
global $wpdb; global $wpdb;
$maxpostid = $wpdb->get_var("SELECT MAX(ID) FROM ".$wpdb->posts." LIMIT 0,1"); $maxpostid = $wpdb->get_var("SELECT MAX(ID) FROM ".$wpdb->posts." LIMIT 0,1");
@ -117,7 +117,12 @@ function sem_AreYouBot($user_agent) {
return $oCheckAgent->isBot(); return $oCheckAgent->isBot();
} }
### Referer nach Suchmaschinen-Queries und interner Suche prüfen und Suchstring extrahieren /**
* Referer nach Suchmaschinen-Queries und interner Suche prüfen und Suchstring extrahieren
*
* @param string $referer
* @return string name of searchengine and keywords
*/
function sem_getKeyword($referer) { function sem_getKeyword($referer) {
if(empty($referer)) return false; if(empty($referer)) return false;
$homehost = '%'.(substr($_SERVER['SERVER_NAME'],0,4) == 'www.')? $homehost = '%'.(substr($_SERVER['SERVER_NAME'],0,4) == 'www.')?
@ -221,14 +226,14 @@ function sem_getKeyword($referer) {
elseif (preg_match("/".$homehost."/i", $keyword["host"])) { elseif (preg_match("/".$homehost."/i", $keyword["host"])) {
parse_str($keyword["query"],$q); parse_str($keyword["query"],$q);
$keyword = $q["s"]; $keyword = $q["s"];
if($keyword == "") return; return "Interne Suche: ".$keyword; if($keyword == "") return; return semr_i18n("Internal search: ").$keyword;
} }
else { else {
return; return;
} }
} }
### Anzahl der Datensätze in der statz-Tabelle ### Anzahl der Datens<EFBFBD>tze in der statz-Tabelle
function sem_showNumStatzEntries() { function sem_showNumStatzEntries() {
global $wpdb; global $wpdb;
$numstatzentries = $wpdb->get_var("SELECT COUNT(id) FROM ".$wpdb->statz); $numstatzentries = $wpdb->get_var("SELECT COUNT(id) FROM ".$wpdb->statz);
@ -259,27 +264,41 @@ function sem_getKeyword($referer) {
} }
} }
### Zeigt Copyright-Notiz an /**
function sem_showCopyright() { * prints a copyright notiz
print "<p class='copyright'>semmelstatzR ". SEMMELSTATZR_VERSION . " happily coded by <a target='_blank' href='http://semmelstatz.sourceforge.net/'>SEM-Team<br /> */
<a target='_blank' style='border:none;' href='http://sourceforge.net/projects/semmelstatz/'> function sem_showCopyright() {
<img src='".get_option('siteurl')."/wp-content/plugins/semmelstatzR/img/statzR.png' /></a></p>"; print "<p class='copyright'>semmelstatzR ". SEMMELSTATZR_VERSION .
} " happily coded by <a target='_blank' href='http://semmelstatz.sourceforge.net/'>SEM-Team<br />
<a target='_blank' style='border:none;' href='http://sourceforge.net/projects/semmelstatz/'>
### statz-Tabelle leeren (NICHT LÖSCHEN!!!) <img src='".get_option('siteurl')."/wp-content/plugins/semmelstatzR/img/statzR.png' /></a></p>";
function sem_truncateStatzTable() {
global $wpdb, $userip;
$wpdb->query('TRUNCATE TABLE '.$wpdb->statz);
sem_optStatzTable();
return $wpdb->query("INSERT INTO `$wpdb->statz`(ip, time, referer, page, username) VALUES('127.0.0.1', NOW(),NULL,0,'statz-Tabelle geleert')");
} }
### Obsolet, bleibt aber aus Kompatibilitätsgründen zu SEMMELSTATZ_DELETE /**
function sem_delOldRecords($days) { * empty statz table
return true; *
} * @global type $wpdb
* @return bool
*/
function sem_truncateStatzTable() {
global $wpdb;
$wpdb->query('TRUNCATE TABLE '.$wpdb->statz);
sem_optStatzTable();
return ($wpdb->query("INSERT INTO `$wpdb->statz`(ip, time, referer, page, username) VALUES('127.0.0.1', NOW(),NULL,0,'statz-Tabelle geleert')"))?true:false;
}
### simpleEncoding für die GoogleChartAPI /**
*
* @deprecated no need to hold unused functions in semR
* @todo remove in next major release
* @param int $days
* @return boolean
*/
function sem_delOldRecords($days) {
return true;
}
### simpleEncoding f<>r die GoogleChartAPI
function sem_encodeChartData($values) { function sem_encodeChartData($values) {
$maxValue = max($values); $maxValue = max($values);
@ -298,7 +317,7 @@ function sem_truncateStatzTable() {
return $chartData; return $chartData;
} }
### Datensätze älter als statz_recdays_limit-Tage löschen ### Datens<EFBFBD>tze <20>lter als statz_recdays_limit-Tage l<>schen
function sem_delOutOfLimit() { function sem_delOutOfLimit() {
global $wpdb; global $wpdb;
$sem_options = get_option('semmelstatzR_options'); ### optionsarray auslesen $sem_options = get_option('semmelstatzR_options'); ### optionsarray auslesen
@ -309,7 +328,7 @@ function sem_truncateStatzTable() {
sem_optStatzTable(); sem_optStatzTable();
} }
### Wenn AUTOMATISCHES LIMIT aktiviert, dann LIMITIERE und erhöhe NEXT_CRON ### Wenn AUTOMATISCHES LIMIT aktiviert, dann LIMITIERE und erh<EFBFBD>he NEXT_CRON
function sem_doCronStatzLimit() { function sem_doCronStatzLimit() {
sem_delOutOfLimit(); sem_delOutOfLimit();
$sem_options = get_option('semmelstatzR_options'); ### optionsarray auslesen $sem_options = get_option('semmelstatzR_options'); ### optionsarray auslesen
@ -330,32 +349,36 @@ function sem_truncateStatzTable() {
} }
### Unter bestimmten Voraussetzungen den Vortag in die statzhist-Tabelle schreiben ### Unter bestimmten Voraussetzungen den Vortag in die statzhist-Tabelle schreiben
function sem_writeYesterdayToHist() { /**
global $wpdb; * @todo add action cache so we don't need to do it with every call
if(!$wpdb->get_var("SELECT date FROM ".$wpdb->statzhist." WHERE substring(date,1,10) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)")) { * @global type $wpdb
*/
function sem_writeYesterdayToHist() {
global $wpdb;
if(!$wpdb->get_var("SELECT date FROM ".$wpdb->statzhist." WHERE substring(date,1,10) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)")) {
if($wpdb->get_var("SELECT COUNT(ip) FROM ".$wpdb->statz." WHERE substring(time,1,10) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)")) { if($wpdb->get_var("SELECT COUNT(ip) FROM ".$wpdb->statz." WHERE substring(time,1,10) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)")) {
$yesterdays = $wpdb->get_results("SELECT COUNT(ip) AS hits, COUNT(DISTINCT ip) AS visitors, COUNT(DISTINCT referer) $yesterdays = $wpdb->get_results("SELECT COUNT(ip) AS hits, COUNT(DISTINCT ip) AS visitors, COUNT(DISTINCT referer)
AS referers, substring(time,1,10) AS date FROM ".$wpdb->statz." WHERE substring(time,1,10) = DATE_SUB(CURDATE(), AS referers, substring(time,1,10) AS date FROM ".$wpdb->statz." WHERE substring(time,1,10) = DATE_SUB(CURDATE(),
INTERVAL 1 DAY) GROUP BY date"); INTERVAL 1 DAY) GROUP BY date");
foreach ($yesterdays as $yesterday) { foreach ($yesterdays as $yesterday) {
$date = $yesterday->date; $date = $yesterday->date;
$visitors = $yesterday->visitors; $visitors = $yesterday->visitors;
$hits = $yesterday->hits; $hits = $yesterday->hits;
$referers = $yesterday->referers; $referers = $yesterday->referers;
}
$sql = $wpdb->query("INSERT INTO ".$wpdb->statzhist." (date, referers, visitors, hits)
VALUES('$date', $referers, $visitors, $hits)");
}
else {
$date = $wpdb->get_var("SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY)");
$sql = $wpdb->query("INSERT INTO ".$wpdb->statzhist." (date, referers, visitors, hits) VALUES('$date', 0, 0, 0)");
} }
$sql = $wpdb->query("INSERT INTO ".$wpdb->statzhist." (date, referers, visitors, hits)
VALUES('$date', $referers, $visitors, $hits)");
}
else {
$date = $wpdb->get_var("SELECT DATE_SUB(CURDATE(), INTERVAL 1 DAY)");
$sql = $wpdb->query("INSERT INTO ".$wpdb->statzhist." (date, referers, visitors, hits) VALUES('$date', 0, 0, 0)");
} }
} }
}
/* Summen der vergangenen Tage in die statzhist schreiben */ /* Summen der vergangenen Tage in die statzhist schreiben */
function sem_writeOldDaysToHist() { function sem_writeOldDaysToHist() {
@ -378,8 +401,11 @@ function sem_truncateStatzTable() {
} }
/** /**
* translate and return a string * translate and return a string
*
* @uses wp-function __() and prefilled plugin gettextdomain * @uses wp-function __() and prefilled plugin gettextdomain
* @author Ortwin Pinke
* @since 1.0.0
* *
* @param string $sValue string to translate * @param string $sValue string to translate
* @param string $sDomain gettextdomain * @param string $sDomain gettextdomain
@ -391,7 +417,10 @@ function semr_i18n($sValue, $sDomain = "semmelstatzR") {
/** /**
* translate and echo a string * translate and echo a string
*
* @uses wp-function _e() and prefilled plugin gettextdomain * @uses wp-function _e() and prefilled plugin gettextdomain
* @author Ortwin Pinke
* @since 1.0.0
* *
* @param string $sValue * @param string $sValue
* @param string $sDomain * @param string $sDomain
@ -403,7 +432,10 @@ function semr_i18ne($sValue, $sDomain = "semmelstatzR") {
/** /**
* translate and return a plural or singular string based on an amount * translate and return a plural or singular string based on an amount
*
* @uses wp-function _n() and prefilled plugin gettextdomain * @uses wp-function _n() and prefilled plugin gettextdomain
* @author Ortwin Pinke
* @since 1.0.0
* *
* @param string $sSingular * @param string $sSingular
* @param string $sPlural * @param string $sPlural
@ -418,8 +450,9 @@ function semr_i18np($sSingular, $sPlural, $iNumber, $sDomain = "semmelstatzR") {
/** /**
* *
* @author anyexample.com * @author anyexample.com
* @license http://www.anyexample.com/license/ * @license modified MIT see http://www.anyexample.com/license/
* @link http://www.anyexample.com/programming/php/php_convert_rgb_from_to_html_hex_color.xml * @link http://www.anyexample.com/programming/php/php_convert_rgb_from_to_html_hex_color.xml
* @since 1.0.0
* *
* @param string $color * @param string $color
* @return array * @return array
@ -445,8 +478,9 @@ function semr_hex2rgb($color) {
/** /**
* *
* @author anyexample.com * @author anyexample.com
* @license http://www.anyexample.com/license/ * @license modified MIT see http://www.anyexample.com/license/
* @link http://www.anyexample.com/programming/php/php_convert_rgb_from_to_html_hex_color.xml * @link http://www.anyexample.com/programming/php/php_convert_rgb_from_to_html_hex_color.xml
* @since 1.0.0
* *
* @param int $r * @param int $r
* @param int $g * @param int $g

Datei anzeigen

@ -3,7 +3,7 @@
Plugin Name: semmelstatzR Plugin Name: semmelstatzR
Plugin URI: http://sourceforge.net/projects/semmelstatz/ Plugin URI: http://sourceforge.net/projects/semmelstatz/
Description: Visitorstatistic for Wordpress, based upon the original wp-plugin semmelstatz by Andreas 'Redunzl' Mueller (http://www.kopfhoch-studio.de) Description: Visitorstatistic for Wordpress, based upon the original wp-plugin semmelstatz by Andreas 'Redunzl' Mueller (http://www.kopfhoch-studio.de)
Version: 1.0.0 Beta Version: 1.0 RC
Author: SEM-Team Author: SEM-Team
Author URI: http://semmelstatz.sf.net Author URI: http://semmelstatz.sf.net
License: GPLv3 License: GPLv3
@ -16,7 +16,7 @@ License URI: http://www.gnu.org/licenses/gpl-3.0.html
* @version $Rev$ * @version $Rev$
* @since 1.0.0 Beta * @since 1.0.0 Beta
* @author SEM-Team * @author SEM-Team
* @copyright (c)2011 SEM-Team * @copyright (c)2011-2012 SEM-Team
* @link http://sourceforge.net/projects/semmelstatz/ * @link http://sourceforge.net/projects/semmelstatz/
* @license http://www.gnu.org/licenses/gpl-3.0.html * @license http://www.gnu.org/licenses/gpl-3.0.html
* *
@ -128,7 +128,7 @@ if(is_admin() == true) {
global $wpdb; global $wpdb;
if(get_option('statz_options')) { if(get_option('statz_options')) {
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'statz%';"); // Löschen der alten Optionen $wpdb->query("DELETE FROM $wpdb->options WHERE option_name LIKE 'statz%';"); // L<EFBFBD>schen der alten Optionen
} }
if(!get_option('semmelstatzR_options')) { if(!get_option('semmelstatzR_options')) {
@ -156,7 +156,7 @@ if(is_admin() == true) {
"statz_topreads_limit" => 10, "statz_topreads_limit" => 10,
"statz_write_admins" => false, "statz_write_admins" => false,
"statz_write_users" => false, "statz_write_users" => false,
"statz_use_img" => true "statz_use_img" => false
); );
add_option( 'semmelstatzR_options', $sem_options ); add_option( 'semmelstatzR_options', $sem_options );
} }
@ -175,7 +175,7 @@ function sem_statzsetup() {
} elseif(@is_file(ABSPATH.'/wp-admin/includes/upgrade.php')) { } elseif(@is_file(ABSPATH.'/wp-admin/includes/upgrade.php')) {
include_once(ABSPATH.'/wp-admin/includes/upgrade.php'); include_once(ABSPATH.'/wp-admin/includes/upgrade.php');
} else { } else {
die('Kann <i>wp-admin/upgrade-functions.php</i> und <i>wp-admin/includes/upgrade.php</i> nicht finden!'); die(semr_i18n('Cannot find <i>wp-admin/upgrade-functions.php</i> and <i>wp-admin/includes/upgrade.php</i>!'));
} }
$create_table = array(); $create_table = array();
@ -228,9 +228,9 @@ function sem_writeStatz() {
// true === $sem_options['statz_use_img'] && // true === $sem_options['statz_use_img'] &&
if(true == $sem_options['statz_use_img'] && !defined('SEMMELSTATZR_STATZIMG')) { if(true == $sem_options['statz_use_img'] && !defined('SEMMELSTATZR_STATZIMG')) {
print '<img src="'.SEMMELSTATZR_HTML_RELPATH.'semr_image.php" alt="" />'; print '<img src="'.SEMMELSTATZR_HTML_RELPATH.'semr_image.php" alt="" />';
return; ### nothing todo if stat image is used return; ### nothing else todo if stat image is used
} }
sem_writeYesterdayToHist(); sem_writeYesterdayToHist();
$useragent = $wpdb->escape($_SERVER['HTTP_USER_AGENT']); $useragent = $wpdb->escape($_SERVER['HTTP_USER_AGENT']);
$isBot = sem_AreYouBot($useragent); $isBot = sem_AreYouBot($useragent);
@ -244,17 +244,16 @@ function sem_writeStatz() {
$userip = $wpdb->escape($_SERVER['REMOTE_ADDR']); $userip = $wpdb->escape($_SERVER['REMOTE_ADDR']);
if($sem_options['statz_encode_ip'] == true) $userip = sem_encodeIP($userip); if($sem_options['statz_encode_ip'] == true) $userip = sem_encodeIP($userip);
$referer = $wpdb->escape(urldecode($_SERVER['HTTP_REFERER'])); $referer = $wpdb->escape(urldecode($_SERVER['HTTP_REFERER']));
$blogtime = gmdate('Y-m-d H:i:s', current_time('timestamp')); $blogtime = gmdate('Y-m-d H:i:s', current_time('timestamp'));
if (!empty($referer)) { if (!empty($referer)) {
if(get_option('blog_charset') == 'iso-8859-1') $referer = utf8_decode($referer); if(get_option('blog_charset') == 'iso-8859-1') $referer = utf8_decode($referer);
$referer = "'".$referer."'"; $referer = "'".$referer."'";
} else {
$referer = 'NULL';
} }
else {
$referer = 'NULL';
}
$readingnow = wp_title('', false); $readingnow = wp_title('', false);
if(empty($readingnow)) { if(empty($readingnow)) {
@ -262,9 +261,9 @@ $referer = 'NULL';
} else { } else {
$page = $wp_query->post->ID; $page = $wp_query->post->ID;
} }
$wpdb->query("INSERT INTO $wpdb->statz (ip, time, referer, page, username) $wpdb->query("INSERT INTO $wpdb->statz (ip, time, referer, page, username)
VALUES('$userip', '$blogtime', $referer, $page, '$username')"); VALUES('$userip', '$blogtime', $referer, $page, '$username')");
if($wpdb->query("SELECT COUNT(hits) FROM $wpdb->posts")) { if($wpdb->query("SELECT COUNT(hits) FROM $wpdb->posts")) {
$wpdb->query("UPDATE $wpdb->posts SET hits = hits + 1 WHERE ID = $page"); // neu ab 3.2 $wpdb->query("UPDATE $wpdb->posts SET hits = hits + 1 WHERE ID = $page"); // neu ab 3.2
@ -272,13 +271,19 @@ $wpdb->query("INSERT INTO $wpdb->statz (ip, time, referer, page, username)
} }
### Zeitgesteuertes Limitieren der statz-Tabelle ### Zeitgesteuertes Limitieren der statz-Tabelle
// Wenn semmelKron JA UND statz_next_cron älter JETZT, dann... // @todo add action cache
$sem_options = get_option('semmelstatzR_options'); ### optionsarray auslesen // Wenn semmelKron JA UND statz_next_cron älter JETZT, dann...
if($sem_options['statz_do_cron'] == true && $sem_options['statz_next_cron'] < time()) { $sem_options = get_option('semmelstatzR_options'); ### optionsarray auslesen
add_action('shutdown', 'sem_doCronStatzLimit'); // ...limitiere statz-Tabelle auf vorgegebenen Wert if($sem_options['statz_do_cron'] == true && $sem_options['statz_next_cron'] < time()) {
} add_action('shutdown', 'sem_doCronStatzLimit'); // ...limitiere statz-Tabelle auf vorgegebenen Wert
}
### Rendert eine Mini-STATZ. Idee: René Tauchnitz /**
* renders a ministatz for dashboard
* Idee: René Tauchnitz
*
* @return void
*/
function sem_dashboardStatz_show() { function sem_dashboardStatz_show() {
$widget_options = get_option( 'dashboard_widget_options' ); $widget_options = get_option( 'dashboard_widget_options' );
@ -299,6 +304,14 @@ function sem_dashboardStatz_show() {
echo '</p>'; echo '</p>';
} }
/**
* dashboard-control for ministatz
*
* @author Ortwin Pinke
* @since semR 1.0
*
* @return void
*/
function sem_dashboardStatz_control() { function sem_dashboardStatz_control() {
if (!$widget_options = get_option('dashboard_widget_options')) if (!$widget_options = get_option('dashboard_widget_options'))
$widget_options = array(); $widget_options = array();