コード例 #1
0
ファイル: ical.class.php プロジェクト: Samara94/dolibarr
 /**
  * Translate Calendar
  *
  * @param	string 	$uri	Url
  * @return	array
  */
 function parse($uri)
 {
     $this->cal = array();
     // new empty array
     $this->event_count = -1;
     // read FILE text
     $this->file_text = $this->read_file($uri);
     $this->file_text = preg_split("[\n]", $this->file_text);
     // is this text vcalendar standart text ? on line 1 is BEGIN:VCALENDAR
     if (!stristr($this->file_text[0], 'BEGIN:VCALENDAR')) {
         return 'error not VCALENDAR';
     }
     $insidealarm = 0;
     $tmpkey = '';
     $tmpvalue = '';
     foreach ($this->file_text as $text) {
         $text = trim($text);
         // trim one line
         if (!empty($text)) {
             // get Key and Value VCALENDAR:Begin -> Key = VCALENDAR, Value = begin
             list($key, $value) = $this->retun_key_value($text);
             //var_dump($text.' -> '.$key.' - '.$value);
             switch ($text) {
                 case "BEGIN:VTODO":
                     $this->todo_count = $this->todo_count + 1;
                     // new to do begin
                     $type = "VTODO";
                     break;
                 case "BEGIN:VEVENT":
                     $this->event_count = $this->event_count + 1;
                     // new event begin
                     $type = "VEVENT";
                     break;
                 case "BEGIN:VFREEBUSY":
                     $this->freebusy_count = $this->freebusy_count + 1;
                     // new event begin
                     $type = "VFREEBUSY";
                     break;
                 case "BEGIN:VCALENDAR":
                     // all other special string
                 // all other special string
                 case "BEGIN:DAYLIGHT":
                 case "BEGIN:VTIMEZONE":
                 case "BEGIN:STANDARD":
                     $type = $value;
                     // save array under value key
                     break;
                 case "END:VTODO":
                     // end special text - goto VCALENDAR key
                 // end special text - goto VCALENDAR key
                 case "END:VEVENT":
                 case "END:VFREEBUSY":
                 case "END:VCALENDAR":
                 case "END:DAYLIGHT":
                 case "END:VTIMEZONE":
                 case "END:STANDARD":
                     $type = "VCALENDAR";
                     break;
                     // Manage VALARM that are inside a VEVENT to avoid fields of VALARM to overwrites fields of VEVENT
                 // Manage VALARM that are inside a VEVENT to avoid fields of VALARM to overwrites fields of VEVENT
                 case "BEGIN:VALARM":
                     $insidealarm = 1;
                     break;
                 case "END:VALARM":
                     $insidealarm = 0;
                     break;
                 default:
                     // no special string (SUMMARY, DESCRIPTION, ...)
                     if ($tmpvalue) {
                         $tmpvalue .= $text;
                         if (!preg_match('/=$/', $text)) {
                             $key = $tmpkey;
                             $value = quotedPrintDecode(preg_replace('/^ENCODING=QUOTED-PRINTABLE:/i', '', $tmpvalue));
                             $tmpkey = '';
                             $tmpvalue = '';
                         }
                     } elseif (preg_match('/^ENCODING=QUOTED-PRINTABLE:/i', $value)) {
                         if (preg_match('/=$/', $value)) {
                             $tmpkey = $key;
                             $tmpvalue = $tmpvalue . preg_replace('/=$/', "", $value);
                             // We must wait to have next line to have complete message
                         } else {
                             $value = quotedPrintDecode(preg_replace('/^ENCODING=QUOTED-PRINTABLE:/i', '', $tmpvalue . $value));
                         }
                     }
                     //$value=quotedPrintDecode($tmpvalue.$value);
                     if (!$insidealarm && !$tmpkey) {
                         $this->add_to_array($type, $key, $value);
                     }
                     // add to array
                     break;
             }
         }
     }
     //var_dump($this->cal);
     return $this->cal;
 }
コード例 #2
0
ファイル: XCalLibTest.php プロジェクト: Samara94/dolibarr
 /**
  * testQuotedPrintEncodeDecode
  *
  * @return  void
  */
 public function testQuotedPrintEncodeDecode()
 {
     global $conf, $user, $langs, $db;
     $conf = $this->savconf;
     $user = $this->savuser;
     $langs = $this->savlangs;
     $db = $this->savdb;
     $stringtoencode = 'ABCD=1234;';
     $result = quotedPrintEncode($stringtoencode);
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertEquals('ABCD=3D1234;', $result);
     $resultback = quotedPrintDecode($result);
     print __METHOD__ . " result=" . $resultback . "\n";
     $this->assertEquals($stringtoencode, $resultback);
 }