function rss_parse($rss)
 {
     $base = $rss;
     //get XML content
     $xmlResponse = '';
     //get RSS Content
     $ch = curl_init();
     /// initialize a cURL session
     curl_setopt($ch, CURLOPT_URL, trim($rss));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $xmlResponse = curl_exec($ch);
     curl_close($ch);
     //check result
     if (!is_string($xmlResponse) || !strlen($xmlResponse)) {
         $this->errorText .= '<span class="' . $this->CssContentStyle . '">Cannot open RSS URL ' . trim($rss) . '</span>';
         return false;
     }
     $rdf = new Rdf_parser();
     $rdf->rdf_parser_create(NULL);
     $rdf->rdf_set_user_data($statements);
     // Here we'd have to use a rdf_set_object and then call the object method if set...
     $rdf->rdf_set_user_data($this);
     $rdf->rdf_set_statement_handler("my_statement_handler");
     $rdf->rdf_set_warning_handler("my_warning_handler");
     $rdf->rdf_set_base($base);
     if (!$rdf->rdf_parse($xmlResponse, strlen($xmlResponse), 0)) {
         $this->errorText = 'Error <' . xml_get_error_code($rdf->rdf_get_xml_parser()) . '> at line ' . xml_get_current_line_number($rdf->rdf_get_xml_parser());
         return false;
     }
     $rdf->rdf_parser_free();
     return true;
 }
Esempio n. 2
0
 function rss_parse_data($data)
 {
     $rdf = new Rdf_parser();
     $rdf->rdf_parser_create(NULL);
     $rdf->rdf_set_user_data($statements);
     // Here we'd have to use a rdf_set_object and then call the object method if set...
     $rdf->rdf_set_user_data($this);
     $rdf->rdf_set_statement_handler("my_statement_handler");
     $rdf->rdf_set_warning_handler("my_warning_handler");
     $rdf->rdf_set_base('');
     $done = false;
     if (!$rdf->rdf_parse($data, strlen($data), true)) {
         printf("**** ERROR **** : %s at line %s", print xml_get_error_code($rdf->rdf_get_xml_parser()), print xml_get_current_line_number($rdf->rdf_get_xml_parser()));
         return false;
     }
     $rdf->rdf_parser_free();
     return true;
 }
Esempio n. 3
0
$input = fopen($base, "r");
$rdf = new Rdf_parser();
$rdf->rdf_parser_create(NULL);
$rdf->rdf_set_user_data($statements);
$rdf->rdf_set_statement_handler("my_statement_handler");
$rdf->rdf_set_parse_type_literal_handler("my_start_parse_type_literal_handler", "my_end_parse_type_literal_handler");
$rdf->rdf_set_element_handler("my_start_element_handler", "my_end_element_handler");
$rdf->rdf_set_character_data_handler("my_character_data_handler");
$rdf->rdf_set_warning_handler("my_warning_handler");
$rdf->rdf_set_base($base);
$done = false;
while (!$done) {
    $buf = fread($input, 512);
    $done = feof($input);
    if (!$rdf->rdf_parse($buf, strlen($buf), feof($input))) {
        printf("**** ERROR **** : %s at line %s", print xml_get_error_code($rdf->rdf_get_xml_parser()), print xml_get_current_line_number($rdf->rdf_get_xml_parser()));
        return 1;
    }
}
/* close file. */
fclose($input);
$rdf->rdf_parser_free();
printf("Total statements: " . $statements);
/* handlers */
function my_statement_handler(&$user_data, $subject_type, $subject, $predicate, $ordinal, $object_type, $object, $xml_lang)
{
    //$statements = $user_data;
    ++$user_data;
    printf("ordinal({$ordinal}) triple(");
    switch ($subject_type) {
        case RDF_SUBJECT_TYPE_URI: