2018-04-02 08:29:19 +02:00
|
|
|
<?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 config extends common {
|
|
|
|
|
|
|
|
public static $actions = [
|
|
|
|
'backup' => self::GROUP_ADMIN,
|
2020-03-02 11:52:52 +01:00
|
|
|
'restore' => self::GROUP_ADMIN,
|
2018-12-25 18:17:11 +01:00
|
|
|
'configMetaImage' => self::GROUP_ADMIN,
|
2019-05-02 13:21:48 +02:00
|
|
|
'generateFiles' => self::GROUP_ADMIN,
|
|
|
|
'updateRobots' => self::GROUP_ADMIN,
|
2019-12-10 10:53:31 +01:00
|
|
|
'index' => self::GROUP_ADMIN,
|
2020-02-27 15:49:32 +01:00
|
|
|
'updateOnline' => self::GROUP_ADMIN
|
2018-04-02 08:29:19 +02:00
|
|
|
];
|
2020-02-27 15:49:32 +01:00
|
|
|
|
|
|
|
public static $newVersion;
|
2018-04-02 08:29:19 +02:00
|
|
|
|
|
|
|
public static $timezones = [
|
|
|
|
'Pacific/Midway' => '(GMT-11:00) Midway Island',
|
|
|
|
'US/Samoa' => '(GMT-11:00) Samoa',
|
|
|
|
'US/Hawaii' => '(GMT-10:00) Hawaii',
|
|
|
|
'US/Alaska' => '(GMT-09:00) Alaska',
|
|
|
|
'US/Pacific' => '(GMT-08:00) Pacific Time (US & Canada)',
|
|
|
|
'America/Tijuana' => '(GMT-08:00) Tijuana',
|
|
|
|
'US/Arizona' => '(GMT-07:00) Arizona',
|
|
|
|
'US/Mountain' => '(GMT-07:00) Mountain Time (US & Canada)',
|
|
|
|
'America/Chihuahua' => '(GMT-07:00) Chihuahua',
|
|
|
|
'America/Mazatlan' => '(GMT-07:00) Mazatlan',
|
|
|
|
'America/Mexico_City' => '(GMT-06:00) Mexico City',
|
|
|
|
'America/Monterrey' => '(GMT-06:00) Monterrey',
|
|
|
|
'Canada/Saskatchewan' => '(GMT-06:00) Saskatchewan',
|
|
|
|
'US/Central' => '(GMT-06:00) Central Time (US & Canada)',
|
|
|
|
'US/Eastern' => '(GMT-05:00) Eastern Time (US & Canada)',
|
|
|
|
'US/East-Indiana' => '(GMT-05:00) Indiana (East)',
|
|
|
|
'America/Bogota' => '(GMT-05:00) Bogota',
|
|
|
|
'America/Lima' => '(GMT-05:00) Lima',
|
|
|
|
'America/Caracas' => '(GMT-04:30) Caracas',
|
|
|
|
'Canada/Atlantic' => '(GMT-04:00) Atlantic Time (Canada)',
|
|
|
|
'America/La_Paz' => '(GMT-04:00) La Paz',
|
|
|
|
'America/Santiago' => '(GMT-04:00) Santiago',
|
|
|
|
'Canada/Newfoundland' => '(GMT-03:30) Newfoundland',
|
|
|
|
'America/Buenos_Aires' => '(GMT-03:00) Buenos Aires',
|
|
|
|
'Greenland' => '(GMT-03:00) Greenland',
|
|
|
|
'Atlantic/Stanley' => '(GMT-02:00) Stanley',
|
|
|
|
'Atlantic/Azores' => '(GMT-01:00) Azores',
|
|
|
|
'Atlantic/Cape_Verde' => '(GMT-01:00) Cape Verde Is.',
|
|
|
|
'Africa/Casablanca' => '(GMT) Casablanca',
|
|
|
|
'Europe/Dublin' => '(GMT) Dublin',
|
|
|
|
'Europe/Lisbon' => '(GMT) Lisbon',
|
|
|
|
'Europe/London' => '(GMT) London',
|
|
|
|
'Africa/Monrovia' => '(GMT) Monrovia',
|
|
|
|
'Europe/Amsterdam' => '(GMT+01:00) Amsterdam',
|
|
|
|
'Europe/Belgrade' => '(GMT+01:00) Belgrade',
|
|
|
|
'Europe/Berlin' => '(GMT+01:00) Berlin',
|
|
|
|
'Europe/Bratislava' => '(GMT+01:00) Bratislava',
|
|
|
|
'Europe/Brussels' => '(GMT+01:00) Brussels',
|
|
|
|
'Europe/Budapest' => '(GMT+01:00) Budapest',
|
|
|
|
'Europe/Copenhagen' => '(GMT+01:00) Copenhagen',
|
|
|
|
'Europe/Ljubljana' => '(GMT+01:00) Ljubljana',
|
|
|
|
'Europe/Madrid' => '(GMT+01:00) Madrid',
|
|
|
|
'Europe/Paris' => '(GMT+01:00) Paris',
|
|
|
|
'Europe/Prague' => '(GMT+01:00) Prague',
|
|
|
|
'Europe/Rome' => '(GMT+01:00) Rome',
|
|
|
|
'Europe/Sarajevo' => '(GMT+01:00) Sarajevo',
|
|
|
|
'Europe/Skopje' => '(GMT+01:00) Skopje',
|
|
|
|
'Europe/Stockholm' => '(GMT+01:00) Stockholm',
|
|
|
|
'Europe/Vienna' => '(GMT+01:00) Vienna',
|
|
|
|
'Europe/Warsaw' => '(GMT+01:00) Warsaw',
|
|
|
|
'Europe/Zagreb' => '(GMT+01:00) Zagreb',
|
|
|
|
'Europe/Athens' => '(GMT+02:00) Athens',
|
|
|
|
'Europe/Bucharest' => '(GMT+02:00) Bucharest',
|
|
|
|
'Africa/Cairo' => '(GMT+02:00) Cairo',
|
|
|
|
'Africa/Harare' => '(GMT+02:00) Harare',
|
|
|
|
'Europe/Helsinki' => '(GMT+02:00) Helsinki',
|
|
|
|
'Europe/Istanbul' => '(GMT+02:00) Istanbul',
|
|
|
|
'Asia/Jerusalem' => '(GMT+02:00) Jerusalem',
|
|
|
|
'Europe/Kiev' => '(GMT+02:00) Kyiv',
|
|
|
|
'Europe/Minsk' => '(GMT+02:00) Minsk',
|
|
|
|
'Europe/Riga' => '(GMT+02:00) Riga',
|
|
|
|
'Europe/Sofia' => '(GMT+02:00) Sofia',
|
|
|
|
'Europe/Tallinn' => '(GMT+02:00) Tallinn',
|
|
|
|
'Europe/Vilnius' => '(GMT+02:00) Vilnius',
|
|
|
|
'Asia/Baghdad' => '(GMT+03:00) Baghdad',
|
|
|
|
'Asia/Kuwait' => '(GMT+03:00) Kuwait',
|
|
|
|
'Europe/Moscow' => '(GMT+03:00) Moscow',
|
|
|
|
'Africa/Nairobi' => '(GMT+03:00) Nairobi',
|
|
|
|
'Asia/Riyadh' => '(GMT+03:00) Riyadh',
|
|
|
|
'Europe/Volgograd' => '(GMT+03:00) Volgograd',
|
|
|
|
'Asia/Tehran' => '(GMT+03:30) Tehran',
|
|
|
|
'Asia/Baku' => '(GMT+04:00) Baku',
|
|
|
|
'Asia/Muscat' => '(GMT+04:00) Muscat',
|
|
|
|
'Asia/Tbilisi' => '(GMT+04:00) Tbilisi',
|
|
|
|
'Asia/Yerevan' => '(GMT+04:00) Yerevan',
|
|
|
|
'Asia/Kabul' => '(GMT+04:30) Kabul',
|
|
|
|
'Asia/Yekaterinburg' => '(GMT+05:00) Ekaterinburg',
|
|
|
|
'Asia/Karachi' => '(GMT+05:00) Karachi',
|
|
|
|
'Asia/Tashkent' => '(GMT+05:00) Tashkent',
|
|
|
|
'Asia/Kolkata' => '(GMT+05:30) Kolkata',
|
|
|
|
'Asia/Kathmandu' => '(GMT+05:45) Kathmandu',
|
|
|
|
'Asia/Almaty' => '(GMT+06:00) Almaty',
|
|
|
|
'Asia/Dhaka' => '(GMT+06:00) Dhaka',
|
|
|
|
'Asia/Novosibirsk' => '(GMT+06:00) Novosibirsk',
|
|
|
|
'Asia/Bangkok' => '(GMT+07:00) Bangkok',
|
|
|
|
'Asia/Jakarta' => '(GMT+07:00) Jakarta',
|
|
|
|
'Asia/Krasnoyarsk' => '(GMT+07:00) Krasnoyarsk',
|
|
|
|
'Asia/Chongqing' => '(GMT+08:00) Chongqing',
|
|
|
|
'Asia/Hong_Kong' => '(GMT+08:00) Hong Kong',
|
|
|
|
'Asia/Irkutsk' => '(GMT+08:00) Irkutsk',
|
|
|
|
'Asia/Kuala_Lumpur' => '(GMT+08:00) Kuala Lumpur',
|
|
|
|
'Australia/Perth' => '(GMT+08:00) Perth',
|
|
|
|
'Asia/Singapore' => '(GMT+08:00) Singapore',
|
|
|
|
'Asia/Taipei' => '(GMT+08:00) Taipei',
|
|
|
|
'Asia/Ulaanbaatar' => '(GMT+08:00) Ulaan Bataar',
|
|
|
|
'Asia/Urumqi' => '(GMT+08:00) Urumqi',
|
|
|
|
'Asia/Seoul' => '(GMT+09:00) Seoul',
|
|
|
|
'Asia/Tokyo' => '(GMT+09:00) Tokyo',
|
|
|
|
'Asia/Yakutsk' => '(GMT+09:00) Yakutsk',
|
|
|
|
'Australia/Adelaide' => '(GMT+09:30) Adelaide',
|
|
|
|
'Australia/Darwin' => '(GMT+09:30) Darwin',
|
|
|
|
'Australia/Brisbane' => '(GMT+10:00) Brisbane',
|
|
|
|
'Australia/Canberra' => '(GMT+10:00) Canberra',
|
|
|
|
'Pacific/Guam' => '(GMT+10:00) Guam',
|
|
|
|
'Australia/Hobart' => '(GMT+10:00) Hobart',
|
|
|
|
'Australia/Melbourne' => '(GMT+10:00) Melbourne',
|
|
|
|
'Pacific/Port_Moresby' => '(GMT+10:00) Port Moresby',
|
|
|
|
'Australia/Sydney' => '(GMT+10:00) Sydney',
|
|
|
|
'Asia/Vladivostok' => '(GMT+10:00) Vladivostok',
|
|
|
|
'Asia/Magadan' => '(GMT+11:00) Magadan',
|
|
|
|
'Pacific/Auckland' => '(GMT+12:00) Auckland',
|
|
|
|
'Pacific/Fiji' => '(GMT+12:00) Fiji',
|
|
|
|
'Asia/Kamchatka' => '(GMT+12:00) Kamchatka'
|
|
|
|
];
|
2018-10-06 05:46:07 +02:00
|
|
|
// Nombre d'objets par page
|
|
|
|
public static $ItemsList = [
|
2018-10-06 06:19:54 +02:00
|
|
|
5 => '5 articles',
|
|
|
|
10 => '10 articles',
|
|
|
|
15 => '15 articles',
|
|
|
|
20 => '20 articles'
|
2018-10-06 05:46:07 +02:00
|
|
|
];
|
2020-03-02 13:08:03 +01:00
|
|
|
// Type de proxy
|
|
|
|
public static $proxyType = [
|
|
|
|
'tcp://' => 'TCP',
|
|
|
|
'http://' => 'HTTP'
|
|
|
|
];
|
2018-04-02 08:29:19 +02:00
|
|
|
|
2018-10-24 22:48:10 +02:00
|
|
|
|
2019-05-02 13:21:48 +02:00
|
|
|
public function generateFiles() {
|
|
|
|
// Mettre à jour le site map
|
2019-12-10 10:53:31 +01:00
|
|
|
$successSitemap=$this->createSitemap();
|
2019-05-02 13:21:48 +02:00
|
|
|
|
|
|
|
// Creer un fichier robots.txt
|
|
|
|
$successRobots=$this->updateRobots();
|
|
|
|
if ( $successSitemap === true &&
|
|
|
|
$successRobots >= 100) {
|
|
|
|
$success = true;
|
|
|
|
} else {
|
|
|
|
$success = false;
|
|
|
|
}
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'notification' => ($successSitemap === true && $successRobots >= 100) ? 'Création réussie' : 'Echec d\'écriture',
|
|
|
|
'redirect' => helper::baseUrl() . 'config',
|
|
|
|
'state' => ($successSitemap === true && $successRobots >=100) ? true : false
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Met à jour un fichier robots.txt lors du changement de réécriture
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function updateRobots() {
|
|
|
|
// Créer le fichier robot si absent
|
|
|
|
if (!file_exists('robots.txt')) {
|
|
|
|
$this->createRobots();
|
|
|
|
}
|
|
|
|
// backup
|
|
|
|
rename ('robots.txt','robots.bak');
|
|
|
|
$fileold = fopen('robots.bak','r');
|
|
|
|
$filenew = fopen('robots.txt','w');
|
|
|
|
while(!feof($fileold)) {
|
|
|
|
$data = fgets($fileold);
|
|
|
|
if (strpos($data,'sitemap.xml') == 0) {
|
|
|
|
fwrite($filenew, $data);
|
|
|
|
} else {
|
2019-06-15 18:27:00 +02:00
|
|
|
fwrite($filenew, 'Sitemap: ' . helper::baseUrl(false) . 'sitemap.xml' . PHP_EOL);
|
|
|
|
fwrite($filenew, 'Sitemap: ' . helper::baseUrl(false) . 'sitemap.xml.gz' . PHP_EOL);
|
2019-05-02 13:21:48 +02:00
|
|
|
fwrite($filenew, '# ZWII CONFIG ---------' . PHP_EOL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose($fileold);
|
|
|
|
unlink('robots.bak');
|
|
|
|
return(fclose($filenew));
|
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
/**
|
|
|
|
* Sauvegarde des données
|
|
|
|
*/
|
|
|
|
public function backup() {
|
2020-02-10 16:36:57 +01:00
|
|
|
// Soumission du formulaire
|
|
|
|
if($this->isPost()) {
|
|
|
|
// Creation du ZIP
|
|
|
|
$filter = $this->getInput('configBackupOption',helper::FILTER_BOOLEAN) === true ? ['backup','tmp'] : ['backup','tmp','file'];
|
|
|
|
$fileName = helper::autoBackup(self::TEMP_DIR,$filter);
|
2020-02-06 21:04:56 +01:00
|
|
|
|
2020-02-10 16:36:57 +01:00
|
|
|
// Téléchargement du ZIP
|
|
|
|
header('Content-Type: application/zip');
|
|
|
|
header('Content-Disposition: attachment; filename="' . $fileName . '"');
|
|
|
|
header('Content-Length: ' . filesize(self::TEMP_DIR . $fileName));
|
|
|
|
readfile(self::TEMP_DIR . $fileName);
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'display' => self::DISPLAY_RAW
|
|
|
|
]);
|
|
|
|
unlink(self::TEMP_DIR . $fileName);
|
|
|
|
} else {
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2020-02-10 17:04:25 +01:00
|
|
|
'title' => 'Télécharger une archive du site',
|
2020-02-10 16:36:57 +01:00
|
|
|
'view' => 'backup'
|
|
|
|
]);
|
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
|
|
|
|
2018-10-24 15:50:07 +02:00
|
|
|
/**
|
2018-12-25 18:17:11 +01:00
|
|
|
* Réalise une copie d'écran du site
|
2018-10-24 15:50:07 +02:00
|
|
|
* https://www.codexworld.com/capture-screenshot-website-url-php-google-api/
|
|
|
|
*/
|
2018-12-25 18:17:11 +01:00
|
|
|
public function configMetaImage() {
|
2018-10-24 22:48:10 +02:00
|
|
|
// fonction désactivée pour un site local
|
|
|
|
if ( strpos(helper::baseUrl(false),'localhost') > 0 OR strpos(helper::baseUrl(false),'127.0.0.1') > 0) {
|
2018-12-25 18:17:11 +01:00
|
|
|
$site = 'https://zwiicms.com/'; } else {
|
2018-10-24 22:48:10 +02:00
|
|
|
$site = helper::baseUrl(false); }
|
2019-06-18 10:13:09 +02:00
|
|
|
|
|
|
|
$success= false;
|
|
|
|
$googlePagespeedData = @file_get_contents('https://www.googleapis.com/pagespeedonline/v2/runPagespeed?url='. $site .'&screenshot=true');
|
|
|
|
if ($googlePagespeedData !== false) {
|
|
|
|
$googlePagespeedData = json_decode($googlePagespeedData, true);
|
|
|
|
$screenshot = $googlePagespeedData['screenshot']['data'];
|
|
|
|
$screenshot = str_replace(array('_','-'),array('/','+'),$screenshot);
|
|
|
|
$data = 'data:image/jpeg;base64,'.$screenshot;
|
|
|
|
$data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data));
|
|
|
|
// Effacer la miniature
|
2019-06-20 18:58:49 +02:00
|
|
|
if (file_exists(self::FILE_DIR.'thumb/screenshot.png')) {
|
|
|
|
unlink (self::FILE_DIR.'thumb/screenshot.png');
|
|
|
|
}
|
2019-06-18 10:13:09 +02:00
|
|
|
file_put_contents( self::FILE_DIR.'source/screenshot.png',$data);
|
|
|
|
$success =true;
|
|
|
|
}
|
2018-10-24 22:48:10 +02:00
|
|
|
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2019-12-23 20:58:30 +01:00
|
|
|
'notification' => $success === true ? 'Image tag réinitialisée' : 'Erreur : image tag non créée',
|
2018-10-24 22:48:10 +02:00
|
|
|
'redirect' => helper::baseUrl() . 'config',
|
2019-06-18 10:13:09 +02:00
|
|
|
'state' => $success
|
2018-10-24 22:48:10 +02:00
|
|
|
]);
|
2018-10-24 15:50:07 +02:00
|
|
|
}
|
|
|
|
|
2019-12-10 10:53:31 +01:00
|
|
|
/**
|
|
|
|
* Procédure d'importation
|
|
|
|
*/
|
2020-02-10 16:36:57 +01:00
|
|
|
public function restore() {
|
2019-12-10 10:53:31 +01:00
|
|
|
// Soumission du formulaire
|
|
|
|
if($this->isPost()) {
|
2020-02-10 16:36:57 +01:00
|
|
|
//if ($this->getInput('configrestoreImportFile'))
|
|
|
|
$fileZip = $this->getInput('configRestoreImportFile');
|
2019-12-10 10:53:31 +01:00
|
|
|
$file_parts = pathinfo($fileZip);
|
|
|
|
$folder = date('Y-m-d-h-i-s', time());
|
|
|
|
$zip = new ZipArchive();
|
|
|
|
if ($file_parts['extension'] !== 'zip') {
|
|
|
|
// Valeurs en sortie erreur
|
|
|
|
$this->addOutput([
|
|
|
|
'notification' => 'Le fichier n\'est pas une archive valide',
|
2020-02-10 16:36:57 +01:00
|
|
|
'redirect' => helper::baseUrl() . 'config/restore',
|
2019-12-10 10:53:31 +01:00
|
|
|
'state' => false
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
$successOpen = $zip->open(self::FILE_DIR . 'source/' . $fileZip);
|
|
|
|
if ($successOpen === FALSE) {
|
|
|
|
// Valeurs en sortie erreur
|
|
|
|
$this->addOutput([
|
|
|
|
'notification' => 'Impossible de lire l\'archive',
|
2020-02-10 16:36:57 +01:00
|
|
|
'redirect' => helper::baseUrl() . 'config/restore',
|
2019-12-10 10:53:31 +01:00
|
|
|
'state' => false
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
// Lire le contenu de l'archive dans le tableau files
|
|
|
|
for( $i = 0; $i < $zip->numFiles; $i++ ){
|
|
|
|
$stat = $zip->statIndex( $i );
|
|
|
|
$files [] = ( basename( $stat['name'] ));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Détermination de la version à installer
|
|
|
|
if (in_array('theme.json',$files) === true &&
|
|
|
|
in_array('core.json',$files) === true &&
|
|
|
|
in_array ('user.json', $files) === false ) {
|
|
|
|
// V9 pas de fichier user dans l'archive
|
|
|
|
// Stocker le choix de conserver les users installées
|
|
|
|
$version = '9';
|
|
|
|
|
|
|
|
} elseif (in_array('theme.json',$files) === true &&
|
|
|
|
in_array('core.json',$files) === true &&
|
|
|
|
in_array ('user.json', $files) === true &&
|
|
|
|
in_array ('config.json', $files) === true ) {
|
2019-12-17 10:34:34 +01:00
|
|
|
// V10 valide user et config
|
2019-12-10 10:53:31 +01:00
|
|
|
$version = '10';
|
|
|
|
// Option active, les users sont stockées
|
2020-02-10 16:36:57 +01:00
|
|
|
if ($this->getInput('configRestoreImportUser', helper::FILTER_BOOLEAN) === true ) {
|
2019-12-10 10:53:31 +01:00
|
|
|
$users = $this->getData(['user']);
|
2019-12-17 10:34:34 +01:00
|
|
|
}
|
2019-12-10 10:53:31 +01:00
|
|
|
} else { // Version invalide
|
|
|
|
// Valeurs en sortie erreur
|
|
|
|
$this->addOutput([
|
|
|
|
'notification' => 'Cette archive n\'est pas une sauvegarde valide',
|
2020-02-10 16:36:57 +01:00
|
|
|
'redirect' => helper::baseUrl() . 'config/restore',
|
2019-12-10 10:53:31 +01:00
|
|
|
'state' => false
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-12-17 10:34:34 +01:00
|
|
|
// Préserver les comptes des utilisateurs d'une version 9 si option cochée
|
|
|
|
// Positionnement d'une variable de session lue au constructeur
|
2019-12-17 16:04:40 +01:00
|
|
|
if ($version === '9') {
|
2020-02-10 16:36:57 +01:00
|
|
|
$_SESSION['KEEP_USERS'] = $this->getInput('configRestoreImportUser', helper::FILTER_BOOLEAN);
|
2019-12-17 10:34:34 +01:00
|
|
|
}
|
|
|
|
|
2019-12-10 10:53:31 +01:00
|
|
|
// Extraire le zip
|
2019-12-17 10:34:34 +01:00
|
|
|
$success = $zip->extractTo( 'site/' );
|
2019-12-10 10:53:31 +01:00
|
|
|
// Fermer l'archive
|
|
|
|
$zip->close();
|
2019-12-17 10:34:34 +01:00
|
|
|
|
2019-12-10 10:53:31 +01:00
|
|
|
// Restaurer les users originaux d'une v10 si option cochée
|
|
|
|
if (!empty($users) &&
|
|
|
|
$version === '10' &&
|
2020-02-10 16:36:57 +01:00
|
|
|
$this->getInput('configRestoreImportUser', helper::FILTER_BOOLEAN) === true) {
|
2019-12-17 16:04:40 +01:00
|
|
|
$this->setData(['user',$users]);
|
2019-12-17 10:34:34 +01:00
|
|
|
}
|
|
|
|
|
2019-12-10 10:53:31 +01:00
|
|
|
// Message de notification
|
|
|
|
$notification = $success === true ? 'Sauvegarde importée avec succès' : 'Erreur d\'extraction';
|
2020-02-10 16:36:57 +01:00
|
|
|
$redirect = $this->getInput('configRestoreImportUser', helper::FILTER_BOOLEAN) === true ? helper::baseUrl() . 'config/restore' : helper::baseUrl() . 'user/login/';
|
2019-12-10 10:53:31 +01:00
|
|
|
// Valeurs en sortie erreur
|
|
|
|
$this->addOutput([
|
|
|
|
'notification' => $notification,
|
|
|
|
'redirect' =>$redirect,
|
|
|
|
'state' => $success
|
|
|
|
]);
|
|
|
|
}
|
2018-10-24 22:48:10 +02:00
|
|
|
|
2019-12-10 10:53:31 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2020-02-10 17:04:25 +01:00
|
|
|
'title' => 'Restaurer une sauvegarde',
|
2020-02-10 16:36:57 +01:00
|
|
|
'view' => 'restore'
|
2019-12-10 10:53:31 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-10-24 22:48:10 +02:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
/**
|
|
|
|
* Configuration
|
|
|
|
*/
|
|
|
|
public function index() {
|
|
|
|
// Soumission du formulaire
|
|
|
|
if($this->isPost()) {
|
2020-03-01 16:04:59 +01:00
|
|
|
// Basculement en mise à jour auto
|
|
|
|
// Remise à 0 du compteur
|
|
|
|
if ($this->getData(['config','autoUpdate']) === false &&
|
|
|
|
$this->getInput('configAutoUpdate', helper::FILTER_BOOLEAN) === true) {
|
|
|
|
$this->setData(['core','lastAutoUpdate',0]);
|
|
|
|
}
|
2020-03-02 13:08:03 +01:00
|
|
|
// Vérification du proxy
|
|
|
|
$proxy = $this->getData(['config','proxyType']) . $this->getData(['config','proxyUrl']) . ':' . $this->getData(['config','proxyPort']);
|
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
$this->setData([
|
|
|
|
'config',
|
|
|
|
[
|
2019-12-11 22:42:05 +01:00
|
|
|
'homePageId' => $this->getInput('configHomePageId', helper::FILTER_ID, true),
|
2018-04-02 08:29:19 +02:00
|
|
|
'analyticsId' => $this->getInput('configAnalyticsId'),
|
|
|
|
'autoBackup' => $this->getInput('configAutoBackup', helper::FILTER_BOOLEAN),
|
|
|
|
'maintenance' => $this->getInput('configMaintenance', helper::FILTER_BOOLEAN),
|
|
|
|
'cookieConsent' => $this->getInput('configCookieConsent', helper::FILTER_BOOLEAN),
|
|
|
|
'favicon' => $this->getInput('configFavicon'),
|
2020-01-02 19:30:23 +01:00
|
|
|
'faviconDark' => $this->getInput('configFaviconDark'),
|
2018-04-02 08:29:19 +02:00
|
|
|
'social' => [
|
|
|
|
'facebookId' => $this->getInput('configSocialFacebookId'),
|
2019-05-02 13:21:48 +02:00
|
|
|
'linkedinId' => $this->getInput('configSocialLinkedinId'),
|
2018-04-02 08:29:19 +02:00
|
|
|
'instagramId' => $this->getInput('configSocialInstagramId'),
|
|
|
|
'pinterestId' => $this->getInput('configSocialPinterestId'),
|
|
|
|
'twitterId' => $this->getInput('configSocialTwitterId'),
|
2019-06-12 09:45:42 +02:00
|
|
|
'youtubeId' => $this->getInput('configSocialYoutubeId'),
|
2020-02-01 20:49:35 +01:00
|
|
|
'youtubeUserId' => $this->getInput('configSocialYoutubeUserId'),
|
2019-06-12 09:45:42 +02:00
|
|
|
'githubId' => $this->getInput('configSocialGithubId')
|
2018-04-02 08:29:19 +02:00
|
|
|
],
|
|
|
|
'timezone' => $this->getInput('configTimezone', helper::FILTER_STRING_SHORT, true),
|
2020-03-02 13:11:16 +01:00
|
|
|
'itemsperPage' => $this->getInput('ConfigItemsperPage', helper::FILTER_INT,true),
|
2019-11-21 22:18:42 +01:00
|
|
|
'legalPageId' => $this->getInput('configLegalPageId'),
|
2019-12-10 10:53:31 +01:00
|
|
|
'metaDescription' => $this->getInput('configMetaDescription', helper::FILTER_STRING_LONG, true),
|
|
|
|
'title' => $this->getInput('configTitle', helper::FILTER_STRING_SHORT, true),
|
2020-03-02 13:08:03 +01:00
|
|
|
'autoUpdate' => $this->getInput('configAutoUpdate', helper::FILTER_BOOLEAN),
|
|
|
|
'proxyType' => $this->getInput('configProxyType'),
|
|
|
|
'proxyUrl' => $this->getInput('configProxyUrl'),
|
2020-03-02 13:11:16 +01:00
|
|
|
'proxyPort' => $this->getInput('configProxyPort',helper::FILTER_INT)
|
2018-04-02 08:29:19 +02:00
|
|
|
]
|
|
|
|
]);
|
2019-12-10 10:53:31 +01:00
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
if(self::$inputNotices === []) {
|
2019-06-07 23:18:44 +02:00
|
|
|
// Ecrire les fichiers de script
|
|
|
|
file_put_contents(self::DATA_DIR . 'head.inc.html',$this->getInput('configScriptHead',null));
|
|
|
|
file_put_contents(self::DATA_DIR . 'body.inc.html',$this->getInput('configScriptBody',null));
|
2018-04-02 08:29:19 +02:00
|
|
|
// Active la réécriture d'URL
|
|
|
|
$rewrite = $this->getInput('rewrite', helper::FILTER_BOOLEAN);
|
|
|
|
if(
|
|
|
|
$rewrite
|
|
|
|
AND helper::checkRewrite() === false
|
|
|
|
) {
|
|
|
|
// Ajout des lignes dans le .htaccess
|
|
|
|
file_put_contents(
|
|
|
|
'.htaccess',
|
|
|
|
PHP_EOL .
|
|
|
|
'<ifModule mod_rewrite.c>' . PHP_EOL .
|
|
|
|
"\tRewriteEngine on" . PHP_EOL .
|
|
|
|
"\tRewriteBase " . helper::baseUrl(false, false) . PHP_EOL .
|
|
|
|
"\tRewriteCond %{REQUEST_FILENAME} !-f" . PHP_EOL .
|
|
|
|
"\tRewriteCond %{REQUEST_FILENAME} !-d" . PHP_EOL .
|
|
|
|
"\tRewriteRule ^(.*)$ index.php?$1 [L]" . PHP_EOL .
|
|
|
|
'</ifModule>',
|
|
|
|
FILE_APPEND
|
|
|
|
);
|
|
|
|
// Change le statut de la réécriture d'URL (pour le helper::baseUrl() de la redirection)
|
|
|
|
helper::$rewriteStatus = true;
|
|
|
|
}
|
|
|
|
// Désactive la réécriture d'URL
|
|
|
|
elseif(
|
|
|
|
$rewrite === false
|
|
|
|
AND helper::checkRewrite()
|
|
|
|
) {
|
|
|
|
// Suppression des lignes dans le .htaccess
|
|
|
|
$htaccess = explode('# URL rewriting', file_get_contents('.htaccess'));
|
|
|
|
file_put_contents('.htaccess', $htaccess[0] . '# URL rewriting');
|
|
|
|
// Change le statut de la réécriture d'URL (pour le helper::baseUrl() de la redirection)
|
|
|
|
helper::$rewriteStatus = false;
|
|
|
|
}
|
2019-12-22 18:33:58 +01:00
|
|
|
// Met à jour la baseUrl
|
|
|
|
$this->setData(['core', 'baseUrl', helper::baseUrl(true,false) ]);
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
2019-05-02 13:21:48 +02:00
|
|
|
// Générer robots.txt et sitemap
|
|
|
|
$this->generateFiles();
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'redirect' => helper::baseUrl() . $this->getUrl(),
|
|
|
|
'notification' => 'Modifications enregistrées',
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
2018-12-30 14:23:08 +01:00
|
|
|
// Initialisation du screen
|
2019-05-27 20:35:04 +02:00
|
|
|
if (!file_exists(self::FILE_DIR.'source/screenshot.png')) {
|
2018-12-30 14:23:08 +01:00
|
|
|
$this->configMetaImage();
|
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'title' => 'Configuration',
|
|
|
|
'view' => 'index'
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-02-27 15:49:32 +01:00
|
|
|
/**
|
|
|
|
* Mise à jour présente
|
|
|
|
*/
|
|
|
|
public function updateOnline() {
|
|
|
|
// Nouvelle version
|
|
|
|
self::$newVersion = file_get_contents('http://zwiicms.com/update/' . common::ZWII_UPDATE_CHANNEL . '/version');
|
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
|
|
|
'notification' => 'Version installée : '. common::ZWII_VERSION . '<br>Version de la mise à jour en ligne : '. self::$newVersion ,
|
|
|
|
'redirect' => helper::baseUrl() . 'config',
|
|
|
|
'state' => true
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class configHelper extends helper {
|
|
|
|
|
|
|
|
/**
|
2019-12-10 10:53:31 +01:00
|
|
|
* Met à jour les données de site avec l'adresse trannsmise
|
2018-04-02 08:29:19 +02:00
|
|
|
*/
|
2019-12-25 11:17:22 +01:00
|
|
|
public function updateBaseUrl () {
|
2019-12-25 11:09:08 +01:00
|
|
|
// Supprimer l'information de redirection
|
|
|
|
$old = str_replace('?','',$this->getData(['core', 'baseUrl']));
|
|
|
|
$new = helper::baseUrl(false,false);
|
|
|
|
$success = false ;
|
2019-12-17 09:23:38 +01:00
|
|
|
// Boucler sur les pages
|
2019-12-10 10:53:31 +01:00
|
|
|
foreach($this->getHierarchy(null,null,null) as $parentId => $childIds) {
|
2019-12-25 11:09:08 +01:00
|
|
|
$content = $this->getData(['page',$parentId,'content']);
|
|
|
|
$replace = str_replace( $old , $new , stripslashes($content),$count) ;
|
|
|
|
if ($count > 0) {
|
|
|
|
$success = true;
|
2019-12-23 20:58:30 +01:00
|
|
|
$this->setData(['page',$parentId,'content', $replace ]);
|
2019-12-23 10:49:57 +01:00
|
|
|
}
|
2019-12-10 10:53:31 +01:00
|
|
|
foreach($childIds as $childId) {
|
|
|
|
$content = $this->getData(['page',$childId,'content']);
|
2019-12-25 11:09:08 +01:00
|
|
|
$replace = str_replace( $old , $new, stripslashes($content),$count) ;
|
|
|
|
if ($count > 0) {
|
|
|
|
$success = true;
|
2019-12-23 20:58:30 +01:00
|
|
|
$this->setData(['page',$childId,'content', $replace ]);
|
2019-12-25 11:09:08 +01:00
|
|
|
}
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
2019-12-25 11:09:08 +01:00
|
|
|
}
|
|
|
|
if ($success === true) {
|
|
|
|
$this->setData(['core','baseUrl',helper::baseUrl(true,false)]);
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
2019-12-10 10:53:31 +01:00
|
|
|
// Valeurs en sortie
|
|
|
|
$this->addOutput([
|
2019-12-25 11:09:08 +01:00
|
|
|
'notification' => $success ? 'Conversion effectuée' : 'Aucune conversion',
|
2020-02-10 16:36:57 +01:00
|
|
|
'redirect' => helper::baseUrl() . 'config/restore',
|
2019-12-25 11:09:08 +01:00
|
|
|
'state' => $success ? true : false
|
2019-12-10 10:53:31 +01:00
|
|
|
]);
|
2018-04-02 08:29:19 +02:00
|
|
|
}
|
2019-05-02 13:21:48 +02:00
|
|
|
}
|