-
-
Save totten/cf6a22150ca7944b14ee to your computer and use it in GitHub Desktop.
Reformatted https://github.com/ojkelly/civicrm-packages/commit/4e88b13ef5263ac874c9922c2dd6c1051a59f1f0 . First, ran PHPStorm autoformat on both sides of the diff, then manually tweaked one side for non-functional changes, and finall used "diff -wu"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- Smarty/Smarty.class.php.orig.af 2015-01-26 15:26:16.000000000 -0800 | |
+++ Smarty/Smarty.class.php.ojk.afc 2015-01-26 15:35:06.000000000 -0800 | |
@@ -137,7 +137,7 @@ | |
* | |
* @var boolean | |
*/ | |
- var $compile_check = TRUE; | |
+ var $compile_check = FALSE; | |
/** | |
* This forces templates to compile every time. Useful for development | |
@@ -163,8 +163,8 @@ | |
* | |
* @var string | |
*/ | |
- var $cache_dir = 'cache'; | |
- | |
+ //var $cwd = getcwd() ; | |
+ var $cache_dir = 'cache'; // Figure out how to locate this | |
/** | |
* This is the number of seconds cached content will persist. | |
* <ul> | |
@@ -174,7 +174,7 @@ | |
* | |
* @var integer | |
*/ | |
- var $cache_lifetime = 3600; | |
+ var $cache_lifetime = 14400; // One Day | |
/** | |
* Only used when $caching is enabled. If true, then If-Modified-Since headers | |
@@ -1017,18 +1017,21 @@ | |
* @return boolean results of {@link smarty_core_rm_auto()} | |
*/ | |
function clear_compiled_tpl($tpl_file = NULL, $compile_id = NULL, $exp_time = NULL) { | |
- if (!isset($compile_id)) { | |
- $compile_id = $this->compile_id; | |
- } | |
- $_params = array( | |
- 'auto_base' => $this->compile_dir, | |
- 'auto_source' => $tpl_file, | |
- 'auto_id' => $compile_id, | |
- 'exp_time' => $exp_time, | |
- 'extensions' => array('.inc', '.php') | |
- ); | |
- require_once(SMARTY_CORE_DIR . 'core.rm_auto.php'); | |
- return smarty_core_rm_auto($_params, $this); | |
+// if (!isset($compile_id)) { | |
+// $compile_id = $this->compile_id; | |
+// } | |
+// $_params = array( | |
+// 'auto_base' => $this->compile_dir, | |
+// 'auto_source' => $tpl_file, | |
+// 'auto_id' => $compile_id, | |
+// 'exp_time' => $exp_time, | |
+// 'extensions' => array('.inc', '.php') | |
+// ); | |
+// require_once(SMARTY_CORE_DIR . 'core.rm_auto.php'); | |
+// return smarty_core_rm_auto($_params, $this); | |
+ | |
+ cache_clear_all(NULL, 'smarty'); | |
+ return TRUE; | |
} | |
/** | |
@@ -1264,7 +1267,13 @@ | |
if ($this->_is_compiled($resource_name, $_smarty_compile_path) | |
|| $this->_compile_resource($resource_name, $_smarty_compile_path) | |
) { | |
- include($_smarty_compile_path); | |
+ $get = cache_get($_smarty_compile_path, 'smarty'); | |
+ if ($get) { | |
+ eval('?>' . $get->data . '<?php '); | |
+ } | |
+ else { | |
+ watchdog('smarty error 1', 'not in cache: ' . $_smarty_compile_path); | |
+ } | |
} | |
} | |
else { | |
@@ -1272,7 +1281,13 @@ | |
if ($this->_is_compiled($resource_name, $_smarty_compile_path) | |
|| $this->_compile_resource($resource_name, $_smarty_compile_path) | |
) { | |
- include($_smarty_compile_path); | |
+ $get = cache_get($_smarty_compile_path, 'smarty'); | |
+ if ($get) { | |
+ eval('?>' . $get->data . '<?php '); | |
+ } | |
+ else { | |
+ watchdog('smarty error 2', 'not in cache: ' . $_smarty_compile_path); | |
+ } | |
} | |
$_smarty_results = ob_get_contents(); | |
ob_end_clean(); | |
@@ -1329,6 +1344,118 @@ | |
} | |
/** | |
+ * Precompile smarty tempaltes | |
+ * @param $resource_name | |
+ * @param null $cache_id | |
+ * @param null $compile_id | |
+ * @param bool $display | |
+ * @return bool|string | |
+ */ | |
+ function precompile($resource_name, $cache_id = NULL, $compile_id = NULL, $display = FALSE) { | |
+ static $_cache_info = array(); | |
+ | |
+ $_smarty_old_error_level = $this->debugging | |
+ ? error_reporting() | |
+ : error_reporting(isset($this->error_reporting) | |
+ ? $this->error_reporting : error_reporting() & ~E_NOTICE); | |
+ | |
+ if (!$this->debugging && $this->debugging_ctrl == 'URL') { | |
+ $_query_string = $this->request_use_auto_globals ? $_SERVER['QUERY_STRING'] | |
+ : $GLOBALS['HTTP_SERVER_VARS']['QUERY_STRING']; | |
+ if (@strstr($_query_string, $this->_smarty_debug_id)) { | |
+ if (@strstr($_query_string, $this->_smarty_debug_id . '=on')) { | |
+ // enable debugging for this browser session | |
+ @setcookie('SMARTY_DEBUG', TRUE); | |
+ $this->debugging = TRUE; | |
+ } | |
+ elseif (@strstr($_query_string, $this->_smarty_debug_id . '=off')) { | |
+ // disable debugging for this browser session | |
+ @setcookie('SMARTY_DEBUG', FALSE); | |
+ $this->debugging = FALSE; | |
+ } | |
+ else { | |
+ // enable debugging for this page | |
+ $this->debugging = TRUE; | |
+ } | |
+ } | |
+ else { | |
+ $this->debugging = (bool) ($this->request_use_auto_globals ? @$_COOKIE['SMARTY_DEBUG'] | |
+ : @$GLOBALS['HTTP_COOKIE_VARS']['SMARTY_DEBUG']); | |
+ } | |
+ } | |
+ | |
+ if ($this->debugging) { | |
+ // capture time for debugging info | |
+ $_params = array(); | |
+ require_once(SMARTY_CORE_DIR . 'core.get_microtime.php'); | |
+ $_debug_start_time = smarty_core_get_microtime($_params, $this); | |
+ $this->_smarty_debug_info[] = array( | |
+ 'type' => 'template', | |
+ 'filename' => $resource_name, | |
+ 'depth' => 0 | |
+ ); | |
+ $_included_tpls_idx = count($this->_smarty_debug_info) - 1; | |
+ } | |
+ | |
+ if (!isset($compile_id)) { | |
+ $compile_id = $this->compile_id; | |
+ } | |
+ | |
+ $this->_compile_id = $compile_id; | |
+ $this->_inclusion_depth = 0; | |
+ | |
+ // load filters that are marked as autoload | |
+ if (count($this->autoload_filters)) { | |
+ foreach ($this->autoload_filters as $_filter_type => $_filters) { | |
+ foreach ($_filters as $_filter) { | |
+ $this->load_filter($_filter_type, $_filter); | |
+ } | |
+ } | |
+ } | |
+ | |
+ $_smarty_compile_path = $this->_get_compile_path($resource_name); | |
+ | |
+ // if we just need to display the results, don't perform output | |
+ // buffering - for speed | |
+ $_cache_including = $this->_cache_including; | |
+ $this->_cache_including = FALSE; | |
+ if ($display && !$this->caching && count($this->_plugins['outputfilter']) == 0) { | |
+ if ($this->_is_compiled($resource_name, $_smarty_compile_path) | |
+ || $this->_compile_resource($resource_name, $_smarty_compile_path) | |
+ ) { | |
+ $get = cache_get($_smarty_compile_path, 'smarty'); | |
+ if ($get) { | |
+ eval('?>' . $get->data . '<?php '); | |
+ } | |
+ else { | |
+ watchdog('smarty error 3', 'not in cache: ' . $_smarty_compile_path); | |
+ } | |
+ } | |
+ } | |
+ else { | |
+ ob_start(); | |
+ if ($this->_is_compiled($resource_name, $_smarty_compile_path) | |
+ || $this->_compile_resource($resource_name, $_smarty_compile_path) | |
+ ) { | |
+ $get = cache_get($_smarty_compile_path, 'smarty'); | |
+ if ($get) { | |
+ eval('?>' . $get->data . '<?php '); | |
+ } | |
+ else { | |
+ watchdog('smarty error 4', 'not in cache: ' . $_smarty_compile_path); | |
+ } | |
+ } | |
+ $_smarty_results = ob_get_contents(); | |
+ ob_end_clean(); | |
+ | |
+ foreach ((array) $this->_plugins['outputfilter'] as $_output_filter) { | |
+ $_smarty_results = call_user_func_array($_output_filter[0], array($_smarty_results, &$this)); | |
+ } | |
+ } | |
+ | |
+ } | |
+ | |
+ /** | |
* load configuration values | |
* | |
* @param string $file | |
@@ -1546,15 +1673,15 @@ | |
//for 'string:' resource smarty might going to fail to create | |
//compile file, so make sure we should have valid path, CRM-5890 | |
- $matches = array(); | |
- if (preg_match('/^(\s+)?string:/', $resource_name, $matches)) { | |
- if (!$this->validateCompilePath($compilePath)) { | |
- $compilePath = $this->_get_auto_filename($this->compile_dir, | |
- time() . rand(), | |
- $this->_compile_id); | |
- $compilePath .= '.php'; | |
- } | |
- } | |
+// $matches = array(); | |
+// if (preg_match('/^(\s+)?string:/', $resource_name, $matches)) { | |
+// if (!$this->validateCompilePath($compilePath)) { | |
+// $compilePath = $this->_get_auto_filename($this->compile_dir, | |
+// time() . rand(), | |
+// $this->_compile_id); | |
+// $compilePath .= '.php'; | |
+// } | |
+// } | |
return $compilePath; | |
} | |
@@ -1952,7 +2079,14 @@ | |
if ($this->_is_compiled($params['smarty_include_tpl_file'], $_smarty_compile_path) | |
|| $this->_compile_resource($params['smarty_include_tpl_file'], $_smarty_compile_path) | |
) { | |
- include($_smarty_compile_path); | |
+ $get = cache_get($_smarty_compile_path, 'smarty'); | |
+ if ($get) { | |
+ eval('?>' . $get->data . '<?php '); | |
+ } | |
+ else { | |
+ watchdog('smarty error 5', 'not in cache: ' . $_smarty_compile_path); | |
+ } | |
+ | |
} | |
// pop the local vars off the front of the stack | |
@@ -2034,6 +2168,16 @@ | |
} | |
} | |
+ function smarty_eval($file) { | |
+ eval('?>' . $file . '<?php '); | |
+ } | |
+ | |
+ function get_file_owner($file) { | |
+ clearstatcache(FALSE, $file); | |
+ $stat = stat($file); | |
+ return print_r($stat, TRUE); | |
+ } | |
+ | |
/**#@-*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ojkelly says that precompile() is not needed, that get_file_owner() is orphaned and that smarty_eval() is a wrapper for eval(). Looks like smarty_eval() isn't being called, but it probably good be by replacing:
with:
So this patch could probably be tightened up even more.