|
TYPO3 API
SVNRelease
|
00001 <?php 00002 00003 /** 00004 * OpenID protocol key-value/comma-newline format parsing and 00005 * serialization 00006 * 00007 * PHP versions 4 and 5 00008 * 00009 * LICENSE: See the COPYING file included in this distribution. 00010 * 00011 * @access private 00012 * @package OpenID 00013 * @author JanRain, Inc. <openid@janrain.com> 00014 * @copyright 2005-2008 Janrain, Inc. 00015 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache 00016 */ 00017 00018 /** 00019 * Container for key-value/comma-newline OpenID format and parsing 00020 */ 00021 class Auth_OpenID_KVForm { 00022 /** 00023 * Convert an OpenID colon/newline separated string into an 00024 * associative array 00025 * 00026 * @static 00027 * @access private 00028 */ 00029 function toArray($kvs, $strict=false) 00030 { 00031 $lines = explode("\n", $kvs); 00032 00033 $last = array_pop($lines); 00034 if ($last !== '') { 00035 array_push($lines, $last); 00036 if ($strict) { 00037 return false; 00038 } 00039 } 00040 00041 $values = array(); 00042 00043 for ($lineno = 0; $lineno < count($lines); $lineno++) { 00044 $line = $lines[$lineno]; 00045 $kv = explode(':', $line, 2); 00046 if (count($kv) != 2) { 00047 if ($strict) { 00048 return false; 00049 } 00050 continue; 00051 } 00052 00053 $key = $kv[0]; 00054 $tkey = trim($key); 00055 if ($tkey != $key) { 00056 if ($strict) { 00057 return false; 00058 } 00059 } 00060 00061 $value = $kv[1]; 00062 $tval = trim($value); 00063 if ($tval != $value) { 00064 if ($strict) { 00065 return false; 00066 } 00067 } 00068 00069 $values[$tkey] = $tval; 00070 } 00071 00072 return $values; 00073 } 00074 00075 /** 00076 * Convert an array into an OpenID colon/newline separated string 00077 * 00078 * @static 00079 * @access private 00080 */ 00081 function fromArray($values) 00082 { 00083 if ($values === null) { 00084 return null; 00085 } 00086 00087 ksort($values); 00088 00089 $serialized = ''; 00090 foreach ($values as $key => $value) { 00091 if (is_array($value)) { 00092 list($key, $value) = array($value[0], $value[1]); 00093 } 00094 00095 if (strpos($key, ':') !== false) { 00096 return null; 00097 } 00098 00099 if (strpos($key, "\n") !== false) { 00100 return null; 00101 } 00102 00103 if (strpos($value, "\n") !== false) { 00104 return null; 00105 } 00106 $serialized .= "$key:$value\n"; 00107 } 00108 return $serialized; 00109 } 00110 } 00111 00112 ?>
1.8.0