Skip to content

Commit

Permalink
MDL-29504 fix invalid plugin callback names
Browse files Browse the repository at this point in the history
Only modules are allow to use old style non-frankenstyle callback names, all other plugins must use full component prefix.
  • Loading branch information
skodak committed Sep 26, 2011
1 parent aff2431 commit 60c452b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 3 additions & 3 deletions blocks/comments/lib.php
Expand Up @@ -37,7 +37,7 @@
* }
* @return boolean
*/
function comments_comment_validate($comment_param) {
function block_comments_comment_validate($comment_param) {
if ($comment_param->commentarea != 'page_comments') {
throw new comment_exception('invalidcommentarea');
}
Expand All @@ -53,7 +53,7 @@ function comments_comment_validate($comment_param) {
* @param stdClass $args
* @return array
*/
function comments_comment_permissions($args) {
function block_comments_comment_permissions($args) {
return array('post'=>true, 'view'=>true);
}

Expand All @@ -64,7 +64,7 @@ function comments_comment_permissions($args) {
* @param stdClass $args
* @return boolean
*/
function comments_comment_display($comments, $args) {
function block_comments_comment_display($comments, $args) {
if ($args->commentarea != 'page_comments') {
throw new comment_exception('invalidcommentarea');
}
Expand Down
17 changes: 16 additions & 1 deletion lib/moodlelib.php
Expand Up @@ -7552,12 +7552,20 @@ function get_list_of_plugins($directory='mod', $exclude='', $basedir='') {
* @return mixed
*/
function plugin_callback($type, $name, $feature, $action, $options = null, $default=null) {
global $CFG;

$component = clean_param($type . '_' . $name, PARAM_COMPONENT);
if (empty($component)) {
throw coding_exception('Invalid component used in plugin_callback():' . $type . '_' . $name);
}

$function = $name.'_'.$feature.'_'.$action;
list($type, $name) = normalize_component($component);
$component = $type . '_' . $name;

$function = null;

$function = $component.'_'.$feature.'_'.$action;
$oldfunction = $name.'_'.$feature.'_'.$action;

$dir = get_component_directory($component);
if (empty($dir)) {
Expand All @@ -7569,6 +7577,13 @@ function plugin_callback($type, $name, $feature, $action, $options = null, $defa
require_once($dir.'/lib.php');
}

if (!function_exists($function) and function_exists($oldfunction)) {
if ($type !== 'mod' and $type !== 'core') {
debugging("Please use new function name $function instead of legacy $oldfunction");
}
$function = $oldfunction;
}

if (function_exists($function)) {
// Function exists, so just return function result
$ret = call_user_func_array($function, (array)$options);
Expand Down

0 comments on commit 60c452b

Please sign in to comment.