Ex7erm1na7oR
Registered
PHP:
<?php if(!defined('BASE')){ header('location:index.php'); }
class HTML{
private static $config;
private static $output;
//Top of the file
private static function checkAtt($id="", $class=""){
$re = "";
if($id != ""){
$re = ' id="' . $id . '"';
}
if($class != ""){
$re .= ' class="' . $class . '"';
}
return $re;
}
public static function xHTML(){
self::$output .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">';
}
public static function closeHTML(){
self::$output .= '</body>
</html>';
}
public static function openHead(){
self::$output .= '<head>';
}
public static function closeHead($bodyId="", $bodyClass=""){
self::$output .= '</head>
<body id="' . $bodyId . '" class="' . $bodyClass . '">';
}
public static function title($title){
self::$output .= '<title>' . $title . '</title>';
}
public static function Meta($name="", $content=""){
if($name == "encoding"){
$res = '<meta http-equiv="Content-Type" content="text/html; charset=' . $content . '" />';
}else{
$res = '<meta name="' . $name . '" content="' . $content . '" />';
}
self::$output .= $res;
}
public static function loadJS(){
$this->config = Config::getInstance();
if($this->config->JSEnabled == true){
foreach($this->config->JSLibs as $key => $value){
$res .= '<script src="' . $this->config->BasePath . '/' . $this->config->ThemePath . '/' . $this->config->ActiveTheme . '/js/' . $value . '.js" type="text/javascript"></script>';
}
}else{
$res = "";
}
self::$output .= $res;
}
public static function loadCSS($cssName, $media="screen"){
$this->config = Config::getInstance();
if(is_array($cssName)){
foreach($cssName as $key => $fileCSS){
$res .= '<link rel="stylesheet" type="text/css" href="' . $this->config->BasePath . '/' . $this->config->ThemePath . '/' . $this->config->ActiveTheme . '/css/' . $fileCSS . '.css" media="' . $media . '" />';
}
}else{
$res = '<link rel="stylesheet" type="text/css" href="' . $this->config->BasePath . '/' . $this->config->ThemePath . '/' . $this->config->ActiveTheme . '/css/' . $cssName . '.css" media="' . $media . '" />';
}
self::$output .= $res;
}
//End of Top of file
//Divs
public static function Div($content, $id="", $class="")
$res = '<div';
$res .= self::checkAtt($id, $class);
$res .= '>' . $content . '</div>';
self::$output .= $res;
}
public static function openDiv($id="", $class=""){
$res = '<div';
$res .= self::checkAtt($id, $class);
$res .= '>';
self::$output .= $res;
}
public static function closeDiv(){
self::$output .= '</div>';
}
//End of Divs
//Content
public static function p($content, $id="", $class=""){
$res = '<p';
$res .= self::checkAtt($id, $class);
$res .= '>' . $content . '</p>';
self::$output .= $res;
}
public static function img($path, $alt="", $title=""){
self::$output .= '<img src="' . $path . '" alt="' . $alt . '" title="' . $title . '" />';
}
public static function h($content, $size="1"){
if($size < 1){
$size = 1;
}
if($size > 6){
$size = 6;
}
self::$output .= '<h' . $size . '>' . $content . '</h' . $size . '>';
}
public static function label($content, $id="", $class=""){
$res = '<label';
$res .= self::checkAtt($id, $class);
$res .= '>' . $content . '</label>';
self::$output .= $res;
}
public static function openList($type="0", $id="", $class=""){
/*
0 for unordered list(ul)
1 for ordered list(ol)
*/
if($type == 0){
$res = '<ul';
}
elseif($type == 1){
$res = '<ol';
}
$res .= self::checkAtt($id, $class);
$res .= '>';
self::$output .= $res;
}
public static function li($content, $id="", $class="", $link=""){
$res = '<li';
$res .= self::checkAtt($id, $class);
$res .= '>';
if($link != ""){
$res .= '<a href="' . $link . '">' . $content . '</a></li>';
}else{
$res .= $content.'</li>';
}
self::$output .= $res;
}
public static function closeList($type="0"){
if($type == 0){
$res = '</ul>';
}
elseif($type == 1){
$res = '</ol>';
}
self::$output .= $res;
}
public static function link($loc, $content, $id="", $class=""){
$res = '<a href="' . $loc . '"';
$res .= self::checkAtt($id, $class);
$res .= '>';
$res .= '' . $content . '</a>';
self::$output .= $res;
}
//End of content
public static function parse(){
//Some logic
echo self::$output;
}
}
?>
удачно ли е да ползвам ехо или трябва да ползвам return?
И ако ползвам return това означава че трябва да подавам функцията към променлива а моята цел е нещо от сорта да ми е темплейт.
PHP:
HTML::xHtml();
HTML::openHead();
HTML::title("Simple Title");
html::meta("encoding", "utf8");
html::meta("keywords", "some, keywords");
HTML::closeHead();
HTML::openDiv("SimpleDivID", "SimpleDivClass");
HTML::link('#', 'SimpleLink');
HTML::p('Some Simple Paragraph');
HTML::h('Simple Heading');
HTML::label('simpleLabel');
HTML::openList();
html::li("Apple");
html::li("Apricot", "", "", "#");
HTML::closeList();
html::div(html::p('Some paragraph in div'), "SimpleID2");
HTML::closeDiv();
HTML::closeHTML();
Някой от разбиращите да си каже мнението.
Също така начин да форматирам извикания код