修改plog/LifeType模板支持coComment.
作者: oldwain(http://oldwain.itpub.net)发表于: 2006.02.20 02:20
分类: Web2.0 , 自产自销
出处: http://oldwain.itpub.net/post/6/54175
---------------------------------------------------------------
主要参考资料: Making a Homebrew Blogging Tool coComment-compatible
基本原理:
通过修改Comment form中对象的名字,使得coComment将blog"识别"成其已经支持的blog系统之一。
注意之处:
- 由于comment form中的对象名字在提交后会被plog/lifetype程序引用,所以不能像参考文章中那样简单的改名。为此可以增加几个相应名称的隐藏对象,在原有对象内容改变后,通过script改变隐藏对象的内容。
- 参考文章中使用了TypePad作为"伪装"对象,由于LifeType与MovableType更为"像"一些,所以这里选用了MovableType作为伪装对象.
具体做法:
- 在header.template文件中加入<link rel="start" href={$url->bloglink()} title="Home" />
- 修改文章页面的title 为"blog名: 文章名"的格式
- 修改commentform.template中以下内容:
- 修改comment form 的id 为comments_form, name可以不变
- 增加隐藏域author, 当userName域发生变化时相应改变author域
- 增加隐藏域email, 当userEmail域发生变化时相应改变email域
- 增加隐藏域text, 当commentText域发生变化时相应改变text域
- 将提交按钮的名字改为post
修改后的comment.template内容类似下面的样子(仅用作示意,具体内容要根据自己所用模板内容进行修改):
{$locale->pr("comment_topic")}<br/>
<input type="text" size="60" name="commentTopic" value="re: {$post->getTopic()}"/><br/>
{$locale->pr("comment_text")} <br/>
<br />
<input type="hidden" name="author" value="none"/>
<input type="hidden" name="email" value="none"/>
<input type="hidden" name="text" value="none"/>
{$locale->pr("comment_username")}<br/> <input type="text" name="userName" value="" onchange="findObj('author').value = this.value" /><br/>
{$locale->pr("comment_email")}<br/> <input type="text" name="userEmail" value="" onchange="findObj('email').value = this.value" /><br/>
{$locale->pr("comment_url")}<br/> <input type="text" size="60" name="userUrl" value=""/><br/>
<input type="submit" value="{$locale->pr("comment_send")}" name="post"/><br/><br/>
<input type="hidden" name="op" value="AddComment"/>
<input type="hidden" name="articleId" value="{$post->getId()}"/>
<input type="hidden" name="blogId" value="{$blog->getId()}"/>
<input type="hidden" name="parentId" value="{$parentId}"/>
</form>
上面使用的findObj函数代码(来源于dreamweaver的示例代码):
function findObj(theObj, theDoc)
{
var p, i, foundObj;
if(!theDoc) theDoc = document;
if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
{
theDoc = parent.frames[theObj.substring(p+1)].document;
theObj = theObj.substring(0,p);
}
if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
for (i=0; !foundObj && i < theDoc.forms.length; i++)
foundObj = theDoc.forms[i][theObj];
for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++)
foundObj = findObj(theObj,theDoc.layers[i].document);
if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
return foundObj;
}
(需要引用, 请注明出处: http://oldwain.itpub.net)




