Initial commit

This commit is contained in:
2020-11-02 15:46:52 +01:00
commit 17f974127c
13788 changed files with 1921656 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : thelia@openstudio.fr */
/* web : http://www.openstudio.fr */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/*    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
require_once __DIR__ . "/../../fonctions/autoload.php";
abstract class FiltreBase
{
public function __construct($regexp)
{
$this->regexp = $regexp;
}
public function init() {
}
public function prerequis() {
return true;
}
public function destroy() {
}
public function exec(&$texte)
{
if (preg_match_all($this->regexp, $texte, $matches, PREG_SET_ORDER)) {
foreach($matches as $match) {
// On ne remplace que le première occurence du filtre. En effet,
// si on a plusieurs occurences identiques du filtre, str_replace()
// remplacera toutes ces occurences en une seule fois, ce qui n'est
// peut-être pas le comportement adéquat.
// Cf. http://thelia.net/forum/viewtopic.php?id=8017
$texte = substr_replace(
$texte,
$this->calcule($match),
strpos($texte, $match[0]),
strlen($match[0])
);
}
}
}
public abstract function calcule($match);
}
?>

View File

@@ -0,0 +1,38 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : thelia@openstudio.fr */
/* web : http://www.openstudio.fr */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* Ê Êalong with this program. ÊIf not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
require_once __DIR__ . "/../../fonctions/autoload.php";
class FiltreDifferent extends FiltreBase {
public function __construct()
{
parent::__construct("`\#FILTRE_different\(([^\|]*)\|\|([^\|]*)\|\|([^\)]*)\)`");
}
public function calcule($match)
{
return $match[1] != $match[2] ? $match[3] : '';
}
}
?>

View File

@@ -0,0 +1,38 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : thelia@openstudio.fr */
/* web : http://www.openstudio.fr */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* Ê Êalong with this program. ÊIf not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
require_once __DIR__ . "/../../fonctions/autoload.php";
class FiltreEgalite extends FiltreBase {
public function __construct()
{
parent::__construct("`\#FILTRE_egalite\(([^\|]*)\|\|([^\|]*)\|\|([^\)]*)\)`");
}
public function calcule($match)
{
return $match[1] == $match[2] ? $match[3] : '';
}
}
?>

View File

@@ -0,0 +1,38 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : thelia@openstudio.fr */
/* web : http://www.openstudio.fr */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* Ê Êalong with this program. ÊIf not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
require_once __DIR__ . "/../../fonctions/autoload.php";
class FiltreFaux extends FiltreBase {
public function __construct()
{
parent::__construct("`\#FILTRE_faux\(([^\|]+)\|\|([^\)]+)\)`");
}
public function calcule($match)
{
return $match[1] == '0' ? $match[2] : '';
}
}
?>

View File

@@ -0,0 +1,53 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : thelia@openstudio.fr */
/* web : http://www.openstudio.fr */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* Ê Êalong with this program. ÊIf not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
require_once __DIR__ . "/../../fonctions/autoload.php";
class FiltreFonction extends FiltreBase {
public function __construct($nom_filtre)
{
switch($nom_filtre)
{
case 'min' :
$this->fonction = 'strtolower';
break;
case 'maj' :
$this->fonction = 'strtoupper';
break;
case 'sanstags' :
$this->fonction = 'strip_tags';
break;
}
parent::__construct("`\#FILTRE_$nom_filtre\(([^\)]+)\)`");
}
public function calcule($match)
{
$func = $this->fonction;
return $func($match[1]);
}
}
?>

View File

@@ -0,0 +1,39 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : thelia@openstudio.fr */
/* web : http://www.openstudio.fr */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/*    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
require_once __DIR__ . "/../../fonctions/autoload.php";
// Renommé en FiltreModuloInt, pour ne pas interférer avec un éventuel plugin filtremodulo déjà installé
class FiltreModuloInt extends FiltreBase {
public function __construct()
{
parent::__construct("`\#FILTRE_modulo\(([^\|]*)\|\|([^\)]*)\|\|([^\)]*)\)`");
}
public function calcule($match)
{
return trim($match[1]) % trim($match[2]) == 0 ? $match[3] : '';
}
}
?>

View File

@@ -0,0 +1,38 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
require_once __DIR__ . "/../../fonctions/autoload.php";
class FiltreSupegal extends FiltreBase {
public function __construct()
{
parent::__construct("`\#FILTRE_supegal\(([^\|]+)\|\|([^\|]+)\|\|([^\|]+)\|\|([^\)]+)\)`");
}
public function calcule($match)
{
return $match[1] >= $match[2] ? $match[3] : $match[4];
}
}
?>

View File

@@ -0,0 +1,38 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : thelia@openstudio.fr */
/* web : http://www.openstudio.fr */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* Ê Êalong with this program. ÊIf not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
require_once __DIR__ . "/../../fonctions/autoload.php";
class FiltreVide extends FiltreBase {
public function __construct()
{
parent::__construct("`\#FILTRE_vide\(([^\|]*)\|\|([^\)]+)\)`");
}
public function calcule($match)
{
return trim($match[1]) == '' ? '' : $match[2];
}
}
?>

View File

@@ -0,0 +1,38 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : thelia@openstudio.fr */
/* web : http://www.openstudio.fr */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* Ê Êalong with this program. ÊIf not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
require_once __DIR__ . "/../../fonctions/autoload.php";
class FiltreVrai extends FiltreBase {
public function __construct()
{
parent::__construct("`\#FILTRE_vrai\(([^\|]+)\|\|([^\)]+)\)`");
}
public function calcule($match)
{
return $match[1] == '1' ? $match[2] : '';
}
}
?>

View File

@@ -0,0 +1,124 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : thelia@openstudio.fr */
/* web : http://www.openstudio.fr */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/*    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
require_once __DIR__ . "/../../fonctions/autoload.php";
class Filtres {
/*
* Les filtres par défaut, liste de couples : suffixe_du nom_de_filtre => suffixe_nom_de_classe
*
*/
static $FILTRES_DEFAUT = array(
'vide' => 'Vide',
'vrai' => 'Vrai',
'faux' => 'Faux',
'egalite' => 'Egalite',
'different' => 'Different',
'min' => 'Fonction',
'maj' => 'Fonction',
'sanstags' => 'Fonction',
'modulo' => 'ModuloInt',
'supegal' => 'Supegal'
);
/*
* Les filtres utilisateurs: instance d'une classe qui implémente FiltreBase. Enrichi par la méthode enregistrer_filtre().
*
* Exemple:
*
* class FiltreExemple extends FiltreBase
* {
* public function __construct()
* {
* parent::__construct("`\#FILTRE_exemple\(([^\|]*)\)`");
* }
*
* public function calcule($match)
* {
* return 'Filtré:'.$match[1];
* }
*
* }
*/
private static $FILTRES_UTILISATEUR = array();
/*
* Effectuer les subtitutions de tous les filtres
*
* @param FiltreBase $filtre une instance de classe qui implémente FiltreBase
*/
public static function exec(&$texte)
{
foreach(self::$FILTRES_DEFAUT as $nom_filtre => $class)
{
if(strstr($texte, "#FILTRE_$nom_filtre")) {
$classname = "Filtre$class";
require_once("$classname.class.php");
$f = new $classname($nom_filtre);
$f->exec($texte);
}
}
// Les filtres présents dans client/plugins
$filtres_utilisateur = ActionsModules::instance()->lister(Modules::FILTRE, true);
// Filtres utilisateur
foreach($filtres_utilisateur as $filtre)
{
try {
$instance = ActionsModules::instance()->instancier($filtre->nom);
$instance->exec($texte);
} catch (Exception $e) {}
}
// Les filtres explicitement enregistrés par enregistrer_filtres();
foreach(self::$FILTRES_UTILISATEUR as $filtre)
{
$filtre->exec($texte);
}
}
/*
* Enregistrer un filtre utilisateur.
*
* @param FiltreBase $filtre une instance de classe qui implémente FiltreBase
*/
public static function enregistrer_filtre($filtre)
{
if ($filtre instanceof FiltreBase) {
self::$FILTRES_UTILISATEUR[] = $filtre;
}
else {
die(class_name($filtre) . " doit implémenter la classe FiltreBase.");
}
}
}
?>