PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/php/Log/mcal.php

https://bitbucket.org/adarshj/convenient_website
PHP | 171 lines | 66 code | 22 blank | 83 comment | 6 complexity | 548c239e498f4b7763390ee281c23ff8 MD5 | raw file
Possible License(s): Apache-2.0, MPL-2.0-no-copyleft-exception, LGPL-2.1, BSD-2-Clause, GPL-2.0, LGPL-3.0
  1. <?php
  2. /**
  3. * $Header: /repository/pear/Log/Log/mcal.php,v 1.17 2004/01/19 08:02:40 jon Exp $
  4. * $Horde: horde/lib/Log/mcal.php,v 1.2 2000/06/28 21:36:13 jon Exp $
  5. *
  6. * @version $Revision: 1.17 $
  7. * @package Log
  8. */
  9. /**
  10. * The Log_mcal class is a concrete implementation of the Log::
  11. * abstract class which sends messages to a local or remote calendar
  12. * store accessed through MCAL.
  13. *
  14. * @author Chuck Hagenbuch <chuck@horde.org>
  15. * @since Horde 1.3
  16. * @since Log 1.0
  17. * @package Log
  18. */
  19. class Log_mcal extends Log {
  20. /**
  21. * holding the calendar specification to connect to.
  22. * @var string
  23. * @access private
  24. */
  25. var $_calendar = '{localhost/mstore}';
  26. /**
  27. * holding the username to use.
  28. * @var string
  29. * @access private
  30. */
  31. var $_username = '';
  32. /**
  33. * holding the password to use.
  34. * @var string
  35. * @access private
  36. */
  37. var $_password = '';
  38. /**
  39. * holding the options to pass to the calendar stream.
  40. * @var integer
  41. * @access private
  42. */
  43. var $_options = 0;
  44. /**
  45. * ResourceID of the MCAL stream.
  46. * @var string
  47. * @access private
  48. */
  49. var $_stream = '';
  50. /**
  51. * Integer holding the log facility to use.
  52. * @var string
  53. * @access private
  54. */
  55. var $_name = LOG_SYSLOG;
  56. /**
  57. * Constructs a new Log_mcal object.
  58. *
  59. * @param string $name The category to use for our events.
  60. * @param string $ident The identity string.
  61. * @param array $conf The configuration array.
  62. * @param int $level Log messages up to and including this level.
  63. * @access public
  64. */
  65. function Log_mcal($name, $ident = '', $conf = array(),
  66. $level = PEAR_LOG_DEBUG)
  67. {
  68. $this->_id = md5(microtime());
  69. $this->_name = $name;
  70. $this->_ident = $ident;
  71. $this->_mask = Log::UPTO($level);
  72. $this->_calendar = $conf['calendar'];
  73. $this->_username = $conf['username'];
  74. $this->_password = $conf['password'];
  75. $this->_options = $conf['options'];
  76. }
  77. /**
  78. * Opens a calendar stream, if it has not already been
  79. * opened. This is implicitly called by log(), if necessary.
  80. * @access public
  81. */
  82. function open()
  83. {
  84. if (!$this->_opened) {
  85. $this->_stream = mcal_open($this->_calendar, $this->_username,
  86. $this->_password, $this->_options);
  87. $this->_opened = true;
  88. }
  89. return $this->_opened;
  90. }
  91. /**
  92. * Closes the calendar stream, if it is open.
  93. * @access public
  94. */
  95. function close()
  96. {
  97. if ($this->_opened) {
  98. mcal_close($this->_stream);
  99. $this->_opened = false;
  100. }
  101. return ($this->_opened === false);
  102. }
  103. /**
  104. * Logs $message and associated information to the currently open
  105. * calendar stream. Calls open() if necessary. Also passes the
  106. * message along to any Log_observer instances that are observing
  107. * this Log.
  108. *
  109. * @param mixed $message String or object containing the message to log.
  110. * @param string $priority The priority of the message. Valid
  111. * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT,
  112. * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING,
  113. * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG.
  114. * @return boolean True on success or false on failure.
  115. * @access public
  116. */
  117. function log($message, $priority = null)
  118. {
  119. /* If a priority hasn't been specified, use the default value. */
  120. if ($priority === null) {
  121. $priority = $this->_priority;
  122. }
  123. /* Abort early if the priority is above the maximum logging level. */
  124. if (!$this->_isMasked($priority)) {
  125. return false;
  126. }
  127. /* If the connection isn't open and can't be opened, return failure. */
  128. if (!$this->_opened && !$this->open()) {
  129. return false;
  130. }
  131. /* Extract the string representation of the message. */
  132. $message = $this->_extractMessage($message);
  133. $date_str = date('Y:n:j:G:i:s');
  134. $dates = explode(':', $date_str);
  135. mcal_event_init($this->_stream);
  136. mcal_event_set_title($this->_stream, $this->_ident);
  137. mcal_event_set_category($this->_stream, $this->_name);
  138. mcal_event_set_description($this->_stream, $message);
  139. mcal_event_add_attribute($this->_stream, 'priority', $priority);
  140. mcal_event_set_start($this->_stream, $dates[0], $dates[1], $dates[2],
  141. $dates[3], $dates[4], $dates[5]);
  142. mcal_event_set_end($this->_stream, $dates[0], $dates[1], $dates[2],
  143. $dates[3], $dates[4], $dates[5]);
  144. mcal_append_event($this->_stream);
  145. $this->_announce(array('priority' => $priority, 'message' => $message));
  146. return true;
  147. }
  148. }
  149. ?>