PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/webroot/updates/concrete5.6.0.2/concrete/core/libraries/log.php

https://bitbucket.org/microwebedu/registratie_carem
PHP | 161 lines | 103 code | 24 blank | 34 comment | 16 complexity | dbb71b42420ab23a2c99c5b8dd727c74 MD5 | raw file
Possible License(s): MIT, LGPL-2.1, BSD-3-Clause
  1. <?php
  2. defined('C5_EXECUTE') or die("Access Denied.");
  3. /**
  4. * A library for dealing with searchable logs.
  5. * @package Utilities
  6. * @author Andrew Embler <andrew@concrete5.org>
  7. * @category Concrete
  8. * @copyright Copyright (c) 2003-2008 Concrete5. (http://www.concrete5.org)
  9. * @license http://www.concrete5.org/license/ MIT License
  10. *
  11. */
  12. class Concrete5_Library_Log {
  13. private $log;
  14. private $logfile;
  15. private $name;
  16. private $session = false;
  17. private $sessionText = null;
  18. private $isInternal = false;
  19. public function __construct($log = null, $session = true, $internal = false) {
  20. $th = Loader::helper('text');
  21. if ($log == null) {
  22. $log = '';
  23. }
  24. $this->log = $log;
  25. $this->name = $th->unhandle($log);
  26. $this->session = $session;
  27. $this->isInternal = $internal;
  28. }
  29. public function write($message) {
  30. $this->sessionText .= $message . "\n";
  31. if (!$this->session) {
  32. $this->close();
  33. }
  34. return $this;
  35. }
  36. public static function addEntry($message, $namespace = false) {
  37. if (!$namespace) {
  38. $namespace = t('debug');
  39. }
  40. $l = new Log($namespace, false);
  41. $l->write($message);
  42. }
  43. /**
  44. * Removes all "custom" log entries - these are entries that an app owner has written and don't have a builtin C5 type
  45. */
  46. public function clearCustom() {
  47. $db = Loader::db();
  48. $db->Execute("delete from Logs where logIsInternal = 0");
  49. }
  50. /**
  51. * Removes log entries by type- these are entries that an app owner has written and don't have a builtin C5 type
  52. * @param string $type Is a lowercase string that uses underscores instead of spaces, e.g. sent_emails
  53. */
  54. public function clearByType($type) {
  55. $db = Loader::db();
  56. $db->Execute("delete from Logs where logType = ?", array($type));
  57. }
  58. public function clearInternal() {
  59. $db = Loader::db();
  60. $db->Execute("delete from Logs where logIsInternal = 1");
  61. }
  62. /**
  63. * Removes all log entries
  64. */
  65. public function clearAll() {
  66. $db = Loader::db();
  67. $db->Execute("delete from Logs");
  68. }
  69. public function close() {
  70. $u = new User();
  71. $v = array($this->log, htmlentities($this->sessionText, ENT_COMPAT, APP_CHARSET), $this->isInternal, $u->getUserID());
  72. $db = Loader::db();
  73. $db->Execute("insert into Logs (logType, logText, logIsInternal, logUserID) values (?, ?, ?, ?)", $v);
  74. $this->sessionText = '';
  75. }
  76. /**
  77. * Renames a log file and moves it to the log archive.
  78. */
  79. public function archive() {
  80. }
  81. /**
  82. * Returns the total number of entries matching this type
  83. */
  84. public static function getTotal($keywords, $type) {
  85. $db = Loader::db();
  86. if ($keywords != '') {
  87. $kw = 'and logText like ' . $db->quote('%' . $keywords . '%');
  88. }
  89. if ($type != false) {
  90. $v = array($type);
  91. $r = $db->GetOne('select count(logID) from Logs where logType = ? ' . $kw, $v);
  92. } else {
  93. $r = $db->GetOne('select count(logID) from Logs where 1=1 ' . $kw);
  94. }
  95. return $r;
  96. }
  97. /**
  98. * Returns a list of log entries
  99. */
  100. public static function getList($keywords, $type, $limit) {
  101. $db = Loader::db();
  102. if ($keywords != '') {
  103. $kw = 'and logText like ' . $db->quote('%' . $keywords . '%');
  104. }
  105. if ($type != false) {
  106. $v = array($type);
  107. $r = $db->Execute('select logID from Logs where logType = ? ' . $kw . ' order by timestamp desc, logID desc limit ' . $limit, $v);
  108. } else {
  109. $r = $db->Execute('select logID from Logs where 1=1 ' . $kw . ' order by timestamp desc, logID desc limit ' . $limit);
  110. }
  111. $entries = array();
  112. while ($row = $r->FetchRow()) {
  113. $entries[] = LogEntry::getByID($row['logID']);
  114. }
  115. return $entries;
  116. }
  117. /**
  118. * Returns an array of distinct log types
  119. */
  120. public static function getTypeList() {
  121. $db = Loader::db();
  122. $lt = $db->GetCol("select distinct logType from Logs");
  123. if (!is_array($lt)) {
  124. $lt = array();
  125. }
  126. return $lt;
  127. }
  128. public function getName() { return $this->name;}
  129. /**
  130. * Returns all the log files in the directory
  131. */
  132. public static function getLogs() {
  133. $db = Loader::db();
  134. $r = $db->GetCol('select distinct logType from Logs order by logType asc');
  135. return $r;
  136. }
  137. }