Tommy 碎碎念

Tommy Wu's blog

« 上一篇 | 下一篇 »

修正 Lifetype 文章標題有 -- 出現時, 會顯示不正常的情形
post by tommy @ 15 六月, 2006 12:25
前幾天有篇文章在標題中出現 -- 字元, 結果在 Firefox 看這篇文章時, 在標題前會出現一個多餘的 //-->, 而這個問題在 IE 中是不會出現的.

這會是 Firefox 的 bug 嗎? 上網問了一下, 有人給了這個 html 註解的定義網頁, 上面有提到註解的定義. 其中, 有說明當使用 -- 當註解之後, 不應該有 -- 存在於註解之中. 所以, 我想 Firefox 這樣子處理, 並不能算是 bug 吧.

既然這不能算是 Firefox 的問題, 所以... 就要想法子由 LifeType 來解決. 會出現這個問題的原因是因為文章的標題會有 -- 出現, 而 LifeType 的 postTrackbackLink() 在輸出資料於註解的時候, 也會把文章標題列在其中, 所以, 我們只要想辦法在這個輸出的地方, 把文章標題有出現 - 的, 都改成 \-, 來避免這個問題. (PS. 會不會造成這個運作有問題呢? 我想應該不會吧, 頂多看到的 topic 不太正確, 並不會影響 trackback 的 link, 而且 \- 在  browser 上頭, 看到的應該也是 - 吧.)

這個 patch 可以由這兒抓取: http://www.teatime.com.tw/~tommy/mypatch/lifetype_postTrackbackLink_topic.patch

diff -Nur class.orig/net/customrequestgenerator.class.php class/net/customrequestgenerator.class.php
--- class.orig/net/customrequestgenerator.class.php 2006-06-16 08:25:45.680792558 +0800
+++ class/net/customrequestgenerator.class.php 2006-06-16 08:36:23.160057155 +0800
@@ -283,11 +283,13 @@
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">';

- $trackbackLink = $this->getTrackbackUrl()."?id=".$post->getId();
+ $trackbackLink = str_replace('-', '%2D', $this->getTrackbackUrl()."?id=".$post->getId());
+ $postLink = str_replace('-', '%2D', $this->postLink($post));
+ $topic = str_replace('-', '\-', $post->getTopic());
$rdfBody = "<rdf:Description
- rdf:about=\"".$this->postLink($post)."\"
- dc:identifier=\"".$this->postLink($post)."\"
- dc:title=\"".$post->getTopic()."\"
+ rdf:about=\"".$postLink."\"
+ dc:identifier=\"".$postLink."\"
+ dc:title=\"".$topic."\"
trackback:ping=\"".$trackbackLink."\"/>";
$rdfFooter = "</rdf:RDF>";

diff -Nur class.orig/net/modrewriterequestgenerator.class.php class/net/modrewriterequestgenerator.class.php
--- class.orig/net/modrewriterequestgenerator.class.php 2006-06-16 08:26:08.656621134 +0800
+++ class/net/modrewriterequestgenerator.class.php 2006-06-16 08:36:55.351819113 +0800
@@ -224,12 +224,13 @@
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">';

- $trackbackLink = $this->getTrackbackUrl()."?id=".$post->getId();
-
+ $trackbackLink = str_replace('-', '%2D', $this->getTrackbackUrl()."?id=".$post->getId());
+ $postLink = str_replace('-', '%2D', $this->postLink($post));
+ $topic = str_replace('-', '\-', $post->getTopic());
$rdfBody = "<rdf:Description
- rdf:about=\"".$this->postLink($post)."\"
- dc:identifier=\"".$this->postLink($post)."\"
- dc:title=\"".$post->getTopic()."\"
+ rdf:about=\"".$postLink."\"
+ dc:identifier=\"".$postLink."\"
+ dc:title=\"".$topic."\"
trackback:ping=\"".$trackbackLink."\"/>";
$rdfFooter = "</rdf:RDF>";

diff -Nur class.orig/net/prettyrequestgenerator.class.php class/net/prettyrequestgenerator.class.php
--- class.orig/net/prettyrequestgenerator.class.php 2006-06-16 08:26:18.596546991 +0800
+++ class/net/prettyrequestgenerator.class.php 2006-06-16 08:37:11.207701904 +0800
@@ -245,11 +245,13 @@
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">';

- $trackbackLink = $this->getTrackbackUrl()."?id=".$post->getId();
+ $trackbackLink = str_replace('-', '%2D', $this->getTrackbackUrl()."?id=".$post->getId());
+ $postLink = str_replace('-', '%2D', $this->postLink($post));
+ $topic = str_replace('-', '\-', $post->getTopic());
$rdfBody = "<rdf:Description
- rdf:about=\"".$this->postLink($post)."\"
- dc:identifier=\"".$this->postLink($post)."\"
- dc:title=\"".$post->getTopic()."\"
+ rdf:about=\"".$postLink."\"
+ dc:identifier=\"".$postLink."\"
+ dc:title=\"".$topic."\"
trackback:ping=\"".$trackbackLink."\"/>";
$rdfFooter = "</rdf:RDF>";

diff -Nur class.orig/net/rawrequestgenerator.class.php class/net/rawrequestgenerator.class.php
--- class.orig/net/rawrequestgenerator.class.php 2006-06-16 08:26:28.660471933 +0800
+++ class/net/rawrequestgenerator.class.php 2006-06-16 08:37:23.439611499 +0800
@@ -260,11 +260,13 @@
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">';

- $trackbackLink = $this->getTrackbackUrl()."?id=".$post->getId();
+ $trackbackLink = str_replace('-', '%2D', $this->getTrackbackUrl()."?id=".$post->getId());
+ $postLink = str_replace('-', '%2D', $this->postLink($post));
+ $topic = str_replace('-', '\-', $post->getTopic());
$rdfBody = "<rdf:Description
- rdf:about=\"".$this->postLink($post)."\"
- dc:identifier=\"".$this->postLink($post)."\"
- dc:title=\"".$post->getTopic()."\"
+ rdf:about=\"".$postLink."\"
+ dc:identifier=\"".$postLink."\"
+ dc:title=\"".$topic."\"
trackback:ping=\"".$trackbackLink."\"/>";
$rdfFooter = "</rdf:RDF>";

 

目前在我這兒, 看起來這樣子似乎沒有什麼問題. 


2006/6/16 修正: 
  1. str_replace() 參數順序弄錯. :-(
  2. 若有用自訂的 URL, 則那些 URL 也要轉換

 

Del.icio.us Furl HEMiDEMi Technorati MyShare
迴響
暱稱:
標題:
個人網頁:
電子郵件:
authimage

迴響

  

Bad Behavior 已經阻擋了 93 個過去 7 天試圖闖關的垃圾迴響與引用。
Power by LifeType. Template design by JamesHuang. Valid XHTML and CSS