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,115 @@
<?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 AbstractTlogDestination {
//Tableau de TlogDestinationConfig paramétrant la destination
protected $_configs;
//Tableau des lignes de logs stockés avant utilisation par ecrire()
protected $_logs;
// Vaudra true si on est dans le back office.
protected $flag_back_office = false;
public function __construct() {
$this->_configs = array();
$this->_logs = array();
// Initialiser les variables de configuration
$this->_configs = $this->get_configs();
// Appliquer la configuration
$this->configurer();
}
//Affecte une valeur à une configuration de la destination
public function set_config($nom, $valeur) {
foreach($this->_configs as $config) {
if($config->nom == $nom) {
$config->valeur = $valeur;
// Appliquer les changements
$this->configurer($config);
return true;
}
}
return false;
}
//Récupère la valeur affectée à une configuration de la destination
public function get_config($nom) {
foreach($this->_configs as $config) {
if($config->nom == $nom) {
return $config->valeur;
}
}
return false;
}
public function get_configs() {
return $this->_configs;
}
public function mode_back_office($bool) {
$this->flag_back_office = $bool;
}
//Ajoute une ligne de logs à la destination
public function ajouter($string) {
$this->_logs[] = $string;
}
protected function inserer_apres_body(&$res, $logdata) {
$match = array();
if (preg_match("/(<body[^>]*>)/i", $res, $match)) {
$res = str_replace($match[0], $match[0] . "\n" . $logdata, $res);
}
else {
$res = $logdata . $res;
}
}
// Demande à la destination de se configurer pour être prête
// a fonctionner. Si $config est != false, celà indique
// que seul le paramètre de configuration indiqué a été modifié.
protected function configurer($config = false) {
// Cette methode doit etre surchargée si nécessaire.
}
//Lance l'écriture de tous les logs par la destination
//$res : contenu de la page html
abstract public function ecrire(&$res);
// Retourne le titre de cette destination, tel qu'affiché dans le menu de selection
abstract public function get_titre();
// Retourne une brève description de la destination
abstract public function get_description();
}
?>

View File

@@ -0,0 +1,61 @@
<?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 TlogDestinationConfig extends Variable {
const TYPE_TEXTAREA = 1;
const TYPE_TEXTFIELD = 2;
public $titre;
public $label;
public $defaut;
public $type;
public $valeur;
public function __construct($nom, $titre, $label, $defaut, $type) {
parent::__construct();
$this->nom = $nom;
$this->titre = $titre;
$this->label = $label;
$this->defaut = $defaut;
$this->type = $type;
$this->charger();
}
public function charger() {
// La variable n'existe pas ? La créer en y affectant la valeur par defaut
if (! parent::charger($this->nom)) {
$this->valeur = $this->defaut;
$this->protege = 1;
$this->cache = 1;
$this->add();
}
}
}
?>

View File

@@ -0,0 +1,56 @@
<?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 TlogDestinationConsoleJavascript extends AbstractTlogDestination {
public function __construct() {
parent::__construct();
}
public function get_titre() {
return "Console javascript";
}
public function get_description() {
return "Permet d'afficher les logs dans la console Javascript de votre navigateur.";
}
public function ecrire(&$res) {
$content = '<script type="text/javascript">try {'."\n";
foreach($this->_logs as $line) {
$content .= "console.log('".str_replace("'", "\\'", str_replace(array("\r\n", "\r", "\n"), '\\n', $line))."');\n";
}
$content .= '} catch(ex) { alert("Les logs Thelia ne peuvent être affichés dans la console javascript:" + ex); }</script>'."\n";
if (preg_match("|</html>|i", $content))
$res = preg_replace("|</html>|i", "$content</html>", $res);
else
$res .= $content;
}
}
?>

View File

@@ -0,0 +1,103 @@
<?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 TlogDestinationFichier extends AbstractTlogDestination {
// Nom des variables de configuration
// ----------------------------------
const VAR_PATH_FICHIER = "tlog_destinationfichier_path";
const VALEUR_NOM_DEFAUT = "log-thelia.txt";
const VAR_MODE = "tlog_destinationfichier_mode";
const VALEUR_MODE_DEFAUT = "E";
protected $path_defaut = false;
protected $fh = false;
public function __construct() {
$this->path_defaut = __DIR__. "/../../../client/tlog/".self::VALEUR_NOM_DEFAUT;
parent::__construct();
}
public function configurer($config = false) {
$file_path = $this->get_config(self::VAR_PATH_FICHIER);
$mode = strtolower($this->get_config(self::VAR_MODE)) == 'a' ? 'a' : 'w';
if (! empty($file_path)) {
if (! is_file($file_path)) {
$dir = dirname($file_path);
if(! is_dir($dir)) {
mkdir($dir, 0777, true);
}
}
if ($this->fh) @fclose($this->fh);
$this->fh = fopen($file_path, $mode);
}
}
public function get_titre() {
return "Fichier texte";
}
public function get_description() {
return "Permet de stocker les logs dans un fichier de votre choix";
}
public function get_configs() {
return array(
new TlogDestinationConfig(
self::VAR_PATH_FICHIER,
"Chemin du fichier",
"Attention, vous devez indiquer un chemin absolu.<br />Le répertoire de base de votre Thelia est ".dirname(getcwd()),
$this->path_defaut,
TlogDestinationConfig::TYPE_TEXTFIELD
),
new TlogDestinationConfig(
self::VAR_MODE,
"Mode d'ouverture (A ou E)",
"Indiquez E pour ré-initialiser le fichier à chaque requête, A pour ne jamais réinitialiser le fichier. Pensez à le vider de temps en temps !",
self::VALEUR_MODE_DEFAUT,
TlogDestinationConfig::TYPE_TEXTFIELD
)
);
}
public function ajouter($texte) {
if ($this->fh) {
fwrite($this->fh, $texte."\n");
}
}
public function ecrire(&$res) {
if ($this->fh) @fclose($this->fh);
$this->fh = false;
}
}
?>

View File

@@ -0,0 +1,71 @@
<?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 TlogDestinationHtml extends AbstractTlogDestination {
// Nom des variables de configuration
// ----------------------------------
const VAR_STYLE = "tlog_destinationhtml_style";
const VALEUR_STYLE_DEFAUT = "text-align: left; font-size: 12px; font-weight: normal; line-height: 14px; float: none; display:block; color: #000; background-color: #fff; font-family: Courier New, courier,fixed;";
private $style;
public function __construct() {
parent::__construct();
}
public function configurer($config = false) {
$this->style = $this->get_config(self::VAR_STYLE);
}
public function get_titre() {
return "Affichage direct dans la page, en HTML";
}
public function get_description() {
return "Permet d'afficher les logs directement dans la page resultat, avec une mise en forme HTML.";
}
public function get_configs() {
return array(
new TlogDestinationConfig(
self::VAR_STYLE,
"Style d'affichage direct dans la page",
"Vous pouvez aussi laisser ce champ vide, et créer un style \"tlog-trace\" dans votre feuille de style.",
self::VALEUR_STYLE_DEFAUT,
TlogDestinationConfig::TYPE_TEXTAREA
)
);
}
public function ecrire(&$res) {
$block = sprintf('<pre class="tlog-trace" style="%s">%s</pre>', $this->style, htmlspecialchars(implode("\n", $this->_logs)));
$this->inserer_apres_body($res, $block);
}
}
?>

View File

@@ -0,0 +1,75 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) 2005-2013 OpenStudio */
/* email : info@thelia.fr */
/* 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 TlogDestinationMail extends AbstractTlogDestination {
// Nom des variables de configuration
// ----------------------------------
const VAR_ADRESSES = "tlog_mail_adresses";
public function __construct() {
parent::__construct();
}
public function get_titre() {
return "E-Mail";
}
public function get_description() {
return "Envoie le log par e-mail aux adresses indiquées";
}
public function get_configs() {
return array(
new TlogDestinationConfig(
self::VAR_ADRESSES,
"Destinataires",
"Indiquez une ou plusieurs adresses e-mail séparées par point-virgule",
Variable::lire('emailfrom'),
TlogDestinationConfig::TYPE_TEXTFIELD
)
);
}
public function ecrire(&$res) {
$texte = implode("\n", $this->_logs);
if (! empty($texte)) {
$adresses = explode(";", $this->get_config(self::VAR_ADRESSES));
// Un CC serait plus efficace...
foreach($adresses as $adresse) {
Mail::envoyer (
"", $adresse,
"Log " . Variable::lire('nomsite'), Variable::lire('emailfrom'),
strftime("%d/%m/%Y %H:%M:%S", time()) . " - Logs " . Variable::lire('nomsite'),
"", $texte);
}
}
}
}
?>

View File

@@ -0,0 +1,45 @@
<?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 TlogDestinationNull extends AbstractTlogDestination {
public function get_titre() {
return "Trou noir";
}
public function get_description() {
return "Cette destination ne provoque aucune sortie";
}
public function ajouter($string) {
// Rien
}
public function ecrire(&$res) {
// Rien
}
}
?>

View File

@@ -0,0 +1,108 @@
<?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 TlogDestinationPopup extends AbstractTlogDestination {
// Nom des variables de configuration
// ----------------------------------
const VAR_POPUP_WIDTH = "tlog_destinationpopup_width";
const VALEUR_POPUP_WIDTH_DEFAUT = "600";
const VAR_POPUP_HEIGHT = "tlog_destinationpopup_height";
const VALEUR_POPUP_HEIGHT_DEFAUT = "600";
const VAR_POPUP_TPL = "tlog_destinationpopup_template";
// Ce fichier doit se trouver dans le même répertoire que TlogDestinationPopup.class.php
const VALEUR_POPUP_TPL_DEFAUT = "TlogDestinationPopup.tpl";
public function __construct() {
parent::__construct();
}
public function get_titre() {
return "Fenêtre javascript";
}
public function get_description() {
return "Permet d'afficher les logs dans une fenêtre séparée de la fenêtre principale.";
}
public function get_configs() {
return array(
new TlogDestinationConfig(
self::VAR_POPUP_TPL,
"Template de la fenêtre popup",
"Insérez #DEBUGTEXT à l'endroit où vous voulez afficher les logs.",
file_get_contents(__DIR__."/" . self::VALEUR_POPUP_TPL_DEFAUT),
TlogDestinationConfig::TYPE_TEXTAREA
),
new TlogDestinationConfig(
self::VAR_POPUP_HEIGHT,
"Hauteur de la fenêtre popup",
"En pixels",
self::VALEUR_POPUP_HEIGHT_DEFAUT,
TlogDestinationConfig::TYPE_TEXTFIELD
),
new TlogDestinationConfig(
self::VAR_POPUP_WIDTH,
"Largeur de la fenêtre popup",
"En pixels",
self::VALEUR_POPUP_WIDTH_DEFAUT,
TlogDestinationConfig::TYPE_TEXTFIELD
)
);
}
public function ecrire(&$res) {
$content = ""; $count = 1;
foreach($this->_logs as $line) {
$content .= "<div class=\"".($count++ % 2 ? "paire" : "impaire")."\">".htmlspecialchars($line)."</div>";
}
$tpl = $this->get_config(self::VAR_POPUP_TPL);
$tpl = str_replace('#DEBUGTEXT', $content, $tpl);
$tpl = str_replace(array("\r\n", "\r", "\n"), '\\n', $tpl);
$wop = sprintf('
<script type="text/javascript">
_thelia_console = window.open("","console_thelia","width=%s,height=%s,resizable,scrollbars=yes");
_thelia_console.document.write("%s");
_thelia_console.document.close();
</script>',
$this->get_config(self::VAR_POPUP_WIDTH),
$this->get_config(self::VAR_POPUP_HEIGHT),
str_replace('"', '\\"', $tpl)
);
if (preg_match("|</html>|i", $res))
$res = preg_replace("|</html>|i", "$wop\n</html>", $res);
else
$res .= $wop;
}
}
?>

View File

@@ -0,0 +1,51 @@
<!--
Template par defaut pour la destination TlogDestinationPopup
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Debug THELIA</title>
<style type="text/css">
body, h1, h2, td, th, p {
font-family: "Courier New", courier, fixed;
font-weight: normal;
font-size: 0.9em;
margin: 0;
padding: 0;
}
h1 {
background-color: #868F99;
border-bottom: 2px solid #127AED;
color: #FFFFFF;
font-family: Arial,Helvetica,sans-serif;
font-weight: bold;
line-height: 20px;
padding: 5px;
}
pre {
margin: 0;
}
.paire {
background-color: #EBEDEE;
padding: 5px;
border-bottom: 1px dotted #fff;
}
.impaire {
background-color: #D4DADD;
padding: 5px;
border-bottom: 1px dotted #fff;
}
</style>
</head>
<body>
<h1>Thelia Debug</h1>
<pre>#DEBUGTEXT</pre>
</body>
</html>

View File

@@ -0,0 +1,48 @@
<?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 TlogDestinationTexte extends AbstractTlogDestination {
public function __construct() {
parent::__construct();
}
public function get_titre() {
return "Affichage direct dans la page, en texte brut";
}
public function get_description() {
return "Permet d'afficher les logs directement dans la page resultat, au format texte brut.";
}
public function ajouter($texte) {
echo $texte."\n";
}
public function ecrire(&$res) {
// Rien
}
}
?>