// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // //============================================================================= /** * @copyright Francois Laupretre * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, V 2.0 * @category PHK * @package PHK *///========================================================================== namespace PHK\Web { if (!class_exists('PHK\Web\Info',false)) { //============================================================================ /** * Web info * * This class handles the 'webinfo' mode * * API status: Private * Included in the PHK PHP runtime: Yes * Implemented in the extension: No *///========================================================================== class Info { private $PHK; // Associated PHK instance private $cmd_titles=array( 'info' => 'Home', 'techinfo' => 'Technical information', 'showmap' => 'Symbol map', 'showfiles' => 'Files', 'test' => 'Unit tests'); //---- public function __construct($phk) { $this->PHK=$phk; \PHK\Mgr::setCache(false); // Don't cache anything in webinfo mode } //---- private static function displayTab($url,$name) { echo '
  • '.$name.'
  • '; } //---- private function header($title=null) { if (is_null($name=$this->PHK->option('name'))) $name=basename($this->PHK->path()); $win_title=(is_null($title) ? $name : "$name - $title"); echo '' ."$win_title" .'' ."' ."\n"; echo ''; //-- Tabs echo ''; //-- $bg_string=(is_null($opt=$this->PHK->option('icon_bgcolor')) ? '' : 'bgcolor="'.$opt.'"'); if (is_null($icon_width=$this->PHK->option('icon_width'))) $icon_width='150'; echo '
      '; self::displayTab('/info','Home'); if (!is_null($this->PHK->option('help_prefix'))) self::displayTab('/autoOption/help','Help'); if (!is_null($this->PHK->option('license_prefix'))) self::displayTab('/autoOption/license','License'); self::displayTab('/techinfo','Info'); self::displayTab('/showfiles','Files'); if ($this->PHK->mapDefined()) self::displayTab('/showmap','Symbol map'); if ((!is_null($this->PHK->option('test_script'))) ||(!is_null($this->PHK->option('phpunit_test_package')))) self::displayTab('/test','Tests'); //-- Package specific tabs if (!is_null($tabs=$this->PHK->option('tabs'))) foreach($tabs as $n => $url) self::displayTab($url,$n); echo '
    '; echo "\n"; echo ''; echo ''; echo ''; echo '
    "; $url=$this->PHK->option('url'); if (!is_null($url)) echo ''; if (!is_null($icon_path=$this->PHK->option('icon'))) echo 'Package Home'; elseif (!is_null($url)) echo '<Website>'; if (!is_null($url)) echo ''; echo "

    '.$name.'

    PHK Home
    '; // Page title if (!is_null($title)) echo "

    $title

    "; @flush(); //-- Tries to flush the header as the command can be quite long } //---- public function run() { #-- Debug mode if (isset($_REQUEST['debug'])) { echo "
    "; echo "

    Environment:

    "; echo "

    _REQUEST :

    "; echo "
    ";
    	var_dump($_REQUEST);
    	echo "
    "; echo "

    _SERVER :

    "; echo "
    ";
    	print_r($_SERVER);
    	echo "
    "; } #-- Get the command and optional arg. Supports both URL formats $command=trim(\PHK::setSubpath(),'/'); if (($pos=strpos($command,'/'))!==false) { $arg=substr($command,$pos+1); $command=substr($command,0,$pos); } else $arg=''; if ($command=='') $command='info'; //-- Default command #-- Run command self::sendCacheHeader(); switch($command) { case 'view': $arg='/'.$arg; $this->header("File: $arg"); $path=$this->PHK->uri($arg); if (!is_file($path)) { echo '* ERROR: '.$arg.': File not found

    '; break; } echo "\n"; echo ''; echo ''; echo "
    Size:'.filesize($path).'
    Storage flags:' .$this->PHK->proxy()->ftree()->lookup($arg)->flagString().'


    "; switch($mime_type=$this->PHK->mimeType($arg)) { case 'application/x-httpd-php': highlight_file($path); break; case 'text/html': echo \PHK\Tools\Util::readFile($path); break; default: if (strpos($mime_type,'image/')===0) // Is it an image ? echo 'Image: '; else echo '
    '.htmlspecialchars(\PHK\Tools\Util::readFile($path))
    					.'
    '; } break; case 'run': $this->header(); eval($this->PHK->webTunnel($arg,true)); break; case 'file': // Bare file eval($this->PHK->webTunnel($arg,true)); return; // Don't put anything after the file case 'info': case 'techinfo': case 'envinfo': case 'showmap': case 'showfiles': case 'test': if (isset($this->cmd_titles[$command])) $t=$this->cmd_titles[$command]; else $t=ucfirst($command); $this->header($t); $this->PHK->$command(array(__CLASS__,'viewSubfileURL')); break; case 'autoFile': $this->header(); echo $this->PHK->autoFile('/'.$arg); break; case 'autoOption': $this->header(ucfirst($arg)); echo $this->PHK->autoOption($arg); break; case 'php_section': require($this->PHK->sectionURI($arg)); return; // Don't put anything after the file case 'section': // Bare section (image, css,...) with PHP source auto-exec eval($this->PHK->webTunnel('/?section&name='.$arg,true)); return; // Don't put anything after the file default: echo ''.$command.': Unknown subcommand

    '; } self::footer(); } //---- // Convert a subfile path to an URL. Needed because Automap must not // directly reference PHK or \PHK\Web\Info (to avoid cyclic dependencies). public static function viewSubfileURL($fname) { return \PHK::subpathURL('/view/'.trim($fname,'/')); } //---- // Set headers to cache this url during 10 mins // Taken from http-conditional (http://alexandre.alapetite.net) // very important because, if it not sent, tabs background images are not // cached by the browser. // Unfortunately, since we had to change the syntax of webinfo URLs to be // compatible with PHP in CGI mode, most browsers won't cache URLs containing // a '?' char. private static function sendCacheHeader() { header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T',time()+600)); header('Cache-Control: public, max-age=600'); //rfc2616-sec14.html#sec14.9 header('Last-Modified: '.gmdate('D, d M Y H:i:s \G\M\T',time())); } //---- private static function footer() { echo '


    '; echo 'For more information about the PHK package format:' .' ' .'http://phk.tekwire.net'; } //--- } // End of class //=========================================================================== } // End of class_exists //=========================================================================== } // End of namespace //=========================================================================== ?>