function item_to_xml($item, $xml) { if (!array_key_exists('tag', $item)) { error_log("no tag for: " . print_r($item, true)); } $elem = $xml->createElement($item['tag']); if (array_key_exists('children', $item)) { foreach ($item['children'] as $child) { $childxml = item_to_xml($child, $xml); $elem->appendChild($childxml); } } if (array_key_exists('text', $item)) { $elem->appendChild($xml->createTextNode($item['text'])); } if (array_key_exists('cdata', $item)) { $elem->appendChild($xml->createCDATASection($item['cdata'])); } if (array_key_exists('attr', $item)) { foreach ($item['attr'] as $attr => $val) { $elem->setAttribute($attr, $val); } } return $elem; }
/** * Get XML response for a single item. Depth is irrelevant for this. */ function get_item($item_path) { global $session; $responses = array(); dbg_error_log("PROPFIND", "Getting item: Path: %s", $item_path); $sql = "SELECT caldav_data.dav_name, caldav_data, caldav_data.dav_etag "; $sql .= "FROM caldav_data WHERE dav_name = ?"; $qry = new PgQuery($sql, PgQuery::Plain(iCalendar::HttpDateFormat()), PgQuery::Plain(iCalendar::HttpDateFormat()), $item_path); if ($qry->Exec("PROPFIND", __LINE__, __FILE__) && $qry->rows > 0) { while ($item = $qry->Fetch()) { $responses[] = item_to_xml($item); } } return $responses; }