aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/template/compile.php
diff options
context:
space:
mode:
authorIgor Wiedler <igor@wiedler.ch>2012-07-21 15:36:25 +0200
committerIgor Wiedler <igor@wiedler.ch>2012-07-21 15:36:25 +0200
commit5d57caee58c58d2a9c283abe8fe88f4eaec9f662 (patch)
treecd36469a74bf6847e5305d1fb8f4ac35266813e2 /phpBB/includes/template/compile.php
parent3ebe89cb7eff57c3ffdbe0b7dcd9cdc35b48d26b (diff)
parent841ea0e494504400c798faa6cc860dd1179e1004 (diff)
downloadforums-5d57caee58c58d2a9c283abe8fe88f4eaec9f662.tar
forums-5d57caee58c58d2a9c283abe8fe88f4eaec9f662.tar.gz
forums-5d57caee58c58d2a9c283abe8fe88f4eaec9f662.tar.bz2
forums-5d57caee58c58d2a9c283abe8fe88f4eaec9f662.tar.xz
forums-5d57caee58c58d2a9c283abe8fe88f4eaec9f662.zip
Merge branch 'develop' into feature/dic
* develop: (441 commits) [feature/new-tz-handling] Don't use global user but make it a parameter [feature/new-tz-handling] Fix size of suggestion button in chrome [feature/new-tz-handling] Fall back to UTC, if the timezone is invalid [feature/new-tz-handling] Add previous selected value to validation if valid [feature/new-tz-handling] Display suggestion when a different value is selected [ticket/10998] Add border-radius to forum rules block - prosilver [feature/new-tz-handling] Remove additional marking of selected items [feature/new-tz-handling] Move update helper function to new class [feature/new-tz-handling] Fix unit test [feature/new-tz-handling] Delete old variable which is not used anymore [feature/new-tz-handling] Rename $user->tz back to $user->timezone [feature/pagination-as-list] New parameter for name of start var [feature/pagination-as-list] Updates for nils comments [feature/pagination-as-list] Rename and deprecate functions [feature/pagination-as-list] Various fixes and improvements [ticket/10968] Render pagination within the template [feature/new-tz-handling] Remove "timezone might be numeric" [feature/new-tz-handling] Add function to update the timezone [feature/new-tz-handling] Correctly update user and board timezones on update [ticket/10996] Use correct DBMS name in Travis config for PostgreSQL ... Conflicts: phpBB/common.php phpBB/composer.json phpBB/composer.lock tests/cron/task_provider_test.php
Diffstat (limited to 'phpBB/includes/template/compile.php')
-rw-r--r--phpBB/includes/template/compile.php128
1 files changed, 128 insertions, 0 deletions
diff --git a/phpBB/includes/template/compile.php b/phpBB/includes/template/compile.php
new file mode 100644
index 0000000000..82b301c1a2
--- /dev/null
+++ b/phpBB/includes/template/compile.php
@@ -0,0 +1,128 @@
+<?php
+/**
+*
+* @package phpBB3
+* @copyright (c) 2005 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+stream_filter_register('phpbb_template', 'phpbb_template_filter');
+
+/**
+* Extension of template class - Functions needed for compiling templates only.
+*
+* @package phpBB3
+* @uses template_filter As a PHP stream filter to perform compilation of templates
+*/
+class phpbb_template_compile
+{
+ /**
+ * Array of parameters to forward to template filter
+ *
+ * @var array
+ */
+ private $filter_params;
+
+ /**
+ * Constructor.
+ *
+ * @param bool @allow_php Whether PHP code will be allowed in templates (inline PHP code, PHP tag and INCLUDEPHP tag)
+ * @param phpbb_style_resource_locator $locator Resource locator
+ * @param string $phpbb_root_path Path to phpBB root directory
+ */
+ public function __construct($allow_php, $locator, $phpbb_root_path)
+ {
+ $this->filter_params = array(
+ 'allow_php' => $allow_php,
+ 'locator' => $locator,
+ 'phpbb_root_path' => $phpbb_root_path
+ );
+ }
+
+ /**
+ * Compiles template in $source_file and writes compiled template to
+ * cache directory
+ *
+ * @param string $handle Template handle to compile
+ * @param string $source_file Source template file
+ * @return bool Return true on success otherwise false
+ */
+ public function compile_file_to_file($source_file, $compiled_file)
+ {
+ $source_handle = @fopen($source_file, 'rb');
+ $destination_handle = @fopen($compiled_file, 'wb');
+
+ if (!$source_handle || !$destination_handle)
+ {
+ return false;
+ }
+
+ @flock($destination_handle, LOCK_EX);
+
+ $this->compile_stream_to_stream($source_handle, $destination_handle);
+
+ @fclose($source_handle);
+ @flock($destination_handle, LOCK_UN);
+ @fclose($destination_handle);
+
+ phpbb_chmod($compiled_file, CHMOD_READ | CHMOD_WRITE);
+
+ clearstatcache();
+
+ return true;
+ }
+
+ /**
+ * Compiles a template located at $source_file.
+ *
+ * Returns PHP source suitable for eval().
+ *
+ * @param string $source_file Source template file
+ * @return string|bool Return compiled code on successful compilation otherwise false
+ */
+ public function compile_file($source_file)
+ {
+ $source_handle = @fopen($source_file, 'rb');
+ $destination_handle = @fopen('php://temp' ,'r+b');
+
+ if (!$source_handle || !$destination_handle)
+ {
+ return false;
+ }
+
+ $this->compile_stream_to_stream($source_handle, $destination_handle);
+
+ @fclose($source_handle);
+
+ rewind($destination_handle);
+ $contents = stream_get_contents($destination_handle);
+ @fclose($dest_handle);
+
+ return $contents;
+ }
+
+ /**
+ * Compiles contents of $source_stream into $dest_stream.
+ *
+ * A stream filter is appended to $source_stream as part of the
+ * process.
+ *
+ * @param resource $source_stream Source stream
+ * @param resource $dest_stream Destination stream
+ * @return void
+ */
+ private function compile_stream_to_stream($source_stream, $dest_stream)
+ {
+ stream_filter_append($source_stream, 'phpbb_template', null, $this->filter_params);
+ stream_copy_to_stream($source_stream, $dest_stream);
+ }
+}