LifeType 中文開發論壇

開發 => 外掛程式 => 主題作者是: andywang 於 三月 10, 2005, 04:26:59 下午



主題: 如何对summary.php展示页面进行改版?
作者: andywang三月 10, 2005, 04:26:59 下午
我現在的需求是當使用0.32的時候,我們看到summary.php載入的頁面形式如下:
(http://218.247.163.55:7080/ch11/summary1.jpg)

图-1

這個不符合我們的要求,我想將它轉換成如下格式:


(http://218.247.163.55:7080/ch11/summary.jpg)

图-2

也就是圖-2中的類別 標題 作者 時間 人氣/回復 來源 等資訊來源我想用程式來實現,可是我對plog這個系統採用的mvc不瞭解,相互之間的調用非常複雜,看起來很費事,我想請教一下您,就是我做成圖-2,怎麼實現?如果您方便請給我一個例子,當然用1.0也會用到這個問題的


主題: 如何对summary.php展示页面进行改版?
作者: markwu三月 10, 2005, 10:27:04 下午
在 pLog 的世界中,要改變網頁的編排並非直接修改程式,而是要修改模版  (template)。以彙整網頁的例子來看,並不需要直接修改程式,而是要修改 summary.template

修改 /plog/templates/summary/summary.template

程式碼:

{include file="summary/header.template"}
 {foreach from=$posts item=post}
   <h3>{$post->getTopic()}</h3>
{assign var="postDate" value=$post->getDateObject()}
{assign var="postOwner" value=$post->getUserInfo()}
<span class="date">{$postOwner->getUsername()} | {$locale->formatDate($postDate,"%d %B, %Y %H:%M")}</span>
<p>
 {$post->getText()}
</p>
<div class="footer">
{assign var="postCategory" value=$post->getCategory()}
{assign var="blogId" value=$post->getBlog()}
<!--
 I don't think we need so many links in the summary...
 but please feel free to change things here :)
-->

<a href="{$url->blogLink($blogId)}">{$blogs[$blogId]->getBlog()}</a> ::
<!--<a href="{$url->postPermalink($blogId, $post)}">{$postCategory->getName()}</a> ::-->
<a href="{$url->postPermalink($blogId, $post)}">{$locale->tr("comment on this")} ({$post->getTotalComments()})</a> ::
<a title="{$locale->tr("permalink_title")}" href="{$url->postPermalink($blogId, $post)}">{$locale->tr("permalink")}</a> <!--::
<a href="{$url->postTrackbackStatsLink($blogId, $post)}">{$locale->tr("trackbacks")} ({$post->getNumTrackbacks()})</a>-->
</div>

  {/foreach}
{include file="summary/footer.template"}


變為

程式碼:

{include file="summary/header.template"}
<table>
<tr>
<td>Category</td>
<td>Topic</td>
<td>Author</td>
<td>Time</td>
<td>Comments</td>
</tr>
 {foreach from=$posts item=post}
<tr>
{assign var="postDate" value=$post->getDateObject()}
{assign var="postOwner" value=$post->getUserInfo()}
{assign var="postCategory" value=$post->getCategory()}
{assign var="blogId" value=$post->getBlog()}
<td>{$postCategory->getName()}</td>
<td><a href="{$url->postPermalink($blogId, $post)}">{$post->getTopic()}</a></td>
<td>{$postOwner->getUsername()}</td>
<td>{$locale->formatDate($postDate,"%d %B, %Y %H:%M")}</td>
<td>{$post->getTotalComments()}</td>
</tr>
  {/foreach}
</table>
{include file="summary/footer.template"}


就可以達到你想要的類似效果。pLog 是採用 smarty 模版引擎。你可以參考 http://smarty.php.net 來更瞭解 smarty。或是參考 http://wiki.lifetype.net/index.php/PLog_1.0/Templates 來瞭解模版如何運作。

Mark


主題: 如何对summary.php展示页面进行改版?
作者: andywang三月 10, 2005, 10:43:14 下午
那如果我再加入别的检索条件怎么办,不一定在您程序里涉及了,我怎么加入它?

您最好能否拿我的需求做一个独立的例子,以后怎么改我也就知道了,我的意思是不用考虑summary.php及其模板的影响,我如果就只是为了显示这部分如图-2数据格式,我该如何实现?


主題: 如何对summary.php展示页面进行改版?
作者: andywang三月 10, 2005, 10:51:15 下午
希望您抽空能单独做个我需求所示模板及其程序的例子,我以后就知道怎么使用它了,这样您为我实现了,可是我还是看不明白,因为我不知道程序和模板是如何实现的,谢谢


主題: 如何对summary.php展示页面进行改版?
作者: andywang三月 11, 2005, 10:28:00 上午
按照上面代码做了,可是还是不能实现,我也清除了tmp下的catche了


主題: 如何对summary.php展示页面进行改版?
作者: markwu三月 11, 2005, 11:03:59 上午
我改錯檔了!我竟然改到 0.32 的檔案。晚一點在放上正確範例。

mark


主題: 如何对summary.php展示页面进行改版?
作者: markwu三月 11, 2005, 01:27:02 下午
我真是『小白』阿!

你把 templates/summary/recent.template 改為

程式碼:
<h4>{$locale->tr("summary_latest_posts")}
<a href="{$url->getRssUrl()}?summary=1"><img src="{$url->getUrl("/imgs/rss_logo_small.gif")}" alt="RSS" /></a>
</h4>
<table>
<tr>

<td>Topic</td>
<td>Author</td>
<td>Time</td>
<td>Comments</td>
</tr>
 {foreach from=$posts item=post}
 {include file="summary/post.template"}
  {/foreach}
</table>


把 templates/summary/post 改為

程式碼:
<tr> 
{assign var="postDate" value=$post->getDateObject()}
{assign var="postOwner" value=$post->getUserInfo()}
{assign var="postCategories" value=$post->getCategories()}
{assign var="blog" value=$post->getBlogInfo()}
{assign var="request" value=$blog->getBlogRequestGenerator()}
<td><a href="{$request->postPermalink($post)}">{$post->getTopic()}</a></td>
<td>{$postOwner->getUsername()}</td>
<td>{$locale->formatDate($postDate,"%d %B, %Y %H:%M")}</td>
<td>{$post->getTotalComments()}</td>
</tr>


應該就可以了! summary.template 已經不用了。  :-( 我竟然改到他..... 真是豬頭。

Mark


主題: 如何对summary.php展示页面进行改版?
作者: andywang三月 11, 2005, 07:02:39 下午
不好意思,我还要获得 文章分类 的这一列,我如何获得呢?我试图用
$category->getName()没有获得成功?不知道如何调用?


主題: 如何对summary.php展示页面进行改版?
作者: andywang三月 11, 2005, 07:51:41 下午
问题我解决了,我是通过加入/templates/summary/post.template如下代码实现的
{assign var="postCategory" value=$post->getCategory()}
<td>{$postCategory->getName()}</td>


现在有新的问题,就是为什么我每次只能显示一条记录?我想全部显示并且实现分页功能?怎么办?


主題: 如何对summary.php展示页面进行改版?
作者: markwu三月 13, 2005, 10:12:55 上午
引用自: andywang
问题我解决了,我是通过加入/templates/summary/post.template如下代码实现的
{assign var="postCategory" value=$post->getCategory()}
<td>{$postCategory->getName()}</td>


现在有新的问题,就是为什么我每次只能显示一条记录?我想全部显示并且实现分页功能?怎么办?


因為 Summary 頁面的 Post 物件只抓取每一個 blog 的一篇文章。避免有人一直寫,結果都抓到他的文章。

Pager 必須自己 implement。目前 admin 頁面有。在其他的頁面如 summary, archive 可能要到 1.1 或是 1.2

Mark


主題: 如何对summary.php展示页面进行改版?
作者: Anonymous三月 14, 2005, 05:52:55 下午
嗚~都怪我衝動
一看到上面的就給它改下去
沒注意到版本
結果summary畫面出現問題...
把原檔覆蓋回去好像沒甚麼用
可以請教一下該怎麼改回來?
http://163.23.112.194/plog/summary.php
[/url]


主題: 如何对summary.php展示页面进行改版?
作者: markwu三月 14, 2005, 06:17:43 下午
用原始的安裝檔覆蓋過去阿!只要你沒改其他的東西,應該是沒問題。

Mark


主題: 如何对summary.php展示页面进行改版?
作者: Anonymous三月 15, 2005, 11:54:56 上午
引用自: markwu
用原始的安裝檔覆蓋過去阿!只要你沒改其他的東西,應該是沒問題。

已經把post.template刪掉(本來沒有=_=)
把之前按上面改的原檔覆蓋回去
但summary畫面還是無法正常耶...
(就像下面這樣,重複很多次)
程式碼:
Exception message: Smarty error: unable to read resource: "summary/post.template"
Error code: 512
-- Backtrace --
/home/webadmin/public_html/plog/class/template/smarty/Smarty.class.php(1102): trigger_error
/home/webadmin/public_html/plog/class/template/smarty/Smarty.class.php(1596): template.trigger_error
/home/webadmin/public_html/plog/class/template/smarty/Smarty.class.php(1397): template._fetch_resource_info
/home/webadmin/public_html/plog/class/template/smarty/Smarty.class.php(1908): template._is_compiled
/home/webadmin/public_html/plog/tmp/%%-66^%%-66975902^recent.template.php(21): template._smarty_include
/home/webadmin/public_html/plog/class/template/smarty/Smarty.class.php(1911): include
/home/webadmin/public_html/plog/tmp/%%-41^%%-41152182^index.template.php(25): template._smarty_include
/home/webadmin/public_html/plog/class/template/smarty/Smarty.class.php(1273): include
/home/webadmin/public_html/plog/class/template/template.class.php(83): smarty.fetch
/home/webadmin/public_html/plog/summary.php(179): template.fetch
/home/webadmin/public_html/plog/class/controller/controller.class.php(118): summaryview.render
/home/webadmin/public_html/plog/summary.php(190): controller.process


為何問題顯示一直有smarty呢?


主題: 如何对summary.php展示页面进行改版?
作者: lss三月 15, 2005, 01:47:31 下午
引用
Exception message: Smarty error: unable to read resource: "summary/post.template"


檢查檔名是否拼錯?

或是

修改後owner換人(比如 root),權限改變,apache 讀不到它?


主題: 如何对summary.php展示页面进行改版?
作者: andywang三月 15, 2005, 06:36:35 下午
<h4>{$locale->tr("summary_latest_posts")}
<a href="{$url->getRssUrl()}?summary=1"><img src="{$url->getUrl("/imgs/rss_logo_small.gif")}" alt="RSS" /></a>
</h4>
<table>
<tr>

<td>Topic</td>
<td>Author</td>
<td>Time</td>
<td>Comments</td>
</tr>
 {foreach from=$posts item=post}
 {include file="summary/post.template"}
  {/foreach}
</table>

这个里面我把 Topic,Author 等换成中文为何显示就乱码了?


主題: 如何对summary.php展示页面进行改版?
作者: lss三月 15, 2005, 07:35:30 下午
樣版裡的中文變亂碼通常只有一個原因,存檔時請存成 utf-8 編碼格式。
其實,你可以這樣寫:
程式碼:
<td>{$locale->tr("topic")}</td>
<td>{$locale->tr("author")}</td>
<td>{$locale->tr("time")}</td>
<td>{$locale->tr("comments")}</td>

由pLog幫你做語系轉換


主題: 如何对summary.php展示页面进行改版?
作者: andywang三月 15, 2005, 08:34:25 下午
谢谢lss,可是我那样改了还是乱码,我知道该如何处理了?


主題: 如何对summary.php展示页面进行改版?
作者: andywang三月 16, 2005, 04:49:13 下午
问题最后解决了,是因为编码的问题,由于安装的时候我采用了utf-8 編碼格式,可是以gb2312编辑修改的,所以肯定乱码,后来我的解决办法是用重新改写了locale_zh_CN.php,把$messages['encoding'] = 'UTF-8';改成gb2312,然后保存,再重新安装plog就可以了!

当然这个办法还是在markwu的指导下做得,所以特此感谢markwu,同时感谢lss的解决办法。


主題: 如何对summary.php展示页面进行改版?
作者: lss三月 16, 2005, 05:10:45 下午
引用自: andywang
问题最后解决了,是因为编码的问题,由于安装的时候我采用了utf-8 編碼格式,可是以gb2312编辑修改的,所以肯定乱码,后来我的解决办法是用重新改写了locale_zh_CN.php,把$messages['encoding'] = 'UTF-8';改成gb2312,然后保存,再重新安装plog就可以了!

当然这个办法还是在markwu的指导下做得,所以特此感谢markwu,同时感谢lss的解决办法。

將編碼改用gb2312,你不是每次pLog大改版時都要這麼來一次嗎?何不直接使用utf-8?只要找個支援的編輯器習慣一下就好了。
如果你用不慣freeware/shareware的編輯器,推薦你用 dreamweaver,mx 以上的版本確定支援將頁面屬性改成utf-8編碼。
純個人意見,參考一下。


主題: 如何对summary.php展示页面进行改版?
作者: markwu三月 16, 2005, 05:28:26 下午
Hi lss:

這一點是很奇怪的喔!其實我遇到不少大陸的 pLog 站長,他們還是是喜歡 GB2312 喔,不喜歡 UTF8。可能 GB2312 的包袱比 Big5 小吧。

Mark


主題: 如何对summary.php展示页面进行改版?
作者: andywang三月 16, 2005, 05:44:50 下午
感谢lss的提醒,我是不想动,但是utf8在使用中有些时候不能正确显示,还有,大陆客户的浏览器默认都是gb2312,当设置为utf8后就有可能不能正常显示,那样客户会很茫然,肯定会尝试用 Big5 ,但是还是不能显示他们就可能放弃访问了,所以这样是不得已而为,另外,变成utf8我后台维护数据就会乱码,将来考虑转为静态的时候也会很麻烦,所以只能改成gb2312了,没办法的,但愿有一天中文都统一用gb2312或者 Big5 就好了,交流没那么多麻烦了。


主題: 如何对summary.php展示页面进行改版?
作者: markwu三月 16, 2005, 05:53:39 下午
引用
统一用gb2312或者 Big5 就好了


統一用 gb2312 或 big5,這不可能。因為編碼有衝突。其實較有可能是 utf-8 或是 gbk ...

最近的 big5 extension 我就不瞭解了。

Mark


主題: 如何对summary.php展示页面进行改版?
作者: lss三月 16, 2005, 05:59:21 下午
引用自: andywang
另外,变成utf8我后台维护数据就会乱码,将来考虑转为静态的时候也会很麻烦,所以只能改成gb2312了,没办法的,


關於這點,我的資料庫預設是 iso-8859-1 ,而我的 blogdb 內存的是 utf-8 ,早期我用 phpMyAdmin 管理時,語言介面是 big5,在phpMyAdmin裡面看到的資料是亂碼,要看資料時,語言介面切成utf-8,換介面變成亂碼。

不過,現在 phpMyAdmin 已經支援 utf-8 的簡/繁語言介面 ,我只要依資料庫(我還有一些 big5 的資料庫)內資料的語系切換適當的語言介面就可以了,還蠻方便的。

參考一下。


主題: 如何对summary.php展示页面进行改版?
作者: andywang三月 16, 2005, 06:09:56 下午
呵呵,你们的这些建议很好,我觉得非常有道理,我是想,现在plog数据库里面的数据可能有一天我要在别的系统用别的开发语言引用,那样就麻烦多些,所以~
当然我说的统一就是这些中文系统里面废除一套,保留一套多好 :-)


主題: Re: 如何对summary.php展示页面进行改版?
作者: xinyuan十一月 04, 2005, 01:45:43 下午
useful


主題: Re: 如何对summary.php展示页面进行改版?
作者: ajer001十一月 07, 2005, 06:39:37 下午
對不起,岔開話題一下,哈

最近看到兩個彰化的學校也都用 LIFTTYPE 來架,真高興
這個大成國小
還有昨天有看到一個和美國中的

ya....彰化人加油... :-P