⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqlstore.php

📁 Joomla15 - 最新开源CMS
💻 PHP
📖 第 1 页 / 共 2 页
字号:
            return $this->resultToBool($r);        }        return true;    }    function create_assoc_table()    {        if (!$this->tableExists($this->associations_table_name)) {            $r = $this->connection->query($this->sql['assoc_table']);            return $this->resultToBool($r);        }        return true;    }    function create_settings_table()    {        if (!$this->tableExists($this->settings_table_name)) {            $r = $this->connection->query($this->sql['settings_table']);            return $this->resultToBool($r);        }        return true;    }    /**     * @access private     */    function _get_auth()    {        return $this->connection->getOne($this->sql['get_auth']);    }    /**     * @access private     */    function _create_auth($str)    {        return $this->connection->query($this->sql['create_auth'],                                        array($str));    }    function getAuthKey()    {        $value = $this->_get_auth();        if (!$value) {            $auth_key =                Auth_OpenID_CryptUtil::randomString($this->AUTH_KEY_LEN);            $auth_key_s = $this->blobEncode($auth_key);            $this->_create_auth($auth_key_s);        } else {            $auth_key_s = $value;            $auth_key = $this->blobDecode($auth_key_s);        }        $this->connection->commit();        if (strlen($auth_key) != $this->AUTH_KEY_LEN) {            $fmt = "Expected %d-byte string for auth key. Got key of length %d";            trigger_error(sprintf($fmt, $this->AUTH_KEY_LEN, strlen($auth_key)),                          E_USER_WARNING);            return null;        }        return $auth_key;    }    /**     * @access private     */    function _set_assoc($server_url, $handle, $secret, $issued,                        $lifetime, $assoc_type)    {        return $this->connection->query($this->sql['set_assoc'],                                        array(                                              $server_url,                                              $handle,                                              $secret,                                              $issued,                                              $lifetime,                                              $assoc_type));    }    function storeAssociation($server_url, $association)    {        if ($this->resultToBool($this->_set_assoc(                                            $server_url,                                            $association->handle,                                            $this->blobEncode(                                                  $association->secret),                                            $association->issued,                                            $association->lifetime,                                            $association->assoc_type                                            ))) {            $this->connection->commit();        } else {            $this->connection->rollback();        }    }    /**     * @access private     */    function _get_assoc($server_url, $handle)    {        $result = $this->connection->getRow($this->sql['get_assoc'],                                            array($server_url, $handle));        if ($this->isError($result)) {            return null;        } else {            return $result;        }    }    /**     * @access private     */    function _get_assocs($server_url)    {        $result = $this->connection->getAll($this->sql['get_assocs'],                                            array($server_url));        if ($this->isError($result)) {            return array();        } else {            return $result;        }    }    function removeAssociation($server_url, $handle)    {        if ($this->_get_assoc($server_url, $handle) == null) {            return false;        }        if ($this->resultToBool($this->connection->query(                              $this->sql['remove_assoc'],                              array($server_url, $handle)))) {            $this->connection->commit();        } else {            $this->connection->rollback();        }        return true;    }    function getAssociation($server_url, $handle = null)    {        if ($handle !== null) {            $assoc = $this->_get_assoc($server_url, $handle);            $assocs = array();            if ($assoc) {                $assocs[] = $assoc;            }        } else {            $assocs = $this->_get_assocs($server_url);        }        if (!$assocs || (count($assocs) == 0)) {            return null;        } else {            $associations = array();            foreach ($assocs as $assoc_row) {                $assoc = new Auth_OpenID_Association($assoc_row['handle'],                                                     $assoc_row['secret'],                                                     $assoc_row['issued'],                                                     $assoc_row['lifetime'],                                                     $assoc_row['assoc_type']);                $assoc->secret = $this->blobDecode($assoc->secret);                if ($assoc->getExpiresIn() == 0) {                    $this->removeAssociation($server_url, $assoc->handle);                } else {                    $associations[] = array($assoc->issued, $assoc);                }            }            if ($associations) {                $issued = array();                $assocs = array();                foreach ($associations as $key => $assoc) {                    $issued[$key] = $assoc[0];                    $assocs[$key] = $assoc[1];                }                array_multisort($issued, SORT_DESC, $assocs, SORT_DESC,                                $associations);                // return the most recently issued one.                list($issued, $assoc) = $associations[0];                return $assoc;            } else {                return null;            }        }    }    /**     * @access private     */    function _add_nonce($nonce, $expires)    {        $sql = $this->sql['add_nonce'];        $result = $this->connection->query($sql, array($nonce, $expires));        return $this->resultToBool($result);    }    /**     * @access private     */    function storeNonce($nonce)    {        if ($this->_add_nonce($nonce, time())) {            $this->connection->commit();        } else {            $this->connection->rollback();        }    }    /**     * @access private     */    function _get_nonce($nonce)    {        $result = $this->connection->getRow($this->sql['get_nonce'],                                            array($nonce));        if ($this->isError($result)) {            return null;        } else {            return $result;        }    }    /**     * @access private     */    function _remove_nonce($nonce)    {        $this->connection->query($this->sql['remove_nonce'],                                 array($nonce));    }    function useNonce($nonce)    {        $row = $this->_get_nonce($nonce);        if ($row !== null) {            $nonce = $row['nonce'];            $timestamp = $row['expires'];            $nonce_age = time() - $timestamp;            if ($nonce_age > $this->max_nonce_age) {                $present = 0;            } else {                $present = 1;            }            $this->_remove_nonce($nonce);        } else {            $present = 0;        }        $this->connection->commit();        return $present;    }    /**     * "Octifies" a binary string by returning a string with escaped     * octal bytes.  This is used for preparing binary data for     * PostgreSQL BYTEA fields.     *     * @access private     */    function _octify($str)    {        $result = "";        for ($i = 0; $i < strlen($str); $i++) {            $ch = substr($str, $i, 1);            if ($ch == "\\") {                $result .= "\\\\\\\\";            } else if (ord($ch) == 0) {                $result .= "\\\\000";            } else {                $result .= "\\" . strval(decoct(ord($ch)));            }        }        return $result;    }    /**     * "Unoctifies" octal-escaped data from PostgreSQL and returns the     * resulting ASCII (possibly binary) string.     *     * @access private     */    function _unoctify($str)    {        $result = "";        $i = 0;        while ($i < strlen($str)) {            $char = $str[$i];            if ($char == "\\") {                // Look to see if the next char is a backslash and                // append it.                if ($str[$i + 1] != "\\") {                    $octal_digits = substr($str, $i + 1, 3);                    $dec = octdec($octal_digits);                    $char = chr($dec);                    $i += 4;                } else {                    $char = "\\";                    $i += 2;                }            } else {                $i += 1;            }            $result .= $char;        }        return $result;    }}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -