- 论坛徽章:
- 0
|
关于在在线编辑器内处理远程图片的问题,完成,结贴
NAPS,一个文章发布系统的做法,解决思路是在编辑器内容提交内直接替换(当然可配置)。
但我更喜欢在编辑器上做一个按钮来实现,困惑的问题如上....
function checkReplaceImage($text, $addtime, &$add_error_msg)
{
global $naps_config;
$getimgarray = array();
$find = "'src[\s\r\n]?=[\s\r\n]?[\\\]?['|\"]?(.*?\.(jpg|gif|png))[\\\]?['\"]?'si";
if (preg_match_all($find, $text, $matches, PREG_SET_ORDER)) {
$add_error_msg = $naps_lang['article_find_http_file'];
if ($this->;cArticleId <= 0) {
$i = 1;
} else {
$i = 100;
}
$img_search = $img_replace = array();
$makefile = false;
include_once ('./include/naps_image.php');
foreach ($matches AS $value) {
$getimageurl = trim($value[1]);
$pos = strpos(strtolower($getimageurl), $naps_config[www_website_index]."/upload" ;
if ($pos === false) {
$classImage = new napsImage();
$uplodefilename = '/'.date('Y-m', $addtime).'/naps_'.$addtime.'_'.$i;
if ($imageurl = $classImage->;copyImage($getimageurl, $uplodefilename)) {
$img_search[] = "/".preg_quote($getimageurl, "/" ."/";
$img_replace[] = $imageurl;
$add_error_msg .= $naps_lang['article_saved_http_successfully'];
$makefile = true;
} else {
$add_error_msg .= $naps_lang['article_saved_http_error'];
}
} else {
$add_error_msg .= $naps_lang['article_saved_local_file'];
}
$i ++;
}
if ($makefile) {
$text = preg_replace($img_search, $img_replace, $text);
}
} else {
$add_error_msg = $naps_lang['article_not_find_http_file'];
}
return $text;
} |
|