diff options
author | wei <> | 2006-01-15 11:04:00 +0000 |
---|---|---|
committer | wei <> | 2006-01-15 11:04:00 +0000 |
commit | abc5bbd9c771dcecfa41ba3590cce1c1ef190cdd (patch) | |
tree | 45884a9f15efb190144165d50f79bab6fa914494 /tests/FunctionalTests/protected/pages | |
parent | 5af330b442f15be0f0535a9e3c053b8e6eb5a202 (diff) |
Diffstat (limited to 'tests/FunctionalTests/protected/pages')
-rw-r--r-- | tests/FunctionalTests/protected/pages/Layout.tpl | 2 | ||||
-rw-r--r-- | tests/FunctionalTests/protected/pages/ViewSource.page | 7 | ||||
-rw-r--r-- | tests/FunctionalTests/protected/pages/ViewSource.php | 79 |
3 files changed, 83 insertions, 5 deletions
diff --git a/tests/FunctionalTests/protected/pages/Layout.tpl b/tests/FunctionalTests/protected/pages/Layout.tpl index 36fabe71..9a798b3c 100644 --- a/tests/FunctionalTests/protected/pages/Layout.tpl +++ b/tests/FunctionalTests/protected/pages/Layout.tpl @@ -27,7 +27,7 @@ <a href="http://validator.w3.org/check?uri=referer">
Validate XHTML 1.0
</a>
-<a href="?page=ViewSource&source=<%= $this->Request->ServiceParameter %>"
+<a href="?page=ViewSource&path=<%= str_replace('.','/', $this->Request->ServiceParameter) %>.page"
style="margin: 0 1em;"
onclick="window.open(this.href); return false;"
onkeypress="window.open(this.href); return false;">View Source</a>
diff --git a/tests/FunctionalTests/protected/pages/ViewSource.page b/tests/FunctionalTests/protected/pages/ViewSource.page index 900c45f6..218cc901 100644 --- a/tests/FunctionalTests/protected/pages/ViewSource.page +++ b/tests/FunctionalTests/protected/pages/ViewSource.page @@ -6,13 +6,18 @@ </com:THead>
<body>
+<com:TForm>
<div id="sourceList">
<com:TLiteral ID="SourceList" />
+<com:TCheckBox ID="showLineNumbers" AutoPostBack="true" />
+<com:TLabel For="showLineNumbers">Show Line Numbers</com:TLabel>
</div>
<div id="sourceView">
-<com:TTextHighlighter ID="Highlighter" ShowLineNumbers="true" CssClass="source">
+<com:TTextHighlighter ID="Highlighter" CssClass="source"
+ ShowLineNumbers="<%# $this->Page->showLineNumbers->Checked %>" >
<com:TLiteral ID="SourceView" />
</com:TTextHighlighter>
+</com:TForm>
</div>
</body>
</html>
\ No newline at end of file diff --git a/tests/FunctionalTests/protected/pages/ViewSource.php b/tests/FunctionalTests/protected/pages/ViewSource.php index eeaf0f80..84f39161 100644 --- a/tests/FunctionalTests/protected/pages/ViewSource.php +++ b/tests/FunctionalTests/protected/pages/ViewSource.php @@ -2,10 +2,83 @@ class ViewSource extends TPage
{
- protected function onLoad($param)
+ private $_path=null;
+ private $_fullPath=null;
+ private $_fileType=null;
+
+ protected function isFileTypeAllowed($extension)
+ {
+ return in_array($extension,array('tpl','page','php'));
+ }
+
+ protected function getFileExtension($fileName)
+ {
+ if(($pos=strrpos($fileName,'.'))===false)
+ return '';
+ else
+ return substr($fileName,$pos+1);
+ }
+
+ public function onLoad($param)
{
- $pageName = $this->Request->getParameter("source");
- var_dump($pageName);
+ parent::onLoad($param);
+ $path=$this->Request->Items['path'];
+ $fullPath=realpath($this->Service->BasePath.'/'.$path);
+ $fileExt=$this->getFileExtension($fullPath);
+ if($fullPath!==false && is_file($fullPath) && strpos($fullPath,$this->Service->BasePath)!==false)
+ {
+ if($this->isFileTypeAllowed($fileExt))
+ {
+ $this->_fullPath=strtr($fullPath,'\\','/');
+ $this->_path=strtr(substr($fullPath,strlen($this->Service->BasePath)),'\\','/');
+ }
+ }
+ if($this->_fullPath===null)
+ throw new THttpException(500,'File Not Found: %s',$path);
+ $basePath=dirname($this->_fullPath);
+ if($dh=opendir($basePath))
+ {
+ $str="<h2>{$this->_path}</h2>\n";
+ while(($file=readdir($dh))!==false)
+ {
+ if(is_file($basePath.'/'.$file))
+ {
+ $fileType=$this->getFileExtension($basePath.'/'.$file);
+ if($this->isFileTypeAllowed($fileType))
+ {
+ if($fileType==='tpl' || $fileType==='page')
+ $type='Template file';
+ else
+ $type='Class file';
+ $path='/'.ltrim(strtr(dirname($this->_path),'\\','/').'/'.$file,'/');
+ $str.="$type: <a href=\"?page=ViewSource&path=$path\">$file</a><br/>";
+ }
+ }
+
+ }
+ closedir($dh);
+ $this->SourceList->Text=$str;
+ }
+
+ switch($fileExt)
+ {
+ case 'page' :
+ case 'tpl' :
+ $this->Highlighter->Language='prado';
+ break;
+ case 'php' :
+ $this->Highlighter->Language='php';
+ break;
+ case 'xml' :
+ $this->Highlighter->Language='xml';
+ break;
+ default :
+ $this->Highlighter->Language='html';
+ break;
+ }
+
+ $this->SourceView->Text=file_get_contents($this->_fullPath);
+ $this->dataBind();
}
}
|