summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaslouski Yauheni2011-10-06 23:03:13 (GMT)
committer Maslouski Yauheni2011-10-06 23:03:13 (GMT)
commite207d118f9415edb83196dac65f2dc32fb971631 (patch)
tree47c4c59409d1082610895b7124e8c172b9a1324a
parent15621dd1f7a33d8efb51595206baae759d3e0bd6 (diff)
by Spleshka: random captcha was ported to 7.x
-rw-r--r--random_captcha_type/random_captcha_type.admin.inc7
-rw-r--r--random_captcha_type/random_captcha_type.inc54
-rw-r--r--random_captcha_type/random_captcha_type.info7
-rw-r--r--random_captcha_type/random_captcha_type.install8
-rw-r--r--random_captcha_type/random_captcha_type.module79
5 files changed, 80 insertions, 75 deletions
diff --git a/random_captcha_type/random_captcha_type.admin.inc b/random_captcha_type/random_captcha_type.admin.inc
index 8d437c2..0870737 100644
--- a/random_captcha_type/random_captcha_type.admin.inc
+++ b/random_captcha_type/random_captcha_type.admin.inc
@@ -1,6 +1,9 @@
<?php
-require_once('random_captcha_type.inc');
+/**
+ * @file
+ * Functionality and helper functions for RANDOM CAPTCHA administration.
+ */
/**
* Configuration form
@@ -25,7 +28,7 @@ function random_captcha_type_settings_form() {
* Implementation of form validation
*/
function random_captcha_type_settings_form_validate($form, &$form_state) {
- // at least 2 CAPTCHA types should be selected
+ // At least 2 CAPTCHA types should be selected
if (count(array_filter($form_state['values']['random_captcha_type_enabled_types'])) < 2) {
form_set_error('random_captcha_type_enabled_types', t('You should select at least two CAPTCHA types.'));
}
diff --git a/random_captcha_type/random_captcha_type.inc b/random_captcha_type/random_captcha_type.inc
deleted file mode 100644
index 7648d10..0000000
--- a/random_captcha_type/random_captcha_type.inc
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-
-/**
- * Function for getting all the possible CAPTCHA types to switch between.
- * For use as #options entry of a checkboxes widget.
- */
-function _random_captcha_type_get_all_types() {
- $captcha_types = array();
- foreach (module_implements('captcha') as $module) {
- // skip random_captcha_type module
- if ($module == 'random_captcha_type') {
- continue;
- }
- // get available types
- $result = module_invoke($module, 'captcha', 'list');
- if (is_array($result)) {
- foreach ($result as $type) {
- $captcha_types["$module/$type"] = "$type ($module)";
- }
- }
- }
- return $captcha_types;
-}
-
-/**
- * Function for getting the enabled CAPTCHA types.
- * Alternative of variable_get('random_captcha_type_enabled_types', ...) with
- * sensible default value.
- * For use as #default_value of checkboxes widget.
- * Returns an array mapping "$module/$type" to "$module/$type" for the enabled types
- */
-function _random_captcha_type_get_enabled_types() {
- $enabled_types = array();
- $_enabled_types = variable_get('random_captcha_type_enabled_types', NULL);
- if ($_enabled_types === NULL) {
- foreach (_random_captcha_type_get_all_types() as $key => $value) {
- $enabled_types[$key] = $key;
- }
- variable_set('random_captcha_type_enabled_types', $enabled_types);
- }
- else {
- foreach ($_enabled_types as $key => $value) {
- if ($value) {
- list($module, $type) = explode('/', $value);
- // check if type is still available
- $list = module_invoke($module, 'captcha', 'list');
- if ($list && in_array($type, $list)) {
- $enabled_types[$key] = $value;
- }
- }
- }
- }
- return $enabled_types;
-}
diff --git a/random_captcha_type/random_captcha_type.info b/random_captcha_type/random_captcha_type.info
index afca337..774f5dc 100644
--- a/random_captcha_type/random_captcha_type.info
+++ b/random_captcha_type/random_captcha_type.info
@@ -1,5 +1,6 @@
-name = "Random CAPTCHA type"
-description = "Provides a 'meta' CAPTCHA that randomly picks a CAPTCHA type."
+name = Random CAPTCHA type
+description = Provides a 'meta' CAPTCHA that randomly picks a CAPTCHA type.
package = "Spam control"
dependencies[] = captcha
-core = 6.x
+core = 7.x
+configure = admin/config/people/captcha/random_captcha_type
diff --git a/random_captcha_type/random_captcha_type.install b/random_captcha_type/random_captcha_type.install
index c8ba3a3..adf3b76 100644
--- a/random_captcha_type/random_captcha_type.install
+++ b/random_captcha_type/random_captcha_type.install
@@ -1,7 +1,13 @@
<?php
/**
- * On uninstall: remove module variables and clear variable cache
+ * @file
+ * Install, update and uninstall functions for the RANDOM CAPTCHA module.
+ */
+
+/**
+ * Implements hook_uninstall().
+ * On uninstall: remove module variables and clear variables cache
*/
function random_captcha_type_uninstall() {
db_query("DELETE FROM {variable} WHERE name LIKE 'random_captcha_type_%'");
diff --git a/random_captcha_type/random_captcha_type.module b/random_captcha_type/random_captcha_type.module
index 6b19598..24b7f58 100644
--- a/random_captcha_type/random_captcha_type.module
+++ b/random_captcha_type/random_captcha_type.module
@@ -1,26 +1,22 @@
<?php
/**
- * Implementation of a "meta CAPTCHA" which randomly picks a CAPTCHA type
- */
-
-/**
- * Implementation of hook_help().
+ * Implements hook_help().
*/
function random_captcha_type_help($path, $arg) {
switch ($path) {
- case 'admin/user/captcha/random_captcha_type':
- return '<p>'. t('This CAPTCHA type is a "meta" CAPTCHA type, which randomly picks one of the selected CAPTCHA types.') .'</p>';
+ case 'admin/config/people/captcha/random_captcha_type':
+ return '<p>' . t('This CAPTCHA type is a "meta" CAPTCHA type, which randomly picks one of the selected CAPTCHA types.') . '</p>';
}
}
/**
- * Implementation of hook_menu().
+ * Implements hook_menu().
*/
function random_captcha_type_menu() {
$items = array();
- // add an administration tab for random_captcha_type
- $items['admin/user/captcha/random_captcha_type'] = array(
+ // Add an administration tab for random_captcha_type
+ $items['admin/config/people/captcha/random_captcha_type'] = array(
'title' => 'Random CAPTCHA type',
'file' => 'random_captcha_type.admin.inc',
'page callback' => 'drupal_get_form',
@@ -32,12 +28,11 @@ function random_captcha_type_menu() {
}
/**
- * Implementation of hook_captcha
+ * Implements hook_captcha().
*/
-function random_captcha_type_captcha($op, $captcha_type='', $captcha_sid='') {
+function random_captcha_type_captcha($op, $captcha_type = '') {
switch ($op) {
case 'list':
- require_once('random_captcha_type.inc');
$enabled_types = _random_captcha_type_get_enabled_types();
if (count($enabled_types) < 2) {
return;
@@ -46,7 +41,6 @@ function random_captcha_type_captcha($op, $captcha_type='', $captcha_sid='') {
case 'generate':
if ($captcha_type == 'Random CAPTCHA type') {
- require_once('random_captcha_type.inc');
if (isset($_POST['random_captcha_type'])) {
// If this is a POST request, we're possibly in a validation phase
// so the CAPTCHA type should be the same as in the originating form
@@ -59,7 +53,7 @@ function random_captcha_type_captcha($op, $captcha_type='', $captcha_sid='') {
}
list($module, $type) = explode('/', $module_and_type);
// Call the generate CAPTCHA hook
- $captcha = module_invoke($module, 'captcha', 'generate', $type, $captcha_sid);
+ $captcha = module_invoke($module, 'captcha', 'generate', $type);
// Store the current CAPTCHA type so it can be recovered for
// regenerating the form in the validation phase
$captcha['form']['random_captcha_type'] = array(
@@ -70,3 +64,58 @@ function random_captcha_type_captcha($op, $captcha_type='', $captcha_sid='') {
}
}
}
+
+
+/**
+ * Function for getting all the possible CAPTCHA types to switch between.
+ * For use as #options entry of a checkboxes widget.
+ */
+function _random_captcha_type_get_all_types() {
+ $captcha_types = array();
+ foreach (module_implements('captcha') as $module) {
+ // Skip random_captcha_type module
+ if ($module == 'random_captcha_type') {
+ continue;
+ }
+ // Get available types
+ $result = module_invoke($module, 'captcha', 'list');
+ if (is_array($result)) {
+ foreach ($result as $type) {
+ $captcha_types["$module/$type"] = "$type ($module)";
+ }
+ }
+ }
+ return $captcha_types;
+}
+
+/**
+ * Function for getting the enabled CAPTCHA types.
+ * Alternative of variable_get('random_captcha_type_enabled_types', ...) with
+ * sensible default value.
+ * For use as #default_value of checkboxes widget.
+ * Returns an array mapping "$module/$type" to "$module/$type" for the enabled types
+ */
+function _random_captcha_type_get_enabled_types() {
+ $enabled_types = array();
+ $_enabled_types = variable_get('random_captcha_type_enabled_types', NULL);
+ if ($_enabled_types === NULL) {
+ foreach (_random_captcha_type_get_all_types() as $key => $value) {
+ $enabled_types[$key] = $key;
+ }
+ variable_set('random_captcha_type_enabled_types', $enabled_types);
+ }
+ else {
+ foreach ($_enabled_types as $key => $value) {
+ if ($value) {
+ list($module, $type) = explode('/', $value);
+ // Check if type is still available
+ $list = module_invoke($module, 'captcha', 'list');
+ if ($list && in_array($type, $list)) {
+ $enabled_types[$key] = $value;
+ }
+ }
+ }
+ }
+ return $enabled_types;
+}
+