[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/libraries/openid/Auth/OpenID/ -> KVForm.php (source)

   1  <?php
   2  
   3  /**
   4   * OpenID protocol key-value/comma-newline format parsing and
   5   * serialization
   6   *
   7   * PHP versions 4 and 5
   8   *
   9   * LICENSE: See the COPYING file included in this distribution.
  10   *
  11   * @access private
  12   * @package OpenID
  13   * @author JanRain, Inc. <openid@janrain.com>
  14   * @copyright 2005-2008 Janrain, Inc.
  15   * @license http://www.apache.org/licenses/LICENSE-2.0 Apache
  16   */
  17  
  18  // Do not allow direct access
  19  defined( '_JEXEC' ) or die( 'Restricted access' );
  20  
  21  /**
  22   * Container for key-value/comma-newline OpenID format and parsing
  23   */
  24  class Auth_OpenID_KVForm {
  25      /**
  26       * Convert an OpenID colon/newline separated string into an
  27       * associative array
  28       *
  29       * @static
  30       * @access private
  31       */
  32      function toArray($kvs, $strict=false)
  33      {
  34          $lines = explode("\n", $kvs);
  35  
  36          $last = array_pop($lines);
  37          if ($last !== '') {
  38              array_push($lines, $last);
  39              if ($strict) {
  40                  return false;
  41              }
  42          }
  43  
  44          $values = array();
  45  
  46          for ($lineno = 0; $lineno < count($lines); $lineno++) {
  47              $line = $lines[$lineno];
  48              $kv = explode(':', $line, 2);
  49              if (count($kv) != 2) {
  50                  if ($strict) {
  51                      return false;
  52                  }
  53                  continue;
  54              }
  55  
  56              $key = $kv[0];
  57              $tkey = trim($key);
  58              if ($tkey != $key) {
  59                  if ($strict) {
  60                      return false;
  61                  }
  62              }
  63  
  64              $value = $kv[1];
  65              $tval = trim($value);
  66              if ($tval != $value) {
  67                  if ($strict) {
  68                      return false;
  69                  }
  70              }
  71  
  72              $values[$tkey] = $tval;
  73          }
  74  
  75          return $values;
  76      }
  77  
  78      /**
  79       * Convert an array into an OpenID colon/newline separated string
  80       *
  81       * @static
  82       * @access private
  83       */
  84      function fromArray($values)
  85      {
  86          if ($values === null) {
  87              return null;
  88          }
  89  
  90          ksort($values);
  91  
  92          $serialized = '';
  93          foreach ($values as $key => $value) {
  94              if (is_array($value)) {
  95                  list($key, $value) = array($value[0], $value[1]);
  96              }
  97  
  98              if (strpos($key, ':') !== false) {
  99                  return null;
 100              }
 101  
 102              if (strpos($key, "\n") !== false) {
 103                  return null;
 104              }
 105  
 106              if (strpos($value, "\n") !== false) {
 107                  return null;
 108              }
 109              $serialized .= "$key:$value\n";
 110          }
 111          return $serialized;
 112      }
 113  }
 114  
 115  ?>


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1