function gethumb($sfp, $w = '', $h = '', $scale = false, $callback = false) { global $iCMS; if (strpos($sfp, 'thumb/') !== false || strpos($sfp, 'http://') !== false) { return $sfp; } $sfn = substr($sfp, 0, strrpos($sfp, '.')); $sfn = substr($sfn, strrpos($sfn, '/')); $tpf = substr($sfp, 0, strrpos($sfp, '/')) . '/thumb' . $sfn . '_'; $rootpf = getfilepath($tpf, iPATH, '+'); if ($callback) { $tfArray = glob($rootpf . "*"); if ($tfArray) { foreach ($tfArray as $filename) { if (file_exists($filename)) { $fn = substr($filename, 0, strrpos($filename, '.')); $per = substr($fn, strrpos($fn, '_') + 1); $tfpList[$per] = $filename; } } } return $tfpList; } else { $srfp = getfilepath($sfp, iPATH, '+'); if (file_exists($srfp)) { empty($w) && ($w = $iCMS->config['thumbwidth']); empty($h) && ($h = $iCMS->config['thumbhight']); $twh = $rootpf . $w . 'x' . $h . '.' . getext($sfp); if (!file_exists($twh)) { $Thumb = MakeThumbnail(substr($srfp, 0, strrpos($srfp, '/')) . '/', $srfp, substr($sfn, strrpos($sfn, '/') + 1), $w, $h, $scale); $twh = $Thumb['src']; } $src = $iCMS->dir . getfilepath($twh, iPATH, '-'); } else { $src = $iCMS->dir . 'include/nopic.gif'; } return $src; } }
function remote(&$content, $one = false) { global $DreamCMS, $title; $content = stripslashes($content); $img = array(); preg_match_all("/(src|SRC)=[\"|'| ]{0,}(http:\\/\\/(.*)\\.(gif|jpg|jpeg|bmp|png))/isU", $content, $img); $_array = array_unique($img[2]); foreach ($_array as $_k => $imgurl) { if (strstr(strtolower($imgurl), $DreamCMS->config['url'])) { unset($_array[$_k]); } } set_time_limit(0); $UploadDir = $DreamCMS->config['uploadfiledir'] . "/"; $RelativePath = $DreamCMS->dir . $UploadDir; //相对路径 $RootPath = DCPATH . $UploadDir; //绝对路径 switch ($DreamCMS->config['savedir']) { case "0": $_CreateDir = ""; break; //全部保存在一起 //全部保存在一起 case 'ym': $_CreateDir = _getdate("Ym") . "/"; break; //按年月 //按年月 case 'ymd': $_CreateDir = _getdate("Ymd") . "/"; break; //按年月日 //按年月日 case 'ext': $_CreateDir = $FileExt . "/"; break; //按文件类型 } $RelativePath = $RelativePath . $_CreateDir; $RootPath = $RootPath . $_CreateDir; $milliSecond = 'remote_' . _getdate("YmdHis") . rand(1, 99999); createdir($RootPath); foreach ($_array as $key => $value) { $value = trim($value); preg_match("/\\.([a-zA-Z0-9]{2,4})\$/", $value, $exts); $FileExt = strtolower($exts[1]); //ļʽ CheckValidExt($FileExt); //判断文件类型 //过滤文件; strstr($FileExt, 'ph') && ($FileExt = "phpfile"); in_array($FileExt, array('cer', 'htr', 'cdx', 'asa', 'asp', 'jsp', 'aspx', 'cgi')) && ($FileExt .= "file"); $sFileName = $milliSecond . $key . "." . $FileExt; $RootPath_FileName = $RootPath . $sFileName; $RelativePath_FileName = $RelativePath . $sFileName; $get_file = fopen_url($value); $get_file && writefile($RootPath_FileName, $get_file); if (in_array($FileExt, array('gif', 'jpg', 'png')) && $DreamCMS->config['isthumb'] && ($DreamCMS->config['thumbwidth'] || $DreamCMS->config['thumbhight'])) { list($width, $height, $imagetype) = GetImageSize($RootPath_FileName); if ($width > $DreamCMS->config['thumbwidth'] || $height > $DreamCMS->config['thumbhight']) { createdir($RootPath . "thumb"); } $Thumbnail = MakeThumbnail($RootPath, $RootPath_FileName, $milliSecond . $key); if (!empty($Thumbnail['filepath'])) { $SmallImagePath_FileName = str_replace($RootPath, $RelativePath, $Thumbnail['filepath']); imageWaterMark($Thumbnail['filepath']); } imageWaterMark($RootPath_FileName); } else { $SmallImagePathFile = ''; } $_FileSize = @filesize($RootPath_FileName); $RelativePath_FileName = str_replace($DreamCMS->dir . $UploadDir, $UploadDir, $RelativePath_FileName); $SmallImagePath_FileName = str_replace($DreamCMS->dir . $UploadDir, $UploadDir, $SmallImagePath_FileName); $DreamCMS->db->query("INSERT INTO `#DC@__file` (`filename`,`ofilename`,`path`,`thumbpath`,`intro`,`ext`,`size` ,`time`,`type`) VALUES ('{$sFileName}', '{$value}', '{$RelativePath_FileName}','{$SmallImagePath_FileName}', '{$title}', '{$FileExt}', '{$_FileSize}', '" . time() . "', 'remote') "); $content = str_replace($value, $DreamCMS->dir . $RelativePath_FileName, $content); if ($one && $key == 0) { break; } } $content = add_magic_quotes($content); }