Revision | 3cd16deb819809263f898d5527f235e55ea15d3d (tree) |
---|---|
Time | 2014-11-29 14:58:44 |
Author | henoheno <henoheno> |
Commiter | umorigu |
BugTrack2/246: do_plugin_init(): KISS.
* This API do one thing: "FALSE or not". Forget meanless rule about NULL.
* htmlspecialchars() everywhere.
@@ -68,19 +68,14 @@ function exist_plugin_inline($name) { | ||
68 | 68 | } |
69 | 69 | |
70 | 70 | // Do init the plugin |
71 | +// NOTE: Returning FALSE from $func, means "an erorr occurerd" | |
71 | 72 | function do_plugin_init($name) |
72 | 73 | { |
73 | 74 | static $checked = array(); |
74 | 75 | |
75 | - // TRUE or FALSE or NULL (Return nothing / Not exists) | |
76 | - if (array_key_exists($name, $checked)) return $checked[$name]; | |
77 | - | |
78 | - $func = 'plugin_' . $name . '_init'; | |
79 | - if (function_exists($func)) { | |
80 | - $result = call_user_func($func); | |
81 | - $checked[$name] = ($result === NULL) ? NULL : (bool)$result; | |
82 | - } else { | |
83 | - $checked[$name] = NULL; | |
76 | + if (! isset($checked[$name])) { | |
77 | + $func = 'plugin_' . $name . '_init'; | |
78 | + $checked[$name] = (! function_exists($func) || call_user_func($func) !== FALSE); | |
84 | 79 | } |
85 | 80 | |
86 | 81 | return $checked[$name]; |
@@ -91,8 +86,9 @@ function do_plugin_action($name) | ||
91 | 86 | { |
92 | 87 | if (! exist_plugin_action($name)) return array(); |
93 | 88 | |
94 | - if(do_plugin_init($name) === FALSE) | |
95 | - die_message('Plugin init failed: ' . $name); | |
89 | + if (do_plugin_init($name) === FALSE) { | |
90 | + die_message('Plugin init failed: ' . htmlspecialchars($name)); | |
91 | + } | |
96 | 92 | |
97 | 93 | $retvar = call_user_func('plugin_' . $name . '_action'); |
98 | 94 |
@@ -110,8 +106,9 @@ function do_plugin_convert($name, $args = '') | ||
110 | 106 | { |
111 | 107 | global $digest; |
112 | 108 | |
113 | - if(do_plugin_init($name) === FALSE) | |
114 | - return '[Plugin init failed: ' . $name . ']'; | |
109 | + if (do_plugin_init($name) === FALSE) { | |
110 | + return '[Plugin init failed: ' . htmlspecialchars($name) . ']'; | |
111 | + } | |
115 | 112 | |
116 | 113 | if (! PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK) { |
117 | 114 | // Multiline plugin? |
@@ -153,13 +150,14 @@ function do_plugin_inline($name, $args, & $body) | ||
153 | 150 | { |
154 | 151 | global $digest; |
155 | 152 | |
156 | - if(do_plugin_init($name) === FALSE) | |
157 | - return '[Plugin init failed: ' . $name . ']'; | |
153 | + if (do_plugin_init($name) === FALSE) { | |
154 | + return '[Plugin init failed: ' . htmlspecialchars($name) . ']'; | |
155 | + } | |
158 | 156 | |
159 | - if ($args !== '') { | |
160 | - $aryargs = csv_explode(',', $args); | |
161 | - } else { | |
157 | + if ($args === '') { | |
162 | 158 | $aryargs = array(); |
159 | + } else { | |
160 | + $aryargs = csv_explode(',', $args); | |
163 | 161 | } |
164 | 162 | |
165 | 163 | // NOTE: A reference of $body is always the last argument |