61 $this->parameters = array();
62 unset($this->rendered);
63 if ( $propstring !=
null && gettype($propstring) ==
'string' ) {
78 $this->rendered = (strlen($propstring) < 72 ? $propstring :
null);
81 $unescaped = preg_replace(
'{\\\\[nN]}',
"\n", $propstring);
92 $split = $this->SplitQuoted($unescaped,
':', 2);
93 if (count($split) != 2) {
95 dbg_error_log(
'ERROR',
"iCalendar::ParseFrom(): Couldn't parse property from string: `%s`, skipping", $unescaped);
98 list($prop, $value) = $split;
101 $this->content = preg_replace(
"/\\\\([,;:\"\\\\])/",
'$1', $value);
104 $parameters = $this->SplitQuoted($prop,
';');
105 $this->name = array_shift($parameters);
106 $this->parameters = array();
107 foreach ($parameters AS $k => $v) {
108 $pos = strpos($v,
'=');
109 $name = substr($v, 0, $pos);
110 $value = substr($v, $pos + 1);
111 $this->parameters[$name] = preg_replace(
'/^"(.+)"$/',
'$1', $value);
124 function SplitQuoted($str, $sep =
',', $limit = 0) {
129 for($i = 0, $len = strlen($str); $i < $len; ++$i) {
132 $inquote = !$inquote;
134 if (!$inquote && $ch == $sep) {
138 if ($limit > 0 && $num == $limit) {
139 $result[] = substr($str, $cursor);
142 $result[] = substr($str, $cursor, $i - $cursor);
146 if ($i + 1 == $len) {
148 $result[] = substr($str, $cursor);
162 function Name( $newname =
null ) {
163 if ( $newname !=
null ) {
164 $this->name = $newname;
165 if ( isset($this->rendered) ) unset($this->rendered);
179 function Value( $newvalue =
null ) {
180 if ( $newvalue !=
null ) {
181 $this->content = $newvalue;
182 if ( isset($this->rendered) ) unset($this->rendered);
184 return $this->content;
195 function Parameters( $newparams =
null ) {
196 if ( $newparams !=
null ) {
197 $this->parameters = $newparams;
198 if ( isset($this->rendered) ) unset($this->rendered);
200 return $this->parameters;
211 function TextMatch( $search ) {
212 if ( isset($this->content) ) {
213 return (stristr( $this->content, $search ) !==
false);
226 function GetParameterValue( $name ) {
227 if ( isset($this->parameters[$name]) )
return $this->parameters[$name];
237 function SetParameterValue( $name, $value ) {
238 if ( isset($this->rendered) ) unset($this->rendered);
239 $this->parameters[$name] = $value;
246 function RenderParameters() {
248 foreach( $this->parameters AS $k => $v ) {
249 $escaped = preg_replace(
"/([;:])/",
'\\\\$1', $v);
250 $rendered .= sprintf(
";%s=%s", $k, $escaped );
262 if ( isset($this->rendered) )
return $this->rendered;
264 $property = preg_replace(
'/[;].*$/',
'', $this->name );
265 $escaped = $this->content;
266 switch( $property ) {
268 case 'ATTACH':
case 'GEO':
case 'PERCENT-COMPLETE':
case 'PRIORITY':
269 case 'DURATION':
case 'FREEBUSY':
case 'TZOFFSETFROM':
case 'TZOFFSETTO':
270 case 'TZURL':
case 'ATTENDEE':
case 'ORGANIZER':
case 'RECURRENCE-ID':
271 case 'URL':
case 'EXRULE':
case 'SEQUENCE':
case 'CREATED':
272 case 'RRULE':
case 'REPEAT':
case 'TRIGGER':
275 case 'COMPLETED':
case 'DTEND':
276 case 'DUE':
case 'DTSTART':
277 case 'DTSTAMP':
case 'LAST-MODIFIED':
278 case 'CREATED':
case 'EXDATE':
280 if ( isset($this->parameters[
'VALUE']) && $this->parameters[
'VALUE'] ==
'DATE' ) {
281 $escaped = substr( $escaped, 0, 8);
287 $escaped = str_replace(
'\\',
'\\\\', $escaped);
288 $escaped = preg_replace(
'/\r?\n/',
'\\n', $escaped);
289 $escaped = preg_replace(
"/([,;])/",
'\\\\$1', $escaped);
291 $property = sprintf(
"%s%s:", $this->name, $this->RenderParameters() );
292 if ( (strlen($property) + strlen($escaped)) <= 72 ) {
293 $this->rendered = $property . $escaped;
295 else if ( (strlen($property) + strlen($escaped)) > 72 && (strlen($property) < 72) && (strlen($escaped) < 72) ) {
296 $this->rendered = $property .
"\r\n " . $escaped;
299 $this->rendered = preg_replace(
'/(.{72})/u',
'$1'.
"\r\n ", $property . $escaped );
301 return $this->rendered;