Project

General

Profile

Revision 2c8c2b87

Added by Assos Assos about 9 years ago

Weekly update of contrib modules

View differences:

drupal7/sites/all/modules/honeypot/honeypot.module
142 142
      $forms = $cache->data;
143 143
    }
144 144
    else {
145
      $forms = array();
145 146
      // Look up all the honeypot forms in the variables table.
146 147
      $result = db_query("SELECT name FROM {variable} WHERE name LIKE 'honeypot_form_%'")->fetchCol();
147 148
      // Add each form that's enabled to the $forms array.
......
185 186
    // Get the element name (default is generic 'url').
186 187
    $honeypot_element = variable_get('honeypot_element_name', 'url');
187 188

  
189
    // Add 'autocomplete="off"' if configured.
190
    $attributes = array();
191
    if (variable_get('honeypot_autocomplete_attribute', 1)) {
192
      $attributes = array('autocomplete' => 'off');
193
    }
194

  
188 195
    // Build the honeypot element.
189 196
    $honeypot_class = $honeypot_element . '-textfield';
190 197
    $form[$honeypot_element] = array(
......
192 199
      '#title' => t('Leave this field blank'),
193 200
      '#size' => 20,
194 201
      '#weight' => 100,
195
      '#attributes' => array('autocomplete' => 'off'),
202
      '#attributes' => $attributes,
196 203
      '#element_validate' => array('_honeypot_honeypot_validate'),
197 204
      '#prefix' => '<div class="' . $honeypot_class . '">',
198 205
      '#suffix' => '</div>',
199
      // Hide honeypot.
206
      // Hide honeypot using CSS.
200 207
      '#attached' => array(
201 208
        'css' => array(
202
          '.' . $honeypot_class . ' { display: none !important; }' => array('type' => 'inline'),
209
          'data' => variable_get('file_public_path', conf_path() . '/files') . '/honeypot/honeypot.css',
203 210
        ),
204 211
      ),
205 212
    );
......
372 379
    rules_invoke_event('honeypot_reject', $form_id, $type);
373 380
  }
374 381
}
382

  
383
/**
384
 * Create CSS file for Honeypot.
385
 */
386
function honeypot_create_css($element_name) {
387
  $path = 'public://honeypot';
388

  
389
  if (!file_prepare_directory($path, FILE_CREATE_DIRECTORY)) {
390
    drupal_set_message(t('Unable to create Honeypot CSS directory, %path. Check the permissions on your files directory.', array('%path' => file_uri_target($path))), 'error');
391
  }
392
  else {
393
    $filename = $path . '/honeypot.css';
394
    $data = '.' . $element_name . '-textfield { display: none !important; }';
395
    file_unmanaged_save_data($data, $filename, FILE_EXISTS_REPLACE);
396
  }
397
}

Also available in: Unified diff