From 5c7f2f17f9c471d306955df457c7cab4e5c6ed3b Mon Sep 17 00:00:00 2001 From: Snap Date: Thu, 16 Apr 2015 14:51:26 -0700 Subject: Google's OpenID Connect method $google_client_id & $google_client_secret must be added to db.inc.php! --- .../src/Google/Logger/Abstract.php | 408 +++++++++++++++++++++ .../src/Google/Logger/Exception.php | 24 ++ .../src/Google/Logger/File.php | 158 ++++++++ .../src/Google/Logger/Null.php | 43 +++ .../src/Google/Logger/Psr.php | 93 +++++ 5 files changed, 726 insertions(+) create mode 100644 includes/google-api-php-client-master/src/Google/Logger/Abstract.php create mode 100644 includes/google-api-php-client-master/src/Google/Logger/Exception.php create mode 100644 includes/google-api-php-client-master/src/Google/Logger/File.php create mode 100644 includes/google-api-php-client-master/src/Google/Logger/Null.php create mode 100644 includes/google-api-php-client-master/src/Google/Logger/Psr.php (limited to 'includes/google-api-php-client-master/src/Google/Logger') diff --git a/includes/google-api-php-client-master/src/Google/Logger/Abstract.php b/includes/google-api-php-client-master/src/Google/Logger/Abstract.php new file mode 100644 index 0000000..d759b95 --- /dev/null +++ b/includes/google-api-php-client-master/src/Google/Logger/Abstract.php @@ -0,0 +1,408 @@ + 600, + self::ALERT => 550, + self::CRITICAL => 500, + self::ERROR => 400, + self::WARNING => 300, + self::NOTICE => 250, + self::INFO => 200, + self::DEBUG => 100, + ); + + /** + * @var integer $level The minimum logging level + */ + protected $level = self::DEBUG; + + /** + * @var string $logFormat The current log format + */ + protected $logFormat = self::DEFAULT_LOG_FORMAT; + /** + * @var string $dateFormat The current date format + */ + protected $dateFormat = self::DEFAULT_DATE_FORMAT; + + /** + * @var boolean $allowNewLines If newlines are allowed + */ + protected $allowNewLines = false; + + /** + * @param Google_Client $client The current Google client + */ + public function __construct(Google_Client $client) + { + $this->setLevel( + $client->getClassConfig('Google_Logger_Abstract', 'level') + ); + + $format = $client->getClassConfig('Google_Logger_Abstract', 'log_format'); + $this->logFormat = $format ? $format : self::DEFAULT_LOG_FORMAT; + + $format = $client->getClassConfig('Google_Logger_Abstract', 'date_format'); + $this->dateFormat = $format ? $format : self::DEFAULT_DATE_FORMAT; + + $this->allowNewLines = (bool) $client->getClassConfig( + 'Google_Logger_Abstract', + 'allow_newlines' + ); + } + + /** + * Sets the minimum logging level that this logger handles. + * + * @param integer $level + */ + public function setLevel($level) + { + $this->level = $this->normalizeLevel($level); + } + + /** + * Checks if the logger should handle messages at the provided level. + * + * @param integer $level + * @return boolean + */ + public function shouldHandle($level) + { + return $this->normalizeLevel($level) >= $this->level; + } + + /** + * System is unusable. + * + * @param string $message The log message + * @param array $context The log context + */ + public function emergency($message, array $context = array()) + { + $this->log(self::EMERGENCY, $message, $context); + } + + /** + * Action must be taken immediately. + * + * Example: Entire website down, database unavailable, etc. This should + * trigger the SMS alerts and wake you up. + * + * @param string $message The log message + * @param array $context The log context + */ + public function alert($message, array $context = array()) + { + $this->log(self::ALERT, $message, $context); + } + + /** + * Critical conditions. + * + * Example: Application component unavailable, unexpected exception. + * + * @param string $message The log message + * @param array $context The log context + */ + public function critical($message, array $context = array()) + { + $this->log(self::CRITICAL, $message, $context); + } + + /** + * Runtime errors that do not require immediate action but should typically + * be logged and monitored. + * + * @param string $message The log message + * @param array $context The log context + */ + public function error($message, array $context = array()) + { + $this->log(self::ERROR, $message, $context); + } + + /** + * Exceptional occurrences that are not errors. + * + * Example: Use of deprecated APIs, poor use of an API, undesirable things + * that are not necessarily wrong. + * + * @param string $message The log message + * @param array $context The log context + */ + public function warning($message, array $context = array()) + { + $this->log(self::WARNING, $message, $context); + } + + /** + * Normal but significant events. + * + * @param string $message The log message + * @param array $context The log context + */ + public function notice($message, array $context = array()) + { + $this->log(self::NOTICE, $message, $context); + } + + /** + * Interesting events. + * + * Example: User logs in, SQL logs. + * + * @param string $message The log message + * @param array $context The log context + */ + public function info($message, array $context = array()) + { + $this->log(self::INFO, $message, $context); + } + + /** + * Detailed debug information. + * + * @param string $message The log message + * @param array $context The log context + */ + public function debug($message, array $context = array()) + { + $this->log(self::DEBUG, $message, $context); + } + + /** + * Logs with an arbitrary level. + * + * @param mixed $level The log level + * @param string $message The log message + * @param array $context The log context + */ + public function log($level, $message, array $context = array()) + { + if (!$this->shouldHandle($level)) { + return false; + } + + $levelName = is_int($level) ? array_search($level, self::$levels) : $level; + $message = $this->interpolate( + array( + 'message' => $message, + 'context' => $context, + 'level' => strtoupper($levelName), + 'datetime' => new DateTime(), + ) + ); + + $this->write($message); + } + + /** + * Interpolates log variables into the defined log format. + * + * @param array $variables The log variables. + * @return string + */ + protected function interpolate(array $variables = array()) + { + $template = $this->logFormat; + + if (!$variables['context']) { + $template = str_replace('%context%', '', $template); + unset($variables['context']); + } else { + $this->reverseJsonInContext($variables['context']); + } + + foreach ($variables as $key => $value) { + if (strpos($template, '%'. $key .'%') !== false) { + $template = str_replace( + '%' . $key . '%', + $this->export($value), + $template + ); + } + } + + return $template; + } + + /** + * Reverses JSON encoded PHP arrays and objects so that they log better. + * + * @param array $context The log context + */ + protected function reverseJsonInContext(array &$context) + { + if (!$context) { + return; + } + + foreach ($context as $key => $val) { + if (!$val || !is_string($val) || !($val[0] == '{' || $val[0] == '[')) { + continue; + } + + $json = @json_decode($val); + if (is_object($json) || is_array($json)) { + $context[$key] = $json; + } + } + } + + /** + * Exports a PHP value for logging to a string. + * + * @param mixed $value The value to + */ + protected function export($value) + { + if (is_string($value)) { + if ($this->allowNewLines) { + return $value; + } + + return preg_replace('/[\r\n]+/', ' ', $value); + } + + if (is_resource($value)) { + return sprintf( + 'resource(%d) of type (%s)', + $value, + get_resource_type($value) + ); + } + + if ($value instanceof DateTime) { + return $value->format($this->dateFormat); + } + + if (version_compare(PHP_VERSION, '5.4.0', '>=')) { + $options = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE; + + if ($this->allowNewLines) { + $options |= JSON_PRETTY_PRINT; + } + + return @json_encode($value, $options); + } + + return str_replace('\\/', '/', @json_encode($value)); + } + + /** + * Converts a given log level to the integer form. + * + * @param mixed $level The logging level + * @return integer $level The normalized level + * @throws Google_Logger_Exception If $level is invalid + */ + protected function normalizeLevel($level) + { + if (is_int($level) && array_search($level, self::$levels) !== false) { + return $level; + } + + if (is_string($level) && isset(self::$levels[$level])) { + return self::$levels[$level]; + } + + throw new Google_Logger_Exception( + sprintf("Unknown LogLevel: '%s'", $level) + ); + } + + /** + * Writes a message to the current log implementation. + * + * @param string $message The message + */ + abstract protected function write($message); +} diff --git a/includes/google-api-php-client-master/src/Google/Logger/Exception.php b/includes/google-api-php-client-master/src/Google/Logger/Exception.php new file mode 100644 index 0000000..6b0e873 --- /dev/null +++ b/includes/google-api-php-client-master/src/Google/Logger/Exception.php @@ -0,0 +1,24 @@ +getClassConfig('Google_Logger_File', 'file'); + if (!is_string($file) && !is_resource($file)) { + throw new Google_Logger_Exception( + 'File logger requires a filename or a valid file pointer' + ); + } + + $mode = $client->getClassConfig('Google_Logger_File', 'mode'); + if (!$mode) { + $this->mode = $mode; + } + + $this->lock = (bool) $client->getClassConfig('Google_Logger_File', 'lock'); + $this->file = $file; + } + + /** + * {@inheritdoc} + */ + protected function write($message) + { + if (is_string($this->file)) { + $this->open(); + } elseif (!is_resource($this->file)) { + throw new Google_Logger_Exception('File pointer is no longer available'); + } + + if ($this->lock) { + flock($this->file, LOCK_EX); + } + + fwrite($this->file, (string) $message); + + if ($this->lock) { + flock($this->file, LOCK_UN); + } + } + + /** + * Opens the log for writing. + * + * @return resource + */ + private function open() + { + // Used for trapping `fopen()` errors. + $this->trappedErrorNumber = null; + $this->trappedErrorString = null; + + $old = set_error_handler(array($this, 'trapError')); + + $needsChmod = !file_exists($this->file); + $fh = fopen($this->file, 'a'); + + restore_error_handler(); + + // Handles trapped `fopen()` errors. + if ($this->trappedErrorNumber) { + throw new Google_Logger_Exception( + sprintf( + "Logger Error: '%s'", + $this->trappedErrorString + ), + $this->trappedErrorNumber + ); + } + + if ($needsChmod) { + @chmod($this->file, $this->mode & ~umask()); + } + + return $this->file = $fh; + } + + /** + * Closes the log stream resource. + */ + private function close() + { + if (is_resource($this->file)) { + fclose($this->file); + } + } + + /** + * Traps `fopen()` errors. + * + * @param integer $errno The error number + * @param string $errstr The error string + */ + private function trapError($errno, $errstr) + { + $this->trappedErrorNumber = $errno; + $this->trappedErrorString = $errstr; + } + + public function __destruct() + { + $this->close(); + } +} diff --git a/includes/google-api-php-client-master/src/Google/Logger/Null.php b/includes/google-api-php-client-master/src/Google/Logger/Null.php new file mode 100644 index 0000000..62fa890 --- /dev/null +++ b/includes/google-api-php-client-master/src/Google/Logger/Null.php @@ -0,0 +1,43 @@ +setLogger($logger); + } + } + + /** + * Sets the PSR-3 logger where logging will be delegated. + * + * NOTE: The `$logger` should technically implement + * `Psr\Log\LoggerInterface`, but we don't explicitly require this so that + * we can be compatible with PHP 5.2. + * + * @param Psr\Log\LoggerInterface $logger The PSR-3 logger + */ + public function setLogger(/*Psr\Log\LoggerInterface*/ $logger) + { + $this->logger = $logger; + } + + /** + * {@inheritdoc} + */ + public function shouldHandle($level) + { + return isset($this->logger) && parent::shouldHandle($level); + } + + /** + * {@inheritdoc} + */ + public function log($level, $message, array $context = array()) + { + if (!$this->shouldHandle($level)) { + return false; + } + + if ($context) { + $this->reverseJsonInContext($context); + } + + $levelName = is_int($level) ? array_search($level, self::$levels) : $level; + $this->logger->log($levelName, $message, $context); + } + + /** + * {@inheritdoc} + */ + protected function write($message, array $context = array()) + { + } +} -- cgit v1.2.3