个人不成熟作品全静态站点引思

php代码:
<?/************** 
  静态页面生成类 
  作者:逛悠~ 
  时间:2005-8-11 
  功能:根据页面生成时间 
  更新和生成新的html页面 
  **************/ 
  class htmlProduct { 
      public $title;  //标题; 
      public $id;     //id号 
      public $keywords = 'PHP,ASP,JSP,web,w3c,W3C,WEB,java'; 
      public $buttons =array('home' =>'home.php', 
                             'code_share' =>'code_share.php', 
                             'download' =>'download.php', 
                             'communicate' =>'communicate.php' 
                            ); 
      public $result; 
      public $content; 

      function __construct($title='',$id='',$content='') 
      { 
          $this->reuslt=''; 
          $this->id=$id; 
          $this->content=$content; 
           
      } 
      function create_html_page() 
      {   //update $id.html 's contents if its lastmodified time more than 3 days! 
          if(file_exists("article/$this->id.html")&&(time()-filemtime("article/$this->id.html"))>25600) 
              { 
                  $fp=fopen("article/$this->id.html","w"); 
                  fputs($fp,$this->Display()); 
                  fclose($fp); 
              } 
          elseif(!file_exists("article/$this->id.html")) 
              { 
                  $fp=fopen("article/$this->id.html","w"); 
                  fputs($fp,$this->Display()); 
                  fclose($fp); 
              } 
               
              return  realpath("article/$this->id.html"); 
      } 
      function create_index_page() { 
        if(file_exists("article/index$this->id.html")&&(time()-filemtime("article/index$this->id.html"))>25600) 
              { 
                  $fp=fopen("article/index$this->id.html","w"); 
                  fputs($fp,$this->Display()); 
                  fclose($fp); 
              } 
          elseif(!file_exists("article/index$this->id.html")) 
              { 
                  $fp=fopen("article/index$this->id.html","w"); 
                  fputs($fp,$this->Display()); 
                  fclose($fp); 
              } 
               
              return  realpath("article/index$this->id.html"); 
      } 
      // class Page's operations 
      public function __set($name,$value) 
      { 
          $this->$name=$value; 
      } 
     
      // product html page! 
      public function Display() 
      { 
          $str.= "<html>\r\n<head>\r\n"; 
          $str.= $this->DisplayTitle(); 
          $str.= $this->DisplayKeywords(); 
          $str.= $this->DisplayStyles(); 
          $str.= "</head>\r\n<body>\r\n"; 
          $str.= $this->DisplayHeader(); 
          $str.= $this->DisplayMenu($this->buttons); 
          $str.="<div width='100%' style='background:#eeeeee;border: 
          1px gray solid;height:500;padding:30px;font-size:9pt'>"; 
          $str.= nl2br($this->content); 
          $str.="</div>"; 
          $str.=$this->DisplayFooter(); 
          $str.="</body>\r\n</html>\r\n"; 
          return $str; 
           
      } 
      public function DisplayTitle() 
      { 
          return  "<title>$this->title</title>"; 
      } 
      public function DisplayKeywords() 
      { 
          return "<meta name=\"keywords\" content=\"".htmlentities($this->keywords)."\" />"; 
      } 
      public function DisplayStyles() 
      { 
           
          $str.='<style>'; 
          $str.='<!--'; 
          $str.='h1{color:white;font-size:24pt;text-align:center;font-family:arial,sans-serif}'; 
          $str.='.menu{color:white;font-size:12pt;text-align:center;font-family:arial,sans-serif;font-weight:bold}'; 
          $str.='td{background:gray}'; 
          $str.='p{color:black;font-size:12pt;text-align:justify;font-family:arial,sans-serif}'; 
          $str.='p.foot{color:white;font-size:9pt;text-align:center;font-family:arial,sans-serif;font-weight:bold}'; 
          $str.='a:link,a:visited,a:active{color:white}'; 
          $str.='-->'; 
          $str.='</style>'; 
         
          return $str; 
     
      } 

      public function DisplayHeader() 
      { 
           
          $str='<table width ="100%" cellpadding ="12" cellspacing ="0" border ="0">'; 
          $str.='<tr bgcolor="black">'; 
          $str.='<td align="left"><img src="images/logo.gif" /></td>'; 
          $str.='<td>'; 
          $str.='<h1>Test Complete Html Create!</h1>'; 
          $str.='</td>'; 
          $str.='<td align ="right"><img src ="images/logo.gif" /></td>'; 
          $str.='</tr>'; 
          $str.='</table>'; 

          return $str; 
     

      } 
      public function DisplayMenu($buttons) 
      { 
          $str="<table width='100%' bgcolor='white' cellpadding='4' cellspacing='4'>\r\n"; 
          $str.="<tr>\r\n"; 

          //calculate button size 
          $width =100/count($buttons); 
          foreach($buttons as $name=>$url) 
          { 
              $str.=$this->DisplayButton($width,$name,$url,!$this->IsURLCurrentPage($url)); 
          } 
          $str.= "</tr>\r\n"; 
          $str.="</table>\r\n"; 
          return $str; 
      } 
      public function IsUrlCurrentPage($url) 
      { 
          if(strpos($_SERVER['PHP_SELF'],$url)==false) 
          { 
              return false; 
          } 
          else 
          { 
              return true; 
          } 
      } 
      public function DisplayButton($width,$name,$url,$active =true) 
      { 
          if($active) 
          { 
              $str="<td width ='".htmlentities($width)."%'> 
              <a href='".htmlentities($url)."'> 
              <img src='images/s_logo.gif' alt='".htmlentities($name)."'border='0' /></a> 
              <a href='".htmlentities($url)."'><span class='menui'>$name</span></a></td>"; 
          } 
          else 
          { 
              $str.= "<td width='".htmlentities($width)."%'><img src='images/side_logo.gif'> 
              <span class='menu'>$name</span></td>"; 
          } 
          return $str; 
      } 
      public function DisplayFooter() 
      { 
           
          $str='<table width="100%" bgcolor="black" cellpadding="12" border="0">'; 
          $str.='<tr>'; 
          $str.='<td>'; 
          $str.='<p class="foot">©Test Complete Html Create.</p>'; 
          $str.='<p class="foot">Please see my <a href=\'legal.php\'>legal information page</a></p>'; 
          $str.='</td>'; 
          $str.='</tr>'; 
          $str.='</table>'; 
         
          return $str; 
               
      } 
  } 
  ?> 

//生成页面(包含分页)
<?php 
/* 
目前手上没有5.0的mysql,用的是appserv,所以使用的面向过程的连接办法 
汗~ 
*/ 
require ('htmlProduct.php'); 
$html= new htmlProduct(); 
$db=mysql_connect('localhost','yoyibf','haoying'); 
$select=mysql_select_db('phpstudy'); 
$result=mysql_query("select article_id,article_title,article_intro from arti_auth "); 
$num=mysql_num_rows($result); 


//生成文章列和单项内容页面 
while($row =mysql_fetch_array($result)) 
{ 
    $html->id=$row['article_id']; 
    $html->content=$row['article_intro']; 
    $html->title=$row['article_title']; 
    //create html page! 
    $arr[]=array("url"=>$html->create_html_page(), 
                 "modifiled"=>filemtime($html->create_html_page()), 
                 "create_stauts"=>"ture" 
                 ); 
    $list_arr[]=array('id'=>$row['article_id'], 
                 'title'=>$row['article_title'] 
                 ); 
     
} 
//生成主题列表页一 
for($j=0,$i=0;$j<ceil($num/5);$j++) { 
    //分页连接 
    $str='<pre><p>Article list for://目前一共有'.$num.'条记录,['.($j+1).'/'.ceil($num/5).'],进入第<select οnchange=\'javascript:location.href=this.options[this.selectedIndex].value\'>'; 
    for($m=0;$m<ceil($num/5);$m++) 
    { 
        $str.='<option value=\'/article/index'.($m+1).'.html\''; 
        $str.=($m==$j)?" selected>":">"; 
        $str.=($m+1).'</a></option>'; 
    } 
    $str.='</select>页<hr>'; 
    for($i=$j*5;$i<$j*5+5&&$i<$num;$i++)    
        $str.='<a style="text-decoration:none;color:#000000" href=\'/article/'.($i+1).'.html\'>['.($i+1).']'.$list_arr[$i]['title'].'</a><br />'; 
//生成主题列表页面 
$html->id=($j+1); 
$html->content=$str; 
$html->title='主题页'; 
$html->create_index_page(); 
//===============================index.$j.html 
echo "<pre>"; 
echo $str; 
echo "<hr>"; 
} 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值