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: 
<?php
/**
 * A script for returning a feed (currently Atom) of recent changes to a calendar collection
 *
 * @package davical
 * @subpackage feed
 * @author Leho Kraav <leho@kraav.com>
 * @author Andrew McMillan <andrew@morphoss.com>
 * @license GPL v2 or later
 */
require_once("./always.php");
dbg_error_log( "feed", " User agent: %s", ((isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : "Unfortunately Mulberry and Chandler don't send a 'User-agent' header with their requests :-(")) );
dbg_log_array( "headers", '_SERVER', $_SERVER, true );

require_once('AwlCache.php');

require_once("HTTPAuthSession.php");
$session = new HTTPAuthSession();

require_once('CalDAVRequest.php');
$request = new CalDAVRequest();

require_once("vComponent.php");
require_once("DAVResource.php");


/**
 * Function for creating anchor links out of plain text.
 * Source: http://stackoverflow.com/questions/1960461/convert-plain-text-hyperlinks-into-html-hyperlinks-in-php
 */
function hyperlink( $text ) {
  return preg_replace( '@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@', '<a href="$1" target="_blank">$1</a>', htmlspecialchars($text) );
}

function caldav_get_feed( $request, $collection ) {
  global $c, $session;

  dbg_error_log("feed", "GET method handler");

  $collection->NeedPrivilege( array('DAV::read') );

  if ( ! $collection->Exists() ) {
    $request->DoResponse( 404, translate("Resource Not Found.") );
  }

  if ( !$collection->IsCollection()
     || !$collection->IsCalendar() && !(isset($c->get_includes_subcollections) && $c->get_includes_subcollections) ) {
    $request->DoResponse( 405, translate("Feeds are only supported for calendars at present.") );
  }

  // Try and pull the answer out of a hat
  $cache = getCacheInstance();
  $cache_ns = 'collection-'.$collection->dav_name();
  $cache_key = 'feed'.$session->user_no;
  $response = $cache->get( $cache_ns, $cache_key );
  if ( $response !== false ) return $response;

  $principal = $collection->GetProperty('principal');

  /**
   * The CalDAV specification does not define GET on a collection, but typically this is
   * used as a .ics download for the whole collection, which is what we do also.
   */
  $sql = 'SELECT caldav_data, caldav_type, caldav_data.user_no, caldav_data.dav_name,';
  $sql .= ' caldav_data.modified, caldav_data.created, ';
  $sql .= ' summary, dtstart, dtend, calendar_item.description ';
  $sql .= ' FROM collection INNER JOIN caldav_data USING(collection_id) INNER JOIN calendar_item USING ( dav_id ) WHERE ';
  if ( isset($c->get_includes_subcollections) && $c->get_includes_subcollections ) {
    $sql .= ' (collection.dav_name ~ :path_match ';
    $sql .= ' OR collection.collection_id IN (SELECT bound_source_id FROM dav_binding WHERE dav_binding.dav_name ~ :path_match)) ';
    $params = array( ':path_match' => '^'.$request->path );
  }
  else {
    $sql .= ' caldav_data.collection_id = :collection_id ';
    $params = array( ':collection_id' => $collection->resource_id() );
  }
  $sql .= ' ORDER BY caldav_data.created DESC';
  $sql .= ' LIMIT '.(isset($c->feed_item_limit) ? $c->feed_item_limit : 15);
  $qry = new AwlQuery( $sql, $params );
  if ( !$qry->Exec("GET",__LINE__,__FILE__) ) {
    $request->DoResponse( 500, translate("Database Error") );
  }

  /**
   * Here we are constructing the feed response for this collection, including
   * the timezones that are referred to by the events we have selected.
   * Library used: http://framework.zend.com/manual/en/zend.feed.writer.html
   */
  require_once('AtomFeed.php');
  $feed = new AtomFeed();

  $feed->setTitle('DAViCal Atom Feed: '. $collection->GetProperty('displayname'));
  $url = $c->protocol_server_port . $collection->url();
  $url = preg_replace( '{/$}', '.ics', $url);
  $feed->setLink($url);
  $feed->setFeedLink($c->protocol_server_port_script . $request->path, 'atom');
  $feed->addAuthor(array(
        'name'  => $principal->GetProperty('displayname'),
        'email' => $principal->GetProperty('email'),
        'uri'   => $c->protocol_server_port . $principal->url(),
  ));
  $feed_description = $collection->GetProperty('description');
  if ( isset($feed_description) && $feed_description != '' ) $feed->setDescription($feed_description);

  require_once('RRule.php');

  $need_zones = array();
  $timezones = array();
  while( $event = $qry->Fetch() ) {
    if ( $event->caldav_type != 'VEVENT' && $event->caldav_type != 'VTODO' && $event->caldav_type != 'VJOURNAL') {
      dbg_error_log( 'feed', 'Skipping peculiar "%s" component in VCALENDAR', $event->caldav_type );
      continue;
    }
    $is_todo = ($event->caldav_type == 'VTODO');

    $ical = new vComponent( $event->caldav_data );
    $event_data = $ical->GetComponents('VTIMEZONE', false);

    $item = $feed->createEntry();
    $item->setId( $c->protocol_server_port_script . ConstructURL($event->dav_name) );

    $dt_created = new RepeatRuleDateTime( $event->created );
    $item->setDateCreated( $dt_created->epoch() );

    $dt_modified = new RepeatRuleDateTime( $event->modified );
    $item->setDateModified( $dt_modified->epoch() );

    $summary = $event->summary;
    $p_title = ($summary != '' ? $summary : translate('No summary'));
    if ( $is_todo ) $p_title = "TODO: " . $p_title;
    $item->setTitle($p_title);

    $content = "";

    $dt_start = new RepeatRuleDateTime($event->dtstart);
    if  ( $dt_start != null ) {
      $p_time = '<strong>' . translate('Time') . ':</strong> ' . strftime(translate('%F %T'), $dt_start->epoch());

      $dt_end = new RepeatRuleDateTime($event->dtend);
      if  ( $dt_end != null ) {
        $p_time .= ' - ' . ( $dt_end->AsDate() == $dt_start->AsDate()
                                 # Translators: his is the formatting of just the time. See http://php.net/manual/en/function.strftime.php
                                 ? strftime(translate('%T'), $dt_end->epoch())
                                 # Translators: this is the formatting of a date with time. See http://php.net/manual/en/function.strftime.php
                                 : strftime(translate('%F %T'), $dt_end->epoch())
                            );
      }
      $content .= $p_time;
    }

    $p_location = $event_data[0]->GetProperty('LOCATION');
    if ( $p_location != null )
    $content .= '<br />'
    .'<strong>' . translate('Location') . '</strong>: ' . hyperlink($p_location->Value());

    $p_attach = $event_data[0]->GetProperty('ATTACH');
    if ( $p_attach != null )
    $content .= '<br />'
    .'<strong>' . translate('Attachment') . '</strong>: ' . hyperlink($p_attach->Value());

    $p_url = $event_data[0]->GetProperty('URL');
    if ( $p_url != null )
    $content .= '<br />'
    .'<strong>' . translate('URL') . '</strong>: ' . hyperlink($p_url->Value());

    $p_cat = $event_data[0]->GetProperty('CATEGORIES');
    if ( $p_cat != null ) {
      $content .= '<br />' .'<strong>' . translate('Categories') . '</strong>: ' . $p_cat->Value();
      $categories = explode(',',$p_cat->Value());
      foreach( $categories AS $category ) {
        $item->addCategory( array('term' => trim($category)) );
      }
    }

    $p_description = $event->description;
    if ( $p_description != '' ) {
      $content .= '<br />'
      .'<br />'
      .'<strong>' . translate('Description') . '</strong>:<br />' . ( nl2br(hyperlink($p_description)) )
      ;
      $item->setDescription($p_description);
    }

    $item->setContent($content);
    $feed->addEntry($item);
    //break;
  }
  $last_modified = new RepeatRuleDateTime($collection->GetProperty('modified'));
  $feed->setDateModified($last_modified->epoch());
  $response = $feed->export('atom');
  $cache->set( $cache_ns, $cache_key, $response );
  return $response;
}

if ( $request->method == 'GET' ) {
  $collection = new DAVResource($request->path);
  $response = caldav_get_feed( $request, $collection );
  header( 'Content-Length: '.strlen($response) );
  header( 'Etag: '.$collection->unique_tag() );
  $request->DoResponse( 200, ($request->method == 'HEAD' ? '' : $response), 'text/xml; charset="utf-8"' );
}
else {
  dbg_error_log( 'feed', 'Unhandled request method >>%s<<', $request->method );
  dbg_log_array( 'feed', '_SERVER', $_SERVER, true );
  dbg_error_log( 'feed', 'RAW: %s', str_replace("\n", '',str_replace("\r", '', $request->raw_post)) );
}

$request->DoResponse( 500, translate('The application program does not understand that request.') );

/* vim: set ts=2 sw=2 tw=0 :*/
DAViCal API documentation generated by ApiGen