Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class WebPage {
- /**
- * @var string Texte compris entre <head> et </head>
- */
- private $head = null;
- /**
- * @var string Texte compris entre <title> et </title>
- */
- private $title = null ;
- /**
- * @var string Texte compris entre <body> et </body>
- */
- private $body = null ;
- /**
- * Constructeur
- * @param string $title Titre de la page
- */
- public function __construct($title=null) {
- $this->head = <<<HTML
- <!DOCTYPE html>
- <html>
- <head>
- HTML;
- }
- /**
- * Protéger les caractères spéciaux pouvant dégrader la page Web
- * @param string $string La chaîne à protéger
- * @return string La chaîne protégée
- */
- public function escapeString($string) {
- return htmlspecialchars($string , ENT_HTML5);
- }
- /**
- * Affecter le titre de la page
- * @param string $title Le titre
- */
- public function setTitle($title) {
- $this->title .= "<title>$title</title>";
- }
- /**
- * Ajouter un contenu dans head
- * @param string $content Le contenu à ajouter
- * @return void
- */
- public function appendToHead($content) {
- $this->head .= $content;
- }
- /**
- * Ajouter un contenu CSS dans head
- * @param string $css Le contenu CSS à ajouter
- * @return void
- */
- public function appendCss($css) {
- $this->head .= "<style>$css</style>";
- }
- /**
- * Ajouter l'URL d'un script CSS dans head
- * @param string $url L'URL du script CSS
- * @return void
- */
- public function appendCssUrl($url) {
- $this->head .= "<link href='$url' rel='stylesheet' type='text/css'>";
- }
- /**
- * Ajouter un contenu JavaScript dans head
- * @param string $js Le contenu JavaScript à ajouter
- * @return void
- */
- public function appendJs($js) {
- $this->head .= "<script type='text/javascript' language='JavaScript'>$js</script>";
- }
- /**
- * Ajouter l'URL d'un script JavaScript dans head
- * @param string $url L'URL du script JavaScript
- * @return void
- */
- public function appendJsUrl($url) {
- $this->head .= "<script type='text/javascript' language='JavaScript' src='$url'></script>";
- }
- /**
- * Ajouter un contenu dans body
- * @param string $content Le contenu à ajouter
- * @return void
- */
- public function appendContent($content) {
- $this->body .= $content;
- }
- /**
- * Produire la page Web complète
- * @return string
- */
- public function toHTML() {
- return "$this->head"."$this->title"."</head><body>"."$this->body"."</body></html>";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment