oldwain随便写
===========================================================
===========================================================

主要参考资料: Making a Homebrew Blogging Tool coComment-compatible

基本原理:

通过修改Comment form中对象的名字,使得coComment将blog"识别"成其已经支持的blog系统之一。

注意之处:

  1. 由于comment form中的对象名字在提交后会被plog/lifetype程序引用,所以不能像参考文章中那样简单的改名。为此可以增加几个相应名称的隐藏对象,在原有对象内容改变后,通过script改变隐藏对象的内容。
  2. 参考文章中使用了TypePad作为"伪装"对象,由于LifeType与MovableType更为"像"一些,所以这里选用了MovableType作为伪装对象.

具体做法:

  • 在header.template文件中加入<link rel="start" href={$url->bloglink()} title="Home" />
  • 修改文章页面的title 为"blog名: 文章名"的格式
  • 修改commentform.template中以下内容:
    1. 修改comment form 的id 为comments_form, name可以不变
    2. 增加隐藏域author, 当userName域发生变化时相应改变author域
    3. 增加隐藏域email, 当userEmail域发生变化时相应改变email域
    4. 增加隐藏域text, 当commentText域发生变化时相应改变text域
    5. 将提交按钮的名字改为post

修改后的comment.template内容类似下面的样子(仅用作示意,具体内容要根据自己所用模板内容进行修改):

<form id = "comments_form" name="NewComment" action="{$url->getBaseUrl()}/index.php" method="post" >
{$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"/>
<textarea rows="10" cols="54" name="commentText" onchange="findObj('text').value = this.value" ></textarea><br/>
{$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;
}
Technorati Tags: , ,

(需要引用, 请注明出处: http://oldwain.itpub.net)

oldwain 发表于:2006.02.20 02:20 ::分类: ( Web2.0 , 自产自销 ) ::阅读:(5079次) :: 评论 (9) ::收藏此页到365Key
re: kastner [回复]

抱歉,上面的代码由于只是用于示例,所以相关的javascript代码没有附上。

为了方便你使用,把findObj的代码附到原文上.

oldwain 评论于: 2006.02.21 02:38
re: 修改plog/LifeType模板支持coComment. [回复]

如果不支持上传.js文件,那么直接放到模板文件内就可以。

oldwain 评论于: 2006.02.21 14:58
re: 修改plog/LifeType模板支持coComment. [回复]

贴上的时候,代码前后要加上script标签啊。

<script type="text/javascript" language="javascript">

script代码

</script>

oldwain 评论于: 2006.02.21 17:08
re: 修改plog/LifeType模板支持coComment. [回复]

在script标签外部,再加上{literal} ... {/literal}试试

oldwain 评论于: 2006.02.21 19:56
re: 修改plog/LifeType模板支持coComment. [回复]

找到原因了。
写这篇文章的时候遗漏了一条(原参考文章中提到了这一点):

修改文章页面的title 为"blog名: 文章名"的格式

具体实现方法因模板实现方法不同而有差异,可以下载我的模板进行参考, 或者把模板文件发给我,我来帮你分析。

oldwain 评论于: 2006.02.23 14:25
re: kastner [回复]

不必客气。tongue

oldwain 评论于: 2006.02.23 19:11
请赐教 [回复]

如何修改blog名
在中国教师博客

emon 评论于: 2006.07.04 22:03
re: emon [回复]

中国教师博客? 没听说过. crying.gifwassat.gif

oldwain 评论于: 2006.07.05 21:25
re: momo [回复]

官方脚本,是在我这篇文章之后才给出的。
并且,那个脚本有时会造成页面刷新有问题。(最初的版本,后来没再试过)

oldwain 评论于: 2006.08.07 09:39

发表评论
标题

在此添加评论
表情符号: smile laughing tongue angry crying sad wassat wink

称呼

邮箱地址(可选)

个人主页(可选)

 authimage


自我介绍
切换风格
新闻聚合
博客日历
文章归档...
最新发表...
最新评论...
最多阅读文章...
最多评论文章...
博客统计...
Blog信息
赞助商
网站链接...
其它资源
我的网摘...