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

📄 filestore.php

📁 简介:IceBB是一个强大
💻 PHP
📖 第 1 页 / 共 2 页
字号:
        if (!$assoc_s) {            return null;        }        $association =            Auth_OpenID_Association::deserialize('Auth_OpenID_Association',                                                $assoc_s);        if (!$association) {            Auth_OpenID_FileStore::_removeIfPresent($filename);            return null;        }        if ($association->getExpiresIn() == 0) {            Auth_OpenID_FileStore::_removeIfPresent($filename);            return null;        } else {            return $association;        }    }    /**     * Remove an association if it exists. Do nothing if it does not.     *     * @return bool $success     */    function removeAssociation($server_url, $handle)    {        if (!$this->active) {            trigger_error("FileStore no longer active", E_USER_ERROR);            return null;        }        $assoc = $this->getAssociation($server_url, $handle);        if ($assoc === null) {            return false;        } else {            $filename = $this->getAssociationFilename($server_url, $handle);            return Auth_OpenID_FileStore::_removeIfPresent($filename);        }    }    /**     * Return whether this nonce is present. As a side effect, mark it     * as no longer present.     *     * @return bool $present     */    function useNonce($server_url, $timestamp, $salt)    {        global $Auth_OpenID_SKEW;        if (!$this->active) {            trigger_error("FileStore no longer active", E_USER_ERROR);            return null;        }        if ( abs($timestamp - mktime()) > $Auth_OpenID_SKEW ) {            return False;        }        if ($server_url) {            list($proto, $rest) = explode('://', $server_url, 2);        } else {            $proto = '';            $rest = '';        }        $parts = explode('/', $rest, 2);        $domain = $this->_filenameEscape($parts[0]);        $url_hash = $this->_safe64($server_url);        $salt_hash = $this->_safe64($salt);        $filename = sprintf('%08x-%s-%s-%s-%s', $timestamp, $proto,                            $domain, $url_hash, $salt_hash);        $filename = $this->nonce_dir . DIRECTORY_SEPARATOR . $filename;        $result = @fopen($filename, 'x');        if ($result === false) {            return false;        } else {            fclose($result);            return true;        }    }    /**     * Remove expired entries from the database. This is potentially     * expensive, so only run when it is acceptable to take time.     *     * @access private     */    function _allAssocs()    {        $all_associations = array();        $association_filenames =            Auth_OpenID_FileStore::_listdir($this->association_dir);        foreach ($association_filenames as $association_filename) {            $association_file = fopen($association_filename, 'rb');            if ($association_file !== false) {                $assoc_s = fread($association_file,                                 filesize($association_filename));                fclose($association_file);                // Remove expired or corrupted associations                $association =                  Auth_OpenID_Association::deserialize(                         'Auth_OpenID_Association', $assoc_s);                if ($association === null) {                    Auth_OpenID_FileStore::_removeIfPresent(                                                 $association_filename);                } else {                    if ($association->getExpiresIn() == 0) {                        $all_associations[] = array($association_filename,                                                    $association);                    }                }            }        }        return $all_associations;    }    function clean()    {        if (!$this->active) {            trigger_error("FileStore no longer active", E_USER_ERROR);            return null;        }        $nonces = Auth_OpenID_FileStore::_listdir($this->nonce_dir);        $now = time();        // Check all nonces for expiry        foreach ($nonces as $nonce) {            if (!Auth_OpenID_checkTimestamp($nonce, $now)) {                $filename = $this->nonce_dir . DIRECTORY_SEPARATOR . $nonce;                Auth_OpenID_FileStore::_removeIfPresent($filename);            }        }        foreach ($this->_allAssocs() as $pair) {            list($assoc_filename, $assoc) = $pair;            if ($assoc->getExpiresIn() == 0) {                Auth_OpenID_FileStore::_removeIfPresent($assoc_filename);            }        }    }    /**     * @access private     */    function _rmtree($dir)    {        if ($dir[strlen($dir) - 1] != DIRECTORY_SEPARATOR) {            $dir .= DIRECTORY_SEPARATOR;        }        if ($handle = opendir($dir)) {            while ($item = readdir($handle)) {                if (!in_array($item, array('.', '..'))) {                    if (is_dir($dir . $item)) {                        if (!Auth_OpenID_FileStore::_rmtree($dir . $item)) {                            return false;                        }                    } else if (is_file($dir . $item)) {                        if (!unlink($dir . $item)) {                            return false;                        }                    }                }            }            closedir($handle);            if (!@rmdir($dir)) {                return false;            }            return true;        } else {            // Couldn't open directory.            return false;        }    }    /**     * @access private     */    function _mkstemp($dir)    {        foreach (range(0, 4) as $i) {            $name = tempnam($dir, "php_openid_filestore_");            if ($name !== false) {                return $name;            }        }        return false;    }    /**     * @access private     */    function _mkdtemp($dir)    {        foreach (range(0, 4) as $i) {            $name = $dir . strval(DIRECTORY_SEPARATOR) . strval(getmypid()) .                "-" . strval(rand(1, time()));            if (!mkdir($name, 0700)) {                return false;            } else {                return $name;            }        }        return false;    }    /**     * @access private     */    function _listdir($dir)    {        $handle = opendir($dir);        $files = array();        while (false !== ($filename = readdir($handle))) {            if (!in_array($filename, array('.', '..'))) {                $files[] = $dir . DIRECTORY_SEPARATOR . $filename;            }        }        return $files;    }    /**     * @access private     */    function _isFilenameSafe($char)    {        $_Auth_OpenID_filename_allowed = Auth_OpenID_letters .            Auth_OpenID_digits . ".";        return (strpos($_Auth_OpenID_filename_allowed, $char) !== false);    }    /**     * @access private     */    function _safe64($str)    {        $h64 = base64_encode(Auth_OpenID_SHA1($str));        $h64 = str_replace('+', '_', $h64);        $h64 = str_replace('/', '.', $h64);        $h64 = str_replace('=', '', $h64);        return $h64;    }    /**     * @access private     */    function _filenameEscape($str)    {        $filename = "";        $b = Auth_OpenID::toBytes($str);        for ($i = 0; $i < count($b); $i++) {            $c = $b[$i];            if (Auth_OpenID_FileStore::_isFilenameSafe($c)) {                $filename .= $c;            } else {                $filename .= sprintf("_%02X", ord($c));            }        }        return $filename;    }    /**     * Attempt to remove a file, returning whether the file existed at     * the time of the call.     *     * @access private     * @return bool $result True if the file was present, false if not.     */    function _removeIfPresent($filename)    {        return @unlink($filename);    }    function cleanupAssociations()    {        $removed = 0;        foreach ($this->_allAssocs() as $pair) {            list($assoc_filename, $assoc) = $pair;            if ($assoc->getExpiresIn() == 0) {                $this->_removeIfPresent($assoc_filename);                $removed += 1;            }        }        return $removed;    }}?>

⌨️ 快捷键说明

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