From 4272e8590204e1977c709afc2b7966201b6be8b7 Mon Sep 17 00:00:00 2001 From: Deltacms Date: Mon, 11 Sep 2023 11:50:11 +0200 Subject: [PATCH] =?UTF-8?q?s=C3=A9curit=C3=A9=20des=20modules=20de=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/agenda/agenda.php | 706 ++++++++++--------- module/blog/blog.php | 1022 +++++++++++++++------------- module/form/form.php | 399 ++++++----- module/gallery/gallery.php | 760 +++++++++++---------- module/news/news.php | 532 ++++++++------- module/redirection/redirection.php | 38 +- module/search/search.php | 84 ++- module/slider/slider.php | 248 +++---- module/statislite/statislite.php | 675 +++++++++--------- 9 files changed, 2421 insertions(+), 2043 deletions(-) diff --git a/module/agenda/agenda.php b/module/agenda/agenda.php index f8006fd..6b5859a 100644 --- a/module/agenda/agenda.php +++ b/module/agenda/agenda.php @@ -126,195 +126,205 @@ class agenda extends common { * Configuration Paramètrage */ public function config() { - // Lexique - include('./module/agenda/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_agenda.php'); - // Mise à jour des données de module - $this->update(); - - // Soumission du formulaire - if($this->isPost()) { - $notification = $text['agenda']['config'][6]; - $state = true; - $fichier_restaure = $this->getInput('config_restaure'); - $fichier_sauve = $this->getInput('config_sauve'); - $droit_creation = $this->getInput('config_droit_creation'); - $droit_limite = $this->getInput('config_droit_limite', helper::FILTER_BOOLEAN); - $fichier_ics = $this->getInput('config_fichier_ics'); - $largeur_maxi = $this->getInput('config_MaxiWidth'); - $fichier_csv_txt = $this->getInput('config_fichier_csv_txt'); - - //Sauvegarder l'agenda - if ($fichier_sauve !=''){ - $json_sauve = file_get_contents(self::DATAMODULE.'data/'.$this->getUrl(0).'/events.json'); - file_put_contents(self::DATAMODULE.'data/'.$this->getUrl(0).'_sauve/'.$fichier_sauve.'.json', $json_sauve); - } + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < agenda::$actions['config'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./module/agenda/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_agenda.php'); + // Mise à jour des données de module + $this->update(); - //Charger un agenda sauvegardé - if (strpos($fichier_restaure,'.json') !== false){ - - //Remplacement par le fichier de restauration - $json_restaure = file_get_contents(self::DATAMODULE.'data/'.$this->getUrl(0).'_sauve/'. $fichier_restaure); - file_put_contents(self::DATAMODULE.'data/'.$this->getUrl(0).'/events.json', $json_restaure); + // Soumission du formulaire + if($this->isPost()) { + $notification = $text['agenda']['config'][6]; + $state = true; + $fichier_restaure = $this->getInput('config_restaure'); + $fichier_sauve = $this->getInput('config_sauve'); + $droit_creation = $this->getInput('config_droit_creation'); + $droit_limite = $this->getInput('config_droit_limite', helper::FILTER_BOOLEAN); + $fichier_ics = $this->getInput('config_fichier_ics'); + $largeur_maxi = $this->getInput('config_MaxiWidth'); + $fichier_csv_txt = $this->getInput('config_fichier_csv_txt'); + + //Sauvegarder l'agenda + if ($fichier_sauve !=''){ + $json_sauve = file_get_contents(self::DATAMODULE.'data/'.$this->getUrl(0).'/events.json'); + file_put_contents(self::DATAMODULE.'data/'.$this->getUrl(0).'_sauve/'.$fichier_sauve.'.json', $json_sauve); + } - //Sauvegarde dans data_sauve de l'agenda chargé - $this->sauve($json_restaure); + //Charger un agenda sauvegardé + if (strpos($fichier_restaure,'.json') !== false){ + + //Remplacement par le fichier de restauration + $json_restaure = file_get_contents(self::DATAMODULE.'data/'.$this->getUrl(0).'_sauve/'. $fichier_restaure); + file_put_contents(self::DATAMODULE.'data/'.$this->getUrl(0).'/events.json', $json_restaure); + + //Sauvegarde dans data_sauve de l'agenda chargé + $this->sauve($json_restaure); + + //Valeurs en sortie après prise en compte du formulaire + $this->addOutput([ + 'notification' => $text['agenda']['config'][7], + 'redirect' => helper::baseUrl() . $this->getUrl(0), + 'state' => true + ]); + } - //Valeurs en sortie après prise en compte du formulaire + //Ajouter des évènements contenus dans le fichier ics + if (strpos($fichier_ics,'.ics') !== false){ + $tableau = $this->getIcsEventsAsArray(self::DATAFILE.'ics/'.$fichier_ics); + foreach($tableau as $key=>$value){ + $evenement_texte = ''; + $date_debut = ''; + $date_fin = ''; + $begin = ''; + $end = ''; + $clef_fin =''; + foreach($value as $key2=>$value2){ + if($key2 == "BEGIN"){ + $begin = $value2; + } + if($key2 == "SUMMARY"){ + $evenement_texte = $value2; + } + if(strpos($key2,"DTSTART") !== false){ + $date_debut = $value2; + $clef_debut = $key2; + } + if(strpos($key2,"DTEND") !== false){ + $date_fin = $value2; + $clef_fin = $key2; + } + if($key2 == "END"){ + $end = $value2; + } + } + + //Si un évènement VEVENT est trouvé, avec summary et dtstart présents, on ajoute cet évènement à l'agenda + if ($evenement_texte != '' && strpos($begin,'VEVENT')!==false && $date_debut!=='' ){ + if($date_fin == '') { + $date_fin = $date_debut; + $clef_fin = $clef_debut; + } + $evenement_texte = $this->modif_texte($evenement_texte); + //Modifier date format ics yyyymmddThhmm... ou yyyymmdd vers format fullcalendar yyyy-mm-ddThh:mm + $date_debut = $this->modif_date($date_debut, $clef_debut); + $date_fin = $this->modif_date($date_fin, $clef_fin); + + //Valeurs par défaut pour l'import ics fond blanc, texte noir, lecture visiteur, modification éditeur + $this->nouvel_evenement($evenement_texte,$date_debut,$date_fin,'white','black','0','2', '0', '', '', ''); + } + } + } + + // Ajouter un carnet d'adresses + if (strpos($fichier_csv_txt,'.csv') !== false || strpos($fichier_csv_txt,'.txt') !== false){ + $adresses = file_get_contents(self::DATAFILE.'adresses/'.$fichier_csv_txt); + if( strrchr($adresses, '@') && ! strrchr($adresses, ';')){ + copy(self::DATAFILE.'adresses/'.$fichier_csv_txt, self::DATAMODULE.'adresses/'.$fichier_csv_txt); + } + else{ + $notification = $text['agenda']['config'][8]; + $state = false; + } + } + + //Mise à jour des données de configuration liées aux droits et à l'affichage + $this->setData(['module', $this->getUrl(0), 'config', [ + 'droit_creation' => intval($droit_creation), + 'droit_limite' => $droit_limite, + 'maxiWidth' => $largeur_maxi, + 'versionData' => $this->getData(['module', $this->getUrl(0), 'config', 'versionData']) + ]]); + $this->setData(['module', $this->getUrl(0), 'texts',[ + 'configTextButtonBack' => $this->getInput('configTextButtonBack'), + 'configTextDateStart' => $this->getInput('configTextDateStart'), + 'configTextDateEnd' =>$this->getInput('configTextDateEnd') + ] + ]); + + //Valeurs en sortie $this->addOutput([ - 'notification' => $text['agenda']['config'][7], + 'notification' => $notification, 'redirect' => helper::baseUrl() . $this->getUrl(0), - 'state' => true + 'state' => $state ]); } - - //Ajouter des évènements contenus dans le fichier ics - if (strpos($fichier_ics,'.ics') !== false){ - $tableau = $this->getIcsEventsAsArray(self::DATAFILE.'ics/'.$fichier_ics); - foreach($tableau as $key=>$value){ - $evenement_texte = ''; - $date_debut = ''; - $date_fin = ''; - $begin = ''; - $end = ''; - $clef_fin =''; - foreach($value as $key2=>$value2){ - if($key2 == "BEGIN"){ - $begin = $value2; - } - if($key2 == "SUMMARY"){ - $evenement_texte = $value2; - } - if(strpos($key2,"DTSTART") !== false){ - $date_debut = $value2; - $clef_debut = $key2; - } - if(strpos($key2,"DTEND") !== false){ - $date_fin = $value2; - $clef_fin = $key2; - } - if($key2 == "END"){ - $end = $value2; - } + else{ + // Fichiers sauvegardés + if(is_dir(self::DATAMODULE.'data/'.$this->getUrl(0).'_sauve')) { + $dir=self::DATAMODULE.'data/'.$this->getUrl(0).'_sauve'; + $values = scandir($dir); + self::$savedFiles=[]; + $values[0] = $text['agenda']['config'][0]; + unset($values[array_search('..', $values)]); + if (count($values) <= 1){ + self::$savedFiles = array(0 => $text['agenda']['config'][1]. self::DATAMODULE.'/data'); } - - //Si un évènement VEVENT est trouvé, avec summary et dtstart présents, on ajoute cet évènement à l'agenda - if ($evenement_texte != '' && strpos($begin,'VEVENT')!==false && $date_debut!=='' ){ - if($date_fin == '') { - $date_fin = $date_debut; - $clef_fin = $clef_debut; - } - $evenement_texte = $this->modif_texte($evenement_texte); - //Modifier date format ics yyyymmddThhmm... ou yyyymmdd vers format fullcalendar yyyy-mm-ddThh:mm - $date_debut = $this->modif_date($date_debut, $clef_debut); - $date_fin = $this->modif_date($date_fin, $clef_fin); - - //Valeurs par défaut pour l'import ics fond blanc, texte noir, lecture visiteur, modification éditeur - $this->nouvel_evenement($evenement_texte,$date_debut,$date_fin,'white','black','0','2', '0', '', '', ''); + else{ + //Modifier les clefs (qui sont les valeurs de retour du formulaire avec 'config_restaure') avec clef = valeur + self::$savedFiles = array_combine($values,$values); } } + else { + self::$savedFiles = array(0 => $text['agenda']['config'][2].self::DATAMODULE.$text['agenda']['config'][3]); + } + // Fichiers ics + if(is_dir(self::DATAFILE.'ics')) { + $dir=self::DATAFILE.'ics'; + $values = scandir($dir); + $values[0] = $text['agenda']['config'][0]; + unset($values[array_search('..', $values)]); + if (count($values) <= 1){ + self::$icsFiles = array(0 => $text['agenda']['config'][1].self::DATAFILE.'ics'); + } + else{ + //Modifier les clefs (qui sont les valeurs de retour du formulaire avec 'config_fichier_ics') avec clef = valeur + self::$icsFiles = array_combine($values,$values); + } + } + else { + self::$icsFiles = array(0 => $text['agenda']['config'][2].self::DATAFILE.$text['agenda']['config'][4]); + } + // Fichiers csv ou txt + if(is_dir(self::DATAFILE.'adresses')) { + $dir=self::DATAFILE.'adresses'; + $values = scandir($dir); + $values[0] = $text['agenda']['config'][0]; + unset($values[array_search('..', $values)]); + // Supprimer les $values qui ne sont pas csv ou txt + for($i=2; $i <= count($values); $i++){ + if ( pathinfo($dir.'/'.$values[$i],PATHINFO_EXTENSION) !== 'txt' && pathinfo($dir.'/'.$values[$i],PATHINFO_EXTENSION) !== 'csv') unset($values[$i]); + } + if (count($values) <= 1){ + self::$csvFiles = array(0 => $text['agenda']['config'][1].self::DATAFILE.'adresses'); + } + else{ + //Modifier les clefs (qui sont les valeurs de retour du formulaire avec 'config_fichier_csv_txt') avec clef = valeur + self::$csvFiles = array_combine($values,$values); + } + } + else { + self::$csvFiles = array(0 => $text['agenda']['config'][2].self::DATAFILE.$text['agenda']['config'][5]); + } + + // Copie des fichiers ics entre les dossiers self::DATAFILE.ics et self::DATAMODULE.ics pour export + $this->custom_copy(self::DATAFILE.'ics', self::DATAMODULE.'ics'); + $this->custom_copy(self::DATAMODULE.'ics', self::DATAFILE.'ics'); + + // Valeurs en sortie hors soumission du formulaire + $this->addOutput([ + 'showBarEditButton' => true, + 'showPageContent' => false, + 'view' => 'config' + ]); } - - // Ajouter un carnet d'adresses - if (strpos($fichier_csv_txt,'.csv') !== false || strpos($fichier_csv_txt,'.txt') !== false){ - $adresses = file_get_contents(self::DATAFILE.'adresses/'.$fichier_csv_txt); - if( strrchr($adresses, '@') && ! strrchr($adresses, ';')){ - copy(self::DATAFILE.'adresses/'.$fichier_csv_txt, self::DATAMODULE.'adresses/'.$fichier_csv_txt); - } - else{ - $notification = $text['agenda']['config'][8]; - $state = false; - } - } - - //Mise à jour des données de configuration liées aux droits et à l'affichage - $this->setData(['module', $this->getUrl(0), 'config', [ - 'droit_creation' => intval($droit_creation), - 'droit_limite' => $droit_limite, - 'maxiWidth' => $largeur_maxi, - 'versionData' => $this->getData(['module', $this->getUrl(0), 'config', 'versionData']) - ]]); - $this->setData(['module', $this->getUrl(0), 'texts',[ - 'configTextButtonBack' => $this->getInput('configTextButtonBack'), - 'configTextDateStart' => $this->getInput('configTextDateStart'), - 'configTextDateEnd' =>$this->getInput('configTextDateEnd') - ] - ]); - - //Valeurs en sortie - $this->addOutput([ - 'notification' => $notification, - 'redirect' => helper::baseUrl() . $this->getUrl(0), - 'state' => $state - ]); - } - else{ - // Fichiers sauvegardés - if(is_dir(self::DATAMODULE.'data/'.$this->getUrl(0).'_sauve')) { - $dir=self::DATAMODULE.'data/'.$this->getUrl(0).'_sauve'; - $values = scandir($dir); - self::$savedFiles=[]; - $values[0] = $text['agenda']['config'][0]; - unset($values[array_search('..', $values)]); - if (count($values) <= 1){ - self::$savedFiles = array(0 => $text['agenda']['config'][1]. self::DATAMODULE.'/data'); - } - else{ - //Modifier les clefs (qui sont les valeurs de retour du formulaire avec 'config_restaure') avec clef = valeur - self::$savedFiles = array_combine($values,$values); - } - } - else { - self::$savedFiles = array(0 => $text['agenda']['config'][2].self::DATAMODULE.$text['agenda']['config'][3]); - } - // Fichiers ics - if(is_dir(self::DATAFILE.'ics')) { - $dir=self::DATAFILE.'ics'; - $values = scandir($dir); - $values[0] = $text['agenda']['config'][0]; - unset($values[array_search('..', $values)]); - if (count($values) <= 1){ - self::$icsFiles = array(0 => $text['agenda']['config'][1].self::DATAFILE.'ics'); - } - else{ - //Modifier les clefs (qui sont les valeurs de retour du formulaire avec 'config_fichier_ics') avec clef = valeur - self::$icsFiles = array_combine($values,$values); - } - } - else { - self::$icsFiles = array(0 => $text['agenda']['config'][2].self::DATAFILE.$text['agenda']['config'][4]); - } - // Fichiers csv ou txt - if(is_dir(self::DATAFILE.'adresses')) { - $dir=self::DATAFILE.'adresses'; - $values = scandir($dir); - $values[0] = $text['agenda']['config'][0]; - unset($values[array_search('..', $values)]); - // Supprimer les $values qui ne sont pas csv ou txt - for($i=2; $i <= count($values); $i++){ - if ( pathinfo($dir.'/'.$values[$i],PATHINFO_EXTENSION) !== 'txt' && pathinfo($dir.'/'.$values[$i],PATHINFO_EXTENSION) !== 'csv') unset($values[$i]); - } - if (count($values) <= 1){ - self::$csvFiles = array(0 => $text['agenda']['config'][1].self::DATAFILE.'adresses'); - } - else{ - //Modifier les clefs (qui sont les valeurs de retour du formulaire avec 'config_fichier_csv_txt') avec clef = valeur - self::$csvFiles = array_combine($values,$values); - } - } - else { - self::$csvFiles = array(0 => $text['agenda']['config'][2].self::DATAFILE.$text['agenda']['config'][5]); - } - - // Copie des fichiers ics entre les dossiers self::DATAFILE.ics et self::DATAMODULE.ics pour export - $this->custom_copy(self::DATAFILE.'ics', self::DATAMODULE.'ics'); - $this->custom_copy(self::DATAMODULE.'ics', self::DATAFILE.'ics'); - - // Valeurs en sortie hors soumission du formulaire - $this->addOutput([ - 'showBarEditButton' => true, - 'showPageContent' => false, - 'view' => 'config' - ]); } } @@ -332,65 +342,76 @@ class agenda extends common { * Suppression d'un évènement */ public function delete($lid, $sauve, $json) { - // Lexique - include('./module/agenda/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_agenda.php'); - $json_initial = $json; - //$pos1 et $pos2 sont les délimiteurs de la partie à supprimer - $pos1 = strpos($json, '{"id":'.$lid); - // si $pos1 non trouvé pas d'effacement - if ( $pos1 !== false ){ - $pos2 = strpos($json, '}', $pos1); - //Premier évènement ? - if ($pos1 < 2) { - //Premier ! et dernier évènement ? - if (strlen($json) < $pos2 + 4){ - $json ='[]'; + // Autorisation si groupe autorisé à modifier l'evt $lid + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + $json = file_get_contents(self::DATAMODULE.'data/'.$this->getUrl(0).'/events.json'); + $tableau = json_decode($json, true); + if( $group < $tableau[$lid]['groupe_mod'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./module/agenda/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_agenda.php'); + $json_initial = $json; + //$pos1 et $pos2 sont les délimiteurs de la partie à supprimer + $pos1 = strpos($json, '{"id":'.$lid); + // si $pos1 non trouvé pas d'effacement + if ( $pos1 !== false ){ + $pos2 = strpos($json, '}', $pos1); + //Premier évènement ? + if ($pos1 < 2) { + //Premier ! et dernier évènement ? + if (strlen($json) < $pos2 + 4){ + $json ='[]'; + } + else{ + $json = substr_replace($json,'{},',$pos1, $pos2-$pos1+2); + } } else{ - $json = substr_replace($json,'{},',$pos1, $pos2-$pos1+2); + $json = substr_replace($json,',{}',$pos1-1, $pos2-$pos1+2); } - } - else{ - $json = substr_replace($json,',{}',$pos1-1, $pos2-$pos1+2); - } - - //Enregistrer le nouveau fichier json - //file_put_contents(self::DATAMODULE.'data/'.$this->getUrl(0).'/events.json', $json); - - //Enregistrer le json et sauvegarder dans data_sauve si suppression de l'évènement et non modification - if ($sauve == true){ - file_put_contents(self::DATAMODULE.'data/'.$this->getUrl(0).'/events.json', $json); - $this->sauve($json); - // Emission d'un mailing éventuel en récupérant les valeurs dans le $json initial - $tableau = json_decode($json_initial, true); - $mailing_val = '0'; - $mailing_adresses = $text['agenda']['delete'][0]; - // Si la clef 'mailing_val' existe dans events.json (version >=3.0) lire mailing_val et mailing_adresses - if( isset( $tableau[$lid]['mailing_val'] )){ - $mailing_val = $tableau[$lid]['mailing_val']; - $mailing_adresses = $tableau[$lid]['mailing_adresses']; - self::$sujet_mailing = $text['agenda']['delete'][1]; + //Enregistrer le nouveau fichier json + //file_put_contents(self::DATAMODULE.'data/'.$this->getUrl(0).'/events.json', $json); + + //Enregistrer le json et sauvegarder dans data_sauve si suppression de l'évènement et non modification + if ($sauve == true){ + file_put_contents(self::DATAMODULE.'data/'.$this->getUrl(0).'/events.json', $json); + $this->sauve($json); + + // Emission d'un mailing éventuel en récupérant les valeurs dans le $json initial + $tableau = json_decode($json_initial, true); + $mailing_val = '0'; + $mailing_adresses = $text['agenda']['delete'][0]; + // Si la clef 'mailing_val' existe dans events.json (version >=3.0) lire mailing_val et mailing_adresses + if( isset( $tableau[$lid]['mailing_val'] )){ + $mailing_val = $tableau[$lid]['mailing_val']; + $mailing_adresses = $tableau[$lid]['mailing_adresses']; + self::$sujet_mailing = $text['agenda']['delete'][1]; + } + $evenement_texte = $text['agenda']['delete'][2].$tableau[$lid]['title']; + $date_debut = $tableau[$lid]['start']; + $date_fin = $tableau[$lid]['end']; + if( $mailing_val === '1') $this->mailing($evenement_texte, $date_debut, $date_fin, $mailing_val, $mailing_adresses); + //Valeurs en sortie si suppression demandée et réalisée + $this->addOutput([ + 'notification' => $text['agenda']['delete'][3], + 'redirect' => helper::baseUrl() . $this->getUrl(0), + 'state' => true + ]); + } + else{ + return $json; } - $evenement_texte = $text['agenda']['delete'][2].$tableau[$lid]['title']; - $date_debut = $tableau[$lid]['start']; - $date_fin = $tableau[$lid]['end']; - if( $mailing_val === '1') $this->mailing($evenement_texte, $date_debut, $date_fin, $mailing_val, $mailing_adresses); - //Valeurs en sortie si suppression demandée et réalisée - $this->addOutput([ - 'notification' => $text['agenda']['delete'][3], - 'redirect' => helper::baseUrl() . $this->getUrl(0), - 'state' => true - ]); } else{ return $json; } } - else{ - return $json; - } - } @@ -398,122 +419,151 @@ class agenda extends common { * Suppression de tous les évènements */ public function deleteall() { - // Lexique - include('./module/agenda/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_agenda.php'); - //Sauvegarde dans data de l'agenda actuel bien qu'il soit déjà sauvegardé dans data_sauve - $json = file_get_contents(self::DATAMODULE.'data/'.$this->getUrl(0).'/events.json'); - file_put_contents(self::DATAMODULE.'data/'.$this->getUrl(0).'/events_'.date('YmdHis').'.json', $json); - - //Enregistrer le nouveau fichier json vide - $json='[]'; - file_put_contents(self::DATAMODULE.'data/'.$this->getUrl(0).'/events.json', $json); - - //Valeurs en sortie - $this->addOutput([ - 'notification' => $text['agenda']['deleteall'][0], - 'redirect' => helper::baseUrl() . $this->getUrl(0), - 'state' => true - ]); - + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < agenda::$actions['deleteall'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./module/agenda/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_agenda.php'); + //Sauvegarde dans data de l'agenda actuel bien qu'il soit déjà sauvegardé dans data_sauve + $json = file_get_contents(self::DATAMODULE.'data/'.$this->getUrl(0).'/events.json'); + file_put_contents(self::DATAMODULE.'data/'.$this->getUrl(0).'/events_'.date('YmdHis').'.json', $json); + + //Enregistrer le nouveau fichier json vide + $json='[]'; + file_put_contents(self::DATAMODULE.'data/'.$this->getUrl(0).'/events.json', $json); + + //Valeurs en sortie + $this->addOutput([ + 'notification' => $text['agenda']['deleteall'][0], + 'redirect' => helper::baseUrl() . $this->getUrl(0), + 'state' => true + ]); + } } /* * Gestion des catégories */ public function categories(){ - // Lexique - include('./module/agenda/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_agenda.php'); - // Soumission du formulaire - if($this->isPost()) { - - // Ajout ou modification d'une catégorie - if( $this->getInput('categorie_name') !== ''){ - $name = $this->getInput('categorie_name'); - $fond = $this->getInput('categorie_couleur_fond'); - $texte = $this->getInput('categorie_couleur_texte'); - $json = file_get_contents(self::DATAMODULE.'categories/categories.json'); - $tabcat = json_decode($json,true); - $unsetkey = ''; - foreach($tabcat as $key=>$value){ - if($value['name'] === $name){ - unset( $value); - $unsetkey = $key; - } - } - $unsetkey === '' ? $indice = count($tabcat) : $indice = $unsetkey; - $tabcat[$indice]['name'] = $name; - $tabcat[$indice]['backgroundcolor'] = $fond; - $tabcat[$indice]['textcolor'] = $texte; - $tabcatjson = json_encode($tabcat); - file_put_contents(self::DATAMODULE.'categories/categories.json', $tabcatjson); - } - - // Validation du choix par catégorie enregistré dans module.json - $valcategories = $this->getInput('val_categories', helper::FILTER_BOOLEAN); - //Mise à jour de la validation du choix des couleurs par catégorie - $this->setData(['module', $this->getUrl(0), 'categories', [ - 'valCategories' => $valcategories - ]]); - - //Valeurs en sortie + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < agenda::$actions['categories'] ) { + // Valeurs en sortie $this->addOutput([ - 'notification' => $text['agenda']['categories'][0], - 'redirect' => helper::baseUrl() . $this->getUrl(), - 'state' => true + 'access' => false + ]); + } else { + // Lexique + include('./module/agenda/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_agenda.php'); + // Soumission du formulaire + if($this->isPost()) { + + // Ajout ou modification d'une catégorie + if( $this->getInput('categorie_name') !== ''){ + $name = $this->getInput('categorie_name'); + $fond = $this->getInput('categorie_couleur_fond'); + $texte = $this->getInput('categorie_couleur_texte'); + $json = file_get_contents(self::DATAMODULE.'categories/categories.json'); + $tabcat = json_decode($json,true); + $unsetkey = ''; + foreach($tabcat as $key=>$value){ + if($value['name'] === $name){ + unset( $value); + $unsetkey = $key; + } + } + $unsetkey === '' ? $indice = count($tabcat) : $indice = $unsetkey; + $tabcat[$indice]['name'] = $name; + $tabcat[$indice]['backgroundcolor'] = $fond; + $tabcat[$indice]['textcolor'] = $texte; + $tabcatjson = json_encode($tabcat); + file_put_contents(self::DATAMODULE.'categories/categories.json', $tabcatjson); + } + + // Validation du choix par catégorie enregistré dans module.json + $valcategories = $this->getInput('val_categories', helper::FILTER_BOOLEAN); + //Mise à jour de la validation du choix des couleurs par catégorie + $this->setData(['module', $this->getUrl(0), 'categories', [ + 'valCategories' => $valcategories + ]]); + + //Valeurs en sortie + $this->addOutput([ + 'notification' => $text['agenda']['categories'][0], + 'redirect' => helper::baseUrl() . $this->getUrl(), + 'state' => true + ]); + } + // Préparation du tableau d'affichage des catégories : nom, couleur du fond, couleur du texte + $json = file_get_contents(self::DATAMODULE.'categories/categories.json'); + $tabcat = json_decode($json,true); + foreach( $tabcat as $key=>$value ){ + self::$tabCategories[] = [ + $value['name'], + $value['backgroundcolor'], + $value['textcolor'], + $value['name'] !== 'Défaut' ? + template::button('categorieDelete' . $key, [ + 'class' => 'buttonRed', + 'href' => helper::baseUrl() . $this->getUrl(0) . '/categorieDelete/' . $key, + 'value' => template::ico('cancel') + ]) + : '', + ]; + } + // Valeurs en sortie hors soumission du formulaire + $this->addOutput([ + 'showBarEditButton' => true, + 'showPageContent' => false, + 'vendor' => [ + 'tinycolorpicker' + ], + 'view' => 'categorie' ]); } - // Préparation du tableau d'affichage des catégories : nom, couleur du fond, couleur du texte - $json = file_get_contents(self::DATAMODULE.'categories/categories.json'); - $tabcat = json_decode($json,true); - foreach( $tabcat as $key=>$value ){ - self::$tabCategories[] = [ - $value['name'], - $value['backgroundcolor'], - $value['textcolor'], - $value['name'] !== 'Défaut' ? - template::button('categorieDelete' . $key, [ - 'class' => 'buttonRed', - 'href' => helper::baseUrl() . $this->getUrl(0) . '/categorieDelete/' . $key, - 'value' => template::ico('cancel') - ]) - : '', - ]; - } - // Valeurs en sortie hors soumission du formulaire - $this->addOutput([ - 'showBarEditButton' => true, - 'showPageContent' => false, - 'vendor' => [ - 'tinycolorpicker' - ], - 'view' => 'categorie' - ]); } /* * Suppression d'une catégorie */ public function categorieDelete(){ - // Lexique - include('./module/agenda/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_agenda.php'); - $json = file_get_contents(self::DATAMODULE.'categories/categories.json'); - $tabcat = json_decode($json,true); - $name = $tabcat[$this->getUrl(2)]['name']; - unset($tabcat[$this->getUrl(2)]); - $ii = 0; - $tab = []; - foreach($tabcat as $key=>$value){ - $tab[$ii] = $value; - $ii++; - } - $tabcatjson = json_encode($tab); - file_put_contents(self::DATAMODULE.'categories/categories.json', $tabcatjson); - //Valeurs en sortie - $this->addOutput([ - 'notification' => $text['agenda']['categorieDelete'][0].$name.$text['agenda']['categorieDelete'][1], - 'redirect' => helper::baseUrl() . $this->getUrl(0).'/categories/', - 'state' => true - ]); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < agenda::$actions['categorieDelete'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./module/agenda/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_agenda.php'); + $json = file_get_contents(self::DATAMODULE.'categories/categories.json'); + $tabcat = json_decode($json,true); + $name = $tabcat[$this->getUrl(2)]['name']; + unset($tabcat[$this->getUrl(2)]); + $ii = 0; + $tab = []; + foreach($tabcat as $key=>$value){ + $tab[$ii] = $value; + $ii++; + } + $tabcatjson = json_encode($tab); + file_put_contents(self::DATAMODULE.'categories/categories.json', $tabcatjson); + //Valeurs en sortie + $this->addOutput([ + 'notification' => $text['agenda']['categorieDelete'][0].$name.$text['agenda']['categorieDelete'][1], + 'redirect' => helper::baseUrl() . $this->getUrl(0).'/categories/', + 'state' => true + ]); + } } /** diff --git a/module/blog/blog.php b/module/blog/blog.php index ea5fa2e..dd1d950 100644 --- a/module/blog/blog.php +++ b/module/blog/blog.php @@ -198,496 +198,112 @@ class blog extends common { * Configuration des textes visibles par l'utiliateur */ public function texts() { - // Lexique - $param = 'blog'; - include('./module/blog/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_blog.php'); - - // Soumission du formulaire - if($this->isPost()) { - $this->setData(['module', $this->getUrl(0), 'texts',[ - 'NoComment' => $this->getInput('blogTextsNoComment',helper::FILTER_STRING_SHORT), - 'Write' => $this->getInput('blogTextsWrite',helper::FILTER_STRING_SHORT), - 'Name' => $this->getInput('blogTextsName',helper::FILTER_STRING_SHORT), - 'Maxi' => $this->getInput('blogTextsMaxi',helper::FILTER_STRING_SHORT), - 'Cara' => $this->getInput('blogTextsCara',helper::FILTER_STRING_SHORT), - 'Comment' => $this->getInput('blogTextsComment',helper::FILTER_STRING_SHORT), - 'CommentOK' => $this->getInput('blogTextsCommentOK',helper::FILTER_STRING_SHORT), - 'Waiting' => $this->getInput('blogTextsWaiting',helper::FILTER_STRING_SHORT), - 'ArticleNoComment' => $this->getInput('blogTextsArticleNoComment',helper::FILTER_STRING_SHORT), - 'Connection' => $this->getInput('blogTextsConnection',helper::FILTER_STRING_SHORT), - 'Edit' => $this->getInput('blogTextsEdit',helper::FILTER_STRING_SHORT), - 'Cancel' => $this->getInput('blogTextsCancel',helper::FILTER_STRING_SHORT), - 'Send' => $this->getInput('blogTextsSend',helper::FILTER_STRING_SHORT), - 'TinymceMaxi' => $this->getInput('blogTextsTinymceMaxi',helper::FILTER_STRING_SHORT), - 'TinymceCara' => $this->getInput('blogTextsTinymceCara',helper::FILTER_STRING_SHORT), - 'TinymceExceed' => $this->getInput('blogTextsTinymceExceed',helper::FILTER_STRING_SHORT), - 'ReadMore' => $this->getInput('blogTextsReadMore',helper::FILTER_STRING_SHORT), - 'Back' => $this->getInput('blogTextsBack',helper::FILTER_STRING_SHORT) - ]]); - + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < blog::$actions['texts'] ) { + // Valeurs en sortie $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['blog']['texts'][1], - 'state' => true + 'access' => false + ]); + } else { + // Lexique + $param = 'blog'; + include('./module/blog/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_blog.php'); + + // Soumission du formulaire + if($this->isPost()) { + $this->setData(['module', $this->getUrl(0), 'texts',[ + 'NoComment' => $this->getInput('blogTextsNoComment',helper::FILTER_STRING_SHORT), + 'Write' => $this->getInput('blogTextsWrite',helper::FILTER_STRING_SHORT), + 'Name' => $this->getInput('blogTextsName',helper::FILTER_STRING_SHORT), + 'Maxi' => $this->getInput('blogTextsMaxi',helper::FILTER_STRING_SHORT), + 'Cara' => $this->getInput('blogTextsCara',helper::FILTER_STRING_SHORT), + 'Comment' => $this->getInput('blogTextsComment',helper::FILTER_STRING_SHORT), + 'CommentOK' => $this->getInput('blogTextsCommentOK',helper::FILTER_STRING_SHORT), + 'Waiting' => $this->getInput('blogTextsWaiting',helper::FILTER_STRING_SHORT), + 'ArticleNoComment' => $this->getInput('blogTextsArticleNoComment',helper::FILTER_STRING_SHORT), + 'Connection' => $this->getInput('blogTextsConnection',helper::FILTER_STRING_SHORT), + 'Edit' => $this->getInput('blogTextsEdit',helper::FILTER_STRING_SHORT), + 'Cancel' => $this->getInput('blogTextsCancel',helper::FILTER_STRING_SHORT), + 'Send' => $this->getInput('blogTextsSend',helper::FILTER_STRING_SHORT), + 'TinymceMaxi' => $this->getInput('blogTextsTinymceMaxi',helper::FILTER_STRING_SHORT), + 'TinymceCara' => $this->getInput('blogTextsTinymceCara',helper::FILTER_STRING_SHORT), + 'TinymceExceed' => $this->getInput('blogTextsTinymceExceed',helper::FILTER_STRING_SHORT), + 'ReadMore' => $this->getInput('blogTextsReadMore',helper::FILTER_STRING_SHORT), + 'Back' => $this->getInput('blogTextsBack',helper::FILTER_STRING_SHORT) + ]]); + + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['blog']['texts'][1], + 'state' => true + ]); + } + + $this->addOutput([ + 'title' => $text['blog']['texts'][2], + 'view' => 'texts', ]); } - - $this->addOutput([ - 'title' => $text['blog']['texts'][2], - 'view' => 'texts', - ]); } /** * Édition */ public function add() { - // Lexique - $param = 'blog'; - include('./module/blog/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_blog.php'); - - // Soumission du formulaire - if($this->isPost()) { - // Modification de l'userId - if($this->getUser('group') === self::GROUP_ADMIN){ - $newuserid = $this->getInput('blogAddUserId', helper::FILTER_STRING_SHORT, true); - } - else{ - $newuserid = $this->getUser('id'); - } - // Incrémente l'id de l'article - $articleId = helper::increment($this->getInput('blogAddTitle', helper::FILTER_ID), $this->getData(['page'])); - $articleId = helper::increment($articleId, (array) $this->getData(['module', $this->getUrl(0)])); - $articleId = helper::increment($articleId, array_keys(self::$actions)); - // Crée l'article - $this->setData(['module', - $this->getUrl(0), - 'posts', - $articleId, [ - 'comment' => $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment']), - 'content' => $this->getInput('blogAddContent', null), - 'picture' => $this->getInput('blogAddPicture', helper::FILTER_STRING_SHORT), - 'hidePicture' => $this->getInput('blogAddHidePicture', helper::FILTER_BOOLEAN), - 'pictureSize' => $this->getInput('blogAddPictureSize', helper::FILTER_STRING_SHORT), - 'picturePosition' => $this->getInput('blogAddPicturePosition', helper::FILTER_STRING_SHORT), - 'publishedOn' => $this->getInput('blogAddPublishedOn', helper::FILTER_DATETIME, true), - 'state' => $this->getInput('blogAddState', helper::FILTER_BOOLEAN), - 'title' => $this->getInput('blogAddTitle', helper::FILTER_STRING_SHORT, true), - 'userId' => $newuserid, - 'editConsent' => $this->getInput('blogAddConsent') === self::EDIT_GROUP ? $this->getUser('group') : $this->getInput('blogAddConsent'), - 'commentMaxlength' => $this->getInput('blogAddCommentMaxlength'), - 'commentApproved' => $this->getInput('blogAddCommentApproved', helper::FILTER_BOOLEAN), - 'commentClose' => $this->getInput('blogAddCommentClose', helper::FILTER_BOOLEAN), - 'commentNotification' => $this->getInput('blogAddCommentNotification', helper::FILTER_BOOLEAN), - 'commentGroupNotification' => $this->getInput('blogAddCommentGroupNotification', helper::FILTER_INT), - ] - ]); - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['blog']['add'][0], - 'state' => true - ]); - } - // Liste des utilisateurs - self::$users = helper::arrayCollumn($this->getData(['user']), 'firstname'); - ksort(self::$users); - foreach(self::$users as $userId => &$userFirstname) { - $userFirstname = $userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']); - } - unset($userFirstname); - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['blog']['add'][1], - 'vendor' => [ - 'flatpickr', - 'tinymce' - ], - 'view' => 'add' - ]); - } - - /** - * Liste des commentaires - */ - public function comment() { - // Lexique - $param = 'blog'; - include('./module/blog/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_blog.php'); - - $comments = $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2),'comment']); - self::$commentsDelete = template::button('blogCommentDeleteAll', [ - 'class' => 'blogCommentDeleteAll buttonRed', - 'href' => helper::baseUrl() . $this->getUrl(0) . '/commentDeleteAll/' . $this->getUrl(2).'/' . $_SESSION['csrf'] , - 'ico' => 'cancel', - 'value' => $text['blog']['comment'][0], - 'disabled' => $this->getUser('group') >= self::GROUP_MODERATOR ? false : true - ]); - // Dates suivant la langue d'administration - setlocale(LC_TIME, 'fr_FR'); - if( $this->getData(['config', 'i18n', 'langAdmin']) === 'en') setlocale(LC_TIME, 'en_GB'); - // Ids des commentaires par ordre de création - $commentIds = array_keys(helper::arrayCollumn($comments, 'createdOn', 'SORT_DESC')); - // Pagination - $pagination = helper::pagination($commentIds, $this->getUrl(),$this->getData(['module', $this->getUrl(0), 'config', 'itemsperPage']) ); - // Liste des pages - self::$pages = $pagination['pages']; - // Commentaires en fonction de la pagination - for($i = $pagination['first']; $i < $pagination['last']; $i++) { - // Met en forme le tableau - $comment = $comments[$commentIds[$i]]; - // Bouton d'approbation - $buttonApproval = ''; - // Compatibilité avec les commentaires des versions précédentes, les valider - $comment['approval'] = array_key_exists('approval', $comment) === false ? true : $comment['approval'] ; - if ( $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2),'commentApproved']) === true) { - $buttonApproval = template::button('blogCommentApproved' . $commentIds[$i], [ - 'class' => $comment['approval'] === true ? 'blogCommentRejected buttonGreen' : 'blogCommentApproved buttonRed' , - 'href' => helper::baseUrl() . $this->getUrl(0) . '/commentApprove/' . $this->getUrl(2) . '/' . $commentIds[$i] . '/' . $_SESSION['csrf'] , - 'value' => $comment['approval'] === true ? 'A' : 'R', - 'disabled' => $this->getUser('group') >= self::GROUP_MODERATOR ? false : true - ]); - } - self::$comments[] = [ - mb_detect_encoding(date('d\/m\/Y\ \-\ H\:i', $comment['createdOn']), 'UTF-8', true) - ? date('d\/m\/Y\ \-\ H\:i', $comment['createdOn']) - : utf8_encode(date('d\/m\/Y\ \-\ H\:i', $comment['createdOn'])), - $comment['content'], - $comment['userId'] ? $this->getData(['user', $comment['userId'], 'firstname']) . ' ' . $this->getData(['user', $comment['userId'], 'lastname']) : $comment['author'], - $buttonApproval, - template::button('blogCommentDelete' . $commentIds[$i], [ - 'class' => 'blogCommentDelete buttonRed', - 'href' => helper::baseUrl() . $this->getUrl(0) . '/commentDelete/' . $this->getUrl(2) . '/' . $commentIds[$i] . '/' . $_SESSION['csrf'] , - 'value' => template::ico('cancel'), - 'disabled' => $this->getUser('group') >= self::GROUP_MODERATOR ? false : true - ]) - ]; - } - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['blog']['comment'][1]. $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'title']), - 'view' => 'comment' - ]); - } - - /** - * Suppression de commentaire - */ - public function commentDelete() { - // Lexique - $param = 'blog'; - include('./module/blog/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_blog.php'); - - // Le commentaire n'existe pas - if($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3)]) === null) { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < blog::$actions['add'] ) { // Valeurs en sortie $this->addOutput([ 'access' => false - ]); - } - // Jeton incorrect - elseif ($this->getUrl(4) !== $_SESSION['csrf']) { - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['blog']['commentDelete'][0] - ]); - } - // Suppression - else { - $this->deleteData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3)]); - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/comment/'.$this->getUrl(2), - 'notification' => $text['blog']['commentDelete'][1], - 'state' => true - ]); - } - } - - /** - * Suppression de tous les commentaires de l'article $this->getUrl(2) - */ - public function commentDeleteAll() { - // Lexique - $param = 'blog'; - include('./module/blog/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_blog.php'); - - // Jeton incorrect - if ($this->getUrl(3) !== $_SESSION['csrf']) { - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['blog']['commentDeleteAll'][0] - ]); - } - // Suppression - else { - $this->setData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment',[] ]); - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/comment', - 'notification' => $text['blog']['commentDeleteAll'][1], - 'state' => true - ]); - } - } - - /** - * Approbation oou désapprobation de commentaire - */ - public function commentApprove() { - // Lexique - $param = 'blog'; - include('./module/blog/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_blog.php'); - - // Le commentaire n'existe pas - if($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3)]) === null) { - // Valeurs en sortie - $this->addOutput([ - 'access' => false - ]); - } - // Jeton incorrect - elseif ($this->getUrl(4) !== $_SESSION['csrf']) { - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['blog']['commentApprove'][0] - ]); - } - // Inversion du statut - else { - $approved = !$this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3), 'approval']) ; - $this->setData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3), [ - 'author' => $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3), 'author']), - 'content' => $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3), 'content']), - 'createdOn' => $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3), 'createdOn']), - 'userId' => $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3), 'userId']), - 'approval' => $approved - ]]); - - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/comment/'.$this->getUrl(2), - 'notification' => $approved ? $text['blog']['commentApprove'][1] : $text['blog']['commentApprove'][2], - 'state' => $approved - ]); - } - } - - /** - * Configuration - */ - public function config() { - // Lexique - $param = 'blog'; - include('./module/blog/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_blog.php'); - - // Mise à jour des données de module - if( null === $this->getData(['module', $this->getUrl(0), 'config', 'versionData']) )$this->update(); - // Soumission du formulaire - if($this->isPost()) { - $this->setData(['module', $this->getUrl(0), 'config',[ - 'feeds' => $this->getInput('blogConfigShowFeeds',helper::FILTER_BOOLEAN), - 'feedsLabel' => $this->getInput('blogConfigFeedslabel',helper::FILTER_STRING_SHORT), - 'itemsperPage' => $this->getInput('blogConfigItemsperPage', helper::FILTER_INT,true), - 'versionData' => $this->getData(['module', $this->getUrl(0), 'config', 'versionData']) - ]]); - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['blog']['config'][0], - 'state' => true - ]); + ]); } else { - // Dates suivant la langue d'administration - setlocale(LC_TIME, 'fr_FR'); - if( $this->getData(['config', 'i18n', 'langAdmin']) === 'en') setlocale(LC_TIME, 'en_GB'); - // Ids des articles par ordre de publication - $articleIds = array_keys(helper::arrayCollumn($this->getData(['module', $this->getUrl(0), 'posts']), 'publishedOn', 'SORT_DESC')); - // Gestion des droits d'accès - $filterData=[]; - foreach ($articleIds as $key => $value) { - if ( - ( // Propriétaire - $this->getData(['module', $this->getUrl(0), 'posts', $value,'editConsent']) === self::EDIT_OWNER - AND ( $this->getData(['module', $this->getUrl(0), 'posts', $value,'userId']) === $this->getUser('id') - OR $this->getUser('group') === self::GROUP_ADMIN ) - ) + // Lexique + $param = 'blog'; + include('./module/blog/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_blog.php'); - OR ( - // Groupe - $this->getData(['module', $this->getUrl(0), 'posts', $value,'editConsent']) !== self::EDIT_OWNER - AND $this->getUser('group') >= $this->getData(['module',$this->getUrl(0), 'posts', $value,'editConsent']) - ) - OR ( - // Tout le monde - $this->getData(['module', $this->getUrl(0), 'posts', $value,'editConsent']) === self::EDIT_ALL - ) - ) { - $filterData[] = $value; - } - } - $articleIds = $filterData; - // Pagination - $pagination = helper::pagination($articleIds, $this->getUrl(),$this->getData(['module', $this->getUrl(0),'config', 'itemsperPage'])); - // Liste des pages - self::$pages = $pagination['pages']; - // Articles en fonction de la pagination - for($i = $pagination['first']; $i < $pagination['last']; $i++) { - // Nombre de commentaires à approuver et approuvés - $approvals = helper::arrayCollumn($this->getData(['module', $this->getUrl(0), 'posts', $articleIds[$i], 'comment' ]),'approval', 'SORT_DESC'); - if ( is_array($approvals) ) { - $a = array_values($approvals); - $toApprove = count(array_keys($a,false)); - $approved = count(array_keys($a,true)); - } else { - $toApprove = 0; - $approved = count($this->getData(['module', $this->getUrl(0), 'posts', $articleIds[$i],'comment'])); - } - // Met en forme le tableau - $date = mb_detect_encoding(date('d\/m\/Y', $this->getData(['module', $this->getUrl(0), 'posts', $articleIds[$i], 'publishedOn'])), 'UTF-8', true) - ? date('d\/m\/Y', $this->getData(['module', $this->getUrl(0), 'posts', $articleIds[$i], 'publishedOn'])) - : utf8_encode(date('d\/m\/Y', $this->getData(['module', $this->getUrl(0), 'posts', $articleIds[$i], 'publishedOn']))); - $heure = mb_detect_encoding(date('H\:i', $this->getData(['module', $this->getUrl(0), 'posts', $articleIds[$i], 'publishedOn'])), 'UTF-8', true) - ? date('H\:i', $this->getData(['module', $this->getUrl(0), 'posts', $articleIds[$i], 'publishedOn'])) - : utf8_encode(date('H\:i', $this->getData(['module', $this->getUrl(0), 'posts', $articleIds[$i], 'publishedOn']))); - self::$articles[] = [ - '' . - $this->getData(['module', $this->getUrl(0), 'posts', $articleIds[$i], 'title']) . - '', - $date .$text['blog']['config'][2]. $heure, - $states[$this->getData(['module', $this->getUrl(0), 'posts', $articleIds[$i], 'state'])], - // Bouton pour afficher les commentaires de l'article - template::button('blogConfigComment' . $articleIds[$i], [ - 'class' => ($toApprove || $approved ) > 0 ? '' : 'buttonGrey' , - 'href' => ($toApprove || $approved ) > 0 ? helper::baseUrl() . $this->getUrl(0) . '/comment/' . $articleIds[$i] : '', - 'value' => $toApprove > 0 ? $toApprove . '/' . $approved : $approved - ]), - template::button('blogConfigEdit' . $articleIds[$i], [ - 'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $articleIds[$i] . '/' . $_SESSION['csrf'], - 'value' => template::ico('pencil') - ]), - template::button('blogConfigDelete' . $articleIds[$i], [ - 'class' => 'blogConfigDelete buttonRed', - 'href' => helper::baseUrl() . $this->getUrl(0) . '/delete/' . $articleIds[$i] . '/' . $_SESSION['csrf'], - 'value' => template::ico('cancel'), - 'disabled' => $this->getUser('group') >= self::GROUP_MODERATOR ? false : true - ]) - ]; - } - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['blog']['config'][1], - 'view' => 'config' - ]); - } - } - - /** - * Suppression - */ - public function delete() { - // Lexique - $param = 'blog'; - include('./module/blog/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_blog.php'); - - if($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2)]) === null) { - // Valeurs en sortie - $this->addOutput([ - 'access' => false - ]); - } - // Jeton incorrect - elseif ($this->getUrl(3) !== $_SESSION['csrf']) { - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['blog']['delete'][0] - ]); - } - // Suppression - else { - $this->deleteData(['module', $this->getUrl(0), 'posts', $this->getUrl(2)]); - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['blog']['delete'][1], - 'state' => true - ]); - } - } - - /** - * Édition - */ - public function edit() { - // Lexique - $param = 'blog'; - include('./module/blog/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_blog.php'); - - // Jeton incorrect - if ($this->getUrl(3) !== $_SESSION['csrf']) { - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['blog']['edit'][0] - ]); - } - // L'article n'existe pas - if($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2)]) === null) { - // Valeurs en sortie - $this->addOutput([ - 'access' => false - ]); - } - // L'article existe - else { // Soumission du formulaire if($this->isPost()) { + // Modification de l'userId if($this->getUser('group') === self::GROUP_ADMIN){ - $newuserid = $this->getInput('blogEditUserId', helper::FILTER_STRING_SHORT, true); + $newuserid = $this->getInput('blogAddUserId', helper::FILTER_STRING_SHORT, true); } else{ $newuserid = $this->getUser('id'); } - $articleId = $this->getInput('blogEditTitle', helper::FILTER_ID, true); - // Incrémente le nouvel id de l'article - if($articleId !== $this->getUrl(2)) { - $articleId = helper::increment($articleId, $this->getData(['page'])); - $articleId = helper::increment($articleId, $this->getData(['module', $this->getUrl(0),'posts'])); - $articleId = helper::increment($articleId, array_keys(self::$actions)); - } + // Incrémente l'id de l'article + $articleId = helper::increment($this->getInput('blogAddTitle', helper::FILTER_ID), $this->getData(['page'])); + $articleId = helper::increment($articleId, (array) $this->getData(['module', $this->getUrl(0)])); + $articleId = helper::increment($articleId, array_keys(self::$actions)); + // Crée l'article $this->setData(['module', $this->getUrl(0), 'posts', $articleId, [ 'comment' => $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment']), - 'content' => $this->getInput('blogEditContent', null), - 'picture' => $this->getInput('blogEditPicture', helper::FILTER_STRING_SHORT), - 'hidePicture' => $this->getInput('blogEditHidePicture', helper::FILTER_BOOLEAN), - 'pictureSize' => $this->getInput('blogEditPictureSize', helper::FILTER_STRING_SHORT), - 'picturePosition' => $this->getInput('blogEditPicturePosition', helper::FILTER_STRING_SHORT), - 'publishedOn' => $this->getInput('blogEditPublishedOn', helper::FILTER_DATETIME, true), - 'state' => $this->getInput('blogEditState', helper::FILTER_BOOLEAN), - 'title' => $this->getInput('blogEditTitle', helper::FILTER_STRING_SHORT, true), + 'content' => $this->getInput('blogAddContent', null), + 'picture' => $this->getInput('blogAddPicture', helper::FILTER_STRING_SHORT), + 'hidePicture' => $this->getInput('blogAddHidePicture', helper::FILTER_BOOLEAN), + 'pictureSize' => $this->getInput('blogAddPictureSize', helper::FILTER_STRING_SHORT), + 'picturePosition' => $this->getInput('blogAddPicturePosition', helper::FILTER_STRING_SHORT), + 'publishedOn' => $this->getInput('blogAddPublishedOn', helper::FILTER_DATETIME, true), + 'state' => $this->getInput('blogAddState', helper::FILTER_BOOLEAN), + 'title' => $this->getInput('blogAddTitle', helper::FILTER_STRING_SHORT, true), 'userId' => $newuserid, - 'editConsent' => $this->getInput('blogEditConsent') === self::EDIT_GROUP ? $this->getUser('group') : $this->getInput('blogEditConsent'), - 'commentMaxlength' => $this->getInput('blogEditCommentMaxlength'), - 'commentApproved' => $this->getInput('blogEditCommentApproved', helper::FILTER_BOOLEAN), - 'commentClose' => $this->getInput('blogEditCommentClose', helper::FILTER_BOOLEAN), - 'commentNotification' => $this->getInput('blogEditCommentNotification', helper::FILTER_BOOLEAN), - 'commentGroupNotification' => $this->getInput('blogEditCommentGroupNotification', helper::FILTER_INT) + 'editConsent' => $this->getInput('blogAddConsent') === self::EDIT_GROUP ? $this->getUser('group') : $this->getInput('blogAddConsent'), + 'commentMaxlength' => $this->getInput('blogAddCommentMaxlength'), + 'commentApproved' => $this->getInput('blogAddCommentApproved', helper::FILTER_BOOLEAN), + 'commentClose' => $this->getInput('blogAddCommentClose', helper::FILTER_BOOLEAN), + 'commentNotification' => $this->getInput('blogAddCommentNotification', helper::FILTER_BOOLEAN), + 'commentGroupNotification' => $this->getInput('blogAddCommentGroupNotification', helper::FILTER_INT), ] ]); - // Supprime l'ancien article - if($articleId !== $this->getUrl(2)) { - $this->deleteData(['module', $this->getUrl(0), 'posts', $this->getUrl(2)]); - } // Valeurs en sortie $this->addOutput([ 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['blog']['edit'][1], + 'notification' => $text['blog']['add'][0], 'state' => true ]); } @@ -695,25 +311,499 @@ class blog extends common { self::$users = helper::arrayCollumn($this->getData(['user']), 'firstname'); ksort(self::$users); foreach(self::$users as $userId => &$userFirstname) { - // Les membres ne sont pas éditeurs, les exclure de la liste - if ( $this->getData(['user', $userId, 'group']) < self::GROUP_MODERATOR) { - unset(self::$users[$userId]); - } - $userFirstname = $userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']) . ' (' . $groupEdits[$this->getData(['user', $userId, 'group'])] . ')'; + $userFirstname = $userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']); } unset($userFirstname); // Valeurs en sortie $this->addOutput([ - 'title' => $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'title']), + 'title' => $text['blog']['add'][1], 'vendor' => [ 'flatpickr', 'tinymce' ], - 'view' => 'edit' + 'view' => 'add' ]); } } + /** + * Liste des commentaires + */ + public function comment() { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < blog::$actions['comment'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + $param = 'blog'; + include('./module/blog/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_blog.php'); + + $comments = $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2),'comment']); + self::$commentsDelete = template::button('blogCommentDeleteAll', [ + 'class' => 'blogCommentDeleteAll buttonRed', + 'href' => helper::baseUrl() . $this->getUrl(0) . '/commentDeleteAll/' . $this->getUrl(2).'/' . $_SESSION['csrf'] , + 'ico' => 'cancel', + 'value' => $text['blog']['comment'][0], + 'disabled' => $this->getUser('group') >= self::GROUP_MODERATOR ? false : true + ]); + // Dates suivant la langue d'administration + setlocale(LC_TIME, 'fr_FR'); + if( $this->getData(['config', 'i18n', 'langAdmin']) === 'en') setlocale(LC_TIME, 'en_GB'); + // Ids des commentaires par ordre de création + $commentIds = array_keys(helper::arrayCollumn($comments, 'createdOn', 'SORT_DESC')); + // Pagination + $pagination = helper::pagination($commentIds, $this->getUrl(),$this->getData(['module', $this->getUrl(0), 'config', 'itemsperPage']) ); + // Liste des pages + self::$pages = $pagination['pages']; + // Commentaires en fonction de la pagination + for($i = $pagination['first']; $i < $pagination['last']; $i++) { + // Met en forme le tableau + $comment = $comments[$commentIds[$i]]; + // Bouton d'approbation + $buttonApproval = ''; + // Compatibilité avec les commentaires des versions précédentes, les valider + $comment['approval'] = array_key_exists('approval', $comment) === false ? true : $comment['approval'] ; + if ( $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2),'commentApproved']) === true) { + $buttonApproval = template::button('blogCommentApproved' . $commentIds[$i], [ + 'class' => $comment['approval'] === true ? 'blogCommentRejected buttonGreen' : 'blogCommentApproved buttonRed' , + 'href' => helper::baseUrl() . $this->getUrl(0) . '/commentApprove/' . $this->getUrl(2) . '/' . $commentIds[$i] . '/' . $_SESSION['csrf'] , + 'value' => $comment['approval'] === true ? 'A' : 'R', + 'disabled' => $this->getUser('group') >= self::GROUP_MODERATOR ? false : true + ]); + } + self::$comments[] = [ + mb_detect_encoding(date('d\/m\/Y\ \-\ H\:i', $comment['createdOn']), 'UTF-8', true) + ? date('d\/m\/Y\ \-\ H\:i', $comment['createdOn']) + : utf8_encode(date('d\/m\/Y\ \-\ H\:i', $comment['createdOn'])), + $comment['content'], + $comment['userId'] ? $this->getData(['user', $comment['userId'], 'firstname']) . ' ' . $this->getData(['user', $comment['userId'], 'lastname']) : $comment['author'], + $buttonApproval, + template::button('blogCommentDelete' . $commentIds[$i], [ + 'class' => 'blogCommentDelete buttonRed', + 'href' => helper::baseUrl() . $this->getUrl(0) . '/commentDelete/' . $this->getUrl(2) . '/' . $commentIds[$i] . '/' . $_SESSION['csrf'] , + 'value' => template::ico('cancel'), + 'disabled' => $this->getUser('group') >= self::GROUP_MODERATOR ? false : true + ]) + ]; + } + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['blog']['comment'][1]. $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'title']), + 'view' => 'comment' + ]); + } + } + + /** + * Suppression de commentaire + */ + public function commentDelete() { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < blog::$actions['commentDelete'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + $param = 'blog'; + include('./module/blog/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_blog.php'); + + // Le commentaire n'existe pas + if($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3)]) === null) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } + // Jeton incorrect + elseif ($this->getUrl(4) !== $_SESSION['csrf']) { + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['blog']['commentDelete'][0] + ]); + } + // Suppression + else { + $this->deleteData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3)]); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/comment/'.$this->getUrl(2), + 'notification' => $text['blog']['commentDelete'][1], + 'state' => true + ]); + } + } + } + + /** + * Suppression de tous les commentaires de l'article $this->getUrl(2) + */ + public function commentDeleteAll() { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < blog::$actions['commentDeleteAll'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + $param = 'blog'; + include('./module/blog/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_blog.php'); + + // Jeton incorrect + if ($this->getUrl(3) !== $_SESSION['csrf']) { + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['blog']['commentDeleteAll'][0] + ]); + } + // Suppression + else { + $this->setData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment',[] ]); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/comment', + 'notification' => $text['blog']['commentDeleteAll'][1], + 'state' => true + ]); + } + } + } + + /** + * Approbation oou désapprobation de commentaire + */ + public function commentApprove() { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < blog::$actions['commentApprove'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + $param = 'blog'; + include('./module/blog/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_blog.php'); + + // Le commentaire n'existe pas + if($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3)]) === null) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } + // Jeton incorrect + elseif ($this->getUrl(4) !== $_SESSION['csrf']) { + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['blog']['commentApprove'][0] + ]); + } + // Inversion du statut + else { + $approved = !$this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3), 'approval']) ; + $this->setData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3), [ + 'author' => $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3), 'author']), + 'content' => $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3), 'content']), + 'createdOn' => $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3), 'createdOn']), + 'userId' => $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment', $this->getUrl(3), 'userId']), + 'approval' => $approved + ]]); + + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/comment/'.$this->getUrl(2), + 'notification' => $approved ? $text['blog']['commentApprove'][1] : $text['blog']['commentApprove'][2], + 'state' => $approved + ]); + } + } + } + + /** + * Configuration + */ + public function config() { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < blog::$actions['config'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + $param = 'blog'; + include('./module/blog/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_blog.php'); + + // Mise à jour des données de module + if( null === $this->getData(['module', $this->getUrl(0), 'config', 'versionData']) )$this->update(); + // Soumission du formulaire + if($this->isPost()) { + $this->setData(['module', $this->getUrl(0), 'config',[ + 'feeds' => $this->getInput('blogConfigShowFeeds',helper::FILTER_BOOLEAN), + 'feedsLabel' => $this->getInput('blogConfigFeedslabel',helper::FILTER_STRING_SHORT), + 'itemsperPage' => $this->getInput('blogConfigItemsperPage', helper::FILTER_INT,true), + 'versionData' => $this->getData(['module', $this->getUrl(0), 'config', 'versionData']) + ]]); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['blog']['config'][0], + 'state' => true + ]); + } else { + // Dates suivant la langue d'administration + setlocale(LC_TIME, 'fr_FR'); + if( $this->getData(['config', 'i18n', 'langAdmin']) === 'en') setlocale(LC_TIME, 'en_GB'); + // Ids des articles par ordre de publication + $articleIds = array_keys(helper::arrayCollumn($this->getData(['module', $this->getUrl(0), 'posts']), 'publishedOn', 'SORT_DESC')); + // Gestion des droits d'accès + $filterData=[]; + foreach ($articleIds as $key => $value) { + if ( + ( // Propriétaire + $this->getData(['module', $this->getUrl(0), 'posts', $value,'editConsent']) === self::EDIT_OWNER + AND ( $this->getData(['module', $this->getUrl(0), 'posts', $value,'userId']) === $this->getUser('id') + OR $this->getUser('group') === self::GROUP_ADMIN ) + ) + + OR ( + // Groupe + $this->getData(['module', $this->getUrl(0), 'posts', $value,'editConsent']) !== self::EDIT_OWNER + AND $this->getUser('group') >= $this->getData(['module',$this->getUrl(0), 'posts', $value,'editConsent']) + ) + OR ( + // Tout le monde + $this->getData(['module', $this->getUrl(0), 'posts', $value,'editConsent']) === self::EDIT_ALL + ) + ) { + $filterData[] = $value; + } + } + $articleIds = $filterData; + // Pagination + $pagination = helper::pagination($articleIds, $this->getUrl(),$this->getData(['module', $this->getUrl(0),'config', 'itemsperPage'])); + // Liste des pages + self::$pages = $pagination['pages']; + // Articles en fonction de la pagination + for($i = $pagination['first']; $i < $pagination['last']; $i++) { + // Nombre de commentaires à approuver et approuvés + $approvals = helper::arrayCollumn($this->getData(['module', $this->getUrl(0), 'posts', $articleIds[$i], 'comment' ]),'approval', 'SORT_DESC'); + if ( is_array($approvals) ) { + $a = array_values($approvals); + $toApprove = count(array_keys($a,false)); + $approved = count(array_keys($a,true)); + } else { + $toApprove = 0; + $approved = count($this->getData(['module', $this->getUrl(0), 'posts', $articleIds[$i],'comment'])); + } + // Met en forme le tableau + $date = mb_detect_encoding(date('d\/m\/Y', $this->getData(['module', $this->getUrl(0), 'posts', $articleIds[$i], 'publishedOn'])), 'UTF-8', true) + ? date('d\/m\/Y', $this->getData(['module', $this->getUrl(0), 'posts', $articleIds[$i], 'publishedOn'])) + : utf8_encode(date('d\/m\/Y', $this->getData(['module', $this->getUrl(0), 'posts', $articleIds[$i], 'publishedOn']))); + $heure = mb_detect_encoding(date('H\:i', $this->getData(['module', $this->getUrl(0), 'posts', $articleIds[$i], 'publishedOn'])), 'UTF-8', true) + ? date('H\:i', $this->getData(['module', $this->getUrl(0), 'posts', $articleIds[$i], 'publishedOn'])) + : utf8_encode(date('H\:i', $this->getData(['module', $this->getUrl(0), 'posts', $articleIds[$i], 'publishedOn']))); + self::$articles[] = [ + '' . + $this->getData(['module', $this->getUrl(0), 'posts', $articleIds[$i], 'title']) . + '', + $date .$text['blog']['config'][2]. $heure, + $states[$this->getData(['module', $this->getUrl(0), 'posts', $articleIds[$i], 'state'])], + // Bouton pour afficher les commentaires de l'article + template::button('blogConfigComment' . $articleIds[$i], [ + 'class' => ($toApprove || $approved ) > 0 ? '' : 'buttonGrey' , + 'href' => ($toApprove || $approved ) > 0 ? helper::baseUrl() . $this->getUrl(0) . '/comment/' . $articleIds[$i] : '', + 'value' => $toApprove > 0 ? $toApprove . '/' . $approved : $approved + ]), + template::button('blogConfigEdit' . $articleIds[$i], [ + 'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $articleIds[$i] . '/' . $_SESSION['csrf'], + 'value' => template::ico('pencil') + ]), + template::button('blogConfigDelete' . $articleIds[$i], [ + 'class' => 'blogConfigDelete buttonRed', + 'href' => helper::baseUrl() . $this->getUrl(0) . '/delete/' . $articleIds[$i] . '/' . $_SESSION['csrf'], + 'value' => template::ico('cancel'), + 'disabled' => $this->getUser('group') >= self::GROUP_MODERATOR ? false : true + ]) + ]; + } + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['blog']['config'][1], + 'view' => 'config' + ]); + } + } + } + + /** + * Suppression + */ + public function delete() { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < blog::$actions['delete'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + $param = 'blog'; + include('./module/blog/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_blog.php'); + + if($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2)]) === null) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } + // Jeton incorrect + elseif ($this->getUrl(3) !== $_SESSION['csrf']) { + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['blog']['delete'][0] + ]); + } + // Suppression + else { + $this->deleteData(['module', $this->getUrl(0), 'posts', $this->getUrl(2)]); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['blog']['delete'][1], + 'state' => true + ]); + } + } + } + + /** + * Édition + */ + public function edit() { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < blog::$actions['edit'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + $param = 'blog'; + include('./module/blog/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_blog.php'); + + // Jeton incorrect + if ($this->getUrl(3) !== $_SESSION['csrf']) { + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['blog']['edit'][0] + ]); + } + // L'article n'existe pas + if($this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2)]) === null) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } + // L'article existe + else { + // Soumission du formulaire + if($this->isPost()) { + if($this->getUser('group') === self::GROUP_ADMIN){ + $newuserid = $this->getInput('blogEditUserId', helper::FILTER_STRING_SHORT, true); + } + else{ + $newuserid = $this->getUser('id'); + } + $articleId = $this->getInput('blogEditTitle', helper::FILTER_ID, true); + // Incrémente le nouvel id de l'article + if($articleId !== $this->getUrl(2)) { + $articleId = helper::increment($articleId, $this->getData(['page'])); + $articleId = helper::increment($articleId, $this->getData(['module', $this->getUrl(0),'posts'])); + $articleId = helper::increment($articleId, array_keys(self::$actions)); + } + $this->setData(['module', + $this->getUrl(0), + 'posts', + $articleId, [ + 'comment' => $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'comment']), + 'content' => $this->getInput('blogEditContent', null), + 'picture' => $this->getInput('blogEditPicture', helper::FILTER_STRING_SHORT), + 'hidePicture' => $this->getInput('blogEditHidePicture', helper::FILTER_BOOLEAN), + 'pictureSize' => $this->getInput('blogEditPictureSize', helper::FILTER_STRING_SHORT), + 'picturePosition' => $this->getInput('blogEditPicturePosition', helper::FILTER_STRING_SHORT), + 'publishedOn' => $this->getInput('blogEditPublishedOn', helper::FILTER_DATETIME, true), + 'state' => $this->getInput('blogEditState', helper::FILTER_BOOLEAN), + 'title' => $this->getInput('blogEditTitle', helper::FILTER_STRING_SHORT, true), + 'userId' => $newuserid, + 'editConsent' => $this->getInput('blogEditConsent') === self::EDIT_GROUP ? $this->getUser('group') : $this->getInput('blogEditConsent'), + 'commentMaxlength' => $this->getInput('blogEditCommentMaxlength'), + 'commentApproved' => $this->getInput('blogEditCommentApproved', helper::FILTER_BOOLEAN), + 'commentClose' => $this->getInput('blogEditCommentClose', helper::FILTER_BOOLEAN), + 'commentNotification' => $this->getInput('blogEditCommentNotification', helper::FILTER_BOOLEAN), + 'commentGroupNotification' => $this->getInput('blogEditCommentGroupNotification', helper::FILTER_INT) + ] + ]); + // Supprime l'ancien article + if($articleId !== $this->getUrl(2)) { + $this->deleteData(['module', $this->getUrl(0), 'posts', $this->getUrl(2)]); + } + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['blog']['edit'][1], + 'state' => true + ]); + } + // Liste des utilisateurs + self::$users = helper::arrayCollumn($this->getData(['user']), 'firstname'); + ksort(self::$users); + foreach(self::$users as $userId => &$userFirstname) { + // Les membres ne sont pas éditeurs, les exclure de la liste + if ( $this->getData(['user', $userId, 'group']) < self::GROUP_MODERATOR) { + unset(self::$users[$userId]); + } + $userFirstname = $userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']) . ' (' . $groupEdits[$this->getData(['user', $userId, 'group'])] . ')'; + } + unset($userFirstname); + // Valeurs en sortie + $this->addOutput([ + 'title' => $this->getData(['module', $this->getUrl(0), 'posts', $this->getUrl(2), 'title']), + 'vendor' => [ + 'flatpickr', + 'tinymce' + ], + 'view' => 'edit' + ]); + } + } + } + /** * Accueil (deux affichages en un pour éviter une url à rallonge) */ diff --git a/module/form/form.php b/module/form/form.php index 1663a60..5a1f2ed 100644 --- a/module/form/form.php +++ b/module/form/form.php @@ -31,8 +31,7 @@ class form extends common { 'delete' => self::GROUP_MODERATOR, 'deleteall' => self::GROUP_MODERATOR, 'index' => self::GROUP_VISITOR, - 'export2csv' => self::GROUP_MODERATOR, - 'output2csv' => self::GROUP_MODERATOR + 'export2csv' => self::GROUP_MODERATOR ]; public static $data = []; @@ -95,162 +94,192 @@ class form extends common { * Configuration */ public function config() { - // Lexique - $param = ''; - include('./module/form/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_form.php'); - // Liste des utilisateurs - $userIdsFirstnames = helper::arrayCollumn($this->getData(['user']), 'firstname'); - ksort($userIdsFirstnames); - self::$listUsers [] = ''; - foreach($userIdsFirstnames as $userId => $userFirstname) { - self::$listUsers [] = $userId; - } - // Soumission du formulaire - if($this->isPost()) { - // Configuration - $this->setData([ - 'module', - $this->getUrl(0), - 'config', - [ - 'button' => $this->getInput('formConfigButton'), - 'captcha' => $this->getInput('formConfigCaptcha', helper::FILTER_BOOLEAN), - 'group' => $this->getInput('formConfigGroup', helper::FILTER_INT), - 'user' => self::$listUsers [$this->getInput('formConfigUser', helper::FILTER_INT)], - 'mail' => $this->getInput('formConfigMail') , - 'pageId' => $this->getInput('formConfigPageIdToggle', helper::FILTER_BOOLEAN) === true ? $this->getInput('formConfigPageId', helper::FILTER_ID) : '', - 'subject' => $this->getInput('formConfigSubject'), - 'replyto' => $this->getInput('formConfigMailReplyTo', helper::FILTER_BOOLEAN), - 'signature' => $this->getInput('formConfigSignature'), - 'logoUrl' => $this->getInput('formConfigLogo'), - 'logoWidth' => $this->getInput('formConfigLogoWidth'), - 'maxSizeUpload' => $this->getInput('formConfigMaxSize'), - 'versionData' => self::VERSION, - 'uploadJpg' => $this->getInput('formConfigUploadJpg', helper::FILTER_BOOLEAN), - 'uploadPng' => $this->getInput('formConfigUploadPng', helper::FILTER_BOOLEAN), - 'uploadPdf' => $this->getInput('formConfigUploadPdf', helper::FILTER_BOOLEAN), - 'uploadZip' => $this->getInput('formConfigUploadZip', helper::FILTER_BOOLEAN), - 'uploadTxt' => $this->getInput('formConfigUploadTxt', helper::FILTER_BOOLEAN) - ] - ]); - // Génération des données vides - if ($this->getData(['module', $this->getUrl(0), 'data']) === null) { - $this->setData(['module', $this->getUrl(0), 'data', []]); - } - // Génération des champs - $inputs = []; - foreach($this->getInput('formConfigPosition', null) as $index => $position) { - $inputs[] = [ - 'name' => htmlspecialchars_decode($this->getInput('formConfigName[' . $index . ']'),ENT_QUOTES), - 'position' => helper::filter($position, helper::FILTER_INT), - 'required' => $this->getInput('formConfigRequired[' . $index . ']', helper::FILTER_BOOLEAN), - 'type' => $this->getInput('formConfigType[' . $index . ']'), - 'values' => $this->getInput('formConfigValues[' . $index . ']') - ]; - } - $this->setData(['module', $this->getUrl(0), 'input', $inputs]); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < form::$actions['config'] ) { // Valeurs en sortie $this->addOutput([ - 'notification' => $text['form']['config'][0], - 'redirect' => helper::baseUrl() . $this->getUrl(), - 'state' => true + 'access' => false + ]); + } else { + // Lexique + $param = ''; + include('./module/form/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_form.php'); + // Liste des utilisateurs + $userIdsFirstnames = helper::arrayCollumn($this->getData(['user']), 'firstname'); + ksort($userIdsFirstnames); + self::$listUsers [] = ''; + foreach($userIdsFirstnames as $userId => $userFirstname) { + self::$listUsers [] = $userId; + } + // Soumission du formulaire + if($this->isPost()) { + // Configuration + $this->setData([ + 'module', + $this->getUrl(0), + 'config', + [ + 'button' => $this->getInput('formConfigButton'), + 'captcha' => $this->getInput('formConfigCaptcha', helper::FILTER_BOOLEAN), + 'group' => $this->getInput('formConfigGroup', helper::FILTER_INT), + 'user' => self::$listUsers [$this->getInput('formConfigUser', helper::FILTER_INT)], + 'mail' => $this->getInput('formConfigMail') , + 'pageId' => $this->getInput('formConfigPageIdToggle', helper::FILTER_BOOLEAN) === true ? $this->getInput('formConfigPageId', helper::FILTER_ID) : '', + 'subject' => $this->getInput('formConfigSubject'), + 'replyto' => $this->getInput('formConfigMailReplyTo', helper::FILTER_BOOLEAN), + 'signature' => $this->getInput('formConfigSignature'), + 'logoUrl' => $this->getInput('formConfigLogo'), + 'logoWidth' => $this->getInput('formConfigLogoWidth'), + 'maxSizeUpload' => $this->getInput('formConfigMaxSize'), + 'versionData' => self::VERSION, + 'uploadJpg' => $this->getInput('formConfigUploadJpg', helper::FILTER_BOOLEAN), + 'uploadPng' => $this->getInput('formConfigUploadPng', helper::FILTER_BOOLEAN), + 'uploadPdf' => $this->getInput('formConfigUploadPdf', helper::FILTER_BOOLEAN), + 'uploadZip' => $this->getInput('formConfigUploadZip', helper::FILTER_BOOLEAN), + 'uploadTxt' => $this->getInput('formConfigUploadTxt', helper::FILTER_BOOLEAN) + ] + ]); + // Génération des données vides + if ($this->getData(['module', $this->getUrl(0), 'data']) === null) { + $this->setData(['module', $this->getUrl(0), 'data', []]); + } + // Génération des champs + $inputs = []; + foreach($this->getInput('formConfigPosition', null) as $index => $position) { + $inputs[] = [ + 'name' => htmlspecialchars_decode($this->getInput('formConfigName[' . $index . ']'),ENT_QUOTES), + 'position' => helper::filter($position, helper::FILTER_INT), + 'required' => $this->getInput('formConfigRequired[' . $index . ']', helper::FILTER_BOOLEAN), + 'type' => $this->getInput('formConfigType[' . $index . ']'), + 'values' => $this->getInput('formConfigValues[' . $index . ']') + ]; + } + $this->setData(['module', $this->getUrl(0), 'input', $inputs]); + // Valeurs en sortie + $this->addOutput([ + 'notification' => $text['form']['config'][0], + 'redirect' => helper::baseUrl() . $this->getUrl(), + 'state' => true + ]); + } + // Liste des pages + foreach($this->getHierarchy(null, false) as $parentPageId => $childrenPageIds) { + self::$pages[$parentPageId] = $this->getData(['page', $parentPageId, 'title']); + foreach($childrenPageIds as $childKey) { + self::$pages[$childKey] = '    ' . $this->getData(['page', $childKey, 'title']); + } + } + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['form']['config'][1], + 'vendor' => [ + 'html-sortable', + 'flatpickr' + ], + 'view' => 'config' ]); } - // Liste des pages - foreach($this->getHierarchy(null, false) as $parentPageId => $childrenPageIds) { - self::$pages[$parentPageId] = $this->getData(['page', $parentPageId, 'title']); - foreach($childrenPageIds as $childKey) { - self::$pages[$childKey] = '    ' . $this->getData(['page', $childKey, 'title']); - } - } - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['form']['config'][1], - 'vendor' => [ - 'html-sortable', - 'flatpickr' - ], - 'view' => 'config' - ]); } /** * Données enregistrées */ public function data() { - // Lexique - $param = ''; - include('./module/form/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_form.php'); - $data = $this->getData(['module', $this->getUrl(0), 'data']); - if($data) { - // Pagination - $pagination = helper::pagination($data, $this->getUrl(),self::ITEMSPAGE); - // Liste des pages - self::$pages = $pagination['pages']; - // Inverse l'ordre du tableau - $dataIds = array_reverse(array_keys($data)); - $data = array_reverse($data); - // Données en fonction de la pagination - for($i = $pagination['first']; $i < $pagination['last']; $i++) { - $content = ''; - foreach($data[$i] as $input => $value) { - $content .= $input . ' : ' . $value . '
'; + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < form::$actions['data'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + $param = ''; + include('./module/form/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_form.php'); + $data = $this->getData(['module', $this->getUrl(0), 'data']); + if($data) { + // Pagination + $pagination = helper::pagination($data, $this->getUrl(),self::ITEMSPAGE); + // Liste des pages + self::$pages = $pagination['pages']; + // Inverse l'ordre du tableau + $dataIds = array_reverse(array_keys($data)); + $data = array_reverse($data); + // Données en fonction de la pagination + for($i = $pagination['first']; $i < $pagination['last']; $i++) { + $content = ''; + foreach($data[$i] as $input => $value) { + $content .= $input . ' : ' . $value . '
'; + } + self::$data[] = [ + $content, + template::button('formDataDelete' . $dataIds[$i], [ + 'class' => 'formDataDelete buttonRed', + 'href' => helper::baseUrl() . $this->getUrl(0) . '/delete/' . $dataIds[$i] . '/' . $_SESSION['csrf'], + 'value' => template::ico('cancel') + ]) + ]; } - self::$data[] = [ - $content, - template::button('formDataDelete' . $dataIds[$i], [ - 'class' => 'formDataDelete buttonRed', - 'href' => helper::baseUrl() . $this->getUrl(0) . '/delete/' . $dataIds[$i] . '/' . $_SESSION['csrf'], - 'value' => template::ico('cancel') - ]) - ]; } + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['form']['data'][0], + 'view' => 'data' + ]); } - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['form']['data'][0], - 'view' => 'data' - ]); } /** * Export CSV */ public function export2csv() { - // Lexique - $param = ''; - include('./module/form/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_form.php'); - // Jeton incorrect - if ($this->getUrl(2) !== $_SESSION['csrf']) { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < form::$actions['export2csv'] ) { // Valeurs en sortie $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data', - 'notification' => $text['form']['export2csv'][0] - ]); + 'access' => false + ]); } else { - $data = $this->getData(['module', $this->getUrl(0), 'data']); - if ($data !== []) { - $csvfilename = 'data-'.date('dmY').'-'.date('hm').'-'.rand(10,99).'.csv'; - if (!file_exists(self::FILE_DIR.'source/data')) { - mkdir(self::FILE_DIR.'source/data', 0755); - } - $fp = fopen(self::FILE_DIR.'source/data/'.$csvfilename, 'w'); - fputcsv($fp, array_keys($data[1]), ';','"'); - foreach ($data as $fields) { - fputcsv($fp, $fields, ';','"'); - } - fclose($fp); + // Lexique + $param = ''; + include('./module/form/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_form.php'); + // Jeton incorrect + if ($this->getUrl(2) !== $_SESSION['csrf']) { // Valeurs en sortie $this->addOutput([ - 'notification' => $text['form']['export2csv'][1].$csvfilename, - 'redirect' => helper::baseUrl() . $this->getUrl(0) .'/data', - 'state' => true + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data', + 'notification' => $text['form']['export2csv'][0] ]); } else { - $this->addOutput([ - 'notification' => $text['form']['export2csv'][2], - 'redirect' => helper::baseUrl() . $this->getUrl(0) .'/data' - ]); + $data = $this->getData(['module', $this->getUrl(0), 'data']); + if ($data !== []) { + $csvfilename = 'data-'.date('dmY').'-'.date('hm').'-'.rand(10,99).'.csv'; + if (!file_exists(self::FILE_DIR.'source/data')) { + mkdir(self::FILE_DIR.'source/data', 0755); + } + $fp = fopen(self::FILE_DIR.'source/data/'.$csvfilename, 'w'); + fputcsv($fp, array_keys($data[1]), ';','"'); + foreach ($data as $fields) { + fputcsv($fp, $fields, ';','"'); + } + fclose($fp); + // Valeurs en sortie + $this->addOutput([ + 'notification' => $text['form']['export2csv'][1].$csvfilename, + 'redirect' => helper::baseUrl() . $this->getUrl(0) .'/data', + 'state' => true + ]); + } else { + $this->addOutput([ + 'notification' => $text['form']['export2csv'][2], + 'redirect' => helper::baseUrl() . $this->getUrl(0) .'/data' + ]); + } } } } @@ -260,35 +289,45 @@ class form extends common { * Suppression */ public function deleteall() { - // Lexique - $param = ''; - include('./module/form/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_form.php'); - // Jeton incorrect - if ($this->getUrl(2) !== $_SESSION['csrf']) { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < form::$actions['deleteall'] ) { // Valeurs en sortie $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data', - 'notification' => $text['form']['deleteall'][0] - ]); + 'access' => false + ]); } else { - $data = ($this->getData(['module', $this->getUrl(0), 'data'])); - if (count($data) > 0 ) { - // Suppression multiple - for ($i = 1; $i <= count($data) ; $i++) { - echo $this->deleteData(['module', $this->getUrl(0), 'data', $i]); - } + // Lexique + $param = ''; + include('./module/form/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_form.php'); + // Jeton incorrect + if ($this->getUrl(2) !== $_SESSION['csrf']) { // Valeurs en sortie $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data', - 'notification' => $text['form']['deleteall'][1], - 'state' => true + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data', + 'notification' => $text['form']['deleteall'][0] ]); } else { - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data', - 'notification' => $text['form']['deleteall'][2] - ]); + $data = ($this->getData(['module', $this->getUrl(0), 'data'])); + if (count($data) > 0 ) { + // Suppression multiple + for ($i = 1; $i <= count($data) ; $i++) { + echo $this->deleteData(['module', $this->getUrl(0), 'data', $i]); + } + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data', + 'notification' => $text['form']['deleteall'][1], + 'state' => true + ]); + } else { + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data', + 'notification' => $text['form']['deleteall'][2] + ]); + } } } } @@ -298,33 +337,43 @@ class form extends common { * Suppression */ public function delete() { - // Lexique - $param = ''; - include('./module/form/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_form.php'); - // Jeton incorrect - if ($this->getUrl(3) !== $_SESSION['csrf']) { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < form::$actions['delete'] ) { // Valeurs en sortie $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data', - 'notification' => $text['form']['delete'][0] - ]); + 'access' => false + ]); } else { - // La donnée n'existe pas - if($this->getData(['module', $this->getUrl(0), 'data', $this->getUrl(2)]) === null) { + // Lexique + $param = ''; + include('./module/form/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_form.php'); + // Jeton incorrect + if ($this->getUrl(3) !== $_SESSION['csrf']) { // Valeurs en sortie $this->addOutput([ - 'access' => false - ]); - } - // Suppression - else { - $this->deleteData(['module', $this->getUrl(0), 'data', $this->getUrl(2)]); - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data', - 'notification' => $text['form']['delete'][1], - 'state' => true + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data', + 'notification' => $text['form']['delete'][0] ]); + } else { + // La donnée n'existe pas + if($this->getData(['module', $this->getUrl(0), 'data', $this->getUrl(2)]) === null) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } + // Suppression + else { + $this->deleteData(['module', $this->getUrl(0), 'data', $this->getUrl(2)]); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/data', + 'notification' => $text['form']['delete'][1], + 'state' => true + ]); + } } } } diff --git a/module/gallery/gallery.php b/module/gallery/gallery.php index 0223e72..2ff436c 100644 --- a/module/gallery/gallery.php +++ b/module/gallery/gallery.php @@ -175,23 +175,33 @@ class gallery extends common { * */ public function sortGalleries() { - if($_POST['response']) { - $data = explode('&',$_POST['response']); - $data = str_replace('galleryTable%5B%5D=','',$data); - for($i=0;$isetData(['module', $this->getUrl(0), 'content', $data[$i], [ - 'config' => [ - 'name' => $this->getData(['module',$this->getUrl(0), 'content', $data[$i],'config','name']), - 'directory' => $this->getData(['module',$this->getUrl(0), 'content', $data[$i],'config','directory']), - 'homePicture' => $this->getData(['module',$this->getUrl(0), 'content', $data[$i],'config','homePicture']), - 'sort' => $this->getData(['module',$this->getUrl(0), 'content', $data[$i],'config','sort']), - 'position'=> $i, - 'fullScreen' => $this->getData(['module',$this->getUrl(0), 'content',$data[$i],'config','fullScreen']) + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < gallery::$actions['sortGalleries'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + if($_POST['response']) { + $data = explode('&',$_POST['response']); + $data = str_replace('galleryTable%5B%5D=','',$data); + for($i=0;$isetData(['module', $this->getUrl(0), 'content', $data[$i], [ + 'config' => [ + 'name' => $this->getData(['module',$this->getUrl(0), 'content', $data[$i],'config','name']), + 'directory' => $this->getData(['module',$this->getUrl(0), 'content', $data[$i],'config','directory']), + 'homePicture' => $this->getData(['module',$this->getUrl(0), 'content', $data[$i],'config','homePicture']), + 'sort' => $this->getData(['module',$this->getUrl(0), 'content', $data[$i],'config','sort']), + 'position'=> $i, + 'fullScreen' => $this->getData(['module',$this->getUrl(0), 'content',$data[$i],'config','fullScreen']) - ], - 'legend' => $this->getData(['module',$this->getUrl(0), 'content', $data[$i],'legend']), - 'positions' => $this->getData(['module',$this->getUrl(0), 'content', $data[$i],'positions']) - ]]); + ], + 'legend' => $this->getData(['module',$this->getUrl(0), 'content', $data[$i],'legend']), + 'positions' => $this->getData(['module',$this->getUrl(0), 'content', $data[$i],'positions']) + ]]); + } } } } @@ -201,24 +211,34 @@ class gallery extends common { * */ public function sortPictures() { - if($_POST['response']) { - $galleryName = $_POST['gallery']; - $data = explode('&',$_POST['response']); - $data = str_replace('galleryTable%5B%5D=','',$data); - // Sauvegarder - $this->setData(['module', $this->getUrl(0), 'content', $galleryName, [ - 'config' => [ - 'name' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','name']), - 'directory' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','directory']), - 'homePicture' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','homePicture']), - 'sort' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','sort']), - 'position' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','position']), - 'fullScreen' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','fullScreen']) + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < gallery::$actions['sortPictures'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + if($_POST['response']) { + $galleryName = $_POST['gallery']; + $data = explode('&',$_POST['response']); + $data = str_replace('galleryTable%5B%5D=','',$data); + // Sauvegarder + $this->setData(['module', $this->getUrl(0), 'content', $galleryName, [ + 'config' => [ + 'name' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','name']), + 'directory' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','directory']), + 'homePicture' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','homePicture']), + 'sort' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','sort']), + 'position' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','position']), + 'fullScreen' => $this->getData(['module',$this->getUrl(0),$galleryName,'config','fullScreen']) - ], - 'legend' => $this->getData(['module',$this->getUrl(0),$galleryName,'legend']), - 'positions' => array_flip($data) - ]]); + ], + 'legend' => $this->getData(['module',$this->getUrl(0),$galleryName,'legend']), + 'positions' => array_flip($data) + ]]); + } } } @@ -227,137 +247,157 @@ class gallery extends common { * Configuration */ public function config() { - // Lexique - $param = ''; - include('./module/gallery/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_gallery.php'); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < gallery::$actions['config'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + $param = ''; + include('./module/gallery/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_gallery.php'); - // Mise à jour des données de module - $this->update(); + // Mise à jour des données de module + $this->update(); - //Affichage de la galerie triée - $g = $this->getData(['module', $this->getUrl(0), 'content']); - $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'] = '' . $gallery['config']['directory'] . $text['gallery']['config'][0].''; - } - } - // Erreur dossier supprimé - else { - $gallery['config']['directory'] = '' . $gallery['config']['directory'] . $text['gallery']['config'][1].''; - } - // Met en forme le tableau - self::$galleries[] = [ - template::ico('sort'), - $gallery['config']['name'], - str_replace('site/file/source/','',$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'), - 'disabled' => $this->getUser('group') >= self::GROUP_MODERATOR ? false : true - ]) - ]; - // Tableau des id des galleries pour le drag and drop - self::$galleriesId[] = $galleryId; + //Affichage de la galerie triée + $g = $this->getData(['module', $this->getUrl(0), 'content']); + $p = helper::arrayCollumn(helper::arrayCollumn($g,'config'),'position'); + asort($p,SORT_NUMERIC); + $galleries = []; + foreach ($p as $positionId => $item) { + $galleries [$positionId] = $g[$positionId]; } - } - // Soumission du formulaire d'ajout d'une galerie - if($this->isPost()) { - if (!$this->getInput('galleryConfigFilterResponse')) { - $galleryId = helper::increment($this->getInput('galleryConfigName', helper::FILTER_ID, true), (array) $this->getData(['module', $this->getUrl(0), 'content'])); - // définir une vignette par défaut - $directory = $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true); - $iterator = new DirectoryIterator($directory); - foreach($iterator as $fileInfos) { - if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) { - // Créer la miniature si manquante - if (!file_exists( str_replace('source','thumb',$fileInfos->getPath()) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename()))) { - $this->makeThumb($fileInfos->getPathname(), - str_replace('source','thumb',$fileInfos->getPath()) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename()), - self::THUMBS_WIDTH); + // 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'] = '' . $gallery['config']['directory'] . $text['gallery']['config'][0].''; } - // Miniatures - $homePicture = strtolower($fileInfos->getFilename()); - break; } + // Erreur dossier supprimé + else { + $gallery['config']['directory'] = '' . $gallery['config']['directory'] . $text['gallery']['config'][1].''; + } + // Met en forme le tableau + self::$galleries[] = [ + template::ico('sort'), + $gallery['config']['name'], + str_replace('site/file/source/','',$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'), + 'disabled' => $this->getUser('group') >= self::GROUP_MODERATOR ? false : true + ]) + ]; + // Tableau des id des galleries pour le drag and drop + self::$galleriesId[] = $galleryId; } - $this->setData(['module', $this->getUrl(0), 'content', $galleryId, [ - 'config' => [ - 'name' => $this->getInput('galleryConfigName'), - 'directory' => $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true), - 'homePicture' => $homePicture, - 'sort' => self::SORT_ASC, - 'position' => $this->getData(['module', $this->getUrl(0), 'content', $galleryId,'config','position']), - 'fullScreen' => false - ], - 'legend' => [], - 'positions' => [] - ]]); - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl() /*. '#galleryConfigForm'*/, - 'notification' => $text['gallery']['config'][2], - 'state' => true - ]); } + // Soumission du formulaire d'ajout d'une galerie + if($this->isPost()) { + if (!$this->getInput('galleryConfigFilterResponse')) { + $galleryId = helper::increment($this->getInput('galleryConfigName', helper::FILTER_ID, true), (array) $this->getData(['module', $this->getUrl(0), 'content'])); + // définir une vignette par défaut + $directory = $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true); + $iterator = new DirectoryIterator($directory); + foreach($iterator as $fileInfos) { + if($fileInfos->isDot() === false AND $fileInfos->isFile() AND @getimagesize($fileInfos->getPathname())) { + // Créer la miniature si manquante + if (!file_exists( str_replace('source','thumb',$fileInfos->getPath()) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename()))) { + $this->makeThumb($fileInfos->getPathname(), + str_replace('source','thumb',$fileInfos->getPath()) . '/' . self::THUMBS_SEPARATOR . strtolower($fileInfos->getFilename()), + self::THUMBS_WIDTH); + } + // Miniatures + $homePicture = strtolower($fileInfos->getFilename()); + break; + } + } + $this->setData(['module', $this->getUrl(0), 'content', $galleryId, [ + 'config' => [ + 'name' => $this->getInput('galleryConfigName'), + 'directory' => $this->getInput('galleryConfigDirectory', helper::FILTER_STRING_SHORT, true), + 'homePicture' => $homePicture, + 'sort' => self::SORT_ASC, + 'position' => $this->getData(['module', $this->getUrl(0), 'content', $galleryId,'config','position']), + 'fullScreen' => false + ], + 'legend' => [], + 'positions' => [] + ]]); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl() /*. '#galleryConfigForm'*/, + 'notification' => $text['gallery']['config'][2], + 'state' => true + ]); + } + } + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['gallery']['config'][3], + 'view' => 'config', + 'vendor' => [ + 'tablednd' + ] + ]); } - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['gallery']['config'][3], - 'view' => 'config', - 'vendor' => [ - 'tablednd' - ] - ]); } /** * Suppression */ public function delete() { - // Lexique - $param = ''; - include('./module/gallery/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_gallery.php'); - - // $url prend l'adresse sans le token - // La galerie n'existe pas - if($this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2)]) === null) { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < gallery::$actions['delete'] ) { // 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' => $text['gallery']['delete'][0] - ]); - } - // Suppression - else { - $this->deleteData(['module', $this->getUrl(0), 'content', $this->getUrl(2)]); - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['gallery']['delete'][1], - 'state' => true - ]); + ]); + } else { + // Lexique + $param = ''; + include('./module/gallery/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_gallery.php'); + + // $url prend l'adresse sans le token + // La galerie n'existe pas + if($this->getData(['module', $this->getUrl(0), 'content', $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' => $text['gallery']['delete'][0] + ]); + } + // Suppression + else { + $this->deleteData(['module', $this->getUrl(0), 'content', $this->getUrl(2)]); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['gallery']['delete'][1], + 'state' => true + ]); + } } } @@ -365,157 +405,177 @@ class gallery extends common { * Liste des dossiers */ public function dirs() { - // Valeurs en sortie - $filter = ['jpg', 'jpeg', 'png', 'gif', 'tiff', 'ico', 'webp']; - $this->addOutput([ - 'display' => self::DISPLAY_JSON, - 'content' => helper::scanDir(self::FILE_DIR.'source', $filter) - ]); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < gallery::$actions['dirs'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Valeurs en sortie + $filter = ['jpg', 'jpeg', 'png', 'gif', 'tiff', 'ico', 'webp']; + $this->addOutput([ + 'display' => self::DISPLAY_JSON, + 'content' => helper::scanDir(self::FILE_DIR.'source', $filter) + ]); + } } /** * Édition */ public function edit() { - // Lexique - $param = ''; - include('./module/gallery/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_gallery.php'); - - // Jeton incorrect - if ($this->getUrl(3) !== $_SESSION['csrf']) { - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['gallery']['edit'][0] - ]); - } - // La galerie n'existe pas - if($this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2)]) === null) { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < gallery::$actions['edit'] ) { // Valeurs en sortie $this->addOutput([ 'access' => false - ]); - } - // La galerie existe - else { - // Soumission du formulaire - if($this->isPost()) { - // Si l'id a changée - $galleryId = !empty($this->getInput('galleryEditName')) ? $this->getInput('galleryEditName', helper::FILTER_ID, true) : $this->getUrl(2); - if($galleryId !== $this->getUrl(2)) { - // Incrémente le nouvel id de la galerie - $galleryId = helper::increment($galleryId, $this->getData(['module', $this->getUrl(0), 'content'])); - // Transférer la position des images - $oldPositions = $this->getData(['module',$this->getUrl(0), $this->getUrl(2),'positions']); - // Supprime l'ancienne galerie - $this->deleteData(['module', $this->getUrl(0), 'content', $this->getUrl(2)]); - } - // légendes - $legends = []; - foreach((array) $this->getInput('legend', null) as $file => $legend) { - // Image de couverture par défaut si non définie - $homePicture = $file; - $file = str_replace('.','',$file); - $legends[$file] = helper::filter($legend, helper::FILTER_STRING_SHORT); + ]); + } else { + // Lexique + $param = ''; + include('./module/gallery/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_gallery.php'); - } - // Photo de la page de garde de l'album définie dans form - if (is_array($this->getInput('homePicture', null)) ) { - $d = array_keys($this->getInput('homePicture', null)); - $homePicture = $d[0]; - } - // Sauvegarder - if ($this->getInput('galleryEditName')) { - $this->setData(['module', $this->getUrl(0), 'content', $galleryId, [ - 'config' => [ - 'name' => $this->getInput('galleryEditName', helper::FILTER_STRING_SHORT, true), - 'directory' => $this->getInput('galleryEditDirectory', helper::FILTER_STRING_SHORT, true), - 'homePicture' => $homePicture, - // pas de positions, on active le tri alpha - 'sort' => $this->getInput('galleryEditSort'), - 'position' => $this->getData(['module', $this->getUrl(0), 'content', $galleryId,'config','position']), - 'fullScreen' => $this->getInput('galleryEditFullscreen', helper::FILTER_BOOLEAN) + // Jeton incorrect + if ($this->getUrl(3) !== $_SESSION['csrf']) { + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['gallery']['edit'][0] + ]); + } + // La galerie n'existe pas + if($this->getData(['module', $this->getUrl(0), 'content', $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 = !empty($this->getInput('galleryEditName')) ? $this->getInput('galleryEditName', helper::FILTER_ID, true) : $this->getUrl(2); + if($galleryId !== $this->getUrl(2)) { + // Incrémente le nouvel id de la galerie + $galleryId = helper::increment($galleryId, $this->getData(['module', $this->getUrl(0), 'content'])); + // Transférer la position des images + $oldPositions = $this->getData(['module',$this->getUrl(0), $this->getUrl(2),'positions']); + // Supprime l'ancienne galerie + $this->deleteData(['module', $this->getUrl(0), 'content', $this->getUrl(2)]); + } + // légendes + $legends = []; + foreach((array) $this->getInput('legend', null) as $file => $legend) { + // Image de couverture par défaut si non définie + $homePicture = $file; + $file = str_replace('.','',$file); + $legends[$file] = helper::filter($legend, helper::FILTER_STRING_SHORT); - ], - 'legend' => $legends, - 'positions' => empty($oldPositions) ? $this->getdata(['module', $this->getUrl(0), 'content', $galleryId, 'positions']) : $oldPositions - ]]); + } + // Photo de la page de garde de l'album définie dans form + if (is_array($this->getInput('homePicture', null)) ) { + $d = array_keys($this->getInput('homePicture', null)); + $homePicture = $d[0]; + } + // Sauvegarder + if ($this->getInput('galleryEditName')) { + $this->setData(['module', $this->getUrl(0), 'content', $galleryId, [ + 'config' => [ + 'name' => $this->getInput('galleryEditName', helper::FILTER_STRING_SHORT, true), + 'directory' => $this->getInput('galleryEditDirectory', helper::FILTER_STRING_SHORT, true), + 'homePicture' => $homePicture, + // pas de positions, on active le tri alpha + 'sort' => $this->getInput('galleryEditSort'), + 'position' => $this->getData(['module', $this->getUrl(0), 'content', $galleryId,'config','position']), + 'fullScreen' => $this->getInput('galleryEditFullscreen', helper::FILTER_BOOLEAN) + + ], + 'legend' => $legends, + 'positions' => empty($oldPositions) ? $this->getdata(['module', $this->getUrl(0), 'content', $galleryId, 'positions']) : $oldPositions + ]]); + } + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $galleryId . '/' . $_SESSION['csrf'] , + 'notification' => $text['gallery']['edit'][1], + 'state' => true + ]); + } + // Met en forme le tableau + $directory = $this->getData(['module', $this->getUrl(0), 'content', $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())) { + // Créer la miniature RFM si manquante + if (!file_exists( str_replace('source','thumb',$fileInfos->getPath()) . '/' . strtolower($fileInfos->getFilename()))) { + $this->makeThumb($fileInfos->getPathname(), + str_replace('source','thumb',$fileInfos->getPath()) . '/' . strtolower($fileInfos->getFilename()), + 122); + } + self::$pictures[str_replace('.','',$fileInfos->getFilename())] = [ + template::ico('sort'), + $fileInfos->getFilename(), + template::checkbox( 'homePicture[' . $fileInfos->getFilename() . ']', true, '', [ + 'checked' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2),'config', 'homePicture']) === $fileInfos->getFilename() ? true : false, + 'class' => 'homePicture' + ]), + template::text('legend[' . $fileInfos->getFilename() . ']', [ + 'value' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'legend', str_replace('.','',$fileInfos->getFilename())]) + ]), + '' + ]; + self::$picturesId [] = str_replace('.','',$fileInfos->getFilename()); + } + } + // Tri des images + switch ($this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'config', 'sort'])) { + case self::SORT_HAND: + $positions = $this->getdata(['module',$this->getUrl(0),'content', $this->getUrl(2),'positions']); + if ($positions) { + foreach ($positions as $key => $value) { + if (array_key_exists($key,self::$pictures)) { + $tempPictures[$key] = self::$pictures[$key]; + $tempPicturesId [] = $key; + } + } + // Images ayant été ajoutées dans le dossier mais non triées + foreach (self::$pictures as $key => $value) { + if (!array_key_exists($key,$tempPictures)) { + $tempPictures[$key] = self::$pictures[$key]; + $tempPicturesId [] = $key; + } + } + self::$pictures = $tempPictures; + self::$picturesId = $tempPicturesId; + } + break; + case self::SORT_ASC: + ksort(self::$pictures,SORT_NATURAL); + sort(self::$picturesId,SORT_NATURAL); + break; + case self::SORT_DSC: + krsort(self::$pictures,SORT_NATURAL); + rsort(self::$picturesId,SORT_NATURAL); + break; + } } // Valeurs en sortie $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $galleryId . '/' . $_SESSION['csrf'] , - 'notification' => $text['gallery']['edit'][1], - 'state' => true + 'title' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'config', 'name']), + 'view' => 'edit', + 'vendor' => [ + 'tablednd' + ] ]); } - // Met en forme le tableau - $directory = $this->getData(['module', $this->getUrl(0), 'content', $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())) { - // Créer la miniature RFM si manquante - if (!file_exists( str_replace('source','thumb',$fileInfos->getPath()) . '/' . strtolower($fileInfos->getFilename()))) { - $this->makeThumb($fileInfos->getPathname(), - str_replace('source','thumb',$fileInfos->getPath()) . '/' . strtolower($fileInfos->getFilename()), - 122); - } - self::$pictures[str_replace('.','',$fileInfos->getFilename())] = [ - template::ico('sort'), - $fileInfos->getFilename(), - template::checkbox( 'homePicture[' . $fileInfos->getFilename() . ']', true, '', [ - 'checked' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2),'config', 'homePicture']) === $fileInfos->getFilename() ? true : false, - 'class' => 'homePicture' - ]), - template::text('legend[' . $fileInfos->getFilename() . ']', [ - 'value' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'legend', str_replace('.','',$fileInfos->getFilename())]) - ]), - '' - ]; - self::$picturesId [] = str_replace('.','',$fileInfos->getFilename()); - } - } - // Tri des images - switch ($this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'config', 'sort'])) { - case self::SORT_HAND: - $positions = $this->getdata(['module',$this->getUrl(0),'content', $this->getUrl(2),'positions']); - if ($positions) { - foreach ($positions as $key => $value) { - if (array_key_exists($key,self::$pictures)) { - $tempPictures[$key] = self::$pictures[$key]; - $tempPicturesId [] = $key; - } - } - // Images ayant été ajoutées dans le dossier mais non triées - foreach (self::$pictures as $key => $value) { - if (!array_key_exists($key,$tempPictures)) { - $tempPictures[$key] = self::$pictures[$key]; - $tempPicturesId [] = $key; - } - } - self::$pictures = $tempPictures; - self::$picturesId = $tempPicturesId; - } - break; - case self::SORT_ASC: - ksort(self::$pictures,SORT_NATURAL); - sort(self::$picturesId,SORT_NATURAL); - break; - case self::SORT_DSC: - krsort(self::$pictures,SORT_NATURAL); - rsort(self::$picturesId,SORT_NATURAL); - break; - } - } - // Valeurs en sortie - $this->addOutput([ - 'title' => $this->getData(['module', $this->getUrl(0), 'content', $this->getUrl(2), 'config', 'name']), - 'view' => 'edit', - 'vendor' => [ - 'tablednd' - ] - ]); } } @@ -657,75 +717,85 @@ class gallery extends common { * Thème de la galerie */ public function theme() { - // Lexique - $param = ''; - include('./module/gallery/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_gallery.php'); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < gallery::$actions['theme'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + $param = ''; + include('./module/gallery/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_gallery.php'); - // Jeton incorrect - if ($this->getUrl(2) !== $_SESSION['csrf']) { - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['gallery']['theme'][0] - ]); - } - // Soumission du formulaire - if($this->isPost()) { - // Dossier de l'instance - if (!is_dir(self::DATADIRECTORY . $this->getUrl(0) )) { - mkdir (self::DATADIRECTORY . $this->getUrl(0), 0755, true); + // Jeton incorrect + if ($this->getUrl(2) !== $_SESSION['csrf']) { + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['gallery']['theme'][0] + ]); + } + // Soumission du formulaire + if($this->isPost()) { + // Dossier de l'instance + if (!is_dir(self::DATADIRECTORY . $this->getUrl(0) )) { + mkdir (self::DATADIRECTORY . $this->getUrl(0), 0755, true); + } + $this->setData(['module', $this->getUrl(0), 'theme', [ + 'thumbAlign' => $this->getinput('galleryThemeThumbAlign', helper::FILTER_STRING_SHORT), + 'thumbWidth' => $this->getinput('galleryThemeThumbWidth', helper::FILTER_STRING_SHORT), + 'thumbHeight' => $this->getinput('galleryThemeThumbHeight', helper::FILTER_STRING_SHORT), + 'thumbMargin' => $this->getinput('galleryThemeThumbMargin', helper::FILTER_STRING_SHORT), + 'thumbBorder' => $this->getinput('galleryThemeThumbBorder', helper::FILTER_STRING_SHORT), + 'thumbBorderColor' => $this->getinput('galleryThemeThumbBorderColor', helper::FILTER_STRING_SHORT), + 'thumbOpacity' => $this->getinput('galleryThemeThumbOpacity', helper::FILTER_STRING_SHORT), + 'thumbShadows' => $this->getinput('galleryThemeThumbShadows', helper::FILTER_STRING_SHORT), + 'thumbShadowsColor' => $this->getinput('galleryThemeThumbShadowsColor', helper::FILTER_STRING_SHORT), + 'thumbRadius' => $this->getinput('galleryThemeThumbRadius', helper::FILTER_STRING_SHORT), + 'legendHeight' => $this->getinput('galleryThemeLegendHeight', helper::FILTER_STRING_SHORT), + 'legendAlign' => $this->getinput('galleryThemeLegendAlign', helper::FILTER_STRING_SHORT), + 'legendTextColor' => $this->getinput('galleryThemeLegendTextColor', helper::FILTER_STRING_SHORT), + 'legendBgColor' => $this->getinput('galleryThemeLegendBgColor', helper::FILTER_STRING_SHORT), + 'style' => self::DATADIRECTORY . $this->getUrl(0) . '/theme.css' + ]]); + // Création des fichiers CSS + $content = file_get_contents('module/gallery/ressource/vartheme.css'); + $themeCss = file_get_contents('module/gallery/ressource/theme.css'); + // Injection des variables + $content = str_replace('#thumbAlign#',$this->getinput('galleryThemeThumbAlign'),$content ); + $content = str_replace('#thumbWidth#',$this->getinput('galleryThemeThumbWidth'),$content ); + $content = str_replace('#thumbHeight#',$this->getinput('galleryThemeThumbHeight'),$content ); + $content = str_replace('#thumbMargin#',$this->getinput('galleryThemeThumbMargin'),$content ); + $content = str_replace('#thumbBorder#',$this->getinput('galleryThemeThumbBorder'),$content ); + $content = str_replace('#thumbBorderColor#',$this->getinput('galleryThemeThumbBorderColor'),$content ); + $content = str_replace('#thumbOpacity#',$this->getinput('galleryThemeThumbOpacity'),$content ); + $content = str_replace('#thumbShadows#',$this->getinput('galleryThemeThumbShadows'),$content ); + $content = str_replace('#thumbShadowsColor#',$this->getinput('galleryThemeThumbShadowsColor'),$content ); + $content = str_replace('#thumbRadius#',$this->getinput('galleryThemeThumbRadius'),$content ); + $content = str_replace('#legendAlign#',$this->getinput('galleryThemeLegendAlign'),$content ); + $content = str_replace('#legendHeight#',$this->getinput('galleryThemeLegendHeight'),$content ); + $content = str_replace('#legendTextColor#',$this->getinput('galleryThemeLegendTextColor'),$content ); + $content = str_replace('#legendBgColor#',$this->getinput('galleryThemeLegendBgColor'),$content ); + $success = file_put_contents(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css', $content . $themeCss); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl() . '/theme', + 'notification' => $success !== FALSE ? $text['gallery']['theme'][1] : $text['gallery']['theme'][2], + 'state' => $success !== FALSE + ]); } - $this->setData(['module', $this->getUrl(0), 'theme', [ - 'thumbAlign' => $this->getinput('galleryThemeThumbAlign', helper::FILTER_STRING_SHORT), - 'thumbWidth' => $this->getinput('galleryThemeThumbWidth', helper::FILTER_STRING_SHORT), - 'thumbHeight' => $this->getinput('galleryThemeThumbHeight', helper::FILTER_STRING_SHORT), - 'thumbMargin' => $this->getinput('galleryThemeThumbMargin', helper::FILTER_STRING_SHORT), - 'thumbBorder' => $this->getinput('galleryThemeThumbBorder', helper::FILTER_STRING_SHORT), - 'thumbBorderColor' => $this->getinput('galleryThemeThumbBorderColor', helper::FILTER_STRING_SHORT), - 'thumbOpacity' => $this->getinput('galleryThemeThumbOpacity', helper::FILTER_STRING_SHORT), - 'thumbShadows' => $this->getinput('galleryThemeThumbShadows', helper::FILTER_STRING_SHORT), - 'thumbShadowsColor' => $this->getinput('galleryThemeThumbShadowsColor', helper::FILTER_STRING_SHORT), - 'thumbRadius' => $this->getinput('galleryThemeThumbRadius', helper::FILTER_STRING_SHORT), - 'legendHeight' => $this->getinput('galleryThemeLegendHeight', helper::FILTER_STRING_SHORT), - 'legendAlign' => $this->getinput('galleryThemeLegendAlign', helper::FILTER_STRING_SHORT), - 'legendTextColor' => $this->getinput('galleryThemeLegendTextColor', helper::FILTER_STRING_SHORT), - 'legendBgColor' => $this->getinput('galleryThemeLegendBgColor', helper::FILTER_STRING_SHORT), - 'style' => self::DATADIRECTORY . $this->getUrl(0) . '/theme.css' - ]]); - // Création des fichiers CSS - $content = file_get_contents('module/gallery/ressource/vartheme.css'); - $themeCss = file_get_contents('module/gallery/ressource/theme.css'); - // Injection des variables - $content = str_replace('#thumbAlign#',$this->getinput('galleryThemeThumbAlign'),$content ); - $content = str_replace('#thumbWidth#',$this->getinput('galleryThemeThumbWidth'),$content ); - $content = str_replace('#thumbHeight#',$this->getinput('galleryThemeThumbHeight'),$content ); - $content = str_replace('#thumbMargin#',$this->getinput('galleryThemeThumbMargin'),$content ); - $content = str_replace('#thumbBorder#',$this->getinput('galleryThemeThumbBorder'),$content ); - $content = str_replace('#thumbBorderColor#',$this->getinput('galleryThemeThumbBorderColor'),$content ); - $content = str_replace('#thumbOpacity#',$this->getinput('galleryThemeThumbOpacity'),$content ); - $content = str_replace('#thumbShadows#',$this->getinput('galleryThemeThumbShadows'),$content ); - $content = str_replace('#thumbShadowsColor#',$this->getinput('galleryThemeThumbShadowsColor'),$content ); - $content = str_replace('#thumbRadius#',$this->getinput('galleryThemeThumbRadius'),$content ); - $content = str_replace('#legendAlign#',$this->getinput('galleryThemeLegendAlign'),$content ); - $content = str_replace('#legendHeight#',$this->getinput('galleryThemeLegendHeight'),$content ); - $content = str_replace('#legendTextColor#',$this->getinput('galleryThemeLegendTextColor'),$content ); - $content = str_replace('#legendBgColor#',$this->getinput('galleryThemeLegendBgColor'),$content ); - $success = file_put_contents(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css', $content . $themeCss); // Valeurs en sortie $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl() . '/theme', - 'notification' => $success !== FALSE ? $text['gallery']['theme'][1] : $text['gallery']['theme'][2], - 'state' => $success !== FALSE + 'title' => $text['gallery']['theme'][3], + 'view' => 'theme', + 'vendor' => [ + 'tinycolorpicker' + ] ]); } - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['gallery']['theme'][3], - 'view' => 'theme', - 'vendor' => [ - 'tinycolorpicker' - ] - ]); } } diff --git a/module/news/news.php b/module/news/news.php index f77f45a..5f65ef7 100644 --- a/module/news/news.php +++ b/module/news/news.php @@ -108,261 +108,35 @@ class news extends common { * Ajout d'un article */ public function add() { - // Lexique - include('./module/news/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_news.php'); - // Soumission du formulaire - if($this->isPost()) { - // Crée la news - $newsId = helper::increment($this->getInput('newsAddTitle', helper::FILTER_ID), (array) $this->getData(['module', $this->getUrl(0), 'posts'])); - $publishedOn = $this->getInput('newsAddPublishedOn', helper::FILTER_DATETIME, true); - $publishedOff = $this->getInput('newsAddPublishedOff' ) ? $this->getInput('newsAddPublishedOff', helper::FILTER_DATETIME) : ''; - $this->setData(['module', $this->getUrl(0),'posts', $newsId, [ - 'content' => $this->getInput('newsAddContent', null), - 'publishedOn' => $publishedOn, - 'publishedOff' => $publishedOff, - 'state' => $this->getInput('newsAddState', helper::FILTER_BOOLEAN), - 'title' => $this->getInput('newsAddTitle', helper::FILTER_STRING_SHORT, true), - 'userId' => $this->getInput('newsAddUserId', helper::FILTER_ID, true) - ]]); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < news::$actions['add'] ) { // Valeurs en sortie $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['news']['add'][0], - 'state' => true - ]); - } - // Liste des utilisateurs - self::$users = helper::arrayCollumn($this->getData(['user']), 'firstname'); - ksort(self::$users); - foreach(self::$users as $userId => &$userFirstname) { - $userFirstname = $userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']); - } - unset($userFirstname); - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['news']['add'][1], - 'vendor' => [ - 'flatpickr', - 'tinymce' - ], - 'view' => 'add' - ]); - } - - /** - * Configuration - */ - public function config() { - // Lexique - include('./module/news/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_news.php'); - // Mise à jour des données de module - $this->update(); - - // Soumission du formulaire - if($this->isPost()) { - - // Générer la feuille de CSS - $style = '.newsFrame {'; - $style .= 'border: solid ' . $this->getInput('newsThemeBorderColor') . ' ' . $this->getInput('newsThemeBorderWidth',helper::FILTER_STRING_SHORT) . ';'; - $style .= 'border-radius:' . $this->getInput('newsBorderRadius',helper::FILTER_STRING_SHORT).';'; - $style .= 'box-shadow:' . $this->getInput('newsBorderShadows',helper::FILTER_STRING_SHORT).';'; - $style .= 'background-color:' . $this->getInput('newsThemeBackgroundColor') . ';'; - $style .= '}'; - - // Dossier de l'instance - if (!is_dir(self::DATADIRECTORY . $this->getUrl(0))) { - mkdir (self::DATADIRECTORY . $this->getUrl(0), 0755, true); - } - - $success = file_put_contents(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css', $style ); - - // Fin feuille de style - - $this->setData(['module', $this->getUrl(0), 'theme',[ - 'style' => $success ? self::DATADIRECTORY . $this->getUrl(0) . '/theme.css' : '', - 'borderColor' => $this->getInput('newsThemeBorderColor'), - 'borderWidth' => $this->getInput('newsThemeBorderWidth',helper::FILTER_STRING_SHORT), - 'backgroundColor' => $this->getInput('newsThemeBackgroundColor'), - 'borderRadius' => $this->getInput('newsBorderRadius',helper::FILTER_STRING_SHORT), - 'borderShadows' => $this->getInput('newsBorderShadows',helper::FILTER_STRING_SHORT) - ]]); - - $this->setData(['module', $this->getUrl(0), 'config',[ - 'feeds' => $this->getInput('newsConfigShowFeeds',helper::FILTER_BOOLEAN), - 'feedsLabel' => $this->getInput('newsConfigFeedslabel',helper::FILTER_STRING_SHORT), - 'itemsperPage' => $this->getInput('newsConfigItemsperPage', helper::FILTER_INT,true), - 'itemsperCol' => $this->getInput('newsConfigItemsperCol', helper::FILTER_INT,true), - 'height' => $this->getInput('newsConfigHeight', helper::FILTER_INT,true), - 'versionData' => $this->getData(['module', $this->getUrl(0), 'config', 'versionData']), - 'hiddeTitle' => $this->getInput('newsThemeTitle',helper::FILTER_BOOLEAN), - 'hideMedia' => $this->getInput('newsThemeMedia',helper::FILTER_BOOLEAN), - 'sameHeight' => $this->getInput('newsThemeSameHeight',helper::FILTER_BOOLEAN), - 'noMargin' => $this->getInput('newsThemeNoMargin',helper::FILTER_BOOLEAN) - ]]); - - - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['news']['config'][0], - 'state' => true - ]); + 'access' => false + ]); } else { - // Ids des news par ordre de publication - $newsIds = array_keys(helper::arrayCollumn($this->getData(['module', $this->getUrl(0), 'posts']), 'publishedOn', 'SORT_DESC')); - // Pagination - $pagination = helper::pagination($newsIds, $this->getUrl(),$this->getData(['module', $this->getUrl(0), 'config', 'itemsperPage']) ); - // Liste des pages - self::$pages = $pagination['pages']; - // News en fonction de la pagination - // Pour les dates suivant la langue d'administration - if( function_exists('datefmt_create') && function_exists('datefmt_create') && extension_loaded('intl') ){ - $lang = $text['news']['config'][4]; - $zone = $text['news']['config'][5]; - $fmt = datefmt_create( - $lang, - IntlDateFormatter::LONG, - IntlDateFormatter::SHORT, - $zone, - IntlDateFormatter::GREGORIAN - ); - } - for($i = $pagination['first']; $i < $pagination['last']; $i++) { - // Met en forme le tableau - if( function_exists('datefmt_create') && function_exists('datefmt_create') && extension_loaded('intl') ){ - $dateOn = datefmt_format($fmt, strtotime( date('Y/m/d H:i:s',$this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOn'])))); - } else { - $dateOn = mb_detect_encoding(date('d/m/Y', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOn'])), 'UTF-8', true) - ? date('d/m/Y', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOn'])) - : utf8_encode(date('d/m/Y', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOn']))); - $dateOn .= $text['news']['config'][3]; - $dateOn .= mb_detect_encoding(date('H:i', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOn'])), 'UTF-8', true) - ? date('H:i', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOn'])) - : utf8_encode(date('H:i', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOn']))); - } - if ($this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff'])) { - if( function_exists('datefmt_create') && function_exists('datefmt_create') && extension_loaded('intl') ){ - $dateOff = datefmt_format($fmt, strtotime( date('Y/m/d H:i:s',$this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff'])))); - } else { - $dateOff = mb_detect_encoding(date('d/m/Y', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff'])), 'UTF-8', true) - ? date('d/m/Y', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff'])) - : utf8_encode(date('d/m/Y', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff']))); - $dateOff .= $text['news']['config'][3]; - $dateOff .= mb_detect_encoding(date('H:i', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff'])), 'UTF-8', true) - ? date('H:i', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff'])) - : utf8_encode(date('H:i', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff']))); - } - } else { - $dateOff = $text['news']['config'][1]; - } - self::$news[] = [ - $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'title']), - $dateOn, - $dateOff, - $states[$this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'state'])], - template::button('newsConfigEdit' . $newsIds[$i], [ - 'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $newsIds[$i]. '/' . $_SESSION['csrf'], - 'value' => template::ico('pencil') - ]), - template::button('newsConfigDelete' . $newsIds[$i], [ - 'class' => 'newsConfigDelete buttonRed', - 'href' => helper::baseUrl() . $this->getUrl(0) . '/delete/' . $newsIds[$i] . '/' . $_SESSION['csrf'], - 'value' => template::ico('cancel'), - 'disabled' => $this->getUser('group') >= self::GROUP_MODERATOR ? false : true - ]) - ]; - } - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['news']['config'][2], - 'view' => 'config', - 'vendor' => [ - 'tinycolorpicker' - ] - ]); - } - } - - /** - * Suppression - */ - public function delete() { - // Lexique - include('./module/news/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_news.php'); - // La news n'existe pas - if($this->getData(['module', $this->getUrl(0),'posts', $this->getUrl(2)]) === null) { - // Valeurs en sortie - $this->addOutput([ - 'access' => false - ]); - } - // Jeton incorrect - elseif ($this->getUrl(3) !== $_SESSION['csrf']) { - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['news']['delete'][0] - ]); - } - // Suppression - else { - $this->deleteData(['module', $this->getUrl(0),'posts', $this->getUrl(2)]); - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['news']['delete'][1], - 'state' => true - ]); - } - } - - /** - * Édition - */ - public function edit() { - // Lexique - include('./module/news/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_news.php'); - // Jeton incorrect - if ($this->getUrl(3) !== $_SESSION['csrf']) { - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['news']['edit'][0] - ]); - } - // La news n'existe pas - if($this->getData(['module', $this->getUrl(0),'posts', $this->getUrl(2)]) === null) { - // Valeurs en sortie - $this->addOutput([ - 'access' => false - ]); - } - // La news existe - else { + // Lexique + include('./module/news/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_news.php'); // Soumission du formulaire if($this->isPost()) { - // Si l'id a changée - $newsId = $this->getInput('newsEditTitle', helper::FILTER_ID, true); - if($newsId !== $this->getUrl(2)) { - // Incrémente le nouvel id de la news - $newsId = helper::increment($newsId, $this->getData(['module', $this->getUrl(0), 'posts'])); - // Supprime l'ancien news - $this->deleteData(['module', $this->getUrl(0),'posts', $this->getUrl(2)]); - } - $publishedOn = $this->getInput('newsEditPublishedOn', helper::FILTER_DATETIME, true); - $publishedOff = $this->getInput('newsEditPublishedOff' ) ? $this->getInput('newsEditPublishedOff', helper::FILTER_DATETIME) : ''; + // Crée la news + $newsId = helper::increment($this->getInput('newsAddTitle', helper::FILTER_ID), (array) $this->getData(['module', $this->getUrl(0), 'posts'])); + $publishedOn = $this->getInput('newsAddPublishedOn', helper::FILTER_DATETIME, true); + $publishedOff = $this->getInput('newsAddPublishedOff' ) ? $this->getInput('newsAddPublishedOff', helper::FILTER_DATETIME) : ''; $this->setData(['module', $this->getUrl(0),'posts', $newsId, [ - 'content' => $this->getInput('newsEditContent', null), + 'content' => $this->getInput('newsAddContent', null), 'publishedOn' => $publishedOn, - 'publishedOff' => $publishedOff < $publishedOn ? '' : $publishedOff, - 'state' => $this->getInput('newsEditState', helper::FILTER_BOOLEAN), - 'title' => $this->getInput('newsEditTitle', helper::FILTER_STRING_SHORT, true), - 'userId' => $this->getInput('newsEditUserId', helper::FILTER_ID, true) + 'publishedOff' => $publishedOff, + 'state' => $this->getInput('newsAddState', helper::FILTER_BOOLEAN), + 'title' => $this->getInput('newsAddTitle', helper::FILTER_STRING_SHORT, true), + 'userId' => $this->getInput('newsAddUserId', helper::FILTER_ID, true) ]]); // Valeurs en sortie $this->addOutput([ 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['news']['edit'][1], + 'notification' => $text['news']['add'][0], 'state' => true ]); } @@ -375,16 +149,282 @@ class news extends common { unset($userFirstname); // Valeurs en sortie $this->addOutput([ - 'title' => $this->getData(['module', $this->getUrl(0),'posts', $this->getUrl(2), 'title']), + 'title' => $text['news']['add'][1], 'vendor' => [ 'flatpickr', 'tinymce' ], - 'view' => 'edit' + 'view' => 'add' ]); } } + /** + * Configuration + */ + public function config() { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < news::$actions['config'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./module/news/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_news.php'); + // Mise à jour des données de module + $this->update(); + + // Soumission du formulaire + if($this->isPost()) { + + // Générer la feuille de CSS + $style = '.newsFrame {'; + $style .= 'border: solid ' . $this->getInput('newsThemeBorderColor') . ' ' . $this->getInput('newsThemeBorderWidth',helper::FILTER_STRING_SHORT) . ';'; + $style .= 'border-radius:' . $this->getInput('newsBorderRadius',helper::FILTER_STRING_SHORT).';'; + $style .= 'box-shadow:' . $this->getInput('newsBorderShadows',helper::FILTER_STRING_SHORT).';'; + $style .= 'background-color:' . $this->getInput('newsThemeBackgroundColor') . ';'; + $style .= '}'; + + // Dossier de l'instance + if (!is_dir(self::DATADIRECTORY . $this->getUrl(0))) { + mkdir (self::DATADIRECTORY . $this->getUrl(0), 0755, true); + } + + $success = file_put_contents(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css', $style ); + + // Fin feuille de style + + $this->setData(['module', $this->getUrl(0), 'theme',[ + 'style' => $success ? self::DATADIRECTORY . $this->getUrl(0) . '/theme.css' : '', + 'borderColor' => $this->getInput('newsThemeBorderColor'), + 'borderWidth' => $this->getInput('newsThemeBorderWidth',helper::FILTER_STRING_SHORT), + 'backgroundColor' => $this->getInput('newsThemeBackgroundColor'), + 'borderRadius' => $this->getInput('newsBorderRadius',helper::FILTER_STRING_SHORT), + 'borderShadows' => $this->getInput('newsBorderShadows',helper::FILTER_STRING_SHORT) + ]]); + + $this->setData(['module', $this->getUrl(0), 'config',[ + 'feeds' => $this->getInput('newsConfigShowFeeds',helper::FILTER_BOOLEAN), + 'feedsLabel' => $this->getInput('newsConfigFeedslabel',helper::FILTER_STRING_SHORT), + 'itemsperPage' => $this->getInput('newsConfigItemsperPage', helper::FILTER_INT,true), + 'itemsperCol' => $this->getInput('newsConfigItemsperCol', helper::FILTER_INT,true), + 'height' => $this->getInput('newsConfigHeight', helper::FILTER_INT,true), + 'versionData' => $this->getData(['module', $this->getUrl(0), 'config', 'versionData']), + 'hiddeTitle' => $this->getInput('newsThemeTitle',helper::FILTER_BOOLEAN), + 'hideMedia' => $this->getInput('newsThemeMedia',helper::FILTER_BOOLEAN), + 'sameHeight' => $this->getInput('newsThemeSameHeight',helper::FILTER_BOOLEAN), + 'noMargin' => $this->getInput('newsThemeNoMargin',helper::FILTER_BOOLEAN) + ]]); + + + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['news']['config'][0], + 'state' => true + ]); + } else { + // Ids des news par ordre de publication + $newsIds = array_keys(helper::arrayCollumn($this->getData(['module', $this->getUrl(0), 'posts']), 'publishedOn', 'SORT_DESC')); + // Pagination + $pagination = helper::pagination($newsIds, $this->getUrl(),$this->getData(['module', $this->getUrl(0), 'config', 'itemsperPage']) ); + // Liste des pages + self::$pages = $pagination['pages']; + // News en fonction de la pagination + // Pour les dates suivant la langue d'administration + if( function_exists('datefmt_create') && function_exists('datefmt_create') && extension_loaded('intl') ){ + $lang = $text['news']['config'][4]; + $zone = $text['news']['config'][5]; + $fmt = datefmt_create( + $lang, + IntlDateFormatter::LONG, + IntlDateFormatter::SHORT, + $zone, + IntlDateFormatter::GREGORIAN + ); + } + for($i = $pagination['first']; $i < $pagination['last']; $i++) { + // Met en forme le tableau + if( function_exists('datefmt_create') && function_exists('datefmt_create') && extension_loaded('intl') ){ + $dateOn = datefmt_format($fmt, strtotime( date('Y/m/d H:i:s',$this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOn'])))); + } else { + $dateOn = mb_detect_encoding(date('d/m/Y', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOn'])), 'UTF-8', true) + ? date('d/m/Y', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOn'])) + : utf8_encode(date('d/m/Y', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOn']))); + $dateOn .= $text['news']['config'][3]; + $dateOn .= mb_detect_encoding(date('H:i', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOn'])), 'UTF-8', true) + ? date('H:i', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOn'])) + : utf8_encode(date('H:i', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOn']))); + } + if ($this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff'])) { + if( function_exists('datefmt_create') && function_exists('datefmt_create') && extension_loaded('intl') ){ + $dateOff = datefmt_format($fmt, strtotime( date('Y/m/d H:i:s',$this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff'])))); + } else { + $dateOff = mb_detect_encoding(date('d/m/Y', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff'])), 'UTF-8', true) + ? date('d/m/Y', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff'])) + : utf8_encode(date('d/m/Y', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff']))); + $dateOff .= $text['news']['config'][3]; + $dateOff .= mb_detect_encoding(date('H:i', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff'])), 'UTF-8', true) + ? date('H:i', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff'])) + : utf8_encode(date('H:i', $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'publishedOff']))); + } + } else { + $dateOff = $text['news']['config'][1]; + } + self::$news[] = [ + $this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'title']), + $dateOn, + $dateOff, + $states[$this->getData(['module', $this->getUrl(0),'posts', $newsIds[$i], 'state'])], + template::button('newsConfigEdit' . $newsIds[$i], [ + 'href' => helper::baseUrl() . $this->getUrl(0) . '/edit/' . $newsIds[$i]. '/' . $_SESSION['csrf'], + 'value' => template::ico('pencil') + ]), + template::button('newsConfigDelete' . $newsIds[$i], [ + 'class' => 'newsConfigDelete buttonRed', + 'href' => helper::baseUrl() . $this->getUrl(0) . '/delete/' . $newsIds[$i] . '/' . $_SESSION['csrf'], + 'value' => template::ico('cancel'), + 'disabled' => $this->getUser('group') >= self::GROUP_MODERATOR ? false : true + ]) + ]; + } + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['news']['config'][2], + 'view' => 'config', + 'vendor' => [ + 'tinycolorpicker' + ] + ]); + } + } + } + + /** + * Suppression + */ + public function delete() { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < news::$actions['delete'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./module/news/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_news.php'); + // La news n'existe pas + if($this->getData(['module', $this->getUrl(0),'posts', $this->getUrl(2)]) === null) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } + // Jeton incorrect + elseif ($this->getUrl(3) !== $_SESSION['csrf']) { + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['news']['delete'][0] + ]); + } + // Suppression + else { + $this->deleteData(['module', $this->getUrl(0),'posts', $this->getUrl(2)]); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['news']['delete'][1], + 'state' => true + ]); + } + } + } + + /** + * Édition + */ + public function edit() { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < news::$actions['edit'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./module/news/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_news.php'); + // Jeton incorrect + if ($this->getUrl(3) !== $_SESSION['csrf']) { + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['news']['edit'][0] + ]); + } + // La news n'existe pas + if($this->getData(['module', $this->getUrl(0),'posts', $this->getUrl(2)]) === null) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } + // La news existe + else { + // Soumission du formulaire + if($this->isPost()) { + // Si l'id a changée + $newsId = $this->getInput('newsEditTitle', helper::FILTER_ID, true); + if($newsId !== $this->getUrl(2)) { + // Incrémente le nouvel id de la news + $newsId = helper::increment($newsId, $this->getData(['module', $this->getUrl(0), 'posts'])); + // Supprime l'ancien news + $this->deleteData(['module', $this->getUrl(0),'posts', $this->getUrl(2)]); + } + $publishedOn = $this->getInput('newsEditPublishedOn', helper::FILTER_DATETIME, true); + $publishedOff = $this->getInput('newsEditPublishedOff' ) ? $this->getInput('newsEditPublishedOff', helper::FILTER_DATETIME) : ''; + $this->setData(['module', $this->getUrl(0),'posts', $newsId, [ + 'content' => $this->getInput('newsEditContent', null), + 'publishedOn' => $publishedOn, + 'publishedOff' => $publishedOff < $publishedOn ? '' : $publishedOff, + 'state' => $this->getInput('newsEditState', helper::FILTER_BOOLEAN), + 'title' => $this->getInput('newsEditTitle', helper::FILTER_STRING_SHORT, true), + 'userId' => $this->getInput('newsEditUserId', helper::FILTER_ID, true) + ]]); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['news']['edit'][1], + 'state' => true + ]); + } + // Liste des utilisateurs + self::$users = helper::arrayCollumn($this->getData(['user']), 'firstname'); + ksort(self::$users); + foreach(self::$users as $userId => &$userFirstname) { + $userFirstname = $userFirstname . ' ' . $this->getData(['user', $userId, 'lastname']); + } + unset($userFirstname); + // Valeurs en sortie + $this->addOutput([ + 'title' => $this->getData(['module', $this->getUrl(0),'posts', $this->getUrl(2), 'title']), + 'vendor' => [ + 'flatpickr', + 'tinymce' + ], + 'view' => 'edit' + ]); + } + } + } + /** * Accueil */ diff --git a/module/redirection/redirection.php b/module/redirection/redirection.php index 413068f..96db62a 100644 --- a/module/redirection/redirection.php +++ b/module/redirection/redirection.php @@ -34,24 +34,34 @@ class redirection extends common { * Configuration */ public function config() { - // Lexique - include('./module/redirection/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_redirection.php'); - - // Soumission du formulaire - if($this->isPost()) { - $this->setData(['module', $this->getUrl(0), 'url', $this->getInput('redirectionConfigUrl', helper::FILTER_URL, true)]); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < redirection::$actions['config'] ) { // Valeurs en sortie $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(), - 'notification' => $text['redirection']['config'][0], - 'state' => true + 'access' => false + ]); + } else { + // Lexique + include('./module/redirection/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_redirection.php'); + + // Soumission du formulaire + if($this->isPost()) { + $this->setData(['module', $this->getUrl(0), 'url', $this->getInput('redirectionConfigUrl', helper::FILTER_URL, true)]); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(), + 'notification' => $text['redirection']['config'][0], + 'state' => true + ]); + } + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['redirection']['config'][1], + 'view' => 'config' ]); } - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['redirection']['config'][1], - 'view' => 'config' - ]); } /** diff --git a/module/search/search.php b/module/search/search.php index 03a472a..df31a14 100644 --- a/module/search/search.php +++ b/module/search/search.php @@ -142,53 +142,63 @@ class search extends common { // Configuration vide public function config() { - // Lexique - include('./module/search/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_search.php'); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < search::$actions['config'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./module/search/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_search.php'); - // Mise à jour des données de module - $this->update(); + // Mise à jour des données de module + $this->update(); - if($this->isPost()) { + if($this->isPost()) { - // Générer la feuille de CSS - $style = '.keywordColor {background:' . $this->getInput('searchKeywordColor') . ';}'; - $success = file_put_contents(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css' , $style ); - // Fin feuille de style + // Générer la feuille de CSS + $style = '.keywordColor {background:' . $this->getInput('searchKeywordColor') . ';}'; + $success = file_put_contents(self::DATADIRECTORY . $this->getUrl(0) . '/theme.css' , $style ); + // Fin feuille de style - // Soumission du formulaire - $this->setData(['module', $this->getUrl(0), 'config',[ - 'submitText' => $this->getInput('searchSubmitText'), - 'placeHolder' => $this->getInput('searchPlaceHolder'), - 'resultHideContent' => $this->getInput('searchResultHideContent',helper::FILTER_BOOLEAN), - 'previewLength' => $this->getInput('searchPreviewLength',helper::FILTER_INT), - 'versionData' => $this->getData(['module', $this->getUrl(0), 'config', 'versionData']), - 'nearWordText' => $this->getInput('searchNearWordText'), - 'successTitle' => $this->getInput('searchSuccessTitle'), - 'failureTitle' => $this->getInput('searchFailureTitle'), - 'commentFailureTitle'=> $this->getInput('searchCommentFailureTitle') - ]]); - $this->setData(['module', $this->getUrl(0), 'theme',[ - 'keywordColor' => $this->getInput('searchKeywordColor'), - 'style' => $success ? self::DATADIRECTORY . $this->getUrl(0) . '/theme.css' : '', - ]]); + // Soumission du formulaire + $this->setData(['module', $this->getUrl(0), 'config',[ + 'submitText' => $this->getInput('searchSubmitText'), + 'placeHolder' => $this->getInput('searchPlaceHolder'), + 'resultHideContent' => $this->getInput('searchResultHideContent',helper::FILTER_BOOLEAN), + 'previewLength' => $this->getInput('searchPreviewLength',helper::FILTER_INT), + 'versionData' => $this->getData(['module', $this->getUrl(0), 'config', 'versionData']), + 'nearWordText' => $this->getInput('searchNearWordText'), + 'successTitle' => $this->getInput('searchSuccessTitle'), + 'failureTitle' => $this->getInput('searchFailureTitle'), + 'commentFailureTitle'=> $this->getInput('searchCommentFailureTitle') + ]]); + $this->setData(['module', $this->getUrl(0), 'theme',[ + 'keywordColor' => $this->getInput('searchKeywordColor'), + 'style' => $success ? self::DATADIRECTORY . $this->getUrl(0) . '/theme.css' : '', + ]]); + // Valeurs en sortie, affichage du formulaire + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(), + 'notification' => $success !== FALSE ? $text['search']['config'][0] : $text['search']['config'][1], + 'state' => $success !== FALSE + ]); + + } // Valeurs en sortie, affichage du formulaire $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(), - 'notification' => $success !== FALSE ? $text['search']['config'][0] : $text['search']['config'][1], - 'state' => $success !== FALSE + 'title' => $text['search']['config'][2], + 'view' => 'config', + 'vendor' => [ + 'tinycolorpicker' + ] ]); - } - // Valeurs en sortie, affichage du formulaire - $this->addOutput([ - 'title' => $text['search']['config'][2], - 'view' => 'config', - 'vendor' => [ - 'tinycolorpicker' - ] - ]); } public function index() { diff --git a/module/slider/slider.php b/module/slider/slider.php index 6e8c83d..7521600 100644 --- a/module/slider/slider.php +++ b/module/slider/slider.php @@ -119,131 +119,141 @@ class slider extends common { * Configuration */ public function config() { - // Lexique - include('./module/slider/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_slider.php'); - // Liste des dossiers dans site/file/source triés et non vides - $filter = ['jpg', 'jpeg', 'png', 'gif', 'tiff', 'ico', 'webp']; - self::$listDirs = helper::scanDir(self::FILE_DIR.'source', $filter); - sort(self::$listDirs); - // Liste des pages pour les liens sur image - self::$pageList['-']=''; - foreach ($this->getHierarchy(null,null,null) as $parentKey=>$parentValue) { - // Exclusions les barres, les pages masquées ou non publiques - if ($this->getData(['page',$parentKey,'group']) !== 0 || - $this->getData(['page', $parentKey, 'block']) === 'bar' ) { - continue; - } - self::$pageList [$parentKey] = $parentKey; - foreach ($parentValue as $childKey) { - self::$pageList [$childKey] = $childKey; - } - } - // Valeurs par défaut si le slider n'existe pas encore - if($this->getData(['module', $this->getUrl(0), 'config', 'directory']) === null){ - $this->setData(['module', $this->getUrl(0), [ - 'config' => [ - 'directory' => self::$listDirs[0], - 'boutonsVisibles' => 'slider2', - 'pagerVisible' => 'true', - 'maxiWidth' => '800', - 'fadingTime' => '1500', - 'sliderTime' => '5000', - 'visibiliteLegende' => 'survol', - 'positionLegende' => 'bas', - 'tempsApparition' => 'opacity 2s ease-in', - 'typeBouton' => 'cer_blanc', - 'tri' => 'SORT_ASC', - 'versionData' => self::VERSION - ], - 'legend' => [], - 'href' => [] - ]]); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < slider::$actions['config'] ) { // Valeurs en sortie $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => 'slider init', - 'state' => true - ]); - } - - // Soumission du formulaire - if($this->isPost()) { - $legends = []; - foreach((array) $this->getInput('legend', null) as $file => $legend) { - $file = str_replace('.','',$file); - $legends[$file] = helper::filter($legend, helper::FILTER_STRING_SHORT); - } - - $hrefs = []; - foreach((array) $this->getInput('sliderHref', null) as $file => $href) { - $file = str_replace('.','',$file); - $hrefs[$file] = self::$pageList[helper::filter($href, helper::FILTER_STRING_SHORT)]; - } - - $this->setData(['module', $this->getUrl(0), [ - 'config' => [ - 'directory' => self::$listDirs[$this->getInput('galleryEditDirectory')], - 'boutonsVisibles' => $this->getInput('sliderBoutonsVisibles', helper::FILTER_STRING_SHORT, true), - 'pagerVisible' => $this->getInput('sliderPagerVisible', helper::FILTER_STRING_SHORT, true), - 'maxiWidth' => $this->getInput('sliderMaxiWidth', helper::FILTER_STRING_SHORT, true), - 'fadingTime' => $this->getInput('sliderFadingTime', helper::FILTER_STRING_SHORT, true), - 'sliderTime' => $this->getInput('sliderDiapoTime', helper::FILTER_STRING_SHORT, true), - 'visibiliteLegende' => $this->getInput('sliderVisibiliteLegende', helper::FILTER_STRING_SHORT, true), - 'positionLegende' => $this->getInput('sliderPositionLegende', helper::FILTER_STRING_SHORT, true), - 'tempsApparition' => $this->getInput('sliderTempsApparition', helper::FILTER_STRING_SHORT, true), - 'typeBouton' => $this->getInput('sliderTypeBouton', helper::FILTER_STRING_SHORT, true), - 'tri' => $this->getInput('sliderTri', helper::FILTER_STRING_SHORT, true), - 'versionData' => self::VERSION - ], - 'legend' => $legends, - 'href' => $hrefs - ]]); - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['slider']['edit'][1], - 'state' => true - ]); - } - // Met en forme le tableau - $directory = $this->getData(['module', $this->getUrl(0), '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::text('legend[' . $fileInfos->getFilename() . ']', [ - 'value' => $this->getData(['module', $this->getUrl(0), 'legend', str_replace('.','',$fileInfos->getFilename())]) - ]), - template::select('sliderHref[' . $fileInfos->getFilename() . ']', self::$pageList,[ - 'selected' => array_flip(self::$pageList)[$this->getData(['module', $this->getUrl(0), 'href', str_replace('.','',$fileInfos->getFilename())])] - ]) - ]; + 'access' => false + ]); + } else { + // Lexique + include('./module/slider/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_slider.php'); + // Liste des dossiers dans site/file/source triés et non vides + $filter = ['jpg', 'jpeg', 'png', 'gif', 'tiff', 'ico', 'webp']; + self::$listDirs = helper::scanDir(self::FILE_DIR.'source', $filter); + sort(self::$listDirs); + // Liste des pages pour les liens sur image + self::$pageList['-']=''; + foreach ($this->getHierarchy(null,null,null) as $parentKey=>$parentValue) { + // Exclusions les barres, les pages masquées ou non publiques + if ($this->getData(['page',$parentKey,'group']) !== 0 || + $this->getData(['page', $parentKey, 'block']) === 'bar' ) { + continue; + } + self::$pageList [$parentKey] = $parentKey; + foreach ($parentValue as $childKey) { + self::$pageList [$childKey] = $childKey; } } - // Tri des images pour affichage de la liste dans la page de configuration - switch ($this->getData(['module', $this->getUrl(0), 'config', 'tri'])) { - case 'SORT_DSC': - krsort(self::$pictures,SORT_NATURAL | SORT_FLAG_CASE); - break; - case 'SORT_ASC': - ksort(self::$pictures,SORT_NATURAL | SORT_FLAG_CASE); - break; - case 'RAND': - // sans intérêt ici - break; - case 'NONE': - break; - default: - break; + // Valeurs par défaut si le slider n'existe pas encore + if($this->getData(['module', $this->getUrl(0), 'config', 'directory']) === null){ + $this->setData(['module', $this->getUrl(0), [ + 'config' => [ + 'directory' => self::$listDirs[0], + 'boutonsVisibles' => 'slider2', + 'pagerVisible' => 'true', + 'maxiWidth' => '800', + 'fadingTime' => '1500', + 'sliderTime' => '5000', + 'visibiliteLegende' => 'survol', + 'positionLegende' => 'bas', + 'tempsApparition' => 'opacity 2s ease-in', + 'typeBouton' => 'cer_blanc', + 'tri' => 'SORT_ASC', + 'versionData' => self::VERSION + ], + 'legend' => [], + 'href' => [] + ]]); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => 'slider init', + 'state' => true + ]); } + + // Soumission du formulaire + if($this->isPost()) { + $legends = []; + foreach((array) $this->getInput('legend', null) as $file => $legend) { + $file = str_replace('.','',$file); + $legends[$file] = helper::filter($legend, helper::FILTER_STRING_SHORT); + } + + $hrefs = []; + foreach((array) $this->getInput('sliderHref', null) as $file => $href) { + $file = str_replace('.','',$file); + $hrefs[$file] = self::$pageList[helper::filter($href, helper::FILTER_STRING_SHORT)]; + } + + $this->setData(['module', $this->getUrl(0), [ + 'config' => [ + 'directory' => self::$listDirs[$this->getInput('galleryEditDirectory')], + 'boutonsVisibles' => $this->getInput('sliderBoutonsVisibles', helper::FILTER_STRING_SHORT, true), + 'pagerVisible' => $this->getInput('sliderPagerVisible', helper::FILTER_STRING_SHORT, true), + 'maxiWidth' => $this->getInput('sliderMaxiWidth', helper::FILTER_STRING_SHORT, true), + 'fadingTime' => $this->getInput('sliderFadingTime', helper::FILTER_STRING_SHORT, true), + 'sliderTime' => $this->getInput('sliderDiapoTime', helper::FILTER_STRING_SHORT, true), + 'visibiliteLegende' => $this->getInput('sliderVisibiliteLegende', helper::FILTER_STRING_SHORT, true), + 'positionLegende' => $this->getInput('sliderPositionLegende', helper::FILTER_STRING_SHORT, true), + 'tempsApparition' => $this->getInput('sliderTempsApparition', helper::FILTER_STRING_SHORT, true), + 'typeBouton' => $this->getInput('sliderTypeBouton', helper::FILTER_STRING_SHORT, true), + 'tri' => $this->getInput('sliderTri', helper::FILTER_STRING_SHORT, true), + 'versionData' => self::VERSION + ], + 'legend' => $legends, + 'href' => $hrefs + ]]); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['slider']['edit'][1], + 'state' => true + ]); + } + // Met en forme le tableau + $directory = $this->getData(['module', $this->getUrl(0), '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::text('legend[' . $fileInfos->getFilename() . ']', [ + 'value' => $this->getData(['module', $this->getUrl(0), 'legend', str_replace('.','',$fileInfos->getFilename())]) + ]), + template::select('sliderHref[' . $fileInfos->getFilename() . ']', self::$pageList,[ + 'selected' => array_flip(self::$pageList)[$this->getData(['module', $this->getUrl(0), 'href', str_replace('.','',$fileInfos->getFilename())])] + ]) + ]; + } + } + // Tri des images pour affichage de la liste dans la page de configuration + switch ($this->getData(['module', $this->getUrl(0), 'config', 'tri'])) { + case 'SORT_DSC': + krsort(self::$pictures,SORT_NATURAL | SORT_FLAG_CASE); + break; + case 'SORT_ASC': + ksort(self::$pictures,SORT_NATURAL | SORT_FLAG_CASE); + break; + case 'RAND': + // sans intérêt ici + break; + case 'NONE': + break; + default: + break; + } + } + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['slider']['config'][3], + 'view' => 'config' + ]); } - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['slider']['config'][3], - 'view' => 'config' - ]); } /** diff --git a/module/statislite/statislite.php b/module/statislite/statislite.php index e84c248..03bacd7 100644 --- a/module/statislite/statislite.php +++ b/module/statislite/statislite.php @@ -32,7 +32,7 @@ class statislite extends common { 'conversionTime' => self::GROUP_VISITOR ]; - const VERSION = '4.8'; + const VERSION = '4.9'; const REALNAME = 'Statislite'; const DELETE = true; const UPDATE = '2.6'; @@ -97,9 +97,9 @@ class statislite extends common { copy('./module/statislite/ressource/download_counter/download_counter.php', self::DATAMODULE.'/download_counter/download_counter.php'); $this->setData(['module', $this->getUrl(0), 'config', 'versionData','4.7']); } - // Version 4.8 - if (version_compare($this->getData(['module', $this->getUrl(0), 'config', 'versionData']), '4.8', '<') ) { - $this->setData(['module', $this->getUrl(0), 'config', 'versionData','4.8']); + // Version 4.9 + if (version_compare($this->getData(['module', $this->getUrl(0), 'config', 'versionData']), '4.9', '<') ) { + $this->setData(['module', $this->getUrl(0), 'config', 'versionData','4.9']); } } @@ -107,128 +107,138 @@ class statislite extends common { * Configuration */ public function config() { - // Lexique - include('./module/statislite/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_statislite.php'); - - // Détection d'un changement de nom de la page statistique pour mettre à jour listeQS - if( is_file( self::$fichiers_json.'filtre_primaire.json')){ - $json = file_get_contents(self::$fichiers_json.'filtre_primaire.json'); - $fp = json_decode($json, true); - $PageStat = 0; - if(isset( $fp['listeQS'])){ - if( ! empty($fp['listeQS'])){ - foreach( $fp['listeQS'] as $key=>$PageQS){ - if( $PageQS == $this->getUrl(0) ) $PageStat = 1; - } - } - if( $PageStat === 0 ){ - $fp['listeQS'][count($fp['listeQS'])] = $this->getUrl(0); - // Suppression des pages inconnues de la listeQS - $i=0; - foreach($this->getData(['page']) as $key=>$page){ - self::$listePages[$i] = $this->getData(['page', $key, 'title']); - $i++; - } - foreach( $fp['listeQS'] as $keyQS=>$PageQS){ - $noexist = true; - foreach( self::$listePages as $keyPage=>$Page){ - $Pagemod = strtolower(str_replace(' ','-',$Page)); - if( $PageQS === $Pagemod) $noexist = false; + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < statislite::$actions['config'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./module/statislite/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_statislite.php'); + + // Détection d'un changement de nom de la page statistique pour mettre à jour listeQS + if( is_file( self::$fichiers_json.'filtre_primaire.json')){ + $json = file_get_contents(self::$fichiers_json.'filtre_primaire.json'); + $fp = json_decode($json, true); + $PageStat = 0; + if(isset( $fp['listeQS'])){ + if( ! empty($fp['listeQS'])){ + foreach( $fp['listeQS'] as $key=>$PageQS){ + if( $PageQS == $this->getUrl(0) ) $PageStat = 1; + } + } + if( $PageStat === 0 ){ + $fp['listeQS'][count($fp['listeQS'])] = $this->getUrl(0); + // Suppression des pages inconnues de la listeQS + $i=0; + foreach($this->getData(['page']) as $key=>$page){ + self::$listePages[$i] = $this->getData(['page', $key, 'title']); + $i++; + } + foreach( $fp['listeQS'] as $keyQS=>$PageQS){ + $noexist = true; + foreach( self::$listePages as $keyPage=>$Page){ + $Pagemod = strtolower(str_replace(' ','-',$Page)); + if( $PageQS === $Pagemod) $noexist = false; + } + if( $noexist ) unset( $fp['listeQS'][$keyQS]); } - if( $noexist ) unset( $fp['listeQS'][$keyQS]); } } } - } - else{ - $json = '{}'; - $fp= json_decode($json, true); - $fp['robots'] = array( 'ua' => 0, 'ip'=> 0); - $fp['listeIP'] = []; - $fp['listeQS'] = array( 0 => $this->getUrl(0)); - $fp['listeBot'] = []; - } - $json = json_encode($fp); - file_put_contents(self::$fichiers_json.'filtre_primaire.json',$json); - - // Soumission du formulaire - if($this->isPost()) { - $this->setData(['module', $this->getUrl(0), 'config',[ - 'timeVisiteMini' => $this->getInput('statisliteConfigTimeVisiteMini', helper::FILTER_STRING_SHORT, true), - 'timePageMini' => $this->getInput('statisliteConfigTimePageMini', helper::FILTER_STRING_SHORT, true), - 'nbPageMini' => $this->getInput('statisliteConfigNbPageMini', helper::FILTER_STRING_SHORT, true), - 'usersExclus' => $this->getInput('statisliteConfigUsersExclus', helper::FILTER_STRING_SHORT, true), - 'nbEnregSession' => $this->getInput('statisliteConfigNbEnregSession', helper::FILTER_STRING_SHORT, true), - 'geolocalisation' => $this->getInput('statisliteConfigGeolocalisation', helper::FILTER_BOOLEAN), - 'nbaffipagesvues' => $this->getInput('statisliteConfigNbAffiPagesVues'), - 'nbaffilangues' => $this->getInput('statisliteConfigNbAffiLangues'), - 'nbaffinavigateurs' => $this->getInput('statisliteConfigNbAffiNavigateurs'), - 'nbaffise' => $this->getInput('statisliteConfigNbAffiSe'), - 'nbaffipays' => $this->getInput('statisliteConfigNbAffiPays'), - 'nbaffidates' => $this->getInput('statisLiteConfigNbAffiDates'), - 'config' => true, - 'versionData' => $this->getData(['module', $this->getUrl(0), 'config', 'versionData']) - ]]); - // Validation des statistiques - $this->setData(['config', 'statislite', 'enable', true]); + else{ + $json = '{}'; + $fp= json_decode($json, true); + $fp['robots'] = array( 'ua' => 0, 'ip'=> 0); + $fp['listeIP'] = []; + $fp['listeQS'] = array( 0 => $this->getUrl(0)); + $fp['listeBot'] = []; + } + $json = json_encode($fp); + file_put_contents(self::$fichiers_json.'filtre_primaire.json',$json); - // Mise à jour forcée des fichiers navigateurs.txt, systemes.txt et langages.txt - $majForce = $this->getInput('statisliteConfigMajForce', helper::FILTER_BOOLEAN); - if( $majForce === true ){ - copy( './module/statislite/ressource/navigateurs.txt', self::$base.'navigateurs.txt'); - copy( './module/statislite/ressource/langages.txt', self::$base.'langages.txt'); - copy( './module/statislite/ressource/systemes.txt', self::$base.'systemes.txt'); - } + // Soumission du formulaire + if($this->isPost()) { + $this->setData(['module', $this->getUrl(0), 'config',[ + 'timeVisiteMini' => $this->getInput('statisliteConfigTimeVisiteMini', helper::FILTER_STRING_SHORT, true), + 'timePageMini' => $this->getInput('statisliteConfigTimePageMini', helper::FILTER_STRING_SHORT, true), + 'nbPageMini' => $this->getInput('statisliteConfigNbPageMini', helper::FILTER_STRING_SHORT, true), + 'usersExclus' => $this->getInput('statisliteConfigUsersExclus', helper::FILTER_STRING_SHORT, true), + 'nbEnregSession' => $this->getInput('statisliteConfigNbEnregSession', helper::FILTER_STRING_SHORT, true), + 'geolocalisation' => $this->getInput('statisliteConfigGeolocalisation', helper::FILTER_BOOLEAN), + 'nbaffipagesvues' => $this->getInput('statisliteConfigNbAffiPagesVues'), + 'nbaffilangues' => $this->getInput('statisliteConfigNbAffiLangues'), + 'nbaffinavigateurs' => $this->getInput('statisliteConfigNbAffiNavigateurs'), + 'nbaffise' => $this->getInput('statisliteConfigNbAffiSe'), + 'nbaffipays' => $this->getInput('statisliteConfigNbAffiPays'), + 'nbaffidates' => $this->getInput('statisLiteConfigNbAffiDates'), + 'config' => true, + 'versionData' => $this->getData(['module', $this->getUrl(0), 'config', 'versionData']) + ]]); + // Validation des statistiques + $this->setData(['config', 'statislite', 'enable', true]); + + // Mise à jour forcée des fichiers navigateurs.txt, systemes.txt et langages.txt + $majForce = $this->getInput('statisliteConfigMajForce', helper::FILTER_BOOLEAN); + if( $majForce === true ){ + copy( './module/statislite/ressource/navigateurs.txt', self::$base.'navigateurs.txt'); + copy( './module/statislite/ressource/langages.txt', self::$base.'langages.txt'); + copy( './module/statislite/ressource/systemes.txt', self::$base.'systemes.txt'); + } - // Restauration si le fichier sélectionné est un fichier cumul.json - $file_cumul = $this->getInput('configRestoreJson', helper::FILTER_STRING_SHORT); - if( strpos( $file_cumul, 'cumul.json' ) === 15){ - // Sauvegarde de sécurité des fichiers json - $this->sauvegardeJson(); - $date = substr( $file_cumul, 0 , 15); - $nameFile = [ '0'=>'cumul.json', '1'=>'affitampon.json', '2'=>'chrono.json', '3'=>'robots.json', '4'=>'sessionInvalide.json', '5'=>'sessionLog.json', ]; - foreach( $nameFile as $key=>$file){ - if( is_file( self::$json_sauve.$date.$file )){ - file_put_contents(self::$fichiers_json.$file, file_get_contents(self::$json_sauve.$date.$file)); + // Restauration si le fichier sélectionné est un fichier cumul.json + $file_cumul = $this->getInput('configRestoreJson', helper::FILTER_STRING_SHORT); + if( strpos( $file_cumul, 'cumul.json' ) === 15){ + // Sauvegarde de sécurité des fichiers json + $this->sauvegardeJson(); + $date = substr( $file_cumul, 0 , 15); + $nameFile = [ '0'=>'cumul.json', '1'=>'affitampon.json', '2'=>'chrono.json', '3'=>'robots.json', '4'=>'sessionInvalide.json', '5'=>'sessionLog.json', ]; + foreach( $nameFile as $key=>$file){ + if( is_file( self::$json_sauve.$date.$file )){ + file_put_contents(self::$fichiers_json.$file, file_get_contents(self::$json_sauve.$date.$file)); + } } } + + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl().$this->getUrl(), + 'notification' => $text['statislite']['config'][1], + 'state' => true + ]); } - - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl().$this->getUrl(), - 'notification' => $text['statislite']['config'][1], - 'state' => true - ]); - } - else{ - // Liste des fichiers de sauvegarde - if(is_dir( self::$json_sauve )) { - $dir = self::$json_sauve; - self::$filesSaved = scandir($dir); - //Ne conserver que les fichiers xxxxxxxxx_cumul.json - foreach( self::$filesSaved as $key=>$val){ - if( strpos($val, 'cumul.json') === false){ - unset( self::$filesSaved[$key]); - } + else{ + // Liste des fichiers de sauvegarde + if(is_dir( self::$json_sauve )) { + $dir = self::$json_sauve; + self::$filesSaved = scandir($dir); + //Ne conserver que les fichiers xxxxxxxxx_cumul.json + foreach( self::$filesSaved as $key=>$val){ + if( strpos($val, 'cumul.json') === false){ + unset( self::$filesSaved[$key]); + } + } + if (count(self::$filesSaved) === 0 ){ + self::$filesSaved = array(0 => $text['statislite']['config'][2]); + } + else{ + self::$filesSaved[0] = $text['statislite']['config'][0]; + // clef = valeur pour renvoyer le nom du fichier et non la clef de type numméro + self::$filesSaved= array_combine(self::$filesSaved,self::$filesSaved); + } } - if (count(self::$filesSaved) === 0 ){ - self::$filesSaved = array(0 => $text['statislite']['config'][2]); - } - else{ - self::$filesSaved[0] = $text['statislite']['config'][0]; - // clef = valeur pour renvoyer le nom du fichier et non la clef de type numméro - self::$filesSaved= array_combine(self::$filesSaved,self::$filesSaved); + else { + self::$filesSaved = array(0 => $text['statislite']['config'][3]); } + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['statislite']['config'][4], + 'view' => 'config' + ]); } - else { - self::$filesSaved = array(0 => $text['statislite']['config'][3]); - } - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['statislite']['config'][4], - 'view' => 'config' - ]); } } @@ -236,157 +246,167 @@ class statislite extends common { * Configuration avancée */ public function advanced() { - // Lexique - include('./module/statislite/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_statislite.php'); - - // Liste des pages du site - $i=0; - foreach($this->getData(['page']) as $key=>$page){ - self::$listePages[$i] = $this->getData(['page', $key, 'title']); - $i++; - } - - // Retour de formulaire - if($this->isPost()) { - // Lecture des données postées bloc IP - $addIP = $this->getInput('statisliteAddIp', helper::FILTER_BOOLEAN); - $supIP = $this->getInput('statisliteSupIp', helper::FILTER_BOOLEAN); - $addressIP = $this->getInput('statisliteEditIP', helper::FILTER_STRING_SHORT); - // Bloc Pages - $addQS = $this->getInput('statisliteAddQS', helper::FILTER_BOOLEAN); - $supQS = $this->getInput('statisliteSupQS', helper::FILTER_BOOLEAN); - $pageQS = self::$listePages[$this->getInput('statisliteEditQS', helper::FILTER_STRING_SHORT)]; - $pageQS = strtolower(str_replace(' ', '-', $pageQS)); - // Bloc robots - $addBot = $this->getInput('statisliteAddBot', helper::FILTER_BOOLEAN); - $supBot = $this->getInput('statisliteSupBot', helper::FILTER_BOOLEAN); - $robot = $this->getInput('statisliteEditBot', helper::FILTER_STRING_SHORT); - - // Ouverture et décodage du fichier json - $json = file_get_contents(self::$fichiers_json.'filtre_primaire.json'); - $fp = json_decode($json, true); - - // Ajout ou suppression d'adresses IP - if ($addIP){ - // Ajout seulement si l'entrée n'existe pas - $noexist =true; - foreach( $fp['listeIP'] as $key=>$value){ - if($value === $addressIP){ - $noexist = false; - break; - } - } - if($noexist) $fp['listeIP'][ count($fp['listeIP'])] = $addressIP; - } - // Suppression si l'entrée existe - elseif( $supIP ){ - foreach( $fp['listeIP'] as $key=>$value){ - if( $value === $addressIP){ - unset($fp['listeIP'][$key]); - $fp['listeIP'] = array_values($fp['listeIP']); - break; - } - } - } - - // Ajout ou suppression de pages à exclure - if ($addQS){ - // Ajout seulement si l'entrée n'existe pas - $noexist =true; - foreach( $fp['listeQS'] as $key=>$value){ - if($value === $pageQS){ - $noexist = false; - break; - } - } - if($noexist) $fp['listeQS'][ count($fp['listeQS'])] = $pageQS; - } - // Suppression si l'entrée existe - elseif( $supQS ){ - foreach( $fp['listeQS'] as $key=>$value){ - if( $value === $pageQS){ - unset($fp['listeQS'][$key]); - $fp['listeQS'] = array_values($fp['listeQS']); - break; - } - } - } - // Ajout ou suppression de robots - if ($addBot){ - // Ajout seulement si l'entrée n'existe pas - $noexist =true; - foreach( $fp['listeBot'] as $key=>$value){ - if($value === $robot){ - $noexist = false; - break; - } - } - if($noexist) $fp['listeBot'][ count($fp['listeBot'])] = $robot; - } - // Suppression si l'entrée existe - elseif( $supBot ){ - foreach( $fp['listeBot'] as $key=>$value){ - if( $value === $robot){ - unset($fp['listeBot'][$key]); - $fp['listeBot'] = array_values($fp['listeBot']); - break; - } - } - } - - // Encodage et fermeture du fichier json - $json = json_encode($fp); - file_put_contents(self::$fichiers_json.'filtre_primaire.json',$json); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < statislite::$actions['advanced'] ) { // Valeurs en sortie $this->addOutput([ - 'redirect' => helper::baseUrl().$this->getUrl(), - 'notification' => $text['statislite']['advanced'][0], - 'state' => true + 'access' => false + ]); + } else { + // Lexique + include('./module/statislite/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_statislite.php'); + + // Liste des pages du site + $i=0; + foreach($this->getData(['page']) as $key=>$page){ + self::$listePages[$i] = $this->getData(['page', $key, 'title']); + $i++; + } + + // Retour de formulaire + if($this->isPost()) { + // Lecture des données postées bloc IP + $addIP = $this->getInput('statisliteAddIp', helper::FILTER_BOOLEAN); + $supIP = $this->getInput('statisliteSupIp', helper::FILTER_BOOLEAN); + $addressIP = $this->getInput('statisliteEditIP', helper::FILTER_STRING_SHORT); + // Bloc Pages + $addQS = $this->getInput('statisliteAddQS', helper::FILTER_BOOLEAN); + $supQS = $this->getInput('statisliteSupQS', helper::FILTER_BOOLEAN); + $pageQS = self::$listePages[$this->getInput('statisliteEditQS', helper::FILTER_STRING_SHORT)]; + $pageQS = strtolower(str_replace(' ', '-', $pageQS)); + // Bloc robots + $addBot = $this->getInput('statisliteAddBot', helper::FILTER_BOOLEAN); + $supBot = $this->getInput('statisliteSupBot', helper::FILTER_BOOLEAN); + $robot = $this->getInput('statisliteEditBot', helper::FILTER_STRING_SHORT); + + // Ouverture et décodage du fichier json + $json = file_get_contents(self::$fichiers_json.'filtre_primaire.json'); + $fp = json_decode($json, true); + + // Ajout ou suppression d'adresses IP + if ($addIP){ + // Ajout seulement si l'entrée n'existe pas + $noexist =true; + foreach( $fp['listeIP'] as $key=>$value){ + if($value === $addressIP){ + $noexist = false; + break; + } + } + if($noexist) $fp['listeIP'][ count($fp['listeIP'])] = $addressIP; + } + // Suppression si l'entrée existe + elseif( $supIP ){ + foreach( $fp['listeIP'] as $key=>$value){ + if( $value === $addressIP){ + unset($fp['listeIP'][$key]); + $fp['listeIP'] = array_values($fp['listeIP']); + break; + } + } + } + + // Ajout ou suppression de pages à exclure + if ($addQS){ + // Ajout seulement si l'entrée n'existe pas + $noexist =true; + foreach( $fp['listeQS'] as $key=>$value){ + if($value === $pageQS){ + $noexist = false; + break; + } + } + if($noexist) $fp['listeQS'][ count($fp['listeQS'])] = $pageQS; + } + // Suppression si l'entrée existe + elseif( $supQS ){ + foreach( $fp['listeQS'] as $key=>$value){ + if( $value === $pageQS){ + unset($fp['listeQS'][$key]); + $fp['listeQS'] = array_values($fp['listeQS']); + break; + } + } + } + // Ajout ou suppression de robots + if ($addBot){ + // Ajout seulement si l'entrée n'existe pas + $noexist =true; + foreach( $fp['listeBot'] as $key=>$value){ + if($value === $robot){ + $noexist = false; + break; + } + } + if($noexist) $fp['listeBot'][ count($fp['listeBot'])] = $robot; + } + // Suppression si l'entrée existe + elseif( $supBot ){ + foreach( $fp['listeBot'] as $key=>$value){ + if( $value === $robot){ + unset($fp['listeBot'][$key]); + $fp['listeBot'] = array_values($fp['listeBot']); + break; + } + } + } + + // Encodage et fermeture du fichier json + $json = json_encode($fp); + file_put_contents(self::$fichiers_json.'filtre_primaire.json',$json); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl().$this->getUrl(), + 'notification' => $text['statislite']['advanced'][0], + 'state' => true + ]); + } + + // Données de filtrage primaire dans filtre_primaire.json avec les clefs 'listeIP', 'listeBot', 'listeQS' + $json = file_get_contents(self::$fichiers_json.'filtre_primaire.json'); + $fp = json_decode($json, true); + $tabListeIP = $fp['listeIP']; + $tabListeQS = $fp['listeQS']; + $tabListeBot = $fp['listeBot']; + + // Liste des IP filtrées + foreach( $tabListeIP as $key=>$value){ + self::$listeIP .= $value."\r\n"; + } + // Lecture de l'adresse IP + // Si internet partagé + self::$yourIP =''; + if (isset($_SERVER['HTTP_CLIENT_IP'])) { + self::$yourIP = $_SERVER['HTTP_CLIENT_IP']; + } + // Si derrière un proxy + elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { + self::$yourIP = $_SERVER['HTTP_X_FORWARDED_FOR']; + } + // Sinon : IP normale + else{ + if(isset($_SERVER['REMOTE_ADDR'])){ + self::$yourIP = $_SERVER['REMOTE_ADDR']; + } + } + // Liste des pages filtrées + foreach( $tabListeQS as $key=>$value){ + self::$listeQS .= $value."\r\n"; + } + + // Liste des robots + foreach( $tabListeBot as $key=>$value){ + self::$listeBot .= $value."\r\n"; + } + + // Valeurs en sortie + $this->addOutput([ + 'title' => $text['statislite']['advanced'][1], + 'view' => 'advanced' ]); } - - // Données de filtrage primaire dans filtre_primaire.json avec les clefs 'listeIP', 'listeBot', 'listeQS' - $json = file_get_contents(self::$fichiers_json.'filtre_primaire.json'); - $fp = json_decode($json, true); - $tabListeIP = $fp['listeIP']; - $tabListeQS = $fp['listeQS']; - $tabListeBot = $fp['listeBot']; - - // Liste des IP filtrées - foreach( $tabListeIP as $key=>$value){ - self::$listeIP .= $value."\r\n"; - } - // Lecture de l'adresse IP - // Si internet partagé - self::$yourIP =''; - if (isset($_SERVER['HTTP_CLIENT_IP'])) { - self::$yourIP = $_SERVER['HTTP_CLIENT_IP']; - } - // Si derrière un proxy - elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { - self::$yourIP = $_SERVER['HTTP_X_FORWARDED_FOR']; - } - // Sinon : IP normale - else{ - if(isset($_SERVER['REMOTE_ADDR'])){ - self::$yourIP = $_SERVER['REMOTE_ADDR']; - } - } - // Liste des pages filtrées - foreach( $tabListeQS as $key=>$value){ - self::$listeQS .= $value."\r\n"; - } - - // Liste des robots - foreach( $tabListeBot as $key=>$value){ - self::$listeBot .= $value."\r\n"; - } - - // Valeurs en sortie - $this->addOutput([ - 'title' => $text['statislite']['advanced'][1], - 'view' => 'advanced' - ]); } @@ -394,33 +414,43 @@ class statislite extends common { * Fonction initJson() */ public function initJson() { - // Lexique - include('./module/statislite/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_statislite.php'); - - // Jeton incorrect - if ($this->getUrl(2) !== $_SESSION['csrf']) { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < statislite::$actions['initJson'] ) { // Valeurs en sortie $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['statislite']['initJson'][0] - ]); + 'access' => false + ]); } else { - // Sauvegarde de sécurité des fichiers json - $this->sauvegardeJson(); - // Réinitialisation des fichiers json - $this -> initcumul(); - $this -> initchrono(); - file_put_contents( self::$fichiers_json.'robots.json', '{}'); - file_put_contents( self::$fichiers_json.'sessionInvalide.json', '{}'); - file_put_contents( self::$fichiers_json.'affitampon.json', '{}'); - file_put_contents( self::$fichiers_json.'sessionLog.json', '{}'); - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['statislite']['initJson'][1], - 'state' => true - ]); - + // Lexique + include('./module/statislite/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_statislite.php'); + + // Jeton incorrect + if ($this->getUrl(2) !== $_SESSION['csrf']) { + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['statislite']['initJson'][0] + ]); + } else { + // Sauvegarde de sécurité des fichiers json + $this->sauvegardeJson(); + // Réinitialisation des fichiers json + $this -> initcumul(); + $this -> initchrono(); + file_put_contents( self::$fichiers_json.'robots.json', '{}'); + file_put_contents( self::$fichiers_json.'sessionInvalide.json', '{}'); + file_put_contents( self::$fichiers_json.'affitampon.json', '{}'); + file_put_contents( self::$fichiers_json.'sessionLog.json', '{}'); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['statislite']['initJson'][1], + 'state' => true + ]); + + } } } @@ -429,44 +459,62 @@ class statislite extends common { * Fonction sauveJson() */ public function sauveJson() { - // Lexique - include('./module/statislite/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_statislite.php'); + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < statislite::$actions['sauveJson'] ) { + // Valeurs en sortie + $this->addOutput([ + 'access' => false + ]); + } else { + // Lexique + include('./module/statislite/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_statislite.php'); - // Sauvegarde des fichiers json - $this->sauvegardeJson(); - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['statislite']['sauveJson'][0], - 'state' => true - ]); - + // Sauvegarde des fichiers json + $this->sauvegardeJson(); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['statislite']['sauveJson'][0], + 'state' => true + ]); + } } /** * Fonction initDownload() */ public function initDownload() { - // Lexique - include('./module/statislite/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_statislite.php'); - - // Jeton incorrect - if ($this->getUrl(2) !== $_SESSION['csrf']) { + // Autorisation + $group = $this->getUser('group'); + if ($group === false ) $group = 0; + if( $group < statislite::$actions['initDownload'] ) { // Valeurs en sortie $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['statislite']['initDownload'][0] - ]); + 'access' => false + ]); } else { - // Réinitialisation du compteur de liens cliqués - file_put_contents( self::$downloadLink.'counter.json', '{}'); - // Valeurs en sortie - $this->addOutput([ - 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', - 'notification' => $text['statislite']['initDownload'][1], - 'state' => true - ]); - + // Lexique + include('./module/statislite/lang/'. $this->getData(['config', 'i18n', 'langAdmin']) . '/lex_statislite.php'); + + // Jeton incorrect + if ($this->getUrl(2) !== $_SESSION['csrf']) { + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['statislite']['initDownload'][0] + ]); + } else { + // Réinitialisation du compteur de liens cliqués + file_put_contents( self::$downloadLink.'counter.json', '{}'); + // Valeurs en sortie + $this->addOutput([ + 'redirect' => helper::baseUrl() . $this->getUrl(0) . '/config', + 'notification' => $text['statislite']['initDownload'][1], + 'state' => true + ]); + } } } @@ -484,6 +532,7 @@ class statislite extends common { $this->custom_copy('./module/statislite/ressource', self::DATAMODULE); if( !is_dir( self::DATAMODULE.'/json' )) mkdir( self::DATAMODULE.'/json', 0755); if( !is_dir( self::DATAMODULE.'/json_sauve' ))mkdir( self::DATAMODULE.'/json_sauve', 0755); + if( !is_dir( self::DATAMODULE.'/tmp' ))mkdir( self::DATAMODULE.'/tmp', 0755); $this->setData(['module', $this->getUrl(0), 'config',[ 'timeVisiteMini' => '30',