diff options
author | Sem <sembrestels@riseup.net> | 2013-11-09 16:27:03 +0100 |
---|---|---|
committer | Sem <sembrestels@riseup.net> | 2013-11-09 16:27:03 +0100 |
commit | 911d0021c374602c31e5bfd71b1cd8074f2c2293 (patch) | |
tree | 7e1d529b705e24906d69b9056d7980f0ebabc772 /mod/openid_api/vendors/php-openid/Auth/OpenID/KVForm.php | |
parent | 5cc7f96262509b2a5d43fa6fbb6cd083064385be (diff) | |
parent | 33c206552a0cfd1166b2d5e4fcceb26f5ff1d224 (diff) | |
download | elgg-911d0021c374602c31e5bfd71b1cd8074f2c2293.tar.gz elgg-911d0021c374602c31e5bfd71b1cd8074f2c2293.tar.bz2 |
Add 'mod/openid_api/' from commit '33c206552a0cfd1166b2d5e4fcceb26f5ff1d224'
git-subtree-dir: mod/openid_api
git-subtree-mainline: 5cc7f96262509b2a5d43fa6fbb6cd083064385be
git-subtree-split: 33c206552a0cfd1166b2d5e4fcceb26f5ff1d224
Diffstat (limited to 'mod/openid_api/vendors/php-openid/Auth/OpenID/KVForm.php')
-rw-r--r-- | mod/openid_api/vendors/php-openid/Auth/OpenID/KVForm.php | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/mod/openid_api/vendors/php-openid/Auth/OpenID/KVForm.php b/mod/openid_api/vendors/php-openid/Auth/OpenID/KVForm.php new file mode 100644 index 000000000..dd02661d8 --- /dev/null +++ b/mod/openid_api/vendors/php-openid/Auth/OpenID/KVForm.php @@ -0,0 +1,111 @@ +<?php + +/** + * OpenID protocol key-value/comma-newline format parsing and + * serialization + * + * PHP versions 4 and 5 + * + * LICENSE: See the COPYING file included in this distribution. + * + * @access private + * @package OpenID + * @author JanRain, Inc. <openid@janrain.com> + * @copyright 2005-2008 Janrain, Inc. + * @license http://www.apache.org/licenses/LICENSE-2.0 Apache + */ + +/** + * Container for key-value/comma-newline OpenID format and parsing + */ +class Auth_OpenID_KVForm { + /** + * Convert an OpenID colon/newline separated string into an + * associative array + * + * @static + * @access private + */ + static function toArray($kvs, $strict=false) + { + $lines = explode("\n", $kvs); + + $last = array_pop($lines); + if ($last !== '') { + array_push($lines, $last); + if ($strict) { + return false; + } + } + + $values = array(); + + for ($lineno = 0; $lineno < count($lines); $lineno++) { + $line = $lines[$lineno]; + $kv = explode(':', $line, 2); + if (count($kv) != 2) { + if ($strict) { + return false; + } + continue; + } + + $key = $kv[0]; + $tkey = trim($key); + if ($tkey != $key) { + if ($strict) { + return false; + } + } + + $value = $kv[1]; + $tval = trim($value); + if ($tval != $value) { + if ($strict) { + return false; + } + } + + $values[$tkey] = $tval; + } + + return $values; + } + + /** + * Convert an array into an OpenID colon/newline separated string + * + * @static + * @access private + */ + static function fromArray($values) + { + if ($values === null) { + return null; + } + + ksort($values); + + $serialized = ''; + foreach ($values as $key => $value) { + if (is_array($value)) { + list($key, $value) = array($value[0], $value[1]); + } + + if (strpos($key, ':') !== false) { + return null; + } + + if (strpos($key, "\n") !== false) { + return null; + } + + if (strpos($value, "\n") !== false) { + return null; + } + $serialized .= "$key:$value\n"; + } + return $serialized; + } +} + |