İnce OpenID Uygulama?

0 Cevap php

5K altında ya da en azından 10K altında OpenID bir uygulama var mı?

Gerçek boyutunu almak için aşağıdaki ayarları ile http://beta.phpformatter.com/ ile kodunuzu biçimlendirmek Lütfen:

Indentation:

Indentation style: {K&R (One true brace style)}
Indent with: {Tabs}
Starting indentation: [1]
Indentation: [1]

Common:

[x] Remove all comments
[x] Remove empty lines
[x] Align assignments statements nicely
[ ] Put a comment with the condition after if, while, for, foreach, declare and catch statements

Improvement:

[x] Remove lines with just a semicolon (;)
[x] Make normal comments (//) from perl comments (#)
[x] Make long opening tag (

Brackets:

[x] Space inside brackets- ( )
[x] Space inside empty brackets- ( )
[x] Space inside block brackets- [ ]
[x] Space inside empty block brackets- [ ]

Edit:

Alix Axel's answer mükemmel, büyük değil gibi görünüyor ama orada oluyor. BTW: Bu yüzden artık küçüğüdür 6.4K, ama çok daha fazla bunu temizlemek için bunun üzerinden gidiyorum.

<?php
    class openID {
        function __construct( $url = null, $realm = null, $return = null, $redirect = true, $verify = false ) {
            $data = array( );
            if ( ( $verify !== true ) && ( self::Value( $_REQUEST, 'openid_mode' ) !== false ) ) {
                if ( strcmp( 'id_res', self::Value( $_REQUEST, 'openid_mode' ) ) === 0 ) {
                    $data[ 'openid.sig' ]          = $_REQUEST[ 'openid_sig' ];
                    $data[ 'openid.mode' ]         = 'check_authentication';
                    $data[ 'openid.signed' ]       = $_REQUEST[ 'openid_signed' ];
                    $data[ 'openid.assoc_handle' ] = $_REQUEST[ 'openid_assoc_handle' ];
                    if ( array_key_exists( 'openid_op_endpoint', $_REQUEST ) === true ) {
                        $data[ 'openid.ns' ] = 'http://specs.openid.net/auth/2.0';
                    }
                    foreach ( explode( ',', self::Value( $_REQUEST, 'openid_signed' ) ) as $value ) {
                        $data[ 'openid.' . $value ] = $_REQUEST[ 'openid_' . str_replace( '.', '_', $value ) ];
                    }
                    if ( preg_match( '~is_valid\s*:\s*true~i', self::CURL( self::__construct( $_REQUEST[ 'openid_identity' ], false, false, false, true ), $data, 'POST' ) ) > 0 ) {
                        return self::Value( $_REQUEST, 'openid_claimed_id', self::Value( $_REQUEST, 'openid_identity' ) );
                    }
                }
            } else if ( ( $result = self::CURL( $url ) ) !== false ) {
                $xml    = self::XML( $result );
                $server = strval( self::XML( $xml, '//xrd/service/uri', 0 ) );
                if ( empty( $server ) === true ) {
                    $server = strval( self::XML( $xml, '//head/link[@rel="openid.server" or @rel="openid2.provider"]/@href', 0 ) );
                }
                if ( self::URL( $server ) === true ) {
                    if ( $redirect === true ) {
                        $realm    = ( isset( $realm ) === true ) ? $realm : sprintf( '%s://%s/', $_SERVER[ "HTTPS" ] ? "https" : "http", $_SERVER[ 'HTTP_HOST' ] );
                        $return   = ( isset( $return ) === true ) ? $return : sprintf( '%s://%s', $_SERVER[ "HTTPS" ] ? "https" : "http", $_SERVER[ 'HTTP_HOST' ] . $_SERVER[ 'REQUEST_URI' ] );
                        $delegate = ( preg_match( '~http://specs[.]openid[.]net/auth/2[.]0/server~', $result ) > 0 ) ? 'http://specs.openid.net/auth/2.0/identifier_select' : $url;
                        if ( preg_match( '~rel="openid[.]delegate"|<[^>]*Delegate[^>]*>~i', $result ) > 0 ) {
                            $delegate = parent::Value( ph()->Text->Regex( $result, '<([^>]*)Delegate[^>]*>([^>]+)</\1Delegate>', 1 ), 0 );
                            if ( empty( $delegate ) === true ) {
                                $delegate = strval( self::XML( $xml, '//head/link[@rel="openid.delegate"]/@href', 0, $delegate ) );
                            }
                        }
                        if ( preg_match( '~rel="openid2[.]provider"|http://specs[.]openid[.]net/auth/2[.]0~i', $result ) > 0 ) {
                            $data[ 'openid.ns' ] = 'http://specs.openid.net/auth/2.0';
                            if ( preg_match( '~rel="openid2[.]local_id"|<(Local|Canonical)ID[^>]*>~i', $result ) > 0 ) {
                                $delegate = self::Value( self::Regex( $result, '<(Local|Canonical)ID[^>]*>([^>]+)</\1ID>', 1 ), 0 );
                                if ( empty( $delegate ) === true ) {
                                    $delegate = strval( self::XML( $xml, '//head/link[@rel="openid2.local_id"]/@href', 0, $delegate ) );
                                }
                            }
                        }
                        $data[ 'openid.mode' ]                                                                                = 'checkid_setup';
                        $data[ 'openid.return_to' ]                                                                           = $return;
                        $data[ 'openid.claimed_id' ]                                                                          = $data[ 'openid.identity' ] = $delegate;
                        $data[ 'openid.' . ( ( array_key_exists( 'openid.ns', $data ) === true ) ? 'realm' : 'trust_root' ) ] = $realm;
                        self::Redirect( sprintf( '%s%s%s', $server, ( strpos( $server, '?' ) !== false ) ? '&' : '?', http_build_query( $data, '', '&' ) ) );
                    }
                    return $server;
                }
            }
            return false;
        }
        function CURL( $url, $data = null, $method = "GET", $options = array( ) ) {
            $result = false;
            if ( ( extension_loaded( "curl" ) === true ) && ( $this->URL( $url ) === true ) ) {
                $curl = curl_init( $url );
                if ( is_resource( $curl ) === true ) {
                    curl_setopt( $curl, CURLOPT_FAILONERROR, true );
                    curl_setopt( $curl, CURLOPT_AUTOREFERER, true );
                    curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, true );
                    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
                    curl_setopt( $curl, CURLOPT_SSL_VERIFYHOST, false );
                    curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, false );
                    if ( preg_match( "~^GET$~i", $method ) > 0 ) {
                        curl_setopt( $curl, CURLOPT_HTTPGET, true );
                    } else if ( preg_match( "~^POST$~i", $method ) > 0 ) {
                        curl_setopt( $curl, CURLOPT_POST, true );
                        curl_setopt( $curl, CURLOPT_POSTFIELDS, $data );
                    }
                    $result = curl_exec( $curl );
                    if ( $result !== false ) {
                        curl_close( $curl );
                    }
                }
            }
            return $result;
        }
        function Redirect( $url, $permanent = false ) {
            if ( headers_sent() !== true ) {
                header( "Location: " . $url, true, ( $permanent === true ) ? 301 : 302 );
            }
            exit( );
        }
        function Regex( $string, $pattern, $key = null, $modifiers = null, $flag = PREG_PATTERN_ORDER, $default = false ) {
            $matches = array( );
            if ( preg_match_all( "~" . $pattern . "~" . $modifiers, $string, $matches, $flag ) > 0 ) {
                if ( isset( $key ) === true ) {
                    return ( $key === true ) ? $matches : Value( $matches, $key, $default );
                }
                return true;
            }
            return $default;
        }
        function URL( $value ) {
            return (bool) filter_var( $value, FILTER_VALIDATE_URL );
        }
        function Value( $data, $key = null, $default = false ) {
            if ( isset( $key ) === true ) {
                foreach ( (array) $key as $value ) {
                    if ( is_object( $data ) === true ) {
                        $data = get_object_vars( $data );
                    }
                    if ( array_key_exists( $value, (array) $data ) !== true ) {
                        return $default;
                    }
                    $data = $data[ $value ];
                }
            }
            return $data;
        }
        function XML( $xml, $xpath = null, $key = null, $default = false ) {
            if ( extension_loaded( "SimpleXML" ) === true ) {
                libxml_use_internal_errors( true );
                if ( ( is_string( $xml ) === true ) && ( class_exists( "DOMDocument" ) === true ) ) {
                    $dom = new DOMDocument();
                    if ( $dom->loadHTML( $xml ) === true ) {
                        return $this->XML( simplexml_import_dom( $dom ), $xpath, $key, $default );
                    }
                } else if ( is_object( $xml ) === true ) {
                    if ( isset( $xpath ) === true ) {
                        $xml = $xml->xpath( $xpath );
                        if ( isset( $key ) === true ) {
                            $xml = $this->Value( $xml, $key, $default );
                        }
                    }
                    return $xml;
                }
            }
            return false;
        }
    }
    new openID( "https://www.google.com/accounts/o8/id" );
?>

0 Cevap