Personal tools

张炳凯

这里是张炳凯的技术博客。

张炳凯的另外一个博客 http://benky52.cn 也是采用 BFG + 易度CMF 搭建立。

让你的站点可匿名用户填写姓名可评注

zhangbingkai 2007-09-17

Plone在默认情况下,开启评论的内容,用户需要登录才能发表评注。下面将讲述如何让匿名用户便可评注;然后做简单定制,实现让匿名用户填写姓名即可评注。

1. 打开评注功能


在编辑页面的属性标签页中如图:


点击“开放”,点击保存。

在Plone3.0中,点击Setting标签页,打开Allowed comments属性。

2. 开启匿名评注功能


你发现用匿名登录后,需要登录后发表评论。如下图:

那我们来开启匿名评注的功能吧:

  • 进入ZMI的根目录的 Security 标签页
  • 找到Reply to item权限项,取消选择Acquire,并选择允许Anonymous角色
  • 单击Save按钮,保存更改

这样,站点的内容如果开启了评论,匿名用户也可对内容进行评论。

3. 找到评注的逻辑及代码


匿名用户可评注,但是在评注表单中要填写用户名和密码才能用姓名发表评注,如下图:

我们在代码中去看这个发表评注的过程。去找评注功能的相关显示及逻辑代码。

我们在提交评注表单的HTML代码中找到提交的Form表单是这样的:

.../discussion_reply_form

那么,我们在Portal_skins中找到discussion_reply_form

这是一个CPT文件,你若不了解什么叫控制页面模板,简易先到CZUG的Plone中文书籍项目中了解第十三章的内容,项目地址:http://czug.everydo.com 登录用户名/密码用 guset/guest 。

在discussion_reply_form这个CPT页面的Actions标签页中,我们看到表单提交成功后会提交到discussion_reply,这便是表单的处理逻辑代码。

4. 定制可填写姓名发表评注


我们来处理表单,在表单中有这样的代码:

<div tal:condition="isAnon">
<dl class="portalMessage warning">
<dt i18n:translate="">
Info
</dt>
<dd i18n:translate="legend_note_reply_anonymous">
You are not logged in. You may optionally enter your
username and password below. If you don't enter anything,
this comment will be posted as 'Anonymous User'.
</dd>
</dl>
<div class="field">
<label for="username" i18n:translate="label_name">Name</label>
<input name="username"
id="username"
value="" alt="Username" title="Name"
size="40"
i18n:attributes="title label_name; alt label_username;" />
</div>
<div class="field">
<label for="password" i18n:translate="label_password">Password</label>
<input type="password"
id="password"
name="password"
value="" alt="Password" title="Password"
size="40"
i18n:attributes="title label_password; alt label_password;" />

</div>
</div>
换成可用填写姓名发表评论:

<div class="field">
<label for="username" i18n:translate="label_name">Name</label>
<input name="username"
id="username"
value="" alt="Username" title="Name"
size="40"
i18n:attributes="title label_name; alt label_username;" />

</div>

现在来处理逻辑部分disscustion_relpy的代码,

这是一个Python Script,它有这样一些参数,在 Parameter List 中看到:

subject,body_text,text_format='plain',username=None,password=None

换成:

subject,body_text,text_format='plain',username=""
我们看到这些代码:

if username or password:
# The user username/password inputs on on the comment form were used,
# which might happen when anonymous commenting is enabled. If they typed
# something in to either of the inputs, we send them to 'logged_in'.
# 'logged_in' will redirect them back to this script if authentication
# succeeds with a query string which will post the message appropriately
# and show them the result. if 'logged_in' fails, the user will be
# presented with the stock login failure page. This all depends
# heavily on cookiecrumbler, but I believe that is a Plone requirement.
came_from = '%s?subject=%s&amp;body_text=%s' % (req['URL'], subject, body_text)
came_from = url_quote_plus(came_from)
portal_url = context.portal_url()

return req.RESPONSE.redirect(
'%s/logged_in?__ac_name=%s'
'&amp;__ac_password=%s'
'&amp;came_from=%s' % (portal_url,
url_quote_plus(username),
url_quote_plus(password),
came_from,
)
)

# if (the user is already logged in) or (if anonymous commenting is enabled and
# they posted without typing a username or password into the form), we do
# the following

creator = mtool.getAuthenticatedMember().getId()
换成下面所示:
if username == '':
username = '匿名用户'
creator = username
现在,在你的站点中匿名用户不用注册登录,不用发表评注时还用着“匿名用户”的字样,就可评注了。

评论...

让你的Ploneboard匿名用户填写姓名可发贴

zhangbingkai 2007-09-17

Everydo.com的论坛使用Ploneboard实现,匿名浏览用户无需注册登录,填写姓名就可发贴;而再次访问Everydo.com时无需再填写姓名,将使用存在Cookie中的姓名来发贴。 因为有社区里朋友问到,我将实现过程写在这里。

1. 开启匿名用户可发贴

在添加了论坛board后,再来添加子论坛forum后,改变forum状态为Free of all,如下图:


2. 了解Ploneboard发贴、发表评论的过程

发贴时,页面打开的是这样地址:

.../add_conversation_form?

我们可以在Portal_skins中找到add_conversation_form的页面,它是一个CPT页面,你若不了解什么叫控制页面模 板,简易先到CZUG的Plone中文书籍项目中了解第十三章的内容,项目地址:http://czug.everydo.com 登录用户名/密码用 guset/guest 。

我们在add_conversation_form页面的Actions标签页中看到Post提交后会提交给 add_conversation_script,很显然,add_conversation_script是处理发贴表单的逻辑代码。我们也可以在 Portal_skins中找到add_conversation_script。

我们再来了解发表评论的过程。

发表评论有两种方式,使用回复或快速回复,我们看到点击“回复”时,链接到了

../add_comment_form

在快速回复的HTML代码中,看到form提交也提交到add_comment_form

很显然,add_comment_form是表单,我们在Portal_skins中找到了它,它也是一个CPT页面,在 add_comment_form的Actions标签页中看到Post后提交给了add_comment_script,那么 add_comment_script就是发表评注表单的处理逻辑代码。

3. 定制“显示”部分代码

我们在add_conversation_form的代码中看到:

<div metal:use-macro="here/add_comment_form/macros/comment_body_title" tal:omit-tag="" />

<div metal:use-macro="here/add_comment_form/macros/comment_body_text" tal:omit-tag="" />

<div metal:use-macro="here/add_comment_form/macros/comment_body_attachments" tal:omit-tag="" />

<div metal:use-macro="here/add_comment_form/macros/comment_body_buttons" tal:omit-tag="" />

显然add_conversation_form使用的是add_comment_form的宏。

我们再来在add_comment_form中定制添加姓名的宏:

 <div metal:define-macro="comment_body_creator" tal:omit-tag="">
<div class="field">
<label for="creator">您的名字</label>

<div class="formHelp">
</div>
<input id="creator" type="text" size="40" name="creator"
tal:attributes="value python:request.get('creator','');"/>
</div>

提示:姓名的表单中有这样的代码:

tal:attributes="value python:request.get('creator','');"

这是后文我们将从表单中的creator和email存放在Cookie中,让用户第一次发贴后,后面的发贴表单中有前面填写的值。

我们再将姓名的宏加在add_conversation_form中:

<div metal:use-macro="here/add_comment_form/macros/comment_body_creator" tal:omit-tag="" />

显示部分就定制完了。

4. 定制“逻辑”部分代码

在add_conversation_script中:

它的参数有:

title, text='', files=None

我们需要加上creator的参数,将 Parameter List 填写为

title, text='', files=None, creator=''

下面这部分代码是用户名的处理:

if pm.isAnonymousUser():
creator = 'Anonymous'
else:
creator = pm.getAuthenticatedMember().getUserName()

我们将它定制为:

if not pm.isAnonymousUser():
creator = pm.getAuthenticatedMember().getUserName()

if creator == '':
creator = '匿名用户'

可以将creator存放在在根目录的Cookie中,保存为30天,这部分代码可写在后面:

cookie_path = '/'
length = 30
expires = (DateTime() + length).toZone('GMT').rfc822()

context.REQUEST.RESPONSE.setCookie('creator',creator, path=cookie_path, expires=expires)

那么,add_comment_script中也类似的定制这样的代码。

然后,你就发现可以类似于Everydo.com中的论坛一样用户不登录可用自己的姓名发贴了。

评论...

[转]Plone3.0的8大酷点

zhangbingkai 2007-09-15

原文在这里


Plone 3 Release Candidate 1 is out. This is a big milestone in the evolution of Plone, and a big leap forward for both developers and for everyday Plone users. The Plone 3 team is still putting the final polish on it, but Release Candidate 1 is more than ready for prodding, poking and testing. Here are eight of the things about Plone 3 that I’m most excited to start using in ONE/Northwest’s projects, with screenshots.

1. A Big HTML editor update: Kupu 1.4

For a lot of everyday Plone users, Kupu (Plone’s graphical HTML editor) is Plone. And in Plone 3, Kupu packs in a lot of improvements. All of the changes in Kupu could fill up an article on its own, but the highlights surely include:

  • Named anchors
  • Automatic image resizing
  • Image captions
  • Inserting of Flash and other embeddable video (e.g. YouTube)
  • Span/character styles

Together with all of Kupu’s existing goodness, most emphatically including its ability to produce valid XHTML code, Plone 3 defines “best of breed” for graphical HTML editing in a CMS.

Here are a few screenshots of Kupu in action, to whet your appetite. Click on each image to see the full-size view.

anchors3.png

Linking to an anchor — in this page or in any other page on your site!

anchors2

Adding and removing anchors from a page.

Anchors

Creating a table of contents from headings in a page.

anchors-toc.png

A table of contents, automatically built by Kupu from headings in your document.

image1.png

Automatic resizing of images using PIL.

image-caption.png

Captioned images — a frequently requested feature!

2. Rich Text fields on Collections

Ok, so this is a small feature. But it really makes me happy. Collections (formerly known as Smart Folders, formerly known as Topics), which are simple build-your-own query listings of content, now have a Rich Text field, which means you can very easily write a nicely formatted introduction to a dynamic listing of content. This is going to make it really easy for non-technical site administrators to build polished, lively sites without knowing a lick of code.

collection1.png

A Collection with a Rich Text intro.

3. The new “Sharing” tab

Plone has long had a fantastic system for creating really precise permissions on content. Plone 3 surfaces a lot of that power in a simple way for everyday users. Check out the all-new “sharing” tab.

sharing2.png

Nice! You can use this single, elegant screen to add give new users & groups the permission to view, to edit and to add new content in a folder. That’s all you need to cover a pretty huge set of intranet/extranet situations.

To see how radically this has improved in Plone 3, check out the old sharing tab from Plone 2.5:

sharing1.png

Holy cow! That’s about 4x as large as in Plone 3, and it doesn’t even do as much! Kudos to Alex Limi and Danny Blomendaal for the big cleanup.

4. New built-in workflows

Plone 3’s elegant new sharing tab is more than complimented by powerful new workflows. Once again, the Plone team has surfaced powerful underlying systems in a friendly, accessible way. Plone 2.5 shipped with one standard workflow. Plone 3 ships wtih several simple workflows, designed to support common user stories including simple publication sites, community sites, and intranet/extranets.

workflows1.png

Choosing among Plone 3’s new workflows.

You can associate these workflows with different content types, or use the included CMFPlacefulWorkflow add-on Product to assign different workflows to different folders. This makes it easy to build a single Plone site that has a public-facing section and a rich, private collaboration space.

workflows2.png

Assigning a custom workflow to a folder.

5. Link integrity: no more broken links

Plone 3 has a powerful new “link integrity” feature that makes sure you never break hyperlinks within your site as you move or delete content. Here’s what happens when you try to delete an image that is used in several pages.

linkintegrity.png

6. Versioning, staging and locking

Plone 3 ships with big-league document management features, starting with document versioning. Versioning allows you to save old versions of a page, compare your current version to older versions, and even to roll back to previous versions. Plone 3.0’s versioning is drawn from CMFEditions, the well-established add-on Product, spiffed up with some nice new user interface.

history1.png

Plone 3’s history tab showing all previous revisions of your document.

history2.png

Plone 3 can also show you exactly what’s been added and removed between versions. Nerds call this a “diff” (short for “difference”)!

Plone 3.0 is also scheduled to include document staging, the ability to work on a copy of a document while the old version is still live, via Kapil Thangavelu’s product “iterate.”

Finally, Plone 3.0 includes locking, which prevents two people from making changes to a document at the same time. Together, versioning, staging and locking will make Plone 3.0 very appealing to folks who are managing sophisticated sites with multiple people editing content at the same time.

7. Automatic full-text searching of Word and PDF files

Plone 3 automatically indexes the entire text of Word and PDF files that you upload. (You can index other kinds of documents, too, with simple add-on Products.) Again, this is a killer feature for intranets, and for any other site that has a lot of document-centric content to share with the world.

UPDATE: Thanks to Daniel Nouri for pointing out that this only happens auto-magically if you have wvware (for Word) and pdftoext or xpdf already installed on your system.

portlets1.png

8. User control of portlets

Plone 3 has a entirely new “portlets” system. Portlets are those little chunks of content that appear in the sidebars of a site. You used to have to go into the ZMI backend to manage them. Now you just click on “Manage Portlets,” then drag and drop your way to glory.

Plone 3 ships with one new kind of portlet, an RSS feed portlet. There’s lots of room for add-on Product developers and site integrators to develop interesting and innovative new portlets.

This feature alone is going to make a lot of our clients very, very happy.

Summing Up

Plone 3 is the most ambitious, exciting release of Plone ever. It pushes Plone to an incredible new level of power, and continues the ongoing processes of polishing Plone’s legendary ease-of-use to a high gloss.

Plone 3.0 RC1 is meant for testing, not production use. There are still a few weeks of fast-paced bug-hunting ahead. That’s where you come in. Download it. Install it. Play with it. Report bugs. Fix ‘em if you can. Plone 3 should be released sometime in early/mid August. I’m excited.

评论...

Plone3.0初显成效

zhangbingkai 2007-09-15

翻译Limi的一篇文章:http://limi.net/articles/some-preliminary-plone-3.0-benchmark-results

文章同时发布在Benky's Space上:http://benky.plonespace.net/sentiment/plone3-0chuxianchengxiao

自从我们更多聚焦在即将发布的Plone3.0的性能后,我运行了一些基本的,下面的结果是相对于Plone2.5的基准:

下图能说明它们的不同:

Plone 2.5 vs. 3.0

对于匿名用户,首页的标准页面,所有的数字表明Plone3.0更佳,测试的Plone服务是在没有任何的缓存代理和Web服务在Plone服务之上,使用的2GHz MacBook Core Duo.

数据用表格表示:

HTTP requests
Page rendering
Page weight
Plone 2.5 28 222 ms 198 KB
Plone 3.0 11 138 ms 127 KB
Difference 17 fewer 84 ms faster 71 KB smaller
Improvement 61% fewer 61% more req/s 36% smaller

的确有不错的进步。我尤其高兴递归一个页面减少HTTP请求的数字--它减少到只有Plone2.5一半还少的请求。一般的浏览器仅做了3个并行请求,所以不论传输速度,怎样快速的在浏览器上显示网页,做出了巨大的差异。

对 于登录用户,Plone3.0也更有重大的速度改进,它非常引人注意。因为新的Ajax UI使得相对Plone2.5有更多的Javascript在服务,但这在首次登录后就被缓存在浏览器中,这是一次性的花费。而且这些使得 Plone3.0更为友好,更具生产力,比如可点击页面上的一些元素并且可直接编辑,这相当于对一次性花费是一个很好的补尝。

评论...

cia.gov(美国中央情报局) is powered by Plone

zhangbingkai 2007-05-27

The Central Intelligence Agency (CIA) <https://www

The Central Intelligence Agency (CIA) <https://www.cia.gov/> (美国中央情报局)的官方站点使用Plone构架。

你甚至还可以看到cia.gov使用着默认的Plone ico

评论...

 

本站由 润普公司资助, 采用 易度CMS 构建。

广而告之:润普公司 易度云办公平台,包括 易度文档管理系统 易度项目管理系统 , 易度部门管理 ,均采用Zope 3/BFG技术开发。
沪ICP备05008050