From adb457fdcc9954de1ae9dd2a7d9b70d8b72e8082 Mon Sep 17 00:00:00 2001 From: mohrt Date: Wed, 26 Jun 2002 21:17:27 +0000 Subject: [PATCH] update plugin loading logic, look in SMARTY_DIR, then cwd. If all fail, then retry all with include_path --- Smarty.class.php | 33 +++++++++++++++++--------- docs/appendixes.sgml | 27 +++++++-------------- docs/designers.sgml | 6 +++++ docs/getting-started.sgml | 42 +++++++++----------------------- docs/programmers.sgml | 50 ++++++++++++++++++++++++++++++++------- libs/Smarty.class.php | 33 +++++++++++++++++--------- 6 files changed, 112 insertions(+), 79 deletions(-) diff --git a/Smarty.class.php b/Smarty.class.php index 58a6f521..c59be313 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -1672,25 +1672,36 @@ function _run_insert_handler($args) $_plugin_filepath = $_plugin_dir . DIR_SEP . $_plugin_filename; - if (@is_readable($_plugin_filepath)) { - return $_plugin_filepath; - } - - // didn't find it, see if path is relative + // see if path is relative if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $_plugin_dir)) { + $_relative = true; // relative path, see if it is in the SMARTY_DIR if (@is_readable(SMARTY_DIR . $_plugin_filepath)) { return SMARTY_DIR . $_plugin_filepath; } - // didn't find it, try include path + } else { + // absolute path + $_relative = false; + } + // try relative to cwd (or absolute) + if (@is_readable($_plugin_filepath)) { + return $_plugin_filepath; + } + } + + // still not found, try PHP include_path + if($_relative) { + foreach ((array)$this->plugins_dir as $_plugin_dir) { + + $_plugin_filepath = $_plugin_dir . DIR_SEP . $_plugin_filename; + if ($this->_get_include_path($_plugin_filepath, $_include_filepath)) { return $_include_filepath; } - } - - - } - + } + } + + return false; } diff --git a/docs/appendixes.sgml b/docs/appendixes.sgml index 9e8537ed..60f45e5d 100644 --- a/docs/appendixes.sgml +++ b/docs/appendixes.sgml @@ -359,9 +359,11 @@ Stock Name: {$ticker_name} Stock Price: {$ticker_price} Do you ever wonder how your E-mail address gets on so many spam mailing lists? One way spammers collect E-mail addresses is from web pages. To - help combat this problem, you can make your E-mail address show up in a - scrambled looking form in the HTML source, yet it it will look and work - correctly in the browser. This is done with the escape modifier. + help combat this problem, you can make your E-mail address show up in + scrambled javascript in the HTML source, yet it it will look and work + correctly in the browser. This is done with the mailto plugin, + available from the plugin repository on the Smarty website. Download + the plugin and drop it into the plugins directory. Example of Obfuscating an E-mail Address @@ -371,26 +373,15 @@ index.tpl --------- Send inquiries to -<a href="mailto:{$EmailAddress|escape:"hex"}">{$EmailAddress|escape:"hexentity"}</a> - -OUTPUT: - -Send inquiries to -<a -href="mailto:%62%6f%62%40%6d%65%2e%6e%65%74">&#x62;&#x6f;&#x62;&#x40;&#x6d;&#x65;&#x2e;&#x6e;&#x65;&#x74;</a> +{mailto address=$EmailAddress encode="javascript" subject="Hello"} - - Although this looks like a mess in the HTML source, it will render - correctly in your browser, and the mailto: hyperlink will go to the correct - address. - Technical Note - This method isn't 100% foolproof. A spammer - could conceivably program his e-mail collector to decode these values. + This method isn't 100% foolproof. A spammer could conceivably program his + e-mail collector to decode these values, but not likely. @@ -398,7 +389,7 @@ href="mailto:%62%6f%62%40%6d%65%2e%6e%65%74">&#x62;&#x6f;&#x62;&a Resources - Smarty's homepage is located at http://www.phpinsider.com/php/code/Smarty/. + Smarty's homepage is located at http://smarty.php.net/. You can join the mailing list by sending an e-mail to smarty-general-subscribe@lists.php.net. An archive of the mailing list can be viewed at http://marc.theaimsgroup.com/?l=smarty&r=1&w=2 diff --git a/docs/designers.sgml b/docs/designers.sgml index cc478539..68b943c7 100644 --- a/docs/designers.sgml +++ b/docs/designers.sgml @@ -3818,6 +3818,12 @@ OUTPUT: root and supply the relative path to this file as the "src" parameter to popup_init. + +popup_init + +{* popup_init must be called once at the top of the page *} +{popup_init src="/javascripts/overlib.js"} + popup diff --git a/docs/getting-started.sgml b/docs/getting-started.sgml index 457b8c07..de581ae0 100644 --- a/docs/getting-started.sgml +++ b/docs/getting-started.sgml @@ -153,8 +153,9 @@ debug.tpl You can either place these library files within your PHP include_path, or - in any directory as long as you define that with the SMARTY_DIR constant. - We'll show an example of both. + in any directory as long as you define that with the SMARTY_DIR constant. We'll show an + example of both. Here is how you create an instance of Smarty in your PHP scripts: @@ -169,8 +170,9 @@ $smarty = new Smarty; If the library files are outside of your PHP include_path, you must define - the absolute path with the SMARTY_DIR constant. SMARTY_DIR must end with a - slash. Lets say we place our Smarty library files in + the absolute path with the SMARTY_DIR constant. SMARTY_DIR must + end with a slash. Lets say we place our Smarty library files in "/usr/local/lib/php/Smarty/". @@ -238,11 +240,11 @@ $smarty = new Smarty; Example file structure -/php/includes/Smarty/Smarty.class.php -/php/includes/Smarty/Smarty_Compiler.class.php -/php/includes/Smarty/Config_File.class.php -/php/includes/Smarty/debug.tpl -/php/includes/Smarty/plugins/*.php +/usr/local/lib/php/Smarty/Smarty.class.php +/usr/local/lib/php/Smarty/Smarty_Compiler.class.php +/usr/local/lib/php/Smarty/Config_File.class.php +/usr/local/lib/php/Smarty/debug.tpl +/usr/local/lib/php/Smarty/plugins/*.php /web/www.mydomain.com/smarty/guestbook/templates/ /web/www.mydomain.com/smarty/guestbook/templates_c/ @@ -420,27 +422,5 @@ $smarty->display('index.tpl'); - - Constants - - - - SMARTY_DIR - - This should be the full system path to the location of the Smarty - class files. If this is not defined, then Smarty will attempt to - determine the appropriate value automatically. If defined, the path - must end with a slash. - - - SMARTY_DIR - -// set path to Smarty directory -define("SMARTY_DIR","/usr/local/lib/php/Smarty/"); - -require_once(SMARTY_DIR."Smarty.class.php"); - - - diff --git a/docs/programmers.sgml b/docs/programmers.sgml index d1d5e3ed..aab8d379 100644 --- a/docs/programmers.sgml +++ b/docs/programmers.sgml @@ -1,5 +1,30 @@ Smarty For Programmers + + + + Constants + + + + SMARTY_DIR + + This should be the full system path to the location of the Smarty + class files. If this is not defined, then Smarty will attempt to + determine the appropriate value automatically. If defined, the path + must end with a slash. + + + SMARTY_DIR + +// set path to Smarty directory +define("SMARTY_DIR","/usr/local/lib/php/Smarty/"); + +require_once(SMARTY_DIR."Smarty.class.php"); + + + + Variables @@ -15,7 +40,7 @@ Technical Note - It is not mandatory to put this directory under + It is not recommended to put this directory under the web server document root. @@ -39,7 +64,7 @@ Technical Note - It is not mandatory to put this directory under + It is not recommended to put this directory under the web server document root. @@ -55,7 +80,7 @@ Technical Note - It is not mandatory to put this directory under + It is not recommended to put this directory under the web server document root. @@ -63,11 +88,20 @@ $plugins_dir - This is the directory where Smarty will look for the plugins that - it needs. The directory must be relative to the directory where - Smarty itself is installed. Default is "plugins". There can be - only one plugins directory. + This is the directories where Smarty will look for the plugins that it + needs. Default is "plugins" under the SMARTY_DIR. If you supply a + relative path, Smarty will first look under the SMARTY_DIR, then + relative to the cwd (current working directory), then relative to each + entry in your PHP include path. + + Technical Note + + For best performance, do not setup your plugins_dir to have to use the + PHP include path. Use an absolute pathname, or a path relative to + SMARTY_DIR or the cwd. + + $debugging @@ -217,7 +251,7 @@ $smarty->autoload_filters = array('pre' => array('trim', 'stamp'), Technical Note - It is not mandatory to put this directory under + It is not recommended to put this directory under the web server document root. diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 58a6f521..c59be313 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -1672,25 +1672,36 @@ function _run_insert_handler($args) $_plugin_filepath = $_plugin_dir . DIR_SEP . $_plugin_filename; - if (@is_readable($_plugin_filepath)) { - return $_plugin_filepath; - } - - // didn't find it, see if path is relative + // see if path is relative if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $_plugin_dir)) { + $_relative = true; // relative path, see if it is in the SMARTY_DIR if (@is_readable(SMARTY_DIR . $_plugin_filepath)) { return SMARTY_DIR . $_plugin_filepath; } - // didn't find it, try include path + } else { + // absolute path + $_relative = false; + } + // try relative to cwd (or absolute) + if (@is_readable($_plugin_filepath)) { + return $_plugin_filepath; + } + } + + // still not found, try PHP include_path + if($_relative) { + foreach ((array)$this->plugins_dir as $_plugin_dir) { + + $_plugin_filepath = $_plugin_dir . DIR_SEP . $_plugin_filename; + if ($this->_get_include_path($_plugin_filepath, $_include_filepath)) { return $_include_filepath; } - } - - - } - + } + } + + return false; }