Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Making a Calendar public via the ACL feed


Google Calendar allows individual calendars to be marked as public, meaning that they can be accessed either via the Calendar UI, embeded calendars, or the Calendar Data API without requiring a password.

Normally, this option is enabled from within the Calendar UI. However, it can be enabled using the Calendar Data API as well. To do so, you'd send the following HTTP request:

POST /calendar/feeds/default/acl/full
Host: www.google.com


  
  
  

In this case, this will make the default calendar as public. If you want to make a secondary calendar public, replace default in the request's location with the desired calendar ID.

XML PHP Pretty Printer


<?
/** Prettifies an XML string into a human-readable and indented work of art
 *  @param string $xml The XML as a string
 *  @param boolean $html_output True if the output should be escaped (for use in HTML)
 */
function xmlpp($xml, $html_output=false) {
    $xml_obj = new SimpleXMLElement($xml);
    $level = 4;
    $indent = 0; // current indentation level
    $pretty = array();
    
    // get an array containing each XML element
    $xml = explode("\n", preg_replace('/>\s*</', ">\n<", $xml_obj->asXML()));

    // shift off opening XML tag if present
    if (count($xml) && preg_match('/^<\?\s*xml/', $xml[0])) {
      $pretty[] = array_shift($xml);
    }

    foreach ($xml as $el) {
      if (preg_match('/^<([\w])+[^>\/]*>$/U', $el)) {
          // opening tag, increase indent
          $pretty[] = str_repeat(' ', $indent) . $el;
          $indent += $level;
      } else {
        if (preg_match('/^<\/.+>$/', $el)) {            
          $indent -= $level;  // closing tag, decrease indent
        }
        if ($indent < 0) {
          $indent += $level;
        }
        $pretty[] = str_repeat(' ', $indent) . $el;
      }
    }   
    $xml = implode("\n", $pretty);   
    return ($html_output) ? htmlentities($xml) : $xml;
}

echo '<pre>' . xmlpp($xml, true) . '</pre>';
?>