感謝 Mark 提供的資料,我使用 pLog 內建的物件來重寫備份程式。
程式變動:
改成呼叫 pLog 的 Article 類別物件
可設定網誌編號來備份不同 blog
取消顯示作者名
------------------------------------------------------------------------
<?php
if (!defined( "PLOG_CLASS_PATH" )) {
define( "PLOG_CLASS_PATH", dirname(__FILE__)."/");
}
include_once( PLOG_CLASS_PATH."config/config.properties.php" );
include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
// plog 的資料表字首
$strPlogPrefix = $config["db_prefix"];
// 輸出路徑,最後面要加斜線(目錄要設定為可讀寫,例如777)
$strArticleIndexPath = PLOG_CLASS_PATH;
// 輸出備份檔名
$strOutput = "article.htm";
// 網誌名稱
$strBlogName = "White Cloud's Blog";
// 網誌編號
$strBlogNumber = "1";
// 放文章的變數
$strFileContent = <<<EOT
<html xmlns="
http://www.w3.org/1999/xhtml" xml:lang="zh_TW" lang="zh_TW" dir="ltr">
<head>
<title>$strBlogName</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
<body><center>
<font size=6 color=green>$strBlogName </font>
<br>這是備份頁面,歡迎存檔慢慢欣賞 :-)<br><br>
EOT;
// $query = "SELECT * FROM plog_articles As a, plog_articles_text As at WHERE a.id=at.article_id AND a.blog_id = 1 ORDER BY a.date DESC";
$strTableArticleText = $strPlogPrefix."articles_text";
$strTableArticle = $strPlogPrefix."articles";
$strTableUsers = $strPlogPrefix."users";
$sql = "select * from $strTableArticleText,$strTableArticle where $strTableArticleText.article_id = $strTableArticle.id and $strTableArticle.blog_id = $strBlogNumber order by article_id desc";
$articles = new Articles();
$result = $articles->getBlogArticlesByQuery( $sql );
foreach( $result as $article ) {
$strTopic = $article->getTopic();
$strText = $article->getText();
//$strAuthor = $article->getUser();
$strDate = $article->getDate();
// 由於改用 MySQL 4.1 的關係,取消此行
//$strDate = substr($strDate,0,4)."/".substr($strDate,4,2)."/".substr($strDate,6,2)." ".substr($strDate,8,2).":".substr($strDate,10,2).":".substr($strDate,12,2);
$strFileContent = $strFileContent.'<table width="80%" border="1"><tr><td>';
// $strFileContent = $strFileContent.$strArticleID;
// $strFileContent = $strFileContent."<br>";
$strFileContent = $strFileContent.'<font size=5><b>';
$strFileContent = $strFileContent.$strTopic;
$strFileContent = $strFileContent.'</b></font>';
$strFileContent = $strFileContent."<br>";
//$strFileContent = $strFileContent.$strAuthor;
//$strFileContent = $strFileContent." ";
$strFileContent = $strFileContent.$strDate;
$strFileContent = $strFileContent."<br><br>";
$strFileContent = $strFileContent.$strText;
$strFileContent = $strFileContent."<br><br>";
$strFileContent = $strFileContent."<td><tr><table><br><br>";
}
$strFileContent = $strFileContent = $strFileContent."All content copyright (c) 2004 $strBlogName";
$strFileContent = $strFileContent = $strFileContent."</center></body></html>";
// 輸出成為 HTML
//echo $strFileContent;
$fp = fopen($strArticleIndexPath.$strOutput, "w");
fputs($fp, $strFileContent);
fclose($fp);
header("Location: $strOutput");
//echo "OK";
?>