/** * Intercepts the current HTTP request and serves an RDF document * if the content negotiation results in a supported RDF format */ public function intercept() { $rdf_format = $this->contentNegotiation->negotiateRdfContentType($_SERVER['HTTP_ACCEPT']); if ($rdf_format != null) { global $wp_query; $graph = $this->rdfBuilder->buildGraph(get_queried_object(), $wp_query); $this->rdfPrinter->printGraph($graph, $rdf_format); exit; } }
public function testBuildGraphForBlogWithPosts() { $builder = new RdfBuilder(new MockedLocalWebIdService()); $firstPost = new \WP_Post(); $firstPost->ID = 1; $firstPost->post_type = 'post'; $firstPost->post_title = 'My first blog post'; $firstPost->post_modified = '2013-04-17 20:16:41'; $firstPost->post_date = '2013-03-17 19:16:41'; $firstPost->post_content = 'The posts content'; $firstPost->post_author = 2; $secondPost = new \WP_Post(); $secondPost->ID = 2; $secondPost->post_type = 'post'; $secondPost->post_title = 'My second blog post'; $posts = array($firstPost, $secondPost); $graph = $builder->buildGraph(null, new \WP_Query($posts)); $blogUri = 'http://example.com#it'; $blog = $graph->resource($blogUri); $containedPosts = $blog->allResources('sioc:container_of'); $this->assertEquals(2, count($containedPosts), 'Blog should have 2 posts'); $containedPost = array_shift($containedPosts); $this->assertEquals('http://example.com/1#it', $containedPost->getUri()); $this->assertEquals('sioct:BlogPost', $containedPost->type()); $this->assertProperty($containedPost, 'dc:title', 'My first blog post'); $createdPost2 = array_shift($containedPosts); $this->assertEquals('http://example.com/2#it', $createdPost2->getUri()); $this->assertEquals('sioct:BlogPost', $createdPost2->type()); $this->assertProperty($createdPost2, 'dc:title', 'My second blog post'); }