diff options
author | xue <> | 2005-12-24 17:14:39 +0000 |
---|---|---|
committer | xue <> | 2005-12-24 17:14:39 +0000 |
commit | da3e4e99d6a2e3b2c9591d969cb63d61a6114eee (patch) | |
tree | 4010a24fa28e4878d23f8301c4b7b79b699be1b5 /demos/quickstart/protected/pages/ViewSource.php | |
parent | 0401be173cd1f80785c09f3a1dfae79d54441197 (diff) |
Diffstat (limited to 'demos/quickstart/protected/pages/ViewSource.php')
-rw-r--r-- | demos/quickstart/protected/pages/ViewSource.php | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/demos/quickstart/protected/pages/ViewSource.php b/demos/quickstart/protected/pages/ViewSource.php new file mode 100644 index 00000000..9509e400 --- /dev/null +++ b/demos/quickstart/protected/pages/ViewSource.php @@ -0,0 +1,66 @@ +<?php
+
+class ViewSource extends TPage
+{
+ 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)
+ {
+ parent::onLoad($param);
+ $path=$this->Request->Items['path'];
+ $fullPath=realpath($this->Service->BasePath.'/'.$path);
+ if($fullPath!==false && is_file($fullPath) && strpos($fullPath,$this->Service->BasePath)!==false)
+ {
+ if($this->isFileTypeAllowed($this->getFileExtension($fullPath)))
+ {
+ $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="<h4>{$this->_path}</h4>\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;
+ }
+
+ $this->SourceView->Text=highlight_string(file_get_contents($this->_fullPath),true);
+ }
+}
+
+?>
\ No newline at end of file |