/** * creates formatted output for calendar component property * * @author Kjell-Inge Gustafsson, kigkonsult <*****@*****.**> * @since 2.16.2 - 2012-12-18 * @param string $label property name * @param string $attributes property attributes * @param string $content property content (optional) * @return string */ function _createElement($label, $attributes = null, $content = FALSE) { switch ($this->format) { case 'xcal': $label = strtolower($label); break; default: $label = strtoupper($label); break; } $output = $this->elementStart1 . $label; $categoriesAttrLang = null; $attachInlineBinary = FALSE; $attachfmttype = null; if ('xcal' == $this->format && 'x-' == substr($label, 0, 2)) { $this->xcaldecl[] = array('xmldecl' => 'ELEMENT', 'ref' => $label, 'type2' => '(#PCDATA)'); } if (!empty($attributes)) { $attributes = trim($attributes); if ('xcal' == $this->format) { $attributes2 = explode($this->intAttrDelimiter, $attributes); $attributes = null; foreach ($attributes2 as $aix => $attribute) { $attrKVarr = explode('=', $attribute); if (empty($attrKVarr[0])) { continue; } if (!isset($attrKVarr[1])) { $attrValue = $attrKVarr[0]; $attrKey = $aix; } elseif (2 == count($attrKVarr)) { $attrKey = strtolower($attrKVarr[0]); $attrValue = $attrKVarr[1]; } else { $attrKey = strtolower($attrKVarr[0]); unset($attrKVarr[0]); $attrValue = implode('=', $attrKVarr); } if ('attach' == $label && in_array($attrKey, array('fmttype', 'encoding', 'value'))) { $attachInlineBinary = TRUE; if ('fmttype' == $attrKey) { $attachfmttype = $attrKey . '=' . $attrValue; } continue; } elseif ('categories' == $label && 'language' == $attrKey) { $categoriesAttrLang = $attrKey . '=' . $attrValue; } else { $attributes .= empty($attributes) ? ' ' : $this->attributeDelimiter . ' '; $attributes .= !empty($attrKey) ? $attrKey . '=' : null; if ('"' == substr($attrValue, 0, 1) && '"' == substr($attrValue, -1)) { $attrValue = substr($attrValue, 1, strlen($attrValue) - 2); $attrValue = str_replace('"', '', $attrValue); } $attributes .= '"' . htmlspecialchars($attrValue) . '"'; } } } else { $attributes = str_replace($this->intAttrDelimiter, $this->attributeDelimiter, $attributes); } } if ('xcal' == $this->format && ('attach' == $label && !$attachInlineBinary || in_array($label, array('tzurl', 'url')))) { $pos = strrpos($content, "/"); $docname = $pos !== false ? substr($content, 1 - strlen($content) + $pos) : $content; $this->xcaldecl[] = array('xmldecl' => 'ENTITY', 'uri' => $docname, 'ref' => 'SYSTEM', 'external' => $content, 'type' => 'NDATA', 'type2' => 'BINERY'); $attributes .= empty($attributes) ? ' ' : $this->attributeDelimiter . ' '; $attributes .= 'uri="' . $docname . '"'; $content = null; if ('attach' == $label) { $attributes = str_replace($this->attributeDelimiter, $this->intAttrDelimiter, $attributes); $content = $this->nl . $this->_createElement('extref', $attributes, null); $attributes = null; } } elseif ('xcal' == $this->format && 'attach' == $label && $attachInlineBinary) { $content = $this->nl . $this->_createElement('b64bin', $attachfmttype, $content); // max one attribute } $output .= $attributes; if (!$content && '0' != $content) { switch ($this->format) { case 'xcal': $output .= ' /'; $output .= $this->elementStart2 . $this->nl; return $output; break; default: $output .= $this->elementStart2 . $this->valueInit; return ICalUtilityFunctions::_size75($output, $this->nl); break; } } $output .= $this->elementStart2; $output .= $this->valueInit . $content; switch ($this->format) { case 'xcal': return $output . $this->elementEnd1 . $label . $this->elementEnd2; break; default: return ICalUtilityFunctions::_size75($output, $this->nl); break; } }