You are here

class OAuthStoreMySQLi in Lingotek Translation 7.4

Same name and namespace in other branches
  1. 7.7 lib/oauth-php/library/store/OAuthStoreMySQLi.php \OAuthStoreMySQLi
  2. 7.2 lib/oauth-php/library/store/OAuthStoreMySQLi.php \OAuthStoreMySQLi
  3. 7.3 lib/oauth-php/library/store/OAuthStoreMySQLi.php \OAuthStoreMySQLi
  4. 7.5 lib/oauth-php/library/store/OAuthStoreMySQLi.php \OAuthStoreMySQLi
  5. 7.6 lib/oauth-php/library/store/OAuthStoreMySQLi.php \OAuthStoreMySQLi

Hierarchy

Expanded class hierarchy of OAuthStoreMySQLi

File

lib/oauth-php/library/store/OAuthStoreMySQLi.php, line 41

View source
class OAuthStoreMySQLi extends OAuthStoreMySQL {
  public function install() {
    $sql = file_get_contents(dirname(__FILE__) . '/mysql/mysql.sql');
    $ps = explode('#--SPLIT--', $sql);
    foreach ($ps as $p) {
      $p = preg_replace('/^\\s*#.*$/m', '', $p);
      $this
        ->query($p);
      $this
        ->sql_errcheck($p);
    }
  }

  /**
   * Construct the OAuthStoreMySQLi.
   * In the options you have to supply either:
   * - server, username, password and database (for a mysqli_connect)
   * - conn (for the connection to be used)
   *
   * @param array options
   */
  function __construct($options = array()) {
    if (isset($options['conn'])) {
      $this->conn = $options['conn'];
    }
    else {
      if (isset($options['server'])) {
        $server = $options['server'];
        $username = $options['username'];
        if (isset($options['password'])) {
          $this->conn = $GLOBALS["___mysqli_ston"] = mysqli_connect($server, $username, $options['password']);
        }
        else {
          $this->conn = $GLOBALS["___mysqli_ston"] = mysqli_connect($server, $username);
        }
      }
      else {

        // Try the default mysql connect
        $this->conn = $GLOBALS["___mysqli_ston"] = mysqli_connect();
      }
      if ($this->conn === false) {
        throw new OAuthException2('Could not connect to MySQL database: ' . (is_object($GLOBALS["___mysqli_ston"]) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
      }
      if (isset($options['database'])) {

        /* TODO: security. mysqli_ doesn't seem to have an escape identifier function.
        			$escapeddb = mysqli_real_escape_string($options['database']);
        			if (!((bool)mysqli_query( $this->conn, "USE `$escapeddb`" )))
        			{
        				$this->sql_errcheck();
        			}*/
      }
      $this
        ->query('set character set utf8');
    }
  }

  /**
   * Perform a query, ignore the results
   *
   * @param string sql
   * @param vararg arguments (for sprintf)
   */
  protected function query($sql) {
    $sql = $this
      ->sql_printf(func_get_args());
    if (!($res = mysqli_query($this->conn, $sql))) {
      $this
        ->sql_errcheck($sql);
    }
    if (!is_bool($res)) {
      mysqli_free_result($res) || is_object($res) && get_class($res) == "mysqli_result" ? true : false;
    }
  }

  /**
   * Perform a query, ignore the results
   *
   * @param string sql
   * @param vararg arguments (for sprintf)
   * @return array
   */
  protected function query_all_assoc($sql) {
    $sql = $this
      ->sql_printf(func_get_args());
    if (!($res = mysqli_query($this->conn, $sql))) {
      $this
        ->sql_errcheck($sql);
    }
    $rs = array();
    while ($row = mysqli_fetch_assoc($res)) {
      $rs[] = $row;
    }
    mysqli_free_result($res) || is_object($res) && get_class($res) == "mysqli_result" ? true : false;
    return $rs;
  }

  /**
   * Perform a query, return the first row
   *
   * @param string sql
   * @param vararg arguments (for sprintf)
   * @return array
   */
  protected function query_row_assoc($sql) {
    $sql = $this
      ->sql_printf(func_get_args());
    if (!($res = mysqli_query($this->conn, $sql))) {
      $this
        ->sql_errcheck($sql);
    }
    if ($row = mysqli_fetch_assoc($res)) {
      $rs = $row;
    }
    else {
      $rs = false;
    }
    mysqli_free_result($res) || is_object($res) && get_class($res) == "mysqli_result" ? true : false;
    return $rs;
  }

  /**
   * Perform a query, return the first row
   *
   * @param string sql
   * @param vararg arguments (for sprintf)
   * @return array
   */
  protected function query_row($sql) {
    $sql = $this
      ->sql_printf(func_get_args());
    if (!($res = mysqli_query($this->conn, $sql))) {
      $this
        ->sql_errcheck($sql);
    }
    if ($row = mysqli_fetch_array($res)) {
      $rs = $row;
    }
    else {
      $rs = false;
    }
    mysqli_free_result($res) || is_object($res) && get_class($res) == "mysqli_result" ? true : false;
    return $rs;
  }

  /**
   * Perform a query, return the first column of the first row
   *
   * @param string sql
   * @param vararg arguments (for sprintf)
   * @return mixed
   */
  protected function query_one($sql) {
    $sql = $this
      ->sql_printf(func_get_args());
    if (!($res = mysqli_query($this->conn, $sql))) {
      $this
        ->sql_errcheck($sql);
    }
    if ($row = mysqli_fetch_assoc($res)) {
      $val = array_pop($row);
    }
    else {
      $val = false;
    }
    mysqli_free_result($res) || is_object($res) && get_class($res) == "mysqli_result" ? true : false;
    return $val;
  }

  /**
   * Return the number of rows affected in the last query
   */
  protected function query_affected_rows() {
    return mysqli_affected_rows($this->conn);
  }

  /**
   * Return the id of the last inserted row
   *
   * @return int
   */
  protected function query_insert_id() {
    return is_null($___mysqli_res = mysqli_insert_id($this->conn)) ? false : $___mysqli_res;
  }
  protected function sql_printf($args) {
    $sql = array_shift($args);
    if (count($args) == 1 && is_array($args[0])) {
      $args = $args[0];
    }
    $args = array_map(array(
      $this,
      'sql_escape_string',
    ), $args);
    return vsprintf($sql, $args);
  }
  protected function sql_escape_string($s) {
    if (is_string($s)) {
      return mysqli_real_escape_string($this->conn, $s);
    }
    else {
      if (is_null($s)) {
        return NULL;
      }
      else {
        if (is_bool($s)) {
          return intval($s);
        }
        else {
          if (is_int($s) || is_float($s)) {
            return $s;
          }
          else {
            return mysqli_real_escape_string($this->conn, strval($s));
          }
        }
      }
    }
  }
  protected function sql_errcheck($sql) {
    if (is_object($this->conn) ? mysqli_errno($this->conn) : (($___mysqli_res = mysqli_connect_errno()) ? $___mysqli_res : false)) {
      $msg = "SQL Error in OAuthStoreMySQL: " . (is_object($this->conn) ? mysqli_error($this->conn) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) . "\n\n" . $sql;
      throw new OAuthException2($msg);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OAuthStoreAbstract::generateKey public function * Generate a unique key * *
OAuthStoreAbstract::isUTF8 protected function * Check to see if a string is valid utf8 * *
OAuthStoreAbstract::makeUTF8 protected function * Make a string utf8, replacing all non-utf8 chars with a '.' * *
OAuthStoreMySQL::$conn protected property * The MySQL connection
OAuthStoreMySQLi::install public function * Initialise the database Overrides OAuthStoreMySQL::install
OAuthStoreMySQLi::query protected function * Perform a query, ignore the results * * Overrides OAuthStoreMySQL::query
OAuthStoreMySQLi::query_affected_rows protected function * Return the number of rows affected in the last query Overrides OAuthStoreMySQL::query_affected_rows
OAuthStoreMySQLi::query_all_assoc protected function * Perform a query, ignore the results * * Overrides OAuthStoreMySQL::query_all_assoc
OAuthStoreMySQLi::query_insert_id protected function * Return the id of the last inserted row * * Overrides OAuthStoreMySQL::query_insert_id
OAuthStoreMySQLi::query_one protected function * Perform a query, return the first column of the first row * * Overrides OAuthStoreMySQL::query_one
OAuthStoreMySQLi::query_row protected function * Perform a query, return the first row * * Overrides OAuthStoreMySQL::query_row
OAuthStoreMySQLi::query_row_assoc protected function * Perform a query, return the first row * * Overrides OAuthStoreMySQL::query_row_assoc
OAuthStoreMySQLi::sql_errcheck protected function Overrides OAuthStoreMySQL::sql_errcheck
OAuthStoreMySQLi::sql_escape_string protected function Overrides OAuthStoreMySQL::sql_escape_string
OAuthStoreMySQLi::sql_printf protected function Overrides OAuthStoreMySQL::sql_printf
OAuthStoreMySQLi::__construct function * Construct the OAuthStoreMySQLi. * In the options you have to supply either: * - server, username, password and database (for a mysqli_connect) * - conn (for the connection to be used) * * Overrides OAuthStoreSQL::__construct
OAuthStoreSQL::$max_request_token_ttl protected property * Default ttl for request tokens
OAuthStoreSQL::$max_timestamp_skew protected property * Maximum delta a timestamp may be off from a previous timestamp. * Allows multiple consumers with some clock skew to work with the same token. * Unit is seconds, default max skew is 10 minutes.
OAuthStoreSQL::addConsumerRequestToken public function * Add an unautorized request token to our server. * * Overrides OAuthStoreAbstract::addConsumerRequestToken
OAuthStoreSQL::addLog public function * Add an entry to the log table * * Overrides OAuthStoreAbstract::addLog 1
OAuthStoreSQL::addServerToken public function * Add a request token we obtained from a server. * * @todo remove old tokens for this user and this ocr_id * Overrides OAuthStoreAbstract::addServerToken
OAuthStoreSQL::authorizeConsumerRequestToken public function * Upgrade a request token to be an authorized request token. * * Overrides OAuthStoreAbstract::authorizeConsumerRequestToken
OAuthStoreSQL::checkServerNonce public function * Check an nonce/timestamp combination. Clears any nonce combinations * that are older than the one received. * * Overrides OAuthStoreAbstract::checkServerNonce
OAuthStoreSQL::countConsumerAccessTokens public function * Count the consumer access tokens for the given consumer. * * Overrides OAuthStoreAbstract::countConsumerAccessTokens
OAuthStoreSQL::countServerTokens public function * Count how many tokens we have for the given server * * Overrides OAuthStoreAbstract::countServerTokens
OAuthStoreSQL::deleteConsumer public function * Delete a consumer key. This removes access to our site for all applications using this key. * * Overrides OAuthStoreAbstract::deleteConsumer
OAuthStoreSQL::deleteConsumerAccessToken public function * Delete a consumer access token. * * Overrides OAuthStoreAbstract::deleteConsumerAccessToken
OAuthStoreSQL::deleteConsumerRequestToken public function * Delete a consumer token. The token must be a request or authorized token. * * Overrides OAuthStoreAbstract::deleteConsumerRequestToken
OAuthStoreSQL::deleteServer public function * Delete a server key. This removes access to that site. * * Overrides OAuthStoreAbstract::deleteServer
OAuthStoreSQL::deleteServerToken public function * Delete a token we obtained from a server. * * Overrides OAuthStoreAbstract::deleteServerToken
OAuthStoreSQL::exchangeConsumerRequestForAccessToken public function * Exchange an authorized request token for new access token. * * Overrides OAuthStoreAbstract::exchangeConsumerRequestForAccessToken
OAuthStoreSQL::getConsumer public function * Fetch a consumer of this server, by consumer_key. * * Overrides OAuthStoreAbstract::getConsumer
OAuthStoreSQL::getConsumerAccessToken public function * Fetch the consumer access token, by access token. * * Overrides OAuthStoreAbstract::getConsumerAccessToken
OAuthStoreSQL::getConsumerRequestToken public function * Fetch the consumer request token, by request token. * * Overrides OAuthStoreAbstract::getConsumerRequestToken
OAuthStoreSQL::getConsumerStatic public function * Fetch the static consumer key for this provider. The user for the static consumer * key is NULL (no user, shared key). If the key did not exist then the key is created. * * Overrides OAuthStoreAbstract::getConsumerStatic
OAuthStoreSQL::getSecretsForSignature public function * Find the server details for signing a request, always looks for an access token. * The returned credentials depend on which local user is making the request. * * The consumer_key must belong to the user or be public (user id is null) * *… Overrides OAuthStoreAbstract::getSecretsForSignature
OAuthStoreSQL::getSecretsForVerify public function * Find stored credentials for the consumer key and token. Used by an OAuth server * when verifying an OAuth request. * * Overrides OAuthStoreAbstract::getSecretsForVerify
OAuthStoreSQL::getServer public function * Get a server from the consumer registry using the consumer key * * Overrides OAuthStoreAbstract::getServer
OAuthStoreSQL::getServerForUri public function * Find the server details that might be used for a request * * The consumer_key must belong to the user or be public (user id is null) * * Overrides OAuthStoreAbstract::getServerForUri
OAuthStoreSQL::getServerToken public function * Get a specific server token for the given user * * Overrides OAuthStoreAbstract::getServerToken
OAuthStoreSQL::getServerTokenSecrets public function * Get the token and token secret we obtained from a server. * * Overrides OAuthStoreAbstract::getServerTokenSecrets
OAuthStoreSQL::listConsumerApplications public function * List of all registered applications. Data returned has not sensitive * information and therefore is suitable for public displaying. * * Overrides OAuthStoreAbstract::listConsumerApplications
OAuthStoreSQL::listConsumers public function * Fetch a list of all consumer keys, secrets etc. * Returns the public (user_id is null) and the keys owned by the user * * Overrides OAuthStoreAbstract::listConsumers
OAuthStoreSQL::listConsumerTokens public function * Fetch a list of all consumer tokens accessing the account of the given user. * * Overrides OAuthStoreAbstract::listConsumerTokens
OAuthStoreSQL::listLog public function * Get a page of entries from the log. Returns the last 100 records * matching the options given. * * Overrides OAuthStoreAbstract::listLog 1
OAuthStoreSQL::listServers public function * Get a list of all consumers from the consumer registry. * The consumer keys belong to the user or are public (user id is null) * * Overrides OAuthStoreAbstract::listServers
OAuthStoreSQL::listServerTokens public function * Get a list of all server token this user has access to. * * Overrides OAuthStoreAbstract::listServerTokens
OAuthStoreSQL::setConsumerAccessTokenTtl public function * Set the ttl of a consumer access token. This is done when the * server receives a valid request with a xoauth_token_ttl parameter in it. * * Overrides OAuthStoreAbstract::setConsumerAccessTokenTtl
OAuthStoreSQL::setServerTokenTtl public function * Set the ttl of a server access token. This is done when the * server receives a valid request with a xoauth_token_ttl parameter in it. * *
OAuthStoreSQL::updateConsumer public function * Insert/update a new consumer with this server (we will be the server) * When this is a new consumer, then also generate the consumer key and secret. * Never updates the consumer key and secret. * When the id is set, then the key and secret… Overrides OAuthStoreAbstract::updateConsumer
OAuthStoreSQL::updateServer public function * Register or update a server for our site (we will be the consumer) * * (This is the registry at the consumers, registering servers ;-) ) * * Overrides OAuthStoreAbstract::updateServer