/**
* The required files
*/
require_once(HTML_BASE_COMMON_PATH.'/Reader.php');
require_once(HTML_BASE_COMMON_PATH.'/Writer.php');
require_once(HTML_BASIC_UTIL_PATH.'/Message.php');
if (defined('HTML_CACHE_UTIL_PATH')) {
require_once(HTML_CACHE_UTIL_PATH.'/Cache.php');
}
if (defined('HTML_LOG_UTIL_PATH')) {
require_once(HTML_LOG_UTIL_PATH.'/Log.php');
}
/**
* The base class for all other classes
* You must extend this class and write your own getHtml() method
* <code>
* Usage:
* class Demo extends Object {
* function Demo() { $this->Object(); } // Constructor
* function getHtml() { return 'Hey Demo'; } // Abstract
* }
* </code>
* @package base
*/
if (!defined('__CLASS__')) {
define('__CLASS__','Unknown __CLASS__');
}
class Object {
/**
* @var String $html Debug info
*/
var $html = '';
/**
* Returns the name of the instanciated class or the parameter if supplied
* <code>
* Usage:
* print $parent->getClassName();
* print $parent->getClassName(__CLASS__);
* </code>
* @static
* @param String $class The class name
* @return String The name of the class
*/
function getClassName($class='') {
$classname = __CLASS__;
if (!empty($this)) {
if ($class!='') {
$classname = $class;
} else {
$classname = ucfirst(get_class($this));
}
}
return $classname;
}
/**
* Get the formatted message and debug level and Log to file ?
* @param int $level The debug level. ALL, QUERY, USER, DEBUG, INFO, WARN, ERROR, FATAL, EMAIL or NONE
* @param String $msg The message to log
* @return String The message in question
*/
function getMsg($level,$msg) {
$html = '';
if (defined('HTML_LOG_UTIL_PATH')) {
switch ($level) {
case LOG_LEVEL_DEBUG:
if ($level & LOG_LEVEL) {
$html .= "<!-- ";
}
break;
case LOG_LEVEL_ALL:
case LOG_LEVEL_QUERY:
case LOG_LEVEL_USER:
case LOG_LEVEL_INFO:
case LOG_LEVEL_WARN:
case LOG_LEVEL_ERROR:
case LOG_LEVEL_FATAL:
case LOG_LEVEL_EMAIL:
case LOG_LEVEL_NONE:
// Known Log Levels
break;
default:
$msg .= "Class: ".$this->getClassName()."<br />\r\n"."->getMsg(), Unknown LOG_LEVEL found, level=".$level;
Log::fatal(__FILE__,__LINE__,$msg);
die('File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n$msg");
break;
}
if ($level & LOG_LEVEL) {
$html .= Log::getLevelName($level).', '.$msg;
}
switch ($level) {
case LOG_LEVEL_DEBUG: // TODO timestamp and log to file
if ($level & LOG_LEVEL) {
$html .= " -->\r\n"; // 2008-03-13 added \r\n because of ../doc/*
}
break;
case LOG_LEVEL_FATAL:
$msg .= "Class: ".$this->getClassName()."<br />\r\nObject->getMsg(), FATAL error, cannot continue, sorry";
if ($level & LOG_LEVEL) {
die('File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n".$msg); // STOP
} else {
$html .= "<br />\r\n".$msg; // continue ??
}
break;
default:
if ($level & LOG_LEVEL) {
$html .= "<br />\r\n";
}
break;
}
} else {
$html .= "<!-- $level, $msg -->\r\n";
}
return $html;
}
/**
* Add the current html to the Cache object
* If the cache is disabled, just print the html
* <code>
* Usage:
* $element = new Element();
* $element->addHtml();
* Or
* $element = new Element();
* $element->addHtml($object->getHtml());
* </code>
* @param String $html Use other html than fetched from $element->getHtml()
*/
function addHtml($html='') {
if (defined('HTML_CACHE_UTIL_PATH')) {
if ($html!='') {
Cache::add($html);
} else {
Cache::add($this->getHtml());
}
} else {
/**
* The Cache object is not available
*/
if ($html!='') {
print $html;
} else {
print $this->getHtml();
}
}
}
/**
* Returns the html for the element
* @abstract
* @return String The complete html
*/
function getHtml() {
$html = '';
$msg = $this->getClassName()."->getHtml() *** ABSTRACT *** You MUST implement this";
if (defined('HTML_LOG_UTIL_PATH')) {
$html .= $this->getMsg(LOG_LEVEL_ERROR, $msg);
} else {
return 'File: '.__FILE__.' Line:'.__LINE__." $msg";
}
return $html;
}
/**
* Returns the information for this class
* <code>
* Usage:
* print Link::toString('Link'); // static or
* print Link->toString(); // instanciated
* </code>
* @param String $path The path to the source files
* @param String $class The name of a valid class name or $this
* @return String The complete info for the class in html
*/
function toString($path='',$class='') {
if ($class!='') {
// require_once($path.'/'.$class); ???
$me = new $class();
} else {
$me = ucfirst($this->getClassName()); // Must be used for v 4.x
}
$html = '';
$html .= $me."<br />\r\n";
if (file_exists(HTML_BASE_COMMON_PATH.'/'.$me.'.php')) {
// Problem with ob_xxx ??
//$source = ShowSouce(HTML_BASE_COMMON_PATH, $me.'.php');
//$html .= $source->getHtml();
}
// TODO, add more class info, like methods, class members
// TODO, may be also, show the phpdoc ?? remember to scramble (md5)
return $html;
}
/**
* Returns the name of the cache file name
* If empty name, create a cache file name
* @param String $path The Path, Where to store the cache files
* @return String The path/name of the cache file
*/
function getCacheFileName($path='') {
return Writer::getCacheFileName($path, $this->getClassName());
}
/**
* Save the cache file
* @param String $content The html content to save as cache file
* @param String $path The Path, Where to store the cache files
* @return boolean True on succes, false if failure
*/
function save($content, $path) {
return Writer::save($content, $this->getCacheFileName($path), $this->getClassName());
}
/**
* Read the content of the specified filename
* <code>
* Usage:
* $object = new Object();
* $content = $object->content($filename);
* Or
* $content = Object::content($filename);
* </code>
* @static
* @param String $filename The filename to read
* @return String The content or empty
*/
function content($filename) {
return Reader::content($filename);
}
}
?>
HTML source code
Den fulde HTML kildekode for Object klassen
<?
ERROR, Object->getHtml() *** ABSTRACT *** You MUST implement this<br />