Files
smarty/libs/plugins/function.fetch.php

52 lines
1.3 KiB
PHP
Raw Normal View History

2002-01-31 20:49:40 +00:00
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* Type: function
* Name: fetch
* Purpose: fetch file, web or ftp data and display results
* -------------------------------------------------------------
*/
2002-02-20 22:24:32 +00:00
function smarty_function_fetch($params, &$smarty)
2002-01-31 20:49:40 +00:00
{
2002-02-20 22:24:32 +00:00
extract($params);
2002-01-31 20:49:40 +00:00
if (empty($file)) {
2002-02-20 22:24:32 +00:00
$smarty->trigger_error("parameter 'file' cannot be empty");
2002-01-31 20:49:40 +00:00
return;
}
2002-02-20 22:24:32 +00:00
if ($smarty->security && !preg_match('!^(http|ftp)://!', $file)) {
2002-01-31 20:49:40 +00:00
// make sure fetched file comes from secure directory
2002-02-20 22:24:32 +00:00
foreach ($smarty->secure_dir as $curr_dir) {
2002-01-31 20:49:40 +00:00
if (substr(realpath($file), 0, strlen(realpath($curr_dir))) == realpath($curr_dir)) {
$resource_is_secure = true;
break;
}
}
if (!$resource_is_secure) {
2002-02-20 22:24:32 +00:00
$smarty->trigger_error("(secure mode) fetch '$file' is not allowed");
2002-01-31 20:49:40 +00:00
return;
}
if (!@is_readable($file)) {
2002-02-20 22:24:32 +00:00
$smarty->trigger_error("fetch cannot read file '$file'");
2002-01-31 20:49:40 +00:00
return;
}
}
if (!empty($assign)) {
ob_start();
readfile($file);
2002-02-20 22:24:32 +00:00
$smarty->assign($assign,ob_get_contents());
2002-01-31 20:49:40 +00:00
ob_end_clean();
} else {
readfile($file);
}
}
/* vim: set expandtab: */
?>