function _linkedin_parse_fields in LinkedIn Integration 7
Same name and namespace in other branches
- 6 linkedin.inc \_linkedin_parse_fields()
1 call to _linkedin_parse_fields()
- _linkedin_get_fields in ./linkedin.inc
- @todo Please document this function.
File
- ./linkedin.inc, line 364
Code
function _linkedin_parse_fields($contents) {
if (!$contents) {
return array();
}
if (!function_exists('xml_parser_create')) {
if (variable_get('linkedin_debug_mode', 0) == 1) {
drupal_set_message(t('Unable to find PHP parser. This module needs php-xml lib'), 'warning');
}
return array();
}
$parser = xml_parser_create('');
xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
xml_parse_into_struct($parser, trim($contents), $xml_values);
xml_parser_free($parser);
if (!$xml_values) {
return;
}
$xml_array = array();
$parents = array();
$opened_tags = array();
$arr = array();
$current =& $xml_array;
$repeated_tag_index = array();
foreach ($xml_values as $data) {
unset($attributes, $value);
extract($data);
$result = array();
$attributes_data = array();
if (isset($value)) {
$result = $value;
}
if ($type == "open") {
$parent[$level - 1] =& $current;
if (!is_array($current) or !in_array($tag, array_keys($current))) {
$current[$tag] = $result;
if ($attributes_data) {
$current[$tag . '_attr'] = $attributes_data;
}
$repeated_tag_index[$tag . '_' . $level] = 1;
$current =& $current[$tag];
}
else {
if (isset($current[$tag][0])) {
$current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
$repeated_tag_index[$tag . '_' . $level]++;
}
else {
$current[$tag] = array(
$current[$tag],
$result,
);
$repeated_tag_index[$tag . '_' . $level] = 2;
if (isset($current[$tag . '_attr'])) {
$current[$tag]['0_attr'] = $current[$tag . '_attr'];
unset($current[$tag . '_attr']);
}
}
$last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1;
$current =& $current[$tag][$last_item_index];
}
}
elseif ($type == "complete") {
if (!isset($current[$tag])) {
$current[$tag] = $result;
$repeated_tag_index[$tag . '_' . $level] = 1;
if ($attributes_data) {
$current[$tag . '_attr'] = $attributes_data;
}
}
else {
if (isset($current[$tag][0]) && is_array($current[$tag])) {
$current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
$repeated_tag_index[$tag . '_' . $level]++;
}
else {
$current[$tag] = array(
$current[$tag],
$result,
);
$repeated_tag_index[$tag . '_' . $level] = 2;
}
}
}
elseif ($type == 'close') {
$current =& $parent[$level - 1];
}
}
return $xml_array;
}