Редакция 2 | Только различия | Не учитывать пробелы | Содержимое файла | Авторство | Последнее изменение | Открыть журнал | RSS
Редакция 2 | Редакция 3 | ||
---|---|---|---|
1 | <?php
|
1 | <?php
|
2 | /**
|
2 | /**
|
3 | * Smarty plugin
|
3 | * Smarty plugin
|
4 | * @package Smarty
|
4 | * @package Smarty
|
5 | * @subpackage plugins
|
5 | * @subpackage plugins
|
6 | */
|
6 | */
|
7 | 7 | ||
8 | /**
|
8 | /**
|
9 | * load a resource plugin
|
9 | * load a resource plugin
|
10 | *
|
10 | *
|
11 | * @param string $type
|
11 | * @param string $type
|
12 | */
|
12 | */
|
13 | 13 | ||
14 | // $type
|
14 | // $type
|
15 | 15 | ||
16 | function smarty_core_load_resource_plugin($params, &$smarty) |
16 | function smarty_core_load_resource_plugin($params, &$smarty) |
17 | {
|
17 | {
|
18 | /*
|
18 | /*
|
19 | * Resource plugins are not quite like the other ones, so they are
|
19 | * Resource plugins are not quite like the other ones, so they are
|
20 | * handled differently. The first element of plugin info is the array of
|
20 | * handled differently. The first element of plugin info is the array of
|
21 | * functions provided by the plugin, the second one indicates whether
|
21 | * functions provided by the plugin, the second one indicates whether
|
22 | * all of them exist or not.
|
22 | * all of them exist or not.
|
23 | */
|
23 | */
|
24 | 24 | ||
25 | $_plugin = &$smarty->_plugins['resource'][$params['type']]; |
25 | $_plugin = &$smarty->_plugins['resource'][$params['type']]; |
26 | if (isset($_plugin)) { |
26 | if (isset($_plugin)) { |
27 | if (!$_plugin[1] && count($_plugin[0])) { |
27 | if (!$_plugin[1] && count($_plugin[0])) { |
28 | $_plugin[1] = true; |
28 | $_plugin[1] = true; |
29 | foreach ($_plugin[0] as $_plugin_func) { |
29 | foreach ($_plugin[0] as $_plugin_func) { |
30 | if (!is_callable($_plugin_func)) { |
30 | if (!is_callable($_plugin_func)) { |
31 | $_plugin[1] = false; |
31 | $_plugin[1] = false; |
32 | break; |
32 | break; |
33 | }
|
33 | }
|
34 | }
|
34 | }
|
35 | }
|
35 | }
|
36 | 36 | ||
37 | if (!$_plugin[1]) { |
37 | if (!$_plugin[1]) { |
38 | $smarty->_trigger_fatal_error("[plugin] resource '" . $params['type'] . "' is not implemented", null, null, __FILE__, __LINE__); |
38 | $smarty->_trigger_fatal_error("[plugin] resource '" . $params['type'] . "' is not implemented", null, null, __FILE__, __LINE__); |
39 | }
|
39 | }
|
40 | 40 | ||
41 | return; |
41 | return; |
42 | }
|
42 | }
|
43 | 43 | ||
44 | $_plugin_file = $smarty->_get_plugin_filepath('resource', $params['type']); |
44 | $_plugin_file = $smarty->_get_plugin_filepath('resource', $params['type']); |
45 | $_found = ($_plugin_file != false); |
45 | $_found = ($_plugin_file != false); |
46 | 46 | ||
47 | if ($_found) { /* |
47 | if ($_found) { /* |
48 | * If the plugin file is found, it -must- provide the properly named
|
48 | * If the plugin file is found, it -must- provide the properly named
|
49 | * plugin functions.
|
49 | * plugin functions.
|
50 | */
|
50 | */
|
51 | include_once($_plugin_file); |
51 | include_once($_plugin_file); |
52 | 52 | ||
53 | /*
|
53 | /*
|
54 | * Locate functions that we require the plugin to provide.
|
54 | * Locate functions that we require the plugin to provide.
|
55 | */
|
55 | */
|
56 | $_resource_ops = array('source', 'timestamp', 'secure', 'trusted'); |
56 | $_resource_ops = array('source', 'timestamp', 'secure', 'trusted'); |
57 | $_resource_funcs = array(); |
57 | $_resource_funcs = array(); |
58 | foreach ($_resource_ops as $_op) { |
58 | foreach ($_resource_ops as $_op) { |
59 | $_plugin_func = 'smarty_resource_' . $params['type'] . '_' . $_op; |
59 | $_plugin_func = 'smarty_resource_' . $params['type'] . '_' . $_op; |
60 | if (!function_exists($_plugin_func)) { |
60 | if (!function_exists($_plugin_func)) { |
61 | $smarty->_trigger_fatal_error("[plugin] function $_plugin_func() not found in $_plugin_file", null, null, __FILE__, __LINE__); |
61 | $smarty->_trigger_fatal_error("[plugin] function $_plugin_func() not found in $_plugin_file", null, null, __FILE__, __LINE__); |
62 | return; |
62 | return; |
63 | } else { |
63 | } else { |
64 | $_resource_funcs[] = $_plugin_func; |
64 | $_resource_funcs[] = $_plugin_func; |
65 | }
|
65 | }
|
66 | }
|
66 | }
|
67 | 67 | ||
68 | $smarty->_plugins['resource'][$params['type']] = array($_resource_funcs, true); |
68 | $smarty->_plugins['resource'][$params['type']] = array($_resource_funcs, true); |
69 | }
|
69 | }
|
70 | }
|
70 | }
|
71 | 71 | ||
72 | /* vim: set expandtab: */
|
72 | /* vim: set expandtab: */
|
73 | 73 | ||
74 | ?>
|
74 | ?>
|
75 | 75 |