Overview

Packages

  • awl
    • caldav-client-v2
    • RRule
  • davical
    • authentication
      • drivers
    • caldav
    • DAViCalSession
    • DAVTicket
    • external-bind
    • feed
    • HTTPAuthSession
    • iSchedule
    • iSchedule-POST
    • logging
    • metrics
    • Principal
    • propfind
    • PublicSession
    • Request
    • Resource
    • tzservice
  • None

Classes

  • AtomEntry
  • AtomFeed
  • AtomXHTMLContent
  • CalDAVClient
  • CalDAVRequest
  • CalendarInfo
  • CheckResult
  • DAViCalSession
  • DAVPrincipal
  • DAVResource
  • DAVTicket
  • FakeSession
  • HTTPAuthSession
  • imapPamDriver
  • iSchedule
  • ldapDriver
  • Principal
  • PublicSession
  • pwauthPamDriver
  • RepeatRule
  • RepeatRuleDateRange
  • RepeatRuleDateTime
  • RepeatRuleTimeZone
  • Rfc5545Duration
  • rimapPamDriver
  • setupFakeSession
  • squidPamDriver
  • Tools
  • VCard
  • VTimezone
  • WritableCollection

Functions

  • access_ticket_browser
  • add_failure
  • add_proxy_response
  • array_values_mapping
  • auth_functions_deprecated
  • AuthExternalAWL
  • binding_row_editor
  • bindings_to_other_browser
  • bindings_to_us_browser
  • bits_to_privilege
  • build_dependencies_table
  • build_privileges_html
  • build_site_statistics
  • BuildSqlFilter
  • caldav_get_feed
  • calquery_apply_filter
  • cardquery_apply_filter
  • catch_setup_errors
  • check_awl_version
  • check_calendar
  • check_curl
  • check_database_connection
  • check_datetime
  • check_davical_version
  • check_for_expansion
  • check_gettext
  • check_iconv
  • check_ldap
  • check_magic_quotes_gpc
  • check_magic_quotes_runtime
  • check_pdo
  • check_pdo_pgsql
  • check_pgsql
  • check_real_php
  • check_schema_version
  • check_string
  • check_suhosin_server_strip
  • check_xml
  • checkiSchedule
  • collection_privilege_format_function
  • component_to_xml
  • confirm_delete_bind_in
  • confirm_delete_binding
  • confirm_delete_collection
  • confirm_delete_principal
  • confirm_delete_ticket
  • ConstructURL
  • controlRequestContainer
  • create_external
  • CreateDefaultRelationships
  • CreateHomeCalendar
  • CreateHomeCollections
  • DateToISODate
  • DeconstructURL
  • delete_collection
  • deliverItipCancel
  • display_status
  • do_error
  • do_scheduling_for_delete
  • do_scheduling_reply
  • do_scheduling_requests
  • doImipMessage
  • doItipAttendeeReply
  • doItipOrganizerCancel
  • early_catch_fatal_error
  • early_exception_handler
  • edit_binding_row
  • edit_grant_row_collection
  • edit_grant_row_principal
  • edit_group_row
  • edit_ticket_row
  • errorResponse
  • expand_event_instances
  • expand_properties
  • expand_timezone_onsets
  • export_iCalendar
  • fetch_external
  • fix_unique_member
  • generateKeys
  • get_address_properties
  • get_collection_contents
  • get_freebusy
  • get_href_containers
  • get_phpinfo
  • getComponentRange
  • GetItip
  • getPrincipalByID
  • getStaticLdap
  • getStatusMessage
  • GetTZID
  • getUserByEMail
  • getUserByID
  • getUserByName
  • getVCalendarRange
  • grant_row_editor
  • group_members_browser
  • group_memberships_browser
  • group_row_editor
  • handle_cancel_request
  • handle_freebusy_request
  • handle_schedule_reply
  • handle_schedule_request
  • handle_subaction
  • hyperlink
  • i18n
  • IMAP_PAM_check
  • import_addressbook_collection
  • import_calendar_collection
  • import_collection
  • ischedule_cancel
  • ischedule_freebusy_request
  • ischedule_get
  • ischedule_request
  • ISODateToHTTPDate
  • late_catch_fatal_error
  • LDAP_check
  • local_session_sql
  • log_caldav_action
  • log_setup_error
  • logRequestHeaders
  • make_help_link
  • obfuscated_event
  • olson_from_vtimezone
  • principal_collection_browser
  • principal_editor
  • principal_grants_browser
  • principal_privilege_format_function
  • print_metric
  • privilege_to_bits
  • privileges_to_XML
  • process_ace
  • processItipCancel
  • property_response
  • public_events_only
  • PWAUTH_PAM_check
  • rdate_expand
  • RIMAP_check
  • rollback
  • rollback_on_error
  • rrule_expand
  • send_dav_header
  • send_page_header
  • simple_write_resource
  • SqlFilterCardDAV
  • SqlFilterFragment
  • SQUID_PAM_check
  • SRVFormat
  • SRVOk
  • sync_LDAP
  • sync_LDAP_groups
  • sync_user_from_LDAP
  • ticket_row_editor
  • unicodeToUtf8
  • update_external
  • UpdateCollectionTimezones
  • UpdateUserFromExternal
  • utf8ToUnicode
  • write_alarms
  • write_attendees
  • write_resource
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 
<?php
/**
 * Atom feed of recent changes to a calendar collection
 *
 * @package davical
 * @subpackage feed
 * @author Andrew McMillan <andrew@morphoss.com>
 * @license GPL v2 or later
 */

require_once("XMLDocument.php");

define('ATOM_XMLNS','http://www.w3.org/2005/Atom');
define('XHTML_XMLNS','http://www.w3.org/1999/xhtml');


/**
 * These two classes here sort of emulate the interface from the  Zend Framework API
 * with regard to ZendFeedWriteFeed for constructing an Atom feed.  Except we do it
 * in a DAViCal way, and we have some huge limitations:
 *  - We *only* support Atom feeds.
 *  - We *only* support creating them.
 *
 * @author Andrew McMillan <andrew@morphoss.com>
 *
 */

class AtomXHTMLContent /* extends XMLElement */ {
   private $content_string;

   function __construct($xhtml) {
     $this->content_string = $xhtml;
   }

   function Render( $ignore1, $ignore2, $ignore3 ) {
     return $this->content_string . "\n";
   }
}


class AtomEntry {
  /**
  <entry xmlns:xhtml="http://www.w3.org/1999/xhtml">
    <title type="html"><![CDATA[Woohoo!  Time to Par-tay! (1/1)]]></title>

    <summary type="html"><![CDATA[Have a microparty. All the best parties are monthly!]]></summary>
    <published>2008-10-25T11:07:49+13:00</published>
    <updated>2010-12-27T06:49:16+13:00</updated>
    <id>http://mycaldav/feed.php/user1/home/MICROPARTY-77C6-4FB7-BDD3-6882E2F1BE74.ics#UID:MICROPARTY-77C6-4FB7-BDD3-6882E2F1BE74</id>
    <content xmlns:xhtml="http://www.w3.org/1999/xhtml" type="xhtml">
      <xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml"><xhtml:strong>Time:</xhtml:strong> 2008-11-21 16:00:00<xhtml:br/><xhtml:br/><xhtml:strong>Description</xhtml:strong>:<xhtml:br/>Have a microparty. All the best parties are monthly!</xhtml:div>

    </content>
  </entry>
  */
  private $id;
  private $title;
  private $updated;
  private $nodes;

  function __construct( $id, $title, $published, $updated ) {
    $this->nodes = array( 'id', 'title', 'updated' );  // placeholders
  }

  public function setId( $new_value ) {
    $this->id = new XMLElement('id', rtrim($new_value,"\r\n"));
    return $this->id;
  }

  public function setTitle( $new_value, $type = 'text' ) {
    $this->title = new XMLElement('title', $new_value, array( 'type' => $type ));
    return $this->title;
  }

  public static function setDate( $tagname, $epoch ) {
    // e.g. 2010-12-26T17:49:16+13:00
    return new XMLElement($tagname, date('Y-m-d\TH:i:sP',$epoch));
  }

  public function setDateModified( $epoch ) {
    $this->updated = self::setDate('updated', $epoch);
    return $this->updated;
  }

  public function setDateCreated( $epoch ) {
    $node = self::setDate('published', $epoch);
    $this->nodes[] = $node;
    return $node;
  }

  public function setLink( $new_value, $type="text/calendar", $rel='alternate' ) {
    return $this->addNode('link', $new_value, array( 'rel' => $rel, 'type' => $type ) );
  }

  public function addAuthor( $new_value ) {
    if ( is_array($new_value) && isset($new_value['name']) ) {
      $author = $this->addNode('author' );
      foreach( $new_value AS $k => $v ) {
        $author->NewElement($k, $v);
      }
      return $author;
    }
    throw new Exception("AtomFeed::addAuthor(\$new_value) the \$new_value MUST be an array with at least a 'name' element. RFC4287-3.2");
  }


  public function addCategory( $new_value ) {
    if ( is_array($new_value) && isset($new_value['term']) ) {
      $category = $this->addNode('category', null, $new_value );
      return $category;
    }
    throw new Exception("AtomFeed::addCategory(\$new_value) the \$new_value MUST be an array with at least a 'term' element, and potentially a 'scheme' and a 'label' element. RFC4287-4.2.2");
  }


  public function setDescription( $new_value, $type = 'text' ) {
    return $this->addNode('summary', $new_value, array( 'type' => $type ) );
  }

  public function setContent( $new_value, $type = 'xhtml' ) {
    $content = $this->addNode('content', null, array( 'type' => $type ) );
    if ( $type == 'xhtml' ) {
      $content->NewElement('div', array( new AtomXHTMLContent($new_value) ), array('xmlns' => XHTML_XMLNS));
    }
    else {
      $content->SetContent($new_value);
    }
    return $content;
  }

  public function addNode( $in_tag, $content=false, $attributes=false, $xmlns=null ) {
    $node = new XMLElement($in_tag,$content,$attributes,$xmlns);
    if ( !isset($node) ) return null;
    $this->nodes[] = $node;
    return $node;
  }

  public function getXML() {
    $this->nodes[0] = $this->id;
    $this->nodes[1] = $this->title;
    $this->nodes[2] = $this->updated;
    return $this->nodes;
  }
}


class AtomFeed extends XMLDocument {

  private $id;
  private $title;
  private $updated;
  private $nodes;

  public function __construct() {
    global $c;
    parent::__construct( array( ATOM_XMLNS => null, XHTML_XMLNS => 'xhtml' ) );
    $this->title = 'DAViCal Atom Feed';
    $this->nodes = array( 'id', 'title', 'updated',  // placeholders
        new XMLElement('generator', 'DAViCal', array('uri' => 'https://www.davical.org/', 'version' => $c->version_string ) )
      );
  }

  /*
  <id>http://mycaldav/feed.php/user1/home.ics</id>
  <title type="text">CalDAV Feed: User 1's Calendaranza</title>
  <updated>2010-12-26T17:49:16+13:00</updated>
  <generator uri="http://framework.zend.com" version="1.10.7">Zend_Feed_Writer</generator>
  <link rel="alternate" type="text/html" href="http://mycaldav/feed.php/user1/home.ics"/>
  <link rel="self" type="application/atom+xml" href="http://mycaldav/feed.php/user1/home/"/>
  <author>
    <name>User 1</name>
    <email>user1@example.net</email>
    <uri>http://mycaldav/feed.php/caldav.php/user1/</uri>
  </author>
  */

  public function setId( $new_value ) {
    $this->id = $this->NewXMLElement('id', $new_value);
    return $this->id;
  }

  public function setTitle( $new_value, $type = 'text' ) {
    $this->title = $this->NewXMLElement('title', $new_value, array( 'type' => $type ));
    return $this->title;
  }

  public function setDateModified( $epoch ) {
    $this->updated = AtomEntry::setDate('updated', $epoch);
    return $this->updated;
  }

  public function setLink( $new_value, $type="text/calendar", $rel='alternate' ) {
    return $this->addNode('link', $new_value, array( 'rel' => $rel, 'type' => $type ) );
  }


  /**
   * Sets the feed link (rel=self), ignoring the parameter which is for
   * compatibility with the Zend library API, although we use this for
   * the Id, whereas they use the first link that is set.
   * @param uri $new_value The link target
   * @return XMLElement the node that was added.
   */
  public function setFeedLink( $new_value, $type = null ) {
    $this->setId($new_value);
    return $this->setLink($new_value , 'application/atom+xml', 'self' );
  }

  public function addAuthor( $new_value ) {
    if ( is_array($new_value) && isset($new_value['name']) ) {
      $author = $this->addNode('author' );
      foreach( $new_value AS $k => $v ) {
        $this->NSElement($author, $k, $v);
      }
      return $author;
    }
    throw new Exception("AtomFeed::addAuthor(\$new_value) the \$new_value MUST be an array with at leas a 'name' element. RFC4287-3.2");
  }


  public function setDescription( $new_value, $type = 'text' ) {
    return $this->addNode('subtitle', $new_value, array( 'type' => $type ) );
  }

  public function addNode( $in_tag, $content=false, $attributes=false, $xmlns=null ) {
    $node = $this->NewXMLElement($in_tag,$content,$attributes,$xmlns);
    if ( !isset($node) ) return null;
    $this->nodes[] = $node;
    return $node;
  }

  public function addEntry( $new_entry ) {
    if ( !isset($new_entry) ) return;
    $this->nodes[] = new XMLElement('entry', $new_entry->getXML() );
  }

  public function createEntry( $id=null, $title=null, $published=null, $updated=null ) {
    return new AtomEntry($id,$title,$published,$updated);
  }

  public function export( $format='atom' ) {
    if ( $format != 'atom' ) throw new Exception("AtomFeed class only supports creation of Atom 1.0 format feeds.");
    $this->nodes[0] = $this->id;
    $this->nodes[1] = $this->title;
    $this->nodes[2] = $this->updated;
    return $this->Render('feed', $this->nodes );
  }
}

DAViCal API documentation generated by ApiGen