public function testBuildGraphForPost()
 {
     \EasyRdf_Namespace::set('sioct', 'http://rdfs.org/sioc/types#');
     $builder = new RdfBuilder(new MockedLocalWebIdService());
     $post = new \WP_Post();
     $post->ID = 1;
     $post->post_type = 'post';
     $post->post_title = 'My first blog post';
     $post->post_modified = '2013-04-17 20:16:41';
     $post->post_date = '2013-03-17 19:16:41';
     $post->post_content = 'The posts content';
     $post->post_author = 1;
     $graph = $builder->buildGraph($post, null);
     $postUri = 'http://example.com/1#it';
     $it = $graph->resource($postUri);
     $this->assertEquals('sioct:BlogPost', $it->type());
     $this->assertProperty($it, 'dc:title', 'My first blog post');
     $this->assertProperty($it, 'sioc:content', 'The posts content');
     $this->assertProperty($it, 'dc:modified', \EasyRdf_Literal_Date::parse('2013-04-17 20:16:41'));
     $this->assertProperty($it, 'dc:created', \EasyRdf_Literal_Date::parse('2013-03-17 19:16:41'));
     $blogResource = $graph->resource('http://example.com#it');
     $this->assertProperty($it, 'sioc:has_container', $blogResource);
     $creator = $graph->get($postUri, 'sioc:has_creator');
     $this->assertEquals('http://example.com/author/1#account', $creator->getUri());
     $this->assertEquals('sioc:UserAccount', $creator->type());
     $this->assertProperty($creator, 'sioc:name', 'Mario Mustermann');
 }
Example #2
0
 /** Constructor for creating a new date literal
  *
  * The date is parsed and stored internally using a DateTime object.
  * @see DateTime
  *
  * @param  mixed  $value     The value of the literal
  * @param  string $lang      Should be null (literals with a datatype can't have a language)
  * @param  string $datatype  Optional datatype (default 'xsd:date')
  * @return object EasyRdf_Literal_Date
  */
 public function __construct($value, $lang = null, $datatype = null)
 {
     // Convert the value into a DateTime object, if it isn't already
     if (!$value instanceof DateTime) {
         $value = new DateTime(strval($value));
     }
     parent::__construct($value, null, $datatype);
 }
 private function buildGraphForPost($graph, $post)
 {
     $type = $this->getRdfTypeForPost($post);
     $post_uri = $this->getPostUri($post);
     $post_resource = $graph->resource($post_uri, $type);
     $post_resource->set('dc:title', $post->post_title);
     $post_resource->set('sioc:content', strip_tags($post->post_content));
     $post_resource->set('dc:modified', \EasyRdf_Literal_Date::parse($post->post_modified));
     $post_resource->set('dc:created', \EasyRdf_Literal_Date::parse($post->post_date));
     $author = get_userdata($post->post_author);
     $accountUri = $this->webIdService->getAccountUri($author);
     $accountResource = $graph->resource($accountUri, 'sioc:UserAccount');
     $accountResource->set('sioc:name', $author->display_name);
     $post_resource->set('sioc:has_creator', $accountResource);
     $blogUri = $this->getBlogUri();
     $blogResource = $graph->resource($blogUri, 'sioct:Weblog');
     $post_resource->set('sioc:has_container', $blogResource);
     return $graph;
 }
Example #4
0
 public function do_content_WP_Post($graph, $post)
 {
     $post_resource = $graph->resource($post->guid, 'sioc:Post');
     $graph = apply_filters("lh_rdf_nodes", $graph, $post->guid, $post);
     $graph = $this->WP_Post_types($graph, $post);
     $post_resource->set('dc:title', $post->post_title);
     $post_resource->set('dcterms:identifier', $post->ID);
     $post_resource->set('dc:modified', \EasyRdf_Literal_Date::parse($post->post_modified));
     $post_resource->set('dc:created', \EasyRdf_Literal_Date::parse($post->post_date));
     $post_resource->set('sioc:link', $graph->resource(get_the_permalink()));
     $post_resource->set('sioc:has_creator', $graph->resource($this->return_user_uri($post->post_author)));
     $post_resource->set('sioc:has_container', $graph->resource(get_bloginfo("url") . "/#posts"));
     $authorseealso = $graph->resource($this->return_user_uri($post->post_author));
     $authorseealso->set('rdfs:seeAlso', $graph->resource($this->return_seeAlso_resource(get_author_posts_url($post->post_author)) ?: null));
     $post_resource->set('dc:abstract', strip_tags($post->post_excerpt));
     $post_resource->set('content:encoded', new EasyRdf_Literal_XML("<![CDATA[" . do_shortcode($post->post_content) . "]]>"));
     $post_resource->set('sioc:content', strip_tags(do_shortcode($post->post_content)));
     if (has_post_thumbnail()) {
         $thumbnail = get_post(get_post_thumbnail_id());
         $post_resource->set('foaf:depiction', $graph->resource($thumbnail->guid));
         $graph->resource($thumbnail->guid)->set('rdfs:seeAlso', $graph->resource(add_query_arg('feed', 'lhrdf', get_attachment_link($thumbnail->ID)) ?: null));
     }
     $graph = $this->WP_Post_taxonomies($graph, $post);
     $graph = $this->WP_Post_attachments($graph, $post);
     return $graph;
 }
 public function testDate()
 {
     $literal = new EasyRdf_Literal_Date('5th August 2011');
     $this->assertEquals(5, $literal->day());
 }
Example #6
0
 public function testDate()
 {
     $literal = new EasyRdf_Literal_Date('2011-08-05');
     $this->assertSame(5, $literal->day());
 }