Example #1
0
/**
 * Removes all invalid characters in xml string, e.g. & replaces with &amp; , < replaces with &lt; ....
 */
function normalizeXML($data)
{
	$LT = '<';
	$GT = '>';
	$res = "";

	//remove all invalid xml characters
	$data = stripInvalidXml($data);
	$lastTagName = "";

	for ($startIndex = 0; $startIndex < strlen($data);) {
		if ($data[$startIndex] == $LT) {
			// parse tag name
			//echo "\nTag";
			$tagStart = $startIndex;
			$tagEnd = strpos($data, $GT, $tagStart);
			$tagName = trim(substr($data, $tagStart + 1, $tagEnd - $tagStart - 1));
			//$tagName = htmlspecialchars_decode($tagName);
			//$tagName = htmlspecialchars($tagName);
			$lastTagName = $tagName;
			$tag = $LT . $tagName . $GT;
			$res = $res . $tag;
			//echo "\n" . $res;
			$startIndex = $tagEnd + 1;

		} else {
			// parse value
			//echo "\nValue";
			$endTag = $LT . "/" . $lastTagName . $GT;
			$valueStart = $startIndex;
			$valueEnd = strpos($data, $endTag, $valueStart);
			$startNextTag = strpos($data, $LT, $valueStart);

			if ($valueEnd === false) {
				$valueEnd = $startNextTag;
			}

			if ($startNextTag < $valueEnd) {
				$valueEnd = $startNextTag;
			}

			$value = trim(substr($data, $valueStart, $valueEnd - $valueStart));
			$value = htmlspecialchars_decode($value);
			$value = htmlspecialchars($value);

			$res = $res . $value;
			//echo "\n" . $res;
			$startIndex = $valueEnd;
		}
	}

	return $res;
}
function populate_metadata_from_dump($id, $meta)
{
    global $fields_title, $fields_embeddedequiv, $fields_type, $optionlists;
    // read in the metadata file and dump it into the right places in the database
    $metadump = file_get_contents($meta);
    // lazy solution: the resourcespace XML namespace is not formally defined
    // and thus the docs will not validate. For now we're just going to do some
    // regex magic to get rid of the namespaces alltogether. Fixme - would be
    // nice to make the metadump files validate
    $metadump = preg_replace('/([<\\/])([a-z0-9]+):/i', '$1$2', $metadump);
    $metadump = preg_replace('/(resourcespace):(resourceid="\\d+">)/i', '$1$2', $metadump);
    # Fix an issue whereby the resourcespace namespace is not defined. Add a fake namespace to the header.
    $metadump = str_replace("xmlns:dc", "xmlns:resourcespace='http://www.resourcespace.org' xmlns:dc", $metadump);
    $metadump = stripInvalidXml($metadump);
    //echo $metadump;
    $xml = new SimpleXMLElement($metadump);
    //print_r($xml);
    //echo "\n field ref for title is " . $xml->dctitle['rsfieldref'] . "\n";
    foreach ($xml as $fieldxml) {
        if ($fieldxml == '') {
            continue;
        }
        $value = $fieldxml;
        $rsfieldtitle = $fieldxml['rsfieldtitle'];
        $rsembeddedequiv = $fieldxml['rsembeddedequiv'];
        $rsfieldref = $fieldxml['rsfieldref'];
        $rsfieldtype = $fieldxml['rsfieldtype'];
        echo "\n==========\n";
        echo "   rsfieldtitle: {$rsfieldtitle}\n";
        echo " rsembeddedequiv: {$rsembeddedequiv}\n";
        echo "     rsfieldref: {$rsfieldref}\n";
        echo "    rsfieldtype: {$rsfieldtype}\n";
        echo "          value: {$value}\n";
        $rsfieldtitle = escape_check($rsfieldtitle);
        $newid = sql_value("select ref value from resource_type_field where title = '{$rsfieldtitle}' and type = '{$rsfieldtype}'", 0);
        if ($newid > 0) {
            $finalid = $newid;
        } else {
            if ($rsfieldtype == '7') {
                // category trees are too complicated to construct, so we're going to treat them as text fields for now.
                $rsfieldtype = '1';
            }
            $sql = "insert into resource_type_field (title,type,name) values ('{$rsfieldtitle}','{$rsfieldtype}','{$rsembeddedequiv}')";
            $result = sql_query($sql);
            $finalid = sql_insert_id();
        }
        if ($rsfieldtype == 2 || $rsfieldtype == 3) {
            if (!isset($optionlists[$finalid])) {
                $optionlists[$finalid] = array();
            }
            if (!in_array($value, $optionlists[$finalid])) {
                $optionlists[$finalid][] = $value;
            }
        }
        $fields_title["{$rsfieldref}"] = $rsfieldtitle;
        $fields_embeddedequiv["{$rsfieldref}"] = $rsembeddedequiv;
        $fields_type["{$rsfieldref}"] = $rsfieldtype;
        $value = escape_check($value);
        $sql = "insert into resource_data (resource, resource_type_field, value) values ('{$id}','{$rsfieldref}','{$value}')";
        sql_query($sql);
    }
}
Example #3
0
            echo "Skipping current=" . $current . "<br />";
            $ret .= " ";
        }
    }
    return $ret;
}
$output = "\"Patron_ID\"" . ",\"Patron_Name\"" . ",\"Fine_type\"" . ",\"Last_Transaction_Date\"" . ",\"Fee_type\"" . ",\"Sum\"" . ",\"Item_Title\"" . ",\"Item_call_number\"" . ",\"Item_barcode\"" . ",\"Item_due_date\"" . ",\"Item_library\"" . ",\"Item_location\"\r\n";
fwrite($GLOBALS['f'], $output);
$output = Null;
// Specify element handler
xml_set_element_handler($parser, "start", "stop");
// Specify data handler
xml_set_character_data_handler($parser, "char");
// Open XML file
// if running locally for testing uncomment below line
// $fp=fopen("../proxyfiles/data/ALMA/AlmaBURSAR.xml","r");
// if running as hosted service on Lamp Server use below line
//$fp=fopen("BURSARNON-TEST.xml","r");
$fp = fopen("/usr/local/data/Alma/working/NONbursarOut.xml", "r");
// Read data
while ($data = fread($fp, 4096)) {
    $data = stripInvalidXml($data);
    xml_parse($parser, $data, feof($fp)) or die(sprintf("XML Error: %s at line %d", xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser)));
}
// Free the XML parser
xml_parser_free($parser);
fclose($f);
?>


Example #4
0
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        $response = curl_exec($ch);
        curl_close($ch);
        $json = json_decode($response, true);
    } else {
        session_start();
        $opts = array('http' => array('header' => 'Cookie: ' . $_SERVER['HTTP_COOKIE'] . "\r\n"));
        // Send cookies for session_start of target
        $context = stream_context_create($opts);
        session_write_close();
        $json = json_decode(json_clean_line_breaks(file_get_contents($uri, false, $context)), true);
    }
    $xml = jsonToXML($json);
    $xml = stripInvalidXml($xml);
} else {
    $xml = file_get_contents($uri);
}
if (false === $xml) {
    echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"></rdf:RDF>';
    exit;
}
if (empty($xsl)) {
    echo $xml;
    exit;
}
$is_html = false !== stripos(substr(trim($xml), 0, 200), '<html') ? true : false;
$XML = new DOMDocument();
if ($is_html) {
    @$XML->loadHTML($xml);
Example #5
0
    //$file = new fixed2CSV( '/data/websites/MINES_Survey/proxyfiles/data/patload.' . $today);
    $file = new fixed2CSV('/usr/local/data/patload.' . $today . ".sif");
    /*** The start position=>width of each field ***/
    // The below $file->fields = array() implements the magic method __set method
    // to set the array.  Not sure why not create function to set array?  Would be more efficient, but not as cool?
    $csvHeaderRecord = "\"patron_id\"," . "\"patron_barcode_id_1\"," . "\"patron_barcode_1\"," . "\"user_group\"," . "\"status\"," . "\"barcode_modified_date_1\"," . "\"patron_barcode_id_2\"," . "\"patron_barcode_2\"," . "\"patron_group_2\"," . "\"barcode_status_2\"," . "\"barcode_modified_date_2\"," . "\"patron_barcode_id_3\"," . "\"patron_barcode_3\"," . "\"patron_group_3\"," . "\"barcode_status_3\"," . "\"barcode_modified_date_3\"," . "\"creationDate\"," . "\"expiry_date\"," . "\"patron_purge_date\"," . "\"voyager_date\"," . "\"voyager_updated\"," . "\"circulation_happening_location_code\"," . "\"userIdentifiers\"," . "\"primary_id\"," . "\"statistic_category\"," . "\"statistical_category_2\"," . "\"statistical_category_3\"," . "\"statistical_category_4\"," . "\"statistical_category_5\"," . "\"statistical_category_6\"," . "\"statistical_category_7\"," . "\"statistical_category_8\"," . "\"statistical_category_9\"," . "\"statistical_category_10\"," . "\"name_type\"," . "\"last_name\"," . "\"first_name\"," . "\"middle_name\"," . "\"title\"," . "\"historical_charges\"," . "\"claims_returned_count\"," . "\"self_shelved_count\"," . "\"lost_items_count\"," . "\"late_media_returns\"," . "\"historical_bookings\"," . "\"canceled_bookings\"," . "\"unclaimed_bookings\"," . "\"historical_callslips\"," . "\"historical_distributions\"," . "\"historical_short_loans\"," . "\"unclaimed_short_loans\"," . "\"address_count\"," . "\"address_id_01\"," . "\"address_type_01\"," . "\"address_status_code_01\"," . "\"startDate_01\"," . "\"endDate_01\"," . "\"line1_01\"," . "\"line2_01\"," . "\"line3_01\"," . "\"line4_01\"," . "\"line5_01\"," . "\"city_01\"," . "\"stateProvince_01\"," . "\"postalCode_01\"," . "\"country_01\"," . "\"phone_01\"," . "\"mobil_01\"," . "\"fax_01\"," . "\"other_01\"," . "\"date_added_updated_01\"," . "\"address_id_02\"," . "\"address_type_02\"," . "\"address_status_code_02\"," . "\"startDate_02\"," . "\"endDate_02\"," . "\"line1_02\"," . "\"line2_02\"," . "\"line3_02\"," . "\"line4_02\"," . "\"line5_02\"," . "\"city_02\"," . "\"stateProvince_02\"," . "\"postalCode_02\"," . "\"country_02\"," . "\"phone_02\"," . "\"mobil_02\"," . "\"fax_02\"," . "\"other_02\"," . "\"date_added_updated_02\"," . "\"address_id_03\"," . "\"address_type_03\"," . "\"address_status_code_03\"," . "\"startDate_03\"," . "\"endDate_03\"," . "\"line1_03\"," . "\"line2_03\"," . "\"line3_03\"," . "\"line4_03\"," . "\"line5_03\"," . "\"city_03\"," . "\"stateProvince_03\"," . "\"postalCode_03\"," . "\"country_03\"," . "\"phone_03\"," . "\"mobil_03\"," . "\"fax_03\"," . "\"other_03\"," . "\"date_added_updated_03\"";
    $outfile = new SplFileObject('/data/websites/MINES_Survey/proxyfiles/data/csvoutput.txt', "w");
    //echo "csvHeaderRecord-><br />".$csvHeaderRecord."<br/><br/>";
    $written = $outfile->fwrite($csvHeaderRecord . "\n");
    $file->fields = array(1 => 10, 11 => 10, 21 => 25, 46 => 10, 56 => 1, 57 => 10, 67 => 10, 77 => 25, 102 => 10, 112 => 1, 113 => 10, 123 => 10, 133 => 25, 158 => 10, 168 => 1, 169 => 10, 179 => 10, 189 => 10, 199 => 10, 209 => 10, 219 => 10, 229 => 10, 239 => 30, 269 => 11, 280 => 3, 283 => 3, 286 => 3, 289 => 3, 292 => 3, 295 => 3, 298 => 3, 301 => 3, 304 => 3, 307 => 3, 310 => 1, 311 => 30, 341 => 20, 361 => 20, 381 => 10, 391 => 10, 401 => 5, 406 => 5, 411 => 5, 416 => 5, 421 => 5, 426 => 5, 431 => 5, 436 => 5, 441 => 5, 446 => 5, 451 => 5, 456 => 1, 457 => 10, 467 => 1, 468 => 1, 469 => 10, 479 => 10, 489 => 50, 539 => 40, 579 => 40, 619 => 40, 659 => 40, 699 => 40, 739 => 7, 746 => 10, 756 => 20, 776 => 25, 801 => 25, 826 => 25, 851 => 25, 876 => 10, 886 => 10, 896 => 1, 897 => 1, 898 => 10, 908 => 10, 918 => 50, 968 => 40, 1008 => 40, 1048 => 40, 1088 => 40, 1128 => 40, 1168 => 7, 1175 => 10, 1185 => 20, 1205 => 25, 1230 => 25, 1255 => 25, 1280 => 25, 1305 => 10, 1315 => 10, 1325 => 1, 1326 => 1, 1327 => 10, 1337 => 10, 1347 => 50, 1397 => 40, 1437 => 40, 1477 => 40, 1517 => 40, 1557 => 40, 1597 => 7, 1604 => 10, 1614 => 20, 1634 => 25, 1659 => 25, 1684 => 25, 1709 => 25, 1734 => 10);
    //echo "processing line<br />";
    /*** output the converted lines ***/
    //$outfile = new SplFileObject('../proxyfiles/data/csvoutput.txt', "w");
    foreach ($file as $line) {
        //echo "line-><br />".$line."<br/><br/>";
        $line = stripInvalidXml($line);
        $written = $outfile->fwrite($line);
    }
    /*** a new instance ***/
    //$new = new fixed2CSV( '../proxyfiles/data/patload_20150126.txt' );
    /*** get only first and third fields ***/
    //$new->fields = array(0=>10, 25=>20);
    /*** output only the first and third fields ***/
    //foreach( $new as $line )
    //{
    //    echo $line;
    //}
    $file = null;
    // close out file.
    include 'VoyagerCSVtoXML_v2.3.php';
} catch (Exception $e) {