/**
* The required files
*/
require_once(HTML_BASE_COMMON_PATH.'/Object.php');
require_once(PORTAL_PATH.CURRENT_MYPHP_VERSION.'/Filename.php');
if (defined('HTML_FILE_UTIL_PATH')) {
require_once(HTML_FILE_UTIL_PATH.'/File.php');
}
if (defined('HTML_LOG_UTIL_PATH')) {
require_once(HTML_LOG_UTIL_PATH.'/Log.php');
}
/**
* The base class for all the HTML classes
*
* You must extend this class and write your own getHtml() method
* <code>
* Usage:
* class Demo extends Html {
* function Demo() { $this->Html(); } // Constructor
* function getHtml() { return 'Hey Demo'; } // Abstract
* }
* and
* $demo = new Demo();
* $demo->set('attribute','value');
* print $demo->get('attribute');
* </code>
*
* @package base
*/
class Html extends Object {
/**
* @var array $elements An array of elements
*/
var $elements = array();
/**
* @var int $sizeof The number of elements in the $elements array
*/
var $sizeof = 0;
/**
* Constructor
*/
function Html() {
$this->Object();
}
/**
* Set the named object to the class attribute (key), with same name
* @param String $key The key to associate with the object
* @param Object $object The object to set
*/
function setObject($key,$object) {
if ($object==NULL || $object=='') {
return;
}
if (!is_object($object)) {
$msg = $this->getClassName()."->setObject($key,$object) not a valid object<br />\r\n";
$msg .= "Format: class->key=object<br />\r\n ";
$msg .= 'Found : '.$this->getClassName().'->'.$key.'='.gettype($object);
if (defined('HTML_LOG_UTIL_PATH')) {
Log::fatal(__FILE__,__LINE__,$msg);
}
$this->getMsg(LOG_LEVEL_FATAL,$msg);
}
if (!array_key_exists($key,get_class_vars(get_class($this)))) {
$msg = $this->getClassName()."->setObject($key,$object) not a valid attribute<br />\r\n";
$msg .= "Format: class->key=object<br />\r\n ";
$msg .= 'Found : '.$this->getClassName().'->'.$key.'='.(isset($value)?''.$value:gettype($object));
if (defined('HTML_LOG_UTIL_PATH')) {
Log::fatal(__FILE__,__LINE__,$msg);
print $this->getMsg(LOG_LEVEL_FATAL,$msg);
} else {
Message::add($msg,__FILE__,__LINE__);
}
}
$this->$key = $object; // All ok, set object attribute
}
/**
* Set the named attribute (key) of a class to specified value
* Display an error message and exit, If not a known attribute
* i.e. You MUST define the attribute at class scope as ... var $myattr='';
* @param String $key The key to set
* @param String $value The value of the key
*/
function set($key,$value) {
if (array_key_exists($key,get_class_vars(get_class($this)))) {
$this->$key = $value;
} else {
$msg = $this->getClassName()."->set() not a valid key=$key<br />\r\n";
$msg .= "Format: class->key=value<br />\r\n ";
$msg .= 'Found : '.$this->getClassName().'->'.$key.'='.(isset($value)?''.$value:gettype($value));
if (defined('HTML_LOG_UTIL_PATH')) {
Log::error(__FILE__,__LINE__,$msg);
print $this->getMsg(LOG_LEVEL_ERROR,$msg);
} else {
Message::add($msg,__FILE__,__LINE__);
}
}
}
/**
* Get the complete html for a key
* Display an error message and exit, If not a known attribute
* i.e. You MUST define the 'key' at class scope as ... var $mykey='';
* @param String $key The value to return
* @param String $default The default value to use if no match
* @return String the html for the attribute (key)
*/
function get($key,$default='') {
$html = '';
$vars = get_object_vars($this);
if (array_key_exists($key,get_class_vars(get_class($this))) || array_key_exists($key, $vars)) {
$html .= $this->$key;
} else {
// Ignore errros
}
if ($html=='') {
$html .= $default;
}
return $html;
}
/**
* Get the complete html for an attribute, i.e. <a class="myclass" ...
* Usage: print '<a '.$html->getAttribute('href').'>test</a>';
* @param String $attribute The attribute to return
* @param String $default The value to return, if attribute is specified, but empty
* @return String the html for the attribute
*/
function getAttribute($attribute,$default='') {
$html = '';
if (isset($this->$attribute)) {
if ($this->$attribute!='') {
$html .= ' '.$attribute.'="'.$this->$attribute.'"';
} else {
if ($default!='') {
$html .= ' '.$attribute.'="'.$default.'"'; // No value found, use default if defined
} else {
// Return nothing
}
}
}
return $html;
}
/**
* Get the complete html for a html tag. A default value may be supplied
* Returns '', if both the $value and teh $default are empty
* <code>
* i.e. <p>My paragraph</p>
* Usage:
* print '$html->getTag('My paragraph','p','default value',"\t\t");
* </code>
* @param String $value The inner html for the tag,
* @param String $tag The tag to get
* @param String $default The default value to use, if
* @param String $tab The tab to insert before the tag start
* @param String $nl The new line to insert after the tag start
* @return String the html for the attribute
*/
function getTag($value,$tag,$default='',$tab='',$nl='') {
$html = '';
if ($value!='' || $default!='') {
if ($tag!='') {
$html .= "$tab<$tag>$nl";
}
$html .= $value!=''?$value:$default;
if ($tag!='') {
$html .= "</$tag>\r\n";
}
}
return $html;
}
/**
* Add an element,
* the number of elements are stored internally in an array.
* @param Object $element The element to add to array
*/
function add($element) {
if (!is_object($element)) {
$msg = $this->getClassName()."->add($element) not a valid object<br />\r\n";
$msg .= "Format: class->add(element)<br />\r\n ";
$msg .= 'Found : '.$this->getClassName().'->add($element), where $element type='.gettype($element);
if (defined('HTML_LOG_UTIL_PATH')) {
Log::fatal(__FILE__,__LINE__,$msg);
}
$this->getMsg(LOG_LEVEL_FATAL,$msg);;
}
$this->sizeof = array_push($this->elements, $element);
}
/**
* Get the number of elements added
* @return int The number of elements in array
*/
function getSizeof() {
return $this->sizeof;
}
/**
* Get the element at position $i in array
* @param int $i, the element $i in array
* @return Object The element in question or '' if not found
*/
function getElement($i) {
if (array_key_exists($i,$this->elements)) {
return $this->elements[$i];
} else {
return '';
}
}
/**
* Get all the elements as html
* @return String The html for all the element in the array
*/
function getElements() {
$html = '';
$sizeOf = $this->getSizeof();
for ($i = 0; $i < $sizeOf; $i++) {
$element = $this->getElement($i); // Get the next element from array
if (is_object($element)) {
$html .= $element->getHtml(); // and get the html for the element
if (is_a($element,'Td') || is_a($element,'Li') || is_a($element,'Span') || is_a($element,'Raw')) {
// Ignore, Problem if Td(), Li(), Span() or Raw())
} else {
$html .= "\r\n";
}
} else {
$html .= "$element"; // Must be a plain string
}
}
return $html;
}
/**
* Get the array of request parameters which will minimize or maximize this component
* <code>
* $array = $this->getToogle(REQUEST_LAYOUT_SHOW, LAYOUT_SHOW, LAYOUT_SHOW_TOP);
* </code>
* @param String $request The request key to use
* @param String $key The key name to use
* @param String $value The value to use
* @return array The array of key=>value pair
*/
function getToogle($request, $key, $value) {
$next = '';
$toogle = Request::get($request, $key);
//if ($key !== $toogle) {
if ($toogle & $value) {
$toogle = $toogle & ~$value; // Minimize
} else {
$toogle = $toogle | $value; // Assume maximize
}
$next = array($request=>$toogle);
//}
return $next;
}
/**
* Get the link to maximize this component
* <code>
* $array = $this->getMaximize(REQUEST_TODO_SHOW, TODO_SHOW, TODO_SHOW_ITEM);
* </code>
* @see String REQUEST_TODO_SHOW The request parameter to use for the item
* @see String TODO_SHOW The final show flags to use for the item
* @see String TODO_SHOW_ITEM The id for the selected item to use
* @return String The html for the maximize link to use if enabled
*/
function getMaximize() {
$html = '';
$param = $this->getMinimize(); // Toogle functionality, return '' or an array
if (is_array($param)) {
if (defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_NN) {
$urlencode = true;
$file = __FILE__;
$line = __LINE__;
$params = Params::get($param, $urlencode, $file, $line);
$class = CSS_CANVAS.' '.CSS_PRINTER; // $this->getCssClass()
$text = '';
if (defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) {
$text = $this->getClassName();
}
$title = LINK_TITLE_CLICK_MAXIMIZE.' '.$this->getClassName();
$link = new Link($text,$params, $class,$title);
$link->add(new Images(IMAGE_TRIANGLE,'','',$title, $class));
$html .= $link->getHtml();
} else {
$html .= "<!-- ".$this->getClassName()."->getMaximize() Disabled -->\r\n";
}
} else {
if (defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_INFO) {
$html .= "<!-- ".$this->getClassName()."->getMaximize() Disabled -->\r\n";
}
}
return $html;
}
/**
* Toogle the request parameters which will minimize or maximize this component
* You may override this function in order to create the minimize functionality
* @see String REQUEST_TODO_SHOW The request parameter to use for the item
* @see String TODO_SHOW The final show flags to use for the item
* @see String TODO_SHOW_ITEM The id for the selected item to use
* @abstract
* @return array The array of key=>value pair
*/
function getMinimize() {
return '';
// $msg = $this->getClassName()."->getMinimize() *** ABSTRACT *** You MUST implement this";
// if (defined('HTML_LOG_UTIL_PATH')) {
// Log::fatal(__FILE__,__LINE__,$msg);
// return $this->getMsg(LOG_LEVEL_FATAL, $msg);
// } else {
// return 'File: '.__FILE__.' Line:'.__LINE__." $msg";
// }
// return $this->getToogle(REQUEST_TODO_SHOW, TODO_SHOW, TODO_SHOW_ITEM);
}
/**
* Return a new Image object, which may be clickable, if the function getMinimize() returns an array
* @param String $value The value name of the image. I.e. IMAGE_TRIANGLE
* @param String $class The CSS class name to use
* @param String $aux The link is used inside an UL tag if LINK_LAYOUT_LI
* @return Object The object of the triangle image, optionally surronded by a link
*/
function newTriangle($value, $class='', $aux='') {
$object = new Raw();
$param = $this->getMinimize(); // '' OR an array
if (is_array($param)) {
$object = new Images($value,'','','',$class);
if (defined('DEBUG_LEVEL') && DEBUG_LEVEL & DEBUG_LEVEL_SHOW_NN) {
$params = Params::get($param);
$object = new Link('',$params,$class,LINK_TITLE_CLICK_MINIMIZE.' '.$this->getClassName(), $aux);
if (is_a($this, 'MenuFisheye')) {
$object->add(new Span(LINK_TEXT_CLICK_MINIMIZE,'','',"display: none;")); // Fisheye menu
}
$object->add(new Images($value,'','','',$class));
}
} else {
// TODO what
}
return $object;
}
/**
* Get Html
* Assume that in some developer mode, some icons will show up
* If user clicks a specific help icon, some fancy help/docphp will show up
* Returns the html for the element
* @abstract
* @return String The complete html
*/
function getHtml() {
$msg = $this->getClassName()."->getHtml() *** ABSTRACT *** You MUST implement this";
if (defined('HTML_LOG_UTIL_PATH')) {
return $this->getMsg(LOG_LEVEL_ERROR, $msg);
} else {
return 'File: '.__FILE__.' Line:'.__LINE__." $msg";
}
}
/**
* Display the html
* <code>
* Usage:
* Html::display($value,$tag);
* i.e. Html::display('p','my tag')
* </code>
* @static
* @param String $value The inner html for the tag,
* @param String $tag The tag to get
*/
function display($value='',$tag='') {
$html = new Html();
$html->addHtml($html->getTag($value,$tag));
}
/**
* Show source
* <code>
* Usage:
* Classname:showsource($path,$aux);
* i.e. Classname:showsource();
* </code>
* @static
* @param String $path The name of the path to the source file. I.e. HTML_BASE_COMMON_PATH
* @param String $aux The type of link to use: BR LI
*/
function showsource($path='HTML_BASE_COMMON_PATH',$aux='') {
ShowSource::link($path,$this->getClassName(),$aux);
}
}
?>
HTML source code
Den fulde HTML kildekode for Html klassen
<?
ERROR, Html->getHtml() *** ABSTRACT *** You MUST implement this<br />