You are here

function filebrowser_get_fileinfo in Filebrowser 5

Loads file metainformation from the specified file. Also allows the file to specify a *callback* with which the descriptions are parsed, so more metainformation can be presented on the output.

2 calls to filebrowser_get_fileinfo()
filebrowser_get_list in ./filebrowser.module
Returns a list of files in a subfolder under the admin specified filebrowser root. File system details (size, last modification) is added, plus a metafile is parsed to gather more information, if available.
filebrowser_page in ./filebrowser.module
Prints a folder layout

File

./filebrowser.module, line 277

Code

function filebrowser_get_fileinfo($fullpath = NULL, $subfolder = '') {
  static $metacols = array();

  // Return (previously generated) meta column list
  if (!isset($fullpath)) {
    return $metacols;
  }

  // Build meta information list
  $metainfo = array();
  if (is_readable($fullpath) && ($file = file($fullpath))) {
    foreach ($file as $line) {

      // Skip empty and commented lines
      if (trim($line) == '' || strpos(trim($line), '#') === 0) {
        continue;
      }
      list($name, $description) = explode(" ", $line, 2);
      if (isset($metainfo[$name])) {
        $metainfo[$name] .= trim($description) . " ";
      }
      else {
        $metainfo[$name] = trim($description) . " ";
      }
    }
    $callback = FALSE;
    if (isset($metainfo['*callback*']) && function_exists(trim($metainfo['*callback*']))) {
      $callback = trim($metainfo['*callback*']);
      unset($metainfo['*callback*']);
    }
    if (isset($metainfo['.'])) {
      filebrowser_help(NULL, $metainfo['.']);
      unset($metainfo['.']);
    }
    foreach ($metainfo as $name => $description) {
      $metainfo[$name] = $callback ? $callback(trim($description), $subfolder, $name) : array(
        trim($description),
      );
    }
    $metacols = $callback ? $callback() : array(
      t('Description'),
    );
  }
  return $metainfo;
}