//本地缩略
else{
//本地大图强制生成本地图缩略
if($litpic=='ddfirst' && !eregi("^http://",$picname)){
$oldpic = $cfg_basedir.$picname;
if(!eregi('_lit',$litpic)){
$litpic = str_replace('.','_lit.',$picname);
$saveinfo = true;
}
@ImageResize($oldpic,$cfg_ddimg_width,$cfg_ddimg_height,$cfg_basedir.$litpic);
}else{
$litpic = $picname;
}
}
}
$imgfile = $cfg_basedir.$litpic;
if($saveinfo && is_file($imgfile) && $litpic!=''){
$info = "";
$imginfos = GetImageSize($imgfile,$info);
//把新上传的图片信息保存到媒体文档管理档案中
$inquery = "
INSERT INTO dede_uploads(title,url,mediatype,width,height,playtime,filesize,uptime,adminid,memberid)
VALUES ('{$title} 图','$litpic','1','".$imginfos[0]."','".$imginfos[1]."','0','".filesize($imgfile)."','".time()."','".$cuserLogin->getUserID()."','0');
";
$dsql = new DedeSql();
$dsql->ExecuteNoneQuery($inquery);
}
return $litpic;
}
//检测栏目是否设置了浏览权限
function GetCoRank($arcrank,$typeid){
$dsql = new DedeSql(false);
$row = $dsql->GetOne("Select corank From dede_arctype where ID='$typeid' ");
if($row['corank']!=0) return $row['corank'];
else return $arcrank;
}
//图集里大图的小图
function GetImageMapDD($filename,$ddm,$oldname=''){
if($oldname!='' && !eregi("^http://",$oldname)){
$ddpicok = $oldname;
}else{
$ddn = substr($filename,-3);
$ddpicok = ereg_replace("\.".$ddn."$","-lp.".$ddn,$filename);
}
$toFile = $GLOBALS['cfg_basedir'].$ddpicok;
ImageResize($GLOBALS['cfg_basedir'].$filename,$ddm,300,$toFile);
return $ddpicok;
}
//------------------------
//上传一个未经处理的图片
//------------------------
/*
//参数一 upname 上传框名称
//参数二 handurl 手工填写的网址
//参数三 ddisremote 是否下载远程图片 0 不下, 1 下载
//参数四 ntitle 注解文字 如果表单有 title 字段可不管
*/
function UploadOneImage($upname,$handurl='',$ddisremote=1,$ntitle='')
{
global $cuserLogin,$cfg_basedir,$cfg_image_dir,$dsql,$title;
if($ntitle!='') $title = $ntitle;
$ntime = time();
$filename = '';
$isrm_up = false;
$handurl = trim($handurl);
//如果用户自行上传了图片
if(!empty($_FILES[$upname]['tmp_name']) && is_uploaded_file($_FILES[$upname]['tmp_name']))
{
$istype = 0;
$sparr = Array("image/pjpeg","image/jpeg","image/gif","image/png");
$_FILES[$upname]['type'] = strtolower(trim($_FILES[$upname]['type']));
if(!in_array($_FILES[$upname]['type'],$sparr)){
ShowMsg("洗图片式使JPEGGIFPNG式一郑","-1");
exit();
}
if(!empty($handurl) && !eregi("^http://",$handurl) && file_exists($cfg_basedir.$handurl) ){
if(!is_object($dsql)) $dsql = new DedeSql();
$dsql->ExecuteNoneQuery("Delete From dede_uploads where url like '$handurl' ");
$fullUrl = eregi_replace("\.([a-z]*)$","",$handurl);
}else{
$savepath = $cfg_image_dir."/".strftime("%Y-%m",$ntime);
CreateDir($savepath);
$fullUrl = $savepath."/".strftime("%d",$ntime).dd2char(strftime("%H%M%S",$ntime).'0'.$cuserLogin->getUserID().'0'.mt_rand(1000,9999));
}
if(strtolower($_FILES[$upname]['type'])=="image/gif") $fullUrl = $fullUrl.".gif";
else if(strtolower($_FILES[$upname]['type'])=="image/png") $fullUrl = $fullUrl.".png";
else $fullUrl = $fullUrl.".jpg";
//保存
@move_uploaded_file($_FILES[$upname]['tmp_name'],$cfg_basedir.$fullUrl);
$filename = $fullUrl;
//水印
@WaterImg($imgfile,'up');
$isrm_up = true;
}
//远程或选择本地图片
else{
if($handurl=='') return '';
//远程图片并要求本地化
if($isremote==1 && eregi("^http://",$handurl)){
$ddinfos = GetRemoteImage($handurl,$cuserLogin->getUserID());
if(!is_array($ddinfos)) $litpic = "";
else $filename = $ddinfos[0];
$isrm_up = true;
//本地图片或远程不要求本地化
}else{
$filename = $handurl;
}
}
$imgfile = $cfg_basedir.$filename;
if(is_file($imgfile) && $isrm_up && $filename!=''){
$info = "";
$imginfos = GetImageSize($imgfile,$info);
//把新上传的图片信息保存到媒体文档管理档案中
$inquery = "
INSERT INTO dede_uploads(title,url,mediatype,width,height,playtime,filesize,uptime,adminid,memberid)
VALUES ('$title','$filename','1','".$imginfos[0]."','".$imginfos[1]."','0','".filesize($imgfile)."','".time()."','".$cuserLogin->getUserID()."','0');
";
$dsql = new DedeSql(false);
$dsql->ExecuteNoneQuery($inquery);
}
return $filename;
}
//------------------
//取第一个图片为缩略图
//------------------
function GetDDImgFromBody(&$body)
{
$litpic = '';
preg_match_all("/(src|SRC)=[\"|'| ]{0,}(.*\.(gif|jpg|jpeg|bmp|png))/isU",$body,$img_array);
$img_array = array_unique($img_array[2]);
if(count($img_array)>0){
$picname = preg_replace("/[\"|'| ]{1,}/","",$img_array[0]);
if(ereg("_lit\.",$picname)) $litpic = $picname;
else $litpic = GetDDImage('ddfirst',$picname,0);
}
return $litpic;
}
//获得一个附加表单
//-----------------------------
function GetFormItemA($ctag)
{
return GetFormItem($ctag,'admin');
}
//---------------------------
//处理不同类型的数据
//---------------------------
function GetFieldValueA($dvalue,$dtype,$aid=0,$job='add',$addvar='')
{
return GetFieldValue($dvalue,$dtype,$aid,$job,$addvar,'admin');
}
//获得带值的表单(编辑时用)
//-----------------------------
function GetFormItemValueA($ctag,$fvalue)
{
return GetFormItemValue($ctag,$fvalue,'admin');
}
//载入自定义表单(用于发布)
function PrintAutoFieldsAdd(&$fieldset,$loadtype='all')
{
$dtp = new DedeTagParse();
$dtp->SetNameSpace("field","<",">");
$dtp->LoadSource($fieldset);
$dede_addonfields = "";
if(is_array($dtp->CTags))
{
foreach($dtp->CTags as $tid=>$ctag)
{
if($loadtype!='autofield'
|| ($loadtype=='autofield' && $ctag->GetAtt('autofield')==1) )
{
$dede_addonfields .= ( $dede_addonfields=="" ? $ctag->GetName().",".$ctag->GetAtt('type') : ";".$ctag->GetName().",".$ctag->GetAtt('type') );
echo GetFormItemA($ctag);
}
}
}
echo "<input type='hidden' name='dede_addonfields' value=\"".$dede_addonfields."\">\r\n";
}
//载入自定义表单(用于编辑)
function PrintAutoFieldsEdit(&$fieldset,&$fieldValues,$loadtype='all')
{
$dtp = new DedeTagParse();
$dtp->SetNameSpace("field","<",">");
$dtp->LoadSource($fieldset);
$dede_addonfields = "";
if(is_array($dtp->CTags))
{
foreach($dtp->CTags as $tid=>$ctag)
{
if($loadtype!='autofield'
|| ($loadtype=='autofield' && $ctag->GetAtt('autofield')==1) )
{
$dede_addonfields .= ( $dede_addonfields=='' ? $ctag->GetName().",".$ctag->GetAtt('type') : ";".$ctag->GetName().",".$ctag->GetAtt('type') );
echo GetFormItemValueA($ctag,$fieldValues[$ctag->GetName()]);
}
}
}
echo "<input type='hidden' name='dede_addonfields' value=\"".$dede_addonfields."\">\r\n";
}
function getfilenameonly($arcid, $typeid, $senddate, $title, $ismake, $arcrank, $money)
{
global $dsql;
require_once DEDEINC.'/inc_channel_unit_functions.php';
$row = $dsql->getone("select namerule, typedir, siterefer, sitepath ,channeltype from dede_arctype where ID='$typeid'");
if(is_array($row)){
if($row['channeltype'] == -2) return $GLOBALS['cfg_plus_dir']."/view.php?aid=$arcid";
$filename = GetFileNewName($arcid, $typeid, $senddate, $title, $ismake, $arcrank, $row['namerule'],
$row['typedir'],$money,$row['siterefer'], $row['sitepath']);
}else{
showmsg('目id','-1');
exit;
}
if($filename=="") $filename = $GLOBALS['cfg_plus_dir']."/view.php?aid=$arcid";
return $filename;
}
?>
(责任编辑:最模板) |