diff --git a/includes/Log-1.12.7/Log.php b/includes/Log-1.12.7/Log.php new file mode 100644 index 000000000..40ad9d839 --- /dev/null +++ b/includes/Log-1.12.7/Log.php @@ -0,0 +1,868 @@ + + * @author Jon Parise + * @since Horde 1.3 + * @package Log + */ +class Log +{ + /** + * Indicates whether or not the log can been opened / connected. + * + * @var boolean + * @access protected + */ + var $_opened = false; + + /** + * Instance-specific unique identification number. + * + * @var integer + * @access protected + */ + var $_id = 0; + + /** + * The label that uniquely identifies this set of log messages. + * + * @var string + * @access protected + */ + var $_ident = ''; + + /** + * The default priority to use when logging an event. + * + * @var integer + * @access protected + */ + var $_priority = PEAR_LOG_INFO; + + /** + * The bitmask of allowed log levels. + * + * @var integer + * @access protected + */ + var $_mask = PEAR_LOG_ALL; + + /** + * Holds all Log_observer objects that wish to be notified of new messages. + * + * @var array + * @access protected + */ + var $_listeners = array(); + + /** + * Starting depth to use when walking a backtrace in search of the + * function that invoked the log system. + * + * @var integer + * @access protected + */ + var $_backtrace_depth = 0; + + /** + * Maps canonical format keys to position arguments for use in building + * "line format" strings. + * + * @var array + * @access protected + */ + var $_formatMap = array('%{timestamp}' => '%1$s', + '%{ident}' => '%2$s', + '%{priority}' => '%3$s', + '%{message}' => '%4$s', + '%{file}' => '%5$s', + '%{line}' => '%6$s', + '%{function}' => '%7$s', + '%{class}' => '%8$s', + '%\{' => '%%{'); + + /** + * Attempts to return a concrete Log instance of type $handler. + * + * @param string $handler The type of concrete Log subclass to return. + * Attempt to dynamically include the code for + * this subclass. Currently, valid values are + * 'console', 'syslog', 'sql', 'file', and 'mcal'. + * + * @param string $name The name of the actually log file, table, or + * other specific store to use. Defaults to an + * empty string, with which the subclass will + * attempt to do something intelligent. + * + * @param string $ident The identity reported to the log system. + * + * @param array $conf A hash containing any additional configuration + * information that a subclass might need. + * + * @param int $level Log messages up to and including this level. + * + * @return object Log The newly created concrete Log instance, or + * null on an error. + * @access public + * @since Log 1.0 + */ + public static function factory($handler, $name = '', $ident = '', + $conf = array(), $level = PEAR_LOG_DEBUG) + { + $handler = strtolower($handler); + $class = 'Log_' . $handler; + $classfile = 'Log/' . $handler . '.php'; + + /* + * Attempt to include our version of the named class, but don't treat + * a failure as fatal. The caller may have already included their own + * version of the named class. + */ + if (!class_exists($class, false)) { + include_once $classfile; + } + + /* If the class exists, return a new instance of it. */ + if (class_exists($class, false)) { + $obj = new $class($name, $ident, $conf, $level); + return $obj; + } + + $null = null; + return $null; + } + + /** + * Attempts to return a reference to a concrete Log instance of type + * $handler, only creating a new instance if no log instance with the same + * parameters currently exists. + * + * You should use this if there are multiple places you might create a + * logger, you don't want to create multiple loggers, and you don't want to + * check for the existance of one each time. The singleton pattern does all + * the checking work for you. + * + * You MUST call this method with the $var = &Log::singleton() syntax. + * Without the ampersand (&) in front of the method name, you will not get + * a reference, you will get a copy. + * + * @param string $handler The type of concrete Log subclass to return. + * Attempt to dynamically include the code for + * this subclass. Currently, valid values are + * 'console', 'syslog', 'sql', 'file', and 'mcal'. + * + * @param string $name The name of the actually log file, table, or + * other specific store to use. Defaults to an + * empty string, with which the subclass will + * attempt to do something intelligent. + * + * @param string $ident The identity reported to the log system. + * + * @param array $conf A hash containing any additional configuration + * information that a subclass might need. + * + * @param int $level Log messages up to and including this level. + * + * @return object Log The newly created concrete Log instance, or + * null on an error. + * @access public + * @since Log 1.0 + */ + public static function singleton($handler, $name = '', $ident = '', + $conf = array(), $level = PEAR_LOG_DEBUG) + { + static $instances; + if (!isset($instances)) $instances = array(); + + $signature = serialize(array($handler, $name, $ident, $conf, $level)); + if (!isset($instances[$signature])) { + $instances[$signature] = Log::factory($handler, $name, $ident, + $conf, $level); + } + + return $instances[$signature]; + } + + /** + * Abstract implementation of the open() method. + * @since Log 1.0 + */ + function open() + { + return false; + } + + /** + * Abstract implementation of the close() method. + * @since Log 1.0 + */ + function close() + { + return false; + } + + /** + * Abstract implementation of the flush() method. + * @since Log 1.8.2 + */ + function flush() + { + return false; + } + + /** + * Abstract implementation of the log() method. + * @since Log 1.0 + */ + function log($message, $priority = null) + { + return false; + } + + /** + * A convenience function for logging a emergency event. It will log a + * message at the PEAR_LOG_EMERG log level. + * + * @param mixed $message String or object containing the message + * to log. + * + * @return boolean True if the message was successfully logged. + * + * @access public + * @since Log 1.7.0 + */ + function emerg($message) + { + return $this->log($message, PEAR_LOG_EMERG); + } + + /** + * A convenience function for logging an alert event. It will log a + * message at the PEAR_LOG_ALERT log level. + * + * @param mixed $message String or object containing the message + * to log. + * + * @return boolean True if the message was successfully logged. + * + * @access public + * @since Log 1.7.0 + */ + function alert($message) + { + return $this->log($message, PEAR_LOG_ALERT); + } + + /** + * A convenience function for logging a critical event. It will log a + * message at the PEAR_LOG_CRIT log level. + * + * @param mixed $message String or object containing the message + * to log. + * + * @return boolean True if the message was successfully logged. + * + * @access public + * @since Log 1.7.0 + */ + function crit($message) + { + return $this->log($message, PEAR_LOG_CRIT); + } + + /** + * A convenience function for logging a error event. It will log a + * message at the PEAR_LOG_ERR log level. + * + * @param mixed $message String or object containing the message + * to log. + * + * @return boolean True if the message was successfully logged. + * + * @access public + * @since Log 1.7.0 + */ + function err($message) + { + return $this->log($message, PEAR_LOG_ERR); + } + + /** + * A convenience function for logging a warning event. It will log a + * message at the PEAR_LOG_WARNING log level. + * + * @param mixed $message String or object containing the message + * to log. + * + * @return boolean True if the message was successfully logged. + * + * @access public + * @since Log 1.7.0 + */ + function warning($message) + { + return $this->log($message, PEAR_LOG_WARNING); + } + + /** + * A convenience function for logging a notice event. It will log a + * message at the PEAR_LOG_NOTICE log level. + * + * @param mixed $message String or object containing the message + * to log. + * + * @return boolean True if the message was successfully logged. + * + * @access public + * @since Log 1.7.0 + */ + function notice($message) + { + return $this->log($message, PEAR_LOG_NOTICE); + } + + /** + * A convenience function for logging a information event. It will log a + * message at the PEAR_LOG_INFO log level. + * + * @param mixed $message String or object containing the message + * to log. + * + * @return boolean True if the message was successfully logged. + * + * @access public + * @since Log 1.7.0 + */ + function info($message) + { + return $this->log($message, PEAR_LOG_INFO); + } + + /** + * A convenience function for logging a debug event. It will log a + * message at the PEAR_LOG_DEBUG log level. + * + * @param mixed $message String or object containing the message + * to log. + * + * @return boolean True if the message was successfully logged. + * + * @access public + * @since Log 1.7.0 + */ + function debug($message) + { + return $this->log($message, PEAR_LOG_DEBUG); + } + + /** + * Returns the string representation of the message data. + * + * If $message is an object, _extractMessage() will attempt to extract + * the message text using a known method (such as a PEAR_Error object's + * getMessage() method). If a known method, cannot be found, the + * serialized representation of the object will be returned. + * + * If the message data is already a string, it will be returned unchanged. + * + * @param mixed $message The original message data. This may be a + * string or any object. + * + * @return string The string representation of the message. + * + * @access protected + */ + function _extractMessage($message) + { + /* + * If we've been given an object, attempt to extract the message using + * a known method. If we can't find such a method, default to the + * "human-readable" version of the object. + * + * We also use the human-readable format for arrays. + */ + if (is_object($message)) { + if (method_exists($message, 'getmessage')) { + $message = $message->getMessage(); + } else if (method_exists($message, 'tostring')) { + $message = $message->toString(); + } else if (method_exists($message, '__tostring')) { + $message = (string)$message; + } else { + $message = var_export($message, true); + } + } else if (is_array($message)) { + if (isset($message['message'])) { + if (is_scalar($message['message'])) { + $message = $message['message']; + } else { + $message = var_export($message['message'], true); + } + } else { + $message = var_export($message, true); + } + } else if (is_bool($message) || $message === NULL) { + $message = var_export($message, true); + } + + /* Otherwise, we assume the message is a string. */ + return $message; + } + + /** + * Using debug_backtrace(), returns the file, line, and enclosing function + * name of the source code context from which log() was invoked. + * + * @param int $depth The initial number of frames we should step + * back into the trace. + * + * @return array Array containing four strings: the filename, the line, + * the function name, and the class name from which log() + * was called. + * + * @access private + * @since Log 1.9.4 + */ + function _getBacktraceVars($depth) + { + /* Start by generating a backtrace from the current call (here). */ + $bt = debug_backtrace(); + + /* Store some handy shortcuts to our previous frames. */ + $bt0 = isset($bt[$depth]) ? $bt[$depth] : null; + $bt1 = isset($bt[$depth + 1]) ? $bt[$depth + 1] : null; + + /* + * If we were ultimately invoked by the composite handler, we need to + * increase our depth one additional level to compensate. + */ + $class = isset($bt1['class']) ? $bt1['class'] : null; + if ($class !== null && strcasecmp($class, 'Log_composite') == 0) { + $depth++; + $bt0 = isset($bt[$depth]) ? $bt[$depth] : null; + $bt1 = isset($bt[$depth + 1]) ? $bt[$depth + 1] : null; + $class = isset($bt1['class']) ? $bt1['class'] : null; + } + + /* + * We're interested in the frame which invoked the log() function, so + * we need to walk back some number of frames into the backtrace. The + * $depth parameter tells us where to start looking. We go one step + * further back to find the name of the encapsulating function from + * which log() was called. + */ + $file = isset($bt0) ? $bt0['file'] : null; + $line = isset($bt0) ? $bt0['line'] : 0; + $func = isset($bt1) ? $bt1['function'] : null; + + /* + * However, if log() was called from one of our "shortcut" functions, + * we're going to need to go back an additional step. + */ + if (in_array($func, array('emerg', 'alert', 'crit', 'err', 'warning', + 'notice', 'info', 'debug'))) { + $bt2 = isset($bt[$depth + 2]) ? $bt[$depth + 2] : null; + + $file = is_array($bt1) ? $bt1['file'] : null; + $line = is_array($bt1) ? $bt1['line'] : 0; + $func = is_array($bt2) ? $bt2['function'] : null; + $class = isset($bt2['class']) ? $bt2['class'] : null; + } + + /* + * If we couldn't extract a function name (perhaps because we were + * executed from the "main" context), provide a default value. + */ + if ($func === null) { + $func = '(none)'; + } + + /* Return a 4-tuple containing (file, line, function, class). */ + return array($file, $line, $func, $class); + } + + /** + * Sets the starting depth to use when walking a backtrace in search of + * the function that invoked the log system. This is used on conjunction + * with the 'file', 'line', 'function', and 'class' formatters. + * + * @param int $depth The new backtrace depth. + * + * @access public + * @since Log 1.12.7 + */ + public function setBacktraceDepth($depth) + { + $this->_backtrace_depth = $depth; + } + + /** + * Produces a formatted log line based on a format string and a set of + * variables representing the current log record and state. + * + * @return string Formatted log string. + * + * @access protected + * @since Log 1.9.4 + */ + function _format($format, $timestamp, $priority, $message) + { + /* + * If the format string references any of the backtrace-driven + * variables (%5 %6,%7,%8), generate the backtrace and fetch them. + */ + if (preg_match('/%[5678]/', $format)) { + /* Plus 2 to account for our internal function calls. */ + $d = $this->_backtrace_depth + 2; + list($file, $line, $func, $class) = $this->_getBacktraceVars($d); + } + + /* + * Build the formatted string. We use the sprintf() function's + * "argument swapping" capability to dynamically select and position + * the variables which will ultimately appear in the log string. + */ + return sprintf($format, + $timestamp, + $this->_ident, + $this->priorityToString($priority), + $message, + isset($file) ? $file : '', + isset($line) ? $line : '', + isset($func) ? $func : '', + isset($class) ? $class : ''); + } + + /** + * Returns the string representation of a PEAR_LOG_* integer constant. + * + * @param int $priority A PEAR_LOG_* integer constant. + * + * @return string The string representation of $level. + * + * @access public + * @since Log 1.0 + */ + function priorityToString($priority) + { + $levels = array( + PEAR_LOG_EMERG => 'emergency', + PEAR_LOG_ALERT => 'alert', + PEAR_LOG_CRIT => 'critical', + PEAR_LOG_ERR => 'error', + PEAR_LOG_WARNING => 'warning', + PEAR_LOG_NOTICE => 'notice', + PEAR_LOG_INFO => 'info', + PEAR_LOG_DEBUG => 'debug' + ); + + return $levels[$priority]; + } + + /** + * Returns the the PEAR_LOG_* integer constant for the given string + * representation of a priority name. This function performs a + * case-insensitive search. + * + * @param string $name String containing a priority name. + * + * @return string The PEAR_LOG_* integer contstant corresponding + * the the specified priority name. + * + * @access public + * @since Log 1.9.0 + */ + function stringToPriority($name) + { + $levels = array( + 'emergency' => PEAR_LOG_EMERG, + 'alert' => PEAR_LOG_ALERT, + 'critical' => PEAR_LOG_CRIT, + 'error' => PEAR_LOG_ERR, + 'warning' => PEAR_LOG_WARNING, + 'notice' => PEAR_LOG_NOTICE, + 'info' => PEAR_LOG_INFO, + 'debug' => PEAR_LOG_DEBUG + ); + + return $levels[strtolower($name)]; + } + + /** + * Calculate the log mask for the given priority. + * + * This method may be called statically. + * + * @param integer $priority The priority whose mask will be calculated. + * + * @return integer The calculated log mask. + * + * @access public + * @since Log 1.7.0 + */ + public static function MASK($priority) + { + return (1 << $priority); + } + + /** + * Calculate the log mask for all priorities up to the given priority. + * + * This method may be called statically. + * + * @param integer $priority The maximum priority covered by this mask. + * + * @return integer The resulting log mask. + * + * @access public + * @since Log 1.7.0 + * + * @deprecated deprecated since Log 1.9.4; use Log::MAX() instead + */ + public static function UPTO($priority) + { + return Log::MAX($priority); + } + + /** + * Calculate the log mask for all priorities greater than or equal to the + * given priority. In other words, $priority will be the lowest priority + * matched by the resulting mask. + * + * This method may be called statically. + * + * @param integer $priority The minimum priority covered by this mask. + * + * @return integer The resulting log mask. + * + * @access public + * @since Log 1.9.4 + */ + public static function MIN($priority) + { + return PEAR_LOG_ALL ^ ((1 << $priority) - 1); + } + + /** + * Calculate the log mask for all priorities less than or equal to the + * given priority. In other words, $priority will be the highests priority + * matched by the resulting mask. + * + * This method may be called statically. + * + * @param integer $priority The maximum priority covered by this mask. + * + * @return integer The resulting log mask. + * + * @access public + * @since Log 1.9.4 + */ + public static function MAX($priority) + { + return ((1 << ($priority + 1)) - 1); + } + + /** + * Set and return the level mask for the current Log instance. + * + * @param integer $mask A bitwise mask of log levels. + * + * @return integer The current level mask. + * + * @access public + * @since Log 1.7.0 + */ + function setMask($mask) + { + $this->_mask = $mask; + + return $this->_mask; + } + + /** + * Returns the current level mask. + * + * @return interger The current level mask. + * + * @access public + * @since Log 1.7.0 + */ + function getMask() + { + return $this->_mask; + } + + /** + * Check if the given priority is included in the current level mask. + * + * @param integer $priority The priority to check. + * + * @return boolean True if the given priority is included in the current + * log mask. + * + * @access protected + * @since Log 1.7.0 + */ + function _isMasked($priority) + { + return (Log::MASK($priority) & $this->_mask); + } + + /** + * Returns the current default priority. + * + * @return integer The current default priority. + * + * @access public + * @since Log 1.8.4 + */ + function getPriority() + { + return $this->_priority; + } + + /** + * Sets the default priority to the specified value. + * + * @param integer $priority The new default priority. + * + * @access public + * @since Log 1.8.4 + */ + function setPriority($priority) + { + $this->_priority = $priority; + } + + /** + * Adds a Log_observer instance to the list of observers that are listening + * for messages emitted by this Log instance. + * + * @param object $observer The Log_observer instance to attach as a + * listener. + * + * @param boolean True if the observer is successfully attached. + * + * @access public + * @since Log 1.0 + */ + function attach(&$observer) + { + if (!is_a($observer, 'Log_observer')) { + return false; + } + + $this->_listeners[$observer->_id] = &$observer; + + return true; + } + + /** + * Removes a Log_observer instance from the list of observers. + * + * @param object $observer The Log_observer instance to detach from + * the list of listeners. + * + * @param boolean True if the observer is successfully detached. + * + * @access public + * @since Log 1.0 + */ + function detach($observer) + { + if (!is_a($observer, 'Log_observer') || + !isset($this->_listeners[$observer->_id])) { + return false; + } + + unset($this->_listeners[$observer->_id]); + + return true; + } + + /** + * Informs each registered observer instance that a new message has been + * logged. + * + * @param array $event A hash describing the log event. + * + * @access protected + */ + function _announce($event) + { + foreach ($this->_listeners as $id => $listener) { + if ($event['priority'] <= $this->_listeners[$id]->_priority) { + $this->_listeners[$id]->notify($event); + } + } + } + + /** + * Indicates whether this is a composite class. + * + * @return boolean True if this is a composite class. + * + * @access public + * @since Log 1.0 + */ + function isComposite() + { + return false; + } + + /** + * Sets this Log instance's identification string. + * + * @param string $ident The new identification string. + * + * @access public + * @since Log 1.6.3 + */ + function setIdent($ident) + { + $this->_ident = $ident; + } + + /** + * Returns the current identification string. + * + * @return string The current Log instance's identification string. + * + * @access public + * @since Log 1.6.3 + */ + function getIdent() + { + return $this->_ident; + } +} diff --git a/includes/Log-1.12.7/Log/composite.php b/includes/Log-1.12.7/Log/composite.php new file mode 100644 index 000000000..88c401289 --- /dev/null +++ b/includes/Log-1.12.7/Log/composite.php @@ -0,0 +1,274 @@ + + * @author Jon Parise + * + * @since Horde 1.3 + * @since Log 1.0 + * @package Log + * + * @example composite.php Using the composite handler. + */ +class Log_composite extends Log +{ + /** + * Array holding all of the Log instances to which log events should be + * sent. + * + * @var array + * @access private + */ + var $_children = array(); + + + /** + * Constructs a new composite Log object. + * + * @param boolean $name This parameter is ignored. + * @param boolean $ident This parameter is ignored. + * @param boolean $conf This parameter is ignored. + * @param boolean $level This parameter is ignored. + * + * @access public + */ + function Log_composite($name, $ident = '', $conf = array(), + $level = PEAR_LOG_DEBUG) + { + $this->_ident = $ident; + } + + /** + * Opens all of the child instances. + * + * @return True if all of the child instances were successfully opened. + * + * @access public + */ + function open() + { + /* Attempt to open each of our children. */ + $this->_opened = true; + foreach ($this->_children as $child) { + $this->_opened &= $child->open(); + } + + /* If all children were opened, return success. */ + return $this->_opened; + } + + /** + * Closes all open child instances. + * + * @return True if all of the opened child instances were successfully + * closed. + * + * @access public + */ + function close() + { + /* If we haven't been opened, there's nothing more to do. */ + if (!$this->_opened) { + return true; + } + + /* Attempt to close each of our children. */ + $closed = true; + foreach ($this->_children as $child) { + if ($child->_opened) { + $closed &= $child->close(); + } + } + + /* Clear the opened state for consistency. */ + $this->_opened = false; + + /* If all children were closed, return success. */ + return $closed; + } + + /** + * Flushes all child instances. It is assumed that all of the children + * have been successfully opened. + * + * @return True if all of the child instances were successfully flushed. + * + * @access public + * @since Log 1.8.2 + */ + function flush() + { + /* Attempt to flush each of our children. */ + $flushed = true; + foreach ($this->_children as $child) { + $flushed &= $child->flush(); + } + + /* If all children were flushed, return success. */ + return $flushed; + } + + /** + * Sends $message and $priority to each child of this composite. If the + * appropriate children aren't already open, they will be opened here. + * + * @param mixed $message String or object containing the message + * to log. + * @param string $priority (optional) The priority of the message. + * Valid values are: PEAR_LOG_EMERG, + * PEAR_LOG_ALERT, PEAR_LOG_CRIT, + * PEAR_LOG_ERR, PEAR_LOG_WARNING, + * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and + * PEAR_LOG_DEBUG. + * + * @return boolean True if the entry is successfully logged. + * + * @access public + */ + function log($message, $priority = null) + { + /* If a priority hasn't been specified, use the default value. */ + if ($priority === null) { + $priority = $this->_priority; + } + + /* + * Abort early if the priority is above the composite handler's + * maximum logging level. + * + * XXX: Consider whether or not introducing this change would break + * backwards compatibility. Some users may be expecting composite + * handlers to pass on all events to their children regardless of + * their own priority. + */ + #if (!$this->_isMasked($priority)) { + # return false; + #} + + /* + * Iterate over all of our children. If a unopened child will respond + * to this log event, we attempt to open it immediately. The composite + * handler's opened state will be enabled as soon as the first child + * handler is successfully opened. + * + * We track an overall success state that indicates whether or not all + * of the relevant child handlers were opened and successfully logged + * the event. If one handler fails, we still attempt any remaining + * children, but we consider the overall result a failure. + */ + $success = true; + foreach ($this->_children as $child) { + /* If this child won't respond to this event, skip it. */ + if (!$child->_isMasked($priority)) { + continue; + } + + /* If this child has yet to be opened, attempt to do so now. */ + if (!$child->_opened) { + $success &= $child->open(); + + /* + * If we've successfully opened our first handler, the + * composite handler itself is considered to be opened. + */ + if (!$this->_opened && $success) { + $this->_opened = true; + } + } + + /* Finally, attempt to log the message to the child handler. */ + if ($child->_opened) { + $success &= $child->log($message, $priority); + } + } + + /* Notify the observers. */ + $this->_announce(array('priority' => $priority, 'message' => $message)); + + /* Return success if all of the open children logged the event. */ + return $success; + } + + /** + * Returns true if this is a composite. + * + * @return boolean True if this is a composite class. + * + * @access public + */ + function isComposite() + { + return true; + } + + /** + * Sets this identification string for all of this composite's children. + * + * @param string $ident The new identification string. + * + * @access public + * @since Log 1.6.7 + */ + function setIdent($ident) + { + /* Call our base class's setIdent() method. */ + parent::setIdent($ident); + + /* ... and then call setIdent() on all of our children. */ + foreach ($this->_children as $child) { + $child->setIdent($ident); + } + } + + /** + * Adds a Log instance to the list of children. + * + * @param object $child The Log instance to add. + * + * @return boolean True if the Log instance was successfully added. + * + * @access public + */ + function addChild(&$child) + { + /* Make sure this is a Log instance. */ + if (!is_a($child, 'Log')) { + return false; + } + + $this->_children[$child->_id] = $child; + + return true; + } + + /** + * Removes a Log instance from the list of children. + * + * @param object $child The Log instance to remove. + * + * @return boolean True if the Log instance was successfully removed. + * + * @access public + */ + function removeChild($child) + { + if (!is_a($child, 'Log') || !isset($this->_children[$child->_id])) { + return false; + } + + unset($this->_children[$child->_id]); + + return true; + } + +} diff --git a/includes/Log-1.12.7/Log/console.php b/includes/Log-1.12.7/Log/console.php new file mode 100644 index 000000000..cfd881258 --- /dev/null +++ b/includes/Log-1.12.7/Log/console.php @@ -0,0 +1,222 @@ + + * @since Log 1.1 + * @package Log + * + * @example console.php Using the console handler. + */ +class Log_console extends Log +{ + /** + * Handle to the current output stream. + * @var resource + * @access private + */ + var $_stream = null; + + /** + * Is this object responsible for closing the stream resource? + * @var bool + * @access private + */ + var $_closeResource = false; + + /** + * Should the output be buffered or displayed immediately? + * @var string + * @access private + */ + var $_buffering = false; + + /** + * String holding the buffered output. + * @var string + * @access private + */ + var $_buffer = ''; + + /** + * String containing the format of a log line. + * @var string + * @access private + */ + var $_lineFormat = '%1$s %2$s [%3$s] %4$s'; + + /** + * String containing the timestamp format. It will be passed directly to + * strftime(). Note that the timestamp string will generated using the + * current locale. + * @var string + * @access private + */ + var $_timeFormat = '%b %d %H:%M:%S'; + + /** + * Constructs a new Log_console object. + * + * @param string $name Ignored. + * @param string $ident The identity string. + * @param array $conf The configuration array. + * @param int $level Log messages up to and including this level. + * @access public + */ + function Log_console($name, $ident = '', $conf = array(), + $level = PEAR_LOG_DEBUG) + { + $this->_id = md5(microtime()); + $this->_ident = $ident; + $this->_mask = Log::UPTO($level); + + if (!empty($conf['stream'])) { + $this->_stream = $conf['stream']; + } elseif (defined('STDOUT')) { + $this->_stream = STDOUT; + } else { + $this->_stream = fopen('php://output', 'a'); + $this->_closeResource = true; + } + + if (isset($conf['buffering'])) { + $this->_buffering = $conf['buffering']; + } + + if (!empty($conf['lineFormat'])) { + $this->_lineFormat = str_replace(array_keys($this->_formatMap), + array_values($this->_formatMap), + $conf['lineFormat']); + } + + if (!empty($conf['timeFormat'])) { + $this->_timeFormat = $conf['timeFormat']; + } + + /* + * If output buffering has been requested, we need to register a + * shutdown function that will dump the buffer upon termination. + */ + if ($this->_buffering) { + register_shutdown_function(array(&$this, '_Log_console')); + } + } + + /** + * Destructor + */ + function _Log_console() + { + $this->close(); + } + + /** + * Open the output stream. + * + * @access public + * @since Log 1.9.7 + */ + function open() + { + $this->_opened = true; + return true; + } + + /** + * Closes the output stream. + * + * This results in a call to flush(). + * + * @access public + * @since Log 1.9.0 + */ + function close() + { + $this->flush(); + $this->_opened = false; + if ($this->_closeResource === true && is_resource($this->_stream)) { + fclose($this->_stream); + } + return true; + } + + /** + * Flushes all pending ("buffered") data to the output stream. + * + * @access public + * @since Log 1.8.2 + */ + function flush() + { + /* + * If output buffering is enabled, dump the contents of the buffer to + * the output stream. + */ + if ($this->_buffering && (strlen($this->_buffer) > 0)) { + fwrite($this->_stream, $this->_buffer); + $this->_buffer = ''; + } + + if (is_resource($this->_stream)) { + return fflush($this->_stream); + } + + return false; + } + + /** + * Writes $message to the text console. Also, passes the message + * along to any Log_observer instances that are observing this Log. + * + * @param mixed $message String or object containing the message to log. + * @param string $priority The priority of the message. Valid + * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, + * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, + * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG. + * @return boolean True on success or false on failure. + * @access public + */ + function log($message, $priority = null) + { + /* If a priority hasn't been specified, use the default value. */ + if ($priority === null) { + $priority = $this->_priority; + } + + /* Abort early if the priority is above the maximum logging level. */ + if (!$this->_isMasked($priority)) { + return false; + } + + /* Extract the string representation of the message. */ + $message = $this->_extractMessage($message); + + /* Build the string containing the complete log line. */ + $line = $this->_format($this->_lineFormat, + strftime($this->_timeFormat), + $priority, $message) . "\n"; + + /* + * If buffering is enabled, append this line to the output buffer. + * Otherwise, print the line to the output stream immediately. + */ + if ($this->_buffering) { + $this->_buffer .= $line; + } else { + fwrite($this->_stream, $line); + } + + /* Notify observers about this log message. */ + $this->_announce(array('priority' => $priority, 'message' => $message)); + + return true; + } +} diff --git a/includes/Log-1.12.7/Log/daemon.php b/includes/Log-1.12.7/Log/daemon.php new file mode 100644 index 000000000..418173d8a --- /dev/null +++ b/includes/Log-1.12.7/Log/daemon.php @@ -0,0 +1,235 @@ + + * @version $Revision: 250926 $ + * @package Log + */ +class Log_daemon extends Log +{ + /** + * Integer holding the log facility to use. + * @var string + */ + var $_name = LOG_DAEMON; + + /** + * Var holding the resource pointer to the socket + * @var resource + */ + var $_socket; + + /** + * The ip address or servername + * @see http://www.php.net/manual/en/transports.php + * @var string + */ + var $_ip = '127.0.0.1'; + + /** + * Protocol to use (tcp, udp, etc.) + * @see http://www.php.net/manual/en/transports.php + * @var string + */ + var $_proto = 'udp'; + + /** + * Port to connect to + * @var int + */ + var $_port = 514; + + /** + * Maximum message length in bytes + * @var int + */ + var $_maxsize = 4096; + + /** + * Socket timeout in seconds + * @var int + */ + var $_timeout = 1; + + + /** + * Constructs a new syslog object. + * + * @param string $name The syslog facility. + * @param string $ident The identity string. + * @param array $conf The configuration array. + * @param int $maxLevel Maximum level at which to log. + * @access public + */ + function Log_daemon($name, $ident = '', $conf = array(), + $level = PEAR_LOG_DEBUG) + { + /* Ensure we have a valid integer value for $name. */ + if (empty($name) || !is_int($name)) { + $name = LOG_SYSLOG; + } + + $this->_id = md5(microtime()); + $this->_name = $name; + $this->_ident = $ident; + $this->_mask = Log::UPTO($level); + + if (isset($conf['ip'])) { + $this->_ip = $conf['ip']; + } + if (isset($conf['proto'])) { + $this->_proto = $conf['proto']; + } + if (isset($conf['port'])) { + $this->_port = $conf['port']; + } + if (isset($conf['maxsize'])) { + $this->_maxsize = $conf['maxsize']; + } + if (isset($conf['timeout'])) { + $this->_timeout = $conf['timeout']; + } + $this->_proto = $this->_proto . '://'; + + register_shutdown_function(array(&$this, '_Log_daemon')); + } + + /** + * Destructor. + * + * @access private + */ + function _Log_daemon() + { + $this->close(); + } + + /** + * Opens a connection to the system logger, if it has not already + * been opened. This is implicitly called by log(), if necessary. + * @access public + */ + function open() + { + if (!$this->_opened) { + $this->_opened = (bool)($this->_socket = @fsockopen( + $this->_proto . $this->_ip, + $this->_port, + $errno, + $errstr, + $this->_timeout)); + } + return $this->_opened; + } + + /** + * Closes the connection to the system logger, if it is open. + * @access public + */ + function close() + { + if ($this->_opened) { + $this->_opened = false; + return fclose($this->_socket); + } + return true; + } + + /** + * Sends $message to the currently open syslog connection. Calls + * open() if necessary. Also passes the message along to any Log_observer + * instances that are observing this Log. + * + * @param string $message The textual message to be logged. + * @param int $priority (optional) The priority of the message. Valid + * values are: LOG_EMERG, LOG_ALERT, LOG_CRIT, + * LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, + * and LOG_DEBUG. The default is LOG_INFO. + * @access public + */ + function log($message, $priority = null) + { + /* If a priority hasn't been specified, use the default value. */ + if ($priority === null) { + $priority = $this->_priority; + } + + /* Abort early if the priority is above the maximum logging level. */ + if (!$this->_isMasked($priority)) { + return false; + } + + /* If the connection isn't open and can't be opened, return failure. */ + if (!$this->_opened && !$this->open()) { + return false; + } + + /* Extract the string representation of the message. */ + $message = $this->_extractMessage($message); + + /* Set the facility level. */ + $facility_level = intval($this->_name) + + intval($this->_toSyslog($priority)); + + /* Prepend ident info. */ + if (!empty($this->_ident)) { + $message = $this->_ident . ' ' . $message; + } + + /* Check for message length. */ + if (strlen($message) > $this->_maxsize) { + $message = substr($message, 0, ($this->_maxsize) - 10) . ' [...]'; + } + + /* Write to socket. */ + fwrite($this->_socket, '<' . $facility_level . '>' . $message . "\n"); + + $this->_announce(array('priority' => $priority, 'message' => $message)); + } + + /** + * Converts a PEAR_LOG_* constant into a syslog LOG_* constant. + * + * This function exists because, under Windows, not all of the LOG_* + * constants have unique values. Instead, the PEAR_LOG_* were introduced + * for global use, with the conversion to the LOG_* constants kept local to + * to the syslog driver. + * + * @param int $priority PEAR_LOG_* value to convert to LOG_* value. + * + * @return The LOG_* representation of $priority. + * + * @access private + */ + function _toSyslog($priority) + { + static $priorities = array( + PEAR_LOG_EMERG => LOG_EMERG, + PEAR_LOG_ALERT => LOG_ALERT, + PEAR_LOG_CRIT => LOG_CRIT, + PEAR_LOG_ERR => LOG_ERR, + PEAR_LOG_WARNING => LOG_WARNING, + PEAR_LOG_NOTICE => LOG_NOTICE, + PEAR_LOG_INFO => LOG_INFO, + PEAR_LOG_DEBUG => LOG_DEBUG + ); + + /* If we're passed an unknown priority, default to LOG_INFO. */ + if (!is_int($priority) || !in_array($priority, $priorities)) { + return LOG_INFO; + } + + return $priorities[$priority]; + } + +} diff --git a/includes/Log-1.12.7/Log/display.php b/includes/Log-1.12.7/Log/display.php new file mode 100644 index 000000000..633f37384 --- /dev/null +++ b/includes/Log-1.12.7/Log/display.php @@ -0,0 +1,181 @@ + + * @since Log 1.8.0 + * @package Log + * + * @example display.php Using the display handler. + */ +class Log_display extends Log +{ + /** + * String containing the format of a log line. + * @var string + * @access private + */ + var $_lineFormat = '%3$s: %4$s'; + + /** + * String containing the timestamp format. It will be passed directly to + * strftime(). Note that the timestamp string will generated using the + * current locale. + * @var string + * @access private + */ + var $_timeFormat = '%b %d %H:%M:%S'; + + /** + * Flag indicating whether raw message text should be passed directly to + * the log system. Otherwise, the text will be converted to an HTML-safe + * representation. + * @var boolean + * @access private + */ + var $_rawText = false; + + /** + * Constructs a new Log_display object. + * + * @param string $name Ignored. + * @param string $ident The identity string. + * @param array $conf The configuration array. + * @param int $level Log messages up to and including this level. + * @access public + */ + function Log_display($name = '', $ident = '', $conf = array(), + $level = PEAR_LOG_DEBUG) + { + $this->_id = md5(microtime()); + $this->_ident = $ident; + $this->_mask = Log::UPTO($level); + + /* Start by configuring the line format. */ + if (!empty($conf['lineFormat'])) { + $this->_lineFormat = str_replace(array_keys($this->_formatMap), + array_values($this->_formatMap), + $conf['lineFormat']); + } + + /* We may need to prepend a string to our line format. */ + $prepend = null; + if (isset($conf['error_prepend'])) { + $prepend = $conf['error_prepend']; + } else { + $prepend = ini_get('error_prepend_string'); + } + if (!empty($prepend)) { + $this->_lineFormat = $prepend . $this->_lineFormat; + } + + /* We may also need to append a string to our line format. */ + $append = null; + if (isset($conf['error_append'])) { + $append = $conf['error_append']; + } else { + $append = ini_get('error_append_string'); + } + if (!empty($append)) { + $this->_lineFormat .= $append; + } + + /* Lastly, the line ending sequence is also configurable. */ + if (isset($conf['linebreak'])) { + $this->_lineFormat .= $conf['linebreak']; + } else { + $this->_lineFormat .= "
\n"; + } + + /* The user can also change the time format. */ + if (!empty($conf['timeFormat'])) { + $this->_timeFormat = $conf['timeFormat']; + } + + /* Message text conversion can be disabled. */ + if (isset($conf['rawText'])) { + $this->_rawText = $conf['rawText']; + } + } + + /** + * Opens the display handler. + * + * @access public + * @since Log 1.9.6 + */ + function open() + { + $this->_opened = true; + return true; + } + + /** + * Closes the display handler. + * + * @access public + * @since Log 1.9.6 + */ + function close() + { + $this->_opened = false; + return true; + } + + /** + * Writes $message to the text browser. Also, passes the message + * along to any Log_observer instances that are observing this Log. + * + * @param mixed $message String or object containing the message to log. + * @param string $priority The priority of the message. Valid + * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, + * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, + * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG. + * @return boolean True on success or false on failure. + * @access public + */ + function log($message, $priority = null) + { + /* If a priority hasn't been specified, use the default value. */ + if ($priority === null) { + $priority = $this->_priority; + } + + /* Abort early if the priority is above the maximum logging level. */ + if (!$this->_isMasked($priority)) { + return false; + } + + /* Extract the string representation of the message. */ + $message = $this->_extractMessage($message); + + /* Convert the message to an HTML-friendly represention unless raw + * text has been requested. */ + if ($this->_rawText === false) { + $message = nl2br(htmlspecialchars($message)); + } + + /* Build and output the complete log line. */ + echo $this->_format($this->_lineFormat, + strftime($this->_timeFormat), + $priority, + $message); + + /* Notify observers about this log message. */ + $this->_announce(array('priority' => $priority, 'message' => $message)); + + return true; + } + +} diff --git a/includes/Log-1.12.7/Log/error_log.php b/includes/Log-1.12.7/Log/error_log.php new file mode 100644 index 000000000..05faf87b1 --- /dev/null +++ b/includes/Log-1.12.7/Log/error_log.php @@ -0,0 +1,160 @@ + + * @since Log 1.7.0 + * @package Log + * + * @example error_log.php Using the error_log handler. + */ +class Log_error_log extends Log +{ + /** + * The error_log() log type. + * @var integer + * @access private + */ + var $_type = PEAR_LOG_TYPE_SYSTEM; + + /** + * The type-specific destination value. + * @var string + * @access private + */ + var $_destination = ''; + + /** + * Additional headers to pass to the mail() function when the + * PEAR_LOG_TYPE_MAIL type is used. + * @var string + * @access private + */ + var $_extra_headers = ''; + + /** + * String containing the format of a log line. + * @var string + * @access private + */ + var $_lineFormat = '%2$s: %4$s'; + + /** + * String containing the timestamp format. It will be passed directly to + * strftime(). Note that the timestamp string will generated using the + * current locale. + * @var string + * @access private + */ + var $_timeFormat = '%b %d %H:%M:%S'; + + /** + * Constructs a new Log_error_log object. + * + * @param string $name One of the PEAR_LOG_TYPE_* constants. + * @param string $ident The identity string. + * @param array $conf The configuration array. + * @param int $level Log messages up to and including this level. + * @access public + */ + function Log_error_log($name, $ident = '', $conf = array(), + $level = PEAR_LOG_DEBUG) + { + $this->_id = md5(microtime()); + $this->_type = $name; + $this->_ident = $ident; + $this->_mask = Log::UPTO($level); + + if (!empty($conf['destination'])) { + $this->_destination = $conf['destination']; + } + + if (!empty($conf['extra_headers'])) { + $this->_extra_headers = $conf['extra_headers']; + } + + if (!empty($conf['lineFormat'])) { + $this->_lineFormat = str_replace(array_keys($this->_formatMap), + array_values($this->_formatMap), + $conf['lineFormat']); + } + + if (!empty($conf['timeFormat'])) { + $this->_timeFormat = $conf['timeFormat']; + } + } + + /** + * Opens the handler. + * + * @access public + * @since Log 1.9.6 + */ + function open() + { + $this->_opened = true; + return true; + } + + /** + * Closes the handler. + * + * @access public + * @since Log 1.9.6 + */ + function close() + { + $this->_opened = false; + return true; + } + + /** + * Logs $message using PHP's error_log() function. The message is also + * passed along to any Log_observer instances that are observing this Log. + * + * @param mixed $message String or object containing the message to log. + * @param string $priority The priority of the message. Valid + * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, + * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, + * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG. + * @return boolean True on success or false on failure. + * @access public + */ + function log($message, $priority = null) + { + /* If a priority hasn't been specified, use the default value. */ + if ($priority === null) { + $priority = $this->_priority; + } + + /* Abort early if the priority is above the maximum logging level. */ + if (!$this->_isMasked($priority)) { + return false; + } + + /* Extract the string representation of the message. */ + $message = $this->_extractMessage($message); + + /* Build the string containing the complete log line. */ + $line = $this->_format($this->_lineFormat, + strftime($this->_timeFormat), + $priority, $message); + + /* Pass the log line and parameters to the error_log() function. */ + $success = error_log($line, $this->_type, $this->_destination, + $this->_extra_headers); + + $this->_announce(array('priority' => $priority, 'message' => $message)); + + return $success; + } + +} diff --git a/includes/Log-1.12.7/Log/file.php b/includes/Log-1.12.7/Log/file.php new file mode 100644 index 000000000..9e84eb38d --- /dev/null +++ b/includes/Log-1.12.7/Log/file.php @@ -0,0 +1,316 @@ + + * @author Roman Neuhauser + * @since Log 1.0 + * @package Log + * + * @example file.php Using the file handler. + */ +class Log_file extends Log +{ + /** + * String containing the name of the log file. + * @var string + * @access private + */ + var $_filename = 'php.log'; + + /** + * Handle to the log file. + * @var resource + * @access private + */ + var $_fp = false; + + /** + * Should new log entries be append to an existing log file, or should the + * a new log file overwrite an existing one? + * @var boolean + * @access private + */ + var $_append = true; + + /** + * Should advisory file locking (i.e., flock()) be used? + * @var boolean + * @access private + */ + var $_locking = false; + + /** + * Integer (in octal) containing the log file's permissions mode. + * @var integer + * @access private + */ + var $_mode = 0644; + + /** + * Integer (in octal) specifying the file permission mode that will be + * used when creating directories that do not already exist. + * @var integer + * @access private + */ + var $_dirmode = 0755; + + /** + * String containing the format of a log line. + * @var string + * @access private + */ + var $_lineFormat = '%1$s %2$s [%3$s] %4$s'; + + /** + * String containing the timestamp format. It will be passed directly to + * strftime(). Note that the timestamp string will generated using the + * current locale. + * @var string + * @access private + */ + var $_timeFormat = '%b %d %H:%M:%S'; + + /** + * String containing the end-on-line character sequence. + * @var string + * @access private + */ + var $_eol = "\n"; + + /** + * Constructs a new Log_file object. + * + * @param string $name Ignored. + * @param string $ident The identity string. + * @param array $conf The configuration array. + * @param int $level Log messages up to and including this level. + * @access public + */ + function Log_file($name, $ident = '', $conf = array(), + $level = PEAR_LOG_DEBUG) + { + $this->_id = md5(microtime()); + $this->_filename = $name; + $this->_ident = $ident; + $this->_mask = Log::UPTO($level); + + if (isset($conf['append'])) { + $this->_append = $conf['append']; + } + + if (isset($conf['locking'])) { + $this->_locking = $conf['locking']; + } + + if (!empty($conf['mode'])) { + if (is_string($conf['mode'])) { + $this->_mode = octdec($conf['mode']); + } else { + $this->_mode = $conf['mode']; + } + } + + if (!empty($conf['dirmode'])) { + if (is_string($conf['dirmode'])) { + $this->_dirmode = octdec($conf['dirmode']); + } else { + $this->_dirmode = $conf['dirmode']; + } + } + + if (!empty($conf['lineFormat'])) { + $this->_lineFormat = str_replace(array_keys($this->_formatMap), + array_values($this->_formatMap), + $conf['lineFormat']); + } + + if (!empty($conf['timeFormat'])) { + $this->_timeFormat = $conf['timeFormat']; + } + + if (!empty($conf['eol'])) { + $this->_eol = $conf['eol']; + } else { + $this->_eol = (strstr(PHP_OS, 'WIN')) ? "\r\n" : "\n"; + } + + register_shutdown_function(array(&$this, '_Log_file')); + } + + /** + * Destructor + */ + function _Log_file() + { + if ($this->_opened) { + $this->close(); + } + } + + /** + * Creates the given directory path. If the parent directories don't + * already exist, they will be created, too. + * + * This implementation is inspired by Python's os.makedirs function. + * + * @param string $path The full directory path to create. + * @param integer $mode The permissions mode with which the + * directories will be created. + * + * @return True if the full path is successfully created or already + * exists. + * + * @access private + */ + function _mkpath($path, $mode = 0700) + { + /* Separate the last pathname component from the rest of the path. */ + $head = dirname($path); + $tail = basename($path); + + /* Make sure we've split the path into two complete components. */ + if (empty($tail)) { + $head = dirname($path); + $tail = basename($path); + } + + /* Recurse up the path if our current segment does not exist. */ + if (!empty($head) && !empty($tail) && !is_dir($head)) { + $this->_mkpath($head, $mode); + } + + /* Create this segment of the path. */ + return @mkdir($head, $mode); + } + + /** + * Opens the log file for output. If the specified log file does not + * already exist, it will be created. By default, new log entries are + * appended to the end of the log file. + * + * This is implicitly called by log(), if necessary. + * + * @access public + */ + function open() + { + if (!$this->_opened) { + /* If the log file's directory doesn't exist, create it. */ + if (!is_dir(dirname($this->_filename))) { + $this->_mkpath($this->_filename, $this->_dirmode); + } + + /* Determine whether the log file needs to be created. */ + $creating = !file_exists($this->_filename); + + /* Obtain a handle to the log file. */ + $this->_fp = fopen($this->_filename, ($this->_append) ? 'a' : 'w'); + + /* We consider the file "opened" if we have a valid file pointer. */ + $this->_opened = ($this->_fp !== false); + + /* Attempt to set the file's permissions if we just created it. */ + if ($creating && $this->_opened) { + chmod($this->_filename, $this->_mode); + } + } + + return $this->_opened; + } + + /** + * Closes the log file if it is open. + * + * @access public + */ + function close() + { + /* If the log file is open, close it. */ + if ($this->_opened && fclose($this->_fp)) { + $this->_opened = false; + } + + return ($this->_opened === false); + } + + /** + * Flushes all pending data to the file handle. + * + * @access public + * @since Log 1.8.2 + */ + function flush() + { + if (is_resource($this->_fp)) { + return fflush($this->_fp); + } + + return false; + } + + /** + * Logs $message to the output window. The message is also passed along + * to any Log_observer instances that are observing this Log. + * + * @param mixed $message String or object containing the message to log. + * @param string $priority The priority of the message. Valid + * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, + * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, + * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG. + * @return boolean True on success or false on failure. + * @access public + */ + function log($message, $priority = null) + { + /* If a priority hasn't been specified, use the default value. */ + if ($priority === null) { + $priority = $this->_priority; + } + + /* Abort early if the priority is above the maximum logging level. */ + if (!$this->_isMasked($priority)) { + return false; + } + + /* If the log file isn't already open, open it now. */ + if (!$this->_opened && !$this->open()) { + return false; + } + + /* Extract the string representation of the message. */ + $message = $this->_extractMessage($message); + + /* Build the string containing the complete log line. */ + $line = $this->_format($this->_lineFormat, + strftime($this->_timeFormat), + $priority, $message) . $this->_eol; + + /* If locking is enabled, acquire an exclusive lock on the file. */ + if ($this->_locking) { + flock($this->_fp, LOCK_EX); + } + + /* Write the log line to the log file. */ + $success = (fwrite($this->_fp, $line) !== false); + + /* Unlock the file now that we're finished writing to it. */ + if ($this->_locking) { + flock($this->_fp, LOCK_UN); + } + + /* Notify observers about this log message. */ + $this->_announce(array('priority' => $priority, 'message' => $message)); + + return $success; + } + +} diff --git a/includes/Log-1.12.7/Log/firebug.php b/includes/Log-1.12.7/Log/firebug.php new file mode 100644 index 000000000..ee79a6432 --- /dev/null +++ b/includes/Log-1.12.7/Log/firebug.php @@ -0,0 +1,207 @@ + + * @since Log 1.9.11 + * @package Log + * + * @example firebug.php Using the firebug handler. + */ +class Log_firebug extends Log +{ + /** + * Should the output be buffered or displayed immediately? + * @var string + * @access private + */ + var $_buffering = false; + + /** + * String holding the buffered output. + * @var string + * @access private + */ + var $_buffer = array(); + + /** + * String containing the format of a log line. + * @var string + * @access private + */ + var $_lineFormat = '%2$s [%3$s] %4$s'; + + /** + * String containing the timestamp format. It will be passed directly to + * strftime(). Note that the timestamp string will generated using the + * current locale. + * + * Note! Default lineFormat of this driver does not display time. + * + * @var string + * @access private + */ + var $_timeFormat = '%b %d %H:%M:%S'; + + /** + * Mapping of log priorities to Firebug methods. + * @var array + * @access private + */ + var $_methods = array( + PEAR_LOG_EMERG => 'error', + PEAR_LOG_ALERT => 'error', + PEAR_LOG_CRIT => 'error', + PEAR_LOG_ERR => 'error', + PEAR_LOG_WARNING => 'warn', + PEAR_LOG_NOTICE => 'info', + PEAR_LOG_INFO => 'info', + PEAR_LOG_DEBUG => 'debug' + ); + + /** + * Constructs a new Log_firebug object. + * + * @param string $name Ignored. + * @param string $ident The identity string. + * @param array $conf The configuration array. + * @param int $level Log messages up to and including this level. + * @access public + */ + function Log_firebug($name = '', $ident = 'PHP', $conf = array(), + $level = PEAR_LOG_DEBUG) + { + $this->_id = md5(microtime()); + $this->_ident = $ident; + $this->_mask = Log::UPTO($level); + if (isset($conf['buffering'])) { + $this->_buffering = $conf['buffering']; + } + + if ($this->_buffering) { + register_shutdown_function(array(&$this, '_Log_firebug')); + } + + if (!empty($conf['lineFormat'])) { + $this->_lineFormat = str_replace(array_keys($this->_formatMap), + array_values($this->_formatMap), + $conf['lineFormat']); + } + + if (!empty($conf['timeFormat'])) { + $this->_timeFormat = $conf['timeFormat']; + } + } + + /** + * Opens the firebug handler. + * + * @access public + */ + function open() + { + $this->_opened = true; + return true; + } + + /** + * Destructor + */ + function _Log_firebug() + { + $this->close(); + } + + /** + * Closes the firebug handler. + * + * @access public + */ + function close() + { + $this->flush(); + $this->_opened = false; + return true; + } + + /** + * Flushes all pending ("buffered") data. + * + * @access public + */ + function flush() { + if (count($this->_buffer)) { + print '\n"; + }; + $this->_buffer = array(); + } + + /** + * Writes $message to Firebug console. Also, passes the message + * along to any Log_observer instances that are observing this Log. + * + * @param mixed $message String or object containing the message to log. + * @param string $priority The priority of the message. Valid + * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, + * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, + * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG. + * @return boolean True on success or false on failure. + * @access public + */ + function log($message, $priority = null) + { + /* If a priority hasn't been specified, use the default value. */ + if ($priority === null) { + $priority = $this->_priority; + } + + /* Abort early if the priority is above the maximum logging level. */ + if (!$this->_isMasked($priority)) { + return false; + } + + /* Extract the string representation of the message. */ + $message = $this->_extractMessage($message); + $method = $this->_methods[$priority]; + + /* normalize line breaks and escape quotes*/ + $message = preg_replace("/\r?\n/", "\\n", addslashes($message)); + + /* Build the string containing the complete log line. */ + $line = $this->_format($this->_lineFormat, + strftime($this->_timeFormat), + $priority, + $message); + + if ($this->_buffering) { + $this->_buffer[] = sprintf('console.%s("%s");', $method, $line); + } else { + print '\n"; + } + /* Notify observers about this log message. */ + $this->_announce(array('priority' => $priority, 'message' => $message)); + + return true; + } +} diff --git a/includes/Log-1.12.7/Log/mail.php b/includes/Log-1.12.7/Log/mail.php new file mode 100644 index 000000000..9f0b29c63 --- /dev/null +++ b/includes/Log-1.12.7/Log/mail.php @@ -0,0 +1,294 @@ + + * @author Jon Parise + * @since Log 1.3 + * @package Log + * + * @example mail.php Using the mail handler. + */ +class Log_mail extends Log +{ + /** + * String holding the recipients' email addresses. Multiple addresses + * should be separated with commas. + * @var string + * @access private + */ + var $_recipients = ''; + + /** + * String holding the sender's email address. + * @var string + * @access private + */ + var $_from = ''; + + /** + * String holding the email's subject. + * @var string + * @access private + */ + var $_subject = '[Log_mail] Log message'; + + /** + * String holding an optional preamble for the log messages. + * @var string + * @access private + */ + var $_preamble = ''; + + /** + * String containing the format of a log line. + * @var string + * @access private + */ + var $_lineFormat = '%1$s %2$s [%3$s] %4$s'; + + /** + * String containing the timestamp format. It will be passed directly to + * strftime(). Note that the timestamp string will generated using the + * current locale. + * @var string + * @access private + */ + var $_timeFormat = '%b %d %H:%M:%S'; + + /** + * String holding the mail message body. + * @var string + * @access private + */ + var $_message = ''; + + /** + * Flag used to indicated that log lines have been written to the message + * body and the message should be sent on close(). + * @var boolean + * @access private + */ + var $_shouldSend = false; + + /** + * String holding the backend name of PEAR::Mail + * @var string + * @access private + */ + var $_mailBackend = ''; + + /** + * Array holding the params for PEAR::Mail + * @var array + * @access private + */ + var $_mailParams = array(); + + /** + * Constructs a new Log_mail object. + * + * Here is how you can customize the mail driver with the conf[] hash : + * $conf['from']: the mail's "From" header line, + * $conf['subject']: the mail's "Subject" line. + * $conf['mailBackend']: backend name of PEAR::Mail + * $conf['mailParams']: parameters for the PEAR::Mail backend + * + * @param string $name The message's recipients. + * @param string $ident The identity string. + * @param array $conf The configuration array. + * @param int $level Log messages up to and including this level. + * @access public + */ + function Log_mail($name, $ident = '', $conf = array(), + $level = PEAR_LOG_DEBUG) + { + $this->_id = md5(microtime()); + $this->_recipients = $name; + $this->_ident = $ident; + $this->_mask = Log::UPTO($level); + + if (!empty($conf['from'])) { + $this->_from = $conf['from']; + } else { + $this->_from = ini_get('sendmail_from'); + } + + if (!empty($conf['subject'])) { + $this->_subject = $conf['subject']; + } + + if (!empty($conf['preamble'])) { + $this->_preamble = $conf['preamble']; + } + + if (!empty($conf['lineFormat'])) { + $this->_lineFormat = str_replace(array_keys($this->_formatMap), + array_values($this->_formatMap), + $conf['lineFormat']); + } + + if (!empty($conf['timeFormat'])) { + $this->_timeFormat = $conf['timeFormat']; + } + + if (!empty($conf['mailBackend'])) { + $this->_mailBackend = $conf['mailBackend']; + } + + if (!empty($conf['mailParams'])) { + $this->_mailParams = $conf['mailParams']; + } + + /* register the destructor */ + register_shutdown_function(array(&$this, '_Log_mail')); + } + + /** + * Destructor. Calls close(). + * + * @access private + */ + function _Log_mail() + { + $this->close(); + } + + /** + * Starts a new mail message. + * This is implicitly called by log(), if necessary. + * + * @access public + */ + function open() + { + if (!$this->_opened) { + if (!empty($this->_preamble)) { + $this->_message = $this->_preamble . "\r\n\r\n"; + } + $this->_opened = true; + $_shouldSend = false; + } + + return $this->_opened; + } + + /** + * Closes the message, if it is open, and sends the mail. + * This is implicitly called by the destructor, if necessary. + * + * @access public + */ + function close() + { + if ($this->_opened) { + if ($this->_shouldSend && !empty($this->_message)) { + if ($this->_mailBackend === '') { // use mail() + $headers = "From: $this->_from\r\n"; + $headers .= 'User-Agent: PEAR Log Package'; + if (mail($this->_recipients, $this->_subject, + $this->_message, $headers) == false) { + return false; + } + } else { // use PEAR::Mail + include_once 'Mail.php'; + $headers = array('From' => $this->_from, + 'To' => $this->_recipients, + 'User-Agent' => 'PEAR Log Package', + 'Subject' => $this->_subject); + $mailer = &Mail::factory($this->_mailBackend, + $this->_mailParams); + $res = $mailer->send($this->_recipients, $headers, + $this->_message); + if (PEAR::isError($res)) { + return false; + } + } + + /* Clear the message string now that the email has been sent. */ + $this->_message = ''; + $this->_shouldSend = false; + } + $this->_opened = false; + } + + return ($this->_opened === false); + } + + /** + * Flushes the log output by forcing the email message to be sent now. + * Events that are logged after flush() is called will be appended to a + * new email message. + * + * @access public + * @since Log 1.8.2 + */ + function flush() + { + /* + * It's sufficient to simply call close() to flush the output. + * The next call to log() will cause the handler to be reopened. + */ + return $this->close(); + } + + /** + * Writes $message to the currently open mail message. + * Calls open(), if necessary. + * + * @param mixed $message String or object containing the message to log. + * @param string $priority The priority of the message. Valid + * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, + * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, + * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG. + * @return boolean True on success or false on failure. + * @access public + */ + function log($message, $priority = null) + { + /* If a priority hasn't been specified, use the default value. */ + if ($priority === null) { + $priority = $this->_priority; + } + + /* Abort early if the priority is above the maximum logging level. */ + if (!$this->_isMasked($priority)) { + return false; + } + + /* If the message isn't open and can't be opened, return failure. */ + if (!$this->_opened && !$this->open()) { + return false; + } + + /* Extract the string representation of the message. */ + $message = $this->_extractMessage($message); + + /* Append the string containing the complete log line. */ + $this->_message .= $this->_format($this->_lineFormat, + strftime($this->_timeFormat), + $priority, $message) . "\r\n"; + $this->_shouldSend = true; + + /* Notify observers about this log message. */ + $this->_announce(array('priority' => $priority, 'message' => $message)); + + return true; + } +} diff --git a/includes/Log-1.12.7/Log/mcal.php b/includes/Log-1.12.7/Log/mcal.php new file mode 100644 index 000000000..76788d00a --- /dev/null +++ b/includes/Log-1.12.7/Log/mcal.php @@ -0,0 +1,170 @@ + + * @since Horde 1.3 + * @since Log 1.0 + * @package Log + */ +class Log_mcal extends Log +{ + /** + * holding the calendar specification to connect to. + * @var string + * @access private + */ + var $_calendar = '{localhost/mstore}'; + + /** + * holding the username to use. + * @var string + * @access private + */ + var $_username = ''; + + /** + * holding the password to use. + * @var string + * @access private + */ + var $_password = ''; + + /** + * holding the options to pass to the calendar stream. + * @var integer + * @access private + */ + var $_options = 0; + + /** + * ResourceID of the MCAL stream. + * @var string + * @access private + */ + var $_stream = ''; + + /** + * Integer holding the log facility to use. + * @var string + * @access private + */ + var $_name = LOG_SYSLOG; + + + /** + * Constructs a new Log_mcal object. + * + * @param string $name The category to use for our events. + * @param string $ident The identity string. + * @param array $conf The configuration array. + * @param int $level Log messages up to and including this level. + * @access public + */ + function Log_mcal($name, $ident = '', $conf = array(), + $level = PEAR_LOG_DEBUG) + { + $this->_id = md5(microtime()); + $this->_name = $name; + $this->_ident = $ident; + $this->_mask = Log::UPTO($level); + $this->_calendar = $conf['calendar']; + $this->_username = $conf['username']; + $this->_password = $conf['password']; + $this->_options = $conf['options']; + } + + /** + * Opens a calendar stream, if it has not already been + * opened. This is implicitly called by log(), if necessary. + * @access public + */ + function open() + { + if (!$this->_opened) { + $this->_stream = mcal_open($this->_calendar, $this->_username, + $this->_password, $this->_options); + $this->_opened = true; + } + + return $this->_opened; + } + + /** + * Closes the calendar stream, if it is open. + * @access public + */ + function close() + { + if ($this->_opened) { + mcal_close($this->_stream); + $this->_opened = false; + } + + return ($this->_opened === false); + } + + /** + * Logs $message and associated information to the currently open + * calendar stream. Calls open() if necessary. Also passes the + * message along to any Log_observer instances that are observing + * this Log. + * + * @param mixed $message String or object containing the message to log. + * @param string $priority The priority of the message. Valid + * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, + * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, + * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG. + * @return boolean True on success or false on failure. + * @access public + */ + function log($message, $priority = null) + { + /* If a priority hasn't been specified, use the default value. */ + if ($priority === null) { + $priority = $this->_priority; + } + + /* Abort early if the priority is above the maximum logging level. */ + if (!$this->_isMasked($priority)) { + return false; + } + + /* If the connection isn't open and can't be opened, return failure. */ + if (!$this->_opened && !$this->open()) { + return false; + } + + /* Extract the string representation of the message. */ + $message = $this->_extractMessage($message); + + $date_str = date('Y:n:j:G:i:s'); + $dates = explode(':', $date_str); + + mcal_event_init($this->_stream); + mcal_event_set_title($this->_stream, $this->_ident); + mcal_event_set_category($this->_stream, $this->_name); + mcal_event_set_description($this->_stream, $message); + mcal_event_add_attribute($this->_stream, 'priority', $priority); + mcal_event_set_start($this->_stream, $dates[0], $dates[1], $dates[2], + $dates[3], $dates[4], $dates[5]); + mcal_event_set_end($this->_stream, $dates[0], $dates[1], $dates[2], + $dates[3], $dates[4], $dates[5]); + mcal_append_event($this->_stream); + + $this->_announce(array('priority' => $priority, 'message' => $message)); + + return true; + } + +} diff --git a/includes/Log-1.12.7/Log/mdb2.php b/includes/Log-1.12.7/Log/mdb2.php new file mode 100644 index 000000000..6d0a9e410 --- /dev/null +++ b/includes/Log-1.12.7/Log/mdb2.php @@ -0,0 +1,358 @@ + + * @author Jon Parise + * @since Log 1.9.0 + * @package Log + */ +class Log_mdb2 extends Log +{ + /** + * Variable containing the DSN information. + * @var mixed + * @access private + */ + var $_dsn = ''; + + /** + * Array containing our set of DB configuration options. + * @var array + * @access private + */ + var $_options = array('persistent' => true); + + /** + * Object holding the database handle. + * @var object + * @access private + */ + var $_db = null; + + /** + * Resource holding the prepared statement handle. + * @var resource + * @access private + */ + var $_statement = null; + + /** + * Flag indicating that we're using an existing database connection. + * @var boolean + * @access private + */ + var $_existingConnection = false; + + /** + * String holding the database table to use. + * @var string + * @access private + */ + var $_table = 'log_table'; + + /** + * String holding the name of the ID sequence. + * @var string + * @access private + */ + var $_sequence = 'log_id'; + + /** + * Maximum length of the $ident string. This corresponds to the size of + * the 'ident' column in the SQL table. + * @var integer + * @access private + */ + var $_identLimit = 16; + + /** + * Set of field types used in the database table. + * @var array + * @access private + */ + var $_types = array( + 'id' => 'integer', + 'logtime' => 'timestamp', + 'ident' => 'text', + 'priority' => 'text', + 'message' => 'clob' + ); + + /** + * Constructs a new sql logging object. + * + * @param string $name The target SQL table. + * @param string $ident The identification field. + * @param array $conf The connection configuration array. + * @param int $level Log messages up to and including this level. + * @access public + */ + function Log_mdb2($name, $ident = '', $conf = array(), + $level = PEAR_LOG_DEBUG) + { + $this->_id = md5(microtime()); + $this->_table = $name; + $this->_mask = Log::UPTO($level); + + /* If an options array was provided, use it. */ + if (isset($conf['options']) && is_array($conf['options'])) { + $this->_options = $conf['options']; + } + + /* If a specific sequence name was provided, use it. */ + if (!empty($conf['sequence'])) { + $this->_sequence = $conf['sequence']; + } + + /* If a specific sequence name was provided, use it. */ + if (isset($conf['identLimit'])) { + $this->_identLimit = $conf['identLimit']; + } + + /* Now that the ident limit is confirmed, set the ident string. */ + $this->setIdent($ident); + + /* If an existing database connection was provided, use it. */ + if (isset($conf['db'])) { + $this->_db = &$conf['db']; + $this->_existingConnection = true; + $this->_opened = true; + } elseif (isset($conf['singleton'])) { + $this->_db = &MDB2::singleton($conf['singleton'], $this->_options); + $this->_existingConnection = true; + $this->_opened = true; + } else { + $this->_dsn = $conf['dsn']; + } + } + + /** + * Opens a connection to the database, if it has not already + * been opened. This is implicitly called by log(), if necessary. + * + * @return boolean True on success, false on failure. + * @access public + */ + function open() + { + if (!$this->_opened) { + /* Use the DSN and options to create a database connection. */ + $this->_db = &MDB2::connect($this->_dsn, $this->_options); + if (PEAR::isError($this->_db)) { + return false; + } + + /* Create a prepared statement for repeated use in log(). */ + if (!$this->_prepareStatement()) { + return false; + } + + /* We now consider out connection open. */ + $this->_opened = true; + } + + return $this->_opened; + } + + /** + * Closes the connection to the database if it is still open and we were + * the ones that opened it. It is the caller's responsible to close an + * existing connection that was passed to us via $conf['db']. + * + * @return boolean True on success, false on failure. + * @access public + */ + function close() + { + /* If we have a statement object, free it. */ + if (is_object($this->_statement)) { + $this->_statement->free(); + $this->_statement = null; + } + + /* If we opened the database connection, disconnect it. */ + if ($this->_opened && !$this->_existingConnection) { + $this->_opened = false; + return $this->_db->disconnect(); + } + + return ($this->_opened === false); + } + + /** + * Sets this Log instance's identification string. Note that this + * SQL-specific implementation will limit the length of the $ident string + * to sixteen (16) characters. + * + * @param string $ident The new identification string. + * + * @access public + * @since Log 1.8.5 + */ + function setIdent($ident) + { + $this->_ident = substr($ident, 0, $this->_identLimit); + } + + /** + * Inserts $message to the currently open database. Calls open(), + * if necessary. Also passes the message along to any Log_observer + * instances that are observing this Log. + * + * @param mixed $message String or object containing the message to log. + * @param string $priority The priority of the message. Valid + * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, + * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, + * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG. + * @return boolean True on success or false on failure. + * @access public + */ + function log($message, $priority = null) + { + /* If a priority hasn't been specified, use the default value. */ + if ($priority === null) { + $priority = $this->_priority; + } + + /* Abort early if the priority is above the maximum logging level. */ + if (!$this->_isMasked($priority)) { + return false; + } + + /* If the connection isn't open and can't be opened, return failure. */ + if (!$this->_opened && !$this->open()) { + return false; + } + + /* If we don't already have a statement object, create one. */ + if (!is_object($this->_statement) && !$this->_prepareStatement()) { + return false; + } + + /* Extract the string representation of the message. */ + $message = $this->_extractMessage($message); + + /* Build our set of values for this log entry. */ + $values = array( + 'id' => $this->_db->nextId($this->_sequence), + 'logtime' => MDB2_Date::mdbNow(), + 'ident' => $this->_ident, + 'priority' => $priority, + 'message' => $message + ); + + /* Execute the SQL query for this log entry insertion. */ + $this->_db->expectError(MDB2_ERROR_NOSUCHTABLE); + $result = &$this->_statement->execute($values); + $this->_db->popExpect(); + + /* Attempt to handle any errors. */ + if (PEAR::isError($result)) { + /* We can only handle MDB2_ERROR_NOSUCHTABLE errors. */ + if ($result->getCode() != MDB2_ERROR_NOSUCHTABLE) { + return false; + } + + /* Attempt to create the target table. */ + if (!$this->_createTable()) { + return false; + } + + /* Recreate our prepared statement resource. */ + $this->_statement->free(); + if (!$this->_prepareStatement()) { + return false; + } + + /* Attempt to re-execute the insertion query. */ + $result = $this->_statement->execute($values); + if (PEAR::isError($result)) { + return false; + } + } + + $this->_announce(array('priority' => $priority, 'message' => $message)); + + return true; + } + + /** + * Create the log table in the database. + * + * @return boolean True on success or false on failure. + * @access private + */ + function _createTable() + { + $this->_db->loadModule('Manager', null, true); + $result = $this->_db->manager->createTable( + $this->_table, + array( + 'id' => array('type' => $this->_types['id']), + 'logtime' => array('type' => $this->_types['logtime']), + 'ident' => array('type' => $this->_types['ident']), + 'priority' => array('type' => $this->_types['priority']), + 'message' => array('type' => $this->_types['message']) + ) + ); + if (PEAR::isError($result)) { + return false; + } + + $result = $this->_db->manager->createIndex( + $this->_table, + 'unique_id', + array('fields' => array('id' => true), 'unique' => true) + ); + if (PEAR::isError($result)) { + return false; + } + + return true; + } + + /** + * Prepare the SQL insertion statement. + * + * @return boolean True if the statement was successfully created. + * + * @access private + * @since Log 1.9.0 + */ + function _prepareStatement() + { + $this->_statement = &$this->_db->prepare( + 'INSERT INTO ' . $this->_table . + ' (id, logtime, ident, priority, message)' . + ' VALUES(:id, :logtime, :ident, :priority, :message)', + $this->_types, MDB2_PREPARE_MANIP); + + /* Return success if we didn't generate an error. */ + return (PEAR::isError($this->_statement) === false); + } +} diff --git a/includes/Log-1.12.7/Log/null.php b/includes/Log-1.12.7/Log/null.php new file mode 100644 index 000000000..5fc69f9eb --- /dev/null +++ b/includes/Log-1.12.7/Log/null.php @@ -0,0 +1,91 @@ + + * @since Log 1.8.2 + * @package Log + * + * @example null.php Using the null handler. + */ +class Log_null extends Log +{ + /** + * Constructs a new Log_null object. + * + * @param string $name Ignored. + * @param string $ident The identity string. + * @param array $conf The configuration array. + * @param int $level Log messages up to and including this level. + * @access public + */ + function Log_null($name, $ident = '', $conf = array(), + $level = PEAR_LOG_DEBUG) + { + $this->_id = md5(microtime()); + $this->_ident = $ident; + $this->_mask = Log::UPTO($level); + } + + /** + * Opens the handler. + * + * @access public + * @since Log 1.9.6 + */ + function open() + { + $this->_opened = true; + return true; + } + + /** + * Closes the handler. + * + * @access public + * @since Log 1.9.6 + */ + function close() + { + $this->_opened = false; + return true; + } + + /** + * Simply consumes the log event. The message will still be passed + * along to any Log_observer instances that are observing this Log. + * + * @param mixed $message String or object containing the message to log. + * @param string $priority The priority of the message. Valid + * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, + * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, + * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG. + * @return boolean True on success or false on failure. + * @access public + */ + function log($message, $priority = null) + { + /* If a priority hasn't been specified, use the default value. */ + if ($priority === null) { + $priority = $this->_priority; + } + + /* Abort early if the priority is above the maximum logging level. */ + if (!$this->_isMasked($priority)) { + return false; + } + + $this->_announce(array('priority' => $priority, 'message' => $message)); + + return true; + } + +} diff --git a/includes/Log-1.12.7/Log/observer.php b/includes/Log-1.12.7/Log/observer.php new file mode 100644 index 000000000..2a857661e --- /dev/null +++ b/includes/Log-1.12.7/Log/observer.php @@ -0,0 +1,129 @@ + + * @since Horde 1.3 + * @since Log 1.0 + * @package Log + * + * @example observer_mail.php An example Log_observer implementation. + */ +class Log_observer +{ + /** + * Instance-specific unique identification number. + * + * @var integer + * @access private + */ + var $_id = 0; + + /** + * The minimum priority level of message that we want to hear about. + * PEAR_LOG_EMERG is the highest priority, so we will only hear messages + * with an integer priority value less than or equal to ours. It defaults + * to PEAR_LOG_INFO, which listens to everything except PEAR_LOG_DEBUG. + * + * @var string + * @access private + */ + var $_priority = PEAR_LOG_INFO; + + /** + * Creates a new basic Log_observer instance. + * + * @param integer $priority The highest priority at which to receive + * log event notifications. + * + * @access public + */ + function Log_observer($priority = PEAR_LOG_INFO) + { + $this->_id = md5(microtime()); + $this->_priority = $priority; + } + + /** + * Attempts to return a new concrete Log_observer instance of the requested + * type. + * + * @param string $type The type of concreate Log_observer subclass + * to return. + * @param integer $priority The highest priority at which to receive + * log event notifications. + * @param array $conf Optional associative array of additional + * configuration values. + * + * @return object The newly created concrete Log_observer + * instance, or null on an error. + */ + function &factory($type, $priority = PEAR_LOG_INFO, $conf = array()) + { + $type = strtolower($type); + $class = 'Log_observer_' . $type; + + /* + * If the desired class already exists (because the caller has supplied + * it from some custom location), simply instantiate and return a new + * instance. + */ + if (class_exists($class)) { + $object = new $class($priority, $conf); + return $object; + } + + /* Support both the new-style and old-style file naming conventions. */ + $newstyle = true; + $classfile = dirname(__FILE__) . '/observer_' . $type . '.php'; + + if (!file_exists($classfile)) { + $classfile = 'Log/' . $type . '.php'; + $newstyle = false; + } + + /* + * Attempt to include our version of the named class, but don't treat + * a failure as fatal. The caller may have already included their own + * version of the named class. + */ + @include_once $classfile; + + /* If the class exists, return a new instance of it. */ + if (class_exists($class)) { + /* Support both new-style and old-style construction. */ + if ($newstyle) { + $object = new $class($priority, $conf); + } else { + $object = new $class($priority); + } + return $object; + } + + $null = null; + return $null; + } + + /** + * This is a stub method to make sure that Log_Observer classes do + * something when they are notified of a message. The default behavior + * is to just print the message, which is obviously not desireable in + * practically any situation - which is why you need to override this + * method. :) + * + * @param array $event A hash describing the log event. + */ + function notify($event) + { + print_r($event); + } +} diff --git a/includes/Log-1.12.7/Log/sql.php b/includes/Log-1.12.7/Log/sql.php new file mode 100644 index 000000000..a8efbfb4c --- /dev/null +++ b/includes/Log-1.12.7/Log/sql.php @@ -0,0 +1,294 @@ + + * @since Horde 1.3 + * @since Log 1.0 + * @package Log + * + * @example sql.php Using the SQL handler. + */ +class Log_sql extends Log +{ + /** + * Variable containing the DSN information. + * @var mixed + * @access private + */ + var $_dsn = ''; + + /** + * String containing the SQL insertion statement. + * + * @var string + * @access private + */ + var $_sql = ''; + + /** + * Array containing our set of DB configuration options. + * @var array + * @access private + */ + var $_options = array('persistent' => true); + + /** + * Object holding the database handle. + * @var object + * @access private + */ + var $_db = null; + + /** + * Resource holding the prepared statement handle. + * @var resource + * @access private + */ + var $_statement = null; + + /** + * Flag indicating that we're using an existing database connection. + * @var boolean + * @access private + */ + var $_existingConnection = false; + + /** + * String holding the database table to use. + * @var string + * @access private + */ + var $_table = 'log_table'; + + /** + * String holding the name of the ID sequence. + * @var string + * @access private + */ + var $_sequence = 'log_id'; + + /** + * Maximum length of the $ident string. This corresponds to the size of + * the 'ident' column in the SQL table. + * @var integer + * @access private + */ + var $_identLimit = 16; + + + /** + * Constructs a new sql logging object. + * + * @param string $name The target SQL table. + * @param string $ident The identification field. + * @param array $conf The connection configuration array. + * @param int $level Log messages up to and including this level. + * @access public + */ + function Log_sql($name, $ident = '', $conf = array(), + $level = PEAR_LOG_DEBUG) + { + $this->_id = md5(microtime()); + $this->_table = $name; + $this->_mask = Log::UPTO($level); + + /* Now that we have a table name, assign our SQL statement. */ + if (!empty($conf['sql'])) { + $this->_sql = $conf['sql']; + } else { + $this->_sql = 'INSERT INTO ' . $this->_table . + ' (id, logtime, ident, priority, message)' . + ' VALUES(?, CURRENT_TIMESTAMP, ?, ?, ?)'; + } + + /* If an options array was provided, use it. */ + if (isset($conf['options']) && is_array($conf['options'])) { + $this->_options = $conf['options']; + } + + /* If a specific sequence name was provided, use it. */ + if (!empty($conf['sequence'])) { + $this->_sequence = $conf['sequence']; + } + + /* If a specific sequence name was provided, use it. */ + if (isset($conf['identLimit'])) { + $this->_identLimit = $conf['identLimit']; + } + + /* Now that the ident limit is confirmed, set the ident string. */ + $this->setIdent($ident); + + /* If an existing database connection was provided, use it. */ + if (isset($conf['db'])) { + $this->_db = &$conf['db']; + $this->_existingConnection = true; + $this->_opened = true; + } else { + $this->_dsn = $conf['dsn']; + } + } + + /** + * Opens a connection to the database, if it has not already + * been opened. This is implicitly called by log(), if necessary. + * + * @return boolean True on success, false on failure. + * @access public + */ + function open() + { + if (!$this->_opened) { + /* Use the DSN and options to create a database connection. */ + $this->_db = &DB::connect($this->_dsn, $this->_options); + if (DB::isError($this->_db)) { + return false; + } + + /* Create a prepared statement for repeated use in log(). */ + if (!$this->_prepareStatement()) { + return false; + } + + /* We now consider out connection open. */ + $this->_opened = true; + } + + return $this->_opened; + } + + /** + * Closes the connection to the database if it is still open and we were + * the ones that opened it. It is the caller's responsible to close an + * existing connection that was passed to us via $conf['db']. + * + * @return boolean True on success, false on failure. + * @access public + */ + function close() + { + if ($this->_opened && !$this->_existingConnection) { + $this->_opened = false; + $this->_db->freePrepared($this->_statement); + return $this->_db->disconnect(); + } + + return ($this->_opened === false); + } + + /** + * Sets this Log instance's identification string. Note that this + * SQL-specific implementation will limit the length of the $ident string + * to sixteen (16) characters. + * + * @param string $ident The new identification string. + * + * @access public + * @since Log 1.8.5 + */ + function setIdent($ident) + { + $this->_ident = substr($ident, 0, $this->_identLimit); + } + + /** + * Inserts $message to the currently open database. Calls open(), + * if necessary. Also passes the message along to any Log_observer + * instances that are observing this Log. + * + * @param mixed $message String or object containing the message to log. + * @param string $priority The priority of the message. Valid + * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, + * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, + * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG. + * @return boolean True on success or false on failure. + * @access public + */ + function log($message, $priority = null) + { + /* If a priority hasn't been specified, use the default value. */ + if ($priority === null) { + $priority = $this->_priority; + } + + /* Abort early if the priority is above the maximum logging level. */ + if (!$this->_isMasked($priority)) { + return false; + } + + /* If the connection isn't open and can't be opened, return failure. */ + if (!$this->_opened && !$this->open()) { + return false; + } + + /* If we don't already have our statement object yet, create it. */ + if (!is_object($this->_statement) && !$this->_prepareStatement()) { + return false; + } + + /* Extract the string representation of the message. */ + $message = $this->_extractMessage($message); + + /* Build our set of values for this log entry. */ + $id = $this->_db->nextId($this->_sequence); + $values = array($id, $this->_ident, $priority, $message); + + /* Execute the SQL query for this log entry insertion. */ + $result =& $this->_db->execute($this->_statement, $values); + if (DB::isError($result)) { + return false; + } + + $this->_announce(array('priority' => $priority, 'message' => $message)); + + return true; + } + + /** + * Prepare the SQL insertion statement. + * + * @return boolean True if the statement was successfully created. + * + * @access private + * @since Log 1.9.1 + */ + function _prepareStatement() + { + $this->_statement = $this->_db->prepare($this->_sql); + + /* Return success if we didn't generate an error. */ + return (DB::isError($this->_statement) === false); + } +} diff --git a/includes/Log-1.12.7/Log/sqlite.php b/includes/Log-1.12.7/Log/sqlite.php new file mode 100644 index 000000000..ee5010947 --- /dev/null +++ b/includes/Log-1.12.7/Log/sqlite.php @@ -0,0 +1,225 @@ + + * @author Jon Parise + * @since Log 1.8.3 + * @package Log + * + * @example sqlite.php Using the Sqlite handler. + */ +class Log_sqlite extends Log +{ + /** + * Array containing the connection defaults + * @var array + * @access private + */ + var $_options = array('mode' => 0666, + 'persistent' => false); + + /** + * Object holding the database handle. + * @var object + * @access private + */ + var $_db = null; + + /** + * Flag indicating that we're using an existing database connection. + * @var boolean + * @access private + */ + var $_existingConnection = false; + + /** + * String holding the database table to use. + * @var string + * @access private + */ + var $_table = 'log_table'; + + + /** + * Constructs a new sql logging object. + * + * @param string $name The target SQL table. + * @param string $ident The identification field. + * @param mixed $conf Can be an array of configuration options used + * to open a new database connection + * or an already opened sqlite connection. + * @param int $level Log messages up to and including this level. + * @access public + */ + function Log_sqlite($name, $ident = '', &$conf, $level = PEAR_LOG_DEBUG) + { + $this->_id = md5(microtime()); + $this->_table = $name; + $this->_ident = $ident; + $this->_mask = Log::UPTO($level); + + if (is_array($conf)) { + foreach ($conf as $k => $opt) { + $this->_options[$k] = $opt; + } + } else { + // If an existing database connection was provided, use it. + $this->_db =& $conf; + $this->_existingConnection = true; + } + } + + /** + * Opens a connection to the database, if it has not already + * been opened. This is implicitly called by log(), if necessary. + * + * @return boolean True on success, false on failure. + * @access public + */ + function open() + { + if (is_resource($this->_db)) { + $this->_opened = true; + return $this->_createTable(); + } else { + /* Set the connection function based on the 'persistent' option. */ + if (empty($this->_options['persistent'])) { + $connectFunction = 'sqlite_open'; + } else { + $connectFunction = 'sqlite_popen'; + } + + /* Attempt to connect to the database. */ + if ($this->_db = $connectFunction($this->_options['filename'], + (int)$this->_options['mode'], + $error)) { + $this->_opened = true; + return $this->_createTable(); + } + } + + return $this->_opened; + } + + /** + * Closes the connection to the database if it is still open and we were + * the ones that opened it. It is the caller's responsible to close an + * existing connection that was passed to us via $conf['db']. + * + * @return boolean True on success, false on failure. + * @access public + */ + function close() + { + /* We never close existing connections. */ + if ($this->_existingConnection) { + return false; + } + + if ($this->_opened) { + $this->_opened = false; + sqlite_close($this->_db); + } + + return ($this->_opened === false); + } + + /** + * Inserts $message to the currently open database. Calls open(), + * if necessary. Also passes the message along to any Log_observer + * instances that are observing this Log. + * + * @param mixed $message String or object containing the message to log. + * @param string $priority The priority of the message. Valid + * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, + * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, + * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG. + * @return boolean True on success or false on failure. + * @access public + */ + function log($message, $priority = null) + { + /* If a priority hasn't been specified, use the default value. */ + if ($priority === null) { + $priority = $this->_priority; + } + + /* Abort early if the priority is above the maximum logging level. */ + if (!$this->_isMasked($priority)) { + return false; + } + + /* If the connection isn't open and can't be opened, return failure. */ + if (!$this->_opened && !$this->open()) { + return false; + } + + // Extract the string representation of the message. + $message = $this->_extractMessage($message); + + // Build the SQL query for this log entry insertion. + $q = sprintf('INSERT INTO [%s] (logtime, ident, priority, message) ' . + "VALUES ('%s', '%s', %d, '%s')", + $this->_table, + strftime('%Y-%m-%d %H:%M:%S', time()), + sqlite_escape_string($this->_ident), + $priority, + sqlite_escape_string($message)); + if (!($res = @sqlite_unbuffered_query($this->_db, $q))) { + return false; + } + $this->_announce(array('priority' => $priority, 'message' => $message)); + + return true; + } + + /** + * Checks whether the log table exists and creates it if necessary. + * + * @return boolean True on success or false on failure. + * @access private + */ + function _createTable() + { + $q = "SELECT name FROM sqlite_master WHERE name='" . $this->_table . + "' AND type='table'"; + + $res = sqlite_query($this->_db, $q); + + if (sqlite_num_rows($res) == 0) { + $q = 'CREATE TABLE [' . $this->_table . '] (' . + 'id INTEGER PRIMARY KEY NOT NULL, ' . + 'logtime NOT NULL, ' . + 'ident CHAR(16) NOT NULL, ' . + 'priority INT NOT NULL, ' . + 'message)'; + + if (!($res = sqlite_unbuffered_query($this->_db, $q))) { + return false; + } + } + + return true; + } + +} diff --git a/includes/Log-1.12.7/Log/syslog.php b/includes/Log-1.12.7/Log/syslog.php new file mode 100644 index 000000000..e221c3195 --- /dev/null +++ b/includes/Log-1.12.7/Log/syslog.php @@ -0,0 +1,238 @@ + + * @author Jon Parise + * @since Horde 1.3 + * @since Log 1.0 + * @package Log + * + * @example syslog.php Using the syslog handler. + */ +class Log_syslog extends Log +{ + /** + * Integer holding the log facility to use. + * @var integer + * @access private + */ + var $_name = LOG_SYSLOG; + + /** + * Should we inherit the current syslog connection for this process, or + * should we call openlog() to start a new syslog connection? + * @var boolean + * @access private + */ + var $_inherit = false; + + /** + * Should we re-open the syslog connection for each log event? + * @var boolean + * @access private + */ + var $_reopen = false; + + /** + * Maximum message length that will be sent to syslog(). If the handler + * receives a message longer than this length limit, it will be split into + * multiple syslog() calls. + * @var integer + * @access private + */ + var $_maxLength = 500; + + /** + * String containing the format of a message. + * @var string + * @access private + */ + var $_lineFormat = '%4$s'; + + /** + * String containing the timestamp format. It will be passed directly to + * strftime(). Note that the timestamp string will generated using the + * current locale. + * @var string + * @access private + */ + var $_timeFormat = '%b %d %H:%M:%S'; + + /** + * Constructs a new syslog object. + * + * @param string $name The syslog facility. + * @param string $ident The identity string. + * @param array $conf The configuration array. + * @param int $level Log messages up to and including this level. + * @access public + */ + function Log_syslog($name, $ident = '', $conf = array(), + $level = PEAR_LOG_DEBUG) + { + /* Ensure we have a valid integer value for $name. */ + if (empty($name) || !is_int($name)) { + $name = LOG_SYSLOG; + } + + if (isset($conf['inherit'])) { + $this->_inherit = $conf['inherit']; + $this->_opened = $this->_inherit; + } + if (isset($conf['reopen'])) { + $this->_reopen = $conf['reopen']; + } + if (isset($conf['maxLength'])) { + $this->_maxLength = $conf['maxLength']; + } + if (!empty($conf['lineFormat'])) { + $this->_lineFormat = str_replace(array_keys($this->_formatMap), + array_values($this->_formatMap), + $conf['lineFormat']); + } + if (!empty($conf['timeFormat'])) { + $this->_timeFormat = $conf['timeFormat']; + } + + $this->_id = md5(microtime()); + $this->_name = $name; + $this->_ident = $ident; + $this->_mask = Log::UPTO($level); + } + + /** + * Opens a connection to the system logger, if it has not already + * been opened. This is implicitly called by log(), if necessary. + * @access public + */ + function open() + { + if (!$this->_opened || $this->_reopen) { + $this->_opened = openlog($this->_ident, LOG_PID, $this->_name); + } + + return $this->_opened; + } + + /** + * Closes the connection to the system logger, if it is open. + * @access public + */ + function close() + { + if ($this->_opened && !$this->_inherit) { + closelog(); + $this->_opened = false; + } + + return true; + } + + /** + * Sends $message to the currently open syslog connection. Calls + * open() if necessary. Also passes the message along to any Log_observer + * instances that are observing this Log. + * + * @param mixed $message String or object containing the message to log. + * @param int $priority (optional) The priority of the message. Valid + * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, + * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, + * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG. + * @return boolean True on success or false on failure. + * @access public + */ + function log($message, $priority = null) + { + /* If a priority hasn't been specified, use the default value. */ + if ($priority === null) { + $priority = $this->_priority; + } + + /* Abort early if the priority is above the maximum logging level. */ + if (!$this->_isMasked($priority)) { + return false; + } + + /* If we need to (re)open the connection and open() fails, abort. */ + if ((!$this->_opened || $this->_reopen) && !$this->open()) { + return false; + } + + /* Extract the string representation of the message. */ + $message = $this->_extractMessage($message); + + /* Build a syslog priority value based on our current configuration. */ + $priority = $this->_toSyslog($priority); + if ($this->_inherit) { + $priority |= $this->_name; + } + + /* Apply the configured line format to the message string. */ + $message = $this->_format($this->_lineFormat, + strftime($this->_timeFormat), + $priority, $message); + + /* Split the string into parts based on our maximum length setting. */ + $parts = str_split($message, $this->_maxLength); + if ($parts === false) { + return false; + } + + foreach ($parts as $part) { + if (!syslog($priority, $part)) { + return false; + } + } + + $this->_announce(array('priority' => $priority, 'message' => $message)); + + return true; + } + + /** + * Converts a PEAR_LOG_* constant into a syslog LOG_* constant. + * + * This function exists because, under Windows, not all of the LOG_* + * constants have unique values. Instead, the PEAR_LOG_* were introduced + * for global use, with the conversion to the LOG_* constants kept local to + * to the syslog driver. + * + * @param int $priority PEAR_LOG_* value to convert to LOG_* value. + * + * @return The LOG_* representation of $priority. + * + * @access private + */ + function _toSyslog($priority) + { + static $priorities = array( + PEAR_LOG_EMERG => LOG_EMERG, + PEAR_LOG_ALERT => LOG_ALERT, + PEAR_LOG_CRIT => LOG_CRIT, + PEAR_LOG_ERR => LOG_ERR, + PEAR_LOG_WARNING => LOG_WARNING, + PEAR_LOG_NOTICE => LOG_NOTICE, + PEAR_LOG_INFO => LOG_INFO, + PEAR_LOG_DEBUG => LOG_DEBUG + ); + + /* If we're passed an unknown priority, default to LOG_INFO. */ + if (!is_int($priority) || !in_array($priority, $priorities)) { + return LOG_INFO; + } + + return $priorities[$priority]; + } + +} diff --git a/includes/Log-1.12.7/Log/win.php b/includes/Log-1.12.7/Log/win.php new file mode 100644 index 000000000..f80d146d9 --- /dev/null +++ b/includes/Log-1.12.7/Log/win.php @@ -0,0 +1,286 @@ + + * @since Log 1.7.0 + * @package Log + * + * @example win.php Using the window handler. + */ +class Log_win extends Log +{ + /** + * The name of the output window. + * @var string + * @access private + */ + var $_name = 'LogWindow'; + + /** + * The title of the output window. + * @var string + * @access private + */ + var $_title = 'Log Output Window'; + + /** + * Mapping of log priorities to styles. + * @var array + * @access private + */ + var $_styles = array( + PEAR_LOG_EMERG => 'color: red;', + PEAR_LOG_ALERT => 'color: orange;', + PEAR_LOG_CRIT => 'color: yellow;', + PEAR_LOG_ERR => 'color: green;', + PEAR_LOG_WARNING => 'color: blue;', + PEAR_LOG_NOTICE => 'color: indigo;', + PEAR_LOG_INFO => 'color: violet;', + PEAR_LOG_DEBUG => 'color: black;' + ); + + /** + * String buffer that holds line that are pending output. + * @var array + * @access private + */ + var $_buffer = array(); + + /** + * Constructs a new Log_win object. + * + * @param string $name Ignored. + * @param string $ident The identity string. + * @param array $conf The configuration array. + * @param int $level Log messages up to and including this level. + * @access public + */ + function Log_win($name, $ident = '', $conf = array(), + $level = PEAR_LOG_DEBUG) + { + $this->_id = md5(microtime()); + $this->_name = str_replace(' ', '_', $name); + $this->_ident = $ident; + $this->_mask = Log::UPTO($level); + + if (isset($conf['title'])) { + $this->_title = $conf['title']; + } + if (isset($conf['styles']) && is_array($conf['styles'])) { + $this->_styles = $conf['styles']; + } + if (isset($conf['colors']) && is_array($conf['colors'])) { + foreach ($conf['colors'] as $level => $color) { + $this->_styles[$level] .= "color: $color;"; + } + } + + register_shutdown_function(array(&$this, '_Log_win')); + } + + /** + * Destructor + */ + function _Log_win() + { + if ($this->_opened || (count($this->_buffer) > 0)) { + $this->close(); + } + } + + /** + * The first time open() is called, it will open a new browser window and + * prepare it for output. + * + * This is implicitly called by log(), if necessary. + * + * @access public + */ + function open() + { + if (!$this->_opened) { + $win = $this->_name; + $styles = $this->_styles; + + if (!empty($this->_ident)) { + $identHeader = "$win.document.writeln('Ident')"; + } else { + $identHeader = ''; + } + + echo <<< EOT + +EOT; + $this->_opened = true; + } + + return $this->_opened; + } + + /** + * Closes the output stream if it is open. If there are still pending + * lines in the output buffer, the output window will be opened so that + * the buffer can be drained. + * + * @access public + */ + function close() + { + /* + * If there are still lines waiting to be written, open the output + * window so that we can drain the buffer. + */ + if (!$this->_opened && (count($this->_buffer) > 0)) { + $this->open(); + } + + if ($this->_opened) { + $this->_writeln(''); + $this->_writeln(''); + $this->_drainBuffer(); + $this->_opened = false; + } + + return ($this->_opened === false); + } + + /** + * Writes the contents of the output buffer to the output window. + * + * @access private + */ + function _drainBuffer() + { + $win = $this->_name; + foreach ($this->_buffer as $line) { + echo "\n"; + } + + /* Now that the buffer has been drained, clear it. */ + $this->_buffer = array(); + } + + /** + * Writes a single line of text to the output buffer. + * + * @param string $line The line of text to write. + * + * @access private + */ + function _writeln($line) + { + /* Add this line to our output buffer. */ + $this->_buffer[] = $line; + + /* Buffer the output until this page's headers have been sent. */ + if (!headers_sent()) { + return; + } + + /* If we haven't already opened the output window, do so now. */ + if (!$this->_opened && !$this->open()) { + return; + } + + /* Drain the buffer to the output window. */ + $this->_drainBuffer(); + } + + /** + * Logs $message to the output window. The message is also passed along + * to any Log_observer instances that are observing this Log. + * + * @param mixed $message String or object containing the message to log. + * @param string $priority The priority of the message. Valid + * values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT, + * PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING, + * PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG. + * @return boolean True on success or false on failure. + * @access public + */ + function log($message, $priority = null) + { + /* If a priority hasn't been specified, use the default value. */ + if ($priority === null) { + $priority = $this->_priority; + } + + /* Abort early if the priority is above the maximum logging level. */ + if (!$this->_isMasked($priority)) { + return false; + } + + /* Extract the string representation of the message. */ + $message = $this->_extractMessage($message); + $message = preg_replace('/\r\n|\n|\r/', '
', $message); + + list($usec, $sec) = explode(' ', microtime()); + + /* Build the output line that contains the log entry row. */ + $line = ''; + $line .= sprintf('%s.%s', + strftime('%H:%M:%S', $sec), substr($usec, 2, 2)); + if (!empty($this->_ident)) { + $line .= '' . $this->_ident . ''; + } + $line .= '' . ucfirst($this->priorityToString($priority)) . ''; + $line .= sprintf('%s', $priority, $message); + $line .= ''; + + $this->_writeln($line); + + $this->_announce(array('priority' => $priority, 'message' => $message)); + + return true; + } + +} diff --git a/module.inc b/module.inc deleted file mode 100644 index 1aea8a86c..000000000 --- a/module.inc +++ /dev/null @@ -1,523 +0,0 @@ -getConfig('galleryBaseUrl'); - $urlgenerator = $gallery->getUrlGenerator(); - $gallery_base_url = $urlgenerator->getCurrentUrlDir(); - - // Gallery specific config overrides array - - $owa_config['report_wrapper'] = 'wrapper_gallery2.tpl'; - $owa_config['images_url'] = OWA_PUBLIC_URL.'i/'; - $owa_config['images_absolute_url'] = $owa_config['images_url']; - $owa_config['main_url'] = $gallery_base_url.'main.php?g2_view=core.SiteAdmin&g2_subView=owa.owaGeneric'; - $owa_config['main_absolute_url'] = $owa_config['main_url']; - $owa_config['action_url'] = $gallery_base_url.'main.php?g2_view=owa.owaAction&owa_specialAction'; - $owa_config['log_url'] = $gallery_base_url.'main.php?g2_view=owa.owaAction&owa_logAction=1'; - $owa_config['link_template'] = '%s&%s'; - //$owa_config['authentication'] = 'gallery'; - $owa_config['site_id'] = md5($gallery_base_url); - $owa_config['query_string_filters'] = 'g2_fromNavId'; - $owa_config['is_embedded'] = 'true'; - - $gallery->debug('hello from gallery owa plugin'); - - // create owa instance - $owa = new owa_php($owa_config); - $gallery->debug('new owa instance created'); - - return $owa; - - endif; - -} - -/** - * Sets OWA priviledge info for current gallery user - */ -function owa_set_priviledges() { - - global $gallery; - - // get Gallery's active user - $u = $gallery->getActiveUser(); - - // create instance of OWA - $owa = owa_factory(); - - //set user level. Needed for OWA's auth module. - - // check to see if user is a guest or not - list ($ret, $user) = GalleryCoreApi::isAnonymousUser(); - - if ($user == true): - - $level = 'everyone'; - - else: - // check to see if the user is a site admin. important becasue we might not want - // to log such users activities. - list ($ret, $admin) = GalleryCoreApi::isUserInSiteAdminGroup(); - - if ($admin = true): - $level = 'admin'; - else: - $level = 'viewer'; - endif; - - endif; - - // preemptively set the current user info and mark as authenticated so that - // downstream controllers don't have to authenticate - $cu =&owa_coreAPI::getCurrentUser(); - - // gallery gives all users a username of guest if there are not named users... - if ($u->userName != 'guest'): - $cu->setUserData('user_id', $u->userName); - $cu->setUserData('email_address', $u->email); - $cu->setUserData('real_name', $u->fullName); - endif; - - $cu->setRole($level); - $cu->setAuthStatus(true); - - return; -} - -/** - * OWA Gallery Module - * - * Integrates OWA with Gallery 2.2 or later - * - * @package owa - * @author Peter Adams - * @version $Revision$ $Date: $ - */ -class owaModule extends GalleryModule { - - function owaModule() { - global $gallery; - - $this->setId('owa'); - $this->setName($gallery->i18n('Open Web Analytics for Gallery')); - $this->setDescription($gallery->i18n('Adds web analytics capabilities to Gallery.')); - $this->setVersion('1.0.0'); - $this->setGroup('OWA', $gallery->i18n('Open Web Analytics')); - $this->setRequiredCoreApi(array(7, 18)); - $this->setRequiredModuleApi(array(3, 4)); - $this->setCallbacks('getSiteAdminViews|getSystemLinks'); - - return; - } - - - /** - * Main OWA logging method - * - * Using getSystemLinks as a callback because it is called on every request. - */ - function getSystemLinks() { - - global $gallery; - - - if (GalleryUtilities::hasRequestVariable('view')): - $viewName = GalleryUtilities::getRequestVariables('view'); - - - // ensure this is not a Gallery admin screen - if ($viewName == "core.SiteAdmin" || $viewName == "core.ItemAdmin"): - return; - else: - - // get instance of owa - $owa = owa_factory(); - - // set user priviledges of the request for OWA to log - owa_set_priviledges(); - - // Setup OWA request params - $params = array(); - - // get information on current view - list ($ret, $view) = GalleryView::loadView($viewName); - list ($ret, $page_type) = $view->getViewDescription(); - $params['page_type'] = $page_type; - - //Log request is for an item, get item details - if (GalleryUtilities::hasRequestVariable('itemId')): - //Lookup item from view - list ($rest, $item) = $view->getItem(); - $params['page_title'] = $item->title; - else: - $params['page_title'] = $page_type; - endif; - - // is RSS page type - - if (($viewName == "rss.Render") || ($viewName == "rss.SimpleRender")): - $params['page_type'] = 'feed'; - $params['is_feedreader'] = true; - $params['feed_format'] = $_GET['feed']; - endif; - - // log request - - //print_r($owa->config); - - $owa->log($params); - endif; - endif; - - return; - - } - - - /** - * Check to see if OWA is installed and activated - * - */ - function owa_isActivated() { - - list ($ret, $params) = GalleryCoreApi::fetchAllPluginParameters('module', 'owa'); - - if (!empty($params)): - return true; - else: - return false; - endif; - } - - - /** - * @see GalleryModule::getSiteAdminViews - */ - function getSiteAdminViews() { - - global $gallery; - - // this is needed becasue on the plugins page this callback is triggered - // whether then plugin is active or not for some reason. - //if ($this->owa_isActivated()): - // get OWA instance - // $owa = owa_factory(); - // set user priviledges of the request for OWA - // owa_set_priviledges(); - //endif; - - $data = array(array('name' => $this->translate('Dashboard'), 'view' => 'owa.owaDashboard'), - array('name' => $this->translate('Admin Settings'), 'view' => 'owa.owaOptions')); - return array(null, $data); - } - - /** - * Module specific logic for install - * - * @see GalleryModule::install - */ - function upgrade($currentVersion, $statusMonitor) { - - global $gallery; - - $owa_config = array(); - $owa_config['do_not_fetch_config_from_db'] = true; - $owa = owa_factory($owa_config); - // set user priviledges of the request for OWA to log - owa_set_priviledges(); - - //get the base gallery url - $urlgenerator = $gallery->getUrlGenerator(); - $site_url = $urlgenerator->getCurrentUrlDir(); - - //Config('galleryBaseUrl'); - - $params = array('site_id' => md5($site_url), - 'name' => 'Gallery', - 'domain' => $site_url, - 'description' => '', - 'do' => 'base.installEmbedded'); - - $page = $owa->handleRequest($params); - - return null; - } - - /* - - // register event handlers - function performFactoryRegistrations() { - - owa_coreAPI::debug("g2 factory regs"); - $ret = GalleryCoreApi::registerFactoryImplementation('GalleryEventListener', 'owaLoginEventHandler ', 'owa', __FILE__, 'owa', array('Gallery::Login'), null); - - $ret = GalleryCoreApi::registerFactoryImplementation('GalleryEventListener', 'owaLoginEventHandler ', 'owa', __FILE__, 'owa', array('Gallery::Logout'), null); - - //$listener = new owaLoginEventHandler(); - //$ret = GalleryCoreApi::registerEventListener('Gallery::Login', $listener, true); - //$ret = GalleryCoreApi::registerEventListener('Gallery::Logout', $listener, true); - - if ($ret) { - return $ret; - } - - return null; - - } - -*/ -} - -/** - * OWA Gallery Views - * - * Enables OWA to be embedded as a Gallery's site admin screen - */ -class owaOptionsView extends GalleryView { - - /** - * @see GalleryView::loadTemplate - */ - function loadTemplate(&$template, &$form) { - - $owa = owa_factory(); - - owa_set_priviledges(); - - $params = array(); - - if (empty($owa->params['do'])): - $params['do'] = 'base.optionsGeneral'; - endif; - - $page = $owa->handleRequest($params); - $template->setVariable('owa', array('content' => $page)); - return array(null, array('body' => 'modules/owa/modules/base/templates/gallery.tpl')); - } - - /** - * Does this view change any data? Only controllers should change data, but AJAX and some - * immediate views are handled in views in Gallery. - * @return bool true if the view changes data - */ - function isControllerLike() { - return true; - } - - -} - -/** - * OWA Gallery Views - * - * - */ -class owaDashboardView extends GalleryView { - - /** - * @see GalleryView::loadTemplate - */ - function loadTemplate(&$template, &$form) { - - $owa = owa_factory(); - - owa_set_priviledges(); - - $params = array(); - //$params['view'] = 'base.report'; - $params['action'] = 'base.reportDashboard'; - $params['period'] = 'today'; - $page = $owa->handleRequest($params); - $template->setVariable('owa', array('content' => $page)); - return array(null, array('body' => 'modules/owa/modules/base/templates/gallery.tpl')); - } - -} - -class owaGenericView extends GalleryView { - - /** - * @see GalleryView::loadTemplate - */ - function loadTemplate(&$template, &$form) { - - $owa = owa_factory(); - - owa_set_priviledges(); - - $page = $owa->handleRequest(); - $template->setVariable('owa', array('content' => $page)); - return array(null, array('body' => 'modules/owa/modules/base/templates/gallery.tpl')); - } - - /** - * Does this view change any data? Only controllers should change data, but AJAX and some - * immediate views are handled in views in Gallery. - * @return bool true if the view changes data - */ - function isControllerLike() { - return true; - } - -} - - -GalleryCoreApi::requireOnce('modules/core/classes/GalleryController.class'); -class owaControlController extends GalleryController { - - /** - * @see GalleryController::handleRequest - */ - function handleRequest($form) { - - $result = array('delegate' => array('view' => 'owa.owaGeneric'), - 'status' => 1, 'error' => ''); - return array(null, $result); - - } - -} - - -/** - * Handles OWA's special action requests - * - */ -class owaActionView extends GalleryView { - - - /** - * @see GalleryView::isImmediate - */ - function isImmediate() { - return true; - } - - /** - * Method called when view is set to render immeadiately. - * This will bypass Gallery's global templating allowing - * the view to send output directly to the browser. - */ - function renderImmediate($status, $error) { - - global $gallery; - $owa = owa_factory(); - - $gallery->debug('hello from owaAction'); - owa_set_priviledges(); - - $owa->handleSpecialActionRequest(); - - return null; - } - - -} - -/** - * Gallery Template Callback for OWA footer elements - * - * This class is packaged here for convienence only but could also be - * put in Callbacks.inc. - */ -class owaCallbacks { - - function callback($params, &$smarty, $callback, $userId=null) { - /* 1. Identify the exact callback */ - switch ($callback) { - case 'pagetags': - - $viewName = GalleryUtilities::getRequestVariables('view'); - // ensure this is not a Gallery admin screen - - if ($viewName == "core.SiteAdmin" || $viewName == "core.ItemAdmin"): - return; - else: - /* 2. Load the requested data */ - - $owa = owa_factory(); - $tags = $owa->placeHelperPageTags(false); - - /* 3. Assign the requested data to a template variable */ - $block =& $smarty->_tpl_vars['block']; - - /* By convention, put the data into $block[$moduleId] (in this case, moduleId is 'owa') */ - $block['owa']['pagetags'] = array('owaData' => $tags, - 'randomNumber' => rand()); // You can put any data into the template variable... - endif; - - break; - - case 'SomeOtherCallbackName': - ; - break; - default: - ; - } - - return null; - } -} - -class owaLoginEventHandler { - - function owaLoginEventHandler() { - return; - } - - function __construct() { - return; - } - - function handleEvent($event) { - global $gallery; - owa_coreAPI::debug("hello from login event handler ".print_r($event)); - return array(null, null); - } - -} - -?> \ No newline at end of file diff --git a/modules/base/classes/cache.php b/modules/base/classes/cache.php index cc8b8a4e4..b15274590 100644 --- a/modules/base/classes/cache.php +++ b/modules/base/classes/cache.php @@ -50,7 +50,7 @@ class owa_cache { */ function __construct($cache_dir = '') { - $this->e = &owa_coreAPI::errorSingleton(); + $this->e = owa_coreAPI::errorSingleton(); } function set($collection, $key, $value, $expires = '') { diff --git a/modules/base/classes/client.php b/modules/base/classes/client.php index 11e1504aa..593be7393 100644 --- a/modules/base/classes/client.php +++ b/modules/base/classes/client.php @@ -332,7 +332,7 @@ function logEventFromUrl($manage_state = false) { // keeps php executing even if the client closes the connection ignore_user_abort(true); - $service = &owa_coreAPI::serviceSingleton(); + $service = owa_coreAPI::serviceSingleton(); $service->request->decodeRequestParams(); $event = owa_coreAPI::supportClassFactory('base', 'event'); $event->setEventType(owa_coreAPI::getRequestParam('event_type')); @@ -823,7 +823,7 @@ function setCampaignCookie($values) { function setCookieDomain($domain) { if (!empty($domain)) { - $c = &owa_coreAPI::configSingleton(); + $c = owa_coreAPI::configSingleton(); // sanitizes the domain $c->setCookieDomain($domain); } diff --git a/modules/base/classes/error.php b/modules/base/classes/error.php index 31b2accce..7218a4aef 100644 --- a/modules/base/classes/error.php +++ b/modules/base/classes/error.php @@ -324,9 +324,6 @@ function make_console_logger() { */ function make_file_logger() { - // fetch config object - //$c = &owa_coreAPI::configSingleton(); - // test to see if file is writable $handle = @fopen(owa_coreAPI::getSetting('base', 'error_log_file'), "a"); @@ -347,9 +344,6 @@ function make_file_logger() { */ function make_mail_logger() { - // fetch config object - $c = &owa_coreAPI::configSingleton(); - $conf = array('subject' => 'Important Error Log Events', 'from' => 'OWA-Error-Logger'); $logger = Log::singleton('mail', owa_coreAPI::getSetting('base', 'notice_email'), getmypid(), $conf); diff --git a/modules/base/classes/installController.php b/modules/base/classes/installController.php index 66c14a77e..5024c7867 100644 --- a/modules/base/classes/installController.php +++ b/modules/base/classes/installController.php @@ -60,7 +60,7 @@ function pre() { function installSchema() { - $service = &owa_coreAPI::serviceSingleton(); + $service = owa_coreAPI::serviceSingleton(); $base = $service->getModule('base'); $status = $base->install(); return $status; @@ -148,7 +148,7 @@ function createDefaultSite($domain, $name = '', $description = '', $site_family function checkDbConnection() { // Check DB connection status - $db = &owa_coreAPI::dbSingleton(); + $db = owa_coreAPI::dbSingleton(); $db->connect(); if ($db->connection_status === true) { return true; diff --git a/modules/base/classes/installManager.php b/modules/base/classes/installManager.php index ec87cbdfc..1c75996d8 100644 --- a/modules/base/classes/installManager.php +++ b/modules/base/classes/installManager.php @@ -38,7 +38,7 @@ function __construct($params = '') { function installSchema() { - $service = &owa_coreAPI::serviceSingleton(); + $service = owa_coreAPI::serviceSingleton(); $base = $service->getModule('base'); $status = $base->install(); return $status; @@ -127,7 +127,7 @@ function createDefaultSite($domain, $name = '', $description = '', $site_family function checkDbConnection() { // Check DB connection status - $db = &owa_coreAPI::dbSingleton(); + $db = owa_coreAPI::dbSingleton(); $db->connect(); if ($db->connection_status === true) { return true; diff --git a/modules/base/classes/settings.php b/modules/base/classes/settings.php index aac2841cb..c316beb19 100644 --- a/modules/base/classes/settings.php +++ b/modules/base/classes/settings.php @@ -517,7 +517,7 @@ function &get_settings($id = 1) { if (!isset($config2)): //print 'hello from alt constructor'; - $config2 = &owa_coreAPI::configSingleton(); + $config2 = owa_coreAPI::configSingleton(); endif; return $config2->fetch('base'); diff --git a/modules/base/flushCacheCli.php b/modules/base/flushCacheCli.php index a5af56a4f..afeaa381f 100644 --- a/modules/base/flushCacheCli.php +++ b/modules/base/flushCacheCli.php @@ -32,7 +32,7 @@ class owa_flushCacheCliController extends owa_cliController { function action() { - $cache = &owa_coreAPI::cacheSingleton(); + $cache = owa_coreAPI::cacheSingleton(); $cache->flush(); $this->e->notice("Cache Flushed"); diff --git a/modules/base/installCli.php b/modules/base/installCli.php index 0cbcd5e7c..a68393c98 100644 --- a/modules/base/installCli.php +++ b/modules/base/installCli.php @@ -37,7 +37,7 @@ function __construct($params) { function action() { - $service = &owa_coreAPI::serviceSingleton(); + $service = owa_coreAPI::serviceSingleton(); $im = owa_coreAPI::supportClassFactory('base', 'installManager'); $this->e->notice('Starting OWA Install from command line.'); diff --git a/modules/base/installConfig.php b/modules/base/installConfig.php index f94cb105f..0f184352d 100644 --- a/modules/base/installConfig.php +++ b/modules/base/installConfig.php @@ -115,7 +115,7 @@ function action() { owa_coreAPI::setSetting('base', 'db_password', OWA_DB_PASSWORD); // Check DB connection status - $db = &owa_coreAPI::dbSingleton(); + $db = owa_coreAPI::dbSingleton(); $db->connect(); if ($db->connection_status != true) { $this->set('error_msg', $this->getMsg(3012)); diff --git a/modules/base/installEmbedded.php b/modules/base/installEmbedded.php index 5593e50c5..3ce88bffd 100644 --- a/modules/base/installEmbedded.php +++ b/modules/base/installEmbedded.php @@ -42,7 +42,7 @@ function __construct($params) { function action() { - $service = &owa_coreAPI::serviceSingleton(); + $service = owa_coreAPI::serviceSingleton(); $this->e->notice('starting Embedded install'); diff --git a/modules/base/kmlVisitsGeolocation.php b/modules/base/kmlVisitsGeolocation.php deleted file mode 100644 index faec4eeec..000000000 --- a/modules/base/kmlVisitsGeolocation.php +++ /dev/null @@ -1,136 +0,0 @@ - - * @copyright Copyright © 2006 Peter Adams - * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 - * @category owa - * @package owa - * @version $Revision$ - * @since owa 1.0.0 - */ - -class owa_kmlVisitsGeolocationController extends owa_reportController { - - function owa_kmlVisitsGeolocationController($params) { - - return owa_kmlVisitsGeolocationController::__construct($params); - - } - - function __construct($params) { - - return parent::__construct($params); - } - - function action() { - - // Load the core API - $api = &owa_coreAPI::singleton($this->params); - - if ($this->params['site_id']): - //get site labels - $s = owa_coreAPI::entityFactory('base.site'); - $s->getByColumn('site_id', $this->getParam('site_id')); - $this->set('site_name', $s->get('name')); - $this->set('site_description', $s->get('description')); - else: - $this->set('site_name', 'All Sites'); - $this->set('site_description', 'All Sites Tracked by OWA'); - endif; - - //setup Metrics - $m = owa_coreApi::metricFactory('base.latestVisits'); - $m->setConstraint('site_id', $this->getParam('site_id')); - $m->setPeriod($this->getPeriod()); - $m->setOrder(OWA_SQL_DESCENDING); - $m->setLimit(15); - $results = $m->generate(); - - - $this->set('latest_visits', $results); - - $this->setView('base.kmlVisitsGeolocation'); - - return; - - } - -} - -/** - * Visits Geolocation KML View - * - * @author Peter Adams - * @copyright Copyright © 2006 Peter Adams - * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 - * @category owa - * @package owa - * @version $Revision$ - * @since owa 1.0.0 - */ - -class owa_kmlVisitsGeolocationView extends owa_view { - - function owa_kmlVisitsGeolocationView() { - - return owa_kmlVisitsGeolocationView::__construct(); - } - - function __construct() { - - return parent::__construct(); - } - - function render($data) { - - $this->t->set_template('wrapper_blank.tpl'); - - // load body template - $this->body->set_template('kml_visits_geolocation.tpl'); - $this->body->set('visits', $this->get('latest_visits')); - $this->body->set('site_name', $this->get('site_name')); - $this->body->set('site_domain', $this->get('site_domain')); - $this->body->set('site_description', $this->get('site_description')); - - //$this->_setLinkState(); - - $this->body->set('xml', ''); - - header('Content-type: application/vnd.google-earth.kml+xml; charset=UTF-8', true); - - header('Content-Disposition: inline; filename="owa.kml"'); - //header('Content-type: text/plain', true); - return; - } - - -} - - -?> \ No newline at end of file diff --git a/modules/base/kmlVisitsGeolocationNetworkLink.php b/modules/base/kmlVisitsGeolocationNetworkLink.php deleted file mode 100644 index d300b5f3a..000000000 --- a/modules/base/kmlVisitsGeolocationNetworkLink.php +++ /dev/null @@ -1,125 +0,0 @@ - - * @copyright Copyright © 2006 Peter Adams - * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 - * @category owa - * @package owa - * @version $Revision$ - * @since owa 1.0.0 - */ - -class owa_kmlVisitsGeolocationNetworkLinkController extends owa_reportController { - - function __construct($params) { - - $this->priviledge_level = 'viewer'; - return parent::__construct($params); - } - - function action() { - - // Load the core API - $api = &owa_coreAPI::singleton($this->params); - - $data = array(); - $data['params'] = $this->params; - - if ($this->params['site_id']): - //get site labels - $s = owa_coreAPI::entityFactory('base.site'); - $s->getByColumn('site_id', $this->params['site_id']); - $data['site_name'] = $s->get('name'); - $data['site_description'] = $s->get('description'); - $data['site_domain'] = $s->get('domain'); - else: - $data['site_name'] = 'All Sites'; - $data['site_description'] = 'Visits for all sitess tracked by OWA.'; - $data['site_domain'] = 'owa'; - endif; - - - $data['view'] = 'base.kmlVisitsGeolocationNetworkLink'; - $data['user_name'] = $this->params['u']; - $data['passkey'] = $this->params['pk']; - - return $data; - - } - -} - - - -/** - * Visits Geolocation KML View - * - * @author Peter Adams - * @copyright Copyright © 2006 Peter Adams - * @license http://www.gnu.org/copyleft/gpl.html GPL v2.0 - * @category owa - * @package owa - * @version $Revision$ - * @since owa 1.0.0 - */ - -class owa_kmlVisitsGeolocationNetworkLinkView extends owa_view { - - function __construct() { - - $this->priviledge_level = 'guest'; - - return parent::__construct(); - } - - function render($data) { - - $this->t->set_template('wrapper_blank.tpl'); - - // load body template - $this->body->set_template('kml_network_link_geolocation.tpl'); - $this->body->set('params', $data['params']); - $this->body->set('site_name', $data['site_name']); - $this->body->set('site_domain', $data['site_domain']); - $this->body->set('site_description', $data['site_description']); - $this->body->set('period_label', owa_lib::get_period_label($data['params']['period'])); - $this->body->set('date_label', owa_lib::getDateLabel($data['params']['period'])); - $this->body->set('xml', ''); - $this->body->set('user_name', $data['user_name']); - $this->body->set('passkey', $data['passkey']); - - $this->_setLinkState(); - - header('Content-type: application/vnd.google-earth.kml+xml; charset=UTF-8', true); - //header('Content-type: application/keyhole', true); - } -} - - -?> \ No newline at end of file diff --git a/modules/base/moduleDeactivate.php b/modules/base/moduleDeactivate.php index fafa2a999..2fe81662f 100644 --- a/modules/base/moduleDeactivate.php +++ b/modules/base/moduleDeactivate.php @@ -42,7 +42,7 @@ function __construct($params) { function action() { - $s = &owa_coreAPI::serviceSingleton(); + $s = owa_coreAPI::serviceSingleton(); $m = $s->getModule($this->getParam('module')); $m->deactivate(); $this->setRedirectAction('base.optionsModules'); diff --git a/modules/base/options.php b/modules/base/options.php index 1902da39d..2b1a4a15c 100644 --- a/modules/base/options.php +++ b/modules/base/options.php @@ -52,7 +52,7 @@ function render($data) { $this->body->set('headline', 'OWA Settings'); // get admin panels - $api = &owa_coreAPI::singleton(); + $api = owa_coreAPI::singleton(); $panels = $api->getAdminPanels(); //print_r($panels); $this->body->set('panels', $panels); diff --git a/modules/base/optionsFlushCache.php b/modules/base/optionsFlushCache.php index d8f48b73d..0b2cb1311 100644 --- a/modules/base/optionsFlushCache.php +++ b/modules/base/optionsFlushCache.php @@ -40,7 +40,7 @@ function __construct($params) { function action() { - $cache = &owa_coreAPI::cacheSingleton(); + $cache = owa_coreAPI::cacheSingleton(); $cache->flush(); $this->e->notice("Cache Flushed"); diff --git a/modules/base/updates/003.php b/modules/base/updates/003.php index 9e132a282..d20cd51ba 100644 --- a/modules/base/updates/003.php +++ b/modules/base/updates/003.php @@ -34,7 +34,7 @@ class owa_base_003_update extends owa_update { function up() { $db = owa_coreAPI::dbSingleton(); - $s = &owa_coreAPI::serviceSingleton(); + $s = owa_coreAPI::serviceSingleton(); $entities = $s->modules[$this->module_name]->getEntities(); diff --git a/modules/base/updatesApply.php b/modules/base/updatesApply.php index 81b80cb21..e269dfecd 100644 --- a/modules/base/updatesApply.php +++ b/modules/base/updatesApply.php @@ -35,7 +35,7 @@ class owa_updatesApplyController extends owa_controller { function action() { // fetch list of modules that require updates - $s = &owa_coreAPI::serviceSingleton(); + $s = owa_coreAPI::serviceSingleton(); $modules = $s->getModulesNeedingUpdates(); //print_r($modules); diff --git a/modules/base/updatesApplyCli.php b/modules/base/updatesApplyCli.php index 70f9b4ac9..eebefcec4 100644 --- a/modules/base/updatesApplyCli.php +++ b/modules/base/updatesApplyCli.php @@ -38,7 +38,7 @@ function __construct($params) { function action() { // fetch list of modules that require updates - $s = &owa_coreAPI::serviceSingleton(); + $s = owa_coreAPI::serviceSingleton(); if ($this->isParam('listpending')) { @@ -90,7 +90,7 @@ function action() { function listPendingUpdates() { - $s = &owa_coreAPI::serviceSingleton(); + $s = owa_coreAPI::serviceSingleton(); $modules = $s->getModulesNeedingUpdates(); if ($modules) { owa_coreAPI::notice(sprintf("Updates pending include: %s",print_r($modules, true))); diff --git a/owa_base.php b/owa_base.php index 5a15d3b6b..2d9d85d91 100644 --- a/owa_base.php +++ b/owa_base.php @@ -75,7 +75,7 @@ class owa_base { function __construct() { owa_coreAPI::profile($this, __FUNCTION__, __LINE__); $this->e = owa_coreAPI::errorSingleton(); - $this->c = &owa_coreAPI::configSingleton(); + $this->c = owa_coreAPI::configSingleton(); $this->config = $this->c->fetch('base'); } diff --git a/owa_caller.php b/owa_caller.php index 3d7011937..b9bf554da 100644 --- a/owa_caller.php +++ b/owa_caller.php @@ -127,7 +127,7 @@ function __construct($config = array()) { } /* LOAD SERVICE LAYER */ - $this->service = &owa_coreAPI::serviceSingleton(); + $this->service = owa_coreAPI::serviceSingleton(); // initialize framework $this->service->initializeFramework(); // notify handlers of 'init' action @@ -178,7 +178,7 @@ function placeHelperPageTags($echo = true, $options = array()) { // check to see if first hit tag is needed if ( isset( $options['delay_first_hit'] ) || owa_coreAPI::getSetting('base', 'delay_first_hit')) { - $service = &owa_coreAPI::serviceSingleton(); + $service = owa_coreAPI::serviceSingleton(); //check for persistant cookie $v = $service->request->getOwaCookie('v'); @@ -275,7 +275,7 @@ function getSetting($module, $name) { } function setCurrentUser($role, $login_name = '') { - $cu =&owa_coreAPI::getCurrentUser(); + $cu = owa_coreAPI::getCurrentUser(); $cu->setRole($role); $cu->setAuthStatus(true); } diff --git a/owa_env.php b/owa_env.php index 4b478f32c..fde0c6919 100644 --- a/owa_env.php +++ b/owa_env.php @@ -37,7 +37,7 @@ define('OWA_BASE_MODULE_DIR', OWA_DIR.'modules/base/'); define('OWA_BASE_CLASS_DIR', OWA_BASE_MODULE_DIR.'classes/'); define('OWA_INCLUDE_DIR', OWA_DIR.'includes/'); -define('OWA_PEARLOG_DIR', OWA_INCLUDE_DIR.'Log-1.12.2'); +define('OWA_PEARLOG_DIR', OWA_INCLUDE_DIR.'Log-1.12.7'); define('OWA_PHPMAILER_DIR', OWA_INCLUDE_DIR.'PHPMailer_5.2.0/'); define('OWA_HTTPCLIENT_DIR', OWA_INCLUDE_DIR.'httpclient-2009-09-02/'); define('OWA_PLUGINS_DIR', OWA_DIR.'plugins'); //depricated diff --git a/owa_install.php b/owa_install.php index cf7f1fef5..21b9d4215 100644 --- a/owa_install.php +++ b/owa_install.php @@ -65,12 +65,10 @@ class owa_install extends owa_base{ * @return owa_install */ - function owa_install() { + function __construct() { - $this->owa_base(); - $this->db = &owa_coreAPI::dbSingleton(); - - return; + parent::__construct(); + $this->db = owa_coreAPI::dbSingleton(); } /** diff --git a/wp_plugin.php b/wp_plugin.php index 97a67c08b..014ace844 100644 --- a/wp_plugin.php +++ b/wp_plugin.php @@ -221,7 +221,7 @@ function &owa_getInstance() { //print_r($current_user); // Set OWA's current user info and mark as authenticated so that // downstream controllers don't have to authenticate - $cu =&owa_coreAPI::getCurrentUser(); + $cu = owa_coreAPI::getCurrentUser(); if (isset($current_user->user_login)) { $cu->setUserData('user_id', $current_user->user_login);