summaryrefslogtreecommitdiff
path: root/demos/quickstart/protected/pages/DetailPage.php
blob: afd81272f45f27b86ec3faba10dfbdf79703062f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php

class DetailPage extends TPage
{
	private $_file;

	public function onLoad($param)
	{
		parent::onLoad($param);
		$isSrc=true;
		if(($id=$this->Request->Items['src'])===null)
			$this->_file=$this->determineFile($this->Request->Items['tpl'],false);
		else
			$this->_file=$this->determineFile($id,true);
	}

	protected function determineFile($id,$isSrcFile)
	{
		$basePath=dirname(__FILE__).'/controls';

		$xml=new TXmlDocument;
		$xml->loadFromFile($basePath.'/config.xml');
		$pages=$xml->getElementByTagName('pages')->getElementsByTagName('page');
		$fileName='';
		foreach($pages as $page)
		{
			if($page->Attributes['id']===$id)
			{
				if($isSrcFile)
					$fileName=$basePath.'/'.$page->Attributes['class'].'.php';
				else if($page->Attributes['TemplateFile']!==null)
				{
					$fileName=$page->Attributes['TemplateFile'];
					if(($pos=strrpos($fileName,'.'))!==false)
						$fileName=substr($fileName,$pos+1);
					$fileName=$basePath.'/'.$fileName.'.tpl';
				}
				else
					$fileName=$basePath.'/'.$page->Attributes['class'].'.tpl';
				break;
			}
		}
		if(empty($fileName) || !is_file($fileName))
			throw new THttpException(500,"File not exists!");
		return $fileName;
	}

	protected function render($writer)
	{
		$contents=file_get_contents($this->_file);
		$writer->write(highlight_string($contents,true));
	}
}

?>