1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
interface ITemplate
{
public function __construct($title, $keyword, $description);
public function addMenu($link, $url, $title, $class='');
public function addTitle($text, $level, $class='');
public function addParagraph ($text, $class='');
public function __destruct();
}
class Template implements ITemplate {
private $html;
public function __construct($title, $keyword, $description, $class=''){
$this->html = '<!DOCTYPE HTML PUBLIC "-W3C//DTD HTML 4.1 Transitional//FR" http://www.w3.org/TR/html4/loose.dtd"
<html>
<head>
<meta http-equiv="content-Type" content="text/html; charset=iso-8859-1">
<meta description="'.$description.'">
<meta keyword="'.$keyword.'">
<link rel="stylesheet" type="text/css" href="'.$class.'">
<title>'.$title.'</title>
</head>
<body>';
}
public function addMenu($link, $url, $title, $class=''){
$error = '';
$arrayLink = array();
$arrayUrl = array();
$arrayLink = explode(',',$link);
$nbrLink = sizeof($arrayLink);
$arrayUrl = explode(',',$url);
$nbrUrl = sizeof($arrayUrl);
if ($nbrLink == $nbrUrl) {
$this->html .= '<ul class="'.$class.'">';
for($i=0;$i<$nbrLink;$i++)
$this->html .= '<li><a href="'.$arrayUrl[$i].'" title="'.$title.'">'.$arrayLink[$i].'</a></li>';
}else{
echo $error = '<SCRIPT LANGUAGE="JavaScript">
alert("Le nombre de liens n\'est pas identique aux nombre d\'url!");
</SCRIPT>';
}
}
public function addTitle($text, $level, $class=''){
$this->html .= '<h'.$level.' class="'.$class.'">'.$text.'<h'.$level.'>';
return $this->html;
}
public function addParagraph ($text, $class=''){
$this->html .= '<p class="'.$class.'">'.$text.'</p>';
}
public function __destruct()
{
$this->html .='</body></html>';
}
} |