From f4de82bcdafba51e4eed9cae6b2d3e5375ffd115 Mon Sep 17 00:00:00 2001
From: xue <>
Date: Tue, 9 May 2006 12:11:38 +0000
Subject:
---
demos/quickstart/protected/pages/ViewSource.php | 90 ++++++++++++++++---------
1 file changed, 58 insertions(+), 32 deletions(-)
(limited to 'demos/quickstart/protected/pages/ViewSource.php')
diff --git a/demos/quickstart/protected/pages/ViewSource.php b/demos/quickstart/protected/pages/ViewSource.php
index cfdc63ef..9a8d7d09 100644
--- a/demos/quickstart/protected/pages/ViewSource.php
+++ b/demos/quickstart/protected/pages/ViewSource.php
@@ -6,19 +6,6 @@ class ViewSource extends TPage
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)
{
parent::onLoad($param);
@@ -35,49 +22,88 @@ class ViewSource extends TPage
}
if($this->_fullPath===null)
throw new THttpException(500,'File Not Found: %s',$path);
+
+ $this->SourceList->DataSource=$this->SourceFiles;
+ $this->SourceList->dataBind();
+
+ $this->Highlighter->Language=$this->getFileLanguage($fileExt);
+ $this->SourceView->Text=file_get_contents($this->_fullPath);
+ }
+
+ public function getFilePath()
+ {
+ return $this->_path;
+ }
+
+ protected function getSourceFiles()
+ {
+ $list=array();
$basePath=dirname($this->_fullPath);
if($dh=opendir($basePath))
{
- $str="
{$this->_path}
\n";
while(($file=readdir($dh))!==false)
{
if(is_file($basePath.'/'.$file))
{
- $fileType=$this->getFileExtension($basePath.'/'.$file);
- if($this->isFileTypeAllowed($fileType))
+ $extension=$this->getFileExtension($basePath.'/'.$file);
+ if($this->isFileTypeAllowed($extension))
{
- if($fileType==='tpl' || $fileType==='page')
- $type='Template file';
- else
- $type='Class file';
- $path='/'.ltrim(strtr(dirname($this->_path),'\\','/').'/'.$file,'/');
- $str.="$type: $file
";
+ $fileType=$this->getFileType($extension);
+ $list[]=array(
+ 'name'=>$file,
+ 'type'=>$fileType,
+ 'active'=>basename($this->_fullPath)===$file,
+ 'url'=>'?page=ViewSource&path=/'.ltrim(strtr(dirname($this->_path),'\\','/').'/'.$file,'/')
+ );
}
}
}
closedir($dh);
- $this->SourceList->Text=$str;
}
+ foreach($list as $item)
+ $aux[]=$item['name'];
+ array_multisort($aux, SORT_ASC, $list);
+ return $list;
+ }
- switch($fileExt)
+ protected function isFileTypeAllowed($extension)
+ {
+ return in_array($extension,array('tpl','page','php','html'));
+ }
+
+ protected function getFileExtension($fileName)
+ {
+ if(($pos=strrpos($fileName,'.'))===false)
+ return '';
+ else
+ return substr($fileName,$pos+1);
+ }
+
+ protected function getFileType($extension)
+ {
+ if($extension==='tpl' || $extension==='page')
+ return 'Template file';
+ else
+ return 'Class file';
+ }
+
+ protected function getFileLanguage($extension)
+ {
+ switch($extension)
{
case 'page' :
case 'tpl' :
- $this->Highlighter->Language='prado';
- break;
+ return 'prado';
case 'php' :
- $this->Highlighter->Language='php';
+ return 'php';
break;
case 'xml' :
- $this->Highlighter->Language='xml';
+ return 'xml';
break;
default :
- $this->Highlighter->Language='html';
- break;
+ return 'html';
}
-
- $this->SourceView->Text=file_get_contents($this->_fullPath);
}
}
--
cgit v1.2.3