|
From: Benjamin C. <bc...@us...> - 2002-09-19 20:07:56
|
Update of /cvsroot/phpbt/phpbt/inc/smarty/plugins
In directory usw-pr-cvs1:/tmp/cvs-serv6306/inc/smarty/plugins
Added Files:
function.assign.php function.cycle.php function.fetch.php
function.popup.php modifier.default.php
Log Message:
Adding latest smarty (2.3.0) to repository
--- NEW FILE: function.assign.php ---
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: assign
* Purpose: assign a value to a template variable
* -------------------------------------------------------------
*/
function smarty_function_assign($params, &$smarty)
{
extract($params);
if (empty($var)) {
$smarty->trigger_error("assign: missing 'var' parameter");
return;
}
if (!in_array('value', array_keys($params))) {
$smarty->trigger_error("assign: missing 'value' parameter");
return;
}
$smarty->assign($var, $value);
}
/* vim: set expandtab: */
?>
--- NEW FILE: function.cycle.php ---
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: cycle
* Version: 1.3
* Date: May 3, 2002
* Author: Monte Ohrt <mo...@is...>
* Credits: Mark Priatel <mpr...@ro...>
* Gerard <ge...@in...>
* Jason Sweat <jsw...@ya...>
* Purpose: cycle through given values
* Input: name = name of cycle (optional)
* values = comma separated list of values to cycle,
* or an array of values to cycle
* (this can be left out for subsequent calls)
*
* reset = boolean - resets given var to true
* print = boolean - print var or not. default is true
* advance = boolean - whether or not to advance the cycle
* delimiter = the value delimiter, default is ","
* assign = boolean, assigns to template var instead of
* printed.
*
* Examples: {cycle values="#eeeeee,#d0d0d0d"}
* {cycle name=row values="one,two,three" reset=true}
* {cycle name=row}
* -------------------------------------------------------------
*/
function smarty_function_cycle($params, &$smarty)
{
static $cycle_vars;
extract($params);
if (empty($name)) {
$name = 'default';
}
if (!isset($print)) {
$print = true;
}
if (!isset($advance)) {
$advance = true;
}
if (!isset($reset)) {
$reset = false;
}
if (!in_array('values', array_keys($params))) {
if(!isset($cycle_vars[$name]['values'])) {
$smarty->trigger_error("cycle: missing 'values' parameter");
return;
}
} else {
if(isset($cycle_vars[$name]['values'])
&& $cycle_vars[$name]['values'] != $values ) {
$cycle_vars[$name]['index'] = 0;
}
$cycle_vars[$name]['values'] = $values;
}
if (isset($delimiter)) {
$cycle_vars[$name]['delimiter'] = $delimiter;
} elseif (!isset($cycle_vars[$name]['delimiter'])) {
$cycle_vars[$name]['delimiter'] = ',';
}
if(!is_array($cycle_vars[$name]['values'])) {
$cycle_array = explode($cycle_vars[$name]['delimiter'],$cycle_vars[$name]['values']);
} else {
$cycle_array = $cycle_vars[$name]['values'];
}
if(!isset($cycle_vars[$name]['index']) || $reset ) {
$cycle_vars[$name]['index'] = 0;
}
if (isset($assign)) {
$print = false;
$smarty->assign($assign, $cycle_array[$cycle_vars[$name]['index']]);
}
if($print) {
echo $cycle_array[$cycle_vars[$name]['index']];
}
if($advance) {
if ( $cycle_vars[$name]['index'] >= count($cycle_array) -1 ) {
$cycle_vars[$name]['index'] = 0;
} else {
$cycle_vars[$name]['index']++;
}
}
}
/* vim: set expandtab: */
?>
--- NEW FILE: function.fetch.php ---
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: fetch
* Purpose: fetch file, web or ftp data and display results
* -------------------------------------------------------------
*/
function smarty_function_fetch($params, &$smarty)
{
$file = $params['file'];
if (empty($file)) {
$smarty->_trigger_plugin_error("parameter 'file' cannot be empty");
return;
}
if ($smarty->security && !preg_match('!^(http|ftp)://!i', $file)) {
// fetching file, make sure it comes from secure directory
foreach ($smarty->secure_dir as $curr_dir) {
if (substr(realpath($file), 0, strlen(realpath($curr_dir))) == realpath($curr_dir)) {
$resource_is_secure = true;
break;
}
}
if (!$resource_is_secure) {
$smarty->_trigger_plugin_error("(secure mode) fetch '$file' is not allowed");
return;
}
// fetch the file
if($fp = @fopen($file,'r')) {
while(!feof($fp)) {
$content .= fgets ($fp,4096);
}
fclose($fp);
} else {
$smarty->_trigger_plugin_error("fetch cannot read file '$file'");
return;
}
} else {
// not a local file
if(preg_match('!^http://!i',$file)) {
// http fetch
if($uri_parts = parse_url($file)) {
// set defaults
$host = $server_name = $uri_parts['host'];
$timeout = 30;
$accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";
$agent = "Smarty Template Engine ".$smarty->_version;
$referer = "";
if(!empty($uri_parts['path'])) {
$uri = $uri_parts['path'];
} else {
$uri = '/';
}
$_is_proxy = false;
if(empty($uri_parts['port'])) {
$port = 80;
} else {
$port = $uri_parts['port'];
}
if(empty($uri_parts['user'])) {
$user = $uri_parts['user'];
}
// loop through parameters, setup headers
foreach($params as $param_key => $param_value) {
switch($param_key) {
case "file":
case "assign":
case "assign_headers":
break;
case "user":
if(!empty($param_value)) {
$user = $param_value;
}
break;
case "pass":
if(!empty($param_value)) {
$pass = $param_value;
}
break;
case "accept":
if(!empty($param_value)) {
$accept = $param_value;
}
break;
case "header":
if(!empty($param_value)) {
if(!preg_match('![\w\d-]+: .+!',$param_value)) {
$smarty->_trigger_plugin_error("invalid header format '".$param_value."'");
return;
} else {
$extra_headers[] = $param_value;
}
}
break;
case "proxy_host":
if(!empty($param_value)) {
$proxy_host = $param_value;
}
break;
case "proxy_port":
if(!preg_match('!\D!', $param_value)) {
$proxy_port = (int) $param_value;
} else {
$smarty->_trigger_plugin_error("invalid value for attribute '".$param_key."'");
return;
}
break;
case "agent":
if(!empty($param_value)) {
$agent = $param_value;
}
break;
case "referer":
if(!empty($param_value)) {
$referer = $param_value;
}
break;
case "timeout":
if(!preg_match('!\D!', $param_value)) {
$timeout = (int) $param_value;
} else {
$smarty->_trigger_plugin_error("invalid value for attribute '".$param_key."'");
return;
}
break;
default:
$smarty->_trigger_plugin_error("unrecognized attribute '".$param_key."'");
return;
}
}
if(!empty($proxy_host) && !empty($proxy_port)) {
$_is_proxy = true;
$fp = fsockopen($proxy_host,$proxy_port,$errno,$errstr,$timeout);
} else {
$fp = fsockopen($server_name,$port,$errno,$errstr,$timeout);
}
if(!$fp) {
$smarty->_trigger_plugin_error("unable to fetch: $errstr ($errno)");
return;
} else {
if($_is_proxy) {
fputs($fp, "GET $file HTTP/1.0\r\n");
} else {
fputs($fp, "GET $uri HTTP/1.0\r\n");
}
if(!empty($host)) {
fputs($fp, "Host: $host\r\n");
}
if(!empty($accept)) {
fputs($fp, "Accept: $accept\r\n");
}
if(!empty($agent)) {
fputs($fp, "User-Agent: $agent\r\n");
}
if(!empty($referer)) {
fputs($fp, "Referer: $referer\r\n");
}
if(is_array($extra_headers)) {
foreach($extra_headers as $curr_header) {
fputs($fp, $curr_header."\r\n");
}
}
if(!empty($user) && !empty($pass)) {
fputs($fp, "Authorization: BASIC ".base64_encode("$user:$pass")."\r\n");
}
fputs($fp, "\r\n");
while(!feof($fp)) {
$content .= fgets($fp,4096);
}
fclose($fp);
$csplit = split("\r\n\r\n",$content,2);
$content = $csplit[1];
if(!empty($params['assign_headers'])) {
$smarty->assign($params['assign_headers'],split("\r\n",$csplit[0]));
}
}
} else {
$smarty->_trigger_plugin_error("unable to parse URL, check syntax");
return;
}
} else {
// ftp fetch
if($fp = @fopen($file,'r')) {
while(!feof($fp)) {
$content .= fgets ($fp,4096);
}
fclose($fp);
} else {
$smarty->_trigger_plugin_error("fetch cannot read file '$file'");
return;
}
}
}
if (!empty($params['assign'])) {
$smarty->assign($params['assign'],$content);
} else {
echo $content;
}
}
/* vim: set expandtab: */
?>
--- NEW FILE: function.popup.php ---
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: popup
* Purpose: make text pop up in windows via overlib
* -------------------------------------------------------------
*/
function smarty_function_popup($params, &$smarty)
{
extract($params);
if (empty($text) && !isset($inarray) && empty($function)) {
$smarty->trigger_error("overlib: attribute 'text' or 'inarray' or 'function' required");
return false;
}
if (empty($trigger)) { $trigger = "onMouseOver"; }
echo $trigger.'="return overlib(\''.str_replace("'","\'",$text).'\'';
if ($sticky) { echo ",STICKY"; }
if (!empty($caption)) { echo ",CAPTION,'".str_replace("'","\'",$caption)."'"; }
if (!empty($fgcolor)) { echo ",FGCOLOR,'$fgcolor'"; }
if (!empty($bgcolor)) { echo ",BGCOLOR,'$bgcolor'"; }
if (!empty($textcolor)) { echo ",TEXTCOLOR,'$textcolor'"; }
if (!empty($capcolor)) { echo ",CAPCOLOR,'$capcolor'"; }
if (!empty($closecolor)) { echo ",CLOSECOLOR,'$closecolor'"; }
if (!empty($textfont)) { echo ",TEXTFONT,'$textfont'"; }
if (!empty($captionfont)) { echo ",CAPTIONFONT,'$captionfont'"; }
if (!empty($closefont)) { echo ",CLOSEFONT,'$closefont'"; }
if (!empty($textsize)) { echo ",TEXTSIZE,$textsize"; }
if (!empty($captionsize)) { echo ",CAPTIONSIZE,$captionsize"; }
if (!empty($closesize)) { echo ",CLOSESIZE,$closesize"; }
if (!empty($width)) { echo ",WIDTH,$width"; }
if (!empty($height)) { echo ",HEIGHT,$height"; }
if (!empty($left)) { echo ",LEFT"; }
if (!empty($right)) { echo ",RIGHT"; }
if (!empty($center)) { echo ",CENTER"; }
if (!empty($above)) { echo ",ABOVE"; }
if (!empty($below)) { echo ",BELOW"; }
if (isset($border)) { echo ",BORDER,$border"; }
if (isset($offsetx)) { echo ",OFFSETX,$offsetx"; }
if (isset($offsety)) { echo ",OFFSETY,$offsety"; }
if (!empty($fgbackground)) { echo ",FGBACKGROUND,'$fgbackground'"; }
if (!empty($bgbackground)) { echo ",BGBACKGROUND,'$bgbackground'"; }
if (!empty($closetext)) { echo ",CLOSETEXT,'".str_replace("'","\'",$closetext)."'"; }
if (!empty($noclose)) { echo ",NOCLOSE"; }
if (!empty($status)) { echo ",STATUS,'".str_replace("'","\'",$status)."'"; }
if (!empty($autostatus)) { echo ",AUTOSTATUS"; }
if (!empty($autostatuscap)) { echo ",AUTOSTATUSCAP"; }
if (isset($inarray)) { echo ",INARRAY,'$inarray'"; }
if (isset($caparray)) { echo ",CAPARRAY,'$caparray'"; }
if (!empty($capicon)) { echo ",CAPICON,'$capicon'"; }
if (!empty($snapx)) { echo ",SNAPX,$snapx"; }
if (!empty($snapy)) { echo ",SNAPY,$snapy"; }
if (isset($fixx)) { echo ",FIXX,$fixx"; }
if (isset($fixy)) { echo ",FIXY,$fixy"; }
if (!empty($background)) { echo ",BACKGROUND,'$background'"; }
if (!empty($padx)) { echo ",PADX,$padx"; }
if (!empty($pady)) { echo ",PADY,$pady"; }
if (!empty($fullhtml)) { echo ",FULLHTML"; }
if (!empty($frame)) { echo ",FRAME,'$frame'"; }
if (isset($timeout)) { echo ",TIMEOUT,$timeout"; }
if (!empty($function)) { echo ",FUNCTION,'$function'"; }
if (isset($delay)) { echo ",DELAY,$delay"; }
if (!empty($hauto)) { echo ",HAUTO"; }
if (!empty($vauto)) { echo ",VAUTO"; }
echo ');" onMouseOut="nd();"';
}
/* vim: set expandtab: */
?>
--- NEW FILE: modifier.default.php ---
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: modifier
* Name: default
* Purpose: designate default value for empty variables
* -------------------------------------------------------------
*/
function smarty_modifier_default($string, $default = '')
{
if (empty($string))
return $default;
else
return $string;
}
/* vim: set expandtab: */
?>
|