getlist();
foreach ($l as $i => $f) {
// remove caption files
if ($f === GALLERY_CAPTIONS_FILENAME || $f === GALLERY_CAPTIONS_LEGACYFILENAME) {
array_splice($l, $i, 1);
}
}
sort($l);
return $l;
}
/**
* Reads the captions from the given gallery directory.
*
* @param string $galleryDir
* the gallery dir, e.g. 'images/NameOfTheGallery'
* @return array the gallery captions as associative array { filename => caption }
*/
function gallery_read_captions($galleryDir) {
$captions = array();
$captionsFileContent = null;
$galleryDirPathAbs = ABS_PATH . FP_CONTENT . $galleryDir . '/';
// read captions.conf from gallery dir
if (file_exists($galleryDirPathAbs . GALLERY_CAPTIONS_FILENAME)) {
$captionsFileContent = file($galleryDirPathAbs . GALLERY_CAPTIONS_FILENAME);
} //
// legacy mode: if captions.conf is not available, check for texte.conf
elseif (file_exists($galleryDirPathAbs . GALLERY_CAPTIONS_LEGACYFILENAME)) {
$captionsFileContent = file($galleryDirPathAbs . GALLERY_CAPTIONS_LEGACYFILENAME);
} //
// no caption file available
else {
return array();
}
// read captions file line by line
foreach ($captionsFileContent as $currentline) {
// image file name is before of the '=' character, ...
$image = trim(substr($currentline, 0, strpos($currentline, '=')));
// ... the caption after.
$caption = trim(substr($currentline, (strpos($currentline, '=') + 1)));
// $captions [$image] = htmlentities($descript);
$captions [$image] = $caption;
}
return $captions;
}
/**
* Stores the given captions for the given gallery
*
* @param string $galleryName
* the gallery dir, e.g. 'NameOfTheGallery'
* @param array $captions
* the gallery captions as associative array { filename => caption }
* @return boolean true
if captions were written successfully; false
otherwise
*/
function gallery_write_captions($galleryName, $captions) {
$gallerydirPath = IMAGES_DIR . $galleryName;
if (!file_exists($gallerydirPath)) {
return false;
}
$captionfilePath = IMAGES_DIR . $galleryName . DIRECTORY_SEPARATOR . GALLERY_CAPTIONS_FILENAME;
$captionfileHandle = fopen($captionfilePath, 'w');
$filecontent = '';
foreach ($captions as $filename => $caption) {
$filecontent .= $filename . ' = ' . $caption . PHP_EOL;
}
fwrite($captionfileHandle, $filecontent);
fclose($captionfileHandle);
// Updating from legacy versions: If legacy captions fill still exists, delete if
$legacyCaptionfilePath = IMAGES_DIR . $galleryName . DIRECTORY_SEPARATOR . GALLERY_CAPTIONS_LEGACYFILENAME;
if (file_exists($legacyCaptionfilePath)) {
unlink($legacyCaptionfilePath);
}
return true;
}