Extension talk:SpecialCalendar

Latest comment: 16 years ago by Sbrunner in topic problem

Name of this extension

edit

It should either be SpecialCalender or SpecialICalendar. If SpecialICalender, the files should be named so as well. --GunterS 21:17, 18 March 2007 (UTC)Reply

whats this

edit

maybe a little explanation of what is the extension, where it works, how you use it, and a screen shot?? --217.64.242.138 09:32, 30 March 2007 (UTC)Reply

It working here: http://www.kk-fj.ch/fj/mw/Special:Calendar/CDP2006
All will be explain in the Install and How to use section !
If you have other question d'on't hesitate.
CU Stéphane
I don't know how to see the calendar on that link Does it look anything like the google calendar extension would? Bouncingmolar 20:43, 12 April 2007 (UTC)Reply
No only the events will be visible !
CU Stéphane 07:07, 13 April 2007 (UTC)Reply

problem

edit

http://www.kk-fj.ch/fj/mw/Special:Calendar/CDP2006

the example site requires identification to see the calendar!

I'm sorry but I don't use anymore this extension, I use micoformat and a php script to convert it in iCal format.

Use script:

<?php
//ini_set('display_errors', '0');
//header('Content-type: application/ical');
//
// configuration
$h2axsl = '.../toICal.xsl'; // path to toICal.xsl
$domain = 'www.kk-fj.ch'; // domain with the hatom content
$permalink_stub = '/convert/hcalendar2ical.php5';// public path to this file
//
// parse request
$requested = $_SERVER['REQUEST_URI'];
$requested = substr_replace($requested,'',0,strlen($permalink_stub)+2);
$requested = urldecode($requested); // deal with encoded
$docurl = 'http://'.$domain.'/'.$requested;

//$docurl = 'http://microformats.org/';//'http://'.$domain.'/'.$requested;
//
// grab file contents
if (function_exists('curl_init')){
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $docurl);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
$file_contents = curl_exec($ch);
curl_close($ch);
} else {
$file_contents= file_get_contents($docurl);
}
//
// pass the file through the transform and send it out
$xsl = new DomDocument();
$xsl->load($h2axsl);
$inputdom = new DomDocument();
if ($inputdom->loadXML(_translateLiteral2NumericEntities($file_contents))) {
$proc = new XsltProcessor();
$proc->importStylesheet($xsl);
$proc->setParameter('', 'source-uri', $docurl);

//$newdom = $proc->transformToDoc($inputdom);
//print $newdom->saveXML();

$result = $proc->transformToXML($inputdom);
print $result;

}

  /**
  * get from http://bugs.php.net/bug.php?id=15092
  *
  * Translate literal entities to their numeric equivalents and vice
versa.
  *
  * PHP's XML parser (in V 4.1.0) has problems with entities! The only
one's that are recognized
  * are &amp;, &lt; &gt; and &quot;. *ALL* others (like &nbsp; &copy;
a.s.o.) cause an 
  * XML_ERROR_UNDEFINED_ENTITY error. I reported this as bug at
http://bugs.php.net/bug.php?id=15092
  * The work around is to translate the entities found in the XML source
to their numeric equivalent
  * E.g. &nbsp; to &#160; / &copy; to &#169; a.s.o.
  * 
  * NOTE: Entities &amp;, &lt; &gt; and &quot; are left 'as is'
  * 
  * @author Sam Blum bs_php@users.sourceforge.net
  * @param string $xmlSource The XML string
  * @param bool   $reverse (default=FALSE) Translate numeric entities to
literal entities.
  * @return The XML string with translatet entities.
  */
  function _translateLiteral2NumericEntities($xmlSource, $reverse =
FALSE) {
    static $literal2NumericEntity;

    if (empty($literal2NumericEntity)) {
      $transTbl = get_html_translation_table(HTML_ENTITIES);
      foreach ($transTbl as $char => $entity) {
        if (strpos('&"<>', $char) !== FALSE) continue;
        $literal2NumericEntity[$entity] = '&#'.ord($char).';';
      }
    }
    if ($reverse) {
      return strtr($xmlSource, array_flip($literal2NumericEntity));
    } else {
      return strtr($xmlSource, $literal2NumericEntity);
    }
  }

?>

And the xls file:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:output encoding="UTF-8" indent="no" media-type="text/x-vcard" method="text"/>

<xsl:param name="prodid" select="&quot;-//connolly.w3.org//palmagent 0.6 (BETA)//EN&quot;"/>

<!-- by Dan Connolly; based on... -->

<!--
brian suda
brian@suda.co.uk
http://suda.co.uk/

XHTML-2-vCard
Version 0.5.1
2005-07-08

Copyright 2005 Brian Suda
This work is licensed under the Creative Commons Attribution-ShareAlike License. 
To view a copy of this license, visit 
http://creativecommons.org/licenses/by-sa/1.0/
-->

<!--Best Practices states this should be
    the URL the calendar was transformed from -->
<xsl:param name="Source"/>

<xsl:param name="Anchor"/>


<xsl:template match="/">
  <xsl:text>BEGIN:VCALENDAR</xsl:text>
    
  <xsl:text>
PRODID:</xsl:text>
  <xsl:value-of select="$prodid"/>
    
  <xsl:text>
VERSION:2.0</xsl:text>

  <xsl:apply-templates/>
  
  <xsl:text>
END:VCALENDAR
</xsl:text>
</xsl:template>


<!-- Each event is listed in succession -->
<xsl:template match="*[contains(concat(' ',normalize-space(@class),' '),' vevent ')]">

  <xsl:if test="not($Anchor) or @id = $Anchor">

    <xsl:text>
BEGIN:VEVENT</xsl:text>

    <xsl:call-template name="cal-props"/>

    <xsl:text>
END:VEVENT</xsl:text>
  </xsl:if>
</xsl:template>

<!-- ... and todos. -->
<xsl:template match="*[contains(concat(' ', normalize-space(@class), ' '),' vtodo ')]">

  <xsl:if test="not($Anchor) or @id = $Anchor">

    <xsl:text>
BEGIN:VTODO</xsl:text>

    <xsl:call-template name="cal-props"/>

    <xsl:text>
END:VTODO</xsl:text>
  </xsl:if>
</xsl:template>

<xsl:template name="cal-props">
    <!-- make a UID out of the Source URI and the ID -->
    <xsl:if test="@id and $Source">
      <xsl:text>
UID:</xsl:text>
      <xsl:call-template name="escapeText">
	<xsl:with-param name="text-string" select="concat($Source, &quot;#&quot;, @id)"/>
      </xsl:call-template>
    </xsl:if>

    <xsl:call-template name="textProp">
      <xsl:with-param name="label">DESCRIPTION</xsl:with-param>
      <xsl:with-param name="class">description</xsl:with-param>
    </xsl:call-template>

    <xsl:call-template name="textProp">
      <xsl:with-param name="label">SUMMARY</xsl:with-param>
      <xsl:with-param name="class">summary</xsl:with-param>
    </xsl:call-template>

    <xsl:call-template name="dateProp">
      <xsl:with-param name="label">DTSTART</xsl:with-param>
      <xsl:with-param name="class">dtstart</xsl:with-param>
    </xsl:call-template>

    <xsl:call-template name="dateProp">
      <xsl:with-param name="label">DTEND</xsl:with-param>
      <xsl:with-param name="class">dtend</xsl:with-param>
    </xsl:call-template>

    <xsl:call-template name="durProp">
      <xsl:with-param name="label">DURATION</xsl:with-param>
      <xsl:with-param name="class">duration</xsl:with-param>
    </xsl:call-template>

    <xsl:call-template name="refProp">
      <xsl:with-param name="label">URL</xsl:with-param>
      <xsl:with-param name="class">url</xsl:with-param>
      <xsl:with-param name="default">
	<xsl:choose>
	  <xsl:when test="@id">
	    <xsl:value-of select="concat($Source, &quot;#&quot;, @id)"/>
	  </xsl:when>
	  <xsl:otherwise>
	    <xsl:value-of select="$Source"/>
	  </xsl:otherwise>
	</xsl:choose>
      </xsl:with-param>
    </xsl:call-template>

    <xsl:call-template name="textProp">
      <xsl:with-param name="label">LOCATION</xsl:with-param>
      <xsl:with-param name="class">location</xsl:with-param>
    </xsl:call-template>

</xsl:template>



<xsl:template name="textProp">
  <xsl:param name="label"/>
  <xsl:param name="class"/>

  <!-- hmm... spec (http://microformats.org/wiki/hcard#XMDP_Profile )
       "If names in the source schema are case-insensitive, then use
       an all lowercase equivalent."
       but X2V and the rfc2629 tools seem to assume case insensitivity
  -->
  <xsl:for-each select=".//*[    contains(concat(' ',    translate(normalize-space(@class),    'ABCDEFGHIJKLMNOPQRSTUVWXYZ',    'abcdefghijklmnopqrstuvwxyz'),    ' '),    concat(' ', $class, ' '))]">

    <!-- @@ "the first descendant element with that class should take
         effect, any others being ignored." -->
    <xsl:text>
</xsl:text>
    <xsl:value-of select="$label"/>

    <xsl:call-template name="lang"/>

    <xsl:text>:</xsl:text>

    <xsl:choose>
      <!-- @@this multiple values stuff doesn't seem to be in the spec
      -->
      <xsl:when test="local-name(.) = &quot;ol&quot; or local-name(.) = &quot;ul&quot;">
	<xsl:for-each select="*">
	  <xsl:if test="not(position()=1)">
	    <xsl:text>,</xsl:text>
	  </xsl:if>

	  <xsl:call-template name="escapeText">
	    <xsl:with-param name="text-string" select="."/>
	  </xsl:call-template>
	</xsl:for-each>
      </xsl:when>

      <xsl:when test="local-name(.) = &quot;abbr&quot; and @title">
	<xsl:variable name="v" select="normalize-space(@title)"/>
	<xsl:call-template name="escapeText">
	  <xsl:with-param name="text-string" select="$v"/>
	</xsl:call-template>
      </xsl:when>

      <xsl:otherwise>
	<xsl:variable name="v" select="normalize-space(.)"/>
	<xsl:call-template name="escapeText">
	  <xsl:with-param name="text-string" select="$v"/>
	</xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>

  </xsl:for-each>
</xsl:template>


<xsl:template name="lang">
  <xsl:variable name="langElt" select="ancestor-or-self::*[@xml:lang or @lang]"/>
  <xsl:if test="$langElt">
    <xsl:variable name="lang">
      <xsl:choose>
	<xsl:when test="$langElt/@xml:lang">
	  <xsl:value-of select="normalize-space($langElt/@xml:lang)"/>
	</xsl:when>
	<xsl:when test="$langElt/@lang">
	  <xsl:value-of select="normalize-space($langElt/@lang)"/>
	</xsl:when>
	<xsl:otherwise>
	  <xsl:message>where id lang and xml:lang go?!?!?
	  </xsl:message>
	</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:text>;LANGUAGE=</xsl:text>
    <xsl:value-of select="$lang"/>
  </xsl:if>
</xsl:template>


<xsl:template name="refProp">
  <xsl:param name="label"/>
  <xsl:param name="class"/>
  <xsl:param name="default"/>

  <xsl:choose>
    <xsl:when test=".//*[       contains(concat(' ', @class, ' '),       concat(' ', $class, ' '))]">

      <xsl:for-each select=".//*[        contains(concat(' ', @class, ' '),        concat(' ', $class, ' '))]">
	<xsl:text>
</xsl:text>
	<xsl:value-of select="$label"/>
	
	<xsl:variable name="ref">
	  <xsl:choose>
	    <!-- @@make absolute? -->
	    <xsl:when test="@href">
	      <xsl:value-of select="@href"/>
	    </xsl:when>
	    
	    <xsl:otherwise>
	      <xsl:value-of select="normalize-space(.)"/>
	    </xsl:otherwise>
	  </xsl:choose>
	</xsl:variable>
	
	<xsl:text>:</xsl:text>
	<xsl:call-template name="escapeText">
	  <xsl:with-param name="text-string" select="$ref"/>
	</xsl:call-template>
	
      </xsl:for-each>
    </xsl:when>

    <xsl:when test="$default">
      <xsl:text>
</xsl:text>
      <xsl:value-of select="$label"/>
      <xsl:text>:</xsl:text>
      <xsl:call-template name="escapeText">
	<xsl:with-param name="text-string" select="$default"/>
      </xsl:call-template>
    </xsl:when>
  </xsl:choose>

</xsl:template>


<xsl:template name="dateProp">
  <xsl:param name="label"/>
  <xsl:param name="class"/>

  <!-- @@ case sensitive class matching? -->
  <xsl:for-each select=".//*[    contains(concat(' ',    translate(normalize-space(@class),    'ABCDEFGHIJKLMNOPQRSTUVWXYZ',    'abcdefghijklmnopqrstuvwxyz'),    ' '),    concat(' ', $class, ' '))]">
    <xsl:text>
</xsl:text>
    <xsl:value-of select="$label"/>

    <xsl:variable name="when">
      <xsl:choose>
	<xsl:when test="@title">
	  <xsl:value-of select="@title">
	  </xsl:value-of>
	</xsl:when>
	<xsl:otherwise>
	  <xsl:value-of select="normalize-space(.)"/>
	</xsl:otherwise>
      </xsl:choose>
    </xsl:variable>

    <xsl:choose>
      <xsl:when test="contains($when, &quot;Z&quot;)">
	<xsl:text>;VALUE=DATE-TIME:</xsl:text>
	<xsl:value-of select="translate($when, &quot;-:&quot;, &quot;&quot;)"/>
      </xsl:when>

      <xsl:when test="string-length($when) =         string-length(&quot;yyyy-mm-ddThh:mm:ss+hhmm&quot;)">
	<xsl:text>;VALUE=DATE-TIME:</xsl:text>
	<xsl:call-template name="timeDelta">
	  <xsl:with-param name="year" select="number(substring($when, 1, 4))"/>
	  <xsl:with-param name="month" select="number(substring($when, 6, 2))"/>
	  <xsl:with-param name="day" select="number(substring($when, 9, 2))"/>
	  <xsl:with-param name="hour" select="number(substring($when, 12, 2))"/>
	  <xsl:with-param name="minute" select="number(substring($when, 15, 2))"/>

	  <xsl:with-param name="hourDelta" select="number(substring($when, 21, 2))"/>
	</xsl:call-template>
      </xsl:when>

      <xsl:when test="contains($when, &quot;T&quot;)">
	<xsl:text>;VALUE=DATE-TIME:</xsl:text>
	<xsl:value-of select="translate($when, &quot;-:&quot;, &quot;&quot;)"/>
      </xsl:when>

      <xsl:otherwise>
	<xsl:text>;VALUE=DATE:</xsl:text>
	<xsl:value-of select="translate($when, &quot;-:&quot;, &quot;&quot;)"/>
      </xsl:otherwise>
    </xsl:choose>

  </xsl:for-each>
</xsl:template>


<xsl:template name="timeDelta">
  <!-- see http://www.microformats.org/wiki/datetime-design-pattern -->
  <!-- returns YYYYMMDDThhmmssZ -->
  <xsl:param name="year"/> <!-- integers -->
  <xsl:param name="month"/>
  <xsl:param name="day"/>
  <xsl:param name="hour"/>
  <xsl:param name="minute"/>

  <xsl:param name="hourDelta"/>

  <xsl:variable name="hour2">
    <xsl:choose>
      <xsl:when test="$hour + $hourDelta &gt; 23">
	<xsl:value-of select="$hour + $hourDelta - 24"/>
      </xsl:when>
      <xsl:when test="$hour + $hourDelta &lt; 0">
	<xsl:value-of select="$hour + $hourDelta + 24"/>
      </xsl:when>
      <xsl:otherwise>
	<xsl:value-of select="$hour + $hourDelta"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="dayDelta">
    <xsl:choose>
      <xsl:when test="$hour + $hourDelta &gt; 23">
	<xsl:value-of select="1"/>
      </xsl:when>
      <xsl:when test="$hour + $hourDelta &lt; 0">
	<xsl:value-of select="-1"/>
      </xsl:when>
      <xsl:otherwise>
	<xsl:value-of select="0"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="maxd">
    <xsl:call-template name="max-days">
      <xsl:with-param name="y" select="$year"/>
      <xsl:with-param name="m" select="$month"/>
    </xsl:call-template>
  </xsl:variable>

  <xsl:variable name="day2">
    <xsl:choose>
      <xsl:when test="$day + $dayDelta &gt; $maxd">
	<xsl:value-of select="1"/>
      </xsl:when>

      <xsl:when test="$day + $dayDelta &lt; 0">
	<xsl:call-template name="max-days">
	  <xsl:with-param name="y" select="$y"/>
	  <!-- @@TODO: handle year crossings -->
	  <xsl:with-param name="m" select="$m - 1"/>
	</xsl:call-template>
      </xsl:when>

      <xsl:otherwise>
	<xsl:value-of select="$day + $dayDelta"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="monthDelta">
    <xsl:choose>
      <xsl:when test="$day + $dayDelta &gt; $maxd">
	<xsl:value-of select="1"/>
      </xsl:when>
      <xsl:when test="$day + $dayDelta &lt; 0">
	<xsl:value-of select="-1"/>
      </xsl:when>
      <xsl:otherwise>
	<xsl:value-of select="0"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="month2">
    <xsl:choose>
      <xsl:when test="$month + $monthDelta &gt; 12">
	<xsl:value-of select="1"/>
      </xsl:when>

      <xsl:when test="$month + $monthDelta &lt; 0">
	<xsl:value-of select="12"/>
      </xsl:when>

      <xsl:otherwise>
	<xsl:value-of select="$month + $monthDelta"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="yearDelta">
    <xsl:choose>
      <xsl:when test="$month + $monthDelta &gt; 12">
	<xsl:value-of select="1"/>
      </xsl:when>

      <xsl:when test="$month + $monthDelta &lt; 0">
	<xsl:value-of select="-1"/>
      </xsl:when>

      <xsl:otherwise>
	<xsl:value-of select="0"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="year2">
    <xsl:value-of select="$year + $yearDelta"/>
  </xsl:variable>

  <xsl:value-of select="concat(format-number($year2, &quot;0000&quot;),    format-number($month2, &quot;00&quot;),    format-number($day2, &quot;00&quot;), &quot;T&quot;,    format-number($hour2, &quot;00&quot;),    format-number($minute, &quot;00&quot;), &quot;00Z&quot;)"/>

</xsl:template>


<xsl:template name="max-days">
  <!-- maximum number of days in the given month of the given year -->
  <!-- @@ skip leap year for now -->
  <xsl:param name="y" select="$y"/>
  <xsl:param name="m" select="$m"/>

  <xsl:choose>
    <xsl:when test="$m = 1 or $m = 3 or $m = 5 or $m = 7 or       $m = 8 or $m = 10 or $m = 12">
      <xsl:value-of select="31"/>
    </xsl:when>

    <xsl:when test="$m = 2">
      <xsl:value-of select="28"/>
    </xsl:when>

    <xsl:otherwise>
      <xsl:value-of select="30"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

<xsl:template name="durProp">
  <xsl:param name="label"/>
  <xsl:param name="class"/>

  <!-- @@ case sensitive class matching? -->
  <xsl:for-each select=".//*[    contains(concat(' ',    translate(normalize-space(@class),    'ABCDEFGHIJKLMNOPQRSTUVWXYZ',    'abcdefghijklmnopqrstuvwxyz'),    ' '),    concat(' ', $class, ' '))]">
    <xsl:text>
</xsl:text>
    <xsl:value-of select="$label"/>

    <xsl:text>:</xsl:text>
    <!-- commas aren't possible, are they? -->
    <xsl:choose>
      <xsl:when test="local-name(.) = &quot;abbr&quot; and @title">
	<xsl:value-of select="@title"/>
      </xsl:when>

      <xsl:otherwise>
	<xsl:value-of select="normalize-space(.)"/>
      </xsl:otherwise>
    </xsl:choose>

  </xsl:for-each>
</xsl:template>


<xsl:template name="blobProp">
  <xsl:param name="label"/>
  <xsl:param name="class"/>

  <!-- @@ case sensitive class matching? -->
  <xsl:for-each select=".//*[    contains(concat(' ',    translate(normalize-space(@class),    'ABCDEFGHIJKLMNOPQRSTUVWXYZ',    'abcdefghijklmnopqrstuvwxyz'),    ' '),    concat(' ', $class, ' '))]">
    <xsl:text>
</xsl:text>
    <xsl:value-of select="$label"/>

    <xsl:choose>
      <xsl:when test="@src">
	<xsl:text>;VALUE=uri:</xsl:text>
	<xsl:call-template name="escapeText">
	  <xsl:with-param name="text-string" select="@src"/>
	</xsl:call-template>
      </xsl:when>

      <!-- hmm... href? -->

      <xsl:otherwise>
	<xsl:text>:</xsl:text>
	<xsl:call-template name="escapeText">
	  <xsl:with-param name="text-string" select="."/>
	</xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:for-each>
</xsl:template>


<xsl:template name="emailProp">
  <xsl:param name="label"/>
  <xsl:param name="class"/>

  <!-- @@ case sensitive class matching? -->
  <xsl:for-each select=".//*[    contains(concat(' ',    translate(normalize-space(@class),    'ABCDEFGHIJKLMNOPQRSTUVWXYZ',    'abcdefghijklmnopqrstuvwxyz'),    ' '),    concat(' ', $class, ' '))]">
    <xsl:text>
</xsl:text>
    <xsl:value-of select="$label"/>

    <!-- @@TYPE=x.400 not supported -->

    <xsl:choose>
      <xsl:when test="@href and starts-with(@href, &quot;mailto:&quot;)">
	<xsl:text>:</xsl:text>
	<xsl:call-template name="escapeText">
	  <xsl:with-param name="text-string" select="substring-after(@href, &quot;:&quot;)"/>
	</xsl:call-template>
      </xsl:when>

      <xsl:otherwise>
	<xsl:text>:</xsl:text>
	<xsl:call-template name="escapeText">
	  <xsl:with-param name="text-string" select="."/>
	</xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:for-each>
</xsl:template>


<xsl:template name="escapeText">
  <xsl:param name="text-string"/>
  <xsl:choose>
    <xsl:when test="substring-before($text-string,',') = true()">
      <xsl:value-of select="substring-before($text-string,',')"/>
      <xsl:text>\,</xsl:text>
      <xsl:call-template name="escapeText">
	<xsl:with-param name="text-string">
	  <xsl:value-of select="substring-after($text-string,',')"/>
	</xsl:with-param>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$text-string"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>


<!-- don't pass text thru -->
<xsl:template match="text()"/>
</xsl:stylesheet>

Stéphane 18:50, 10 December 2007 (UTC)Reply

example

edit

i would like to see an example... a screenshot or a link would be great.

Return to "SpecialCalendar" page.