本文整理汇总了PHP中DOMNode::hasChildren方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMNode::hasChildren方法的具体用法?PHP DOMNode::hasChildren怎么用?PHP DOMNode::hasChildren使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMNode
的用法示例。
在下文中一共展示了DOMNode::hasChildren方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addQuotesAndStripTags
/**
* convert blockquotes to quotes ("> ") and strip tags
*
* this function uses tidy or DOM to recursivly walk the dom tree of the html mail
* @see http://php.net/manual/de/tidy.root.php
* @see http://php.net/manual/en/book.dom.php
*
* @param tidyNode|DOMNode $_node
* @param integer $_quoteIndent
* @param string $_eol
* @return string
*
* @todo we can transform more tags here, i.e. the <strong>BOLDTEXT</strong> tag could be replaced with *BOLDTEXT*
* @todo think about removing the tidy code
* @todo reduce complexity
*/
public static function addQuotesAndStripTags($_node, $_quoteIndent = 0, $_eol = "\n")
{
$result = '';
$hasChildren = $_node instanceof DOMNode ? $_node->hasChildNodes() : $_node->hasChildren();
$nameProperty = $_node instanceof DOMNode ? 'nodeName' : 'name';
$valueProperty = $_node instanceof DOMNode ? 'nodeValue' : 'value';
$divNewline = FALSE;
if ($hasChildren) {
$lastChild = NULL;
$children = $_node instanceof DOMNode ? $_node->childNodes : $_node->child;
if ($_node->{$nameProperty} == 'div') {
$divNewline = TRUE;
}
foreach ($children as $child) {
$isTextLeaf = $child instanceof DOMNode ? $child->{$nameProperty} == '#text' : !$child->{$nameProperty};
if ($isTextLeaf) {
// leaf -> add quotes and append to content string
if ($_quoteIndent > 0) {
$result .= str_repeat(self::QUOTE, $_quoteIndent) . $child->{$valueProperty};
} else {
if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . "value: " . $child->{$valueProperty} . " / name: " . $_node->{$nameProperty} . "\n");
}
if ($divNewline) {
$result .= $_eol . str_repeat(self::QUOTE, $_quoteIndent);
$divNewline = FALSE;
}
$result .= $child->{$valueProperty};
}
} else {
if ($child->{$nameProperty} == 'blockquote') {
// opening blockquote
$_quoteIndent++;
} else {
if ($child->{$nameProperty} == 'br') {
if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . "value: " . $child->{$valueProperty} . " / name: " . $_node->{$nameProperty} . "\n");
}
// reset quoted state on newline
if ($lastChild !== NULL && $lastChild->{$nameProperty} == 'br') {
// add quotes to repeating newlines
$result .= str_repeat(self::QUOTE, $_quoteIndent);
}
$result .= $_eol;
$divNewline = FALSE;
}
}
}
$result .= self::addQuotesAndStripTags($child, $_quoteIndent, $_eol);
if ($child->{$nameProperty} == 'blockquote') {
// closing blockquote
$_quoteIndent--;
// add newline after last closing blockquote
if ($_quoteIndent == 0) {
$result .= $_eol;
}
}
$lastChild = $child;
}
// add newline if closing div
if ($divNewline) {
$result .= $_eol . str_repeat(self::QUOTE, $_quoteIndent);
}
}
return $result;
}