[ Index ]

PHP Cross Reference of Nucleus CMS 3.64

title

Body

[close]

/nucleus3.64/nucleus/libs/ -> ACTIONLOG.php (source)

   1  <?php
   2  /*
   3   * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
   4   * Copyright (C) 2002-2009 The Nucleus Group
   5   *
   6   * This program is free software; you can redistribute it and/or
   7   * modify it under the terms of the GNU General Public License
   8   * as published by the Free Software Foundation; either version 2
   9   * of the License, or (at your option) any later version.
  10   * (see nucleus/documentation/index.html#license for more info)
  11   */
  12  /**
  13   * Actionlog class for Nucleus
  14   *
  15   * @license http://nucleuscms.org/license.txt GNU General Public License
  16   * @copyright Copyright (C) 2002-2009 The Nucleus Group
  17   * @version $Id: ACTIONLOG.php 1470 2010-11-29 22:10:16Z ftruscot $
  18   */
  19  define('ERROR',1);        // only errors
  20  define('WARNING',2);    // errors and warnings
  21  define('INFO',3);        // info, errors and warnings
  22  define('DEBUG',4);        // everything
  23  $CONF['LogLevel'] = INFO;
  24  
  25  class ACTIONLOG {
  26  
  27      /**
  28        * (Static) Method to add a message to the action log
  29        */
  30  	function add($level, $message) {
  31          global $member, $CONF;
  32  
  33          if ($CONF['LogLevel'] < $level)
  34              return;
  35  
  36          if ($member && $member->isLoggedIn())
  37              $message = "[" . $member->getDisplayName() . "] " . $message;
  38  
  39          $message = sql_real_escape_string($message);        // add slashes
  40          $timestamp = date("Y-m-d H:i:s",time());    // format timestamp
  41          $query = "INSERT INTO " . sql_table('actionlog') . " (timestamp, message) VALUES ('$timestamp', '$message')";
  42  
  43          sql_query($query);
  44  
  45          ACTIONLOG::trimLog();
  46      }
  47  
  48      /**
  49        * (Static) Method to clear the whole action log
  50        */
  51  	function clear() {
  52          global $manager;
  53  
  54          $query = 'DELETE FROM ' . sql_table('actionlog');
  55  
  56          $manager->notify('ActionLogCleared',array());
  57  
  58          return sql_query($query);
  59      }
  60  
  61      /**
  62        * (Static) Method to trim the action log (from over 500 back to 250 entries)
  63        */
  64  	function trimLog() {
  65          static $checked = 0;
  66  
  67          // only check once per run
  68          if ($checked) return;
  69  
  70          // trim
  71          $checked = 1;
  72  
  73          $iTotal = quickQuery('SELECT COUNT(*) AS result FROM ' . sql_table('actionlog'));
  74  
  75          // if size > 500, drop back to about 250
  76          $iMaxSize = 500;
  77          $iDropSize = 250;
  78          if ($iTotal > $iMaxSize) {
  79              $tsChop = quickQuery('SELECT timestamp as result FROM ' . sql_table('actionlog') . ' ORDER BY timestamp DESC LIMIT '.$iDropSize.',1');
  80              sql_query('DELETE FROM ' . sql_table('actionlog') . ' WHERE timestamp < \'' . $tsChop . '\'');
  81          }
  82  
  83      }
  84  
  85  }
  86  
  87  ?>


Generated: Mon May 2 16:14:08 2011 Cross-referenced by PHPXref 0.7.1