diff options
author | Brion Vibber <brion@status.net> | 2010-08-12 11:39:42 -0700 |
---|---|---|
committer | Brion Vibber <brion@status.net> | 2010-08-12 11:39:42 -0700 |
commit | f14f252a1633c9297f33a98ef7f4ccf6db0efaef (patch) | |
tree | 42efaba960adc6870c5da311906739b111d8fc07 | |
parent | 3370a326d84f3eb8a39a073eae3705069b517263 (diff) |
TinyMCE: fixes to attachment handling
-rw-r--r-- | plugins/TinyMCE/TinyMCEPlugin.php | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/plugins/TinyMCE/TinyMCEPlugin.php b/plugins/TinyMCE/TinyMCEPlugin.php index f67d6ea13..47d3d059f 100644 --- a/plugins/TinyMCE/TinyMCEPlugin.php +++ b/plugins/TinyMCE/TinyMCEPlugin.php @@ -148,8 +148,7 @@ class TinyMCEPlugin extends Plugin $this->formatAttachment($img, $media); } } - $html = $dom->saveHTML(); - $options['rendered'] = $html; + $options['rendered'] = $this->saveHtml($dom); } // The regular code will append the short URL to the plaintext content. @@ -166,29 +165,26 @@ class TinyMCEPlugin extends Plugin */ private function formatAttachment($img, $media) { + $parent = $img->parentNode; $dom = $img->ownerDocument; + $link = $dom->createElement('a'); $link->setAttribute('href', $media->fileurl); + $link->setAttribute('title', File::url($media->filename)); if ($this->isEmbeddable($media)) { - common_log(LOG_INFO, 'QQQQQ'); // Fix the the <img> attributes and wrap the link around it... $this->insertImage($img, $media); - common_log(LOG_INFO, 'QQQQQ A!'); - try { - $dom->replaceChild($link, $img); //it dies in here?! - } catch (Exception $wtf) { - common_log(LOG_ERR, 'QQQ WTF? ' . $wtf->getMessage()); - } - common_log(LOG_INFO, 'QQQQQ B!'); + $parent->replaceChild($link, $img); //it dies in here?! $link->appendChild($img); - common_log(LOG_INFO, 'QQQQQ C!'); } else { - common_log(LOG_INFO, 'QQQQQ X'); // Not an image? Replace it with a text link. + $link->setAttribute('rel', 'external'); + $link->setAttribute('class', 'attachment'); + $link->setAttribute('id', 'attachment-' . $media->fileRecord->id); $text = $dom->createTextNode($media->shortUrl()); $link->appendChild($text); - $dom->replaceChild($link, $img); + $parent->replaceChild($link, $img); } } @@ -265,6 +261,15 @@ class TinyMCEPlugin extends Plugin } } + private function saveHtml($dom) + { + $html = $dom->saveHTML(); + // hack to remove surrounding crap added to the dom + // all we wanted was a fragment + $stripped = preg_replace('/^.*<body[^>]*>(.*)<\/body.*$/is', '$1', $html); + return $stripped; + } + function _inlineScript() { $path = common_path('plugins/TinyMCE/js/tiny_mce.js'); |