IMP_Compose::_cleanHtmlOutput PHP Method

_cleanHtmlOutput() protected method

Clean outgoing HTML (remove unexpected data URLs).
protected _cleanHtmlOutput ( Horde_Domhtml $html )
$html Horde_Domhtml The HTML data.
    protected function _cleanHtmlOutput(Horde_Domhtml $html)
    {
        global $registry;
        $xpath = new DOMXPath($html->dom);
        foreach ($xpath->query('//*[@src]') as $node) {
            $src = $node->getAttribute('src');
            /* Check for attempts to sneak data URL information into the
             * output. */
            if (Horde_Url_Data::isData($src)) {
                if (IMP_Compose_HtmlSignature::isSigImage($node, true)) {
                    /* This is HTML signature image data. Convert to an
                     * attachment. */
                    $sig_img = new Horde_Url_Data($src);
                    if ($sig_img->data) {
                        $data_part = new Horde_Mime_Part();
                        $data_part->setContents($sig_img->data);
                        $data_part->setType($sig_img->type);
                        try {
                            $this->addRelatedAttachment($this->addAttachmentFromPart($data_part), $node, 'src');
                        } catch (IMP_Compose_Exception $e) {
                            // Remove image on error.
                        }
                    }
                }
                $node->removeAttribute('src');
            } elseif (strcasecmp($node->tagName, 'IMG') === 0) {
                /* Check for smileys. They live in the JS directory, under
                 * the base ckeditor directory, so search for that and replace
                 * with the filesystem information if found (Request
                 * #13051). Need to ignore other image links that may have
                 * been explicitly added by the user. */
                $js_path = strval(Horde::url($registry->get('jsuri', 'horde'), true));
                if (stripos($src, $js_path . '/ckeditor') === 0) {
                    $file = str_replace($js_path, $registry->get('jsfs', 'horde'), $src);
                    if (is_readable($file)) {
                        $data_part = new Horde_Mime_Part();
                        $data_part->setContents(file_get_contents($file));
                        $data_part->setName(basename($file));
                        try {
                            $this->addRelatedAttachment($this->addAttachmentFromPart($data_part), $node, 'src');
                        } catch (IMP_Compose_Exception $e) {
                            // Keep existing data on error.
                        }
                    }
                }
            }
        }
    }