summaryrefslogtreecommitdiff
path: root/lib/smarty3/plugins/function.fetch.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/smarty3/plugins/function.fetch.php')
-rw-r--r--lib/smarty3/plugins/function.fetch.php69
1 files changed, 26 insertions, 43 deletions
diff --git a/lib/smarty3/plugins/function.fetch.php b/lib/smarty3/plugins/function.fetch.php
index cb60dd9..768761b 100644
--- a/lib/smarty3/plugins/function.fetch.php
+++ b/lib/smarty3/plugins/function.fetch.php
@@ -5,11 +5,10 @@
* @package Smarty
* @subpackage PluginsFunction
*/
-
/**
* Smarty {fetch} plugin
- * Type: function<br>
- * Name: fetch<br>
+ * Type: function
+ * Name: fetch
* Purpose: fetch file, web or ftp data and display results
*
* @link http://www.smarty.net/manual/en/language.function.fetch.php {fetch}
@@ -25,21 +24,17 @@
function smarty_function_fetch($params, $template)
{
if (empty($params[ 'file' ])) {
- trigger_error("[plugin] fetch parameter 'file' cannot be empty", E_USER_NOTICE);
-
+ trigger_error('[plugin] fetch parameter \'file\' cannot be empty', E_USER_NOTICE);
return;
}
-
// strip file protocol
if (stripos($params[ 'file' ], 'file://') === 0) {
$params[ 'file' ] = substr($params[ 'file' ], 7);
}
-
$protocol = strpos($params[ 'file' ], '://');
if ($protocol !== false) {
$protocol = strtolower(substr($params[ 'file' ], 0, $protocol));
}
-
if (isset($template->smarty->security_policy)) {
if ($protocol) {
// remote resource (or php stream, …)
@@ -53,17 +48,16 @@ function smarty_function_fetch($params, $template)
}
}
}
-
$content = '';
- if ($protocol == 'http') {
+ if ($protocol === 'http') {
// http fetch
if ($uri_parts = parse_url($params[ '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::SMARTY_VERSION;
- $referer = "";
+ $accept = 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*';
+ $agent = 'Smarty Template Engine ' . Smarty::SMARTY_VERSION;
+ $referer = '';
$uri = !empty($uri_parts[ 'path' ]) ? $uri_parts[ 'path' ] : '/';
$uri .= !empty($uri_parts[ 'query' ]) ? '?' . $uri_parts[ 'query' ] : '';
$_is_proxy = false;
@@ -81,72 +75,68 @@ function smarty_function_fetch($params, $template)
// loop through parameters, setup headers
foreach ($params as $param_key => $param_value) {
switch ($param_key) {
- case "file":
- case "assign":
- case "assign_headers":
+ case 'file':
+ case 'assign':
+ case 'assign_headers':
break;
- case "user":
+ case 'user':
if (!empty($param_value)) {
$user = $param_value;
}
break;
- case "pass":
+ case 'pass':
if (!empty($param_value)) {
$pass = $param_value;
}
break;
- case "accept":
+ case 'accept':
if (!empty($param_value)) {
$accept = $param_value;
}
break;
- case "header":
+ case 'header':
if (!empty($param_value)) {
if (!preg_match('![\w\d-]+: .+!', $param_value)) {
- trigger_error("[plugin] invalid header format '" . $param_value . "'", E_USER_NOTICE);
-
+ trigger_error("[plugin] invalid header format '{$param_value}'", E_USER_NOTICE);
return;
} else {
$extra_headers[] = $param_value;
}
}
break;
- case "proxy_host":
+ case 'proxy_host':
if (!empty($param_value)) {
$proxy_host = $param_value;
}
break;
- case "proxy_port":
+ case 'proxy_port':
if (!preg_match('!\D!', $param_value)) {
- $proxy_port = (int) $param_value;
+ $proxy_port = (int)$param_value;
} else {
- trigger_error("[plugin] invalid value for attribute '" . $param_key . "'", E_USER_NOTICE);
-
+ trigger_error("[plugin] invalid value for attribute '{$param_key }'", E_USER_NOTICE);
return;
}
break;
- case "agent":
+ case 'agent':
if (!empty($param_value)) {
$agent = $param_value;
}
break;
- case "referer":
+ case 'referer':
if (!empty($param_value)) {
$referer = $param_value;
}
break;
- case "timeout":
+ case 'timeout':
if (!preg_match('!\D!', $param_value)) {
- $timeout = (int) $param_value;
+ $timeout = (int)$param_value;
} else {
- trigger_error("[plugin] invalid value for attribute '" . $param_key . "'", E_USER_NOTICE);
-
+ trigger_error("[plugin] invalid value for attribute '{$param_key}'", E_USER_NOTICE);
return;
}
break;
default:
- trigger_error("[plugin] unrecognized attribute '" . $param_key . "'", E_USER_NOTICE);
-
+ trigger_error("[plugin] unrecognized attribute '{$param_key}'", E_USER_NOTICE);
return;
}
}
@@ -156,10 +146,8 @@ function smarty_function_fetch($params, $template)
} else {
$fp = fsockopen($server_name, $port, $errno, $errstr, $timeout);
}
-
if (!$fp) {
trigger_error("[plugin] unable to fetch: $errstr ($errno)", E_USER_NOTICE);
-
return;
} else {
if ($_is_proxy) {
@@ -185,25 +173,21 @@ function smarty_function_fetch($params, $template)
}
}
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");
}
-
fputs($fp, "\r\n");
while (!feof($fp)) {
$content .= fgets($fp, 4096);
}
fclose($fp);
$csplit = preg_split("!\r\n\r\n!", $content, 2);
-
$content = $csplit[ 1 ];
-
if (!empty($params[ 'assign_headers' ])) {
$template->assign($params[ 'assign_headers' ], preg_split("!\r\n!", $csplit[ 0 ]));
}
}
} else {
trigger_error("[plugin fetch] unable to parse URL, check syntax", E_USER_NOTICE);
-
return;
}
} else {
@@ -212,7 +196,6 @@ function smarty_function_fetch($params, $template)
throw new SmartyException("{fetch} cannot read resource '" . $params[ 'file' ] . "'");
}
}
-
if (!empty($params[ 'assign' ])) {
$template->assign($params[ 'assign' ], $content);
} else {