public static function get_blocks_from_path($path) {
        global $DB;

        $blocks = array(); // To return results

        static $availableblocks = array(); // Get and cache available blocks
        if (empty($availableblocks)) {
            $availableblocks = array_keys(core_component::get_plugin_list('block'));
        }

        $path = $path . '/blocks'; // Always look under blocks subdir

        if (!is_dir($path)) {
            return array();
        }

        if (!$dir = opendir($path)) {
            return array();
        }
        while (false !== ($file = readdir($dir))) {
            if ($file == '.' || $file == '..') { // Skip dots
                continue;
            }
            if (is_dir($path .'/' . $file)) { // Dir found, check it's a valid block
                if (!file_exists($path .'/' . $file . '/block.xml')) { // Skip if xml file not found
                    continue;
                }
                // Extract block name
                $blockname = preg_replace('/(.*)_\d+/', '\\1', $file);
                // Check block exists and is installed
                if (in_array($blockname, $availableblocks) && $DB->record_exists('block', array('name' => $blockname))) {
                    $blocks[$path .'/' . $file] = $blockname;
                }
            }
        }
        closedir($dir);

        return $blocks;
    }
public static function get_blocks_from_path($path) {
        global $DB;

        $blocks = array(); // To return results

        static $availableblocks = array(); // Get and cache available blocks
        if (empty($availableblocks)) {
            $availableblocks = array_keys(core_component::get_plugin_list('block'));
        }

        $path = $path . '/blocks'; // Always look under blocks subdir

        if (!is_dir($path)) {
            return array();
        }

        if (!$dir = opendir($path)) {
            return array();
        }
        while (false !== ($file = readdir($dir))) {
            if ($file == '.' || $file == '..') { // Skip dots
                continue;
            }
            if (is_dir($path .'/' . $file)) { // Dir found, check it's a valid block
                if (!file_exists($path .'/' . $file . '/block.xml')) { // Skip if xml file not found
                    continue;
                }
                // Extract block name
                $blockname = preg_replace('/(.*)_\d+/', '\\1', $file);
                // Check block exists and is installed
                if (in_array($blockname, $availableblocks) && $DB->record_exists('block', array('name' => $blockname))) {
                    $blocks[$path .'/' . $file] = $blockname;
                }
            }
        }
        closedir($dir);

        return $blocks;
    }
public static function get_blocks_from_path ( $ path ) { global $ DB ; $ blocks = array ( ) ; // To return results static $ availableblocks = array ( ) ; // Get and cache available blocks if ( empty ( $ availableblocks ) ) { $ availableblocks = array_keys ( core_component :: get_plugin_list ( 'block' ) ) ; } $ path = $ path . '/blocks' ; // Always look under blocks subdir if ( ! is_dir ( $ path ) ) { return array ( ) ; } if ( ! $ dir = opendir ( $ path ) ) { return array ( ) ; } while ( false !== ( $ file = readdir ( $ dir ) ) ) { if ( $ file == '.' || $ file == '..' ) { // Skip dots continue ; } if ( is_dir ( $ path . '/' . $ file ) ) { // Dir found, check it's a valid block if ( ! file_exists ( $ path . '/' . $ file . '/block.xml' ) ) { // Skip if xml file not found continue ; } // Extract block name $ blockname = preg_replace ( '/(.*)_\d+/' , '\\1' , $ file ) ; // Check block exists and is installed if ( in_array ( $ blockname , $ availableblocks ) && $ DB -> record_exists ( 'block' , array ( 'name' => $ blockname ) ) ) { $ blocks [ $ path . '/' . $ file ] = $ blockname ; } } } closedir ( $ dir ) ; return $ blocks ; }
Load all the blocks information needed for a given path within moodle2 backup

This function, given one full path (course, activities/xxxx) will look for all the
blocks existing in the backup file, returning one array used to build the
proper restore plan by the @restore_plan_builder
Load all the blocks information needed for a given path within moodle2 backup