| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 3 // Global variables to track parsing state 4 $xrds_open_elements = array(); 5 $xrds_services = array(); 6 $xrds_current_service = array(); 7 8 /** 9 * Main entry point for parsing XRDS documents 10 */ 11 function xrds_parse($xml) { 12 global $xrds_services; 13 14 $parser = xml_parser_create_ns(); 15 xml_set_element_handler($parser, '_xrds_element_start', '_xrds_element_end'); 16 xml_set_character_data_handler($parser, '_xrds_cdata'); 17 18 xml_parse($parser, $xml); 19 xml_parser_free($parser); 20 21 return $xrds_services; 22 } 23 24 /** 25 * Parser callback functions 26 */ 27 function _xrds_element_start(&$parser, $name, $attribs) { 28 global $xrds_open_elements; 29 30 $xrds_open_elements[] = _xrds_strip_namespace($name); 31 } 32 33 function _xrds_element_end(&$parser, $name) { 34 global $xrds_open_elements, $xrds_services, $xrds_current_service; 35 36 $name = _xrds_strip_namespace($name); 37 if ($name == 'SERVICE') { 38 if (in_array(OPENID_NS_2_0 .'/signon', $xrds_current_service['types']) || 39 in_array(OPENID_NS_2_0 .'/server', $xrds_current_service['types'])) { 40 $xrds_current_service['version'] = 2; 41 } 42 elseif (in_array(OPENID_NS_1_1, $xrds_current_service['types']) || 43 in_array(OPENID_NS_1_0, $xrds_current_service['types'])) { 44 $xrds_current_service['version'] = 1; 45 } 46 if (!empty($xrds_current_service['version'])) { 47 $xrds_services[] = $xrds_current_service; 48 } 49 $xrds_current_service = array(); 50 } 51 array_pop($xrds_open_elements); 52 } 53 54 function _xrds_cdata(&$parser, $data) { 55 global $xrds_open_elements, $xrds_services, $xrds_current_service; 56 $path = strtoupper(implode('/', $xrds_open_elements)); 57 switch ($path) { 58 case 'XRDS/XRD/SERVICE/TYPE': 59 $xrds_current_service['types'][] = $data; 60 break; 61 case 'XRDS/XRD/SERVICE/URI': 62 $xrds_current_service['uri'] = $data; 63 break; 64 case 'XRDS/XRD/SERVICE/DELEGATE': 65 $xrds_current_service['delegate'] = $data; 66 break; 67 case 'XRDS/XRD/SERVICE/LOCALID': 68 $xrds_current_service['localid'] = $data; 69 break; 70 } 71 } 72 73 function _xrds_strip_namespace($name) { 74 // Strip namespacing. 75 $pos = strrpos($name, ':'); 76 if ($pos !== FALSE) { 77 $name = substr($name, $pos + 1, strlen($name)); 78 } 79 80 return $name; 81 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |