first import
This commit is contained in:
339
sites/all/modules/geocoder/LICENSE.txt
Normal file
339
sites/all/modules/geocoder/LICENSE.txt
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
52
sites/all/modules/geocoder/README.txt
Normal file
52
sites/all/modules/geocoder/README.txt
Normal file
@@ -0,0 +1,52 @@
|
||||
(
|
||||
( ( ( )\ ) ( (
|
||||
)\))( ))\ ( ( ( (()/( ))\ )(
|
||||
((_))\ /((_))\ )\ )\ ((_))((_|()\
|
||||
(()(_|_)) ((_) ((_|(_) _| (_)) ((_)
|
||||
/ _` |/ -_) _ \/ _/ _ \/ _` / -_)| '_|
|
||||
\__, |\___\___/\__\___/\__,_\___||_|
|
||||
|___/
|
||||
|
||||
CONTENTS OF THIS FILE
|
||||
---------------------
|
||||
|
||||
* About Geocoder
|
||||
* Install
|
||||
* Configure
|
||||
* Credits
|
||||
|
||||
ABOUT GEOCODER
|
||||
--------------
|
||||
|
||||
Geocoder is a Drupal 7 module that will extract geographical data (geocode) from just about anything you throw at it such as addresses, GPX files, Geotags from EXIF data in photos, and KML files.
|
||||
|
||||
A convenient way to allow users to enter an address and have it automatically geocoded is to use it in combination with the Addressfield (http://drupal.org/project/addressfield) and Geofield (http://drupal.org/project/geofield) modules.
|
||||
|
||||
Geocoder uses the external geocoding services from Google, Yahoo and Yandex.
|
||||
|
||||
Here you find great documentation on Geocoder: http://drupal.org/node/1355780
|
||||
|
||||
INSTALL
|
||||
-------
|
||||
|
||||
Install and enable the Geocoder module and its required modules geoPHP (http://drupal.org/project/geophp) and Chaos tool suite (http://drupal.org/project/ctools) in the usual way. Install and enable the optional modules Addressfield and Geofield.
|
||||
Learn more about installing Drupal modules: http://drupal.org/documentation/install/modules-themes/modules-7
|
||||
|
||||
CONFIGURE
|
||||
---------
|
||||
|
||||
Assign the necessary permissions at /admin/people/permissions#module-geocoder
|
||||
|
||||
If you have enabled the modules Addressfield and Geofield you can start using Geocoder in a content type, e.g., an event.
|
||||
|
||||
Add a new address field by going to /admin/structure/types, choosing the desired content type and opening the "Manage fields" tab. Add a "Postal address" field and configure the field. Add a geofield and select "Geocode from another field" as widget. In the settings for the geofield you can now choose the source field to geocode from. You can also choose which geocoding service (Google et cetera) to use and configure these services.
|
||||
|
||||
Now you have a place where Geocoder can store its result (geofield) and the input to the geocode operation (addressfield). You can then use /project/openlayers">OpenLayers</a> to map the geofields.
|
||||
|
||||
Note: you can use Geocoder in any entity such as a user, a taxonomy term or a comment.
|
||||
|
||||
CREDITS
|
||||
-------
|
||||
|
||||
Geocoder was crafted by cspiker, phayes, henryblyth, jeff h, Les Lim, mikeytown2, fago, patrickavella & michaelfavia
|
||||
|
44
sites/all/modules/geocoder/geocoder.admin.inc
Normal file
44
sites/all/modules/geocoder/geocoder.admin.inc
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Settings form.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module settings page.
|
||||
*/
|
||||
function geocoder_admin_settings($form, &$form_state) {
|
||||
$geocoder_settings= variable_get("geocoder_settings", array());
|
||||
$form['geocoder_apikey_yahoo'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Yahoo PlaceFinder API Key'),
|
||||
'#description' => t('You can obtain a Yahoo PlaceFinder consumer key at') . ' ' . 'http://developer.yahoo.com/geo/placefinder/',
|
||||
'#default_value' => empty($geocoder_settings['geocoder_apikey_yahoo']) ? '' : $geocoder_settings['geocoder_apikey_yahoo'],
|
||||
'#required' => FALSE,
|
||||
);
|
||||
|
||||
$form['geocoder_apikey_yandex'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Yandex Maps API Key'),
|
||||
'#description' => t('You can obtain a Yandex API Key at ') . 'http://api.yandex.ru/maps/getkey.xml',
|
||||
'#default_value' => empty($geocoder_settings['geocoder_apikey_yandex']) ? '' : $geocoder_settings['geocoder_apikey_yandex'],
|
||||
'#required' => FALSE,
|
||||
);
|
||||
|
||||
$form['#submit'][] = 'geocoder_admin_settings_submit';
|
||||
return system_settings_form($form);
|
||||
}
|
||||
|
||||
function geocoder_admin_settings_validate($form_id, $form_values) {
|
||||
if (!empty($form_values['values']['geocoder_apikey_yahoo']) && preg_match("/[^A-Za-z0-9\\-]/", trim($form_values['values']['geocoder_apikey_yahoo']))) {
|
||||
form_set_error('geocoder_apikey_yahoo', t('Yahoo API keys are alpha numeric and dashes only.'));
|
||||
}
|
||||
}
|
||||
|
||||
function geocoder_admin_settings_submit($form, &$form_state) {
|
||||
$geocoder_settings= variable_get("geocoder_settings", array());
|
||||
$geocoder_settings['geocoder_apikey_yahoo'] = trim($form_state['values']['geocoder_apikey_yahoo']);
|
||||
$geocoder_settings['geocoder_apikey_yandex'] = trim($form_state['values']['geocoder_apikey_yandex']);
|
||||
variable_set("geocoder_settings", $geocoder_settings);
|
||||
}
|
42
sites/all/modules/geocoder/geocoder.admin.js
Normal file
42
sites/all/modules/geocoder/geocoder.admin.js
Normal file
@@ -0,0 +1,42 @@
|
||||
(function ($) {
|
||||
|
||||
Drupal.behaviors.geocoderWidgetSettings = {
|
||||
attach: function (context, settings) {
|
||||
$(':input[name="instance[widget][settings][geocoder_field]"]', context).once('geofield_widget_settings', function () {
|
||||
// When the geocoder_field field is changed, update the geocoder_handler options.
|
||||
$(this).change(function() {
|
||||
var field = $(this).val();
|
||||
var field_type = settings.geocoder_widget_settings.types[field];
|
||||
var valid_handlers = settings.geocoder_widget_settings.handlers[field_type];
|
||||
$(':input[name="instance[widget][settings][geocoder_handler]"] option', context).each(function () {
|
||||
var handler_type = $(this).val();
|
||||
if (geocoder_admin_handler_in_array(handler_type, valid_handlers)) {
|
||||
$(this).removeAttr('disabled').show();
|
||||
}
|
||||
else {
|
||||
$(this).attr('disabled', 'disabled').hide();
|
||||
}
|
||||
});
|
||||
|
||||
// If the currently selected handler is not valid, set it to the first valid handler.
|
||||
// Trigger a change event so that depdendent fields will update.
|
||||
if (!geocoder_admin_handler_in_array($(':input[name="instance[widget][settings][geocoder_handler]"]').val(), valid_handlers)) {
|
||||
$('#:input[name="instance[widget][settings][geocoder_handler]"]').val(valid_handlers[0]).trigger('change');
|
||||
}
|
||||
});
|
||||
|
||||
function geocoder_admin_handler_in_array(needle, haystack) {
|
||||
var length = haystack.length;
|
||||
for(var i = 0; i < length; i++) {
|
||||
if(haystack[i] == needle) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
// Trigger an initial change event to initialize the dependent field.
|
||||
$(this).trigger('change');
|
||||
}
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
|
64
sites/all/modules/geocoder/geocoder.drush.inc
Normal file
64
sites/all/modules/geocoder/geocoder.drush.inc
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implementation of hook_drush_command().
|
||||
*/
|
||||
function geocoder_drush_command() {
|
||||
$items = array();
|
||||
|
||||
// the key in the $items array is the name of the command.
|
||||
$items['geocoder-backfill'] = array(
|
||||
'callback' => 'geocoder_drush_backfill',
|
||||
'description' => "Geocodes all nodes that have a geocoder widget but no geodata.",
|
||||
'options' => array(
|
||||
'force' => 'Force the geocode to run, even if there is already geodata',
|
||||
),
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
function geocoder_drush_backfill() {
|
||||
$force_reload = drush_get_option('force');
|
||||
$all_entity_info = entity_get_info();
|
||||
foreach ($all_entity_info as $entity_type => $entity_info) {
|
||||
if ($entity_type == 'node') { //TODO: FIX THE LOGIC BELOW and implement for all entities
|
||||
if ($entity_info['fieldable']) {
|
||||
foreach ($entity_info['bundles'] as $bundle_name => $bundle_info) {
|
||||
foreach (field_info_instances($entity_type, $bundle_name) as $field_name => $field_instance) {
|
||||
$field_info = field_info_field($field_name);
|
||||
if ($field_instance['widget']['type'] === 'geocoder') {
|
||||
$entity_load = $entity_info['load hook'];
|
||||
|
||||
$query = db_select($entity_info['base table'])
|
||||
->fields($entity_info['base table'], array($entity_info['entity keys']['id']))
|
||||
->condition($entity_info['entity keys']['bundle'], $bundle_name);
|
||||
|
||||
$results = $query->execute();
|
||||
while ($id = $results->fetchField()) {
|
||||
$entity = $entity_load($id);
|
||||
$langcode = field_language($entity_type, $entity, $field_name);
|
||||
$items = field_get_items($entity_type, $entity, $field_name, $langcode);
|
||||
|
||||
if ($force_reload) {
|
||||
$entity->original = array();
|
||||
}
|
||||
|
||||
// Check for values and if there are no values, reload the entity
|
||||
if ($field_info['type'] == 'geofield') {
|
||||
if ($force_reload || (empty($items['wkt']) && empty($items['geom']))) node_save($entity); //TODO: fix for all entities
|
||||
}
|
||||
if ($field_info['type'] == 'location') {
|
||||
if ($force_reload || empty($items['latitude'])) node_save($entity); //TODO: fix for all entities
|
||||
}
|
||||
if ($field_info['type'] == 'geolocation') {
|
||||
if ($force_reload || empty($items['lat'])) node_save($entity); //TODO: fix for all entities
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
12
sites/all/modules/geocoder/geocoder.info
Normal file
12
sites/all/modules/geocoder/geocoder.info
Normal file
@@ -0,0 +1,12 @@
|
||||
name = Geocoder
|
||||
description = An API and widget to geocode various known data into other GIS data types.
|
||||
core = 7.x
|
||||
dependencies[] = geophp
|
||||
dependencies[] = ctools
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-11-18
|
||||
version = "7.x-1.2+4-dev"
|
||||
core = "7.x"
|
||||
project = "geocoder"
|
||||
datestamp = "1353201427"
|
||||
|
289
sites/all/modules/geocoder/geocoder.module
Normal file
289
sites/all/modules/geocoder/geocoder.module
Normal file
@@ -0,0 +1,289 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Module file for geocoder module.
|
||||
*/
|
||||
|
||||
include_once('geocoder.widget.inc');
|
||||
include_once('geocoder.services.inc');
|
||||
|
||||
/**
|
||||
* The Geocoder API call.
|
||||
*
|
||||
* Given a handler and data, geocode the data into a geometry object using the handler.
|
||||
*
|
||||
* @param string $handler
|
||||
* The geocoder handler to use. Call geocoder_handler_info() to get a list
|
||||
*
|
||||
* @param mixed $data
|
||||
* Data to be passed into the handler for geocoding. For example a address string.
|
||||
*
|
||||
* @param array $options
|
||||
* Additional options to pass to the handler. Exact key / values to pass depend on the handler.
|
||||
*
|
||||
* @param int $cache_type
|
||||
* (optional) The type of caching to use. Defaults to 2 (static and persistent)
|
||||
* 0 or FALSE is no-caching at all
|
||||
* 1 is static-cache but no persistent-cache
|
||||
* 2 is both static-cache AND persistent-cache
|
||||
*
|
||||
* @pram bool $cache_reset
|
||||
* (optional) Empty the static-cache and re-fill the persistent-cache. Defaults to FALSE.
|
||||
*
|
||||
* @return geometry
|
||||
* Returns a geoPHP geometry object. Generally a Point.
|
||||
* See http://drupal.org/project/geoPHP and https://github.com/phayes/geoPHP/wiki/API-Reference
|
||||
*
|
||||
* @example:
|
||||
* geocoder('google','4925 Gair Ave, Terrace, BC');
|
||||
* geocoder('google','New York City',array('geometry_type' => 'bounds'));
|
||||
*/
|
||||
function geocoder($handler, $data, $options = array(), $cache_type = 2, $cache_reset = FALSE) {
|
||||
ctools_include('plugins');
|
||||
static $static_cache = array();
|
||||
|
||||
if ($cache_reset) {
|
||||
$static_cache = array();
|
||||
}
|
||||
|
||||
if ($cache_type) {
|
||||
$cache_id = $handler . '_' . md5(serialize(array($data, $options)));
|
||||
if (!empty($static_cache[$cache_id])) {
|
||||
return $static_cache[$cache_id];
|
||||
}
|
||||
}
|
||||
|
||||
$processor = ctools_get_plugins('geocoder', 'geocoder_handler', $handler);
|
||||
$geometry = call_user_func($processor['callback'], $data, $options);
|
||||
|
||||
if ($cache_type) {
|
||||
$static_cache[$cache_id] = $geometry;
|
||||
}
|
||||
|
||||
return $geometry;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function geocoder_menu() {
|
||||
// Admin settings for the site.
|
||||
$items['admin/config/content/geocoder'] = array(
|
||||
'title' => 'Geocoder settings',
|
||||
'description' => 'Configuration for API keys.',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('geocoder_admin_settings'),
|
||||
'file' => 'geocoder.admin.inc',
|
||||
'access arguments' => array('administer site configuration'),
|
||||
'type' => MENU_NORMAL_ITEM, // optional
|
||||
);
|
||||
$items['geocoder/service/%'] = array(
|
||||
'title' => 'AJAX / AJAJ geocoding service',
|
||||
'description' => 'Provides basic callback for geocoding using JavaScript',
|
||||
'page callback' => 'geocoder_service_callback',
|
||||
'page arguments' => array(2),
|
||||
'type' => MENU_CALLBACK,
|
||||
'access arguments' => array(arg(2)),
|
||||
'access callback' => 'geocoder_service_check_perms',
|
||||
);
|
||||
return $items;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Geocoder Handler Information
|
||||
*
|
||||
* Return a list of all handlers that might geocode something for you.
|
||||
* Optionally you may pass a field-type and get back a list of
|
||||
* handlers that are compatible with that field.
|
||||
*/
|
||||
function geocoder_handler_info($field_type = NULL) {
|
||||
ctools_include('plugins');
|
||||
|
||||
static $handlers;
|
||||
if (!$handlers) {
|
||||
$handlers = ctools_get_plugins('geocoder', 'geocoder_handler');
|
||||
}
|
||||
if ($field_type) {
|
||||
$field_handlers = $handlers;
|
||||
foreach ($field_handlers as $i => $handler) {
|
||||
if (!isset($handler['field_types']) || !in_array($field_type, $handler['field_types'])) {
|
||||
unset($field_handlers[$i]);
|
||||
}
|
||||
}
|
||||
return $field_handlers;
|
||||
}
|
||||
return $handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch geocoder handler
|
||||
*
|
||||
* Given a name, fetch the full handler definition
|
||||
*/
|
||||
function geocoder_get_handler($handler_name) {
|
||||
$handlers = geocoder_handler_info();
|
||||
if (isset($handlers[$handler_name])) {
|
||||
return $handlers[$handler_name];
|
||||
}
|
||||
else return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get supported field types
|
||||
*
|
||||
* Get a list of supported field types along with the processors that support them
|
||||
*/
|
||||
function geocoder_supported_field_types() {
|
||||
$supported = array();
|
||||
|
||||
$processors = geocoder_handler_info();
|
||||
|
||||
foreach ($processors as $processor) {
|
||||
if (isset($processor['field_types'])) {
|
||||
foreach ($processor['field_types'] as $field_type) {
|
||||
$supported[$field_type][] = $processor['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $supported;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of hook_ctools_plugin_api().
|
||||
*/
|
||||
function geocoder_ctools_plugin_api() {
|
||||
return array('version' => 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_ctools_plugin_dierctory() to let the system know
|
||||
* we implement plugins.
|
||||
*/
|
||||
function geocoder_ctools_plugin_directory($module, $plugin) {
|
||||
return 'plugins/' . $plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_ctools_plugin_type
|
||||
*/
|
||||
function geocoder_ctools_plugin_type() {
|
||||
return array(
|
||||
'geocoder_handler' => array(),
|
||||
);
|
||||
}
|
||||
|
||||
// These functions have to do with providing AJAX / AHAH
|
||||
// service functionality so that users can make use of
|
||||
// geocoder interactively via JavaScript.
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*
|
||||
* We define permissions for accessing geocoder over AJAX / services.
|
||||
* There is one global permission which gives access to everything,
|
||||
* and one permission per handler. The site-administrator can therefore
|
||||
* fine tune which handlers are accessible. Note that to use AJAX with
|
||||
* geocoder these permissions need to be set.
|
||||
*/
|
||||
function geocoder_permission() {
|
||||
$handler_info = geocoder_handler_info();
|
||||
$perms = array(
|
||||
'geocoder_service_all_handlers' => array(
|
||||
'title' => t('Can use all Geocoder handlers through AJAX / service'),
|
||||
),
|
||||
);
|
||||
foreach ($handler_info as $name => $handler) {
|
||||
$perms['geocoder_service_handler_' . $name] = array(
|
||||
'title' => t('Can geocode using @handler through AJAX / service', array('@handler' => $handler['title'])),
|
||||
);
|
||||
}
|
||||
return $perms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Geocoder service check permissions
|
||||
*
|
||||
* Given a handler, check to see if the user has
|
||||
* permission to execute it via AJAX / services
|
||||
*/
|
||||
function geocoder_service_check_perms($handler) {
|
||||
return (user_access('geocoder_service_all_handlers') || user_access('geocoder_service_handler_' . $handler));
|
||||
}
|
||||
|
||||
/**
|
||||
* Page callback for AJAX / Geocoder service
|
||||
*
|
||||
* This service can be accessed at /geocoder/service/<handler>
|
||||
* and takes the query-parameter "data". Optinally a "output"
|
||||
* paramater may also be passed. "output" corresponds to
|
||||
* geoPHP output formats.
|
||||
*
|
||||
* Some examples:
|
||||
* /geocoder/service/google?data=4925 Gair Ave, Terrace, BC
|
||||
* /geocoder/service/wkt?data=POINT(10 10)
|
||||
* /geocoder/service/yahoo?data=94112&output=wkt
|
||||
*/
|
||||
function geocoder_service_callback($handler) {
|
||||
if (!isset($_GET['data'])) {
|
||||
throw new Exception(t('No data parameter found'));
|
||||
exit();
|
||||
}
|
||||
|
||||
$format = isset($_GET['output']) ? $_GET['output'] : 'json';
|
||||
|
||||
geophp_load();
|
||||
geocoder_service_check_request($handler, $format);
|
||||
$geom = geocoder($handler, $_GET['data']);
|
||||
|
||||
header('Content-Type: ' . geocoder_service_get_content_type($format));
|
||||
print $geom->out($format);
|
||||
exit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Content-Type for an output format
|
||||
*
|
||||
* Given an output format, this helper function passes
|
||||
* a compatible HTTP content-type to be placed in the
|
||||
* header.
|
||||
*/
|
||||
function geocoder_service_get_content_type($format) {
|
||||
$types = array(
|
||||
'json' => 'application/json',
|
||||
'kml' => 'application/xml',
|
||||
'georss' => 'application/xml',
|
||||
'gpx' => 'application/xml',
|
||||
'wkt' => 'text/plain',
|
||||
'wkb' => 'text/plain',
|
||||
'google_geocode' => 'text/plain',
|
||||
);
|
||||
return $types[$format];
|
||||
}
|
||||
|
||||
/**
|
||||
* Geocoder Service Check Request
|
||||
*
|
||||
* Check to make sure the request to the service is valid. This
|
||||
* checks to make sure the handler and the format exists, and
|
||||
* also checks permission
|
||||
*/
|
||||
function geocoder_service_check_request($handler, $format, $check_ac = TRUE) {
|
||||
if (!geocoder_get_handler($handler)) {
|
||||
drupal_set_message(t('Could not find handler @handler', array('@handler' => $handler)), 'error');
|
||||
drupal_not_found();
|
||||
exit();
|
||||
}
|
||||
if (($format && $format != 'default') && !in_array($format, array_keys(geoPHP::getAdapterMap()))) {
|
||||
throw new Exception(t('Could not find output-format @format', array('@format' => $format)), 'error');
|
||||
exit();
|
||||
}
|
||||
if (!geocoder_service_check_perms($handler)) {
|
||||
drupal_access_denied();
|
||||
exit();
|
||||
}
|
||||
}
|
92
sites/all/modules/geocoder/geocoder.services.inc
Normal file
92
sites/all/modules/geocoder/geocoder.services.inc
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* Implements hook_services_resources().
|
||||
*/
|
||||
function geocoder_services_resources() {
|
||||
return array(
|
||||
'geocoder' => array(
|
||||
'retrieve' => array(
|
||||
'help' => 'Geocode data',
|
||||
'file' => array('type' => 'inc', 'module' => 'geocoder', 'name' => 'geocoder.services'),
|
||||
'callback' => 'geocoder_services_geocode',
|
||||
'access callback' => 'geocoder_services_access',
|
||||
'access arguments append' => TRUE,
|
||||
'args' => array(
|
||||
array(
|
||||
'name' => 'handler',
|
||||
'type' => 'string',
|
||||
'description' => 'The geocoder handler to use - google, gpx, kml etc.',
|
||||
'source' => array('path' => '0'),
|
||||
'optional' => FALSE,
|
||||
),
|
||||
array(
|
||||
'name' => 'data',
|
||||
'type' => 'string',
|
||||
'description' => 'Value to geocode',
|
||||
'source' => array('param' => 'data'),
|
||||
'optional' => FALSE,
|
||||
),
|
||||
array(
|
||||
'name' => 'output',
|
||||
'type' => 'string',
|
||||
'description' => 'Output Format (GPX, WKT, etc.)',
|
||||
'source' => array('param' => 'output'),
|
||||
'optional' => TRUE,
|
||||
),
|
||||
),
|
||||
),
|
||||
'index' => array(
|
||||
'help' => 'List Geocoder Capabilities',
|
||||
'file' => array('type' => 'inc', 'module' => 'geocoder', 'name' => 'geocoder.services'),
|
||||
'callback' => 'geocoder_services_capabilities',
|
||||
'access callback' => 'geocoder_services_capabilities_ac', // Always returns TRUE
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
function geocoder_services_capabilities_ac() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function geocoder_services_access($handler, $data, $output) {
|
||||
if ($handler == 'default') {
|
||||
$handler == 'json';
|
||||
}
|
||||
return geocoder_service_check_perms($handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for geocoding service
|
||||
*
|
||||
* @param string $handler
|
||||
* @param string $data
|
||||
* @return object
|
||||
*/
|
||||
function geocoder_services_geocode($handler, $data, $format = 'default') {
|
||||
geophp_load();
|
||||
geocoder_service_check_request($handler, $format);
|
||||
|
||||
$geom = geocoder($handler, $data);
|
||||
if (!$format || $format == 'default') {
|
||||
$result = $geom->out('json');
|
||||
return json_decode($result);
|
||||
}
|
||||
else {
|
||||
return $geom->out($format);
|
||||
}
|
||||
}
|
||||
|
||||
function geocoder_services_capabilities() {
|
||||
geophp_load();
|
||||
|
||||
$handlers = array();
|
||||
foreach (geocoder_handler_info() as $hid => $handler) {
|
||||
$handlers[$hid] = $handler['title'] . ' - ' . $handler['description'];
|
||||
}
|
||||
|
||||
$object = new stdClass();
|
||||
$object->handlers = $handlers;
|
||||
$object->output = geoPHP::getAdapterMap();
|
||||
return $object;
|
||||
}
|
463
sites/all/modules/geocoder/geocoder.widget.inc
Normal file
463
sites/all/modules/geocoder/geocoder.widget.inc
Normal file
@@ -0,0 +1,463 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_field_widget_info().
|
||||
*/
|
||||
function geocoder_field_widget_info() {
|
||||
return array(
|
||||
'geocoder' => array(
|
||||
'label' => t('Geocode from another field'),
|
||||
'field types' => array('geofield', 'geolocation_latlng', 'location'),
|
||||
'behaviors' => array(
|
||||
'multiple values' => FIELD_BEHAVIOR_CUSTOM,
|
||||
'default value' => FIELD_BEHAVIOR_NONE,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements field_widget_settings_form().
|
||||
*/
|
||||
function geocoder_field_widget_settings_form($this_field, $instance) {
|
||||
$settings = $instance['widget']['settings'];
|
||||
|
||||
$entity_fields = field_info_instances($instance['entity_type'], $instance['bundle']);
|
||||
$all_fields = field_info_fields();
|
||||
$supported_field_types = geocoder_supported_field_types();
|
||||
$processors = geocoder_handler_info();
|
||||
$handlers_by_type = array();
|
||||
$field_types = array();
|
||||
$valid_fields = array();
|
||||
$available_handlers = array();
|
||||
|
||||
// Add in the title/name
|
||||
//@@TODO Do this programatically by getting entity_info
|
||||
switch ($instance['entity_type']) {
|
||||
case 'node':
|
||||
$all_fields['title'] = array(
|
||||
'field_name' => 'title',
|
||||
'type' => 'text',
|
||||
);
|
||||
|
||||
$entity_fields['title']['label'] = t('Title');
|
||||
break;
|
||||
|
||||
case 'taxonomy_term':
|
||||
$all_fields['name'] = array(
|
||||
'field_name' => 'name',
|
||||
'type' => 'text',
|
||||
);
|
||||
|
||||
$entity_fields['name']['label'] = t('Name');
|
||||
break;
|
||||
}
|
||||
|
||||
// Get a list of all valid fields that we both support and are part of this entity
|
||||
foreach ($all_fields as $field) {
|
||||
if (array_key_exists($field['field_name'], $entity_fields)) {
|
||||
if (in_array($field['type'], array_keys($supported_field_types)) && ($field['field_name'] != $this_field['field_name'])) {
|
||||
$valid_fields[$field['field_name']] = $entity_fields[$field['field_name']]['label'];
|
||||
foreach ($supported_field_types[$field['type']] as $handler) {
|
||||
$available_handlers[$handler] = $processors[$handler]['title'];
|
||||
$handlers_by_type[$field['type']][] = $handler;
|
||||
$field_types[$field['field_name']] = $field['type'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$form['geocoder_field'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Geocode from field'),
|
||||
'#default_value' => isset($settings['geocoder_field']) ? $settings['geocoder_field']: '',
|
||||
'#options' => $valid_fields,
|
||||
'#description' => t('Select which field you would like to geocode from.'),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
|
||||
$form['geocoder_handler'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Geocoder'),
|
||||
'#prefix' => '<div id="geocoder-handler-div">',
|
||||
'#suffix' => '</div>',
|
||||
'#default_value' => isset($settings['geocoder_handler']) ? $settings['geocoder_handler']: '',
|
||||
'#options' => $available_handlers,
|
||||
'#description' => t('Select which type of geocoding handler you would like to use'),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
|
||||
$form['handler_settings'] = array(
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
|
||||
// Add the handler settings forms
|
||||
foreach ($processors as $handler_id => $handler) {
|
||||
if (isset($handler['settings_callback']) || isset($handler['terms_of_service'])) {
|
||||
$default_values = isset($settings['handler_settings'][$handler_id]) ? $settings['handler_settings'][$handler_id] : array();
|
||||
$form['handler_settings'][$handler_id] = array();
|
||||
$form['handler_settings'][$handler_id]['#type'] = 'fieldset';
|
||||
$form['handler_settings'][$handler_id]['#attributes'] = array('class' => array('geocoder-handler-setting', 'geocoder-handler-setting-' . $handler_id));
|
||||
$form['handler_settings'][$handler_id]['#title'] = $handler['title'] . ' Settings';
|
||||
$form['handler_settings'][$handler_id]['#states'] = array(
|
||||
'visible' => array(
|
||||
':input[id="edit-instance-widget-settings-geocoder-handler"]' => array('value' => $handler_id),
|
||||
),
|
||||
);
|
||||
|
||||
if (isset($handler['terms_of_service'])) {
|
||||
$form['handler_settings'][$handler_id]['tos'] = array(
|
||||
'#type' => 'item',
|
||||
'#markup' => t('This handler has terms of service. Click the following link to learn more.') . ' ' . l($handler['terms_of_service'], $handler['terms_of_service']),
|
||||
);
|
||||
}
|
||||
|
||||
if (isset($handler['settings_callback'])) {
|
||||
$settings_callback = $handler['settings_callback'];
|
||||
$form['handler_settings'][$handler_id] = array_merge($form['handler_settings'][$handler_id], $settings_callback($default_values));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$form['delta_handling'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Multi-value input handling'),
|
||||
'#description' => t('Should geometries from multiple inputs be: <ul><li>Matched with each input (e.g. One POINT for each address field)</li><li>Aggregated into a single MULTIPOINT geofield (e.g. One MULTIPOINT polygon from multiple address fields)</li><li>Broken up into multiple geometries (e.g. One MULTIPOINT to multiple POINTs.)</li></ul>'),
|
||||
'#default_value' => isset($settings['delta_handling']) ? $settings['delta_handling']: 'default',
|
||||
'#options' => array(
|
||||
'default' => 'Match Multiples (default)',
|
||||
'm_to_s' => 'Multiple to Single',
|
||||
's_to_m' => 'Single to Multiple',
|
||||
'c_to_s' => 'Concatenate to Single',
|
||||
'c_to_m' => 'Concatenate to Multiple',
|
||||
),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
|
||||
// Add javascript to sync allowed values. Note that we are not using AJAX because we do not have access to the raw form_state here
|
||||
drupal_add_js(array('geocoder_widget_settings' => array('handlers' => $handlers_by_type, 'types' => $field_types)), 'setting');
|
||||
drupal_add_js(drupal_get_path('module', 'geocoder') . '/geocoder.admin.js', 'file');
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_attach_presave().
|
||||
*
|
||||
* Geocoding for the geocoder widget is done here to ensure that only validated
|
||||
* and fully processed fields values are accessed.
|
||||
*/
|
||||
function geocoder_field_attach_presave($entity_type, $entity) {
|
||||
// Loop over any geofield using our geocode widget
|
||||
$entity_info = entity_get_info($entity_type);
|
||||
$bundle_name = empty($entity_info['entity keys']['bundle']) ? $entity_type : $entity->{$entity_info['entity keys']['bundle']};
|
||||
foreach (field_info_instances($entity_type, $bundle_name) as $field_instance) {
|
||||
if ($field_instance['widget']['type'] === 'geocoder') {
|
||||
if (($field_value = geocoder_widget_get_field_value($entity_type, $field_instance, $entity)) !== FALSE) {
|
||||
$entity->{$field_instance['field_name']} = $field_value;
|
||||
}
|
||||
else {
|
||||
$entity->{$field_instance['field_name']} = array();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a field's value based on geocoded data.
|
||||
*
|
||||
* @param $entity_type
|
||||
* Type of entity
|
||||
* @para field_instance
|
||||
* Field instance definition array
|
||||
* @param $entity
|
||||
* Optionally, the entity. You must pass either the entity or $source_field_values
|
||||
* @param $source_field_values
|
||||
* Array of deltas / source field values. You must pass either this or $entity.
|
||||
*
|
||||
* @return
|
||||
* Three possibilities could be returned by this function:
|
||||
* - FALSE: do nothing.
|
||||
* - An empty array: use it to unset the existing field value.
|
||||
* - A populated array: assign a new field value.
|
||||
*/
|
||||
function geocoder_widget_get_field_value($entity_type, $field_instance, $entity = NULL, $source_field_values = NULL) {
|
||||
if (!$source_field_values && !$entity) {
|
||||
trigger_error('geocoder_widget_get_field_value: You must pass either $source_field_values OR $entity', E_USER_ERROR);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$entity_info = entity_get_info($entity_type);
|
||||
|
||||
// Required settings
|
||||
if (isset($field_instance['widget']['settings']['geocoder_handler']) && isset($field_instance['widget']['settings']['geocoder_field'])) {
|
||||
$handler = geocoder_get_handler($field_instance['widget']['settings']['geocoder_handler']);
|
||||
$field_name = is_array($field_instance['widget']['settings']['geocoder_field']) ? reset($field_instance['widget']['settings']['geocoder_field']) : $field_instance['widget']['settings']['geocoder_field'];
|
||||
$target_info = field_info_field($field_instance['field_name']);
|
||||
$target_type = $target_info['type'];
|
||||
|
||||
// Determine the source type, if it's a entity-key, we mock it as a "text" field
|
||||
if (in_array($field_name, $entity_info['entity keys']) && $entity) {
|
||||
$field_info = array('type' => 'text', 'entity_key' => TRUE);
|
||||
}
|
||||
else {
|
||||
$field_info = field_info_field($field_name);
|
||||
$field_info['entity_key'] = FALSE;
|
||||
}
|
||||
|
||||
// Get the source values
|
||||
if (!$source_field_values) {
|
||||
if ($field_info['entity_key'] && $entity) {
|
||||
$source_field_values = array(array('value' => $entity->$field_name));
|
||||
}
|
||||
else if ($entity) {
|
||||
$source_field_values = field_get_items($entity_type, $entity, $field_name, isset($entity->language) ? $entity->language : NULL);
|
||||
}
|
||||
else {
|
||||
// We can't find the source values
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove source values that are not valid.
|
||||
if ($source_field_values) {
|
||||
foreach ($source_field_values as $delta => $item) {
|
||||
if (!is_numeric($delta)) {
|
||||
unset($source_field_values[$delta]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// If no valid source values were passed.
|
||||
if (empty($source_field_values)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// For entities being updated, determine if another geocode is necessary
|
||||
if ($entity) {
|
||||
if (!empty($entity->original)) {
|
||||
//@@TODO: Deal with entity-properties (non-fields)
|
||||
//@@TODO: This isn't working with file fields. Should use some kind of lookup / map
|
||||
$field_original = field_get_items($entity_type, $entity->original, $field_name, isset($entity->original->language) ? $entity->original->language : NULL);
|
||||
if (!empty($field_original)) {
|
||||
$diff = geocoder_widget_array_recursive_diff($field_original, $source_field_values);
|
||||
if (empty($diff)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get the handler-specific-settings
|
||||
if (isset($field_instance['widget']['settings']['handler_settings'][$handler['name']])) {
|
||||
$handler_settings = $field_instance['widget']['settings']['handler_settings'][$handler['name']];
|
||||
}
|
||||
|
||||
// Determine how we deal with deltas (multi-value fields)
|
||||
if (empty($field_instance['widget']['settings']['delta_handling'])) {
|
||||
$delta_handling = 'default';
|
||||
}
|
||||
else {
|
||||
$delta_handling = $field_instance['widget']['settings']['delta_handling'];
|
||||
}
|
||||
|
||||
// Check to see if we should be concatenating
|
||||
if ($delta_handling == 'c_to_s' || $delta_handling == 'c_to_m') {
|
||||
$source_field_values = geocoder_widget_get_field_concat($source_field_values);
|
||||
}
|
||||
|
||||
if (is_array($source_field_values) && count($source_field_values)) {
|
||||
$values = array();
|
||||
|
||||
// Geocode geometries
|
||||
$geometries = array();
|
||||
foreach ($source_field_values as $delta => $item) {
|
||||
// Geocode any value from our source field.
|
||||
try {
|
||||
if (isset($handler_settings)) {
|
||||
$geometry = call_user_func($handler['field_callback'], $field_info, $item, $handler_settings);
|
||||
}
|
||||
else {
|
||||
$geometry = call_user_func($handler['field_callback'], $field_info, $item);
|
||||
}
|
||||
if ($geometry instanceof Geometry) {
|
||||
$geometries[] = $geometry;
|
||||
}
|
||||
else {
|
||||
// An error occured
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
watchdog_exception('geocoder', $e);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($geometries)) {
|
||||
// This field has no data, so set the field to an empty array in
|
||||
// order to delete its saved data.
|
||||
$values = array(NULL);
|
||||
return array();
|
||||
}
|
||||
else {
|
||||
// Resolve multiple-values - get back values from our delta-resolver
|
||||
$values = geocoder_widget_resolve_deltas($geometries, $delta_handling, $target_type);
|
||||
|
||||
// Set the values - geofields do not support languages
|
||||
return array(LANGUAGE_NONE => $values);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get field items and info
|
||||
*
|
||||
* We always pass the full field-item array (with all columns) to the handler, but there is some preprocessing
|
||||
* that we need to do for the special case of entity-labels and multi-field contactenation
|
||||
* For these two special cases we "mock-up" a text-field and pass it back for geocoding
|
||||
*/
|
||||
function geocoder_widget_get_field_concat($items) {
|
||||
// Check if we should concatenate
|
||||
$concat = '';
|
||||
foreach ($items as $item) {
|
||||
$concat .= trim($item['value']) . ', ';
|
||||
}
|
||||
$concat = trim($concat, ', ');
|
||||
$items = array(array('value' => $concat));
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Geocder Widget - Resolve Deltas
|
||||
*
|
||||
* Given a list of geometries, and user configuration on how to handle deltas,
|
||||
* we created a list of items to be inserted into the fields.
|
||||
*/
|
||||
function geocoder_widget_resolve_deltas($geometries, $delta_handling = 'default', $field_type) {
|
||||
$values = array();
|
||||
|
||||
// Default delta handling: just pass one delta to the next
|
||||
if ($delta_handling == 'default') {
|
||||
foreach ($geometries as $geometry) {
|
||||
$values[] = geocoder_widget_values_from_geometry($geometry, $field_type);
|
||||
}
|
||||
}
|
||||
|
||||
// Single-to-multiple handling - if we can, explode out the component geometries
|
||||
if ($delta_handling == 's_to_m' || $delta_handling == 'c_to_m') {
|
||||
$type = $geometries[0]->geometryType();
|
||||
if (in_array($type, array('MultiPoint', 'MultiLineString', 'MultiPolygon', 'GeometryCollection'))) {
|
||||
$components = $geometries[0]->getComponents();
|
||||
foreach ($components as $component) {
|
||||
$values[] = geocoder_widget_values_from_geometry($component, $field_type);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$values[] = geocoder_widget_values_from_geometry($geometries[0], $field_type);
|
||||
}
|
||||
}
|
||||
|
||||
// For multiple-to-single handling, run it though geometryReduce
|
||||
if ($delta_handling == 'm_to_s' || $delta_handling == 'c_to_s') {
|
||||
$reduced_geom = geoPHP::geometryReduce($geometries);
|
||||
$values[] = geocoder_widget_values_from_geometry($reduced_geom, $field_type);
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Geocder Widget - Field values from geometry
|
||||
*
|
||||
* Given a geometry and the field type, return back a values array for that field.
|
||||
* The passed back array represents a single delta.
|
||||
*/
|
||||
function geocoder_widget_values_from_geometry($geometry, $field_type) {
|
||||
if ($field_type == 'geofield') return geofield_get_values_from_geometry($geometry);
|
||||
if ($field_type == 'geolocation_latlng') {
|
||||
$centroid = $geometry->centroid();
|
||||
$lat = $centroid->y();
|
||||
$lng = $centroid->x();
|
||||
|
||||
return array(
|
||||
'lat' => $lat,
|
||||
'lng' => $lng,
|
||||
'lat_sin' => sin(deg2rad($lat)),
|
||||
'lat_cos' => cos(deg2rad($lat)),
|
||||
'lng_rad' => deg2rad($lng),
|
||||
);
|
||||
}
|
||||
if ($field_type == 'location') {
|
||||
$centroid = $geometry->centroid();
|
||||
return array(
|
||||
'latitude' => $centroid->y(),
|
||||
'longitude' => $centroid->x(),
|
||||
'source' => 2,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Geocoder Widget - Parse an address field
|
||||
*/
|
||||
function geocoder_widget_parse_addressfield($field_item) {
|
||||
$address = '';
|
||||
if (!empty($field_item['premise'])) $address .= $field_item['premise'] . ',';
|
||||
if (!empty($field_item['thoroughfare'])) $address .= $field_item['thoroughfare'] . ',';
|
||||
if (!empty($field_item['locality'])) $address .= $field_item['locality'] . ',';
|
||||
if (!empty($field_item['administrative_area'])) $address .= $field_item['administrative_area'] . ',';
|
||||
if (!empty($field_item['sub_administrative_area'])) $address .= $field_item['sub_administrative_area'] . ',';
|
||||
if (!empty($field_item['country'])) $address .= $field_item['country'] . ',';
|
||||
if (!empty($field_item['postal_code'])) $address .= $field_item['postal_code'] . ',';
|
||||
|
||||
$address = rtrim($address, ', ');
|
||||
|
||||
return $address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Geocoder Widget - Parse a location field
|
||||
*/
|
||||
function geocoder_widget_parse_locationfield($field_item) {
|
||||
$address = '';
|
||||
if (!empty($field_item['name'])) $address .= $field_item['name'] . ',';
|
||||
if (!empty($field_item['street'])) $address .= $field_item['street'] . ',';
|
||||
if (!empty($field_item['additional'])) $address .= $field_item['additional'] . ',';
|
||||
if (!empty($field_item['city'])) $address .= $field_item['city'] . ',';
|
||||
if (!empty($field_item['province']) && function_exists('location_province_name')) {
|
||||
$province_fullname = location_province_name($field_item['country'], $field_item['province']);
|
||||
$address .= $province_fullname . ',';
|
||||
}
|
||||
if (!empty($field_item['country'])) $address .= $field_item['country'] . ',';
|
||||
if (!empty($field_item['postal_code'])) $address .= $field_item['postal_code'] . ',';
|
||||
|
||||
$address = rtrim($address, ', ');
|
||||
|
||||
return $address;
|
||||
}
|
||||
|
||||
|
||||
function geocoder_widget_array_recursive_diff($aArray1, $aArray2) {
|
||||
$aReturn = array();
|
||||
if (empty($aArray1)) {
|
||||
return $aReturn;
|
||||
}
|
||||
foreach ($aArray1 as $mKey => $mValue) {
|
||||
if (array_key_exists($mKey, $aArray2)) {
|
||||
if (is_array($mValue)) {
|
||||
$aRecursiveDiff = geocoder_widget_array_recursive_diff($mValue, $aArray2[$mKey]);
|
||||
if (count($aRecursiveDiff)) { $aReturn[$mKey] = $aRecursiveDiff; }
|
||||
} else {
|
||||
if ($mValue != $aArray2[$mKey]) {
|
||||
$aReturn[$mKey] = $mValue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$aReturn[$mKey] = $mValue;
|
||||
}
|
||||
}
|
||||
return $aReturn;
|
||||
}
|
50
sites/all/modules/geocoder/plugins/geocoder_handler/exif.inc
Normal file
50
sites/all/modules/geocoder/plugins/geocoder_handler/exif.inc
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
$plugin = array(
|
||||
'title' => t("Image/exif"),
|
||||
'description' => t('Get a location from an image that was taken with a GPS enabled phone or camera'),
|
||||
'callback' => 'geocoder_exif',
|
||||
'field_types' => array('file', 'image'),
|
||||
'field_callback' => 'geocoder_exif_field',
|
||||
);
|
||||
|
||||
function geocoder_exif($url, $options = array()) {
|
||||
// Invoke hook_file_download to check permissions
|
||||
// We are essentially duplicating the logic found in file.inc file_download()
|
||||
foreach (module_implements('file_download') as $module) {
|
||||
$function = $module . '_file_download';
|
||||
$result = $function($url);
|
||||
if ($result == -1) {
|
||||
drupal_set_message(t('You do not have permission to access this file'), 'error');
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// The user has permission to access the file. Geocode it.
|
||||
geophp_load();
|
||||
if ($data = exif_read_data($url)) {
|
||||
if (!isset($data['GPSLatitudeRef'])) return FALSE;
|
||||
$lat = geocoder_exif_from($data['GPSLatitudeRef'], $data['GPSLatitude']);
|
||||
$lon = geocoder_exif_from($data['GPSLongitudeRef'], $data['GPSLongitude']);
|
||||
$point = new Point($lon, $lat);
|
||||
return $point;
|
||||
}
|
||||
else return FALSE;
|
||||
}
|
||||
|
||||
function geocoder_exif_field($field, $field_item) {
|
||||
if ($field_item['fid']) {
|
||||
$file = file_load($field_item['fid']);
|
||||
return geocoder_exif($file->uri);
|
||||
}
|
||||
}
|
||||
|
||||
function geocoder_exif_from($dir, $data) {
|
||||
foreach ($data as $k => $item) {
|
||||
list($deg, $pct) = explode('/', $item);
|
||||
if ($pct) $data[$k] = $deg / $pct;
|
||||
}
|
||||
$point = (float) $data[0] + ($data[1] / 60) + ($data[2] / 3600);
|
||||
if (in_array($dir, array('S', 'W'))) $point = $point * -1;
|
||||
return $point;
|
||||
}
|
177
sites/all/modules/geocoder/plugins/geocoder_handler/google.inc
Normal file
177
sites/all/modules/geocoder/plugins/geocoder_handler/google.inc
Normal file
@@ -0,0 +1,177 @@
|
||||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide a google geocoder.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Google Geocoder"),
|
||||
'description' => t('Geocodes via google geocoder'),
|
||||
'callback' => 'geocoder_google',
|
||||
'field_types' => array('text', 'text_long', 'addressfield', 'location', 'text_with_summary', 'computed', 'taxonomy_term_reference'),
|
||||
'field_callback' => 'geocoder_google_field',
|
||||
'settings_callback' => 'geocoder_google_form',
|
||||
'terms_of_service' => 'http://code.google.com/apis/maps/documentation/geocoding/#Limits',
|
||||
);
|
||||
|
||||
/**
|
||||
* Process Markup
|
||||
*/
|
||||
function geocoder_google($address, $options = array()) {
|
||||
try {
|
||||
geophp_load();
|
||||
|
||||
$query = array(
|
||||
'address' => $address,
|
||||
'sensor' => 'false',
|
||||
);
|
||||
|
||||
$url = url("http://maps.googleapis.com/maps/api/geocode/json", array('query' => $query));
|
||||
$result = drupal_http_request($url);
|
||||
|
||||
if (isset($result->error)) {
|
||||
$args = array(
|
||||
'@code' => $result->code,
|
||||
'@error' => $result->error,
|
||||
);
|
||||
$msg = t('HTTP request to google API failed.\nCode: @code\nError: @error', $args);
|
||||
throw new Exception($msg);
|
||||
}
|
||||
|
||||
$data = json_decode($result->data);
|
||||
|
||||
if ($data->status != 'OK') {
|
||||
$args = array('@status' => $data->status);
|
||||
$msg = t('Google API returned bad status.\nStatus: @status', $args);
|
||||
throw new Exception($msg);
|
||||
}
|
||||
|
||||
$geometries = array();
|
||||
|
||||
foreach ($data->results as $item) {
|
||||
// Check if we should reject these results
|
||||
if (isset($options['reject_results'])) {
|
||||
if (in_array($item->geometry->location_type, $options['reject_results'], TRUE)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Construct a geoPHP Geometry depending on what type of geometry we want returned (defaults to point)
|
||||
if (!isset($options['geometry_type']) || $options['geometry_type'] == 'point') {
|
||||
$geom = new Point($item->geometry->location->lng, $item->geometry->location->lat);
|
||||
}
|
||||
elseif ($options['geometry_type'] == 'bounds') {
|
||||
$points = array(
|
||||
new Point($item->geometry->bounds->southwest->lng, $item->geometry->bounds->southwest->lat),
|
||||
new Point($item->geometry->bounds->southwest->lng, $item->geometry->bounds->northeast->lat),
|
||||
new Point($item->geometry->bounds->northeast->lng, $item->geometry->bounds->northeast->lat),
|
||||
new Point($item->geometry->bounds->northeast->lng, $item->geometry->bounds->southwest->lat),
|
||||
new Point($item->geometry->bounds->southwest->lng, $item->geometry->bounds->southwest->lat),
|
||||
);
|
||||
$geom = new Polygon(array(new LineString($points)));
|
||||
}
|
||||
elseif ($options['geometry_type'] == 'viewport') {
|
||||
$points = array(
|
||||
new Point($item->geometry->viewport->southwest->lng, $item->geometry->viewport->southwest->lat),
|
||||
new Point($item->geometry->viewport->southwest->lng, $item->geometry->viewport->northeast->lat),
|
||||
new Point($item->geometry->viewport->northeast->lng, $item->geometry->viewport->northeast->lat),
|
||||
new Point($item->geometry->viewport->northeast->lng, $item->geometry->viewport->southwest->lat),
|
||||
new Point($item->geometry->viewport->southwest->lng, $item->geometry->viewport->southwest->lat),
|
||||
);
|
||||
$geom = new Polygon(array(new LineString($points)));
|
||||
}
|
||||
|
||||
// Add additional metadata to the geometry - it might be useful!
|
||||
$geom->data = array();
|
||||
$geom->data['geocoder_accuracy'] = $item->geometry->location_type;
|
||||
$geom->data['geocoder_formatted_address'] = $item->formatted_address;
|
||||
$geom->data['geocoder_address_components'] = $item->address_components;
|
||||
|
||||
$geometries[] = $geom;
|
||||
}
|
||||
|
||||
if (empty($geometries)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if we should return all results as a compound geometry
|
||||
if (isset($options['all_results'])) {
|
||||
if ($options['all_results']) {
|
||||
return geoPHP::geometryReduce($geometries);
|
||||
}
|
||||
}
|
||||
// The connonical geometry is the first result (best guesse)
|
||||
$geometry = array_shift($geometries);
|
||||
|
||||
// If there are any other geometries, these are auxiliary geometries that represent "alternatives"
|
||||
if (count($geometries)) {
|
||||
$geometry->data['geocoder_alternatives'] = $geometries;
|
||||
}
|
||||
|
||||
return $geometry;
|
||||
} catch (Exception $e) {
|
||||
watchdog_exception('geocoder', $e);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
function geocoder_google_field($field, $field_item, $options = array()) {
|
||||
if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'text_with_summary' || $field['type'] == 'computed') {
|
||||
return geocoder_google($field_item['value'], $options);
|
||||
}
|
||||
if ($field['type'] == 'addressfield') {
|
||||
$address = geocoder_widget_parse_addressfield($field_item);
|
||||
return geocoder_google($address, $options);
|
||||
}
|
||||
if ($field['type'] == 'location') {
|
||||
$address = geocoder_widget_parse_locationfield($field_item);
|
||||
return geocoder_google($address, $options);
|
||||
}
|
||||
if ($field['type'] == 'taxonomy_term_reference') {
|
||||
$term = taxonomy_term_load($field_item['tid']);
|
||||
return geocoder_google($term->name);
|
||||
}
|
||||
}
|
||||
|
||||
function geocoder_google_form($default_values = array()) {
|
||||
$form = array();
|
||||
|
||||
$form['geometry_type'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => 'Geometry Type',
|
||||
'#options' => array(
|
||||
'point' => 'Point (default)',
|
||||
'bounds' => 'Bounding Box',
|
||||
'viewport' => 'Viewport',
|
||||
),
|
||||
'#default_value' => isset($default_values['geometry_type']) ? $default_values['geometry_type'] : 'point',
|
||||
);
|
||||
|
||||
$form['all_results'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => 'Geocode all alternative results',
|
||||
'#default_value' => isset($default_values['all_results']) ? $default_values['all_results'] : FALSE,
|
||||
'#description' => 'Often an ambiguous address (such as "Springfield USA") can result in multiple hits. By default we only return the first (best guess) result. Check this to return all results as a Multi-Geometry (MultiPoint or MultiPolygon).',
|
||||
);
|
||||
|
||||
$form['reject_results'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => 'Reject Results',
|
||||
'#options' => array(
|
||||
'APPROXIMATE' => 'APPROXIMATE: indicates that the returned result is approximate.',
|
||||
'GEOMETRIC_CENTER' => 'GEOMETRIC_CENTER: indicates that the returned result is the geometric center of a result such as a polyline (for example, a street) or polygon (region).',
|
||||
'RANGE_INTERPOLATED' => 'RANGE_INTERPOLATED: indicates that the returned result reflects an approximation (usually on a road) interpolated between two precise points (such as intersections). Interpolated results are generally returned when rooftop geocodes are unavailable for a street address.',
|
||||
'ROOFTOP' => 'ROOFTOP: indicates that the returned result is a precise geocode for which we have location information accurate down to street address precision.',
|
||||
),
|
||||
'#default_value' => isset($default_values['reject_results']) ? $default_values['reject_results'] : array(),
|
||||
'#description' => 'Reject results that do not meet a certain level of quality or precision. Check all types of results to reject.',
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
44
sites/all/modules/geocoder/plugins/geocoder_handler/gpx.inc
Normal file
44
sites/all/modules/geocoder/plugins/geocoder_handler/gpx.inc
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php // $Id: gpx.inc,v 1.1 2009/03/02 18:14:07 vauxia Exp $
|
||||
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* Parsing utilities for GPX track files. Originally written to cover a more
|
||||
* comprehensive usage than what Geocode is doing, but handy nonetheless.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("GPX"),
|
||||
'description' => t('Get the geomtry of a GPX string or file'),
|
||||
'callback' => 'geocoder_gpx',
|
||||
'field_types' => array('text', 'text_long', 'file', 'computed'),
|
||||
'field_callback' => 'geocoder_gpx_field',
|
||||
);
|
||||
|
||||
/**
|
||||
* Process GPX
|
||||
*/
|
||||
function geocoder_gpx($gpx_string, $options = array()) {
|
||||
geophp_load();
|
||||
return geoPHP::load($gpx_string, 'gpx');
|
||||
}
|
||||
|
||||
function geocoder_gpx_field($field, $field_item) {
|
||||
if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'computed') {
|
||||
return geocoder_gpx($field_item['value']);
|
||||
}
|
||||
if ($field['type'] == 'file') {
|
||||
if ($field_item['fid']) {
|
||||
$file = file_load($field_item['fid']);
|
||||
$gpx = file_get_contents($file->uri);
|
||||
return geocoder_gpx($gpx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
40
sites/all/modules/geocoder/plugins/geocoder_handler/json.inc
Normal file
40
sites/all/modules/geocoder/plugins/geocoder_handler/json.inc
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide a google geocoder.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("GeoJSON"),
|
||||
'description' => t('Get the geometry of a GeoJSON string, file, or URL'),
|
||||
'callback' => 'geocoder_json',
|
||||
'field_types' => array('text', 'text_long', 'file', 'computed'),
|
||||
'field_callback' => 'geocoder_json_field',
|
||||
);
|
||||
|
||||
/**
|
||||
* Process Markup
|
||||
*/
|
||||
function geocoder_json($json_string, $options = array()) {
|
||||
geophp_load();
|
||||
return geoPHP::load($json_string, 'json');
|
||||
}
|
||||
|
||||
function geocoder_json_field($field, $field_item) {
|
||||
if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'computed') {
|
||||
return geocoder_json($field_item['value']);
|
||||
}
|
||||
if ($field['type'] == 'file') {
|
||||
if ($field_item['fid']) {
|
||||
$file = file_load($field_item['fid']);
|
||||
$json = file_get_contents($file->uri);
|
||||
return geocoder_json($json);
|
||||
}
|
||||
}
|
||||
}
|
40
sites/all/modules/geocoder/plugins/geocoder_handler/kml.inc
Normal file
40
sites/all/modules/geocoder/plugins/geocoder_handler/kml.inc
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide a kml geocoder.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("KML"),
|
||||
'description' => t('Get the geometry out of a KML string, file, or URL'),
|
||||
'callback' => 'geocoder_kml',
|
||||
'field_types' => array('text', 'text_long', 'file', 'computed'),
|
||||
'field_callback' => 'geocoder_kml_field',
|
||||
);
|
||||
|
||||
/**
|
||||
* Process Markup
|
||||
*/
|
||||
function geocoder_kml($kml_string, $options = array()) {
|
||||
geophp_load();
|
||||
return geoPHP::load($kml_string, 'kml');
|
||||
}
|
||||
|
||||
function geocoder_kml_field($field, $field_item) {
|
||||
if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'computed') {
|
||||
return geocoder_kml($field_item['value']);
|
||||
}
|
||||
if ($field['type'] == 'file') {
|
||||
if ($field_item['fid']) {
|
||||
$file = file_load($field_item['fid']);
|
||||
$kml = file_get_contents($file->uri);
|
||||
return geocoder_kml($kml);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide a google geocoder.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Latitude / Longitude"),
|
||||
'description' => t('Parse location from freeform latitude and longitude string'),
|
||||
'callback' => 'geocoder_latlon',
|
||||
'field_types' => array('text', 'text_long', 'text_with_summary', 'computed'),
|
||||
'field_callback' => 'geocoder_latlon_field',
|
||||
);
|
||||
|
||||
/**
|
||||
* Process Markup
|
||||
*/
|
||||
function geocoder_latlon($latlon_string, $options = array()) {
|
||||
geophp_load();
|
||||
|
||||
$delims = array("," , "/" , " " , "\t");
|
||||
|
||||
foreach ($delims as $delim) {
|
||||
$parts = explode($delim, $latlon_string);
|
||||
if (count($parts) == 2) {
|
||||
$lat = geocoder_latlon_DMStoDEC(trim($parts[0]));
|
||||
$lon = geocoder_latlon_DMStoDEC(trim($parts[1]));
|
||||
return new Point($lon, $lat);
|
||||
}
|
||||
}
|
||||
|
||||
// Failed to parse
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
function geocoder_latlon_DMStoDEC($dms) {
|
||||
if (is_numeric($dms)) {
|
||||
// It's already decimal degrees, just return it
|
||||
return $dms;
|
||||
}
|
||||
|
||||
// If it contains both an H and M, then it's an angular hours
|
||||
if (stripos($dms, 'H') !== FALSE && stripos($dms, 'M') !== FALSE) {
|
||||
$dms = strtr($dms, "'\"HOURSMINTECNDAhoursmintecnda", " ");
|
||||
$dms = preg_replace('/\s\s+/', ' ', $dms);
|
||||
|
||||
$dms = explode(" ", $dms);
|
||||
$deg = $dms[0];
|
||||
$min = $dms[1];
|
||||
$sec = $dms[2];
|
||||
|
||||
$dec = floatval(($deg*15) + ($min/4) + ($sec/240));
|
||||
|
||||
return $dec;
|
||||
}
|
||||
|
||||
// If it contains an S or a W, then it's a negative
|
||||
if (stripos($dms, 'S') !== FALSE || stripos($dms, 'W') !== FALSE) {
|
||||
$direction = -1;
|
||||
}
|
||||
else {
|
||||
$direction = 1;
|
||||
}
|
||||
|
||||
// Strip all characters and replace them with empty space
|
||||
$dms = strtr($dms, "<EFBFBD>'\"NORTHSEAWnorthseaw'", " ");
|
||||
$dms = preg_replace('/\s\s+/', ' ', $dms);
|
||||
|
||||
$dms = explode(" ", $dms);
|
||||
$deg = $dms[0];
|
||||
$min = $dms[1];
|
||||
$sec = $dms[2];
|
||||
|
||||
// Direction should be checked only for nonnegative coordinates
|
||||
$dec = floatval($deg+((($min*60)+($sec))/3600));
|
||||
if ($dec > 0) {
|
||||
$dec = $direction * $dec;
|
||||
}
|
||||
return $dec;
|
||||
}
|
||||
|
||||
|
||||
function geocoder_latlon_field($field, $field_item) {
|
||||
return geocoder_latlon($field_item['value']);
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide a MapQuest Nominatim geocoder.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("MapQuest Nominatim"),
|
||||
'description' => t('Geocodes via MapQuest Nominatim'),
|
||||
'callback' => 'geocoder_mapquest_nominatim',
|
||||
'field_types' => array('text', 'text_long', 'addressfield', 'location', 'text_with_summary', 'computed', 'taxonomy_term_reference'),
|
||||
'field_callback' => 'geocoder_mapquest_nominatim_field',
|
||||
'terms_of_service' => 'http://developer.mapquest.com/web/info/terms-of-use',
|
||||
);
|
||||
|
||||
/**
|
||||
* Process Markup
|
||||
*/
|
||||
function geocoder_mapquest_nominatim($address, $options = array()) {
|
||||
$geocoder_settings = variable_get("geocoder_settings", array());
|
||||
$api_url = "http://open.mapquestapi.com/nominatim/v1/search";
|
||||
$params = array(
|
||||
'q' => str_replace(' ', '+', $address),
|
||||
'format' => 'json',
|
||||
'addressdetails' => 0,
|
||||
'limit' => 1,
|
||||
'osm_type' => 'N',
|
||||
);
|
||||
$request = drupal_http_request($api_url . '?' . drupal_http_build_query($params));
|
||||
$data = json_decode($request->data);
|
||||
return _geocoder_mapquest_nominatim_geometry($data);
|
||||
}
|
||||
|
||||
function geocoder_mapquest_nominatim_field($field, $field_item) {
|
||||
if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'text_with_summary' || $field['type'] == 'computed') {
|
||||
return geocoder_mapquest_nominatim($field_item['value']);
|
||||
}
|
||||
if ($field['type'] == 'addressfield') {
|
||||
$address = geocoder_widget_parse_addressfield($field_item);
|
||||
return geocoder_mapquest_nominatim($address);
|
||||
}
|
||||
if ($field['type'] == 'location') {
|
||||
$address = geocoder_widget_parse_locationfield($field_item);
|
||||
return geocoder_mapquest_nomination($address);
|
||||
}
|
||||
if ($field['type'] == 'taxonomy_term_reference') {
|
||||
$term = taxonomy_term_load($field_item['tid']);
|
||||
return geocoder_mapquest_nominatim($term->name);
|
||||
}
|
||||
}
|
||||
|
||||
function _geocoder_mapquest_nominatim_geometry(&$data) {
|
||||
if (!isset($data[0]->lon)) {
|
||||
return NULL;
|
||||
}
|
||||
geophp_load();
|
||||
return new Point($data[0]->lon, $data[0]->lat);
|
||||
}
|
43
sites/all/modules/geocoder/plugins/geocoder_handler/wkt.inc
Normal file
43
sites/all/modules/geocoder/plugins/geocoder_handler/wkt.inc
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide a WKT geocoder.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("WKT"),
|
||||
'description' => t('Get the geometry of a WKT string'),
|
||||
'callback' => 'geocoder_wkt',
|
||||
'field_types' => array('text', 'text_long', 'file', 'geofield', 'computed'),
|
||||
'field_callback' => 'geocoder_wkt_field',
|
||||
);
|
||||
|
||||
/**
|
||||
* Process WKT
|
||||
*/
|
||||
function geocoder_wkt($wkt, $options = array()) {
|
||||
geophp_load();
|
||||
return geoPHP::load($wkt, 'wkt');
|
||||
}
|
||||
|
||||
function geocoder_wkt_field($field, $field_item) {
|
||||
if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'computed') {
|
||||
return geocoder_wkt($field_item['value']);
|
||||
}
|
||||
if ($field['type'] == 'geofield') {
|
||||
return geocoder_wkt($field_item['wkt']);
|
||||
}
|
||||
if ($field['type'] == 'file') {
|
||||
if ($field_item['fid']) {
|
||||
$file = file_load($field_item['fid']);
|
||||
$wkt = file_get_contents($file->uri);
|
||||
return geocoder_wkt($wkt);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide a yahoo geocoder.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Yahoo Placefinder"),
|
||||
'description' => t('Geocodes via Yahoo Placefinder'),
|
||||
'callback' => 'geocoder_yahoo',
|
||||
'field_types' => array('text', 'text_long', 'addressfield', 'location', 'text_with_summary', 'computed', 'taxonomy_term_reference'),
|
||||
'field_callback' => 'geocoder_yahoo_field',
|
||||
'terms_of_service' => 'http://developer.yahoo.com/geo/placefinder/',
|
||||
);
|
||||
|
||||
/**
|
||||
* Process Markup
|
||||
*/
|
||||
function geocoder_yahoo($address, $options = array()) {
|
||||
global $base_path;
|
||||
$geocoder_settings = variable_get("geocoder_settings", array());
|
||||
|
||||
if (!empty($geocoder_settings["geocoder_apikey_yahoo"])) {
|
||||
$consumer_key = $geocoder_settings["geocoder_apikey_yahoo"];
|
||||
}
|
||||
else {
|
||||
drupal_set_message("You must set up your Yahoo API key. Click <a href='$base_path/admin/config/content/geocoder'>here</a>",'error');
|
||||
return;
|
||||
}
|
||||
|
||||
$request = drupal_http_request("http://where.yahooapis.com/geocode?location=" . urlencode($address) . "&flags=J&appid={$consumer_key}");
|
||||
$data = json_decode($request->data);
|
||||
|
||||
geophp_load();
|
||||
return _geocoder_yahoo_geometry($data);
|
||||
}
|
||||
|
||||
function geocoder_yahoo_field($field, $field_item) {
|
||||
if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'text_with_summary' || $field['type'] == 'computed') {
|
||||
return geocoder_yahoo($field_item['value']);
|
||||
}
|
||||
if ($field['type'] == 'addressfield') {
|
||||
$address = geocoder_widget_parse_addressfield($field_item);
|
||||
return geocoder_yahoo($address);
|
||||
}
|
||||
if ($field['type'] == 'location') {
|
||||
$address = geocoder_widget_parse_locationfield($field_item);
|
||||
return geocoder_yahoo($address);
|
||||
}
|
||||
if ($field['type'] == 'taxonomy_term_reference') {
|
||||
$term = taxonomy_term_load($field_item['tid']);
|
||||
return geocoder_yahoo($term->name);
|
||||
}
|
||||
}
|
||||
|
||||
function _geocoder_yahoo_geometry(&$data) {
|
||||
if (!isset($data->ResultSet)) {
|
||||
return NULL;
|
||||
}
|
||||
// Yahoo Placefinder API v2.
|
||||
elseif (isset($data->ResultSet->Result->longitude)) {
|
||||
return new Point($data->ResultSet->Result->longitude, $data->ResultSet->Result->latitude);
|
||||
}
|
||||
// Yahoo Placefinder API v1.
|
||||
elseif (isset($data->ResultSet->Results[0]->longitude)) {
|
||||
return new Point($data->ResultSet->Results[0]->longitude, $data->ResultSet->Results[0]->latitude);
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
// $Id$
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide a yandex geocoder.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Plugins are described by creating a $plugin array which will be used
|
||||
* by the system that includes this file.
|
||||
*/
|
||||
$plugin = array(
|
||||
'title' => t("Yandex (Яндекс.Карт)"),
|
||||
'description' => t('Geocodes addresses via Yandex (Яндекс.Карт)'),
|
||||
'callback' => 'geocoder_yandex',
|
||||
'field_types' => array('text','text_long','addressfield', 'location','text_with_summary','computed', 'taxonomy_term_reference'),
|
||||
'field_callback' => 'geocoder_yandex_field',
|
||||
'terms_of_service' => 'http://api.yandex.ru/maps/geocoder/doc/desc/concepts/About.xml',
|
||||
);
|
||||
|
||||
/**
|
||||
* Process Address
|
||||
*/
|
||||
function geocoder_yandex($address, $options = array()) {
|
||||
global $base_path;
|
||||
$geocoder_settings = variable_get("geocoder_settings", array());
|
||||
|
||||
if (!empty($geocoder_settings["geocoder_apikey_yandex"])) {
|
||||
$consumer_key = $geocoder_settings["geocoder_apikey_yandex"];
|
||||
}
|
||||
else {
|
||||
drupal_set_message("You must set up your Yandex API key. Click <a href='$base_path/admin/config/content/geocoder'>here</a>",'error');
|
||||
return;
|
||||
}
|
||||
|
||||
$params = array (
|
||||
'format' => 'json',
|
||||
'results' => 1,
|
||||
'key' => $consumer_key,
|
||||
'geocode' => $address,
|
||||
);
|
||||
$request = drupal_http_request("http://geocode-maps.yandex.ru/1.x/?" . http_build_query($params));
|
||||
$data = json_decode($request->data);
|
||||
|
||||
return _geocoder_yandex_geometry($data);
|
||||
}
|
||||
|
||||
function geocoder_yandex_field($field, $field_item) {
|
||||
if ($field['type'] == 'text' || $field['type'] == 'text_long' || $field['type'] == 'text_with_summary' || $field['type'] == 'computed') {
|
||||
return geocoder_yandex($field_item['value']);
|
||||
}
|
||||
if ($field['type'] == 'addressfield') {
|
||||
$address = geocoder_widget_parse_addressfield($field_item);
|
||||
return geocoder_yandex($address);
|
||||
}
|
||||
if ($field['type'] == 'location') {
|
||||
$address = geocoder_widget_parse_locationfield($field_item);
|
||||
return geocoder_google($address);
|
||||
}
|
||||
if ($field['type'] == 'taxonomy_term_reference') {
|
||||
$term = taxonomy_term_load($field_item['tid']);
|
||||
return geocoder_yandex($term->name);
|
||||
}
|
||||
}
|
||||
|
||||
function _geocoder_yandex_geometry(&$data) {
|
||||
try {
|
||||
geophp_load();
|
||||
|
||||
if (isset($data->error)) {
|
||||
$args = array(
|
||||
'@status' => $data->error->status,
|
||||
'@error' => $data->error->message,
|
||||
);
|
||||
$msg = t('Yandex API has reported an error.\nStatus: @status\nError: @error', $args);
|
||||
throw new Exception($msg);
|
||||
}
|
||||
|
||||
if($data->response->GeoObjectCollection->metaDataProperty->GeocoderResponseMetaData->found == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$loc = explode(' ', $data->response->GeoObjectCollection->featureMember[0]->GeoObject->Point->pos);
|
||||
return new Point ($loc[0], $loc[1]);
|
||||
} catch (Exception $e) {
|
||||
watchdog_exception('geocoder', $e);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user