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

📄 news_ac.php

📁 没用的东西? 国外php免费程序,相册 留言板 等
💻 PHP
字号:
<?php
global $pageNum;
$cate=g('cate');
$month=array('','January','February','March','April','May','June','July','August','September','October','November','December');

/*Auto Archive*/
$sql = "select nCreated from news where nShow=1 group by from_unixtime(nCreated,'%Y-%M')";
$result=$this->db->query($sql);
while($row=$this->db->fetch_array($result)){
	$nCreated=date('M Y',$row['nCreated']);
	$nArchive=date('Ym',$row['nCreated']);
	$archive[]=array($nCreated,$nArchive);
}
if(isset($archive)) $this->set('archive',$archive);

/*If Need to show Content Page*/
if(isset($page) and is_array($page)){
	$page=join($page,',');
	$result=$this->db->query("select * from page where id in($page)");
	unset($page);
	while($row=$this->db->fetch_array($result)){
		$title=$row['pTitle'];
		$kws=$row['pKeywords'];
		$dsc=$row['pDescription'];
		$cnt=$row['pContent'];
		$cms[]=array($title,$kws,$dsc,$cnt);
	}
	if(isset($cms)) $this->set('cms',$cms);
}
		
		
/*Default Actions*/			
switch($cate){
	case "view":
		$id=g('id');
		if($id){
			$sql = "select * from news where nShow=1 and id=$id";
			$result=$this->db->query($sql);
			if($row=$this->db->fetch_array($result)){
				$id=$row['ID'];
				$nTitle=$row['nTitle'];
				$nKeywords=$row['nKeywords'];
				$nDescription=$row['nDescription'];
				$nContent=$row['nContent'];
				$nCreated=date('d/m/Y',$row['nCreated']);
				$nUpdated=date('d/m/Y',$row['nUpdated']);
				$news=array($id,$nTitle,$nKeywords,$nDescription,$nContent,$nCreated,$nUpdated);
				$this->set('news',$news);
				$this->run('viewNews');
			}
			else{
				echo "<script>alert('News No. not found.');location.href='news.php';</script>";exit;
			}
		}
		else{header('location:news.php');exit;}
	break;
	case "archive":
		$time=g('ym');
		if($time){
			$page[]=$pageNum;
			if(g('page')){$page[]=intval(g('page'));}else{$page[]=1;}
			$sql="select count(id) as amount from news where nShow=1 and from_unixtime(nCreated,'%Y%m')='$time'";
			$result=$this->db->query($sql);
			$row=$this->db->fetch_array($result);
			$amount = $row['amount'];
			if($amount){
				if($amount % $page[0]){$page[]=(int)($amount/$page[0])+1;}else{$page[]=$amount/$page[0];}
				$page[]=$amount;
			}
			else{$page[]=0;$page[]=0;}
			
			$sql = "select * from news where nShow=1 and from_unixtime(nCreated,'%Y%m')='$time' order by nCreated desc limit ".($page[1]-1)*$page[0].",".$page[0];
			$result=$this->db->query($sql);
			while($row=$this->db->fetch_array($result)){
				$id=$row['ID'];
				$nTitle=$row['nTitle'];
				$nContent=strip_tags($row['nContent']);
				$nCreated=date('d/m/Y',$row['nCreated']);
				$nUpdated=date('d/m/Y',$row['nUpdated']);
				$news[]=array($id,$nTitle,$nContent,$nCreated,$nUpdated);
			}
			$this->set('page',$page);
			if(isset($news)) $this->set('news',$news);
			$this->set('pageParam',"news.php?cate=archive&ym=$time&");
			$this->run('news');
		}
		else{header('location:news.php');exit;}
	break;
	default:
		$page[]=$pageNum;
		if(g('page')){$page[]=intval(g('page'));}else{$page[]=1;}
		$sql="select count(id) as amount from news where nShow=1";
		$result=$this->db->query($sql);
		$row=$this->db->fetch_array($result);
		$amount = $row['amount'];
		if($amount){
			if($amount % $page[0]){$page[]=(int)($amount/$page[0])+1;}else{$page[]=$amount/$page[0];}
			$page[]=$amount;
		}
		else{$page[]=0;$page[]=0;}
		
		$sql = "select * from news where nShow=1 order by nCreated desc limit ".($page[1]-1)*$page[0].",".$page[0];
		$result=$this->db->query($sql);
		while($row=$this->db->fetch_array($result)){
			$id=$row['ID'];
			$nTitle=$row['nTitle'];
			$nContent=strip_tags($row['nContent']);
			$nCreated=date('d/m/Y',$row['nCreated']);
			$nUpdated=date('d/m/Y',$row['nUpdated']);
			$news[]=array($id,$nTitle,$nContent,$nCreated,$nUpdated);
		}
		$this->set('page',$page);
		if(isset($news)) $this->set('news',$news);
		$this->set('pageParam','news.php?');
		$this->run('news');
	break;
}

function StripHTML($string){
$pattern=array ("'<script[^>]*?>.*?</script>'si", "'<style[^>]*?>.*?</style>'si",  "'<[/!]*?[^<>]*?>'si",  "'([])[s]+'",  "'&(quot|#34);'i",  "'&(amp|#38);'i",  "'&(lt|#60);'i",  "'&(gt|#62);'i",  "'&(nbsp|#160);'i",  "'&(iexcl|#161);'i",  "'&(cent|#162);'i",  "'&(pound|#163);'i",  "'&(copy|#169);'i",  "'&#(d+);'e");$replace=array ("", "", "\1", "", "&", "<", ">", " ", chr(161), chr(162), chr(163), chr(169), "chr(\1)");
return preg_replace ($pattern,$replace,$str);
}
?>

⌨️ 快捷键说明

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