Projet

Général

Profil

Révision 55670b15

Ajouté par Assos Assos il y a presque 10 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/honeypot/honeypot.module
91 91
  }
92 92
}
93 93

  
94
/**
95
 * Implements hook_trigger_info().
96
 */
97
function honeypot_trigger_info() {
98
  return array(
99
    'honeypot' => array(
100
      'honeypot_reject' => array(
101
        'label' => t('Honeypot rejection'),
102
      ),
103
    ),
104
  );
105
}
106

  
107
/**
108
 * Implements hook_rules_event_info()
109
 */
110
function honeypot_rules_event_info() {
111
  return array(
112
    'honeypot_reject' => array(
113
      'label' => t('Honeypot rejection'),
114
      'group' => t('Honeypot'),
115
      'variables' => array(
116
        'form_id' => array(
117
          'type' => 'text',
118
          'label' => t('Form ID of the form the user was disallowed from submitting.'),
119
        ),
120
        // Don't provide 'uid' in context because it is available as
121
        // site:current-user:uid.
122
        'type' => array(
123
          'type' => 'text',
124
          'label' => t('String indicating the reason the submission was blocked.'),
125
        ),
126
      ),
127
    ),
128
  );
129
}
130

  
94 131
/**
95 132
 * Build an array of all the protected forms on the site, by form_id.
96 133
 *
......
223 260
  // If not, throw an error.
224 261
  if (time() < ($honeypot_time + $time_limit)) {
225 262
    _honeypot_log($form_state['values']['form_id'], 'honeypot_time');
226
    $time_limit = honeypot_get_time_limit();
263
    // Get the time limit again, since it increases after first failure.
264
    $time_limit = honeypot_get_time_limit($form_state['values']);
227 265
    $form_state['values']['honeypot_time'] = time();
228 266
    form_set_error('', t('There was a problem with your form submission. Please wait @limit seconds and try again.', array('@limit' => $time_limit)));
229 267
  }
......
275 313
      ))->fetchField();
276 314
    }
277 315
    // Don't add more than 30 days' worth of extra time.
278
    $honeypot_time_limit = $honeypot_time_limit + (int) min($honeypot_time_limit + exp($number), 2592000);
316
    $honeypot_time_limit = (int) min($honeypot_time_limit + exp($number) - 1, 2592000);
279 317
    $additions = module_invoke_all('honeypot_time_limit', $honeypot_time_limit, $form_values, $number);
280 318
    if (count($additions)) {
281 319
      $honeypot_time_limit += array_sum($additions);
......
313 351

  
314 352
  // Allow other modules to react to honeypot rejections.
315 353
  module_invoke_all('honeypot_reject', $form_id, $user->uid, $type);
354

  
355
  // Trigger honeypot_reject action.
356
  if (module_exists('trigger')) {
357
    $aids = trigger_get_assigned_actions('honeypot_reject');
358
    $context = array(
359
      'group' => 'honeypot',
360
      'hook' => 'honeypot_reject',
361
      'form_id' => $form_id,
362
      // Do not provide $user in context because it is available as a global.
363
      'type' => $type,
364
    );
365
    // Honeypot does not act on any specific object.
366
    $object = NULL;
367
    actions_do(array_keys($aids), $object, $context);
368
  }
369

  
370
  // Trigger rules honeypot_reject event.
371
  if (module_exists('rules')) {
372
    rules_invoke_event('honeypot_reject', $form_id, $type);
373
  }
316 374
}

Formats disponibles : Unified diff