topical media & game development

talk show tell print

basic-xml-13-index.htm / htm



  <?xml version="1.0" encoding="utf-8"?><!-- generator="wordpress/1.2-epsilon-RC1" -->
  <rdf:RDF
          xmlns="http://purl.org/rss/1.0/"
          xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
          xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
          xmlns:dc="http://purl.org/dc/elements/1.1/"
          xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
          xmlns:foaf="http://xmlns.com/foaf/0.1/"
          xmlns:admin="http://webns.net/mvcb/"
          xmlns:content="http://purl.org/rss/1.0/modules/content/"
  >
  <channel rdf:about="http://purl.org/net/morten/blog/rdf">
          <title>Binary Relations</title>
          <link>http://purl.org/net/morten/blog>
          <description>Reflections on the web</description>
          <dc:language>en</dc:language>
          <dc:date>2004-05-21T22:40:27Z</dc:date>
          <admin:generatorAgent rdf:resource="http://wordpress.org/?v=1.2-epsilon-RC1"/>
          <sy:updatePeriod>daily</sy:updatePeriod>
          <sy:updateFrequency>1</sy:updateFrequency>
          <sy:updateBase>2004-01-01T12:00+00:00</sy:updateBase>
          <items>
                  <rdf:Seq>
                                          <rdf:li rdf:resource="http://purl.org/net/morten/blog/archives/2004/05/21/foaf-output-from-wordpress"/>
                                          <rdf:li rdf:resource="http://purl.org/net/morten/blog/archives/2004/05/21/wordpress-presentation-hacks"/>
                                          <rdf:li rdf:resource="http://purl.org/net/morten/blog/archives/2004/05/20/wordpress-and-i18n"/>
                                          <rdf:li rdf:resource="http://purl.org/net/morten/blog/archives/2004/05/20/improving-rss-output-from-wordpress"/>
                                          <rdf:li rdf:resource="http://purl.org/net/morten/blog/archives/2004/05/20/yet-another-semweb-blogger"/>
                                  </rdf:Seq>
          </items>
  </channel>
  <item rdf:about="http://purl.org/net/morten/blog/archives/2004/05/21/foaf-output-from-wordpress">
          <title>FOAF output from WordPress</title>
          <link>http://purl.org/net/morten/blog/archives/2004/05/21/foaf-output-from-wordpress>
          <dc:date>2004-05-21T21:35:49Z</dc:date>
          <dc:creator>mortenf</dc:creator>
          <foaf:maker>
                  <foaf:Person>
                          <foaf:name>Morten Frederiksen</foaf:name>
                          <foaf:nick>mortenf</foaf:nick>
                          <foaf:mbox_sha1sum>65b983bb397fb71849da910996741752ace8369b</foaf:mbox_sha1sum>
                          <foaf:weblog rdf:resource="http://purl.org/net/morten/blog"/>
                  </foaf:Person>
          </foaf:maker>
          
          <dc:subject>FOAF</dc:subject><foaf:topic rdf:parseType="Resource"><dc:title>FOAF</dc:title><foaf:page rdf:resource="http://www.foaf-project.org/"/></foaf:topic>
          <dc:subject>WordPress</dc:subject><foaf:topic rdf:parseType="Resource"><dc:title>WordPress</dc:title><foaf:page rdf:resource="http://wordpress.org/"/></foaf:topic>        <description>The one where the author "homepage" is extended and a FOAF profile document is created. </description>
          <content:encoded><![CDATA[<p>A few days ago, <a href="http://www.livejournal.com/users/crschmidt/">Christopher Schmidt</a> mentioned <a href="http://www.livejournal.com/users/crschmidt/252710.html?thread=1153318#t1153318">in a comment</a> that he had been hacking on FOAF export for WordPress. He kindly let me take a look at his work, and in addition posted a <a href="http://rdfweb.org/pipermail/rdfweb-dev/2004-May/013286.html">message to rdfweb-dev</a>.</p>
          <p>In short, he had created a set of dynamic stand-alone profile pages, one with HTML output and one with RDF/XML output using FOAF, in a single file, <code>/profile2.php</code>.</p>
          <p>Seeing that, it dawned on me: WordPress already has a &#8220;profile&#8221; page for each of the authors, likely at <code>/archives/author/&lt;login&gt;/</code> (depending on the permalink structure defined) &#8212; and it even has a template name: <code>the_author_posts_link</code>. In its default incarnation it&#8217;s simply a list of the posts by that author, but turning it into a profile page by also showing the basic information and linked friends didn&#8217;t seem too hard.</p>
          <p><a id="more-7"></a></p>
          <p>So, first order of business is making the profile page &#8220;visible&#8221; by linking to it from the author name displayed with each post, by hacking in <code>/index.php</code>:</p>
          <pre class="code">&lt;?php _e("Filed under:"); ?&gt; &lt;?php the_category() ?&gt; &amp;#8212;
    &lt;?php the_author<ins>_posts_link</ins>(); ?&gt;
    @ &lt;?php the_time() ?&gt;
    &lt;?php edit_post_link(); ?&gt;</pre>
          <p>Next up is actually displaying the profile information when desired &#8212; when an author is specified as the search criteria (in <code>/index.php</code>):</p>
          <pre class="code">&lt;div id="content"&gt;
  <ins>&lt;?php if ('&#8217; != author): ?&gt;
    &lt;h2&gt;Author profile for &lt;?php the_author(); ?&gt;&lt;/h2&gt;
    &lt;div class="profile"&gt;
      &lt;?php the_profile(); ?&gt;
    &lt;/div&gt;
  &lt;?php endif; ?&gt;</ins>
  &lt;?php if (posts) : foreach (posts as post) : start_wp(); ?&gt; </pre>
          <p>This is not enough however, since the template <code>the_profile</code> isn&#8217;t defined yet. This is done in <code><a href="/morten/2004/05/wp-profile.php.txt">wp-profile.php.txt</a></code> (rename to <code>wp-profile.php</code> and place in root directory), which is an extended version of Christopher Schmidt&#8217;s original.</p>
          <p>This new version now also includes relationships based on the <a href="http://gmpg.org/xfn/1">XFN</a> link <code>rel</code> definitions, most of which are also translated into terms from the <a href="http://vocab.org/relationship/">relationship vocabulary</a>. This last task provided for a few challenges.</p>
          <p>First, as has been pointed out by <a href="http://www.ldodds.com/blog/">Leigh Dodds</a> in his post simply titled <a href="http://www.ldodds.com/blog/archives/000105.html">XFN</a>, the information expressed with XFN is incomplete as compared to FOAF and a few assumptions are needed, so if you intend to use this code, make sure you fill out the link fields in the link manager as follows, otherwise the FOAF output will be wrong:</p>
          <ul>
          <li>URI: Link to weblog of the person.</li>
          <li>Link Name: Name of the weblog.</li>
          <li>Short description: Name of the person.</li>
          </ul>
          <p>Second, the relationship vocabulary doesn&#8217;t have equivalent terms for the XFN relationships <code>muse</code>, <code>crush</code>, <code>date</code>, and <code>sweetheart</code>, so these are simply ignored in the translation process. Also, the relationship terms <code>childOf</code> and <code>parentOf</code> seems to be incorrectly or at least vaguely specified.</p>
          <p>Next up is making sure that the actual FOAF output in RDF/XML is sent when requested. For this to work, a few extra lines at the top of <code>/index.php</code> are needed:</p>
          <pre class="code">&lt;?php
  /* Don't remove this line. */
  require('./wp-blog-header.php');
  <ins>if ('&#8217; != author) {
    authordata = get_userdata(author);
    require(&#8217;./wp-profile.php&#8217;);
  }</ins>
  ?&gt;</pre>
          <p>The final step is adding a link element, for <a href="http://rdfweb.org/topic/Autodiscovery">FOAF autodiscovery</a>, to the head of the HTML profile page, also in <code>/index.php</code>:</p>
          <pre class="code">&lt;link rel="alternate" type="application/rdf+xml" title="RSS 1.0" href="&lt;?php bloginfo('rdf_url'); ?&gt;" /&gt;
  <ins>  &lt;?php if ('&#8217; != author): ?&gt;
      &lt;link rel="meta&#8221; type="application/rdf+xml&#8221; title="FOAF&#8221; href="&lt;?php print get_author_link(0, authordata-&gt;ID, authordata-&gt;user_nicename); ?&gt;?format=rdf&#8221; /&gt;
  &lt;?php endif; ?&gt;</ins></pre>
          <p>Phew, that should do it, see for yourself on <a href="/morten/blog/?author_name=mortenf">my profile page</a>.</p>
          <p>Next on the agenda might be integrating with a triple store&#8230;</p>]]></content:encoded>
  
  </item>
  <item rdf:about="http://purl.org/net/morten/blog/archives/2004/05/21/wordpress-presentation-hacks">
          <title>WordPress presentation hacks</title>
          <link>http://purl.org/net/morten/blog/archives/2004/05/21/wordpress-presentation-hacks>
          <dc:date>2004-05-21T13:30:45Z</dc:date>
          <dc:creator>mortenf</dc:creator>
          <foaf:maker>
                  <foaf:Person>
                          <foaf:name>Morten Frederiksen</foaf:name>
                          <foaf:nick>mortenf</foaf:nick>
                          <foaf:mbox_sha1sum>65b983bb397fb71849da910996741752ace8369b</foaf:mbox_sha1sum>
                          <foaf:weblog rdf:resource="http://purl.org/net/morten/blog"/>
                  </foaf:Person>
          </foaf:maker>
          
          <dc:subject>WordPress</dc:subject><foaf:topic rdf:parseType="Resource"><dc:title>WordPress</dc:title><foaf:page rdf:resource="http://wordpress.org/"/></foaf:topic>        <description>The one where next/previous links are added, excerpts are put to use, and categories are styled with icons. </description>
          <content:encoded><![CDATA[<p>One thing missing from the default WordPress setup is the lack of previous/next links. Fixing this is not really a problem though, as WordPress includes a number of <a href="http://wordpress.org/docs/template/">template functions</a>, among which are <code>next_post</code> and <code>previous_post</code>. Both of these take care of all the necessary logic, so that the correct links are displayed, and only when necessary, i.e. only when displaying a single post. I decided to put the links at the top of the post page, next to the post metadata such as categories and author (in the file <code>/index.php</code>):</p>
          <pre class="code">&lt;div class="meta"&gt;
  <ins>    &lt;span class="nav-prev"&gt;&lt;?php previous_post(&#8217;&amp;laquo; %&#8217;, &#8216;&#8217;); ?&gt;&lt;/span&gt;
      &lt;span class="nav-next"&gt;&lt;?php next_post(&#8217;% &amp;raquo;&#8217;, &#8216;&#8217;); ?&gt;&lt;/span&gt; </ins>
      &lt;?php _e("Filed under:"); ?&gt; &lt;?php the_category() ?&gt; &amp;#8212; &lt;?php the_author() ?&gt; @ &lt;?php the_time() ?&gt; &lt;?php edit_post_link(); ?&gt;
  &lt;/div&gt;</pre>
          <p>Another thing that I thought would be nice, was only showing excerpts on pages with a large number of posts. This is also quite easy, thanks to the <code>get_excerpt</code> template function:</p>
          <pre class="code"><ins>&lt;?php if(sizeof(posts)&gt;get_settings(&#8217;posts_per_page&#8217;)) : ?&gt;
    &lt;div class="storyexcerpt"&gt;
      &lt;?php the_excerpt(); ?&gt;
    &lt;/div&gt;
  &lt;?php else: ?&gt;</ins>
    &lt;div class="storycontent"&gt;
      &lt;?php the_content(); ?&gt;
    &lt;/div&gt;
    &lt;div class="feedback"&gt;
      &lt;?php wp_link_pages(); ?&gt;
      &lt;?php comments_popup_link(__(&#8217;Comments (0)&#8217;), __(&#8217;Comments (1)&#8217;), __(&#8217;Comments (%)&#8217;)); ?&gt;
    &lt;/div&gt;
  <ins>&lt;?php endif; ?&gt;</ins></pre>
          <p>Finally, I wanted to fiddle a little with the CSS, styling the posts so that a category specific icon is displayed next to posts in that category. To accomplish this, I had to add some category information to the <code>class<code>div</code> containing the post:</p>
          <pre class="code">&lt;div class="post<ins>&lt;? foreach(get_the_category() as cat){ print(&#8217; post-category-&#8217;.cat-&gt;category_nicename);}; ?&gt;</ins>&#8220;&gt;</pre>
          <p>With this in place, the CSS is easily tweaked to display an icon next to the post title (note that only the last one of the rules will be in effect for posts in multiple categories, so ordering is important):</p>
          <pre class="code"><ins>.post-category-wordpress h3 {
    background: url(/images/wp-button.png) no-repeat right;
  }
  .post-category-foaf h3 {
    background: url(/images/foaf-tiny.png) no-repeat right;
  }</ins></pre>
          <p>Improving this approach to be able to handle more than one category icon at a time is left as an exercise for the reader&#8230;</p>]]></content:encoded>
  
  </item>
  <item rdf:about="http://purl.org/net/morten/blog/archives/2004/05/20/wordpress-and-i18n">
          <title>WordPress and i18n</title>
          <link>http://purl.org/net/morten/blog/archives/2004/05/20/wordpress-and-i18n>
          <dc:date>2004-05-20T14:00:55Z</dc:date>
          <dc:creator>mortenf</dc:creator>
          <foaf:maker>
                  <foaf:Person>
                          <foaf:name>Morten Frederiksen</foaf:name>
                          <foaf:nick>mortenf</foaf:nick>
                          <foaf:mbox_sha1sum>65b983bb397fb71849da910996741752ace8369b</foaf:mbox_sha1sum>
                          <foaf:weblog rdf:resource="http://purl.org/net/morten/blog"/>
                  </foaf:Person>
          </foaf:maker>
          
          <dc:subject>WordPress</dc:subject><foaf:topic rdf:parseType="Resource"><dc:title>WordPress</dc:title><foaf:page rdf:resource="http://wordpress.org/"/></foaf:topic>        <description>The one where the post calendar is configured for weeks starting with monday. </description>
          <content:encoded><![CDATA[<p>While WordPress gives you choices for translating the names of the weekdays for use with the post calendar, it&#8217;s not possible by configuration to choose which day a week starts with. Being used to starting the week on a monday - there&#8217;s a reason saturday and sunday are referred to as <em>weekend</em>, I just had to tweak the PHP code to generate output suitable for non-US bloggers.</p>
          <p>The template function responsible for the calendar output is called <code>get_calendar</code>, and is located in the file <code>/wp-includes/template-functions-general.php</code>. The code that generates the actual output is located near the end of that function, and starts with a comment: <code>// See how much we should pad in the beginning</code>.</p>
          <p>On the line following the comment is a calculation of the padding to be performed before the first day of the month. This should be changed by substracting 1 from the existing result:</p>
          <pre class="code">pad = intval(date('w', unixmonth))<ins> - 1</ins>;</pre>
          <p>Following the initial padding is the loop that outputs each of the cells containing a day of the month. At the end of the loop it is decided whether to skip to the next row, originally done after outputting saturdays, now changed to skipping after sunday (weekday zero):</p>
          <pre class="code">if (<del>6</del><ins>0</ins> == date(&#8217;w', mktime(0, 0 , 0, thismonth, day, thisyear)))
      newrow = true;</pre>
          <p>Then, after the loop is finished, the padding after the last day of the month is determined. Just as the padding before the first day was decreased by one, the padding after the last day should be increased by one:</p>
          <pre class="code">pad = <del>7</del><ins>8</ins> - date(&#8217;w', mktime(0, 0 , 0, thismonth, day, thisyear));</pre>
          <p>The last thing to fix is the ordering of the labels in the calendar, and fortunately this is much easier. In the file <code>wp-includes/locale.php</code>, simply move the line assigning value to <code>weekday[0]</code> (sunday) to the end of the list, after assignment to <code>weekday[6]</code> (saturday):</p>
          <pre class="code">weekday[6] = __('Saturday');
  weekday[0] = __('Sunday');</pre>
          <p>The calendar should now display each week starting with monday.</p>]]></content:encoded>
  
  </item>
  <item rdf:about="http://purl.org/net/morten/blog/archives/2004/05/20/improving-rss-output-from-wordpress">
          <title>Improving RSS output from WordPress</title>
          <link>http://purl.org/net/morten/blog/archives/2004/05/20/improving-rss-output-from-wordpress>
          <dc:date>2004-05-20T12:40:04Z</dc:date>
          <dc:creator>mortenf</dc:creator>
          <foaf:maker>
                  <foaf:Person>
                          <foaf:name>Morten Frederiksen</foaf:name>
                          <foaf:nick>mortenf</foaf:nick>
                          <foaf:mbox_sha1sum>65b983bb397fb71849da910996741752ace8369b</foaf:mbox_sha1sum>
                          <foaf:weblog rdf:resource="http://purl.org/net/morten/blog"/>
                  </foaf:Person>
          </foaf:maker>
          
          <dc:subject>FOAF</dc:subject><foaf:topic rdf:parseType="Resource"><dc:title>FOAF</dc:title><foaf:page rdf:resource="http://www.foaf-project.org/"/></foaf:topic>
          <dc:subject>WordPress</dc:subject><foaf:topic rdf:parseType="Resource"><dc:title>WordPress</dc:title><foaf:page rdf:resource="http://wordpress.org/"/></foaf:topic>        <description>The one where FOAF properties are added to the RSS RDF/XML template and functions. </description>
          <content:encoded><![CDATA[<p>The default syndication output from WordPress is okay, but does leave room for improvement - even though it &#8220;defaults&#8221; to RSS 2.0, there&#8217;s <a href="http://purl.org/rss/1.0/">RSS</a> 1.0 hidden behind the scenes.</p>
          <p>The first order of action is to fix the default page template to point to the RDF/XML output instead of RSS 2.0. In the file <code>/index.php</code> there are <code>link</code> elements in the <code>head</code> section of the HTML output, switching to RSS 1.0 is quite easy, simply change the RSS 2.0 line to the following (and remove the link to the 0.92 version):</p>
          <pre class="code">&lt;link rel="alternate" type="application/rdf+xml" title="RSS 1.0" href="&lt;?php bloginfo('rdf_url'); ?&gt;" /&gt;</pre>
          <p>In the <i>meta</i> section there is also a couple of links, one for RSS 2.0 that will be replaced by a link to RSS 1.0, and one for comments that is just dropped (an RDF/XML version may be added at a later date):</p>
          <pre class="code">&lt;li&gt;&lt;a href="&lt;?php bloginfo('rdf_url'); ?&gt;" title="&lt;?php _e('Syndicate this site using RSS'); ?&gt;"&gt;&lt;?php _e('&lt;abbr title="RDF Site Summary"&gt;RSS&lt;/abbr&gt; 1.0'); ?&gt;&lt;/a&gt;&lt;/li&gt;</pre>
          <p>Now to the actual content of the RSS file: The default template includes, for each post, a <code>dc:creator</code> property that looks like this:</p>
          <pre class="code">&lt;dc:creator&gt;mortenf (mailto:mort&;amp;#101;n&amp;#64;&amp;#119;as&amp;#97;b.dk)&lt;/dc:creator&gt;</pre>
          <p>That&#8217;s not terribly helpful for the Semantic Web, so I&#8217;ve hacked the template <code>wp-rdf.php</code> to include the following <a href="http://www.foaf-project.org/">FOAF</a> structure instead:</p>
          <pre class="code">&lt;foaf:maker&gt;
    &lt;foaf:Person&gt;
      &lt;foaf:name&gt;&lt;?php the_author_firstname(); print ' '; the_author_lastname() ?&gt;&lt;/foaf:name&gt;
      &lt;foaf:nick&gt;&lt;?php the_author_login() ?&gt;&lt;/foaf:nick&gt;
      &lt;foaf:mbox_sha1sum&gt;&lt;?php print(bin2hex(mhash(MHASH_SHA1,'mailto:'.$authordata-&;gt;user_email))) ?&gt;&lt;/foaf:mbox_sha1sum&gt;
      &lt;foaf:weblog rdf:resource="&lt;?php bloginfo_rss('url') ?&gt;"/&gt;
    &lt;/foaf:Person&gt;
  &lt;/foaf:maker&gt;</pre>
          <p>In addition to this improvement, the indication of categories could also use a little tune-up. The default output shows categories through the use of <code>dc:subject</code>, which is quite allright but somewhat too vague - how could anyone know that my category <em>SemWeb/FOAF</em> is essentially the same as <a href="http://dannyayers.com/">Danny Ayers</a>&#8216; <em><a href="http://dannyayers.com/archives/category/knowledge/foaf/">Knowledge/FOAF</a></em> category? To make up for this, it is possible to use the <code>Description</code> field in WordPress&#8217; category system to assign a URI to each (or some) of the categories, and then generate appropriate statements by adding two lines to the <code>the_category_rss</code> template function in <code>/wp-includes/template-functions-category.php</code>:</p>
          <pre class="code">if(preg_match('|^w+:.+/|',category-&gt;category_description))
      the_list .= '&lt;foaf:topic rdf:parseType="Resource"&gt;&lt;dc:title&gt;'.category-&gt;cat_name.'&lt;/dc:title&gt;&lt;foaf:page rdf:resource="'.category-&gt;category_description.'"/&gt;&lt;/foaf:topic&gt;';</pre>
          <p>The results of these tweakings should show up nicely in the RSS feed - <a href="http://www.wasab.dk/morten/blog/feed/rdf">check it out here</a>.</p>]]></content:encoded>
  
  </item>
  <item rdf:about="http://purl.org/net/morten/blog/archives/2004/05/20/yet-another-semweb-blogger">
          <title>Yet another semweb blogger</title>
          <link>http://purl.org/net/morten/blog/archives/2004/05/20/yet-another-semweb-blogger>
          <dc:date>2004-05-20T10:49:48Z</dc:date>
          <dc:creator>mortenf</dc:creator>
          <foaf:maker>
                  <foaf:Person>
                          <foaf:name>Morten Frederiksen</foaf:name>
                          <foaf:nick>mortenf</foaf:nick>
                          <foaf:mbox_sha1sum>65b983bb397fb71849da910996741752ace8369b</foaf:mbox_sha1sum>
                          <foaf:weblog rdf:resource="http://purl.org/net/morten/blog"/>
                  </foaf:Person>
          </foaf:maker>
          
          <dc:subject>SemWeb</dc:subject><foaf:topic rdf:parseType="Resource"><dc:title>SemWeb</dc:title><foaf:page rdf:resource="http://www.w3.org/2001/sw/"/></foaf:topic>
          <dc:subject>Blogging</dc:subject>        <description>The one where Morten Frederiksen makes his debut as a blogger. </description>
          <content:encoded><![CDATA[<p>In the words of <a href="http://www.mnot.net/">Mark Nottingham</a>:</p>
          <blockquote><p>
  Everybody seems to have one, so here’s mine.
  </p></blockquote>
          <p>I&#8217;ve been biding my time, mostly because I&#8217;m still not sure that blogs provide an advantage over other means of community communication such as mailing lists and wikis, but also because I, like a lot of other people, want to roll my own tool. Time does not come cheap, and progress in that area is slow, so here it is - powered by <a href="http://wordpress.org/">WordPress</a>&#8230;</p>
          <p>The first posts will likely be on exactly that subject, WordPress, trying to make it fit my needs better, but as the title - Binary Relations - of my new weblog suggests, the writing here will focus on the Semantic Web with it&#8217;s social and technical implications. Subjects in that area will be <a href="http://www.redland.opensource.ac.uk/">Redland</a>, <a href="http://www.foaf-project.org/">FOAF</a>, <a href="http://rdfweb.org/topic/NamesInFoaf">names in FOAF</a> and <a href="http://esw.w3.org/topic/ImageDescription">image description</a>, tying together my digital photos with the currently upcoming <a href="http://www.w3.org/2001/sw/Europe/events/200406-img/">SWAD-Europe Image Description Workshop</a>.</p>
          <p>This will likely not be a link blog, as people like <a href="http://dannyayers.com/">Danny Ayers</a> and the collective efforts by the <a href="http://rdfig.xmlhack.com/">#rdfig community</a> do a good job in that area. My vision for this blog is more along the lines of the work by <a href="http://www.hackdiary.com/">Matt Biddulph</a> and <a href="http://diveintomark.org/">Mark Pilgrim</a> - longish posts trying to generate forward motion in an interesting area.</p>
          <p>We&#8217;ll see&#8230;</p>]]></content:encoded>
  
  </item>
  </rdf:RDF>


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.