/** * creates formatted output for calendar component property data value type duration * * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**> * @since 2.15.8 - 2012-10-30 * @param array $duration, array( week, day, hour, min, sec ) * @return string */ public static function _format_duration($duration) { return ICalUtilityFunctions::_duration2str($duration); }
/** * Add children to a SimpleXMLelement * * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**> * @since 2.15.5 - 2012-10-19 * @param object $parent, reference to a SimpleXMLelement node * @param string $name, new element node name * @param string $type, content type, subelement(-s) name * @param string $content, new subelement content * @param array $params, new element 'attributes' * @return void */ public static function _addXMLchild(&$parent, $name, $type, $content, $params = array()) { /** create new child node */ $name = strtolower($name); $child = $parent->addChild($name); if (isset($params['VALUE'])) { unset($params['VALUE']); } if (!empty($params)) { $parameters = $child->addChild('parameters'); foreach ($params as $param => $parVal) { $param = strtolower($param); if ('x-' == substr($param, 0, 2)) { $p1 = $parameters->addChild($param); $p2 = $p1->addChild('unknown', htmlspecialchars($parVal)); } else { $p1 = $parameters->addChild($param); switch ($param) { case 'altrep': case 'dir': $ptype = 'uri'; break; case 'delegated-from': case 'delegated-to': case 'member': case 'sent-by': $ptype = 'cal-address'; break; case 'rsvp': $ptype = 'boolean'; break; default: $ptype = 'text'; break; } if (is_array($parVal)) { foreach ($parVal as $pV) { $p2 = $p1->addChild($ptype, htmlspecialchars($pV)); } } else { $p2 = $p1->addChild($ptype, htmlspecialchars($parVal)); } } } } if (empty($content) && '0' != $content) { return; } /** store content */ switch ($type) { case 'binary': $v = $child->addChild($type, $content); break; case 'boolean': break; case 'cal-address': $v = $child->addChild($type, $content); break; case 'date': if (array_key_exists('year', $content)) { $content = array($content); } foreach ($content as $date) { $str = sprintf('%04d-%02d-%02d', $date['year'], $date['month'], $date['day']); $v = $child->addChild($type, $str); } break; case 'date-time': if (array_key_exists('year', $content)) { $content = array($content); } foreach ($content as $dt) { if (!isset($dt['hour'])) { $dt['hour'] = 0; } if (!isset($dt['min'])) { $dt['min'] = 0; } if (!isset($dt['sec'])) { $dt['sec'] = 0; } $str = sprintf('%04d-%02d-%02dT%02d:%02d:%02d', $dt['year'], $dt['month'], $dt['day'], $dt['hour'], $dt['min'], $dt['sec']); if (isset($dt['tz']) && 'Z' == $dt['tz']) { $str .= 'Z'; } $v = $child->addChild($type, $str); } break; case 'duration': $output = 'trigger' == $name && FALSE !== $content['before'] ? '-' : ''; $v = $child->addChild($type, $output . ICalUtilityFunctions::_duration2str($content)); break; case 'geo': $v1 = $child->addChild('latitude', number_format((double) $content['latitude'], 6, '.', '')); $v1 = $child->addChild('longitude', number_format((double) $content['longitude'], 6, '.', '')); break; case 'integer': $v = $child->addChild($type, $content); break; case 'period': if (!is_array($content)) { break; } foreach ($content as $period) { $v1 = $child->addChild($type); $str = sprintf('%04d-%02d-%02dT%02d:%02d:%02d', $period[0]['year'], $period[0]['month'], $period[0]['day'], $period[0]['hour'], $period[0]['min'], $period[0]['sec']); if (isset($period[0]['tz']) && 'Z' == $period[0]['tz']) { $str .= 'Z'; } $v2 = $v1->addChild('start', $str); if (array_key_exists('year', $period[1])) { $str = sprintf('%04d-%02d-%02dT%02d:%02d:%02d', $period[1]['year'], $period[1]['month'], $period[1]['day'], $period[1]['hour'], $period[1]['min'], $period[1]['sec']); if (isset($period[1]['tz']) && 'Z' == $period[1]['tz']) { $str .= 'Z'; } $v2 = $v1->addChild('end', $str); } else { $v2 = $v1->addChild('duration', ICalUtilityFunctions::_duration2str($period[1])); } } break; case 'recur': foreach ($content as $rulelabel => $rulevalue) { $rulelabel = strtolower($rulelabel); switch ($rulelabel) { case 'until': if (isset($rulevalue['hour'])) { $str = sprintf('%04d-%02d-%02dT%02d:%02d:%02dZ', $rulevalue['year'], $rulevalue['month'], $rulevalue['day'], $rulevalue['hour'], $rulevalue['min'], $rulevalue['sec']); } else { $str = sprintf('%04d-%02d-%02d', $rulevalue['year'], $rulevalue['month'], $rulevalue['day']); } $v = $child->addChild($rulelabel, $str); break; case 'bysecond': case 'byminute': case 'byhour': case 'bymonthday': case 'byyearday': case 'byweekno': case 'bymonth': case 'bysetpos': if (is_array($rulevalue)) { foreach ($rulevalue as $vix => $valuePart) { $v = $child->addChild($rulelabel, $valuePart); } } else { $v = $child->addChild($rulelabel, $rulevalue); } break; case 'byday': if (isset($rulevalue['DAY'])) { $str = isset($rulevalue[0]) ? $rulevalue[0] : ''; $str .= $rulevalue['DAY']; $p = $child->addChild($rulelabel, $str); } else { foreach ($rulevalue as $valuePart) { if (isset($valuePart['DAY'])) { $str = isset($valuePart[0]) ? $valuePart[0] : ''; $str .= $valuePart['DAY']; $p = $child->addChild($rulelabel, $str); } else { $p = $child->addChild($rulelabel, $valuePart); } } } break; case 'freq': case 'count': case 'interval': case 'wkst': default: $p = $child->addChild($rulelabel, $rulevalue); break; } // end switch( $rulelabel ) } // end foreach( $content as $rulelabel => $rulevalue ) break; case 'rstatus': $v = $child->addChild('code', number_format((double) $content['statcode'], 2, '.', '')); $v = $child->addChild('description', htmlspecialchars($content['text'])); if (isset($content['extdata'])) { $v = $child->addChild('data', htmlspecialchars($content['extdata'])); } break; case 'text': if (!is_array($content)) { $content = array($content); } foreach ($content as $part) { $v = $child->addChild($type, htmlspecialchars($part)); } break; case 'time': break; case 'uri': $v = $child->addChild($type, $content); break; case 'utc-offset': if (in_array(substr($content, 0, 1), array('-', '+'))) { $str = substr($content, 0, 1); $content = substr($content, 1); } else { $str = '+'; } $str .= substr($content, 0, 2) . ':' . substr($content, 2, 2); if (4 < strlen($content)) { $str .= ':' . substr($content, 4); } $v = $child->addChild($type, $str); break; case 'unknown': default: if (is_array($content)) { $content = implode('', $content); } $v = $child->addChild('unknown', htmlspecialchars($content)); break; } }
/** * creates formatted output for calendar component property trigger * * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**> * @since 2.4.16 - 2008-10-21 * @return string */ function createTrigger() { if (empty($this->trigger)) { return FALSE; } if (empty($this->trigger['value'])) { return $this->getConfig('allowEmpty') ? $this->_createElement('TRIGGER') : FALSE; } $content = $attributes = null; if (isset($this->trigger['value']['year']) && isset($this->trigger['value']['month']) && isset($this->trigger['value']['day'])) { $content .= ICalUtilityFunctions::_date2strdate($this->trigger['value']); } else { if (TRUE !== $this->trigger['value']['relatedStart']) { $attributes .= $this->intAttrDelimiter . 'RELATED=END'; } if ($this->trigger['value']['before']) { $content .= '-'; } $content .= ICalUtilityFunctions::_duration2str($this->trigger['value']); } $attributes .= $this->_createParams($this->trigger['params']); return $this->_createElement('TRIGGER', $attributes, $content); }