You are here

function _filebrowser_load_description_file in Filebrowser 8

Same name and namespace in other branches
  1. 6.2 includes/metadata.inc \_filebrowser_load_description_file()
  2. 7.4 filebrowser.common.inc \_filebrowser_load_description_file()
  3. 7.2 filebrowser.common.inc \_filebrowser_load_description_file()
  4. 7.3 filebrowser.common.inc \_filebrowser_load_description_file()
2 calls to _filebrowser_load_description_file()
filebrowser_filebrowser_metadata_set in ./filebrowser.module
_filebrowser_read_description in ./filebrowser.common.inc

File

./filebrowser.common.inc, line 525
Misc filebrowser common functions.

Code

function _filebrowser_load_description_file($path, $replace = NULL) {
  static $descriptions = array();
  if ($replace) {
    $descriptions[$path] = $replace;
  }

  //echo(print_r($descriptions) . '<br> path '. $path . '<br>');
  if (!isset($descriptions[$path])) {
    $descriptions[$path] = array(
      'data' => array(),
    );
    $description_file = $path . '/descript.ion';
    if (!file_exists($description_file)) {
      $description_file = $path . '/file.bbs';
    }
    if (file_exists($description_file)) {
      $descriptions[$path]['file'] = $description_file;
      foreach (file($description_file) as $line) {
        if (trim($line) == '' || strpos(trim($line), '#') === 0) {
          continue;
        }
        $matches = array();
        preg_match('/"([^"]+)"\\s+(.*)|(\\S+)\\s+(.*)/', $line, $matches);
        $name = !empty($matches[1]) ? $matches[1] : $matches[3];

        // FIXME JSJ Changed to matches[1] because 4 givers error
        $description = !empty($matches[2]) ? $matches[2] : $matches[1];
        $description = str_replace('\\n', "\n", $description);
        if (isset($descriptions[$path][$name])) {
          $descriptions[$path]['data'][$name] .= ' ' . trim($description);
        }
        else {
          $descriptions[$path]['data'][$name] = trim($description);
        }
      }
    }
  }
  return $descriptions[$path];
}