自己写的MonolithCMS上面用到的文章类,可能不是很
来源:自学PHP网
时间:2014-09-18 13:09 作者:
阅读:次
[导读] 自己写的MonolithCMS上面用到的文章类,可能不是很通用, 但是胜在我有全部的注释...
调用方法如下:
复制代码 代码如下: $Template= '<li class="xxx">[<a href="{catedir}">{catetitle}</a>]<a href="{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 class="xxx"><a href="{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="{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 class="xxx"><a href="{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('/{tit
|
|