PHP Classes

File: class.setistats.php

Recommend this page to a friend!
  Classes of Christian Legler   Setistats   class.setistats.php   Download  
File: class.setistats.php
Role: ???
Content type: text/plain
Description: The sourcecode of class
Class: Setistats
Author: By
Last change: some changes
Date: 22 years ago
Size: 9,128 bytes
 

Contents

Class file image Download
<?php // --------------------------------------------------------------------------------- // Setistats - class.setistats.php // tested with Apache 1.2.23 / PHP 4.1.2 on Debian 2.2r5 // Created: Mar 29, 2002 // Last modified: Mar 31, 2002 // // Copyright © 2002 by Christian Legler ([email protected]) // --------------------------------------------------------------------------------- class SetiStats { var $exp = array ( //@access private //array for the regexp's "UserName" => "URL)\n</td>\n<td>\n(.*)\n</td>\n</tr>\n<tr>\n<td>\nResults", "Workunits" => "<TR>\n<TD>\nResults Received\n</TD>\n<TD>\n(.*)\n</TD>\n</TR>\n<TR>\n<TD>\nTotal CPU Time", "TotalCPUTime" => "<TR>\n<TD>\nTotal CPU Time\n</TD>\n<TD>\n(.*)\n</TD>\n</TR>\n<TR>\n<TD>\nAverage CPU Time per work unit", "AverageCPUTime" => "<TR>\n<TD>\nAverage CPU Time per work unit\n</TD>\n<TD>\n(.*)\n</td>\n</tr>\n<tr>\n<td>\nAverage results received per day", "LastResult" => "<TR><TD>Last result returned:</TD><TD>(.*)</TD>\n<TR><TD>Registered on:</TD>", "RegisteredOn" => "<TR><TD>Registered on:</TD><TD>(.*)</TD>\n<TR><TD>&nbsp;</TD><TD><a href=", "SetiUserFor" => "<TR><TD>SETI@home user for:</TD><TD>(.*)</TD></TR>\n<TR BGCOLOR=\"#303080\"><TD COLSPAN=2><b>Your group info", "GroupName" => ".html\"><b>(.*)</b></a></td>\n</tr>\n<tr>\n<td", "GroupURL" => "<tr>\n<td>\nYou belong to the group named:\n</td>\n<td>\n<a href=\"(.*)\"><b>", "TotalUsers" => "<tr><td>\nYour rank out of <b>(.*)</b> total users is:\n</td><td>", "Rank" => "</td><td>\n<b>(.*)<sup>", "TotalUsersWithThisRank" => "The number of users who have this rank:\n</td><td>\n<b>(.*)</b>\n</td></tr>\n<tr><td>\nYou have completed more work units than", "MoreWorkUnitsThan" => "work units than\n</td><td>\n<b>(.*)</b> of our", "AverageResultsPerDay" => "Average results received per day\n</td>\n<td>\n(.*)\n</td>\n</tr>\n<TR><TD>Last", "RegistrationClass" => "</TD>\n<TR><TD>&nbsp;</TD><TD><a href=(.*)>View Registration Class</a></TD>\n<TR><TD>SETI@home user for" ); var $errors = array( //@access private //array for errorstings "SiteDown" => "Seti@Home Server unreachable", "ParseError" => "Parse Error", "Error" => "Error" ); function setEmail($user_email) //@access public //This sets the email address and build the urls of the userstats website //usage setEmail('[email protected]') { $this->email = $user_email; $this->server1 = "http://setiathome.ssl.berkeley.edu/fcgi-bin/fcgi?email=". $this->email. "&cmd=user_stats_new"; $this->server2 = "http://iosef.ssl.berkeley.edu/fcgi-bin/fcgi?email=". $this->email. "&cmd=user_stats_new"; return true; } function Init() //@access public //This grabs the Seti@home UserStats Website //usage Init() //you have to call this before you can get the data { $this->raw = @implode("", @file($this->server1)); if (!$this->raw){ $this->raw = @implode("", @file($this->server2)); } } function viewStats($what) //@access public //This prints out the part of the stats you want //usage i.e. viewStats('UserName') prints the username //see the $exp array for availible options { if (!$this->raw) { $this->$what = $this->errors["SiteDown"]; } else { if (@eregi($this->exp[$what], $this->raw, $output)) { $this->$what = $output[1]; } else { $this->$what = $this->errors["ParseError"]; } } if (!$this->$what) { $this->$what = $this->errors["Error"]; } return $this->$what; } function checkCert($cert_num, $url) //@access public //checks the certs of the user i.e. 100 Workunits //usage //checkCert ('0',1) returns the url to view the cert //checkCert ('0',0) returns true or false //100 Wokunits => $cert_num = '0' //250 Wokunits => $cert_num = '1' //500 Wokunits => $cert_num = '2' //and so on { if (!$this->raw) { $this->cert_check = $this->errors["SiteDown"]; } else { if (@eregi("&certnum=".$cert_num, $this->raw)) { if ($url == 1) { $this->cert_check = "http://setiathome.ssl.berkeley.edu/fcgi-bin/fcgi?email=".$this->email."&cmd=print_cert&certnum=".$cert_num."&size=0"; } else { $this->cert_check = true; } } else { $this->cert_check = false; } } if (!$this->cert_check) { $this->cert_check = false; } return $this->cert_check; } function Group() //@access public //prints out the Group name & url { if (@eregi("You do not currently belong to a group", $this->raw)) { $this->Groupname = "none"; $this->Groupurl = ""; } else { $this->Groupname = $this->viewStats('GroupName'); $this->Groupurl = $this->viewStats('GroupURL'); } $this->Groupstuff = array ( "name" => $this->Groupname, "url" => $this->Groupurl ); return $this->Groupstuff; } function ResultInt() //@access public //prints out the result interval //ResultsInt() { list ($this->null, $this->tmp_month, $this->tmp_null, $this->tmp_day, $this->tmp_time, $this->tmp_year, $this->null) = split ('[ ]', $this->viewStats('RegisteredOn')); list ($this->tmp_hour, $this->tmp_min, $this->tmp_sec) = split ('[:]', $this->tmp_time); switch ($this->tmp_month) { case 'Jan'; $this->tmp_month = 1; break; case 'Feb'; $this->tmp_month = 2; break; case 'Mar'; $this->tmp_month = 3; break; case 'Apr'; $this->tmp_month = 4; break; case 'May'; $this->tmp_month = 5; break; case 'Jun'; $this->tmp_month = 6; break; case 'Jul'; $this->tmp_month = 7; break; case 'Aug'; $this->tmp_month = 8; break; case 'Sep'; $this->tmp_month = 9; break; case 'Oct'; $this->tmp_month = 10; break; case 'Nov'; $this->tmp_month = 11; break; case 'Dec'; $this->tmp_month = 12; break; } $this->RegDate = mktime($this->tmp_hour, $this->tmp_min, $this->tmp_sec, $this->tmp_month, $this->tmp_day, $this->tmp_year); $this->ActDate = time(); $this->DiffDate = ($this->ActDate-$this->RegDate); $this->ResInt = ($this->DiffDate/$this->viewStats('Workunits')); $this->days = floor($this->ResInt / 24 / 60 / 60 ); $this->ResInt = $this->ResInt - ($this->days*24*60*60); $this->hours = floor($this->ResInt / 60 / 60); $this->ResInt = ($this->ResInt - ($this->hours*60*60)); $this->minutes = floor($this->ResInt / 60); $this->ResInt = $this->ResInt - ($this->minutes*60); $this->seconds = floor($this->ResInt); $this->ResultInterval = array ( "days" => $this->days, "hours" => $this->hours, "minutes" => $this->minutes, "seconds" => $this->seconds ); return $this->ResultInterval; } function AverageResultsPerWeek() //@access public //returns users average results per week //usage AverageResultsPerWeek() { return $this->viewStats('AverageResultsPerDay')*7; } function AverageResultsPerMonth() //@access public //returns users average results per month //usage AverageResultsPerMonth() { return $this->viewStats('AverageResultsPerDay')*30; } } ?>