Showing
1 changed file
with
45 additions
and
0 deletions
patch/captcha/captcha_points_cache.patch
0 → 100644
| 1 | +diff --git a/captcha.inc b/captcha.inc | ||
| 2 | +index 4dc6f82..eb8b584 100644 | ||
| 3 | +--- a/captcha.inc | ||
| 4 | ++++ b/captcha.inc | ||
| 5 | +@@ -64,6 +64,7 @@ function captcha_set_form_id_setting($form_id, $captcha_type) { | ||
| 6 | + 'warning' | ||
| 7 | + ); | ||
| 8 | + } | ||
| 9 | ++ cache_clear_all('captcha_points:' . $form_id,'cache_captcha'); | ||
| 10 | + } | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | +@@ -82,18 +83,21 @@ function captcha_set_form_id_setting($form_id, $captcha_type) { | ||
| 14 | + * or in the form 'captcha/Math'. | ||
| 15 | + */ | ||
| 16 | + function captcha_get_form_id_setting($form_id, $symbolic = FALSE) { | ||
| 17 | +- // Fetch setting from database. | ||
| 18 | +- if (module_exists('ctools')) { | ||
| 19 | +- ctools_include('export'); | ||
| 20 | +- $object = ctools_export_load_object('captcha_points', 'names', array($form_id)); | ||
| 21 | +- $captcha_point = array_pop($object); | ||
| 22 | +- } | ||
| 23 | +- else { | ||
| 24 | +- $result = db_query("SELECT module, captcha_type FROM {captcha_points} WHERE form_id = :form_id", | ||
| 25 | +- array(':form_id' => $form_id)); | ||
| 26 | +- $captcha_point = $result->fetchObject(); | ||
| 27 | +- } | ||
| 28 | ++ | ||
| 29 | ++ $cache_key = 'captcha_points:' . $form_id; | ||
| 30 | + | ||
| 31 | ++ $cache = cache_get($cache_key,'cache_captcha'); | ||
| 32 | ++ $captcha_point = false; | ||
| 33 | ++ if($cache && !empty($cache->data)){ | ||
| 34 | ++ $captcha_point = $cache->data; | ||
| 35 | ++ }else{ | ||
| 36 | ++ $captcha_points = captcha_get_captcha_points(); | ||
| 37 | ++ if(isset($captcha_points[$form_id])){ | ||
| 38 | ++ $captcha_point = $captcha_points[$form_id]; | ||
| 39 | ++ cache_set($cache_key,$captcha_point,'cache_captcha',CACHE_PERMANENT); | ||
| 40 | ++ } | ||
| 41 | ++ } | ||
| 42 | ++ | ||
| 43 | + // If no setting is available in database for the given form, | ||
| 44 | + // but 'captcha_default_challenge_on_nonlisted_forms' is enabled, pick the default type anyway. | ||
| 45 | + if (!$captcha_point && variable_get('captcha_default_challenge_on_nonlisted_forms', FALSE)) { |
Please
register
or
login
to post a comment