inc_archives_functions.php

来自「这是matlab的一个小程序」· PHP 代码 · 共 777 行 · 第 1/2 页

PHP
777
字号
<?php
require_once(DEDEINC.'/dedehttpdown.class.php');
require_once(DEDEINC.'/image.func.php');
require_once(DEDEINC.'/archives.func.php');
require_once(DEDEINC.'/arc.partview.class.php');
if(!isset($_NOT_ARCHIVES))
{
	require_once(DEDEINC."/customfields.func.php");
}

//获得HTML里的外部资源,针对图集
function GetCurContentAlbum($body,$rfurl,&$firstdd)
{
	global $cfg_multi_site,$cfg_basehost,$ddmaxwidth,$cfg_basedir,$pagestyle;
	include_once(DEDEINC."/dedecollection.func.php");
	if(empty($ddmaxwidth))
	{
		$ddmaxwidth = 240;
	}
	$rsimg = '';
	$cfg_uploaddir = $GLOBALS['cfg_image_dir'];
	$cfg_basedir = $GLOBALS['cfg_basedir'];
	$basehost = "http://".$_SERVER["HTTP_HOST"];
	$img_array = array();
	preg_match_all("/(src)=[\"|'| ]{0,}(http:\/\/([^>]*)\.(gif|jpg|png))/isU",$body,$img_array);
	$img_array = array_unique($img_array[2]);
	$imgUrl = $cfg_uploaddir."/".MyDate("ymd",time());
	$imgPath = $cfg_basedir.$imgUrl;
	if(!is_dir($imgPath."/"))
	{
		MkdirAll($imgPath,$GLOBALS['cfg_dir_purview']);
		CloseFtp();
	}
	$milliSecond = MyDate("His",time());
	foreach($img_array as $key=>$value)
	{
		if(eregi($basehost,$value))
		{
			continue;
		}
		if($cfg_basehost!=$basehost && eregi($cfg_basehost,$value))
		{
			continue;
		}
		if(!eregi("^http://",$value))
		{
			continue;
		}
		$value = trim($value);
		$itype =  substr($value,-4,4);
		if(!eregi("\.(gif|jpg|png)",$itype))
		{
			$itype = ".jpg";
		}
		$rndFileName = $imgPath."/".$milliSecond.$key.$itype;
		$iurl = $imgUrl."/".$milliSecond.$key.$itype;

		//下载并保存文件
		//$rs = $htd->SaveToBin($rndFileName);
		$rs = DownImageKeep($value,$rfurl,$rndFileName,'',0,30);
		if($rs)
		{
			if($pagestyle > 2)
			{
				$litpicname = GetImageMapDD($iurl,$ddmaxwidth);
			}
			else
			{
				$litpicname = '';
			}
			if(empty($firstdd) && !empty($litpicname))
			{
				$firstdd = $litpicname;
				if(!file_exists($cfg_basedir.$firstdd))
				{
					$firstdd = $iurl;
				}
			}
			@WaterImg($rndFileName,'down');
			$info = '';
			$imginfos = GetImageSize($rndFileName,$info);
			$rsimg .= "{dede:img ddimg='$litpicname' text='' width='".$imginfos[0]."' height='".$imginfos[1]."'} $iurl {/dede:img}\r\n";
		}
	}
	return $rsimg;
}

//获得文章body里的外部资源
function GetCurContent($body)
{
	global $cfg_multi_site,$cfg_basehost,$cfg_basedir,$cfg_image_dir;
	$cfg_uploaddir = $cfg_image_dir;
	$htd = new DedeHttpDown();
	$basehost = "http://".$_SERVER["HTTP_HOST"];
	$img_array = array();
	preg_match_all("/src=[\"|'|\s]{0,}(http:\/\/([^>]*)\.(gif|jpg|png))/isU",$body,$img_array);
	$img_array = array_unique($img_array[1]);
	$imgUrl = $cfg_uploaddir."/".MyDate("ymd",time());
	$imgPath = $cfg_basedir.$imgUrl;
	if(!is_dir($imgPath."/"))
	{
		MkdirAll($imgPath,$GLOBALS['cfg_dir_purview']);
		CloseFtp();
	}
	$milliSecond = MyDate("His",time());
	foreach($img_array as $key=>$value)
	{
		if(eregi($basehost,$value))
		{
			continue;
		}
		if($cfg_basehost!=$basehost && eregi($cfg_basehost,$value))
		{
			continue;
		}
		if(!eregi("^http://",$value))
		{
			continue;
		}
		$htd->OpenUrl($value);
		$itype = $htd->GetHead("content-type");
		$itype = substr($value,-4,4);
		if(!eregi("\.(jpg|gif|png)",$itype))
		{
			if($itype=='image/gif')
			{
				$itype = ".gif";
			}
			else if($itype=='image/png')
			{
				$itype = ".png";
			}
			else
			{
				$itype = '.jpg';
			}
		}
		$milliSecondN = dd2char($milliSecond.mt_rand(1000,8000));
		$value = trim($value);
		$rndFileName = $imgPath."/".$milliSecondN.'-'.$key.$itype;
		$fileurl = $imgUrl."/".$milliSecondN.'-'.$key.$itype;
		$rs = $htd->SaveToBin($rndFileName);
		if($rs)
		{
			$body = str_replace($value,$fileurl,$body);
			@WaterImg($rndFileName,'down');
		}
	}
	$htd->Close();
	return $body;
}

//获取一个远程图片
function GetRemoteImage($url,$uid=0)
{
	global $cfg_basedir,$cfg_image_dir;
	$cfg_uploaddir = $cfg_image_dir;
	$revalues = Array();
	$ok = false;
	$htd = new DedeHttpDown();
	$htd->OpenUrl($url);
	$sparr = Array("image/pjpeg","image/jpeg","image/gif","image/png","image/xpng","image/wbmp");
	if(!in_array($htd->GetHead("content-type"),$sparr))
	{
		return "";
	}
	else
	{
		$imgUrl = $cfg_uploaddir."/".MyDate("ymd",time());
		$imgPath = $cfg_basedir.$imgUrl;
		CreateDir($imgUrl);
		$itype = $htd->GetHead("content-type");
		if($itype=="image/gif")
		{
			$itype = ".gif";
		}
		else if($itype=="image/png")
		{
			$itype = ".png";
		}
		else if($itype=="image/wbmp")
		{
			$itype = ".bmp";
		}
		else
		{
			$itype = ".jpg";
		}
		$rndname = dd2char($uid."_".MyDate("His",time()).mt_rand(1000,9999));
		$rndtrueName = $imgPath."/".$rndname.$itype;
		$fileurl = $imgUrl."/".$rndname.$itype;
		$ok = $htd->SaveToBin($rndtrueName);
		@WaterImg($rndtrueName,'down');
		if($ok)
		{
			$data = GetImageSize($rndtrueName);
			$revalues[0] = $fileurl;
			$revalues[1] = $data[0];
			$revalues[2] = $data[1];
		}
	}
	$htd->Close();
	if($ok)
	{
		return $revalues;
	}
	else
	{
		return "";
	}
}

//获取一个远程Flash文件
function GetRemoteFlash($url,$uid=0)
{
	$cfg_uploaddir = $GLOBALS['media_dir'];
	$cfg_basedir = $GLOBALS['cfg_basedir'];
	$revalues = "";
	$sparr = "application/x-shockwave-flash";
	$htd = new DedeHttpDown();
	$htd->OpenUrl($url);
	if($htd->GetHead("content-type")!=$sparr)
	{
		return "";
	}
	else
	{
		$imgUrl = $cfg_uploaddir."/".MyDate("ymd",time());
		$imgPath = $cfg_basedir.$imgUrl;
		CreateDir($imgUrl);
		$itype = ".swf";
		$milliSecond = $uid."_".MyDate("His",time());
		$rndFileName = $imgPath."/".$milliSecond.$itype;
		$fileurl = $imgUrl."/".$milliSecond.$itype;
		$ok = $htd->SaveToBin($rndFileName);
		if($ok)
		{
			$revalues = $fileurl;
		}
	}
	$htd->Close();
	return $revalues;
}

//检测频道ID
function CheckChannel($typeid,$channelid)
{
	global $dsql;
	if($typeid==0)
	{
		return true;
	}
	$row = $dsql->GetOne("Select ispart,channeltype From `#@__arctype` where id='$typeid' ");
	if($row['ispart']!=0 || $row['channeltype']!=$channelid)
	{
		return false;
	}
	else
	{
		return true;
	}
}

//检测档案权限
function CheckArcAdmin($aid,$adminid)
{
	global $dsql;
	$row = $dsql->GetOne("Select mid From `#@__archives` where id='$aid' ");
	if($row['mid']!=$adminid)
	{
		return false;
	}
	else
	{
		return true;
	}
}

//文档自动分页
function SpLongBody($mybody,$spsize,$sptag)
{
	if(strlen($mybody)<$spsize)
	{
		return $mybody;
	}
	$mybody = stripslashes($mybody);
	$bds = explode('<',$mybody);
	$npageBody = '';
	$istable = 0;
	$mybody = '';
	foreach($bds as $i=>$k)
	{
		if($i==0)
		{
			$npageBody .= $bds[$i]; continue;
		}
		$bds[$i] = "<".$bds[$i];
		if(strlen($bds[$i])>6)
		{
			$tname = substr($bds[$i],1,5);
			if(strtolower($tname)=='table')
			{
				$istable++;
			}
			else if(strtolower($tname)=='/tabl')
			{
				$istable--;
			}
			if($istable>0)
			{
				$npageBody .= $bds[$i]; continue;
			}
			else
			{
				$npageBody .= $bds[$i];
			}
		}
		else
		{
			$npageBody .= $bds[$i];
		}
		if(strlen($npageBody)>$spsize)
		{
			$mybody .= $npageBody.$sptag;
			$npageBody = '';
		}
	}
	if($npageBody!='')
	{
		$mybody .= $npageBody;
	}
	return $mybody;
}

//创建指定ID的文档
function MakeArt($aid,$mkindex=false,$ismakesign=false)
{
	global $cfg_makeindex,$cfg_basedir,$cfg_templets_dir,$cfg_df_style;
	require_once(DEDEINC.'/arc.archives.class.php');
	if($ismakesign)
	{
		$envs['makesign'] = 'yes'; //这种状态表示是更新单个文档时不启用缓存
	}
	$arc = new Archives($aid);
	$reurl = $arc->MakeHtml();
	//是否更新主页,通常只在发布/修改单个文档才使用
	if($mkindex)
	{
		if(isset($typeid))
		{
			$preRow =  $arc->dsql->GetOne("Select id From `#@__arctiny` where id<$aid And arcrank>-1 And typeid='$typeid' order by id desc");
			$nextRow = $arc->dsql->GetOne("Select id From `#@__arctiny` where id>$aid And arcrank>-1 And typeid='$typeid' order by id asc");
			if(is_array($preRow))
			{
				$arc = new Archives($preRow['id']);
				$arc->MakeHtml();
			}
			if(is_array($nextRow))
			{
				$arc = new Archives($nextRow['id']);
				$arc->MakeHtml();
			}
		}
		if($cfg_makeindex=='Y')
		{
			$pv = new PartView();
			$row = $pv->dsql->GetOne("Select * From `#@__homepageset`");
			$templet = str_replace("{style}",$cfg_df_style,$row['templet']);
			$homeFile = dirname(__FILE__)."/../".$row['position'];
			$homeFile = str_replace("\\","/",$homeFile);
			$homeFile = str_replace("//","/",$homeFile);
			$fp = fopen($homeFile,"w") or die("不可写入,无法更新网站主页到:$homeFile 位置");
			fclose($fp);
			$tpl = $cfg_basedir.$cfg_templets_dir."/".$templet;
			if(!file_exists($tpl))
			{
				$tpl = $cfg_basedir.$cfg_templets_dir.'/default/index.htm';
			}
			$pv->SetTemplet($tpl);
			$pv->SaveToHtml($homeFile);
		}
	}
	return $reurl;
}

//取第一个图片为缩略图
function GetDDImgFromBody(&$body)
{
	$litpic = '';

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?