Commit b473fc58 authored by soxofaan's avatar soxofaan
Browse files

various drupal 7 porting things (admin page works already)

parent cdd89fd9
......@@ -26,6 +26,6 @@ Conflicts/known issues:
error: unknown CAPTCHA session ID'.
Configuration:
The configuration page is at admin/user/captcha, here you can configure
The configuration page is at admin/config/people/captcha, here you can configure
the CAPTCHA module and enable challenges for the desired forms.
You can also tweak the image CAPTCHA to your liking.
......@@ -17,6 +17,7 @@
* and $type the name of the CAPTCHA type.
*/
function _captcha_available_challenge_types($add_special_options=TRUE) {
$captcha_types = array();
if ($add_special_options) {
$captcha_types['none'] = '[' . t('none') . ']';
$captcha_types['default'] = '[' . t('default challenge type') . ']';
......@@ -65,12 +66,11 @@ function captcha_admin_settings() {
);
$form['captcha_form_protection']['captcha_form_id_overview']['captcha_captcha_points'] = array();
$captcha_type_options = _captcha_available_challenge_types();
// TODO: make a wrapper for this query to make it a bit cleaner?
$result = db_query("SELECT * FROM {captcha_points} ORDER BY form_id");
while ($captcha_point = db_fetch_object($result)) {
$result = db_select('captcha_points', 'cp')->fields('cp')->orderBy('form_id')->execute();
foreach ($result as $captcha_point) {
$form['captcha_form_protection']['captcha_form_id_overview']['captcha_captcha_points'][$captcha_point->form_id] = array();
$form['captcha_form_protection']['captcha_form_id_overview']['captcha_captcha_points'][$captcha_point->form_id]['form_id'] = array(
'#value' => $captcha_point->form_id,
'#markup' => $captcha_point->form_id,
);
// Select widget for CAPTCHA type.
if (isset($captcha_point->module) && $captcha_point->module) {
......@@ -89,8 +89,8 @@ function captcha_admin_settings() {
);
// Additional operations.
$form['captcha_form_protection']['captcha_form_id_overview']['captcha_captcha_points'][$captcha_point->form_id]['operations'] = array(
'#value' => implode(", ", array(
l(t('delete'), "admin/user/captcha/captcha/captcha_point/{$captcha_point->form_id}/delete"),
'#markup' => implode(", ", array(
l(t('delete'), "admin/config/people/captcha/captcha/captcha_point/{$captcha_point->form_id}/delete"),
))
);
}
......@@ -189,7 +189,7 @@ function captcha_admin_settings() {
$form['captcha_log_wrong_responses'] = array(
'#type' => 'checkbox',
'#title' => t('Log wrong responses'),
'#description' => t('Report information about wrong responses to the !log.', array('!log' => l(t('log'), 'admin/reports/dblog'))),
'#description' => t('Report information about wrong responses to the <a href="!dblog">log</a>.', array('!dblog' => url('admin/reports/dblog'))),
'#default_value' => variable_get('captcha_log_wrong_responses', FALSE),
);
......@@ -205,7 +205,8 @@ function captcha_admin_settings() {
/**
* Custom theme function for a table of (form_id -> CAPTCHA type) settings
*/
function theme_captcha_admin_settings_captcha_points($form) {
function theme_captcha_admin_settings_captcha_points($variables) {
$form = $variables['form'];
$header = array('form_id', t('Challenge type'), t('Operations'));
$rows = array();
// Existing CAPTCHA points.
......@@ -223,7 +224,7 @@ function theme_captcha_admin_settings_captcha_points($form) {
$row[] = '';
$rows[] = $row;
$output = theme('table', $header, $rows);
$output = theme('table', array('header' => $header, 'rows' => $rows));
return $output;
}
......@@ -352,7 +353,7 @@ function captcha_point_admin_form($form_state, $captcha_point_form_id=NULL) {
'#options' => _captcha_available_challenge_types(),
);
// redirect to general CAPTCHA settings page after submission
$form['#redirect'] = 'admin/user/captcha';
$form['#redirect'] = 'admin/config/people/captcha';
// submit button
$form['submit'] = array(
'#type' => 'submit',
......@@ -403,7 +404,7 @@ function captcha_point_disable_confirm(&$form_state, $captcha_point_form_id, $de
$message = t('Are you sure you want to disable the CAPTCHA for form_id %form_id?', array('%form_id' => $captcha_point_form_id));
$yes = t('Disable');
}
return confirm_form($form, $message, 'admin/user/captcha/captcha', '', $yes);
return confirm_form($form, $message, 'admin/config/people/captcha/captcha', '', $yes);
}
/**
......@@ -420,7 +421,7 @@ function captcha_point_disable_confirm_submit($form, &$form_state) {
captcha_set_form_id_setting($captcha_point_form_id, 'none');
drupal_set_message(t('Disabled CAPTCHA for form %form_id.', array('%form_id' => $captcha_point_form_id)));
}
$form_state['redirect'] = 'admin/user/captcha/captcha';
$form_state['redirect'] = 'admin/config/people/captcha/captcha';
}
/**
......@@ -466,7 +467,7 @@ function captcha_examples($form_state, $module, $challenge) {
'#title' => t('Challenge "%challenge" by module "%module"', array('%challenge' => $challenge, '%module' => $module)),
'challenge' => _captcha_generate_example_challenge($module, $challenge),
'more_examples' => array(
'#value' => l(t('10 more examples of this challenge.'), "admin/user/captcha/captcha/examples/$module/$challenge"),
'#value' => l(t('10 more examples of this challenge.'), "admin/config/people/captcha/captcha/examples/$module/$challenge"),
),
);
}
......
......@@ -19,25 +19,38 @@
* @return nothing
*/
function captcha_set_form_id_setting($form_id, $captcha_type) {
// Handle 'none'.
if ($captcha_type == 'none') {
db_query("DELETE FROM {captcha_points} WHERE form_id = '%s'", $form_id);
db_query("INSERT INTO {captcha_points} (form_id, module, type) VALUES ('%s', NULL, NULL)", $form_id);
db_merge('captcha_points')
->key(array('form_id' => $form_id))
->fields(array('module' => NULL, 'type' => NULL))
->execute();
}
// Handle 'default'.
elseif ($captcha_type == 'default') {
db_query("DELETE FROM {captcha_points} WHERE form_id = '%s'", $form_id);
db_query("INSERT INTO {captcha_points} (form_id, module, type) VALUES ('%s', NULL, '%s')", $form_id, 'default');
db_merge('captcha_points')
->key(array('form_id' => $form_id))
->fields(array('module' => NULL, 'type' => 'default'))
->execute();
}
// Handle NULL.
elseif ($captcha_type == NULL) {
db_query("DELETE FROM {captcha_points} WHERE form_id = '%s'", $form_id);
db_delete('captcha_points')->condition('form_id', $form_id)->execute();
}
// Handle a captcha_type object.
elseif (is_object($captcha_type) && isset($captcha_type->module) && isset($captcha_type->type)) {
db_query("DELETE FROM {captcha_points} WHERE form_id = '%s'", $form_id);
db_query("INSERT INTO {captcha_points} (form_id, module, type) VALUES ('%s', '%s', '%s')", $form_id, $captcha_type->module, $captcha_type->type);
db_merge('captcha_points')
->key(array('form_id' => $form_id))
->fields(array('module' => $captcha_type->module, 'type' => $captcha_type->type))
->execute();
}
// Handle a captcha_type string.
elseif (is_string($captcha_type) && substr_count($captcha_type, '/') == 1) {
list($module, $type) = explode('/', $captcha_type);
db_query("DELETE FROM {captcha_points} WHERE form_id = '%s'", $form_id);
db_query("INSERT INTO {captcha_points} (form_id, module, type) VALUES ('%s', '%s', '%s')", $form_id, $module, $type);
db_merge('captcha_points')
->key(array('form_id' => $form_id))
->fields(array('module' => $module, 'type' => $type))
->execute();
}
else {
drupal_set_message(t('Failed to set a CAPTCHA type for form %form_id: could not interpret value "@captcha_type"',
......@@ -57,11 +70,8 @@ function captcha_set_form_id_setting($form_id, $captcha_type) {
* or in the form 'captcha/Math'.
*/
function captcha_get_form_id_setting($form_id, $symbolic=FALSE) {
$result = db_query("SELECT module, type FROM {captcha_points} WHERE form_id = '%s'", $form_id);
if (!$result) {
return NULL;
}
$captcha_point = db_fetch_object($result);
$result = db_query("SELECT module, type FROM {captcha_points} WHERE form_id = :form_id", array(':form_id' => $form_id));
$captcha_point = $result->fetchObject();
if (!$captcha_point) {
$captcha_point = NULL;
}
......@@ -94,8 +104,19 @@ function captcha_get_form_id_setting($form_id, $symbolic=FALSE) {
*/
function _captcha_generate_captcha_session($form_id=NULL, $status=CAPTCHA_STATUS_UNSOLVED) {
global $user;
db_query("INSERT into {captcha_sessions} (uid, sid, ip_address, timestamp, form_id, solution, status, attempts) VALUES (%d, '%s', '%s', %d, '%s', '%s', %d, %d)", $user->uid, session_id(), ip_address(), REQUEST_TIME, $form_id, 'undefined', $status, 0);
$captcha_sid = db_last_insert_id('captcha_sessions', 'csid');
// Insert an entry and thankfully receive the value of the autoincrement field 'csid'.
$captcha_sid = db_insert('captcha_sessions')
->fields(array(
'uid' => $user->uid,
'sid' => session_id(),
'ip_address' => ip_address(),
'timestamp' => REQUEST_TIME,
'form_id' => $form_id,
'solution' => 'undefined',
'status' => $status,
'attempts' => 0,
))
->execute();
return $captcha_sid;
}
......@@ -106,7 +127,13 @@ function _captcha_generate_captcha_session($form_id=NULL, $status=CAPTCHA_STATUS
* @param $solution the new solution to associate with the given CAPTCHA session.
*/
function _captcha_update_captcha_session($captcha_sid, $solution) {
db_query("UPDATE {captcha_sessions} SET timestamp=%d, solution='%s' WHERE csid=%d", REQUEST_TIME, $solution, $captcha_sid);
db_update('captcha_sessions')
->condition('csid', $captcha_sid)
->fields(array(
'timestamp' => REQUEST_TIME,
'solution' => $solution,
))
->execute();
}
/**
......@@ -114,7 +141,7 @@ function _captcha_update_captcha_session($captcha_sid, $solution) {
* based on CAPTCHA session ID and user session info.
*/
function _captcha_required_for_user($captcha_sid, $form_id) {
$captcha_session_status = db_result(db_query("SELECT status FROM {captcha_sessions} WHERE csid = %d", $captcha_sid));
$captcha_session_status = db_query('SELECT status FROM {captcha_sessions} WHERE csid = :csid', array(':csid' => $captcha_sid))->fetchField();
$captcha_success_form_ids = isset($_SESSION['captcha_success_form_ids']) ? (array)($_SESSION['captcha_success_form_ids']) : array();
......@@ -148,7 +175,7 @@ function _captcha_get_description($lang_code=NULL) {
global $language;
$lang_code = isset($lang_code) ? $lang_code : $language->language;
// The hardcoded but localizable default.
$default = t('This question is for testing whether you are a human visitor and to prevent automated spam submissions.', array(), $lang_code);
$default = t('This question is for testing whether you are a human visitor and to prevent automated spam submissions.', array(), array('langcode' => $lang_code));
// Look up the configured CAPTCHA description or fall back on the (localized) default.
if (module_exists('locale')) {
$description = variable_get("captcha_description_$lang_code", $default);
......
......@@ -113,12 +113,18 @@ function captcha_install() {
$form_ids = array('comment_form', 'contact_mail_user', 'contact_mail_page',
'user_register', 'user_pass', 'user_login', 'user_login_block', 'forum_node_form');
foreach ($form_ids as $form_id) {
db_query("INSERT INTO {captcha_points} (form_id, module, type) VALUES ('%s', NULL, NULL)", $form_id);
db_insert('captcha_points')
->fields(array(
'form_id' => $form_id,
'module' => NULL,
'type' => NULL,
))
->execute();
}
// what to do after install?
drupal_set_message($t('You can now <a href="!captcha_admin">configure the CAPTCHA module</a> for your site.',
array('!captcha_admin' => url('admin/user/captcha'))), 'status');
array('!captcha_admin' => url('admin/config/people/captcha'))), 'status');
}
/**
......
......@@ -2,27 +2,29 @@
(function ($) {
// TODO: change this to Drupal.behaviors.captchaadmin = function (context) {}
$(document).ready(function(){
Drupal.behaviors.captchaAdmin = {
attach: function(context) {
// Add onclick handler to checkbox for adding a CAPTCHA description
// so that the textfields for the CAPTCHA description are hidden
// when no description should be added.
// @todo: div.form-item-captcha-description depends on theming, maybe
// it's better to add our own wrapper with id (instead of a class).
$("#edit-captcha-add-captcha-description").click(function() {
if ($("#edit-captcha-add-captcha-description").is(":checked")) {
// Show the CAPTCHA description textfield(s).
$("div.form-item-captcha-description").show('slow');
}
else {
// Hide the CAPTCHA description textfield(s).
$("div.form-item-captcha-description").hide('slow');
}
});
// Hide the CAPTCHA description textfields if option is disabled on page load.
if (!$("#edit-captcha-add-captcha-description").is(":checked")) {
$("div.form-item-captcha-description").hide();
}
}
// Add onclick handler to checkbox for adding a CAPTCHA description
// so that the textfields for the CAPTCHA description are hidden
// when no description should be added.
$("#edit-captcha-add-captcha-description").click(function() {
if ($("#edit-captcha-add-captcha-description").is(":checked")) {
// Show the CAPTCHA description textfield(s).
$("#edit-captcha-description-wrapper").show("slow");
}
else {
// Hide the CAPTCHA description textfield(s).
$("#edit-captcha-description-wrapper").hide("slow");
}
});
// Hide the CAPTCHA description textfields if option is disabled on page load.
if (!$("#edit-captcha-add-captcha-description").is(":checked")) {
$("#edit-captcha-description-wrapper").hide();
}
});
};
})(jQuery);
......@@ -39,9 +39,9 @@ function captcha_help($path, $arg) {
) . '</p>';
$output .= '<p>' . t('CAPTCHA is a trademark of Carnegie Mellon University.') . '</p>';
return $output;
case 'admin/user/captcha':
case 'admin/user/captcha/captcha':
case 'admin/user/captcha/captcha/settings':
case 'admin/config/people/captcha':
case 'admin/config/people/captcha/captcha':
case 'admin/config/people/captcha/captcha/settings':
$output = '<p>' . t('A CAPTCHA can be added to virtually each Drupal form. Some default forms are already provided in the form list, but arbitrary forms can be easily added and managed when the option "%adminlinks" is enabled.',
array('%adminlinks' => t('Add CAPTCHA administration links to forms'))) . '</p>';
$output .= '<p>' . t('Users with the "%skipcaptcha" <a href="@perm">permission</a> won\'t be offered a challenge. Be sure to grant this permission to the trusted users (e.g. site administrators). If you want to test a protected form, be sure to do it as a user without the "%skipcaptcha" permission (e.g. as anonymous user).',
......@@ -56,7 +56,7 @@ function captcha_help($path, $arg) {
function captcha_menu() {
$items = array();
// main configuration page of the basic CAPTCHA module
$items['admin/user/captcha'] = array(
$items['admin/config/people/captcha'] = array(
'title' => 'CAPTCHA',
'description' => 'Administer how and where CAPTCHAs are used.',
'file' => 'captcha.admin.inc',
......@@ -67,19 +67,19 @@ function captcha_menu() {
);
// 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(
$items['admin/config/people/captcha/captcha'] = array(
'title' => 'CAPTCHA',
'access arguments' => array('administer CAPTCHA settings'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -20,
);
$items['admin/user/captcha/captcha/settings'] = array(
$items['admin/config/people/captcha/captcha/settings'] = array(
'title' => 'General settings',
'access arguments' => array('administer CAPTCHA settings'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
$items['admin/user/captcha/captcha/examples'] = array(
$items['admin/config/people/captcha/captcha/examples'] = array(
'title' => 'Examples',
'description' => 'An overview of the available challenge types with examples.',
'file' => 'captcha.admin.inc',
......@@ -89,7 +89,7 @@ function captcha_menu() {
'type' => MENU_LOCAL_TASK,
'weight' => 5,
);
$items['admin/user/captcha/captcha/captcha_point'] = array(
$items['admin/config/people/captcha/captcha/captcha_point'] = array(
'title' => 'CAPTCHA point administration',
'file' => 'captcha.admin.inc',
'page callback' => 'captcha_point_admin',
......@@ -142,10 +142,10 @@ function captcha_requirements($phase) {
function captcha_theme() {
return array(
'captcha_admin_settings_captcha_points' => array(
'arguments' => array('form' => NULL),
'render element' => 'form',
),
'captcha' => array(
'arguments' => array('element' => NULL),
'render element' => 'element',
),
);
}
......@@ -156,19 +156,21 @@ function captcha_theme() {
* Remove old entries from captcha_sessions table.
*/
function captcha_cron() {
// remove challenges older than 1 day
db_query('DELETE FROM {captcha_sessions} WHERE timestamp < %d', REQUEST_TIME - 60*60*24);
// Remove challenges older than 1 day.
db_delete('captcha_sessions')
->condition('timestamp', REQUEST_TIME - 60*60*24, '<')
->execute();
}
/**
* Implementation of hook_elements().
*/
function captcha_elements() {
function captcha_element_info() {
// Define the CAPTCHA form element with default properties.
$captcha_element = array(
'#input' => TRUE,
'#process' => array('captcha_process'),
'#process' => array('captcha_element_process'),
// The type of challenge: e.g. 'default', 'none', 'captcha/Math', 'image_captcha/Image', ...
'#captcha_type' => 'default',
'#default_value' => '',
......@@ -189,7 +191,8 @@ function captcha_elements() {
/**
* Process callback for CAPTCHA form element.
*/
function captcha_process($element, $edit, &$form_state, $complete_form) {
function captcha_element_process($element, $edit, &$form_state, $complete_form) {
module_load_include('inc', 'captcha');
// Prevent caching of the page with CAPTCHA elements.
......@@ -339,7 +342,7 @@ function captcha_form_alter(&$form, &$form_state, $form_id) {
if ($captcha_point !== NULL && $captcha_point->type) {
$captcha_element['#title'] = t('CAPTCHA: challenge "@type" enabled', array('@type' => $captcha_point->type));
$captcha_element['#description'] = t('Untrusted users will see a CAPTCHA here (!settings).',
array('!settings' => l(t('general CAPTCHA settings'), 'admin/user/captcha'))
array('!settings' => l(t('general CAPTCHA settings'), 'admin/config/people/captcha'))
);
$captcha_element['challenge'] = array(
'#type' => 'item',
......@@ -347,8 +350,8 @@ function captcha_form_alter(&$form, &$form_state, $form_id) {
'#value' => t('"@type" by module "@module" (!change, !disable)', array(
'@type' => $captcha_point->type,
'@module' => $captcha_point->module,
'!change' => l(t('change'), "admin/user/captcha/captcha/captcha_point/$form_id", array('query' => drupal_get_destination())),
'!disable' => l(t('disable'), "admin/user/captcha/captcha/captcha_point/$form_id/disable", array('query' => drupal_get_destination())),
'!change' => l(t('change'), "admin/config/people/captcha/captcha/captcha_point/$form_id", array('query' => drupal_get_destination())),
'!disable' => l(t('disable'), "admin/config/people/captcha/captcha/captcha_point/$form_id/disable", array('query' => drupal_get_destination())),
)),
);
// Add an example challenge with solution.
......@@ -375,7 +378,7 @@ function captcha_form_alter(&$form, &$form_state, $form_id) {
else {
$captcha_element['#title'] = t('CAPTCHA: no challenge enabled');
$captcha_element['add_captcha'] = array(
'#value' => l(t('Place a CAPTCHA here for untrusted users.'), "admin/user/captcha/captcha/captcha_point/$form_id", array('query' => drupal_get_destination()))
'#markup' => l(t('Place a CAPTCHA here for untrusted users.'), "admin/config/people/captcha/captcha/captcha_point/$form_id", array('query' => drupal_get_destination()))
);
}
......@@ -496,8 +499,13 @@ function captcha_validate($element, &$form_state) {
list($posted_form_id, $posted_captcha_sid) = _captcha_get_posted_captcha_info($element, $form_state);
$csid = $posted_captcha_sid;
$solution = db_result(db_query('SELECT solution FROM {captcha_sessions} WHERE csid = %d AND status = %d', $csid, CAPTCHA_STATUS_UNSOLVED));
$solution = db_query(
'SELECT solution FROM {captcha_sessions} WHERE csid = :csid AND status = :status',
array(':csid' => $csid, ':status' => CAPTCHA_STATUS_UNSOLVED)
)
->fetchField();
// @todo: what is the result when there is no entry for the captcha_session? in D6 it was FALSE, what in D7?
if ($solution === FALSE) {
// Unknown challenge_id.
form_set_error('captcha', t('CAPTCHA validation error: unknown CAPTCHA session ID. Contact the site administrator if this problem persists.'));
......@@ -519,11 +527,18 @@ function captcha_validate($element, &$form_state) {
// Correct answer.
$_SESSION['captcha_success_form_ids'][$form_id] = $form_id;
// Record success.
db_query("UPDATE {captcha_sessions} SET status=%d, attempts=attempts+1 WHERE csid=%d", CAPTCHA_STATUS_SOLVED, $csid);
db_update('captcha_sessions')
->condition('csid', $csid)
->fields(array('status' => CAPTCHA_STATUS_SOLVED))
->expression('attempts', 'attempts + 1')
->execute();
}
else {
// Wrong answer.
db_query("UPDATE {captcha_sessions} SET attempts=attempts+1 WHERE csid=%d", $csid);
db_update('captcha_sessions')
->condition('csid', $csid)
->expression('attempts', 'attempts + 1')
->execute();
// set form error
form_set_error('captcha_response', t('The answer you entered for the CAPTCHA was not correct.'));
// update wrong response counter
......
......@@ -246,12 +246,12 @@ class CapchaAdminTestCase extends DrupalWebTestCase {
*/
function testAdminAccess() {
$this->drupalLogin($this->normal_user);
$this->drupalGet('admin/user/captcha');
$this->drupalGet('admin/config/people/captcha');
file_put_contents('tmp.simpletest.html', $this->drupalGetContent());
$this->assertText(t('Access denied'), 'Normal users should not be able to access the CAPTCHA admin pages', 'CAPTCHA');
$this->drupalLogin($this->admin_user);
$this->drupalGet('admin/user/captcha');
$this->drupalGet('admin/config/people/captcha');
$this->assertNoText(t('Access denied'), 'Admin users should be able to access the CAPTCHA admin pages', 'CAPTCHA');
}
......@@ -328,7 +328,7 @@ class CapchaAdminTestCase extends DrupalWebTestCase {
$edit = array(
'captcha_administration_mode' => TRUE,
);
$this->drupalPost('admin/user/captcha', $edit, 'Save configuration');
$this->drupalPost('admin/config/people/captcha', $edit, 'Save configuration');
// Create a node with comments enabled.
$node_settings = array(
......
......@@ -80,7 +80,7 @@ core = 6.x
More advanced CAPTCHA modules probably want some configuration page.
To integrate nicely with the base CAPTCHA module you should offer your
configuration page as a MENU_LOCAL_TASK menu entry under 'admin/user/captcha/'.
configuration page as a MENU_LOCAL_TASK menu entry under 'admin/config/people/captcha/'.
For our simple foo CAPTCHA module this would mean:
......@@ -91,7 +91,7 @@ For our simple foo CAPTCHA module this would mean:
function foo_captcha_menu($may_cache) {
$items = array();
if ($may_cache) {
$items['admin/user/captcha/foo_captcha'] = array(
$items['admin/config/people/captcha/foo_captcha'] = array(
'title' => t('Foo CAPTCHA'),
'page callback' => 'drupal_get_form',
'page arguments' => array('foo_captcha_settings_form'),
......@@ -120,7 +120,7 @@ For our simple foo CAPTCHA module this would mean:
*/
function foo_captcha_help($path, $arg) {
switch ($path) {
case 'admin/user/captcha/foo_captcha':
case 'admin/config/people/captcha/foo_captcha':
return '<p>'. t('This is a very simple challenge, which requires users to enter "foo" in a textfield.') .'</p>';
}
}
......
......@@ -32,11 +32,11 @@ function image_captcha_image($captcha_sid=NULL) {
// Send the image resource as an image file to the client.
$file_format = variable_get('image_captcha_file_format', IMAGE_CAPTCHA_FILE_FORMAT_JPG);
if ($file_format == IMAGE_CAPTCHA_FILE_FORMAT_JPG) {
drupal_set_header("Content-type: image/jpeg");
drupal_add_http_header('Content-Type', 'image/jpeg');
imagejpeg($image);
}
else {
drupal_set_header("Content-type: image/png");
drupal_add_http_header('Content-Type', 'image/png');
imagepng($image);
}
// Clean up the image resource.
......
<?php
// $Id$
// @todo: this is an old test file, can it be removed or is there still some stuff that needs porting?
/**
* @file Tests for the CAPTCHA administration.
*/
......
Supports Markdown
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