]> git.mjollnir.org Git - moodle.git/commitdiff
moodle_page: MDL-12212 rewrite blocks_name_allowed_in_format to improve readability
authortjhunt <tjhunt>
Wed, 6 May 2009 08:36:50 +0000 (08:36 +0000)
committertjhunt <tjhunt>
Wed, 6 May 2009 08:36:50 +0000 (08:36 +0000)
lib/blocklib.php

index 80350491141efabbdbeb82b3f96f09bde16c5c6c..9f7273155f1e37950ca9c6119a3f38ca6cd291ce 100644 (file)
@@ -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;