Vangar

Page Generation

Dec 11th, 2011
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.52 KB | None | 0 0
  1. <?php
  2.  
  3. class page {
  4.  
  5.     private $head;
  6.     private $body;
  7.  
  8.     public function __construct(){
  9.         $this->head = array('scripts'=>array(),'styles'=>array());
  10.         $this->body = '';
  11.     }
  12.  
  13.     public function addStylesheet($link) {
  14.         $this->head['styles'][] = $link;
  15.     }
  16.  
  17.     public function addScript($link) {
  18.         $this->head['scripts'][] = $link;
  19.     }
  20.  
  21.     public function setBody($content) {
  22.         $this->body = $content;
  23.     }
  24.  
  25.     public function buildOutput() {
  26.         $c_styles = count($this->head['styles']);
  27.         $c_scripts = count($this->head['scripts']);
  28.         $styles = '';
  29.         $scripts = '';
  30.  
  31.         for ($i = 0; $i < $c_styles; $i++) {
  32.             $styles .= '<link rel="stylesheet" type="text/css" href="'.$this->head['styles'][$i].'" />'."\n";
  33.         }
  34.  
  35.         for ($i = 0; $i < $c_scripts; $i++) {
  36.             $scripts .= '<script src="'.$this->head['scripts'][$i].'"></script>'."\n";
  37.         }
  38.  
  39.         $html = "
  40. <html>
  41. <head>
  42. $styles
  43. $scripts
  44. </head>
  45. <body>
  46. $this->body
  47. </body>
  48. </html>
  49. ";
  50.         return $html;
  51.     }
  52.  
  53. }
  54.  
  55. $page = new page;
  56.  
  57. $page->addStylesheet('http://www.example.com/my.css');
  58. $page->addStylesheet('http://www.example.com/their.css');
  59. $page->addScript('http://www.example.com/my.js');
  60. $page->addScript('http://www.example.com/their.js');
  61. $page->setBody('<p>This is my body</p>');
  62.  
  63. echo $page->buildOutput();
  64.  
  65. // Jesus that's right, $html = include(structure.php) !!!!!!!! fuck im an idiot and should sleep now.
  66.  
  67. ?>
  68.  
  69.  
Advertisement
Add Comment
Please, Sign In to add comment