Skip to content

Commit

Permalink
Merge pull request cafuego#1 from singularo/master
Browse files Browse the repository at this point in the history
Fix call to format_size in the over-quota code path and use isset() to avoid warnings on unset vars, as PHP 5.3+ is noisy. Also hide errors during run-time.
  • Loading branch information
cafuego committed Apr 9, 2012
2 parents 4d774cf + 6863aba commit 3a1a3ef
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions internode.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@
* image output already included this information.
*/

// Newer PHP versions output a fee too many errors
ini_set('error_reporting', E_ALL ^ E_NOTICE);

// Your username and password, change these.
define("INTERNODE_USERNAME", "replace_with_your_username");
define("INTERNODE_PASSWORD", "replace_with_your_password");
Expand Down Expand Up @@ -482,10 +485,12 @@ function display_history() {
}

// Add weekly moving average.
if($i > 0) {
if (isset($i) && ($i > 0)) {
for($j = ($i-3); $j <= ($i+3); $j++) {
if( $this->history[$j] ) {
$avg_w += abs($this->history[$j]->usage);
if( isset($this->history[$j]) && $this->history[$j] ) {
if (isset($this->history[$j]->usage)) {
$avg_w += abs($this->history[$j]->usage);
}
$k_w++;
}
}
Expand All @@ -499,10 +504,12 @@ function display_history() {
}

// Add quarterly moving average.
if($i > 0) {
if (isset($i) && ($i > 0)) {
for($j = ($i-44); $j <= ($i+44); $j++) {
if( $this->history[$j] ) {
$avg_m += abs($this->history[$j]->usage);
if( isset($this->history[$j]) && $this->history[$j] ) {
if (isset($this->history[$j]->usage)) {
$avg_m += abs($this->history[$j]->usage);
}
$k_m++;
}
}
Expand Down Expand Up @@ -544,21 +551,21 @@ function display_history() {
$string = $string = sprintf("Graph Interval: %d days Remaining: %d days", count($this->history), $this->days_remaining);
imagestring($im, 2, IMAGE_BORDER_LEFT+IMAGE_BORDER+imagefontwidth(2), (imagefontheight(2) * 2), $string, $blue);

$string = sprintf("Daily Transfer: %s Total Transfer: %s", format_size($total / count($this->history)), format_size($total));
$string = sprintf("Daily Transfer: %s Total Transfer: %s", format_size($this->used / count($this->history)), format_size($this->used));
imagestring($im, 2, IMAGE_BORDER_LEFT+IMAGE_BORDER+imagefontwidth(2), (imagefontheight(2) * 3), $string, $darkgreen);

if($this->remaining > 0) {
$string = sprintf("Daily Remaining: %s Total Remaining: %s", format_size($this->remaining / $this->days_remaining), format_size($this->remaining) );
imagestring($im, 2, IMAGE_BORDER_LEFT+IMAGE_BORDER+imagefontwidth(2), (imagefontheight(2) * 4), $string, $orange);
} else {
$string = sprintf("WARNING: You are %s over quota!", $this->format_size($over) );
$string = sprintf("WARNING: You are %s over quota!", format_size($over) );
imagestring($im, 2, IMAGE_BORDER_LEFT+IMAGE_BORDER+imagefontwidth(2), (imagefontheight(2) * 4), $string, $red);
}
} else {
$string = $string = sprintf("Graph Interval: %d days", count($this->history));
imagestring($im, 2, IMAGE_BORDER_LEFT+IMAGE_BORDER+imagefontwidth(2), (imagefontheight(2) * 2), $string, $blue);

$string = sprintf("Daily Transfer: %s Total Transfer: %s", $this->format_size($total / count($this->history)), $this->format_size($total/1000));
$string = sprintf("Daily Transfer: %s Total Transfer: %s", format_size($total / count($this->history)), $this->format_size($total/1000));
imagestring($im, 2, IMAGE_BORDER_LEFT+IMAGE_BORDER+imagefontwidth(2), (imagefontheight(2) * 3), $string, $darkgreen);
}

Expand Down

0 comments on commit 3a1a3ef

Please sign in to comment.