update plugin loading logic, look in SMARTY_DIR, then cwd. If all fail, then retry all with include_path

This commit is contained in:
mohrt
2002-06-26 21:17:27 +00:00
parent 9eb4b64890
commit adb457fdcc
6 changed files with 112 additions and 79 deletions

View File

@@ -1672,25 +1672,36 @@ function _run_insert_handler($args)
$_plugin_filepath = $_plugin_dir . DIR_SEP . $_plugin_filename; $_plugin_filepath = $_plugin_dir . DIR_SEP . $_plugin_filename;
if (@is_readable($_plugin_filepath)) { // see if path is relative
return $_plugin_filepath;
}
// didn't find it, see if path is relative
if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $_plugin_dir)) { if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $_plugin_dir)) {
$_relative = true;
// relative path, see if it is in the SMARTY_DIR // relative path, see if it is in the SMARTY_DIR
if (@is_readable(SMARTY_DIR . $_plugin_filepath)) { if (@is_readable(SMARTY_DIR . $_plugin_filepath)) {
return 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)) { if ($this->_get_include_path($_plugin_filepath, $_include_filepath)) {
return $_include_filepath; return $_include_filepath;
} }
} }
}
}
return false; return false;
} }

View File

@@ -359,9 +359,11 @@ Stock Name: {$ticker_name} Stock Price: {$ticker_price}</programlisting>
<para> <para>
Do you ever wonder how your E-mail address gets on so many spam mailing 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 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 help combat this problem, you can make your E-mail address show up in
scrambled looking form in the HTML source, yet it it will look and work scrambled javascript in the HTML source, yet it it will look and work
correctly in the browser. This is done with the escape modifier. 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.
</para> </para>
<example> <example>
<title>Example of Obfuscating an E-mail Address</title> <title>Example of Obfuscating an E-mail Address</title>
@@ -371,26 +373,15 @@ index.tpl
--------- ---------
Send inquiries to Send inquiries to
&lt;a href="mailto:{$EmailAddress|escape:"hex"}"&gt;{$EmailAddress|escape:"hexentity"}&lt;/a&gt; {mailto address=$EmailAddress encode="javascript" subject="Hello"}
OUTPUT:
Send inquiries to
&lt;a
href="mailto:%62%6f%62%40%6d%65%2e%6e%65%74"&gt;&amp;#x62;&amp;#x6f;&amp;#x62;&amp;#x40;&amp;#x6d;&amp;#x65;&amp;#x2e;&amp;#x6e;&amp;#x65;&amp;#x74;&lt;/a&gt;
</programlisting> </programlisting>
</example> </example>
<para>
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.
</para>
<note> <note>
<title>Technical Note</title> <title>Technical Note</title>
<para> <para>
This method isn't 100% foolproof. A spammer This method isn't 100% foolproof. A spammer could conceivably program his
could conceivably program his e-mail collector to decode these values. e-mail collector to decode these values, but not likely.
</para> </para>
</note> </note>
</sect1> </sect1>
@@ -398,7 +389,7 @@ href="mailto:%62%6f%62%40%6d%65%2e%6e%65%74"&gt;&amp;#x62;&amp;#x6f;&amp;#x62;&a
<chapter id="resources"> <chapter id="resources">
<title>Resources</title> <title>Resources</title>
<para> <para>
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 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 smarty-general-subscribe@lists.php.net. An archive of the mailing list can be
viewed at http://marc.theaimsgroup.com/?l=smarty&amp;r=1&amp;w=2 viewed at http://marc.theaimsgroup.com/?l=smarty&amp;r=1&amp;w=2

View File

@@ -3818,6 +3818,12 @@ OUTPUT:
root and supply the relative path to this file as the "src" root and supply the relative path to this file as the "src"
parameter to popup_init. parameter to popup_init.
</para> </para>
<example>
<title>popup_init</title>
<programlisting>
{* popup_init must be called once at the top of the page *}
{popup_init src="/javascripts/overlib.js"}</programlisting>
</example>
</sect1> </sect1>
<sect1 id="language.function.popup"> <sect1 id="language.function.popup">
<title>popup</title> <title>popup</title>

View File

@@ -153,8 +153,9 @@ debug.tpl
<para> <para>
You can either place these library files within your PHP include_path, or 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. in any directory as long as you define that with the <link
We'll show an example of both. linkend="constant.smarty.dir">SMARTY_DIR</link> constant. We'll show an
example of both.
</para> </para>
<para> <para>
Here is how you create an instance of Smarty in your PHP scripts: Here is how you create an instance of Smarty in your PHP scripts:
@@ -169,8 +170,9 @@ $smarty = new Smarty;</screen>
<para> <para>
If the library files are outside of your PHP include_path, you must define 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 the absolute path with the <link
slash. Lets say we place our Smarty library files in linkend="constant.smarty.dir">SMARTY_DIR</link> constant. SMARTY_DIR must
end with a slash. Lets say we place our Smarty library files in
"/usr/local/lib/php/Smarty/". "/usr/local/lib/php/Smarty/".
</para> </para>
@@ -238,11 +240,11 @@ $smarty = new Smarty;</screen>
<example> <example>
<title>Example file structure</title> <title>Example file structure</title>
<screen> <screen>
/php/includes/Smarty/Smarty.class.php /usr/local/lib/php/Smarty/Smarty.class.php
/php/includes/Smarty/Smarty_Compiler.class.php /usr/local/lib/php/Smarty/Smarty_Compiler.class.php
/php/includes/Smarty/Config_File.class.php /usr/local/lib/php/Smarty/Config_File.class.php
/php/includes/Smarty/debug.tpl /usr/local/lib/php/Smarty/debug.tpl
/php/includes/Smarty/plugins/*.php /usr/local/lib/php/Smarty/plugins/*.php
/web/www.mydomain.com/smarty/guestbook/templates/ /web/www.mydomain.com/smarty/guestbook/templates/
/web/www.mydomain.com/smarty/guestbook/templates_c/ /web/www.mydomain.com/smarty/guestbook/templates_c/
@@ -420,27 +422,5 @@ $smarty->display('index.tpl');</screen>
</sect1> </sect1>
<sect1 id="smarty.constants">
<title>Constants</title>
<para></para>
<sect2 id="constant.smarty.dir">
<title>SMARTY_DIR</title>
<para>
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.
</para>
<example>
<title>SMARTY_DIR</title>
<programlisting>
// set path to Smarty directory
define("SMARTY_DIR","/usr/local/lib/php/Smarty/");
require_once(SMARTY_DIR."Smarty.class.php");</programlisting>
</example>
</sect2>
</sect1>
</chapter> </chapter>
</part> </part>

View File

@@ -1,5 +1,30 @@
<part id="smarty.for.programmers"> <part id="smarty.for.programmers">
<title>Smarty For Programmers</title> <title>Smarty For Programmers</title>
<chapter id="smarty.constants">
<title>Constants</title>
<para></para>
<sect1 id="constant.smarty.dir">
<title>SMARTY_DIR</title>
<para>
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.
</para>
<example>
<title>SMARTY_DIR</title>
<programlisting>
// set path to Smarty directory
define("SMARTY_DIR","/usr/local/lib/php/Smarty/");
require_once(SMARTY_DIR."Smarty.class.php");</programlisting>
</example>
</sect1>
</chapter>
<chapter id="api.variables"> <chapter id="api.variables">
<title>Variables</title> <title>Variables</title>
@@ -15,7 +40,7 @@
<note> <note>
<title>Technical Note</title> <title>Technical Note</title>
<para> <para>
It is not mandatory to put this directory under It is not recommended to put this directory under
the web server document root. the web server document root.
</para> </para>
</note> </note>
@@ -39,7 +64,7 @@
<note> <note>
<title>Technical Note</title> <title>Technical Note</title>
<para> <para>
It is not mandatory to put this directory under It is not recommended to put this directory under
the web server document root. the web server document root.
</para> </para>
</note> </note>
@@ -55,7 +80,7 @@
<note> <note>
<title>Technical Note</title> <title>Technical Note</title>
<para> <para>
It is not mandatory to put this directory under It is not recommended to put this directory under
the web server document root. the web server document root.
</para> </para>
</note> </note>
@@ -63,11 +88,20 @@
<sect1 id="variable.plugins.dir"> <sect1 id="variable.plugins.dir">
<title>$plugins_dir</title> <title>$plugins_dir</title>
<para> <para>
This is the directory where Smarty will look for the plugins that This is the directories where Smarty will look for the plugins that it
it needs. The directory must be relative to the directory where needs. Default is "plugins" under the SMARTY_DIR. If you supply a
Smarty itself is installed. Default is "plugins". There can be relative path, Smarty will first look under the SMARTY_DIR, then
only one plugins directory. relative to the cwd (current working directory), then relative to each
entry in your PHP include path.
</para> </para>
<note>
<title>Technical Note</title>
<para>
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.
</para>
</note>
</sect1> </sect1>
<sect1 id="variable.debugging"> <sect1 id="variable.debugging">
<title>$debugging</title> <title>$debugging</title>
@@ -217,7 +251,7 @@ $smarty-&gt;autoload_filters = array('pre' =&gt; array('trim', 'stamp'),
<note> <note>
<title>Technical Note</title> <title>Technical Note</title>
<para> <para>
It is not mandatory to put this directory under It is not recommended to put this directory under
the web server document root. the web server document root.
</para> </para>
</note> </note>

View File

@@ -1672,25 +1672,36 @@ function _run_insert_handler($args)
$_plugin_filepath = $_plugin_dir . DIR_SEP . $_plugin_filename; $_plugin_filepath = $_plugin_dir . DIR_SEP . $_plugin_filename;
if (@is_readable($_plugin_filepath)) { // see if path is relative
return $_plugin_filepath;
}
// didn't find it, see if path is relative
if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $_plugin_dir)) { if (!preg_match("/^([\/\\\\]|[a-zA-Z]:[\/\\\\])/", $_plugin_dir)) {
$_relative = true;
// relative path, see if it is in the SMARTY_DIR // relative path, see if it is in the SMARTY_DIR
if (@is_readable(SMARTY_DIR . $_plugin_filepath)) { if (@is_readable(SMARTY_DIR . $_plugin_filepath)) {
return 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)) { if ($this->_get_include_path($_plugin_filepath, $_include_filepath)) {
return $_include_filepath; return $_include_filepath;
} }
} }
}
}
return false; return false;
} }