import theme à l'installation
This commit is contained in:
parent
6266ab4ff7
commit
c3ae90b746
|
@ -932,80 +932,71 @@ class theme extends common {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function import($zipName = '') {
|
public function import($zipName = '') {
|
||||||
// Autorisation
|
// Pas de sécurité car cette fonction est utilisée à l'installation
|
||||||
$group = $this->getUser('group');
|
// Lexique
|
||||||
if ($group === false ) $group = 0;
|
include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php');
|
||||||
if( $group < theme::$actions['import'] ) {
|
|
||||||
// Valeurs en sortie
|
|
||||||
$this->addOutput([
|
|
||||||
'access' => false
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
// Lexique
|
|
||||||
include('./core/module/theme/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_theme.php');
|
|
||||||
|
|
||||||
if ($zipName !== '' &&
|
if ($zipName !== '' &&
|
||||||
file_exists($zipName)) {
|
file_exists($zipName)) {
|
||||||
// Init variables de retour
|
// Init variables de retour
|
||||||
$success = false;
|
$success = false;
|
||||||
$notification = '';
|
$notification = '';
|
||||||
// Dossier temporaire
|
// Dossier temporaire
|
||||||
$tempFolder = uniqid();
|
$tempFolder = uniqid();
|
||||||
// Ouvrir le zip
|
// Ouvrir le zip
|
||||||
$zip = new ZipArchive();
|
$zip = new ZipArchive();
|
||||||
if ($zip->open($zipName) === TRUE) {
|
if ($zip->open($zipName) === TRUE) {
|
||||||
mkdir (self::TEMP_DIR . $tempFolder, 0755);
|
mkdir (self::TEMP_DIR . $tempFolder, 0755);
|
||||||
$zip->extractTo(self::TEMP_DIR . $tempFolder );
|
$zip->extractTo(self::TEMP_DIR . $tempFolder );
|
||||||
$modele = '';
|
$modele = '';
|
||||||
// Archive de thème ?
|
// Archive de thème ?
|
||||||
if (
|
if (
|
||||||
file_exists(self::TEMP_DIR . $tempFolder . '/site/data/custom.css')
|
file_exists(self::TEMP_DIR . $tempFolder . '/site/data/custom.css')
|
||||||
AND file_exists(self::TEMP_DIR . $tempFolder . '/site/data/theme.css')
|
AND file_exists(self::TEMP_DIR . $tempFolder . '/site/data/theme.css')
|
||||||
AND file_exists(self::TEMP_DIR . $tempFolder . '/site/data/theme.json')
|
AND file_exists(self::TEMP_DIR . $tempFolder . '/site/data/theme.json')
|
||||||
) {
|
|
||||||
$modele = 'theme';
|
|
||||||
$this->sauve( $modele );
|
|
||||||
}
|
|
||||||
if(
|
|
||||||
file_exists(self::TEMP_DIR . $tempFolder . '/site/data/admin.json')
|
|
||||||
AND file_exists(self::TEMP_DIR . $tempFolder . '/site/data/admin.css')
|
|
||||||
) {
|
) {
|
||||||
$modele = 'admin';
|
$modele = 'theme';
|
||||||
$this->sauve( $modele );
|
$this->sauve( $modele );
|
||||||
}
|
}
|
||||||
if (!empty($modele)
|
if(
|
||||||
) {
|
file_exists(self::TEMP_DIR . $tempFolder . '/site/data/admin.json')
|
||||||
// traiter l'archive
|
AND file_exists(self::TEMP_DIR . $tempFolder . '/site/data/admin.css')
|
||||||
$importFolder = './site/file/import';
|
) {
|
||||||
mkdir ($importFolder, 0755);
|
$modele = 'admin';
|
||||||
$success = $zip->extractTo($importFolder);
|
$this->sauve( $modele );
|
||||||
// $path = $importFolder.'/site/file/source/';
|
|
||||||
// Modifie le nom de tous les fichiers de $path et leur nom dans theme.json
|
|
||||||
// $this->changeName($path);
|
|
||||||
$this->copyDir( $importFolder, './');
|
|
||||||
$this->removeDir($importFolder);
|
|
||||||
// traitement de l'erreur
|
|
||||||
$notification = $success ? $text['core_theme']['import'][0] : $text['core_theme']['import'][1];
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// pas une archive de thème
|
|
||||||
$success = false;
|
|
||||||
$notification = $text['core_theme']['import'][2];
|
|
||||||
}
|
|
||||||
// Supprimer le dossier temporaire même si le thème est invalide
|
|
||||||
$this->removeDir(self::TEMP_DIR . $tempFolder);
|
|
||||||
$zip->close();
|
|
||||||
} else {
|
|
||||||
// erreur à l'ouverture
|
|
||||||
$success = false;
|
|
||||||
$notification = $text['core_theme']['import'][3];
|
|
||||||
}
|
}
|
||||||
return (['success' => $success, 'notification' => $notification]);
|
if (!empty($modele)
|
||||||
}
|
) {
|
||||||
|
// traiter l'archive
|
||||||
|
$importFolder = './site/file/import';
|
||||||
|
mkdir ($importFolder, 0755);
|
||||||
|
$success = $zip->extractTo($importFolder);
|
||||||
|
// $path = $importFolder.'/site/file/source/';
|
||||||
|
// Modifie le nom de tous les fichiers de $path et leur nom dans theme.json
|
||||||
|
// $this->changeName($path);
|
||||||
|
$this->copyDir( $importFolder, './');
|
||||||
|
$this->removeDir($importFolder);
|
||||||
|
// traitement de l'erreur
|
||||||
|
$notification = $success ? $text['core_theme']['import'][0] : $text['core_theme']['import'][1];
|
||||||
|
|
||||||
return (['success' => false, 'notification' => $text['core_theme']['import'][4]]);
|
|
||||||
|
} else {
|
||||||
|
// pas une archive de thème
|
||||||
|
$success = false;
|
||||||
|
$notification = $text['core_theme']['import'][2];
|
||||||
|
}
|
||||||
|
// Supprimer le dossier temporaire même si le thème est invalide
|
||||||
|
$this->removeDir(self::TEMP_DIR . $tempFolder);
|
||||||
|
$zip->close();
|
||||||
|
} else {
|
||||||
|
// erreur à l'ouverture
|
||||||
|
$success = false;
|
||||||
|
$notification = $text['core_theme']['import'][3];
|
||||||
|
}
|
||||||
|
return (['success' => $success, 'notification' => $notification]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (['success' => false, 'notification' => $text['core_theme']['import'][4]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue