- file_get_contents instead of imploding file()s or fread()ing till the maximum filesize

- language and style properly use compression
- language now prompts user for methods
- functions_compress does not need to eval() to get a hex date, instead calls pack()
- A writing method is defined at the end of tar operations only if data has been sent to the archive
- BBCode parser does not have to eval(), it instead uses the regex to loop around the matches

Hopefully nothing broke :-)


git-svn-id: file:///svn/phpbb/trunk@5422 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
David M 2006-01-04 06:37:17 +00:00
parent 6583da5bf0
commit 17dc26e19b
7 changed files with 38 additions and 68 deletions

View file

@ -479,7 +479,7 @@ class acp_language
{
if ($is_email_file)
{
$lang = implode('', file($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, $file_from_store)));
$lang = file_get_contents($phpbb_root_path . $this->get_filename($lang_iso, $this->language_directory, $this->language_file, $file_from_store));
}
else
{
@ -627,9 +627,9 @@ class acp_language
$db->sql_freeresult($result);
$use_method = request_var('use_method', '');
$methods = array('tar');
$methods = array('.tar');
$available_methods = array('tar.gz' => 'zlib', 'tar.bz2' => 'bz2', 'zip' => 'zlib');
$available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib');
foreach ($available_methods as $type => $module)
{
if (!@extension_loaded($module))
@ -640,11 +640,6 @@ class acp_language
$methods[] = $type;
}
if (!in_array($use_method, $methods))
{
$use_method = 'tar';
}
// Let the user decide in which format he wants to have the pack
if (!$use_method)
{
@ -666,6 +661,11 @@ class acp_language
return;
}
if (!in_array($use_method, $methods))
{
$use_method = '.tar';
}
include_once($phpbb_root_path . 'includes/functions_compress.' . $phpEx);
if ($use_method == 'zip')

View file

@ -768,23 +768,23 @@ pagination_sep = \'{PAGINATION_SEP}\'
switch ($format)
{
case 'tar':
$ext = 'tar';
$ext = '.tar';
$mimetype = 'x-tar';
$compress = 'compress_tar';
break;
case 'zip':
$ext = 'zip';
$ext = '.zip';
$mimetype = 'zip';
break;
case 'tar.gz':
$ext = 'tar.gz';
$ext = '.tar.gz';
$mimetype = 'x-gzip';
break;
case 'tar.bz2':
$ext = 'tar.bz2';
$ext = '.tar.bz2';
$mimetype = 'x-bzip2';
break;
@ -800,11 +800,11 @@ pagination_sep = \'{PAGINATION_SEP}\'
if ($format == 'zip')
{
$compress = new compress_zip('w', $phpbb_root_path . "store/$path.$ext");
$compress = new compress_zip('w', $phpbb_root_path . "store/$path$ext");
}
else
{
$compress = new compress_tar('w', $phpbb_root_path . "store/$path.$ext", $ext);
$compress = new compress_tar('w', $phpbb_root_path . "store/$path$ext", $ext);
}
if (sizeof($files))
@ -830,11 +830,11 @@ pagination_sep = \'{PAGINATION_SEP}\'
if (!$store)
{
$compress->download($path);
@unlink("{$phpbb_root_path}store/$path.$ext");
@unlink("{$phpbb_root_path}store/$path$ext");
exit;
}
trigger_error(sprintf($user->lang[$l_prefix . '_EXPORTED'], "store/$path.$ext") . adm_back_link($this->u_action));
trigger_error(sprintf($user->lang[$l_prefix . '_EXPORTED'], "store/$path$ext") . adm_back_link($this->u_action));
}
}

View file

@ -342,12 +342,10 @@ class bbcode
if (empty($this->bbcode_template))
{
if (!($fp = @fopen($this->template_filename, 'rb')))
if (($tpl = file_get_contents($this->template_filename)) === false)
{
trigger_error('Could not load bbcode template');
}
$tpl = fread($fp, filesize($this->template_filename));
@fclose($fp);
// replace \ with \\ and then ' with \'.
$tpl = str_replace('\\', '\\\\', $tpl);
@ -355,12 +353,16 @@ class bbcode
// strip newlines and indent
$tpl = preg_replace("/\n[\n\r\s\t]*/", '', $tpl);
// Turn template blocks into PHP assignment statements for the values of $bbcode_tpl..
$tpl = preg_replace('#<!-- BEGIN (.*?) -->(.*?)<!-- END (.*?) -->#', "\n" . "\$this->bbcode_template['\$1'] = \$this->bbcode_tpl_replace('\$1','\$2');", $tpl);
$this->bbcode_template = array();
eval($tpl);
$matches = preg_match_all('#<!-- BEGIN (.*?) -->(.*?)<!-- END (?:.*?) -->#', $tpl, $match);
for ($i = 0; $i < $matches - 1; $i++)
{
$this->bbcode_template[$match[1][$i]] = $this->bbcode_tpl_replace($match[1][$i], $match[2][$i]);
}
}
return (isset($this->bbcode_template[$tpl_name])) ? $this->bbcode_template[$tpl_name] : ((isset($bbcode_hardtpl[$tpl_name])) ? $bbcode_hardtpl[$tpl_name] : false);

View file

@ -31,15 +31,7 @@ class compress
if (is_file($phpbb_root_path . $src))
{
if (!($fp = @fopen("$phpbb_root_path$src", 'rb')))
{
return false;
}
$data = fread($fp, filesize("$phpbb_root_path$src"));
fclose($fp);
$this->data($src_path, $data, false, stat("$phpbb_root_path$src"));
$this->data($src_path, file_get_contents("$phpbb_root_path$src"), false, stat("$phpbb_root_path$src"));
}
else if (is_dir($phpbb_root_path . $src))
{
@ -73,7 +65,7 @@ class compress
continue;
}
$this->data("$src_path$path$file", implode('', file("$phpbb_root_path$src$path$file")), false, stat("$phpbb_root_path$src$path$file"));
$this->data("$src_path$path$file", file_get_contents("$phpbb_root_path$src$path$file"), false, stat("$phpbb_root_path$src$path$file"));
}
}
@ -99,8 +91,8 @@ class compress
function methods()
{
$methods = array('tar');
$available_methods = array('tar.gz' => 'zlib', 'tar.bz2' => 'bz2', 'zip' => 'zlib');
$methods = array('.tar');
$available_methods = array('.tar.gz' => 'zlib', '.tar.bz2' => 'bz2', '.zip' => 'zlib');
foreach ($available_methods as $type => $module)
{
@ -314,8 +306,7 @@ class compress_zip extends compress
$name = str_replace('\\', '/', $name);
$dtime = dechex($this->unix_to_dos_time($stat[9]));
$hexdtime = '\x' . $dtime[6] . $dtime[7] . '\x' . $dtime[4] . $dtime[5] . '\x' . $dtime[2] . $dtime[3] . '\x' . $dtime[0] . $dtime[1];
eval('$hexdtime = "' . $hexdtime . '";');
$hexdtime = pack('H*', $dtime[6] . $dtime[7] . $dtime[4] . $dtime[5] . $dtime[2] . $dtime[3] . $dtime[0] . $dtime[1]);
if ($is_dir)
{
@ -563,11 +554,11 @@ class compress_tar extends compress
function close()
{
$fzwrite = ($this->isbz && function_exists('bzwrite')) ? 'bzwrite' : (($this->isgz && extension_loaded('zlib')) ? 'gzwrite' : 'fwrite');
$fzclose = ($this->isbz && function_exists('bzclose')) ? 'bzclose' : (($this->isgz && extension_loaded('zlib')) ? 'gzclose' : 'fclose');
if ($this->wrote)
if ($this->wrote)
{
$fzwrite = ($this->isbz && function_exists('bzwrite')) ? 'bzwrite' : (($this->isgz && extension_loaded('zlib')) ? 'gzwrite' : 'fwrite');
$fzwrite($this->fp, pack("a1024", ""));
}

View file

@ -675,12 +675,10 @@ function display_attachments($forum_id, $blockname, &$attachment_data, &$update_
$attachment_tpl = array();
$template_filename = $phpbb_root_path . 'styles/' . $user->theme['template_path'] . '/template/attachment.html';
if (!($fp = @fopen($template_filename, 'rb')))
if (($attachment_template = file_get_contents($template_filename)) === false)
{
trigger_error('Could not load template file "' . $template_filename . '"');
}
$attachment_template = fread($fp, filesize($template_filename));
@fclose($fp);
// replace \ with \\ and then ' with \'.
$attachment_template = str_replace('\\', '\\\\', $attachment_template);

View file

@ -44,13 +44,12 @@ class template_compile
function _tpl_load_file($handle)
{
// Try and open template for read
if (!($fp = @fopen($this->template->files[$handle], 'r')))
if (!file_exists($this->template->files[$handle]))
{
trigger_error("template->_tpl_load_file(): File {$this->template->files[$handle]} does not exist or is empty", E_USER_ERROR);
}
$this->template->compiled_code[$handle] = $this->compile(trim(@fread($fp, filesize($this->template->files[$handle]))));
@fclose($fp);
$this->template->compiled_code[$handle] = $this->compile(trim(@file_get_contents($this->template->files[$handle])));
// Actually compile the code now.
$this->compile_write($handle, $this->template->compiled_code[$handle]);

View file

@ -84,10 +84,10 @@ if ($id && $sid)
}
$force_load = true; // Ideally this needs to be based on $config['load_tplcompile']
if ($theme['theme_mtime'] < filemtime("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css') || $force_load)
{
$theme['theme_data'] = implode('', file("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css'));
$theme['theme_data'] = file_get_contents("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/stylesheet.css');
// Match CSS imports
$matches = array();
@ -97,7 +97,7 @@ if ($id && $sid)
{
foreach ($matches[0] as $idx => $match)
{
$theme['theme_data'] = str_replace($match, load_css_file($matches[1][$idx]), $theme['theme_data']);
$theme['theme_data'] = str_replace($match, file_get_contents("{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/' . $matches[1][$idx]), $theme['theme_data']);
}
}
@ -132,24 +132,4 @@ if ($id && $sid)
$db->sql_close();
}
function load_css_file($filename)
{
global $phpbb_root_path, $theme;
$handle = "{$phpbb_root_path}styles/" . $theme['theme_path'] . '/theme/' . $filename;
if ($fp = @fopen($handle, 'r'))
{
$content = trim(@fread($fp, filesize($handle)));
@fclose($fp);
}
else
{
$content = '';
}
return $content;
}
?>