Jun
30
2008
2

ErrorHandle

Hi,

hier ein kleines Tool um Fehler in PHP abzufangen und zu handeln:

 
<?php
require_once 'ErrorHandle.class.php';
error_reporting(E_ALL);
ini_set("error_display",0);
set_error_handler(array("ErrorHandle", "add"));
?>
 
 
<?php
class ErrorHandle{
	private static $errors = array();
	public static $send = false;
 
	public static $errortypes_to_ignore = array(E_STRICT);
 
	public static function add($errno, $errmsg, $filename, $linenum){
		ErrorHandle::$errors[] = new ErrorHandle($errno, $errmsg, $filename, $linenum);
	}
 
	public static function getAll(){
		return ErrorHandle::$errors;
	}
 
	public static function toString(){
		$return = "";
		foreach(ErrorHandle::getAll() as $error){
			$msg = $error->__toString();
			if($msg != false){
				$return .= $msg . "\n\n";
			}
		}
		return $return;
	}
 
	private $errno = "";
	private $errmsg = "";
	private $filename = "";
	private $linenum = "";
	private $trace = array();
 
	public $errortypes = Array(
		E_ERROR    => 'Error',
		E_WARNING   => 'Warning',
		E_PARSE    => 'Parsing Error',
		E_NOTICE   => 'Notice',
		E_CORE_ERROR  => 'Core Error',
		E_CORE_WARNING  => 'Core Warning',
		E_COMPILE_ERROR  => 'Compile Error',
		E_COMPILE_WARNING => 'Compile Warning',
		E_USER_ERROR  => 'User Error',
		E_USER_WARNING  => 'User Warning',
		E_USER_NOTICE  => 'User Notice',
		E_STRICT   => 'Runtime Notice'//,
		//E_RECOVERABLE_ERRROR=> 'Catchable Fatal Error'
	);
 
	public function __construct($errno, $errmsg, $filename, $linenum){
		$this->errno = $errno;
		$this->errmsg = $errmsg;
		$this->filename = $filename;
		$this->linenum = $linenum;
		$this->trace = debug_backtrace();
	}
 
	public function __destruct(){
		if(ErrorHandle::$send == true) return false;
		ErrorHandle::$send = true;
 
		echo ErrorHandle::toString();
	}
 
	public function __toString(){
		if(	in_array($this->errno, ErrorHandle::$errortypes_to_ignore)	) return false;
 
		ob_start();
		print_r($this->trace);
		$trace_ret = ob_get_contents();
		ob_end_clean();
 
		return 	"Errortype:\t" 	. $this->errortypes[$this->errno] . "\n" .
				"Filename:\t"	. $this->filename  . "\n" .
				"Linenumber\t"	. $this->linenum . "\n" .
				"Errormsg\t"	. $this->errmsg . "\n" .
				"\nTrace: \n" 	. $trace_ret;
	}
}
?>
 

Kleiner Tipp: Leichte Erweiterung und Einbettung in HTML möglich :)

Written by Alexander Kaletsch in: Allgemein |
Jun
25
2008
2

Simple Apache Frameforward

Hier ein kleiner und simpler Frameforwarder von Pat und mir:

Apache Config:

 
<VirtualHost *>
        ServerName blog.alexander-kaletsch.de
        DocumentRoot /yourpath/forwarder
 
        ErrorLog /yourpath2/forwarder.error.log
 
        LogLevel warn
 
        CustomLog /yourpath3/forwarder.log combined
        ServerSignature On
</VirtualHost>
 

Weitere Subdomains können dann einfach über ServerAlias hinzugefügt werden.

Die index.php die sich im Forwarder Verzeichnis befinden muss:

 
<?php
error_reporting(0);
ini_set("error_display",0);
 
$mapper = array("blog.alexander-kaletsch.de" => "http://www.patworx.de/blog");
 
$host = $_SERVER['HTTP_HOST'];
$url = $mapper[$host];
 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?=$host?></title>
<style type="text/css">
<!--
HTML, BODY, FRAMESET, FRAME, NOFRAMES{
	height: 100%; 
	width: 100%
}
-->
</style>
 
</head>
<frameset>
    <frame frameborder="0" name="main" title="<?=$host?>" noresize="noresize" src="<?=$url?>"/>
    <noframes>
    <body>
 
<a href="<?=$url?>">Klicken Sie hier, da Ihr Browser keine Frames unterstu&uuml;zt</a>
 
    </body>
    </noframes>
</frameset>
</html>
 
Written by Alexander Kaletsch in: Allgemein, PHP, Snippets | Schlagwörter:,
Jun
25
2008
3

iCal

Die Klasse habe ich zwar schon vor einigen Monaten geschrieben, aber Dorian (http://www.proksch-it.de/) hat mich dazu bewogen, sie doch noch zu veröffentlichen, da er sie nun selbst verwendet.

Eine minimalistische Klasse für die Generierung von iCal Files.

Ziel ist: Wenig Features und wenig Probleme :)

 
class iCal{
	private $valid_elems = array("author", "start", "end", "topic", "msg", "location");
	private $min_elems = array("author", "start", "end",  "topic", "msg");
 
	public function __construct($values = array()){
		foreach($values as $key => $value){
			$this->set($key, $value);
		}
	}
 
	public function __set($key, $value){
		if(!in_array($key, $this->valid_elems)) throw new Exception("Element nicht zugelassen");
 
		$this->$key = $value;
	}
 
	public function __get($key){
		if(!in_array($key, $this->valid_elems)) throw new Exception("Element nicht vorhanden");
		return isset($this->$key) ? $this->$key : null;
	}
 
	public function __toString(){
		foreach($this->min_elems as $value){
			if($this->$value === null) throw new Exception("Nicht alle Pflichtelemente angegeben");
		}
 
		if(headers_sent()) throw new Exception("Header wurden bereits gesendet!");
 
		header('Content-Type: text/Calendar; charset=UTF-8');
		header('Content-Disposition: attachment; filename=iCal_' . date('Y-m-d_H-m-s') . '.ics');
 
		$output = "";
		$output  = (string) "BEGIN:VCALENDAR\r\n";
		$output .= 'PRODID:' . '#//PHP/AKCD//DE' . "\r\n";
		$output .= "VERSION:2.0\r\n";
		$output .= "METHOD:PUBLISH\r\n";
		$output .= "BEGIN:VEVENT\r\n";
		$output .= "DTSTART:". gmdate('Ymd\THi00\Z', $this->start) ."\r\n";
		$output .= "DTEND:". gmdate('Ymd\THi00\Z', $this->end) ."\r\n";
		if($this->location !== null) $output .= "LOCATION" . $this->quotedPrintableEncode($this->location) ."\r\n";
		$output .= "TRANSP:OPAQUE\r\n";
		$output .= "SEQUENCE:0\r\n";
		$output .= "UID:". md5("ICAL".$this->start.rand(1,5000).$this->end)."\r\n";
		$output .= "DTSTAMP:".gmdate('Ymd\THi00\Z',time())."\r\n";
		$output .= "CATEGORIES".$this->quotedPrintableEncode($this->author)."\r\n";
		$output .= "DESCRIPTION".$this->quotedPrintableEncode($this->msg)."\r\n";
		$output .= "SUMMARY".$this->quotedPrintableEncode($this->topic)."\r\n";
		$output .= "PRIORITY:5\r\n";
		$output .= "CLASS:PUBLIC\r\n";
		$output .= "STATUS:CONFIRMED\r\n";
		$output .= "END:VEVENT\r\n";
		$output .= "END:VCALENDAR\r\n";
 
		return $output;
	}
 
	private function quotedPrintableEncode($msg, $lang = "de"){
		$msg = preg_replace('/<a href="(.*)">.*<\/a>/i', "$1", $msg);
		$msg = str_replace("€", "Euro", $msg);
		$msg = ereg_replace("(\r\n|\n|\r)", "=0D=0A", $msg);
		return ";LANGUAGE=de;ENCODING=QUOTED-PRINTABLE:" . $msg;
	}
}
 

Sample:

 
$iCal = new iCal(); 
 
$iCal->start	= time() + (24 * 60 * 60);
$iCal->end	= time() + (24 * 60 * 60 * 3);
$iCal->author	= "Alexander-Kaletsch.de";
$iCal->msg	= utf8_encode('Hallo <img src='http://www.patworx.de/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> ');
$iCal->location	= utf8_encode('http://www.alexander-kaletsch.de');
$iCal->topic	= utf8_encode('Visit Alexander-Kaletsch.de');
 
echo $iCal;
 

Wer unbedingt mehr Features benötigt sollte sich die iCal Klassen von Michael Wimmer (http://www.flamino.com) anschauen.

Written by Alexander Kaletsch in: PHP, Snippets | Schlagwörter:
Jun
24
2008
2

Projekt www.descargasimaginarium.es fertig gestellt!

Imaginarium

Unter der URL www.descargasimaginarium.es wurde das spanische Download-Portal der Spielwarenfirma Imaginarium gestartet.

Written by Patrick Weinstein in: Projekte |
Jun
22
2008
2

Essknete-Laden.de released

Essknete-Laden.de

Unser neuestes Projekt:

Essknete-Laden.de wurde für die FamilyNet GmbH released.

Written by Alexander Kaletsch in: Projekte |
Jun
05
2008
2

merciless-records.de launched

Die seit Anfang der Neunziger bestehende Heavy Metal Schmiede Merciless Records hat einen neuen Webauftritt bekommen: www.merciless-records.de

Written by Patrick Weinstein in: Projekte |

Powered by WordPress | Theme: Aeros 2.0 by TheBuckmaker.com