Availability
GateKeeper Plugin 0.1 is available from Blojsom3 Plugins download page
.
Description
GateKeeper Plugin fights comment spam by displaying a random question on the form which should be answered by the commenter. Questions can be configured from Blojsom context file, from the database, and from blog properties.
There are 3 question answer providers which could easily be enabled disabled by uncommenting / commenting out the beans in blojsom-plugins.xml file.
- ContextBlojsomQAProvider: question and answer pairs are specified in blojsom-plugins.xml, shared by all blogs within the same Blojsom installation.
- DatabaseBlojsomQAProvider: question and answer pairs are specified in database, shared by all blogs within the same Blojsom installation.
- PropertiesBlogQAProvider: question and answer pairs are specified as blog properties, specific for each blog (not shared).
Installation and Setup
Place gatekeeperplugin-x.y.jar in /WEB-INF/lib/ directory.
Add the following to /WEB-INF/classes/blojsom-plugins.xml file.
Note that the configuration below only enables context QA provider which allows you to set up question and answer pairs from blojsom-plugins.xml, whereas database and blog properties QA providers are commented out.
<bean id="gateKeeperPropertiesBlogQAProvider" class="com.mbledug.blojsom.plugin.gatekeeper.provider.PropertiesBlogQAProvider">
<constructor-arg><value>5</value></constructor-arg>
</bean>
<bean id="gateKeeperDatabaseBlojsomQAProvider" class="com.mbledug.blojsom.plugin.gatekeeper.provider.DatabaseBlojsomQAProvider">
<constructor-arg>
<bean class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg><ref bean="dataSource"/></constructor-arg>
</bean>
</constructor-arg>
</bean>
<bean id="gateKeeperContextBlojsomQAProvider" class="com.mbledug.blojsom.plugin.gatekeeper.provider.ContextBlojsomQAProvider">
<constructor-arg>
<list>
<bean class="com.mbledug.blojsom.plugin.gatekeeper.QA">
<constructor-arg><value>Please type the word 'eggtart' in the textfield below:</value></constructor-arg>
<constructor-arg><value>eggtart</value></constructor-arg>
</bean>
<bean class="com.mbledug.blojsom.plugin.gatekeeper.QA">
<constructor-arg><value>What number comes after 7?</value></constructor-arg>
<constructor-arg><value>8</value></constructor-arg>
</bean>
</list>
</constructor-arg>
</bean>
<bean id="gatekeeper" class="com.mbledug.blojsom.plugin.gatekeeper.GateKeeperPlugin" init-method="init" destroy-method="destroy">
<constructor-arg>
<bean class="com.mbledug.blojsom.plugin.gatekeeper.QAManager">
<constructor-arg>
<list>
<ref bean="gateKeeperContextBlojsomQAProvider"/>
<!-- Uncomment the bean below to enable database provider.
<ref bean="gateKeeperDatabaseBlojsomQAProvider"/>
-->
</list>
</constructor-arg>
<constructor-arg>
<list>
<!-- Uncomment the bean below to enable blog properties provider.
<ref bean="gateKeeperPropertiesBlogQAProvider"/>
-->
</list>
</constructor-arg>
</bean>
</constructor-arg>
</bean>
Modify HTML plugin chain from Blojsom administration menu plugins->mappings
Add "gatekeeper" to one of the flavor-based plugin chains. You must place it before "comment" within the chain, for example:
| html |
..., gatekeeper, ..., comment, ... |
Configure GateKeeper properties from Blojsom administration menu weblog settings->properties->set property
| Property |
Sample Value |
Description |
| gatekeeper-enabled |
true |
Enable GateKeeper Plugin. |
DatabaseBlojsomQAProvider Setup (optional, do this only if you want to use this provider)
Create gatekeeper table:
create table gatekeeper (
question varchar(512) not null,
answer varchar(128) not null
);
Add question and answer pair:
insert into gatekeeper values('Type the word \'eggtart\' in the textfield below:','eggtart');
Uncomment bean gateKeeperDatabaseBlojsomQAProvider in blojsom-plugins.xml .
PropertiesBlogQAProvider Setup (optional, do this only if you want to use this provider)
Add question and answer properties from Blojsom administration menu weblog settings->properties->set property
| Property |
Sample Value |
Description |
| gatekeeper-question-1 |
Type the word 'eggtart' below: |
First question. |
| gatekeeper-answer-1 |
eggtart |
First answer. |
| gatekeeper-question-2 |
What number comes after 7? |
Second question. |
| gatekeeper-answer-2 |
8 |
Second answer. |
The idea is to match gatekeeper-question-<number> to gatekeeper-answer-<number>, where <number> starts from 1 up to the value passed to bean constructor in blojsom-plugins.xml .
E.g. the configuration below
<bean id="gateKeeperPropertiesBlogQAProvider" class="com.mbledug.blojsom.plugin.gatekeeper.provider.PropertiesBlogQAProvider">
<constructor-arg><value>30</value></constructor-arg>
</bean>
will check for the existence of gatekeeper-question-1, gatekeeper-question-2, ..., gatekeeper-question-30, with each corresponding answer property.
Note that it's not mandatory to specify question and answer from 1 - 30. You're free to have question answer for any number you want between 1 to 30, e.g. if you specify question answer for number 3, 10, and 23, the provider will happily ignore the rest of the numbers between 1 - 30.
The provider will also ignore question without a corresponding answer property. E.g. gatekeeper-question-8 without gatekeeper-answer-8.
Usage
Add GateKeeper input textfield to your comment form:
E.g. for asual theme, add the code below to asual-entry.vm template.
<form id="commentform" method="post" action="$permalink">
...
<!-- START GATEKEEPER PLUGIN -->
<p>
<span class="section">$GATEKEEPER_QA.getQuestion()</span> (<span class="mandatory">*</span>)
<br/>
<input type="text" name="gatekeeper" size="10" maxlength="128"/><br/>
</p>
<!-- END GATEKEEPER PLUGIN -->
...
</form>