PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_virtuemart/classes/Log/mcal.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 187 lines | 67 code | 22 blank | 98 comment | 8 complexity | cb229cc21433a07ffe77aea9c72e6204 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
  3. /**
  4. *
  5. * @version $Id: mcal.php 1336 2008-03-31 17:06:23Z soeren_nb $
  6. * @package VirtueMart
  7. * @subpackage Log
  8. * @copyright Copyright (C) 2004-2008 soeren - All rights reserved.
  9. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  10. * VirtueMart is free software. This version may have been modified pursuant
  11. * to the GNU General Public License, and as distributed it includes or
  12. * is derivative of works licensed under the GNU General Public License or
  13. * other free or open source software licenses.
  14. * See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
  15. *
  16. * http://virtuemart.net
  17. */
  18. /**
  19. * $Header$
  20. * $Horde: horde/lib/Log/mcal.php,v 1.2 2000/06/28 21:36:13 jon Exp $
  21. *
  22. * @version $ Revision: 1.18 $
  23. * @package Log
  24. */
  25. /**
  26. * The vmLog_mcal class is a concrete implementation of the Log::
  27. * abstract class which sends messages to a local or remote calendar
  28. * store accessed through MCAL.
  29. *
  30. * @author Chuck Hagenbuch <chuck@horde.org>
  31. * @since Horde 1.3
  32. * @since Log 1.0
  33. * @package Log
  34. */
  35. class vmLog_mcal extends vmLog
  36. {
  37. /**
  38. * holding the calendar specification to connect to.
  39. * @var string
  40. * @access private
  41. */
  42. var $_calendar = '{localhost/mstore}';
  43. /**
  44. * holding the username to use.
  45. * @var string
  46. * @access private
  47. */
  48. var $_username = '';
  49. /**
  50. * holding the password to use.
  51. * @var string
  52. * @access private
  53. */
  54. var $_password = '';
  55. /**
  56. * holding the options to pass to the calendar stream.
  57. * @var integer
  58. * @access private
  59. */
  60. var $_options = 0;
  61. /**
  62. * ResourceID of the MCAL stream.
  63. * @var string
  64. * @access private
  65. */
  66. var $_stream = '';
  67. /**
  68. * Integer holding the log facility to use.
  69. * @var string
  70. * @access private
  71. */
  72. var $_name = LOG_SYSLOG;
  73. /**
  74. * Constructs a new vmLog_mcal object.
  75. *
  76. * @param string $name The category to use for our events.
  77. * @param string $ident The identity string.
  78. * @param array $conf The configuration array.
  79. * @param int $level Log messages up to and including this level.
  80. * @access public
  81. */
  82. function vmLog_mcal($name, $ident = '', $conf = array(),
  83. $level = PEAR_LOG_DEBUG)
  84. {
  85. $this->_id = md5(microtime());
  86. $this->_name = $name;
  87. $this->_ident = $ident;
  88. $this->_mask = vmLog::UPTO($level);
  89. $this->_calendar = $conf['calendar'];
  90. $this->_username = $conf['username'];
  91. $this->_password = $conf['password'];
  92. $this->_options = $conf['options'];
  93. }
  94. /**
  95. * Opens a calendar stream, if it has not already been
  96. * opened. This is implicitly called by log(), if necessary.
  97. * @access public
  98. */
  99. function open()
  100. {
  101. if (!$this->_opened) {
  102. $this->_stream = mcal_open($this->_calendar, $this->_username,
  103. $this->_password, $this->_options);
  104. $this->_opened = true;
  105. }
  106. return $this->_opened;
  107. }
  108. /**
  109. * Closes the calendar stream, if it is open.
  110. * @access public
  111. */
  112. function close()
  113. {
  114. if ($this->_opened) {
  115. mcal_close($this->_stream);
  116. $this->_opened = false;
  117. }
  118. return ($this->_opened === false);
  119. }
  120. /**
  121. * Logs $message and associated information to the currently open
  122. * calendar stream. Calls open() if necessary. Also passes the
  123. * message along to any Log_observer instances that are observing
  124. * this Log.
  125. *
  126. * @param mixed $message String or object containing the message to log.
  127. * @param string $priority The priority of the message. Valid
  128. * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT,
  129. * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING,
  130. * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG.
  131. * @return boolean True on success or false on failure.
  132. * @access public
  133. */
  134. function log($message, $priority = null)
  135. {
  136. /* If a priority hasn't been specified, use the default value. */
  137. if ($priority === null) {
  138. $priority = $this->_priority;
  139. }
  140. /* Abort early if the priority is above the maximum logging level. */
  141. if (!$this->_isMasked($priority)) {
  142. return false;
  143. }
  144. /* If the connection isn't open and can't be opened, return failure. */
  145. if (!$this->_opened && !$this->open()) {
  146. return false;
  147. }
  148. /* Extract the string representation of the message. */
  149. $message = $this->_extractMessage($message);
  150. $date_str = date('Y:n:j:G:i:s');
  151. $dates = explode(':', $date_str);
  152. mcal_event_init($this->_stream);
  153. mcal_event_set_title($this->_stream, $this->_ident);
  154. mcal_event_set_category($this->_stream, $this->_name);
  155. mcal_event_set_description($this->_stream, $message);
  156. mcal_event_add_attribute($this->_stream, 'priority', $priority);
  157. mcal_event_set_start($this->_stream, $dates[0], $dates[1], $dates[2],
  158. $dates[3], $dates[4], $dates[5]);
  159. mcal_event_set_end($this->_stream, $dates[0], $dates[1], $dates[2],
  160. $dates[3], $dates[4], $dates[5]);
  161. mcal_append_event($this->_stream);
  162. $this->_announce(array('priority' => $priority, 'message' => $message));
  163. return true;
  164. }
  165. }