mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 18:34:27 +02:00
removed unused functionality to load a subset of lines from a file in
Smarty::_read_file() additionally removed a warning that is emitted since php-4.3.5 when fread() is called on an empty file (with filesize()==0). thanks to Andreas Streichardt who pointed this out.
This commit is contained in:
1
NEWS
1
NEWS
@@ -1,3 +1,4 @@
|
||||
- removed unused functionality to load a subset of lines from a file (messju)
|
||||
- fix is_secure() should only check if a file is_readable, not if
|
||||
the directory where it is in is readable (sagi, messju)
|
||||
- fix problem displaying debug console when $default_resource_type
|
||||
|
@@ -240,7 +240,7 @@ class Config_File {
|
||||
return false;
|
||||
}
|
||||
|
||||
$contents = fread($fp, filesize($config_file));
|
||||
$contents = ($size = filesize($config_file)) ? fread($fp, $size) : '';
|
||||
fclose($fp);
|
||||
|
||||
$this->_config_data[$config_file] = $this->parse_contents($contents);
|
||||
|
@@ -1702,39 +1702,15 @@ class Smarty
|
||||
* @param integer $lines
|
||||
* @return string
|
||||
*/
|
||||
function _read_file($filename, $start=null, $lines=null)
|
||||
function _read_file($filename)
|
||||
{
|
||||
if (!($fd = @fopen($filename, 'r'))) {
|
||||
if ($fd = @fopen($filename, 'rb')) {
|
||||
$contents = ($size = filesize($filename)) ? fread($fd, $size) : '';
|
||||
fclose($fd);
|
||||
return $contents;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
flock($fd, LOCK_SH);
|
||||
if ($start == null && $lines == null) {
|
||||
// read the entire file
|
||||
$contents = fread($fd, filesize($filename));
|
||||
} else {
|
||||
if ( $start > 1 ) {
|
||||
// skip the first lines before $start
|
||||
for ($loop=1; $loop < $start; $loop++) {
|
||||
fgets($fd, 65536);
|
||||
}
|
||||
}
|
||||
if ( $lines == null ) {
|
||||
// read the rest of the file
|
||||
while (!feof($fd)) {
|
||||
$contents .= fgets($fd, 65536);
|
||||
}
|
||||
} else {
|
||||
// read up to $lines lines
|
||||
for ($loop=0; $loop < $lines; $loop++) {
|
||||
$contents .= fgets($fd, 65536);
|
||||
if (feof($fd)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose($fd);
|
||||
return $contents;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user