--- /dev/null
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=6
+
+inherit php-pear-r2
+
+DESCRIPTION="Integrated Templates"
+LICENSE="BSD"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~hppa ~ia64 ~ppc ~ppc64 ~x86"
+IUSE="examples test"
+DEPEND="test? ( dev-php/phpunit ${RDEPEND} )"
+
+src_prepare() {
+ eapply "${FILESDIR}/preg-callback.patch" \
+ "${FILESDIR}/constructor.patch"
+ eapply_user
+}
+
+src_install() {
+ use examples && HTML_DOCS=(
+ examples/sample_it.php
+ examples/sample_itx_addblockfile.php
+ examples/templates/
+ )
+ php-pear-r2_src_install
+}
+
+src_test() {
+ phpunit tests/AllTests.php || die
+}
--- /dev/null
+diff -aurN a/HTML/Template/IT_Error.php b/HTML/Template/IT_Error.php
+--- a/HTML/Template/IT_Error.php 2010-03-10 03:08:10.000000000 -0500
++++ b/HTML/Template/IT_Error.php 2017-08-01 16:44:31.257269180 -0400
+@@ -58,8 +58,11 @@
+ */\r
+ function IT_Error($msg, $file = __FILE__, $line = __LINE__)\r
+ {\r
++ $this->__construct($msg, $file, $line);\r
++ }\r
++ function __construct($msg, $file = __FILE__, $line = __LINE__)\r
++ {\r
+ $this->PEAR_Error(sprintf("%s [%s on line %d].", $msg, $file, $line)); \r
+ } // end func IT_Error\r
+ \r
+ } // end class IT_Error\r
+-?>\r
+diff -aurN a/HTML/Template/IT.php b/HTML/Template/IT.php
+--- a/HTML/Template/IT.php 2017-08-01 16:40:29.822907534 -0400
++++ b/HTML/Template/IT.php 2017-08-01 16:44:46.515860952 -0400
+@@ -409,6 +409,10 @@
+ */\r
+ function HTML_Template_IT($root = '', $options = null)\r
+ {\r
++ $this->__construct($root, $options);\r
++ }\r
++ function __construct($root = '', $options = null)\r
++ {\r
+ if (!is_null($options)) {\r
+ $this->setOptions($options);\r
+ }\r
+@@ -1184,4 +1188,3 @@
+ $errorMessages[$value] : $errorMessages[IT_ERROR];\r
+ }\r
+ } // end class IntegratedTemplate\r
+-?>\r
+diff -aurN a/HTML/Template/ITX.php b/HTML/Template/ITX.php
+--- a/HTML/Template/ITX.php 2010-03-10 03:08:10.000000000 -0500
++++ b/HTML/Template/ITX.php 2017-08-01 16:44:41.185654236 -0400
+@@ -138,13 +138,17 @@
+ */\r
+ function HTML_Template_ITX($root = '')\r
+ {\r
++ $this->__construct($root);\r
++ }\r
++ function __construct($root = '')\r
++ {\r
+ \r
+ $this->checkblocknameRegExp = '@' . $this->blocknameRegExp . '@';\r
+ \r
+ $this->functionRegExp = '@' . $this->functionPrefix . '(' .\r
+ $this->functionnameRegExp . ')\s*\(@sm';\r
+ \r
+- $this->HTML_Template_IT($root);\r
++ parent::__construct($root);\r
+ } // end func constructor\r
+ \r
+ /**\r
+@@ -886,4 +890,3 @@
+ } // end func warning\r
+ \r
+ } // end class HTML_Template_ITX\r
+-?>\r
--- /dev/null
+diff -aurN a/HTML/Template/IT.php b/HTML/Template/IT.php
+--- a/HTML/Template/IT.php 2010-03-10 03:08:10.000000000 -0500
++++ b/HTML/Template/IT.php 2017-08-01 15:12:31.161235223 -0400
+@@ -1088,9 +1088,10 @@
+ $content = fread($fh, $fsize);\r
+ fclose($fh);\r
+ \r
+- return preg_replace(\r
+- "#<!-- INCLUDE (.*) -->#ime",\r
+- "\$this->getFile('\\1')",\r
++ return preg_replace_callback(\r
++ "#<!-- INCLUDE (.*) -->#im",\r
++ function($matches) {\r
++ return $this->getFile($matches[1]); },\r
+ $content\r
+ );\r
+ } // end func getFile\r