$image = new image(); $thumbimgwidth = $_G['setting']['portalarticleimgthumbwidth'] ? $_G['setting']['portalarticleimgthumbwidth'] : 300; $thumbimgheight = $_G['setting']['portalarticleimgthumbheight'] ? $_G['setting']['portalarticleimgthumbheight'] : 300; $attach['thumb'] = $image->Thumb($attach['target'], '', $thumbimgwidth, $thumbimgheight, 2); $image->Watermark($attach['target'], '', 'portal'); } if (getglobal('setting/ftp/on') && (!$_G['setting']['ftp']['allowedexts'] && !$_G['setting']['ftp']['disallowedexts'] || $_G['setting']['ftp']['allowedexts'] && in_array($attach['ext'], $_G['setting']['ftp']['allowedexts']) || $_G['setting']['ftp']['disallowedexts'] && !in_array($attach['ext'], $_G['setting']['ftp']['disallowedexts'])) && (!$_G['setting']['ftp']['minsize'] || $attach['size'] >= $_G['setting']['ftp']['minsize'] * 1024)) { if (ftpcmd('upload', 'portal/' . $attach['attachment']) && (!$attach['thumb'] || ftpcmd('upload', 'portal/' . getimgthumbname($attach['attachment'])))) { @unlink($_G['setting']['attachdir'] . '/portal/' . $attach['attachment']); @unlink($_G['setting']['attachdir'] . '/portal/' . getimgthumbname($attach['attachment'])); $attach['remote'] = 1; } else { if (getglobal('setting/ftp/mirror')) { @unlink($attach['target']); @unlink(getimgthumbname($attach['target'])); portal_upload_error(lang('portalcp', 'upload_remote_failed')); } } } $setarr = array('uid' => $_G['uid'], 'filename' => $attach['name'], 'attachment' => $attach['attachment'], 'filesize' => $attach['size'], 'isimage' => $attach['isimage'], 'thumb' => $attach['thumb'], 'remote' => $attach['remote'], 'filetype' => $attach['extension'], 'dateline' => $_G['timestamp'], 'aid' => $aid); $setarr['attachid'] = C::t('portal_attachment')->insert($setarr, true); if ($downremotefile) { $attach['url'] = ($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']) . 'portal/'; $imagereplace['newimageurl'][] = $attach['url'] . $attach['attachment']; } portal_upload_show($setarr); } if ($downremotefile && $imagereplace) { $string = preg_replace(array("/\\<(script|style|iframe)[^\\>]*?\\>.*?\\<\\/(\\1)\\>/si", "/\\<!*(--|doctype|html|head|meta|link|body)[^\\>]*?\\>/si"), '', $string); $string = str_replace($imagereplace['oldimageurl'], $imagereplace['newimageurl'], $string); $string = str_replace(array("\r", "\n", "\r\n"), '', addcslashes($string, '/"\\\''));
function downremotefile($arr, $action, $old_arr = array()) { global $_G; $evo_img_no = $_G['cache']['evn_milu_pick']['evo_img_no']; $config = get_pick_set(); $get_file_ext_arr = $config['get_file_ext'] ? explode('|', $config['get_file_ext']) : array(); if ($arr['is_bbs'] != 1) { //是论坛回帖就不合并 if ($action == 'portal') { $page_flag = $arr['is_page_public'] == 1 ? '' : '1'; if ($arr['content_arr']) { $arr['content'] = content_merge($arr['content_arr'], $page_flag); } } else { if ($arr['content_arr']) { $arr['content'] = content_merge($arr['content_arr']); } } } //if(VIP) $arr['content'] = post($arr['content'], array('cookie' => $arr['cookie'], 'page_url' => $arr['page_url'], 'cid' => $arr['cid'])); $arr['content'] = htmlspecialchars_decode($arr['content'], ENT_QUOTES); if ($arr['is_download_img'] == 1 || $arr['is_download_file'] == 1) { if (file_exists(libfile('class/upload'))) { require_once libfile('class/upload'); } else { require_once libfile('discuz/upload', 'class'); } $upload = new discuz_upload(); $arrayimageurl = $temp = $imagereplace = $attach_arr = array(); $string = dstripslashes($arr['content']); $downremotefile = true; $aid = $arr['aid']; preg_match_all("/\\<img.+src=('|\"|)?(.*)(\\1)(.*)?\\>/isU", $string, $temp, PREG_SET_ORDER); if ($arr['is_download_file'] == 1) { $attach_arr = get_attach_data($arr['page_url'], $string); } $attach_arr = $attach_arr ? $attach_arr : array(); $temp = $temp ? $temp : array(); $temp = array_merge($temp, $attach_arr); $del_a = 0; if ($arr['content_filter_html'][0] == 0 && $arr['content_filter_html']) { $del_a = 1; } //print_r($arr['content']); //print_r($temp); if (is_array($temp) && !empty($temp)) { foreach ($temp as $tempvalue) { $img_url = $tempvalue[2]; $img_url = str_replace('\\"', '', $img_url); $no_remote = 0; if (strlen($img_url)) { $img_url = trim(strip_tags($img_url)); if (!filter_something($img_url, $evo_img_no)) { //存在 $no_remote = 1; } if ($no_remote == 0) { $tempvalue[2] = $img_url; $arrayimageurl[] = $tempvalue; } } } if ($arrayimageurl) { $content_md5_arr = array(); foreach ($arrayimageurl as $key => $tempvalue) { $imageurl = $tempvalue[4] == 1 ? $tempvalue[1] : $tempvalue[2]; $attach['ext'] = $upload->fileext($imageurl); if ($upload->is_image_ext($attach['ext']) == 1 && $arr['is_download_img'] != 1) { unset($imagereplace['oldimageurl'][$key]); continue; } $snoopy_args['cookie'] = $arr['cookie']; $snoop_obj = get_snoopy_obj($snoopy_args); $imagereplace['oldimageurl'][$key] = $tempvalue[4] == 1 ? $tempvalue[0] : $tempvalue[2]; if (!$upload->is_image_ext($attach['ext'])) { $ext = 'no_get'; //continue; } $content = ''; if (preg_match('/^(http:\\/\\/|\\.)/i', $imageurl)) { if ($imageurl && snoop_obj) { $content_re = get_img_content($imageurl, $snoop_obj, $ext); } unset($snoop_obj); if (is_array($content_re)) { $content = $content_re['content']; $file_name = $attach['name'] = $content_re['file_name'] ? $content_re['file_name'] : ($value[2] ? _striptext($value[2]) : time() . '.' . $content_re['file_ext']); $attach['ext'] = $content_re['file_ext'] ? $content_re['file_ext'] : trim($upload->fileext($file_name)); $file_name = $attach['name'] = $file_name; } else { $content = $content_re; } if (in_array(md5($content), $content_md5_arr)) { unset($imagereplace['oldimageurl'][$key]); continue; } $content_md5_arr[] = md5($content); } elseif (checkperm('allowdownlocalimg')) { if (preg_match('/^data\\/(.*?)\\.thumb\\.jpg$/i', $imageurl)) { $content = file_get_contents(substr($imageurl, 0, strrpos($imageurl, '.') - 6)); } elseif (preg_match('/^data\\/(.*?)\\.(jpg|jpeg|gif|png)$/i', $imageurl)) { $content = file_get_contents($imageurl); } } if (empty($content)) { if ($tempvalue[4] == 1) { if ($del_a == 1) { unset($imagereplace['oldimageurl'][$key]); $imagereplace['oldimageurl_a'][$key] = $tempvalue[0]; $imagereplace['newimageurl_a'][$key] = $tempvalue[2]; } else { unset($imagereplace['oldimageurl'][$key]); } } else { unset($imagereplace['oldimageurl'][$key]); } continue; } if (!$attach['name']) { $temp = explode('/', $imageurl); $attach['name'] = trim($temp[count($temp) - 1]); } $attach['thumb'] = ''; $attach['isimage'] = $upload->is_image_ext($attach['ext']); $attach['extension'] = $upload->get_target_extension($attach['ext']); $attach['attachdir'] = $upload->get_target_dir($action); $attach['attachment'] = $attach['attachdir'] . $upload->get_target_filename($action) . '.' . $attach['extension']; $attach['target'] = getglobal('setting/attachdir') . './' . $action . '/' . $attach['attachment']; if ($attach['isimage'] == 1 && $arr['is_download_img'] != 1) { unset($imagereplace['oldimageurl'][$key]); continue; } if (!in_array($attach['ext'], $get_file_ext_arr) && $get_file_ext_arr && $attach['isimage'] == 0) { if ($tempvalue[4] == 1) { if ($del_a == 1) { unset($imagereplace['oldimageurl'][$key]); $imagereplace['oldimageurl_a'][$key] = $tempvalue[0]; $imagereplace['newimageurl_a'][$key] = $tempvalue[2]; } else { unset($imagereplace['oldimageurl'][$key]); } } else { unset($imagereplace['oldimageurl'][$key]); } continue; } if ($attach['isimage'] == 0) { $imagereplace['oldimageurl'][$key] = $tempvalue[1]; if ($action == 'album') { unset($imagereplace['oldimageurl'][$key], $imagereplace['oldimageurl_a'][$key], $imagereplace['newimageurl_a'][$key]); } } if (!@($fp = fopen($attach['target'], 'wb'))) { continue; } else { flock($fp, 2); fwrite($fp, $content); fclose($fp); } if (!$upload->get_image_info($attach['target']) && $attach['isimage'] == 1) { @unlink($attach['target']); continue; } $attach['size'] = filesize($attach['target']); $attachs[] = daddslashes($attach); } } } } //print_r($imagereplace);//exit(); if ($attachs) { foreach ($attachs as $key => $attach) { if ($action != 'forum' && $attach['isimage'] && empty($_G['setting']['portalarticleimgthumbclosed'])) { require_once libfile('class/image'); $image = new image(); $thumbimgwidth = $_G['setting']['portalarticleimgthumbwidth'] ? $_G['setting']['portalarticleimgthumbwidth'] : 300; $thumbimgheight = $_G['setting']['portalarticleimgthumbheight'] ? $_G['setting']['portalarticleimgthumbheight'] : 300; $attach['thumb'] = $image->Thumb($attach['target'], '', $thumbimgwidth, $thumbimgheight, 2); if ($arr['is_water_img'] == 1) { $image->Watermark($attach['target'], '', $action); } //打水印 } if ($action == 'portal') { //if(!$arr['attachment']) $arr['attachment'] = 'portal/'.$attach['attachment']; if (getglobal('setting/ftp/on') && (!$_G['setting']['ftp']['allowedexts'] && !$_G['setting']['ftp']['disallowedexts'] || $_G['setting']['ftp']['allowedexts'] && in_array($attach['ext'], $_G['setting']['ftp']['allowedexts']) || $_G['setting']['ftp']['disallowedexts'] && !in_array($attach['ext'], $_G['setting']['ftp']['disallowedexts'])) && (!$_G['setting']['ftp']['minsize'] || $attach['size'] >= $_G['setting']['ftp']['minsize'] * 1024)) { if (ftpcmd('upload', 'portal/' . $attach['attachment']) && (!$attach['thumb'] || ftpcmd('upload', 'portal/' . getimgthumbname($attach['attachment'])))) { @unlink($_G['setting']['attachdir'] . '/portal/' . $attach['attachment']); @unlink($_G['setting']['attachdir'] . '/portal/' . getimgthumbname($attach['attachment'])); $attach['remote'] = 1; } else { if (getglobal('setting/ftp/mirror')) { @unlink($attach['target']); @unlink(getimgthumbname($attach['target'])); portal_upload_error(lang('portalcp', 'upload_remote_failed')); } } } $setarr = array('uid' => $arr['uid'], 'filename' => $attach['name'], 'attachment' => $attach['attachment'], 'filesize' => $attach['size'], 'isimage' => $attach['isimage'], 'thumb' => $attach['thumb'], 'remote' => $attach['remote'], 'filetype' => $attach['extension'], 'dateline' => $_G['timestamp'], 'aid' => $aid); $setarr['attachid'] = DB::insert("portal_attachment", $setarr, true); } else { if ($action == 'album') { $arr['pic'] = $attach['attachment']; $new_name = $attach['target']; require_once libfile('class/image'); $image = new image(); $result = $image->Thumb($new_name, '', 140, 140, 1); $thumb = empty($result) ? 0 : 1; if ($_G['setting']['maxthumbwidth'] && $_G['setting']['maxthumbheight']) { if ($_G['setting']['maxthumbwidth'] < 300) { $_G['setting']['maxthumbwidth'] = 300; } if ($_G['setting']['maxthumbheight'] < 300) { $_G['setting']['maxthumbheight'] = 300; } $image->Thumb($new_name, '', $_G['setting']['maxthumbwidth'], $_G['setting']['maxthumbheight'], 1, 1); } if ($iswatermark) { $image->Watermark($new_name, '', 'album'); } $attach['remote'] = 0; $album_picflag = 1; if (getglobal('setting/ftp/on')) { $ftpresult_thumb = 0; $ftpresult = ftpcmd('upload', 'album/' . $attach['attachment']); if ($ftpresult) { @unlink($_G['setting']['attachdir'] . 'album/' . $attach['attachment']); if ($thumb) { $thumbpath = getimgthumbname($attach['attachment']); ftpcmd('upload', 'album/' . $thumbpath); @unlink($_G['setting']['attachdir'] . 'album/' . $thumbpath); } $attach['remote'] = 1; $album_picflag = 2; } else { if (getglobal('setting/ftp/mirror')) { @unlink($upload->attach['target']); @unlink(getimgthumbname($upload->attach['target'])); return lang('spacecp', 'ftp_upload_file_size'); } } } $setarr = array('uid' => $arr['uid'], 'filename' => $attach['name'], 'filepath' => $attach['attachment'], 'size' => $attach['size'], 'thumb' => $attach['thumb'], 'username' => $arr['username'], 'postip' => $_G['clientip'], 'remote' => $attach['remote'], 'type' => $attach['extension'], 'dateline' => $arr['public_time']); //print_r($setarr);exit(); $setarr['attachid'] = DB::insert("home_pic", $setarr, true); if ($attach['thumb'] == 1 && $feed_re != 1) { $feed['image_1'] = 'data/attachment/album/' . $attach['attachment'] . '.thumb.jpg'; $feed['image_1_link'] = 'home.php?mod=space&uid=' . $arr['uid'] . '&do=blog&id=' . $arr['aid']; DB::update("home_feed", $feed, array("idtype" => 'blogid', 'id' => $arr['aid'])); $feed_re = 1; } } } if ($downremotefile) { $attach['url'] = ($attach['remote'] ? $_G['setting']['ftp']['attachurl'] : $_G['setting']['attachurl']) . '' . $action . '/'; $imagereplace['newimageurl'][] = $attach['url'] . $attach['attachment']; } } if ($downremotefile && $imagereplace || $del_a == 1 && $imagereplace) { $string = preg_replace(array("/\\<(script|style|iframe)[^\\>]*?\\>.*?\\<\\/(\\1)\\>/si", "/\\<!*(--|doctype|html|head|meta|link|body)[^\\>]*?\\>/si"), '', $string); $string = str_replace($imagereplace['oldimageurl'], $imagereplace['newimageurl'], $string); $string = str_replace($imagereplace['oldimageurl_a'], $imagereplace['newimageurl_a'], $string); $string = str_replace(array("\r", "\n", "\r\n"), '', addcslashes($string, '/"\\')); $arr['content'] = $string; } } if ($del_a == 1) { $arr['content'] = clear_html_script($arr['content'], array(0)); } if (DISCUZ_VERSION != 'X2') { //2.5版本 $arr['content'] = dstripslashes($arr['content']); //不必转义 } $do = $action . '_article_content'; if ($action != 'forum') { $do($arr, $old_arr); } }