added gallery functions
This commit is contained in:
parent
226482d3b6
commit
1eb93121d5
110
fp-includes/core/core.gallery.php
Normal file
110
fp-includes/core/core.gallery.php
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Functions for handling image galleries.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the captions file
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
const GALLERY_CAPTIONS_FILENAME = 'captions.conf';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the captions file (legacy mode for galleries managed with PhotoSwipe plugin version < 1.1)
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
const GALLERY_CAPTIONS_LEGACYFILENAME = 'texte.conf';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads the images from the gallery directory and returns their names as iterative array
|
||||||
|
*
|
||||||
|
* @param string $galleryDir
|
||||||
|
* the gallery dir, e.g. 'images/NameOfTheGallery'
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function gallery_read_images($galleryDir) {
|
||||||
|
$d = substr_replace($galleryDir, IMAGES_DIR, 0, 7);
|
||||||
|
$fs = new fs_filelister($d);
|
||||||
|
$l = $fs->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 <code>true</code> if captions were written successfully; <code>false</code> 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;
|
||||||
|
}
|
@ -1,48 +1,45 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// includes.php
|
// includes.php
|
||||||
// this is just a list of all the standard includes
|
// this is just a list of all the standard includes
|
||||||
|
require_once INCLUDES_DIR . 'core.utils.php';
|
||||||
|
utils_checksmarty();
|
||||||
|
require (SMARTY_DIR . 'Smarty.class.php');
|
||||||
|
$smarty = new Smarty();
|
||||||
|
$_FP_SMARTY = & $smarty;
|
||||||
|
|
||||||
require_once INCLUDES_DIR.'core.utils.php';
|
// WordPress plugin system
|
||||||
utils_checksmarty();
|
require_once INCLUDES_DIR . 'core.wp-plugin-interface.php';
|
||||||
require(SMARTY_DIR . 'Smarty.class.php');
|
require_once INCLUDES_DIR . 'core.wp-functions.php';
|
||||||
$smarty = new Smarty;
|
// require_once INCLUDES_DIR.'core.wp-options.php';
|
||||||
$_FP_SMARTY =& $smarty;
|
require_once INCLUDES_DIR . 'core.wp-formatting.php';
|
||||||
|
require_once INCLUDES_DIR . 'core.wp-default-filters.php';
|
||||||
|
|
||||||
|
require_once INCLUDES_DIR . 'core.filesystem.php';
|
||||||
|
require_once INCLUDES_DIR . 'core.fileio.php';
|
||||||
|
require_once INCLUDES_DIR . 'core.cache.php';
|
||||||
|
require_once INCLUDES_DIR . 'core.blogdb.php';
|
||||||
|
require_once INCLUDES_DIR . 'core.bplustree.class.php';
|
||||||
|
|
||||||
// WordPress plugin system
|
require_once INCLUDES_DIR . 'core.administration.php';
|
||||||
require_once INCLUDES_DIR.'core.wp-plugin-interface.php';
|
require_once INCLUDES_DIR . 'core.widgets.php';
|
||||||
require_once INCLUDES_DIR.'core.wp-functions.php';
|
require_once INCLUDES_DIR . 'core.comment.php';
|
||||||
//require_once INCLUDES_DIR.'core.wp-options.php';
|
require_once INCLUDES_DIR . 'core.config.php';
|
||||||
require_once INCLUDES_DIR.'core.wp-formatting.php';
|
require_once INCLUDES_DIR . 'core.date.php';
|
||||||
require_once INCLUDES_DIR.'core.wp-default-filters.php';
|
require_once INCLUDES_DIR . 'core.entry.php';
|
||||||
|
require_once INCLUDES_DIR . 'core.static.php';
|
||||||
|
require_once INCLUDES_DIR . 'core.draft.php';
|
||||||
|
|
||||||
|
require_once INCLUDES_DIR . 'core.fpdb.class.php';
|
||||||
|
|
||||||
require_once INCLUDES_DIR.'core.filesystem.php';
|
require_once INCLUDES_DIR . 'core.language.php';
|
||||||
require_once INCLUDES_DIR.'core.fileio.php';
|
require_once INCLUDES_DIR . 'core.plugins.php';
|
||||||
require_once INCLUDES_DIR.'core.cache.php';
|
require_once INCLUDES_DIR . 'core.session.php';
|
||||||
require_once INCLUDES_DIR.'core.blogdb.php';
|
require_once INCLUDES_DIR . 'core.cookie.php';
|
||||||
require_once INCLUDES_DIR.'core.bplustree.class.php';
|
require_once INCLUDES_DIR . 'core.system.php';
|
||||||
|
require_once INCLUDES_DIR . 'core.theme.php';
|
||||||
|
// require_once INCLUDES_DIR.'core.layout.php';
|
||||||
require_once INCLUDES_DIR.'core.administration.php';
|
require_once INCLUDES_DIR . 'core.users.php';
|
||||||
require_once INCLUDES_DIR.'core.widgets.php';
|
require_once INCLUDES_DIR . 'core.gallery.php';
|
||||||
require_once INCLUDES_DIR.'core.comment.php';
|
|
||||||
require_once INCLUDES_DIR.'core.config.php';
|
|
||||||
require_once INCLUDES_DIR.'core.date.php';
|
|
||||||
require_once INCLUDES_DIR.'core.entry.php';
|
|
||||||
require_once INCLUDES_DIR.'core.static.php';
|
|
||||||
require_once INCLUDES_DIR.'core.draft.php';
|
|
||||||
|
|
||||||
require_once INCLUDES_DIR.'core.fpdb.class.php';
|
|
||||||
|
|
||||||
require_once INCLUDES_DIR.'core.language.php';
|
|
||||||
require_once INCLUDES_DIR.'core.plugins.php';
|
|
||||||
require_once INCLUDES_DIR.'core.session.php';
|
|
||||||
require_once INCLUDES_DIR.'core.cookie.php';
|
|
||||||
require_once INCLUDES_DIR.'core.system.php';
|
|
||||||
require_once INCLUDES_DIR.'core.theme.php';
|
|
||||||
// require_once INCLUDES_DIR.'core.layout.php';
|
|
||||||
require_once INCLUDES_DIR.'core.users.php';
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user