Esempio n. 1
0
 /**
  * parses a STRING represeting an iCalendar (vCalendar 2)
  * @param STRING $str - iCalendar formatted String
  * @return
  */
 function parse($str)
 {
     $this->data = array();
     $lines = explode("\n", $str);
     $cur = null;
     for ($i = 0; $i < count($lines); $i++) {
         $line = trim($lines[$i]);
         while (!empty($lines[$i + 1]) && substr($lines[$i + 1], 0, 1) == " ") {
             $line .= trim(substr($lines[$i + 1], 1));
             $i++;
         }
         $kv = explode(':', $line, 2);
         if (count($kv) == 1) {
             continue;
         }
         $key = trim($kv[0]);
         $value = trim($kv[1]);
         switch ($key) {
             case 'END':
                 switch ($value) {
                     case 'VCALENDAR':
                         if ($cur) {
                             $this->data['calendar'][] = $cur;
                             $cur = null;
                         }
                         break;
                     default:
                         if ($cur) {
                             $cur->process($key, $value);
                         } else {
                             throw new Exception('Invalid END Tag - ' . $line);
                         }
                 }
                 break;
             case 'BEGIN':
                 switch ($value) {
                     case 'VCALENDAR':
                         $cur = new vCalendar();
                         break;
                     default:
                         if ($cur) {
                             $cur->process($key, $value);
                         } else {
                             throw new Exception('Invalid BEGIN Tag - ' . $line);
                         }
                 }
                 break;
             default:
                 if ($cur) {
                     $cur->process($key, $value);
                 } else {
                     throw new Exception('Invalid Tag - ' . $line);
                 }
         }
     }
 }