基于php的CMS中展示文章类实例分析

这篇文章主要介绍了基于php的CMS中展示文章类,涉及针对文章的各种常用设置与操作技巧,需要的朋友可以参考下,本文实例讲述了基于php的CMS中展示文章类,分享给大家供大家参考,具体分析如下:

  1. <?php
  2. /***********************************************
  3. //实例:
  4. include("config.inc.php"); //数据库连接文件
  5. $info = new sys_function;
  6. $test = new show_article;
  7. $test->set_sql("SELECT `id`,`title`,`dateandtime`,`thetype` FROM `df_company_bringup` ORDER BY `dateandtime` DESC");
  8. $test->set_filename("display");
  9. $test->set_morename("morearticle");
  10. $test->set_icon(" ☆ ");
  11. $test->set_omitstr("...");
  12. $test->show_company_bringup();
  13. ***********************************************/
  14. /****Article List Class****/
  15. class show_article
  16. {
  17. /****声明****/
  18. var $sql,$query,$arr,$article_list;
  19. var $strlen,$articleline,$dateandtime;
  20. var $len,$line,$icon,$omitstr,$line_height,$more_name;
  21. var $year,$month,$day,$datetype;
  22. var $showmore,$showdate,$showomit,$showclueon,$showicon;
  23. /****构造函数****/
  24. function show_article()
  25. {
  26. $this->set_strlen(40); //设置每行显示字数;
  27. $this->set_articleline(10); //设置Article显示行数;
  28. $this->set_showmore(false); //是否显示"更多Article";
  29. $this->set_showdate(true); //是否显示Article发布日期;
  30. $this->set_showomit(true); //字数超过指定字符后是否显示所设置的字符,如"...";
  31. $this->set_showclueon(true); //是否显示Article提示(鼠标移动到Article标题上面显示的提示);
  32. $this->set_open(true); //是否在新窗口打开;
  33. $this->set_showicon(true); //是否显示Article修改前缀;
  34. $this->set_lineheight(1.5); //段落行高值;
  35. $this->set_datetype(1); //设置日期格式,1为2004-10-21 2为2004年10月21日;
  36. }
  37. /****设置每行显示字数****/
  38. function set_strlen($strlen)
  39. {
  40. $this->len = $strlen;
  41. }
  42. /****设置Article显示行数****/
  43. function set_articleline($articleline)
  44. {
  45. $this->line = $articleline;
  46. }
  47. /****设置查询语句****/
  48. function set_sql($sql)
  49. {
  50. $this->sql = $sql;
  51. }
  52. /****设置Article标题前缀修饰****/
  53. function set_icon($icon)
  54. {
  55. $this->icon = $icon;
  56. }
  57. /****是否显示Article标题前缀修饰****/
  58. function set_showicon($showicon)
  59. {
  60. $this->showicon = $showicon;
  61. }
  62. /****是否打开新窗口****/
  63. function set_open($open)
  64. {
  65. $this->open = $open;
  66. }
  67. /****设置Article标题长度超过限制后显示的字符****/
  68. function set_omitstr($omitstr)
  69. {
  70. $this->omitstr = $omitstr;
  71. }
  72. /****设置打开Article的文件名****/
  73. function set_filename($filename)
  74. {
  75. $this->filename = $filename;
  76. }
  77. /****更多Article页面名称****/
  78. function set_morename($more_name)
  79. {
  80. $this->more_name = $more_name;
  81. }
  82. /****Article分类名称****/
  83. function set_typename($type_name)
  84. {
  85. $this->type_name = $type_name;
  86. }
  87. /****是否显示更多Article****/
  88. function set_showmore($showmore)
  89. {
  90. $this->showmore = $showmore;
  91. }
  92. /****设置日期格式(1:2004-10-21 2:2004年10月21日)****/
  93. function set_datetype($datetype)
  94. {
  95. $this->datetype = $datetype;
  96. }
  97. /****格式化日期****/
  98. function formatdate($dateandtime,$num)
  99. {
  100. list($year,$month,$day) = split("[-]",substr($dateandtime,0,10));
  101. if($num == 1){
  102. return $year."-".$month."-".$day;
  103. }else{
  104. return $year."年".$month."月".$day."日";
  105. }
  106. }
  107. /****是否显示Article发布日期****/
  108. function set_showdate($showdate)
  109. {
  110. $this->showdate = $showdate;
  111. }
  112. /****段落行高值****/
  113. function set_lineheight($line_height)
  114. {
  115. $this->line_height = $line_height;
  116. }
  117. /****是否显示Article标题长度超过限制后显示的字符****/
  118. function set_showomit($showomit)
  119. {
  120. $this->showomit = $showomit;
  121. }
  122. /****是否显示鼠标移动到Article上后显示的提示****/
  123. function set_showclueon($showclueon)
  124. {
  125. $this->showclueon = $showclueon;
  126. }
  127. /****从结果集中取得一行作为枚举数组****/
  128. function execute_row($query)
  129. {
  130. return $this->arr = mysql_fetch_row($query);
  131. }
  132. /****从结果集中取得一行作为关联数组,或数字数组,或二者兼有****/
  133. function execute_array($query)
  134. {
  135. return $this->arr = mysql_fetch_array($query);
  136. }
  137. /****将释放所有与结果标识符 result 所关联的内存****/
  138. function free_record($query)
  139. {
  140. @mysql_free_result($query);
  141. }
  142. /****调用指定Article List****/
  143. function show_company_bringup()
  144. {
  145. $n = 1;
  146. $article_list = "<div .$n."' .$this->line_height."'>";
  147. $this->query = mysql_query($this->sql);
  148. while($this->execute_row($this->query))
  149. {
  150. if($this->showicon){$article_list .= $this->icon;}
  151. $article_list .= "<a href='".$this->filename.".php?'";
  152. if($this->showclueon){$article_list .= " title='".$this->arr[1]."' ";}
  153. if($this->open){$article_list .= " target='_blank' ";}
  154. $article_list .= ">";
  155. if(strlen($this->arr[1]) > $this->len)
  156. {
  157. if($this->showomit){
  158. $article_list .= substr($this->arr[1],0,$this->len).$this->omitstr;
  159. }else{
  160. $article_list .= substr($this->arr[1],0,$this->len);
  161. }
  162. }else{
  163. $article_list .= $this->arr[1];
  164. }
  165. if($this->showdate){$article_list .= "[".$this->formatdate($this->arr[2],$this->datetype)."]";}
  166. $article_list .= "</a><br>\n";
  167. if($n == $this->line){break;}
  168. $n++;
  169. }
  170. if($this->showmore){
  171. $article_list .= "</div><div .$n."' align='right'><a href='".$this->more_name.".php?type=".$this->type_name."'>>> >更多</a></div>";
  172. }else{
  173. $article_list .= "</div>";
  174. }
  175. $this->free_record($this->query);
  176. print $article_list;
  177. }
  178. }
  179. ?>