/** * Encode for cal export * * @param string $format vcal or ical * @param string $string string to encode * @return string string encoded */ function format_cal($format, $string) { global $conf; $newstring = $string; if ($format == 'vcal') { $newstring = quotedPrintEncode($newstring); } if ($format == 'ical') { // Replace new lines chars by '\n' $newstring = preg_replace('/' . "\r\n" . '/i', "\n", $newstring); $newstring = preg_replace('/' . "\n\r" . '/i', "\n", $newstring); $newstring = preg_replace('/' . "\n" . '/i', '\\n', $newstring); // Must not exceed 75 char. Cut with "\r\n"+Space $newstring = calEncode($newstring); } return $newstring; }
/** * 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); }