metadata.inc in Filebrowser 6.2
File
includes/metadata.inc
View source
<?php
function _filebrowser_read_description($file_path) {
$base_path = _filebrowser_safe_dirname($file_path);
$data = _filebrowser_load_description_file($base_path);
$name = _filebrowser_safe_basename($file_path);
if (isset($data['data'][$name])) {
return $data['data'][$name];
}
else {
return '';
}
}
function _filebrowser_save_description_file($data) {
$output = array();
foreach ($data['data'] as $key => $value) {
$value = str_replace(array(
"\r\n",
"\n",
), array(
'\\n',
'\\n',
), $value);
$output[] = "\"{$key}\"\t{$value}";
}
file_put_contents($data['file'], implode("\n", $output));
}
function _filebrowser_load_description_file($path, $replace = NULL) {
static $descriptions = array();
if ($replace) {
$descriptions[$path] = $replace;
}
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];
$description = !empty($matches[2]) ? $matches[2] : '';
$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];
}