You are here

function _ddblock_dir_scan_directory in Dynamic display block 7

Get the sub directories, starting with the mapping string, of a directory.

Parameters

$dir: directory.

$mapping: the start characters of the directory

Return value

An array of directories.

2 calls to _ddblock_dir_scan_directory()
ddblock_form_alter in ./ddblock.module
Implements hook_form_alter().
_ddblock_get_template_size in ./ddblock.module
Get theme sizes of a theme.

File

./ddblock.module, line 2852
Enables your site to display dynamic content in a block.

Code

function _ddblock_dir_scan_directory($dir, $mapping = '') {
  $dirs = array();
  $mask = '/[^0-9A-Za-z\\-]/';
  if (is_dir($dir) && ($handle = opendir($dir))) {
    while ($file = readdir($handle)) {

      // no current and previous directory
      if ($file[0] != '.') {
        if (is_dir("{$dir}/{$file}")) {

          //only alphanumeric dirs
          if (!preg_match($mask, $file)) {
            if (!empty($mapping)) {
              if (substr($file, 0, 3) == $mapping) {

                // add dir.
                $dirs[] = $file;
              }
            }
            else {

              // add dir.
              $dirs[] = $file;
            }
          }
        }
      }
    }
    closedir($handle);
  }
  return $dirs;
}