[ Index ] |
PHP Cross Reference of PHK Manager |
[Summary view] [Print] [Text view]
1 <?php 2 //============================================================================= 3 // 4 // Copyright Francois Laupretre <phk@tekwire.net> 5 // 6 // Licensed under the Apache License, Version 2.0 (the "License"); 7 // you may not use this file except in compliance with the License. 8 // You may obtain a copy of the License at 9 // 10 // http://www.apache.org/licenses/LICENSE-2.0 11 // 12 // Unless required by applicable law or agreed to in writing, software 13 // distributed under the License is distributed on an "AS IS" BASIS, 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 // See the License for the specific language governing permissions and 16 // limitations under the License. 17 // 18 //============================================================================= 19 /** 20 * @copyright Francois Laupretre <phk@tekwire.net> 21 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, V 2.0 22 * @category PHK 23 * @package PHK 24 *///========================================================================== 25 26 namespace PHK\Web { 27 28 if (!class_exists('PHK\Web\Info',false)) 29 { 30 //============================================================================ 31 /** 32 * Web info 33 * 34 * This class handles the 'webinfo' mode 35 * 36 * API status: Private 37 * Included in the PHK PHP runtime: Yes 38 * Implemented in the extension: No 39 *///========================================================================== 40 41 class Info 42 { 43 private $PHK; // Associated PHK instance 44 45 private $cmd_titles=array( 46 'info' => 'Home', 47 'techinfo' => 'Technical information', 48 'showmap' => 'Symbol map', 49 'showfiles' => 'Files', 50 'test' => 'Unit tests'); 51 52 //---- 53 54 public function __construct($phk) 55 { 56 $this->PHK=$phk; 57 58 \PHK\Mgr::setCache(false); // Don't cache anything in webinfo mode 59 } 60 61 //---- 62 63 private static function displayTab($url,$name) 64 { 65 echo '<li id="'.$name.'"><a href="'.\PHK::subpathURL($url) 66 .'"><span>'.$name.'</span></a></li>'; 67 } 68 69 //---- 70 71 private function header($title=null) 72 { 73 if (is_null($name=$this->PHK->option('name'))) 74 $name=basename($this->PHK->path()); 75 $win_title=(is_null($title) ? $name : "$name - $title"); 76 77 echo '<head>' 78 ."<title>$win_title</title>" 79 .'<link href="'.\PHK::subpathURL('/php_section/STATIC/tabs/tabs.css.php') 80 .'" rel="stylesheet" type="text/css">' 81 ."<style type=text/css><!--\n" 82 ."a,a:active,a:link { color: blue; text-decoration: none; }\n" 83 ."a:hover { color: blue; text-decoration: underline; }\n" 84 .'--></style>' 85 ."</head>\n"; 86 87 echo '<table width=100% border=0 cellpadding=0 cellspacing=0>'; 88 89 //-- Tabs 90 91 echo '<tr><td><div class="tabs"><ul>'; 92 93 self::displayTab('/info','Home'); 94 95 if (!is_null($this->PHK->option('help_prefix'))) 96 self::displayTab('/autoOption/help','Help'); 97 98 if (!is_null($this->PHK->option('license_prefix'))) 99 self::displayTab('/autoOption/license','License'); 100 101 self::displayTab('/techinfo','Info'); 102 self::displayTab('/showfiles','Files'); 103 104 if ($this->PHK->mapDefined()) 105 self::displayTab('/showmap','Symbol map'); 106 107 if ((!is_null($this->PHK->option('test_script'))) 108 ||(!is_null($this->PHK->option('phpunit_test_package')))) 109 self::displayTab('/test','Tests'); 110 111 //-- Package specific tabs 112 113 if (!is_null($tabs=$this->PHK->option('tabs'))) 114 foreach($tabs as $n => $url) self::displayTab($url,$n); 115 116 echo '</ul></div></td></tr>'; 117 118 //-- 119 120 $bg_string=(is_null($opt=$this->PHK->option('icon_bgcolor')) 121 ? '' : 'bgcolor="'.$opt.'"'); 122 123 if (is_null($icon_width=$this->PHK->option('icon_width'))) $icon_width='150'; 124 125 echo '<tr><td width=100%><table width=100% border=1 bordercolor="#aaaaaa"' 126 .' cellpadding=3 cellspacing=0>'; 127 echo "<tr><td width=$icon_width $bg_string align=center>"; 128 129 $url=$this->PHK->option('url'); 130 if (!is_null($url)) echo '<a href="'.$url.'" target=_blank>'; 131 if (!is_null($icon_path=$this->PHK->option('icon'))) 132 echo '<img border=0 src="'.\PHK::subpathURL('/file/'.trim($icon_path,'/')) 133 .'" alt="Package Home">'; 134 elseif (!is_null($url)) echo '<Website>'; 135 if (!is_null($url)) echo '</a>'; 136 echo "</td>\n"; 137 138 echo '<td bgcolor="#D7E2FF" align=center><h1>'.$name.'</h1></td>'; 139 140 echo '<td width=151 align=center><a href="http://phk.tekwire.net"' 141 .' target=_blank><img width=151 height=88 border=0 src="' 142 .\PHK::subpathURL('/section/STATIC/phk_logo.png') 143 .'" alt="PHK Home"></a></td>'; 144 echo '</tr>'; 145 146 echo '</table></td></tr></table>'; 147 148 // Page title 149 150 if (!is_null($title)) echo "<p><h1>$title</h1>"; 151 @flush(); //-- Tries to flush the header as the command can be quite long 152 } 153 154 //---- 155 156 public function run() 157 { 158 #-- Debug mode 159 160 if (isset($_REQUEST['debug'])) 161 { 162 echo "<hr>"; 163 echo "<h2>Environment:</h2>"; 164 165 echo "<h3>_REQUEST :</h3>"; 166 echo "<pre>"; 167 var_dump($_REQUEST); 168 echo "</pre>"; 169 170 echo "<h3>_SERVER :</h3>"; 171 echo "<pre>"; 172 print_r($_SERVER); 173 echo "</pre>"; 174 } 175 176 #-- Get the command and optional arg. Supports both URL formats 177 178 $command=trim(\PHK::setSubpath(),'/'); 179 if (($pos=strpos($command,'/'))!==false) 180 { 181 $arg=substr($command,$pos+1); 182 $command=substr($command,0,$pos); 183 } 184 else $arg=''; 185 186 if ($command=='') $command='info'; //-- Default command 187 188 #-- Run command 189 190 self::sendCacheHeader(); 191 192 switch($command) 193 { 194 case 'view': 195 $arg='/'.$arg; 196 $this->header("File: $arg"); 197 $path=$this->PHK->uri($arg); 198 if (!is_file($path)) 199 { 200 echo '* ERROR: '.$arg.': File not found<p>'; 201 break; 202 } 203 204 echo "<table border=0>\n"; 205 echo '<tr><td>Size:</td><td>'.filesize($path).'</td></tr>'; 206 echo '<tr><td>Storage flags:</td><td>' 207 .$this->PHK->proxy()->ftree()->lookup($arg)->flagString().'</td></tr>'; 208 echo "</table><hr/>"; 209 210 switch($mime_type=$this->PHK->mimeType($arg)) 211 { 212 case 'application/x-httpd-php': 213 highlight_file($path); 214 break; 215 216 case 'text/html': 217 echo \PHK\Tools\Util::readFile($path); 218 break; 219 220 default: 221 if (strpos($mime_type,'image/')===0) // Is it an image ? 222 echo 'Image: <img src="'.\PHK::subpathURL('/file'.$arg).'">'; 223 else echo '<pre>'.htmlspecialchars(\PHK\Tools\Util::readFile($path)) 224 .'</pre>'; 225 } 226 break; 227 228 case 'run': 229 $this->header(); 230 eval($this->PHK->webTunnel($arg,true)); 231 break; 232 233 case 'file': // Bare file 234 eval($this->PHK->webTunnel($arg,true)); 235 return; // Don't put anything after the file 236 237 case 'info': 238 case 'techinfo': 239 case 'envinfo': 240 case 'showmap': 241 case 'showfiles': 242 case 'test': 243 if (isset($this->cmd_titles[$command])) $t=$this->cmd_titles[$command]; 244 else $t=ucfirst($command); 245 $this->header($t); 246 $this->PHK->$command(array(__CLASS__,'viewSubfileURL')); 247 break; 248 249 case 'autoFile': 250 $this->header(); 251 echo $this->PHK->autoFile('/'.$arg); 252 break; 253 254 case 'autoOption': 255 $this->header(ucfirst($arg)); 256 echo $this->PHK->autoOption($arg); 257 break; 258 259 case 'php_section': 260 require($this->PHK->sectionURI($arg)); 261 return; // Don't put anything after the file 262 263 case 'section': // Bare section (image, css,...) with PHP source auto-exec 264 eval($this->PHK->webTunnel('/?section&name='.$arg,true)); 265 return; // Don't put anything after the file 266 267 default: 268 echo '<b>'.$command.': Unknown subcommand</b><p>'; 269 } 270 271 self::footer(); 272 } 273 274 //---- 275 // Convert a subfile path to an URL. Needed because Automap must not 276 // directly reference PHK or \PHK\Web\Info (to avoid cyclic dependencies). 277 278 public static function viewSubfileURL($fname) 279 { 280 return \PHK::subpathURL('/view/'.trim($fname,'/')); 281 } 282 283 //---- 284 // Set headers to cache this url during 10 mins 285 // Taken from http-conditional (http://alexandre.alapetite.net) 286 // very important because, if it not sent, tabs background images are not 287 // cached by the browser. 288 // Unfortunately, since we had to change the syntax of webinfo URLs to be 289 // compatible with PHP in CGI mode, most browsers won't cache URLs containing 290 // a '?' char. 291 292 private static function sendCacheHeader() 293 { 294 header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T',time()+600)); 295 header('Cache-Control: public, max-age=600'); //rfc2616-sec14.html#sec14.9 296 header('Last-Modified: '.gmdate('D, d M Y H:i:s \G\M\T',time())); 297 } 298 299 //---- 300 301 private static function footer() 302 { 303 echo '<hr>'; 304 echo '<font size="-1"><i>For more information about the PHK package format:' 305 .' <a href="http://phk.tekwire.net" target="_blank">' 306 .'http://phk.tekwire.net</i></font>'; 307 } 308 309 //--- 310 } // End of class 311 //=========================================================================== 312 } // End of class_exists 313 //=========================================================================== 314 } // End of namespace 315 //=========================================================================== 316 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jun 4 18:33:15 2015 | Cross-referenced by PHPXref 0.7.1 |