diff options
Diffstat (limited to 'library')
-rw-r--r-- | library/OAuth1.php | 118 | ||||
-rw-r--r-- | library/cacert.pem | 30 | ||||
-rw-r--r-- | library/certs/cacert.pem | 30 | ||||
-rw-r--r-- | library/ical.php | 379 | ||||
-rw-r--r-- | library/twitteroauth.php | 24 |
5 files changed, 130 insertions, 451 deletions
diff --git a/library/OAuth1.php b/library/OAuth1.php index b790655af..0a6b20b0a 100644 --- a/library/OAuth1.php +++ b/library/OAuth1.php @@ -3,11 +3,11 @@ /* Generic exception class */ -class OAuthException extends Exception { +class OAuth1Exception extends Exception { // pass } -class OAuthConsumer { +class OAuth1Consumer { public $key; public $secret; @@ -18,11 +18,11 @@ class OAuthConsumer { } function __toString() { - return "OAuthConsumer[key=$this->key,secret=$this->secret]"; + return "OAuth1Consumer[key=$this->key,secret=$this->secret]"; } } -class OAuthToken { +class OAuth1Token { // access tokens and request tokens public $key; public $secret; @@ -46,9 +46,9 @@ class OAuthToken { */ function to_string() { return "oauth_token=" . - OAuthUtil::urlencode_rfc3986($this->key) . + OAuth1Util::urlencode_rfc3986($this->key) . "&oauth_token_secret=" . - OAuthUtil::urlencode_rfc3986($this->secret); + OAuth1Util::urlencode_rfc3986($this->secret); } function __toString() { @@ -60,7 +60,7 @@ class OAuthToken { * A class for implementing a Signature Method * See section 9 ("Signing Requests") in the spec */ -abstract class OAuthSignatureMethod { +abstract class OAuth1SignatureMethod { /** * Needs to return the name of the Signature Method (ie HMAC-SHA1) * @return string @@ -70,20 +70,20 @@ abstract class OAuthSignatureMethod { /** * Build up the signature * NOTE: The output of this function MUST NOT be urlencoded. - * the encoding is handled in OAuthRequest when the final + * the encoding is handled in OAuth1Request when the final * request is serialized - * @param OAuthRequest $request - * @param OAuthConsumer $consumer - * @param OAuthToken $token + * @param OAuth1Request $request + * @param OAuth1Consumer $consumer + * @param OAuth1Token $token * @return string */ abstract public function build_signature($request, $consumer, $token); /** * Verifies that a given signature is correct - * @param OAuthRequest $request - * @param OAuthConsumer $consumer - * @param OAuthToken $token + * @param OAuth1Request $request + * @param OAuth1Consumer $consumer + * @param OAuth1Token $token * @param string $signature * @return bool */ @@ -101,7 +101,7 @@ abstract class OAuthSignatureMethod { * character (ASCII code 38) even if empty. * - Chapter 9.2 ("HMAC-SHA1") */ -class OAuthSignatureMethod_HMAC_SHA1 extends OAuthSignatureMethod { +class OAuth1SignatureMethod_HMAC_SHA1 extends OAuth1SignatureMethod { function get_name() { return "HMAC-SHA1"; } @@ -115,7 +115,7 @@ class OAuthSignatureMethod_HMAC_SHA1 extends OAuthSignatureMethod { ($token) ? $token->secret : "" ); - $key_parts = OAuthUtil::urlencode_rfc3986($key_parts); + $key_parts = OAuth1Util::urlencode_rfc3986($key_parts); $key = implode('&', $key_parts); @@ -129,7 +129,7 @@ class OAuthSignatureMethod_HMAC_SHA1 extends OAuthSignatureMethod { * over a secure channel such as HTTPS. It does not use the Signature Base String. * - Chapter 9.4 ("PLAINTEXT") */ -class OAuthSignatureMethod_PLAINTEXT extends OAuthSignatureMethod { +class OAuth1SignatureMethod_PLAINTEXT extends OAuth1SignatureMethod { public function get_name() { return "PLAINTEXT"; } @@ -141,7 +141,7 @@ class OAuthSignatureMethod_PLAINTEXT extends OAuthSignatureMethod { * - Chapter 9.4.1 ("Generating Signatures") * * Please note that the second encoding MUST NOT happen in the SignatureMethod, as - * OAuthRequest handles this! + * OAuth1Request handles this! */ public function build_signature($request, $consumer, $token) { $key_parts = array( @@ -149,7 +149,7 @@ class OAuthSignatureMethod_PLAINTEXT extends OAuthSignatureMethod { ($token) ? $token->secret : "" ); - $key_parts = OAuthUtil::urlencode_rfc3986($key_parts); + $key_parts = OAuth1Util::urlencode_rfc3986($key_parts); $key = implode('&', $key_parts); $request->base_string = $key; @@ -165,7 +165,7 @@ class OAuthSignatureMethod_PLAINTEXT extends OAuthSignatureMethod { * specification. * - Chapter 9.3 ("RSA-SHA1") */ -abstract class OAuthSignatureMethod_RSA_SHA1 extends OAuthSignatureMethod { +abstract class OAuth1SignatureMethod_RSA_SHA1 extends OAuth1SignatureMethod { public function get_name() { return "RSA-SHA1"; } @@ -224,7 +224,7 @@ abstract class OAuthSignatureMethod_RSA_SHA1 extends OAuthSignatureMethod { } } -class OAuthRequest { +class OAuth1Request { private $parameters; private $http_method; private $http_url; @@ -235,7 +235,7 @@ class OAuthRequest { function __construct($http_method, $http_url, $parameters=NULL) { @$parameters or $parameters = array(); - $parameters = array_merge( OAuthUtil::parse_parameters(parse_url($http_url, PHP_URL_QUERY)), $parameters); + $parameters = array_merge( OAuth1Util::parse_parameters(parse_url($http_url, PHP_URL_QUERY)), $parameters); $this->parameters = $parameters; $this->http_method = $http_method; $this->http_url = $http_url; @@ -262,10 +262,10 @@ class OAuthRequest { // parsed parameter-list if (!$parameters) { // Find request headers - $request_headers = OAuthUtil::get_headers(); + $request_headers = OAuth1Util::get_headers(); // Parse the query-string to find GET parameters - $parameters = OAuthUtil::parse_parameters($_SERVER['QUERY_STRING']); + $parameters = OAuth1Util::parse_parameters($_SERVER['QUERY_STRING']); // It's a POST request of the proper content-type, so parse POST // parameters and add those overriding any duplicates from GET @@ -274,7 +274,7 @@ class OAuthRequest { "application/x-www-form-urlencoded") ) { - $post_data = OAuthUtil::parse_parameters( + $post_data = OAuth1Util::parse_parameters( file_get_contents(self::$POST_INPUT) ); $parameters = array_merge($parameters, $post_data); @@ -283,7 +283,7 @@ class OAuthRequest { // We have a Authorization-header with OAuth data. Parse the header // and add those overriding any duplicates from GET or POST if (@substr($request_headers['Authorization'], 0, 6) == "OAuth ") { - $header_parameters = OAuthUtil::split_header( + $header_parameters = OAuth1Util::split_header( $request_headers['Authorization'] ); $parameters = array_merge($parameters, $header_parameters); @@ -296,7 +296,7 @@ class OAuthRequest { $http_url = substr($http_url, 0, strpos($http_url,$parameters['q'])+strlen($parameters['q'])); unset( $parameters['q'] ); - return new OAuthRequest($http_method, $http_url, $parameters); + return new OAuth1Request($http_method, $http_url, $parameters); } /** @@ -304,16 +304,16 @@ class OAuthRequest { */ public static function from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters=NULL) { @$parameters or $parameters = array(); - $defaults = array("oauth_version" => OAuthRequest::$version, - "oauth_nonce" => OAuthRequest::generate_nonce(), - "oauth_timestamp" => OAuthRequest::generate_timestamp(), + $defaults = array("oauth_version" => OAuth1Request::$version, + "oauth_nonce" => OAuth1Request::generate_nonce(), + "oauth_timestamp" => OAuth1Request::generate_timestamp(), "oauth_consumer_key" => $consumer->key); if ($token) $defaults['oauth_token'] = $token->key; $parameters = array_merge($defaults, $parameters); - return new OAuthRequest($http_method, $http_url, $parameters); + return new OAuth1Request($http_method, $http_url, $parameters); } public function set_parameter($name, $value, $allow_duplicates = true) { @@ -357,7 +357,7 @@ class OAuthRequest { unset($params['oauth_signature']); } - return OAuthUtil::build_http_query($params); + return OAuth1Util::build_http_query($params); } /** @@ -374,7 +374,7 @@ class OAuthRequest { $this->get_signable_parameters() ); - $parts = OAuthUtil::urlencode_rfc3986($parts); + $parts = OAuth1Util::urlencode_rfc3986($parts); return implode('&', $parts); } @@ -423,7 +423,7 @@ class OAuthRequest { * builds the data one would send in a POST request */ public function to_postdata() { - return OAuthUtil::build_http_query($this->parameters); + return OAuth1Util::build_http_query($this->parameters); } /** @@ -432,7 +432,7 @@ class OAuthRequest { public function to_header($realm=null) { $first = true; if($realm) { - $out = 'Authorization: OAuth realm="' . OAuthUtil::urlencode_rfc3986($realm) . '"'; + $out = 'Authorization: OAuth realm="' . OAuth1Util::urlencode_rfc3986($realm) . '"'; $first = false; } else $out = 'Authorization: OAuth'; @@ -441,12 +441,12 @@ class OAuthRequest { foreach ($this->parameters as $k => $v) { if (substr($k, 0, 5) != "oauth") continue; if (is_array($v)) { - throw new OAuthException('Arrays not supported in headers'); + throw new OAuth1Exception('Arrays not supported in headers'); } $out .= ($first) ? ' ' : ','; - $out .= OAuthUtil::urlencode_rfc3986($k) . + $out .= OAuth1Util::urlencode_rfc3986($k) . '="' . - OAuthUtil::urlencode_rfc3986($v) . + OAuth1Util::urlencode_rfc3986($v) . '"'; $first = false; } @@ -491,7 +491,7 @@ class OAuthRequest { } } -class OAuthServer { +class OAuth1Server { protected $timestamp_threshold = 300; // in seconds, five minutes protected $version = '1.0'; // hi blaine protected $signature_methods = array(); @@ -572,7 +572,7 @@ class OAuthServer { $version = '1.0'; } if ($version !== $this->version) { - throw new OAuthException("OAuth version '$version' not supported"); + throw new OAuth1Exception("OAuth1 version '$version' not supported"); } return $version; } @@ -587,12 +587,12 @@ class OAuthServer { if (!$signature_method) { // According to chapter 7 ("Accessing Protected Ressources") the signature-method // parameter is required, and we can't just fallback to PLAINTEXT - throw new OAuthException('No signature method parameter. This parameter is required'); + throw new OAuth1Exception('No signature method parameter. This parameter is required'); } if (!in_array($signature_method, array_keys($this->signature_methods))) { - throw new OAuthException( + throw new OAuth1Exception( "Signature method '$signature_method' not supported " . "try one of the following: " . implode(", ", array_keys($this->signature_methods)) @@ -607,12 +607,12 @@ class OAuthServer { private function get_consumer(&$request) { $consumer_key = @$request->get_parameter("oauth_consumer_key"); if (!$consumer_key) { - throw new OAuthException("Invalid consumer key"); + throw new OAuth1Exception("Invalid consumer key"); } $consumer = $this->data_store->lookup_consumer($consumer_key); if (!$consumer) { - throw new OAuthException("Invalid consumer"); + throw new OAuth1Exception("Invalid consumer"); } return $consumer; @@ -627,7 +627,7 @@ class OAuthServer { $consumer, $token_type, $token_field ); if (!$token) { - throw new OAuthException("Invalid $token_type token: $token_field"); + throw new OAuth1Exception("Invalid $token_type token: $token_field"); } return $token; } @@ -656,7 +656,7 @@ class OAuthServer { if (!$valid_sig) { - throw new OAuthException("Invalid signature"); + throw new OAuth1Exception("Invalid signature"); } } @@ -665,14 +665,14 @@ class OAuthServer { */ private function check_timestamp($timestamp) { if( ! $timestamp ) - throw new OAuthException( + throw new OAuth1Exception( 'Missing timestamp parameter. The parameter is required' ); // verify that timestamp is recentish $now = time(); if (abs($now - $timestamp) > $this->timestamp_threshold) { - throw new OAuthException( + throw new OAuth1Exception( "Expired timestamp, yours $timestamp, ours $now" ); } @@ -683,7 +683,7 @@ class OAuthServer { */ private function check_nonce($consumer, $token, $nonce, $timestamp) { if( ! $nonce ) - throw new OAuthException( + throw new OAuth1Exception( 'Missing nonce parameter. The parameter is required' ); @@ -695,13 +695,13 @@ class OAuthServer { $timestamp ); if ($found) { - throw new OAuthException("Nonce already used: $nonce"); + throw new OAuth1Exception("Nonce already used: $nonce"); } } } -class OAuthDataStore { +class OAuth1DataStore { function lookup_consumer($consumer_key) { // implement me } @@ -727,10 +727,10 @@ class OAuthDataStore { } -class OAuthUtil { +class OAuth1Util { public static function urlencode_rfc3986($input) { if (is_array($input)) { - return array_map(array('OAuthUtil', 'urlencode_rfc3986'), $input); + return array_map(array('OAuth1Util', 'urlencode_rfc3986'), $input); } else if (is_scalar($input)) { return str_replace( '+', @@ -762,7 +762,7 @@ class OAuthUtil { $header_name = $matches[2][0]; $header_content = (isset($matches[5])) ? $matches[5][0] : $matches[4][0]; if (preg_match('/^oauth_/', $header_name) || !$only_allow_oauth_parameters) { - $params[$header_name] = OAuthUtil::urldecode_rfc3986($header_content); + $params[$header_name] = OAuth1Util::urldecode_rfc3986($header_content); } $offset = $match[1] + strlen($match[0]); } @@ -834,8 +834,8 @@ class OAuthUtil { $parsed_parameters = array(); foreach ($pairs as $pair) { $split = explode('=', $pair, 2); - $parameter = OAuthUtil::urldecode_rfc3986($split[0]); - $value = isset($split[1]) ? OAuthUtil::urldecode_rfc3986($split[1]) : ''; + $parameter = OAuth1Util::urldecode_rfc3986($split[0]); + $value = isset($split[1]) ? OAuth1Util::urldecode_rfc3986($split[1]) : ''; if (isset($parsed_parameters[$parameter])) { // We have already recieved parameter(s) with this name, so add to the list @@ -859,8 +859,8 @@ class OAuthUtil { if (!$params) return ''; // Urlencode both keys and values - $keys = OAuthUtil::urlencode_rfc3986(array_keys($params)); - $values = OAuthUtil::urlencode_rfc3986(array_values($params)); + $keys = OAuth1Util::urlencode_rfc3986(array_keys($params)); + $values = OAuth1Util::urlencode_rfc3986(array_values($params)); $params = array_combine($keys, $values); // Parameters are sorted by name, using lexicographical byte value ordering. @@ -885,5 +885,3 @@ class OAuthUtil { return implode('&', $pairs); } } - -?> diff --git a/library/cacert.pem b/library/cacert.pem index 739128024..ef43898ab 100644 --- a/library/cacert.pem +++ b/library/cacert.pem @@ -4078,3 +4078,33 @@ Nr4TDea9Y355e6cJDUCrat2PisP29owaQgVR1EX1n6diIWgVIEM8med8vSTYqZEX c4g/VhsxOBi0cQ+azcgOno4uG+GMmIPLHzHxREzGBHNJdmAPx/i9F4BrLunMTA5a mnkPIAou1Z5jJh5VkpTYghdae9C8x49OhgQ= -----END CERTIFICATE----- + +Lets Encrypt +============ +-----BEGIN CERTIFICATE----- +MIIEqDCCA5CgAwIBAgIRAJgT9HUT5XULQ+dDHpceRL0wDQYJKoZIhvcNAQELBQAw +PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD +Ew5EU1QgUm9vdCBDQSBYMzAeFw0xNTEwMTkyMjMzMzZaFw0yMDEwMTkyMjMzMzZa +MEoxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MSMwIQYDVQQD +ExpMZXQncyBFbmNyeXB0IEF1dGhvcml0eSBYMTCCASIwDQYJKoZIhvcNAQEBBQAD +ggEPADCCAQoCggEBAJzTDPBa5S5Ht3JdN4OzaGMw6tc1Jhkl4b2+NfFwki+3uEtB +BaupnjUIWOyxKsRohwuj43Xk5vOnYnG6eYFgH9eRmp/z0HhncchpDpWRz/7mmelg +PEjMfspNdxIknUcbWuu57B43ABycrHunBerOSuu9QeU2mLnL/W08lmjfIypCkAyG +dGfIf6WauFJhFBM/ZemCh8vb+g5W9oaJ84U/l4avsNwa72sNlRZ9xCugZbKZBDZ1 +gGusSvMbkEl4L6KWTyogJSkExnTA0DHNjzE4lRa6qDO4Q/GxH8Mwf6J5MRM9LTb4 +4/zyM2q5OTHFr8SNDR1kFjOq+oQpttQLwNh9w5MCAwEAAaOCAZIwggGOMBIGA1Ud +EwEB/wQIMAYBAf8CAQAwDgYDVR0PAQH/BAQDAgGGMH8GCCsGAQUFBwEBBHMwcTAy +BggrBgEFBQcwAYYmaHR0cDovL2lzcmcudHJ1c3RpZC5vY3NwLmlkZW50cnVzdC5j +b20wOwYIKwYBBQUHMAKGL2h0dHA6Ly9hcHBzLmlkZW50cnVzdC5jb20vcm9vdHMv +ZHN0cm9vdGNheDMucDdjMB8GA1UdIwQYMBaAFMSnsaR7LHH62+FLkHX/xBVghYkQ +MFQGA1UdIARNMEswCAYGZ4EMAQIBMD8GCysGAQQBgt8TAQEBMDAwLgYIKwYBBQUH +AgEWImh0dHA6Ly9jcHMucm9vdC14MS5sZXRzZW5jcnlwdC5vcmcwPAYDVR0fBDUw +MzAxoC+gLYYraHR0cDovL2NybC5pZGVudHJ1c3QuY29tL0RTVFJPT1RDQVgzQ1JM +LmNybDATBgNVHR4EDDAKoQgwBoIELm1pbDAdBgNVHQ4EFgQUqEpqYwR93brm0Tm3 +pkVl7/Oo7KEwDQYJKoZIhvcNAQELBQADggEBANHIIkus7+MJiZZQsY14cCoBG1hd +v0J20/FyWo5ppnfjL78S2k4s2GLRJ7iD9ZDKErndvbNFGcsW+9kKK/TnY21hp4Dd +ITv8S9ZYQ7oaoqs7HwhEMY9sibED4aXw09xrJZTC9zK1uIfW6t5dHQjuOWv+HHoW +ZnupyxpsEUlEaFb+/SCI4KCSBdAsYxAcsHYI5xxEI4LutHp6s3OT2FuO90WfdsIk +6q78OMSdn875bNjdBYAqxUp2/LEIHfDBkLoQz0hFJmwAbYahqKaLn73PAAm1X2kj +f1w8DdnkabOLGeOVcj9LQ+s67vBykx4anTjURkbqZslUEUsn2k5xeua2zUk= +-----END CERTIFICATE----- diff --git a/library/certs/cacert.pem b/library/certs/cacert.pem index 1ff34f9b5..e4da7fc15 100644 --- a/library/certs/cacert.pem +++ b/library/certs/cacert.pem @@ -3986,3 +3986,33 @@ PDCBBpEi6lmt2hkuIsKNuYyH4Ga8cyNfIWRjgEj1oDwYPZTISEEdQLpe/v5WOaHIz16eGWRGENoX kbcFgKyLmZJ956LYBws2J+dIeWCKw9cTXPhyQN9Ky8+ZAAoACxGV2lZFA4gKn2fQ1XmxqI1AbQ3C ekD6819kR5LLU7m7Wc5P/dAVUwHY3+vZ5nbv0CO7O6l5s9UCKc2Jo5YPSjXnTkLAdc0Hz+Ys63su -----END CERTIFICATE----- + +Lets Encrypt +============ +-----BEGIN CERTIFICATE----- +MIIEqDCCA5CgAwIBAgIRAJgT9HUT5XULQ+dDHpceRL0wDQYJKoZIhvcNAQELBQAw +PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD +Ew5EU1QgUm9vdCBDQSBYMzAeFw0xNTEwMTkyMjMzMzZaFw0yMDEwMTkyMjMzMzZa +MEoxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MSMwIQYDVQQD +ExpMZXQncyBFbmNyeXB0IEF1dGhvcml0eSBYMTCCASIwDQYJKoZIhvcNAQEBBQAD +ggEPADCCAQoCggEBAJzTDPBa5S5Ht3JdN4OzaGMw6tc1Jhkl4b2+NfFwki+3uEtB +BaupnjUIWOyxKsRohwuj43Xk5vOnYnG6eYFgH9eRmp/z0HhncchpDpWRz/7mmelg +PEjMfspNdxIknUcbWuu57B43ABycrHunBerOSuu9QeU2mLnL/W08lmjfIypCkAyG +dGfIf6WauFJhFBM/ZemCh8vb+g5W9oaJ84U/l4avsNwa72sNlRZ9xCugZbKZBDZ1 +gGusSvMbkEl4L6KWTyogJSkExnTA0DHNjzE4lRa6qDO4Q/GxH8Mwf6J5MRM9LTb4 +4/zyM2q5OTHFr8SNDR1kFjOq+oQpttQLwNh9w5MCAwEAAaOCAZIwggGOMBIGA1Ud +EwEB/wQIMAYBAf8CAQAwDgYDVR0PAQH/BAQDAgGGMH8GCCsGAQUFBwEBBHMwcTAy +BggrBgEFBQcwAYYmaHR0cDovL2lzcmcudHJ1c3RpZC5vY3NwLmlkZW50cnVzdC5j +b20wOwYIKwYBBQUHMAKGL2h0dHA6Ly9hcHBzLmlkZW50cnVzdC5jb20vcm9vdHMv +ZHN0cm9vdGNheDMucDdjMB8GA1UdIwQYMBaAFMSnsaR7LHH62+FLkHX/xBVghYkQ +MFQGA1UdIARNMEswCAYGZ4EMAQIBMD8GCysGAQQBgt8TAQEBMDAwLgYIKwYBBQUH +AgEWImh0dHA6Ly9jcHMucm9vdC14MS5sZXRzZW5jcnlwdC5vcmcwPAYDVR0fBDUw +MzAxoC+gLYYraHR0cDovL2NybC5pZGVudHJ1c3QuY29tL0RTVFJPT1RDQVgzQ1JM +LmNybDATBgNVHR4EDDAKoQgwBoIELm1pbDAdBgNVHQ4EFgQUqEpqYwR93brm0Tm3 +pkVl7/Oo7KEwDQYJKoZIhvcNAQELBQADggEBANHIIkus7+MJiZZQsY14cCoBG1hd +v0J20/FyWo5ppnfjL78S2k4s2GLRJ7iD9ZDKErndvbNFGcsW+9kKK/TnY21hp4Dd +ITv8S9ZYQ7oaoqs7HwhEMY9sibED4aXw09xrJZTC9zK1uIfW6t5dHQjuOWv+HHoW +ZnupyxpsEUlEaFb+/SCI4KCSBdAsYxAcsHYI5xxEI4LutHp6s3OT2FuO90WfdsIk +6q78OMSdn875bNjdBYAqxUp2/LEIHfDBkLoQz0hFJmwAbYahqKaLn73PAAm1X2kj +f1w8DdnkabOLGeOVcj9LQ+s67vBykx4anTjURkbqZslUEUsn2k5xeua2zUk= +-----END CERTIFICATE----- diff --git a/library/ical.php b/library/ical.php deleted file mode 100644 index 6bb26bad8..000000000 --- a/library/ical.php +++ /dev/null @@ -1,379 +0,0 @@ -<?php -/** - * This PHP-Class should only read a iCal-File (*.ics), parse it and give an - * array with its content. - * - * PHP Version 5 - * - * @category Parser - * @package Ics-parser - * @author Martin Thoma <info@martin-thoma.de> - * @license http://www.opensource.org/licenses/mit-license.php MIT License - * @version SVN: <svn_id> - * @link http://code.google.com/p/ics-parser/ - * @example $ical = new ical('MyCal.ics'); - * print_r( $ical->events() ); - */ - -/** - * This example demonstrates how the Ics-Parser should be used. - * - * PHP Version 5 - * - * @category Example - * @package Ics-parser - * @author Martin Thoma <info@martin-thoma.de> - * @license http://www.opensource.org/licenses/mit-license.php MIT License - * @version SVN: <svn_id> - * @link http://code.google.com/p/ics-parser/ - * @example $ical = new ical('MyCal.ics'); - * print_r( $ical->get_event_array() ); - -require 'class.iCalReader.php'; - -$ical = new ICal('MyCal.ics'); -$events = $ical->events(); - -$date = $events[0]['DTSTART']; -echo "The ical date: "; -echo $date; -echo "<br/>"; - -echo "The Unix timestamp: "; -echo $ical->iCalDateToUnixTimestamp($date); -echo "<br/>"; - -echo "The number of events: "; -echo $ical->event_count; -echo "<br/>"; - -echo "The number of todos: "; -echo $ical->todo_count; -echo "<br/>"; -echo "<hr/><hr/>"; - -foreach ($events as $event) { - echo "SUMMARY: ".$event['SUMMARY']."<br/>"; - echo "DTSTART: ".$event['DTSTART']." - UNIX-Time: ".$ical->iCalDateToUnixTimestamp($event['DTSTART'])."<br/>"; - echo "DTEND: ".$event['DTEND']."<br/>"; - echo "DTSTAMP: ".$event['DTSTAMP']."<br/>"; - echo "UID: ".$event['UID']."<br/>"; - echo "CREATED: ".$event['CREATED']."<br/>"; - echo "DESCRIPTION: ".$event['DESCRIPTION']."<br/>"; - echo "LAST-MODIFIED: ".$event['LAST-MODIFIED']."<br/>"; - echo "LOCATION: ".$event['LOCATION']."<br/>"; - echo "SEQUENCE: ".$event['SEQUENCE']."<br/>"; - echo "STATUS: ".$event['STATUS']."<br/>"; - echo "TRANSP: ".$event['TRANSP']."<br/>"; - echo "<hr/>"; -} - - (end example) - * - * - */ - -// error_reporting(E_ALL); - -/** - * This is the iCal-class - * - * @category Parser - * @package Ics-parser - * @author Martin Thoma <info@martin-thoma.de> - * @license http://www.opensource.org/licenses/mit-license.php MIT License - * @link http://code.google.com/p/ics-parser/ - * - * @param {string} filename The name of the file which should be parsed - * @constructor - */ -class ICal -{ - /* How many ToDos are in this ical? */ - public /** @type {int} */ $todo_count = 0; - - /* How many events are in this ical? */ - public /** @type {int} */ $event_count = 0; - - /* The parsed calendar */ - public /** @type {Array} */ $cal; - - /* Which keyword has been added to cal at last? */ - private /** @type {string} */ $_lastKeyWord; - - /** - * Creates the iCal-Object - * - * @param {string} $filename The path to the iCal-file - * - * @return Object The iCal-Object - */ - public function __construct($filename) - { - if (!$filename) { - return false; - } - - $lines = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); - if (stristr($lines[0], 'BEGIN:VCALENDAR') === false) { - return false; - } else { - // TODO: Fix multiline-description problem (see http://tools.ietf.org/html/rfc2445#section-4.8.1.5) - foreach ($lines as $line) { - $line = trim($line); - $add = $this->keyValueFromString($line); - if ($add === false) { - $this->addCalendarComponentWithKeyAndValue($type, false, $line); - continue; - } - - list($keyword, $value) = $add; - - switch ($line) { - // http://www.kanzaki.com/docs/ical/vtodo.html - case "BEGIN:VTODO": - $this->todo_count++; - $type = "VTODO"; - break; - - // http://www.kanzaki.com/docs/ical/vevent.html - case "BEGIN:VEVENT": - //echo "vevent gematcht"; - $this->event_count++; - $type = "VEVENT"; - break; - - //all other special strings - case "BEGIN:VCALENDAR": - case "BEGIN:DAYLIGHT": - // http://www.kanzaki.com/docs/ical/vtimezone.html - case "BEGIN:VTIMEZONE": - case "BEGIN:STANDARD": - $type = $value; - break; - case "END:VTODO": // end special text - goto VCALENDAR key - case "END:VEVENT": - case "END:VCALENDAR": - case "END:DAYLIGHT": - case "END:VTIMEZONE": - case "END:STANDARD": - $type = "VCALENDAR"; - break; - default: - $this->addCalendarComponentWithKeyAndValue($type, - $keyword, - $value); - break; - } - } - return $this->cal; - } - } - - /** - * Add to $this->ical array one value and key. - * - * @param {string} $component This could be VTODO, VEVENT, VCALENDAR, ... - * @param {string} $keyword The keyword, for example DTSTART - * @param {string} $value The value, for example 20110105T090000Z - * - * @return {None} - */ - public function addCalendarComponentWithKeyAndValue($component, - $keyword, - $value) - { - if ($keyword == false) { - $keyword = $this->last_keyword; - switch ($component) { - case 'VEVENT': - $value = $this->cal[$component][$this->event_count - 1] - [$keyword].$value; - break; - case 'VTODO' : - $value = $this->cal[$component][$this->todo_count - 1] - [$keyword].$value; - break; - } - } - - if (stristr($keyword, "DTSTART") or stristr($keyword, "DTEND")) { - $keyword = explode(";", $keyword); - $keyword = $keyword[0]; - } - - switch ($component) { - case "VTODO": - $this->cal[$component][$this->todo_count - 1][$keyword] = $value; - //$this->cal[$component][$this->todo_count]['Unix'] = $unixtime; - break; - case "VEVENT": - $this->cal[$component][$this->event_count - 1][$keyword] = $value; - break; - default: - $this->cal[$component][$keyword] = $value; - break; - } - $this->last_keyword = $keyword; - } - - /** - * Get a key-value pair of a string. - * - * @param {string} $text which is like "VCALENDAR:Begin" or "LOCATION:" - * - * @return {array} array("VCALENDAR", "Begin") - */ - public function keyValueFromString($text) - { - preg_match("/([^:]+)[:]([\w\W]*)/", $text, $matches); - if (count($matches) == 0) { - return false; - } - $matches = array_splice($matches, 1, 2); - return $matches; - } - - /** - * Return Unix timestamp from ical date time format - * - * @param {string} $icalDate A Date in the format YYYYMMDD[T]HHMMSS[Z] or - * YYYYMMDD[T]HHMMSS - * - * @return {int} - */ - public function iCalDateToUnixTimestamp($icalDate) - { - $icalDate = str_replace('T', '', $icalDate); - $icalDate = str_replace('Z', '', $icalDate); - - $pattern = '/([0-9]{4})'; // 1: YYYY - $pattern .= '([0-9]{2})'; // 2: MM - $pattern .= '([0-9]{2})'; // 3: DD - $pattern .= '([0-9]{0,2})'; // 4: HH - $pattern .= '([0-9]{0,2})'; // 5: MM - $pattern .= '([0-9]{0,2})/'; // 6: SS - preg_match($pattern, $icalDate, $date); - - // Unix timestamp can't represent dates before 1970 - if ($date[1] <= 1970) { - return false; - } - // Unix timestamps after 03:14:07 UTC 2038-01-19 might cause an overflow - // if 32 bit integers are used. - $timestamp = mktime((int)$date[4], - (int)$date[5], - (int)$date[6], - (int)$date[2], - (int)$date[3], - (int)$date[1]); - return $timestamp; - } - - /** - * Returns an array of arrays with all events. Every event is an associative - * array and each property is an element it. - * - * @return {array} - */ - public function events() - { - $array = $this->cal; - return $array['VEVENT']; - } - - /** - * Returns a boolean value whether thr current calendar has events or not - * - * @return {boolean} - */ - public function hasEvents() - { - return ( count($this->events()) > 0 ? true : false ); - } - - /** - * Returns false when the current calendar has no events in range, else the - * events. - * - * Note that this function makes use of a UNIX timestamp. This might be a - * problem on January the 29th, 2038. - * See http://en.wikipedia.org/wiki/Unix_time#Representing_the_number - * - * @param {boolean} $rangeStart Either true or false - * @param {boolean} $rangeEnd Either true or false - * - * @return {mixed} - */ - public function eventsFromRange($rangeStart = false, $rangeEnd = false) - { - $events = $this->sortEventsWithOrder($this->events(), SORT_ASC); - - if (!$events) { - return false; - } - - $extendedEvents = array(); - - if ($rangeStart !== false) { - $rangeStart = new DateTime(); - } - - if ($rangeEnd !== false or $rangeEnd <= 0) { - $rangeEnd = new DateTime('2038/01/18'); - } else { - $rangeEnd = new DateTime($rangeEnd); - } - - $rangeStart = $rangeStart->format('U'); - $rangeEnd = $rangeEnd->format('U'); - - - - // loop through all events by adding two new elements - foreach ($events as $anEvent) { - $timestamp = $this->iCalDateToUnixTimestamp($anEvent['DTSTART']); - if ($timestamp >= $rangeStart && $timestamp <= $rangeEnd) { - $extendedEvents[] = $anEvent; - } - } - - return $extendedEvents; - } - - /** - * Returns a boolean value whether thr current calendar has events or not - * - * @param {array} $events An array with events. - * @param {array} $sortOrder Either SORT_ASC, SORT_DESC, SORT_REGULAR, - * SORT_NUMERIC, SORT_STRING - * - * @return {boolean} - */ - public function sortEventsWithOrder($events, $sortOrder = SORT_ASC) - { - $extendedEvents = array(); - - // loop through all events by adding two new elements - foreach ($events as $anEvent) { - if (!array_key_exists('UNIX_TIMESTAMP', $anEvent)) { - $anEvent['UNIX_TIMESTAMP'] = - $this->iCalDateToUnixTimestamp($anEvent['DTSTART']); - } - - if (!array_key_exists('REAL_DATETIME', $anEvent)) { - $anEvent['REAL_DATETIME'] = - date("d.m.Y", $anEvent['UNIX_TIMESTAMP']); - } - - $extendedEvents[] = $anEvent; - } - - foreach ($extendedEvents as $key => $value) { - $timestamp[$key] = $value['UNIX_TIMESTAMP']; - } - array_multisort($timestamp, $sortOrder, $extendedEvents); - - return $extendedEvents; - } -} diff --git a/library/twitteroauth.php b/library/twitteroauth.php index a40949534..d6fb1b3a2 100644 --- a/library/twitteroauth.php +++ b/library/twitteroauth.php @@ -6,8 +6,8 @@ * The first PHP Library to support OAuth for Twitter's REST API. */ -/* Load OAuth lib. You can find it at http://oauth.net */ -if(!class_exists('OAuthException')) +/* Load OAuth1 lib. You can find it at http://oauth.net */ +if(!class_exists('OAuth1Exception')) require_once('library/OAuth1.php'); /** @@ -58,10 +58,10 @@ class TwitterOAuth { * construct TwitterOAuth object */ function __construct($consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) { - $this->sha1_method = new OAuthSignatureMethod_HMAC_SHA1(); - $this->consumer = new OAuthConsumer($consumer_key, $consumer_secret); + $this->sha1_method = new OAuth1SignatureMethod_HMAC_SHA1(); + $this->consumer = new OAuth1Consumer($consumer_key, $consumer_secret); if (!empty($oauth_token) && !empty($oauth_token_secret)) { - $this->token = new OAuthConsumer($oauth_token, $oauth_token_secret); + $this->token = new OAuth1Consumer($oauth_token, $oauth_token_secret); } else { $this->token = NULL; } @@ -79,8 +79,8 @@ class TwitterOAuth { $parameters['oauth_callback'] = $oauth_callback; } $request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters); - $token = OAuthUtil::parse_parameters($request); - $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']); + $token = OAuth1Util::parse_parameters($request); + $this->token = new OAuth1Consumer($token['oauth_token'], $token['oauth_token_secret']); return $token; } @@ -115,8 +115,8 @@ class TwitterOAuth { $parameters['oauth_verifier'] = $oauth_verifier; } $request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters); - $token = OAuthUtil::parse_parameters($request); - $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']); + $token = OAuth1Util::parse_parameters($request); + $this->token = new OAuth1Consumer($token['oauth_token'], $token['oauth_token_secret']); return $token; } @@ -135,8 +135,8 @@ class TwitterOAuth { $parameters['x_auth_password'] = $password; $parameters['x_auth_mode'] = 'client_auth'; $request = $this->oAuthRequest($this->accessTokenURL(), 'POST', $parameters); - $token = OAuthUtil::parse_parameters($request); - $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']); + $token = OAuth1Util::parse_parameters($request); + $this->token = new OAuth1Consumer($token['oauth_token'], $token['oauth_token_secret']); return $token; } @@ -180,7 +180,7 @@ class TwitterOAuth { if (strrpos($url, 'https://') !== 0 && strrpos($url, 'http://') !== 0) { $url = "{$this->host}{$url}.{$this->format}"; } - $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters); + $request = OAuth1Request::from_consumer_and_token($this->consumer, $this->token, $method, $url, $parameters); $request->sign_request($this->sha1_method, $this->consumer, $this->token); switch ($method) { case 'GET': |