- Patch #270508 by paul.levvik and pwolanin: usability improvement: image toolkits should not have to be copied.

merge-requests/26/head
Dries Buytaert 2008-07-08 01:08:15 +00:00
parent a4883506e3
commit ffdfefebbc
5 changed files with 25 additions and 16 deletions

View File

@ -1175,7 +1175,7 @@ function ip_address($reset = false) {
if (!isset($ip_address) || $reset) { if (!isset($ip_address) || $reset) {
$ip_address = $_SERVER['REMOTE_ADDR']; $ip_address = $_SERVER['REMOTE_ADDR'];
if (variable_get('reverse_proxy', 0)) { if (variable_get('reverse_proxy', 0)) {
if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) { if (array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER)) {
// If an array of known reverse proxy IPs is provided, then trust // If an array of known reverse proxy IPs is provided, then trust

View File

@ -21,11 +21,13 @@
* from this problem, but it requires the ISP to have installed additional * from this problem, but it requires the ISP to have installed additional
* software. * software.
* *
* Image toolkits are installed by copying the image.ToolkitName.inc file into * Image toolkits are discovered based on the associated module's
* Drupal's includes directory. The toolkit must then be enabled using the * hook_image_toolkits. Additionally the image toolkit include file
* admin/settings/image-toolkit form. * must be identified in the files array in the module.info file. The
* toolkit must then be enabled using the admin/settings/image-toolkit
* form.
* *
* Only one toolkit maybe selected at a time. If a module author wishes to call * Only one toolkit may be selected at a time. If a module author wishes to call
* a specific toolkit they can check that it is installed by calling * a specific toolkit they can check that it is installed by calling
* image_get_available_toolkits(), and then calling its functions directly. * image_get_available_toolkits(), and then calling its functions directly.
*/ */
@ -37,18 +39,17 @@
* An array of toolkit name => descriptive title. * An array of toolkit name => descriptive title.
*/ */
function image_get_available_toolkits() { function image_get_available_toolkits() {
$toolkits = file_scan_directory('includes', 'image\..*\.inc$'); // hook_image_toolkits returns an array of toolkit names.
$toolkits = module_invoke_all('image_toolkits');
$output = array(); $output = array();
foreach ($toolkits as $file => $toolkit) { foreach ($toolkits as $name) {
include_once "./$file"; $function = 'image_' . $name . '_info';
$function = str_replace('.', '_', $toolkit->name) . '_info'; if (drupal_function_exists($function)) {
if (function_exists($function)) {
$info = $function(); $info = $function();
$output[$info['name']] = $info['title']; $output[$info['name']] = $info['title'];
} }
} }
return $output; return $output;
} }
@ -63,11 +64,11 @@ function image_get_toolkit() {
if (!$toolkit) { if (!$toolkit) {
$toolkit = variable_get('image_toolkit', 'gd'); $toolkit = variable_get('image_toolkit', 'gd');
$toolkit_file = './includes/image.' . $toolkit . '.inc'; if (isset($toolkit) &&
if (isset($toolkit) && file_exists($toolkit_file)) { drupal_function_exists("image_" . $toolkit . "_resize")) {
include_once $toolkit_file;
} }
elseif (!image_gd_check_settings()) { elseif (!drupal_function_exists("image_gd_check_settings") ||
!image_gd_check_settings()) {
$toolkit = FALSE; $toolkit = FALSE;
} }
} }
@ -88,7 +89,7 @@ function image_get_toolkit() {
function image_toolkit_invoke($method, $params = array()) { function image_toolkit_invoke($method, $params = array()) {
if ($toolkit = image_get_toolkit()) { if ($toolkit = image_get_toolkit()) {
$function = 'image_' . $toolkit . '_' . $method; $function = 'image_' . $toolkit . '_' . $method;
if (function_exists($function)) { if (drupal_function_exists($function)) {
return call_user_func_array($function, $params); return call_user_func_array($function, $params);
} }
else { else {

View File

@ -6,3 +6,4 @@ version = VERSION
core = 7.x core = 7.x
files[] = system.module files[] = system.module
files[] = system.admin.inc files[] = system.admin.inc
files[] = image.gd.inc

View File

@ -2105,3 +2105,10 @@ function theme_meta_generator_html($version = VERSION) {
function theme_meta_generator_header($version = VERSION) { function theme_meta_generator_header($version = VERSION) {
drupal_set_header('X-Generator: Drupal ' . $version . ' (http://drupal.org)'); drupal_set_header('X-Generator: Drupal ' . $version . ' (http://drupal.org)');
} }
/**
* Implementation of hook_image_toolkits().
*/
function system_image_toolkits() {
return array('gd');
}