Plugin Directory

Changeset 715544


Ignore:
Timestamp:
05/20/2013 10:36:19 AM (13 years ago)
Author:
aveltens
Message:

Version 0.2

Location:
wp-linked-data/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • wp-linked-data/trunk/rdf/RdfBuilder.php

    r705406 r715544  
    1010    public function buildGraph ($queriedObject, $wpQuery) {
    1111        $graph = new \EasyRdf_Graph();
     12        if (!$queriedObject) {
     13            return $this->buildGraphForBlog ($graph, $wpQuery);
     14        }
    1215        if ($queriedObject) {
    1316            if ($queriedObject instanceof \WP_User) {
     
    3639
    3740        $post_resource->set ('dc:title', $post->post_title);
    38         $post_resource->set ('dc:content', $post->post_content);
     41        $post_resource->set ('sioc:content', strip_tags($post->post_content));
    3942        $post_resource->set ('dc:modified', \EasyRdf_Literal_Date::parse($post->post_modified));
    4043        $post_resource->set ('dc:created', \EasyRdf_Literal_Date::parse($post->post_date));
    4144
    4245        $author = get_userdata ($post->post_author);
    43         $author_uri = $this->getAuthorUri ($author);
    44         $author_resource = $graph->resource ($author_uri, 'foaf:Person');
    45         $author_resource->set ('foaf:name', $author->display_name);
    46         $post_resource->set ('dc:creator', $author_resource);
     46        $accountUri = $this->getAccountUri ($author);
     47        $accountResource = $graph->resource ($accountUri, 'sioc:UserAccount');
     48        $accountResource->set ('sioc:name', $author->display_name);
     49        $post_resource->set ('sioc:has_creator', $accountResource);
     50
     51        $blogUri = $this->getBlogUri ();
     52        $blogResource = $graph->resource ($blogUri, 'sioct:Weblog');
     53        $post_resource->set ('sioc:has_container', $blogResource);
    4754
    4855        return $graph;
     
    5461
    5562    private function getAuthorUri ($author) {
    56         return untrailingslashit (get_author_posts_url ($author->ID)) . '#me';
     63        return $this->getAuthorDocumentUri ($author) . '#me';
     64    }
     65
     66    private function getAccountUri ($author) {
     67        return $this->getAuthorDocumentUri ($author) . '#account';
     68    }
     69
     70    private function getAuthorDocumentUri ($author) {
     71        return untrailingslashit (get_author_posts_url ($author->ID));
    5772    }
    5873
     
    6681    private function buildGraphForUser ($graph, $user, $wpQuery) {
    6782        $author_uri = $this->getAuthorUri ($user);
     83        $account_uri = $this->getAccountUri ($user);
    6884        $author_resource = $graph->resource ($author_uri, 'foaf:Person');
     85        $account_resource = $graph->resource ($account_uri, 'sioc:UserAccount');
     86
    6987        $author_resource->set ('foaf:name', $user->display_name ?: null);
    7088        $author_resource->set ('foaf:givenName', $user->user_firstname ?: null);
     
    7290        $author_resource->set ('foaf:nick', $user->nickname ?: null);
    7391        $author_resource->set ('bio:olb', $user->user_description ?: null);
     92        $author_resource->set ('foaf:account', $account_resource);
    7493
     94        $account_resource->set ('sioc:name', $user->display_name ?: null);
     95        $account_resource->set ('sioc:account_of', $author_resource);
     96
     97        $this->linkAllPosts ($wpQuery, $graph, $account_resource, 'sioc:creator_of');
     98        return $graph;
     99    }
     100
     101    private function linkAllPosts ($wpQuery, $graph, $resourceToLink, $property) {
    75102        while ($wpQuery->have_posts ()) {
    76103            $wpQuery->next_post ();
     
    79106            $post_resource = $graph->resource ($post_uri, 'sioct:BlogPost');
    80107            $post_resource->set ('dc:title', $post->post_title);
    81             $author_resource->add ('foaf:publications', $post_resource);
     108            $resourceToLink->add ($property, $post_resource);
     109        }
     110    }
    82111
    83         }
     112    private function buildGraphForBlog ($graph, $wpQuery) {
     113        $blogUri = $this->getBlogUri ();
     114        $blogResource = $graph->resource ($blogUri, 'sioct:Weblog');
     115        $blogResource->set ('rdfs:label', get_bloginfo('name') ?: null);
     116        $blogResource->set ('rdfs:comment', get_bloginfo('description') ?: null);
     117        $this->linkAllPosts ($wpQuery, $graph, $blogResource, 'sioc:container_of');
    84118        return $graph;
    85119    }
    86120
     121    private function getBlogUri () {
     122        return site_url () . '#it';
     123    }
     124
    87125}
  • wp-linked-data/trunk/wp-linked-data.php

    r705406 r715544  
    22/*
    33Plugin Name: wp-linked-data
    4 Plugin URI: http://datenwissen.de
     4Plugin URI: http://wordpress.org/extend/plugins/wp-linked-data/
    55Description: Publishing blog contents as linked data
    6 Version: 0.1
     6Version: 0.2
    77Author: Angelo Veltens
    88Author URI: http://me.desone.org/person/aveltens#me
Note: See TracChangeset for help on using the changeset viewer.