LogDAO.php 871 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. class FreshRSS_LogDAO {
  3. public static function lines() {
  4. $logs = array();
  5. $handle = @fopen(join_path(DATA_PATH, 'users', Minz_Session::param('currentUser', '_'), 'log.txt'), 'r');
  6. if ($handle) {
  7. while (($line = fgets($handle)) !== false) {
  8. if (preg_match('/^\[([^\[]+)\] \[([^\[]+)\] --- (.*)$/', $line, $matches)) {
  9. $myLog = new FreshRSS_Log ();
  10. $myLog->_date($matches[1]);
  11. $myLog->_level($matches[2]);
  12. $myLog->_info($matches[3]);
  13. $logs[] = $myLog;
  14. }
  15. }
  16. fclose($handle);
  17. }
  18. return array_reverse($logs);
  19. }
  20. public static function truncate() {
  21. file_put_contents(join_path(DATA_PATH, 'users', Minz_Session::param('currentUser', '_'), 'log.txt'), '');
  22. if (FreshRSS_Auth::hasAccess('admin')) {
  23. file_put_contents(ADMIN_LOG, '');
  24. file_put_contents(API_LOG, '');
  25. file_put_contents(PSHB_LOG, '');
  26. }
  27. }
  28. }