diff options
author | ctrlaltca <> | 2012-07-12 11:21:01 +0000 |
---|---|---|
committer | ctrlaltca <> | 2012-07-12 11:21:01 +0000 |
commit | 903ae8a581fac1e6917fc3e31d2ad8fb91df80c3 (patch) | |
tree | e08bf04f0823650a231227ac3499121270172a23 /demos/quickstart/protected/pages/ViewSource.php | |
parent | 3e4e6e66aeb3f8fea4e1eb4237498ef9d2358f63 (diff) |
standardize the use of unix eol; use svn properties to enforce native eol
Diffstat (limited to 'demos/quickstart/protected/pages/ViewSource.php')
-rw-r--r-- | demos/quickstart/protected/pages/ViewSource.php | 222 |
1 files changed, 111 insertions, 111 deletions
diff --git a/demos/quickstart/protected/pages/ViewSource.php b/demos/quickstart/protected/pages/ViewSource.php index f267f318..2bbcf097 100644 --- a/demos/quickstart/protected/pages/ViewSource.php +++ b/demos/quickstart/protected/pages/ViewSource.php @@ -1,112 +1,112 @@ -<?php
-
-class ViewSource extends TPage
-{
- private $_path=null;
- private $_fullPath=null;
- private $_fileType=null;
-
- public function onLoad($param)
- {
- parent::onLoad($param);
- $path=$this->Request['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);
-
- $this->SourceList->DataSource=$this->SourceFiles;
- $this->SourceList->dataBind();
-
- $this->Highlighter->Language=$this->getFileLanguage($fileExt);
- if($this->Request['lines']==='false')
- $this->Highlighter->ShowLineNumbers=false;
- $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))
- {
- while(($file=readdir($dh))!==false)
- {
- if(is_file($basePath.'/'.$file))
- {
- $extension=$this->getFileExtension($basePath.'/'.$file);
- if($this->isFileTypeAllowed($extension))
- {
- $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);
- }
- foreach($list as $item)
- $aux[]=$item['name'];
- array_multisort($aux, SORT_ASC, $list);
- return $list;
- }
-
- 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' :
- return 'prado';
- case 'php' :
- return 'php';
- break;
- case 'xml' :
- return 'xml';
- break;
- default :
- return 'html';
- }
- }
-}
-
+<?php + +class ViewSource extends TPage +{ + private $_path=null; + private $_fullPath=null; + private $_fileType=null; + + public function onLoad($param) + { + parent::onLoad($param); + $path=$this->Request['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); + + $this->SourceList->DataSource=$this->SourceFiles; + $this->SourceList->dataBind(); + + $this->Highlighter->Language=$this->getFileLanguage($fileExt); + if($this->Request['lines']==='false') + $this->Highlighter->ShowLineNumbers=false; + $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)) + { + while(($file=readdir($dh))!==false) + { + if(is_file($basePath.'/'.$file)) + { + $extension=$this->getFileExtension($basePath.'/'.$file); + if($this->isFileTypeAllowed($extension)) + { + $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); + } + foreach($list as $item) + $aux[]=$item['name']; + array_multisort($aux, SORT_ASC, $list); + return $list; + } + + 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' : + return 'prado'; + case 'php' : + return 'php'; + break; + case 'xml' : + return 'xml'; + break; + default : + return 'html'; + } + } +} + ?>
\ No newline at end of file |