Rajout du dossier core + MAJ .gitignore
This commit is contained in:
133
core/lib/Thelia/Log/Destination/TlogDestinationFile.php
Normal file
133
core/lib/Thelia/Log/Destination/TlogDestinationFile.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Log\Destination;
|
||||
|
||||
use Thelia\Log\AbstractTlogDestination;
|
||||
use Thelia\Log\TlogDestinationConfig;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
class TlogDestinationFile extends AbstractTlogDestination
|
||||
{
|
||||
// Nom des variables de configuration
|
||||
// ----------------------------------
|
||||
const VAR_PATH_FILE = "tlog_destinationfile_path";
|
||||
const TLOG_DEFAULT_NAME = "log-thelia.txt";
|
||||
|
||||
const VAR_MODE = "tlog_destinationfile_mode";
|
||||
const VALEUR_MODE_DEFAULT = "A";
|
||||
|
||||
protected $path_defaut = false;
|
||||
protected $fh = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->path_defaut = "log" . DS . self::TLOG_DEFAULT_NAME;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function getFilePath()
|
||||
{
|
||||
$filePath = $this->getConfig(self::VAR_PATH_FILE);
|
||||
|
||||
if (preg_match('/^[a-z]:\\\|^\//i', $filePath) === 0) {
|
||||
$filePath = THELIA_ROOT . $filePath;
|
||||
}
|
||||
|
||||
return $filePath;
|
||||
}
|
||||
|
||||
protected function getOpenMode()
|
||||
{
|
||||
return strtolower($this->getConfig(self::VAR_MODE, self::VALEUR_MODE_DEFAULT)) == 'a' ? 'a' : 'w';
|
||||
}
|
||||
|
||||
public function configure()
|
||||
{
|
||||
$filePath = $this->getFilePath();
|
||||
$mode = $this->getOpenMode();
|
||||
|
||||
if (!empty($filePath)) {
|
||||
$this->resolvePath($filePath, $mode);
|
||||
}
|
||||
}
|
||||
|
||||
protected function resolvePath($filePath, $mode)
|
||||
{
|
||||
if (! empty($filePath)) {
|
||||
if (! is_file($filePath)) {
|
||||
$dir = dirname($filePath);
|
||||
if (! is_dir($dir)) {
|
||||
mkdir($dir, 0777, true);
|
||||
}
|
||||
|
||||
touch($filePath);
|
||||
chmod($filePath, 0666);
|
||||
}
|
||||
|
||||
if ($this->fh) {
|
||||
@fclose($this->fh);
|
||||
}
|
||||
|
||||
$this->fh = fopen($filePath, $mode);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return Translator::getInstance()->trans('Text File');
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return Translator::getInstance()->trans('Store logs into text file');
|
||||
}
|
||||
|
||||
public function getConfigs()
|
||||
{
|
||||
return array(
|
||||
new TlogDestinationConfig(
|
||||
self::VAR_PATH_FILE,
|
||||
'Absolute file path',
|
||||
'You should enter an abolute file path. The base directory of your Thelia installation is '.THELIA_ROOT,
|
||||
$this->path_defaut,
|
||||
TlogDestinationConfig::TYPE_TEXTFIELD
|
||||
),
|
||||
new TlogDestinationConfig(
|
||||
self::VAR_MODE,
|
||||
'File opening mode (A or E)',
|
||||
'Enter E to empty this file for each request, or A to always append logs. Consider resetting the file from time to time',
|
||||
self::VALEUR_MODE_DEFAULT,
|
||||
TlogDestinationConfig::TYPE_TEXTFIELD
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function add($texte)
|
||||
{
|
||||
if ($this->fh) {
|
||||
fwrite($this->fh, $texte."\n");
|
||||
}
|
||||
}
|
||||
|
||||
public function write(&$res)
|
||||
{
|
||||
if ($this->fh) {
|
||||
@fclose($this->fh);
|
||||
}
|
||||
|
||||
$this->fh = false;
|
||||
}
|
||||
}
|
||||
66
core/lib/Thelia/Log/Destination/TlogDestinationHtml.php
Normal file
66
core/lib/Thelia/Log/Destination/TlogDestinationHtml.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Log\Destination;
|
||||
|
||||
use Thelia\Log\AbstractTlogDestination;
|
||||
use Thelia\Log\TlogDestinationConfig;
|
||||
|
||||
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 configure()
|
||||
{
|
||||
$this->style = $this->getConfig(self::VAR_STYLE);
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return "Direct HTML display";
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return "Display logs in HTML format, on top of generated pages.";
|
||||
}
|
||||
|
||||
public function getConfigs()
|
||||
{
|
||||
return array(
|
||||
new TlogDestinationConfig(
|
||||
self::VAR_STYLE,
|
||||
"CSS of each log line",
|
||||
"You may also leave this field empty, and define a \"tlog-trace\" style in your CSS.",
|
||||
self::VALEUR_STYLE_DEFAUT,
|
||||
TlogDestinationConfig::TYPE_TEXTAREA
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function write(&$res)
|
||||
{
|
||||
$block = sprintf('<pre class="tlog-trace" style="%s">%s</pre>', $this->style, htmlspecialchars(implode("\n", $this->logs)));
|
||||
|
||||
$this->insertAfterBody($res, $block);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Log\Destination;
|
||||
|
||||
use Thelia\Log\AbstractTlogDestination;
|
||||
|
||||
class TlogDestinationJavascriptConsole extends AbstractTlogDestination
|
||||
{
|
||||
public function getTitle()
|
||||
{
|
||||
return "Browser's Javascript console";
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return "The Thelia logs are displayed in your browser's Javascript console.";
|
||||
}
|
||||
|
||||
public function write(&$res)
|
||||
{
|
||||
$content = '<script>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("|</body>|i", $res)) {
|
||||
$res = preg_replace("|</body>|i", "$content</html>", $res);
|
||||
}
|
||||
}
|
||||
}
|
||||
38
core/lib/Thelia/Log/Destination/TlogDestinationNull.php
Normal file
38
core/lib/Thelia/Log/Destination/TlogDestinationNull.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Log\Destination;
|
||||
|
||||
use Thelia\Log\AbstractTlogDestination;
|
||||
|
||||
class TlogDestinationNull extends AbstractTlogDestination
|
||||
{
|
||||
public function getTitle()
|
||||
{
|
||||
return "Black hole";
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return "This destinations consumes the logs but don't display them";
|
||||
}
|
||||
|
||||
public function add($string)
|
||||
{
|
||||
// Rien
|
||||
}
|
||||
|
||||
public function write(&$res)
|
||||
{
|
||||
// Rien
|
||||
}
|
||||
}
|
||||
104
core/lib/Thelia/Log/Destination/TlogDestinationPopup.php
Normal file
104
core/lib/Thelia/Log/Destination/TlogDestinationPopup.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Log\Destination;
|
||||
|
||||
use Thelia\Log\AbstractTlogDestination;
|
||||
use Thelia\Log\TlogDestinationConfig;
|
||||
|
||||
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 getTitle()
|
||||
{
|
||||
return "Javascript popup window";
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return "Display logs in a popup window, separate from the main window .";
|
||||
}
|
||||
|
||||
public function getConfigs()
|
||||
{
|
||||
return array(
|
||||
new TlogDestinationConfig(
|
||||
self::VAR_POPUP_TPL,
|
||||
"Popup windows template",
|
||||
"Put #LOGTEXT in the template text where you want to display logs..",
|
||||
file_get_contents(__DIR__.DS. self::VALEUR_POPUP_TPL_DEFAUT),
|
||||
TlogDestinationConfig::TYPE_TEXTAREA
|
||||
),
|
||||
new TlogDestinationConfig(
|
||||
self::VAR_POPUP_HEIGHT,
|
||||
"Height of the popup window",
|
||||
"In pixels",
|
||||
self::VALEUR_POPUP_HEIGHT_DEFAUT,
|
||||
TlogDestinationConfig::TYPE_TEXTFIELD
|
||||
),
|
||||
new TlogDestinationConfig(
|
||||
self::VAR_POPUP_WIDTH,
|
||||
"Width of the popup window",
|
||||
"In pixels",
|
||||
self::VALEUR_POPUP_WIDTH_DEFAUT,
|
||||
TlogDestinationConfig::TYPE_TEXTFIELD
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function write(&$res)
|
||||
{
|
||||
$content = "";
|
||||
$count = 1;
|
||||
|
||||
foreach ($this->logs as $line) {
|
||||
$content .= "<div class=\"".($count++ % 2 ? "paire" : "impaire")."\">".htmlspecialchars($line)."</div>";
|
||||
}
|
||||
|
||||
$tpl = $this->getConfig(self::VAR_POPUP_TPL);
|
||||
|
||||
$tpl = str_replace('#LOGTEXT', $content, $tpl);
|
||||
$tpl = str_replace(array("\r\n", "\r", "\n"), '\\n', $tpl);
|
||||
|
||||
$wop = sprintf(
|
||||
'<script>
|
||||
_thelia_console = window.open("","thelia_console","width=%s,height=%s,resizable,scrollbars=yes");
|
||||
if (_thelia_console == null) {
|
||||
alert("The log popup window could not be opened. Please disable your popup blocker for this site.");
|
||||
} else {
|
||||
_thelia_console.document.write("%s");
|
||||
_thelia_console.document.close();
|
||||
}
|
||||
</script>',
|
||||
$this->getConfig(self::VAR_POPUP_WIDTH),
|
||||
$this->getConfig(self::VAR_POPUP_HEIGHT),
|
||||
str_replace('"', '\\"', $tpl)
|
||||
);
|
||||
|
||||
if (preg_match("|</body>|i", $res)) {
|
||||
$res = preg_replace("|</body>|i", "$wop\n</body>", $res);
|
||||
} else {
|
||||
$res .= $wop;
|
||||
}
|
||||
}
|
||||
}
|
||||
52
core/lib/Thelia/Log/Destination/TlogDestinationPopup.tpl
Normal file
52
core/lib/Thelia/Log/Destination/TlogDestinationPopup.tpl
Normal file
@@ -0,0 +1,52 @@
|
||||
<!--
|
||||
Default template for TlogDestinationPopup. Insert #LOGTEXT where you want to
|
||||
write the log text in your template.
|
||||
-->
|
||||
<!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>Thelia logs</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>#LOGTEXT</pre>
|
||||
</body>
|
||||
</html>
|
||||
119
core/lib/Thelia/Log/Destination/TlogDestinationRotatingFile.php
Normal file
119
core/lib/Thelia/Log/Destination/TlogDestinationRotatingFile.php
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Log\Destination;
|
||||
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Thelia\Log\TlogDestinationConfig;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
class TlogDestinationRotatingFile extends TlogDestinationFile
|
||||
{
|
||||
// Nom des variables de configuration
|
||||
// ----------------------------------
|
||||
|
||||
const VAR_MAX_FILE_SIZE_KB = "tlog_destinationfile_max_file_size";
|
||||
const VAR_MAX_FILE_COUNT = "tlog_destinationfile_max_file_count";
|
||||
|
||||
const MAX_FILE_SIZE_KB_DEFAULT = 1024; // 1 Mb
|
||||
const MAX_FILE_COUNT_DEFAULT = 10;
|
||||
|
||||
public function __construct($maxFileSize = self::MAX_FILE_SIZE_KB_DEFAULT)
|
||||
{
|
||||
$this->path_defaut = "log" . DS . self::TLOG_DEFAULT_NAME;
|
||||
|
||||
$this->setConfig(self::VAR_MAX_FILE_SIZE_KB, $maxFileSize, false);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$filePath = $this->getFilePath();
|
||||
$mode = $this->getOpenMode();
|
||||
|
||||
if ($this->fh) {
|
||||
@fclose($this->fh);
|
||||
}
|
||||
|
||||
if (filesize($filePath) > 1024 * $this->getConfig(self::VAR_MAX_FILE_SIZE_KB, self::MAX_FILE_SIZE_KB_DEFAULT)) {
|
||||
$backupFile = $filePath . '.' . strftime('%Y-%m-%d_%H-%M-%S');
|
||||
|
||||
@rename($filePath, $backupFile);
|
||||
|
||||
@touch($filePath);
|
||||
@chmod($filePath, 0666);
|
||||
|
||||
// Keep the number of files below VAR_MAX_FILE_COUNT
|
||||
$maxCount = $this->getConfig(self::VAR_MAX_FILE_COUNT, self::MAX_FILE_COUNT_DEFAULT);
|
||||
|
||||
$finder = new Finder();
|
||||
|
||||
$files = $finder
|
||||
->in(dirname($filePath))
|
||||
->files()
|
||||
->name(basename($filePath).'.*')
|
||||
->sortByModifiedTime();
|
||||
|
||||
$deleteCount = 1 + $files->count() - $maxCount;
|
||||
|
||||
if ($deleteCount > 0) {
|
||||
foreach ($files as $file) {
|
||||
@unlink($file);
|
||||
|
||||
if (--$deleteCount <= 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->fh = fopen($filePath, $mode);
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return Translator::getInstance()->trans('Rotated Text File');
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return Translator::getInstance()->trans('Store logs into text file, up to a certian size, then a new file is created');
|
||||
}
|
||||
|
||||
public function getConfigs()
|
||||
{
|
||||
$arr = parent::getConfigs();
|
||||
|
||||
$arr[] =
|
||||
new TlogDestinationConfig(
|
||||
self::VAR_MAX_FILE_SIZE_KB,
|
||||
'Maximum log file size, in Kb',
|
||||
'When this size if exeeded, a backup copy of the file is made, and a new log file is opened. As the file size check is performed only at the beginning of a request, the file size may be bigger thant this limit. Note: 1 Mb = 1024 Kb',
|
||||
self::MAX_FILE_SIZE_KB_DEFAULT,
|
||||
TlogDestinationConfig::TYPE_TEXTFIELD
|
||||
);
|
||||
|
||||
$arr[] =
|
||||
new TlogDestinationConfig(
|
||||
self::VAR_MAX_FILE_COUNT,
|
||||
'Maximum number of files to keep',
|
||||
'When this number if exeeded, the oldest files are deleted.',
|
||||
self::MAX_FILE_COUNT_DEFAULT,
|
||||
TlogDestinationConfig::TYPE_TEXTFIELD
|
||||
);
|
||||
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
43
core/lib/Thelia/Log/Destination/TlogDestinationText.php
Normal file
43
core/lib/Thelia/Log/Destination/TlogDestinationText.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Log\Destination;
|
||||
|
||||
use Thelia\Log\AbstractTlogDestination;
|
||||
|
||||
class TlogDestinationText extends AbstractTlogDestination
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
{
|
||||
return "Direct text display";
|
||||
}
|
||||
|
||||
public function getDescription()
|
||||
{
|
||||
return "Display logs in raw text format, on top of generated pages.";
|
||||
}
|
||||
|
||||
public function add($texte)
|
||||
{
|
||||
echo trim($texte)."\n";
|
||||
}
|
||||
|
||||
public function write(&$res)
|
||||
{
|
||||
// Rien
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user