* finish task #1607.

This commit is contained in:
wyd621
2013-07-25 17:05:46 +08:00
parent 24723cf1f0
commit fa39edb4bc
3 changed files with 58 additions and 2 deletions
+14 -2
View File
@@ -53,9 +53,21 @@ $(document).ready(function()
uploadJson: createLink('file', 'ajaxUpload'),
allowFileManager:true,
langType:'<?php echo $editorLang?>',
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);
});
}
});
});
})
});
})
</script>
+15
View File
@@ -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);
}
}
}
+29
View File
@@ -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('/<img src=\\\"(data:image\/(\w+);base64,(.+))\\\" .+ \/>/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;
}
}