class OAuthStorePDO in Lingotek Translation 7.2
Same name and namespace in other branches
- 7.7 lib/oauth-php/library/store/OAuthStorePDO.php \OAuthStorePDO
- 7.3 lib/oauth-php/library/store/OAuthStorePDO.php \OAuthStorePDO
- 7.4 lib/oauth-php/library/store/OAuthStorePDO.php \OAuthStorePDO
- 7.5 lib/oauth-php/library/store/OAuthStorePDO.php \OAuthStorePDO
- 7.6 lib/oauth-php/library/store/OAuthStorePDO.php \OAuthStorePDO
Hierarchy
- class \OAuthStoreAbstract
- class \OAuthStoreSQL
- class \OAuthStorePDO
- class \OAuthStoreSQL
Expanded class hierarchy of OAuthStorePDO
File
- lib/
oauth-php/ library/ store/ OAuthStorePDO.php, line 37
View source
class OAuthStorePDO extends OAuthStoreSQL {
private $conn;
// PDO connection
private $lastaffectedrows;
/**
* Construct the OAuthStorePDO.
* In the options you have to supply either:
* - dsn, username, password and database (for a new PDO connection)
* - 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['dsn'])) {
try {
$this->conn = new PDO($options['dsn'], $options['username'], @$options['password']);
} catch (PDOException $e) {
throw new OAuthException2('Could not connect to PDO database: ' . $e
->getMessage());
}
$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());
try {
$this->lastaffectedrows = $this->conn
->exec($sql);
if ($this->lastaffectedrows === FALSE) {
$this
->sql_errcheck($sql);
}
} catch (PDOException $e) {
$this
->sql_errcheck($sql);
}
}
/**
* 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());
$result = array();
try {
$stmt = $this->conn
->query($sql);
$result = $stmt
->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
$this
->sql_errcheck($sql);
}
return $result;
}
/**
* 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());
$result = $this
->query_all_assoc($sql);
$val = array_pop($result);
return $val;
}
/**
* 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());
try {
$all = $this->conn
->query($sql, PDO::FETCH_NUM);
$row = array();
foreach ($all as $r) {
$row = $r;
break;
}
} catch (PDOException $e) {
$this
->sql_errcheck($sql);
}
return $row;
}
/**
* 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());
$row = $this
->query_row($sql);
$val = array_pop($row);
return $val;
}
/**
* Return the number of rows affected in the last query
*/
protected function query_affected_rows() {
return $this->lastaffectedrows;
}
/**
* Return the id of the last inserted row
*
* @return int
*/
protected function query_insert_id() {
return $this->conn
->lastInsertId();
}
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)) {
$s = $this->conn
->quote($s);
// kludge. Quote already adds quotes, and this conflicts with OAuthStoreSQL.
// so remove the quotes
$len = mb_strlen($s);
if ($len == 0) {
return $s;
}
$startcut = 0;
while (isset($s[$startcut]) && $s[$startcut] == '\'') {
$startcut++;
}
$endcut = $len - 1;
while (isset($s[$endcut]) && $s[$endcut] == '\'') {
$endcut--;
}
$s = mb_substr($s, $startcut, $endcut - $startcut + 1);
return $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 $this->conn
->quote(strval($s));
}
}
}
}
}
protected function sql_errcheck($sql) {
$msg = "SQL Error in OAuthStoreMySQL: " . print_r($this->conn
->errorInfo(), true) . "\n\n" . $sql;
$backtrace = debug_backtrace();
$msg .= "\n\nAt file " . $backtrace[1]['file'] . ", line " . $backtrace[1]['line'];
throw new OAuthException2($msg);
}
/**
* Initialise the database
*/
public function install() {
// TODO: this depends on mysql extension
require_once dirname(__FILE__) . '/mysql/install.php';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
OAuthStoreAbstract:: |
public | function | * Generate a unique key * * | |
OAuthStoreAbstract:: |
protected | function | * Check to see if a string is valid utf8 * * | |
OAuthStoreAbstract:: |
protected | function | * Make a string utf8, replacing all non-utf8 chars with a '.' * * | |
OAuthStorePDO:: |
private | property | ||
OAuthStorePDO:: |
private | property | ||
OAuthStorePDO:: |
public | function |
* Initialise the database Overrides OAuthStoreAbstract:: |
|
OAuthStorePDO:: |
protected | function |
* Perform a query, ignore the results
*
* Overrides OAuthStoreSQL:: |
|
OAuthStorePDO:: |
protected | function |
* Return the number of rows affected in the last query Overrides OAuthStoreSQL:: |
|
OAuthStorePDO:: |
protected | function |
* Perform a query, ignore the results
*
* Overrides OAuthStoreSQL:: |
|
OAuthStorePDO:: |
protected | function |
* Return the id of the last inserted row
*
* Overrides OAuthStoreSQL:: |
|
OAuthStorePDO:: |
protected | function |
* Perform a query, return the first column of the first row
*
* Overrides OAuthStoreSQL:: |
|
OAuthStorePDO:: |
protected | function |
* Perform a query, return the first row
*
* Overrides OAuthStoreSQL:: |
|
OAuthStorePDO:: |
protected | function |
* Perform a query, return the first row
*
* Overrides OAuthStoreSQL:: |
|
OAuthStorePDO:: |
protected | function |
Overrides OAuthStoreSQL:: |
|
OAuthStorePDO:: |
protected | function |
Overrides OAuthStoreSQL:: |
|
OAuthStorePDO:: |
protected | function |
Overrides OAuthStoreSQL:: |
|
OAuthStorePDO:: |
function |
* Construct the OAuthStorePDO.
* In the options you have to supply either:
* - dsn, username, password and database (for a new PDO connection)
* - conn (for the connection to be used)
*
* Overrides OAuthStoreSQL:: |
||
OAuthStoreSQL:: |
protected | property | * Default ttl for request tokens | |
OAuthStoreSQL:: |
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:: |
public | function |
* Add an unautorized request token to our server.
*
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
public | function |
* Add an entry to the log table
*
* Overrides OAuthStoreAbstract:: |
1 |
OAuthStoreSQL:: |
public | function |
* Add a request token we obtained from a server.
*
* @todo remove old tokens for this user and this ocr_id
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
public | function |
* Upgrade a request token to be an authorized request token.
*
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
public | function |
* Check an nonce/timestamp combination. Clears any nonce combinations
* that are older than the one received.
*
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
public | function |
* Count the consumer access tokens for the given consumer.
*
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
public | function |
* Count how many tokens we have for the given server
*
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
public | function |
* Delete a consumer key. This removes access to our site for all applications using this key.
*
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
public | function |
* Delete a consumer access token.
*
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
public | function |
* Delete a consumer token. The token must be a request or authorized token.
*
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
public | function |
* Delete a server key. This removes access to that site.
*
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
public | function |
* Delete a token we obtained from a server.
*
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
public | function |
* Exchange an authorized request token for new access token.
*
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
public | function |
* Fetch a consumer of this server, by consumer_key.
*
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
public | function |
* Fetch the consumer access token, by access token.
*
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
public | function |
* Fetch the consumer request token, by request token.
*
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
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:: |
|
OAuthStoreSQL:: |
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:: |
|
OAuthStoreSQL:: |
public | function |
* Find stored credentials for the consumer key and token. Used by an OAuth server
* when verifying an OAuth request.
*
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
public | function |
* Get a server from the consumer registry using the consumer key
*
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
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:: |
|
OAuthStoreSQL:: |
public | function |
* Get a specific server token for the given user
*
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
public | function |
* Get the token and token secret we obtained from a server.
*
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
public | function |
* List of all registered applications. Data returned has not sensitive
* information and therefore is suitable for public displaying.
*
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
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:: |
|
OAuthStoreSQL:: |
public | function |
* Fetch a list of all consumer tokens accessing the account of the given user.
*
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
public | function |
* Get a page of entries from the log. Returns the last 100 records
* matching the options given.
*
* Overrides OAuthStoreAbstract:: |
1 |
OAuthStoreSQL:: |
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:: |
|
OAuthStoreSQL:: |
public | function |
* Get a list of all server token this user has access to.
*
* Overrides OAuthStoreAbstract:: |
|
OAuthStoreSQL:: |
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:: |
|
OAuthStoreSQL:: |
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:: |
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:: |
|
OAuthStoreSQL:: |
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:: |