diff options
author | xue <> | 2006-05-09 12:11:38 +0000 |
---|---|---|
committer | xue <> | 2006-05-09 12:11:38 +0000 |
commit | f4de82bcdafba51e4eed9cae6b2d3e5375ffd115 (patch) | |
tree | 08f98e1763e87f0639961c6da33224082345c7c3 /demos/quickstart/protected/pages/ViewSource.php | |
parent | 92dca3315f083f00dcff610ea207af52284d0616 (diff) |
Diffstat (limited to 'demos/quickstart/protected/pages/ViewSource.php')
-rw-r--r-- | demos/quickstart/protected/pages/ViewSource.php | 90 |
1 files changed, 58 insertions, 32 deletions
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="<h2>{$this->_path}</h2>\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: <a href=\"?page=ViewSource&path=$path\">$file</a><br/>";
+ $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);
}
}
|