You are here

static function OAuthRequestLogger::flush in Lingotek Translation 7.3

Same name and namespace in other branches
  1. 7.2 lib/oauth-php/library/OAuthRequestLogger.php \OAuthRequestLogger::flush()

* Logs the request to the database, sends any cached output. * Also called on shutdown, to make sure we always log the request being handled.

7 calls to OAuthRequestLogger::flush()
OAuthRequester::requestAccessToken in lib/oauth-php/library/OAuthRequester.php
* Request an access token from the site belonging to consumer_key. * Before this we got an request token, now we want to exchange it for * an access token. * *
OAuthRequester::requestRequestToken in lib/oauth-php/library/OAuthRequester.php
* Request a request token from the site belonging to consumer_key * *
OAuthRequestVerifier::verifyIfSigned in lib/oauth-php/library/OAuthRequestVerifier.php
* Verify the request if it seemed to be signed. * *
OAuthServer::accessToken in lib/oauth-php/library/OAuthServer.php
* Exchange a request token for an access token. * The exchange is only succesful iff the request token has been authorized. * * Never returns, calls exit() when token is exchanged or when error is returned.
OAuthServer::authorizeFinish in lib/oauth-php/library/OAuthServer.php
* Overrule this method when you want to display a nice page when * the authorization is finished. This function does not know if the authorization was * succesfull, you need to check the token in the database. * *

... See full list

File

lib/oauth-php/library/OAuthRequestLogger.php, line 96

Class

OAuthRequestLogger
Log OAuth requests

Code

static function flush() {
  if (OAuthRequestLogger::$logging) {
    OAuthRequestLogger::$logging = false;
    if (is_null(OAuthRequestLogger::$sent)) {

      // What has been sent to the user-agent?
      $data = ob_get_contents();
      if (strlen($data) > 0) {
        ob_end_flush();
      }
      elseif (ob_get_level()) {
        ob_end_clean();
      }
      $hs = headers_list();
      $sent = implode("\n", $hs) . "\n\n" . $data;
    }
    else {

      // The request we sent
      $sent = OAuthRequestLogger::$sent;
    }
    if (is_null(OAuthRequestLogger::$received)) {

      // Build the request we received
      $hs0 = self::getAllHeaders();
      $hs = array();
      foreach ($hs0 as $h => $v) {
        $hs[] = "{$h}: {$v}";
      }
      $data = '';
      $fh = @fopen('php://input', 'r');
      if ($fh) {
        while (!feof($fh)) {
          $s = fread($fh, 1024);
          if (is_string($s)) {
            $data .= $s;
          }
        }
        fclose($fh);
      }
      $received = implode("\n", $hs) . "\n\n" . $data;
    }
    else {

      // The answer we received
      $received = OAuthRequestLogger::$received;
    }

    // The request base string
    if (OAuthRequestLogger::$request_object) {
      $base_string = OAuthRequestLogger::$request_object
        ->signatureBaseString();
    }
    else {
      $base_string = '';
    }

    // Figure out to what keys we want to log this request
    $keys = array();
    if (OAuthRequestLogger::$request_object) {
      $consumer_key = OAuthRequestLogger::$request_object
        ->getParam('oauth_consumer_key', true);
      $token = OAuthRequestLogger::$request_object
        ->getParam('oauth_token', true);
      switch (get_class(OAuthRequestLogger::$request_object)) {

        // tokens are access/request tokens by a consumer
        case 'OAuthServer':
        case 'OAuthRequestVerifier':
          $keys['ocr_consumer_key'] = $consumer_key;
          $keys['oct_token'] = $token;
          break;

        // tokens are access/request tokens to a server
        case 'OAuthRequester':
        case 'OAuthRequestSigner':
          $keys['osr_consumer_key'] = $consumer_key;
          $keys['ost_token'] = $token;
          break;
      }
    }

    // Log the request
    if (OAuthRequestLogger::$store_log) {
      $store = OAuthStore::instance();
      $store
        ->addLog($keys, $received, $sent, $base_string, OAuthRequestLogger::$note, OAuthRequestLogger::$user_id);
    }
    OAuthRequestLogger::$log[] = array(
      'keys' => $keys,
      'received' => $received,
      'sent' => $sent,
      'base_string' => $base_string,
      'note' => OAuthRequestLogger::$note,
    );
  }
}