author | Dan |
Tue, 23 Sep 2008 23:26:15 -0400 | |
changeset 49 | d62212462f9b |
parent 0 | c63de9eb7045 |
permissions | -rw-r--r-- |
0
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
1 |
<?php |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
2 |
/** |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
3 |
* Smarty plugin |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
4 |
* @package Smarty |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
5 |
* @subpackage plugins |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
6 |
*/ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
7 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
8 |
/** |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
9 |
* Load requested plugins |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
10 |
* |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
11 |
* @param array $plugins |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
12 |
*/ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
13 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
14 |
// $plugins |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
15 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
16 |
function smarty_core_load_plugins($params, &$smarty) |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
17 |
{ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
18 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
19 |
foreach ($params['plugins'] as $_plugin_info) { |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
20 |
list($_type, $_name, $_tpl_file, $_tpl_line, $_delayed_loading) = $_plugin_info; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
21 |
$_plugin = &$smarty->_plugins[$_type][$_name]; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
22 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
23 |
/* |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
24 |
* We do not load plugin more than once for each instance of Smarty. |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
25 |
* The following code checks for that. The plugin can also be |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
26 |
* registered dynamically at runtime, in which case template file |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
27 |
* and line number will be unknown, so we fill them in. |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
28 |
* |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
29 |
* The final element of the info array is a flag that indicates |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
30 |
* whether the dynamically registered plugin function has been |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
31 |
* checked for existence yet or not. |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
32 |
*/ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
33 |
if (isset($_plugin)) { |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
34 |
if (empty($_plugin[3])) { |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
35 |
if (!is_callable($_plugin[0])) { |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
36 |
$smarty->_trigger_fatal_error("[plugin] $_type '$_name' is not implemented", $_tpl_file, $_tpl_line, __FILE__, __LINE__); |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
37 |
} else { |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
38 |
$_plugin[1] = $_tpl_file; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
39 |
$_plugin[2] = $_tpl_line; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
40 |
$_plugin[3] = true; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
41 |
if (!isset($_plugin[4])) $_plugin[4] = true; /* cacheable */ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
42 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
43 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
44 |
continue; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
45 |
} else if ($_type == 'insert') { |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
46 |
/* |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
47 |
* For backwards compatibility, we check for insert functions in |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
48 |
* the symbol table before trying to load them as a plugin. |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
49 |
*/ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
50 |
$_plugin_func = 'insert_' . $_name; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
51 |
if (function_exists($_plugin_func)) { |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
52 |
$_plugin = array($_plugin_func, $_tpl_file, $_tpl_line, true, false); |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
53 |
continue; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
54 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
55 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
56 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
57 |
$_plugin_file = $smarty->_get_plugin_filepath($_type, $_name); |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
58 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
59 |
if (! $_found = ($_plugin_file != false)) { |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
60 |
$_message = "could not load plugin file '$_type.$_name.php'\n"; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
61 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
62 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
63 |
/* |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
64 |
* If plugin file is found, it -must- provide the properly named |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
65 |
* plugin function. In case it doesn't, simply output the error and |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
66 |
* do not fall back on any other method. |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
67 |
*/ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
68 |
if ($_found) { |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
69 |
include_once $_plugin_file; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
70 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
71 |
$_plugin_func = 'smarty_' . $_type . '_' . $_name; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
72 |
if (!function_exists($_plugin_func)) { |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
73 |
$smarty->_trigger_fatal_error("[plugin] function $_plugin_func() not found in $_plugin_file", $_tpl_file, $_tpl_line, __FILE__, __LINE__); |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
74 |
continue; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
75 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
76 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
77 |
/* |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
78 |
* In case of insert plugins, their code may be loaded later via |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
79 |
* 'script' attribute. |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
80 |
*/ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
81 |
else if ($_type == 'insert' && $_delayed_loading) { |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
82 |
$_plugin_func = 'smarty_' . $_type . '_' . $_name; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
83 |
$_found = true; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
84 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
85 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
86 |
/* |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
87 |
* Plugin specific processing and error checking. |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
88 |
*/ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
89 |
if (!$_found) { |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
90 |
if ($_type == 'modifier') { |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
91 |
/* |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
92 |
* In case modifier falls back on using PHP functions |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
93 |
* directly, we only allow those specified in the security |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
94 |
* context. |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
95 |
*/ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
96 |
if ($smarty->security && !in_array($_name, $smarty->security_settings['MODIFIER_FUNCS'])) { |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
97 |
$_message = "(secure mode) modifier '$_name' is not allowed"; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
98 |
} else { |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
99 |
if (!function_exists($_name)) { |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
100 |
$_message = "modifier '$_name' is not implemented"; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
101 |
} else { |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
102 |
$_plugin_func = $_name; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
103 |
$_found = true; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
104 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
105 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
106 |
} else if ($_type == 'function') { |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
107 |
/* |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
108 |
* This is a catch-all situation. |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
109 |
*/ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
110 |
$_message = "unknown tag - '$_name'"; |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
111 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
112 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
113 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
114 |
if ($_found) { |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
115 |
$smarty->_plugins[$_type][$_name] = array($_plugin_func, $_tpl_file, $_tpl_line, true, true); |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
116 |
} else { |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
117 |
// output error |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
118 |
$smarty->_trigger_fatal_error('[plugin] ' . $_message, $_tpl_file, $_tpl_line, __FILE__, __LINE__); |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
119 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
120 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
121 |
} |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
122 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
123 |
/* vim: set expandtab: */ |
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
124 |
|
c63de9eb7045
First commit. Basic things are working and implemented (webserver, templating, DCOP interface)
Dan
parents:
diff
changeset
|
125 |
?> |