Commit 492e9c36 authored by RobLoach's avatar RobLoach

#176265 by Rob Loach: Drupal 6 Port - Still a bunch to work on.

parent 594ed963
; $Id$
name = CAPTCHA
description = "Base CAPTCHA module for adding challenges to arbitrary forms."
description = Base CAPTCHA module for adding challenges to arbitrary forms.
package = "Spam control"
core = 6.x
......@@ -2,49 +2,55 @@
// $Id$
/**
* Create tables on install
* Implementation of hook_schema().
*/
function captcha_schema() {
$schema['captcha_points'] = array(
'fields' => array(
'form_id' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE
),
'module' => array(
'type' => 'varchar',
'length' => 64,
'default' => NULL
),
'type' => array(
'type' => 'varchar',
'length' => 64,
'default' => NULL
),
),
'primary key' => array('form_id'),
);
return $schema;
}
/**
* Implementation of hook_install().
*/
function captcha_install() {
switch ($GLOBALS['db_type']) {
case 'mysql':
case 'mysqli':
db_query("CREATE TABLE {captcha_points} (
form_id varchar(128) NOT NULL,
module varchar(64) default NULL,
type varchar(64) default NULL,
PRIMARY KEY (form_id)
) /*!40100 DEFAULT CHARACTER SET utf8 */;"
);
$succes = TRUE;
break;
case 'pgsql':
db_query("CREATE TABLE {captcha_points} (
form_id varchar(128) NOT NULL,
module varchar(64) default NULL,
type varchar(64) default NULL,
PRIMARY KEY (form_id)
);"
);
$succes = TRUE;
break;
default:
drupal_set_message(t('Unsupported database.'), 'error');
$succes = FALSE;
}
if ($succes) {
// insert some defaults
$form_ids = array('comment_form', 'contact_mail_user', 'contact_mail_page',
'user_register', 'user_pass', 'user_login', 'user_login_block');
foreach ($form_ids as $form_id) {
db_query("INSERT INTO {captcha_points} (form_id, module, type) VALUES ('%s', NULL, NULL)", $form_id);
}
drupal_set_message(t('The installation of the captcha_points table and some default entries was successful'), 'status');
}
else {
drupal_set_message(t('The installation of the CAPTCHA module failed'), 'error');
drupal_install_schema('captcha');
// insert some defaults
$form_ids = array('comment_form', 'contact_mail_user', 'contact_mail_page',
'user_register', 'user_pass', 'user_login', 'user_login_block');
foreach ($form_ids as $form_id) {
db_query("INSERT INTO {captcha_points} (form_id, module, type) VALUES ('%s', NULL, NULL)", $form_id);
}
}
/**
* Implementation of hook_uninstall().
*/
function captcha_uninstall() {
drupal_uninstall_schema('captcha');
db_query("DELETE FROM {variable} WHERE name LIKE 'captcha_%'");
cache_clear_all('variables', 'cache');
}
/**
* Implementation of hook_update_N()
*/
......@@ -100,12 +106,3 @@ function captcha_update_2() {
}
return $items;
}
/**
* Remove tables on uninstall.
*/
function captcha_uninstall() {
db_query("DROP TABLE {captcha_points}");
db_query("DELETE FROM {variable} WHERE name LIKE 'captcha_%'");
cache_clear_all('variables', 'cache');
}
......@@ -11,7 +11,6 @@
*/
define('CAPTCHA_UNSOLVED_CHALLENGES_MAX', 20);
define('CAPTCHA_PERSISTENCE_SHOW_ALWAYS', 1);
define('CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL_PER_FORM', 2);
define('CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL', 3);
......@@ -19,8 +18,8 @@ define('CAPTCHA_PERSISTENCE_SKIP_ONCE_SUCCESSFUL', 3);
/**
* Implementation of hook_help().
*/
function captcha_help($section = 'admin/help#captcha') {
switch ($section) {
function captcha_help($path, $arg) {
switch ($path) {
case 'admin/help#captcha':
$output = '<p>'. t('"CAPTCHA" is an acronym for "Completely Automated Public Turing test to tell Computers and Humans Apart". It is typically a challenge-response test to determine whether the user is human. The CAPTCHA module is a tool to fight automated submission by malicious users (spamming) of for example comments forms, user registration forms, guestbook forms, etc. You can extend the desired forms with an additional challenge, which should be easy for a human to solve correctly, but hard enough to keep automated scripts and spam bots out.') .'</p>';
$output .= '<p>'. t('Note that the CAPTCHA module interacts with page caching (see <a href="!performancesettings">performance settings</a>). Because the challenge should be unique for each generated form, the caching of the page it appears on is prevented. Make sure that these forms do not appear on too many pages or you will lose much caching efficiency. For example, if you put a CAPTCHA on the user login block, which typically appears on each page for anonymous visitors, caching will practically be disabled. The comment submission forms are another example. In this case you should set the "%commentlocation" to "%separatepage" in <a href="!commentsettings">the comment settings</a> for better caching efficiency.' ,
......@@ -48,41 +47,36 @@ function captcha_help($section = 'admin/help#captcha') {
/**
* Implementation of hook_menu().
*/
function captcha_menu($may_cache) {
function captcha_menu() {
/* TODO - Update Menu and Form system */
$items = array();
if ($may_cache) {
// main configuration page of the basic CAPTCHA module
$items[] = array(
'path' => 'admin/user/captcha',
'title' => t('CAPTCHA'),
'description' => t('Administer how and where CAPTCHAs are used.'),
'callback' => 'captcha_admin',
'access' => user_access('administer CAPTCHA settings'),
'type' => MENU_NORMAL_ITEM,
);
// the default local task (needed when other modules want to offer
// alternative CAPTCHA types and their own configuration page as local task)
$items[] = array(
'path' => 'admin/user/captcha/captcha',
'title' => t('CAPTCHA'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -20,
);
$items[] = array(
'path' => 'admin/user/captcha/captcha/settings',
'title' => t('General settings'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
$items[] = array(
'path' => 'admin/user/captcha/captcha/examples',
'title' => t('Examples'),
'description' => t('An overview of the available challenge types with examples.'),
'callback' => 'captcha_examples',
'type' => MENU_LOCAL_TASK,
'weight' => 5,
);
}
// main configuration page of the basic CAPTCHA module
$items['admin/user/captcha'] = array(
'title' => t('CAPTCHA'),
'description' => t('Administer how and where CAPTCHAs are used.'),
'callback' => 'captcha_admin',
'access' => user_access('administer CAPTCHA settings'),
'type' => MENU_NORMAL_ITEM,
);
// the default local task (needed when other modules want to offer
// alternative CAPTCHA types and their own configuration page as local task)
$items['admin/user/captcha/captcha'] = array(
'title' => t('CAPTCHA'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -20,
);
$items['admin/user/captcha/captcha/settings'] = array(
'title' => t('General settings'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
$items['admin/user/captcha/captcha/examples'] = array(
'title' => t('Examples'),
'description' => t('An overview of the available challenge types with examples.'),
'callback' => 'captcha_examples',
'type' => MENU_LOCAL_TASK,
'weight' => 5,
);
return $items;
}
......@@ -158,7 +152,7 @@ function _captcha_get_description($lang_code=NULL) {
* the form_id.
* Otherwise: returns the general CAPTCHA configuration form.
*/
function captcha_admin($form_id='', $op='') {
function captcha_admin($form_id = '', $op = '') {
// if $form_id and action $op given: do the action
if ($form_id) {
switch ($op) {
......@@ -217,6 +211,7 @@ function captcha_admin_settings() {
$captcha_types = _captcha_available_challenge_types();
$result = db_query("SELECT * FROM {captcha_points} ORDER BY form_id");
while ($captcha_point = db_fetch_object($result)) {
dvm($captcha_point);
$form['captcha_types'][$captcha_point->form_id]['form_id'] = array(
'#value' => $captcha_point->form_id,
);
......@@ -282,7 +277,7 @@ function captcha_admin_settings() {
// submit button
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
'#value' => t('Save'),
);
return $form;
}
......@@ -356,7 +351,7 @@ function captcha_captcha_point_settings_form($form_id) {
// submit button
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
'#value' => t('Save'),
);
// cancel button
$form['cancel'] = array(
......@@ -523,9 +518,9 @@ function captcha_form_alter($form_id, &$form) {
'#description' => t('The challenge "@type" (by module "@module") is enabled here for untrusted users: !edit, !disable or !general.', array(
'@type' => $captcha_point->type,
'@module' => $captcha_point->module,
'!edit' => l(t('edit challenge type'), "admin/user/captcha/$form_id", array(), drupal_get_destination()),
'!disable' => l(t('disable challenge'), "admin/user/captcha/$form_id/disable", array(), drupal_get_destination()),
'!general' => l(t('edit general challenge settings'), "admin/user/captcha"),
'!edit' => l(t('edit challenge type'), "admin/user/captcha/$form_id", array('query' => 'destination='. drupal_get_destination())),
'!disable' => l(t('disable challenge'), "admin/user/captcha/$form_id/disable", array('query' => 'destination='. drupal_get_destination())),
'!general' => l(t('edit general challenge settings'), 'admin/user/captcha'),
))
);
}
......@@ -533,7 +528,7 @@ function captcha_form_alter($form_id, &$form) {
$form['captcha'] = array(
'#type' => 'item',
'#title' => t('CAPTCHA administration'),
'#description' => l(t('Place a challenge here for untrusted users.'), "admin/user/captcha/$form_id/enable", array(), drupal_get_destination()),
'#description' => l(t('Place a challenge here for untrusted users.'), "admin/user/captcha/$form_id/enable", array('query' => 'destination='. drupal_get_destination())),
);
}
// Add pre_render function for placing the CAPTCHA just above the submit button
......@@ -709,7 +704,7 @@ function captcha_examples($module=NULL, $challenge=NULL) {
/**
* Default implementation of hook_captcha
*/
function captcha_captcha($op, $captcha_type='') {
function captcha_captcha($op, $captcha_type = '') {
switch ($op) {
case 'list':
return array('Math');
......
......@@ -65,6 +65,7 @@ name = "Foo CAPTCHA"
description = "The foo CAPTCHA requires the user to enter the word 'foo'."
package = "Spam control"
dependencies = captcha
core = 6.x
"""
......@@ -85,11 +86,10 @@ For our simple foo CAPTCHA module this would mean:
function foo_captcha_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'path' => 'admin/user/captcha/foo_captcha',
$items['admin/user/captcha/foo_captcha'] = array(
'title' => t('Foo CAPTCHA'),
'callback' => 'drupal_get_form',
'callback arguments' => array('foo_captcha_settings_form'),
'page callback' => 'drupal_get_form',
'page arguments' => array('foo_captcha_settings_form'),
'type' => MENU_LOCAL_TASK,
);
}
......@@ -113,8 +113,8 @@ For our simple foo CAPTCHA module this would mean:
/**
* Implementation of hook_help().
*/
function foo_captcha_help($section) {
switch ($section) {
function foo_captcha_help($path, $arg) {
switch ($path) {
case 'admin/user/captcha/foo_captcha':
return '<p>'. t('This is a very simple challenge, which requires users to enter "foo" in a textfield.') .'</p>';
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment