public function do_feed_rdf() { $format = $this->map_mime_request(); include 'library/EasyRdf.php'; include 'library/object-handlers.php'; include 'library/php-json-ld.php'; $doc[] = (object) array("@id" => "http://dbpedia.org/resource/John_Lennon", "http://schema.org/name" => "Manu Sporny", "http://schema.org/url" => (object) array("@id" => "http://manu.sporny.org/"), "http://schema.org/image" => (object) array("@id" => "http://manu.sporny.org/images/manu.png")); $doc[] = (object) array("@id" => "http://dbpedia.org/resource/John_walton", "http://schema.org/name" => "Manu walton", "http://schema.org/url" => (object) array("@id" => "http://manu.sporny.org/"), "http://schema.org/image" => (object) array("@id" => "http://manu.sporny.org/images/manu.png")); $context = (object) array("name" => "http://schema.org/name", "homepage" => (object) array("@id" => "http://schema.org/url", "@type" => "@id"), "image" => (object) array("@id" => "http://schema.org/image", "@type" => "@id")); // compact a document according to a particular context // see: http://json-ld.org/spec/latest/json-ld/#compacted-document-form $compacted = jsonld_compact($doc, $context); //echo json_encode($compacted, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); foreach ($this->return_namespaces() as $key => $value) { EasyRdf_Namespace::set($key, $value); } EasyRdf_Namespace::delete("rss"); $graph = new EasyRdf_Graph(); $lh_rdf_object_handlers = new LH_rdf_object_handlers($format); if ($theobject = get_queried_object()) { $thetype = get_class($theobject); $action = "do_content_" . $thetype; $graph = $lh_rdf_object_handlers->{$action}($graph, $theobject); } elseif (is_attachment()) { global $wp_query; if ($wp_query->query[attachment_id]) { $args = array('post__in' => array($wp_query->query[attachment_id]), 'post_type' => 'attachment'); } else { $args = array('name' => $wp_query->query[attachment], 'post_type' => 'attachment', 'posts_per_page' => 1); } $attachment_post = get_posts($args); $graph = $lh_rdf_object_handlers->do_content_attachment($graph, $attachment_post[0]); } else { global $wp_query; $graph = $lh_rdf_object_handlers->do_content_wp_query($graph, $wp_query); } $graph = apply_filters("lh_rdf_graph", $graph); $serialize = $graph->serialise($format); $etag = md5($serialize); header("Etag: " . $etag); echo $serialize; }
/** * THE FUNCTION: Generates the Feed in the proper format based on the request **/ public function do_feed_rdf() { // Get the current format the client is asking for $format = $this->map_mime_request(); // Setting namespace value foreach ($this->return_namespaces() as $key => $value) { EasyRdf_Namespace::set($key, $value); } // Initializing the Rdf_graph $graph = new EasyRdf_Graph(); // Initializing objects handlers $lh_rdf_object_handlers = new LH_rdf_object_handlers($format); // If we do get the object queried for (valid for Post/Page/Feed) if ($queried_object = get_queried_object()) { // Get the current queried object class $queried_object_type = get_class($queried_object); // Compute the queried object type associated action $action = "do_content_" . $queried_object_type; // Call the related action as a method of the handler and get the initialized RDF Graph $graph = $lh_rdf_object_handlers->{$action}($graph, $queried_object); // If the queried object is an attachment } elseif (is_attachment()) { global $wp_query; // Querying the attachment related data if ($wp_query->query[attachment_id]) { $args = array('post__in' => array($wp_query->query[attachment_id]), 'post_type' => 'attachment'); } else { $args = array('name' => $wp_query->query[attachment], 'post_type' => 'attachment', 'posts_per_page' => 1); } // Get related post based on data initialized above $attachment_post = get_posts($args); // Initialize and get the associated RDF graph $graph = $lh_rdf_object_handlers->do_content_attachment($graph, $attachment_post[0]); // If the content is something else } else { global $wp_query; // Call generic content related method to initialize the RDF graph $graph = $lh_rdf_object_handlers->do_content_wp_query($graph, $wp_query); } // Serialiazing the graph we get in the proper format using the EasyRdf_Graph library $serialized_graph = $graph->serialise($format); // Generating proper etag $etag = md5($serialized_graph); // Adding the Etag information to the response headers header("Etag: " . $etag); // Display the whole graph echo $serialized_graph; }