<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"><channel><title>Disruptive Library Technology Jester &#187; hcalendar</title> <atom:link href="http://dltj.org/tag/hcalendar/feed/" rel="self" type="application/rss+xml" /><link>http://dltj.org</link> <description>We&#039;re Disrupted, We&#039;re Librarians, and We&#039;re Not Going to Take It Anymore</description> <lastBuildDate>Mon, 06 Feb 2012 20:04:22 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <cloud domain='dltj.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' /> <creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/us/</creativeCommons:license> <item><title>PHP Script for hCalendar to iCalendar Conversion</title><link>http://dltj.org/article/xhtml2vcal/</link> <comments>http://dltj.org/article/xhtml2vcal/#comments</comments> <pubDate>Thu, 11 Dec 2008 00:52:26 +0000</pubDate> <dc:creator>Peter Murray</dc:creator> <category><![CDATA[Raw Technology]]></category> <category><![CDATA[hcalendar]]></category> <category><![CDATA[iCalendar]]></category> <category><![CDATA[microformats]]></category> <category><![CDATA[semantic web]]></category><guid isPermaLink="false">http://dltj.org/?p=628</guid> <description><![CDATA[I try to do the &#8220;right thing&#8221; in postings on DLTJ. In the context of this discussion &#8220;right&#8221; is an attempt to be progressive: including hCalendar microformat markup for postings that include mention of events. The latest example of this &#8230; <a href="http://dltj.org/article/xhtml2vcal/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<abbr class="unapi-id ignore noPrint" title="http://dltj.org/?p=628"></abbr><p>I try to do the &#8220;right thing&#8221; in postings on <acronym title="Disruptive Library Technology Jester"><i>DLTJ</i></acronym>.  In the context of this discussion &#8220;right&#8221; is an attempt to be progressive:  including <a href="http://microformats.org/wiki/hcalendar" title="hCalendar &amp;middot; Microformats Wiki">hCalendar microformat markup</a> for postings that include mention of events.  The latest example of this was yesterday&#8217;s posting of the <a href="http://dltj.org/article/llt-2009-program/">Learning, Libraries and Technology Conference</a>.  Embedded in the first paragraph is markup that another application reading the <acronym title="Disruptive Library Technology Jester"><i>DLTJ</i></acronym> feed can use to understand that the posting is talking about an event.  (The <a href="http://technorati.com/events/" title="Technorati: Events Feed Service">Technorati Events&#8221;</a> service is one example.)  The key parts of the HTML are bolded below:</p><p><code>&lt;div <b>class="vevent"</b> id="llt2009-call-for-proposals-hcalendar"&gt;&lt;a href="http://www.oln.org/conferences/LLT2009/pdf/LLT09precons.pdf"&gt;Pre-conference workshop descriptions&lt;/a&gt; [PDF] and the &lt;a href="http://www.oln.org/conferences/LLT2009/pdf/LLT09draftprogram.pdf"&gt;preliminary program&lt;/a&gt; [PDF] as well as the &lt;a href="https://secure.oln.org/LLT2009/LLT2009registration.php"&gt;registration form &lt;/a&gt;for the <b>&lt;span class="summary"&gt;</b>&lt;a href="http://www.oln.org/conferences/LLT2009/" <b>class="url"</b>&gt;Learning, Libraries and Technology Conference&lt;/a&gt;&lt;/span&gt; have been posted to the conference website. <b>&lt;span class="description"&gt;</b>Learning, Libraries &amp; Technology 2009 is a learning and networking opportunity from the &lt;a href="http://www.uso.edu/"&gt;University System of Ohio&lt;/a&gt; with content of interest to everyone involved in Ohio education, including those from colleges and universities of all sizes, independent colleges, workforce development centers and high schools.&lt;/span&gt;  Held at the <b>&lt;span class="location"&gt;</b>&lt;a href="http://www.eastontowncenter.com/"&gt;Easton Town Center&lt;/a&gt; in Columbus, Ohio&lt;/span&gt;, the pre-conference Workshops will be on <b>&lt;abbr class="dtstart" title="2009-03-01"</b> style="border:none;text-decoration: none;"&gt;March 1, 2009&lt;/abbr&gt; followed by the main conference on <b>&lt;abbr class="dtend" title="2009-03-04"</b> style="border:none;text-decoration: none;"&gt;March 2-3, 2009&lt;/abbr&gt;.&lt;/div&gt;</code></p><p>(There is an <a href="http://microformats.org/code/hcalendar/creator" title="hCalendar Creator">hCalendar creator</a> that can be used to create the proper markup.)  The <a href="http://microformats.org/wiki/Main_Page" title="Microformats Wiki homepage">microformats wiki</a> describes the above markup this way:<br /><blockquote>Microformats are small bits of HTML that represent things like people, events, tags, etc. in web pages.  Microformats enable the publishing of higher fidelity information on the Web, providing the fastest and simplest way to support feeds and APIs for your website.</p></blockquote><p> The hCalendar microformat is based on the <a href="http://en.wikipedia.org/wiki/ICalendar" title="iCalendar - Wikipedia">iCalendar file format</a> &#8212; a mechanism for calendaring programs to share information about events and meeting requests.</p><p><div id="sample_hCalendar_graphic" class="wp-caption alignright" style="width: 110px;  border: 1px solid #dddddd; background-color: #f3f3f3; padding-top: 4px; margin: 10px; text-align:center; float: right;"><span style="font-size: 80%; width: 100px;"><img src="http://cdn.dltj.org/wp-content/uploads/2008/12/microformat_hcalendar1.png" alt="hCalendar Encoded Microformat" width="80" height="15" style="border:none;text-decoration: none;" /><br /><span style="font-color:#7F89A6;text-decoration:underline;">Add this event to your desktop calendar program.</span></span><p style=' padding: 0 4px 5px; margin: 0;'  class="wp-caption-text">Sample link for hCalendar to iCalendar translator</p></div> Also included in the posting is a link that says &#8220;add this event to your desktop calendar program.&#8221;  This link uses an XSLT-driven process to transform the microformat data embedded in the XHTML posting into the iCalendar format.  The <a href="http://suda.co.uk/projects/X2V/" title="suda.co.uk/projects [X2V]">XSLT transformation</a> was written by <a href="http://suda.co.uk/cv/" title="suda.co.uk/cv [CV of an Informatician]">Brian Suda</a>; Brian also has a <a href="http://suda.co.uk/projects/X2V/#H2I" title="suda.co.uk/projects [X2V]">transformation service</a> for taking an arbitrary XHTML document with hCalendar markup and creating the corresponding iCalendar file.  I&#8217;ve used this transformation service in previous postings on <acronym title="Disruptive Library Technology Jester"><i>DLTJ</i></acronym>.</p><p>I&#8217;ve used this so much that I decided not to sponge on Brian&#8217;s translation service any more and create an equivalent translation service that runs on <acronym title="Disruptive Library Technology Jester"><i>DLTJ</i></acronym>.  Included below is some PHP code that will drive the XSLT transformation process.  If you copy and paste this PHP into a file in the same directory with <a href="http://hg.microformats.org/" title="Mercurial repositories index">Brian&#8217;s &#8220;x2v&#8221; implementation</a>, then you can do the same thing.</p><p><h2>The Script</h2><br />Here is the script itself:</p><div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Copyright 2008 by Peter Murray.   Licensed under the
</span><span style="color: #666666; font-style: italic;"># Educational Community License, Version 2.0 (the &quot;License&quot;); you may
</span><span style="color: #666666; font-style: italic;"># not use this file except in compliance with the License. You may
</span><span style="color: #666666; font-style: italic;"># obtain a copy of the License at
</span><span style="color: #666666; font-style: italic;">#
</span><span style="color: #666666; font-style: italic;">#  http://www.osedu.org/licenses/ECL-2.0
</span><span style="color: #666666; font-style: italic;">#
</span><span style="color: #666666; font-style: italic;"># Unless required by applicable law or agreed to in writing,
</span><span style="color: #666666; font-style: italic;"># software distributed under the License is distributed on an &quot;AS IS&quot;
</span><span style="color: #666666; font-style: italic;"># BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
</span><span style="color: #666666; font-style: italic;"># or implied. See the License for the specific language governing
</span><span style="color: #666666; font-style: italic;"># permissions and limitations under the License.
</span>
<span style="color: #666666; font-style: italic;">## For more information about this program, see:
</span><span style="color: #666666; font-style: italic;">##   http://dltj.org/article/xhtml2vcal
</span>
<span style="color: #666666; font-style: italic;"># Array of tokens representing site prefixes.  To see how these
</span><span style="color: #666666; font-style: italic;"># are used, look at the $pathInfo explode() below.
</span><span style="color: #000088;">$siteTokens</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">&quot;dltj&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;http://dltj.org/article/%pageToken%/&quot;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># $pathInfo[0] is blank; it represents the empty space before the leading slash
</span><span style="color: #666666; font-style: italic;"># $pathInfo[1] is the site token; see site tokens above
</span><span style="color: #666666; font-style: italic;"># $pathInfo[2] is the page token; it is appended to the end of the URI
</span><span style="color: #000088;">$pathInfo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PATH_INFO'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Check to see if the token is one that we know about
</span><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pathInfo</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$siteTokens</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;"># Substitute the page token into the site uri template
</span>  <span style="color: #000088;">$uri</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/%pageToken%/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$pathInfo</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$siteTokens</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$pathInfo</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP/1.0 400 Invalid site token '</span><span style="color: #339933;">.</span><span style="color: #000088;">$pathInfo</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: text/plain'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Invalid site token: '</span><span style="color: #339933;">.</span><span style="color: #000088;">$pathInfo</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># See if we have 'curl'  
</span><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'curl_init'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP/1.0 500 curl_init() function not found'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Prepare and execute a 'curl' request
</span><span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$uri</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Check to see if we got a resource back
</span><span style="color: #000088;">$httpCode</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_getinfo</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #339933;">,</span> CURLINFO_HTTP_CODE<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$httpCode</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">'200'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP/1.0 404 Remote document not found'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: text/plain'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Remote resource returned HTTP code '<span style="color: #006699; font-weight: bold;">$httpCode</span>' for URI <span style="color: #006699; font-weight: bold;">$uri</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Load the XML source from that URI
</span><span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #339933;">;</span>
<span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadHTML</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$buffer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Load the XSLT document
</span><span style="color: #000088;">$xsl</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMDocument<span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span> <span style="color: #000088;">$xsl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'x2v/hcalendar/xhtml2vcal.xsl'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HTTP/1.0 500 XSLT style sheet not found'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: text/plain'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;XSLT stylesheet not found&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">exit</span><span style="color: #339933;">;</span>  
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Configure the transformer
</span><span style="color: #000088;">$proc</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> XSLTProcessor<span style="color: #339933;">;</span>
<span style="color: #000088;">$proc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">importStyleSheet</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xsl</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// attach the xsl rules</span>
<span style="color: #000088;">$proc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Source'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$uri</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Tell the browser we're sending an iCalendar file
</span><span style="color: #000088;">$fileName</span><span style="color: #339933;">=</span><span style="color: #000088;">$pathInfo</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;.ics&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: text/calendar; charset=utf-8; name=<span style="color: #006699; font-weight: bold;">$fileName</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Disposition: attachment; filename=<span style="color: #006699; font-weight: bold;">$fileName</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Do the transformation
</span><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$proc</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">transformToXML</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Add a Control-M to the end of the file and flush the output
</span><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot; 15n&quot;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div> ]]></content:encoded> <wfw:commentRss>http://dltj.org/article/xhtml2vcal/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Served from: dltj.org @ 2012-02-11 11:35:34 by W3 Total Cache -->
