- * This function removes images at the very end of a post based on the assumption that this images are interpreted
- * as attachments
- * @param array $rendered_html
- * @return array
- */
- private function cutAttachedImages($rendered_html)
- {
- $doc = new DOMDocument();
- libxml_use_internal_errors(true);
- $doc->loadHTML($rendered_html);
- libxml_clear_errors();
-
- $root = $doc->getElementsByTagName("p")[0];
-
- $lastTextNode = null;
- if ($root && $root->childNodes) {
- foreach ($root->childNodes as $node) {
- if ($node->nodeName == "#text" && strlen(trim($node->nodeValue)) > 0) {
- $lastTextNode = $node;
- }
- }
- }
-
- if ($lastTextNode == null) {
- // no text at all, return nothing:
- return '';
- }
-
- $toremove = array();
- if ($lastTextNode) {
- $sibling = $lastTextNode->nextSibling;
- while ($sibling) {
- $toremove[] = array($sibling);
- $sibling = $sibling->nextSibling;
- }
- foreach ($toremove as $remove) {
- $root->removeChild($remove[0]);
- }
- $html = '';
- foreach ($root->childNodes as $node) {
- $html .= $node->ownerDocument->saveHTML($node);
- }
- return $html;
- }
-
- return $rendered_html;
- }
-
- /**
- * @param array $data
- * @return string|void