You are here

static function LingotekOAuthRequestLogger::flush in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lib/oauth-php/library/LingotekOAuthRequestLogger.php \LingotekOAuthRequestLogger::flush()
  2. 7.4 lib/oauth-php/library/LingotekOAuthRequestLogger.php \LingotekOAuthRequestLogger::flush()
  3. 7.5 lib/oauth-php/library/LingotekOAuthRequestLogger.php \LingotekOAuthRequestLogger::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 LingotekOAuthRequestLogger::flush()
LingotekOAuthRequester::requestAccessToken in lib/oauth-php/library/LingotekOAuthRequester.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. * *
LingotekOAuthRequester::requestRequestToken in lib/oauth-php/library/LingotekOAuthRequester.php
* Request a request token from the site belonging to consumer_key * *
LingotekOAuthRequestVerifier::verifyIfSigned in lib/oauth-php/library/LingotekOAuthRequestVerifier.php
* Verify the request if it seemed to be signed. * *
LingotekOAuthServer::accessToken in lib/oauth-php/library/LingotekOAuthServer.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.
LingotekOAuthServer::authorizeFinish in lib/oauth-php/library/LingotekOAuthServer.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/LingotekOAuthRequestLogger.php, line 96

Class

LingotekOAuthRequestLogger
Log OAuth requests

Code

static function flush() {
  if (LingotekOAuthRequestLogger::$logging) {
    LingotekOAuthRequestLogger::$logging = false;
    if (is_null(LingotekOAuthRequestLogger::$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 = LingotekOAuthRequestLogger::$sent;
    }
    if (is_null(LingotekOAuthRequestLogger::$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 = LingotekOAuthRequestLogger::$received;
    }

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

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

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

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

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