Source for file RSSerror.php
Documentation is available at RSSerror.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2005 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Antonio Jozzolino <info@sgd.com.br> |
// +----------------------------------------------------------------------+
// $Id: RSSerror.php,v 1.13 2006/11/24 17:18:58 Antonio Jozzolino Exp $
//This verifies if the class already was declared.
* This class is necessary to make xml file.
* @link http://www.phpclasses.org/browse/package/1820.html
require_once("phpclasses/class_easyrss/class.easyrss.php");
* Generates a rss feed from the php error log file.
* <li>XML 2.0 compatible</li>
* <li>Shows the error line and some lines of source code.</li>
* <li>Protected with password.</li>
* <li>Generates link for edition of php file in developer machine (Best result with Firefox 2.0 e sage extension).</li>
* Create a file with a name secret or deceiving (ex: listimages.php ) and put this code below.
* include_once('RSSerror.php');
* $args = array( "root" => "/home/user/public_html/",
* "local" => "file:///C:/Documents%20and%20Settings/User/My%20Documents/My%20site/",
* "log" => "/home/user/var/error_log",
* "url" => "http://www.user.com.br/",
* $param = array( "encoding" => "UTF-8",
* "title" => "Error Report for www.user.com.br",
* "description" => "Please corrects some errors occurred in the site www.user.com.br",
* "stylesheet" => "http://www.user.com.br/rsserror.css",
* "link" => "http://www.user.com.br/"
* $rss = new RRSerror($args, $param);
* in your feeds agregador, call the file of that sorts things out:
* http://www.domain.com/listimages.php?p=123456
* @example RSSerrorExample.php How to use this class.
* @author Antonio Jozzolino <info@sgd.com.br>
* @version $Revision: 1.13 $
* @since 2006/11/21 17:34:32
* @see http://www.sgd.com.br
* @todo Create a way to turn application secure, specifically to encrypt the xml code generated.
* @todo To do xml code more compatible with RSS readers like Google Reader.
* @link http://www.sgd.com.br/images/class_RSSerror.png Google Reader screenshot
* @link http://www.phpclasses.org/browse/package/3543.html phpclasses.org package
* @link http://www.sgd.com.br/content/view/26/88888890/ Monitorando erros em sites PHP via RSS
* Necessary parameters for the class RSSerror
* @var string key["root"] Path of home directory of your site in UNIX format.
* @var string key["local"] Path of home LOCAL directory of your site in UNIX or Windows format .
* @var string key["log"] Complete path of your log file in UNIX format.
* @var string key["url"] URL of your site.
* @var string key["lines"] Number of lines before and after the line that to present error.
* @var string key["password"] Your password.
var $args = array("root" => "/home/www/",
"local" => "file:///C:/Documents%20and%20Settings/Antonio%20Jozzolino/My%20Documents/My%20site/",
"log" => "/home/var/logs/.error_log",
"url" => "http://www.sgd.com.br/",
* Necessary parameters for the class easyRSS
* @var string key["encoding"] Default is UTF-8.
* @var string key["language"] Default is pt-BR.
* @var string key["title"] Title of your feed.
* @var string key["description"] Description of your feed.
* @var string key["stylesheet"] URL of your css file. Let it empty if you don't have one.
* @var string key["link"] Link to your site.
var $param = array("encoding" => "UTF-8",
"title" => "Error Report for www.sgd.com.br",
"description" => "Please corrects some errors occurred in the site www.sgd.com.br",
"stylesheet" => "http://www.sgd.com.br/includes/class_RSSerror/rsserror.css",
"link" => "http://www.sgd.com.br/"
* This var save old value off $args["root"]
* This function opens the log file, it extracts the information passing
* them for an array, setting up the ítens of the file rss. In the end,
* it calls the function easy RSS and it prints the xml file .
* @param array [$args] Necessary parameters for the class RSSerror
* @param array [$param] Necessary parameters for the class easyRSS
* @return string xml/rss file format
* @since 2006/11/23 13:39:13
//save old value of $this->args["root"] var
$this->args["root"] = "";
for ($i= 1; $i< count($log); $i++ ){
$this->args["root"] .= "\/". $log[$i];
//Ok, I know, it's horrible. I promise fix it soon.
if(!isset ($_GET["p"])) exit;
if($_GET["p"] != $this->args["password"] ) exit;
//It opens the log archive
//It verify if log file is empty
//This makes an array from the log file
$size = (count($file_log) >= 10)? 10 : count($file_log);
for($i= 0; $i< $size; $i++ ){
$error[$i]["title"] = $this->title($file_log[$i]);
$error[$i]["description"] = $this->description($file_log[$i]);
$error[$i]["pubDate"] = $this->data($file_log[$i]);
$error[$i]["link"] = $this->links($file_log[$i]);
$error[0]["title"] = "All clear";
$error[0]["description"] = "No error detected yet.";
$error[0]["pubDate"] = time();
$error[0]["link"] = $this->args["url"];
//RSS setup parameters Attribution
$atrbs = array( "encoding" => $this->param["encoding"],
"language" => $this->param["language"],
"title" => $this->param["title"],
"description" => $this->param["description"],
"stylesheet" => $this->param["stylesheet"],
"link" => $this->param["link"],
header("Content-type: application/xml");
echo parent::rss($atrbs);
* This function returns PHP error type.
* @param string [$line] Line of log file
* @return string PHP error type
* @since 2006/11/23 12:36:36
* This function returns part of the source code with the line that presented error.
* @param string [$line] Line of log file
* @return string HTML formated source code
* @since 2006/11/23 12:36:36
preg_match("/\][^P]*P[^:]*: (.*)/", $line, $result);
preg_match("/on line ([0-9]*)/", $result[1], $line_n);
$output = "<p><strong>". utf8_encode($result[1]). "</strong></p>\n";
$begin = (($line_n[1] - $this->args['lines']) <= 0)? 0 : ($line_n[1] - $this->args['lines']);
$end = (($line_n[1] + $this->args['lines']) >= count($source))? count($source) : ($line_n[1] + $this->args['lines']);
for($i= $begin; $i<= $end; $i++ ){
$output .= '<table border="0" cellpadding="0" cellspacing="0" width="100%">'
. '<tr><td bgcolor="#DFDFDF"><strong>['. $i
. '] </strong></td><td bgcolor="#DFDFDF"><strong>'
. "</strong></td></tr></table>";
$output = "Sorry! I can't show source code now.";
$output = "Sorry! I can't show source code now.";
* This function catches the date in the log file and it returns converted in the format of the UNIX.
* @param string [$line] Line of log file
* @return integer UNIX timestamp date format
* @since 2006/11/23 12:36:36
$datetime = split(" ", $result[1]);
$hour = split(":", $datetime[1]);
$time = (strtotime($datetime[0]) + ($hour[0]* 3600) + ($hour[1]* 60) + $hour[2]);
* This function returns the physical path or the url of the file that it presented errors.
* @param string [$line] Line of log file
* @param bolean [$default] Key to choose the return value
* @return string It returns url file or file fisical path if false
* @since 2006/11/23 11:30:08
$links = $this->args['local']. $result[1];
|