layout = new qJerry('./layout.xml'); $this->langs = new qJerry('./langs.xml'); // detect output language $defaultLang = $this->langs->children("lang[@default='yes']")->attr('id'); $lang = isset($_GET['lang']) ? $_GET['lang'] : $defaultLang; if(!$this->langs->children("lang[@id='$lang']")->length) $lang = $defaultLang; $this->lang = $lang; $this->dict = $this->langs->children("lang[@id='$this->lang']")->children('dictionary'); // load content $this->content = new qJerry("./site.{$this->lang}.xml"); $this->news = new qJerry("./news.{$this->lang}.xml"); $this->release = new qJerry('./release.xml'); $this->counters = new qJerry('./counters.xml'); } private function layout() { $this->layout-> // set document type doctype('html', self::DTD_PUBLIC, self::DTD_SYSTEM)-> // set main page title find('head/title')->text($this->content->children('title')->text())-> // set keywords meta siblings("@name='keywords'")->attr('content', $this->content->children('keywords')->text())-> // set description meta siblings("@name='description'")->attr('content', $this->content->children('description')->text())->root()-> // set h1 title find('body/h1')->text($this->content->children('title')->text())-> // output intro siblings("@id='intro'")->append($this->content->children('content')->children()); } private function languages() { $langs = $this->layout->find("body//div[@id='langs']"); foreach($this->langs->children() as $lang) { $langCode = $lang->attr('id'); $langName = $lang->attr('name'); if($langCode == $this->lang) $langs->append('span')->text($langName); else { $href = $langCode == key($this->langs) ? '/' : "?lang=$langCode"; $langs->append('a')->attr('href', $href)->text($langName); } } } private function toc() { $ol = $this->layout->find("body//div[@id='toc']")->append('ol'); foreach($this->content->children('section') as $section) $ol->append('li')-> append('a')->attr('href', '#'.$section->attr('id'))->text($section->children('name')->text()); } private function content() { $sections = $this->layout->children("body//div[@id='content']"); foreach($this->content->children('section') as $section) $sections->append('div')->attr('class', 'section')-> append('a')->attr('name', $section->attr('id'))-> after('h2')->text($section->children('title')->text())->parent()-> append($section->children('content')->children())->parent()-> append('p')->attr('class', 'top')-> append('a')->attr('href', '#top')->text($this->dict->children('top')->text())->parent()-> appendText(' ↑'); } private function download() { $download = $this->layout->find("body//div[@id='download']"); $download-> append('h3')->text($this->dict->children('download')->text())-> after('p')->text($this->dict->children('current')->text().': ')-> append('a')->attr('href', $this->release->children('link')->text())-> attr('target', '_blank')-> text($this->release->children('title')->text())->parent()-> appendText(' ')->append('span')->attr('class', 'rdate')->text('('.$this->release->attr('date').')')->parent()-> appendText('.'); $download->append('p')-> append('a')->attr('href', $this->release->children('changes')->text())-> attr('target', '_blank')-> text($this->dict->children('changes')->text())->parent()-> appendText('.'); } private function news() { $news = $this->layout->find("body//div[@id='news']"); $news->append('h3')->text($this->dict->children('news')->text()); foreach($this->news->children('message') as $message) $news->append('dl')-> append('dt')-> append('span')->attr('class', 'title')->text($message->children('title')->text())-> after('br')-> after('span')->attr('class', 'rdate')->text($message->attr('date'))->parent()-> after('dd')-> append($message->children('content')->children()); } private function footer() { $this->layout->children('body')->append($this->counters->children()); } public function render() { $this->layout(); // populate template with generic data $this->languages(); // language selector $this->toc(); // table of contents $this->content(); // content sections $this->download(); // download block $this->news(); // news block $this->footer(); // counter } public function output() { // implicitly called qJerry::__toString() method echo $this->layout->format(); } } try { $site = new qJerrySite(); $site->render(); $site->output(); } catch(qJException $ex) { echo "Oops! ".$ex->getMessage(); } catch(Exception $ex) { echo "WTF? ".$ex->getMessage(); } ?>