调用方法如下:
复制代码 代码如下:
$Template= '<li>[<a href="https://www.jb51.net/{catedir}">{catetitle}</a>]<a href="https://www.jb51.net/article/{html}" title="{title}" >{title|6}{title2|20}</a>点击数:{hits} 日期:{posttime|H:i:s}</li>';
$Article=new Article();
$Article->Template=$Template;
$Article->CateId=30;
DebugStr('根据模板调用文章');
DebugStr($Article->getArticleListByCateId());
$Template='<li><a href="https://www.jb51.net/article/{html}" title="{title}" >{title}</a>点击数:{hits} 日期:{posttime|Y-m-d H:i:s}</li>';
$Article->Template=$Template;
$Article->CateId=30;
DebugStr($Article->getArticleListByCateId($Template, 30));
$Template='<a href="https://www.jb51.net/article/{html}" title="{title}" >{title}</a> 日期:{posttime}<br>';
$Article->Template=$Template;
$Article->CateId=28;
DebugStr($Article->getArticleListByCateId($Template, 28));
类代码如下:
复制代码 代码如下:
<?php
/**
* 文章类,方便文章列表、内容的调用
* 仅支持PHP5
*
* 类函数列表:
* getArticleListByCateId();
*
* @author Zerolone
* @version 2011-3-14 9:53:42
*
* 2011-1-31 10:11:07 增加静态方法 getCatePreviewUrl getPreviewUrl
*/
class Article {
public $CateId = 0; //栏目编号 0,可以为一个栏目编号, 或者多个栏目。例如:12, 或者12,13
public $Count = 10; //记录数 10
public $TitleCount = 20; //文字显示数 20
public $BeginCount = 0; //起始记录数 0
public $OrderBy = 'id'; //排序字段 默认以id字段排序
public $OrderSort = 'DESC'; //排序顺序 默认DESC,倒序
public $OrderBy2 = ''; //排序字段2
public $OrderSort2 = ''; //排序顺序2
public $Area = 0; //显示区域 0,全部显示
public $Flag = ISSUEFLAG; //显示文章状态 2,2为 已保存 已发布
public $Pic = 0; //仅调用有图片的 0,1为仅调用有图的
public $Video = 0; //仅调用有视频的 0,1为仅调用视频的
public $notshowlist= 0; //不显示不在列表中的 0,不显示, 1 显示
public $AndWhere = ''; //额外加入的查询
public $Loop = 0; //循环列表 0,
public $Template = ''; //模板
public $IdList = ''; //Id列表,用于外部调用
//内部使用的变量
protected $SqlCateId = ''; //栏目Sql语句
protected $SqlCateTitleId = ''; //栏目Sql语句
protected $SqlArea = ''; //显示区域Sql语句
protected $SqlFlag = ''; //状态
protected $SqlNotShow = ''; //不显示列表中
protected $SqlPic = ''; //是否仅调用图片
protected $SqlVideo = ''; //是否仅调用视频
protected $SqlOrder = ''; //排序
protected $SqlLimit = ''; //显示个数
protected $SqlWhere = ''; //加入查询
public $SqlStr = ''; //调试用
/**
* 初始化Sql语句
*
*/
function InitSql(){
//栏目编号
$CateId=$this->CateId;
if (strpos($CateId, ',')) {
$this->SqlCateId=' AND `cateid` in ('.$CateId.')';
} elseif ($CateId>0) {
$this->SqlCateId=' AND `cateid` ='.$CateId;
}
if ($CateId==0) $this->SqlCateId='';
/*
$CateId=$this->CateId;
$this->SqlCateTitleId=' AND `id` ='.$CateId;
*/
//显示区域
$Area=$this->Area;
if ($Area>0) {
$Area+=0;
$this->SqlArea= ' AND `area'.$Area.'` =1';
}
//状态
$this->SqlFlag= ' AND `flag` = '. $this->Flag;
//列表中不显示
$this->SqlNotShow= ' AND `notshowlist` = '. $this->notshowlist;
//图片
$Pic = $this->Pic;
if ($Pic==1){
$this->SqlPic= ' AND (`pic1` <>"" or `pic2`<>"") ';
}else {
$this->SqlPic= '';
}
//视频
$Video = $this->Video;
if ($Video==1){
$this->SqlVideo= ' AND `isvideo`=1 ';
}else {
$this->SqlVideo= '';
}
//额外加入的查询
$AndWhere = $this->AndWhere;
if ($AndWhere<>''){
$this->SqlWhere = ' And ' . $AndWhere;
}
//排序
$this->SqlOrder= ' ORDER BY `'.$this->OrderBy.'` '.$this->OrderSort;
if ($this->OrderBy2!='') $this->SqlOrder.= ' ,`'.$this->OrderBy2.'` '.$this->OrderSort2;
//显示个数
$this->SqlLimit= ' LIMIT '.$this->BeginCount.', '.$this->Count.';';
}
/**
* 清除,置为默认
*/
function Clear(){
$this->CateId = 0; //栏目编号 0,可以为一个栏目编号, 或者多个栏目。例如:12, 或者12,13
$this->Count = 10; //记录数 10
$this->TitleCount = 20; //文字显示数 20
$this->BeginCount = 0; //起始记录数 0
$this->OrderBy = 'id'; //排序字段 默认以id字段排序
$this->OrderSort = 'DESC'; //排序顺序 默认DESC,倒序
$this->Area = 0; //显示区域 0,全部显示
$this->Flag = ISSUEFLAG; //显示文章状态 2,2为 已保存 已发布
$this->Pic = 0; //仅调用有图片的 0,1为仅调用有图的
$this->Video = 0; //仅调用有视频的 0,1为仅调用视频的
$this->notshowlist = 0; //不显示不在列表中的 0,不显示, 1 显示
$this->AndWhere = ''; //额外加入的查询
$this->Loop = 0; //循环列表 0,
$this->Template = ''; //模板
}
/**
* 返回文章内容字符串
*
* {<li><a href="https://www.jb51.net/article/{html}" title="{title}" >{title|20}{title2|20}</a>点击数:{hits} {memo|20} 日期:{posttime|H:i:s y-m-d}</li>}
* 说明如下, 产生一个循环模板,{}里面的说明如下
* html 链接,优先显示跳转链接
* title 标题,加|线后面的参数:1、为字数显示限制,2、为字数限制后是否显示省略符号, title为优先显示title, title2为优先显示title2
* hits 点击率
* posttime 提交时间,后面的参数为日期格式化方法
* memo 调用文字,加|线后面的参数:1、为字数显示限制,2、为字数限制后是否显示省略符号
* loop 循环变量
*
* @return 文章列表
*/
function getArticleListByCateId(){
$this->InitSql();
$Str_Loop = '';
$ReturnString = '';
$Template = $this->Template;
//文章列表
$SqlStr = 'SELECT * FROM `'.DB_TABLE_PRE . 'view_article`';
$SqlStr.= ' WHERE 1=1';
$SqlStr.=$this->SqlNotShow; //是否显示不显示的
$SqlStr.=$this->SqlCateId; //栏目
$SqlStr.=$this->SqlArea; //区域
$SqlStr.=$this->SqlFlag; //状态
$SqlStr.=$this->SqlPic; //图片
$SqlStr.=$this->SqlVideo; //视频
$SqlStr.=$this->SqlWhere; //额外的查询
$SqlStr.=$this->SqlOrder; //排序
$SqlStr.=$this->SqlLimit; //显示条数
$this->SqlStr=$SqlStr;
$this->OrderBy2 = '';
$this->OrderSort2 = '';
//标题1
@preg_match('/{title\|([\d].+?)}/i', $Template, $matches);
@$title_count = $matches[1];
//标题2
@preg_match('/{title2\|([\d].+?)}/i', $Template, $matches);
@$title2_count = $matches[1];
//调用文字
@preg_match('/{memo\|([\d].+?)}/i', $Template, $matches);
@$memo_count = $matches[1];
//时间显示格式
@preg_match('/{posttime\|(.+?)}/i', $Template, $matches);
@$posttime_format=$matches[1];
//替换掉这些
$Template = preg_replace('/({title\|[\d].+?})/i', '{title}', $Template);
$Template = preg_replace('/({title2\|[\d]+.?})/i', '{title2}', $Template);
$Template = preg_replace('/({posttime\|.+?})/i', '{posttime}', $Template);
$Template = preg_replace('/({memo\|[\d].+?})/i', '{memo}', $Template);
//loop
$loop = $this->Loop;
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) {
$DB_Record_Arr = $MyDatabase->ResultArr;
foreach ( $DB_Record_Arr as $DB_Record ) {
$id = $DB_Record['id'];
$this->IdList .= $id . ',';
$title = $DB_Record['title'];
$title_full = $title;
$title2 = $DB_Record['title2'];
$titlestrip = strip_tags($title);
$memo = $DB_Record['memo'];
$posttime = $DB_Record['posttime'];
$reurl = $DB_Record['reurl'];
$url = $DB_Record['html'];
$hits = $DB_Record['hits'];
$titlecolor = $DB_Record['titlecolor'];
$catetitle = $DB_Record['catetitle'];
$catedir = $DB_Record['catedir'];
$catedesc = $DB_Record['catedesc'];
$Str_Loop = $Template;
//处理各个字符串
//跳转链接,如果存在,则文章链接为跳转链接
if ($reurl<>''){
$html = $reurl;
}else {
$html = SITE_URL . SITE_FOLDER . ARTICLEURL . $url;
}
$pic1 = $DB_Record['pic1'];
$pic2 = $DB_Record['pic2'];
if ($pic2<>''){
$pic = $pic2;
}else{
$pic = $pic1;
}
//标题长度 //调用文字
if ($title_count) $title = subString($title, $title_count);
if ($title2_count) $title2 = subString($title2, $title2_count);
if ($memo_count) $memo = subString($memo, $memo_count);
//文章标题颜色,用Style级别好像更高
if ($titlecolor<>'') $title = '<font>'.$title.'</font>';
//时间格式化
if ($posttime_format!=''){
$posttime=date($posttime_format, $posttime);
}else {
$posttime=date('Y-m-d H:i', $posttime);
}
//替换各个内容
//标题
$Arr_Search = array('{id}', '{title_full}', '{title}', '{title2}', '{titlestrip}', '{memo}', 'https://www.jb51.net/article/{html}', '{hits}', '{posttime}', '{catetitle}', 'https://www.jb51.net/{catedir}', '{pic}', '{pic1}', '{pic2}', '{loop}', '{catedesc}');
$Arr_Replace = array($id, $title_full, $title, $title2, $titlestrip, $memo, $html, $hits, $posttime, $catetitle, $catedir, $pic, $pic1, $pic2, $loop++, $catedesc);
$Str_Loop=str_replace($Arr_Search, $Arr_Replace, $Str_Loop);
$ReturnString.=$Str_Loop;
}
}
//用完清空
$this->Clear();
return $ReturnString;
}
/**
* 返回栏目里面的html
*/
function DefaultHtml(){
$html='';
$this->InitSql();
//-------------------0
$SqlStr = 'SELECT `html` FROM `'.DB_TABLE_PRE . 'view_article`';
$SqlStr.= ' WHERE 1=1';
$SqlStr.=$this->SqlCateId;//栏目
$SqlStr.=$this->SqlFlag;//状态
$SqlStr.=$this->SqlOrder;//排序
$SqlStr.=$this->SqlLimit;//显示个数
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) {
$html = $MyDatabase->ResultArr [0][0];
}
return $html;
}
/**
* 获取栏目地址
* @param $id 栏目编号
*/
static public function getCateHTML($id){
$html = '';
$SqlStr = 'SELECT `dir` FROM `'.DB_TABLE_PRE . 'article_cate`';
$SqlStr.= ' WHERE `id`='.$id;
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) {
$html = $MyDatabase->ResultArr [0][0];
}
return $html;
}
/**
* 返回栏目标题
*/
function getCateTitle(){
$CateTitle='';
//-------------------0
$SqlStr = 'SELECT `title` FROM `'.DB_TABLE_PRE . 'view_article`';
$SqlStr.= ' WHERE 1=1';
$SqlStr.=$this->SqlCateTitleId; //栏目
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) {
$CateTitle = $MyDatabase->ResultArr [0][0];
}
return $CateTitle;
}
/**
* 获取文章日期返回一个以 2011-1 这种类型的列表链接
*/
function getArticListDate(){
//栏目编号
$CateId=$this->CateId;
if (strpos($CateId, ',')) {
$this->SqlCateId=' AND `cateid` in ('.$CateId.')';
} elseif ($CateId>0) {
$this->SqlCateId=' AND `cateid` ='.$CateId;
}
$cateList='';
$intCount=0;
$strSearch=''; //搜索年月
$strMonth=''; //月名
//获取今天的年-月
$year=date("Y",time());
$month=date("m",time());
//今年
$SqlStr = 'SELECT COUNT( * ) from `'.DB_TABLE_PRE . 'view_article`'' WHERE DATE_FORMAT(`posttime`, \'%Y\')=\''.$year.'\'';
//栏目
$SqlStr.=$this->SqlCateId;
$MyDatabase->SqlStr = $SqlStr;
$MyDatabase=Database::Get();
if ($MyDatabase->Query ()) {
$intCount = $MyDatabase->ResultArr [0][0];
$cateList.=' <li><a href="#">'.$year.' ('.$intCount.')</a></li>';
}
//循环今年
for($i=$month;$i>0;$i--){
if (strlen($i)==1){
$strSearch= $year . '-0' . $i;
}else{
$strSearch= $year . '-' . $i;
}
switch ($i) {
case 1:
$strMonth='一月';
break;
case 2:
$strMonth='二月';
break;
case 3:
$strMonth='三月';
break;
case 4:
$strMonth='四月';
break;
case 5:
$strMonth='五月';
break;
case 6:
$strMonth='六月';
break;
case 7:
$strMonth='七月';
break;
case 8:
$strMonth='八月';
break;
case 9:
$strMonth='九月';
break;
case 10:
$strMonth='十月';
break;
case 11:
$strMonth='十一月';
break;
case 12:
$strMonth='十二月';
break;
}
$SqlStr = 'SELECT COUNT( * ) from `'.DB_TABLE_PRE.'article` WHERE DATE_FORMAT(`posttime`, \'%Y-%m\')=\''.$strSearch.'\'';
//栏目
$SqlStr.=$this->SqlCateId;
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query () ) {
$DB_Record = $MyDatabase->ResultArr [0];
$intCount = $DB_Record[0];
if($intCount>0){
$cateList.=' <li><a href="#">'.$strMonth.' ('.$intCount.')</a></li>';
}
}
}
//最近9年循环
for($i=$year-1;$i>$year-10;$i--){
$SqlStr = 'SELECT COUNT( * ) from `'.DB_TABLE_PRE.'article` WHERE DATE_FORMAT(`posttime`, \'%Y\')=\''.$i.'\'';
//栏目
$SqlStr.=$this->SqlCateId;
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query () ) {
$DB_Record = $MyDatabase->ResultArr [0];
$intCount = $DB_Record[0];
if($intCount>0){
$cateList.=' <li><a href="#">'.$i.' ('.$intCount.')</a></li>';
}
}
}
return $cateList;
}
/**
* 根据上级栏目编号, 返回栏目标题列表。
*
* @param 上级编号 $parentid
*
*/
function getTitleListByCateId($parentid){
$CateTitleList='';
//-------------------0------1------2
$SqlStr = 'SELECT `title`, `id`, `url` FROM `'.DB_TABLE_PRE . 'view_article`';
$SqlStr.= ' WHERE parentid=' . $parentid;
$SqlStr.= ' ORDER BY `level` ASC;';
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) {
$DB_Record_Arr = $MyDatabase->ResultArr;
foreach ( $DB_Record_Arr as $DB_Record ) {
if($DB_Record[2]==''){
$CateTitleList.= '<a href="article.php?id='.$DB_Record[1].'">'.$DB_Record[0].'</a> ';
}else{
$CateTitleList.= '<a href="'https://www.jb51.net/article/.$DB_Record[2].'?id='.$DB_Record[1].'">'.$DB_Record[0].'</a> ';
}
}
}
return $CateTitleList;
}
/**
* 根据栏目编号, 返回栏目文章图文列表。
* @param $cateid 上级编号
* @param $limit 显示条数
* @param $prev 前置标记
*/
function getArticlePicListByCateId($cateid, $limit, $prev=''){
$str_return='';
//-------------------0------1------2---------3-------4--------5
$SqlStr = 'SELECT `title`, `id`, `reurl`, `html`, `pic1`, `memo` FROM `'.DB_TABLE_PRE . 'view_article`';
$SqlStr.= ' WHERE `cateid`=' . $cateid;
$SqlStr.= ' AND `flag`=' . ARTICLE_FLAG;
$SqlStr.= ' AND `pic1`!=\'\'';
$SqlStr.= ' ORDER BY `order` ASC, `id` DESC';
$SqlStr.= ' LIMIT ' . $limit;
//echo $SqlStr;
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) {
$DB_Record_Arr = $MyDatabase->ResultArr;
foreach ( $DB_Record_Arr as $DB_Record ) {
$DB_Record[0] = subString($DB_Record[0], 18);
$DB_Record[5] = subString($DB_Record[5], 56);
$url= $DB_Record[3];
if($DB_Record[2]!='') $url= $DB_Record[2];
$str_return.= '<dl>';
$str_return.= '<dd><a href="'https://www.jb51.net/article/.$url.'"><img src="'https://www.jb51.net/article/.$DB_Record[4].'" /></a></dd>';
$str_return.= '<dt><a href="'https://www.jb51.net/article/.$url.'">'.$DB_Record[0].'</a>'.$DB_Record[5].'<a href="'https://www.jb51.net/article/.$url.'">查看</a></dt>';
$str_return.= '</dl>';
}
}
return $str_return;
}
/**
* 根据ID, 返回下级最大分类。
*
* @param 编号 $id
*
*/
function getSIdById($id){
$ReturnContent='';
//------------------0------1
$SqlStr = 'SELECT `id` FROM `'.DB_TABLE_PRE . 'view_article`';
$SqlStr.= ' WHERE `parentid`=' . $id;
$SqlStr.= ' ORDER BY `level` DESC';
// echo $SqlStr;
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) {
$ReturnContent = $MyDatabase->ResultArr [0][0];
}
return $ReturnContent;
}
/**
* 返回栏目标题
* @param $id 栏目编号
*/
function getCateTitleById($id){
$CateTitle='';
//-------------------0
$SqlStr = 'SELECT `title` FROM `'.DB_TABLE_PRE . 'view_article`';
$SqlStr.= ' WHERE 1=1';
$SqlStr.= ' AND `id`='.$id;
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) {
$CateTitle = $MyDatabase->ResultArr [0][0];
}
return $CateTitle;
}
/**
* 返回上级栏目ID
* @param $id 栏目编号
*/
function getParentCateIdById($id){
$CateTitle='';
//--------------------0
$SqlStr = 'SELECT `parentid` FROM `'.DB_TABLE_PRE . 'view_article`';
$SqlStr.= ' WHERE 1=1';
$SqlStr.= ' AND `id`='.$id;
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) {
$CateTitle = $MyDatabase->ResultArr [0][0];
}
return $CateTitle;
}
/**
* 根据文章编号,增加一个点击
* @param $id 文章编号
*/
static public function UpdateHits($id){
//-------------------0
$SqlStr = 'UPDATE `' . DB_TABLE_PRE . 'article`';
$SqlStr.= ' SET `hits`=`hits`+1';
$SqlStr.= ' WHERE 1=1';
$SqlStr.= ' AND `id`='.$id;
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
$MyDatabase->ExecuteQuery ();
}
/**
* 根据文章编号,返回点击数
* @param $id 文章编号
*/
static public function GetHits($id){
$ReturnContent='';
//-------------------0
$SqlStr = 'SELECT `hits` FROM `' . DB_TABLE_PRE . 'article`';
$SqlStr.= ' WHERE 1=1';
$SqlStr.= ' AND `id`='.$id;
// var_dump($SqlStr);
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) {
$ReturnContent = $MyDatabase->ResultArr [0][0];
}
return $ReturnContent;
}
/**
* 根据编号, 返回内容
* @param $id 文章编号
*/
function getContentById($id){
$ReturnContent='';
//-------------------0
$SqlStr = 'SELECT `content` FROM `'.DB_TABLE_PRE . 'view_article`';
$SqlStr.= ' WHERE 1=1';
$SqlStr.= ' AND `id`='.$id;
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) {
$ReturnContent = $MyDatabase->ResultArr [0][0];
}
return $ReturnContent;
}
/**
* 根据编号, 返回地址
* @param $id 文章编号
*/
function getUrlById($id){
$ReturnContent='';
//------------------0
$SqlStr = 'SELECT `reurl` FROM `'.DB_TABLE_PRE . 'view_article`';
$SqlStr.= ' WHERE 1=1';
$SqlStr.= ' AND `id`='.$id;
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) {
$ReturnContent = $MyDatabase->ResultArr [0][0];
if($ReturnContent==''){
$ReturnContent='article_details.php?id='.$id;
}
}
return $ReturnContent;
}
/**
* 根据编号, 返回静态页面地址
* @param $id 文章编号
*/
function getHTMLById($id){
$ReturnContent='';
//------------------0
$SqlStr = 'SELECT `html` FROM `'.DB_TABLE_PRE . 'view_article`';
$SqlStr.= ' WHERE 1=1';
$SqlStr.= ' AND `id`='.$id;
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) $ReturnContent = $MyDatabase->ResultArr [0][0];
return $ReturnContent;
}
/**
* 根据编号, 返回上一页
* @param 编号 $id
* @param 栏目编号 $cateid
*/
function getPrevById($id, $cateid){
$ReturnContent='没有文章';
//------------------0
$SqlStr = 'SELECT `title`, `html` FROM `'.DB_TABLE_PRE . 'view_article`';
$SqlStr.= ' WHERE 1=1';
$SqlStr.= ' AND `id`<'.$id;
$SqlStr.= ' AND `cateid`='.$cateid;
$SqlStr.= ' AND `flag`=' . ARTICLE_FLAG;
$SqlStr.= ' ORDER BY `order` ASC, `id` desc';
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) $ReturnContent = '<a href="'.$MyDatabase->ResultArr [0][1].'">'. subString($MyDatabase->ResultArr [0][0], 100) . '</a>';
return $ReturnContent;
}
/**
* 根据编号, 返回下一页
*
* @param 编号 $id
* @param 栏目编号 $cateid
*/
function getNextById($id, $cateid){
$ReturnContent='没有文章';
//------------------0
$SqlStr = 'SELECT `title`, `html` FROM `'.DB_TABLE_PRE . 'view_article`';
$SqlStr.= ' WHERE 1=1';
$SqlStr.= ' AND `id`>'.$id;
$SqlStr.= ' AND `cateid`='.$cateid;
$SqlStr.= ' AND `flag`=' . ARTICLE_FLAG;
$SqlStr.= ' ORDER BY `order` ASC, `id` desc';
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) $ReturnContent = '<a href="'.$MyDatabase->ResultArr [0][1].'">'. subString($MyDatabase->ResultArr [0][0], 100) . '</a>';
return $ReturnContent;
}
/**
* 根据level, 返回导航信息
* @param $level
*/
function getNavByLevel($level){
$ReturnContent=SITE_NAV;
$ReturnContent.=ARTICLE_NAV;
//$level=substr($level, 0, 2);
//$level='01010101';
$level_list='';
$level_len=strlen($level);
for ($i=2; $i<$level_len;$i+=2){
$level_list.=substr($level,0,$i) . ',';
}
$level_list.=$level;
// DebugStr( $level_list);
$SqlStr = 'SELECT * FROM `'.DB_TABLE_PRE . 'view_article`';
$SqlStr.= ' WHERE `level` in (' .$level_list . ')';
$SqlStr.= ' ORDER BY `level` ASC;';
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) {
$levels = $MyDatabase->ResultArr;
foreach ($levels as $level){
$ReturnContent.=' <a href="'https://www.jb51.net/article/.$level['dir'].'">'https://www.jb51.net/article/.$level['title'].' ></a>';
}
}
return $ReturnContent;
}
/**
* 首页专用调用, 根据一个栏目编号, 返回该栏目下面的文章, 其中包括一张图片。
* @param $cateid
*/
function getPartByCateId($cateid){
$strReturn='<dl>';
$id=0;
$SqlStr = 'SELECT * FROM `'.DB_TABLE_PRE . 'view_article`';
$SqlStr.= ' WHERE `cateid` =' .$cateid;
$SqlStr.= ' AND `flag` ='.ARTICLE_FLAG;
$SqlStr.= ' AND `pic1` !=\'\'';
$SqlStr.= ' ORDER BY `order` ASC, `id` DESC';
$SqlStr.= ' LIMIT 1;';
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
// DebugStr($SqlStr);
if ($MyDatabase->Query ()) {
$article = $MyDatabase->ResultArr[0];
$id = $article['id'];
$strReturn.='<dd><a href="'https://www.jb51.net/article/.$article['html'].'"><img src="'https://www.jb51.net/article/.$article['pic1'].'" /></a></dd>';
}
$strReturn.='<dt>';
//文章列表
$SqlStr = 'SELECT * FROM `'.DB_TABLE_PRE . 'view_article`';
$SqlStr.= ' WHERE `cateid` =' .$cateid;
$SqlStr.= ' AND `flag` ='.ARTICLE_FLAG;
$SqlStr.= ' AND `id` !='.$id;
$SqlStr.= ' ORDER BY `order` ASC, `id` DESC';
$SqlStr.= ' LIMIT 6;';
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) {
$articles = $MyDatabase->ResultArr;
$i=1;
foreach ($articles as $article){
if ($i==1){
$strReturn.='<a href="'https://www.jb51.net/article/.$article['html'].'">'.subString($article['title'],34).'</a>';
}else{
$strReturn.='<a href="'https://www.jb51.net/article/.$article['html'].'">'.subString($article['title'],50).'</a>';
}
$i++;
}
}
$strReturn.='</dt></dl>';
return $strReturn;
}
/**
* 根据编号, 返回Level
* @param $id
*/
function getLevelById($id){
$ReturnContent='';
$SqlStr = 'SELECT `Level` FROM `'.DB_TABLE_PRE . 'article_cate`';
$SqlStr.= ' WHERE 1=1';
$SqlStr.= ' AND `id`='.$id;
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) $ReturnContent = $MyDatabase->ResultArr [0][0];
return $ReturnContent;
}
/**
* 显示文章状态状态
*
* @param 整型 $flag
* @return 状态字符串
*/
public static function printFlag ( $flag = 0 ){
switch ( $flag ){
case 0:
return "<Font color=\"#FF0000\">未存 未发</Font>";
case 1:
return "<Font color=\"#009900\">已存</Font> <Font color=\"#FF0000\">未发</Font>";
case 2:
return "<Font color=\"#009900\">已存 已发</Font>";
default:
return "未知状态";
}
}
/**
* 显示HTML生成状态
*
* @param 整型 $flag
* @return 状态字符串
*/
public static function printHtmlFlag ( $flag= 0 ){
switch ( $flag ){
case 0:
return "<Font color=\"#FF0000\">未生</Font>";
case 1:
return "<Font color=\"#009900\">已生</Font>";
default:
return "未知状态";
}
}
/**
* 显示视频状态
*
* @param 整型 $flag
* @return 状态字符串
*/
public static function printVideoFlag ( $flag= 0 ){
switch ( $flag ){
case 1:
return '<Font color="red"><b>视</b></Font>';
default:
return '';
}
}
/**
* 显示审核状态
*
* @param 整型 $flag
* @return 状态字符串
*/
public static function printIssueFlag ( $flag = 0 ){
switch ( $flag ){
case 1:
return "<Font color=\"#FF0000\">未审</Font>";
case 2:
return "<Font color=\"#009900\">已审</Font>";
default:
return "未知状态";
}
}
/**
* 返回是否可以创建文件夹
*
* @param $dir 文件夹名
* @param $cateid 栏目编号
*/
public static function canCreateDir($dir, $cateid){
$can=true;
//文件夹为空, 肯定不能添加的
if ($dir==''){
$can=false;
}
//系统定义不能创建的目录
if (strpos(CANTDIR, '|'. $dir . '|')){
$can=false;
}
//文章系统文件夹文件夹分类中是否已存在该文件夹
//-------------------0
$SqlStr = 'SELECT `dir` FROM `'.DB_TABLE_PRE . 'article_cate`' ;
$SqlStr.= ' WHERE `dir`=\'' . $dir . '\'';
$SqlStr.= ' AND `id`<>\'' . $cateid . '\'';
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) $can=false;
//返回值
return($can);
}
/**
* 通过栏目编号, 获取栏目预览地址
* @param $cateid
*/
public static function getCatePreviewUrl($cateid){
$template_url ='';
$SqlStr = ' SELECT `template_url`';
$SqlStr.= ' FROM `'.DB_TABLE_PRE.'view_articlecate` ';
$SqlStr.= ' WHERE `id`='.$cateid;
$SqlStr.= ' LIMIT 1';
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()){
$template_url = $MyDatabase->ResultArr [0][0];
}
return($template_url);
}
/**
* 通过文章编号, 获取文章预览地址
* @param $cateid
*/
public static function getPreviewUrl($id){
$template_url ='';
$SqlStr = ' SELECT `template_url`';
$SqlStr.= ' FROM `'.DB_TABLE_PRE.'view_articlelist` ';
$SqlStr.= ' WHERE `id`='.$id;
$SqlStr.= ' LIMIT 1;';
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()){
$template_url = $MyDatabase->ResultArr [0][0];
}
return($template_url);
}
/**
* 更新HTML文件名
* @param $id 所属id,没有默认值,必须指定
* @param $posttime 提交时间,默认值为当前
*
* @return 更新后的地址
*/
function UpdateHTML($id, $posttime=''){
//如果没有日期,则获取当前时间
if ($posttime==''){
$posttime=time();
}else{
$posttime=strtotime($posttime);
}
$ArticlePath = date("ym",$posttime) . 'https://www.jb51.net/'. date("d",$posttime);
if (createFolder(ARTICLEPATH, $ArticlePath)){
$html = ARTICLEURL . $ArticlePath . 'https://www.jb51.net/' . date( "His", time() ) . rand( 1000, 9999 ) . '.html';
$MyDatabase=Database::Get();
$ArrField=array('html');
$ArrValue=array($html);
$MyDatabase->Update('article', $ArrField, $ArrValue, '`id`='.$id);
return($html);
}
}
/**
* 生成HTML文件
* @param $id
*/
function HTML($id){
}
/**
* 获取栏目名
*
* @param $id 文章栏目编号
*/
function getCate($cateid){
$level = $this->getLevelById($cateid);
$level_len= strlen($level) / 2 ;
//level列表
$level_str='0';
for ($i=1;$i<=$level_len;$i++){
$level_str.= ','.substr($level,0, 2*$i);
}
$navbar = '<a href="'. SITE_URL .'">首 页</a> >';
$SqlStr = ' SELECT * ';
$SqlStr.= ' FROM `'. DB_TABLE_PRE . 'article_cate`';
$SqlStr.= ' WHERE `level` in ('.$level_str.')';
$SqlStr.= ' ORDER BY `level` ASC';
$MyDatabase=Database::Get();
$MyDatabase->SqlStr = $SqlStr;
if ($MyDatabase->Query ()) {
$DB_Record_Arr = $MyDatabase->ResultArr;
foreach ( $DB_Record_Arr as $DB_Record ) {
$html = $DB_Record['id'];
if ($DB_Record['url']!='') $html=$DB_Record['url'];
$navbar.=' <a href="' . SITE_URL . SITE_FOLDER . CATEURL . $html .'/index.html">'. $DB_Record['title'] .'</a> >';
}
}
return $navbar;
}
}
?>
数据库
复制代码 代码如下: