Skip to content

Commit

Permalink
moodle_page: MDL-12212 rewrite blocks_name_allowed_in_format to impro…
Browse files Browse the repository at this point in the history
…ve readability
  • Loading branch information
tjhunt committed May 6, 2009
1 parent f731028 commit cd2bc3c
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions lib/blocklib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cd2bc3c

Please sign in to comment.