javascriptcursus/php/bookpage.php

<?php require_once 'page.php'; class subChapter { // Public: public $chapter; public $subChapter; public $text; public function __construct($chapter, $subChapter) { $this->chapter = $chapter; $this->subChapter = $subChapter; $this->text = null; } public function title($withChapterNumbers = true) { if($withChapterNumbers) return "{$this->chapter}.{$this->subChapter}. ".$GLOBALS['chapter_titles'][$this->chapter][$this->subChapter]; else return $GLOBALS['chapter_titles'][$this->chapter][$this->subChapter]; } }; class bookpage extends page { // Public: public function __construct($chapter) { parent::__construct($GLOBALS['chapter_titles'][$chapter][0]." (hoofdstuk $chapter)"); $this->chapter = $chapter; $this->mainText = null; $this->subChapters = array(); } public function flushContent() { $this->flushCode(); $count; if(($count = count($this->subChapters)) == 0) $this->mainText = $this->content; else $this->subChapters[$count-1]->text .= $this->content; $this->content = null; } public function nextSubChapter() { $this->flushContent(); array_push($this->subChapters, new subChapter($this->chapter, count($this->subChapters)+1)); } public function printAll() { $this->flushContent(); $this->content .= $this->mainText; foreach($this->subChapters as $subChapter) { $this->content .= "<a class=\"to-top\" href=\"#H{$this->chapter}.0\">Naar boven</a><h2 id=\"H{$subChapter->chapter}.{$subChapter->subChapter}\">".$subChapter->title().'</h2>'; $this->content .= $subChapter->text; } parent::printAll(); } // Protected: protected $chapter; protected $mainText; protected $subChapters; protected function generateH1() { return "<h1 id=\"H{$this->chapter}.0\">{$this->chapter}. ".$GLOBALS['chapter_titles'][$this->chapter][0]."</h1>"; } }; ?>

Resultaat

Made by Thijs Aarnoudse