ZwiiCMS, le gestionnaire de site Web sans base de données à installer.
Conçu en 2008 par Rémi Jean, le développement a été repris par Frédéric Tempez en 2018.
zwii cms nosql json flat file
https://www.zwiicms.fr
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
461 lines
15 KiB
461 lines
15 KiB
<?php |
|
|
|
/** |
|
* This file is part of Zwii. |
|
* |
|
* For full copyright and license information, please see the LICENSE |
|
* file that was distributed with this source code. |
|
* |
|
* @author Rémi Jean <remi.jean@outlook.com> |
|
* @copyright Copyright (C) 2008-2018, Rémi Jean |
|
* @license GNU General Public License, version 3 |
|
* @link http://zwiicms.com/ |
|
*/ |
|
|
|
class gallery extends common { |
|
|
|
public static $actions = [ |
|
'config' => self::GROUP_MODERATOR, |
|
'delete' => self::GROUP_MODERATOR, |
|
'dirs' => self::GROUP_MODERATOR, |
|
'edit' => self::GROUP_MODERATOR, |
|
'filter' => self::GROUP_MODERATOR, |
|
'index' => self::GROUP_VISITOR |
|
]; |
|
|
|
public static $sort = [ |
|
'SORT_ASC' => 'Alphabétique ', |
|
'SORT_DSC' => 'Alphabétique inversé', |
|
'none' => 'Aucun tri', |
|
]; |
|
|
|
public static $directories = []; |
|
|
|
public static $firstPictures = []; |
|
|
|
public static $galleries = []; |
|
|
|
public static $galleriesId = []; |
|
|
|
public static $pictures = []; |
|
|
|
const GALLERY_VERSION = '2.0'; |
|
|
|
// ************* Mofifié par @bruno ************** |
|
// **************** le 04/02/2020 **************** |
|
private $width_thumb = 300; // Largeur des miniatures crées. hauteur respectant le ratio de image originale |
|
|
|
public function IsDir_or_CreateIt($path) { |
|
if (is_dir($path)) { |
|
return true; |
|
} else { |
|
if (mkdir($path)) { return true; } |
|
else { return false; } |
|
} |
|
} |
|
|
|
public function CopyDir($origine, $destination) { |
|
$test = scandir($origine); |
|
foreach($test as $val) { |
|
if($val!="." && $val!="..") { |
|
if(is_dir($origine."/".$val)) { |
|
CopyDir($origine."/".$val, $destination."/".$val); |
|
IsDir_or_CreateIt($destination."/".$val); |
|
} |
|
} |
|
} |
|
return true; |
|
} |
|
|
|
public function fix_strtolower($str){ |
|
if (function_exists( 'mb_strtoupper' )) { return mb_strtolower($str); } |
|
else { return strtolower($str); } |
|
} |
|
// *********************************************** |
|
|
|
public function filter() { |
|
// Traitement du tri |
|
$data = explode('&',($this->getInput('galleryConfigFilterResponse'))); |
|
$data = str_replace('galleryTable%5B%5D=','',$data); |
|
for($i=0;$i<count($data);$i++) { |
|
$this->setData(['module', $this->getUrl(0), $data[$i], [ |
|
'config' => [ |
|
'name' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','name']), |
|
'directory' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','directory']), |
|
'homePicture' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','homePicture']), |
|
'sort' => $this->getData(['module',$this->getUrl(0),$data[$i],'config','sort']), |
|
'position' => $i + 1 |
|
], |
|
'legend' => $this->getData(['module',$this->getUrl(0),$data[$i],'legend']) |
|
]]); |
|
} |
|
$this->saveData(); |
|
// Valeurs en sortie |
|
// Recharge la page |
|
header('Refresh: 0;url='. helper::baseUrl() . $this->getUrl() ); |
|
} |
|
|
|
/** |
|
* Configuration |
|
*/ |
|
public function config() { |
|
// Tri des galeries |
|
$g = $this->getData(['module', $this->getUrl(0)]); |
|
$p = helper::arrayCollumn(helper::arrayCollumn($g,'config'),'position'); |
|
asort($p,SORT_NUMERIC); |
|
$galleries = []; |
|
foreach ($p as $positionId => $item) { |
|
$galleries [$positionId] = $g[$positionId]; |
|
} |
|
// Traitement de l'affichage |
|
if($galleries) { |
|
foreach($galleries as $galleryId => $gallery) { |
|
// Erreur dossier vide |
|
if(is_dir($gallery['config']['directory'])) { |
|
if(count(scandir($gallery['config']['directory'])) === 2) { |
|
$gallery['config']['directory'] = '<span class="galleryConfigError">' . $gallery['config']['directory'] . ' (dossier vide)</span>'; |
|
} |
|
} |
|
// Erreur dossier supprimé |
|
else { |
|
$gallery['config']['directory'] = '<span class="galleryConfigError">' . $gallery['config']['directory'] . ' (dossier introuvable)</span>'; |
|
} |
|
// Met en forme le tableau |
|
self::$galleries[] = [ |
|
template::ico('sort'), |
|
$gallery['config']['name'], |
|
$gallery['config']['directory'], |
|
template::button('galleryConfigEdit' . $galleryId , [ |
|
'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $galleryId . '/' . $_SESSION['csrf'], |
|
'value' => template::ico('pencil') |
|
]), |
|
template::button('galleryConfigDelete' . $galleryId, [ |
|
'class' => 'galleryConfigDelete buttonRed', |
|
'href' => helper::baseUrl() . $this->getUrl(0) . '/delete/' . $galleryId . '/' . $_SESSION['csrf'], |
|
'value' => template::ico('cancel') |
|
]) |
|
]; |
|
// Tableau des id des galleries pour le drag and drop |
|
self::$galleriesId[] = $galleryId; |
|
} |
|
} |
|
// Soumission du formulaire |
|
|
|
if($this->isPost()) { |
|
if ($this->getInput('galleryConfigFilterResponse')) { |
|
self::filter(); |
|
} else { |
|
$galleryId = helper::increment($this->getInput('galleryConfigName', helper::FILTER_ID, true), (array) $this->getData(['module', $this->getUrl(0)])); |
|
$this->setData(['module', $this->getUrl(0), $galleryId, [ |
|
'config' => [ |
|
'name' => $this->getInput('galleryConfigName'), |
|
'directory' => $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true), |
|
'homePicture' => '', |
|
'sort' => $this->getInput('galleryConfigSort'), |
|
'position' => count($this->getData(['module',$this->getUrl(0)])) + 1 |
|
], |
|
'legend' => [] |
|
]]); |
|
// Valeurs en sortie |
|
$this->addOutput([ |
|
'redirect' => helper::baseUrl() . $this->getUrl(), |
|
'notification' => 'Modifications enregistrées', |
|
'state' => true |
|
]); |
|
} |
|
} |
|
// Valeurs en sortie |
|
$this->addOutput([ |
|
'title' => 'Configuration du module', |
|
'view' => 'config', |
|
'vendor' => [ |
|
'tablednd' |
|
] |
|
]); |
|
} |
|
|
|
/** |
|
* Suppression |
|
*/ |
|
public function delete() { |
|
// $url prend l'adresse sans le token |
|
// La galerie n'existe pas |
|
if($this->getData(['module', $this->getUrl(0), $this->getUrl(2)]) === null) { |
|
// Valeurs en sortie |
|
$this->addOutput([ |
|
'access' => false |
|
]); |
|
} |
|
// Jeton incorrect |
|
if ($this->getUrl(3) !== $_SESSION['csrf']) { |
|
// Valeurs en sortie |
|
$this->addOutput([ |
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', |
|
'notification' => 'Suppression non autorisée' |
|
]); |
|
} |
|
// Suppression |
|
else { |
|
$this->deleteData(['module', $this->getUrl(0), $this->getUrl(2)]); |
|
// Valeurs en sortie |
|
$this->addOutput([ |
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', |
|
'notification' => 'Galerie supprimée', |
|
'state' => true |
|
]); |
|
} |
|
} |
|
|
|
/** |
|
* Liste des dossiers |
|
*/ |
|
public function dirs() { |
|
// Valeurs en sortie |
|
$this->addOutput([ |
|
'display' => self::DISPLAY_JSON, |
|
'content' => galleriesHelper::scanDir(self::FILE_DIR.'source') |
|
]); |
|
} |
|
|
|
/** |
|
* Édition |
|
*/ |
|
public function edit() { |
|
// Jeton incorrect |
|
if ($this->getUrl(3) !== $_SESSION['csrf']) { |
|
// Valeurs en sortie |
|
$this->addOutput([ |
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', |
|
'notification' => 'Action non autorisée' |
|
]); |
|
} |
|
// La galerie n'existe pas |
|
if($this->getData(['module', $this->getUrl(0), $this->getUrl(2)]) === null) { |
|
// Valeurs en sortie |
|
$this->addOutput([ |
|
'access' => false |
|
]); |
|
} |
|
// La galerie existe |
|
else { |
|
// Soumission du formulaire |
|
if($this->isPost()) { |
|
// Si l'id a changée |
|
$galleryId = $this->getInput('galleryEditName', helper::FILTER_ID, true); |
|
if($galleryId !== $this->getUrl(2)) { |
|
// Incrémente le nouvel id de la galerie |
|
$galleryId = helper::increment($galleryId, $this->getData(['module', $this->getUrl(0)])); |
|
// Supprime l'ancienne galerie |
|
$this->deleteData(['module', $this->getUrl(0), $this->getUrl(2)]); |
|
} |
|
// légendes |
|
$legends = []; |
|
foreach((array) $this->getInput('legend', null) as $file => $legend) { |
|
$file = str_replace('.','',$file); |
|
$legends[$file] = helper::filter($legend, helper::FILTER_STRING_SHORT); |
|
} |
|
// Photo de la page de garde de l'album |
|
$homePictures = []; |
|
foreach((array) $this->getInput('homePicture', null) as $file => $homePicture) { |
|
// null : pas de variable définie (compatibilité) ou choix non effectif |
|
$homePictures[$file] = $file === 0 ? null : helper::filter($file, helper::FILTER_STRING_SHORT) ; |
|
} |
|
$this->setData(['module', $this->getUrl(0), $galleryId, [ |
|
'config' => [ |
|
'name' => $this->getInput('galleryEditName', helper::FILTER_STRING_SHORT, true), |
|
'directory' => $this->getInput('galleryEditDirectory', helper::FILTER_STRING_SHORT, true), |
|
'homePicture' => $homePictures[$file], |
|
'sort' => $this->getInput('galleryEditSort'), |
|
'position' => count($this->getData(['module',$this->getUrl(0)])) + 1 |
|
], |
|
'legend' => $legends |
|
]]); |
|
// Valeurs en sortie |
|
$this->addOutput([ |
|
'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', |
|
'notification' => 'Modifications enregistrées', |
|
'state' => true |
|
]); |
|
} |
|
// Met en forme le tableau |
|
$directory = $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'directory']); |
|
if(is_dir($directory)) { |
|
$iterator = new DirectoryIterator($directory); |
|
foreach($iterator as $fileInfos) { |
|
if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) { |
|
self::$pictures[$fileInfos->getFilename()] = [ |
|
$fileInfos->getFilename(), |
|
template::checkbox( 'homePicture[' . $fileInfos->getFilename() . ']', true, '', [ |
|
'checked' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2),'config', 'homePicture']) === $fileInfos->getFilename() ? true : false, |
|
'class' => 'homePicture' |
|
|
|
]), |
|
template::text('legend[' . $fileInfos->getFilename() . ']', [ |
|
'value' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'legend', str_replace('.','',$fileInfos->getFilename())]) |
|
]) |
|
]; |
|
} |
|
} |
|
// Tri des images par ordre alphabétique |
|
switch ($this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'sort'])) { |
|
case 'none': |
|
break; |
|
case 'SORT_DSC': |
|
krsort(self::$pictures,SORT_NATURAL); |
|
break; |
|
case 'SORT_ASC': |
|
default: |
|
ksort(self::$pictures,SORT_NATURAL); |
|
break; |
|
} |
|
} |
|
// Valeurs en sortie |
|
$this->addOutput([ |
|
'title' => $this->getData(['module', $this->getUrl(0), $this->getUrl(2), 'config', 'name']), |
|
'view' => 'edit' |
|
]); |
|
} |
|
} |
|
|
|
/** |
|
* Accueil (deux affichages en un pour éviter une url à rallonge) |
|
*/ |
|
public function index() { |
|
// Images d'une galerie |
|
if($this->getUrl(1)) { |
|
// La galerie n'existe pas |
|
if($this->getData(['module', $this->getUrl(0), $this->getUrl(1)]) === null) { |
|
// Valeurs en sortie |
|
$this->addOutput([ |
|
'access' => false |
|
]); |
|
} |
|
// La galerie existe |
|
else { |
|
// Images de la galerie |
|
$need_dir = true; // Si besion de créer des miniatures, recrée si besion l'arborescence du/des répertoires. |
|
$directory = $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'config', 'directory']); |
|
if(is_dir($directory)) { |
|
$iterator = new DirectoryIterator($directory); |
|
foreach($iterator as $fileInfos) { |
|
if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) { |
|
$rp = realpath($fileInfos->getPathname()); |
|
$tp = str_replace("source", "thumb", $rp); |
|
if (is_readable($tp)) { |
|
$info = pathinfo($tp); |
|
if (in_array(strtolower($info['extension']), array( 'jpg', 'jpeg', 'png' ))) { |
|
$gis = getimagesize("$tp"); |
|
if ($gis[0]<$this->width_thumb) { $need_resize = true; } |
|
else { $need_resize = false; } |
|
} |
|
} |
|
else { $need_resize = true; } |
|
if ($need_resize) { |
|
if ($need_dir) { |
|
$dir = dirname($tp); |
|
$p = explode ( "thumb" , $dir); |
|
if (!is_dir($dir)) { // Création de TOUT les dossiers et sous dossiers |
|
$p = explode ( "thumb" , $dir); |
|
CopyDir("$p[0]source", "$p[0]thumb"); |
|
$need_dir = false; |
|
} |
|
} |
|
$_SESSION['RF']["verify"] = "RESPONSIVEfilemanager"; // Pour éviter un forbiden dans la face |
|
@require_once("core/vendor/filemanager/include/utils.php"); // Désolé pour @, pour éviter les erreurs |
|
require_once("core/vendor/filemanager/include/php_image_magician.php"); |
|
|
|
$magicianObj = new imageLib($rp); |
|
$magicianObj -> resizeImage($this->width_thumb, 300, 2); |
|
$magicianObj -> saveImage($tp); |
|
} |
|
self::$pictures[$directory . '/' . $fileInfos->getFilename()] = $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'legend', str_replace('.','',$fileInfos->getFilename())]); |
|
} |
|
} |
|
// Tri des images par ordre alphabétique |
|
switch ($this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'config', 'sort'])) { |
|
case 'none': |
|
break; |
|
case 'SORT_DSC': |
|
krsort(self::$pictures,SORT_NATURAL); |
|
break; |
|
case 'SORT_ASC': |
|
default: |
|
ksort(self::$pictures,SORT_NATURAL); |
|
break; |
|
} |
|
} |
|
// Affichage du template |
|
if(self::$pictures) { |
|
// Valeurs en sortie |
|
$this->addOutput([ |
|
'showBarEditButton' => true, |
|
'title' => $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'config', 'name']), |
|
/* Désactivé car SLB est actif pour tout le site |
|
'vendor' => [ |
|
'simplelightbox' |
|
],*/ |
|
'view' => 'gallery' |
|
]); |
|
} |
|
// Pas d'image dans la galerie |
|
else { |
|
// Valeurs en sortie |
|
$this->addOutput([ |
|
'access' => false |
|
]); |
|
} |
|
} |
|
|
|
} |
|
// Liste des galeries |
|
else { |
|
// Tri des galeries |
|
$g = $this->getData(['module', $this->getUrl(0)]); |
|
$p = helper::arrayCollumn(helper::arrayCollumn($g,'config'),'position'); |
|
asort($p,SORT_NUMERIC); |
|
$galleries = []; |
|
foreach ($p as $positionId => $item) { |
|
$galleries [$positionId] = $g[$positionId]; |
|
} |
|
foreach((array) $galleries as $galleryId => $gallery) { |
|
if(is_dir($gallery['config']['directory'])) { |
|
$iterator = new DirectoryIterator($gallery['config']['directory']); |
|
foreach($iterator as $fileInfos) { |
|
if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) { |
|
self::$galleries[$galleryId] = $gallery; |
|
self::$firstPictures[$galleryId] = $gallery['config']['directory'] . '/' . $fileInfos->getFilename(); |
|
continue(2); |
|
} |
|
} |
|
} |
|
} |
|
// Valeurs en sortie |
|
$this->addOutput([ |
|
'showBarEditButton' => true, |
|
'showPageContent' => true, |
|
'view' => 'index' |
|
]); |
|
} |
|
} |
|
|
|
} |
|
|
|
class galleriesHelper extends helper { |
|
|
|
/** |
|
* Scan le contenu d'un dossier et de ses sous-dossiers |
|
* @param string $dir Dossier à scanner |
|
* @return array |
|
*/ |
|
public static function scanDir($dir) { |
|
$dirContent = []; |
|
$iterator = new DirectoryIterator($dir); |
|
foreach($iterator as $fileInfos) { |
|
if($fileInfos->isDot() === false AND $fileInfos->isDir()) { |
|
$dirContent[] = $dir . '/' . $fileInfos->getBasename(); |
|
$dirContent = array_merge($dirContent, self::scanDir($dir . '/' . $fileInfos->getBasename())); |
|
} |
|
} |
|
return $dirContent; |
|
} |
|
}
|
|
|