谦卑的程序员






         静水流深

July 30, 2008

为drupal配置Captcha

Filed under: 1.2 Web开发 — Eric Tou @ 9:03 pm
Tags: , ,

  站点已经发布几个月了,但是只有几个朋友知道,因此并没有什么评论。但最近有人开始提交垃圾信息的评论来骚扰我。
  手工删除这些垃圾信息是很麻烦的,一个人和一个自动运行的机器人斗争?看来是时候采取行动保护自己了。

  CAPTCHA是一个通过生成人类能够但是计算机程序不能通过的测试来保护网站,对抗网络机器人的程序。
  CAPTCHA包含针对应用安全的几个程序, 包含(但不局限于):
  Preventing Comment Spam in Blogs.
  Protecting Website Registration.
  Protecting Email Addresses From Scrapers.
  Online Polls.
  Preventing Dictionary Attacks.
  Search Engine Bots.
  Worms and Spam.

  通常你不需要生成你自己的captcha脚本。reCAPTCHA 项目提供了一个免费、安全且易访问的CAPTCHA解决方案。并且为WordPress, MediaWiki, PHP, Perl, Python和其他环境提供易于安装的插件。reCAPTCHA官方推荐的CAPTCHA解决方案。
  而且,reCAPTCHA在阻止垃圾信息的同时还帮助将书本数字化!显示的文本直接来自于书籍并且被数字化。

  (美国宾夕法尼亚匹兹堡市CMU研究小组受“互联网档案馆”这一非盈利组织委托,将海量的古老书籍和手稿通过OCR(光学字符识别)转化非电子文本,以方便电脑存储和查询。但是由于原稿质量太差,电脑出错率高,需要人工核对,而这样的工作不是一个人或者一个小组可以胜任的。于是CMU设计了 reCAPTCHA,将OCR无法识别的文字扫描图传给世界各大网站,用以替换原来的验证码图片;那些网站的用户在正确识别出这些文字之后,其答案便会传回CMU为了提高用户辨识文字的正确率,他们往往被要求辨认两个单词,其中一个答案已经知晓。这样一来,正确辨认出有答案那个单词的用户,很有可能也会正确辨认另一个单词。有时候,CMU也会将一个未经辨认的单词提交给不同的用户,如果得到的是相同的答案,那这个答案便可以肯定是正确的。)

  实现非常简单。reCAPTCHA是一个Web服务。因此,使用它只需要简单地在你的网站中添加四行代码。对很多应用程序和编程语言,比如 Wordpress和PHP还有易于安装的插件。由reCAPTCHA生成并验证扭曲的图片,e而你则不必花费代价来运行图片生成程序。
————————————————–

  对于我安装的drupal我该怎么办呢,记得么?我们总能找到一个插件来完成工作。

  Captcha模块是基础的CAPTCHA模块,提供了常用的CAPTCHA管理和一个简单的数学验证。 (安装reCAPTCHA模块的前提)

  安装步骤和其他模块相同。
  配置页面在admin/user/captcha (和其他模块不同)
  权限:“skip captcha”

  附带的text_captcha模块提供另一个简单的文本验证。
  附带的image_captcha模块提供一个基于图像的验证。

  如果你准备使用image_captcha模块,你需要安装TTF字体到image_captcha/fonts或者files目录。你能在网上找到免费的字体(阅读readme文件查找下载地址)
————————————————–

  我们也可以在Captcha的基础上安装reCAPTCHA模块。reCAPTCHA模块使用了reCAPTCHA的Web服务来增强CAPTCHA的功能。
  安装步骤相当简单,请阅读文档。

July 1, 2008

升级Drupal的Localizer模块自v1.10至v3版本

Filed under: 1.2 Web开发 — Eric Tou @ 11:39 pm
Tags: , , , ,

    My site is built on Drupal 5, and enable the Localizer module to provide multilingual content
    You have another choice: Internationalization (i18n).
    On Drupal you always have different choices, turn left or turn right, it’s a problem. Localizer is just my choice after I estimate two modules according my demands.

    When I first time set up my site, latest Localizer is v1.10 for Drupal 5, it works fine, especially with the Taxonomy Menu module,  this module can automatically transform my tags into the tree menu I need, it’s the main reason I choose Localizer module because i18n does this job terrible.
     The only problem for me is the RSS feed, I was confused by how to get the separate RSS feed for each language, when you visit http://{hostname}/rss.xml, you just get the RSS feed of contents in default language.
     This article <How does RSS work on a multi-lingual site?> describe how the Localizer provide RSS feed of contents in different languages.
     >. Active “Switch by locale parameter” setting of Localizer
     >. Access the RSS feed like:
        http://{hostname}/rss.xml?locale=en
        http://{hostname}/rss.xml?locale=zh-hans
     It works in the Web Browsers (Firefox, IE), But it doesn’t work in RSS Reader (Google Reader), FeedBurner neither. I guess it’s because “?” mark in the URL.
    So, still only can get contents in default language from RSS feed. I searched a lot, but failed to find a solution.

    Recently i found Localizer module is updated to v3, Give a try to see if they resolved the problem? Why not?
    The update process it’s easy, all you have to do is follow the Readme.txt file in the package.
    This module has changed hugely, how many changes occurred? Read here
    After installed this module, go to the setting page, you will find it does change a lot.
    ‘Switch by locale parameter’ option disappeared, instead of a ‘Language prefix’ option block. I guess that’s what I want, active the ‘Automatically append language prefix to all content (node) pages’ option and save, check the RSS feed again. Now the RSS feed becomes like:
        http://{hostname}/en/rss.xml
        http://{hostname}/zh-hans/rss.xml

    Cool, but wait, Why there are Chinese contents in English RSS feed? Go back to setting page, I found the Option ‘Activate content language fallback support’ in ‘Content settings’ block (previous ‘Support for different contents types’ block) is active.
    What’s meaning of ‘language fallback’? You can find the answer in here
    That’s not what I want, so I deactivated this option. Now my site contains English and Chinese contents, I want to set English as my BASE language, it means the Chinese reader can read the English content if it doesn’t have counterpart Chinese content, but the English reader only need to access the English contents.(Many Chinese speak English, But how many foreigners can understand Chinese?)
    My previous solution is post the English content I want to display in both languages as ‘ANY’ language. Let’s test it again, create a node, Oh….h.
Where is my lovely TinyMCE button? Where is my ‘ANY’ language?
    TinyMCE problem is easy, remember the language prefix? Go to the Setting page of TinyMCE, edit the Visibility option in profile, add the language prefix, save, done.
    But without ‘ANY’ language, things become troublesome, All of my contents in ‘ANY’ language are still there, but not displayed in any language. The solution is Change it into a specific language.But, to display the content in all languages, I have to create duplicated node in every languages.

    This is life, at least it gives me a reason to expect the next release.

使用Windows Live Writer发布Blog到Drupal未遂

Filed under: 1.2 Web开发 — Eric Tou @ 3:12 pm
Tags: ,

    I already add TinyMCE module to Drupal to edit article, TinyMCE is a platform independent web based Javascript HTML WYSIWYG editor, it’s very easy to integrate into other Content Management Systems.
    It’s cool, but the disadvantage of the embedded online editor is:  I have to save a lot times and everytime i have to wait it refreshes. And, sometimes the format displays oddly, which annoyed me. How bizarre?Anyway, you just can not expect it as stable as MS Word.

    So, i guess i need a offline editor. It’s said Windows Live Writer can support 3rd party blog service like Drupal, I tried.
    Steps:
    1. login to Drupal, enable the Blog API module.
    2. Open the Windows Live Writer, Add a Weblog Account.
    3. Choose Weblog Type: another weblog service
    4. type your blog URL as http://{hostname}/blog/{userid} and enter your username and password.
    5. Select either of the four APIs suggested above. MovableType API works best.
    6. For the remote posting URL enter http://{hostname}/xmlrpc.php
    7. Complete

    It looks easy, but i got a error at step 4. What’s the problem? I find it’s because i didn’t enable the Blog module. Currently all contents of my site are based on Story module.
    You may ask, what is the difference between Story and Blog module?
    Here is an article from durpal.org
    Let me make it clearer,
    1. If you post all contents on your own, there is no difference, there are all nodes. (Yes, With Blog module you can use Windows Live Writer)
    2. If there are multi-users, Blog give every user their own blog, for Story, you should care about the privilege.

    Because i don’t want to move contents on Blog module, finnally i fail to use Windows Live Writer publish to Drupal, but that’s ok, It doesn’t mean i don’t need to edit article online any more even though i can use the Windows Live Writer.  Don’t forget, There are Localizer, Teaser, Tag, Attachment, URL Path which Windows Live Writer still can’t (fully) support.

June 25, 2008

Drupal的Attachment与Filemanager插件

Filed under: 1.2 Web开发 — Eric Tou @ 11:16 pm
Tags: , , ,

    drupal core already provided Upload module to allow users to upload and attach files to content, but Attachment + Filemanager do a better Job.

    Attachment module is an alternative to Drupal’s included upload module. Filemanager module provides file management API for attachment module to use.
    Attachment  module uses the filemanager module to allow a unique namespace per node and support large number of files. In addition this module allows you to give each attachment a title and description.

Installation steps:

    1. Upload Filemanager and Attachment module, enable them and disable upload module.
    2. Go to /admin/settings/filemanager , specify Public/Private file system path, and create folder on the server.
    3. Go to /admin/settings/attachment , config attachment module, I didn’t check the ‘Private files’ option, I prefer to stay public.
    4. Go to /admin/content/types/[type] to enable attachments.
    5. Go to /admin/user/access , give ‘add attachments’ permission to a role you prefer.
    6. Create a node, you will see the attachments section, done.

    known issue is the module can’t be compatible with double byte character like Chinese. It will lose the file name after uploaded the file.

June 24, 2008

提交网站至Google搜索引擎

Filed under: 1.2 Web开发 — Eric Tou @ 6:31 pm
Tags: , , ,

    After you published your website, Submit your website to search engine is a good idea to help your visitor find you. Firstly, of course my favorite Google.

    Through this url, you can submit the URL of your website to Google search engine, and then the GoogleBot will index the entire website.
    But that’s not enough, Through Webmaster Tools, you can submit a XML Sitemap of your website and use tools to increase your site’s visibility on Google.
    Why? Read <What is a Sitemap file and why should I have one>

    How? Manually create a sitemap file for a dynamic cms system like drupal is impossible, a mature cms always has its solution:
XML Sitemap module (replaced the old Google Sitemap from Drupal 5), can automatically create a site map which support Google, Yahoo, Windows Live, Ask engines.

    After installed and enabled this module, fill the location of the Sitemap file in Webmaster Tools like http://{hostname}/sitemap.xml , Done.

June 23, 2008

为网站添加Google Analytics

Filed under: 1.2 Web开发 — Eric Tou @ 6:57 pm
Tags: , ,

    Want to track visitors and traffic of  your website? Try Google Analytics, It’s free, and it can do more.

Steps:
    1. Use your google account to login to Analytics
    2. Click on Add Website Profile, A form displays
    3. Select Add a Profile for a New Domain
    4. Enter the URL of your site
    5. Select your country and time zone. Click Finish
    6. Analytics provides you two code blocks (the old one urchin.js and the new one ga.js) - to add to your site’s pages.
    7. Copy the code block (ga.js) to every page you want to add Analytics as below:
    <body>
        (Google Analytics Code Block is going to go here!!!)
    </body>

    Copy and paste the code block one by one? Don’t tell me you website doesn’t have a template. Today more and more people use content management system like Drupal, Joomla, Wordpress to publish their website and blog, some Web Hosts even provide 1-click installation, and you also can find one by youself at Open Source CMS.
    Once you walk on this way, things become quite easy. Basically, there will be a module/plugin which can be easily configurated.
    For example, i am using Durpal and this site are built by Drupal, all i need to do is go to the website, find the Google Analytics module, install it, configuration, fill a Goolge Analytics account number(in the code block, UA-xxxx-x), finish. and then DONE.

    Google Analytics need 24 hours to gether data, after one day, you can read the report.

WPMU Theme pack by WPMU-DEV.