From fa39edb4bca4d2da9ba8f38828a4fa359885acc4 Mon Sep 17 00:00:00 2001 From: wyd621 Date: Thu, 25 Jul 2013 17:05:46 +0800 Subject: [PATCH] * finish task #1607. --- module/common/view/kindeditor.html.php | 16 ++++++++++++-- module/file/control.php | 15 +++++++++++++ module/file/model.php | 29 ++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/module/common/view/kindeditor.html.php b/module/common/view/kindeditor.html.php index 459f9f82bd..044431af51 100644 --- a/module/common/view/kindeditor.html.php +++ b/module/common/view/kindeditor.html.php @@ -53,9 +53,21 @@ $(document).ready(function() uploadJson: createLink('file', 'ajaxUpload'), allowFileManager:true, langType:'', - afterBlur: function(){this.sync();} + afterBlur: function(){this.sync();}, + afterCreate : function() + { + if(!K.GECKO) return false; + var doc = this.edit.doc; + K(doc.body).bind('paste', function() + { + setTimeout(function() + { + $.post(createLink('file', 'ajaxEditorImage'), {editor: K(doc.body).html()}, function(data){K(doc.body).html(data);}) + }, 80); + }); + } }); }); - }) + }); }) diff --git a/module/file/control.php b/module/file/control.php index 0ddc27ef1d..fa86a08ef0 100644 --- a/module/file/control.php +++ b/module/file/control.php @@ -291,4 +291,19 @@ class file extends control $this->view->file = $this->file->getById($fileID); $this->display(); } + + /** + * Ajax replace editor image + * + * @access public + * @return void + */ + public function ajaxEditorImage() + { + if($_POST) + { + $data = $this->file->replaceEditorImage($this->post->editor); + echo str_replace('\"', '"', $data); + } + } } diff --git a/module/file/model.php b/module/file/model.php index 8a0b8798c6..48242a958f 100644 --- a/module/file/model.php +++ b/module/file/model.php @@ -236,4 +236,33 @@ class fileModel extends model } } + /** + * Replace editor image + * + * @param string $data + * @access public + * @return string + */ + public function replaceEditorImage($data) + { + preg_match_all('//U', $data, $out); + foreach($out[3] as $id => $base64Image) + { + $imageData = base64_decode($base64Image); + + $file['extension'] = $out[2][$id]; + $file['pathname'] = $this->setPathName($id, $file['extension']); + $file['size'] = strlen($imageData); + $file['addedBy'] = $this->app->user->account; + $file['addedDate'] = helper::today(); + $file['title'] = 'Paste in editor'; + + file_put_contents($this->savePath . $file['pathname'], $imageData); + $this->dao->insert(TABLE_FILE)->data($file)->exec(); + + $data = str_replace($out[1][$id], $this->webPath . $file['pathname'], $data); + } + + return $data; + } }