@ -26,7 +26,7 @@ class config extends common {
'updateBaseUrl' => self::GROUP_ADMIN,
'script' => self::GROUP_ADMIN
];
public static $timezones = [
'Pacific/Midway' => '(GMT-11:00) Midway Island',
'US/Samoa' => '(GMT-11:00) Samoa',
@ -147,7 +147,7 @@ class config extends common {
5 => '5 articles',
10 => '10 articles',
15 => '15 articles',
20 => '20 articles'
20 => '20 articles'
];
// Type de proxy
public static $proxyType = [
@ -187,7 +187,7 @@ class config extends common {
}
/**
* Met à jour un fichier robots.txt lors du changement de réécriture
* Met à jour un fichier robots.txt lors du changement de réécriture
*/
public function updateRobots() {
@ -199,7 +199,7 @@ class config extends common {
rename ('robots.txt','robots.bak');
$fileold = fopen('robots.bak','r');
$filenew = fopen('robots.txt','w');
while(!feof($fileold)) {
while(!feof($fileold)) {
$data = fgets($fileold);
if (strpos($data,'sitemap.xml') == 0) {
fwrite($filenew, $data);
@ -221,11 +221,11 @@ class config extends common {
public function backup() {
// Soumission du formulaire
if($this->isPost()) {
// Creation du ZIP
// Creation du ZIP
$filter = $this->getInput('configBackupOption',helper::FILTER_BOOLEAN) === true ? ['backup','tmp'] : ['backup','tmp','file'];
$fileName = helper::autoBackup(self::TEMP_DIR,$filter);
// Téléchargement du ZIP
// Téléchargement du ZIP
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="' . $fileName . '"');
header('Content-Length: ' . filesize(self::TEMP_DIR . $fileName));
@ -249,18 +249,18 @@ class config extends common {
* https://www.codexworld.com/capture-screenshot-website-url-php-google-api/
*/
public function configMetaImage() {
// 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) {
// 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) {
$site = 'https://zwiicms.com/'; } else {
$site = helper::baseUrl(false); }
$success= false;
$googlePagespeedData = helper::urlGetContents('https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url='. $site .'&screenshot=true');
if ($googlePagespeedData !== false) {
$googlePagespeedData = json_decode($googlePagespeedData, true);
$data = str_replace('_','/',$googlePagespeedData['lighthouseResult']['audits']['final-screenshot']['details']['data']);
$data = str_replace('-','+',$data);
$img = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data));
$img = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $data));
// Effacer la miniature
if (file_exists(self::FILE_DIR.'thumb/screenshot.jpg')) {
unlink (self::FILE_DIR.'thumb/screenshot.jpg');
@ -274,7 +274,7 @@ class config extends common {
'redirect' => helper::baseUrl() . 'config',
'state' => $success
]);
}
}
/**
* Procédure d'importation
@ -296,7 +296,7 @@ class config extends common {
]);
}
$successOpen = $zip->open(self::FILE_DIR . 'source/' . $fileZip);
if ($successOpen === FALSE) {
if ($successOpen === FALSE) {
// Valeurs en sortie erreur
$this->addOutput([
'notification' => 'Impossible de lire l\'archive',
@ -305,29 +305,29 @@ class config extends common {
]);
}
// 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'] ));
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 ) {
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 & &
} 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 ) {
// V10 valide
$version = '10';
// Option active, les users sont stockées
if ($this->getInput('configManageImportUser', helper::FILTER_BOOLEAN) === true ) {
$users = $this->getData(['user']);
}
if ($this->getInput('configManageImportUser', helper::FILTER_BOOLEAN) === true ) {
$users = $this->getData(['user']);
}
} else { // Version invalide
// Valeurs en sortie erreur
$this->addOutput([
@ -343,35 +343,35 @@ class config extends common {
$_SESSION['KEEP_USERS'] = $this->getInput('configManageImportUser', helper::FILTER_BOOLEAN);
}
// Extraire le zip ou 'site/'
$success = $zip->extractTo( 'site/' );
// Fermer l'archive
$success = $zip->extractTo( 'site/' );
// Fermer l'archive
$zip->close();
// Restaurer les users originaux d'une v10 si option cochée
if (!empty($users) & &
$version === '10' & &
$this->getInput('configManageImportUser', helper::FILTER_BOOLEAN) === true) {
$this->setData(['user',$users]);
$this->getInput('configManageImportUser', helper::FILTER_BOOLEAN) === true) {
$this->setData(['user',$users]);
}
/*
if ($version === '9' ) {
$this->importData($this->getInput('configManageImportUser', helper::FILTER_BOOLEAN));
$this->importData($this->getInput('configManageImportUser', helper::FILTER_BOOLEAN));
$this->setData(['core','dataVersion',0]);
}*/
// Met à jours les URL dans les contenus de page
// Message de notification
$notification = $success === true ? 'Restauration réalisée avec succès' : 'Erreur inconnue';
$notification = $success === true ? 'Restauration réalisée avec succès' : 'Erreur inconnue';
$redirect = $this->getInput('configManageImportUser', helper::FILTER_BOOLEAN) === true ? helper::baseUrl() . 'config/manage' : helper::baseUrl() . 'user/login/';
// Valeurs en sortie erreur
// Valeurs en sortie erreur
$this->addOutput([
'notification' => $notification,
'redirect' =>$redirect,
'state' => $success
]);
}
}
// Valeurs en sortie
$this->addOutput([
'title' => 'Restaurer',
@ -421,9 +421,9 @@ class config extends common {
'timezone' => $this->getInput('configTimezone', helper::FILTER_STRING_SHORT, true),
'itemsperPage' => $this->getInput('configItemsperPage', helper::FILTER_INT,true),
'legalPageId' => $this->getInput('configLegalPageId'),
'metaDescription' => $this->getInput('configMetaDescription', helper::FILTER_STRING_LONG, true),
'metaDescription' => $this->getInput('configMetaDescription', helper::FILTER_STRING_LONG, true),
'title' => $this->getInput('configTitle', helper::FILTER_STRING_SHORT, true),
'autoUpdate' => helper::urlGetContents('http://zwiicms.com/update/' . common::ZWII_UPDATE_CHANNEL . '/version') === false
'autoUpdate' => helper::urlGetContents('http://zwiicms.com/update/' . common::ZWII_UPDATE_CHANNEL . '/version') === false
? false
: $this->getInput('configAutoUpdate', helper::FILTER_BOOLEAN),
'proxyType' => $this->getInput('configProxyType'),
@ -488,8 +488,8 @@ class config extends common {
'state' => true
]);
}
// Initialisation du screen
if (!file_exists(self::FILE_DIR.'source/screenshot.pn g')) {
// Initialisation du screen
if (!file_exists(self::FILE_DIR.'source/screenshot.j pg')) {
$this->configMetaImage();
}
// Valeurs en sortie
@ -507,8 +507,8 @@ class config extends common {
file_put_contents(self::DATA_DIR . 'head.inc.html',$this->getInput('configScriptHead',null));
}
if ($this->geturl(2) === 'body') {
file_put_contents(self::DATA_DIR . 'body.inc.html',$this->getInput('configScriptBody',null));
}
file_put_contents(self::DATA_DIR . 'body.inc.html',$this->getInput('configScriptBody',null));
}
// Valeurs en sortie
$this->addOutput([
'notification' => 'Modifications enregistrées',
@ -529,17 +529,17 @@ class config extends common {
/**
* Met à jour les données de site avec l'adresse trannsmise
*/
public function updateBaseUrl () {
public function updateBaseUrl () {
// Supprimer l'information de redirection
$old = str_replace('?','',$this->getData(['core', 'baseUrl']));
$new = helper::baseUrl(false,false);
$c3 = 0;
$success = false ;
// Boucler sur les pages
// Boucler sur les pages
foreach($this->getHierarchy(null,null,null) as $parentId => $childIds) {
$content = $this->getData(['page',$parentId,'content']);
$replace = str_replace( 'href="' . $old , 'href="'. $new , stripslashes($content),$c1) ;
$replace = str_replace( 'src="' . $old , 'src="'. $new , stripslashes($replace),$c2) ;
$replace = str_replace( 'href="' . $old , 'href="'. $new , stripslashes($content),$c1) ;
$replace = str_replace( 'src="' . $old , 'src="'. $new , stripslashes($replace),$c2) ;
if ($c1 > 0 || $c2 > 0) {
$success = true;
@ -548,21 +548,21 @@ class config extends common {
}
foreach($childIds as $childId) {
$content = $this->getData(['page',$childId,'content']);
$replace = str_replace( 'href="' . $old , 'href="'. $new , stripslashes($content),$c1) ;
$replace = str_replace( 'src="' . $old , 'src="'. $new , stripslashes($replace),$c2) ;
$replace = str_replace( 'href="' . $old , 'href="'. $new , stripslashes($content),$c1) ;
$replace = str_replace( 'src="' . $old , 'src="'. $new , stripslashes($replace),$c2) ;
if ($c1 > 0 || $c2 > 0) {
$success = true;
$this->setData(['page',$childId,'content', $replace ]);
$c3 += $c1 + $c2;
}
}
}
}
// Traiter les modules dont la redirection
$content = $this->getdata(['module']);
$replace = $this->recursive_array_replace('href="' . $old , 'href="'. $new, $content, $c1);
$replace = $this->recursive_array_replace('src="' . $old , 'src="'. $new, $replace, $c2);
if ($content !== $replace) {
$this->setdata(['module',$replace]);
$this->setdata(['module',$replace]);
$c3 += $c1 + $c2;
$success = true;
}
@ -584,14 +584,14 @@ class config extends common {
* @param int count nombres d'occurences
* @return array avec les valeurs remplacées.
*/
private function recursive_array_replace ($find, $replace, $array, & $count) {
private function recursive_array_replace ($find, $replace, $array, & $count) {
if (!is_array($array)) {
return str_replace($find, $replace, $array, $count);
return str_replace($find, $replace, $array, $count);
}
$newArray = [];
foreach ($array as $key => $value) {
$newArray[$key] = $this->recursive_array_replace($find, $replace, $value,$c);
$newArray[$key] = $this->recursive_array_replace($find, $replace, $value,$c);
$count += $c;
}
return $newArray;