⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inc_archives_functions.php

📁 讲的是网络编程
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php 
require_once(DEDEADMIN."/../include/pub_httpdown.php");
require_once(DEDEADMIN."/../include/inc_photograph.php");
require_once(DEDEADMIN."/../include/pub_oxwindow.php");
require_once(DEDEADMIN."/../include/inc_tag_functions.php");
require_once(DEDEADMIN."/../include/inc_custom_fields.php");
//---------------------------
//获得HTML里的外部资源,针对图集
//---------------------
function GetCurContentAlbum($body,$rfurl,&$firstdd)
{
	global $cfg_multi_site,$cfg_basehost,$ddmaxwidth,$cfg_basedir;
	include_once(DEDEADMIN."/../include/pub_collection_functions.php");
	if(empty($ddmaxwidth)) $ddmaxwidth = 150;
	$rsimg = '';
	$cfg_uploaddir = $GLOBALS['cfg_image_dir'];
	$cfg_basedir = $GLOBALS['cfg_basedir'];
	$basehost = "http://".$_SERVER["HTTP_HOST"];
  if($cfg_multi_site == 'N'){
    $body = str_replace(strtolower($basehost),"",$body);
    $body = str_replace(strtoupper($basehost),"",$body);
  }else{
  	if($cfg_basehost!=$basehost){
  		$body = str_replace(strtolower($basehost),$cfg_basehost,$body);
  		$body = str_replace(strtoupper($basehost),$cfg_basehost,$body);
  	}
  }
	$img_array = array();
	preg_match_all("/(src|SRC)=[\"|'| ]{0,}(http:\/\/(.*)\.(gif|jpg|jpeg|png))/isU",$body,$img_array);
	$img_array = array_unique($img_array[2]);
	
	$imgUrl = $cfg_uploaddir."/".strftime("%y%m%d",time());
	$imgPath = $cfg_basedir.$imgUrl;
	if(!is_dir($imgPath."/")){
		MkdirAll($imgPath,$GLOBALS['cfg_dir_purview']);
		CloseFtp();
	}
	$milliSecond = strftime("%H%M%S",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,0,-4);
		if(!eregi("gif|jpg|jpeg|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){
			$litpicname = GetImageMapDD($iurl,$ddmaxwidth);
			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_uploaddir = $GLOBALS['cfg_image_dir'];
	$cfg_basedir = $GLOBALS['cfg_basedir'];
	$htd = new DedeHttpDown();
	
	$basehost = "http://".$_SERVER["HTTP_HOST"];
	
	/*
	//避免删除本地链接
	if($cfg_multi_site == 'N'){
		$body = str_replace(strtolower($basehost),"",$body);
		$body = str_replace(strtoupper($basehost),"",$body);
	}else{
		if($cfg_basehost!=$basehost){
			$body = str_replace(strtolower($basehost),$cfg_basehost,$body);
			$body = str_replace(strtoupper($basehost),$cfg_basehost,$body);
		}
	}
	*/
  
	$img_array = array();
	preg_match_all("/(src|SRC)=[\"|'| ]{0,}(http:\/\/(.*)\.(gif|jpg|jpeg|bmp|png))/isU",$body,$img_array);
	$img_array = array_unique($img_array[2]);
	
	$imgUrl = $cfg_uploaddir."/".strftime("%y%m%d",time());
	$imgPath = $cfg_basedir.$imgUrl;
	if(!is_dir($imgPath."/")){
		MkdirAll($imgPath,$GLOBALS['cfg_dir_purview']);
		CloseFtp();
	}
	$milliSecond = strftime("%H%M%S",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");
		if($itype=="image/gif") $itype = ".gif";
		else if($itype=="image/png") $itype = ".png";
		else $itype = ".jpg";
		$value = trim($value);
		$rndFileName = $imgPath."/".$milliSecond.$key.$itype;
		$fileurl = $imgUrl."/".$milliSecond.$key.$itype;
		//下载并保存文件
		$rs = $htd->SaveToBin($rndFileName);
		if($rs){
			$body = str_replace($value,$fileurl,$body);
			@WaterImg($rndFileName,'down');
	  }
	}
	$htd->Close();
	return $body;
}
//------------------------------
//获取一个远程图片
//------------------------------
$GLOBALS['_i'] = 0;
function GetRemoteImage($url,$uid=0)
{
	global $cuserLogin,$_i;
	$_i++;
	if(empty($uid)) $uid = $cuserLogin->getUserID();
	$cfg_uploaddir = $GLOBALS['cfg_image_dir'];
	$cfg_basedir = $GLOBALS['cfg_basedir'];
	$revalues = Array();
	$ok = false;
	$htd = new DedeHttpDown();
	$htd->OpenUrl($url);
	$sparr = Array("image/pjpeg","image/jpeg","image/gif","image/png","image/x-png","image/wbmp");
	if(!in_array($htd->GetHead("content-type"),$sparr)){
		return "";
	}else{  	
  	$imgUrl = $cfg_uploaddir."/".strftime("%Y%m",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."_".strftime("%H%M%S",time()).mt_rand(1000,9999));
		$rndname = strftime("%d",$ntime).dd2char(strftime("%H%M%S",$ntime).'0'.$uid.'0'.mt_rand(1000,9999)).'-'.$_i;
		
		$rndtrueName = $imgPath."/".$rndname.$itype;
		$fileurl = $imgUrl."/".$rndname.$itype;
		
  	$ok = $htd->SaveToBin($rndtrueName);
  	
  	//加水印
  	@WaterImg($rndtrueName,'down');
  	if($ok){
  	  $info = '';
  	  $data = GetImageSize($rndtrueName,$info);
  	  $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."/".strftime("%y%m%d",time());
	  $imgPath = $cfg_basedir.$imgUrl;
	  CreateDir($imgUrl);
  	$itype = ".swf";
		$milliSecond = $uid."_".strftime("%H%M%S",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)
{
	 if($typeid==0) return true;
	 $dsql = new DedeSql(false); 
	 $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)
{
	 $dsql = new DedeSql(false);
	 $row = $dsql->GetOne("Select adminid From #@__archives where ID='$aid' ");
	 if($row['adminid']!=$adminid) return false;
	 else return true;
}
//---------------
//文档自动分页
//---------------
function SpLongBody(&$mybody,$spsize,$sptag)
{
  if(strlen($mybody)<$spsize) return $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,$checkLike=false)
{
	
	global $cfg_makeindex,$cfg_basedir,$cfg_templets_dir,$cfg_df_style,$cfg_up_prenext,$typeid;
	include_once(DEDEADMIN."/../include/inc_archives_view.php");
	$arc = new Archives($aid);
  $reurl = $arc->MakeHtml();
  //更新上下篇文章
  if($cfg_up_prenext=='Y' && !empty($typeid))
  {
     $preRow =  $arc->dsql->GetOne("Select ID From `{$arc->MainTable}` where ID<$aid And arcrank>-1 And typeid='$typeid' order by ID desc");
     $nextRow = $arc->dsql->GetOne("Select ID From `{$arc->MainTable}` 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);
	  $pv->SetTemplet($cfg_basedir.$cfg_templets_dir."/".$templet);
	  $pv->SaveToHtml($homeFile);
  }
  return $reurl;
}
//---------------------------
//上传缩略图

⌨️ 快捷键说明

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