You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ZwiiCMS/core/core.php

2664 lines
100 KiB
PHTML

5 years ago
<?php
/**
* This file is part of Zwii. *
5 years ago
* For full copyright and license information, please see the LICENSE
* file that was distributed with this source code.
*
* @author Rémi Jean <remi.jean@outlook.com>
* @copyright Copyright (C) 2008-2018, Rémi Jean
* @license GNU General Public License, version 3
* @author Frédéric Tempez <frederic.tempez@outlook.com>
3 years ago
* @copyright Copyright (C) 2018-2020, Frédéric Tempez
5 years ago
* @link http://zwiicms.com/
*/
class common {
const DISPLAY_RAW = 0;
const DISPLAY_JSON = 1;
const DISPLAY_LAYOUT_BLANK = 2;
const DISPLAY_LAYOUT_MAIN = 3;
const DISPLAY_LAYOUT_LIGHT = 4;
const GROUP_BANNED = -1;
const GROUP_VISITOR = 0;
const GROUP_MEMBER = 1;
const GROUP_MODERATOR = 2;
const GROUP_ADMIN = 3;
// Dossier de travail
const BACKUP_DIR = 'site/backup/';
const DATA_DIR = 'site/data/';
const FILE_DIR = 'site/file/';
const TEMP_DIR = 'site/tmp/';
// Miniatures de la galerie
const THUMBS_SEPARATOR = 'mini_';
const THUMBS_WIDTH = 640;
// Contrôle d'édition temps max en secondes avant déconnexion 30 minutes
const ACCESS_TIMER = 1800;
// Numéro de version
const ZWII_VERSION = '10.2.00.dev28';
const ZWII_UPDATE_CHANNEL = "v10";
5 years ago
public static $actions = [];
public static $coreModuleIds = [
'config',
'install',
'maintenance',
'page',
'search',
5 years ago
'sitemap',
'theme',
'user'
5 years ago
];
public static $dataStage = [
'config',
'core',
'module',
'page',
'user',
'theme',
'admin'
];
public static $accessList = [
'user',
'theme',
'config',
'edit',
'config'
];
public static $accessExclude = [
'login',
'logout'
];
5 years ago
private $data = [];
private $hierarchy = [
'all' => [],
'visible' => [],
'bar' => []
5 years ago
];
private $input = [
'_COOKIE' => [],
'_POST' => []
];
public static $inputBefore = [];
public static $inputNotices = [];
public static $importNotices = [];
public static $coreNotices = [];
5 years ago
public $output = [
'access' => true,
'content' => '',
4 years ago
'contentLeft' => '',
'contentRight' => '',
5 years ago
'display' => self::DISPLAY_LAYOUT_MAIN,
'metaDescription' => '',
'metaTitle' => '',
'notification' => '',
'redirect' => '',
5 years ago
'script' => '',
'showBarEditButton' => false,
'showPageContent' => false,
'state' => false,
'style' => '',
'title' => null, // Null car un titre peut être vide
// Trié par ordre d'exécution
'vendor' => [
'jquery',
'normalize',
'lity',
'filemanager',
'flatpickr',
5 years ago
// 'tinycolorpicker', Désactivé par défaut
// 'tinymce', Désactivé par défaut
// 'codemirror', // Désactivé par défaut
'tippy',
'zwiico',
'imagemap',
'simplelightbox'
5 years ago
],
'view' => ''
];
public static $groups = [
self::GROUP_BANNED => 'Banni',
self::GROUP_VISITOR => 'Visiteur',
self::GROUP_MEMBER => 'Membre',
self::GROUP_MODERATOR => 'Éditeur',
5 years ago
self::GROUP_ADMIN => 'Administrateur'
];
public static $groupEdits = [
self::GROUP_BANNED => 'Banni',
self::GROUP_MEMBER => 'Membre',
self::GROUP_MODERATOR => 'Éditeur',
5 years ago
self::GROUP_ADMIN => 'Administrateur'
];
public static $groupNews = [
self::GROUP_MEMBER => 'Membre',
self::GROUP_MODERATOR => 'Éditeur',
5 years ago
self::GROUP_ADMIN => 'Administrateur'
];
public static $groupPublics = [
self::GROUP_VISITOR => 'Visiteur',
self::GROUP_MEMBER => 'Membre',
self::GROUP_MODERATOR => 'Éditeur',
5 years ago
self::GROUP_ADMIN => 'Administrateur'
];
public static $timezone;
private $url = '';
private $user = [];
private $page = '';
5 years ago
/**
* Constructeur commun
*/
public function __construct() {
// Extraction des données http
if(isset($_POST)) {
$this->input['_POST'] = $_POST;
}
if(isset($_COOKIE)) {
$this->input['_COOKIE'] = $_COOKIE;
}
// Import version 9
if (file_exists(self::DATA_DIR . 'core.json') === true &&
$this->getData(['core','dataVersion']) < 10000) {
$keepUsers = isset($_SESSION['KEEP_USERS']) ? $_SESSION['KEEP_USERS'] : false;
$this->importData($keepUsers);
unset ($_SESSION['KEEP_USERS']);
// Réinstaller htaccess
copy('core/module/install/ressource/.htaccess', self::DATA_DIR . '.htaccess');
common::$importNotices [] = "Importation réalisée avec succès" ;
//echo '<script>window.location.replace("' . helper::baseUrl() . $this->getData(['config','homePageId']) . '")</script>';
}
// Installation fraîche, initialisation des modules manquants
// La langue d'installation par défaut est fr
foreach (self::$dataStage as $stageId) {
$folder = $this->dirData ($stageId, 'fr');
if (file_exists($folder . $stageId .'.json') === false) {
$this->initData($stageId,'fr');
common::$coreNotices [] = $stageId ;
}
}
5 years ago
// Utilisateur connecté
if($this->user === []) {
$this->user = $this->getData(['user', $this->getInput('ZWII_USER_ID')]);
}
3 years ago
// Mise en cache des pages
$this->page = $this->getPageCache();
5 years ago
// Construit la liste des pages parents/enfants
if($this->hierarchy['all'] === []) {
$pages = helper::arrayCollumn($this->getData(['page']), 'position', 'SORT_ASC');
// Parents
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'])
)
)
) {
if($pagePosition !== 0) {
$this->hierarchy['visible'][$pageId] = [];
}
if($this->getData(['page', $pageId, 'block']) === 'bar') {
$this->hierarchy['bar'][$pageId] = [];
}
5 years ago
$this->hierarchy['all'][$pageId] = [];
}
}
// Enfants
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
)
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) {
$this->hierarchy['visible'][$parentId][] = $pageId;
}
if($this->getData(['page', $pageId, 'block']) === 'bar') {
$this->hierarchy['bar'][$pageId] = [];
}
5 years ago
$this->hierarchy['all'][$parentId][] = $pageId;
}
}
}
// Construit l'url
if($this->url === '') {
if($url = $_SERVER['QUERY_STRING']) {
$this->url = $url;
}
else {
$this->url = $this->getData(['config', 'homePageId']);
}
}
// Mise à jour des données core
$this->update();
// 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'])) ) {
$context = array(
'http' => array(
'proxy' => $proxy,
'request_fulluri' => true,
'verify_peer' => false,
'verify_peer_name' => false,
),
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false
)
);
stream_context_set_default($context);
}
5 years ago
}
/**
* Ajoute les valeurs en sortie
* @param array $output Valeurs en sortie
*/
public function addOutput($output) {
$this->output = array_merge($this->output, $output);
}
/**
* Ajoute une notice de champ obligatoire
* @param string $key Clef du champ
*/
public function addRequiredInputNotices($key) {
// La clef est un tableau
if(preg_match('#\[(.*)\]#', $key, $secondKey)) {
$firstKey = explode('[', $key)[0];
$secondKey = $secondKey[1];
if(empty($this->input['_POST'][$firstKey][$secondKey])) {
common::$inputNotices[$firstKey . '_' . $secondKey] = 'Obligatoire';
}
}
// La clef est une chaine
elseif(empty($this->input['_POST'][$key])) {
common::$inputNotices[$key] = 'Obligatoire';
}
}
/**
* Check du token CSRF (true = bo
*/
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) {
//Retourne une chaine contenant le dossier à créer
$folder = $this->dirData ($keys[0],'fr');
// Constructeur JsonDB
//require_once "core/vendor/jsondb/Dot.php";
//require_once "core/vendor/jsondb/JsonDb.php";
$db = new \Prowebcraft\JsonDb([
'name' => $keys[0] . '.json',
'dir' => $folder,
'template' => self::TEMP_DIR . 'data.template.json'
]);
5 years ago
switch(count($keys)) {
case 1:
$db->delete($keys[0]);
$db->save();
5 years ago
break;
case 2:
$db->delete($keys[0].'.'.$keys[1]);
$db->save();
5 years ago
break;
case 3:
$db->delete($keys[0].'.'.$keys[1].'.'.$keys[2]);
$db->save();
5 years ago
break;
case 4:
$db->delete($keys[0].'.'.$keys[1].'.'.$keys[2].'.'.$keys[3]);
$db->save();
5 years ago
break;
case 5:
$db->delete($keys[0].'.'.$keys[1].'.'.$keys[2].'.'.$keys[3].'.'.$keys[4]);
$db->save();
5 years ago
break;
case 6:
$db->delete($keys[0].'.'.$keys[1].'.'.$keys[2].'.'.$keys[3].'.'.$keys[4].'.'.$keys[5]);
$db->save();
5 years ago
break;
case 7:
$db->delete($keys[0].'.'.$keys[1].'.'.$keys[2].'.'.$keys[3].'.'.$keys[4].'.'.$keys[5].'.'.$keys[6]);
$db->save();
5 years ago
break;
}
}
/**
* Accède aux données
* @param array $keys Clé(s) des données
* @return mixed
*/
public function getData($keys = []) {
if (count($keys) >= 1) {
// Lecture d'une donnée de page en cache
if ($keys[0] === 'page') {
// Décent dans les niveaux de la variable $data
$data = $this->page;
foreach($keys as $key) {
// Si aucune donnée n'existe retourne null
if(isset($data[$key]) === false) {
return null;
}
// Sinon décent dans les niveaux
else {
$data = $data[$key];
}
}
// Retourne les données
return $data;
}
//Retourne une chaine contenant le dossier à créer
$folder = $this->dirData ($keys[0],'fr');
// Constructeur JsonDB
$db = new \Prowebcraft\JsonDb([
'name' => $keys[0] . '.json',
'dir' => $folder,
'template' => self::TEMP_DIR . 'data.template.json'
]);
switch(count($keys)) {
case 1:
$tempData = $db->get($keys[0]);
break;
case 2:
$tempData = $db->get($keys[0].'.'.$keys[1]);
break;
case 3:
$tempData = $db->get($keys[0].'.'.$keys[1].'.'.$keys[2]);
break;
case 4:
$tempData = $db->get($keys[0].'.'.$keys[1].'.'.$keys[2].'.'.$keys[3]);
break;
case 5:
$tempData = $db->get($keys[0].'.'.$keys[1].'.'.$keys[2].'.'.$keys[3].'.'.$keys[4]);
break;
case 6:
$tempData = $db->get($keys[0].'.'.$keys[1].'.'.$keys[2].'.'.$keys[3].'.'.$keys[4].'.'.$keys[5]);
break;
case 7:
$tempData = $db->get($keys[0].'.'.$keys[1].'.'.$keys[2].'.'.$keys[3].'.'.$keys[4].'.'.$keys[5].'.'.$keys[6]);
break;
5 years ago
}
return $tempData;
5 years ago
}
}
/**
* Lecture des fichiers de données de page et mise ne cache
* @param @return string données des pages
*/
3 years ago
public function getPageCache() {
// Trois tentatives
for($i = 0; $i < 3; $i++) {
$data =json_decode(file_get_contents(self::DATA_DIR.'fr/page.json'), true);
if($data) {
return($data);
}
elseif($i === 2) {
3 years ago
exit('Erreur fatale : impossible d\'accéder aux pages');
}
// Pause de 10 millisecondes
usleep(10000);
}
}
/*
* Dummy function
* Compatibilité des modules avec v8 et v9
*/
public function saveData() {
return;
}
5 years ago
/**
* Accède à la liste des pages parents et de leurs enfants
5 years ago
* @param int $parentId Id de la page parent
* @param bool $onlyVisible Affiche seulement les pages visibles
* @param bool $onlyBlock Affiche seulement les pages de type barre
5 years ago
* @return array
*/
public function getHierarchy($parentId = null, $onlyVisible = true, $onlyBlock = false) {
5 years ago
$hierarchy = $onlyVisible ? $this->hierarchy['visible'] : $this->hierarchy['all'];
$hierarchy = $onlyBlock ? $this->hierarchy['bar'] : $hierarchy;
5 years ago
// Enfants d'un parent
if($parentId) {
if(array_key_exists($parentId, $hierarchy)) {
return $hierarchy[$parentId];
}
else {
return [];
}
}
// Parents et leurs enfants
else {
return $hierarchy;
}
}
/**
* Accède à une valeur des variables http (ordre de recherche en l'absence de type : _COOKIE, _POST)
* @param string $key Clé de la valeur
* @param int $filter Filtre à appliquer à la valeur
* @param bool $required Champ requis
* @return mixed
*/
public function getInput($key, $filter = helper::FILTER_STRING_SHORT, $required = false) {
// La clef est un tableau
if(preg_match('#\[(.*)\]#', $key, $secondKey)) {
$firstKey = explode('[', $key)[0];
$secondKey = $secondKey[1];
foreach($this->input as $type => $values) {
// Champ obligatoire
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
5 years ago
if(
array_key_exists($firstKey, $values)
AND array_key_exists($secondKey, $values[$firstKey])
) {
// Retourne la valeur filtrée
if($filter) {
return helper::filter($this->input[$type][$firstKey][$secondKey], $filter);
}
// Retourne la valeur
else {
return $this->input[$type][$firstKey][$secondKey];
}
}
}
}
// La clef est une chaine
else {
foreach($this->input as $type => $values) {
// Champ obligatoire
5 years ago
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
5 years ago
if(array_key_exists($key, $values)) {
// Retourne la valeur filtrée
if($filter) {
return helper::filter($this->input[$type][$key], $filter);
}
// Retourne la valeur
else {
return $this->input[$type][$key];
}
}
}
}
// Sinon retourne null
return helper::filter(null, $filter);
}
/**
* Accède à une partie l'url ou à l'url complète
* @param int $key Clé de l'url
* @return string|null
*/
public function getUrl($key = null) {
// Url complète
if($key === null) {
return $this->url;
}
// Une partie de l'url
else {
$url = explode('/', $this->url);
return array_key_exists($key, $url) ? $url[$key] : null;
}
}
/**
* Accède à l'utilisateur connecté
* @param int $key Clé de la valeur
* @return string|null
*/
public function getUser($key) {
if(is_array($this->user) === false) {
return false;
}
elseif($key === 'id') {
return $this->getInput('ZWII_USER_ID');
}
elseif(array_key_exists($key, $this->user)) {
return $this->user[$key];
}
else {
return false;
}
}
/**
* Check qu'une valeur est transmise par la méthode _POST
* @return bool
*/
public function isPost() {
return ($this->checkCSRF() AND $this->input['_POST'] !== []);
}
/**
* Import des données de la version 9
* Convertit un fichier de données data.json puis le renomme
5 years ago
*/
public function importData($keepUsers = false) {
// Trois tentatives de lecture
5 years ago
for($i = 0; $i < 3; $i++) {
$tempData=json_decode(file_get_contents(self::DATA_DIR.'core.json'), true);
$tempTheme=json_decode(file_get_contents(self::DATA_DIR.'theme.json'), true);
if($tempData && $tempTheme) {
// Backup
rename (self::DATA_DIR.'core.json',self::DATA_DIR.'imported_core.json');
rename (self::DATA_DIR.'theme.json',self::DATA_DIR.'imported_theme.json');
break;
}
elseif($i === 2) {
exit('Impossible de lire les données à importer.');
5 years ago
}
// Pause de 10 millisecondes
usleep(10000);
}
// Dossier de langues
if (!file_exists(self::DATA_DIR . '/fr')) {
mkdir (self::DATA_DIR . '/fr');
}
// Un seul fichier pour éviter les erreurs de sauvegarde des v9
$tempData = array_merge($tempData,$tempTheme);
// Ecriture des données
$this->setData(['config',$tempData['config']]);
$this->setData(['core',$tempData['core']]);
$this->setData(['page',$tempData['page']]);
$this->setData(['module',$tempData['module']]);
$this->setData(['theme',$tempData['theme']]);
// Import des users sauvegardés si option active
if ($keepUsers === false) {
$this->setData(['user',$tempData['user']]);
}
// Nettoyage du fichier de thème pour forcer une régénération
if (file_exists(self::DATA_DIR . '/theme.css')) { // On ne sait jamais
unlink (self::DATA_DIR . '/theme.css');
}
5 years ago
}
/**
* Génère un fichier json avec la liste des pages
*
*/
public function pages2Json() {
// 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) {
$children = [];
// Exclure les barres
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, 'title']), 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, 'title']), 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, 'title']), ENT_QUOTES) ,
'value'=> $rewrite.$parentId
]);
// puis on ajoute les enfants au parent
$parents [] = ['title' => html_entity_decode($this->getData(['page', $parentId, 'title']), 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
];
// 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) {
break;
}
// Pause de 10 millisecondes
usleep(10000);
}
}
/**
* Retourne une chemin localisé pour l'enregistrement des données
* @param $stageId nom du module
* @param $lang langue des pages
* @return string du dossier à créer
*/
public function dirData($id, $lang) {
// Sauf pour les pages et les modules
if ($id === 'page' ||
$id === 'module') {
$folder = self::DATA_DIR . $lang . '/' ;
} else {
$folder = self::DATA_DIR;
}
return ($folder);
}
4 years ago
/**
* Génère un fichier robots.txt à l'installation
* Si le fichier existe déjà les commandes sont ajoutées
4 years ago
*/
public function createRobots() {
$robotValue =
4 years ago
PHP_EOL .
'# ZWII CONFIG ---------' . PHP_EOL .
'User-agent: *' . PHP_EOL .
'Allow: /site/file/' .PHP_EOL .
'Disallow: /site/' .PHP_EOL .
'Sitemap: ' . helper::baseUrl(false) . 'sitemap.xml' . PHP_EOL .
'Sitemap: ' . helper::baseUrl(false) . 'sitemap.xml.gz' . PHP_EOL .
4 years ago
'# ZWII CONFIG ---------' . PHP_EOL ;
if (file_exists('robots.txt')) {
4 years ago
return(file_put_contents(
'robots.txt',
$robotValue,
FILE_APPEND
));
} else {
// Sinon on crée un fichier
return(file_put_contents(
'robots.txt',
$robotValue
));
}
}
/**
* Génère un fichier un fichier sitemap.xml
4 years ago
* https://github.com/icamys/php-sitemap-generator
* $command valeurs possible
* all : génère un site map complet
4 years ago
* Sinon contient id de la page à créer
*/
public function createSitemap($command = "all") {
//require_once "core/vendor/sitemap/SitemapGenerator.php";
4 years ago
$timezone = $this->getData(['config','timezone']);
4 years ago
$sitemap = new \Icamys\SitemapGenerator\SitemapGenerator(helper::baseurl());
// will create also compressed (gzipped) sitemap
$sitemap->createGZipFile = true;
// determine how many urls should be put into one file
// according to standard protocol 50000 is maximum value (see http://www.sitemaps.org/protocol.html)
$sitemap->maxURLsPerSitemap = 50000;
// sitemap file name
$sitemap->sitemapFileName = "sitemap.xml";
4 years ago
$datetime = new DateTime(date('c'));
$datetime->format(DateTime::ATOM); // Updated ISO8601
// sitemap index file name
$sitemap->sitemapIndexFileName = "sitemap-index.xml";
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' ) {
continue;
}
// Page désactivée, traiter les sous-pages sans prendre en compte la page parente.
if ($this->getData(['page', $parentPageId, 'disable']) !== true ) {
$sitemap->addUrl ($parentPageId,$datetime);
}
// Sous-pages
4 years ago
foreach($childrenPageIds as $childKey) {
if ($this->getData(['page',$childKey,'group']) !== 0 || $this->getData(['page', $childKey, 'disable']) === true) {
continue;
}
4 years ago
$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]) as $articleId => $article) {
if($this->getData(['module',$childKey,$articleId,'state']) === true) {
$date = $this->getData(['module',$childKey,$articleId,'publishedOn']);
$sitemap->addUrl( $childKey . '/' . $articleId , new DateTime("@{$date}",new DateTimeZone($timezone)));
}
}
}
}
// Articles du blog
if ($this->getData(['page', $parentPageId, 'moduleId']) === 'blog' &&
!empty($this->getData(['module',$parentPageId])) ) {
foreach($this->getData(['module',$parentPageId]) as $articleId => $article) {
if($this->getData(['module',$parentPageId,$articleId,'state']) === true) {
$date = $this->getData(['module',$parentPageId,$articleId,'publishedOn']);
$sitemap->addUrl( $parentPageId . '/' . $articleId , new DateTime("@{$date}",new DateTimeZone($timezone)));
}
}
4 years ago
}
}
4 years ago
// generating internally a sitemap
$sitemap->createSitemap();
// writing early generated sitemap to file
$sitemap->writeSitemap();
4 years ago
return(file_exists('sitemap.xml'));
}
/*
* Création d'une miniature
* Fonction utilisée lors de la mise à jour d'une version 9 à une version 10
* @param string $src image source
* @param string $dets image destination
* @param integer $desired_width largeur demandée
*/
function makeThumb($src, $dest, $desired_width) {
// Vérifier l'existence du dossier de destination.
$fileInfo = pathinfo($dest);
if (!is_dir($fileInfo['dirname'])) {
mkdir($fileInfo['dirname'],0755,true);
}
// Type d'image
switch( $fileInfo['extension']) {
case 'jpeg':
case 'jpg':
$source_image = imagecreatefromjpeg($src);
break;
case 'png':
$source_image = imagecreatefrompng($src);
break;
case 'gif':
$source_image = imagecreatefromgif($src);
break;
}
// Image valide
if ($source_image) {
$width = imagesx($source_image);
$height = imagesy($source_image);
/* find the "desired height" of this thumbnail, relative to the desired width */
$desired_height = floor($height * ($desired_width / $width));
/* create a new, "virtual" image */
$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) ) {
case 'image/jpeg':
case 'image/jpg':
return (imagejpeg($virtual_image, $dest));
break;
case 'image/png':
return (imagepng($virtual_image, $dest));
break;
case 'image/gif':
return (imagegif($virtual_image, $dest));
break;
}
} else {
return (false);
}
}
/**
5 years ago
* Envoi un mail
* @param string|array $to Destinataire
* @param string $subject Sujet
* @param string $content Contenu
* @return bool
*/
public function sendMail($to, $subject, $content, $replyTo = null) {
3 years ago
5 years ago
// Layout
ob_start();
include 'core/layout/mail.php';
5 years ago
$layout = ob_get_clean();
$mail = new PHPMailer\PHPMailer\PHPMailer;
$mail->CharSet = 'UTF-8';
5 years ago
// Mail
try{
3 years ago
// Paramètres SMTP
if ($this->getdata(['config','smtp','enable'])) {
//$mail->SMTPDebug = PHPMailer\PHPMailer\SMTP::DEBUG_SERVER;
3 years ago
$mail->isSMTP();
$mail->SMTPAutoTLS = false;
3 years ago
$mail->Host = $this->getdata(['config','smtp','host']);
$mail->Port = (int) $this->getdata(['config','smtp','port']);
if ($this->getData(['config','smtp','auth'])) {
3 years ago
$mail->Username = $this->getData(['config','smtp','username']);
$mail->Password = helper::decrypt($this->getData(['config','smtp','username']),$this->getData(['config','smtp','password']));
3 years ago
$mail->SMTPAuth = $this->getData(['config','smtp','auth']);