Pummel then insert HTML into our database

@param string $html
@param string $title
@param string $post_type (front-matter', 'chapter', 'back-matter')
@param int $chapter_parent
@param string $post_status
544431
protected function kneadAndInsert( $html, $title, $post_type, $chapter_parent, $post_status ) {

		$body = $this->tidy( $html );
		$body = $this->kneadHTML( $body );

		$title = wp_strip_all_tags( $title );

		$new_post = [
			'post_title' => $title,
			'post_content' => $body,
			'post_type' => $post_type,
			'post_status' => $post_status,
		];

		if ( 'chapter' === $post_type ) {
			$new_post['post_parent'] = $chapter_parent;
		}

		$pid = wp_insert_post( add_magic_quotes( $new_post ) );

		update_post_meta( $pid, 'pb_show_title', 'on' );

		Book::consolidatePost( $pid, get_post( $pid ) ); // Reorder
	}
872448
function _onChildNodeInserted(event, res) {
        // res = {parentNodeId, previousNodeId, node}
        if (res.node.nodeId > 0) {
            var parent = nodeWithId(res.parentNodeId);
            var previousNode = nodeWithId(res.previousNodeId);
            var node = new DOMNode(exports, res.node);
            parent.insertChildAfter(node, previousNode);
        }
    }
227198
public function add_meta_boxes($post_type, $post){
        if( $this->is_valid_post_type($post_type) && $this->has_cap() ){
            if( empty($this->name) || empty($this->label) ){
                $message = sprintf($this->__('<code>%s</code> has invalid name or label.'), get_called_class());
                add_action('admin_notices', function() use ($message) {
                    printf('<div class="error"><p>%s</p></div>', $message);
                });
            }else{
                add_meta_box($this->name, $this->label, [$this, 'render'], $post_type, $this->context, $this->priority);
            }
        }
    }
538675
function handleNode( $node, &$sectionLevel, $isLastTag = false )
    {
        $xhtmlTextContent = "";
//    if ( $node->namespaceURI() == 'http://openoffice.org/2000/text' )
        {

            // If another tag than paragraph comes then terminate collapsing tags, if any
            if ( $node->localName != "p" and $this->CollapsingTagName != false )
            {
                $xhtmlTextContent .= '<paragraph>' . '<' . $this->CollapsingTagName . ' ' . $this->CollapsingTagAttribute . ' >' . $this->CollapsingTagContent . "</" . $this->CollapsingTagName . ">\n</paragraph>\n";
                $this->CollapsingTagContent = false;
                $this->CollapsingTagAttribute = false;
                $this->CollapsingTagName = false;
            }

            switch ( $node->localName )
            {
                case 'sequence-decls' :
                case 'forms' :
                {
                    // do nothing
                }break;


                case 'section' :
                {
                    foreach ( $node->childNodes as $childNode )
                    {
                        $xhtmlTextContent  .= self::handleNode( $childNode, $sectionLevel );
                    }
                }break;

                case 'h' :
                {
                    $level = $node->getAttributeNS( self::NAMESPACE_TEXT, 'outline-level' );

                    if ( $level > 6 )
                        $level = 6;

                    if ( $level >= 1 && $level <= 6 )
                    {
                        $levelDiff = $level - $sectionLevel;
                        $sectionLevel = $level;
                        $headerContent = "";

                        foreach ( $node->childNodes as $childNode )
                        {
                            // Alex 2008/04/21 - added initializations for $nextlineBreak and $prevlineBreak
                            $nextLineBreak = ( isset( $childNode->nextSibling ) &&
                                               $childNode->nextSibling->localName == 'line-break' );

                            $prevLineBreak = ( isset( $childNode->previousSibling ) &&
                                               $childNode->previousSibling->localName == 'line-break' );

                            $headerContent .= self::handleInlineNode( $childNode, $nextLineBreak, $prevLineBreak );
                        }
                        $sectionLevel = $level;

                        if ( $levelDiff > 0 )
                            $xhtmlTextContent .= str_repeat( "<section>", $levelDiff );

                        if ( $levelDiff < 0 )
                            $xhtmlTextContent .= str_repeat( "</section>", abs( $levelDiff ) );

                        $xhtmlTextContent .= "<header>" . $headerContent . "</header>\n";
                    }
                    else
                    {
                        eZDebug::writeError( "Unsupported header level $level<br>" . $node->textContent . "<br>" );
                    }
                }break;

                case 'p' :
                {
                    $styleName = $node->getAttributeNS( self::NAMESPACE_TEXT, 'style-name' );

                    $lastCollapsingTagName = $this->CollapsingTagName;

                    // Check for custom tags

                    if ( substr( $styleName, 0, 12 ) == "eZCustom_20_" )
                    {
                        $customName = substr( $styleName, 12, strlen( $styleName ) - 12 );
                        $this->CollapsingTagName = "custom";
                        $this->CollapsingTagAttribute = "name='$customName'";
                    }
                    else
                    {
                        switch ( $styleName )
                        {
                            case "Preformatted_20_Text" :
                            {
                                $this->CollapsingTagName = "literal";
                            }break;
                            default:
                            {
                                $this->CollapsingTagName = false;
                            }break;
                        }
                    }

                    // Check for bold and italic styles
                    // OOo does not have tags for these styles but set the style on the whole paragraph
                    $fontWeight = false;
                    $fontStyle = false;
                    $headerLevel = false;
                    foreach ( $this->AutomaticStyles as $style )
                    {
                        if ( $style->nodeType !== XML_ELEMENT_NODE )
                        {
                            continue;
                        }

                        $tmpStyleName = $style->getAttributeNS( self::NAMESPACE_STYLE, "name" );

                        if ( $styleName == $tmpStyleName )
                        {
                            foreach ( $style->childNodes as $styleChild )
                            {
                                $fontWeight = $styleChild->getAttributeNS( self::NAMESPACE_FO, 'font-weight' );
                                $fontStyle = $styleChild->getAttributeNS( self::NAMESPACE_FO, 'font-style' );
                            }

                            // Get the parent style name, it's used to see if it's a
                            // header which comes from Word conversion
                            $parentStyleName = $style->getAttributeNS( self::NAMESPACE_STYLE, "parent-style-name" );

                            // Check if we've got a header definition and which level Heading_20
                            // Header styles is either defined in style-name or parent-style-name when
                            // converting a Word document to OOo, here we check the parent-style-name
                            if ( substr( $parentStyleName, 0, 11 ) == "Heading_20_" )
                            {
                                $level = substr( $parentStyleName, 11, strlen( $parentStyleName )  );
                                if ( is_numeric( $level ) )
                                    $headerLevel = $level;
                            }

                        }
                    }

                    // Check if paragraph style is set to a header in the style-name
                    if ( substr( $styleName, 0, 11 ) == "Heading_20_" )
                    {
                        $level = substr( $styleName, 11, strlen( $styleName )  );
                        if ( is_numeric( $level ) )
                            $headerLevel = $level;
                    }

                    $preStyles = "";
                    if ( $fontWeight == "bold" )
                        $preStyles .= "<strong>";
                    if ( $fontStyle == "italic" )
                        $preStyles .= "<emphasize>";

                    $postStyles = "";
                    if ( $fontStyle == "italic" )
                        $postStyles .= "</emphasize>";
                    if ( $fontWeight == "bold" )
                        $postStyles .= "</strong>";

                    $paragraphContent = "";
                    foreach ( $node->childNodes as $childNode )
                    {
                        $nextLineBreak = ( isset( $childNode->nextSibling ) &&
                                           $childNode->nextSibling->localName == 'line-break' );

                        $prevLineBreak = ( isset( $childNode->previousSibling ) &&
                                           $childNode->previousSibling->localName == 'line-break' );

                        $paragraphContent .= self::handleInlineNode( $childNode, $nextLineBreak, $prevLineBreak );
                    }

                    // If current paragraph is actually a header, then skip sub-formatting
                    if ( $headerLevel !== false )
                    {
                        if ( $level > 6 )
                            $level = 6;

                        if ( $level >= 1 && $level <= 6 )
                        {
                            $levelDiff = $level - $sectionLevel;
                            $sectionLevel = $level;

                            if ( $levelDiff > 0 )
                                $xhtmlTextContent .= str_repeat( "<section>", $levelDiff );

                            if ( $levelDiff < 0 )
                                $xhtmlTextContent .= str_repeat( "</section>", abs( $levelDiff ) );

                            $xhtmlTextContent .= "<header>" . $paragraphContent . "</header>\n";
                        }
                    }
                    else
                    {
                        // Handle normal paragraphs

                        if ( $this->CollapsingTagName == false )
                        {
                            // Add collapsed tag, if beyond the last collapsing tag
                            if ( $lastCollapsingTagName !== false )
                            {
                                // Content should be quoted because it breaks the XML.
                                $tagContent = str_replace( "&", "&amp;", $this->CollapsingTagContent );
                                $tagContent = str_replace( ">", "&gt;", $tagContent );
                                $tagContent = str_replace( "<", "&lt;", $tagContent );
                                $tagContent = str_replace( "'", "&apos;", $tagContent );
                                $tagContent = str_replace( '"', "&quot;", $tagContent );

                                $collapsingTagAttrText = $this->CollapsingTagAttribute ? ' ' . $this->CollapsingTagAttribute : '';
                                $xhtmlTextContent .= '<paragraph>' . '<' . $lastCollapsingTagName . $collapsingTagAttrText . '>' . $tagContent . "</" . $lastCollapsingTagName . ">\n</paragraph>\n";
                                $this->CollapsingTagContent = false;
                                $this->CollapsingTagAttribute = false;
                            }

                            if ( trim( $paragraphContent ) != "" )
                            {
                                $xhtmlTextContent .= '<paragraph>' . $preStyles . $paragraphContent . $postStyles . "</paragraph>\n";
                            }
                        }
                        else
                        {
                            if ( $isLastTag == true )
                            {
                                if ( $this->CollapsingTagName != false )
                                    $lastCollapsingTagName = $this->CollapsingTagName;
                                $xhtmlTextContent .= '<paragraph>' . '<' . $lastCollapsingTagName . ' ' . $this->CollapsingTagAttribute . '>' . $paragraphContent . "</" . $lastCollapsingTagName . ">\n</paragraph>\n";
                                $this->CollapsingTagContent = false;
                                $this->CollapsingTagAttribute = false;
                                $this->CollapsingTagName = false;
                            }
                            else
                            {
                                if ( $this->CollapsingTagName == "custom" )
                                {
                                    if ( trim( $paragraphContent ) != "" )
                                    {
                                        $this->CollapsingTagContent .= '<paragraph>' . $preStyles . $paragraphContent . $postStyles . "</paragraph>\n";
                                    }
                                }
                                else
                                {
                                    $this->CollapsingTagContent .= $paragraphContent . "\n";
                                }
                            }
                        }

                    }
                }break;

                case 'numbered-paragraph' :
                {
                    $listContent = "";
                    foreach ( $node->childNodes as $itemNode )
                    {
                        if ( $itemNode->localName == 'p' )
                        {
                            $listContent .= "<li>" . strip_tags( self::handleNode( $itemNode, $sectionLevel ) ) . "</li>";
                        }
                    }

                    $xhtmlTextContent .= "<paragraph><ul>" . $listContent . "</ul></paragraph>\n";
                }break;

                case 'list' :
                {
                    $styleName = $node->getAttributeNS( self::NAMESPACE_TEXT, 'style-name' );

                    // Check list style for unordered/ordered list
                    $listType = false;
                    foreach ( $this->AutomaticStyles as $style )
                    {
                        if ( $style->nodeType !== XML_ELEMENT_NODE )
                        {
                            continue;
                        }

                        $tmpStyleName = $style->getAttributeNS( self::NAMESPACE_STYLE, "name" );

                        if ( $styleName == $tmpStyleName )
                        {
                            if ( $style->childNodes->length >= 1 )
                            {
                                $children = $style->childNodes;

                                switch ( $children->item( 0 )->localName )
                                {
                                    case "list-level-style-number":
                                    {
                                        $listType = "ordered";
                                        $this->InsideListType = "ordered";
                                    } break;

                                    case "list-level-style-bullet":
                                    {
                                        $listType = "unordered";
                                        $this->InsideListType = "unordered";
                                    } break;
                                }
                            }
                        }
                    }

                    if ( $listType == false )
                        $listType = $this->InsideListType;

                    $listItemCount = 0;
                    $listContent = "";

                    $isSubList = $this->IsSubList;
                    $this->IsSubList = true;
                    foreach ( $node->childNodes as $itemNode )
                    {
                        if ( $itemNode->localName == 'list-item' )
                        {
                            foreach ( $itemNode->childNodes as $childNode )
                            {
                                $listItemContent = self::handleNode( $childNode, $sectionLevel );

                                if ( substr( $listItemContent, 0, 4 ) == "<ol>" or
                                     substr( $listItemContent, 0, 4 ) == "<ul>" )
                                {
                                    $listContent .= $listItemContent;
                                }
                                else
                                {
                                    $endItemTag = "</li>";
                                    if ( $listItemCount == 0 )
                                        $endItemTag = "";
                                    $listContent .= "$endItemTag<li>" . $listItemContent;
                                }

                                $listItemCount++;
                            }
                        }
                    }

                    $this->IsSubList = $isSubList;

                    $paragraphPreTag = "<paragraph>";
                    $paragraphPostTag = "</paragraph>";

                    // If we are inside a list, ommit paragraph tag
                    if ( $this->IsSubList != false )
                    {
                        $paragraphPreTag = "";
                        $paragraphPostTag = "";
                    }

                    // Do not add empty lists
                    if ( $listItemCount > 0 )
                    {
                        if ( $listType == "ordered" )
                            $xhtmlTextContent .= "$paragraphPreTag<ol>" . $listContent . "</li></ol>$paragraphPostTag\n";
                        else
                        {
                            $xhtmlTextContent .= "$paragraphPreTag<ul>" . $listContent . "</li></ul>$paragraphPostTag\n";
                        }
                    }
                }break;

                case 'table' :
                {
                    $tableContent = "";
                    foreach ( $node->childNodes as $itemNode )
                    {
                        if ( $itemNode->localName == 'table-header-rows' )
                        {
                            foreach ( $itemNode->childNodes as $headerRow )
                            {
                                if ( $headerRow->localName == 'table-row' )
                                {
                                    $rowContent = "";
                                    foreach ( $headerRow->childNodes as $tableCell )
                                    {
                                        $colSpan = $tableCell->getAttributeNS( self::NAMESPACE_TABLE, 'number-columns-spanned' );

                                        if ( $tableCell->localName == 'table-cell' )
                                        {
                                            $cellContent = "";
                                            foreach ( $tableCell->childNodes as $tableContentNode )
                                            {
                                                $cellContent .= self::handleNode( $tableContentNode, $sectionLevel );
                                            }
                                            $colSpanXML = "";
                                            if ( is_numeric( $colSpan ) and $colSpan > 1 )
                                            {
                                                $colSpanXML = " xhtml:colspan='$colSpan' ";
                                            }
                                            $rowContent .= "<th $colSpanXML>" . $cellContent . "</th>";
                                        }
                                    }
                                    $tableContent .= "<tr>" . $rowContent . "</tr>";
                                }
                            }
                        }
                        else if ( $itemNode->localName == 'table-row' )
                        {
                            $rowContent = "";
                            foreach ( $itemNode->childNodes as $tableCell )
                            {
                                if ( $tableCell->localName == 'table-cell' )
                                {
                                    $cellContent = "";
                                    $colSpan = $tableCell->getAttributeNS( self::NAMESPACE_TABLE, 'number-columns-spanned' );
                                    foreach ( $tableCell->childNodes as $tableContentNode )
                                    {
                                        $cellContent .= self::handleNode( $tableContentNode, $sectionLevel );
                                    }
                                    $colSpanXML = "";
                                    if ( is_numeric( $colSpan ) and $colSpan > 1 )
                                    {
                                        $colSpanXML = " xhtml:colspan='$colSpan' ";
                                    }
                                    $rowContent .= "<td $colSpanXML>" . $cellContent . "</td>";
                                }
                            }
                            $tableContent .= "<tr>" . $rowContent . "</tr>";
                        }
                    }
                    $xhtmlTextContent .= "<paragraph><table width='100%'>" . $tableContent . "</table></paragraph>";
                }break;


                default:
                {
                    eZDebug::writeError( "Unsupported top node " . $node->localName . "<br/>" );
                }break;
            }
        }
        return $xhtmlTextContent;
    }
418760
@Override protected void handleEvents(final String EVENT_TYPE) {
        super.handleEvents(EVENT_TYPE);

        if ("VISIBILITY".equals(EVENT_TYPE)) {
            Helper.enableNode(titleText, !tile.getTitle().isEmpty());
            Helper.enableNode(text, tile.isTextVisible());
            Helper.enableNode(valueText, tile.isValueVisible());
            Helper.enableNode(unitText, !tile.getUnit().isEmpty());
            Helper.enableNode(threshold, tile.isThresholdVisible());
            Helper.enableNode(thresholdText, tile.isThresholdVisible());
            sectionsVisible = tile.getSectionsVisible();
            redraw();
        }
    }
753786
@Override protected void handleEvents(final String EVENT_TYPE) {
        super.handleEvents(EVENT_TYPE);

        if ("VISIBILITY".equals(EVENT_TYPE)) {
            Helper.enableNode(titleText, !tile.getTitle().isEmpty());
            Helper.enableNode(text, tile.isTextVisible());
        } else if ("RECALC".equals(EVENT_TYPE)) {
            matrix.setColsAndRows(tile.getMatrixSize());
            resize();
        }
    }
1352235
public void writeHtmlString(String strHTML, PrintWriter out)
    {
        int iIndex;
        if (strHTML == null)
            return;
        while ((iIndex = strHTML.indexOf(HtmlConstants.TITLE_TAG)) != -1)
        {   // ** FIX THIS to look for a <xxx/> and look up the token **
            strHTML = strHTML.substring(0, iIndex) + ((BasePanel)this.getScreenField()).getTitle() + strHTML.substring(iIndex + HtmlConstants.TITLE_TAG.length());
        }
        out.println(strHTML);
    }
893959
public function add($element, $postion=null, $type=null) {
		parent::add($element, $postion, $type);
	}
9658
@Override protected void handleEvents(final String EVENT_TYPE) {
        super.handleEvents(EVENT_TYPE);
        if ("RECALC".equals(EVENT_TYPE)) {
            resize();
            redraw();
            setBar(gauge.getCurrentValue());
        } else if ("SECTION".equals(EVENT_TYPE)) {
            sections = gauge.getSections();
            resize();
            redraw();
        } else if ("VISIBILITY".equals(EVENT_TYPE)) {
            Helper.enableNode(valueText, gauge.isValueVisible());
            Helper.enableNode(titleText, !gauge.getTitle().isEmpty());
            redraw();
        } else if ("FINISHED".equals(EVENT_TYPE)) {
            StringBuilder content = new StringBuilder(formatNumber(gauge.getLocale(), gauge.getFormatString(), gauge.getDecimals(), gauge.getValue()))
                .append("\n(").append(valueText.getText()).append(")");
            barTooltip.setText(content.toString());
        }
    }
331091
public function setHtml($html)
	{
		if (!$this->mpdf) {
			$this->init();
		}
		$this->mpdf->WriteHTML($html);
	}
482395
@Override protected void handleEvents(final String EVENT_TYPE) {
        super.handleEvents(EVENT_TYPE);

        if ("VISIBILITY".equals(EVENT_TYPE)) {
            Helper.enableNode(titleText, !tile.getTitle().isEmpty());
            Helper.enableNode(text, tile.isTextVisible());
            graphicContainer.setMaxSize(size * 0.9, tile.isTextVisible() ? size * 0.68 : size * 0.795);
            graphicContainer.setPrefSize(size * 0.9, tile.isTextVisible() ? size * 0.68 : size * 0.795);
        }
    }
791524
protected function inline($type, $title, $text = null)
    {
        $html   = (string) $text;
        $inline = <<<EOD
           $(document).ready(function(){                 
                swal($.extend({}, APP.swal.$type(), {
                    title: '$title',
                    text: '$html',                    
                    showConfirmButton: false,
                    showCancelButton: true,
                    cancelButtonText: 'Ok',
                    closeOnConfirm: false,
                    closeOnCancel: true
                }));
        });
EOD;
        return $inline;
    }
1311436
public function html(string $html, array $parentAttributes = [])
    {
        return $this->add(Html::raw($html)->setParentAttributes($parentAttributes));
    }
1133853
public function iShouldSeeThatTheBlogPostWasWrittenOnBy($title, $date, $author)
    {
        $xpath = sprintf('//h2[contains(., "%s")]/following-sibling::div[@class="post-meta"]', $title);
        $node = $this->getSession()->getPage()->find('xpath', $xpath);

        if (is_null($node)) {
            throw new ElementNotFoundException($this->getSession(), 'Post meta');
        }

        $meta = $node->getText();

        if (false === strpos($meta, date('d M Y', strtotime($date)))) {
            throw new ExpectationException(sprintf('Publishing date for "%s" was not found in meta details: "%s"', $title, $meta), $this->getSession());
        }

        if (false === strpos($meta, $author)) {
            throw new ExpectationException(sprintf('Publishing date for "%s" was not found in meta details', $title, $meta), $this->getSession());
        }
    }
1077519
public static function generate_html_id($title)
    {
        $t = $title;
        $t = str_replace('&amp;', '-and-', $t);
        $t = str_replace('&', '-and-', $t);
        $t = preg_replace('/[^A-Za-z0-9]+/', '-', $t);
        $t = preg_replace('/-+/', '-', $t);
        $t = trim($t, '-');
        $t = strtolower($t);

        return $t;
    }
559656
public function iClickTheTitleOnTheBlogPostList($title)
    {
        $node = $this->getSession()->getPage()->find('xpath', sprintf('//h2[contains(., "%s")]/a', $title));

        if (is_null($node)) {
            throw new ElementNotFoundException($this->getSession(), 'Blog post title');
        }

        $node->click();
    }
503488
public function writeHtml($strHtml, $strCss = '')
    {
        $strHtml = ($strCss ? '<style>' . $strCss . '</style>' : '') . $strHtml;

        $this->objPdf->WriteHTML(html_entity_decode($this->replaceInsertTags($strHtml)));
    }