isLoggedIn() ) { $message = "[" . $member->getDisplayName() . "] " . $message; } $query = "INSERT INTO %s (timestamp, message) VALUES (%s, %s)"; $query = sprintf($query, sql_table('actionlog'), DB::formatDateTime(), DB::quoteValue($message)); DB::execute($query); self::trimLog(); return; } /** * (Static) Method to clear the whole action log */ function clear() { global $manager; $query = sprintf('DELETE FROM %s', sql_table('actionlog')); $manager->notify('ActionLogCleared',array()); return DB::execute($query) !== FALSE; } /** * (Static) Method to trim the action log (from over 500 back to 250 entries) */ function trimLog() { static $checked = 0; // only check once per run if ($checked) return; // trim $checked = 1; $query = sprintf('SELECT COUNT(*) AS result FROM %s', sql_table('actionlog')); $iTotal = DB::getValue($query); // if size > 500, drop back to about 250 $iMaxSize = 500; $iDropSize = 250; if ($iTotal > $iMaxSize) { $query = sprintf('SELECT timestamp as result FROM %s ORDER BY timestamp DESC LIMIT %d,1', sql_table('actionlog'), intval($iDropSize)); $tsChop = DB::getValue($query); $query = sprintf("DELETE FROM %s WHERE timestamp < '%s'", sql_table('actionlog'), $tsChop); DB::execute($query); } } } ?>