aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/template.php
diff options
context:
space:
mode:
authorPaul S. Owen <psotfx@users.sourceforge.net>2003-03-18 14:58:07 +0000
committerPaul S. Owen <psotfx@users.sourceforge.net>2003-03-18 14:58:07 +0000
commit58b47c8312935fa09ceea09a3d14b8cd1d78fb5d (patch)
treeab1aa9e5ab409cc9fdd5baafd2e61fac297fd69d /phpBB/includes/template.php
parentd85156d5cd684d16e7e37e300f229a3131603c68 (diff)
downloadforums-58b47c8312935fa09ceea09a3d14b8cd1d78fb5d.tar
forums-58b47c8312935fa09ceea09a3d14b8cd1d78fb5d.tar.gz
forums-58b47c8312935fa09ceea09a3d14b8cd1d78fb5d.tar.bz2
forums-58b47c8312935fa09ceea09a3d14b8cd1d78fb5d.tar.xz
forums-58b47c8312935fa09ceea09a3d14b8cd1d78fb5d.zip
Change cache location to root path cache, you can delete the cache/ and its contents from the templates/ directory. Moved cache show, decompile, etc. methods to new admin_ object in functions_admin
git-svn-id: file:///svn/phpbb/trunk@3662 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/template.php')
-rw-r--r--phpBB/includes/template.php145
1 files changed, 17 insertions, 128 deletions
diff --git a/phpBB/includes/template.php b/phpBB/includes/template.php
index f93aaef1e1..ceee724c81 100644
--- a/phpBB/includes/template.php
+++ b/phpBB/includes/template.php
@@ -40,7 +40,6 @@
// Changes for 2.2:
//
// * Allow use of Smarty plug-ins?
-// * Allow use of DB for storage of compiled templates
// * Reduce number of methods and variables
class Template {
@@ -56,6 +55,7 @@ class Template {
// Root dir and hash of filenames for each template handle.
var $root = '';
+ var $cache_root = 'cache/templates/';
var $files = array();
// this will hash handle names to the compiled/uncompiled code for that handle.
@@ -71,8 +71,9 @@ class Template {
function set_template($template = '')
{
global $phpbb_root_path;
+
$this->root = $phpbb_root_path . 'templates/' . $template;
- $this->cachedir = $phpbb_root_path . 'templates/cache/' . $template . '/';
+ $this->cachedir = $phpbb_root_path . $this->cache_root . $template . '/';
if (!file_exists($this->cachedir))
{
@@ -83,10 +84,8 @@ class Template {
return true;
}
- /**
- * Sets the template filenames for handles. $filename_array
- * should be a hash of handle => filename pairs.
- */
+ // Sets the template filenames for handles. $filename_array
+ // should be a hash of handle => filename pairs.
function set_filenames($filename_array)
{
if (!is_array($filename_array))
@@ -109,11 +108,9 @@ class Template {
return true;
}
- /**
- * Generates a full path+filename for the given filename, which can either
- * be an absolute name, or a name relative to the rootdir for this Template
- * object.
- */
+ // Generates a full path+filename for the given filename, which can either
+ // be an absolute name, or a name relative to the rootdir for this Template
+ // object.
function make_filename($filename)
{
// Check if it's an absolute or relative path.
@@ -685,9 +682,7 @@ class Template {
return $varref;
}
- //
// Compilation stuff
- //
function compile_load(&$_str, &$handle, $do_echo)
{
global $phpEx, $user;
@@ -716,128 +711,22 @@ class Template {
$filename = $this->cachedir . $this->filename[$handle] . '.' . $phpEx;
- $data = '<?php' . "\nif (\$this->security()) {\n" . $data . "\n}\n?".">";
-
- $fp = fopen($filename, 'w+');
- fwrite ($fp, $data);
- fclose($fp);
-
- touch($filename, filemtime($this->files[$handle]));
- @chmod($filename, 0644);
-
- return;
- }
+ $data = '<?php' . "\nif (\$this->security()) {\n" . $data . "\n}\n?" . '>';
- function compile_cache_clear($mode, &$dir, &$template)
- {
- $template_list = array();
- if ($mode == 'all')
- {
- $dp = opendir($dir . 'cache');
- while ($file = readdir($dp)) array_push($template_list, $file);
- closedir($dp);
- }
- else
+ if ($fp = @fopen($filename, 'w+'))
{
- array_push($template_list, $template);
- }
-
- foreach ($template_list as $template)
- {
- $dp = opendir($dir . 'cache/' . $template);
- while ($file = readdir($dp))
- {
- unlink($dir . 'cache/' . $template . '/' . $file);
- }
- closedir($dp);
- }
-
- return;
- }
-
- function compile_cache_show(&$template)
- {
- global $phpbb_root_path;
-
- $template_cache = array();
+ @flock($fp, LOCK_EX);
+ @fwrite ($fp, $data);
+ @flock($fp, LOCK_UN);
+ @fclose($fp);
- $dp = opendir($phpbb_root_path . 'templates/cache/' . $template . '/');
- while ($file = readdir($dp))
- {
- if (strstr($file, '.html') && is_file($phpbb_root_path . 'templates/cache/' . $template . '/' . $file))
- {
- array_push($template_cache, $file);
- }
+ @touch($filename, filemtime($this->files[$handle]));
+ @umask(0);
+ @chmod($filename, 0644);
}
- closedir($dp);
return;
}
-
- function decompile(&$_str, $savefile = false)
- {
- $match_tags = array(
- '#<\?php\nif \(\$this\->security\(\)\) \{(.*)[ \n]*?\n\}\n\?>$#s',
- '#echo \'(.*?)\';#s',
-
- '#\/\/ (INCLUDEPHP .*?)\n.?this\->assign_from_include_php\(\'.*?\'\);\n#s',
- '#\/\/ (INCLUDE .*?)\n.?this\->assign_from_include\(\'.*?\'\);[\n]?#s',
-
- '#\/\/ (IF .*?)\nif \(.*?\) \{[ ]?\n#',
- '#\/\/ (ELSEIF .*?)\n\} elseif \(.*?\) \{[ ]?\n#',
- '#\/\/ (ELSE)\n\} else \{\n#',
- '#[\n]?\/\/ (ENDIF)\n}#',
-
- '#\/\/ (BEGIN .*?)\n.?_.*? = \(.*?\) : 0;\nif \(.*?\) \{\nfor \(.*?\)\n\{\n#',
- '#\}\}?\n\/\/ (END .*?)\n#',
- '#\/\/ (BEGINELSE)[\n]+?\}\} else \{\n#',
-
- '#\' \. \(\(isset\(\$this\->_tpldata\[\'\.\'\]\[0\]\[\'(L_([A-Z0-9_])+?)\'\]\)\).*?\}\'\)\) \. \'#s',
-
- '#\' \. \(\(isset\(\$this\->_tpldata\[\'\.\'\]\[0\]\[\'([A-Z0-9_]+?)\'\]\)\).*?\'\'\) \. \'#s',
-
- '#\' \. \(\(isset\(\$this\->_tpldata\[\'([a-z0-9_\.]+?)\'\].*?[\'([a-z0-9_\.]+?)\'\].*?\[\'([A-Z0-9_]+?)\'\]\)\).*?\'\'\) \. \'#s',
- );
-
- $replace_tags = array(
- '\1',
- '\1',
- '<!-- \1 -->',
- '<!-- \1 -->',
- '<!-- \1 -->',
- '<!-- \1 -->',
- '<!-- \1 -->',
- '<!-- \1 -->',
- '<!-- \1 -->',
- '<!-- \1 -->',
- '<!-- \1 -->',
- '{\1}',
- '{\1}',
- '{\1\2\3}',
- );
-
- preg_match_all('#\/\/ PHP START\n(.*?)\n\/\/ PHP END\n#s', $_str, $matches);
- $php_blocks = $matches[1];
- $_str = preg_replace('#\/\/ PHP START\n(.*?)\/\/ PHP END\n#s', '<!-- PHP -->', $_str);
-
- $_str = preg_replace($match_tags, $replace_tags, $_str);
- $text_blocks = preg_split('#<!-- PHP -->#s', $_str);
-
- $_str = '';
- for ($i = 0; $i < count($text_blocks); $i++)
- {
- $_str .= $text_blocks[$i] . ((!empty($php_blocks[$i])) ? '<!-- PHP -->' . $php_blocks[$i] . '<!-- ENDPHP -->' : '');
- }
-
- $tmpfile = '';
- if ($savefile)
- {
- $tmpfile = tmpfile();
- fwrite($tmpfile, $_str);
- }
-
- return $_str;
- }
}
?> \ No newline at end of file