[SPIP][PLUGINS] v3.0-->v3.2
[lhc/web/www.git] / www / ecrire / inc / log.php
index 07f9e78..34c4ca2 100644 (file)
 /***************************************************************************\
  *  SPIP, Systeme de publication pour l'internet                           *
  *                                                                         *
- *  Copyright (c) 2001-2016                                                *
+ *  Copyright (c) 2001-2017                                                *
  *  Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James  *
  *                                                                         *
  *  Ce programme est un logiciel libre distribue sous licence GNU/GPL.     *
  *  Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne.   *
 \***************************************************************************/
 
-if (!defined('_ECRIRE_INC_VERSION')) return;
+if (!defined('_ECRIRE_INC_VERSION')) {
+       return;
+}
 
-function inc_log_dist($message, $logname=NULL, $logdir=NULL, $logsuf=NULL) {
+function inc_log_dist($message, $logname = null, $logdir = null, $logsuf = null) {
        static $test_repertoire = array();
        static $compteur = array();
-       static $debugverb = ""; // pour ne pas le recalculer au reappel
-       global $nombre_de_logs, $taille_des_logs;
+       static $debugverb = ''; // pour ne pas le recalculer au reappel
 
-       if (is_null($logname) OR !is_string($logname))
+       if (is_null($logname) or !is_string($logname)) {
                $logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip';
-       if (!isset($compteur[$logname])) $compteur[$logname] = 0;
+       }
+       if (!isset($compteur[$logname])) {
+               $compteur[$logname] = 0;
+       }
        if ($logname != 'maj'
-       AND defined('_MAX_LOG')
-       AND (
-               $compteur[$logname]++ > _MAX_LOG
-               OR !$nombre_de_logs
-               OR !$taille_des_logs
-       ))
+               and defined('_MAX_LOG')
+               and (
+                       $compteur[$logname]++ > _MAX_LOG
+                       or !$GLOBALS['nombre_de_logs']
+                       or !$GLOBALS['taille_des_logs']
+               )
+       ) {
                return;
+       }
 
-       $logfile = ($logdir===NULL ? _DIR_LOG : $logdir)
-         . ($logname)
-         . ($logsuf===NULL ? _FILE_LOG_SUFFIX : $logsuf);
+       $logfile = ($logdir === null ? _DIR_LOG : $logdir)
+               . ($logname)
+               . ($logsuf === null ? _FILE_LOG_SUFFIX : $logsuf);
 
        if (!isset($test_repertoire[$d = dirname($logfile)])) {
                $test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire
-               $test_repertoire[$d] = (@is_dir($d)?true:(function_exists('sous_repertoire')?sous_repertoire($d, '', false, true):false));
+               $test_repertoire[$d] = (@is_dir($d) ? true : (function_exists('sous_repertoire') ? sous_repertoire(
+                       $d,
+                       '',
+                       false,
+                       true
+               ) : false));
        }
 
        // si spip_log() dans mes_options, ou repertoire log/ non present, poser dans tmp/
-       if (!defined('_DIR_LOG') OR !$test_repertoire[$d])
-               $logfile = _DIR_RACINE._NOM_TEMPORAIRES_INACCESSIBLES.$logname.'.log';
+       if (!defined('_DIR_LOG') or !$test_repertoire[$d]) {
+               $logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log';
+       }
 
        $rotate = 0;
-       $pid = '(pid '.@getmypid().')';
+       $pid = '(pid ' . @getmypid() . ')';
 
        // accepter spip_log( Array )
-       if (!is_string($message)) $message = var_export($message, true);
+       if (!is_string($message)) {
+               $message = var_export($message, true);
+       }
 
-       if (!$debugverb AND defined('_LOG_FILELINE') AND _LOG_FILELINE){
+       if (!$debugverb and defined('_LOG_FILELINE') and _LOG_FILELINE) {
                $debug = debug_backtrace();
                $l = $debug[1]['line'];
                $fi = $debug[1]['file'];
-               if (strncmp($fi,_ROOT_RACINE,strlen(_ROOT_RACINE))==0)
-                       $fi = substr($fi,strlen(_ROOT_RACINE));
+               if (strncmp($fi, _ROOT_RACINE, strlen(_ROOT_RACINE)) == 0) {
+                       $fi = substr($fi, strlen(_ROOT_RACINE));
+               }
                $fu = isset($debug[2]['function']) ? $debug[2]['function'] : '';
-               $debugverb = "$fi:L$l:$fu"."():";
+               $debugverb = "$fi:L$l:$fu" . '():';
        }
 
-       $m = date("Y-m-d H:i:s").' '.$GLOBALS['ip'].' '.$pid.' '
-         //distinguer les logs prives et publics dans les grep
+       $m = date('Y-m-d H:i:s') . ' ' . (isset($GLOBALS['ip']) ? $GLOBALS['ip'] : '') . ' ' . $pid . ' '
+               //distinguer les logs prives et publics dans les grep
                . $debugverb
-               . (test_espace_prive()?':Pri:':':Pub:')
-               .preg_replace("/\n*$/", "\n", $message);
+               . (test_espace_prive() ? ':Pri:' : ':Pub:')
+               . preg_replace("/\n*$/", "\n", $message);
 
 
        if (@is_readable($logfile)
-       AND (!$s = @filesize($logfile) OR $s > $taille_des_logs * 1024)) {
-               $rotate = $nombre_de_logs;
+               and (!$s = @filesize($logfile) or $s > $GLOBALS['taille_des_logs'] * 1024)
+       ) {
+               $rotate = $GLOBALS['nombre_de_logs'];
                $m .= "[-- rotate --]\n";
        }
 
-       $f = @fopen($logfile, "ab");
+       $f = @fopen($logfile, 'ab');
        if ($f) {
-               fputs($f, (defined('_LOG_BRUT') AND _LOG_BRUT) ? $m : str_replace('<','&lt;',$m));
+               fputs($f, (defined('_LOG_BRUT') and _LOG_BRUT) ? $m : str_replace('<', '&lt;', $m));
                fclose($f);
        }
 
        if ($rotate-- > 0
-       AND function_exists('spip_unlink')) {
+               and function_exists('spip_unlink')
+       ) {
                spip_unlink($logfile . '.' . $rotate);
                while ($rotate--) {
                        @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1));
@@ -88,9 +105,9 @@ function inc_log_dist($message, $logname=NULL, $logdir=NULL, $logsuf=NULL) {
 
        // Dupliquer les erreurs specifiques dans le log general
        if ($logname !== _FILE_LOG
-         AND defined('_FILE_LOG'))
-               inc_log_dist($logname=='maj' ? 'cf maj.log' : $message);
-       $debugverb = "";
+               and defined('_FILE_LOG')
+       ) {
+               inc_log_dist($logname == 'maj' ? 'cf maj.log' : $message);
+       }
+       $debugverb = '';
 }
-
-?>