removed tabs. fixed indentiation.

This commit is contained in:
messju
2003-12-19 17:18:56 +00:00
parent 6711d0cebf
commit f6bb3389f6
16 changed files with 243 additions and 243 deletions

View File

@@ -53,9 +53,9 @@ function smarty_function_counter($params, &$smarty)
if ($print) { if ($print) {
$retval = $counter['count']; $retval = $counter['count'];
} else { } else {
$retval = null; $retval = null;
} }
if (isset($params['skip'])) { if (isset($params['skip'])) {
$counter['skip'] = $params['skip']; $counter['skip'] = $params['skip'];
@@ -69,9 +69,9 @@ function smarty_function_counter($params, &$smarty)
$counter['count'] -= $counter['skip']; $counter['count'] -= $counter['skip'];
else else
$counter['count'] += $counter['skip']; $counter['count'] += $counter['skip'];
return $retval; return $retval;
} }
/* vim: set expandtab: */ /* vim: set expandtab: */

View File

@@ -27,182 +27,182 @@ function smarty_function_fetch($params, &$smarty)
} }
if ($smarty->security && !preg_match('!^(http|ftp)://!i', $params['file'])) { if ($smarty->security && !preg_match('!^(http|ftp)://!i', $params['file'])) {
$_params = array('resource_type' => 'file', 'resource_name' => $params['file']); $_params = array('resource_type' => 'file', 'resource_name' => $params['file']);
require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.is_secure.php'); require_once(SMARTY_DIR . 'core' . DIRECTORY_SEPARATOR . 'core.is_secure.php');
if(!smarty_core_is_secure($_params, $smarty)) { if(!smarty_core_is_secure($_params, $smarty)) {
$smarty->_trigger_fatal_error('[plugin] (secure mode) fetch \'' . $params['file'] . '\' is not allowed'); $smarty->_trigger_fatal_error('[plugin] (secure mode) fetch \'' . $params['file'] . '\' is not allowed');
return; return;
} }
// fetch the file // fetch the file
if($fp = @fopen($params['file'],'r')) { if($fp = @fopen($params['file'],'r')) {
while(!feof($fp)) { while(!feof($fp)) {
$content .= fgets ($fp,4096); $content .= fgets ($fp,4096);
} }
fclose($fp); fclose($fp);
} else { } else {
$smarty->_trigger_fatal_error('[plugin] fetch cannot read file \'' . $params['file'] . '\''); $smarty->_trigger_fatal_error('[plugin] fetch cannot read file \'' . $params['file'] . '\'');
return; return;
} }
} else { } else {
// not a local file // not a local file
if(preg_match('!^http://!i',$params['file'])) { if(preg_match('!^http://!i',$params['file'])) {
// http fetch // http fetch
if($uri_parts = parse_url($params['file'])) { if($uri_parts = parse_url($params['file'])) {
// set defaults // set defaults
$host = $server_name = $uri_parts['host']; $host = $server_name = $uri_parts['host'];
$timeout = 30; $timeout = 30;
$accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";
$agent = "Smarty Template Engine ".$smarty->_version; $agent = "Smarty Template Engine ".$smarty->_version;
$referer = ""; $referer = "";
$uri = !empty($uri_parts['path']) ? $uri_parts['path'] : '/'; $uri = !empty($uri_parts['path']) ? $uri_parts['path'] : '/';
$uri .= !empty($uri_parts['query']) ? '?' . $uri_parts['query'] : ''; $uri .= !empty($uri_parts['query']) ? '?' . $uri_parts['query'] : '';
$_is_proxy = false; $_is_proxy = false;
if(empty($uri_parts['port'])) { if(empty($uri_parts['port'])) {
$port = 80; $port = 80;
} else { } else {
$port = $uri_parts['port']; $port = $uri_parts['port'];
} }
if(empty($uri_parts['user'])) { if(empty($uri_parts['user'])) {
$user = ''; $user = '';
} }
// loop through parameters, setup headers // loop through parameters, setup headers
foreach($params as $param_key => $param_value) { foreach($params as $param_key => $param_value) {
switch($param_key) { switch($param_key) {
case "file": case "file":
case "assign": case "assign":
case "assign_headers": case "assign_headers":
break; break;
case "user": case "user":
if(!empty($param_value)) { if(!empty($param_value)) {
$user = $param_value; $user = $param_value;
} }
break; break;
case "pass": case "pass":
if(!empty($param_value)) { if(!empty($param_value)) {
$pass = $param_value; $pass = $param_value;
} }
break; break;
case "accept": case "accept":
if(!empty($param_value)) { if(!empty($param_value)) {
$accept = $param_value; $accept = $param_value;
} }
break; break;
case "header": case "header":
if(!empty($param_value)) { if(!empty($param_value)) {
if(!preg_match('![\w\d-]+: .+!',$param_value)) { if(!preg_match('![\w\d-]+: .+!',$param_value)) {
$smarty->_trigger_fatal_error("[plugin] invalid header format '".$param_value."'"); $smarty->_trigger_fatal_error("[plugin] invalid header format '".$param_value."'");
return; return;
} else { } else {
$extra_headers[] = $param_value; $extra_headers[] = $param_value;
} }
} }
break; break;
case "proxy_host": case "proxy_host":
if(!empty($param_value)) { if(!empty($param_value)) {
$proxy_host = $param_value; $proxy_host = $param_value;
} }
break; break;
case "proxy_port": case "proxy_port":
if(!preg_match('!\D!', $param_value)) { if(!preg_match('!\D!', $param_value)) {
$proxy_port = (int) $param_value; $proxy_port = (int) $param_value;
} else { } else {
$smarty->_trigger_fatal_error("[plugin] invalid value for attribute '".$param_key."'"); $smarty->_trigger_fatal_error("[plugin] invalid value for attribute '".$param_key."'");
return; return;
} }
break; break;
case "agent": case "agent":
if(!empty($param_value)) { if(!empty($param_value)) {
$agent = $param_value; $agent = $param_value;
} }
break; break;
case "referer": case "referer":
if(!empty($param_value)) { if(!empty($param_value)) {
$referer = $param_value; $referer = $param_value;
} }
break; break;
case "timeout": case "timeout":
if(!preg_match('!\D!', $param_value)) { if(!preg_match('!\D!', $param_value)) {
$timeout = (int) $param_value; $timeout = (int) $param_value;
} else { } else {
$smarty->_trigger_fatal_error("[plugin] invalid value for attribute '".$param_key."'"); $smarty->_trigger_fatal_error("[plugin] invalid value for attribute '".$param_key."'");
return; return;
} }
break; break;
default: default:
$smarty->_trigger_fatal_error("[plugin] unrecognized attribute '".$param_key."'"); $smarty->_trigger_fatal_error("[plugin] unrecognized attribute '".$param_key."'");
return; return;
} }
} }
if(!empty($proxy_host) && !empty($proxy_port)) { if(!empty($proxy_host) && !empty($proxy_port)) {
$_is_proxy = true; $_is_proxy = true;
$fp = fsockopen($proxy_host,$proxy_port,$errno,$errstr,$timeout); $fp = fsockopen($proxy_host,$proxy_port,$errno,$errstr,$timeout);
} else { } else {
$fp = fsockopen($server_name,$port,$errno,$errstr,$timeout); $fp = fsockopen($server_name,$port,$errno,$errstr,$timeout);
} }
if(!$fp) { if(!$fp) {
$smarty->_trigger_fatal_error("[plugin] unable to fetch: $errstr ($errno)"); $smarty->_trigger_fatal_error("[plugin] unable to fetch: $errstr ($errno)");
return; return;
} else { } else {
if($_is_proxy) { if($_is_proxy) {
fputs($fp, 'GET ' . $params['file'] . " HTTP/1.0\r\n"); fputs($fp, 'GET ' . $params['file'] . " HTTP/1.0\r\n");
} else { } else {
fputs($fp, "GET $uri HTTP/1.0\r\n"); fputs($fp, "GET $uri HTTP/1.0\r\n");
} }
if(!empty($host)) { if(!empty($host)) {
fputs($fp, "Host: $host\r\n"); fputs($fp, "Host: $host\r\n");
} }
if(!empty($accept)) { if(!empty($accept)) {
fputs($fp, "Accept: $accept\r\n"); fputs($fp, "Accept: $accept\r\n");
} }
if(!empty($agent)) { if(!empty($agent)) {
fputs($fp, "User-Agent: $agent\r\n"); fputs($fp, "User-Agent: $agent\r\n");
} }
if(!empty($referer)) { if(!empty($referer)) {
fputs($fp, "Referer: $referer\r\n"); fputs($fp, "Referer: $referer\r\n");
} }
if(isset($extra_headers) && is_array($extra_headers)) { if(isset($extra_headers) && is_array($extra_headers)) {
foreach($extra_headers as $curr_header) { foreach($extra_headers as $curr_header) {
fputs($fp, $curr_header."\r\n"); fputs($fp, $curr_header."\r\n");
} }
} }
if(!empty($user) && !empty($pass)) { if(!empty($user) && !empty($pass)) {
fputs($fp, "Authorization: BASIC ".base64_encode("$user:$pass")."\r\n"); fputs($fp, "Authorization: BASIC ".base64_encode("$user:$pass")."\r\n");
} }
$content = ''; $content = '';
fputs($fp, "\r\n"); fputs($fp, "\r\n");
while(!feof($fp)) { while(!feof($fp)) {
$content .= fgets($fp,4096); $content .= fgets($fp,4096);
} }
fclose($fp); fclose($fp);
$csplit = split("\r\n\r\n",$content,2); $csplit = split("\r\n\r\n",$content,2);
$content = $csplit[1]; $content = $csplit[1];
if(!empty($params['assign_headers'])) { if(!empty($params['assign_headers'])) {
$smarty->assign($params['assign_headers'],split("\r\n",$csplit[0])); $smarty->assign($params['assign_headers'],split("\r\n",$csplit[0]));
} }
} }
} else { } else {
$smarty->_trigger_fatal_error("[plugin] unable to parse URL, check syntax"); $smarty->_trigger_fatal_error("[plugin] unable to parse URL, check syntax");
return; return;
} }
} else { } else {
// ftp fetch // ftp fetch
if($fp = @fopen($params['file'],'r')) { if($fp = @fopen($params['file'],'r')) {
while(!feof($fp)) { while(!feof($fp)) {
$content .= fgets ($fp,4096); $content .= fgets ($fp,4096);
} }
fclose($fp); fclose($fp);
} else { } else {
$smarty->_trigger_fatal_error('[plugin] fetch cannot read file \'' . $params['file'] .'\''); $smarty->_trigger_fatal_error('[plugin] fetch cannot read file \'' . $params['file'] .'\'');
return; return;
} }
} }
} }
if (!empty($params['assign'])) { if (!empty($params['assign'])) {

View File

@@ -20,14 +20,14 @@
*/ */
function smarty_function_popup_init($params, &$smarty) function smarty_function_popup_init($params, &$smarty)
{ {
$zindex = 1000; $zindex = 1000;
if (!empty($params['zindex'])) { if (!empty($params['zindex'])) {
$zindex = $params['zindex']; $zindex = $params['zindex'];
} }
if (!empty($params['src'])) { if (!empty($params['src'])) {
return '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:'.$zindex.';"></div>' . "\n" return '<div id="overDiv" style="position:absolute; visibility:hidden; z-index:'.$zindex.';"></div>' . "\n"
. '<script type="text/javascript" language="JavaScript" src="'.$params['src'].'"></script>' . "\n"; . '<script type="text/javascript" language="JavaScript" src="'.$params['src'].'"></script>' . "\n";
} else { } else {
$smarty->trigger_error("popup_init: missing src parameter"); $smarty->trigger_error("popup_init: missing src parameter");

View File

@@ -19,7 +19,7 @@
*/ */
function smarty_modifier_capitalize($string) function smarty_modifier_capitalize($string)
{ {
return ucwords($string); return ucwords($string);
} }
?> ?>

View File

@@ -17,7 +17,7 @@
* Example: {$var|cat:"foo"} * Example: {$var|cat:"foo"}
* @link http://smarty.php.net/manual/en/language.modifier.cat.php cat * @link http://smarty.php.net/manual/en/language.modifier.cat.php cat
* (Smarty online manual) * (Smarty online manual)
* @author Monte Ohrt <monte@ispi.net> * @author Monte Ohrt <monte@ispi.net>
* @version 1.0 * @version 1.0
* @param string * @param string
* @param string * @param string
@@ -25,7 +25,7 @@
*/ */
function smarty_modifier_cat($string, $cat) function smarty_modifier_cat($string, $cat)
{ {
return $string . $cat; return $string . $cat;
} }
/* vim: set expandtab: */ /* vim: set expandtab: */

View File

@@ -11,7 +11,7 @@
require_once $smarty->_get_plugin_filepath('shared','make_timestamp'); require_once $smarty->_get_plugin_filepath('shared','make_timestamp');
/** /**
* Smarty date_format modifier plugin * Smarty date_format modifier plugin
* *
* Type: modifier<br> * Type: modifier<br>
* Name: date_format<br> * Name: date_format<br>
* Purpose: format datestamps via strftime<br> * Purpose: format datestamps via strftime<br>
@@ -29,13 +29,13 @@ require_once $smarty->_get_plugin_filepath('shared','make_timestamp');
*/ */
function smarty_modifier_date_format($string, $format="%b %e, %Y", $default_date=null) function smarty_modifier_date_format($string, $format="%b %e, %Y", $default_date=null)
{ {
if($string != '') { if($string != '') {
return strftime($format, smarty_make_timestamp($string)); return strftime($format, smarty_make_timestamp($string));
} elseif (isset($default_date) && $default_date != '') { } elseif (isset($default_date) && $default_date != '') {
return strftime($format, smarty_make_timestamp($default_date)); return strftime($format, smarty_make_timestamp($default_date));
} else { } else {
return; return;
} }
} }
/* vim: set expandtab: */ /* vim: set expandtab: */

View File

@@ -21,7 +21,7 @@
*/ */
function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40) function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40)
{ {
$_replace = array("\n"=>'<i>&#92;n</i>', "\r"=>'<i>&#92;r</i>', "\t"=>'<i>&#92;t</i>'); $_replace = array("\n"=>'<i>&#92;n</i>', "\r"=>'<i>&#92;r</i>', "\t"=>'<i>&#92;t</i>');
if (is_array($var)) { if (is_array($var)) {
$results = "<b>Array (".count($var).")</b>"; $results = "<b>Array (".count($var).")</b>";
foreach ($var as $curr_key => $curr_val) { foreach ($var as $curr_key => $curr_val) {

View File

@@ -34,20 +34,20 @@ function smarty_modifier_escape($string, $esc_type = 'html')
// escape unescaped single quotes // escape unescaped single quotes
return preg_replace("%(?<!\\\\)'%", "\\'", $string); return preg_replace("%(?<!\\\\)'%", "\\'", $string);
case 'hex': case 'hex':
// escape every character into hex // escape every character into hex
$return = ''; $return = '';
for ($x=0; $x < strlen($string); $x++) { for ($x=0; $x < strlen($string); $x++) {
$return .= '%' . bin2hex($string[$x]); $return .= '%' . bin2hex($string[$x]);
} }
return $return; return $return;
case 'hexentity': case 'hexentity':
$return = ''; $return = '';
for ($x=0; $x < strlen($string); $x++) { for ($x=0; $x < strlen($string); $x++) {
$return .= '&#x' . bin2hex($string[$x]) . ';'; $return .= '&#x' . bin2hex($string[$x]) . ';';
} }
return $return; return $return;
case 'javascript': case 'javascript':
// escape quotes and backslashes and newlines // escape quotes and backslashes and newlines

View File

@@ -21,7 +21,7 @@
*/ */
function smarty_modifier_indent($string,$chars=4,$char=" ") function smarty_modifier_indent($string,$chars=4,$char=" ")
{ {
return preg_replace('!^!m',str_repeat($char,$chars),$string); return preg_replace('!^!m',str_repeat($char,$chars),$string);
} }
?> ?>

View File

@@ -19,7 +19,7 @@
*/ */
function smarty_modifier_lower($string) function smarty_modifier_lower($string)
{ {
return strtolower($string); return strtolower($string);
} }
?> ?>

View File

@@ -21,7 +21,7 @@
* @link http://smarty.php.net/manual/en/language.modifier.nl2br.php * @link http://smarty.php.net/manual/en/language.modifier.nl2br.php
* nl2br (Smarty online manual) * nl2br (Smarty online manual)
* @version 1.0 * @version 1.0
* @author Monte Ohrt <monte@ispi.net> * @author Monte Ohrt <monte@ispi.net>
* @param string * @param string
* @return string * @return string
*/ */

View File

@@ -25,7 +25,7 @@
*/ */
function smarty_modifier_strip($text, $replace = ' ') function smarty_modifier_strip($text, $replace = ' ')
{ {
return preg_replace('!\s+!', $replace, $text); return preg_replace('!\s+!', $replace, $text);
} }
/* vim: set expandtab: */ /* vim: set expandtab: */

View File

@@ -19,7 +19,7 @@
*/ */
function smarty_modifier_upper($string) function smarty_modifier_upper($string)
{ {
return strtoupper($string); return strtoupper($string);
} }
?> ?>

View File

@@ -22,7 +22,7 @@
*/ */
function smarty_modifier_wordwrap($string,$length=80,$break="\n",$cut=false) function smarty_modifier_wordwrap($string,$length=80,$break="\n",$cut=false)
{ {
return wordwrap($string,$length,$break,$cut); return wordwrap($string,$length,$break,$cut);
} }
?> ?>

View File

@@ -16,7 +16,7 @@
* template source after it gets interpreted, cleaning * template source after it gets interpreted, cleaning
* up code and saving bandwidth. Does not affect * up code and saving bandwidth. Does not affect
* <<PRE>></PRE> and <SCRIPT></SCRIPT> blocks.<br> * <<PRE>></PRE> and <SCRIPT></SCRIPT> blocks.<br>
* Install: Drop into the plugin directory, call * Install: Drop into the plugin directory, call
* <code>$smarty->load_filter('output','trimwhitespace');</code> * <code>$smarty->load_filter('output','trimwhitespace');</code>
* from application. * from application.
* @author Monte Ohrt <monte@ispi.net> * @author Monte Ohrt <monte@ispi.net>
@@ -25,51 +25,51 @@
* @param string * @param string
* @param Smarty * @param Smarty
*/ */
function smarty_outputfilter_trimwhitespace($source, &$smarty) function smarty_outputfilter_trimwhitespace($source, &$smarty)
{ {
// Pull out the script blocks // Pull out the script blocks
preg_match_all("!<script[^>]+>.*?</script>!is", $source, $match); preg_match_all("!<script[^>]+>.*?</script>!is", $source, $match);
$_script_blocks = $match[0]; $_script_blocks = $match[0];
$source = preg_replace("!<script[^>]+>.*?</script>!is", $source = preg_replace("!<script[^>]+>.*?</script>!is",
'@@@SMARTY:TRIM:SCRIPT@@@', $source); '@@@SMARTY:TRIM:SCRIPT@@@', $source);
// Pull out the pre blocks // Pull out the pre blocks
preg_match_all("!<pre>.*?</pre>!is", $source, $match); preg_match_all("!<pre>.*?</pre>!is", $source, $match);
$_pre_blocks = $match[0]; $_pre_blocks = $match[0];
$source = preg_replace("!<pre>.*?</pre>!is", $source = preg_replace("!<pre>.*?</pre>!is",
'@@@SMARTY:TRIM:PRE@@@', $source); '@@@SMARTY:TRIM:PRE@@@', $source);
// Pull out the textarea blocks // Pull out the textarea blocks
preg_match_all("!<textarea[^>]+>.*?</textarea>!is", $source, $match); preg_match_all("!<textarea[^>]+>.*?</textarea>!is", $source, $match);
$_textarea_blocks = $match[0]; $_textarea_blocks = $match[0];
$source = preg_replace("!<textarea[^>]+>.*?</textarea>!is", $source = preg_replace("!<textarea[^>]+>.*?</textarea>!is",
'@@@SMARTY:TRIM:TEXTAREA@@@', $source); '@@@SMARTY:TRIM:TEXTAREA@@@', $source);
// remove all leading spaces, tabs and carriage returns NOT // remove all leading spaces, tabs and carriage returns NOT
// preceeded by a php close tag. // preceeded by a php close tag.
$source = trim(preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source)); $source = trim(preg_replace('/((?<!\?>)\n)[\s]+/m', '\1', $source));
// replace script blocks // replace script blocks
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:SCRIPT@@@",$_script_blocks, $source); smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:SCRIPT@@@",$_script_blocks, $source);
// replace pre blocks // replace pre blocks
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:PRE@@@",$_pre_blocks, $source); smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:PRE@@@",$_pre_blocks, $source);
// replace textarea blocks // replace textarea blocks
smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:TEXTAREA@@@",$_textarea_blocks, $source); smarty_outputfilter_trimwhitespace_replace("@@@SMARTY:TRIM:TEXTAREA@@@",$_textarea_blocks, $source);
return $source; return $source;
} }
function smarty_outputfilter_trimwhitespace_replace($search_str, $replace, &$subject) { function smarty_outputfilter_trimwhitespace_replace($search_str, $replace, &$subject) {
$_len = strlen($search_str); $_len = strlen($search_str);
$_pos = 0; $_pos = 0;
for ($_i=0, $_count=count($replace); $_i<$_count; $_i++) for ($_i=0, $_count=count($replace); $_i<$_count; $_i++)
if (($_pos=strpos($subject, $search_str, $_pos))!==false) if (($_pos=strpos($subject, $search_str, $_pos))!==false)
$subject = substr_replace($subject, $replace[$_i], $_pos, $_len); $subject = substr_replace($subject, $replace[$_i], $_pos, $_len);
else else
break; break;
} }
?> ?>

View File

@@ -17,12 +17,12 @@
*/ */
function smarty_function_escape_special_chars($string) function smarty_function_escape_special_chars($string)
{ {
if(!is_array($string)) { if(!is_array($string)) {
$string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string); $string = preg_replace('!&(#?\w+);!', '%%%SMARTY_START%%%\\1%%%SMARTY_END%%%', $string);
$string = htmlspecialchars($string); $string = htmlspecialchars($string);
$string = str_replace(array('%%%SMARTY_START%%%','%%%SMARTY_END%%%'), array('&',';'), $string); $string = str_replace(array('%%%SMARTY_START%%%','%%%SMARTY_END%%%'), array('&',';'), $string);
} }
return $string; return $string;
} }
/* vim: set expandtab: */ /* vim: set expandtab: */