ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilICalWriter.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
25{
26 const LINEBREAK = "\r\n";
27 #const LINEBREAK = '<br />';
28 // minus one to fix multi line breaks.
29 const LINE_SIZE = 74;
31
32 private $ical = '';
33
34 public function __construct()
35 {
36 $this->ical = '';
37 }
38
39 public static function escapeText($a_text)
40 {
41 $a_text = str_replace("\r\n", '\\n', $a_text);
42
43 return preg_replace(
44 array(
45 '/\\\/',
46 '/;/',
47 '/,/',
48 ),
49 array(
50 '\\',
51 '\;',
52 '\,',
53 ),
54 $a_text
55 );
56 }
57
63 public function addLine($a_line)
64 {
65 //$chunks = str_split($a_line, self::LINE_SIZE);
66
67 include_once './Services/Utilities/classes/class.ilStr.php';
68
69 // use multibyte split
70 $chunks = array();
71 $len = ilStr::strLen($a_line);
72 while ($len) {
73 $chunks[] = ilStr::subStr($a_line, 0, self::LINE_SIZE);
74 $a_line = ilStr::subStr($a_line, self::LINE_SIZE, $len);
75 $len = ilStr::strLen($a_line);
76 }
77
78 for ($i = 0; $i < count($chunks); $i++) {
79 $this->ical .= $chunks[$i];
80 if (isset($chunks[$i+1])) {
81 $this->ical .= self::LINEBREAK;
82 $this->ical .= self::BEGIN_LINE_WHITESPACE;
83 }
84 }
85 $this->ical .= self::LINEBREAK;
86 }
87
92 public function __toString()
93 {
94 return $this->ical;
95 }
96}
An exception for terminatinating execution or to throw for unit testing.
static escapeText($a_text)
addLine($a_line)
Add a line to the ical string.
__toString()
Return ical string.
static subStr($a_str, $a_start, $a_length=null)
Definition: class.ilStr.php:15
static strLen($a_string)
Definition: class.ilStr.php:78
$i
Definition: disco.tpl.php:19