'."\n"; $output .= ''; $output .= ''."\n"; $output .= ' '. $project_name .''."\n"; $output .= ' '. _escape_for_rdf($replacer, $project_information['short_description']) .''."\n"; $output .= ' '. _escape_for_rdf($replacer, $project_information['description']) .''."\n"; $os = explode(',', $project_information['operating_system']); foreach ($os as $o) { $output .= ' '. _escape_for_rdf($replacer, trim($o)) .''."\n"; } $pl = explode(',', $project_information['programming_language']); foreach ($pl as $p) { $output .= ' '. _escape_for_rdf($replacer, trim($p)) .''."\n"; } // category. actually should be links (rdf:resource="...") $cats = explode(',', $project_information['category']); foreach ($cats as $cat) { $output .= ' '. _escape_for_rdf($replacer, trim($cat)) .''."\n"; } // licensce. actually should be links (rdf:resource="...") to RDF resources of the license $lic = explode(',', $project_information['license']); foreach ($lic as $l) { $output .= ' '. _escape_for_rdf($replacer, trim($l)) .''."\n"; } $project_base_url = get_origo_project_link($project_name); $output .= ' '."\n"; $output .= ' '."\n"; $output .= ' '."\n"; $output .= ' '."\n"; $output .= ' '."\n"; $output .= ' '."\n"; $output .= ' '."\n"; $output .= ' '."\n"; $output .= ' '."\n"; $output .= ' '."\n"; $output .= ''."\n"; $output .= ''."\n"; header('Content-Type: application/rdf+xml'); print $output; } // -------------------------------------------------------- // Helper functions /* * Utility function for facilitating proper encoding of UTF-8 characters in our data into RDF compatible form. * The proper encoding produced by this function (as opposed to just using "htmlentities") was checked with * the RDF validator at http://www.w3.org/RDF/Validator/ * * Parameters: * $replacer: Unicode replacer, see class below * $string: The text to be replaced. * * Return value: * Encoded string */ function _escape_for_rdf($replacer, $string) { $entities = $replacer->UTF8entities($string); return htmlentities($entities, NULL, NULL, FALSE); } /** * Utility class for converting strings from UTF-8 into an NCR [numeric character reference]. * Taken from http://www.php.net/manual/en/function.htmlentities.php#92105 */ class unicode_replace_entities { public function UTF8entities($content="") { $contents = $this->unicode_string_to_array($content); $swap = ""; $iCount = count($contents); for ($o=0;$o<$iCount;$o++) { $contents[$o] = $this->unicode_entity_replace($contents[$o]); $swap .= $contents[$o]; } return mb_convert_encoding($swap, "UTF-8"); //not really necessary, but why not. } public function unicode_string_to_array( $string ) { //adjwilli $strlen = mb_strlen($string); while ($strlen) { $array[] = mb_substr( $string, 0, 1, "UTF-8" ); $string = mb_substr( $string, 1, $strlen, "UTF-8" ); $strlen = mb_strlen( $string ); } return $array; } public function unicode_entity_replace($c) { //m. perez $h = ord($c{0}); if ($h <= 0x7F) { return $c; } elseif ($h < 0xC2) { return $c; } if ($h <= 0xDF) { $h = ($h & 0x1F) << 6 | (ord($c{1}) & 0x3F); $h = "&#" . $h . ";"; return $h; } elseif ($h <= 0xEF) { $h = ($h & 0x0F) << 12 | (ord($c{1}) & 0x3F) << 6 | (ord($c{2}) & 0x3F); $h = "&#" . $h . ";"; return $h; } elseif ($h <= 0xF4) { $h = ($h & 0x0F) << 18 | (ord($c{1}) & 0x3F) << 12 | (ord($c{2}) & 0x3F) << 6 | (ord($c{3}) & 0x3F); $h = "&#" . $h . ";"; return $h; } } }