From: tjhunt Date: Wed, 6 May 2009 08:36:50 +0000 (+0000) Subject: moodle_page: MDL-12212 rewrite blocks_name_allowed_in_format to improve readability X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=cd2bc3c98a18009ac0ecd146ae5646362993d212;p=moodle.git moodle_page: MDL-12212 rewrite blocks_name_allowed_in_format to improve readability --- diff --git a/lib/blocklib.php b/lib/blocklib.php index 8035049114..9f7273155f 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -132,21 +132,21 @@ function blocks_remove_inappropriate($page) { } function blocks_name_allowed_in_format($name, $pageformat) { - - $accept = NULL; - $depth = -1; - if ($formats = block_method_result($name, 'applicable_formats')) { - foreach($formats as $format => $allowed) { - $thisformat = '^'.str_replace('*', '[^-]*', $format).'.*$'; - if(ereg($thisformat, $pageformat)) { - if(($scount = substr_count($format, '-')) > $depth) { - $depth = $scount; - $accept = $allowed; - } - } + $accept = NULL; + $maxdepth = -1; + $formats = block_method_result($name, 'applicable_formats'); + if (!$formats) { + $formats = array(); + } + foreach ($formats as $format => $allowed) { + $formatregex = '/^'.str_replace('*', '[^-]*', $format).'.*$/'; + $depth = substr_count($format, '-'); + if (preg_match($formatregex, $pageformat) && $depth > $maxdepth) { + $maxdepth = $depth; + $accept = $allowed; } } - if($accept === NULL) { + if ($accept === NULL) { $accept = !empty($formats['all']); } return $accept;