|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
gyopee Smarty Rookie
Joined: 27 Jan 2014 Posts: 14
|
Posted: Thu Jan 30, 2014 8:29 am Post subject: fetch bug |
|
|
In case I'd like to fetch a php file, Smarty {fetch} function returns a weird result.
For example:
PHP to fetch:
Code: | <?php
require_once 'libs/Smarty.class.php';
$smarty = new Smarty();
$smarty->display('smarty.htm');
|
Expected result:
Code: | <?php
require_once 'libs/Smarty.class.php';
$smarty = new Smarty();
$smarty->display('smarty.htm');
|
Displayed:
Code: | display('smarty_counter_and_cycle.htm'); |
That's basically not a Smarty bug.
It's because file_get_contents PHP function.
But Smarty can avoid using file_get_contents, for example in this way:
In function.fetch.php the block starting at line 208 should be changed from:
Code: |
$content = @file_get_contents($params['file']);
if ($content === false) {
throw new SmartyException("{fetch} cannot read resource '" . $params['file'] ."'");
}
|
to:
Code: |
$fp = @fopen($params['file'],'r');
if($fp===false){
throw new SmartyException("{fetch} cannot read resource '" . $params['file'] ."'");
}
else{
$content = htmlspecialchars(fread($fp,filesize($params['file'])));
fclose($fp);
}
|
|
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Thu Jan 30, 2014 5:37 pm Post subject: |
|
|
This is not a bug. It is intended that fetch does display the fetch content as it is.
For example {fetch} can be used to load dynamically JavaScript files from remote servers or the local file system.
If you would run the content through htmlspecialchars you would get the js files displayed which is not intended.
If you want to display as in your example the content of a PHP source file you can do it by adding modifier
Code: | {fetch|htmlspecialchars|nl2br file='./foo.php'} |
|
|
Back to top |
|
gyopee Smarty Rookie
Joined: 27 Jan 2014 Posts: 14
|
Posted: Thu Jan 30, 2014 7:03 pm Post subject: |
|
|
Yes, you are right.
My bad. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|