';
// Label
- if($attributes['label']) {
+ if ($attributes['label']) {
$html .= self::label($attributes['id'], $attributes['label'], [
'help' => $attributes['help']
]);
}
// Notice
$notice = '';
- if(array_key_exists($attributes['id'], common::$inputNotices)) {
+ if (array_key_exists($attributes['id'], common::$inputNotices)) {
$notice = common::$inputNotices[$attributes['id']];
$attributes['class'] .= ' notice';
}
@@ -887,12 +912,13 @@ class template {
}
/**
- * Crée un champ texte long
- * @param string $nameId Nom et id du champ
- * @param array $attributes Attributs ($key => $value)
- * @return string
- */
- public static function textarea($nameId, array $attributes = []) {
+ * Crée un champ texte long
+ * @param string $nameId Nom et id du champ
+ * @param array $attributes Attributs ($key => $value)
+ * @return string
+ */
+ public static function textarea($nameId, array $attributes = [])
+ {
// Attributs par défaut
$attributes = array_merge([
'before' => true,
@@ -912,20 +938,20 @@ class template {
$attributes['label'] = helper::translate($attributes['label']);
$attributes['help'] = helper::translate($attributes['help']);
// Sauvegarde des données en cas d'erreur
- if($attributes['before'] AND array_key_exists($attributes['id'], common::$inputBefore)) {
+ if ($attributes['before'] and array_key_exists($attributes['id'], common::$inputBefore)) {
$attributes['value'] = common::$inputBefore[$attributes['id']];
}
// Début du wrapper
$html = '
';
// Label
- if($attributes['label']) {
+ if ($attributes['label']) {
$html .= self::label($attributes['id'], $attributes['label'], [
'help' => $attributes['help']
]);
}
// Notice
$notice = '';
- if(array_key_exists($attributes['id'], common::$inputNotices)) {
+ if (array_key_exists($attributes['id'], common::$inputNotices)) {
$notice = common::$inputNotices[$attributes['id']];
$attributes['class'] .= ' notice';
}
diff --git a/core/core.php b/core/core.php
index 96a59bc4..29bbfb64 100644
--- a/core/core.php
+++ b/core/core.php
@@ -13,7 +13,8 @@
* @link http://zwiicms.fr/
*/
-class common {
+class common
+{
const DISPLAY_RAW = 0;
const DISPLAY_JSON = 1;
@@ -290,13 +291,14 @@ class common {
/**
* Constructeur commun
*/
- public function __construct() {
+ public function __construct()
+ {
// Extraction des données http
- if(isset($_POST)) {
+ if (isset($_POST)) {
$this->input['_POST'] = $_POST;
}
- if(isset($_COOKIE)) {
+ if (isset($_COOKIE)) {
$this->input['_COOKIE'] = $_COOKIE;
}
@@ -305,12 +307,11 @@ class common {
self::$i18nUI = $t['config']['i18n']['interface'];
// Déterminer la langue du contenu du site
- if (isset($this->input['_COOKIE']['ZWII_I18N_SITE'])
- ) {
+ if (isset($this->input['_COOKIE']['ZWII_I18N_SITE'])) {
// Déterminé par le cookie
self::$i18nContent = $this->input['_COOKIE']['ZWII_I18N_SITE'];
- setlocale (LC_TIME, self::$i18nContent . '_' . strtoupper (self::$i18nContent) );
- } else {
+ setlocale(LC_TIME, self::$i18nContent . '_' . strtoupper(self::$i18nContent));
+ } else {
// Absence du cookie, la langue par défaut est celle de l'interface.
self::$i18nContent = (isset(self::$i18nUI)) ? self::$i18nUI : 'fr_FR';
}
@@ -321,7 +322,7 @@ class common {
// Constructeur JsonDB
$this->dataFiles[$keys] = new \Prowebcraft\JsonDb([
'name' => $keys . '.json',
- 'dir' => $this->dataPath ($keys, self::$i18nContent),
+ 'dir' => $this->dataPath($keys, self::$i18nContent),
'backup' => file_exists('site/data/.backup')
]);;
}
@@ -330,19 +331,20 @@ class common {
// Installation fraîche, initialisation des modules manquants
// La langue d'installation par défaut est fr
foreach ($this->dataFiles as $stageId => $item) {
- $folder = $this->dataPath ($stageId, self::$i18nContent);
- if ( file_exists($folder . $stageId .'.json') === false ||
- $this->getData([$stageId]) === NULL
- ) {
+ $folder = $this->dataPath($stageId, self::$i18nContent);
+ if (
+ file_exists($folder . $stageId . '.json') === false ||
+ $this->getData([$stageId]) === NULL
+ ) {
$this->initData($stageId, self::$i18nContent);
- common::$coreNotices [] = $stageId ;
+ common::$coreNotices[] = $stageId;
}
}
// Langue de l'administration
self::$i18nUI = $this->getData(['config', 'i18n', 'interface']);
// La langue par défaut du contenu est celle du site si le cookie est absent.
- self::$i18nUI = (empty(self::$i18nUI) || is_null(self::$i18nUI)) ? self::$i18nUI = 'fr_FR' : self::$i18nUI ;
+ self::$i18nUI = (empty(self::$i18nUI) || is_null(self::$i18nUI)) ? self::$i18nUI = 'fr_FR' : self::$i18nUI;
// Le fichier existe-t-il ?
@@ -351,58 +353,54 @@ class common {
}
// Utilisateur connecté
- if($this->user === []) {
+ if ($this->user === []) {
$this->user = $this->getData(['user', $this->getInput('ZWII_USER_ID')]);
}
// Construit la liste des pages parents/enfants
- if($this->hierarchy['all'] === []) {
+ if ($this->hierarchy['all'] === []) {
$pages = helper::arrayColumn($this->getData(['page']), 'position', 'SORT_ASC');
// Parents
- foreach($pages as $pageId => $pagePosition) {
- if(
+ foreach ($pages as $pageId => $pagePosition) {
+ if (
// Page parent
$this->getData(['page', $pageId, 'parentPageId']) === ""
// Ignore les pages dont l'utilisateur n'a pas accès
- AND (
- $this->getData(['page', $pageId, 'group']) === self::GROUP_VISITOR
- OR (
- $this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')
- AND $this->getUser('group') >= $this->getData(['page', $pageId, 'group'])
+ and ($this->getData(['page', $pageId, 'group']) === self::GROUP_VISITOR
+ or ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')
+ and $this->getUser('group') >= $this->getData(['page', $pageId, 'group'])
)
)
) {
- if($pagePosition !== 0) {
+ if ($pagePosition !== 0) {
$this->hierarchy['visible'][$pageId] = [];
}
- if($this->getData(['page', $pageId, 'block']) === 'bar') {
+ if ($this->getData(['page', $pageId, 'block']) === 'bar') {
$this->hierarchy['bar'][$pageId] = [];
}
$this->hierarchy['all'][$pageId] = [];
}
}
// Enfants
- foreach($pages as $pageId => $pagePosition) {
- if(
+ foreach ($pages as $pageId => $pagePosition) {
+ if (
// Page parent
$parentId = $this->getData(['page', $pageId, 'parentPageId'])
// Ignore les pages dont l'utilisateur n'a pas accès
- AND (
- (
- $this->getData(['page', $pageId, 'group']) === self::GROUP_VISITOR
- AND $this->getData(['page', $parentId, 'group']) === self::GROUP_VISITOR
+ and (
+ ($this->getData(['page', $pageId, 'group']) === self::GROUP_VISITOR
+ and $this->getData(['page', $parentId, 'group']) === self::GROUP_VISITOR
)
- OR (
- $this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')
- AND $this->getUser('group') >= $this->getData(['page', $parentId, 'group'])
- AND $this->getUser('group') >= $this->getData(['page', $pageId, 'group'])
+ or ($this->getUser('password') === $this->getInput('ZWII_USER_PASSWORD')
+ and $this->getUser('group') >= $this->getData(['page', $parentId, 'group'])
+ and $this->getUser('group') >= $this->getData(['page', $pageId, 'group'])
)
)
) {
- if($pagePosition !== 0) {
+ if ($pagePosition !== 0) {
$this->hierarchy['visible'][$parentId][] = $pageId;
}
- if($this->getData(['page', $pageId, 'block']) === 'bar') {
+ if ($this->getData(['page', $pageId, 'block']) === 'bar') {
$this->hierarchy['bar'][$pageId] = [];
}
$this->hierarchy['all'][$parentId][] = $pageId;
@@ -411,11 +409,10 @@ class common {
}
// Construit l'url
- if($this->url === '') {
- if($url = $_SERVER['QUERY_STRING']) {
+ if ($this->url === '') {
+ if ($url = $_SERVER['QUERY_STRING']) {
$this->url = $url;
- }
- else {
+ } else {
$this->url = $this->getData(['locale', 'homePageId']);
}
}
@@ -424,12 +421,14 @@ class common {
self::$dialog = json_decode(file_get_contents(self::I18N_DIR . self::$i18nUI . '.json'), true);
// Mise à jour des données core
- if( $this->getData(['core', 'dataVersion']) !== intval(str_replace('.','',self::ZWII_VERSION))) include( 'core/include/update.inc.php');
+ if ($this->getData(['core', 'dataVersion']) !== intval(str_replace('.', '', self::ZWII_VERSION))) include('core/include/update.inc.php');
// Données de proxy
- $proxy = $this->getData(['config','proxyType']) . $this->getData(['config','proxyUrl']) . ':' . $this->getData(['config','proxyPort']);
- if (!empty($this->getData(['config','proxyUrl'])) &&
- !empty($this->getData(['config','proxyPort'])) ) {
+ $proxy = $this->getData(['config', 'proxyType']) . $this->getData(['config', 'proxyUrl']) . ':' . $this->getData(['config', 'proxyPort']);
+ if (
+ !empty($this->getData(['config', 'proxyUrl'])) &&
+ !empty($this->getData(['config', 'proxyPort']))
+ ) {
$context = array(
'http' => array(
'proxy' => $proxy,
@@ -437,21 +436,21 @@ class common {
'verify_peer' => false,
'verify_peer_name' => false,
),
- "ssl"=>array(
- "verify_peer"=>false,
- "verify_peer_name"=>false
+ "ssl" => array(
+ "verify_peer" => false,
+ "verify_peer_name" => false
)
);
stream_context_set_default($context);
}
-
}
/**
* Ajoute les valeurs en sortie
* @param array $output Valeurs en sortie
*/
- public function addOutput($output) {
+ public function addOutput($output)
+ {
$this->output = array_merge($this->output, $output);
}
@@ -459,17 +458,18 @@ class common {
* Ajoute une notice de champ obligatoire
* @param string $key Clef du champ
*/
- public function addRequiredInputNotices($key) {
+ public function addRequiredInputNotices($key)
+ {
// La clef est un tableau
- if(preg_match('#\[(.*)\]#', $key, $secondKey)) {
+ if (preg_match('#\[(.*)\]#', $key, $secondKey)) {
$firstKey = explode('[', $key)[0];
$secondKey = $secondKey[1];
- if(empty($this->input['_POST'][$firstKey][$secondKey])) {
+ if (empty($this->input['_POST'][$firstKey][$secondKey])) {
common::$inputNotices[$firstKey . '_' . $secondKey] = 'Obligatoire';
}
}
// La clef est une chaine
- elseif(empty($this->input['_POST'][$key])) {
+ elseif (empty($this->input['_POST'][$key])) {
common::$inputNotices[$key] = 'Obligatoire';
}
}
@@ -477,21 +477,23 @@ class common {
/**
* Check du token CSRF (true = bo
*/
- public function checkCSRF() {
- return ((empty($_POST['csrf']) OR hash_equals($_SESSION['csrf'], $_POST['csrf']) === false) === false);
+ public function checkCSRF()
+ {
+ return ((empty($_POST['csrf']) or hash_equals($_SESSION['csrf'], $_POST['csrf']) === false) === false);
}
/**
* Supprime des données
* @param array $keys Clé(s) des données
*/
- public function deleteData($keys) {
+ public function deleteData($keys)
+ {
// Descripteur de la base
$db = $this->dataFiles[$keys[0]];
// Initialisation de la requête par le nom de la base
$query = $keys[0];
// Construire la requête
- for ($i=1; $i <= count($keys) -1 ; $i++) {
+ for ($i = 1; $i <= count($keys) - 1; $i++) {
$query .= '.' . $keys[$i];
}
// Effacer la donnée
@@ -499,19 +501,22 @@ class common {
return is_object($success);
}
- /**
+ /**
* Sauvegarde des données
* @param array $keys Clé(s) des données
*/
- public function setData($keys = []) {
+ public function setData($keys = [])
+ {
// Pas d'enregistrement lorsqu'une notice est présente ou tableau transmis vide
- if (!empty(self::$inputNotices)
- OR empty($keys)) {
+ if (
+ !empty(self::$inputNotices)
+ or empty($keys)
+ ) {
return false;
}
// Empêcher la sauvegarde d'une donnée nulle.
- if (gettype($keys[count($keys) -1]) === NULL) {
+ if (gettype($keys[count($keys) - 1]) === NULL) {
return false;
}
@@ -524,11 +529,11 @@ class common {
$query = $keys[0];
// Construire la requête
// Ne pas tenir compte du dernier élément qui une une value donc <
- for ($i=1; $i < count($keys)-1 ; $i++) {
+ for ($i = 1; $i < count($keys) - 1; $i++) {
$query .= '.' . $keys[$i];
}
// Appliquer la modification, le dernier élément étant la donnée à sauvegarder
- $success = is_object ($db->set($query, $keys[count($keys)-1], true));
+ $success = is_object($db->set($query, $keys[count($keys) - 1], true));
}
return $success;
}
@@ -538,7 +543,8 @@ class common {
* @param array $keys Clé(s) des données
* @return mixed
*/
- public function getData($keys = []) {
+ public function getData($keys = [])
+ {
// Eviter une requete vide
if (count($keys) >= 1) {
@@ -546,7 +552,7 @@ class common {
$db = $this->dataFiles[$keys[0]];
$query = $keys[0];
// Construire la requête
- for ($i=1; $i < count($keys) ; $i++) {
+ for ($i = 1; $i < count($keys); $i++) {
$query .= '.' . $keys[$i];
}
return $db->get($query);
@@ -559,18 +565,18 @@ class common {
* @param string langue
* @param return contenu de la page
*/
- public function getPage($page, $lang) {
+ public function getPage($page, $lang)
+ {
// Le nom de la ressource et le fichier de contenu sont définis :
if (
- $this->getData(['page', $page, 'content']) !== ''
- && file_exists(self::DATA_DIR . $lang . '/content/' . $this->getData(['page', $page, 'content']))
- ) {
- return file_get_contents(self::DATA_DIR . $lang . '/content/' . $this->getData(['page', $page, 'content']));
- } else {
- return 'Aucun contenu trouvé.';
+ $this->getData(['page', $page, 'content']) !== ''
+ && file_exists(self::DATA_DIR . $lang . '/content/' . $this->getData(['page', $page, 'content']))
+ ) {
+ return file_get_contents(self::DATA_DIR . $lang . '/content/' . $this->getData(['page', $page, 'content']));
+ } else {
+ return 'Aucun contenu trouvé.';
}
-
}
/**
@@ -579,10 +585,10 @@ class common {
* @param string contenu de la page
* @param return nombre d'octets écrits ou erreur
*/
- public function setPage($page, $value, $lang) {
+ public function setPage($page, $value, $lang)
+ {
return file_put_contents(self::DATA_DIR . $lang . '/content/' . $page . '.html', $value);
-
}
@@ -592,10 +598,10 @@ class common {
* @param string pageId
* @param return statut de l'effacement
*/
- public function deletePage($page, $lang) {
-
- return unlink(self::DATA_DIR . $lang . '/content/' . $this->getData(['page', $page, 'content']));
+ public function deletePage($page, $lang)
+ {
+ return unlink(self::DATA_DIR . $lang . '/content/' . $this->getData(['page', $page, 'content']));
}
/**
@@ -603,21 +609,22 @@ class common {
* @param array $module : nom du module à générer
* choix valides : core config user theme page module
*/
- public function initData($module, $lang , $sampleSite = false) {
+ public function initData($module, $lang, $sampleSite = false)
+ {
// Tableau avec les données vierges
require_once('core/module/install/ressource/defaultdata.php');
// Stockage dans un sous-dossier localisé
if (!file_exists(self::DATA_DIR . $lang)) {
- mkdir (self::DATA_DIR .$lang, 0755);
+ mkdir(self::DATA_DIR . $lang, 0755);
}
$db = $this->dataFiles[$module];
if ($sampleSite === true) {
- $db->set($module,init::$siteData[$module]);
+ $db->set($module, init::$siteData[$module]);
} else {
- $db->set($module,init::$defaultData[$module]);
+ $db->set($module, init::$defaultData[$module]);
}
$db->save;
@@ -627,12 +634,12 @@ class common {
mkdir(self::DATA_DIR . $lang . '/content', 0755);
}
// Créer le jeu de pages du site de test
- if ($module === 'page' ) {
+ if ($module === 'page') {
// Site de test ou page simple
if ($sampleSite === true) {
- foreach(init::$siteContent as $key => $value) {
+ foreach (init::$siteContent as $key => $value) {
// Creation du contenu de la page
- if (!empty($this->getData(['page', $key, 'content'])) ) {
+ if (!empty($this->getData(['page', $key, 'content']))) {
file_put_contents(self::DATA_DIR . $lang . '/content/' . $this->getData(['page', $key, 'content']), $value);
}
}
@@ -650,15 +657,15 @@ class common {
* @param bool $onlyBlock Affiche seulement les pages de type barre
* @return array
*/
- public function getHierarchy($parentId = null, $onlyVisible = true, $onlyBlock = false) {
+ public function getHierarchy($parentId = null, $onlyVisible = true, $onlyBlock = false)
+ {
$hierarchy = $onlyVisible ? $this->hierarchy['visible'] : $this->hierarchy['all'];
$hierarchy = $onlyBlock ? $this->hierarchy['bar'] : $hierarchy;
// Enfants d'un parent
- if($parentId) {
- if(array_key_exists($parentId, $hierarchy)) {
+ if ($parentId) {
+ if (array_key_exists($parentId, $hierarchy)) {
return $hierarchy[$parentId];
- }
- else {
+ } else {
return [];
}
}
@@ -675,24 +682,25 @@ class common {
* @param bool $required Champ requis
* @return mixed
*/
- public function getInput($key, $filter = helper::FILTER_STRING_SHORT, $required = false) {
+ public function getInput($key, $filter = helper::FILTER_STRING_SHORT, $required = false)
+ {
// La clef est un tableau
- if(preg_match('#\[(.*)\]#', $key, $secondKey)) {
+ if (preg_match('#\[(.*)\]#', $key, $secondKey)) {
$firstKey = explode('[', $key)[0];
$secondKey = $secondKey[1];
- foreach($this->input as $type => $values) {
+ foreach ($this->input as $type => $values) {
// Champ obligatoire
- if($required) {
+ if ($required) {
$this->addRequiredInputNotices($key);
}
// Check de l'existence
// Également utile pour les checkbox qui ne retournent rien lorsqu'elles ne sont pas cochées
- if(
+ if (
array_key_exists($firstKey, $values)
- AND array_key_exists($secondKey, $values[$firstKey])
+ and array_key_exists($secondKey, $values[$firstKey])
) {
// Retourne la valeur filtrée
- if($filter) {
+ if ($filter) {
return helper::filter($this->input[$type][$firstKey][$secondKey], $filter);
}
// Retourne la valeur
@@ -704,16 +712,16 @@ class common {
}
// La clef est une chaîne
else {
- foreach($this->input as $type => $values) {
+ foreach ($this->input as $type => $values) {
// Champ obligatoire
- if($required) {
+ if ($required) {
$this->addRequiredInputNotices($key);
}
// Check de l'existence
// Également utile pour les checkbox qui ne retournent rien lorsqu'elles ne sont pas cochées
- if(array_key_exists($key, $values)) {
+ if (array_key_exists($key, $values)) {
// Retourne la valeur filtrée
- if($filter) {
+ if ($filter) {
return helper::filter($this->input[$type][$key], $filter);
}
// Retourne la valeur
@@ -732,9 +740,10 @@ class common {
* @param int $key Clé de l'url
* @return string|null
*/
- public function getUrl($key = null) {
+ public function getUrl($key = null)
+ {
// Url complète
- if($key === null) {
+ if ($key === null) {
return $this->url;
}
// Une partie de l'url
@@ -749,17 +758,15 @@ class common {
* @param int $key Clé de la valeur
* @return string|null
*/
- public function getUser($key) {
- if(is_array($this->user) === false) {
+ public function getUser($key)
+ {
+ if (is_array($this->user) === false) {
return false;
- }
- elseif($key === 'id') {
+ } elseif ($key === 'id') {
return $this->getInput('ZWII_USER_ID');
- }
- elseif(array_key_exists($key, $this->user)) {
+ } elseif (array_key_exists($key, $this->user)) {
return $this->user[$key];
- }
- else {
+ } else {
return false;
}
}
@@ -768,64 +775,73 @@ class common {
* Check qu'une valeur est transmise par la méthode _POST
* @return bool
*/
- public function isPost() {
- return ($this->checkCSRF() AND $this->input['_POST'] !== []);
+ public function isPost()
+ {
+ return ($this->checkCSRF() and $this->input['_POST'] !== []);
}
/**
* Génère un fichier json avec la liste des pages
*
- */
- public function listPages() {
- // Sauve la liste des pages pour TinyMCE
+ */
+ public function listPages()
+ {
+ // Sauve la liste des pages pour TinyMCE
$parents = [];
- $rewrite = (helper::checkRewrite()) ? '' : '?';
- // Boucle de recherche des pages actives
- foreach($this->getHierarchy(null,false,false) as $parentId => $childIds) {
+ $rewrite = (helper::checkRewrite()) ? '' : '?';
+ // Boucle de recherche des pages actives
+ foreach ($this->getHierarchy(null, false, false) as $parentId => $childIds) {
$children = [];
// Exclure les barres
- if ($this->getData(['page', $parentId, 'block']) !== 'bar' ) {
+ if ($this->getData(['page', $parentId, 'block']) !== 'bar') {
// Boucler sur les enfants et récupérer le tableau children avec la liste des enfants
- foreach($childIds as $childId) {
- $children [] = [ 'title' => ' » '. html_entity_decode($this->getData(['page', $childId, 'shortTitle']), ENT_QUOTES) ,
- 'value'=> $rewrite.$childId
+ foreach ($childIds as $childId) {
+ $children[] = [
+ 'title' => ' » ' . html_entity_decode($this->getData(['page', $childId, 'shortTitle']), ENT_QUOTES),
+ 'value' => $rewrite . $childId
];
}
// Traitement
if (empty($childIds)) {
// Pas d'enfant, uniquement l'entrée du parent
- $parents [] = ['title' => html_entity_decode($this->getData(['page', $parentId, 'shortTitle']), ENT_QUOTES) ,
- 'value'=> $rewrite.$parentId
+ $parents[] = [
+ 'title' => html_entity_decode($this->getData(['page', $parentId, 'shortTitle']), ENT_QUOTES),
+ 'value' => $rewrite . $parentId
];
} else {
// Des enfants, on ajoute la page parent en premier
- array_unshift ($children , ['title' => html_entity_decode($this->getData(['page', $parentId, 'shortTitle']), ENT_QUOTES) ,
- 'value'=> $rewrite.$parentId
+ array_unshift($children, [
+ 'title' => html_entity_decode($this->getData(['page', $parentId, 'shortTitle']), ENT_QUOTES),
+ 'value' => $rewrite . $parentId
]);
// puis on ajoute les enfants au parent
- $parents [] = ['title' => html_entity_decode($this->getData(['page', $parentId, 'shortTitle']), ENT_QUOTES) ,
- 'value'=> $rewrite.$parentId ,
- 'menu' => $children
+ $parents[] = [
+ 'title' => html_entity_decode($this->getData(['page', $parentId, 'shortTitle']), ENT_QUOTES),
+ 'value' => $rewrite . $parentId,
+ 'menu' => $children
];
}
}
}
- // Sitemap et Search
- $children = [];
- $children [] = ['title'=>'Rechercher dans le site',
- 'value'=>$rewrite.'search'
- ];
- $children [] = ['title'=>'Plan du site',
- 'value'=>$rewrite.'sitemap'
- ];
- $parents [] = ['title' => 'Pages spéciales',
- 'value' => '#',
- 'menu' => $children
- ];
+ // Sitemap et Search
+ $children = [];
+ $children[] = [
+ 'title' => 'Rechercher dans le site',
+ 'value' => $rewrite . 'search'
+ ];
+ $children[] = [
+ 'title' => 'Plan du site',
+ 'value' => $rewrite . 'sitemap'
+ ];
+ $parents[] = [
+ 'title' => 'Pages spéciales',
+ 'value' => '#',
+ 'menu' => $children
+ ];
// Enregistrement : 3 tentatives
- for($i = 0; $i < 3; $i++) {
- if (file_put_contents ('core/vendor/tinymce/link_list.json', json_encode($parents), LOCK_EX) !== false) {
+ for ($i = 0; $i < 3; $i++) {
+ if (file_put_contents('core/vendor/tinymce/link_list.json', json_encode($parents), LOCK_EX) !== false) {
break;
}
// Pause de 10 millisecondes
@@ -839,12 +855,15 @@ class common {
* @param $lang langue des pages
* @return string du dossier à créer
*/
- public function dataPath($id, $lang) {
+ public function dataPath($id, $lang)
+ {
// Sauf pour les pages et les modules
- if ($id === 'page' ||
+ if (
+ $id === 'page' ||
$id === 'module' ||
- $id === 'locale' ) {
- $folder = self::DATA_DIR . $lang . '/' ;
+ $id === 'locale'
+ ) {
+ $folder = self::DATA_DIR . $lang . '/';
} else {
$folder = self::DATA_DIR;
}
@@ -858,15 +877,16 @@ class common {
* $command valeurs possible
* all : génère un site map complet
* Sinon contient id de la page à créer
- */
+ */
- public function createSitemap($command = "all") {
+ public function createSitemap($command = "all")
+ {
//require_once "core/vendor/sitemap/SitemapGenerator.php";
- $timezone = $this->getData(['config','timezone']);
+ $timezone = $this->getData(['config', 'timezone']);
$outputDir = getcwd();
- $sitemap = new \Icamys\SitemapGenerator\SitemapGenerator(helper::baseurl(false),$outputDir);
+ $sitemap = new \Icamys\SitemapGenerator\SitemapGenerator(helper::baseurl(false), $outputDir);
// will create also compressed (gzipped) sitemap : option buguée
// $sitemap->enableCompression();
@@ -876,58 +896,63 @@ class common {
$sitemap->setMaxUrlsPerSitemap(50000);
// sitemap file name
- $sitemap->setSitemapFileName( 'sitemap.xml') ;
+ $sitemap->setSitemapFileName('sitemap.xml');
// Set the sitemap index file name
- $sitemap->setSitemapIndexFileName( 'sitemap-index.xml');
+ $sitemap->setSitemapIndexFileName('sitemap-index.xml');
$datetime = new DateTime(date('c'));
$datetime->format(DateTime::ATOM); // Updated ISO8601
- foreach($this->getHierarchy(null, null, null) as $parentPageId => $childrenPageIds) {
+ foreach ($this->getHierarchy(null, null, null) as $parentPageId => $childrenPageIds) {
// Exclure les barres et les pages non publiques et les pages masquées
- if ($this->getData(['page',$parentPageId,'group']) !== 0 ||
- $this->getData(['page', $parentPageId, 'block']) === 'bar' ) {
+ if (
+ $this->getData(['page', $parentPageId, 'group']) !== 0 ||
+ $this->getData(['page', $parentPageId, 'block']) === 'bar'
+ ) {
continue;
}
// Page désactivée, traiter les sous-pages sans prendre en compte la page parente.
- if ($this->getData(['page', $parentPageId, 'disable']) !== true ) {
+ if ($this->getData(['page', $parentPageId, 'disable']) !== true) {
// Cas de la page d'accueil ne pas dupliquer l'URL
$pageId = ($parentPageId !== $this->getData(['locale', 'homePageId'])) ? $parentPageId : '';
- $sitemap->addUrl ('/' . $pageId, $datetime);
+ $sitemap->addUrl('/' . $pageId, $datetime);
}
// Articles du blog
- if ($this->getData(['page', $parentPageId, 'moduleId']) === 'blog' &&
- !empty($this->getData(['module',$parentPageId])) ) {
- foreach($this->getData(['module',$parentPageId,'posts']) as $articleId => $article) {
- if($this->getData(['module',$parentPageId,'posts',$articleId,'state']) === true) {
- $date = $this->getData(['module',$parentPageId,'posts',$articleId,'publishedOn']);
- $sitemap->addUrl('/' . $parentPageId . '/' . $articleId , new DateTime("@{$date}",new DateTimeZone($timezone)));
+ if (
+ $this->getData(['page', $parentPageId, 'moduleId']) === 'blog' &&
+ !empty($this->getData(['module', $parentPageId]))
+ ) {
+ foreach ($this->getData(['module', $parentPageId, 'posts']) as $articleId => $article) {
+ if ($this->getData(['module', $parentPageId, 'posts', $articleId, 'state']) === true) {
+ $date = $this->getData(['module', $parentPageId, 'posts', $articleId, 'publishedOn']);
+ $sitemap->addUrl('/' . $parentPageId . '/' . $articleId, new DateTime("@{$date}", new DateTimeZone($timezone)));
}
}
}
// Sous-pages
- foreach($childrenPageIds as $childKey) {
- if ($this->getData(['page',$childKey,'group']) !== 0 || $this->getData(['page', $childKey, 'disable']) === true) {
+ foreach ($childrenPageIds as $childKey) {
+ if ($this->getData(['page', $childKey, 'group']) !== 0 || $this->getData(['page', $childKey, 'disable']) === true) {
continue;
}
// Cas de la page d'accueil ne pas dupliquer l'URL
$pageId = ($childKey !== $this->getData(['locale', 'homePageId'])) ? $childKey : '';
- $sitemap->addUrl('/' . $childKey,$datetime);
+ $sitemap->addUrl('/' . $childKey, $datetime);
// La sous-page est un blog
- if ($this->getData(['page', $childKey, 'moduleId']) === 'blog' &&
- !empty($this->getData(['module',$childKey])) ) {
- foreach($this->getData(['module',$childKey,'posts']) as $articleId => $article) {
- if($this->getData(['module',$childKey,'posts',$articleId,'state']) === true) {
- $date = $this->getData(['module',$childKey,'posts',$articleId,'publishedOn']);
- $sitemap->addUrl( '/' . $childKey . '/' . $articleId , new DateTime("@{$date}",new DateTimeZone($timezone)));
+ if (
+ $this->getData(['page', $childKey, 'moduleId']) === 'blog' &&
+ !empty($this->getData(['module', $childKey]))
+ ) {
+ foreach ($this->getData(['module', $childKey, 'posts']) as $articleId => $article) {
+ if ($this->getData(['module', $childKey, 'posts', $articleId, 'state']) === true) {
+ $date = $this->getData(['module', $childKey, 'posts', $articleId, 'publishedOn']);
+ $sitemap->addUrl('/' . $childKey . '/' . $articleId, new DateTime("@{$date}", new DateTimeZone($timezone)));
}
}
}
}
-
}
// Flush all stored urls from memory to the disk and close all necessary tags.
@@ -938,22 +963,21 @@ class common {
// Update robots.txt file in output directory
- if ($this->getData(['config','seo', 'robots']) === true) {
+ if ($this->getData(['config', 'seo', 'robots']) === true) {
if (file_exists('robots.txt')) {
unlink('robots.txt');
}
$sitemap->updateRobots();
} else {
- file_put_contents('robots.txt','User-agent: *' . PHP_EOL . 'Disallow: /');
+ file_put_contents('robots.txt', 'User-agent: *' . PHP_EOL . 'Disallow: /');
}
// Submit your sitemaps to Google, Yahoo, Bing and Ask.com
- if (empty ($this->getData(['config','proxyType']) . $this->getData(['config','proxyUrl']) . ':' . $this->getData(['config','proxyPort'])) ) {
+ if (empty($this->getData(['config', 'proxyType']) . $this->getData(['config', 'proxyUrl']) . ':' . $this->getData(['config', 'proxyPort']))) {
$sitemap->submitSitemap();
}
- return(file_exists('sitemap.xml') && file_exists('robots.txt'));
-
+ return (file_exists('sitemap.xml') && file_exists('robots.txt'));
}
/*
@@ -963,7 +987,8 @@ class common {
* @param string $dets image destination
* @param integer $desired_width largeur demandée
*/
- function makeThumb($src, $dest, $desired_width) {
+ function makeThumb($src, $dest, $desired_width)
+ {
// Vérifier l'existence du dossier de destination.
$fileInfo = pathinfo($dest);
if (!is_dir($fileInfo['dirname'])) {
@@ -971,7 +996,7 @@ class common {
}
$source_image = '';
// Type d'image
- switch( $fileInfo['extension']) {
+ switch ($fileInfo['extension']) {
case 'jpeg':
case 'jpg':
$source_image = imagecreatefromjpeg($src);
@@ -993,7 +1018,7 @@ class common {
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);
/* copy source image at a resized size */
imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
- switch(mime_content_type($src) ) {
+ switch (mime_content_type($src)) {
case 'image/jpeg':
case 'image/jpg':
return (imagejpeg($virtual_image, $dest));
@@ -1018,7 +1043,8 @@ class common {
* @param string $content Contenu
* @return bool
*/
- public function sendMail($to, $subject, $content, $replyTo = null) {
+ public function sendMail($to, $subject, $content, $replyTo = null)
+ {
// Layout
ob_start();
include 'core/layout/mail.php';
@@ -1026,27 +1052,27 @@ class common {
$mail = new PHPMailer\PHPMailer\PHPMailer;
$mail->CharSet = 'UTF-8';
// Mail
- try{
+ try {
// Paramètres SMTP
- if ($this->getdata(['config','smtp','enable'])) {
+ if ($this->getdata(['config', 'smtp', 'enable'])) {
//$mail->SMTPDebug = PHPMailer\PHPMailer\SMTP::DEBUG_SERVER;
$mail->isSMTP();
$mail->SMTPAutoTLS = false;
- $mail->Host = $this->getdata(['config','smtp','host']);
- $mail->Port = (int) $this->getdata(['config','smtp','port']);
- if ($this->getData(['config','smtp','auth'])) {
- $mail->Username = $this->getData(['config','smtp','username']);
- $mail->Password = helper::decrypt($this->getData(['config','smtp','username']),$this->getData(['config','smtp','password']));
- $mail->SMTPAuth = $this->getData(['config','smtp','auth']);
- $mail->SMTPSecure = $this->getData(['config','smtp','secure']);
- $mail->setFrom($this->getData(['config','smtp','username']));
+ $mail->Host = $this->getdata(['config', 'smtp', 'host']);
+ $mail->Port = (int) $this->getdata(['config', 'smtp', 'port']);
+ if ($this->getData(['config', 'smtp', 'auth'])) {
+ $mail->Username = $this->getData(['config', 'smtp', 'username']);
+ $mail->Password = helper::decrypt($this->getData(['config', 'smtp', 'username']), $this->getData(['config', 'smtp', 'password']));
+ $mail->SMTPAuth = $this->getData(['config', 'smtp', 'auth']);
+ $mail->SMTPSecure = $this->getData(['config', 'smtp', 'secure']);
+ $mail->setFrom($this->getData(['config', 'smtp', 'username']));
if (is_null($replyTo)) {
- $mail->addReplyTo($this->getData(['config','smtp','username']));
+ $mail->addReplyTo($this->getData(['config', 'smtp', 'username']));
} else {
$mail->addReplyTo($replyTo);
}
}
- // Fin SMTP
+ // Fin SMTP
} else {
$host = str_replace('www.', '', $_SERVER['HTTP_HOST']);
$mail->setFrom('no-reply@' . $host, $this->getData(['locale', 'title']));
@@ -1056,26 +1082,22 @@ class common {
$mail->addReplyTo($replyTo);
}
}
- if(is_array($to)) {
- foreach($to as $userMail) {
- $mail->addAddress($userMail);
- }
- }
- else {
- $mail->addAddress($to);
+ if (is_array($to)) {
+ foreach ($to as $userMail) {
+ $mail->addAddress($userMail);
+ }
+ } else {
+ $mail->addAddress($to);
}
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = $layout;
$mail->AltBody = strip_tags($content);
- if($mail->send()) {
- return true;
+ if ($mail->send()) {
+ return true;
+ } else {
+ return $mail->ErrorInfo;
}
- else {
- return $mail->ErrorInfo;
- }
- } catch (phpmailerException $e) {
- return $e->errorMessage();
} catch (Exception $e) {
return $e->getMessage();
}
@@ -1084,15 +1106,16 @@ class common {
/**
- * Effacer un dossier non vide.
- * @param string URL du dossier à supprimer
- */
- public function removeDir ( $path ) {
- foreach ( new DirectoryIterator($path) as $item ) {
- if ( $item->isFile() ) @unlink($item->getRealPath());
- if ( !$item->isDot() && $item->isDir() ) $this->removeDir($item->getRealPath());
+ * Effacer un dossier non vide.
+ * @param string URL du dossier à supprimer
+ */
+ public function removeDir($path)
+ {
+ foreach (new DirectoryIterator($path) as $item) {
+ if ($item->isFile()) @unlink($item->getRealPath());
+ if (!$item->isDot() && $item->isDir()) $this->removeDir($item->getRealPath());
}
- return ( rmdir($path) );
+ return (rmdir($path));
}
@@ -1102,7 +1125,8 @@ class common {
* @param string $dst dossier destination
* @return bool
*/
- public function copyDir($src, $dst) {
+ public function copyDir($src, $dst)
+ {
// Ouvrir le dossier source
$dir = opendir($src);
// Créer le dossier de destination
@@ -1112,16 +1136,17 @@ class common {
$success = true;
// Boucler dans le dossier source en l'absence d'échec de lecture écriture
- while( $success
- AND $file = readdir($dir) ) {
+ while (
+ $success
+ and $file = readdir($dir)
+ ) {
- if (( $file != '.' ) && ( $file != '..' )) {
- if ( is_dir($src . '/' . $file) ){
+ if (($file != '.') && ($file != '..')) {
+ if (is_dir($src . '/' . $file)) {
// Appel récursif des sous-dossiers
$s = $this->copyDir($src . '/' . $file, $dst . '/' . $file);
$success = $s || $success;
- }
- else {
+ } else {
$s = copy($src . '/' . $file, $dst . '/' . $file);
$success = $s || $success;
}
@@ -1139,14 +1164,15 @@ class common {
* @param int count nombres d'occurrences
* @return array avec les valeurs remplacées.
*/
- public function recursive_array_replace ($find, $replace, $array, &$count) {
+ public function recursive_array_replace($find, $replace, $array, &$count)
+ {
if (!is_array($array)) {
return str_replace($find, $replace, $array, $count);
}
$newArray = [];
foreach ($array as $key => $value) {
- $newArray[$key] = $this->recursive_array_replace($find, $replace, $value,$c);
+ $newArray[$key] = $this->recursive_array_replace($find, $replace, $value, $c);
$count += $c;
}
return $newArray;
@@ -1158,23 +1184,24 @@ class common {
* @param string folder path à zipper
* @param array filter dossiers à exclure
*/
- public function makeZip ($fileName, $folder, $filter = [] ) {
+ public function makeZip($fileName, $folder, $filter = [])
+ {
$zip = new ZipArchive();
$zip->open($fileName, ZipArchive::CREATE | ZipArchive::OVERWRITE);
//$directory = 'site/';
$files = new RecursiveIteratorIterator(
new RecursiveCallbackFilterIterator(
- new RecursiveDirectoryIterator(
- $folder,
- RecursiveDirectoryIterator::SKIP_DOTS
- ),
- function ($fileInfo, $key, $iterator) use ($filter) {
- return $fileInfo->isFile() || !in_array($fileInfo->getBaseName(), $filter);
- }
+ new RecursiveDirectoryIterator(
+ $folder,
+ RecursiveDirectoryIterator::SKIP_DOTS
+ ),
+ function ($fileInfo, $key, $iterator) use ($filter) {
+ return $fileInfo->isFile() || !in_array($fileInfo->getBaseName(), $filter);
+ }
)
);
- foreach ($files as $name => $file) {
- if (!$file->isDir()) {
+ foreach ($files as $name => $file) {
+ if (!$file->isDir()) {
$filePath = $file->getRealPath();
$relativePath = substr($filePath, strlen(realpath($folder)) + 1);
$zip->addFile($filePath, $relativePath);
@@ -1188,11 +1215,11 @@ class common {
/**
* Affiche le consentement aux cookies
*/
- public function showCookies() {
+ public function showCookies()
+ {
// Gestion des cookies intégrée
- if ($this->getData(['config', 'cookieConsent']) === true )
- {
+ if ($this->getData(['config', 'cookieConsent']) === true) {
// Détermine si le bloc doit être affiché selon la validité du cookie
// L'URL du serveur faut TRUE
$item = '
getData(['locale', 'cookies', 'titleLabel']) . '';
+ $item .= '
' . $this->getData(['locale', 'cookies', 'titleLabel']) . '
';
$item .= '
' . $this->getData(['locale', 'cookies', 'mainLabel']) . '
';
// Formulaire de réponse
$item .= '
';
// mentions légales si la page est définie
$legalPage = $this->getData(['locale', 'legalPageId']);
- if ($legalPage !== 'none') {
+ if ($legalPage !== 'none') {
$item .= '
' . $this->getData(['locale', 'cookies', 'linkLegalLabel']) . '
';
}
$item .= '
';
echo $item;
}
-
}
/**
* Formate le contenu de la page selon les gabarits
* @param Page par defaut
*/
- public function showSection() {
+ public function showSection()
+ {
echo '
';
// Récupérer la config de la page courante
- $blocks = explode('-',$this->getData(['page',$this->getUrl(0),'block']));
+ $blocks = explode('-', $this->getData(['page', $this->getUrl(0), 'block']));
// Initialiser
- $blockleft=$blockright="";
+ $blockleft = $blockright = "";
switch (sizeof($blocks)) {
- case 1 : // une colonne
- $content = 'col'. $blocks[0] ;
+ case 1: // une colonne
+ $content = 'col' . $blocks[0];
break;
- case 2 : // 2 blocs
+ case 2: // 2 blocs
if ($blocks[0] < $blocks[1]) { // détermine la position de la colonne
- $blockleft = 'col'. $blocks[0];
- $content = 'col'. $blocks[1] ;
+ $blockleft = 'col' . $blocks[0];
+ $content = 'col' . $blocks[1];
} else {
$content = 'col' . $blocks[0];
$blockright = 'col' . $blocks[1];
}
- break;
- case 3 : // 3 blocs
- $blockleft = 'col' . $blocks[0];
- $content = 'col' . $blocks[1];
- $blockright = 'col' . $blocks[2];
+ break;
+ case 3: // 3 blocs
+ $blockleft = 'col' . $blocks[0];
+ $content = 'col' . $blocks[1];
+ $blockright = 'col' . $blocks[2];
}
// Page pleine pour la configuration des modules et l'édition des pages sauf l'affichage d'un article de blog
- $pattern = ['config','edit','add','comment','data'];
+ $pattern = ['config', 'edit', 'add', 'comment', 'data'];
if ((sizeof($blocks) === 1 ||
- in_array($this->getUrl(1),$pattern) )
- ) { // Pleine page en mode configuration
- $this->showContent();
- if (file_exists(self::DATA_DIR . 'body.inc.html')) {
- include( self::DATA_DIR . 'body.inc.html');
- }
+ in_array($this->getUrl(1), $pattern))) { // Pleine page en mode configuration
+ $this->showContent();
+ if (file_exists(self::DATA_DIR . 'body.inc.html')) {
+ include(self::DATA_DIR . 'body.inc.html');
+ }
} else {
echo '';
- /**
- * Barre gauche
- */
- if ($blockleft !== "") {
- echo '
";
+ /**
+ * Barre gauche
+ */
+ if ($blockleft !== "") {
+ echo '
";
+ }
+ /**
+ * Contenu de page
+ */
+ echo '
';
+ $this->showContent();
+ if (file_exists(self::DATA_DIR . 'body.inc.html')) {
+ include(self::DATA_DIR . 'body.inc.html');
+ }
+ echo '
';
+ /**
+ * Barre droite
+ */
+ if ($blockright !== "") {
+ echo '
';
+ // Détermine si le menu est présent
+ if ($this->getData(['page', $this->getData(['page', $this->getUrl(0), 'barRight']), 'displayMenu']) === 'none') {
+ // Pas de menu
+ echo $this->output['contentRight'];
+ } else {
+ // $mark contient 0 le menu est positionné à la fin du contenu
+ $contentRight = str_replace('[]', '[MENU]', $this->output['contentRight']);
+ $contentRight = str_replace('[menu]', '[MENU]', $contentRight);
+ $mark = strrpos($contentRight, '[MENU]') !== false ? strrpos($contentRight, '[MENU]') : strlen($contentRight);
+ echo substr($contentRight, 0, $mark);
+ echo '';
+ echo substr($contentRight, $mark + 6, strlen($contentRight));
}
+ echo ' ';
+ }
echo '
';
}
echo '';
@@ -1321,68 +1347,67 @@ class common {
* Affiche le contenu
* @param Page par défaut
*/
- public function showContent() {
- if(
+ public function showContent()
+ {
+ if (
$this->output['title']
- AND (
- $this->getData(['page', $this->getUrl(0)]) === null
- OR $this->getData(['page', $this->getUrl(0), 'hideTitle']) === false
- OR $this->getUrl(1) === 'config'
+ and ($this->getData(['page', $this->getUrl(0)]) === null
+ or $this->getData(['page', $this->getUrl(0), 'hideTitle']) === false
+ or $this->getUrl(1) === 'config'
)
) {
echo '
' . $this->output['title'] . '
';
}
echo $this->output['content'];
-
}
/**
* Affiche le pied de page
*/
- public function showFooter () {
+ public function showFooter()
+ {
// Déterminer la position
$positionFixed = '';
if (
$this->getData(['theme', 'footer', 'position']) === 'site'
// Affiche toujours le pied de page pour l'édition du thème
- OR (
- $this->getData(['theme', 'footer', 'position']) === 'hide'
- AND $this->getUrl(0) === 'theme'
+ or ($this->getData(['theme', 'footer', 'position']) === 'hide'
+ and $this->getUrl(0) === 'theme'
)
- ) {
- $position = 'site';
- } else {
- $position = 'body';
- if ( $this->getData(['theme', 'footer', 'fixed']) === true) {
- $positionFixed = ' footerbodyFixed';
- }
- // Sortir de la division précédente
- echo '
';
+ ) {
+ $position = 'site';
+ } else {
+ $position = 'body';
+ if ($this->getData(['theme', 'footer', 'fixed']) === true) {
+ $positionFixed = ' footerbodyFixed';
+ }
+ // Sortir de la division précédente
+ echo '