* finish task #1607.
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user