Posted by litrik on June 4, 2008 at 9:46am
| Project: | GeoNames |
| Version: | 6.x-1.1 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | SeroSero |
| Status: | closed (fixed) |
Issue Summary
The use of file_get_contents() causes problems on servers where allow_url_fopen is disabled in php.ini. The full error message is
warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /var/vwww/sites/all/modules/geonames/geonames.module on line 175.
Other modules have replaced their call to file_get_contents() by a call to drupal_http_request(). See #180101: Alternative for Dreamhost? (can't use file_get_contents) and #262815: file_get_contents and some hosts
I'll attach a patch later today.
Comments
#1
I actually fixed that for D6 last week, but haven't had time to commit yet;
< if (!$result && !$data) {
< $data = file_get_contents(geonames_service_url($service) . $querystring . '&app=drupal');
< if ($data == FALSE) {
---
> if (!$result && !$data) {
> $request = drupal_http_request(geonames_service_url($service) . $querystring . '&app=drupal');
> $data = $request->data;
> if (empty($data)) {
Those lines are probably the same in D5.
Sero
// Ah.. missed a few lines, rewritten to work for now -- will do it properly later...
#2
Yup, these are the same lines as in D5.
Be aware that the original $data variable is used a couple of times in that function. I decided to assign the result of the drupal_http_request() call to the existing $data variable to avoid problems.
Also, your empty() call should not have a "!".
BTW: this is tricky code to test because you only get there when caching is disabled.
Attached is my patch against HEAD, which should be straightforward to apply to D5 as well. The code works for me.
#3
Fixed in Drupal 6 current official stable release.
#4
Automatically closed -- issue fixed for two weeks with no activity.
#5
Why is this fix not in the latest 6.x dev version? Is it lost somewhere?