Automatically exported from code.google.com/p/planningalerts
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

171 satır
4.8 KiB

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