mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-11-03 22:01:36 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			72 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			72 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			PHP
		
	
	
		
			Executable File
		
	
	
	
	
<?php
 | 
						|
/*
 | 
						|
  +----------------------------------------------------------------------+
 | 
						|
  | PHP Version 5                                                        |
 | 
						|
  +----------------------------------------------------------------------+
 | 
						|
  | Copyright (c) 1997-2004 The PHP Group                                |
 | 
						|
  +----------------------------------------------------------------------+
 | 
						|
  | This source file is subject to version 3.0 of the PHP license,       |
 | 
						|
  | that is bundled with this package in the file LICENSE, and is        |
 | 
						|
  | available through the world-wide-web at the following url:           |
 | 
						|
  | http://www.php.net/license/3_0.txt.                                  |
 | 
						|
  | If you did not receive a copy of the PHP license and are unable to   |
 | 
						|
  | obtain it through the world-wide-web, please send a note to          |
 | 
						|
  | license@php.net so we can mail you a copy immediately.               |
 | 
						|
  +----------------------------------------------------------------------+
 | 
						|
  | Authors:    Jakub Vrána <vrana@php.net>                              |
 | 
						|
  |             Nuno Lopes  <nlopess@php.net>                            |
 | 
						|
  +----------------------------------------------------------------------+
 | 
						|
  | Highlight PHP examples                                               |
 | 
						|
  +----------------------------------------------------------------------+
 | 
						|
 | 
						|
  $Id$
 | 
						|
*/
 | 
						|
 | 
						|
if ($_SERVER["argc"] < 3) {
 | 
						|
	exit("Purpose: Syntax highlight PHP examples in DSSSL generated HTML manual.\n"
 | 
						|
		.'Usage: html_syntax.php [ "html" | "php" ] [ filename.ext | dir | wildcard ] ...' ."\n"
 | 
						|
		.'"html" - highlight_string() is applied, "php" - highlight_string() is added' ."\n"
 | 
						|
	);
 | 
						|
}
 | 
						|
set_time_limit(5*60); // can run long, but not more than 5 minutes
 | 
						|
 | 
						|
function callback_html_number_entities_decode($matches) {
 | 
						|
	return chr($matches[1]);
 | 
						|
}
 | 
						|
 | 
						|
function callback_highlight_php($matches) {
 | 
						|
	$with_tags = preg_replace_callback("!&#([0-9]+);!", "callback_html_number_entities_decode", $matches[1]);
 | 
						|
	if ($GLOBALS["TYPE"] == "php") {
 | 
						|
		return "\n<?php\nhighlight_string('". addcslashes($with_tags, "'\\") ."');\n?>\n";
 | 
						|
	} else { // "html"
 | 
						|
		return highlight_string($with_tags, true);
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
$files = $_SERVER["argv"];
 | 
						|
array_shift($files); // $argv[0] - script filename
 | 
						|
$TYPE = array_shift($files); // "html" or "php"
 | 
						|
while (($file = array_shift($files)) !== null) {
 | 
						|
	if (is_file($file)) {
 | 
						|
		$process = array($file);
 | 
						|
	} elseif (is_dir($file)) {
 | 
						|
		$lastchar = substr($file, -1);
 | 
						|
		$process = glob($file . ($lastchar == "/" || $lastchar == "\\" ? "*" : "/*"));
 | 
						|
	} else { // should be wildcard
 | 
						|
		$process = glob($file);
 | 
						|
	}
 | 
						|
	foreach ($process as $filename) {
 | 
						|
		if (!is_file($filename)) { // do not recurse
 | 
						|
			continue;
 | 
						|
		}
 | 
						|
		$original = file_get_contents($filename);
 | 
						|
		$highlighted = preg_replace_callback("!<PRE\r?\nCLASS=\"php\"\r?\n>(.*)</PRE\r?\n>!sU", "callback_highlight_php", $original);
 | 
						|
		if ($original != $highlighted) {
 | 
						|
			$fp = fopen($filename, "w");
 | 
						|
			fwrite($fp, $highlighted);
 | 
						|
			fclose($fp);
 | 
						|
		}
 | 
						|
	}
 | 
						|
}
 | 
						|
?>
 |