歡迎光臨, 訪客. 請先 登入註冊一個帳號.
三月 28, 2024, 03:37:23 下午
19595 文章 在 3865 主題 由 4580 會員
最新註冊會員: aa123aa1
LifeType 中文開發論壇  |  開發  |  外掛程式  |  外掛程式精華區  |  非外掛程式 -- pLog 內容輸出成為 HTML (一) « 上篇主題 下篇主題 »
頁: [1]
作者 主題: 非外掛程式 -- pLog 內容輸出成為 HTML (一)  (閱讀 33274 次)
WhiteCloud
初級會員
**
文章: 51


檢視個人資料 個人網站
« 於: 九月 09, 2005, 08:36:35 下午 »

看到 番薯藤 的 樂多網誌 速度飛快,原來也是使用靜態的 HTML 方式來呈現網誌內容。於是我決定把全站內容備份稍做改版,也做出靜態 HTML 格式的索引檔和內容檔。

我自己的輸出測試結果網址如下:http://sky-heart.com/plog/html/

輸出程式使用方法:

※ 將索引檔程式存成 plog_index.php,內容檔程式存成 plog_c.php,放在 pLog 安裝路徑下。

※ 在 pLog 安裝路徑下另外建立一個新目錄 html,權限設定為 755

※ 執行 plog_index.php, plog_c.php

※ 在瀏覽器上看結果,輸入你的網址後面加上/html/,例如:http://www.(你的網址名).com/plog/html/

索引檔程式如下(內容例如網誌名稱,編號等等請自行修改):

※ 2005.10.02 有做小修正,說明請看回覆文章
http://forum.lifetype.org.tw/index.php?topic=1124.from1128256464;topicseen#msg7135

※ 2006.03.30 有網友到我的部落格指正錯誤並給予建議,因此做了修正,感謝 sam 網友。
-------------------------------------------------------------------------

程式碼:
<?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."html/";
// 輸出檔名
$strOutput "index.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 ";
$sql $sql."where $strTableArticleText.article_id = $strTableArticle.id ";
$sql $sql."and $strTableArticle.blog_id = $strBlogNumber ";
$sql $sql."and $strTableArticle.status = 1 ";
$sql $sql."order by article_id desc";

    
$articles = new Articles();
    
$result $articles->getBlogArticlesByQuery$sql );   

foreach( 
$result as $article ) {

$strId $article->getId();

$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="0"><tr><td>';
// $strFileContent = $strFileContent.$strArticleID;
// $strFileContent = $strFileContent."<br>";

// 2006.03.30 更新這行
$strFileContent $strFileContent.'<a href=';

$strFileContent $strFileContent.$strId.".html>";
$strFileContent $strFileContent.'<font size=5><b>';
$strFileContent $strFileContent.$strTopic;
$strFileContent $strFileContent.'</b></font></a>';
$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>";

}

//2006.03.30 更新兩行
$strFileContent $strFileContent."All content copyright (c) 2004 $strBlogName";
$strFileContent $strFileContent."</center></body></html>";

// 輸出成為 HTML
//echo $strFileContent;
$fp fopen($strArticleIndexPath.$strOutput"w");
fputs($fp$strFileContent);
fclose($fp);

header("Location: /plog/html/$strOutput");
//echo "OK";
?>
« 最後編輯時間: 三月 30, 2006, 12:19:14 上午 由 WhiteCloud » 已記錄
WhiteCloud
初級會員
**
文章: 51


檢視個人資料 個人網站
« 回覆文章 #1 於: 十月 02, 2005, 07:34:24 下午 »

pLog 內容輸出成為 HTML → 小修正說明

本次修正:

檔名仍然不變,索引檔程式為 plog_index.php,內容檔程式為 plog_c.php

1. 索引檔程式和內容檔程式都加上判斷,已經刪除的文章不要輸出。

2. 內容檔程式可以指定參數,這個參數的作用可以讓內容檔程式只有輸出大於指定編號的內容文章。這樣讓程式運作起來更有效率,因為以前輸出過的文章不用重複再輸出一次。

3. 內容檔程式輸出後直接轉去執行索引檔程式,不用分開兩次做。

※ 請先參考之前的文章

※ plog_index.php,plog_index_c.php 放在 /plog 安裝目錄下

※ 使用方法:假如 pLog 網站在 http://www.xyzxyzxyz.com/plog/

例如: http://www.xyzxyzxyz.com/plog/plog_c.php?NUM=20

執行後,會輸出編號大於 20 的全部文章
已記錄
kingxl
新手見習
*
文章: 6


檢視個人資料
« 回覆文章 #2 於: 二月 10, 2006, 08:55:26 上午 »

多用户如何使用?如何让其他用户使用分别生成到各自的目录?
已記錄

我的Plog
blog.Yj163.com
WhiteCloud
初級會員
**
文章: 51


檢視個人資料 個人網站
« 回覆文章 #3 於: 三月 30, 2006, 12:24:52 上午 »

本程式的架構目前並不適合多用戶,比較適合自己架站的人備份成為靜態 HTML。

要改很多地方才適合多人使用。
已記錄
maomaode
一般會員
***
文章: 115


檢視個人資料
« 回覆文章 #4 於: 四月 19, 2006, 11:33:59 下午 »

什么时候做成plugin?  眨眼睛
已記錄

我的blog:
               http://maomaode.bokeland.com
Blog搬家/同步
               http://banjia.bokeland.com
WhiteCloud
初級會員
**
文章: 51


檢視個人資料 個人網站
« 回覆文章 #5 於: 四月 20, 2006, 01:50:24 下午 »

因為興趣和時間的規劃上,還沒研究如何寫成 plug-in,這得對 LifeType  架構和 API 多了解才行。有興趣者不妨研究看看,再分享給大家。:-)

而且這個程式並沒有套用到漂亮的版面,實用性還可以再加強。有心要做的人似乎可考慮讓使用者可以選擇套用 template 再做輸出。

我當初寫這個其實只為了自己備份之用,將小小程式回饋給社群而已。 微笑
已記錄
maomaode
一般會員
***
文章: 115


檢視個人資料
« 回覆文章 #6 於: 四月 23, 2006, 10:48:41 下午 »

做成plugin并不是很困难。

困难的是将链接方式全部变为静态html的方式。
记得typepad好像是有这个功能,

如果有一天lifepad也能这样就爽了, 速度肯定会快很多。

已記錄

我的blog:
               http://maomaode.bokeland.com
Blog搬家/同步
               http://banjia.bokeland.com
markwu
系統管理員
超級會員
*****
文章: 3928


Mark Wu


檢視個人資料 個人網站
« 回覆文章 #7 於: 四月 23, 2006, 11:42:11 下午 »

如果你有看過  http://blog.markplace.net/marks_place/archives/2006/01/

你應該知道 1.1 已經接近靜態頁面了!

基本上在 1.1 cahce 了:
1. Smarty compiled code
2. View cache
3. DB cache

所以甚至連 DB 暫時斷線,資料都還是可以讀出來。

Mark
已記錄

maomaode
一般會員
***
文章: 115


檢視個人資料
« 回覆文章 #8 於: 五月 06, 2006, 09:57:27 下午 »

Hi Mark,

事实上我是在收到你的邮件后才知道1.1里面已经包括了
引用
基本上在 1.1 cahce 了:
1. Smarty compiled code
2. View cache
3. DB cache

不过我还是有以下几点疑问:
1. 三层Cache是否共享一个Expiration date?
2. 如果Cache 过期, 三层Cache是否全部要重新生产?
3. 事实上按照原先的Cache机制, 如果某一篇文章更新, 整个用户目录下的cache会全部被清空,
而如果我们能有机制, 生产HTML的话, 可以不用全部清空用户cache. 而只生产局部HTML, 而且这种连接方式是完全不需要PHP程序或者数据库读取了

这是我个人的一些想法, 不是很成熟, 请次教.
thx.
P.S 我有回复你的邮件哦, 不知道收到没有 眨眼睛
已記錄

我的blog:
               http://maomaode.bokeland.com
Blog搬家/同步
               http://banjia.bokeland.com
頁: [1]
LifeType 中文開發論壇  |  開發  |  外掛程式  |  外掛程式精華區  |  非外掛程式 -- pLog 內容輸出成為 HTML (一) « 上篇主題 下篇主題 »
    前往: