firstChild; $child !== NULL; $child = $child->nextSibling) { if ($child->nodeType !== XML_TEXT_NODE) { $has_non_text_child = TRUE; process_node($econf, $in_elm, $out_elm); } } if (!$has_non_text_child) { $count = intval($in_elm->textContent); ++$count; replace_children($in_elm, $in_elm->ownerDocument->createTextNode($count)); $econf->modified_now(); process_node($econf, $in_elm, $out_elm); } } function process_next_element($econf, $in_elm) { remove_node_shallow($in_elm); $econf->modified_now(); } function process_once_element($econf, $in_elm) { $in_elm->parentNode->removeChild($in_elm); $econf->modified_now(); } function process_del_element($econf, $in_elm) { $in_elm->parentNode->removeChild($in_elm); $econf->modified_now(); } function process_res_element($econf, $in_elm, $out_elm) { $res = $in_elm->ownerDocument->importNode($out_elm, TRUE); replace_content($in_elm, $res); remove_node_shallow($in_elm); $econf->modified_now(); } function prepare_undo($econf, $in_elm) { $template = get_w2ml_attribute($in_elm, 'template'); if ($in_elm->namespaceURI === W2ML_NS && $in_elm->localName === 'undo' || $in_elm->namespaceURI !== W2ML_NS && $template !== NULL) { $undo_elm = $in_elm->cloneNode(TRUE); $econf->store_undo_data($undo_elm); } } function finish_undo($econf, $in_elm) { $undo_elm = $econf->revert_undo_data(); if ($undo_elm !== NULL) { $in_elm->parentNode->replaceChild($undo_elm, $in_elm); } } function process_once_attribute($econf, $in_elm) { for ($pass = 1; ($once_attr = get_w2ml_attribute($in_elm, 'once')) !== NULL; ++$pass) { $once_value = $once_attr->value; $in_elm->removeAttributeNode($once_attr); $econf->modified_now(); add_once_attribute($econf, $pass, $once_value, $in_elm); } } function process_next_attribute($econf, $in_elm) { $next_attr = get_w2ml_attribute($in_elm, 'next'); if ($next_attr !== NULL) { $next_value = $next_attr->value; $in_elm->removeAttributeNode($next_attr); $econf->modified_now(); add_next_attribute($econf, $next_value, $in_elm); } } function add_once_attribute($econf, $pass, $attr_markup, $element) { $once_attrs = parse_attribute_markup($econf, $attr_markup, $element); if ($once_attrs !== NULL) { $econf->once_attrs = array_merge($econf->once_attrs, $once_attrs); $replaced_attrs = set_attributes($element, $once_attrs); if ($pass === 1) { $econf->once_orig_attrs = $replaced_attrs; } } } function add_next_attribute($econf, $attr_markup, $element) { $next_attrs = parse_attribute_markup($econf, $attr_markup, $element); if ($next_attrs !== NULL) { set_attributes($element, $next_attrs); } } # Parse $attr_markup in the context of $element opening tag. The markup must be attribute-value # pairs and nothing else (injection of elements and other markup is prevented). # Return parsed attributes in an array. On error, return NULL and log. function parse_attribute_markup($econf, $attr_markup, $element) { $element_clone = $element->cloneNode(); remove_attributes($element_clone); $rand_attr_name = generate_str_id(ALPHA_STR, 15); $element_clone->setAttributeNS(NULL, $rand_attr_name, ''); $element->appendChild($element_clone); $markup = $element_clone->ownerDocument->saveXML(); $element->removeChild($element_clone); $markup = preg_replace('@('.$rand_attr_name.'="")@', '$1 '.$attr_markup, $markup); $dom = lib_xml_parse($markup); if (!is_string($dom)) { $element_clone = get_element_with_attribute_ns(NULL, $rand_attr_name, $dom->documentElement); if ($element_clone !== NULL && $element_clone->nextSibling === NULL && $element_clone->firstChild === NULL) { $element_clone->removeAttributeNS(NULL, $rand_attr_name); $res = get_attributes_array($element_clone); return $res; } else { log_error('Markup injection in attributes: "'.$attr_markup.'"', $econf->log); } } else { log_error('Invalid attributes: "'.$attr_markup.'"', $econf->log); } return NULL; } function process_once_attribute_2($econf, $in_elm) { foreach ($econf->once_attrs as $attr) { $in_elm->removeAttributeNS($attr->namespaceURI, $attr->localName); } foreach ($econf->once_orig_attrs as $attr) { $in_elm->setAttributeNS($attr->namespaceURI, $attr->nodeName, $attr->value); } } ?>