[ Index ] |
|
Code source de PRADO 3.0.6 |
1 <?php 2 3 class ViewSource extends TPage 4 { 5 private $_path=null; 6 private $_fullPath=null; 7 private $_fileType=null; 8 9 public function onLoad($param) 10 { 11 parent::onLoad($param); 12 $path=$this->Request['path']; 13 $fullPath=realpath($this->Service->BasePath.'/'.$path); 14 $fileExt=$this->getFileExtension($fullPath); 15 if($fullPath!==false && is_file($fullPath) && strpos($fullPath,$this->Service->BasePath)!==false) 16 { 17 if($this->isFileTypeAllowed($fileExt)) 18 { 19 $this->_fullPath=strtr($fullPath,'\\','/'); 20 $this->_path=strtr(substr($fullPath,strlen($this->Service->BasePath)),'\\','/'); 21 } 22 } 23 if($this->_fullPath===null) 24 throw new THttpException(500,'File Not Found: %s',$path); 25 26 $this->SourceList->DataSource=$this->SourceFiles; 27 $this->SourceList->dataBind(); 28 29 $this->Highlighter->Language=$this->getFileLanguage($fileExt); 30 if($this->Request['lines']==='false') 31 $this->Highlighter->ShowLineNumbers=false; 32 $this->SourceView->Text=file_get_contents($this->_fullPath); 33 } 34 35 public function getFilePath() 36 { 37 return $this->_path; 38 } 39 40 protected function getSourceFiles() 41 { 42 $list=array(); 43 $basePath=dirname($this->_fullPath); 44 if($dh=opendir($basePath)) 45 { 46 while(($file=readdir($dh))!==false) 47 { 48 if(is_file($basePath.'/'.$file)) 49 { 50 $extension=$this->getFileExtension($basePath.'/'.$file); 51 if($this->isFileTypeAllowed($extension)) 52 { 53 $fileType=$this->getFileType($extension); 54 $list[]=array( 55 'name'=>$file, 56 'type'=>$fileType, 57 'active'=>basename($this->_fullPath)===$file, 58 'url'=>'?page=ViewSource&path=/'.ltrim(strtr(dirname($this->_path),'\\','/').'/'.$file,'/') 59 ); 60 } 61 } 62 63 } 64 closedir($dh); 65 } 66 foreach($list as $item) 67 $aux[]=$item['name']; 68 array_multisort($aux, SORT_ASC, $list); 69 return $list; 70 } 71 72 protected function isFileTypeAllowed($extension) 73 { 74 return in_array($extension,array('tpl','page','php','html')); 75 } 76 77 protected function getFileExtension($fileName) 78 { 79 if(($pos=strrpos($fileName,'.'))===false) 80 return ''; 81 else 82 return substr($fileName,$pos+1); 83 } 84 85 protected function getFileType($extension) 86 { 87 if($extension==='tpl' || $extension==='page') 88 return 'Template file'; 89 else 90 return 'Class file'; 91 } 92 93 protected function getFileLanguage($extension) 94 { 95 switch($extension) 96 { 97 case 'page' : 98 case 'tpl' : 99 return 'prado'; 100 case 'php' : 101 return 'php'; 102 break; 103 case 'xml' : 104 return 'xml'; 105 break; 106 default : 107 return 'html'; 108 } 109 } 110 } 111 112 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 21:07:04 2007 | par Balluche grâce à PHPXref 0.7 |