Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class LibraryRenderer{
- public $menu;
- public $movies;
- private $library;
- public function __construct($library){
- $this->library = $library;
- }
- public function render(){
- $html[] = "<!doctype html>";
- $html[] = "<html>";
- $html[] = $this->getHead();
- $html[] = $this->getBody();
- $html[] = "</html>";
- return $this->getHtmlString($html);
- }
- private function getHead(){
- $head[] = "<head>";
- $head[] = "<title>Library</title>";
- foreach ($this->library->css as $css){
- $head[] = '<link rel="stylesheet" type="text/css" href="'.$css.'">';
- }
- foreach ($this->library->javascript as $javascript){
- $head[] = '<script type="text/javascript" src="'.$javascript.'"></script>';
- }
- $head[] = "</head>";
- return $head;
- }
- private function getBody(){
- $body[] = "<body>";
- $body[] = '<nav id="main-nav">';
- foreach($this->menu as $menu){
- $body[] = '<a href="?folder='.$menu.'">'.$menu.'</a>';
- }
- $body[] = "</nav>";
- $body[] = "<section>";
- foreach($this->movies as $movie){
- $body[] = '<article class="movie">';
- $body[] = '<img src="'.$movie['img'].'">';
- $body[] = '<h3>'.$movie['name'].'</h3>';
- $body[] = '<ul>';
- $body[] = '<li>Videos</li>';
- $body[] = '<ul>';
- foreach($movie['video'] as $video){
- $body[] = '<li>'.$video['name'].'</li>';
- }
- $body[] = '</ul>';
- $body[] = '<li>Subtitles</li>';
- $body[] = '<ul>';
- foreach($movie['subtitles'] as $subtitle){
- $body[] = '<li>'.$subtitle['name'].'</li>';
- }
- $body[] = '</ul>';
- $body[] = '</ul>';
- $body[] = '</article>';
- }
- $body[] = "</section>";
- $body[] = "</body>";
- return $body;
- }
- private function getHtmlString($array){
- foreach($array as $html){
- if(is_array($html)){
- $string .= $this->getHtmlString($html);
- }else{
- $string .= $html;
- }
- }
- return $string;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement