FINAL suepr merge step : added all modules to this super repos
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
diff --git contrib/location_cck/location_cck.module contrib/location_cck/location_cck.module
|
||||
index ba1a592..a5bcc77 100644
|
||||
--- contrib/location_cck/location_cck.module
|
||||
+++ contrib/location_cck/location_cck.module
|
||||
@@ -162,6 +162,17 @@ function location_cck_field_insert($entity_type, $entity, $field, $instance, $la
|
||||
);
|
||||
location_save_locations($items, $criteria);
|
||||
}
|
||||
+ }else{
|
||||
+ if (!empty($items)) {
|
||||
+ list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
|
||||
+ // Store instances of locations by field name and vid.
|
||||
+ $criteria = array(
|
||||
+ 'genid' => 'field:' . $field['field_name'] . ':' . $entity_type . ':' . $id,
|
||||
+ 'vid' => $vid ? $vid : $id,
|
||||
+ 'nid' => $id,
|
||||
+ );
|
||||
+ location_save_locations($items, $criteria);
|
||||
+ }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,6 +190,17 @@ function location_cck_field_update($entity_type, $entity, $field, $instance, $la
|
||||
);
|
||||
location_save_locations($items, $criteria);
|
||||
}
|
||||
+ }else{
|
||||
+ if (!empty($items)) {
|
||||
+ list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
|
||||
+ // Store instances of locations by field name and vid.
|
||||
+ $criteria = array(
|
||||
+ 'genid' => 'field:' . $field['field_name'] . ':' . $entity_type . ':' . $id,
|
||||
+ 'vid' => $vid ? $vid : $id,
|
||||
+ 'nid' => $id,
|
||||
+ );
|
||||
+ location_save_locations($items, $criteria);
|
||||
+ }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,6 +221,11 @@ function location_cck_field_delete($entity_type, $entity, $field, $instance, $la
|
||||
$locs = array();
|
||||
location_save_locations($locs, array('genid' => $genid));
|
||||
}
|
||||
+ }else {
|
||||
+ list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
|
||||
+ $genid = 'field:' . $field['field_name'] . ':' . $entity_type . ':' . $id;
|
||||
+ $locs = array();
|
||||
+ location_save_locations($locs, array('genid' => $genid));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,6 +237,11 @@ function location_cck_field_delete_revision($entity_type, $entity, $field, $inst
|
||||
$genid = 'cck:' . $field['field_name'] . ':' . $entity->vid;
|
||||
$locs = array();
|
||||
location_save_locations($locs, array('genid' => $genid));
|
||||
+ } else {
|
||||
+ list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
|
||||
+ $genid = 'field:' . $field['field_name'] . ':' . $entity_type . ':' . $id;
|
||||
+ $locs = array();
|
||||
+ location_save_locations($locs, array('genid' => $genid));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +256,6 @@ function location_cck_field_validate($entity_type, $entity, $field, $instance, $
|
||||
* Implement hook_field_load().
|
||||
*/
|
||||
function location_cck_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) {
|
||||
- if ($entity_type == 'node') {
|
||||
foreach ($entities as $id => $entity) {
|
||||
foreach ($items[$id] as $delta => $item) {
|
||||
$location = array();
|
||||
@@ -238,7 +269,6 @@ function location_cck_field_load($entity_type, $entities, $field, $instances, $l
|
||||
$items[$id][$delta] = array_merge($location, $item);
|
||||
}
|
||||
}
|
||||
- }
|
||||
}
|
||||
|
||||
/**
|
8
sites/all/modules/contrib/fields/location/CREDITS.txt
Normal file
8
sites/all/modules/contrib/fields/location/CREDITS.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
Originally developed and implemented by:
|
||||
Ankur Rishi (user name 'ankur': http://drupal.org/user/11703 )
|
||||
|
||||
|
||||
Maintained by:
|
||||
Brandon Bergren (user name 'Bdragon' http://drupal.org/user/53801 )
|
||||
Rebecca White (user name 'bec' http://drupal.org/user/81067)
|
73
sites/all/modules/contrib/fields/location/INSTALL.txt
Normal file
73
sites/all/modules/contrib/fields/location/INSTALL.txt
Normal file
@@ -0,0 +1,73 @@
|
||||
|
||||
CONTENTS OF THIS FILE
|
||||
---------------------
|
||||
|
||||
* Introduction
|
||||
* Installation
|
||||
|
||||
INTRODUCTION
|
||||
------------
|
||||
|
||||
Current maintainer: Brandon Bergren <http://drupal.org/user/53081>
|
||||
|
||||
Location module and its associated API allows Drupal objects, including nodes
|
||||
and users, to be associated with specific physical locations.
|
||||
|
||||
This package consists of several modules, including:
|
||||
- Location (required): Base module that provides a standard API and storage for
|
||||
location data.
|
||||
- Location Add Another: Quickly add additional locations directly from a node.
|
||||
- Location Fax: Add a fax number to a location.
|
||||
- Location Phone: Add a phone number to a location.
|
||||
- Location Search: A custom search page for locations.
|
||||
|
||||
For Drupal 6, Views support has been rolled directly into the base Location module.
|
||||
|
||||
INSTALLATION
|
||||
------------
|
||||
|
||||
1. Copy the files to your sites/SITENAME/modules directory.
|
||||
|
||||
2. Enable the Location module and any desired optional modules at Administer >>
|
||||
Site building >> Modules (admin/build/modules).
|
||||
|
||||
3. Set user permissions for Location module at Administer >> User management >>
|
||||
Access control (admin/user/access).
|
||||
|
||||
4. Configure Location module's settings at Administer >> Site configuration >>
|
||||
Location (admin/settings/location). Here, you may configure settings related
|
||||
to how Location fields are displayed, how location data is gathered, what
|
||||
geocoding service is used to translate addresses to longitude and latitude
|
||||
points, and which mapping service should display them.
|
||||
|
||||
5. If you wish to collect location data about content, go to Administer >>
|
||||
Content management >> Content types and click "edit" on the given type, such
|
||||
as "Event". In the Locative information fieldset, expand and set your
|
||||
options accordingly.
|
||||
|
||||
6. (Optional) Import a postal codes database for the countries served by your
|
||||
website, to support proximity searches and other useful features. Postal
|
||||
code databases may be found in the "databases/" sub-directory of the
|
||||
Location module directory. The files are in the format of zipcodes.CC.mysql,
|
||||
where CC is a two-letter country code such as 'us' or 'de'.
|
||||
|
||||
Note: If your site is using table prefixes, you will need to adjust for this
|
||||
manually, by opening the file in a text editor and replacing 'zipcodes' with
|
||||
'prefix_zipcodes' throughout.
|
||||
|
||||
To import the files from the command line, enter the following:
|
||||
|
||||
cd sites/SITENAME/modules/location
|
||||
mysql -u username -p database-name < database/zipcodes.us.mysql
|
||||
|
||||
KNOWN ISSUES
|
||||
------------
|
||||
|
||||
1. Node locations and CCK locations cannot safely be used on the same content types.
|
||||
You can use both on one site but they must be used on different content types.
|
||||
To turn node locations off for a particular content type edit the content type
|
||||
and set the max number of locations to zero.
|
||||
The problem is that node locations can interfere with the saving of cck locations
|
||||
and you can end up losing your cck locations.
|
||||
For more information see this issue - http://drupal.org/node/906968.
|
||||
|
339
sites/all/modules/contrib/fields/location/LICENSE.txt
Normal file
339
sites/all/modules/contrib/fields/location/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.
|
3
sites/all/modules/contrib/fields/location/TODO-3.txt
Normal file
3
sites/all/modules/contrib/fields/location/TODO-3.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
- Make sure that we scan for broken location table (oid -> eid)
|
||||
- lid editor
|
||||
- Remove variable 'gmap_location_map' -- gmap was taking care of it for us but we never used it.
|
@@ -0,0 +1,16 @@
|
||||
name = Location Add Another
|
||||
description = Allows you to quickly add locations directly from a node without having to click 'edit' first.
|
||||
dependencies[] = location
|
||||
dependencies[] = location_node
|
||||
package = Location
|
||||
core = 7.x
|
||||
files[] = location_addanother.module
|
||||
files[] = location_addanother.install
|
||||
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-02-18
|
||||
version = "7.x-3.x-dev"
|
||||
core = "7.x"
|
||||
project = "location"
|
||||
datestamp = "1329524299"
|
||||
|
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the location_addanother module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementshook_install().
|
||||
*/
|
||||
function location_addanother_install() {
|
||||
// Change weight so we execute after location.
|
||||
db_update('system')
|
||||
->fields(array(
|
||||
'weight' => 1,
|
||||
))
|
||||
->condition('name', 'location_addanother')
|
||||
->condition('type', 'module')
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementshook_uninstall().
|
||||
*/
|
||||
function location_addanother_uninstall() {
|
||||
$result = db_query("SELECT name FROM {variable} WHERE name LIKE 'location_addanother_%'")->fetchCol();
|
||||
foreach ($result as $row) {
|
||||
variable_del($row->name);
|
||||
}
|
||||
}
|
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* "Add location from node view" functionality.
|
||||
* Split from main location.module in version 3.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_node_view().
|
||||
*/
|
||||
function location_addanother_node_view($node, $view_mode) {
|
||||
if (variable_get('location_addanother_' . $node->type, 0) && count($node->locations) < variable_get('location_maxnum_' . $node->type, 0) && $view_mode == 'full' && node_access('update', $node)) {
|
||||
$addanother_form = drupal_get_form('location_addanother_form', $node);
|
||||
$node->content['location_addanother'] = array(
|
||||
'#type' => 'markup',
|
||||
'#markup' => drupal_render($addanother_form),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
* Alter the node_type_form form.
|
||||
*/
|
||||
function location_addanother_form_node_type_form_alter(&$form, &$form_state, $form_id) {
|
||||
$type = $form['#node_type']->type;
|
||||
|
||||
$form['location_settings']['multiple']['location_addanother'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Add another location from node view page'),
|
||||
'#default_value' => variable_get('location_addanother_' . $type, 0),
|
||||
'#description' => t('Display the "Add another location" option on the node view page.'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Form to display directly on a node view for "quick location add" functionality.
|
||||
*/
|
||||
function location_addanother_form($form, &$form_state, &$node) {
|
||||
$settings = variable_get('location_settings_node_' . $node->type, array());
|
||||
|
||||
$form['location'] = array(
|
||||
'#type' => 'location_element',
|
||||
'#title' => t('Add another location'),
|
||||
'#default_value' => NULL,
|
||||
'#location_settings' => $settings['form']['fields'],
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
);
|
||||
$form['location']['nid'] = array(
|
||||
'#type' => 'hidden', // @@@ See if we can get away with value-ing this.
|
||||
'#value' => $node->nid,
|
||||
);
|
||||
|
||||
$form['actions'] = array('#type' => 'actions');
|
||||
$form['actions']['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Add location'),
|
||||
'#weight' => 50,
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation function for "add another location" form.
|
||||
*/
|
||||
function location_addanother_form_validate($form, &$form_state) {
|
||||
$location = $form_state['values']['location'];
|
||||
$node = node_load($location['nid']);
|
||||
unset($location['nid']);
|
||||
if (!(variable_get('location_addanother_' . $node->type, 0) && count($node->locations) < variable_get('location_maxnum_' . $node->type, 0) && node_access('update', $node))) {
|
||||
form_set_error('location', t("You don't have permission to add a location to this node, or the node has the maximum number of locations already."));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Submission function for "add another location" form.
|
||||
*/
|
||||
function location_addanother_form_submit($form, &$form_state) {
|
||||
$location = $form_state['values']['location'];
|
||||
$node = node_load($location['nid']);
|
||||
$locations = $node->locations;
|
||||
unset($location['nid']);
|
||||
$locations[] = $location;
|
||||
|
||||
location_save_locations($locations, array('nid' => $node->nid, 'vid' => $node->vid));
|
||||
|
||||
return 'node/' . $node->nid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_node_type_delete().
|
||||
* Synchronize our settings.
|
||||
*/
|
||||
function hook_node_type_delete($info) {
|
||||
variable_del('location_addanother_' . $info->type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_node_type_update().
|
||||
* Synchronize our settings.
|
||||
*/
|
||||
function hook_node_type_update($info) {
|
||||
if (!empty($info->old_type) && $info->old_type != $info->type) {
|
||||
$setting = variable_get('location_addanother_' . $info->old_type, 0);
|
||||
variable_del('location_addanother_' . $info->old_type);
|
||||
variable_set('location_addanother_' . $info->type, $setting);
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
name = Location CCK
|
||||
description = Defines a Location field type.
|
||||
dependencies[] = location
|
||||
package = CCK
|
||||
core = 7.x
|
||||
files[] = location_cck.module
|
||||
files[] = location_cck.install
|
||||
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-02-18
|
||||
version = "7.x-3.x-dev"
|
||||
core = "7.x"
|
||||
project = "location"
|
||||
datestamp = "1329524299"
|
||||
|
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the location_cck module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Drupal 6 location_cck 3.x update.
|
||||
*/
|
||||
function location_cck_update_6301() {
|
||||
// Create a temporary table to fix some location_instance data.
|
||||
$schema = drupal_get_schema('location_instance');
|
||||
$schema['description'] = 'Temp table to repair data integrity of location_instance table.';
|
||||
unset($schema['indexes']);
|
||||
db_create_table('location_instance_tmp', $schema);
|
||||
|
||||
// Populate the temporary table.
|
||||
$join_select = db_select('location_instance', 'li');
|
||||
$join_select->addExpression("SUBSTRING_INDEX(genid, ':', -1)", 'genvid');
|
||||
$join_select->fields('li', array('lid', 'genid'));
|
||||
|
||||
$insert_select = db_select('node', 'n')
|
||||
->fields('n', array('nid', 'vid'))
|
||||
->fields('l', array('genid', 'lid'))
|
||||
->join($join_select, 'l', 'n.vid = l.genvid');
|
||||
|
||||
db_insert('location_instance_tmp')
|
||||
->fields(array('nid', 'vid', 'genid', 'lid'))
|
||||
->from($insert_select)
|
||||
->execute();
|
||||
|
||||
// Update the location_instance table.
|
||||
db_delete('location_instance')
|
||||
->condition('genid', 'cck:%', 'LIKE')
|
||||
->execute();
|
||||
|
||||
$insert_select = db_select('location_instance_tmp', 'lit')
|
||||
->fields('lit', array('nid', 'vid', 'genid', 'lid'));
|
||||
|
||||
db_insert('location_instance')
|
||||
->fields(array('nid', 'vid', 'genid', 'lid'))
|
||||
->from($insert_select)
|
||||
->execute();
|
||||
|
||||
// Remove the temporary table.
|
||||
db_drop_table('location_instance_tmp');
|
||||
}
|
@@ -0,0 +1,617 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Defines location field type.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function location_cck_theme() {
|
||||
return array(
|
||||
'location_cck_field_all' => array(
|
||||
'variables' => array(
|
||||
'location' => NULL,
|
||||
'hide' => array(),
|
||||
'field' => NULL,
|
||||
'instance' => NULL,
|
||||
),
|
||||
),
|
||||
'location_cck_field_map' => array(
|
||||
'variables' => array(
|
||||
'locations' => NULL,
|
||||
'field' => NULL,
|
||||
'instance' => NULL,
|
||||
),
|
||||
),
|
||||
'location_cck_field_popup' => array(
|
||||
'variables' => array(
|
||||
'location' => NULL,
|
||||
'instance' => NULL,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_info().
|
||||
*/
|
||||
function location_cck_field_info() {
|
||||
return array(
|
||||
'location' => array(
|
||||
'label' => t('Location'),
|
||||
'description' => t('Store a location.module location.'),
|
||||
'settings' => array(),
|
||||
'instance_settings' => array(),
|
||||
'default_widget' => 'location',
|
||||
'default_formatter' => 'location_default',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement hook_field_settings_form().
|
||||
*/
|
||||
function location_cck_field_settings_form($field, $instance, $has_data) {
|
||||
$settings = isset($field['settings']['location_settings']) ? $field['settings']['location_settings'] : array();
|
||||
$form = array();
|
||||
$form['location_settings'] = location_settings($settings);
|
||||
|
||||
// Multiple is handled by CCK.
|
||||
unset($form['location_settings']['multiple']);
|
||||
// CCK handles weight, and collapsibility is not changeable.
|
||||
unset($form['location_settings']['form']['weight']);
|
||||
unset($form['location_settings']['form']['collapsible']);
|
||||
unset($form['location_settings']['form']['collapsed']);
|
||||
unset($form['location_settings']['display']['weight']);
|
||||
|
||||
// We want to see the settings, so uncollapse them.
|
||||
$form['location_settings']['#collapsible'] = FALSE;
|
||||
$form['location_settings']['form']['#collapsed'] = FALSE;
|
||||
$form['location_settings']['display']['#collapsed'] = FALSE;
|
||||
|
||||
// Add some GMap settings, if GMap is enabled.
|
||||
if (module_exists('gmap')) {
|
||||
$form['gmap_macro'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('GMap Macro'),
|
||||
'#rows' => 2,
|
||||
'#maxlength' => 500,
|
||||
'#description' => t('A macro to be used as a base map for this field. This map will be recentered on the location, so the center is not that important.'),
|
||||
'#default_value' => !empty($field['settings']['gmap_macro']) ? $field['settings']['gmap_macro'] : '[gmap ]',
|
||||
);
|
||||
$options = gmap_get_marker_titles();
|
||||
$form['gmap_marker'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('GMap marker'),
|
||||
'#options' => $options,
|
||||
'#default_value' => !empty($field['settings']['gmap_marker']) ? $field['settings']['gmap_marker'] : 'drupal',
|
||||
);
|
||||
}
|
||||
else {
|
||||
// Preserve existing data, apply defaults even if gmap is disabled.
|
||||
$form['gmap_macro'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => !empty($field['settings']['gmap_macro']) ? $field['settings']['gmap_macro'] : '[gmap ]',
|
||||
);
|
||||
$form['gmap_marker'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => !empty($field['settings']['gmap_marker']) ? $field['settings']['gmap_marker'] : 'drupal',
|
||||
);
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_settings().
|
||||
*/
|
||||
function location_cck_field_settings($op, $field) {
|
||||
switch ($op) {
|
||||
case 'views data':
|
||||
// We want to for the most part use the CCK stuff, but we also want to
|
||||
// patch in a relationship so location's views support can target
|
||||
// cck fields directly.
|
||||
$table = content_views_tablename($field);
|
||||
$db_info = content_database_info($field);
|
||||
$field_alias = $db_info['columns']['lid']['column'];
|
||||
$data = content_views_field_views_data($field);
|
||||
$data[$table][$field_alias]['relationship'] = array(
|
||||
'base' => 'location',
|
||||
'field' => 'lid',
|
||||
'handler' => 'views_handler_relationship',
|
||||
'label' => t('Location'), // @@@ Some sort of better name?
|
||||
);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement hook_field_schema().
|
||||
*/
|
||||
function location_cck_field_schema($field) {
|
||||
switch ($field['type']) {
|
||||
case 'location':
|
||||
$columns = array(
|
||||
'lid' => array(
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => FALSE,
|
||||
),
|
||||
);
|
||||
break;
|
||||
}
|
||||
return array(
|
||||
'columns' => $columns,
|
||||
'indexes' => array('lid' => array('lid')),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement hook_field_insert().
|
||||
*/
|
||||
function location_cck_field_insert($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
if ($entity_type == 'node') {
|
||||
if (!empty($items)) {
|
||||
// Store instances of locations by field name and vid.
|
||||
$criteria = array(
|
||||
'genid' => 'cck:' . $field['field_name'] . ':' . $entity->vid,
|
||||
'vid' => $entity->vid,
|
||||
'nid' => $entity->nid,
|
||||
);
|
||||
location_save_locations($items, $criteria);
|
||||
}
|
||||
}else{
|
||||
if (!empty($items)) {
|
||||
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
|
||||
// Store instances of locations by field name and vid.
|
||||
$criteria = array(
|
||||
'genid' => 'field:' . $field['field_name'] . ':' . $entity_type . ':' . $id,
|
||||
'vid' => $vid ? $vid : $id,
|
||||
'nid' => $id,
|
||||
);
|
||||
location_save_locations($items, $criteria);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement hook_field_update().
|
||||
*/
|
||||
function location_cck_field_update($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
if ($entity_type == 'node') {
|
||||
if (!empty($items)) {
|
||||
// Store instances of locations by field name and vid.
|
||||
$criteria = array(
|
||||
'genid' => 'cck:' . $field['field_name'] . ':' . $entity->vid,
|
||||
'vid' => $entity->vid,
|
||||
'nid' => $entity->nid,
|
||||
);
|
||||
location_save_locations($items, $criteria);
|
||||
}
|
||||
}else{
|
||||
if (!empty($items)) {
|
||||
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
|
||||
// Store instances of locations by field name and vid.
|
||||
$criteria = array(
|
||||
'genid' => 'field:' . $field['field_name'] . ':' . $entity_type . ':' . $id,
|
||||
'vid' => $vid ? $vid : $id,
|
||||
'nid' => $id,
|
||||
);
|
||||
location_save_locations($items, $criteria);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement hook_field_delete().
|
||||
*/
|
||||
function location_cck_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
if ($entity_type == 'node') {
|
||||
// @TODO: Fix this properly.
|
||||
|
||||
// Use the CCK storage to figure out the vids that need to be deleted,
|
||||
// and clean up all the applicable references.
|
||||
// $db_info = content_database_info($field);
|
||||
// $result = db_query('SELECT vid FROM {' . $db_info['table'] . '} WHERE nid = :nid', array(':nid' => $node->nid));
|
||||
$result = db_query('SELECT vid FROM {node_revision} WHERE nid = :nid', array(':nid' => $entity->nid));
|
||||
foreach ($result as $row) {
|
||||
$genid = 'cck:' . $field['field_name'] . ':' . $row->vid;
|
||||
$locs = array();
|
||||
location_save_locations($locs, array('genid' => $genid));
|
||||
}
|
||||
}else {
|
||||
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
|
||||
$genid = 'field:' . $field['field_name'] . ':' . $entity_type . ':' . $id;
|
||||
$locs = array();
|
||||
location_save_locations($locs, array('genid' => $genid));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement hook_field_delete_revision().
|
||||
*/
|
||||
function location_cck_field_delete_revision($entity_type, $entity, $field, $instance, $langcode, &$items) {
|
||||
if ($entity_type == 'node') {
|
||||
$genid = 'cck:' . $field['field_name'] . ':' . $entity->vid;
|
||||
$locs = array();
|
||||
location_save_locations($locs, array('genid' => $genid));
|
||||
}else{
|
||||
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
|
||||
$genid = 'field:' . $field['field_name'] . ':' . $entity_type . ':' . $id;
|
||||
$locs = array();
|
||||
location_save_locations($locs, array('genid' => $genid));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement hook_field_validate().
|
||||
*/
|
||||
function location_cck_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
|
||||
// @@@ Fixme
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement hook_field_load().
|
||||
*/
|
||||
function location_cck_field_load($entity_type, $entities, $field, $instances, $langcode, &$items, $age) {
|
||||
// if ($entity_type == 'node') {
|
||||
foreach ($entities as $id => $entity) {
|
||||
foreach ($items[$id] as $delta => $item) {
|
||||
$location = array();
|
||||
// Load the location if it exists.
|
||||
// If we are previewing a new node it will not.
|
||||
if (!empty($item['lid'])) {
|
||||
$location = location_load_location($item['lid']);
|
||||
}
|
||||
// Combine the item with the location loaded from the database.
|
||||
// This will allow $item to display in the case of previewing a node.
|
||||
$items[$id][$delta] = array_merge($location, $item);
|
||||
}
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field().
|
||||
*/
|
||||
function location_cck_field($op, &$node, $field, &$items, $teaser, $page) {
|
||||
switch ($op) {
|
||||
case 'sanitize':
|
||||
// Get the location information for the lid if it hasn't already been
|
||||
// loaded (in the hook_field() load $op using location_load_location()).
|
||||
// This is necessary for Views and any other modules that use the
|
||||
// content_format() function to render CCK fields because content_format()
|
||||
// doesn't call the "load" $op.
|
||||
foreach ($items as $delta => $item) {
|
||||
if (!isset($item['latitude'])) {
|
||||
$items[$delta] = array_merge($items[$delta], location_load_location($item['lid']));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_field_formatter_info().
|
||||
*/
|
||||
function location_cck_field_formatter_info() {
|
||||
$info = array(
|
||||
'location_default' => array(
|
||||
'label' => t('Default (address)'),
|
||||
'field types' => array('location'),
|
||||
),
|
||||
);
|
||||
if (module_exists('gmap')) {
|
||||
$info['location_all'] = array(
|
||||
'label' => t('Address with map'),
|
||||
'field types' => array('location'),
|
||||
);
|
||||
$info['location_map'] = array(
|
||||
'label' => t('Map only'),
|
||||
'field types' => array('location'),
|
||||
);
|
||||
// @@@ How to do in D7?
|
||||
$info['location_multiple'] = array(
|
||||
'label' => t('Multiple field values on a single map'),
|
||||
'field types' => array('location'),
|
||||
);
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_formatter_view().
|
||||
* @Todo: This.
|
||||
*/
|
||||
function location_cck_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
|
||||
$element = array();
|
||||
|
||||
$settings = $field['settings']['location_settings'];
|
||||
$hide = (isset($settings['display']['hide'])) ? array_keys(array_filter($settings['display']['hide'])) : array();
|
||||
|
||||
switch ($display['type']) {
|
||||
case 'location_default':
|
||||
foreach ($items as $delta => $item) {
|
||||
if (!empty($item['lid']) || !empty($entity->in_preview)) {
|
||||
$element[$delta]['#theme'] = 'location';
|
||||
$element[$delta]['#location'] = $item;
|
||||
$element[$delta]['#hide'] = $hide;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'location_all':
|
||||
foreach ($items as $delta => $item) {
|
||||
if (!empty($item['lid']) || !empty($entity->in_preview)) {
|
||||
$element[$delta]['#theme'] = 'location_cck_field_all';
|
||||
$element[$delta]['#location'] = $item;
|
||||
$element[$delta]['#hide'] = $hide;
|
||||
$element[$delta]['#field'] = $field;
|
||||
$element[$delta]['#instance'] = $instance;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'location_map':
|
||||
foreach ($items as $delta => $item) {
|
||||
if (!empty($item['lid']) || !empty($entity->in_preview)) {
|
||||
$element[$delta]['#theme'] = 'location_cck_field_map';
|
||||
$element[$delta]['#locations'] = array($item);
|
||||
$element[$delta]['#field'] = $field;
|
||||
$element[$delta]['#instance'] = $instance;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'location_multiple':
|
||||
$element[0]['#theme'] = 'location_cck_field_map';
|
||||
$element[0]['#locations'] = $items;
|
||||
$element[0]['#field'] = $field;
|
||||
$element[0]['#instance'] = $instance;
|
||||
break;
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_widget_info().
|
||||
*/
|
||||
function location_cck_field_widget_info() {
|
||||
return array(
|
||||
'location' => array(
|
||||
'label' => t('Location Field'),
|
||||
'field types' => array('location'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement hook_field_widget_form().
|
||||
*/
|
||||
function location_cck_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
|
||||
if ($field['type'] == 'location') {
|
||||
$settings = $field['settings']['location_settings'];
|
||||
|
||||
// Load location data for existing locations.
|
||||
if ($form_state['rebuild'] && !empty($form_state['values'][$field['field_name']][$langcode][$delta])) {
|
||||
$location = $form_state['values'][$field['field_name']][$langcode][$delta];
|
||||
}
|
||||
elseif (isset($items[$delta]['lid']) && $items[$delta]['lid']) {
|
||||
$location = location_load_location($items[$delta]['lid']);
|
||||
}
|
||||
// Load location data passed by cck.
|
||||
else if (isset($items[$delta]) && is_array($items[$delta]) && !empty($items[$delta])) {
|
||||
|
||||
// Initialize empty location.
|
||||
$location = location_empty_location($settings);
|
||||
foreach ($items[$delta] as $k => $v) {
|
||||
$location[$k] = $v;
|
||||
}
|
||||
// We can't trust that CCK is giving us the right information.
|
||||
// It can't tell us whether $items is defaults or multistep values.
|
||||
// Location *needs* the defaults to match the initial field values,
|
||||
// so we re-calculate the defaults here and stash them into the settings.
|
||||
// @@@ There is still a bug here!
|
||||
// If you go back and edit something, and you hadn't set a location the
|
||||
// first time, CCK fails to set up the defaults properly!
|
||||
// I'm just going to leave it like that for now, because I don't know how
|
||||
// to work around it.
|
||||
$temp = NULL; //content_default_value($form, $form_state, $field, 0);
|
||||
if (is_array($temp) && isset($temp[$delta]) && is_array($temp[$delta])) {
|
||||
foreach ($temp[$delta] as $k => $v) {
|
||||
$settings['form']['fields'][$k]['default'] = $v;
|
||||
}
|
||||
}
|
||||
// unset($location['location_settings']);
|
||||
// unset($location['locpick']);
|
||||
}
|
||||
else {
|
||||
$location = location_empty_location($settings);
|
||||
}
|
||||
|
||||
$element = array(
|
||||
'#type' => 'location_element',
|
||||
'#has_garbage_value' => TRUE,
|
||||
'#value' => '',
|
||||
'#title' => t($instance['label']),
|
||||
'#description' => t($instance['description']),
|
||||
'#required' => $instance['required'],
|
||||
'#location_settings' => $settings,
|
||||
'#default_value' => $location,
|
||||
);
|
||||
|
||||
return $element;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_field_is_empty().
|
||||
*/
|
||||
function location_cck_field_is_empty($item, $field) {
|
||||
$fields = array();
|
||||
if (location_is_empty($item, $fields)) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return both an address and a map for an individual item.
|
||||
*/
|
||||
function theme_location_cck_field_all($variables) {
|
||||
$content = theme('location', array('location' => $variables['location'], 'hide' => $variables['hide']));
|
||||
$content .= theme_location_cck_field_map(array('locations' => array($variables['location']), 'field' => $variables['field'], 'instance' => $variables['instance']));
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternate function to return a map with all
|
||||
* multiple values in the same map.
|
||||
*/
|
||||
function theme_location_cck_formatter_combined($variables) {
|
||||
$location = $variables['element'];
|
||||
|
||||
$field = content_fields($element['#field_name'], $element['#type_name']);
|
||||
$locations = $element['#items'];
|
||||
return theme_location_cck_field_map(array('locations' => $locations, 'field' => $field));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a GMap map for one or more location field values.
|
||||
*
|
||||
* Mostly just cut and paste from gmap_location
|
||||
* block view.
|
||||
*/
|
||||
function theme_location_cck_field_map($variables) {
|
||||
$locations = $variables['locations'];
|
||||
$field = $variables['field'];
|
||||
$instance = $variables['instance'];
|
||||
|
||||
$count = 0;
|
||||
$content = '';
|
||||
foreach ($locations as $location) {
|
||||
if (location_has_coordinates($location)) {
|
||||
$count++;
|
||||
$markername = isset($field['settings']['gmap_marker']) ? $field['settings']['gmap_marker'] : 'drupal';
|
||||
$markers[] = array(
|
||||
'latitude' => $location['latitude'],
|
||||
'longitude' => $location['longitude'],
|
||||
'markername' => $markername,
|
||||
'offset' => $count-1,
|
||||
'text' => theme('location_cck_field_popup', array('location' => $location, 'instance' => $instance)),
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!empty($markers)) {
|
||||
$macro = !empty($field['settings']['gmap_macro']) ? $field['settings']['gmap_macro'] : '[gmap ]';
|
||||
$map = array_merge(gmap_defaults(), gmap_parse_macro($macro));
|
||||
$map['latitude'] = $markers[0]['latitude'];
|
||||
$map['longitude'] = $markers[0]['longitude'];
|
||||
$map['markers'] = $markers;
|
||||
$map['id'] = gmap_get_auto_mapid();
|
||||
// Render a map element.
|
||||
$location_map = array(
|
||||
'#type' => 'gmap',
|
||||
'#gmap_settings' => $map,
|
||||
);
|
||||
$content = drupal_render($location_map);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme the GMap popup text for the field.
|
||||
*/
|
||||
function theme_location_cck_field_popup($variables) {
|
||||
$location = $variables['location'];
|
||||
$instance = $variables['instance'];
|
||||
|
||||
$hide = (isset($field['location_settings']['display']['hide'])) ? array_keys(array_filter($field['location_settings']['display']['hide'])) : array();
|
||||
// Don't use a map link in a popup!
|
||||
// We're making the name into a title.
|
||||
$hide[] = 'map_link';
|
||||
$hide[] = 'name';
|
||||
|
||||
$markertitle = $instance['label'];
|
||||
if (!empty($location['name'])) {
|
||||
$markertitle = $location['name'];
|
||||
}
|
||||
return '<h4>'. $markertitle .'</h4>'. theme('location', array('location' => $location, 'hide' => $hide));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_token_list().
|
||||
*/
|
||||
function location_cck_token_list($type = 'all') {
|
||||
if ($type == 'field') {
|
||||
$tokens = array();
|
||||
|
||||
$fields = location_field_names(TRUE);
|
||||
// @@@ We really need to rethink fields in location..
|
||||
unset($fields['locpick']);
|
||||
foreach ($fields as $k => $v) {
|
||||
$tokens['location'][$k] = $v;
|
||||
}
|
||||
|
||||
return $tokens;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_token_values().
|
||||
*/
|
||||
function location_cck_token_values($type, $object = NULL) {
|
||||
if ($type == 'field') {
|
||||
$tokens = array();
|
||||
$item = $object[0];
|
||||
if ($item['lid']) {
|
||||
// If the location exists, we need to set up the tokens.
|
||||
|
||||
$location = array(
|
||||
// There is no way to find out which elements to hide because $item does not contain
|
||||
// the 'location_settings' element, so for now, just set it to be an empty array.
|
||||
// See http://drupal.org/node/463618 for more infomation.
|
||||
'hide' => array(),
|
||||
'location' => location_load_location($item['lid']),
|
||||
);
|
||||
|
||||
// @@@ This is rather silly, but I can't think of anything better at the moment.
|
||||
$variables = array('location' => $location);
|
||||
template_preprocess_location($variables);
|
||||
|
||||
$fields = location_field_names(TRUE);
|
||||
// @@@ We really need to rethink fields in location..
|
||||
unset($fields['locpick']);
|
||||
foreach ($fields as $k => $v) {
|
||||
if (isset($location[$k])) {
|
||||
$tokens[$k] = $location[$k];
|
||||
}
|
||||
else {
|
||||
$tokens[$k] = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
return $tokens;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_locationapi().
|
||||
*/
|
||||
function location_cck_locationapi(&$obj, $op, $a3 = NULL, $a4 = NULL, $a5 = NULL) {
|
||||
switch ($op) {
|
||||
case 'instance_links':
|
||||
foreach ($obj as $k => $v) {
|
||||
if (substr($v['genid'], 0, 4) == 'cck:') {
|
||||
$data = explode(':', $v['genid']);
|
||||
$obj[$k]['href'] = 'node/' . $data[2];
|
||||
$obj[$k]['title'] = t('CCK location');
|
||||
$obj[$k]['type'] = t('CCK location');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
name = Location Fax
|
||||
package = Location
|
||||
description = Allows you to add a fax number to a location.
|
||||
dependencies[] = location
|
||||
core = 7.x
|
||||
files[] = location_fax.module
|
||||
files[] = location_fax.install
|
||||
files[] = location_fax.views.inc
|
||||
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-02-18
|
||||
version = "7.x-3.x-dev"
|
||||
core = "7.x"
|
||||
project = "location"
|
||||
datestamp = "1329524299"
|
||||
|
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the location_fax module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function location_fax_schema() {
|
||||
$schema['location_fax'] = array(
|
||||
'description' => 'location_fax.module {location} supplementary table.',
|
||||
'fields' => array(
|
||||
'lid' => array(
|
||||
'description' => '{location}.lid',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'fax' => array(
|
||||
'description' => 'Fax number',
|
||||
'type' => 'varchar',
|
||||
'length' => 31,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
),
|
||||
'primary key' => array('lid'),
|
||||
);
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_install().
|
||||
*/
|
||||
function location_fax_install() {
|
||||
// Change weight so we execute after location.
|
||||
db_update('system')
|
||||
->fields(array(
|
||||
'weight' => 1,
|
||||
))
|
||||
->condition('name', 'location_fax')
|
||||
->condition('type', 'module')
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Location 3.0 update 1.
|
||||
* Fix pgsql -- The table definition was broken.
|
||||
*/
|
||||
function location_fax_update_5300() {
|
||||
if (!db_table_exists('location_fax')) {
|
||||
$schema['location_fax'] = array(
|
||||
'description' => 'location_fax.module {location} supplementary table.',
|
||||
'fields' => array(
|
||||
'lid' => array(
|
||||
'description' => '{location}.lid',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'fax' => array(
|
||||
'description' => 'Fax number',
|
||||
'type' => 'varchar',
|
||||
'length' => 31,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
),
|
||||
'primary key' => array('lid'),
|
||||
);
|
||||
|
||||
db_create_table('location_fax', $schema['location_fax']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Location 3.0 update 2.
|
||||
* Change weight of module.
|
||||
*/
|
||||
function location_fax_update_5301() {
|
||||
// This update was moved to update 5302.
|
||||
}
|
||||
|
||||
/**
|
||||
* Location 3.0 update 2.
|
||||
* Change weight of module.
|
||||
*/
|
||||
function location_fax_update_5302() {
|
||||
// Change weight.
|
||||
db_update('system')
|
||||
->fields(array(
|
||||
'weight' => 1,
|
||||
))
|
||||
->condition('name', 'location_fax')
|
||||
->condition('type', 'module')
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Drupal 6 updates.
|
||||
*/
|
||||
function location_fax_update_6301() {
|
||||
db_change_field('location_fax', 'fax', 'fax', array(
|
||||
'description' => 'Fax number',
|
||||
'type' => 'varchar',
|
||||
'length' => 31,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
));
|
||||
}
|
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Add fax number fields to Location address.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_locationapi().
|
||||
*/
|
||||
function location_fax_locationapi(&$location, $op, $a3 = NULL, $a4 = NULL) {
|
||||
switch ($op) {
|
||||
case 'fields':
|
||||
return array('fax' => t('Fax number'));
|
||||
|
||||
case 'defaults':
|
||||
return array(
|
||||
'fax' => array('default' => '', 'collect' => 0, 'weight' => 30),
|
||||
);
|
||||
|
||||
case 'field_expand':
|
||||
if ($a3 == 'fax') {
|
||||
return array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Fax number'),
|
||||
'#size' => 31,
|
||||
'#maxlength' => 31,
|
||||
'#description' => NULL,
|
||||
'#required' => ($a4 == 2),
|
||||
'#default_value' => $location,
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'save':
|
||||
db_delete('location_fax')
|
||||
->condition('lid', $location['lid'])
|
||||
->execute();
|
||||
if (!empty($location['fax'])) {
|
||||
db_insert('location_fax')
|
||||
->fields(array(
|
||||
'lid' => $location['lid'],
|
||||
'fax' => $location['fax'],
|
||||
))
|
||||
->execute();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'load':
|
||||
$fields = array();
|
||||
$fax = db_query('SELECT fax FROM {location_fax} WHERE lid = :lid', array(':lid' => $location['lid']))->fetchField();
|
||||
$fields['fax'] = $fax ? $fax : '';
|
||||
return $fields;
|
||||
|
||||
case 'delete':
|
||||
db_delete('location_fax')
|
||||
->condition('lid', $location['lid'])
|
||||
->execute();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_api().
|
||||
*/
|
||||
function location_fax_views_api() {
|
||||
return array(
|
||||
'api' => 3,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_token_list().
|
||||
*/
|
||||
function location_fax_token_list($type = 'all') {
|
||||
if ($type == 'node' || $type == 'user' || $type == 'all') {
|
||||
$tokens['location']['location-fax_N'] = t('Location Fax number (If there are multiple locations per node, N is the iteration, starting with 0)');
|
||||
return $tokens;
|
||||
}
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views 3 support for Location Fax.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_views_data().
|
||||
*/
|
||||
function location_fax_views_data() {
|
||||
// ----------------------------------------------------------------
|
||||
// location_fax table -- basic table information.
|
||||
|
||||
// Define the base group of this table. Fields that don't
|
||||
// have a group defined will go into this field by default.
|
||||
|
||||
$data['location_fax']['table']['group'] = t('Location');
|
||||
|
||||
// Join location_fax to all the tables that would be useful
|
||||
$data['location_fax']['table']['join'] = array(
|
||||
// location_fax links to location via lid.
|
||||
'location' => array(
|
||||
'left_field' => 'lid',
|
||||
'field' => 'lid',
|
||||
),
|
||||
// location_fax links to node through location_instance via lid.
|
||||
'node' => array(
|
||||
'left_table' => 'location_instance',
|
||||
'left_field' => 'lid',
|
||||
'field' => 'lid',
|
||||
),
|
||||
// location_fax links to node_revision through location_instance via lid.
|
||||
'node_revision' => array(
|
||||
'left_table' => 'location_instance',
|
||||
'left_field' => 'lid',
|
||||
'field' => 'lid',
|
||||
),
|
||||
// location_fax links to users through location_instance via lid.
|
||||
'users' => array(
|
||||
'left_table' => 'location_instance',
|
||||
'left_field' => 'lid',
|
||||
'field' => 'lid',
|
||||
),
|
||||
);
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// location_fax table -- fields
|
||||
|
||||
$data['location_fax']['fax'] = array(
|
||||
'title' => t('Fax'),
|
||||
'help' => t('The fax number of the selected location.'),
|
||||
'field' => array(
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'views_handler_argument_string',
|
||||
'empty field name' => t('None'),
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_string',
|
||||
'allow empty' => TRUE,
|
||||
),
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
name = Location Generate
|
||||
description = Bulk assign random latitude and longitudes to nodes.
|
||||
package = Development
|
||||
dependencies[] = devel_generate
|
||||
dependencies[] = location
|
||||
core = 7.x
|
||||
files[] = location_generate.module
|
||||
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-02-18
|
||||
version = "7.x-3.x-dev"
|
||||
core = "7.x"
|
||||
project = "location"
|
||||
datestamp = "1329524299"
|
||||
|
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Generate random locations.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_node_presave().
|
||||
*/
|
||||
function location_generate_node_presave($node) {
|
||||
// Devel.module bulk node generation.
|
||||
if (isset($node->devel_generate)) {
|
||||
// Argh, we inherit a broken rand() on windows because devel_generate
|
||||
// calls array_rand()...
|
||||
// http://bugs.php.net/bug.php?id=45301
|
||||
srand((double) microtime() * 1000000);
|
||||
$sources = array(LOCATION_LATLON_USER_SUBMITTED, LOCATION_LATLON_GEOCODED_APPROX, LOCATION_LATLON_GEOCODED_EXACT);
|
||||
$results = $node->devel_generate;
|
||||
if ($results['add_locations']) {
|
||||
$countries = location_get_iso3166_list();
|
||||
|
||||
$numlocs = rand(0, (int) variable_get('location_maxnum_' . $node->type, 0));
|
||||
$node->locations = array();
|
||||
for ($i = 0; $i < $numlocs; $i++) {
|
||||
$country_code = array_rand($countries);
|
||||
$provinces = location_get_provinces($country_code);
|
||||
$province_code = array_rand($provinces);
|
||||
|
||||
$location = array(
|
||||
'lid' => NULL,
|
||||
'name' => devel_create_greeking(mt_rand(1, 4), TRUE),
|
||||
'street' => location_generate_generate_street(),
|
||||
'additional' => '',
|
||||
'city' => devel_generate_word(mt_rand(5, 15)),
|
||||
'province' => $province_code,
|
||||
'postal_code' => mt_rand(1000, 99999),
|
||||
'country' => $country_code,
|
||||
'latitude' => (float) ((mt_rand(0, 120000) - 60000) / 1000),
|
||||
'longitude' => (float) ((mt_rand(0, 360000) - 180000) / 1000),
|
||||
'source' => $sources[rand(0, 2)],
|
||||
'inhibit_geocode' => TRUE,
|
||||
);
|
||||
$settings = variable_get('location_settings_node_' . $node->type, array());
|
||||
$location['location_settings'] = $settings;
|
||||
$node->locations[] = $location;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
* Alter the devel_generate_content_form form.
|
||||
*/
|
||||
function location_generate_form_devel_generate_content_form_alter(&$form, &$form_state) {
|
||||
$form['add_locations'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Add locations to each node.'),
|
||||
'#description' => t('Added by location_generate.module'),
|
||||
'#default_value' => FALSE,
|
||||
);
|
||||
|
||||
if (!isset($form['submit']['#weight'])) {
|
||||
$form['submit']['#weight'] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to generate street values.
|
||||
*/
|
||||
function location_generate_generate_street() {
|
||||
$type = array(
|
||||
'Street' => 'Street',
|
||||
'Road' => 'Road',
|
||||
'Boulevard' => 'Boulevard',
|
||||
'Way' => 'Way',
|
||||
'Terrace' => 'Terrace',
|
||||
'Row' => 'Row',
|
||||
'Lane' => 'Lane',
|
||||
'Place' => 'Place',
|
||||
'Close' => 'Close',
|
||||
'Court' => 'Court',
|
||||
'Alley' => 'Alley',
|
||||
'Crescent' => 'Crescent',
|
||||
'Parkway' => 'Parkway',
|
||||
);
|
||||
|
||||
return mt_rand(1, 9999) . ' ' . devel_create_greeking(mt_rand(1, 3), TRUE) . ' ' . array_rand($type);
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
name = Location Phone
|
||||
package = Location
|
||||
description = Allows you to add a phone number to a location.
|
||||
dependencies[] = location
|
||||
core = 7.x
|
||||
files[] = location_phone.module
|
||||
files[] = location_phone.install
|
||||
files[] = location_phone.views.inc
|
||||
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-02-18
|
||||
version = "7.x-3.x-dev"
|
||||
core = "7.x"
|
||||
project = "location"
|
||||
datestamp = "1329524299"
|
||||
|
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the location_phone module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function location_phone_schema() {
|
||||
$schema['location_phone'] = array(
|
||||
'description' => 'location_phone.module {location} supplementary table.',
|
||||
'fields' => array(
|
||||
'lid' => array(
|
||||
'description' => '{location}.lid',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'phone' => array(
|
||||
'description' => 'Phone number',
|
||||
'type' => 'varchar',
|
||||
'length' => 31,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
),
|
||||
'primary key' => array('lid'),
|
||||
);
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_install().
|
||||
*/
|
||||
function location_phone_install() {
|
||||
// Change weight.
|
||||
db_update('system')
|
||||
->fields(array(
|
||||
'weight' => 1,
|
||||
))
|
||||
->condition('name', 'location_phone')
|
||||
->condition('type', 'module')
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Location 3.0 update 1.
|
||||
* Fix pgsql -- The table definition was broken.
|
||||
*/
|
||||
function location_phone_update_5300() {
|
||||
if (!db_table_exists('location_phone')) {
|
||||
$schema['location_phone'] = array(
|
||||
'description' => 'location_phone.module {location} supplementary table.',
|
||||
'fields' => array(
|
||||
'lid' => array(
|
||||
'description' => '{location}.lid',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'phone' => array(
|
||||
'description' => 'Phone number',
|
||||
'type' => 'varchar',
|
||||
'length' => 31,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
),
|
||||
'primary key' => array('lid'),
|
||||
);
|
||||
db_create_table('location_phone', $schema['location_phone']);
|
||||
}
|
||||
else {
|
||||
// If the table WAS created (i.e. user manually fixed bug and reinstalled), g/c the postal_code column.
|
||||
if (db_field_exists('location_phone', 'postal_code')) {
|
||||
db_drop_field('location_phone', 'postal_code');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Location 3.0 update 2.
|
||||
* Change weight of module.
|
||||
*/
|
||||
function location_phone_update_5301() {
|
||||
// This update was moved to update 5302.
|
||||
}
|
||||
|
||||
/**
|
||||
* Location 3.0 update 2.
|
||||
* Change weight of module.
|
||||
*/
|
||||
function location_phone_update_5302() {
|
||||
// Change weight.
|
||||
db_update('system')
|
||||
->fields(array(
|
||||
'weight' => 1,
|
||||
))
|
||||
->condition('name', 'location_phone')
|
||||
->condition('type', 'module')
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Drupal 6 updates.
|
||||
*/
|
||||
function location_phone_update_6301() {
|
||||
db_change_field('location_phone', 'phone', 'phone', array(
|
||||
'description' => 'Phone number',
|
||||
'type' => 'varchar',
|
||||
'length' => 31,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
));
|
||||
}
|
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Add phone number fields to Location address.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_locationapi().
|
||||
*/
|
||||
function location_phone_locationapi(&$location, $op, $a3 = NULL, $a4 = NULL) {
|
||||
switch ($op) {
|
||||
case 'fields':
|
||||
return array('phone' => t('Phone number'));
|
||||
|
||||
case 'defaults':
|
||||
return array(
|
||||
'phone' => array('default' => '', 'collect' => 0, 'weight' => 25),
|
||||
);
|
||||
|
||||
case 'field_expand':
|
||||
if ($a3 == 'phone') {
|
||||
return array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Phone number'),
|
||||
'#size' => 31,
|
||||
'#maxlength' => 31,
|
||||
'#description' => NULL,
|
||||
'#required' => ($a4 == 2),
|
||||
'#default_value' => $location,
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'save':
|
||||
db_delete('location_phone')
|
||||
->condition('lid', $location['lid'])
|
||||
->execute();
|
||||
if (!empty($location['phone'])) {
|
||||
db_insert('location_phone')
|
||||
->fields(array(
|
||||
'lid' => $location['lid'],
|
||||
'phone' => $location['phone'],
|
||||
))
|
||||
->execute();
|
||||
}
|
||||
break;
|
||||
|
||||
case 'load':
|
||||
$fields = array();
|
||||
$phone = db_query('SELECT phone FROM {location_phone} WHERE lid = :lid', array(':lid' => $location['lid']))->fetchField();
|
||||
$fields['phone'] = $phone ? $phone : '';
|
||||
return $fields;
|
||||
|
||||
case 'delete':
|
||||
db_delete('location_phone')
|
||||
->condition('lid', $location['lid'])
|
||||
->execute();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_api().
|
||||
*/
|
||||
function location_phone_views_api() {
|
||||
return array(
|
||||
'api' => 3,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_token_list().
|
||||
*/
|
||||
function location_phone_token_list($type = 'all') {
|
||||
if ($type == 'node' || $type == 'user' || $type == 'all') {
|
||||
$tokens['location']['location-phone_N'] = t('Location Phone number (If there are multiple locations per node, N is the iteration, starting with 0)');
|
||||
return $tokens;
|
||||
}
|
||||
}
|
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views 3 support for Location Phone.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_views_data().
|
||||
*/
|
||||
function location_phone_views_data() {
|
||||
// ----------------------------------------------------------------
|
||||
// location_phone table -- basic table information.
|
||||
|
||||
// Define the base group of this table. Fields that don't
|
||||
// have a group defined will go into this field by default.
|
||||
|
||||
$data['location_phone']['table']['group'] = t('Location');
|
||||
|
||||
// Join location_phone to all the tables that would be useful
|
||||
$data['location_phone']['table']['join'] = array(
|
||||
// location_phone links to location via lid.
|
||||
'location' => array(
|
||||
'left_field' => 'lid',
|
||||
'field' => 'lid',
|
||||
),
|
||||
// location_phone links to node through location_instance via lid.
|
||||
'node' => array(
|
||||
'left_table' => 'location_instance',
|
||||
'left_field' => 'lid',
|
||||
'field' => 'lid',
|
||||
),
|
||||
// location_phone links to node_revision through location_instance via lid.
|
||||
'node_revision' => array(
|
||||
'left_table' => 'location_instance',
|
||||
'left_field' => 'lid',
|
||||
'field' => 'lid',
|
||||
),
|
||||
// location_phone links to users through location_instance via lid.
|
||||
'users' => array(
|
||||
'left_table' => 'location_instance',
|
||||
'left_field' => 'lid',
|
||||
'field' => 'lid',
|
||||
),
|
||||
);
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// location_phone table -- fields
|
||||
|
||||
$data['location_phone']['phone'] = array(
|
||||
'title' => t('Phone'),
|
||||
'help' => t('The phone number of the selected location.'),
|
||||
'field' => array(
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'views_handler_argument_string',
|
||||
'empty field name' => t('None'),
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_string',
|
||||
'allow empty' => TRUE,
|
||||
),
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
@@ -0,0 +1,547 @@
|
||||
|
||||
Note: This is currently broken and outdated.
|
||||
The location search api is not ready for location 3.
|
||||
|
||||
|
||||
|
||||
This file describes the public API for the CivicSpace location system as defined by
|
||||
in the library implemented by "location.inc" and its supporting files.
|
||||
|
||||
For a example of this API's usage, please consult "location.module"
|
||||
|
||||
|
||||
FUNCTION SPECIFICATIONS DESCRIBED IN THIS FILE:
|
||||
----------------------------------------------
|
||||
location_nearby_postalcodes_bylocation(): A function that searches for postal codes within a specified search-radius
|
||||
for a specified location.
|
||||
|
||||
location_nearby_postalcodes_bylatlon(): A function that searches for postal codes within a specified search-radius for
|
||||
a specified latitude and longitude.
|
||||
|
||||
location_get_postalcode_data(): A function that takes a (postalcode,country) pair an returns lat/lon, city, province. This
|
||||
function is meant to replace location_latlon_rough(); see below.
|
||||
|
||||
location_latlon_rough(): A function that returns the latitude and longitude of the specified postal-code/country pair.
|
||||
This latitude and longitude will be of the approximate center of the postal-code's area. This function
|
||||
will soon be removed from the API as it has been replaced by the more comprehensive
|
||||
location_get_postalcode_data() described above. [TO BE DEPRECATED]
|
||||
|
||||
location_latlon_exact(): A function that returns the latitude and longitude of the given full location. Typically implemented
|
||||
on top of a web-service. [TO BE IMPLEMENTED]
|
||||
|
||||
location_map_link(): A function that returns, based on the site configuration, either NULL or 1 or more deep-links to mapping
|
||||
web sites for the parameter location array.
|
||||
|
||||
location_driving_directions_link(): A function that returns, given 2 locationes, a deep-link to Yahoo! Maps or some other site
|
||||
that provides driving directions. The site chosen depends on the implementation at the country-level.
|
||||
|
||||
location_form(): A function that generates a form for collecting locative information. Depending on the parameters,
|
||||
it can collect just the postal code and country or a full location or whatever fields are specified
|
||||
in its parameters.
|
||||
|
||||
location_proximity_form(): A function that generates a form for collecting proximity search parameters.
|
||||
|
||||
location_valid(): A function for validating locationes. [TO BE SPECIFIED]
|
||||
|
||||
theme_location(): A function that takes in an location and themes it. (e.g., $output .= theme('location', $location)).
|
||||
|
||||
location_distance_between(): A function that, given a pair of lat/lon pairs, returns the distance between them.
|
||||
|
||||
location_form2api(): A function that, given an location submitted via a form generated by location_form, converts the
|
||||
submitted location into a form to be used by the rest of the API.
|
||||
|
||||
location_api2form(): A function that, given an location in the standard array format (see "IMPORTANT NOTES" below)
|
||||
returns an location in a format that can be passed to location_form in order to render the
|
||||
form with the appropriate prefilled values.
|
||||
|
||||
|
||||
"[TO BE SPECIFIED]" => Function spec has not been completed and may possibly be eliminated from spec.
|
||||
"[TO BE IMPLEMENTED]" => Function spec exists but is to be implemented in a future release.
|
||||
"[TO BE DEPRECATED]" => This function will soon be removed from the API.
|
||||
----------------------------------------------
|
||||
|
||||
|
||||
|
||||
IMPORTANT NOTES:
|
||||
----------------
|
||||
Formats
|
||||
---
|
||||
In the following API, a 'location' is merely an associative array with the following keys:
|
||||
'street' => A string for the street portion of an location
|
||||
'additional' => A string for the additional street portion of an location
|
||||
'province' => An upper-case, standard postal abbreviation of a state/province/territory
|
||||
'postal_code' => A string or integer for the postal code
|
||||
'country' => The lower-case of the ISO 3166 two-letter alpha code (e.g., 'us' for U.S., 'ca' for Canada).
|
||||
|
||||
For locations that are passed to location_form() for the $prefilled_values parameter, the same format applies
|
||||
except that the 'province' field is the concatenation of the country code, '-', and the province abbreviation.
|
||||
For example, 'CA' is the value for California for all purposes, but when passing this in a location for prefilled
|
||||
values, it should be 'us-CA'. There are two functions to help convert back and forth between these formats:
|
||||
location_form2api() and location_api2form(). These are described further below.
|
||||
|
||||
Delegation
|
||||
---
|
||||
With the exception of location_form() and location_proximity_form(), the calls to functions listed here are, in the end,
|
||||
dispatched to country-specific location libraries which are implemented in country-specific '.inc' files. For example,
|
||||
location_latlon_rough(), when given a U.S. location, really returns a result that is determined by call to
|
||||
"location_latlon_rough_us()" which is implemented in the file "location.us.inc".
|
||||
|
||||
Current Implementation
|
||||
---
|
||||
Currently, the only country supported is the United States. For the future, however, there will be documentation for how to
|
||||
implement a country-specific include file that can be plugged into the system to support these calls for new countries. This
|
||||
scheme will revolve around method signatures for a handful of simple-to-write functions.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function location_nearby_postalcodes_bylocation($location, $distance, $distance_unit = 'km');
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
Takes an location and a distance and returns an array of all postal-codes (from all countries that are supported)
|
||||
within the specified distance of the specified location.
|
||||
|
||||
@param $location
|
||||
An associative array where
|
||||
'street' => the street location
|
||||
'additional' => extra street location or building name or hall or something like that.
|
||||
'city' => a city name
|
||||
'province' => province code as defined by the country specific include file
|
||||
'country' => lower-cased two-letter ISO 3166 code (REQUIRED)
|
||||
'postal_code' => the postal_code
|
||||
|
||||
@param $distance
|
||||
The number portion of the distance; it is forced to an integer ceiling
|
||||
|
||||
@param $distance_unit
|
||||
The unit of distance being used for the distance being submitted.
|
||||
Valid arguments for $distance_unit are 'mile' and 'km'. If something other than one of
|
||||
these unit types is submitted for this argument, it is forced to 'km'.
|
||||
|
||||
@return
|
||||
An array where
|
||||
-> the keys are a postive integer ranking of the search result's closeness to the parameter $postal_code
|
||||
with 1 being assigned to the nearest postal code
|
||||
-> the values are an associative array where
|
||||
'postal_code' => A postal code that fell within the search-radius given by $distance and $distance_unit.
|
||||
'country' => The two-letter ISO code for the home-country of this particular postal_code search result.
|
||||
'city' => The city to which this postal code belongs.
|
||||
'province' => The province to which this postal code belongs.
|
||||
'lon' => The longitude coordinate of the approximate center of the area covered by 'postal_code'
|
||||
'lat' => The latitude coordinate of the approximate center of the area covered by 'postal_code'
|
||||
'distance' => The number of 'km's or 'mile's that are between the approximate center of the area of
|
||||
the $postal_code parameter and that of the 'postal_code' in this subarray
|
||||
'distance_unit' => The unit of distance specified by 'scalar'
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function location_nearby_postalcodes_bylatlon($lon, $lat, $distance, $distance_unit = 'km');
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
Takes a latitude, longitude, and a distance, and returns all postal_codes within
|
||||
|
||||
@param $lon
|
||||
A floating point of the longitude coordinate of the search point
|
||||
|
||||
@param $lat
|
||||
A floating point of the latitude coordinate of the search point
|
||||
|
||||
@param $distance
|
||||
The number portion of the distance; it is forced to an integer ceiling
|
||||
|
||||
@param $distance_unit
|
||||
The unit of distance being used for the distance being submitted.
|
||||
Valid arguments for $distance_unit are 'mile' and 'km'. If something other than one of
|
||||
these unit types is submitted for this argument, it is forced to 'km'.
|
||||
|
||||
@return
|
||||
An array where
|
||||
-> the keys are a contatenation of the country's ISO code and the postal code. For example, if
|
||||
one of the search results is for postal code "94803" in the United States, the key is then "us94803"
|
||||
-> the values are an associative array where
|
||||
'postal_code' => A postal code that fell within the search-radius given by $distance and $distance_unit.
|
||||
'country' => The two-letter ISO code for the home-country of this particular postal_code search result.
|
||||
'lon' => The longitude coordinate of the approximate center of the area covered by 'postal_code'
|
||||
'lat' => The latitude coordinate of the approximate center of the area covered by 'postal_code'
|
||||
'distance' => The number of 'km's or 'mile's that are between the approximate center of the area of the
|
||||
$postal_code parameter and that of the 'postal_code' in this array
|
||||
'distance_unit' => The unit of distance specified by 'distance'
|
||||
|
||||
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function location_get_postalcode_data($location = array()); +
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
Takes a location and uses the combination of postal code and country to return an array that gives the
|
||||
city, province, and lat/lon dat for that postal code.
|
||||
|
||||
@param $location
|
||||
An associative array $location where
|
||||
'street' => the street portion of the location
|
||||
'additional' => additional street portion of the location
|
||||
'province' => the province, state, or territory
|
||||
'country' => lower-cased two-letter ISO code (REQUIRED)
|
||||
'postal_code' => international postal code (REQUIRED)
|
||||
|
||||
@return
|
||||
NULL if data cannot be found.
|
||||
Otherwise, an associative array where
|
||||
'lat' => is a floating point of the latitude coordinate of this location
|
||||
'lon' => is a floating point of the longitude coordinate of this location
|
||||
'city' => is a string for the city this postalcode is in (or the most recognized city at the given postal)
|
||||
'province' => the province of the given postal code.
|
||||
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function location_latlon_rough($location = array()); +
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
Takes an location and returns a "rough" latitude/longitude pair based on the postal code
|
||||
data available for the given country.
|
||||
|
||||
@param $location
|
||||
An associative array $location where
|
||||
'street' => the street portion of the location
|
||||
'additional' => additional street portion of the location
|
||||
'province' => the province, state, or territory
|
||||
'country' => lower-cased two-letter ISO code (REQUIRED)
|
||||
'postal_code' => international postal code (REQUIRED)
|
||||
|
||||
@return
|
||||
NULL if data cannont be found.
|
||||
Otherwise, an associative array where
|
||||
'lat' => is a floating point of the latitude coordinate of this location
|
||||
'lon' => is a floating point of the longitude coordinate of this location
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function location_latlon_exact($location = array()); +
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
Currently, this is not a priority until there is an implementable use for exact longitude,
|
||||
latitude coordinates for an location. The idea is that this call will eventually retrieve
|
||||
information through a web-service. Whereas location_latlon_rough() returns an approximate
|
||||
lat/lon pair based strictly on the postal code where this lat/lon pair is pulled from a
|
||||
database table, this function is intended to send the entire location to a web-service and
|
||||
to retrieve exact lat/lon coordinates.
|
||||
|
||||
@param $location
|
||||
An array where
|
||||
-> the key values are 'street', 'additional', 'province', 'country', 'postal_code'
|
||||
-> the values are:
|
||||
'street' => the string representing the street location (REQUIRED)
|
||||
'additional' => the string representing the additional street location portion in the location form
|
||||
'city' => the city name (REQUIRED)
|
||||
'province' => the province code defined in the country-specific include file
|
||||
'country' => the lower-case of the two-letter ISO code (REQUIRED)
|
||||
'postal_code' => the postal-code (REQUIRED)
|
||||
|
||||
@return
|
||||
NULL if the delegated-to function that does the actual look-up does not exist.
|
||||
If the appropriate function exists, then this function returns an associative array where
|
||||
'lon' => A floating point number for the longitude coordinate of the parameter location
|
||||
'lat' => A floating point number for the latitude coordinate of the parameter location
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function location_map_link($location = array(), $link_text = 'See map'); +
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
Get deep-links to a mapping services such as Yahoo! Maps or MapQuest (actual providers depend on configuration
|
||||
of location module) given a location. The call is delegated based on the 'country' value in the $location parameter.
|
||||
|
||||
@param $location
|
||||
An associative array where
|
||||
'street' => A string representing the street location
|
||||
'additional' => A string for any additional portion of the street location
|
||||
'city' => A string for the city name
|
||||
'province' => The standard postal abbreviation for the province
|
||||
'country' => The two-letter ISO code for the country of the location (REQUIRED)
|
||||
'postal_code' => The international postal code for the location
|
||||
|
||||
@return
|
||||
NULL if there are not mapping providers configured for the country or if no links could be generated.
|
||||
A string of the form "See map: Yahoo! Maps, MapQuest" where Yahoo! Maps and Mapquest are links to the
|
||||
given location and can be replaced with other options (e.g., Google) available in the location module settings.
|
||||
The idea is to encode the appropriate parameters as HTTP GET variables to the URL.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function location_driving_directions_link($locationA = array(), $locationB = array(), $link_text = 'Get directions');
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
Takes two locationes and tries to return a deep-link to driving directions.
|
||||
|
||||
Parameters:
|
||||
@param $locationA
|
||||
An associative array that represents an location where
|
||||
'street' => the street portions of the location
|
||||
'additional' => additional street portion of the location
|
||||
'city' => the city name
|
||||
'province' => the province, state, or territory
|
||||
'country' => lower-cased two-letter ISO code (REQUIRED)
|
||||
'postal_code' => the postal code
|
||||
|
||||
@param $locationB
|
||||
An associative array that represents an location in the same way that
|
||||
parameter $locationA does.
|
||||
|
||||
@param $link_text
|
||||
The text of the HTML link that is to be generated.
|
||||
|
||||
@return
|
||||
A deep-link to driving directions on Yahoo! or some other mapping service, if enough fields are filled in the parameters.
|
||||
A deep-link to a form for driving directions with information pre-filled if not enough, but some fields are filled in the parameters.
|
||||
The empty string if no information is provided (or if so little information is provided that there is no function to which to delegate
|
||||
the call.
|
||||
|
||||
We dispatch the call to a country-specific function. The country-specific function, in this case,
|
||||
will be the one reflected by the country parameter of the first function. We require that
|
||||
both locationes supplied have a country field at the minimum.
|
||||
|
||||
The country-specific functions will ultimately decide, with the parameters given, whether to
|
||||
to link to a form for driving directions is provided, where this form will be
|
||||
pre-populated with whatever values were available or whether to link directly to the driving
|
||||
directions themselves if enough fields are filled for each location.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function location_form($fields = array(), $prefilled_values = array(), $required_fields = array(), $description = '', $form_name = 'location', $function = NULL);
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
Generates a Drupal HTML form for collecting locationes.
|
||||
|
||||
@param $fields
|
||||
An array of values where each value is one of 'street', 'city', 'province', 'postal_code', or 'country'.
|
||||
The presence of values in this array determines which fields will be served in the location form generated
|
||||
by a call to this function. If this array is empty, all fields are generated.
|
||||
|
||||
@param $prefilled_values
|
||||
An associative array where
|
||||
-> Each key is one of the location fields: 'street', 'additional', 'city', 'province', 'postal_code', 'country'
|
||||
-> Each value is a prefilled value for the given field. ..... ))
|
||||
|
||||
@param $required_fields
|
||||
An array of values that are required. Each string can be one of 'street', 'city', 'postal_code', 'province', or 'country'.
|
||||
The presence of values in this array determines which fields will be marked as 'required'. Validation (i.e., making sure
|
||||
a required value is actually filled in is the responsibility of the caller)
|
||||
|
||||
@param $description
|
||||
A text description of specifically what location is being collected by the form to be served.
|
||||
|
||||
@param $form_name
|
||||
An additional parameter to help prevent HTML input name collisions. If the caller is using this
|
||||
function to generate more than 1 location form on a page, then the generated name for each HTML input's
|
||||
"name" attribute will go by the value supplied for $form_name. This parameter is defaulted to 'location'
|
||||
For example, if $form_name == 'xyz' and there is a 'street' field in the form to be served,
|
||||
the "name" attribute for the HTML <input> will be "edit[xyz][street]"
|
||||
|
||||
@param $function
|
||||
A string that tells location_form() which location API function will be using the location submitted via the
|
||||
generated form. For example, if $function == 'latlon_rough', then the returned location_form (if it includes
|
||||
a country field) will only generate a list of countries in the HTML select for which function location_latlon_rough()
|
||||
is supported. To figure out which countries these are, we check to see which of the configured countries have existing
|
||||
functions to support the call. In this case, we would check to see if there existed a function called "location_latlon_rough_us()"
|
||||
before listing the United States in the HTML SELECT for the generated location form. $function is defaulted to NULL.
|
||||
If $function is NULL, the HTML SELECT that is generated will list all countries.
|
||||
|
||||
@return
|
||||
An location form based on the parameters specified. If the $fields array is empty, then the
|
||||
function returns a form in which all possible fields are served as optional form items.
|
||||
|
||||
|
||||
EXAMPLES:
|
||||
|
||||
-> The following call returns a form that only contains fields for a postal_code and country where
|
||||
the postal_code is required:
|
||||
---
|
||||
$form = location_form(array('postal_code', 'country'), array(), array('postal_code', 'country'), 'Permanent location')
|
||||
---
|
||||
The form returned by this call is generated with calls to Drupal's 'form_' functions:
|
||||
|
||||
$form = form_textfield('Postal Code', 'location][postal_code', '', 64, 64, NULL, NULL, TRUE);
|
||||
-------------------------------------------------------------------------------------------------
|
||||
-> The following call returns a form that contains fields for a street, province, and postal_code,
|
||||
but the street, city, and province fields are optional while postal_code is required:
|
||||
---
|
||||
$form = location_form(array('street', 'city', 'province', 'postal_code'), array(), array('postal_code'));
|
||||
---
|
||||
-> The form returned by this call is generated with the following calls to Drupal's 'form_' functions:
|
||||
|
||||
$form = form_textfield('Street', 'location][street', '', 64, 64);
|
||||
$form .= form_textfield('Additional', 'location][additional', '', 64, 64);
|
||||
// The 'Additional' field is always and only generated when 'street' is specified as one of the fields.
|
||||
// The 'Additional' field is always optional whether or not 'Street' is required.
|
||||
$form .= form_textfield('City', 'location][city', '', 64, 64);
|
||||
$form .= _location_province_select_options(); // defined below
|
||||
$form .= form_textfield('Postal Code', 'location][postal_code', '', 64, 64, NULL, NULL, TRUE);
|
||||
------------------------------------------------------------------------------------------------
|
||||
For the following examples, assume we have the following two locationes:
|
||||
(1) $locationA = ('street' => '2010 Broadway St', 'city' => 'Redwood City', 'province' => 'CA', 'postal_code' => '94063', 'country' => 'us');
|
||||
(2) $locationB = ('street' => '2010 Broadway St', 'city' => 'Redwood City', 'province' => 'us-CA', 'postal_code' => '94063', 'country' => 'us');
|
||||
-> The following calls return the exact same form that contains fields for a street, province, postal_code, where prefilled
|
||||
values are submitted to the form.
|
||||
|
||||
$form = location_form(array('street', 'city', 'province', 'postal_code', 'country'), $locationB, array('street', 'city', 'province', 'postal_code', country'), '', 'home_location');
|
||||
|
||||
$form = location_form(array('street', 'city', 'province', 'postal_code', 'country'), location_api2form($locationA), array('street', 'city', 'province', 'postal_code', 'country'), '', 'home_location');
|
||||
|
||||
-> The form returned by these call is ultimately generated with the following calls to Drupal's 'form_' functions:
|
||||
|
||||
$form = textfield('Street', 'home_location][street', '2010 Broadway St.', 64, 64, NULL, NULL, TRUE);
|
||||
$form .= textfield('Additional', 'home_location][additional', 'Attn: Ankur Rishi', 64, 64, NULL, NULL, TRUE);
|
||||
$form .= textfield('City', 'home_location][city', 'Redwood City', 64, 64, NULL, NULL, TRUE);
|
||||
$form .= _location_province_select_options(TRUE, 'us-CA', 'home_location');
|
||||
$form .= textfield('Postal Code', 'home_location][postal_code', '94063', 64, 64, NULL, NULL, TRUE);
|
||||
$form .= _location_country_select_options(TRUE, 'us', 'home_location');
|
||||
|
||||
Note that in both cases, the first and third argument can take the same array since all the fields are being required.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function location_proximity_form($location_form = '', $label = '', $description = '', $prefilled_values = array(), $form_name = 'location');
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
This function generates a form for doing proximity searches within a certain distance
|
||||
of a specified point.
|
||||
|
||||
Depending on the context within which this function is called, the search-point can either
|
||||
be user-supplied via the location form that is passed (if one is available) or done within
|
||||
a search-point extracted from a contact table or some other location source specified by
|
||||
the programmer calling this function.
|
||||
|
||||
@param $location_form
|
||||
An optional location form, preferably generated by location_form(). If the script processing this
|
||||
form also needs a user-supplied location, this parameter is used to specify a form for collecting the
|
||||
search-point about which this search is being done. If the caller does not supply a form, it is
|
||||
assumed that the caller already has a search point in mind and that this will be made clear in
|
||||
the $description parameter.
|
||||
|
||||
@param $label
|
||||
The label you want to apply to the form group that is returned (passed as $legend param to form_group()).
|
||||
|
||||
@param $description
|
||||
A text description of what is being searched for (e.g., 'Find all upcoming events near you.')
|
||||
|
||||
@param $prefilled_values
|
||||
An associative array for prefilled values for the proximity search parameters, where
|
||||
'distance' => is the prefilled int value to be selected for the distance scalar
|
||||
'distance_unit' => is 'km' or 'mile'
|
||||
|
||||
@param $form_name
|
||||
An additional parameter to help prevent HTML input name collisions. If the caller is using this
|
||||
function to generate more than 1 location proximity form on a page, then the generated name for
|
||||
each HTML input's "name" attribute will be $form_name. Allowing the caller to pass $form_name allows
|
||||
the caller the flexibility of using more than one location proximity search form on one page.
|
||||
|
||||
@return
|
||||
An HTML form (generated by Drupal form functions) that lets users specify proximity search parameters that include distance,
|
||||
the unit of distance, and a search-point if the optional $location_form parameter is passed. If one is not passed,
|
||||
the caller of this function will be assumed to already have one.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function theme_location($location = array()); +
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
Generates HTML for the passed location.
|
||||
|
||||
@param $location
|
||||
An associative array where
|
||||
'street' => A string representing the street location
|
||||
'additional' => A string for any additional portion of the street location
|
||||
'city' => A string for the city name
|
||||
'province' => The standard postal abbreviation for the province
|
||||
'country' => The two-letter ISO code for the country of the location (REQUIRED)
|
||||
'postal_code' => The international postal code for the location
|
||||
|
||||
@return
|
||||
An HTML string with special tags for locationes.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function location_distance_between($latlonA = array(), $latlonB = array(), $distance_unit = 'km'); +
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
Given two points in lat/lon form, returns the distance between them.
|
||||
|
||||
@param $latlonA
|
||||
An associative array where
|
||||
'lon' => is a floating point of the longitude coordinate for the point given by latlonA
|
||||
'lat' => is a floating point of the latitude coordinate for the point given by latlonB
|
||||
|
||||
@param $latlonB
|
||||
Another point formatted like $latlonB
|
||||
|
||||
@param $distance_unit
|
||||
A string that is either 'km' or 'mile'.
|
||||
If neither 'km' or 'mile' is passed, the parameter is forced to 'km'
|
||||
|
||||
@return
|
||||
NULL if sense can't be made of the parameters.
|
||||
An associative array where
|
||||
'scalar' => Is the distance between the two lat/lon parameter points
|
||||
'distance_unit' => Is the unit of distance being represented by 'scalar'.
|
||||
This will be 'km' unless 'mile' is passed for the $distance_unit param
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function location_form2api($location = array()); +
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
@param $location
|
||||
An associative array that has been submitted by an HTML form generated by location_form().
|
||||
|
||||
@return
|
||||
An associative array in which the submitted values are modified to pass to the location API
|
||||
as the $location parameter (excepting location_form()).
|
||||
|
||||
This means changing the province field to remove the country code and dash.
|
||||
For example: California is served by the key 'us-CA' in the location form and this is what is passed when it is
|
||||
submitted through a form generated by location_form().
|
||||
|
||||
This is changed to 'CA' in the returned array.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function location_api2form($location = array()); +
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
Inverse of location_form2api()
|
||||
|
||||
@param $location
|
||||
An associative array that can be passed as the $location parameter to the location API.
|
||||
|
||||
@return
|
||||
An associative array with the same values modified so that the array can be passed as the
|
||||
$prefilled_values parameter to location_api2form()
|
||||
|
||||
Meant to take the standard location array format used by the public API (minus the form generating functions) and convert them
|
||||
into values that can be used by location_form() to fill in the prefilled values.
|
||||
|
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Administration related forms for the location_search module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Admin settings form.
|
||||
*
|
||||
* @ingroup form
|
||||
*/
|
||||
function location_search_admin_settings($form, &$form_state) {
|
||||
$gmap = module_exists('gmap');
|
||||
$form['location_search_map'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Use map to pick search coordinates'),
|
||||
'#return_value' => 1,
|
||||
'#default_value' => variable_get('location_search_map', 1),
|
||||
'#description' => $gmap ? t('Requires the gmap module.') : t('You must install the gmap module to enable this feature.'),
|
||||
'#disabled' => !$gmap,
|
||||
);
|
||||
$form['location_search_map_address'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Add geocoding address field to search map'),
|
||||
'#return_value' => 1,
|
||||
'#default_value' => variable_get('location_search_map_address', 1),
|
||||
);
|
||||
$form['location_search_map_macro'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Macro for search map'),
|
||||
'#default_value' => variable_get('location_search_map_macro', '[gmap |behavior=+collapsehack]'),
|
||||
);
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
name = Location Search
|
||||
package = Location
|
||||
description = Advanced search page for locations.
|
||||
dependencies[] = search
|
||||
dependencies[] = location
|
||||
core = 7.x
|
||||
files[] = location_search.module
|
||||
files[] = location_search.install
|
||||
files[] = location_search.admin.inc
|
||||
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-02-18
|
||||
version = "7.x-3.x-dev"
|
||||
core = "7.x"
|
||||
project = "location"
|
||||
datestamp = "1329524299"
|
||||
|
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the location_search module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_schema().
|
||||
*/
|
||||
function location_search_schema() {
|
||||
$schema['location_search_work'] = array(
|
||||
'description' => 'List of lids to index.',
|
||||
'fields' => array(
|
||||
'lid' => array(
|
||||
'description' => 'Primary Key: location ID.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
),
|
||||
'primary key' => array('lid'),
|
||||
);
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_install().
|
||||
*/
|
||||
function location_search_install() {
|
||||
// Force reindexing.
|
||||
$insert_select = db_select('location', 'l');
|
||||
$insert_select->addField('l', 'lid');
|
||||
|
||||
db_insert('location_search_work')
|
||||
->fields(array('lid'))
|
||||
->from($insert_select)
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function location_search_uninstall() {
|
||||
variable_del('location_search_map');
|
||||
variable_del('location_search_map_address');
|
||||
variable_del('location_search_map_macro');
|
||||
}
|
||||
|
||||
/**
|
||||
* Rewritten location_search -- Uses the fulltext engine.
|
||||
*/
|
||||
function location_search_update_5300() {
|
||||
// Create our worklist table.
|
||||
$schema['location_search_work'] = array(
|
||||
'description' => 'List of lids to index.',
|
||||
'fields' => array(
|
||||
'lid' => array(
|
||||
'description' => 'Primary Key: location ID.',
|
||||
'type' => 'int',
|
||||
'unsigned' => TRUE,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
),
|
||||
'primary key' => array('lid'),
|
||||
);
|
||||
db_create_table('location_search_work', $schema['location_search_work']);
|
||||
|
||||
// Force reindexing.
|
||||
$insert_select = db_select('location', 'l');
|
||||
$insert_select->addField('l', 'lid');
|
||||
|
||||
db_insert('location_search_work')
|
||||
->fields(array('lid'))
|
||||
->from($insert_select)
|
||||
->execute();
|
||||
|
||||
// Remove unused variables.
|
||||
variable_del('location_suppress_country');
|
||||
variable_del('location_search_distance_unit');
|
||||
}
|
@@ -0,0 +1,416 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Location search interface.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function location_search_menu() {
|
||||
$items['admin/settings/location/search'] = array(
|
||||
'title' => 'Search options',
|
||||
'description' => 'Settings for Location Search module',
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('location_search_admin_settings'),
|
||||
'file' => 'location_search.admin.inc',
|
||||
'access arguments' => array('administer site configuration'),
|
||||
'type' => MENU_LOCAL_TASK,
|
||||
'weight' => 5,
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_theme().
|
||||
*/
|
||||
function location_search_theme() {
|
||||
return array(
|
||||
'search_result_location' => array(
|
||||
'variables' => array(
|
||||
'result' => NULL,
|
||||
'module' => NULL,
|
||||
),
|
||||
'template' => 'search_result_location',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_search_info().
|
||||
*/
|
||||
function location_search_search_info() {
|
||||
return array(
|
||||
'title' => 'Locations',
|
||||
'path' => 'location',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_search_access().
|
||||
*/
|
||||
function location_search_search_access() {
|
||||
return user_access('access content');
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_search_reset().
|
||||
*/
|
||||
function location_search_search_reset() {
|
||||
db_delete('location_search_work')->execute();
|
||||
$insert_select = db_select('location', 'l');
|
||||
$insert_select->addField('l', 'lid');
|
||||
|
||||
db_insert('location_search_work')
|
||||
->fields(array('lid'))
|
||||
->from($insert_select)
|
||||
->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_search_status().
|
||||
*/
|
||||
function location_search_search_status() {
|
||||
$total = db_query('SELECT COUNT(lid) FROM {location}')->fetchField();
|
||||
$remaining = db_query('SELECT COUNT(lid) FROM {location_search_work}')->fetchField();
|
||||
return array('remaining' => $remaining, 'total' => $total);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements hook_search_execute().
|
||||
*/
|
||||
function location_search_search_execute($keys = NULL, $conditions = NULL) {
|
||||
$proximity = FALSE;
|
||||
|
||||
$lids = array();
|
||||
|
||||
// Determine whether this is a fulltext search or not.
|
||||
$fulltext = $keys;
|
||||
$fulltext = search_expression_insert($fulltext, 'country');
|
||||
$fulltext = search_expression_insert($fulltext, 'province');
|
||||
$fulltext = search_expression_insert($fulltext, 'city');
|
||||
$fulltext = search_expression_insert($fulltext, 'from');
|
||||
$fulltext = empty($fulltext) ? FALSE : TRUE;
|
||||
|
||||
if ($fulltext) {
|
||||
// Fuzzy search -- Use the fulltext routines against the indexed locations.
|
||||
$query = db_select('search_index', 'i')->extend('SearchQuery')->extend('PagerDefault');
|
||||
$query->join('location', 'l', 'l.lid = i.sid');
|
||||
$query->searchExpression($keys, 'node');
|
||||
|
||||
// Insert special keywords.
|
||||
$query->setOption('country', 'l.country');
|
||||
$query->setOption('province', 'l.province');
|
||||
$query->setOption('city', 'l.city');
|
||||
|
||||
// setOption() can't handle the complexity of this so do it manually.
|
||||
if ($value = search_expression_extract($keys, 'from')) {
|
||||
// Set up a proximity search.
|
||||
$proximity = TRUE;
|
||||
list($lat, $lon, $dist, $unit) = explode(',', $value);
|
||||
$distance_meters = _location_convert_distance_to_meters($dist, $unit);
|
||||
|
||||
// MBR query to make it easier on the database.
|
||||
$latrange = earth_latitude_range($lon, $lat, $distance_meters);
|
||||
$lonrange = earth_longitude_range($lon, $lat, $distance_meters);
|
||||
$query->condition('l.latitude', array($latrange[0], $latrange[1]), 'BETWEEN');
|
||||
$query->condition('l.longitude', array($lonrange[0], $lonrange[1]), 'BETWEEN');
|
||||
|
||||
// Distance query to finish the job.
|
||||
$query->where(earth_distance_sql($lon, $lat) . ' < ' . $distance_meters);
|
||||
|
||||
// Override the scoring mechanism to use calculated distance
|
||||
// as the scoring metric.
|
||||
$query->addExpression(earth_distance_sql($lon, $lat, 'l'), 'distance');
|
||||
$query->orderBy('distance', 'DESC');
|
||||
|
||||
$query->searchExpression = search_expression_insert($query->searchExpression, 'from');
|
||||
}
|
||||
|
||||
// Only continue if the first pass query matches.
|
||||
if (!$query->executeFirstPass()) {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
else {
|
||||
$query = db_select('location', 'l')->extend('PagerDefault');
|
||||
// sid is the alias so that our results match the fulltext search results.
|
||||
$query->addField('l', 'lid', 'sid');
|
||||
// Insert special keywords.
|
||||
if ($value = search_expression_extract($keys, 'country')) {
|
||||
$query->condition('l.country', $value);
|
||||
}
|
||||
if ($value = search_expression_extract($keys, 'province')) {
|
||||
$query->condition('l.province', $value);
|
||||
}
|
||||
if ($value = search_expression_extract($keys, 'city')) {
|
||||
$query->condition('l.city', $value);
|
||||
}
|
||||
// This is almost duplicated from the fulltext search above because if it
|
||||
// were refactored out it would make the code a little less clean and a
|
||||
// little harder to understand.
|
||||
if ($value = search_expression_extract($keys, 'from')) {
|
||||
// Set up a proximity search.
|
||||
$proximity = TRUE;
|
||||
list($lat, $lon, $dist, $unit) = explode(',', $value);
|
||||
$distance_meters = _location_convert_distance_to_meters($dist, $unit);
|
||||
|
||||
// MBR query to make it easier on the database.
|
||||
$latrange = earth_latitude_range($lon, $lat, $distance_meters);
|
||||
$lonrange = earth_longitude_range($lon, $lat, $distance_meters);
|
||||
$query->condition('l.latitude', array($latrange[0], $latrange[1]), 'BETWEEN');
|
||||
$query->condition('l.longitude', array($lonrange[0], $lonrange[1]), 'BETWEEN');
|
||||
|
||||
// Distance query to finish the job.
|
||||
$query->where(earth_distance_sql($lon, $lat) . ' < ' . $distance_meters);
|
||||
|
||||
// Override the scoring mechanism to use calculated distance
|
||||
// as the scoring metric.
|
||||
$query->addExpression(earth_distance_sql($lon, $lat, 'l'), 'distance');
|
||||
$query->orderBy('distance', 'DESC');
|
||||
}
|
||||
}
|
||||
|
||||
// Load results.
|
||||
$found = $query
|
||||
->limit(10)
|
||||
->execute();
|
||||
|
||||
foreach ($found as $item) {
|
||||
$lids[] = $item->sid;
|
||||
}
|
||||
|
||||
$results = array();
|
||||
foreach ($lids as $lid) {
|
||||
$loc = location_load_location($lid);
|
||||
|
||||
$result = db_query('SELECT nid, uid, genid FROM {location_instance} WHERE lid = :lid', array(':lid' => $lid), array('fetch' => PDO::FETCH_ASSOC));
|
||||
$instance_links = array();
|
||||
foreach ($result as $row) {
|
||||
$instance_links[] = $row;
|
||||
}
|
||||
location_invoke_locationapi($instance_links, 'instance_links');
|
||||
|
||||
$results[] = array(
|
||||
'links' => $instance_links,
|
||||
'location' => $loc,
|
||||
);
|
||||
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
function location_search_form_alter(&$form, &$form_state, $form_id) {
|
||||
if ($form_id == 'search_form' && arg(1) == 'location' && user_access('use advanced search')) {
|
||||
// @@@ Cache this.
|
||||
$result = db_query('SELECT DISTINCT country FROM {location}', array(), array('fetch' => PDO::FETCH_ASSOC));
|
||||
$countries = array('' => '');
|
||||
foreach ($result as $row) {
|
||||
if (!empty($row['country'])) {
|
||||
$country = $row['country'];
|
||||
location_standardize_country_code($country);
|
||||
$countries[$country] = location_country_name($country);
|
||||
}
|
||||
}
|
||||
ksort($countries);
|
||||
|
||||
drupal_add_js(drupal_get_path('module', 'location') .'/location_autocomplete.js');
|
||||
|
||||
// Keyword boxes:
|
||||
$form['advanced'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Advanced search'),
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#attributes' => array('class' => array('search-advanced')),
|
||||
);
|
||||
|
||||
$form['advanced']['country'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Country'),
|
||||
'#options' => $countries,
|
||||
// Used by province autocompletion js.
|
||||
'#attributes' => array('class' => array('location_auto_country')),
|
||||
);
|
||||
|
||||
$form['advanced']['province'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('State/Province'),
|
||||
'#autocomplete_path' => 'location/autocomplete/'. variable_get('location_default_country', 'us'),
|
||||
// Used by province autocompletion js.
|
||||
'#attributes' => array('class' => array('location_auto_province')),
|
||||
);
|
||||
|
||||
$form['advanced']['city'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('City'),
|
||||
);
|
||||
|
||||
$form['advanced']['proximity'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#collapsible' => TRUE,
|
||||
'#collapsed' => TRUE,
|
||||
'#title' => t('Proximity'),
|
||||
);
|
||||
|
||||
$form['advanced']['proximity']['map'] = array();
|
||||
|
||||
if (variable_get('location_search_map_address', 1)) {
|
||||
$form['advanced']['proximity']['locpick_address'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Locate Address'),
|
||||
);
|
||||
}
|
||||
|
||||
$form['advanced']['proximity']['latitude'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Latitude'),
|
||||
);
|
||||
$form['advanced']['proximity']['longitude'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Longitude'),
|
||||
);
|
||||
$form['advanced']['proximity']['distance'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Distance'),
|
||||
);
|
||||
$form['advanced']['proximity']['distance']['distance'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#size' => 5,
|
||||
'#maxlength' => 5,
|
||||
);
|
||||
$form['advanced']['proximity']['distance']['units'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => array(
|
||||
'mi' => t('mi'),
|
||||
'km' => t('km'),
|
||||
),
|
||||
);
|
||||
|
||||
if (variable_get('location_search_map', 1)) {
|
||||
$map_fields = array(
|
||||
'latitude' => 'latitude',
|
||||
'longitude' => 'longitude',
|
||||
);
|
||||
if (variable_get('location_search_map_address', 1)) {
|
||||
$map_fields['address'] = 'locpick_address';
|
||||
}
|
||||
if (module_exists('gmap')) {
|
||||
$form['advanced']['proximity']['map']['#value'] = gmap_set_location(variable_get('location_search_map_macro', '[gmap |behavior=+collapsehack]'), $form['advanced']['proximity'], $map_fields);
|
||||
}
|
||||
}
|
||||
|
||||
$form['advanced']['submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Advanced search'),
|
||||
'#prefix' => '<div class="action">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
|
||||
$form['#validate'][] = 'location_search_validate';
|
||||
}
|
||||
}
|
||||
|
||||
function location_search_validate($form, &$form_state) {
|
||||
$values = $form_state['values'];
|
||||
|
||||
// Initialise using any existing basic search keywords.
|
||||
$keys = $values['processed_keys'];
|
||||
|
||||
if (!empty($values['country'])) {
|
||||
$keys = search_expression_insert($keys, 'country', $values['country']);
|
||||
|
||||
if (!empty($values['province'])) {
|
||||
$keys = search_expression_insert($keys, 'province', location_province_code($values['country'], $values['province']));
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($values['city'])) {
|
||||
$keys = search_expression_insert($keys, 'city', $values['city']);
|
||||
}
|
||||
|
||||
if (!empty($values['latitude']) && !empty($values['longitude']) && !empty($values['distance'])) {
|
||||
$keys = search_expression_insert($keys, 'from', $values['latitude'] .','. $values['longitude'] .','. $values['distance'] .','. $values['units']);
|
||||
}
|
||||
|
||||
if (!empty($keys)) {
|
||||
form_set_value($form['basic']['processed_keys'], trim($keys), $form_state);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_update_index().
|
||||
*/
|
||||
function location_update_index() {
|
||||
$limit = (int)variable_get('search_cron_limit', 100);
|
||||
|
||||
$result = db_query_range('SELECT lid FROM {location_search_work}', 0, $limit);
|
||||
foreach ($result as $row) {
|
||||
$loc = location_load_location($row->lid);
|
||||
$text = theme('location', array('location' => $loc, 'hide' => array())); // @@@ hide?
|
||||
|
||||
search_index($row->lid, 'location', $text);
|
||||
db_delete('location_search_work')
|
||||
->condition('lid', $row->lid)
|
||||
->execute();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_locationapi().
|
||||
*/
|
||||
function location_search_locationapi(&$obj, $op, $a3 = NULL, $a4 = NULL, $a5 = NULL) {
|
||||
if ($op == 'save') {
|
||||
// Ensure the changed location is in our work list.
|
||||
db_delete('location_search_work')
|
||||
->condition('lid', $obj['lid'])
|
||||
->execute();
|
||||
db_insert('location_search_work')
|
||||
->fields(array(
|
||||
'lid' => $obj['lid'],
|
||||
))
|
||||
->execute();
|
||||
}
|
||||
if ($op == 'delete') {
|
||||
search_reindex($obj['lid'], 'location');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_search_page().
|
||||
*/
|
||||
function location_search_search_page($results) {
|
||||
$output['prefix']['#markup'] = '<ol class="search-results">';
|
||||
|
||||
foreach ($results as $entry) {
|
||||
$output[] = array(
|
||||
'#theme' => 'search_result_location',
|
||||
'#result' => $entry,
|
||||
'#module' => 'location',
|
||||
);
|
||||
}
|
||||
$output['suffix']['#markup'] = '</ol>' . theme('pager');
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
function template_preprocess_search_result_location(&$variables) {
|
||||
$result = $variables['result'];
|
||||
|
||||
$variables['links_raw'] = array();
|
||||
foreach ($result['links'] as $link) {
|
||||
if (isset($link['title']) && isset($link['href'])) {
|
||||
$variables['links_raw'][] = $link;
|
||||
}
|
||||
}
|
||||
$variables['location_raw'] = $result['location'];
|
||||
|
||||
$variables['location'] = theme('location', array('location' => $result['location'], 'hide' => array())); // @@@ hide?
|
||||
$variables['links'] = theme('links', array('links' => $variables['links_raw']));
|
||||
|
||||
// Provide alternate search result template.
|
||||
$variables['theme_hook_suggestions'][] = 'search_result_' . $variables['module'];
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file search_result_location.tpl.php
|
||||
* Theme a location search result.
|
||||
*
|
||||
* Available variables:
|
||||
* - $links: A themed set of links to all the objects that reference this location.
|
||||
* - $location: A themed location.
|
||||
*/
|
||||
?>
|
||||
<dt class="title">
|
||||
<?php print $links; ?>
|
||||
</dt>
|
||||
<dd>
|
||||
<?php print $location; ?>
|
||||
</dd>
|
@@ -0,0 +1,16 @@
|
||||
name = Location Taxonomy
|
||||
description = Associate locations with taxonomy terms.
|
||||
dependencies[] = location
|
||||
dependencies[] = taxonomy
|
||||
package = Location
|
||||
core = 7.x
|
||||
files[] = location_taxonomy.module
|
||||
files[] = location_taxonomy.install
|
||||
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-02-18
|
||||
version = "7.x-3.x-dev"
|
||||
core = "7.x"
|
||||
project = "location"
|
||||
datestamp = "1329524299"
|
||||
|
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the location_taxonomy module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function location_taxonomy_uninstall() {
|
||||
// @@@ Delete data?
|
||||
|
||||
// Delete vocabulary location settings.
|
||||
$result = db_query("SELECT name FROM {variable} WHERE name LIKE 'location_taxonomy_%'")->fetchCol();
|
||||
foreach ($result as $var) {
|
||||
variable_del($var);
|
||||
}
|
||||
}
|
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Associate locations with taxonomy terms.
|
||||
*/
|
||||
|
||||
/**
|
||||
* NOTE: At the moment, you'll have to do your own theming.
|
||||
* To load locations for a tid:
|
||||
* $locations = location_load_locations('taxonomy:'. $tid, 'genid');
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_taxonomy_vocabulary_delete().
|
||||
*/
|
||||
function location_taxonomy_taxonomy_vocabulary_delete($vocabulary) {
|
||||
variable_del('location_taxonomy_' . $vocabulary->vid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_taxonomy_term_delete().
|
||||
*/
|
||||
function location_taxonomy_taxonomy_term_delete($term) {
|
||||
$locations = array();
|
||||
location_save_locations($locations, array('genid' => 'taxonomy:' . $term->tid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_alter().
|
||||
*/
|
||||
function location_taxonomy_form_alter(&$form, &$form_state, $form_id) {
|
||||
if ($form_id == 'taxonomy_form_vocabulary') {
|
||||
$settings = array();
|
||||
if (isset($form['vid'])) {
|
||||
$settings = variable_get('location_taxonomy_' . $form['vid']['#value'], array());
|
||||
}
|
||||
$form['location_settings'] = location_settings($settings);
|
||||
$form['#submit'][] = 'location_taxonomy_vocabulary_form_submit';
|
||||
}
|
||||
if ($form_id == 'taxonomy_form_term') {
|
||||
$vid = $form['vid']['#value'];
|
||||
$settings = variable_get('location_taxonomy_' . $vid, FALSE);
|
||||
if ($settings && $settings['multiple']['max']) {
|
||||
$locations = array();
|
||||
if (isset($form['tid']) && $form['tid']['#value']) {
|
||||
$locations = location_load_locations('taxonomy:' . $form['tid']['#value'], 'genid');
|
||||
}
|
||||
$form['locations'] = location_form($settings, $locations);
|
||||
$form['#submit'][] = 'location_taxonomy_term_form_submit';
|
||||
}
|
||||
}
|
||||
|
||||
// Move the Save and Delete buttons down below our additions.
|
||||
if ($form_id == 'taxonomy_form_vocabulary' || $form_id == 'taxonomy_form_term') {
|
||||
if (isset($form['submit']['#weight'])) {
|
||||
$form['submit']['#weight']++;
|
||||
}
|
||||
else {
|
||||
$form['submit']['#weight'] = 1;
|
||||
}
|
||||
if (isset($form['delete'])) {
|
||||
if (isset($form['delete']['#weight'])) {
|
||||
$form['delete']['#weight'] += 2;
|
||||
}
|
||||
else {
|
||||
$form['delete']['#weight'] = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for the vocabulary add/edit form.
|
||||
*/
|
||||
function location_taxonomy_vocabulary_form_submit($form, &$form_state) {
|
||||
if (isset($form_state['values']['location_settings'])) {
|
||||
variable_set('location_taxonomy_' . $form_state['values']['vid'], $form_state['values']['location_settings']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit handler for the term add/edit form.
|
||||
*/
|
||||
function location_taxonomy_term_form_submit($form, &$form_state) {
|
||||
$settings = variable_get('location_taxonomy_' . $form_state['values']['vid'], FALSE);
|
||||
if ($settings && $settings['multiple']['max']) {
|
||||
location_save_locations($form_state['values']['locations'], array('genid' => 'taxonomy:' . $form_state['values']['tid']));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_locationapi().
|
||||
*/
|
||||
function location_taxonomy_locationapi(&$obj, $op, $a3 = NULL, $a4 = NULL, $a5 = NULL) {
|
||||
switch ($op) {
|
||||
case 'instance_links':
|
||||
foreach ($obj as $k => $v) {
|
||||
if (substr($v['genid'], 0, 9) == 'taxonomy:') {
|
||||
$data = explode(':', $v['genid']);
|
||||
$obj[$k]['href'] = 'taxonomy/term/' . $data[1];
|
||||
$obj[$k]['title'] = t('Term location');
|
||||
$obj[$k]['type'] = t('Taxonomy location');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
9280
sites/all/modules/contrib/fields/location/database/zipcodes.au.mysql
Normal file
9280
sites/all/modules/contrib/fields/location/database/zipcodes.au.mysql
Normal file
File diff suppressed because it is too large
Load Diff
2781
sites/all/modules/contrib/fields/location/database/zipcodes.be.mysql
Normal file
2781
sites/all/modules/contrib/fields/location/database/zipcodes.be.mysql
Normal file
File diff suppressed because it is too large
Load Diff
3207
sites/all/modules/contrib/fields/location/database/zipcodes.ch.mysql
Normal file
3207
sites/all/modules/contrib/fields/location/database/zipcodes.ch.mysql
Normal file
File diff suppressed because it is too large
Load Diff
8253
sites/all/modules/contrib/fields/location/database/zipcodes.de.mysql
Normal file
8253
sites/all/modules/contrib/fields/location/database/zipcodes.de.mysql
Normal file
File diff suppressed because it is too large
Load Diff
2934
sites/all/modules/contrib/fields/location/database/zipcodes.gb.mysql
Normal file
2934
sites/all/modules/contrib/fields/location/database/zipcodes.gb.mysql
Normal file
File diff suppressed because it is too large
Load Diff
42412
sites/all/modules/contrib/fields/location/database/zipcodes.in.mysql
Normal file
42412
sites/all/modules/contrib/fields/location/database/zipcodes.in.mysql
Normal file
File diff suppressed because it is too large
Load Diff
2195
sites/all/modules/contrib/fields/location/database/zipcodes.no.mysql
Normal file
2195
sites/all/modules/contrib/fields/location/database/zipcodes.no.mysql
Normal file
File diff suppressed because it is too large
Load Diff
43196
sites/all/modules/contrib/fields/location/database/zipcodes.us.mysql
Normal file
43196
sites/all/modules/contrib/fields/location/database/zipcodes.us.mysql
Normal file
File diff suppressed because it is too large
Load Diff
184
sites/all/modules/contrib/fields/location/earth.inc
Normal file
184
sites/all/modules/contrib/fields/location/earth.inc
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* License clarification:
|
||||
*
|
||||
* On Feb 13, 2005, in message <Pine.LNX.4.58.0502131827510.5072@server1.LFW.org>,
|
||||
* the creator of these routines, Ka-Ping Yee, authorized these routines to be
|
||||
* distributed under the GPL.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Trigonometry for calculating geographical distances.
|
||||
* All function arguments and return values measure distances in metres
|
||||
* and angles in degrees. The ellipsoid model is from the WGS-84 datum.
|
||||
* Ka-Ping Yee, 2003-08-11
|
||||
*/
|
||||
|
||||
//$earth_radius_semimajor = 6378137.0;
|
||||
//$earth_flattening = 1/298.257223563;
|
||||
//$earth_radius_semiminor = $earth_radius_semimajor * (1 - $earth_flattening);
|
||||
//$earth_eccentricity_sq = 2*$earth_flattening - pow($earth_flattening, 2);
|
||||
|
||||
// I don't know what's up: PHP is hating on my global variables (commented out above),
|
||||
// so I have to write functions that return them! (-Ankur)
|
||||
// Commenting out the global variables above and replacing them with functions that
|
||||
// return the same values is the only thing I changed since, for some reason, my
|
||||
// PHP wasn't acknowledging these global variables.
|
||||
// This library is an original implementation of UCB CS graduate student, Ka-Ping Yee (http://www.zesty.ca).
|
||||
|
||||
function earth_radius_semimajor() {
|
||||
return 6378137.0;
|
||||
}
|
||||
|
||||
function earth_flattening() {
|
||||
return (1/298.257223563);
|
||||
}
|
||||
|
||||
function earth_radius_semiminor() {
|
||||
return (earth_radius_semimajor() * (1 - earth_flattening()));
|
||||
}
|
||||
|
||||
function earth_eccentricity_sq() {
|
||||
return (2*earth_flattening() - pow(earth_flattening(), 2));
|
||||
}
|
||||
|
||||
// Latitudes in all of U. S.: from -7.2 (American Samoa) to 70.5 (Alaska).
|
||||
// Latitudes in continental U. S.: from 24.6 (Florida) to 49.0 (Washington).
|
||||
// Average latitude of all U. S. zipcodes: 37.9.
|
||||
|
||||
function earth_radius($latitude=37.9) {
|
||||
//global $earth_radius_semimajor, $earth_radius_semiminor;
|
||||
// Estimate the Earth's radius at a given latitude.
|
||||
// Default to an approximate average radius for the United States.
|
||||
|
||||
$lat = deg2rad($latitude);
|
||||
|
||||
$x = cos($lat)/earth_radius_semimajor();
|
||||
$y = sin($lat)/earth_radius_semiminor();
|
||||
return 1 / (sqrt($x*$x + $y*$y));
|
||||
}
|
||||
|
||||
function earth_xyz($longitude, $latitude, $height = 0) {
|
||||
// Convert longitude and latitude to earth-centered earth-fixed coordinates.
|
||||
// X axis is 0 long, 0 lat; Y axis is 90 deg E; Z axis is north pole.
|
||||
//global $earth_radius_semimajor, $earth_eccentricity_sq;
|
||||
$long = deg2rad($longitude);
|
||||
$lat = deg2rad($latitude);
|
||||
|
||||
$coslong = cos($long);
|
||||
$coslat = cos($lat);
|
||||
$sinlong = sin($long);
|
||||
$sinlat = sin($lat);
|
||||
$radius = earth_radius_semimajor() /
|
||||
sqrt(1 - earth_eccentricity_sq() * $sinlat * $sinlat);
|
||||
$x = ($radius + $height) * $coslat * $coslong;
|
||||
$y = ($radius + $height) * $coslat * $sinlong;
|
||||
$z = ($radius * (1 - earth_eccentricity_sq()) + $height) * $sinlat;
|
||||
return array($x, $y, $z);
|
||||
}
|
||||
|
||||
function earth_arclength($angle, $latitude=37.9) {
|
||||
// Convert a given angle to earth-surface distance.
|
||||
return deg2rad($angle) * earth_radius($latitude);
|
||||
}
|
||||
|
||||
function earth_distance($longitude1, $latitude1, $longitude2, $latitude2) {
|
||||
// Estimate the earth-surface distance between two locations.
|
||||
$long1 = deg2rad($longitude1);
|
||||
$lat1 = deg2rad($latitude1);
|
||||
$long2 = deg2rad($longitude2);
|
||||
$lat2 = deg2rad($latitude2);
|
||||
$radius = earth_radius(($latitude1 + $latitude2) / 2);
|
||||
|
||||
$cosangle = cos($lat1)*cos($lat2) *
|
||||
(cos($long1)*cos($long2) + sin($long1)*sin($long2)) +
|
||||
sin($lat1)*sin($lat2);
|
||||
return acos($cosangle) * $radius;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the SQL fragment needed to add a column called 'distance'
|
||||
* to a query that includes the location table
|
||||
*
|
||||
* @param $longitude The measurement point
|
||||
* @param $latibude The measurement point
|
||||
* @param $tbl_alias If necessary, the alias name of the location table to work from. Only required when working with named {location} tables
|
||||
*/
|
||||
function earth_distance_sql($longitude, $latitude, $tbl_alias = '') {
|
||||
// Make a SQL expression that estimates the distance to the given location.
|
||||
$long = deg2rad($longitude);
|
||||
$lat = deg2rad($latitude);
|
||||
$radius = earth_radius($latitude);
|
||||
|
||||
// If the table alias is specified, add on the separator.
|
||||
$tbl_alias = empty($tbl_alias) ? $tbl_alias : ($tbl_alias .'.');
|
||||
|
||||
$coslong = cos($long);
|
||||
$coslat = cos($lat);
|
||||
$sinlong = sin($long);
|
||||
$sinlat = sin($lat);
|
||||
return "(IFNULL(ACOS($coslat*COS(RADIANS({$tbl_alias}latitude))*($coslong*COS(RADIANS({$tbl_alias}longitude)) + $sinlong*SIN(RADIANS({$tbl_alias}longitude))) + $sinlat*SIN(RADIANS({$tbl_alias}latitude))), 0.00000)*$radius)";
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo This function uses earth_asin_safe so is not accurate for all possible
|
||||
* parameter combinations. This means this function doesn't work properly
|
||||
* for high distance values. This function needs to be re-written to work properly for
|
||||
* larger distance values. See http://drupal.org/node/821628
|
||||
*/
|
||||
function earth_longitude_range($longitude, $latitude, $distance) {
|
||||
// Estimate the min and max longitudes within $distance of a given location.
|
||||
$long = deg2rad($longitude);
|
||||
$lat = deg2rad($latitude);
|
||||
$radius = earth_radius($latitude);
|
||||
|
||||
$angle = $distance / $radius;
|
||||
$diff = earth_asin_safe(sin($angle)/cos($lat));
|
||||
$minlong = $long - $diff;
|
||||
$maxlong = $long + $diff;
|
||||
if ($minlong < -pi()) { $minlong = $minlong + pi()*2; }
|
||||
if ($maxlong > pi()) { $maxlong = $maxlong - pi()*2; }
|
||||
return array(rad2deg($minlong), rad2deg($maxlong));
|
||||
}
|
||||
|
||||
function earth_latitude_range($longitude, $latitude, $distance) {
|
||||
// Estimate the min and max latitudes within $distance of a given location.
|
||||
$long = deg2rad($longitude);
|
||||
$lat = deg2rad($latitude);
|
||||
$radius = earth_radius($latitude);
|
||||
|
||||
$angle = $distance / $radius;
|
||||
$minlat = $lat - $angle;
|
||||
$maxlat = $lat + $angle;
|
||||
$rightangle = pi()/2;
|
||||
if ($minlat < -$rightangle) { // wrapped around the south pole
|
||||
$overshoot = -$minlat - $rightangle;
|
||||
$minlat = -$rightangle + $overshoot;
|
||||
if ($minlat > $maxlat) { $maxlat = $minlat; }
|
||||
$minlat = -$rightangle;
|
||||
}
|
||||
if ($maxlat > $rightangle) { // wrapped around the north pole
|
||||
$overshoot = $maxlat - $rightangle;
|
||||
$maxlat = $rightangle - $overshoot;
|
||||
if ($maxlat < $minlat) { $minlat = $maxlat; }
|
||||
$maxlat = $rightangle;
|
||||
}
|
||||
return array(rad2deg($minlat), rad2deg($maxlat));
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a helper function to avoid errors when using the asin() PHP function.
|
||||
* asin is only real for values between -1 and 1.
|
||||
* If a value outside that range is given it returns NAN (not a number), which
|
||||
* we don't want to happen.
|
||||
* So this just rounds values outside this range to -1 or 1 first.
|
||||
*
|
||||
* This means that calculations done using this function with $x outside the range
|
||||
* will not be accurate. The alternative though is getting NAN, which is an error
|
||||
* and won't give accurate results anyway.
|
||||
*/
|
||||
function earth_asin_safe($x) {
|
||||
return asin(max(-1, min($x, 1)));
|
||||
}
|
254
sites/all/modules/contrib/fields/location/geocoding/google.inc
Normal file
254
sites/all/modules/contrib/fields/location/geocoding/google.inc
Normal file
@@ -0,0 +1,254 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Google geocoder.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns an XML document containing the list of countries supported by the
|
||||
* Google geocoder.
|
||||
* A cached version is stored in the Drupal cache in case Google is unreachable.
|
||||
*/
|
||||
function google_geocode_country_list_xml() {
|
||||
// Get the google data from the feed.
|
||||
$source = drupal_http_request('http://spreadsheets.google.com/feeds/list/p9pdwsai2hDMsLkXsoM05KQ/default/public/values');
|
||||
|
||||
if (!$source->data) {
|
||||
// Use the cache.
|
||||
$data = cache_get('location_google');
|
||||
if (!defined('LIBXML_VERSION') || (version_compare(phpversion(), '5.1.0', '<'))) {
|
||||
$xml = simplexml_load_string($data->data, NULL);
|
||||
}
|
||||
else {
|
||||
$xml = simplexml_load_string($data->data, NULL, LIBXML_NOERROR | LIBXML_NOWARNING);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!defined('LIBXML_VERSION') || (version_compare(phpversion(), '5.1.0', '<'))) {
|
||||
$xml = simplexml_load_string($source->data, NULL);
|
||||
// Stores the XML in the cache to eventually use it later.
|
||||
cache_set('location_google', $xml->asXML());
|
||||
}
|
||||
else {
|
||||
$xml = simplexml_load_string($source->data, NULL, LIBXML_NOERROR | LIBXML_NOWARNING);
|
||||
// Store the XML in the cache to eventually use it later.
|
||||
cache_set('location_google', $xml->asXML());
|
||||
}
|
||||
}
|
||||
|
||||
return $xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the list of ISO3166 codes supported by this geocoder.
|
||||
* Coverage list: http://gmaps-samples.googlecode.com/svn/trunk/mapcoverage_filtered.html
|
||||
* Coverage list feed: http://spreadsheets.google.com/feeds/list/p9pdwsai2hDMsLkXsoM05KQ/default/public/values
|
||||
*/
|
||||
function google_geocode_country_list() {
|
||||
// Get the google data from the feed.
|
||||
$xml = google_geocode_country_list_xml();
|
||||
|
||||
// Loop through google data and find all valid entries.
|
||||
$regionclean = array();
|
||||
foreach($xml->entry as $region) {
|
||||
$pos = strpos($region->content, 'geocoding:') + 11;
|
||||
$geocoding = substr($region->content, $pos, strpos($region->content, ',', $pos) - $pos);
|
||||
if (strpos($geocoding, "Yes") !== FALSE) {
|
||||
$regionclean[] = t(htmlentities($region->title));
|
||||
}
|
||||
}
|
||||
|
||||
// Get the countries list and clean it up so that names will match to google.
|
||||
// The regex removes parenthetical items so that both of the "Congo" entries
|
||||
// and the "Coco Islands" work.
|
||||
// The $countriesfixes overwrites values in the Drupal API countries list
|
||||
// with values that will match to google's entries.
|
||||
// "Sao Tome and Principe" are non-accented in the Drupal API so the entry
|
||||
// here is to match the htmlentities() fix in the foreach loop below.
|
||||
// Note: it may be neccessary to adjust/add to the fixes list in the future
|
||||
// if google adds countries that don't match the Drupal API list for whatever
|
||||
// reason.
|
||||
$countries = location_get_iso3166_list();
|
||||
$regex = "#[ (].*[)]#e";
|
||||
$cntryclean = preg_replace($regex, "", $countries);
|
||||
$countriesfixes = array_merge($cntryclean, array(
|
||||
"hk" => t("China"),
|
||||
"mo" => t("China"),
|
||||
"pn" => t("Pitcairn Islands"),
|
||||
"wf" => t("Wallis Futuna"),
|
||||
"st" => t("São Tomé and Príncipe"),
|
||||
));
|
||||
|
||||
// Compare new google data found to fixed country name values and return
|
||||
// matches with abbreviations as keys.
|
||||
$googlematched = array_intersect($countriesfixes, $regionclean);
|
||||
|
||||
// Compare new keys to original Drupal API and return the array with the
|
||||
// original name values.
|
||||
$fixedkeys = array_intersect_key($countries, $googlematched);
|
||||
return array_keys($fixedkeys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return general information about this geocoder.
|
||||
*/
|
||||
function google_geocode_info() {
|
||||
return array(
|
||||
'name' => 'Google Maps',
|
||||
'url' => 'http://maps.google.com',
|
||||
'tos' => 'http://www.google.com/help/terms_local.html',
|
||||
'general' => TRUE,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a geocode on a location array.
|
||||
* @param $location
|
||||
* The location array to process.
|
||||
* @return
|
||||
* an associative array with keys 'lat' and 'lon' containing the coordinates.
|
||||
*/
|
||||
function google_geocode_location($location = array()) {
|
||||
|
||||
if (function_exists('gmap_get_key')) {
|
||||
$key = gmap_get_key();
|
||||
}
|
||||
else {
|
||||
$key = variable_get('location_geocode_google_apikey', '');
|
||||
}
|
||||
|
||||
$query = array(
|
||||
'key' => $key,
|
||||
'sensor' => 'false', // Required by TOS.
|
||||
'output' => 'xml',
|
||||
//'ll' => 0,
|
||||
//'spn' => 0,
|
||||
'gl' => $location['country'],
|
||||
'q' => _google_geocode_flatten($location),
|
||||
);
|
||||
|
||||
$url = url('http://maps.google.com/maps/geo', array(
|
||||
'query' => $query,
|
||||
'external' => TRUE,
|
||||
));
|
||||
|
||||
$http_reply = drupal_http_request($url);
|
||||
|
||||
$status_code_match = array();
|
||||
preg_match('/<code>(.*)<\/code>/', $http_reply->data, $status_code_match);
|
||||
$status_code = $status_code_match[1];
|
||||
if ($status_code != 200) {
|
||||
watchdog('location', 'Google geocoding returned status code: %status_code', array('%status_code' => $status_code));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$accuracy_code_match = array();
|
||||
preg_match('/Accuracy="([0-9])"/', $http_reply->data, $accuracy_code_match);
|
||||
$accuracy_code = $accuracy_code_match[1];
|
||||
$min_accuracy = variable_get('location_geocode_' . $location['country'] . 'google_accuracy_code', variable_get('location_geocode_google_minimum_accuracy', '3'));
|
||||
if ($accuracy_code < $min_accuracy) {
|
||||
watchdog('location', 'Google geocoding result for %country did not meet the minimum accuracy level of %min_accuracy. Result accuracy: %accuracy_code', array('%country' => $location['country'], '%min_accuracy' => $min_accuracy, '%accuracy_code' => $accuracy_code));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$latlon_match = array();
|
||||
preg_match('/<coordinates>(.*)<\/coordinates>/', $http_reply->data, $latlon_match);
|
||||
|
||||
$latlon_exploded = explode(',', $latlon_match[1]);
|
||||
|
||||
return array('lat' => $latlon_exploded[1], 'lon' => $latlon_exploded[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* General settings for this geocoder.
|
||||
*/
|
||||
function google_geocode_settings() {
|
||||
$form = array();
|
||||
$key = '';
|
||||
if (function_exists('gmap_get_key')) {
|
||||
$key = gmap_get_key();
|
||||
}
|
||||
|
||||
if (!empty($key)) {
|
||||
$form['location_geocode_google_apikey'] = array(
|
||||
'#type' => 'item',
|
||||
'#title' => t('Google Maps API Key'),
|
||||
'#value' => $key,
|
||||
'#description' => t('The key in use was automatically provided by GMap.'),
|
||||
);
|
||||
}
|
||||
else {
|
||||
$form['location_geocode_google_apikey'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Google Maps API Key'),
|
||||
'#size' => 64,
|
||||
'#maxlength' => 128,
|
||||
'#default_value' => variable_get('location_geocode_google_apikey', ''),
|
||||
'#description' => t('In order to use the Google Maps API geocoding web-service, you will need a Google Maps API Key. You can obtain one at the !sign_up_link for the !google_maps_api. PLEASE NOTE: You will <em>not</em> have to re-enter your API key for each country for which you have selected Google Maps for geocoding. This setting is global.', array('!sign_up_link' => '<a href="http://www.google.com/apis/maps/signup.html">sign-up page</a>', '!google_maps_api' => '<a href="http://www.google.com/apis/maps/">Google Maps API</a>'))
|
||||
);
|
||||
}
|
||||
|
||||
$country = arg(5);
|
||||
if ($country) {
|
||||
$form['location_geocode_' . $country . '_google_accuracy_code'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Google Maps Geocoding Accuracy for %country', array('%country' => $country ) ),
|
||||
'#default_value' => variable_get('location_geocode_' . $country . '_google_accuracy_code', variable_get('location_geocode_google_minimum_accuracy', '3')),
|
||||
'#options' => location_google_geocode_accuracy_codes(),
|
||||
'#description' => t('The minimum required accuracy for the geolocation data to be saved.'),
|
||||
);
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
|
||||
function _google_geocode_flatten($location = array()) {
|
||||
// Check if its a valid address
|
||||
if (empty($location)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$address = '';
|
||||
if (!empty($location['street'])) {
|
||||
$address .= $location['street'];
|
||||
}
|
||||
|
||||
if (!empty($location['city'])) {
|
||||
if (!empty($address)) {
|
||||
$address .= ', ';
|
||||
}
|
||||
|
||||
$address .= $location['city'];
|
||||
}
|
||||
|
||||
if (!empty($location['province'])) {
|
||||
if (!empty($address)) {
|
||||
$address .= ', ';
|
||||
}
|
||||
|
||||
// @@@ Fix this!
|
||||
if (substr($location['province'], 0, 3) == $location['country'] . '-') {
|
||||
$address .= substr($location['province'], 3);
|
||||
watchdog('Location', 'BUG: Country found in province attribute.');
|
||||
}
|
||||
else {
|
||||
$address .= $location['province'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($location['postal_code'])) {
|
||||
if (!empty($address)) {
|
||||
$address .= ' ';
|
||||
}
|
||||
$address .= $location['postal_code'];
|
||||
}
|
||||
|
||||
if (!empty($location['country'])) {
|
||||
if (!empty($address)) {
|
||||
$address .= ', ';
|
||||
}
|
||||
$address .= $location['country'];
|
||||
}
|
||||
|
||||
return $address;
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Argument handler to accept a country code or name.
|
||||
*/
|
||||
class location_handler_argument_location_country extends views_handler_argument {
|
||||
/**
|
||||
* Override the behavior of title(). Get the country name.
|
||||
*/
|
||||
function title() {
|
||||
return location_country_name($this->argument);
|
||||
}
|
||||
|
||||
function summary_name($data) {
|
||||
$value = $data->{$this->name_alias};
|
||||
if (empty($value)) {
|
||||
return t('Unknown');
|
||||
}
|
||||
return location_country_name($value);
|
||||
}
|
||||
}
|
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Argument handler to accept a province code or name.
|
||||
*/
|
||||
class location_handler_argument_location_province extends views_handler_argument {
|
||||
/**
|
||||
* Override the behavior of title(). Get the province name.
|
||||
*/
|
||||
function title() {
|
||||
if (isset($this->view->argument['country'])) {
|
||||
$country = $this->view->argument['country']->argument;
|
||||
}
|
||||
else {
|
||||
$country = variable_get('location_default_country', 'us');
|
||||
}
|
||||
return location_province_name($country, $this->argument);
|
||||
}
|
||||
|
||||
function summary_name($data) {
|
||||
$value = $data->{$this->name_alias};
|
||||
if (empty($value)) {
|
||||
return t('Unknown');
|
||||
}
|
||||
|
||||
if (isset($this->view->argument['country'])) {
|
||||
$country = $this->view->argument['country']->argument;
|
||||
}
|
||||
else {
|
||||
$country = variable_get('location_default_country', 'us');
|
||||
}
|
||||
|
||||
return location_province_name($country, $value);
|
||||
}
|
||||
}
|
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Location proximity argument handler.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Argument handler to accept proximity
|
||||
*/
|
||||
class location_handler_argument_location_proximity extends views_handler_argument {
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
// As only us and uk use miles, make km the default otherwise.
|
||||
$country = variable_get('location_default_country', 'us');
|
||||
$options['search_units'] = array('default' => ($country == 'us' || $country == 'uk' ? 'mile' : 'km'));
|
||||
$options['search_method'] = array('default' => 'mbr');
|
||||
$options['type'] = array('default' => 'postal');
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a form elements to select options for this argument.
|
||||
*/
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['type'] = array(
|
||||
'#title' => t('Coordinate Type'),
|
||||
'#type' => 'select',
|
||||
'#options' => array(
|
||||
'postal' => t('Postal Code (Zipcode)'),
|
||||
'latlon' => t('Decimal Latitude and Longitude coordinates, comma delimited'),
|
||||
),
|
||||
'#default_value' => $this->options['type'],
|
||||
'#description' => t('Type of center point.') . '<br />' . t('Postal code argument format: country_postcode_distance or postcode_distance') . '<br />' . t('Lat/Lon argument format: lat,lon_distance') . '<br />' . t('where distance is either a number or a comma delimited pair of decimal degrees'),
|
||||
);
|
||||
|
||||
// Units used.
|
||||
$form['search_units'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Distance unit'),
|
||||
'#options' => array(
|
||||
'km' => t('Kilometers'),
|
||||
'm' => t('Meters'),
|
||||
'mile' => t('Miles'),
|
||||
'dd' => t('Decimal degrees'),
|
||||
),
|
||||
'#default_value' => $this->options['search_units'],
|
||||
'#description' => t('Select the unit of distance. Decimal degrees should be comma delimited.'),
|
||||
);
|
||||
|
||||
$form['search_method'] = array(
|
||||
'#title' => t('Method'),
|
||||
'#type' => 'select',
|
||||
'#options' => array(
|
||||
'dist' => t('Circular Proximity'),
|
||||
'mbr' => t('Rectangular Proximity'),
|
||||
),
|
||||
'#default_value' => $this->options['search_method'],
|
||||
'#description' => t('Method of determining proximity. Please note that Circular Proximity does not work with Decimal degrees.'),
|
||||
);
|
||||
}
|
||||
|
||||
function calculate_coords() {
|
||||
if (!empty($this->value['latitude']) && !empty($this->value['longitude'])) {
|
||||
// If there are already coordinates, there's no work for us.
|
||||
return TRUE;
|
||||
}
|
||||
// @@@ Switch to mock location object and rely on location more?
|
||||
|
||||
if ($this->options['type'] == 'postal') {
|
||||
if (!isset($this->value['country'])) {
|
||||
$this->value['country'] = variable_get('location_default_country', 'us');
|
||||
}
|
||||
// Zip code lookup.
|
||||
if (!empty($this->value['postal_code']) && !empty($this->value['country'])) {
|
||||
location_load_country($this->value['country']);
|
||||
$coord = location_get_postalcode_data($this->value);
|
||||
if ($coord) {
|
||||
$this->value['latitude'] = $coord['lat'];
|
||||
$this->value['longitude'] = $coord['lon'];
|
||||
}
|
||||
else {
|
||||
$coord = location_latlon_rough($this->value);
|
||||
if ($coord) {
|
||||
$this->value['latitude'] = $coord['lat'];
|
||||
$this->value['longitude'] = $coord['lon'];
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up the query for this argument.
|
||||
*
|
||||
* The argument sent may be found at $this->argument.
|
||||
*/
|
||||
function query($group_by = FALSE) {
|
||||
// Get and process argument.
|
||||
if ($this->options['type'] == 'postal') {
|
||||
foreach ($this->view->argument as $argument) {
|
||||
if ($argument->field == 'distance') {
|
||||
$arg_parts = explode('_', $this->view->args[$argument->position]);
|
||||
if (count($arg_parts) == 3) {
|
||||
$this->value['country'] = drupal_strtolower($arg_parts[0]);
|
||||
$this->value['postal_code'] = $arg_parts[1];
|
||||
$this->value['search_distance'] = $arg_parts[2];
|
||||
}
|
||||
else {
|
||||
$this->value['postal_code'] = $arg_parts[0];
|
||||
$this->value['search_distance'] = $arg_parts[1];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ($this->options['type'] == 'latlon') {
|
||||
foreach ($this->view->argument as $argument) {
|
||||
if ($argument->field == 'distance') {
|
||||
list($coords, $this->value['search_distance']) = explode('_', $this->view->args[$argument->position]);
|
||||
list($this->value['latitude'], $this->value['longitude']) = explode(',', $coords);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Coordinates available?
|
||||
if (!$this->calculate_coords()) {
|
||||
// Distance set?
|
||||
if (!empty($this->value['search_distance'])) {
|
||||
// Hmm, distance set but unable to resolve coordinates.
|
||||
// Force nothing to match.
|
||||
$this->query->add_where(0, "1 = 0");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
$this->ensure_my_table();
|
||||
|
||||
$lat = $this->value['latitude'];
|
||||
$lon = $this->value['longitude'];
|
||||
|
||||
// search_distance
|
||||
if ($this->options['search_units'] == 'dd') {
|
||||
list($lat_distance, $lon_distance) = explode(',', $this->value['search_distance']);
|
||||
$latrange[0] = $lat - $lat_distance;
|
||||
$latrange[1] = $lat + $lat_distance;
|
||||
$lonrange[0] = $lon - $lon_distance;
|
||||
$lonrange[1] = $lon + $lon_distance;
|
||||
}
|
||||
else {
|
||||
$distance = $this->value['search_distance'];
|
||||
if ($this->options['search_units'] == 'm') {
|
||||
$distance_meters = $distance;
|
||||
}
|
||||
else {
|
||||
$distance_meters = _location_convert_distance_to_meters($distance, $this->options['search_units']);
|
||||
}
|
||||
|
||||
$latrange = earth_latitude_range($lon, $lat, $distance_meters);
|
||||
$lonrange = earth_longitude_range($lon, $lat, $distance_meters);
|
||||
}
|
||||
|
||||
// Add MBR check (always).
|
||||
// In case we go past the 180/-180 mark for longitude.
|
||||
if ($lonrange[0] > $lonrange[1]) {
|
||||
$where = "$this->table_alias.latitude > :minlat AND $this->table_alias.latitude < :maxlat AND (($this->table_alias.longitude < 180 AND $this->table_alias.longitude > :minlon) OR ($this->table_alias.longitude < :maxlon AND $this->table_alias.longitude > -180))";
|
||||
}
|
||||
else {
|
||||
$where = "$this->table_alias.latitude > :minlat AND $this->table_alias.latitude < :maxlat AND $this->table_alias.longitude > :minlon AND $this->table_alias.longitude < :maxlon";
|
||||
}
|
||||
$this->query->add_where_expression(0, $where, array(':minlat' => $latrange[0], ':maxlat' => $latrange[1], ':minlon' => $lonrange[0], ':maxlon' => $lonrange[1]));
|
||||
|
||||
if ($this->options['search_method'] == 'dist') {
|
||||
// Add radius check.
|
||||
$this->query->add_where_expression(0, earth_distance_sql($lon, $lat, $this->table_alias) . ' < :distance', array(':distance' => $distance_meters));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Field handler to display a complete address.
|
||||
*/
|
||||
|
||||
class location_handler_field_location_address extends views_handler_field {
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['hide'] = array('default' => array());
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['hide'] = array(
|
||||
'#type' => 'checkboxes',
|
||||
'#title' => t('Hide fields from display'),
|
||||
'#options' => location_field_names(TRUE),
|
||||
'#default_value' => $this->options['hide'],
|
||||
);
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
if ($values->{$this->field_alias}) {
|
||||
$location = location_load_location($values->{$this->field_alias});
|
||||
if ($location['lid']) {
|
||||
return theme('location', array('location' => $location, 'hide' => $this->options['hide']));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Country field handler.
|
||||
*/
|
||||
|
||||
class location_handler_field_location_country extends views_handler_field {
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['style'] = array('default' => 'name');
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['style'] = array(
|
||||
'#title' => t('Display style'),
|
||||
'#type' => 'select',
|
||||
'#options' => array('name' => t('Country name'), 'code' => t('Country code')),
|
||||
'#default_value' => $this->options['style'],
|
||||
);
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
if ($this->options['style'] == 'name') {
|
||||
return check_plain(location_country_name($values->{$this->field_alias}));
|
||||
}
|
||||
else {
|
||||
return check_plain(strtoupper($values->{$this->field_alias}));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Coordinates field handler.
|
||||
*/
|
||||
|
||||
class location_handler_field_location_distance extends views_handler_field {
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['origin'] = array('default' => 'user');
|
||||
$options['units'] = array('default' => 'km');
|
||||
$options['latitude'] = array('default' => '');
|
||||
$options['longitude'] = array('default' => '');
|
||||
$options['postal_code'] = array('default' => '');
|
||||
$options['country'] = array('default' => '');
|
||||
$options['php_code'] = array('default' => '');
|
||||
$options['nid_arg'] = array('default' => '');
|
||||
$options['nid_loc_field'] = array('default' => 'node');
|
||||
$options['uid_arg'] = array('default' => '');
|
||||
return $options;
|
||||
}
|
||||
|
||||
function has_extra_options() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function extra_options_form(&$form, &$form_state) {
|
||||
$form['units'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Units'),
|
||||
'#options' => array(
|
||||
'km' => t('Kilometers'),
|
||||
'mi' => t('Miles'),
|
||||
),
|
||||
'#default_value' => $this->options['units'],
|
||||
);
|
||||
$form['origin'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Origin'),
|
||||
'#options' => array(
|
||||
'user' => t("User's Latitude / Longitude (blank if unset)"),
|
||||
'hybrid' => t("User's Latitude / Longitude (fall back to static if unset)"),
|
||||
'static' => t('Static Latitude / Longitude'),
|
||||
'tied' => t("Use Distance / Proximity filter"),
|
||||
'postal' => t('Postal Code / Country'),
|
||||
'postal_default' => t('Postal Code (assume default country)'),
|
||||
'php' => t('Use PHP code to determine latitude/longitude'),
|
||||
'nid_arg' => t("Node's Latitude / Longitude from views nid argument"),
|
||||
'uid_arg' => t("User's Latitude / Longitude from views uid argument"),
|
||||
'distance_arg' => t("Latitude / Longitude from views argument"),
|
||||
),
|
||||
'#description' => t("This will be the way the latitude/longitude of origin is determined. When using the user's latitude / longitude, if a user has multiple locations the first will be used."),
|
||||
'#default_value' => $this->options['origin'],
|
||||
);
|
||||
|
||||
$form['latitude'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Latitude'),
|
||||
'#default_value' => $this->options['latitude'],
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('hybrid', 'static')),
|
||||
);
|
||||
$form['longitude'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Longitude'),
|
||||
'#default_value' => $this->options['longitude'],
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('hybrid', 'static')),
|
||||
);
|
||||
|
||||
$form['postal_code'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Postal code'),
|
||||
'#default_value' => $this->options['postal_code'],
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('postal', 'postal_default')),
|
||||
'#maxlength' => 16
|
||||
);
|
||||
|
||||
$form['country'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Country'),
|
||||
'#options' => array('' => '') + location_get_iso3166_list(),
|
||||
'#default_value' => $this->options['country'],
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('postal')),
|
||||
);
|
||||
|
||||
$form['php_code'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('PHP code for latitude, longitude'),
|
||||
'#default_value' => $this->options['php_code'],
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('php')),
|
||||
'#description' => t("Enter PHP code that returns a latitude/longitude. Do not use <?php ?>. You must return only an array with float values set for the 'latitude' and 'longitude' keys."),
|
||||
);
|
||||
|
||||
list($nid_argument_options, $uid_argument_options) = location_views_proximity_get_argument_options($this->view);
|
||||
$nid_loc_field_options = location_views_proximity_get_location_field_options();
|
||||
|
||||
$form['nid_arg'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Node ID argument to use'),
|
||||
'#options' => $nid_argument_options,
|
||||
'#default_value' => $this->options['nid_arg'],
|
||||
'#description' => empty($nid_argument_options) ? t("Select which of the view's arguments to use as the node ID. The latitude / longitude of the first location of that node will be used as the origin. Use the 'Global: Null' argument if you don't want to also restrict results to that node ID. You must have added arguments to the view to use this option.") : t("Select which of the view's arguments to use as the node ID. The latitude / longitude of the first location of that node will be used as the origin. Use the 'Global: Null' argument if you don't want to also restrict results to that node ID."),
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('nid_arg')),
|
||||
);
|
||||
$form['nid_loc_field'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Location to use'),
|
||||
'#options' => $nid_loc_field_options,
|
||||
'#default_value' => $this->options['nid_loc_field'],
|
||||
'#description' => t("Select which of the node's locations to use as the origin. Either the node locations or a CCK location field. If the location supports multiple entries the first one will be used."),
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('nid_arg')),
|
||||
);
|
||||
$form['uid_arg'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('User ID argument to use'),
|
||||
'#options' => $uid_argument_options,
|
||||
'#default_value' => $this->options['uid_arg'],
|
||||
'#description' => empty($uid_argument_options) ? t("Select which of the view's arguments to use as the user ID. The latitude / longitude of the first location of that user will be used as the origin. Use the 'Global: Null' argument if you don't want to also restrict results to that user ID. You must have added arguments to the view to use this option.") : t("Select which of the view's arguments to use as the user ID. The latitude / longitude of the first location of that user will be used as the origin. Use the 'Global: Null' argument if you don't want to also restrict results to that user ID."),
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('uid_arg')),
|
||||
);
|
||||
}
|
||||
|
||||
function click_sort($order) {
|
||||
$location = location_views_proximity_get_reference_location($this->view, $this->options);
|
||||
|
||||
if ($location) {
|
||||
$this->query->add_orderby(NULL, earth_distance_sql($location['longitude'], $location['latitude'], $this->table_alias), $order, $this->field_alias);
|
||||
}
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
if (empty($values->{$this->field_alias}) || $values->{$this->field_alias} == 'Unknown') {
|
||||
// Unset location, empty display.
|
||||
return;
|
||||
}
|
||||
$dist = (float)$values->{$this->field_alias};
|
||||
if ($this->options['units'] == 'km') {
|
||||
$dist = $dist / 1000.0;
|
||||
return theme('location_distance', array('distance' => $dist, 'units' => 'km'));
|
||||
}
|
||||
else {
|
||||
$dist = $dist / 1609.347;
|
||||
return theme('location_distance', array('distance' => $dist, 'units' => 'mi'));
|
||||
}
|
||||
}
|
||||
|
||||
function query() {
|
||||
$this->ensure_my_table();
|
||||
|
||||
$coordinates = location_views_proximity_get_reference_location($this->view, $this->options);
|
||||
|
||||
if (!empty($coordinates)) {
|
||||
$this->field_alias = $this->query->add_field(NULL, earth_distance_sql($coordinates['longitude'], $coordinates['latitude'], $this->table_alias), $this->table_alias .'_'. $this->field);
|
||||
}
|
||||
else {
|
||||
$this->field_alias = $this->query->add_field(NULL, "'Unknown'", $this->table_alias .'_'. $this->field);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Province field handler.
|
||||
*/
|
||||
|
||||
class location_handler_field_location_province extends views_handler_field {
|
||||
|
||||
function construct() {
|
||||
parent::construct();
|
||||
$this->additional_fields = array(
|
||||
'country' => 'country',
|
||||
);
|
||||
}
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['style'] = array('default' => 'name');
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['style'] = array(
|
||||
'#title' => t('Display style'),
|
||||
'#type' => 'select',
|
||||
'#options' => array('name' => t('Province name'), 'code' => t('Province code')),
|
||||
'#default_value' => $this->options['style'],
|
||||
);
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
if ($this->options['style'] == 'name') {
|
||||
return check_plain(location_province_name($values->{$this->aliases['country']}, $values->{$this->field_alias}));
|
||||
}
|
||||
else {
|
||||
return check_plain(strtoupper($values->{$this->field_alias}));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Province field handler.
|
||||
*/
|
||||
|
||||
class location_handler_field_location_street extends views_handler_field {
|
||||
|
||||
function construct() {
|
||||
parent::construct();
|
||||
$this->additional_fields = array(
|
||||
'additional' => 'additional',
|
||||
);
|
||||
}
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['style'] = array('default' => 'both');
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['style'] = array(
|
||||
'#title' => t('Display style'),
|
||||
'#type' => 'select',
|
||||
'#options' => array(
|
||||
'both' => t('Both street and additional'),
|
||||
'street' => t('Street only'),
|
||||
'additional' => t('Additional only'),
|
||||
),
|
||||
'#default_value' => $this->options['style'],
|
||||
);
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
$parts = array();
|
||||
if ($this->options['style'] != 'additional') {
|
||||
$parts[] = check_plain($values->{$this->field_alias});
|
||||
}
|
||||
if ($this->options['style'] != 'street') {
|
||||
$additional = trim($values->{$this->aliases['additional']});
|
||||
if (!empty($additional)) {
|
||||
$parts[] = check_plain($values->{$this->aliases['additional']});
|
||||
}
|
||||
}
|
||||
// @@@ Better theming?
|
||||
return implode('<br />', $parts);
|
||||
}
|
||||
}
|
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Filter on country.
|
||||
*/
|
||||
class location_handler_filter_location_country extends views_handler_filter_in_operator {
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['operator'] = array('default' => 'in');
|
||||
return $options;
|
||||
}
|
||||
|
||||
|
||||
function admin_summary() {
|
||||
return '';
|
||||
// $options = $this->operator_options('short');
|
||||
// return (!empty($this->options['exposed']) ? t('exposed') : $options[$this->operator]);
|
||||
}
|
||||
|
||||
function get_value_options() {
|
||||
$this->value_options = location_get_iso3166_list();
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide widgets for filtering by country.
|
||||
*/
|
||||
function value_form(&$form, &$form_state) {
|
||||
$this->get_value_options();
|
||||
$options = $this->value_options;
|
||||
$default_value = (array) $this->value;
|
||||
|
||||
if (!empty($form_state['exposed'])) {
|
||||
$identifier = $this->options['expose']['identifier'];
|
||||
|
||||
if (empty($this->options['expose']['use_operator']) || empty($this->options['expose']['operator'])) {
|
||||
// exposed and locked.
|
||||
$which = in_array($this->operator, $this->operator_values(1)) ? 'value' : 'none';
|
||||
}
|
||||
else {
|
||||
$source = 'edit-' . drupal_clean_css_identifier($this->options['expose']['operator']);
|
||||
}
|
||||
|
||||
if (!empty($this->options['expose']['reduce'])) {
|
||||
$options = $this->reduce_value_options();
|
||||
|
||||
if (empty($this->options['expose']['single']) && !empty($this->options['expose']['optional'])) {
|
||||
$default_value = array();
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->options['expose']['single'])) {
|
||||
if (!empty($this->options['expose']['optional']) && (empty($default_value) || !empty($this->options['expose']['reduce']))) {
|
||||
$default_value = 'All';
|
||||
}
|
||||
else if (empty($default_value)) {
|
||||
$keys = array_keys($options);
|
||||
$default_value = array_shift($keys);
|
||||
}
|
||||
else {
|
||||
$copy = $default_value;
|
||||
$default_value = array_shift($copy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$form['value'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Country'),
|
||||
'#default_value' => $default_value,
|
||||
'#options' => $options,
|
||||
// Used by province autocompletion js.
|
||||
'#attributes' => array('class' => array('location_auto_country')),
|
||||
'#multiple' => TRUE, // views will change this as necessary when exposed.
|
||||
);
|
||||
|
||||
// Let location_autocomplete.js find the correct fields to attach.
|
||||
$form['value']['#attributes']['class'][] = 'location_auto_join_' . $this->options['expose']['identifier'];
|
||||
}
|
||||
|
||||
function reduce_value_options($input = NULL) {
|
||||
if (empty($this->options)) {
|
||||
$this->get_value_options();
|
||||
}
|
||||
if (!empty($this->options['expose']['reduce']) && !empty($this->options['value'])) {
|
||||
$reduced_options = array();
|
||||
foreach ($this->options['value'] as $value) {
|
||||
$reduced_options[$value] = $this->value_options[$value];
|
||||
}
|
||||
return $reduced_options;
|
||||
}
|
||||
return $this->get_value_options();
|
||||
}
|
||||
|
||||
function accept_exposed_input($input) {
|
||||
if (empty($this->options['exposed'])) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator_id']) && isset($input[$this->options['expose']['operator_id']])) {
|
||||
$this->operator = $input[$this->options['expose']['operator_id']];
|
||||
}
|
||||
|
||||
if (!empty($this->options['expose']['identifier'])) {
|
||||
$value = $input[$this->options['expose']['identifier']];
|
||||
|
||||
if (empty($this->options['expose']['required'])) {
|
||||
if ($value == 'All' || $value === array()) {
|
||||
if (empty($this->options['value']) || (!empty($this->options['value']) && empty($this->options['expose']['reduce']))) {
|
||||
return FALSE;
|
||||
}
|
||||
else {
|
||||
$value = $this->options['value'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->always_multiple) && $value === '') {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($value)) {
|
||||
$this->value = $value;
|
||||
if (empty($this->always_multiple) && empty($this->options['expose']['multiple'])) {
|
||||
$this->value = array($value);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function operator_options($which = 'title') {
|
||||
if (empty($this->options['expose']['multiple'])) {
|
||||
return array(
|
||||
'in' => t('Is'),
|
||||
'not in' => t('Is not'),
|
||||
);
|
||||
}
|
||||
else {
|
||||
return array(
|
||||
'in' => t('Is one of'),
|
||||
'not in' => t('Is not one of'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function query() {
|
||||
if (empty($this->value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->ensure_my_table();
|
||||
$field = "$this->table_alias.$this->real_field";
|
||||
|
||||
// Normalize values.
|
||||
$value = $this->value;
|
||||
if (is_array($value)) {
|
||||
if (count($value) == 1) {
|
||||
// If multiple is allowed but only one was chosen, use a string instead.
|
||||
$value = reset($value);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_array($value)) {
|
||||
// Multiple values
|
||||
$operator = ($this->operator == 'in') ? 'IN' : 'NOT IN';
|
||||
$this->query->add_where($this->options['group'], $field, $value, $operator);
|
||||
}
|
||||
else {
|
||||
// Single value
|
||||
$operator = ($this->operator == 'in') ? '=' : '!=';
|
||||
$this->query->add_where($this->options['group'], $field, $value, $operator);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Filter on province.
|
||||
*/
|
||||
class location_handler_filter_location_province extends views_handler_filter {
|
||||
|
||||
var $location_country = FALSE;
|
||||
var $location_country_identifier = FALSE;
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['operator'] = array('default' => 'is');
|
||||
return $options;
|
||||
}
|
||||
|
||||
function admin_summary() {
|
||||
return '';
|
||||
// $options = $this->operator_options('short');
|
||||
// return (!empty($this->options['exposed']) ? t('exposed') : $options[$this->operator]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a simple textfield for equality
|
||||
*/
|
||||
function value_form(&$form, &$form_state) {
|
||||
$country = $this->grovel_country();
|
||||
|
||||
drupal_add_js(drupal_get_path('module', 'location') .'/location_autocomplete.js');
|
||||
|
||||
$ac = $country;
|
||||
if (is_array($ac)) {
|
||||
$ac = implode(',', $ac);
|
||||
}
|
||||
$form['value'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('State/Province'),
|
||||
'#autocomplete_path' => 'location/autocomplete/'. $ac,
|
||||
'#default_value' => $this->value,
|
||||
'#size' => 64,
|
||||
'#maxlength' => 64,
|
||||
// Used by province autocompletion js.
|
||||
'#attributes' => array('class' => array('location_auto_province')),
|
||||
'#multiple' => TRUE, //$this->options['multiple'],
|
||||
);
|
||||
|
||||
// Let location_autocomplete.js find the correct fields to attach.
|
||||
if ($this->location_country_identifier) {
|
||||
$form['value']['#attributes']['class'][] = 'location_auto_join_' . $this->location_country_identifier;
|
||||
}
|
||||
}
|
||||
|
||||
function operator_options() {
|
||||
if ($this->options['expose']['single']) {
|
||||
return array(
|
||||
'is' => t('Is'),
|
||||
'is not' => t('Is not'),
|
||||
);
|
||||
}
|
||||
else {
|
||||
return array(
|
||||
'is' => t('Is one of'),
|
||||
'is not' => t('Is not one of'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function grovel_country() {
|
||||
$country = variable_get('location_default_country', 'us');
|
||||
if (!empty($this->view->filter))
|
||||
foreach ($this->view->filter as $k => $v) {
|
||||
if ($v->table == 'location' && $v->field == 'country' && $v->options['relationship'] == $this->options['relationship']) {
|
||||
$country = $v->value;
|
||||
if (!empty($v->options['expose']['identifier'])) {
|
||||
if (isset($this->view->exposed_input[$v->options['expose']['identifier']])) {
|
||||
$country = $this->view->exposed_input[$v->options['expose']['identifier']];
|
||||
}
|
||||
$this->location_country_identifier = $v->options['expose']['identifier'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($country == '' || $country == 'All' || $country == ' ' || $country == 'xx') {
|
||||
// It's set to something nonsensical, reset to the default to prevent malfunctions.
|
||||
$country = variable_get('location_default_country', 'us');
|
||||
}
|
||||
$this->location_country = $country;
|
||||
return $country;
|
||||
}
|
||||
|
||||
function query() {
|
||||
// Normalize values.
|
||||
$value = $this->value;
|
||||
if (is_array($value)) {
|
||||
// At one point during development, provinces was a select box.
|
||||
// Right now it's an autocomplete textfield.
|
||||
// @@@ Investigate correct fix sometime.
|
||||
//$value = array_keys($value);
|
||||
if (count($value) == 1) {
|
||||
// If multiple is allowed but only one was chosen, use a string instead.
|
||||
$value = reset($value);
|
||||
}
|
||||
}
|
||||
if (empty($value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$country = $this->grovel_country();
|
||||
|
||||
$this->ensure_my_table();
|
||||
$field = "$this->table_alias.$this->real_field";
|
||||
|
||||
|
||||
if (is_array($value)) {
|
||||
// Multiple values
|
||||
foreach ($value as $k => $v) {
|
||||
// Convert to province codes.
|
||||
$value[$k] = location_province_code($country, $v);
|
||||
}
|
||||
$operator = ($this->operator == 'is') ? 'IN' : 'NOT IN';
|
||||
$this->query->add_where($this->options['group'], $field, $value, $operator);
|
||||
}
|
||||
else {
|
||||
// Single value
|
||||
// Convert to province code.
|
||||
$value = location_province_code($country, $value);
|
||||
$operator = ($this->operator == 'is') ? '=' : '!=';
|
||||
$this->query->add_where($this->options['group'], $field, $value, $operator);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Coordinates sort handler.
|
||||
*/
|
||||
|
||||
class location_handler_sort_location_distance extends views_handler_sort {
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['origin'] = array('default' => 'user');
|
||||
$options['latitude'] = array('default' => '');
|
||||
$options['longitude'] = array('default' => '');
|
||||
$options['postal_code'] = array('default' => '');
|
||||
$options['country'] = array('default' => '');
|
||||
$options['php_code'] = array('default' => '');
|
||||
$options['nid_arg'] = array('default' => '');
|
||||
$options['nid_loc_field'] = array('default' => 'node');
|
||||
$options['uid_arg'] = array('default' => '');
|
||||
return $options;
|
||||
}
|
||||
|
||||
function has_extra_options() {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function extra_options_form(&$form, &$form_state) {
|
||||
$form['origin'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Origin'),
|
||||
'#options' => array(
|
||||
'user' => t("User's Latitude / Longitude (blank if unset)"),
|
||||
'hybrid' => t("User's Latitude / Longitude (fall back to static if unset)"),
|
||||
'static' => t('Static Latitude / Longitude'),
|
||||
'tied' => t("Use Distance / Proximity filter"),
|
||||
'postal' => t('Postal Code / Country'),
|
||||
'postal_default' => t('Postal Code (assume default country)'),
|
||||
'php' => t('Use PHP code to determine latitude/longitude'),
|
||||
'nid_arg' => t("Node's Latitude / Longitude from views nid argument"),
|
||||
'uid_arg' => t("User's Latitude / Longitude from views uid argument"),
|
||||
),
|
||||
'#description' => t("This will be the way the latitude/longitude of origin is determined. When using the user's latitude / longitude, if a user has multiple locations the first will be used."),
|
||||
'#default_value' => $this->options['origin'],
|
||||
);
|
||||
$form['latitude'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Latitude'),
|
||||
'#default_value' => $this->options['latitude'],
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('hybrid', 'static')),
|
||||
);
|
||||
$form['longitude'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Longitude'),
|
||||
'#default_value' => $this->options['longitude'],
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('hybrid', 'static')),
|
||||
);
|
||||
|
||||
$form['postal_code'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Postal code'),
|
||||
'#default_value' => $this->options['postal_code'],
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('postal', 'postal_default')),
|
||||
'#maxlength' => 16
|
||||
);
|
||||
|
||||
$form['country'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Country'),
|
||||
'#options' => array('' => '') + location_get_iso3166_list(),
|
||||
'#default_value' => $this->options['country'],
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('postal')),
|
||||
);
|
||||
|
||||
$form['php_code'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('PHP code for latitude, longitude'),
|
||||
'#default_value' => $this->options['php_code'],
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('php')),
|
||||
'#description' => t("Enter PHP code that returns a latitude/longitude. Do not use <?php ?>. You must return only an array with float values set for the 'latitude' and 'longitude' keys."),
|
||||
);
|
||||
|
||||
list($nid_argument_options, $uid_argument_options) = location_views_proximity_get_argument_options($this->view);
|
||||
$nid_loc_field_options = location_views_proximity_get_location_field_options();
|
||||
|
||||
$form['nid_arg'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Node ID argument to use'),
|
||||
'#options' => $nid_argument_options,
|
||||
'#default_value' => $this->options['nid_arg'],
|
||||
'#description' => empty($nid_argument_options) ? t("Select which of the view's arguments to use as the node ID. The latitude / longitude of the first location of that node will be used as the origin. Use the 'Global: Null' argument if you don't want to also restrict results to that node ID. You must have added arguments to the view to use this option.") : t("Select which of the view's arguments to use as the node ID. The latitude / longitude of the first location of that node will be used as the origin. Use the 'Global: Null' argument if you don't want to also restrict results to that node ID."),
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('nid_arg')),
|
||||
);
|
||||
$form['nid_loc_field'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Location to use'),
|
||||
'#options' => $nid_loc_field_options,
|
||||
'#default_value' => $this->options['nid_loc_field'],
|
||||
'#description' => t("Select which of the node's locations to use as the origin. Either the node locations or a CCK location field. If the location supports multiple entries the first one will be used."),
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('nid_arg')),
|
||||
);
|
||||
$form['uid_arg'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('User ID argument to use'),
|
||||
'#options' => $uid_argument_options,
|
||||
'#default_value' => $this->options['uid_arg'],
|
||||
'#description' => empty($uid_argument_options) ? t("Select which of the view's arguments to use as the user ID. The latitude / longitude of the first location of that user will be used as the origin. Use the 'Global: Null' argument if you don't want to also restrict results to that user ID. You must have added arguments to the view to use this option.") : t("Select which of the view's arguments to use as the user ID. The latitude / longitude of the first location of that user will be used as the origin. Use the 'Global: Null' argument if you don't want to also restrict results to that user ID."),
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('uid_arg')),
|
||||
);
|
||||
}
|
||||
|
||||
function query() {
|
||||
$coordinates = location_views_proximity_get_reference_location($this->view, $this->options);
|
||||
|
||||
$this->ensure_my_table();
|
||||
|
||||
// OK, so this part will need a little explanation.
|
||||
// Since the distance calculation is so icky, we try quite hard
|
||||
// to save some work for the database.
|
||||
// If someone has added a field that matches the sort, we just sort on that column!
|
||||
$alias = $this->table_alias . '_' . $this->field . '_sort';
|
||||
foreach ($this->view->field as $filter) {
|
||||
if ($filter->table == 'location' && $filter->field == 'distance' && $filter->options['relationship'] == $this->options['relationship']) {
|
||||
if ($filter->options['origin'] == $this->options['origin']
|
||||
&& $filter->options['latitude'] == $this->options['latitude']
|
||||
&& $filter->options['longitude'] == $this->options['longitude']) {
|
||||
// We have a match! Sync aliases to make it easier on the database.
|
||||
$alias = $filter->field_alias;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($coordinates)) {
|
||||
// We don't know the distance.
|
||||
// Therefore, we don't need to sort on it.
|
||||
}
|
||||
else {
|
||||
// This is done exactly the same as the field version.
|
||||
// Views is ok with us redefining the formula for a field.
|
||||
// If ANYTHING differs in the configuration, we will use a new alias.
|
||||
$this->query->add_orderby(NULL, earth_distance_sql($coordinates['longitude'], $coordinates['latitude'], $this->table_alias), $this->options['order'], $alias);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Coordinates field handler.
|
||||
*/
|
||||
|
||||
class location_views_handler_field_coordinates extends location_views_handler_field_latitude {
|
||||
|
||||
function construct() {
|
||||
parent::construct();
|
||||
$this->additional_fields['longitude'] = 'longitude';
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
if ($this->options['style'] == 'dms') {
|
||||
return theme('location_latitude_dms', array('latitude' => $values->{$this->field_alias})) . ', ' . theme('location_longitude_dms', array('longitude' => $values->{$this->aliases['longitude']}));
|
||||
}
|
||||
else {
|
||||
return check_plain($values->{$this->field_alias}) . ', ' . check_plain($values->{$this->aliases['longitude']});
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Latitude field handler.
|
||||
*/
|
||||
|
||||
class location_views_handler_field_latitude extends views_handler_field {
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['style'] = array('default' => 'dms');
|
||||
return $options;
|
||||
}
|
||||
|
||||
function options_form(&$form, &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
$form['style'] = array(
|
||||
'#title' => t('Display style'),
|
||||
'#type' => 'select',
|
||||
'#options' => array(
|
||||
'dd' => t('Decimal degrees'),
|
||||
'dms' => t('Degrees, minutes, seconds'),
|
||||
),
|
||||
'#default_value' => $this->options['style'],
|
||||
);
|
||||
}
|
||||
|
||||
function render($values) {
|
||||
if ($this->options['style'] == 'dd') {
|
||||
return check_plain($values->{$this->field_alias});
|
||||
}
|
||||
else {
|
||||
return theme('location_latitude_dms', array('latitude' => $values->{$this->field_alias}));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Longitude field handler.
|
||||
*/
|
||||
|
||||
class location_views_handler_field_longitude extends location_views_handler_field_latitude {
|
||||
|
||||
function render($values) {
|
||||
if ($this->options['style'] == 'dms') {
|
||||
return theme('location_longitude_dms', array('longitude' => $values->{$this->field_alias}));
|
||||
}
|
||||
return parent::render($values);
|
||||
}
|
||||
}
|
@@ -0,0 +1,334 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* General proximity filter for location latitude/longitude.
|
||||
*/
|
||||
class location_views_handler_filter_proximity extends views_handler_filter {
|
||||
// This is always multiple, because we can have distance, units etc.
|
||||
var $always_multiple = TRUE;
|
||||
|
||||
function option_definition() {
|
||||
$options = parent::option_definition();
|
||||
$options['operator'] = array('default' => 'mbr');
|
||||
|
||||
$options['identifier'] = array('default' => 'dist');
|
||||
|
||||
$options['origin'] = array('default' => 'user');
|
||||
|
||||
$options['value'] = array(
|
||||
'default' => array(
|
||||
'latitude' => '',
|
||||
'longitude' => '',
|
||||
'postal_code' => '',
|
||||
'country' => '',
|
||||
'php_code' => '',
|
||||
'nid_arg' => '',
|
||||
'nid_loc_field' => 'node',
|
||||
'uid_arg' => '',
|
||||
'search_distance' => 100,
|
||||
'search_units' => 'mile',
|
||||
),
|
||||
);
|
||||
|
||||
$options['expose']['contains']['gmap_macro'] = array('default' => '[gmap ]');
|
||||
$options['expose']['contains']['user_location_choose'] = array('default' => FALSE);
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
function admin_summary() {
|
||||
return '';
|
||||
}
|
||||
|
||||
function operator_options() {
|
||||
return array(
|
||||
'mbr' => t('Proximity (Rectangular)'),
|
||||
'dist' => t('Proximity (Circular)'),
|
||||
);
|
||||
}
|
||||
|
||||
function expose_options() {
|
||||
parent::expose_options();
|
||||
$this->options['expose']['gmap_macro'] = array('default' => '[gmap ]');
|
||||
$this->options['expose']['user_location_choose'] = array('default' => FALSE);
|
||||
}
|
||||
|
||||
function expose_form_left(&$form, &$form_state) {
|
||||
parent::expose_form_left($form, $form_state);
|
||||
// @@@ Todo: autohide this.
|
||||
$form['expose']['gmap_macro'] = array(
|
||||
'#parents' => array('options', 'gmap_macro'),
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('GMap macro'),
|
||||
'#description' => t('The macro to use for the Latitude / Longitude map, if applicable.'),
|
||||
'#default_value' => $this->options['expose']['gmap_macro'],
|
||||
);
|
||||
|
||||
$form['expose']['user_location_choose'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t("Allow choice of user location"),
|
||||
'#default_value' => $this->options['expose']['user_location_choose'],
|
||||
'#description' => t("If checked and using a user location origin, the user will be able to choose which of their locations to use. Otherwise their first location will be used."),
|
||||
);
|
||||
}
|
||||
|
||||
function value_form(&$form, &$form_state) {
|
||||
$form['origin'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Origin'),
|
||||
'#options' => array(
|
||||
'user' => t("User's Latitude / Longitude (blank if unset)"),
|
||||
'hybrid' => t("User's Latitude / Longitude (fall back to static if unset)"),
|
||||
'static' => t('Static Latitude / Longitude'),
|
||||
'postal' => t('Postal Code / Country'),
|
||||
'postal_default' => t('Postal Code (assume default country)'),
|
||||
'php' => t('Use PHP code to determine latitude/longitude'),
|
||||
'nid_arg' => t("Node's Latitude / Longitude from views nid argument"),
|
||||
'uid_arg' => t("User's Latitude / Longitude from views uid argument"),
|
||||
),
|
||||
'#description' => t('This will be the way the latitude/longitude of origin is determined. If this filter is exposed, this will determine the default values. NOTE: The PHP code, nid argument and uid argument options will not be available when the filter is exposed and the use of map is only available when the filter is exposed.'),
|
||||
'#default_value' => $this->options['origin'] ? $this->options['origin'] : 'user',
|
||||
);
|
||||
if (module_exists('gmap')) {
|
||||
$form['origin']['#options']['latlon_gmap'] = t('Latitude / Longitude input (use map)');
|
||||
}
|
||||
|
||||
// [11:44] <merlinofchaos> If you load the page from scratch, $input for your identifier will be empty.
|
||||
// [11:44] <merlinofchaos> So what's going on here is that for $_GET forms, there's no form id, no op button or anything, so they always appear to submit.
|
||||
// [11:45] <merlinofchaos> FAPI doesn't quite get along with that; sometimes it handles the input being empty right and sometimes it doesn't.
|
||||
// [11:45] <Bdragon> But if I set #default_value to a static string, it doesn't work either
|
||||
// [11:45] <merlinofchaos> Right, fapi thinks the empty input is actually input, thus it overrides the default value.
|
||||
// [11:45] <Bdragon> Ahh, hmm...
|
||||
// [11:46] <Bdragon> So where would I go to clean it up?
|
||||
// [11:55] <merlinofchaos> Bdragon: See views_handler_filter_string.inc line 174
|
||||
// [11:55] <merlinofchaos> Bdragon: That's how i address this problem.
|
||||
// [11:58] <Bdragon> Hmm, OK
|
||||
if (!empty($form_state['exposed'])) {
|
||||
$identifier = $this->options['expose']['identifier'];
|
||||
if (!isset($form_state['input'][$identifier])) {
|
||||
// We need to pretend the user already inputted the defaults, because
|
||||
// fapi will malfunction otherwise.
|
||||
$form_state['input'][$identifier] = $this->value;
|
||||
}
|
||||
}
|
||||
|
||||
$form['value'] = array(
|
||||
'#tree' => TRUE,
|
||||
);
|
||||
|
||||
$form['value']['latitude'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Latitude'),
|
||||
'#default_value' => $this->value['latitude'],
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('hybrid', 'static', 'latlon_gmap')),
|
||||
'#weight' => 1,
|
||||
);
|
||||
$form['value']['longitude'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Longitude'),
|
||||
'#default_value' => $this->value['longitude'],
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('hybrid', 'static', 'latlon_gmap')),
|
||||
'#weight' => 2,
|
||||
);
|
||||
|
||||
$form['value']['postal_code'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Postal code'),
|
||||
'#default_value' => $this->value['postal_code'],
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('postal', 'postal_default')),
|
||||
'#weight' => 3,
|
||||
'#maxlength' => 16
|
||||
);
|
||||
|
||||
$form['value']['country'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Country'),
|
||||
'#options' => array('' => '') + location_get_iso3166_list(),
|
||||
'#default_value' => $this->value['country'],
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('postal')),
|
||||
'#weight' => 4,
|
||||
);
|
||||
|
||||
$form['value']['php_code'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('PHP code for latitude, longitude'),
|
||||
'#default_value' => $this->value['php_code'],
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('php')),
|
||||
'#description' => t("Enter PHP code that returns a latitude/longitude. Do not use <?php ?>. You must return only an array with float values set for the 'latitude' and 'longitude' keys."),
|
||||
'#weight' => 5,
|
||||
);
|
||||
|
||||
list($nid_argument_options, $uid_argument_options) = location_views_proximity_get_argument_options($this->view);
|
||||
$nid_loc_field_options = location_views_proximity_get_location_field_options();
|
||||
|
||||
$form['value']['nid_arg'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Node ID argument to use'),
|
||||
'#options' => $nid_argument_options,
|
||||
'#default_value' => $this->value['nid_arg'],
|
||||
'#description' => empty($nid_argument_options) ? t("Select which of the view's arguments to use as the node ID. The latitude / longitude of the first location of that node will be used as the origin. Use the 'Global: Null' argument if you don't want to also restrict results to that node ID. You must have added arguments to the view to use this option.") : t("Select which of the view's arguments to use as the node ID. The latitude / longitude of the first location of that node will be used as the origin. Use the 'Global: Null' argument if you don't want to also restrict results to that node ID."),
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('nid_arg')),
|
||||
'#weight' => 6,
|
||||
);
|
||||
$form['value']['nid_loc_field'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Location to use'),
|
||||
'#options' => $nid_loc_field_options,
|
||||
'#default_value' => $this->value['nid_loc_field'],
|
||||
'#description' => t("Select which of the node's locations to use as the origin. Either the node locations or a CCK location field. If the location supports multiple entries the first one will be used."),
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('nid_arg')),
|
||||
'#weight' => 7,
|
||||
);
|
||||
$form['value']['uid_arg'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('User ID argument to use'),
|
||||
'#options' => $uid_argument_options,
|
||||
'#default_value' => $this->value['uid_arg'],
|
||||
'#description' => empty($uid_argument_options) ? t("Select which of the view's arguments to use as the user ID. The latitude / longitude of the first location of that user will be used as the origin. Use the 'Global: Null' argument if you don't want to also restrict results to that user ID. You must have added arguments to the view to use this option.") : t("Select which of the view's arguments to use as the user ID. The latitude / longitude of the first location of that user will be used as the origin. Use the 'Global: Null' argument if you don't want to also restrict results to that user ID."),
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('edit-options-origin' => array('uid_arg')),
|
||||
'#weight' => 8,
|
||||
);
|
||||
|
||||
$form['value']['search_distance'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Distance'),
|
||||
'#default_value' => $this->value['search_distance'],
|
||||
'#weight' => 9,
|
||||
);
|
||||
|
||||
$form['value']['search_units'] = array(
|
||||
'#type' => 'select',
|
||||
'#options' => array(
|
||||
'mile' => t('Miles'),
|
||||
'km' => t('Kilometers'),
|
||||
),
|
||||
'#default_value' => $this->value['search_units'],
|
||||
'#weight' => 10,
|
||||
);
|
||||
}
|
||||
|
||||
function exposed_form(&$form, &$form_state) {
|
||||
parent::exposed_form($form, $form_state);
|
||||
$key = $this->options['expose']['identifier'];
|
||||
$origin = $this->options['origin'];
|
||||
|
||||
// Strip dependencies off on exposed form.
|
||||
foreach (element_children($form[$key]) as $el) {
|
||||
if (!empty($form[$key][$el]['#dependency'])) {
|
||||
$form[$key][$el]['#dependency'] = array();
|
||||
}
|
||||
}
|
||||
|
||||
if ($origin == 'latlon_gmap' && module_exists('gmap')) {
|
||||
// Bad things happen if we try to show a gmap in the views live preview.
|
||||
if (!empty($form_state['view']->live_preview)) {
|
||||
$form[$key]['proximity_map'] = array(
|
||||
'#markup' => t('Gmap location selection is not available during live preview.'),
|
||||
'#weight' => 0,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$form[$key]['proximity_map'] = array(
|
||||
'#markup' => gmap_set_location($this->options['expose']['gmap_macro'], $form[$key], array('latitude' => 'latitude', 'longitude' => 'longitude')),
|
||||
'#weight' => 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
else if (($origin == 'user' || $origin == 'hybrid') && $this->options['expose']['user_location_choose']) {
|
||||
global $user;
|
||||
$user_locations = isset($user->locations) ? $user->locations : location_load_locations($user->uid, 'uid');
|
||||
$location_options = array();
|
||||
if (!empty($user_locations)) {
|
||||
foreach ($user_locations as $i => $location) {
|
||||
if (isset($location['latitude']) && isset($location['longitude'])) {
|
||||
if (!empty($location['name'])) {
|
||||
$location_options[$i] = t(check_plain($location['name']));
|
||||
}
|
||||
else {
|
||||
$location_options[$i] = t('Location #@num', array('@num' => $i + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$form[$key]['user_location_delta'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Location'),
|
||||
'#options' => $location_options,
|
||||
'#description' => t('Select which of your locations to use.'),
|
||||
'#weight' => 0,
|
||||
);
|
||||
}
|
||||
|
||||
// Remove unneeded fields when exposing the form.
|
||||
// It's shorter than redefining value_form.
|
||||
if ($origin != 'static' && $origin != 'latlon_gmap') {
|
||||
unset($form[$key]['latitude']);
|
||||
unset($form[$key]['longitude']);
|
||||
}
|
||||
if ($origin != 'postal' && $origin != 'postal_default') {
|
||||
unset($form[$key]['postal_code']);
|
||||
}
|
||||
if ($origin != 'postal') {
|
||||
unset($form[$key]['country']);
|
||||
}
|
||||
|
||||
// And we definitely do not want to expose the php code option when exposing the filter
|
||||
unset($form[$key]['php_code']);
|
||||
// The nid/uid arg options are not useful on an exposed form.
|
||||
unset($form[$key]['nid_arg']);
|
||||
unset($form[$key]['nid_loc_field']);
|
||||
unset($form[$key]['uid_arg']);
|
||||
|
||||
unset($form['origin']);
|
||||
}
|
||||
|
||||
function query() {
|
||||
if (empty($this->value)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// We need to merge with $this->options['value'] for filter values
|
||||
// and $this->value for exposed filter values.
|
||||
$options = array_merge($this->options, $this->options['value'], $this->value);
|
||||
$coordinates = location_views_proximity_get_reference_location($this->view, $options);
|
||||
|
||||
// If we don't have any coordinates or distance, there's nothing to filter
|
||||
// by, so don't modify the query at all.
|
||||
if (empty($coordinates) || empty($this->value['search_distance'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->ensure_my_table();
|
||||
|
||||
$lat = $coordinates['latitude'];
|
||||
$lon = $coordinates['longitude'];
|
||||
|
||||
$distance_meters = _location_convert_distance_to_meters($this->value['search_distance'], $this->value['search_units']);
|
||||
$latrange = earth_latitude_range($lon, $lat, $distance_meters);
|
||||
$lonrange = earth_longitude_range($lon, $lat, $distance_meters);
|
||||
|
||||
// Add MBR check (always).
|
||||
// In case we go past the 180/-180 mark for longitude.
|
||||
if ($lonrange[0] > $lonrange[1]) {
|
||||
$where = "$this->table_alias.latitude > :minlat AND $this->table_alias.latitude < :maxlat AND (($this->table_alias.longitude < 180 AND $this->table_alias.longitude > :minlon) OR ($this->table_alias.longitude < :maxlon AND $this->table_alias.longitude > -180))";
|
||||
}
|
||||
else {
|
||||
$where = "$this->table_alias.latitude > :minlat AND $this->table_alias.latitude < :maxlat AND $this->table_alias.longitude > :minlon AND $this->table_alias.longitude < :maxlon";
|
||||
}
|
||||
$this->query->add_where_expression($this->options['group'], $where, array(':minlat' => $latrange[0], ':maxlat' => $latrange[1], ':minlon' => $lonrange[0], ':maxlon' => $lonrange[1]));
|
||||
|
||||
if ($this->operator == 'dist') {
|
||||
// Add radius check.
|
||||
$this->query->add_where_expression($this->options['group'], earth_distance_sql($lon, $lat, $this->table_alias) .' < :distance', array(':distance' => $distance_meters));
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
<p> Location 3.0 and later provide a location_api_variant() function to aid in allowing add-on modules to support
|
||||
multiple releases, even if there are incompatible changes.</p>
|
||||
|
||||
<h3>API variant 1</h3>
|
||||
<p>Start of API tracking. Based on Location 3.0.</p>
|
||||
|
||||
<h3>API variant 2</h3>
|
||||
<p>location_diff() renamed to location_calc_difference() because diff.module was trying to invoke it as a hook.</p>
|
||||
<p>Before: Call location_diff().</p>
|
||||
<p>Now: Call location_calc_difference().</p>
|
264
sites/all/modules/contrib/fields/location/help/extending.html
Normal file
264
sites/all/modules/contrib/fields/location/help/extending.html
Normal file
@@ -0,0 +1,264 @@
|
||||
|
||||
<p><em>Note:</em> This file describes the original country API. While the API itself hasn't
|
||||
changed, some things have moved in directions not forseen by this documentation.
|
||||
For example, there is less emphasis today on postal data and more emphasis on
|
||||
geocoding webservices. Please take this documentation with a grain of salt until
|
||||
it is fully cleaned up and brought up to date.</p>
|
||||
|
||||
<h3>location.xx.inc: Adding support for an unsupported country</h3>
|
||||
<hr />
|
||||
|
||||
<p>This file is a PHP programmer's description of what needs to be done in order to extend the
|
||||
location system to support locationes from a new country.</p>
|
||||
|
||||
<p>Let's suppose we want to extend the location system to support locationes from Belgium. To this end,
|
||||
there are 2 tasks:</p>
|
||||
|
||||
TASK #1
|
||||
<p>We use the lower-case of the country's two-letter ISO 3166 code to create a file, "location.be.inc", that
|
||||
defines the necessary functions that will "hook" into the location system. This way, when a high-level
|
||||
function in the public location API receives a call that uses some Belgium specific function, the call
|
||||
will be delegated to the appropriately named function in "location.be.inc".</p>
|
||||
|
||||
TASK #2
|
||||
<p>You need postal code data for your country. This postal code data needs to be able to connect the
|
||||
base-length postal code (e.g., U.S. postal codes can be 9 digits, but we're only interested to the
|
||||
level of 5 digits and most people only know the 5-digit version) to a city, province/state, country (duh),
|
||||
and a latitude/longitude pair in degrees that represents the approximate center of the postal code's area.
|
||||
Ultimately, you will want to create a database dump that inserts these fields into specific columns:
|
||||
'zip' (for postal codes), 'city' (for city names), 'province' for (the standard state/province/country
|
||||
abbreviation), 'country' (for the lower-case of the country's two letter ISO code), 'latitude' (for the
|
||||
latitude in degree value, as opposed to radian value) and 'longitude' (for the degree value of the
|
||||
longitude).</p>
|
||||
|
||||
<p>In a lot of countries, this data costs money! You cannot simply create a dump and then publish it on
|
||||
drupal.org unless the data is free to redistribute. However, if you are interested in buying this data
|
||||
from some vendor and using it on your own site, you can do so but may have to acquire a new license for
|
||||
each seperate business or web site for which you wish to use postal code data if, in fact, you had to
|
||||
pay a fee or license for this data.</p>
|
||||
|
||||
<p>This postalcode-to-lat/lon mapping is important if you want to enable location-based proximity searches of
|
||||
anykind for addresses in a particular country. The module will still work fine without it, but will not
|
||||
be able to support searches based on postal codes.</p>
|
||||
|
||||
<h3>Contents of location.be.inc</h3>
|
||||
<hr />
|
||||
<p>This file will need to implement a handful of functions with the parameters and return values described below.</p>
|
||||
|
||||
<p>It is possible to not implement all of these functions since the caller usually checks to see if the function
|
||||
exists before calling it, but it may limit the number of features the location system will be able to support
|
||||
for your country.</p>
|
||||
|
||||
<p>For an example implementation of the functions described below, see "supported/location.us.inc".</p>
|
||||
|
||||
<pre>
|
||||
-------------------------------------------------------------------------------------------------
|
||||
function theme_location_be($location, $hide); |
|
||||
-------------------------------------------------------------------------------------------------
|
||||
@param $location
|
||||
An associative array $location where
|
||||
'street' => the street portion of the location
|
||||
'additional' => additional street portion of the location
|
||||
'city' => the city of the location
|
||||
'province' => the province, state, or territory
|
||||
'country' => lower-cased two-letter ISO code (REQUIRED)
|
||||
'postal_code' => the international postal code for this location (REQUIRED)
|
||||
@param $hide
|
||||
An linear array where the values are the location fields to suppress in the themed display.
|
||||
@return
|
||||
A string of the themed location. The entire location should be enclosed by <dl class="location"> </dl> tags.
|
||||
The different lines of the location should be enclosed by <dl> </dl> tags. The idea is to allow country-specific
|
||||
files to change the display of an location from the default theming done in theme_location() defined in location.inc
|
||||
</pre>
|
||||
|
||||
<pre>
|
||||
-------------------------------------------------------------------------------------------------
|
||||
function location_province_list_be(); |
|
||||
-------------------------------------------------------------------------------------------------
|
||||
Returns an associative array where
|
||||
-> the keys are the all-uppercase standard postal abbreviation for provinces, territories, and like subdivisions.
|
||||
-> the values are the fully spelled names of the abbreviated names.
|
||||
|
||||
Preferrably, these will be sorted by the full name.
|
||||
</pre>
|
||||
|
||||
<pre>
|
||||
-------------------------------------------------------------------------------------------------
|
||||
function location_map_link_be($location); |
|
||||
-------------------------------------------------------------------------------------------------
|
||||
Returns a deep-link to an online mapping service (e.g., "Yahoo! Maps", "MapQuest", or some other
|
||||
preferrably free service) given a full/partial location in the format described in public API
|
||||
document (location_API.txt).
|
||||
|
||||
@param $location
|
||||
An associative array $location where
|
||||
'street' => the street portion of the location
|
||||
'additional' => additional street portion of the location
|
||||
'city' => the city of the location
|
||||
'province' => the province, state, or territory
|
||||
'country' => lower-cased two-letter ISO code (REQUIRED)
|
||||
'postal_code' => the international postal code for this location (REQUIRED)
|
||||
|
||||
@return
|
||||
A URL with encoded HTTP GET variables to a free online-mapping service. (Note: URL, not HTML link).
|
||||
NULL if there is not even enough information to generate even a semi-useful link. "Useful" may depend
|
||||
entirely on the mapping service you choose to link to. You are advised to experiment: usually, a
|
||||
city/province combination is enough as is a postal code by itself, however, some services get confused
|
||||
when all fields are supplied. Some mapping services will be unable to map a city/province location
|
||||
while they can't do anything with a postal code while others map postal codes fine, but can't do
|
||||
anything useful with a city/province pair.
|
||||
</pre>
|
||||
|
||||
<pre>
|
||||
--------------------------------------------------------------------------------------------------
|
||||
function location_map_link_be_providers(); |
|
||||
--------------------------------------------------------------------------------------------------
|
||||
Returns an array of mapping services to which the generation of deep-links is supported. "Supported"
|
||||
means that the function for that particular mapping service has been defined. For example, if the
|
||||
location.be.inc file for Belgium has functions for taking a location and generating a deep-link to
|
||||
Yahoo! Maps and google, this function will return that list in an array that give additional info.
|
||||
|
||||
See location.us.inc for an example.
|
||||
|
||||
@return
|
||||
An associative array where
|
||||
--> The keys are single words (no spaces) that identify a function in the same file for returning
|
||||
a deep link. For example, 'yahoo' means location_map_link_be_yahoo(). 'google' means
|
||||
location_map_link_be_google().
|
||||
--> The values are themselves associative arrays with 3 expected keys:
|
||||
'name' => The name of the mapping service. In the case of Yahoo, it would be 'Yahoo! Maps'
|
||||
'url' => The full URL of the main page of the mapping service (i.e., the home page)
|
||||
'tos' => The full URL of the Terms Of Service for the mapping service.
|
||||
</pre>
|
||||
|
||||
<pre>
|
||||
--------------------------------------------------------------------------------------------------
|
||||
function location_map_link_be_default_providers(); |
|
||||
--------------------------------------------------------------------------------------------------
|
||||
Returns an array of 'default' mapping services. It may happen that the site administrator has not
|
||||
yet made it to the settings page for selecting mapping providers. In this case, we want to tell
|
||||
the location modules which one to use as defaults. To help the site admin avoid being in violation
|
||||
of each mapping services's Terms of Service, we return a linear array whose values are the appropriately
|
||||
selected keys in the array returned the location_map_link_xx_providers() function.
|
||||
|
||||
@return
|
||||
A linear array with the one-word, no-spaced identifiers used to identify the mapping function. These
|
||||
should only be for the mapping services with relatively lenient and permissive Terms of Service.
|
||||
|
||||
|
||||
IMPORTANT: For more information on how to add support for deep-links, you are encouraged to see
|
||||
the examples in modules/location/supported/location.us.inc. If you need extra help, please feel
|
||||
free to submit a question on the issues queue for this project at: http://drupal.org/project/issues/location
|
||||
Replies will be prompt.
|
||||
</pre>
|
||||
|
||||
<pre>
|
||||
--------------------------------------------------------------------------------------------------
|
||||
function location_driving_directions_link_be($locationA, $locationB); |
|
||||
--------------------------------------------------------------------------------------------------
|
||||
Returns a deep-link to an online mapping service (e.g., "Yahoo! Maps", "MapQuest", or some other
|
||||
preferrably free service) given full/partial locationes. Depending on whether or not the parameter
|
||||
locationes are complete enough for the chosen service, this function will return either a deep-link
|
||||
directly to the driving direction or will provide a deep-link to a partially pre-filled form for
|
||||
driving directions on the site you choose to link to.
|
||||
|
||||
@param $locationA
|
||||
An associative array $location where
|
||||
'street' => the street portion of the location
|
||||
'additional' => additional street portion of the location
|
||||
'city' => the city of the location
|
||||
'province' => the province, state, or territory
|
||||
'country' => lower-cased two-letter ISO code (REQUIRED)
|
||||
'postal_code' => the international postal code for this location (REQUIRED)
|
||||
|
||||
@param $locationB
|
||||
An associative array $location where
|
||||
'street' => the street portion of the location
|
||||
'additional' => additional street portion of the location
|
||||
'city' => the city of the location
|
||||
'province' => the province, state, or territory
|
||||
'country' => lower-cased two-letter ISO code (REQUIRED)
|
||||
'postal_code' => the international postal code for this location (REQUIRED)
|
||||
|
||||
@return
|
||||
A URL (not HTML link) with HTTP GET variables tacked on to the end. This URL either points to a
|
||||
form for driving directions from $locationA to $locationB or a deep-link directly to the driving
|
||||
directions depending on how complete the locationes are.
|
||||
</pre>
|
||||
|
||||
<pre>
|
||||
--------------------------------------------------------------------------------------------------
|
||||
function location_get_postalcode_data_be($location = array()); |
|
||||
--------------------------------------------------------------------------------------------------
|
||||
@param $location
|
||||
An associative array $location where
|
||||
'street' => the street portion of the location
|
||||
'additional' => additional street portion of the location
|
||||
'city' => the city of the location
|
||||
'province' => the province, state, or territory
|
||||
'country' => lower-cased two-letter ISO code (REQUIRED)
|
||||
'postal_code' => the international postal code for this location (REQUIRED)
|
||||
|
||||
@return
|
||||
An associative array where
|
||||
'lat' => A floating point for the latitude of the approximate center of the postal_code in the given $location
|
||||
'lon' => A floating point for the longitude of the approximate center of the postal code in the given $location
|
||||
'city' => The most appropriate city name for the given postal code in $location
|
||||
'province' => The most appropriate province name for the given postal code in $location
|
||||
Returns NULL if the postal code doesn't make sense.
|
||||
|
||||
Typically, this function will pull out the latitude/longitude of the approximate center of postal code
|
||||
in the given $location parameter as well as other data. The reason this can't be implemented at the
|
||||
non-country specific level in location.inc is that postal codes may be submitted in varying formats
|
||||
of varying precision while postal codes for this country in the database table may all be in a particular
|
||||
format. It is up to this country specific function to examine $location['postal_code'] and format it
|
||||
appropriately so that it matches with a postal code in the postal codes table. This 'hook' is meant
|
||||
to be a replacement for the location_get_latlon_rough_xx hook, described next.
|
||||
</pre>
|
||||
|
||||
<pre>
|
||||
--------------------------------------------------------------------------------------------------
|
||||
function location_latlon_rough_be($location = array()); |
|
||||
--------------------------------------------------------------------------------------------------
|
||||
@param $location
|
||||
An associative array $location where
|
||||
'street' => the street portion of the location
|
||||
'additional' => additional street portion of the location
|
||||
'city' => the city of the location
|
||||
'province' => the province, state, or territory
|
||||
'country' => lower-cased two-letter ISO code (REQUIRED)
|
||||
'postal_code' => the international postal code for this location (REQUIRED)
|
||||
|
||||
@return
|
||||
An associative array where
|
||||
'lat' => A floating point for the latitude of the approximate center of the postal_code in the given $location
|
||||
'lon' => A floating point for the longitude of the approximate center of the postal code in the given $location
|
||||
Returns NULL if the postal code doesn't make sense.
|
||||
|
||||
Typically, this function will pull out the latitude/longitude of the approximate center of postal code
|
||||
in the given $location parameter.
|
||||
</pre>
|
||||
|
||||
<pre>
|
||||
--------------------------------------------------------------------------------------------------
|
||||
function location_latlon_exact_be($location = array()); |
|
||||
--------------------------------------------------------------------------------------------------
|
||||
@param $location
|
||||
An associative array $location where
|
||||
'street' => the street portion of the location
|
||||
'additional' => additional street portion of the location
|
||||
'city' => the city of the location
|
||||
'province' => the province, state, or territory
|
||||
'country' => lower-cased two-letter ISO code (REQUIRED)
|
||||
'postal_code' => the international postal code for this location (REQUIRED)
|
||||
|
||||
@return
|
||||
An associative array where
|
||||
'lat' => A floating point for the latitude of the approximate center of the postal_code in the given $location
|
||||
'lon' => A floating point for the longitude of the approximate center of the postal code in the given $location
|
||||
Returns NULL if the postal code doesn't make sense.
|
||||
|
||||
Typically, this function will be implemented on top of a web-service for retrieving exact lat/lon information
|
||||
for a full location. This function is not a necessity, but a sample implementation would be helpful for
|
||||
future users. If not, it can always be added on a supply and demand basis.
|
||||
</pre>
|
@@ -0,0 +1,12 @@
|
||||
|
||||
[testing]
|
||||
title = "Testing Procedure"
|
||||
file = test_procedure
|
||||
|
||||
[extending]
|
||||
title = "Country API"
|
||||
file = extending
|
||||
|
||||
[api_changelog]
|
||||
title = "API variant reference (changelog)"
|
||||
file = api_changelog
|
@@ -0,0 +1,62 @@
|
||||
<h3>GMap 1.x / Location 3.x Tester Checklist</h3>
|
||||
<hr />
|
||||
|
||||
Setup from scratch:
|
||||
|
||||
<ul>
|
||||
<li>Enable modules</li>
|
||||
<li>Visit <a href="base_url:admin/settings/gmap">admin/settings/gmap</a> and configure API key.</li>
|
||||
<li>Visit <a href="base_url:admin/settings/filters">admin/settings/filters</a> and set up a GMap filter.</li>
|
||||
<li>Visit <a href="base_url:admin/content/types">admin/content/types</a> and (create if desired and) location-enable a content type.</li>
|
||||
<li>Visit <a href="base_url:admin/settings/location/geocoding">admin/settings/location/geocoding</a> and configure geocoding for a country.</li>
|
||||
<li>Visit <a href="base_url:admin/user/settings">admin/user/settings</a> and configure the Location Fields section.</li>
|
||||
<li>Visit <a href="base_url:admin/build/block">admin/build/block</a> and enable the Author Map and Location Map blocks.</li>
|
||||
<li>Visit <a href="base_url:admin/build/block/configure/gmap_location/1">admin/build/block/configure/gmap_location/1</a> and enable the Author block for the content type you location-enabled.</li>
|
||||
</ul>
|
||||
|
||||
Tests 1 (GMap macros):
|
||||
|
||||
<ul>
|
||||
<li>Visit <a href="base_url:map/macro">map/macro</a>, play with the controls and ensure map responds, play with map and ensure controls respond.</li>
|
||||
<li>Doodle on the map, make sure drawing controls work as expected.</li>
|
||||
<li>Copy macro, open another window/tab.</li>
|
||||
<li>Create a node, set filter to GMap filter and paste macro.</li>
|
||||
<li>Save node, compare display of map to macro in other window/tab.</li>
|
||||
</ul>
|
||||
|
||||
Tests 2 (Location user):
|
||||
|
||||
<ul>
|
||||
<li>Edit your user account. Add your location.</li>
|
||||
<li>Ensure geocoding works.</li>
|
||||
<li>Ensure the data is not lost when going back to edit.</li>
|
||||
</ul>
|
||||
|
||||
Tests 3 (Location nodes):
|
||||
|
||||
<ul>
|
||||
<li>Create a node with locative information.</li>
|
||||
<li>Ensure Author Map and Location Map display as expected.</li>
|
||||
</ul>
|
||||
|
||||
<h3>Advanced section - Stuff involving special setup or advanced knowledge</h3>
|
||||
<hr />
|
||||
|
||||
ADVANCED: Upgrade path:
|
||||
|
||||
<ul>
|
||||
<li>Create test site on Location 2.7.</li>
|
||||
<li>Perform tasks from "Setup from scratch" section.</li>
|
||||
<li>Create or import test data.</li>
|
||||
<li>Install Location 3.</li>
|
||||
<li>Attempt to perform updates.</li>
|
||||
<li>Ensure in database that data was properly split off into {location_instance}.</li>
|
||||
<li>Ensure site settings are in a sane state (You should not get any misconfiguration-related warnings/errors.)</li>
|
||||
<li>Visually inspect some locations on site.</li>
|
||||
</ul>
|
||||
|
||||
ADVANCED: Nonstandard usage:
|
||||
|
||||
<ul>
|
||||
<li>Disable gmap and create locative nodes. Ensure form continues to work in the absence of gmap.</li>
|
||||
</ul>
|
388
sites/all/modules/contrib/fields/location/location.admin.inc
Normal file
388
sites/all/modules/contrib/fields/location/location.admin.inc
Normal file
@@ -0,0 +1,388 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Admin forms for Location.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Admin settings form.
|
||||
*
|
||||
* @ingroup form
|
||||
*/
|
||||
function location_admin_settings($form, &$form_state) {
|
||||
// Recalculate the supported countries.
|
||||
cache_clear_all('location:supported-countries', 'cache');
|
||||
_location_supported_countries();
|
||||
|
||||
$iso_list_sorted = location_get_iso3166_list();
|
||||
array_multisort($iso_list_sorted);
|
||||
$iso_list_sorted = array_merge(array('' => ''), $iso_list_sorted);
|
||||
|
||||
$form = array();
|
||||
$form['location_default_country'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Default country selection'),
|
||||
'#default_value' => variable_get('location_default_country', 'us'),
|
||||
'#options' => $iso_list_sorted,
|
||||
'#description' => t('This will be the country that is automatically selected when a location form is served for a new location.')
|
||||
);
|
||||
$form['location_display_location'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Toggle location display'),
|
||||
'#default_value' => variable_get('location_display_location', 1),
|
||||
'#options' => array(
|
||||
0 => t('Disable the display of locations.'),
|
||||
1 => t('Enable the display of locations.')
|
||||
),
|
||||
'#description' => t('If you are interested in turning off locations and having a custom theme control their display, you may want to disable the display of locations so your theme can take that function.')
|
||||
);
|
||||
|
||||
$form['location_use_province_abbreviation'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Province display'),
|
||||
'#default_value' => variable_get('location_use_province_abbreviation', 1),
|
||||
'#options' => array(
|
||||
0 => t('Display full province name.'),
|
||||
1 => t('Display province/state code.'),
|
||||
),
|
||||
);
|
||||
|
||||
$form['location_usegmap'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Use a Google Map to set latitude and longitude '),
|
||||
'#default_value' => variable_get('location_usegmap', FALSE),
|
||||
'#description' => t('If the gmap.module is installed and <a href="@enabled">enabled</a>, and this setting is also turned on, users that are allowed to manually enter latitude/longitude coordinates will be able to do so with an interactive Google Map. You should also make sure you have entered a <a href="@google_maps_api_key">Google Maps API key</a> into your <a href="@gmap_module_settings">gmap module settings</a>.', array('@enabled' => url('admin/build/modules'), '@google_maps_api_key' => 'http://www.google.com/apis/maps', '@gmap_module_settings' => url('admin/config/content/gmap'))),
|
||||
// @@@ megapatch This is an idea, but I'd opt more for a warning here...
|
||||
// '#disabled' => !module_exists('gmap'),
|
||||
);
|
||||
|
||||
$form['location_locpick_macro'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Location chooser macro'),
|
||||
'#size' => 50,
|
||||
'#maxlength' => 500,
|
||||
'#default_value' => variable_get('location_locpick_macro', '[gmap]'),
|
||||
'#description' => t('If you would like to change the macro used to generate the location chooser map, you can do so here. Note: Behaviors <em>locpick</em> and <em>collapsehack</em> are forced to be enabled and cannot be changed.'),
|
||||
);
|
||||
|
||||
$form['location_jit_geocoding'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Enable JIT geocoding'),
|
||||
'#default_value' => variable_get('location_jit_geocoding', FALSE),
|
||||
'#description' => t('If you are going to be importing locations in bulk directly into the database, you may wish to enable JIT geocoding and load the locations with source set to 4 (LOCATION_LATLON_JIT_GEOCODING). The system will automatically geocode locations as they are loaded.'),
|
||||
);
|
||||
|
||||
$form['maplink_external'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Map link'),
|
||||
);
|
||||
$form['maplink_external']['location_maplink_external'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Open map link in new window'),
|
||||
'#default_value' => variable_get('location_maplink_external', 0),
|
||||
'#description' => t('Select this if you want the map link to open in a separate window'),
|
||||
);
|
||||
$form['maplink_external']['location_maplink_external_method'] = array(
|
||||
'#type' => 'radios',
|
||||
'#title' => t('Open in new window method'),
|
||||
'#options' => array(
|
||||
'target="_blank"' => 'target="_blank"',
|
||||
'rel="external"' => 'rel="external"',
|
||||
),
|
||||
'#default_value' => variable_get('location_maplink_external_method', 'target="_blank"'),
|
||||
'#description' => t('If you have selected to open map in a new window this controls the method used to open in a new window. target="_blank" will just work but is not XTHML Strict compliant. rel="external" is XHTML Strict compliant but will not open in a new window unless you add some jQuery to your site to add the target attribute. If you are unsure leave set to target="_blank"'),
|
||||
);
|
||||
|
||||
return system_settings_form($form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings page for map links.
|
||||
*/
|
||||
function location_map_link_options_form($form, &$form_state) {
|
||||
$form = array();
|
||||
|
||||
$form['countries'] = array(
|
||||
'#type' => 'markup',
|
||||
'#markup' => ''
|
||||
);
|
||||
|
||||
foreach (_location_supported_countries() as $country_iso => $country_name) {
|
||||
location_load_country($country_iso);
|
||||
|
||||
$form['countries'][$country_iso] = array(
|
||||
'#type' => 'markup',
|
||||
'#markup' => ''
|
||||
);
|
||||
|
||||
$form['countries'][$country_iso]['label_'. $country_iso] = array(
|
||||
'#type' => 'markup',
|
||||
'#markup' => $country_name
|
||||
);
|
||||
|
||||
// Set up '#options' array for mapping providers for the current country
|
||||
$mapping_options = array();
|
||||
$provider_function = 'location_map_link_'. $country_iso .'_providers';
|
||||
$default_provider_function = 'location_map_link_'. $country_iso .'_default_providers';
|
||||
$checked = variable_get('location_map_link_'. $country_iso, function_exists($default_provider_function) ? $default_provider_function() : array());
|
||||
//print "Calling provider function $provider_function";
|
||||
if (function_exists($provider_function)) {
|
||||
foreach ($provider_function() as $name => $details) {
|
||||
$mapping_options[$name] = '<a href="'. $details['url'] .'">'. $details['name'] .'</a> (<a href="'. $details['tos'] .'">Terms of Use</a>)';
|
||||
}
|
||||
}
|
||||
|
||||
if (count($mapping_options)) {
|
||||
$form['countries'][$country_iso]['location_map_link_'. $country_iso] = array(
|
||||
'#title' => '',
|
||||
'#type' => 'checkboxes',
|
||||
'#default_value' => $checked,
|
||||
'#options' => $mapping_options
|
||||
);
|
||||
}
|
||||
else {
|
||||
$form['countries'][$country_iso]['location_map_link_'. $country_iso] = array(
|
||||
'#type' => 'markup',
|
||||
'#markup' => t('None supported.')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$form = system_settings_form($form);
|
||||
$form['#theme'] = 'location_map_link_options';
|
||||
return $form;
|
||||
}
|
||||
|
||||
function location_geocoding_options_form($form, &$form_state) {
|
||||
$form = array();
|
||||
|
||||
$form['location_geocode_google_minimum_accuracy'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Google Maps geocoding minimum accuracy'),
|
||||
'#options' => location_google_geocode_accuracy_codes(),
|
||||
'#default_value' => variable_get('location_geocode_google_minimum_accuracy', '3'),
|
||||
'#description' => t('The Google Maps geocoding API returns results with a given accuracy. Any responses below this minimum accuracy will be ignored. See a !accuracy_values_link.', array('!accuracy_values_link' => '<a href="http://code.google.com/apis/maps/documentation/reference.html#GGeoAddressAccuracy">description of these values</a>'))
|
||||
);
|
||||
$form['countries'] = array();
|
||||
|
||||
// First, we build two arrays to help us figure out on the fly whether a specific country is covered by a multi-country geocoder,
|
||||
// and what the details of the multi-country geocoder are
|
||||
// (1) Get list of geocoders
|
||||
$general_geocoders_list = location_get_general_geocoder_list();
|
||||
|
||||
// (2) get data about each geocoder and the list of coutnries covered by each geocoder
|
||||
$general_geocoders_data = array();
|
||||
$general_geocoders_countries = array();
|
||||
foreach ($general_geocoders_list as $geocoder_name) {
|
||||
location_load_geocoder($geocoder_name);
|
||||
$info_function = $geocoder_name .'_geocode_info';
|
||||
if (function_exists($info_function)) {
|
||||
$general_geocoders_data[$geocoder_name] = $info_function();
|
||||
}
|
||||
|
||||
$countries_function = $geocoder_name .'_geocode_country_list';
|
||||
if (function_exists($countries_function)) {
|
||||
$general_geocoders_countries[$geocoder_name] = $countries_function();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (_location_supported_countries() as $country_iso => $country_name) {
|
||||
location_load_country($country_iso);
|
||||
|
||||
$geocoding_options = array();
|
||||
|
||||
$form['countries'][$country_iso] = array(
|
||||
'#type' => 'markup',
|
||||
'#markup' => ''
|
||||
);
|
||||
|
||||
$form['countries'][$country_iso]['label_'. $country_iso] = array(
|
||||
'#type' => 'markup',
|
||||
'#markup' => '<div id="'. $country_iso .'">'. $country_name .'</div>'
|
||||
);
|
||||
|
||||
// Next, we look for options presented by country specific providers
|
||||
$country_specific_provider_function = 'location_geocode_'. $country_iso .'_providers';
|
||||
if (function_exists($country_specific_provider_function)) {
|
||||
foreach ($country_specific_provider_function() as $name => $details) {
|
||||
$geocoding_options[$name .'|'. $country_iso] = '<a href="'. $details['url'] .'">'. $details['name'] .'</a> (<a href="'. $details['tos'] .'">Terms of Use</a>)';
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($general_geocoders_list as $geocoder_name) {
|
||||
if (in_array($country_iso, $general_geocoders_countries[$geocoder_name])) {
|
||||
$geocoding_options[$geocoder_name] = '<a href="'. $general_geocoders_data[$geocoder_name]['url'] .'">'. $general_geocoders_data[$geocoder_name]['name'] .'</a> (<a href="'. $general_geocoders_data[$geocoder_name]['tos'] .'">Terms of Use</a>)';
|
||||
}
|
||||
}
|
||||
|
||||
if (count($geocoding_options)) {
|
||||
$geocoding_options = array_merge(array('none' => t('None')), $geocoding_options);
|
||||
|
||||
$form['countries'][$country_iso]['location_geocode_'. $country_iso] = array(
|
||||
'#type' => 'radios',
|
||||
'#default_value' => variable_get('location_geocode_'. $country_iso, 'none'),
|
||||
'#options' => $geocoding_options
|
||||
);
|
||||
}
|
||||
else {
|
||||
$form['countries'][$country_iso]['location_geocode_'. $country_iso] = array(
|
||||
'#type' => 'markup',
|
||||
'#markup' => t('None supported.')
|
||||
);
|
||||
}
|
||||
|
||||
$current_value = variable_get('location_geocode_'. $country_iso, 'none');
|
||||
if ($current_value == 'none') {
|
||||
$form['countries'][$country_iso]['location_geocode_config_link_'. $country_iso] = array(
|
||||
'#type' => 'markup',
|
||||
'#markup' => t('No service selected for country.')
|
||||
);
|
||||
}
|
||||
else {
|
||||
$current_val_chopped = substr($current_value, 0, strpos($current_value, '|'));
|
||||
$geocode_settings_form_function_specific = 'location_geocode_'. $country_iso .'_'. $current_val_chopped .'_settings';
|
||||
$geocode_settings_form_function_general = $current_value .'_geocode_settings';
|
||||
|
||||
if (function_exists($geocode_settings_form_function_specific)) {
|
||||
$form['countries'][$country_iso]['location_geocode_config_link_'. $country_iso] = array(
|
||||
'#type' => 'link',
|
||||
'#title' => t('Configure parameters'),
|
||||
'#href' => 'admin/config/content/location/geocoding/' . $country_iso . '/' . $current_val_chopped,
|
||||
);
|
||||
}
|
||||
elseif (function_exists($geocode_settings_form_function_general)) {
|
||||
$form['countries'][$country_iso]['location_geocode_config_link_'. $country_iso] = array(
|
||||
'#type' => 'link',
|
||||
'#title' => t('Configure parameters'),
|
||||
'#href' => 'admin/config/content/location/geocoding/' . $country_iso . '/' . $current_value,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$form['countries'][$country_iso]['location_geocode_config_link_'. $country_iso] = array(
|
||||
'#type' => 'markup',
|
||||
'#markup' => t('No configuration necessary for selected service.')
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
$form = system_settings_form($form);
|
||||
$form['#theme'] = 'location_geocoding_options';
|
||||
array_unshift($form['#submit'], 'location_geocoding_options_form_submit');
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
function location_geocoding_options_form_submit($form, &$form_state) {
|
||||
$general_geocoders = location_get_general_geocoder_list();
|
||||
$general_geocoders_in_use = array();
|
||||
|
||||
foreach ($form_state['values'] as $key => $value) {
|
||||
if (substr($key, 0, 17) == 'location_geocode_' && $key != 'location_geocode_google_minimum_accuracy') {
|
||||
if (in_array($value, $general_geocoders)) {
|
||||
$general_geocoders_in_use[$value] = $value;
|
||||
variable_set($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
variable_set('location_geocode_google_minimum_accuracy', $form_state['values']['location_geocode_google_minimum_accuracy']);
|
||||
variable_set('location_general_geocoders_in_use', $general_geocoders_in_use);
|
||||
}
|
||||
|
||||
|
||||
function theme_location_map_link_options($variables) {
|
||||
$form = $variables['form'];
|
||||
|
||||
$header = array(array('align' => 'center', 'data' => '<center>'. t('Country') .'</center>'), array('align' => 'center', 'data' => '<center>'. t('Options') .'</center>'));
|
||||
$rows = array();
|
||||
foreach (element_children($form['countries']) as $country_iso) {
|
||||
$row = array();
|
||||
$row[] = array(
|
||||
'data' => drupal_render($form['countries'][$country_iso]['label_'. $country_iso])
|
||||
);
|
||||
$row[] = array(
|
||||
'data' => drupal_render($form['countries'][$country_iso]['location_map_link_'. $country_iso])
|
||||
);
|
||||
$rows[] = $row;
|
||||
}
|
||||
$output = theme('table', array('header' => $header, 'rows' => $rows));
|
||||
$output .= drupal_render_children($form);
|
||||
return $output;
|
||||
}
|
||||
|
||||
function theme_location_geocoding_options($variables) {
|
||||
$form = $variables['form'];
|
||||
|
||||
$output = drupal_render($form['location_geocode_google_minimum_accuracy']);
|
||||
$header = array(
|
||||
array('align' => 'center', 'data' => '<center>'. t('Country') .'</center>'),
|
||||
array('align' => 'center', 'data' => '<center>'. t('Options') .'</center>'),
|
||||
array('align' => 'center', 'data' => '<center>'. t('Configure') .'</center>')
|
||||
);
|
||||
$rows = array();
|
||||
foreach (element_children($form['countries']) as $country_iso) {
|
||||
$row = array();
|
||||
$row[] = array(
|
||||
'data' => drupal_render($form['countries'][$country_iso]['label_'. $country_iso])
|
||||
);
|
||||
$row[] = array(
|
||||
'data' => drupal_render($form['countries'][$country_iso]['location_geocode_'. $country_iso])
|
||||
);
|
||||
$row[] = array(
|
||||
'data' => drupal_render($form['countries'][$country_iso]['location_geocode_config_link_'. $country_iso])
|
||||
);
|
||||
$rows[] = $row;
|
||||
}
|
||||
$output .= theme('table', array('header' => $header, 'rows' => $rows));
|
||||
$output .= drupal_render_children($form);
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Location Utilities form.
|
||||
*/
|
||||
function location_util_form($form, &$form_State) {
|
||||
$form['province_clear'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Clear province cache'),
|
||||
'#description' => t('If you have modified location.xx.inc files, you will need to clear the province cache to get Location to recognize the modifications.'),
|
||||
);
|
||||
|
||||
$form['supported_countries_clear'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('Clear supported country list'),
|
||||
'#description' => t('If you have added support for a new country, you will need to clear the supported country list to get Location to recognize the modifications.'),
|
||||
);
|
||||
|
||||
$form['actions'] = array(
|
||||
'#type' => 'actions',
|
||||
);
|
||||
$form['actions']['province_clear_submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Clear province cache'),
|
||||
'#submit' => array('location_util_form_clear_province_cache_submit'),
|
||||
);
|
||||
$form['actions']['supported_countries_clear_submit'] = array(
|
||||
'#type' => 'submit',
|
||||
'#value' => t('Clear supported country list'),
|
||||
'#submit' => array('location_util_form_clear_supported_countries_submit'),
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Location utilities form: Clear province cache.
|
||||
*/
|
||||
function location_util_form_clear_province_cache_submit() {
|
||||
drupal_set_message(t('Location province cache cleared.'));
|
||||
cache_clear_all('provinces:', 'cache_location', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Location utilities form: Clear supported countries cache.
|
||||
*/
|
||||
function location_util_form_clear_supported_countries_submit() {
|
||||
drupal_set_message(t('Location supported country list cleared.'));
|
||||
cache_clear_all('location:supported-countries', 'cache_location');
|
||||
}
|
137
sites/all/modules/contrib/fields/location/location.css
Normal file
137
sites/all/modules/contrib/fields/location/location.css
Normal file
@@ -0,0 +1,137 @@
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Location CSS rules.
|
||||
*/
|
||||
|
||||
table.location-search-form {
|
||||
margin:0;
|
||||
border:0;
|
||||
padding:0;
|
||||
}
|
||||
|
||||
table.location-search-form-table tbody {
|
||||
margin:0;
|
||||
border:0;
|
||||
padding:0;
|
||||
}
|
||||
|
||||
table.location-search-form-table tbody tr {
|
||||
border:0;
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
|
||||
table.location-search-form-table tbody tr td {
|
||||
border:0;
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
|
||||
table.location-search-form-table tbody tr td table {
|
||||
border:0;
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
|
||||
table.location-search-form-table tbody tr td table tbody {
|
||||
border:0;
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
|
||||
table.location-search-form-table tbody tr td table tbody tr {
|
||||
border:0;
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
|
||||
table.location-search-form-table tbody tr td table tbody tr td {
|
||||
border:0;
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
|
||||
table.location-search-form-table tbody tr td table tbody tr td table {
|
||||
border:0;
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
|
||||
table.location-search-form-table tbody tr td table tbody tr td table tbody {
|
||||
border:0;
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
|
||||
table.location-search-form-table tbody tr td table tbody tr td table tbody tr {
|
||||
border:0;
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
|
||||
table.location-search-form-table tbody tr td table tbody tr td table tbody tr td {
|
||||
border:0;
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
|
||||
/*
|
||||
.location .container-inline {
|
||||
clear: left;
|
||||
}
|
||||
.location .container-inline label {
|
||||
display: block;
|
||||
float: left;
|
||||
width: 120px;
|
||||
}
|
||||
.location .form-item .description {
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.location .container-inline { clear: left; }
|
||||
.location .container-inline label { display: block; float: left; width: 120px; }
|
||||
*/
|
||||
|
||||
.location-current-coordinates-fieldset {
|
||||
width: 35em;
|
||||
}
|
||||
|
||||
.location .form-item input {
|
||||
display: block;
|
||||
width: 25em;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.location .form-item label {
|
||||
display: block;
|
||||
float: left;
|
||||
text-align: left;
|
||||
width: 10em;
|
||||
padding-right: 10px;
|
||||
}
|
||||
|
||||
.location .form-item {
|
||||
clear:both;
|
||||
}
|
||||
|
||||
/* "Delete" checkbox. */
|
||||
.location .form-item label.option {
|
||||
display: inline;
|
||||
float: none;
|
||||
text-align: inherit;
|
||||
width: auto;
|
||||
padding-right: 0;
|
||||
}
|
||||
|
||||
/* "Delete" checkbox. */
|
||||
.location .form-item input.form-checkbox {
|
||||
display: inline;
|
||||
float: none;
|
||||
width: auto;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.location .description {
|
||||
white-space: normal;
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* GeoRSS support for Location.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @function
|
||||
* Return an array of RSS items for a location.
|
||||
*/
|
||||
function _location_rss_item($location, $mode = 'simple') {
|
||||
$ret = FALSE;
|
||||
if (location_has_coordinates($location, TRUE)) {
|
||||
switch ($mode) {
|
||||
// W3C Basic Geo Vocabulary
|
||||
case 'w3c':
|
||||
$ret = array(
|
||||
'key' => 'geo:Point',
|
||||
'namespace' => array('xmlns:geo' => 'http://www.w3.org/2003/01/geo/wgs84_pos#'),
|
||||
'value' => array(
|
||||
array('key' => 'geo:lat', 'value' => $location['latitude']),
|
||||
array('key' => 'geo:long', 'value' => $location['longitude']),
|
||||
),
|
||||
);
|
||||
break;
|
||||
// Location 1.x-2.x bug compatible.
|
||||
// W3C Basic Geo Vocabulary with a misspelled longitude tag.
|
||||
case 'w3c_bugcompat':
|
||||
$ret = array(
|
||||
'key' => 'geo:Point',
|
||||
'namespace' => array('xmlns:geo' => 'http://www.w3.org/2003/01/geo/wgs84_pos#'),
|
||||
'value' => array(
|
||||
array('key' => 'geo:lat', 'value' => $location['latitude']),
|
||||
array('key' => 'geo:lon', 'value' => $location['longitude']),
|
||||
),
|
||||
);
|
||||
break;
|
||||
// GeoRSS-Simple
|
||||
case 'simple':
|
||||
$ret = array(
|
||||
'key' => 'georss:point',
|
||||
'namespace' => array('xmlns:georss' => 'http://www.georss.org/georss'),
|
||||
'value' => "$location[latitude] $location[longitude]",
|
||||
);
|
||||
break;
|
||||
//
|
||||
case 'gml':
|
||||
$ret = array(
|
||||
'key' => 'georss:where',
|
||||
'namespace' => array(
|
||||
'xmlns:georss' => 'http://www.georss.org/georss',
|
||||
'xmlns:gml' => 'http://www.opengis.net/gml',
|
||||
),
|
||||
'value' => array(
|
||||
'gml:Point' => array(
|
||||
'gml:pos' => "$location[latitude] $location[longitude]",
|
||||
),
|
||||
),
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $ret;
|
||||
}
|
679
sites/all/modules/contrib/fields/location/location.inc
Normal file
679
sites/all/modules/contrib/fields/location/location.inc
Normal file
@@ -0,0 +1,679 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @defgroup Location Location: An API for working with locations.
|
||||
*
|
||||
* Public API for the Location module.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @file
|
||||
* An implementation of a universal API for location manipulation. Provides functions for
|
||||
* postal_code proximity searching, deep-linking into online mapping services. Currently,
|
||||
* some options are configured through an interface provided by location.module.
|
||||
*/
|
||||
|
||||
include_once(DRUPAL_ROOT . '/' . drupal_get_path('module', 'location') . '/earth.inc');
|
||||
|
||||
/**
|
||||
* Get a deep-link to a mapping service such as Yahoo! Maps or MapPoint given an location. The
|
||||
* call is delegated based on the 'country' value in the $location parameter.
|
||||
*
|
||||
* @param $location
|
||||
* An associative array where
|
||||
* 'street' => A string representing the street location
|
||||
* 'additional' => A string for any additional portion of the street location
|
||||
* 'city' => A string for the city name
|
||||
* 'province' => The standard postal abbreviation for the province
|
||||
* 'country' => The two-letter ISO code for the country of the location (REQUIRED)
|
||||
* 'postal_code' => The international postal code for the location
|
||||
*
|
||||
* @return
|
||||
* A link to a map provided by a third-party. The idea is to encode the appropriate
|
||||
* parameters as HTTP GET variables to the URL.
|
||||
*
|
||||
* @ingroup Location
|
||||
*/
|
||||
function location_map_link($location = array(), $link_text = 'See map: ') {
|
||||
if (!isset($location['country']) || $location['country'] == 'xx') {
|
||||
return '';
|
||||
}
|
||||
|
||||
location_load_country($location['country']);
|
||||
|
||||
$default_func = 'location_map_link_'. $location['country'] .'_default_providers';
|
||||
$providers_func = 'location_map_link_'. $location['country'] .'_providers';
|
||||
$providers = function_exists($providers_func) ? $providers_func() : array();
|
||||
$selected_providers = variable_get('location_map_link_'. $location['country'], function_exists($default_func) ? $default_func() : array());
|
||||
|
||||
$links = array();
|
||||
foreach ($selected_providers as $mapper) {
|
||||
$link_func = 'location_map_link_'. $location['country'] .'_'. $mapper;
|
||||
if (function_exists($link_func)) {
|
||||
if ($link = $link_func($location)) {
|
||||
$links[] = '<a href="'. $link .'"'. (variable_get('location_maplink_external', 0) ? ' '. variable_get('location_maplink_external_method', 'target="_blank"') : '') .'>'. $providers[$mapper]['name'] .'</a>';
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($links)) {
|
||||
return '<div class="location map-link">'. t($link_text) . implode($links, ", ") .'</div>';
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to extract the the Latitude and Longitude data from the
|
||||
* postal code.
|
||||
*
|
||||
* @param $location
|
||||
* Array. the location data
|
||||
* -> the values are:
|
||||
* 'street' => the string representing the street location (REQUIRED)
|
||||
* 'additional' => the string representing the additional street location portion in the location form
|
||||
* 'city' => the city name (REQUIRED)
|
||||
* 'province' => the province code defined in the country-specific include file
|
||||
* 'country' => the lower-case of the two-letter ISO code (REQUIRED)
|
||||
* 'postal_code' => the postal-code (REQUIRED)
|
||||
*
|
||||
* @return
|
||||
* Array or NULL. NULL if the delegated-to function that does the
|
||||
* actual look-up does not exist. If the appropriate function exists,
|
||||
* then this function returns an associative array where
|
||||
* 'lon' => A floating point number for the longitude coordinate of the parameter location
|
||||
* 'lat' => A floating point number for the latitude coordinate of the parameter location
|
||||
*
|
||||
* @ingroup Location
|
||||
*/
|
||||
function location_get_postalcode_data($location = array()) {
|
||||
$location['country'] = isset($location['country']) ? trim($location['country']) : NULL;
|
||||
$location['postal_code'] = isset($location['postal_code']) ? trim($location['postal_code']) : NULL;
|
||||
if (is_null($location['postal_code']) || is_null($location['country']) || empty($location['country']) || empty($location['postal_code']) || $location['postal_code'] == 'xx') {
|
||||
return NULL;
|
||||
}
|
||||
location_load_country($location['country']);
|
||||
$country_specific_function = 'location_get_postalcode_data_'. $location['country'];
|
||||
if (function_exists($country_specific_function)) {
|
||||
return $country_specific_function($location);
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Given two points in lat/lon form, returns the distance between them.
|
||||
*
|
||||
* @param $latlon_a
|
||||
* An associative array where
|
||||
* 'lon' => is a floating point of the longitude coordinate for the point given by latlonA
|
||||
* 'lat' => is a floating point of the latitude coordinate for the point given by latlonB
|
||||
*
|
||||
* @param $latlon_b
|
||||
* Another point formatted like $latlon_b
|
||||
*
|
||||
* @param $distance_unit
|
||||
* A string that is either 'km' or 'mile'.
|
||||
* If neither 'km' or 'mile' is passed, the parameter is forced to 'km'
|
||||
*
|
||||
* @return
|
||||
* NULL if sense can't be made of the parameters.
|
||||
* An associative array where
|
||||
* 'scalar' => Is the distance between the two lat/lon parameter points
|
||||
* 'distance_unit' => Is the unit of distance being represented by 'scalar'.
|
||||
* This will be 'km' unless 'mile' is passed for the $distance_unit param
|
||||
*
|
||||
* @ingroup Location
|
||||
*/
|
||||
function location_distance_between($latlon_a = array(), $latlon_b = array(), $distance_unit = 'km') {
|
||||
if (!isset($latlon_a['lon']) || !isset($latlon_a['lat']) || !isset($latlon_b['lon']) || !isset($latlon_b['lat'])) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ($distance_unit != 'km' && $distance_unit != 'mile') {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// $conversion_factor = number to divide by to convert meters to $distance_unit
|
||||
// At this point, $distance_unit == 'km' or 'mile' and nothing else
|
||||
//$conversion_factor = ($distance_unit == 'km') ? 1000.0 : 1609.347;
|
||||
|
||||
$meters = earth_distance($latlon_a['lon'], $latlon_a['lat'], $latlon_b['lon'], $latlon_b['lat']);
|
||||
return array('scalar' => round($meters/(($distance_unit == 'km') ? 1000.0 : 1609.347), 1), 'distance_unit' => $distance_unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes two locations and tries to return a deep-link to driving directions.
|
||||
*
|
||||
* Parameters:
|
||||
* @param $location_a
|
||||
* An associative array that represents an location where
|
||||
* 'street' => the street portions of the location
|
||||
* 'additional' => additional street portion of the location
|
||||
* 'city' => the city name
|
||||
* 'province' => the province, state, or territory
|
||||
* 'country' => lower-cased two-letter ISO code (REQUIRED)
|
||||
* 'postal_code' => the postal code
|
||||
*
|
||||
* @param $location_b
|
||||
* An associative array that represents an location in the same way that
|
||||
* parameter $location_a does.
|
||||
*
|
||||
* @param $link_text
|
||||
* The text of the HTML link that is to be generated.
|
||||
*
|
||||
* @return
|
||||
* A deep-link to driving directions on Yahoo! or some other mapping service, if enough fields are filled in the parameters.
|
||||
* A deep-link to a form for driving directions with information pre-filled if not enough, but some fields are filled in the parameters.
|
||||
* The empty string if no information is provided (or if so little information is provided that there is no function to which to delegate
|
||||
* the call.
|
||||
*
|
||||
* We dispatch the call to a country-specific function. The country-specific function, in this case,
|
||||
* will be the one reflected by the country parameter of the first function. We require that
|
||||
* both locationes supplied have a country field at the minimum.
|
||||
*
|
||||
* The country-specific functions will ultimately decide, with the parameters given, whether to
|
||||
* to link to a form for driving directions is provided, where this form will be
|
||||
* pre-populated with whatever values were available or whether to link directly to the driving
|
||||
* directions themselves if enough fields are filled for each location.
|
||||
*
|
||||
* @ingroup Location
|
||||
*/
|
||||
function location_driving_directions_link($location_a = array(), $location_b = array(), $link_text = 'Get directions') {
|
||||
if (!isset($location_a['country']) or !isset($location_b['country'])) {
|
||||
return '';
|
||||
}
|
||||
|
||||
// For now, return empty string if starting-point and destinations are in different countries
|
||||
//if ($location_a['country'] != $location_b['country']) {
|
||||
// return '';
|
||||
//}
|
||||
// Lines above commented out because I want to let the country-specific function of the departure point decide
|
||||
// what it will do with driving destination locationes from other countries. As an example, Yahoo! Maps supports driving
|
||||
// direction queries for locations between the U.S. and Canada.
|
||||
|
||||
$driving_direction_function = 'location_driving_directions_link_'. $location_a['country'];
|
||||
if (function_exists($driving_direction_function)) {
|
||||
$http_link = $driving_direction_function($location_a, $location_b);
|
||||
if (strlen($http_link)) {
|
||||
return '<a href="'. $http_link .'">'. $link_text .'</a>';
|
||||
}
|
||||
else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $distance
|
||||
* A number in either miles or km.
|
||||
*
|
||||
* @param $distance_unit
|
||||
* String (optional). Either 'mile' or 'km' (default)
|
||||
*
|
||||
* @return
|
||||
* A floating point number where the number in meters after the initially passed scalar has been ceil()'d
|
||||
* This is done after the $distance_unit parmeter is forced to be 'km' or 'mile'
|
||||
*/
|
||||
function _location_convert_distance_to_meters($distance, $distance_unit = 'km') {
|
||||
if (!is_numeric($distance)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ($distance == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ($distance_unit != 'km' && $distance_unit != 'mile') {
|
||||
$distance_unit = 'km';
|
||||
}
|
||||
|
||||
// Convert distance to meters
|
||||
$retval = round(floatval($distance) * (($distance_unit == 'km') ? 1000.0 : 1609.347), 2);
|
||||
return $retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an location and returns a "rough" latitude/longitude pair based on the postal code
|
||||
* data available for the given country.
|
||||
*
|
||||
* @param $location
|
||||
* An associative array $location where
|
||||
* 'street' => the street portion of the location
|
||||
* 'additional' => additional street portion of the location
|
||||
* 'province' => the province, state, or territory
|
||||
* 'country' => lower-cased two-letter ISO code (REQUIRED)
|
||||
* 'postal_code' => international postal code (REQUIRED)
|
||||
*
|
||||
* @return
|
||||
* NULL if data cannont be found.
|
||||
* Otherwise, an associative array where
|
||||
* 'lat' => is a floating point of the latitude coordinate of this location
|
||||
* 'lon' => is a floating point of the longitude coordinate of this location
|
||||
*
|
||||
* @ingroup Location
|
||||
*/
|
||||
function location_latlon_rough($location = array()) {
|
||||
if (!isset($location['country']) || !isset($location['postal_code'])) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
location_load_country($location['country']);
|
||||
|
||||
$latlon_function = 'location_latlon_rough_'. $location['country'];
|
||||
if (function_exists($latlon_function) && $result = $latlon_function($location)) {
|
||||
return $result;
|
||||
}
|
||||
else {
|
||||
return location_latlon_rough_default($location);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a lat/lon pair of the approximate center of the given postal code in the given country
|
||||
* This function is a default implementation, in case the country support doesn't implement a proper function for this.
|
||||
*
|
||||
* @param $location
|
||||
* An associative array $location where
|
||||
* 'street' => the street portion of the location
|
||||
* 'supplemental' => additional street portion of the location
|
||||
* 'province' => the province, state, or territory
|
||||
* 'country' => lower-cased two-letter ISO code (REQUIRED)
|
||||
* 'postal_code' => the international postal code for this location (REQUIRED)
|
||||
*
|
||||
* @return
|
||||
* An associative array where
|
||||
* 'lat' => approximate latitude of the center of the postal code's area
|
||||
* 'lon' => approximate longitude of the center of the postal code's area
|
||||
*
|
||||
*/
|
||||
function location_latlon_rough_default($location = array()) {
|
||||
if (!isset($location['country']) || !isset($location['postal_code'])) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$query = db_select('zipcodes', 'z');
|
||||
$query->addField('z', 'latitude', 'lat');
|
||||
$query->addField('z', 'longitude', 'lon');
|
||||
$coords = $query->condition('country', $location['country'])
|
||||
->condition('zip', $location['postal_code'])
|
||||
->execute()
|
||||
->fetchAssoc();
|
||||
|
||||
if ($coords) {
|
||||
return $coords;
|
||||
}
|
||||
// if nothing found internally (new zipcode, or incomplete zipcodes table)
|
||||
elseif (($newlatlong = location_latlon_exact($location)) != NULL) {
|
||||
// try a one-time external geocoding
|
||||
if ($newlatlong['lat']) {
|
||||
// and store results in zipcodes table for next lookups being internally handled
|
||||
// (yeah this is missing city/state info a.t.m., but is way better than nothing!)
|
||||
db_insert('zipcodes')
|
||||
->fields(array(
|
||||
'latitude' => $newlatlong['lat'],
|
||||
'longitude' => $newlatlong['lon'],
|
||||
'country' => $location['country'],
|
||||
'zip' => $location['postal_code'],
|
||||
))
|
||||
->execute();
|
||||
}
|
||||
return $newlatlong;
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an appropriate bounding box for showing an entire country on a map.
|
||||
* Target is a bounding box large enough to show the country in both spherical
|
||||
* mercator and mercator projections.
|
||||
* @param $location
|
||||
* Either a location array or a country code.
|
||||
*
|
||||
* @return
|
||||
* An array with 'minlng', 'minlat', 'maxlng', and 'maxlat' elements.
|
||||
*/
|
||||
function location_country_bounds($location = array()) {
|
||||
if (!is_array($location)) {
|
||||
$location = array('country' => $location);
|
||||
}
|
||||
if (!empty($location['country'])) {
|
||||
location_load_country($location['country']);
|
||||
}
|
||||
|
||||
$country_bounds_function = 'location_bounds_' . $location['country'];
|
||||
|
||||
if (function_exists($country_bounds_function)) {
|
||||
return $country_bounds_function();
|
||||
}
|
||||
else {
|
||||
return array(
|
||||
'minlng' => -180.0,
|
||||
'minlat' => -90.0,
|
||||
'maxlng' => 180.0,
|
||||
'maxlat' => 90.0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently, this is not a priority until there is an implementable use for exact longitude,
|
||||
* latitude coordinates for an location. The idea is that this call will eventually retrieve
|
||||
* information through a web-service. Whereas location_latlon_rough() returns an approximate
|
||||
* lat/lon pair based strictly on the postal code where this lat/lon pair is pulled from a
|
||||
* database table, this function is intended to send the entire location to a web-service and
|
||||
* to retrieve exact lat/lon coordinates.
|
||||
*
|
||||
* @param $location
|
||||
* An array where
|
||||
* -> the key values are 'street', 'additional', 'province', 'country', 'postal_code'
|
||||
* -> the values are:
|
||||
* 'street' => the string representing the street location (REQUIRED)
|
||||
* 'additional' => the string representing the additional street location portion in the location form
|
||||
* 'city' => the city name (REQUIRED)
|
||||
* 'province' => the province code defined in the country-specific include file
|
||||
* 'country' => the lower-case of the two-letter ISO code (REQUIRED)
|
||||
* 'postal_code' => the postal-code (REQUIRED)
|
||||
*
|
||||
* @return
|
||||
* NULL if the delegated-to function that does the actual look-up does not exist.
|
||||
* If the appropriate function exists, then this function returns an associative array where
|
||||
* 'lon' => A floating point number for the longitude coordinate of the parameter location
|
||||
* 'lat' => A floating point number for the latitude coordinate of the parameter location
|
||||
*
|
||||
* @ingroup Location
|
||||
*/
|
||||
function location_latlon_exact($location = array()) {
|
||||
$country = $location['country'];
|
||||
location_standardize_country_code($country);
|
||||
$service = variable_get('location_geocode_'. $country, 'none');
|
||||
if (!empty($country) && $service != 'none') {
|
||||
// figure out what the exact function should be
|
||||
if (strpos($service, '|')) {
|
||||
location_load_country($country);
|
||||
// The code change below fixes the problem of the country specific
|
||||
// function for geocoding not being correctly called (it removes any
|
||||
// text from the pipe (|) onwards)
|
||||
$exact_latlon_function = 'location_geocode_'. $country .'_'. substr($service, 0, strpos($service, '|'));
|
||||
}
|
||||
else {
|
||||
location_load_geocoder($service);
|
||||
$exact_latlon_function = $service .'_geocode_location';
|
||||
}
|
||||
if (function_exists($exact_latlon_function)) {
|
||||
return $exact_latlon_function($location);
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an associative array of countries currently supported
|
||||
* by the location system where
|
||||
* -> the keys represent the two-letter ISO code and
|
||||
* -> the values represent the English name of the country.
|
||||
* The array is sorted the index (i.e., by the short English name of the country).
|
||||
*
|
||||
* Please note the different between "supported" countries and "configured"
|
||||
* countries: A country being "supported" means that there is an include file
|
||||
* to support the country while "configure" implies that the site admin has
|
||||
* configured the site to actually use that country.
|
||||
*
|
||||
* @ingroup Location
|
||||
*/
|
||||
function _location_supported_countries() {
|
||||
$supported_countries = &drupal_static(__FUNCTION__, array());
|
||||
|
||||
|
||||
// If this function has already been called this request, we can avoid a DB hit.
|
||||
if (!empty($supported_countries)) {
|
||||
return $supported_countries;
|
||||
}
|
||||
|
||||
// Try first to load from cache, it's much faster than the scan below.
|
||||
if ($cache = cache_get('location:supported-countries', 'cache_location')) {
|
||||
$supported_countries = $cache->data;
|
||||
}
|
||||
else {
|
||||
// '<ISO two-letter code>' => '<English name for country>'
|
||||
$iso_list = location_get_iso3166_list();
|
||||
$path = drupal_get_path('module', 'location') .'/supported/location.';
|
||||
foreach ($iso_list as $cc => $name) {
|
||||
if (file_exists($path . $cc .'.inc')) {
|
||||
$supported_countries[$cc] = $name;
|
||||
}
|
||||
}
|
||||
cache_set('location:supported-countries', $supported_countries, 'cache_location');
|
||||
}
|
||||
return $supported_countries;
|
||||
}
|
||||
|
||||
// @@@ New in 3.x, document.
|
||||
/**
|
||||
* Fetch the provinces for a country.
|
||||
*/
|
||||
function location_get_provinces($country = 'us') {
|
||||
$provinces = &drupal_static(__FUNCTION__, array());
|
||||
|
||||
location_standardize_country_code($country);
|
||||
if (isset($provinces[$country])) {
|
||||
return $provinces[$country];
|
||||
}
|
||||
if ($cache = cache_get("provinces:$country", 'cache_location')) {
|
||||
$provinces[$country] = $cache->data;
|
||||
return $provinces[$country];
|
||||
}
|
||||
location_load_country($country);
|
||||
$func = 'location_province_list_'. $country;
|
||||
if (function_exists($func)) {
|
||||
$provinces[$country] = $func();
|
||||
cache_set("provinces:$country", $provinces[$country], 'cache_location');
|
||||
return $provinces[$country];
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
// @@@ New in 3.x, document.
|
||||
/**
|
||||
* Get the translated name of a country code.
|
||||
*/
|
||||
function location_country_name($country = 'us') {
|
||||
location_standardize_country_code($country);
|
||||
$countries = location_get_iso3166_list();
|
||||
if (isset($countries[$country])) {
|
||||
return $countries[$country];
|
||||
}
|
||||
else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// @@@ New in 3.x, document.
|
||||
/**
|
||||
* Get the full name of a province code.
|
||||
*/
|
||||
function location_province_name($country = 'us', $province = 'xx') {
|
||||
$provinces = location_get_provinces($country);
|
||||
$province = strtoupper($province);
|
||||
if (isset($provinces[$province])) {
|
||||
return $provinces[$province];
|
||||
}
|
||||
else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
// @@@ New in 3.x, document.
|
||||
/**
|
||||
* Get a province code from a code or full name and a country.
|
||||
*/
|
||||
function location_province_code($country = 'us', $province = 'xx') {
|
||||
// An array of countries is useful if someone specified multiple countries
|
||||
// in an autoselect for example.
|
||||
// It *is* possibly ambiguous, especially if the province was already a code.
|
||||
// We make an array here for single (the usual case) for code simplicity reasons.
|
||||
if (!is_array($country)) {
|
||||
$country = array($country);
|
||||
}
|
||||
|
||||
$p = strtoupper($province);
|
||||
foreach ($country as $c) {
|
||||
$provinces = location_get_provinces($c);
|
||||
foreach ($provinces as $k => $v) {
|
||||
if ($p == strtoupper($k) || $p == strtoupper($v)) {
|
||||
return $k;
|
||||
}
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
// @@@ New in 3.x, document.
|
||||
/**
|
||||
* Canonicalize a country code.
|
||||
*/
|
||||
function location_standardize_country_code(&$country) {
|
||||
$country = trim($country);
|
||||
// @@@ Double check the validity of this validity check. ;)
|
||||
if (!ctype_alpha($country) || strlen($country) != 2) {
|
||||
$country = 'xx';
|
||||
return FALSE;
|
||||
}
|
||||
else {
|
||||
$country = strtolower($country);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load support for a country.
|
||||
*
|
||||
* This function will load support for a country identified by its two-letter ISO code.
|
||||
*
|
||||
* @param $country
|
||||
* Two-letter ISO code for country.
|
||||
*
|
||||
* @return
|
||||
* TRUE if the file was found and loaded, FALSE otherwise.
|
||||
*/
|
||||
function location_load_country($country) {
|
||||
location_standardize_country_code($country);
|
||||
|
||||
$file = DRUPAL_ROOT . '/' . drupal_get_path('module', 'location') . '/supported/location.' . $country . '.inc';
|
||||
if (file_exists($file)) {
|
||||
include_once($file);
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// @@@ New in 3.x, document.
|
||||
/**
|
||||
* Load a general geocoding service.
|
||||
*/
|
||||
function location_load_geocoder($geocoder) {
|
||||
include_once(DRUPAL_ROOT . '/' . drupal_get_path('module', 'location') . '/geocoding/' . $geocoder . '.inc');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a single line address.
|
||||
*
|
||||
* @param $location
|
||||
* Array. The address parts
|
||||
* @return
|
||||
* String. The single line address
|
||||
*/
|
||||
function location_address2singleline($location = array()) {
|
||||
// Check if its a valid address
|
||||
if (empty($location)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$address = '';
|
||||
if (!empty($location['street'])) {
|
||||
$address .= $location['street'];
|
||||
}
|
||||
|
||||
if (!empty($location['city'])) {
|
||||
if (!empty($location['street'])) {
|
||||
$address .= ', ';
|
||||
}
|
||||
|
||||
$address .= $location['city'];
|
||||
}
|
||||
|
||||
if (!empty($location['province'])) {
|
||||
if (!empty($location['street']) || !empty($location['city'])) {
|
||||
$address .= ', ';
|
||||
}
|
||||
|
||||
// @@@ Fix this!
|
||||
if (substr($location['province'], 0, 3) == $location['country'] .'-') {
|
||||
$address .= substr($location['province'], 3);
|
||||
watchdog('Location', 'BUG: Country found in province attribute.');
|
||||
}
|
||||
else {
|
||||
$address .= $location['province'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($location['postal_code'])) {
|
||||
if (!empty($address)) {
|
||||
$address .= ' ';
|
||||
}
|
||||
$address .= $location['postal_code'];
|
||||
}
|
||||
|
||||
if (!empty($location['country'])) {
|
||||
$address .= ', '. $location['country'];
|
||||
}
|
||||
|
||||
return $address;
|
||||
}
|
||||
|
||||
function location_get_general_geocoder_list() {
|
||||
$list = &drupal_static(__FUNCTION__, array());
|
||||
|
||||
if (!count($list)) {
|
||||
$files = file_scan_directory(drupal_get_path('module', 'location') . '/geocoding', '/\.inc$/', array('nomask' => '/(\.\.?|CVS|\.svn)$/'));
|
||||
foreach ($files as $full_path_name => $fileinfo) {
|
||||
$list[] = $fileinfo->name;
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
* The following is an array of all
|
||||
* countrycode => country-name pairs as layed out in
|
||||
* ISO 3166-1 alpha-2
|
||||
*/
|
||||
function location_get_iso3166_list($upper = FALSE) {
|
||||
include_once DRUPAL_ROOT . '/includes/locale.inc';
|
||||
|
||||
// Statically cache a version of the core Drupal list of countries
|
||||
// with lower case country codes for use by this module.
|
||||
$countries = &drupal_static(__FUNCTION__);
|
||||
|
||||
if ($upper) {
|
||||
// Drupal core stores ISO 3166-1 alpha2 codes in upper case, as
|
||||
// per the ISO standard.
|
||||
return country_get_list();
|
||||
}
|
||||
elseif (!isset($countries)) {
|
||||
// Location module uses lower-case ISO 3166-1 alpha2 codes, so we need
|
||||
// to convert.
|
||||
$countries = array_change_key_case(country_get_list(), CASE_LOWER);
|
||||
}
|
||||
return $countries;
|
||||
}
|
42
sites/all/modules/contrib/fields/location/location.info
Normal file
42
sites/all/modules/contrib/fields/location/location.info
Normal file
@@ -0,0 +1,42 @@
|
||||
name = Location
|
||||
package = Location
|
||||
description = The location module allows you to associate a geographic location with content and users. Users can do proximity searches by postal code. This is useful for organizing communities that have a geographic presence.
|
||||
core = 7.x
|
||||
configure = admin/config/content/location
|
||||
files[] = location.module
|
||||
files[] = location.install
|
||||
files[] = location.admin.inc
|
||||
files[] = location.georss.inc
|
||||
files[] = location.inc
|
||||
files[] = location.token.inc
|
||||
files[] = location.views.inc
|
||||
files[] = location.views_default.inc
|
||||
files[] = tests/location_testcase.php
|
||||
files[] = tests/cow.test
|
||||
files[] = tests/earth.test
|
||||
files[] = tests/google_geocoder.test
|
||||
files[] = tests/location_cck.test
|
||||
files[] = handlers/location_handler_argument_location_country.inc
|
||||
files[] = handlers/location_handler_argument_location_province.inc
|
||||
files[] = handlers/location_handler_argument_location_proximity.inc
|
||||
files[] = handlers/location_handler_field_location_address.inc
|
||||
files[] = handlers/location_handler_field_location_country.inc
|
||||
files[] = handlers/location_handler_field_location_distance.inc
|
||||
files[] = handlers/location_handler_field_location_province.inc
|
||||
files[] = handlers/location_handler_field_location_street.inc
|
||||
files[] = handlers/location_handler_filter_location_country.inc
|
||||
files[] = handlers/location_handler_filter_location_province.inc
|
||||
files[] = handlers/location_handler_sort_location_distance.inc
|
||||
files[] = handlers/location_views_handler_field_coordinates.inc
|
||||
files[] = handlers/location_views_handler_field_latitude.inc
|
||||
files[] = handlers/location_views_handler_field_longitude.inc
|
||||
files[] = handlers/location_views_handler_filter_proximity.inc
|
||||
files[] = plugins/contexts/location.inc
|
||||
files[] = plugins/relationships/location_from_node.inc
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-02-18
|
||||
version = "7.x-3.x-dev"
|
||||
core = "7.x"
|
||||
project = "location"
|
||||
datestamp = "1329524299"
|
||||
|
1288
sites/all/modules/contrib/fields/location/location.install
Normal file
1288
sites/all/modules/contrib/fields/location/location.install
Normal file
File diff suppressed because it is too large
Load Diff
1917
sites/all/modules/contrib/fields/location/location.module
Normal file
1917
sites/all/modules/contrib/fields/location/location.module
Normal file
File diff suppressed because it is too large
Load Diff
62
sites/all/modules/contrib/fields/location/location.token.inc
Normal file
62
sites/all/modules/contrib/fields/location/location.token.inc
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Short description.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of hook_token_values().
|
||||
*/
|
||||
function _location_token_values($type, $object = NULL) {
|
||||
if ($type == 'node' || $type == 'user') {
|
||||
if (!empty($object->locations)) {
|
||||
// @@@ Strip virtual fields?
|
||||
foreach ($object->locations as $key => $location) {
|
||||
|
||||
// Normally, location_load_location() will take care of this.
|
||||
// However, token is commonly used during *saving*.
|
||||
// See #322328.
|
||||
if (empty($location['country_name'])) {
|
||||
if (!empty($location['country'])) {
|
||||
$location['country_name'] = location_country_name($location['country']);
|
||||
if (!empty($location['province'])) {
|
||||
$location['province_name'] = location_province_name($location['country'], $location['province']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($location as $field => $value) {
|
||||
if (!is_array($value)) {
|
||||
$values["location-{$field}_{$key}"] = check_plain($value);
|
||||
}
|
||||
}
|
||||
// Backwards compatibility.
|
||||
$values["location-provincename_$key"] = $values["location-province_name_$key"];
|
||||
$values["location-countryname_$key"] = $values["location-country_name_$key"];
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_token_list().
|
||||
*/
|
||||
function _location_token_list($type = 'all') {
|
||||
if ($type == 'node' || $type == 'user' || $type == 'all') {
|
||||
$tokens['location']['location-name_N'] = t('Location Name (If there are multiple locations per node, N is the iteration, starting with 0)');
|
||||
$tokens['location']['location-street_N'] = t('Street (If there are multiple locations per node, N is the iteration, starting with 0)');
|
||||
$tokens['location']['location-additional_N'] = t('Additional (If there are multiple locations per node, N is the iteration, starting with 0)');
|
||||
$tokens['location']['location-city_N'] = t('City (If there are multiple locations per node, N is the iteration, starting with 0)');
|
||||
$tokens['location']['location-province_N'] = t('State/Province (If there are multiple locations per node, N is the iteration, starting with 0)');
|
||||
$tokens['location']['location-province_name_N'] = t('State/Province Name (If there are multiple locations per node, N is the iteration, starting with 0)');
|
||||
$tokens['location']['location-postal_code_N'] = t('Postal Code (If there are multiple locations per node, N is the iteration, starting with 0)');
|
||||
$tokens['location']['location-latitude_N'] = t('Latitude (If there are multiple locations per node, N is the iteration, starting with 0)');
|
||||
$tokens['location']['location-longitude_N'] = t('Longitude (If there are multiple locations per node, N is the iteration, starting with 0)');
|
||||
$tokens['location']['location-country_N'] = t('Country (If there are multiple locations per node, N is the iteration, starting with 0)');
|
||||
$tokens['location']['location-country_name_N'] = t('Country Name (If there are multiple locations per node, N is the iteration, starting with 0)');
|
||||
return $tokens;
|
||||
}
|
||||
}
|
51
sites/all/modules/contrib/fields/location/location.tpl.php
Normal file
51
sites/all/modules/contrib/fields/location/location.tpl.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<div class="location vcard">
|
||||
<div class="adr">
|
||||
<?php if (!empty($name)): ?>
|
||||
<span class="fn"><?php print $name; ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($street)): ?>
|
||||
<div class="street-address">
|
||||
<?php print $street; ?>
|
||||
<?php if (!empty($additional)): ?>
|
||||
<?php print ' ' . $additional; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($city)): ?>
|
||||
<span class="locality"><?php print $city; ?></span><?php if (!empty($province)) print ', '; ?>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($province)): ?>
|
||||
<span class="region"><?php print $province_print; ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($postal_code)): ?>
|
||||
<span class="postal-code"><?php print $postal_code; ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($country_name)): ?>
|
||||
<div class="country-name"><?php print $country_name; ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($phone)): ?>
|
||||
<div class="tel">
|
||||
<abbr class="type" title="voice"><?php print t("Phone"); ?>:</abbr>
|
||||
<span class="value"><?php print $phone; ?></span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (!empty($fax)): ?>
|
||||
<div class="tel">
|
||||
<abbr class="type" title="fax"><?php print t("Fax"); ?>:</abbr>
|
||||
<span><?php print $fax; ?></span>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php // "Geo" microformat, see http://microformats.org/wiki/geo ?>
|
||||
<?php if (isset($latitude) && isset($longitude)): ?>
|
||||
<?php // Assume that 0, 0 is invalid. ?>
|
||||
<?php if ($latitude != 0 || $longitude != 0): ?>
|
||||
<span class="geo"><abbr class="latitude" title="<?php print $latitude; ?>"><?php print $latitude_dms; ?></abbr>, <abbr class="longitude" title="<?php print $longitude; ?>"><?php print $longitude_dms; ?></abbr></span>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php if (!empty($map_link)): ?>
|
||||
<div class="map-link">
|
||||
<?php print $map_link; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
565
sites/all/modules/contrib/fields/location/location.views.inc
Normal file
565
sites/all/modules/contrib/fields/location/location.views.inc
Normal file
@@ -0,0 +1,565 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Views 3 support for Location.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
TODO:
|
||||
* Finish porting!
|
||||
* Write "relationships" -- see book.views.inc, upload.views.inc, nodequeue...
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_views_handlers().
|
||||
*/
|
||||
function location_views_handlers() {
|
||||
return array(
|
||||
'info' => array(
|
||||
'path' => drupal_get_path('module', 'location') .'/handlers',
|
||||
),
|
||||
'handlers' => array(
|
||||
'location_views_handler_field_latitude' => array(
|
||||
'parent' => 'views_handler_field',
|
||||
),
|
||||
'location_views_handler_field_longitude' => array(
|
||||
'parent' => 'location_views_handler_field_latitude',
|
||||
),
|
||||
'location_views_handler_field_coordinates' => array(
|
||||
'parent' => 'location_views_handler_field_latitude',
|
||||
),
|
||||
'location_handler_field_location_country' => array(
|
||||
'parent' => 'views_handler_field',
|
||||
),
|
||||
'location_handler_filter_location_country' => array(
|
||||
'parent' => 'views_handler_filter_in_operator',
|
||||
),
|
||||
'location_handler_argument_location_country' => array(
|
||||
'parent' => 'views_handler_argument',
|
||||
),
|
||||
'location_handler_field_location_province' => array(
|
||||
'parent' => 'views_handler_field',
|
||||
),
|
||||
'location_handler_filter_location_province' => array(
|
||||
'parent' => 'views_handler_filter',
|
||||
),
|
||||
'location_handler_argument_location_province' => array(
|
||||
'parent' => 'views_handler_argument',
|
||||
),
|
||||
'location_handler_argument_location_proximity' => array(
|
||||
'parent' => 'views_handler_argument',
|
||||
),
|
||||
'location_handler_field_location_address' => array(
|
||||
'parent' => 'views_handler_field',
|
||||
),
|
||||
'location_handler_field_location_street' => array(
|
||||
'parent' => 'views_handler_field',
|
||||
),
|
||||
'location_views_handler_filter_proximity' => array(
|
||||
'parent' => 'views_handler_filter',
|
||||
),
|
||||
'location_handler_field_location_distance' => array(
|
||||
'parent' => 'views_handler_field',
|
||||
),
|
||||
'location_handler_sort_location_distance' => array(
|
||||
'parent' => 'views_handler_sort',
|
||||
),
|
||||
// 'location_handler_relationship_location_distance' => array(
|
||||
// 'parent' => 'views_handler_relationship',
|
||||
// ),
|
||||
|
||||
// 'location_handler_field_location_coordinates_user' => array(
|
||||
// 'parent' => 'views_handler_field',
|
||||
// ),
|
||||
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of hook_views_data().
|
||||
*/
|
||||
function location_views_data() {
|
||||
// ----------------------------------------------------------------
|
||||
// location table -- basic table information.
|
||||
|
||||
// Define the base group of this table. Fields that don't
|
||||
// have a group defined will go into this field by default.
|
||||
|
||||
$data['location']['table']['group'] = t('Location');
|
||||
|
||||
// Advertise this table as a possible base table
|
||||
$data['location']['table']['base'] = array(
|
||||
'field' => 'lid',
|
||||
'title' => t('Location'),
|
||||
'help' => t('Locations are addresses and map coordinates.'),
|
||||
'weight' => -10,
|
||||
);
|
||||
|
||||
$data['location']['table']['join'] = array(
|
||||
// Location links to node through location_instance via lid.
|
||||
'node' => array(
|
||||
'left_table' => 'location_instance',
|
||||
'left_field' => 'lid',
|
||||
'field' => 'lid',
|
||||
),
|
||||
// Location links to node_revision through location_instance via lid.
|
||||
'node_revision' => array(
|
||||
'left_table' => 'location_instance',
|
||||
'left_field' => 'lid',
|
||||
'field' => 'lid',
|
||||
),
|
||||
// Location links to users through location_instance via lid.
|
||||
'users' => array(
|
||||
'left_table' => 'location_instance',
|
||||
'left_field' => 'lid',
|
||||
'field' => 'lid',
|
||||
),
|
||||
);
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// location table -- fields
|
||||
|
||||
// lid
|
||||
$data['location']['lid'] = array(
|
||||
'title' => t('Lid'),
|
||||
'help' => t('The location ID of the location.'), // The help that appears on the UI,
|
||||
// Information for displaying the lid
|
||||
'field' => array(
|
||||
'handler' => 'views_handler_field', // @@@
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
// Information for accepting a lid as an argument
|
||||
/*
|
||||
'argument' => array(
|
||||
'handler' => 'views_handler_argument_node_nid',
|
||||
'name field' => 'title', // the field to display in the summary.
|
||||
'numeric' => TRUE,
|
||||
'validate type' => 'nid',
|
||||
),
|
||||
*/
|
||||
// Information for accepting a lid as a filter
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_numeric',
|
||||
'allow empty' => TRUE,
|
||||
),
|
||||
// Information for sorting on a lid.
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
|
||||
$data['location']['name'] = array(
|
||||
'title' => t('Name'),
|
||||
'help' => t('The name of the selected location.'),
|
||||
'field' => array(
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_string',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
|
||||
// @@@ 1.x Conversion -- 'additional' => 'street', style 'additional'
|
||||
$data['location']['street'] = array(
|
||||
'title' => t('Street'),
|
||||
'help' => t('The street address of the selected location.'),
|
||||
'field' => array(
|
||||
'handler' => 'location_handler_field_location_street',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_string',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
|
||||
$data['location']['city'] = array(
|
||||
'title' => t('City'),
|
||||
'help' => t('The city of the selected location.'),
|
||||
'field' => array(
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'views_handler_argument_string',
|
||||
'empty field name' => t('Unknown'),
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_string',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
|
||||
// @@@ 1.x Conversion -- 'province' => 'province', style 'name'; 'province_code' => 'province', style 'code'
|
||||
$data['location']['province'] = array(
|
||||
'title' => t('Province'),
|
||||
'help' => t('The province of the selected location.'),
|
||||
'field' => array(
|
||||
'handler' => 'location_handler_field_location_province',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'location_handler_argument_location_province',
|
||||
//'name field' => 'name',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'location_handler_filter_location_province',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
// TODO: needs handler to sort by name, not code
|
||||
),
|
||||
);
|
||||
|
||||
$data['location']['postal_code'] = array(
|
||||
'title' => t('Postal Code'),
|
||||
'help' => t('The postal code of the selected location.'),
|
||||
'field' => array(
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_string',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
|
||||
// @@@ 1.x Conversion -- 'country' => 'country', style 'name'; 'country_code' => 'country', style 'code'.
|
||||
$data['location']['country'] = array(
|
||||
'title' => t('Country'),
|
||||
'help' => t('The country of the selected location.'),
|
||||
'field' => array(
|
||||
'handler' => 'location_handler_field_location_country',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'location_handler_argument_location_country',
|
||||
//'name field' => 'name',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'location_handler_filter_location_country',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
// TODO: needs handler to sort by name, not code
|
||||
),
|
||||
);
|
||||
|
||||
$data['location']['latitude'] = array(
|
||||
'title' => t('Latitude'),
|
||||
'help' => t('The latitude of the selected location.'),
|
||||
'field' => array(
|
||||
'handler' => 'location_views_handler_field_latitude',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_numeric',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
$data['location']['longitude'] = array(
|
||||
'title' => t('Longitude'),
|
||||
'help' => t('The longitude of the selected location.'),
|
||||
'field' => array(
|
||||
'handler' => 'location_views_handler_field_longitude',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'views_handler_filter_numeric',
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'views_handler_sort',
|
||||
),
|
||||
);
|
||||
$data['location']['coordinates'] = array(
|
||||
'title' => t('Coordinates'),
|
||||
'help' => t("The coordinates of the selected location in 'lat, long' format."),
|
||||
'field' => array(
|
||||
'field' => 'latitude', // The handler adds the longitude.
|
||||
'handler' => 'location_views_handler_field_coordinates',
|
||||
'click sortable' => FALSE,
|
||||
),
|
||||
);
|
||||
|
||||
$data['location']['distance'] = array(
|
||||
'title' => t('Distance / Proximity'),
|
||||
'help' => t("The distance from the selected location and either the current user or a specific location."),
|
||||
'field' => array(
|
||||
'handler' => 'location_handler_field_location_distance',
|
||||
'click sortable' => TRUE,
|
||||
),
|
||||
'sort' => array(
|
||||
'handler' => 'location_handler_sort_location_distance',
|
||||
),
|
||||
'argument' => array(
|
||||
'handler' => 'location_handler_argument_location_proximity',
|
||||
),
|
||||
'filter' => array(
|
||||
'handler' => 'location_views_handler_filter_proximity',
|
||||
),
|
||||
// 'relationship' => array(
|
||||
// 'handler' => 'location_handler_relationship_location_distance',
|
||||
// ),
|
||||
);
|
||||
|
||||
// $data['location']['coordinates_user'] = array(
|
||||
// 'title' => t('Coordinates of logged-on user'),
|
||||
// 'help' => t('This will contain the coordinates of the logged-on user.'),
|
||||
// 'field' => array(
|
||||
// 'handler' => 'location_handler_field_location_coordinates_user',
|
||||
// 'click sortable' => FALSE,
|
||||
// ),
|
||||
// );
|
||||
|
||||
/*
|
||||
'latitude' => array(
|
||||
'name' => t('Latitude'),
|
||||
'sortable' => TRUE,
|
||||
),
|
||||
'longitude' => array(
|
||||
'name' => t('Longitude'),
|
||||
'sortable' => TRUE,
|
||||
),
|
||||
*/
|
||||
|
||||
|
||||
$data['location']['address'] = array(
|
||||
'title' => t('Address'),
|
||||
'help' => t('The entire address block for the location.'),
|
||||
'field' => array(
|
||||
'field' => 'lid',
|
||||
'handler' => 'location_handler_field_location_address',
|
||||
'element type' => 'div',
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
$data['location_instance']['table']['group'] = t('Location');
|
||||
|
||||
$data['location_instance']['table']['join'] = array(
|
||||
'location' => array(
|
||||
'left_field' => 'lid',
|
||||
'field' => 'lid',
|
||||
),
|
||||
'users' => array(
|
||||
'left_field' => 'uid',
|
||||
'field' => 'uid',
|
||||
),
|
||||
'node' => array(
|
||||
'left_field' => 'vid',
|
||||
'field' => 'vid',
|
||||
),
|
||||
'node_revision' => array(
|
||||
'left_field' => 'vid',
|
||||
'field' => 'vid',
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
// Tell the base tables about us.
|
||||
$data['node']['table']['join']['location'] = array(
|
||||
'left_table' => 'location_instance',
|
||||
'left_field' => 'vid',
|
||||
'field' => 'vid',
|
||||
);
|
||||
$data['node_revision']['table']['join']['location'] = array(
|
||||
'left_table' => 'location_instance',
|
||||
'left_field' => 'vid',
|
||||
'field' => 'vid',
|
||||
);
|
||||
$data['users']['table']['join']['location'] = array(
|
||||
'left_table' => 'location_instance',
|
||||
'left_field' => 'uid',
|
||||
'field' => 'uid',
|
||||
);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for proximity handlers.
|
||||
* Gets a list of available node location and cck location fields.
|
||||
*
|
||||
* @return
|
||||
* An array of the location field options.
|
||||
*/
|
||||
function location_views_proximity_get_location_field_options() {
|
||||
// Get the CCK location field options.
|
||||
$field_options = array('node' => t('Node location'));
|
||||
if (module_exists('location_cck')) {
|
||||
$fields = field_info_fields();
|
||||
foreach ($fields as $field) {
|
||||
if ($field['module'] == 'location_cck') {
|
||||
$field_options[$field['field_name']] = t('CCK Location: @name', array('@name' => $field['field_name']));
|
||||
}
|
||||
}
|
||||
}
|
||||
return $field_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for proximity handlers.
|
||||
* Gets available arguments for argument related handler options.
|
||||
*
|
||||
* @param $view
|
||||
* The view object.
|
||||
*
|
||||
* @return
|
||||
* An array containing arrays of the nid arguments and the uid arguments.
|
||||
*/
|
||||
function location_views_proximity_get_argument_options($view) {
|
||||
// Get the arguments for this view so we can use nid, uid or Global: Null arguments.
|
||||
$uid_argument_options = array();
|
||||
$nid_argument_options = array();
|
||||
$arguments = $view->display_handler->get_handlers('argument');
|
||||
foreach ($arguments as $id => $handler) {
|
||||
if ($handler->field == 'null') {
|
||||
$uid_argument_options[$id] = $handler->ui_name();
|
||||
$nid_argument_options[$id] = $handler->ui_name();
|
||||
}
|
||||
else if ($handler->field == 'nid') {
|
||||
$nid_argument_options[$id] = $handler->ui_name();
|
||||
}
|
||||
else if ($handler->field == 'uid') {
|
||||
$uid_argument_options[$id] = $handler->ui_name();
|
||||
}
|
||||
}
|
||||
return array($nid_argument_options, $uid_argument_options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for proximity handlers.
|
||||
* Retrieves the coordinates of the location that this field measures distances against.
|
||||
*
|
||||
* @param $view
|
||||
* The view object.
|
||||
* @param $options
|
||||
* An array of the options (or values in the case of the filter) of the handler.
|
||||
*
|
||||
* @return
|
||||
* An array with keys 'latitude' and 'longitude' or an empty array.
|
||||
*/
|
||||
function location_views_proximity_get_reference_location($view, $options) {
|
||||
$coordinates = array();
|
||||
switch ($options['origin']) {
|
||||
case 'user':
|
||||
case 'hybrid':
|
||||
global $user;
|
||||
$user_locations = isset($user->locations) ? $user->locations : location_load_locations($user->uid, 'uid');
|
||||
// This user_location_delta will only possibly be set if we are dealing with the filter.
|
||||
$i = (isset($options['user_location_delta']) && !empty($options['user_location_delta'])) ? $options['user_location_delta'] : 0;
|
||||
if (isset($user_locations[$i]['latitude']) || !empty($user_locations[$i]['latitude'])) {
|
||||
$coordinates['latitude'] = (float) $user_locations[$i]['latitude'];
|
||||
$coordinates['longitude'] = (float) $user_locations[$i]['longitude'];
|
||||
}
|
||||
else if ($options['origin'] == 'hybrid') {
|
||||
$coordinates['latitude'] = (float) $options['latitude'];
|
||||
$coordinates['longitude'] = (float) $options['longitude'];
|
||||
}
|
||||
break;
|
||||
case 'static':
|
||||
case 'latlon_gmap':
|
||||
$coordinates['latitude'] = (float) $options['latitude'];
|
||||
$coordinates['longitude'] = (float) $options['longitude'];
|
||||
break;
|
||||
case 'tied':
|
||||
if (!empty($view->filter)) {
|
||||
foreach ($view->filter as $filter) {
|
||||
if ($filter->table == 'location' && $filter->field == 'distance' && $filter->options['relationship'] == $options['relationship']) {
|
||||
$filter_options = array_merge($filter->options, $filter->options['value'], $filter->value);
|
||||
if ($coords = location_views_proximity_get_reference_location($view, $filter_options)) {
|
||||
$coordinates['latitude'] = (float) $coords['latitude'];
|
||||
$coordinates['longitude'] = (float) $coords['longitude'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'postal':
|
||||
case 'postal_default':
|
||||
// Force default for country.
|
||||
if ($options['origin'] == 'postal_default') {
|
||||
$options['country'] = variable_get('location_default_country', 'us');
|
||||
}
|
||||
// Zip code lookup.
|
||||
if (!empty($options['postal_code']) && !empty($options['country'])) {
|
||||
$coords = location_latlon_rough($options);
|
||||
if ($coords) {
|
||||
$coordinates['latitude'] = (float) $coords['lat'];
|
||||
$coordinates['longitude'] = (float) $coords['lon'];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'php':
|
||||
ob_start();
|
||||
$result = eval($options['php_code']);
|
||||
ob_end_clean();
|
||||
if ($result && $result['latitude'] && $result['longitude']) {
|
||||
$coordinates['latitude'] = (float) $result['latitude'];
|
||||
$coordinates['longitude'] = (float) $result['longitude'];
|
||||
}
|
||||
break;
|
||||
case 'nid_arg':
|
||||
if ($nodehandler = $view->display_handler->get_handler('argument', $options['nid_arg'])) {
|
||||
$nid = $nodehandler->get_value();
|
||||
if ($nid && is_numeric($nid) && $tempnode = node_load($nid)) {
|
||||
$field_name = $options['nid_loc_field'];
|
||||
if ($field_name == 'node') {
|
||||
$coordinates['latitude'] = (float) $tempnode->location['latitude'];
|
||||
$coordinates['longitude'] = (float) $tempnode->location['longitude'];
|
||||
}
|
||||
else {
|
||||
if (isset($tempnode->$field_name)) {
|
||||
$cck_location = $tempnode->$field_name;
|
||||
if (isset($cck_location[LANGUAGE_NONE][0]['longitude']) && isset($cck_location[LANGUAGE_NONE][0]['latitude'])) {
|
||||
$coordinates['latitude'] = (float) $cck_location[LANGUAGE_NONE][0]['latitude'];
|
||||
$coordinates['longitude'] = (float) $cck_location[LANGUAGE_NONE][0]['longitude'];
|
||||
}
|
||||
else if (isset($cck_location[0]['longitude']) && isset($cck_location[0]['latitude'])) {
|
||||
$coordinates['latitude'] = (float) $cck_location[0]['latitude'];
|
||||
$coordinates['longitude'] = (float) $cck_location[0]['longitude'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'uid_arg':
|
||||
if ($userhandler = $view->display_handler->get_handler('argument', $options['uid_arg'])) {
|
||||
$uid = $userhandler->get_value();
|
||||
if ($uid && is_numeric($uid) && $tempuser = user_load(array('uid' => $uid))) {
|
||||
$coordinates['latitude'] = (float) $tempuser->location['latitude'];
|
||||
$coordinates['longitude'] = (float) $tempuser->location['longitude'];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'distance_arg':
|
||||
foreach ($view->argument as $argument) {
|
||||
if ($argument->field == 'distance') {
|
||||
list($coords, $search_distance) = explode('_', $view->args[$argument->position]);
|
||||
list($lat, $lon) = explode(',', $coords);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$coordinates['latitude'] = (float) $lat;
|
||||
$coordinates['longitude'] = (float) $lon;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return $coordinates;
|
||||
}
|
@@ -0,0 +1,621 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Default views for location module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_default_view_views().
|
||||
*/
|
||||
function location_views_default_views() {
|
||||
$view = new view;
|
||||
$view->name = 'location_table';
|
||||
$view->description = 'Node location table.';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 2;
|
||||
$view->disabled = TRUE;
|
||||
$handler = $view->new_display('default', 'Defaults', 'default');
|
||||
$handler->override_option('fields', array(
|
||||
'title' => array(
|
||||
'label' => 'Title',
|
||||
'link_to_node' => 1,
|
||||
'exclude' => 0,
|
||||
'id' => 'title',
|
||||
'table' => 'node',
|
||||
'field' => 'title',
|
||||
'override' => array(
|
||||
'button' => 'Override',
|
||||
),
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'street' => array(
|
||||
'label' => 'Street',
|
||||
'style' => 'both',
|
||||
'exclude' => 0,
|
||||
'id' => 'street',
|
||||
'table' => 'location',
|
||||
'field' => 'street',
|
||||
'override' => array(
|
||||
'button' => 'Override',
|
||||
),
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'city' => array(
|
||||
'label' => 'City',
|
||||
'exclude' => 0,
|
||||
'id' => 'city',
|
||||
'table' => 'location',
|
||||
'field' => 'city',
|
||||
'override' => array(
|
||||
'button' => 'Override',
|
||||
),
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'province' => array(
|
||||
'label' => 'Province',
|
||||
'style' => 'name',
|
||||
'exclude' => 0,
|
||||
'id' => 'province',
|
||||
'table' => 'location',
|
||||
'field' => 'province',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'postal_code' => array(
|
||||
'label' => 'Postal Code',
|
||||
'exclude' => 0,
|
||||
'id' => 'postal_code',
|
||||
'table' => 'location',
|
||||
'field' => 'postal_code',
|
||||
'override' => array(
|
||||
'button' => 'Override',
|
||||
),
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'country' => array(
|
||||
'label' => 'Country',
|
||||
'style' => 'name',
|
||||
'exclude' => 0,
|
||||
'id' => 'country',
|
||||
'table' => 'location',
|
||||
'field' => 'country',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
$handler->override_option('filters', array(
|
||||
'status_extra' => array(
|
||||
'operator' => '=',
|
||||
'value' => '',
|
||||
'group' => '0',
|
||||
'exposed' => FALSE,
|
||||
'expose' => array(
|
||||
'operator' => FALSE,
|
||||
'label' => '',
|
||||
),
|
||||
'id' => 'status_extra',
|
||||
'table' => 'node',
|
||||
'field' => 'status_extra',
|
||||
'override' => array(
|
||||
'button' => 'Override',
|
||||
),
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'lid' => array(
|
||||
'operator' => 'not empty',
|
||||
'value' => array(
|
||||
'value' => '',
|
||||
'min' => '',
|
||||
'max' => '',
|
||||
),
|
||||
'group' => '0',
|
||||
'exposed' => FALSE,
|
||||
'expose' => array(
|
||||
'operator' => FALSE,
|
||||
'label' => '',
|
||||
),
|
||||
'id' => 'lid',
|
||||
'table' => 'location',
|
||||
'field' => 'lid',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
$handler->override_option('access', array(
|
||||
'type' => 'perm',
|
||||
'perm' => 'view node location table',
|
||||
));
|
||||
$handler->override_option('style_plugin', 'table');
|
||||
$handler->override_option('style_options', array(
|
||||
'grouping' => '',
|
||||
'override' => 1,
|
||||
'sticky' => 0,
|
||||
'order' => 'asc',
|
||||
'columns' => array(
|
||||
'title' => 'title',
|
||||
'street' => 'street',
|
||||
'city' => 'city',
|
||||
'province' => 'province',
|
||||
'postal_code' => 'postal_code',
|
||||
'country' => 'country',
|
||||
),
|
||||
'info' => array(
|
||||
'title' => array(
|
||||
'sortable' => 1,
|
||||
'separator' => '',
|
||||
),
|
||||
'street' => array(
|
||||
'sortable' => 1,
|
||||
'separator' => '',
|
||||
),
|
||||
'city' => array(
|
||||
'sortable' => 1,
|
||||
'separator' => '',
|
||||
),
|
||||
'province' => array(
|
||||
'sortable' => 1,
|
||||
'separator' => '',
|
||||
),
|
||||
'postal_code' => array(
|
||||
'sortable' => 1,
|
||||
'separator' => '',
|
||||
),
|
||||
'country' => array(
|
||||
'sortable' => 1,
|
||||
'separator' => '',
|
||||
),
|
||||
),
|
||||
'default' => '-1',
|
||||
));
|
||||
$handler = $view->new_display('page', 'Page', 'page_1');
|
||||
$handler->override_option('path', 'location/views');
|
||||
$handler->override_option('menu', array(
|
||||
'type' => 'normal',
|
||||
'title' => 'Location table',
|
||||
'weight' => '0',
|
||||
));
|
||||
$handler->override_option('tab_options', array(
|
||||
'type' => 'none',
|
||||
'title' => '',
|
||||
'weight' => 0,
|
||||
));
|
||||
$views[$view->name] = $view;
|
||||
|
||||
|
||||
$view = new view;
|
||||
$view->name = 'location_directory';
|
||||
$view->description = 'Location directory filtered by arguments in the url.';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'node';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 2;
|
||||
$view->disabled = TRUE;
|
||||
$handler = $view->new_display('default', 'Defaults', 'default');
|
||||
$handler->override_option('fields', array(
|
||||
'title' => array(
|
||||
'label' => 'Title',
|
||||
'link_to_node' => 1,
|
||||
'exclude' => 0,
|
||||
'id' => 'title',
|
||||
'table' => 'node',
|
||||
'field' => 'title',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'street' => array(
|
||||
'label' => 'Street',
|
||||
'style' => 'both',
|
||||
'exclude' => 0,
|
||||
'id' => 'street',
|
||||
'table' => 'location',
|
||||
'field' => 'street',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'city' => array(
|
||||
'label' => 'City',
|
||||
'exclude' => 0,
|
||||
'id' => 'city',
|
||||
'table' => 'location',
|
||||
'field' => 'city',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'province' => array(
|
||||
'label' => 'Province',
|
||||
'style' => 'name',
|
||||
'exclude' => 0,
|
||||
'id' => 'province',
|
||||
'table' => 'location',
|
||||
'field' => 'province',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'postal_code' => array(
|
||||
'label' => 'Postal Code',
|
||||
'exclude' => 0,
|
||||
'id' => 'postal_code',
|
||||
'table' => 'location',
|
||||
'field' => 'postal_code',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'country' => array(
|
||||
'label' => 'Country',
|
||||
'style' => 'name',
|
||||
'exclude' => 0,
|
||||
'id' => 'country',
|
||||
'table' => 'location',
|
||||
'field' => 'country',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
$handler->override_option('arguments', array(
|
||||
'country' => array(
|
||||
'default_action' => 'summary asc',
|
||||
'style_plugin' => 'default_summary',
|
||||
'style_options' => array(
|
||||
'count' => 1,
|
||||
'override' => 0,
|
||||
'items_per_page' => '25',
|
||||
),
|
||||
'wildcard' => 'all',
|
||||
'wildcard_substitution' => 'All',
|
||||
'title' => '%1',
|
||||
'default_argument_type' => 'fixed',
|
||||
'default_argument' => '',
|
||||
'validate_type' => 'none',
|
||||
'validate_fail' => 'not found',
|
||||
'id' => 'country',
|
||||
'table' => 'location',
|
||||
'field' => 'country',
|
||||
'relationship' => 'none',
|
||||
'default_options_div_prefix' => '',
|
||||
'default_argument_fixed' => '',
|
||||
'default_argument_php' => '',
|
||||
'validate_argument_node_type' => array(
|
||||
'page' => 0,
|
||||
'story' => 0,
|
||||
),
|
||||
'validate_argument_node_access' => 0,
|
||||
'validate_argument_nid_type' => 'nid',
|
||||
'validate_argument_php' => '',
|
||||
),
|
||||
'province' => array(
|
||||
'default_action' => 'summary asc',
|
||||
'style_plugin' => 'default_summary',
|
||||
'style_options' => array(
|
||||
'count' => 1,
|
||||
'override' => 0,
|
||||
'items_per_page' => '25',
|
||||
),
|
||||
'wildcard' => 'all',
|
||||
'wildcard_substitution' => 'All',
|
||||
'title' => '%2',
|
||||
'default_argument_type' => 'fixed',
|
||||
'default_argument' => '',
|
||||
'validate_type' => 'none',
|
||||
'validate_fail' => 'not found',
|
||||
'id' => 'province',
|
||||
'table' => 'location',
|
||||
'field' => 'province',
|
||||
'relationship' => 'none',
|
||||
'default_options_div_prefix' => '',
|
||||
'default_argument_fixed' => '',
|
||||
'default_argument_php' => '',
|
||||
'validate_argument_node_type' => array(
|
||||
'page' => 0,
|
||||
'story' => 0,
|
||||
),
|
||||
'validate_argument_node_access' => 0,
|
||||
'validate_argument_nid_type' => 'nid',
|
||||
'validate_argument_php' => '',
|
||||
),
|
||||
'city' => array(
|
||||
'default_action' => 'summary asc',
|
||||
'style_plugin' => 'default_summary',
|
||||
'style_options' => array(
|
||||
'count' => 1,
|
||||
'override' => 0,
|
||||
'items_per_page' => '25',
|
||||
),
|
||||
'wildcard' => 'all',
|
||||
'wildcard_substitution' => 'All',
|
||||
'title' => '%3',
|
||||
'default_argument_type' => 'fixed',
|
||||
'default_argument' => '',
|
||||
'validate_type' => 'none',
|
||||
'validate_fail' => 'not found',
|
||||
'glossary' => 1,
|
||||
'limit' => '1',
|
||||
'case' => 'none',
|
||||
'path_case' => 'none',
|
||||
'transform_dash' => 0,
|
||||
'id' => 'city',
|
||||
'table' => 'location',
|
||||
'field' => 'city',
|
||||
'relationship' => 'none',
|
||||
'default_options_div_prefix' => '',
|
||||
'default_argument_fixed' => '',
|
||||
'default_argument_php' => '',
|
||||
'validate_argument_node_type' => array(
|
||||
'page' => 0,
|
||||
'story' => 0,
|
||||
),
|
||||
'validate_argument_node_access' => 0,
|
||||
'validate_argument_nid_type' => 'nid',
|
||||
'validate_argument_php' => '',
|
||||
),
|
||||
));
|
||||
$handler->override_option('filters', array(
|
||||
'status_extra' => array(
|
||||
'operator' => '=',
|
||||
'value' => '',
|
||||
'group' => '0',
|
||||
'exposed' => FALSE,
|
||||
'expose' => array(
|
||||
'operator' => FALSE,
|
||||
'label' => '',
|
||||
),
|
||||
'id' => 'status_extra',
|
||||
'table' => 'node',
|
||||
'field' => 'status_extra',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'lid' => array(
|
||||
'operator' => 'not empty',
|
||||
'value' => array(
|
||||
'value' => '',
|
||||
'min' => '',
|
||||
'max' => '',
|
||||
),
|
||||
'group' => '0',
|
||||
'exposed' => FALSE,
|
||||
'expose' => array(
|
||||
'operator' => FALSE,
|
||||
'label' => '',
|
||||
),
|
||||
'id' => 'lid',
|
||||
'table' => 'location',
|
||||
'field' => 'lid',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
$handler->override_option('access', array(
|
||||
'type' => 'perm',
|
||||
'perm' => 'view location directory',
|
||||
));
|
||||
$handler->override_option('style_plugin', 'table');
|
||||
$handler->override_option('style_options', array(
|
||||
'grouping' => '',
|
||||
'override' => 1,
|
||||
'sticky' => 0,
|
||||
'order' => 'asc',
|
||||
'columns' => array(
|
||||
'title' => 'title',
|
||||
'street' => 'street',
|
||||
'city' => 'city',
|
||||
'province' => 'province',
|
||||
'postal_code' => 'postal_code',
|
||||
'country' => 'country',
|
||||
),
|
||||
'info' => array(
|
||||
'title' => array(
|
||||
'sortable' => 1,
|
||||
'separator' => '',
|
||||
),
|
||||
'street' => array(
|
||||
'sortable' => 1,
|
||||
'separator' => '',
|
||||
),
|
||||
'city' => array(
|
||||
'sortable' => 1,
|
||||
'separator' => '',
|
||||
),
|
||||
'province' => array(
|
||||
'sortable' => 1,
|
||||
'separator' => '',
|
||||
),
|
||||
'postal_code' => array(
|
||||
'sortable' => 1,
|
||||
'separator' => '',
|
||||
),
|
||||
'country' => array(
|
||||
'sortable' => 1,
|
||||
'separator' => '',
|
||||
),
|
||||
),
|
||||
'default' => '-1',
|
||||
));
|
||||
$handler = $view->new_display('page', 'Page', 'page_1');
|
||||
$handler->override_option('title', 'Locations');
|
||||
$handler->override_option('path', 'location/directory');
|
||||
$handler->override_option('menu', array(
|
||||
'type' => 'normal',
|
||||
'title' => 'Locations',
|
||||
'weight' => '0',
|
||||
));
|
||||
$handler->override_option('tab_options', array(
|
||||
'type' => 'none',
|
||||
'title' => '',
|
||||
'weight' => 0,
|
||||
));
|
||||
$views[$view->name] = $view;
|
||||
|
||||
|
||||
$view = new view;
|
||||
$view->name = 'user_location_table';
|
||||
$view->description = 'User location table.';
|
||||
$view->tag = '';
|
||||
$view->view_php = '';
|
||||
$view->base_table = 'users';
|
||||
$view->is_cacheable = FALSE;
|
||||
$view->api_version = 2;
|
||||
$view->disabled = TRUE;
|
||||
$handler = $view->new_display('default', 'Defaults', 'default');
|
||||
$handler->override_option('fields', array(
|
||||
'name' => array(
|
||||
'label' => 'Name',
|
||||
'link_to_user' => 1,
|
||||
'exclude' => 0,
|
||||
'id' => 'name',
|
||||
'table' => 'users',
|
||||
'field' => 'name',
|
||||
'override' => array(
|
||||
'button' => 'Override',
|
||||
),
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'street' => array(
|
||||
'label' => 'Street',
|
||||
'style' => 'both',
|
||||
'exclude' => 0,
|
||||
'id' => 'street',
|
||||
'table' => 'location',
|
||||
'field' => 'street',
|
||||
'override' => array(
|
||||
'button' => 'Override',
|
||||
),
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'city' => array(
|
||||
'label' => 'City',
|
||||
'exclude' => 0,
|
||||
'id' => 'city',
|
||||
'table' => 'location',
|
||||
'field' => 'city',
|
||||
'override' => array(
|
||||
'button' => 'Override',
|
||||
),
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'province' => array(
|
||||
'label' => 'Province',
|
||||
'style' => 'name',
|
||||
'exclude' => 0,
|
||||
'id' => 'province',
|
||||
'table' => 'location',
|
||||
'field' => 'province',
|
||||
'override' => array(
|
||||
'button' => 'Override',
|
||||
),
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'postal_code' => array(
|
||||
'label' => 'Postal Code',
|
||||
'exclude' => 0,
|
||||
'id' => 'postal_code',
|
||||
'table' => 'location',
|
||||
'field' => 'postal_code',
|
||||
'override' => array(
|
||||
'button' => 'Override',
|
||||
),
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'country' => array(
|
||||
'label' => 'Country',
|
||||
'style' => 'name',
|
||||
'exclude' => 0,
|
||||
'id' => 'country',
|
||||
'table' => 'location',
|
||||
'field' => 'country',
|
||||
'override' => array(
|
||||
'button' => 'Override',
|
||||
),
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
$handler->override_option('filters', array(
|
||||
'status' => array(
|
||||
'operator' => '=',
|
||||
'value' => 1,
|
||||
'group' => '0',
|
||||
'exposed' => FALSE,
|
||||
'expose' => array(
|
||||
'operator' => FALSE,
|
||||
'label' => '',
|
||||
),
|
||||
'id' => 'status',
|
||||
'table' => 'users',
|
||||
'field' => 'status',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
'lid' => array(
|
||||
'operator' => 'not empty',
|
||||
'value' => array(
|
||||
'value' => '',
|
||||
'min' => '',
|
||||
'max' => '',
|
||||
),
|
||||
'group' => '0',
|
||||
'exposed' => FALSE,
|
||||
'expose' => array(
|
||||
'operator' => FALSE,
|
||||
'label' => '',
|
||||
),
|
||||
'id' => 'lid',
|
||||
'table' => 'location',
|
||||
'field' => 'lid',
|
||||
'relationship' => 'none',
|
||||
),
|
||||
));
|
||||
$handler->override_option('access', array(
|
||||
'type' => 'perm',
|
||||
'perm' => 'view user location table',
|
||||
));
|
||||
$handler->override_option('style_plugin', 'table');
|
||||
$handler->override_option('style_options', array(
|
||||
'grouping' => '',
|
||||
'override' => 1,
|
||||
'sticky' => 0,
|
||||
'order' => 'asc',
|
||||
'columns' => array(
|
||||
'name' => 'name',
|
||||
'street' => 'street',
|
||||
'city' => 'city',
|
||||
'province' => 'province',
|
||||
'postal_code' => 'postal_code',
|
||||
'country' => 'country',
|
||||
),
|
||||
'info' => array(
|
||||
'name' => array(
|
||||
'sortable' => 1,
|
||||
'separator' => '',
|
||||
),
|
||||
'street' => array(
|
||||
'sortable' => 1,
|
||||
'separator' => '',
|
||||
),
|
||||
'city' => array(
|
||||
'sortable' => 1,
|
||||
'separator' => '',
|
||||
),
|
||||
'province' => array(
|
||||
'sortable' => 1,
|
||||
'separator' => '',
|
||||
),
|
||||
'postal_code' => array(
|
||||
'sortable' => 1,
|
||||
'separator' => '',
|
||||
),
|
||||
'country' => array(
|
||||
'sortable' => 1,
|
||||
'separator' => '',
|
||||
),
|
||||
),
|
||||
'default' => '-1',
|
||||
));
|
||||
$handler = $view->new_display('page', 'Page', 'page_1');
|
||||
$handler->override_option('path', 'location/users');
|
||||
$handler->override_option('menu', array(
|
||||
'type' => 'normal',
|
||||
'title' => 'User location table',
|
||||
'weight' => '0',
|
||||
));
|
||||
$handler->override_option('tab_options', array(
|
||||
'type' => 'none',
|
||||
'title' => '',
|
||||
'weight' => 0,
|
||||
));
|
||||
$views[$view->name] = $view;
|
||||
|
||||
|
||||
return $views;
|
||||
}
|
303
sites/all/modules/contrib/fields/location/location_API.txt
Normal file
303
sites/all/modules/contrib/fields/location/location_API.txt
Normal file
@@ -0,0 +1,303 @@
|
||||
|
||||
This file describes the public API for the CivicSpace location system as defined by
|
||||
in the library implemented by "location.inc" and its supporting files.
|
||||
|
||||
For a example of this API's usage, please consult "location.module"
|
||||
|
||||
|
||||
FUNCTION SPECIFICATIONS DESCRIBED IN THIS FILE:
|
||||
----------------------------------------------
|
||||
location_get_postalcode_data(): A function that takes a (postalcode,country) pair an returns lat/lon, city, province. This
|
||||
function is meant to replace location_latlon_rough(); see below.
|
||||
|
||||
location_latlon_rough(): A function that returns the latitude and longitude of the specified postal-code/country pair.
|
||||
This latitude and longitude will be of the approximate center of the postal-code's area. This function
|
||||
will soon be removed from the API as it has been replaced by the more comprehensive
|
||||
location_get_postalcode_data() described above. [TO BE DEPRECATED]
|
||||
|
||||
location_latlon_exact(): A function that returns the latitude and longitude of the given full location. Typically implemented
|
||||
on top of a web-service. [TO BE IMPLEMENTED]
|
||||
|
||||
location_map_link(): A function that returns, based on the site configuration, either NULL or 1 or more deep-links to mapping
|
||||
web sites for the parameter location array.
|
||||
|
||||
location_driving_directions_link(): A function that returns, given 2 locationes, a deep-link to Yahoo! Maps or some other site
|
||||
that provides driving directions. The site chosen depends on the implementation at the country-level.
|
||||
|
||||
location_proximity_form(): A function that generates a form for collecting proximity search parameters.
|
||||
|
||||
location_valid(): A function for validating locationes. [TO BE SPECIFIED]
|
||||
|
||||
theme_location(): A function that takes in an location and themes it. (e.g., $output .= theme('location', $location)).
|
||||
|
||||
location_distance_between(): A function that, given a pair of lat/lon pairs, returns the distance between them.
|
||||
|
||||
|
||||
"[TO BE SPECIFIED]" => Function spec has not been completed and may possibly be eliminated from spec.
|
||||
"[TO BE IMPLEMENTED]" => Function spec exists but is to be implemented in a future release.
|
||||
"[TO BE DEPRECATED]" => This function will soon be removed from the API.
|
||||
----------------------------------------------
|
||||
|
||||
|
||||
|
||||
IMPORTANT NOTES:
|
||||
----------------
|
||||
Formats
|
||||
---
|
||||
In the following API, a 'location' is merely an associative array with the following keys:
|
||||
'street' => A string for the street portion of an location
|
||||
'additional' => A string for the additional street portion of an location
|
||||
'province' => An upper-case, standard postal abbreviation of a state/province/territory
|
||||
'postal_code' => A string or integer for the postal code
|
||||
'country' => The lower-case of the ISO 3166 two-letter alpha code (e.g., 'us' for U.S., 'ca' for Canada).
|
||||
|
||||
For locations that are passed to location_form() for the $prefilled_values parameter, the same format applies
|
||||
except that the 'province' field is the concatenation of the country code, '-', and the province abbreviation.
|
||||
For example, 'CA' is the value for California for all purposes, but when passing this in a location for prefilled
|
||||
values, it should be 'us-CA'. There are two functions to help convert back and forth between these formats:
|
||||
location_form2api() and location_api2form(). These are described further below.
|
||||
|
||||
Delegation
|
||||
---
|
||||
With the exception of location_form() and location_proximity_form(), the calls to functions listed here are, in the end,
|
||||
dispatched to country-specific location libraries which are implemented in country-specific '.inc' files. For example,
|
||||
location_latlon_rough(), when given a U.S. location, really returns a result that is determined by call to
|
||||
"location_latlon_rough_us()" which is implemented in the file "location.us.inc".
|
||||
|
||||
Current Implementation
|
||||
---
|
||||
Currently, the only country supported is the United States. For the future, however, there will be documentation for how to
|
||||
implement a country-specific include file that can be plugged into the system to support these calls for new countries. This
|
||||
scheme will revolve around method signatures for a handful of simple-to-write functions.
|
||||
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function location_get_postalcode_data($location = array()); +
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
Takes a location and uses the combination of postal code and country to return an array that gives the
|
||||
city, province, and lat/lon dat for that postal code.
|
||||
|
||||
@param $location
|
||||
An associative array $location where
|
||||
'street' => the street portion of the location
|
||||
'additional' => additional street portion of the location
|
||||
'province' => the province, state, or territory
|
||||
'country' => lower-cased two-letter ISO code (REQUIRED)
|
||||
'postal_code' => international postal code (REQUIRED)
|
||||
|
||||
@return
|
||||
NULL if data cannot be found.
|
||||
Otherwise, an associative array where
|
||||
'lat' => is a floating point of the latitude coordinate of this location
|
||||
'lon' => is a floating point of the longitude coordinate of this location
|
||||
'city' => is a string for the city this postalcode is in (or the most recognized city at the given postal)
|
||||
'province' => the province of the given postal code.
|
||||
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function location_latlon_rough($location = array()); +
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
Takes an location and returns a "rough" latitude/longitude pair based on the postal code
|
||||
data available for the given country.
|
||||
|
||||
@param $location
|
||||
An associative array $location where
|
||||
'street' => the street portion of the location
|
||||
'additional' => additional street portion of the location
|
||||
'province' => the province, state, or territory
|
||||
'country' => lower-cased two-letter ISO code (REQUIRED)
|
||||
'postal_code' => international postal code (REQUIRED)
|
||||
|
||||
@return
|
||||
NULL if data cannont be found.
|
||||
Otherwise, an associative array where
|
||||
'lat' => is a floating point of the latitude coordinate of this location
|
||||
'lon' => is a floating point of the longitude coordinate of this location
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function location_latlon_exact($location = array()); +
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
Currently, this is not a priority until there is an implementable use for exact longitude,
|
||||
latitude coordinates for an location. The idea is that this call will eventually retrieve
|
||||
information through a web-service. Whereas location_latlon_rough() returns an approximate
|
||||
lat/lon pair based strictly on the postal code where this lat/lon pair is pulled from a
|
||||
database table, this function is intended to send the entire location to a web-service and
|
||||
to retrieve exact lat/lon coordinates.
|
||||
|
||||
@param $location
|
||||
An array where
|
||||
-> the key values are 'street', 'additional', 'province', 'country', 'postal_code'
|
||||
-> the values are:
|
||||
'street' => the string representing the street location (REQUIRED)
|
||||
'additional' => the string representing the additional street location portion in the location form
|
||||
'city' => the city name (REQUIRED)
|
||||
'province' => the province code defined in the country-specific include file
|
||||
'country' => the lower-case of the two-letter ISO code (REQUIRED)
|
||||
'postal_code' => the postal-code (REQUIRED)
|
||||
|
||||
@return
|
||||
NULL if the delegated-to function that does the actual look-up does not exist.
|
||||
If the appropriate function exists, then this function returns an associative array where
|
||||
'lon' => A floating point number for the longitude coordinate of the parameter location
|
||||
'lat' => A floating point number for the latitude coordinate of the parameter location
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function location_map_link($location = array(), $link_text = 'See map'); +
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
Get deep-links to a mapping services such as Yahoo! Maps or MapQuest (actual providers depend on configuration
|
||||
of location module) given a location. The call is delegated based on the 'country' value in the $location parameter.
|
||||
|
||||
@param $location
|
||||
An associative array where
|
||||
'street' => A string representing the street location
|
||||
'additional' => A string for any additional portion of the street location
|
||||
'city' => A string for the city name
|
||||
'province' => The standard postal abbreviation for the province
|
||||
'country' => The two-letter ISO code for the country of the location (REQUIRED)
|
||||
'postal_code' => The international postal code for the location
|
||||
|
||||
@return
|
||||
NULL if there are not mapping providers configured for the country or if no links could be generated.
|
||||
A string of the form "See map: Yahoo! Maps, MapQuest" where Yahoo! Maps and Mapquest are links to the
|
||||
given location and can be replaced with other options (e.g., Google) available in the location module settings.
|
||||
The idea is to encode the appropriate parameters as HTTP GET variables to the URL.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function location_driving_directions_link($locationA = array(), $locationB = array(), $link_text = 'Get directions');
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
Takes two locationes and tries to return a deep-link to driving directions.
|
||||
|
||||
Parameters:
|
||||
@param $locationA
|
||||
An associative array that represents an location where
|
||||
'street' => the street portions of the location
|
||||
'additional' => additional street portion of the location
|
||||
'city' => the city name
|
||||
'province' => the province, state, or territory
|
||||
'country' => lower-cased two-letter ISO code (REQUIRED)
|
||||
'postal_code' => the postal code
|
||||
|
||||
@param $locationB
|
||||
An associative array that represents an location in the same way that
|
||||
parameter $locationA does.
|
||||
|
||||
@param $link_text
|
||||
The text of the HTML link that is to be generated.
|
||||
|
||||
@return
|
||||
A deep-link to driving directions on Yahoo! or some other mapping service, if enough fields are filled in the parameters.
|
||||
A deep-link to a form for driving directions with information pre-filled if not enough, but some fields are filled in the parameters.
|
||||
The empty string if no information is provided (or if so little information is provided that there is no function to which to delegate
|
||||
the call.
|
||||
|
||||
We dispatch the call to a country-specific function. The country-specific function, in this case,
|
||||
will be the one reflected by the country parameter of the first function. We require that
|
||||
both locationes supplied have a country field at the minimum.
|
||||
|
||||
The country-specific functions will ultimately decide, with the parameters given, whether to
|
||||
to link to a form for driving directions is provided, where this form will be
|
||||
pre-populated with whatever values were available or whether to link directly to the driving
|
||||
directions themselves if enough fields are filled for each location.
|
||||
|
||||
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function location_proximity_form($location_form = '', $label = '', $description = '', $prefilled_values = array(), $form_name = 'location');
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
This function generates a form for doing proximity searches within a certain distance
|
||||
of a specified point.
|
||||
|
||||
Depending on the context within which this function is called, the search-point can either
|
||||
be user-supplied via the location form that is passed (if one is available) or done within
|
||||
a search-point extracted from a contact table or some other location source specified by
|
||||
the programmer calling this function.
|
||||
|
||||
@param $location_form
|
||||
An optional location form, preferably generated by location_form(). If the script processing this
|
||||
form also needs a user-supplied location, this parameter is used to specify a form for collecting the
|
||||
search-point about which this search is being done. If the caller does not supply a form, it is
|
||||
assumed that the caller already has a search point in mind and that this will be made clear in
|
||||
the $description parameter.
|
||||
|
||||
@param $label
|
||||
The label you want to apply to the form group that is returned (passed as $legend param to form_group()).
|
||||
|
||||
@param $description
|
||||
A text description of what is being searched for (e.g., 'Find all upcoming events near you.')
|
||||
|
||||
@param $prefilled_values
|
||||
An associative array for prefilled values for the proximity search parameters, where
|
||||
'distance' => is the prefilled int value to be selected for the distance scalar
|
||||
'distance_unit' => is 'km' or 'mile'
|
||||
|
||||
@param $form_name
|
||||
An additional parameter to help prevent HTML input name collisions. If the caller is using this
|
||||
function to generate more than 1 location proximity form on a page, then the generated name for
|
||||
each HTML input's "name" attribute will be $form_name. Allowing the caller to pass $form_name allows
|
||||
the caller the flexibility of using more than one location proximity search form on one page.
|
||||
|
||||
@return
|
||||
An HTML form (generated by Drupal form functions) that lets users specify proximity search parameters that include distance,
|
||||
the unit of distance, and a search-point if the optional $location_form parameter is passed. If one is not passed,
|
||||
the caller of this function will be assumed to already have one.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function theme_location($location = array()); +
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
Generates HTML for the passed location.
|
||||
|
||||
@param $location
|
||||
An associative array where
|
||||
'street' => A string representing the street location
|
||||
'additional' => A string for any additional portion of the street location
|
||||
'city' => A string for the city name
|
||||
'province' => The standard postal abbreviation for the province
|
||||
'country' => The two-letter ISO code for the country of the location (REQUIRED)
|
||||
'postal_code' => The international postal code for the location
|
||||
|
||||
@return
|
||||
An HTML string with special tags for locationes.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
function location_distance_between($latlonA = array(), $latlonB = array(), $distance_unit = 'km'); +
|
||||
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
Given two points in lat/lon form, returns the distance between them.
|
||||
|
||||
@param $latlonA
|
||||
An associative array where
|
||||
'lon' => is a floating point of the longitude coordinate for the point given by latlonA
|
||||
'lat' => is a floating point of the latitude coordinate for the point given by latlonB
|
||||
|
||||
@param $latlonB
|
||||
Another point formatted like $latlonB
|
||||
|
||||
@param $distance_unit
|
||||
A string that is either 'km' or 'mile'.
|
||||
If neither 'km' or 'mile' is passed, the parameter is forced to 'km'
|
||||
|
||||
@return
|
||||
NULL if sense can't be made of the parameters.
|
||||
An associative array where
|
||||
'scalar' => Is the distance between the two lat/lon parameter points
|
||||
'distance_unit' => Is the unit of distance being represented by 'scalar'.
|
||||
This will be 'km' unless 'mile' is passed for the $distance_unit param
|
@@ -0,0 +1,37 @@
|
||||
|
||||
/**
|
||||
* Twiddle the province autocomplete whenever the user changes the country.
|
||||
*/
|
||||
(function ($) {
|
||||
Drupal.behaviors.location = {
|
||||
attach: function(context) {
|
||||
$('select.location_auto_country:not(.location-processed)', context).change(function(e) {
|
||||
var obj = this;
|
||||
var input = null;
|
||||
var result = this.className.match(/(location_auto_join_[^ ]*)/);
|
||||
if (result) {
|
||||
input = $('.location_auto_province.' + result)
|
||||
}
|
||||
else {
|
||||
// No joining class found, fallback to searching the immediate area.
|
||||
input = $('.location_auto_province', $(this).parents('fieldset:first, .views-exposed-form:first'))
|
||||
}
|
||||
|
||||
if (input && input.length) {
|
||||
//Unbind events on province field and empty its value
|
||||
input.unbind().val('');
|
||||
input.each(function(i) {
|
||||
//Get the (hidden) *-autocomplete input element
|
||||
var input_autocomplete = $('#' + this.id + '-autocomplete');
|
||||
// Update autocomplete url
|
||||
input_autocomplete.val(input_autocomplete.val().substr(0, input_autocomplete.val().lastIndexOf('/') + 1) + $(obj).val());
|
||||
// Mark as not processed.
|
||||
input_autocomplete.removeClass('autocomplete-processed');
|
||||
});
|
||||
// Reprocess.
|
||||
Drupal.behaviors.autocomplete.attach(document);
|
||||
}
|
||||
}).addClass('location-processed');
|
||||
}
|
||||
};
|
||||
})(jQuery);
|
@@ -0,0 +1 @@
|
||||
<?php print number_format($distance, 2) . ' ' . $shortunit; ?>
|
14
sites/all/modules/contrib/fields/location/location_node.info
Normal file
14
sites/all/modules/contrib/fields/location/location_node.info
Normal file
@@ -0,0 +1,14 @@
|
||||
name = Node Locations
|
||||
description = Associate locations with nodes.
|
||||
dependencies[] = location
|
||||
package = Location
|
||||
core = 7.x
|
||||
files[] = location_node.module
|
||||
files[] = location_node.install
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-02-18
|
||||
version = "7.x-3.x-dev"
|
||||
core = "7.x"
|
||||
project = "location"
|
||||
datestamp = "1329524299"
|
||||
|
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the location_node module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implentation of hook_uninstall().
|
||||
*/
|
||||
function location_node_uninstall() {
|
||||
// Delete node settings.
|
||||
$result = db_query("SELECT name FROM {variable} WHERE name LIKE 'location_settings_node_%'")->fetchCol();
|
||||
foreach ($result as $var) {
|
||||
variable_del($var);
|
||||
}
|
||||
|
||||
// Delete compatibility variables.
|
||||
$result = db_query("SELECT name FROM {variable} WHERE name LIKE 'location_maxnum_%'")->fetchCol();
|
||||
foreach ($result as $var) {
|
||||
variable_del($var);
|
||||
}
|
||||
$result = db_query("SELECT name FROM {variable} WHERE name LIKE 'location_defaultnum_%'")->fetchCol();
|
||||
foreach ($result as $var) {
|
||||
variable_del($var);
|
||||
}
|
||||
}
|
296
sites/all/modules/contrib/fields/location/location_node.module
Normal file
296
sites/all/modules/contrib/fields/location/location_node.module
Normal file
@@ -0,0 +1,296 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Associate locations with nodes.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_form_BASE_FORM_ID_alter().
|
||||
* Alter the node forms.
|
||||
*/
|
||||
function location_node_form_node_form_alter(&$form, &$form_state, $form_id) {
|
||||
// Add the Location fields on the node edit form.
|
||||
$node = $form['#node'];
|
||||
$settings = variable_get('location_settings_node_' . $node->type, array());
|
||||
if (isset($settings['multiple']['max']) && $settings['multiple']['max'] > 0) {
|
||||
if (!empty($form_state['rebuild']) && !empty($form_state['values']['locations'])) {
|
||||
$locations = $form_state['values']['locations'];
|
||||
}
|
||||
else {
|
||||
$locations = isset($node->locations) ? $node->locations : array();
|
||||
}
|
||||
$form['locations'] = location_form($settings, $locations);
|
||||
$form['locations']['#group'] = 'additional_settings';
|
||||
unset($form['locations']['collapsible']);
|
||||
unset($form['locations']['collapsed']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_node_revision_delete().
|
||||
*/
|
||||
function location_node_node_revision_delete($node) {
|
||||
if (location_node_node_locations_enabled($node->type)) {
|
||||
$locations = array();
|
||||
location_save_locations($locations, array('vid' => $node->vid));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_node_delete().
|
||||
*/
|
||||
function location_node_node_delete($node) {
|
||||
if (location_node_node_locations_enabled($node->type)) {
|
||||
$locations = array();
|
||||
location_save_locations($locations, array('vid' => $node->vid));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_node_load().
|
||||
*
|
||||
* @todo
|
||||
* Make this load all locations at once instead of running separate queries
|
||||
* for each node to enhance performance.
|
||||
* location_load_locations() and location_load_location() will need
|
||||
* changing to make this happen.
|
||||
*/
|
||||
function location_node_node_load($nodes, $types) {
|
||||
foreach ($nodes as $nid => $node) {
|
||||
$nodes[$nid]->locations = location_load_locations($node->vid);
|
||||
$nodes[$nid]->location = count($nodes[$nid]->locations) ? $nodes[$nid]->locations[0] : array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_node_insert().
|
||||
*/
|
||||
function location_node_node_insert($node) {
|
||||
if (location_node_node_locations_enabled($node->type)) {
|
||||
if (!empty($node->locations)) {
|
||||
location_save_locations($node->locations, array('nid' => $node->nid, 'vid' => $node->vid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_node_update().
|
||||
*/
|
||||
function location_node_node_update($node) {
|
||||
if (location_node_node_locations_enabled($node->type)) {
|
||||
if (!empty($node->locations)) {
|
||||
location_save_locations($node->locations, array('nid' => $node->nid, 'vid' => $node->vid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_node_view().
|
||||
*/
|
||||
function location_node_node_view($node, $view_mode) {
|
||||
$settings = variable_get('location_settings_node_' . $node->type, array());
|
||||
|
||||
if ($view_mode == 'rss') {
|
||||
$mode = isset($settings['rss']['mode']) ? $settings['rss']['mode'] : 'simple';
|
||||
if ($mode != 'none') {
|
||||
if (is_array($node->locations)) {
|
||||
foreach ($node->locations as $location) {
|
||||
if (($item = location_rss_item($location, $mode))) {
|
||||
$node->rss_elements[] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (variable_get('location_display_location', 1) && !empty($node->locations)) {
|
||||
if (isset($settings['display']['teaser']) && isset($settings['display']['full'])) {
|
||||
if (($view_mode == 'teaser' && $settings['display']['teaser']) || ($view_mode == 'full' && $settings['display']['full'])) {
|
||||
$node->content['locations'] = location_display($settings, $node->locations);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_locationapi().
|
||||
*/
|
||||
function location_node_locationapi(&$obj, $op, $a3 = NULL, $a4 = NULL, $a5 = NULL) {
|
||||
switch ($op) {
|
||||
case 'instance_links':
|
||||
foreach ($obj as $k => $v) {
|
||||
if ($v['nid'] != 0) {
|
||||
$node = node_load($v['nid']);
|
||||
$obj[$k]['href'] = 'node/' . $v['nid'];
|
||||
$obj[$k]['title'] = $node->title;
|
||||
$obj[$k]['type'] = t('Node location');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
* Alter the node_type_form form.
|
||||
*/
|
||||
function location_node_form_node_type_form_alter(&$form, &$form_state, $form_id) {
|
||||
$type = $form['#node_type']->type;
|
||||
|
||||
// Hook the form handlers so we can correctly extract our information;
|
||||
// the node type form doesn't handle nested values correctly.
|
||||
array_unshift($form['#validate'], 'location_node_settings_validate');
|
||||
//array_unshift($form['#submit'], 'node_type_form_submit');
|
||||
array_unshift($form['#submit'], '_location_node_type_save_submit');
|
||||
|
||||
$settings = variable_get('location_settings_node_'. $type, array());
|
||||
$form['location_settings'] = location_settings($settings);
|
||||
$form['location_settings']['#group'] = 'additional_settings';
|
||||
|
||||
// Tack on customizations for node settings.
|
||||
$form['location_settings']['display']['teaser'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Display location in teaser view'),
|
||||
'#default_value' => isset($settings['display']['teaser']) ? $settings['display']['teaser'] : TRUE,
|
||||
'#weight' => -2,
|
||||
);
|
||||
$form['location_settings']['display']['full'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Display location in full view'),
|
||||
'#default_value' => isset($settings['display']['full']) ? $settings['display']['full'] : TRUE,
|
||||
'#weight' => -1,
|
||||
);
|
||||
$form['location_settings']['rss'] = array(
|
||||
'#type' => 'fieldset',
|
||||
'#title' => t('RSS Settings'),
|
||||
'#description' => t('Here, you can change how locative data affects RSS feeds on nodes.'),
|
||||
'#tree' => TRUE,
|
||||
'#weight' => 5,
|
||||
);
|
||||
$form['location_settings']['rss']['mode'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('RSS mode'),
|
||||
'#description' => t('Select how to use locations in RSS feeds for this content type.'),
|
||||
'#options' => array(
|
||||
'none' => t('None (Do not put locational data in RSS feeds)'),
|
||||
'w3c' => t('W3C Geo (deprecated)'),
|
||||
'w3c_bugcompat' => t('Location 1.x-2.x compatible (buggy W3C)'),
|
||||
'simple' => t('GeoRSS-Simple'),
|
||||
'gml' => t('GeoRSS GML'),
|
||||
),
|
||||
'#default_value' => isset($settings['rss']['mode']) ? $settings['rss']['mode'] : 'simple',
|
||||
);
|
||||
|
||||
// Make the weights inaccessible if CCK is being used.
|
||||
if (module_exists('content')) {
|
||||
$form['location_settings']['form']['weight']['#type'] = 'value';
|
||||
$form['location_settings']['form']['weight']['#value'] = $form['location_settings']['form']['weight']['#default_value'];
|
||||
$form['location_settings']['display']['weight']['#type'] = 'value';
|
||||
$form['location_settings']['display']['weight']['#value'] = $form['location_settings']['display']['weight']['#default_value'];
|
||||
}
|
||||
|
||||
// @@@ THIS IS NOT GOOD. --Bdragon
|
||||
// clear the views cache in case anything was changed
|
||||
if (function_exists('views_invalidate_cache')) {
|
||||
views_invalidate_cache();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validation function for node settings form.
|
||||
* Logically, the default number of locations per node cannot
|
||||
* be bigger than the max locations.
|
||||
*
|
||||
* @ingroup $form
|
||||
*/
|
||||
function location_node_settings_validate($form, &$form_state) {
|
||||
if (!empty($form_state['values']['location_settings']['multiple']['max']) && empty($form_state['values']['location_settings']['multiple']['add'])) {
|
||||
form_error($form['location_settings']['multiple']['add'], t("You must have at least one empty location form enabled if you are going to allow locations to be submitted for nodes of this content type. If you don't intend to allow locations to be submitted for nodes of this content type, set the maximum number of locations allowed for this content type to 0."));
|
||||
}
|
||||
elseif ($form_state['values']['location_settings']['multiple']['max'] > 0) {
|
||||
if ($form_state['values']['location_settings']['multiple']['add'] > $form_state['values']['location_settings']['multiple']['max']) {
|
||||
form_error($form['location_settings']['multiple']['add'], t("You can't show more empty location forms than the maximum number of locations allowed for this content type."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom submit function to save location settings properly.
|
||||
*/
|
||||
function _location_node_type_save_submit($form, &$form_state) {
|
||||
variable_set('location_settings_node_' . $form_state['values']['type'], $form_state['values']['location_settings']);
|
||||
|
||||
// @@@ Backwards compatibility variables.
|
||||
// There are a few places in contrib where these variables are checked.
|
||||
variable_set('location_maxnum_' . $form_state['values']['type'], $form_state['values']['location_settings']['multiple']['max']);
|
||||
variable_set('location_defaultnum_' . $form_state['values']['type'], $form_state['values']['location_settings']['multiple']['add']);
|
||||
|
||||
// Prevent the "normal" submit handler from stomping our variable.
|
||||
unset($form_state['values']['location_settings']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter the content_field_overview_form form.
|
||||
*/
|
||||
function location_node_form_content_field_overview_form_alter(&$form, &$form_state) {
|
||||
$form['#submit'][] = 'location_node_content_extra_save';
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_content_extra_fields().
|
||||
*
|
||||
* For being able to edit location weight in node forms and node view.
|
||||
*/
|
||||
function location_node_content_extra_fields($type_name) {
|
||||
$settings = variable_get('location_settings_node_' . $type_name, array());
|
||||
if (isset($settings['multiple']) && $settings['multiple']['max'] > 0) {
|
||||
$weight = isset($settings['form']['weight']) ? $settings['form']['weight'] : 0;
|
||||
$extra['locations'] = array(
|
||||
'label' => t('Locations'),
|
||||
'description' => t('Node Locations module form.'),
|
||||
'weight' => $weight,
|
||||
);
|
||||
return $extra;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saving the fields management's weight for location node data in forms and node view
|
||||
*
|
||||
* @param $form
|
||||
* @param $form_state
|
||||
*/
|
||||
function location_node_content_extra_save($form, &$form_state) {
|
||||
$type = $form['#type_name'];
|
||||
// We need to stay in sync with CCK's idea of the weight.
|
||||
$settings = variable_get('location_settings_node_' . $type, array());
|
||||
if (isset($form_state['values']['locations'])) {
|
||||
$settings['form']['weight'] = $form_state['values']['locations']['weight'];
|
||||
$settings['display']['weight'] = $form_state['values']['locations']['weight'];
|
||||
}
|
||||
variable_set('location_settings_node_' . $type, $settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether or not node locations are enabled for a given node type.
|
||||
*
|
||||
* This is needed to stop location_node from deleting/inserting/updating
|
||||
* location_cck locations. This is not used for loading and viewing locations
|
||||
* because it is expected that cck locations will be loaded into
|
||||
* $node->locations.
|
||||
*
|
||||
* @param $type
|
||||
* The node type.
|
||||
*
|
||||
* @return
|
||||
* Boolean depending on whether or not node locations are enabled.
|
||||
*/
|
||||
function location_node_node_locations_enabled($type) {
|
||||
$settings = variable_get('location_settings_node_' . $type, array());
|
||||
// If max number of locations is zero it is disabled.
|
||||
if (!empty($settings) && isset($settings['multiple']['max']) && !empty($settings['multiple']['max'])) {
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
15
sites/all/modules/contrib/fields/location/location_user.info
Normal file
15
sites/all/modules/contrib/fields/location/location_user.info
Normal file
@@ -0,0 +1,15 @@
|
||||
name = User Locations
|
||||
description = Associate locations with users.
|
||||
dependencies[] = location
|
||||
package = Location
|
||||
core = 7.x
|
||||
files[] = location_user.module
|
||||
files[] = location_user.install
|
||||
configure = admin/config/people/accounts
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-02-18
|
||||
version = "7.x-3.x-dev"
|
||||
core = "7.x"
|
||||
project = "location"
|
||||
datestamp = "1329524299"
|
||||
|
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for the location_user module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implentation of hook_uninstall().
|
||||
*/
|
||||
function location_user_uninstall() {
|
||||
// Delete user settings.
|
||||
variable_del('location_settings_user');
|
||||
}
|
151
sites/all/modules/contrib/fields/location/location_user.module
Normal file
151
sites/all/modules/contrib/fields/location/location_user.module
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Associate locations with users.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_permission().
|
||||
*/
|
||||
function location_user_permission() {
|
||||
return array(
|
||||
'administer user locations' => array(
|
||||
'title' => t('administer user locations'),
|
||||
),
|
||||
'view own user location' => array(
|
||||
'title' => t('view own user location'),
|
||||
),
|
||||
'view all user locations' => array(
|
||||
'title' => t('view all user locations'),
|
||||
),
|
||||
'set own user location' => array(
|
||||
'title' => t('set own user location'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
* Alter the user_admin_settings form.
|
||||
*/
|
||||
function location_user_form_user_admin_settings_alter(&$form, &$form_state, $form_id) {
|
||||
if (isset($form_state['values']['location_settings_user'])) {
|
||||
$settings = $form_state['values']['location_settings_user'];
|
||||
}
|
||||
else {
|
||||
$settings = variable_get('location_settings_user', array());
|
||||
}
|
||||
|
||||
$form['location_settings_user'] = location_settings($settings);
|
||||
$form['location_settings_user']['#title'] = t('User locations');
|
||||
|
||||
$form['location_settings_user']['form']['register'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Collect during registration'),
|
||||
'#default_value' => isset($settings['form']['register']) ? $settings['form']['register'] : FALSE,
|
||||
'#weight' => -5,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_user_load().
|
||||
*
|
||||
* @todo
|
||||
* Make this load all locations at once instead of running separate queries
|
||||
* for each user to enhance performance.
|
||||
* location_load_locations() and location_load_location() will need
|
||||
* changing to make this happen.
|
||||
*/
|
||||
function location_user_user_load($users) {
|
||||
foreach ($users as $uid => $user) {
|
||||
$users[$uid]->locations = location_load_locations($user->uid, 'uid');
|
||||
$users[$uid]->location = count($users[$uid]->locations) ? $users[$uid]->locations[0] : array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_user_insert().
|
||||
*/
|
||||
function location_user_user_insert(&$edit, $account, $category) {
|
||||
if (!empty($edit['locations'])) {
|
||||
location_save_locations($edit['locations'], array('uid' => $account->uid));
|
||||
}
|
||||
unset($edit['locations']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_user_update().
|
||||
*/
|
||||
function location_user_user_update(&$edit, $account, $category) {
|
||||
if (!empty($edit['locations'])) {
|
||||
location_save_locations($edit['locations'], array('uid' => $account->uid));
|
||||
}
|
||||
unset($edit['locations']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_user_delete().
|
||||
*/
|
||||
function location_user_user_delete($account) {
|
||||
$locations = array();
|
||||
location_save_locations($locations, array('uid' => $account->uid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_user_view().
|
||||
*/
|
||||
function location_user_user_view($account, $view_mode, $langcode) {
|
||||
global $user;
|
||||
|
||||
if ((($user->uid == $account->uid) && user_access('view own user location')) || user_access('administer users') || user_access('view all user locations') || user_access('administer user locations')) {
|
||||
if (variable_get('location_display_location', 1) && isset($account->locations) && count($account->locations)) {
|
||||
$settings = variable_get('location_settings_user', array());
|
||||
$account->content['locations'] = location_display($settings, $account->locations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
* Alter the user profile form.
|
||||
*/
|
||||
function location_user_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
|
||||
global $user;
|
||||
|
||||
if ($form['#user_category'] == 'account') {
|
||||
$account = $form['#user'];
|
||||
if ((($user->uid == $account->uid) && user_access('set own user location')) || user_access('administer user locations')) {
|
||||
$settings = variable_get('location_settings_user', array());
|
||||
$form['locations'] = location_form($settings, $account->locations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
* Alter the user registration form.
|
||||
*/
|
||||
function location_user_form_user_register_form_alter(&$form, &$form_state, $form_id) {
|
||||
$settings = variable_get('location_settings_user', array());
|
||||
if (isset($settings['form']['register']) && $settings['form']['register']) {
|
||||
$form['locations'] = location_form($settings, array());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_locationapi().
|
||||
*/
|
||||
function location_user_locationapi(&$obj, $op, $a3 = NULL, $a4 = NULL, $a5 = NULL) {
|
||||
switch ($op) {
|
||||
case 'instance_links':
|
||||
foreach ($obj as $k => $v) {
|
||||
if ($v['uid'] != 0) {
|
||||
$account = user_load($v['uid']);
|
||||
$obj[$k]['href'] = 'user/' . $v['uid'];
|
||||
$obj[$k]['title'] = $account->name;
|
||||
$obj[$k]['type'] = t('User location');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
<?php if (!empty($locations)): ?>
|
||||
<h3 class="location-locations-header"><?php print format_plural(count($locations), 'Location', 'Locations'); ?></h3>
|
||||
<div class="location-locations-wrapper">
|
||||
<?php foreach ($locations as $location): ?>
|
||||
<?php print $location; ?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Creates a location context.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implement hook_[context_name]_ctools_contexts().
|
||||
*/
|
||||
function location_location_ctools_contexts() {
|
||||
return array(
|
||||
'title' => t('Location'),
|
||||
'description' => t('Location'),
|
||||
'context' => 'location_context_create_location',
|
||||
'context name' => 'location',
|
||||
'settings form' => 'location_context_location_settings_form',
|
||||
'keyword' => 'location',
|
||||
'context name' => 'location',
|
||||
'convert list' => 'location_context_location_convert_list',
|
||||
'convert' => 'location_context_location_convert',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a context, either from configuration or an argument on the URL.
|
||||
*
|
||||
* @param $empty
|
||||
* If true, just return an empty context.
|
||||
* @param $data
|
||||
* If from settings form, a form values array. If from argument, a string.
|
||||
* @param $conf
|
||||
* TRUE if the $data is coming from admin configuration, FALSE if it's
|
||||
* from a URL arg.
|
||||
*
|
||||
* @return
|
||||
* a Context object
|
||||
*/
|
||||
function location_context_create_location($empty, $data = NULL, $conf = FALSE) {
|
||||
$context = new ctools_context('location');
|
||||
$context->plugin = 'location';
|
||||
|
||||
if ($empty) {
|
||||
return $context;
|
||||
}
|
||||
|
||||
if ($conf) {
|
||||
$lid = is_array($data) && isset($data['lid']) ? $data['lid'] : (is_object($data) ? $data->lid : 0);
|
||||
if (is_array($data) || !empty($reload)) {
|
||||
$nid = $data['nid'];
|
||||
$data = location_load_location($lid);
|
||||
$data['nid'] = $nid;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($data)) {
|
||||
$context->data = $data;
|
||||
$context->title = $data['city'];
|
||||
$context->argument = $data['lid'];
|
||||
return $context;
|
||||
}
|
||||
}
|
||||
|
||||
function location_settings_form($conf, $external = FALSE) {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a list of ways that this context can be converted to a string.
|
||||
*/
|
||||
function location_context_location_convert_list() {
|
||||
$fields = location_field_names();
|
||||
$fields['country_name'] = t('Country name');
|
||||
$fields['province_name'] = t('State/Province name');
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a context into a string.
|
||||
*/
|
||||
function location_context_location_convert($context, $type) {
|
||||
switch ($type) {
|
||||
case 'name':
|
||||
case 'street':
|
||||
case 'additional':
|
||||
case 'city':
|
||||
case 'province':
|
||||
case 'postal_code':
|
||||
case 'country':
|
||||
case 'latitude':
|
||||
case 'longitude':
|
||||
case 'province_name':
|
||||
case 'country_name':
|
||||
if (isset($context->data[$type])) {
|
||||
return check_plain($context->data[$type]);
|
||||
}
|
||||
|
||||
default:
|
||||
return t('Unknown location keyword');
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Plugin to provide an relationship handler for location data from node.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implement hook_[relationship_name]_ctools_relationships().
|
||||
*/
|
||||
function location_location_from_node_ctools_relationships() {
|
||||
return array(
|
||||
'title' => t('Node location'),
|
||||
'keyword' => 'location',
|
||||
'description' => t('Creates a location context from a node.'),
|
||||
'required context' => new ctools_context_required(t('Node'), 'node'),
|
||||
'context' => 'location_location_from_node_context',
|
||||
'settings form' => 'location_location_from_node_settings_form',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new location context based on a node context.
|
||||
*
|
||||
* This does all the magic from the relationship settings to select if we're
|
||||
* dealing with a location_node field or a location_cck field, what field
|
||||
* offset to use, etc.
|
||||
*
|
||||
* @param $context
|
||||
* The node context we're creating a relationship context out of.
|
||||
* @param $conf
|
||||
* The configuration settings for this relationship.
|
||||
*
|
||||
* @return
|
||||
* Either a valid location context object based on the given node and the
|
||||
* currently active configuration settings, an empty context object
|
||||
* (e.g. for configuration in the Panels admin UI), or NULL in case the
|
||||
* given node context does not contain valid location data matching the
|
||||
* current relationship settings.
|
||||
*/
|
||||
function location_location_from_node_context($context, $conf) {
|
||||
// If unset it wants a generic, unfilled context, which is just NULL.
|
||||
if (empty($context->data)) {
|
||||
$new_context = ctools_context_create_empty('location', NULL);
|
||||
}
|
||||
|
||||
// Grab the right location data based on the relationship settings.
|
||||
if (isset($conf['location_type'])) {
|
||||
if ($conf['location_type'] == 'location_node' && isset($context->data->locations)) {
|
||||
$location_offset = isset($conf['location_node_offset']) ? $conf['location_node_offset'] : 0;
|
||||
$location = $context->data->locations[$location_offset];
|
||||
}
|
||||
elseif ($conf['location_type'] == 'location_cck' && isset($conf['location_cck_field_name'])) {
|
||||
$field_name = $conf['location_cck_field_name'];
|
||||
$field_offset = isset($conf['location_cck_field_offset']) ? $conf['location_cck_field_offset'] : 0;
|
||||
if (isset($context->data->{$field_name}[$field_offset]['lid'])) {
|
||||
$location = $context->data->{$field_name}[$field_offset];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($location)) {
|
||||
$location['nid'] = $context->data->nid;
|
||||
$new_context = ctools_context_create('location', $location);
|
||||
}
|
||||
|
||||
if (!empty($new_context)) {
|
||||
return $new_context;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings form for the location relationship.
|
||||
*
|
||||
* Before we can create a CTools context for the relationship attached to a
|
||||
* node, we need to know what kind of location we're looking for. So, the
|
||||
* relationship settings form tries to figure out if the site is using
|
||||
* location_node or location_cck.
|
||||
*
|
||||
* If only location_node is enabled, the only thing we have to handle is the
|
||||
* case where there are multiple locations attached to nodes, so the only
|
||||
* settings form element is the location offset to use (which defaults to 0
|
||||
* for the first location in the node).
|
||||
*
|
||||
* If only location_cck is enabled, we see if there are any Location CCK
|
||||
* fields defined on any content types and present all of those as options for
|
||||
* the admin to select which Location CCK field should be used for the
|
||||
* relationship. Again, to handle multi-valued fields, we need to ask for an
|
||||
* offset.
|
||||
*
|
||||
* If both location_node and location_cck are enabled, the form presents two
|
||||
* radio buttons so the user selects which kind of location field they want to
|
||||
* use for the relationship, and we use the magic of CTools #dependency to
|
||||
* conditionally show/hide the appropriate sub-settings based on the currently
|
||||
* selected radio.
|
||||
*
|
||||
* @param $conf
|
||||
* Array of existing configuration options for this relationship.
|
||||
*
|
||||
* @return
|
||||
* FormAPI array of settings form elements.
|
||||
*/
|
||||
function location_location_from_node_settings_form($conf) {
|
||||
ctools_include('dependent');
|
||||
$location_type_options = array();
|
||||
$offset_options = array();
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$offset_options[$i] = $i;
|
||||
}
|
||||
|
||||
if (module_exists('location_node')) {
|
||||
$location_type_options['location_node'] = t('Use location directly saved in the node for this relationship');
|
||||
|
||||
$form['location_node_offset'] = array(
|
||||
'#title' => t('Node location offset'),
|
||||
'#type' => 'select',
|
||||
'#options' => $offset_options,
|
||||
'#default_value' => isset($conf['location_node_offset']) ? $conf['location_node_offset'] : 0,
|
||||
'#description' => t('If the nodes that will be used for this relationship have multiple locations, select which location you want to use.'),
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('radio:relationship[relationship_settings][location_type]' => array('location_node')),
|
||||
'#weight' => 4,
|
||||
);
|
||||
}
|
||||
if (module_exists('location_cck')) {
|
||||
$cck_options = array();
|
||||
foreach (content_fields() as $field) {
|
||||
if ($field['type'] == 'location') {
|
||||
$cck_options[$field['field_name']] = t($field['widget']['label']);
|
||||
}
|
||||
}
|
||||
if (!empty($cck_options)) {
|
||||
$form['location_cck_field_name'] = array(
|
||||
'#title' => t('Location CCK field to use for this relationship'),
|
||||
'#type' => 'select',
|
||||
'#options' => $cck_options,
|
||||
'#default_value' => isset($conf['location_cck_field_name']) ? $conf['location_cck_field_name'] : '',
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('radio:relationship[relationship_settings][location_type]' => array('location_cck')),
|
||||
'#prefix' => '<div class="clear-block">',
|
||||
'#suffix' => '</div>',
|
||||
'#weight' => 6,
|
||||
);
|
||||
|
||||
$form['location_cck_field_offset'] = array(
|
||||
'#title' => t('Location CCK field offset'),
|
||||
'#type' => 'select',
|
||||
'#options' => $offset_options,
|
||||
'#default_value' => isset($conf['location_cck_field_offset']) ? $conf['location_cck_field_offset'] : 0,
|
||||
'#description' => t('If the nodes that will be used for this relationship have multiple locations, select which location you want to use.'),
|
||||
'#process' => array('ctools_dependent_process'),
|
||||
'#dependency' => array('radio:relationship[relationship_settings][location_type]' => array('location_cck')),
|
||||
'#weight' => 7,
|
||||
'#prefix' => '<div class="clear-block">',
|
||||
'#suffix' => '</div>',
|
||||
);
|
||||
|
||||
// Since we have valid Location CCK fields on the site, present this as
|
||||
// an option for the location relationship.
|
||||
$location_type_options['location_cck'] = t('Use location CCK fields for this relationship');
|
||||
}
|
||||
}
|
||||
if (isset($location_type_options)) {
|
||||
if (count($location_type_options) > 1) {
|
||||
$form['location_type'] = array(
|
||||
'#title' => t('Location type'),
|
||||
'#type' => 'radios',
|
||||
'#options' => $location_type_options,
|
||||
'#default_value' => isset($conf['location_type']) ? $conf['location_type'] : '',
|
||||
'#weight' => 2,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$form['location_type'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => reset(array_keys($location_type_options)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
// Ascension Island
|
||||
|
||||
function location_province_list_ac() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns minimum and maximum latitude and longitude needed to create a bounding box.
|
||||
*/
|
||||
function location_bounds_ac() {
|
||||
// NaturalEarth 10m Admin 0 - Countries (v1.3.0)
|
||||
// Bounds manually eyeballed by bdragon in EPSG:4326 using the coordinate
|
||||
// readout in udig, because the poly is grouped with Saint Helena.
|
||||
return array(
|
||||
'minlng' => -14.4278,
|
||||
'minlat' => -7.9875,
|
||||
'maxlng' => -14.2581,
|
||||
'maxlat' => -7.8630,
|
||||
);
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
// Andorra
|
||||
|
||||
function location_province_list_ad() {
|
||||
return array('ALV' => "Andorra la Vella",
|
||||
'CAN' => "Canillo",
|
||||
'ENC' => "Encamp",
|
||||
'ESE' => "Escaldes-Engordany",
|
||||
'LMA' => "La Massana",
|
||||
'ORD' => "Ordino",
|
||||
'SJL' => "Sant Julia de L<>ria");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns minimum and maximum latitude and longitude needed to create a bounding box.
|
||||
*/
|
||||
function location_bounds_ad() {
|
||||
return array(
|
||||
'minlng' => 1.3726,
|
||||
'minlat' => 42.404867,
|
||||
'maxlng' => 1.781219,
|
||||
'maxlat' => 42.621636,
|
||||
);
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
// United Arab Emirates
|
||||
|
||||
function location_province_list_ae() {
|
||||
return array('AZ' => "Abu Zaby",
|
||||
'AJ' => "'Ajman",
|
||||
'FU' => "Al Fujayrah",
|
||||
'SH' => "Ash Shariqah",
|
||||
'DU' => "Dubayy",
|
||||
'RK' => "R'as al Khaymah",
|
||||
'UQ' => "Umm al Qaywayn");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns minimum and maximum latitude and longitude needed to create a bounding box.
|
||||
*/
|
||||
function location_bounds_ae() {
|
||||
return array(
|
||||
'minlng' => 50.7756,
|
||||
'minlat' => 22.540493,
|
||||
'maxlng' => 56.3684,
|
||||
'maxlat' => 26.241233,
|
||||
);
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
// Afghanistan
|
||||
|
||||
function location_province_list_af() {
|
||||
return array('BDS' => "Badakhshan province",
|
||||
'BDG' => "Badghis province",
|
||||
'BGL' => "Baghlan province",
|
||||
'BAL' => "Balkh province",
|
||||
'BAM' => "Bamian province",
|
||||
'FRA' => "Farah province",
|
||||
'FYB' => "Faryab province",
|
||||
'GHA' => "Ghazni province",
|
||||
'GHO' => "Ghowr province",
|
||||
'HEL' => "Helmand province",
|
||||
'HER' => "Herat province",
|
||||
'JOW' => "Jowzjan province",
|
||||
'KAB' => "Kabul province",
|
||||
'KAN' => "Kandahar province",
|
||||
'KAP' => "Kapisa province",
|
||||
'KHO' => "Khost province",
|
||||
'KNR' => "Konar province",
|
||||
'KDZ' => "Kondoz province",
|
||||
'LAG' => "Laghman province",
|
||||
'LOW' => "Lowgar province",
|
||||
'NAN' => "Nangrahar province",
|
||||
'NIM' => "Nimruz province",
|
||||
'NUR' => "Nurestan province",
|
||||
'ORU' => "Oruzgan province",
|
||||
'PIA' => "Paktia province",
|
||||
'PKA' => "Paktika province",
|
||||
'PAR' => "Parwan province",
|
||||
'SAM' => "Samangan province",
|
||||
'SAR' => "Sar-e Pol province",
|
||||
'TAK' => "Takhar province",
|
||||
'WAR' => "Wardak province",
|
||||
'ZAB' => "Zabol province");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns minimum and maximum latitude and longitude needed to create a bounding box.
|
||||
*/
|
||||
function location_bounds_af() {
|
||||
return array(
|
||||
'minlng' => 60.5054,
|
||||
'minlat' => 29.612733,
|
||||
'maxlng' => 74.93195,
|
||||
'maxlat' => 38.538967,
|
||||
);
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
// Antigua and Barbuda
|
||||
|
||||
function location_province_list_ag() {
|
||||
return array('ASG' => "Saint George",
|
||||
'ASJ' => "Saint John",
|
||||
'ASM' => "Saint Mary",
|
||||
'ASL' => "Saint Paul",
|
||||
'ASR' => "Saint Peter",
|
||||
'ASH' => "Saint Philip",
|
||||
'BAR' => "Barbuda",
|
||||
'RED' => "Redonda");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns minimum and maximum latitude and longitude needed to create a bounding box.
|
||||
*/
|
||||
function location_bounds_ag() {
|
||||
return array(
|
||||
'minlng' => -61.89365,
|
||||
'minlat' => 16.9478,
|
||||
'maxlng' => -61.64325,
|
||||
'maxlat' => 17.735533,
|
||||
);
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
// Anguilla
|
||||
|
||||
function location_province_list_ai() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns minimum and maximum latitude and longitude needed to create a bounding box.
|
||||
*/
|
||||
function location_bounds_ai() {
|
||||
return array(
|
||||
'minlng' => -63.1879,
|
||||
'minlat' => 18.137033,
|
||||
'maxlng' => -62.9537,
|
||||
'maxlat' => 18.248633,
|
||||
);
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
// Albania
|
||||
|
||||
function location_province_list_al() {
|
||||
return array('BR' => "Berat",
|
||||
'BU' => "Bulqize",
|
||||
'DL' => "Delvine",
|
||||
'DV' => "Devoll",
|
||||
'DI' => "Diber",
|
||||
'DR' => "Durres",
|
||||
'EL' => "Elbasan",
|
||||
'ER' => "Kolonje",
|
||||
'FR' => "Fier",
|
||||
'GJ' => "Gjirokaster",
|
||||
'GR' => "Gramsh",
|
||||
'HA' => "Has",
|
||||
'KA' => "Kavaje",
|
||||
'KB' => "Kurbin",
|
||||
'KC' => "Kucove",
|
||||
'KO' => "Korce",
|
||||
'KR' => "Kruje",
|
||||
'KU' => "Kukes",
|
||||
'LB' => "Librazhd",
|
||||
'LE' => "Lezhe",
|
||||
'LU' => "Lushnje",
|
||||
'MM' => "Malesi e Madhe",
|
||||
'MK' => "Mallakaster",
|
||||
'MT' => "Mat",
|
||||
'MR' => "Mirdite",
|
||||
'PQ' => "Peqin",
|
||||
'PR' => "Permet",
|
||||
'PG' => "Pogradec",
|
||||
'PU' => "Puke",
|
||||
'SH' => "Shkoder",
|
||||
'SK' => "Skrapar",
|
||||
'SR' => "Sarande",
|
||||
'TE' => "Tepelene",
|
||||
'TP' => "Tropoje",
|
||||
'TR' => "Tirane",
|
||||
'VL' => "Vlore");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns minimum and maximum latitude and longitude needed to create a bounding box.
|
||||
*/
|
||||
function location_bounds_al() {
|
||||
return array(
|
||||
'minlng' => 19.29795,
|
||||
'minlat' => 39.713733,
|
||||
'maxlng' => 21.072,
|
||||
'maxlat' => 42.7006,
|
||||
);
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
// Armenia
|
||||
|
||||
function location_province_list_am() {
|
||||
return array('AGT' => "Aragatsotn",
|
||||
'ARR' => "Ararat",
|
||||
'ARM' => "Armavir",
|
||||
'GEG' => "Geghark'unik'",
|
||||
'KOT' => "Kotayk'",
|
||||
'LOR' => "Lorri",
|
||||
'SHI' => "Shirak",
|
||||
'SYU' => "Syunik'",
|
||||
'TAV' => "Tavush",
|
||||
'VAY' => "Vayots' Dzor",
|
||||
'YER' => "Yerevan");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns minimum and maximum latitude and longitude needed to create a bounding box.
|
||||
*/
|
||||
function location_bounds_am() {
|
||||
return array(
|
||||
'minlng' => 43.4194,
|
||||
'minlat' => 38.9416,
|
||||
'maxlng' => 46.5982,
|
||||
'maxlat' => 41.3796,
|
||||
);
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
// Netherlands Antilles
|
||||
|
||||
function location_province_list_an() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns minimum and maximum latitude and longitude needed to create a bounding box.
|
||||
*/
|
||||
function location_bounds_an() {
|
||||
return array(
|
||||
'minlng' => -69.16155,
|
||||
'minlat' => 11.711233,
|
||||
'maxlng' => -66.13465,
|
||||
'maxlat' => 12.397367,
|
||||
);
|
||||
}
|
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
// Angola
|
||||
|
||||
function location_province_list_ao() {
|
||||
return array('BGO' => "Bengo",
|
||||
'BGU' => "Benguela province",
|
||||
'BIE' => "Bie",
|
||||
'CAB' => "Cabinda",
|
||||
'CCU' => "Cuando-Cubango",
|
||||
'CNO' => "Cuanza Norte",
|
||||
'CUS' => "Cuanza Sul",
|
||||
'CNN' => "Cunene",
|
||||
'HUA' => "Huambo province",
|
||||
'HUI' => "Huila province",
|
||||
'LUA' => "Luanda",
|
||||
'LNO' => "Lunda Norte",
|
||||
'LSU' => "Lunda Sul",
|
||||
'MAL' => "Malange",
|
||||
'MOX' => "Moxico",
|
||||
'NAM' => "Namibe",
|
||||
'UIG' => "Uige",
|
||||
'ZAI' => "Zaire");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns minimum and maximum latitude and longitude needed to create a bounding box.
|
||||
*/
|
||||
function location_bounds_ao() {
|
||||
return array(
|
||||
'minlng' => 11.57905,
|
||||
'minlat' => -18.112767,
|
||||
'maxlng' => 24.1105,
|
||||
'maxlat' => -4.424667,
|
||||
);
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
// Antarctica
|
||||
|
||||
function location_province_list_aq() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns minimum and maximum latitude and longitude needed to create a bounding box.
|
||||
*/
|
||||
function location_bounds_aq() {
|
||||
return array(
|
||||
'minlng' => -179.999427042259,
|
||||
'minlat' => -89.9,
|
||||
'maxlng' => 179.999427042256,
|
||||
'maxlat' => -60.9997330347133,
|
||||
);
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
// Argentina
|
||||
|
||||
function location_province_list_ar() {
|
||||
return array('A' => "Salta",
|
||||
'B' => "Buenos Aires Province",
|
||||
'C' => "Distrito Federal",
|
||||
'D' => "San Luis",
|
||||
'E' => "Entre Rios",
|
||||
'F' => "La Rioja",
|
||||
'G' => "Santiago del Estero",
|
||||
'H' => "Chaco",
|
||||
'J' => "San Juan",
|
||||
'K' => "Catamarca",
|
||||
'L' => "La Pampa",
|
||||
'M' => "Mendoza",
|
||||
'N' => "Misiones",
|
||||
'P' => "Formosa",
|
||||
'Q' => "Neuquen",
|
||||
'R' => "Rio Negro",
|
||||
'S' => "Santa Fe",
|
||||
'T' => "Tucuman",
|
||||
'U' => "Chubut",
|
||||
'V' => "Tierra del Fuego",
|
||||
'W' => "Corrientes",
|
||||
'X' => "Cordoba",
|
||||
'Y' => "Jujuy",
|
||||
'Z' => "Santa Cruz");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns minimum and maximum latitude and longitude needed to create a bounding box.
|
||||
*/
|
||||
function location_bounds_ar() {
|
||||
return array(
|
||||
'minlng' => -73.4967,
|
||||
'minlat' => -55.049767,
|
||||
'maxlng' => -53.64205,
|
||||
'maxlat' => -21.829967,
|
||||
);
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
// American Samoa
|
||||
|
||||
function location_province_list_as() {
|
||||
return array('E' => "Eastern",
|
||||
'M' => "Manu'a",
|
||||
'R' => "Rose Island",
|
||||
'S' => "Swains Island",
|
||||
'W' => "Western");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns minimum and maximum latitude and longitude needed to create a bounding box.
|
||||
*/
|
||||
function location_bounds_as() {
|
||||
return array(
|
||||
'minlng' => -170.9021,
|
||||
'minlat' => -14.541433,
|
||||
'maxlng' => -168.23395,
|
||||
'maxlat' => -14.183633,
|
||||
);
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
// Austria
|
||||
|
||||
function location_province_list_at() {
|
||||
return array(
|
||||
'BUR' => "Burgenland",
|
||||
'KAR' => "Kärnten",
|
||||
'NOS' => "Niederösterreich",
|
||||
'OOS' => "Oberösterreich",
|
||||
'SAL' => "Salzburg",
|
||||
'STE' => "Steiermark",
|
||||
'TIR' => "Tirol",
|
||||
'VOR' => "Vorarlberg",
|
||||
'WIE' => "Wien",
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns minimum and maximum latitude and longitude needed to create a bounding box.
|
||||
*/
|
||||
function location_bounds_at() {
|
||||
return array(
|
||||
'minlng' => 9.47885,
|
||||
'minlat' => 46.427367,
|
||||
'maxlng' => 17.15825,
|
||||
'maxlat' => 49.010433,
|
||||
);
|
||||
}
|
@@ -0,0 +1,507 @@
|
||||
<?php
|
||||
|
||||
// Australia
|
||||
|
||||
/**
|
||||
* Returns a lat/lon pair of the approximate center of the given postal code in the given country
|
||||
*
|
||||
* @param $location
|
||||
* An associative array $location where
|
||||
* 'street' => the street portion of the location
|
||||
* 'supplemental' => additional street portion of the location
|
||||
* 'province' => the province, state, or territory
|
||||
* 'country' => lower-cased two-letter ISO code (REQUIRED)
|
||||
* 'postal_code' => the international postal code for this location (REQUIRED)
|
||||
*
|
||||
* @return
|
||||
* An associative array where
|
||||
* 'lat' => approximate latitude of the center of the postal code's area
|
||||
* 'lon' => approximate longitude of the center of the postal code's area
|
||||
*
|
||||
*/
|
||||
function location_latlon_rough_au($location = array()) {
|
||||
if (!isset($location['postal_code'])) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$row = db_query("SELECT latitude, longitude FROM {zipcodes} WHERE country = :country AND zip = :zip", array(':country' => $location['country'], ':zip' => substr(str_pad($location['postal_code'], 4, '0', STR_PAD_LEFT), 0, 4)))->fetchObject();
|
||||
|
||||
if ($row) {
|
||||
return array('lat' => $row->latitude, 'lon' => $row->longitude);
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a lat/lon pair of the approximate center of the given postal code in the given country
|
||||
*
|
||||
* @param $location
|
||||
* An associative array $location where only postal code and country are necessary, but can have the keys:
|
||||
* 'street' => the street portion of the location
|
||||
* 'supplemental' => additional street portion of the location
|
||||
* 'province' => the province, state, or territory
|
||||
* 'country' => lower-cased two-letter ISO code (REQUIRED)
|
||||
* 'postal_code' => the international postal code for this location (REQUIRED)
|
||||
*
|
||||
* @return
|
||||
* An associative array where
|
||||
* 'lat' => approximate latitude of the center of the postal code's area
|
||||
* 'lon' => approximate longitude of the center of the postal code's area
|
||||
*
|
||||
*/
|
||||
function _location_latlon_postalcode_au($location = array()) {
|
||||
$dash_index = strpos($location['postal_code'], '-');
|
||||
// First we strip slash off if we're dealing with a 8-digit AU zipcode
|
||||
if (!($dash_index === FALSE)) {
|
||||
$location['postal_code'] = substr($location['postal_code'], 0, $dash_index);
|
||||
}
|
||||
|
||||
// Now we pad the thing and query.
|
||||
$row = db_query("SELECT * FROM {zipcodes} where country = :country AND zip = :zip", array(':country' => $location['country'], ':zip' => str_pad($location['postal_code'], 4, "0", STR_PAD_LEFT)))->fetchObject();
|
||||
if ($row) {
|
||||
return array('lat' => $row->latitude, 'lon' => $row->longitude, 'city' => $row->city, 'province' => $row->state, 'country' => $row->country);
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameters:
|
||||
* An associative array $location where
|
||||
* 'street' => the street portion of the location
|
||||
* 'supplemental' => additional street portion of the location
|
||||
* 'province' => the province, state, or territory
|
||||
* 'country' => lower-cased two-letter ISO code (REQUIRED)
|
||||
* 'postal_code' => the international postal code for this location (REQUIRED)
|
||||
*
|
||||
*
|
||||
*/
|
||||
function location_latlon_exact_au($location = array()) {
|
||||
return NULL;
|
||||
// By uncommenting the line of code below, you legally acknowledge that you understand that you can only
|
||||
// do so under the terms of the Non-Commercial Share-alike license described at http://creativecommons.org/licenses/by-nc-sa/2.0/
|
||||
//return _location_latlon_exact_us_geocoder($location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls up a web-service to retrieve a lat/lon pair for a full, correct U.S. location.
|
||||
*
|
||||
* @param $location
|
||||
* An associative array that represents an location where
|
||||
* 'street' => is the street location
|
||||
* 'supplemental' => any supplemental portion to the street location
|
||||
* 'city' => city name
|
||||
* 'province' => state, province, or territorial abbreviation
|
||||
* 'postal_code' => postal code
|
||||
*
|
||||
* @return
|
||||
* An associative array where
|
||||
* 'lat' => Is a float value in latitude
|
||||
* 'lon' => Is a float value in longitude
|
||||
* If the location supplied does not provide enough information, NULL is returned.
|
||||
* "Enough information" means that there is either
|
||||
* (a valid 'street' AND valid 'postal_code') OR (valid 'street' AND valid 'city' AND valid 'province')
|
||||
*/
|
||||
function _location_latlon_exact_au_geocoder($location = array()) {
|
||||
$location_string = '';
|
||||
if (isset($location['street']) && trim($location['street']) != '') {
|
||||
if (isset($location['postal_code'])) {
|
||||
$location_string = $location['street'] .' '. $location['postal_code'];
|
||||
}
|
||||
elseif (isset($location['city']) && isset($location['province']) && trim($location['city']) != '' && trim($location['province'])) {
|
||||
$location_string = $location['street'] .', '. $location['city'] .', '. $location['province'];
|
||||
}
|
||||
else { // else geocoder.us won't do bidness with you!
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$result = xmlrpc('http://rpc.geocoder.us/service/xmlrpc', array('geocode' => array($location_string)));
|
||||
|
||||
if (is_array($result) && is_array($result[0]) && isset($result[0]['lat']) && is_numeric($result[0]['lat']) && isset($result[0]['long']) && is_numeric($result[0]['long'])) {
|
||||
return array('lat' => $result[0]['lat'], 'lon' => $result[0]['long']);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
function location_map_link_au_yahoo($location = array()) {
|
||||
$get_query = '?';
|
||||
if (isset($location['street'])) {
|
||||
$get_query .= 'addr='. urlencode($location['street']) .'&';
|
||||
}
|
||||
if ($location['province'] != '' || $location['city'] != '' || $location['postal_code'] != '') {
|
||||
$get_query .= 'csz='. _location_au_yahoo_csz_get_field($location) .'&';
|
||||
}
|
||||
$get_query .= 'country='. urlencode($location['country']);
|
||||
return ('http://maps.yahoo.com/maps_result'. $get_query);
|
||||
}
|
||||
|
||||
function location_map_link_au_google($location = array()) {
|
||||
$query_params = array();
|
||||
|
||||
foreach (array('street', 'city', 'province', 'postal_code', 'country') as $field) {
|
||||
if (isset($location[$field])) {
|
||||
$query_params[] = $location[$field];
|
||||
}
|
||||
}
|
||||
|
||||
if (count($query_params)) {
|
||||
return ('http://maps.google.com?q='. urlencode(implode(", ", $query_params)));
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
function location_map_link_au_mapquest($location = array()) {
|
||||
if (isset($location['street'])) {
|
||||
$get_query .= 'address='. urlencode($location['street']) .'&';
|
||||
}
|
||||
|
||||
if (isset($location['city'])) {
|
||||
$get_query .= 'city='. urlencode($location['city']) .'&';
|
||||
}
|
||||
|
||||
if (isset($location['province'])) {
|
||||
$get_query .= 'state='. urlencode($location['province']) .'&';
|
||||
}
|
||||
|
||||
if (isset($location['postal_code'])) {
|
||||
$get_query .= 'zipcode='. urlencode($location['postal_code']);
|
||||
}
|
||||
if (strlen($get_query)) {
|
||||
return 'http://www.mapquest.com/maps/map.adp?searchtype=address&country=AU&'. $get_query;
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* An array where
|
||||
* -> the key is the word that helps identify the name of function that builds the link. For example, a key of 'yahoo' means the name of the
|
||||
* the function that builds a link to a map on Yahoo! Maps would be 'location_map_link_us_yahoo'
|
||||
* -> the value is itself an array with 3 key/value pairs:
|
||||
* 'name' => points to the name of the mapping service. For 'yahoo', this would be 'Yahoo! Maps'
|
||||
* 'url' => the url of the main page of the mapping service. For 'yahoo', this would be 'http://maps.yahoo.com'
|
||||
* 'tos' => the url of the page that explains the map providers Terms of Service, or Terms of Use. For 'yahoo', this would be
|
||||
* 'http://help.yahoo.com/help/us/maps/maps-24.html'
|
||||
*/
|
||||
function location_map_link_au_providers() {
|
||||
return array('google' => array('name' => 'Google Maps', 'url' => 'http://maps.google.com', 'tos' => 'http://www.google.com/help/terms_local.html'),
|
||||
'yahoo' => array('name' => 'Yahoo! Maps', 'url' => 'http://maps.yahoo.com', 'tos' => 'http://help.yahoo.com/help/us/maps/maps-24.html'),
|
||||
'mapquest' => array('name' => 'MapQuest', 'url' => 'http://www.mapquest.com', 'tos' => 'http://www.mapquest.com/features/main.adp?page=legal')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* An array of values that work as keys to the array returned by location_map_link_us_providers. The idea is that if the
|
||||
* administrator of the site has not yet had a chance to visit the "Map Links" subtab on the location module's settings page,
|
||||
* that we can provide deep-linking to a relatively safe default. By 'relatively safe', we mean that the Terms Of Service of
|
||||
* the provider of the maps are flexible enough for most parties.
|
||||
*
|
||||
* For the case of the U.S., 'google' has relatively flexible Terms Of Service, whereas Yahoo! Maps and MapQuest have more
|
||||
* restrictive Terms Of Service.
|
||||
*
|
||||
*/
|
||||
function location_map_link_au_default_providers() {
|
||||
return array('google');
|
||||
}
|
||||
|
||||
function location_geocode_au_providers() {
|
||||
return array(
|
||||
'yahoo' => array('name' => 'Yahoo! Maps Web Services', 'url' => 'http://developer.yahoo.com/maps/rest/V1/geocode.html', 'tos' => 'http://developer.yahoo.com/maps/mapsTerms.html'),
|
||||
);
|
||||
}
|
||||
|
||||
function location_geocode_au_yahoo_settings() {
|
||||
$form = array();
|
||||
|
||||
$form['location_geocode_au_yahoo_appid'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Yahoo! Web Services Application ID'),
|
||||
'#size' => 64,
|
||||
'#maxlength' => 128,
|
||||
'#default_value' => variable_get('location_geocode_au_yahoo_appid', 'YahooDemo'),
|
||||
'#description' => t('Unless you are using this site to test and develop, you will need to obtain a Yahoo! Web Services Application ID from the %network_link. If you are using for development and testing purposes, you can use \'YahooDemo\' as your AppID. When getting an Application ID from Yahoo!, please also be sure to review the %usage_policy.', array('%network_link' => '<a href="http://api.search.yahoo.com/webservices/register_application">Yahoo! Developer Network</a>', '%usage_policy' => '<a href="http://developer.yahoo.com/usagePolicy/index.html">usage policy</a>'))
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
function location_geocode_au_yahoo($location = array()) {
|
||||
$service_url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=". variable_get('location_geocode_au_yahoo_appid', "YahooDemo") ."&location=";
|
||||
|
||||
$address = location_address2singleline($location);
|
||||
|
||||
$http_reply = drupal_http_request($service_url . urlencode($address));
|
||||
|
||||
// address may have been improperly formatted or invalid
|
||||
if ($http_reply->code == 400) {
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
// got a successful reply, but we only want to return if we have address-level precision
|
||||
$matches = array();
|
||||
preg_match('/precision="([a-z]*)"/', $http_reply->data, $matches);
|
||||
|
||||
if ($matches[1] != 'address') {
|
||||
// The precision we got back was not down to the street-address level
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
$lat_match = array();
|
||||
$lon_match = array();
|
||||
$latlon = array();
|
||||
|
||||
if (preg_match('/<Latitude>(.*)<\/Latitude>/', $http_reply->data, $lat_match)) {
|
||||
$latlon['lat'] = $lat_match[1];
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
if (preg_match('/<Longitude>(.*)<\/Longitude>/', $http_reply->data, $lon_match)) {
|
||||
$latlon['lon'] = $lon_match[1];
|
||||
|
||||
return $latlon;
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameters:
|
||||
* -> $location_a is an associative array that represents a full location where
|
||||
* 'street' => the street portions of the location
|
||||
* 'supplemental' => additional street portion of the location
|
||||
* 'province' => the province, state, or territory
|
||||
* 'country' => lower-cased two-letter ISO code (REQUIRED)
|
||||
* -> $location_b is associative array that represents a full location in the same way that
|
||||
* parameter $location_b does.
|
||||
*
|
||||
* Returns: a link to driving directions
|
||||
*
|
||||
* For now, assume site-admin wants American driving directions linked to Yahoo! Driving Directions.
|
||||
* Maybe later, we can add some kind of country-specific settings page that allows the site-admin to
|
||||
* decide which site to link to for driving directions.
|
||||
*/
|
||||
function location_driving_directions_link_au($location_a, $location_b) {
|
||||
return _location_driving_directions_link_au_yahoo($location_a, $location_b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameters:
|
||||
* Function that is called by location_driving_directions_link_au() under assumption that it
|
||||
* is the chosen function
|
||||
*
|
||||
* Returns:
|
||||
* a URL with HTTP GET variables
|
||||
* Depending on how full the locationes are, the URL will either point to the driving directions
|
||||
* on Yahoo! or, if only partial locationes are provided, a URL that points to the *form* for
|
||||
* Yahoo! driving directions where the form is filled with whatever fields have been provided
|
||||
* for the partial location(es).
|
||||
*/
|
||||
function _location_driving_directions_link_au_yahoo($location_a, $location_b) {
|
||||
if (trim($location_b['country']) != 'ca' && trim($location_b['country']) != 'au') {
|
||||
return '';
|
||||
}
|
||||
|
||||
// These are the fields that need to be in each location if we are to provide a direct
|
||||
// link to yahoo directions. If all of these fields don't have values, then we generate
|
||||
// a link to the *form* for Yahoo! driving directions rather than directly to the driving
|
||||
// directions themselves.
|
||||
|
||||
|
||||
foreach ($location_a as $field => $value) {
|
||||
$location_a[$field] = trim($value);
|
||||
}
|
||||
|
||||
foreach ($location_b as $field => $value) {
|
||||
$location_b[$field] = trim($value);
|
||||
}
|
||||
|
||||
if (_location_au_enough_fields_for_yahoo($location_a) && _location_au_enough_fields_for_yahoo($location_b)) {
|
||||
$yahoo_maps_path = 'dd_result';
|
||||
}
|
||||
else {
|
||||
$yahoo_maps_path = 'dd';
|
||||
}
|
||||
|
||||
$get_query = '?';
|
||||
|
||||
$get_query .= 'addr='. urlencode($location_a['street']) .'&';
|
||||
$get_query .= 'csz='. _location_au_yahoo_csz_get_field($location_a) .'&';
|
||||
$get_query .= 'country='. urlencode($location_a['country']) .'&';
|
||||
|
||||
$get_query .= 'taddr='. urlencode($location_b['street']) .'&';
|
||||
$get_query .= 'tcsz='. _location_au_yahoo_csz_get_field($location_b) .'&';
|
||||
$get_query .= 'tcountry='. urlencode($location_b['country']);
|
||||
|
||||
$get_query .= '&getrte='. urlencode('Get Directions');
|
||||
|
||||
return ('http://maps.yahoo.com/'. $yahoo_maps_path . $get_query);
|
||||
}
|
||||
|
||||
function _location_au_enough_fields_for_yahoo($location) {
|
||||
// These are the fields that need to be in each location if we are to provide a direct
|
||||
// link to yahoo directions. If all of these fields don't have values, then we generate
|
||||
// a link to the *form* for Yahoo! driving directions rather than directly to the driving
|
||||
// directions themselves.
|
||||
if (strlen($location['street']) && strlen($location['city']) && strlen($location['province'])) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (strlen($location['street']) && strlen($location['postal_code'])) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (strlen($location['street']) && strlen($location['city']) && strlen($location['province'])) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Don't mess with this function unless you understand its logic. It has to do with
|
||||
* the question of "to comma or not to comma?"
|
||||
*/
|
||||
function _location_au_yahoo_csz_get_field($location) {
|
||||
// For some reasons, to the end of pinpointing a location, Yahoo! Maps and Driving Directions
|
||||
// do better a better job with retrieving info based strictly on a Canadian city/province
|
||||
// than on a Canadian postal code.
|
||||
if ($location['country'] = 'ca') {
|
||||
if (strlen($location['city']) && strlen($location['province'])) {
|
||||
return urlencode($location['city'] .', '. $location['province']);
|
||||
}
|
||||
|
||||
if (strlen($location['postal_code'])) {
|
||||
return urlencode($location['postal_code']);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (strlen($location['postal_code'])) {
|
||||
return urlencode($location['postal_code']);
|
||||
}
|
||||
|
||||
if (strlen($location['city']) && strlen($location['province'])) {
|
||||
return urlencode($location['city'] .', '. $location['province']);
|
||||
}
|
||||
}
|
||||
|
||||
if (strlen($location['city']) || strlen($location['state'])) {
|
||||
if (strlen($location['city'])) {
|
||||
return urlencode($location['city']);
|
||||
}
|
||||
else {
|
||||
return urlencode($location['state']);
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function _location_au_geocoder_oneline($location = array()) {
|
||||
$line = '';
|
||||
|
||||
$line .= $location['street'] .', ';
|
||||
|
||||
if (strlen($location['city']) && strlen($location['province']) && strlen($location['postal_code'])) {
|
||||
$line .= $location['city'] .', '. $location['province'] .' '. $location['postal_code'];
|
||||
}
|
||||
elseif (strlen($location['city']) && strlen($location['province'])) {
|
||||
$line .= $location['city'] .', '. $location['state'];
|
||||
}
|
||||
elseif (strlen($location['postal_code'])) {
|
||||
if (strlen($location['city']) || strlen($location['state'])) {
|
||||
if (strlen($location['city'])) {
|
||||
$line .= $location['city'] .', '. $location['postal_code'];
|
||||
}
|
||||
else {
|
||||
$line .= $location['state'] .', '. $location['postal_code'];
|
||||
}
|
||||
}
|
||||
else {
|
||||
$line .= $location['postal_code'];
|
||||
}
|
||||
}
|
||||
// DEBUG: commented code is for testing/debugging purposes
|
||||
//print '_location_au_geocoder_oneline() RETURNING '. $line ."<br/>\n";
|
||||
return $line;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an associative array of states/territories where
|
||||
* -> the keys are integers starting from 1
|
||||
* -> the values are the English names for those states/territories
|
||||
*
|
||||
* The states are grouped together at the beginning of the array and sorted
|
||||
* alphabetically.
|
||||
*
|
||||
* The territories are grouped together at the end of the array and sorted
|
||||
* alphabetically.
|
||||
*
|
||||
*/
|
||||
function location_province_list_au() {
|
||||
return array(
|
||||
'ACT' => 'Australian Capital Territory',
|
||||
'NSW' => 'New South Wales',
|
||||
'NT' => 'Northern Territory',
|
||||
'QLD' => 'Queensland',
|
||||
'SA' => 'South Australia',
|
||||
'TAS' => 'Tasmania',
|
||||
'VIC' => 'Victoria',
|
||||
'WA' => 'Western Australia',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an associative array of states/territories where
|
||||
* -> the keys are integers starting from 1
|
||||
* -> the values are the English names for those states/territories
|
||||
*
|
||||
* The states are grouped together at the beginning of the array and sorted
|
||||
* alphabetically.
|
||||
*
|
||||
* The territories are grouped together at the end of the array and sorted
|
||||
* alphabetically.
|
||||
*
|
||||
* Currently not being used, but may be in order to be compatible with CiviCRM
|
||||
* TODO: These numeric indices need to be changed to match those in the CiviCRM database
|
||||
*/
|
||||
function location_province_list_numeric_au() {
|
||||
return array(
|
||||
'001' => "New South Wales",
|
||||
'002' => "Queensland",
|
||||
'003' => "South Australia",
|
||||
'004' => "Tasmania",
|
||||
'005' => "Victoria",
|
||||
'006' => "Western Australia",
|
||||
'007' => "Australian Capital Territory",
|
||||
'008' => "Northern Territory",
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns minimum and maximum latitude and longitude needed to create a bounding box.
|
||||
*/
|
||||
function location_bounds_au() {
|
||||
return array(
|
||||
'minlng' => 72.57625,
|
||||
'minlat' => -53.259967,
|
||||
'maxlng' => 159.4839,
|
||||
'maxlat' => -10.078033,
|
||||
);
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
// Aruba
|
||||
|
||||
function location_province_list_aw() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns minimum and maximum latitude and longitude needed to create a bounding box.
|
||||
*/
|
||||
function location_bounds_aw() {
|
||||
return array(
|
||||
'minlng' => -70.08745,
|
||||
'minlat' => 12.4276,
|
||||
'maxlng' => -69.83805,
|
||||
'maxlat' => 12.647367,
|
||||
);
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
// Aland Islands
|
||||
|
||||
function location_province_list_ax() {
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns minimum and maximum latitude and longitude needed to create a bounding box.
|
||||
*/
|
||||
function location_bounds_ax() {
|
||||
// NaturalEarth 10m Admin 0 - Countries (v1.3.0)
|
||||
// EPSG:900913
|
||||
return array(
|
||||
'minlng' => 19.5137748,
|
||||
'minlat' => 59.9044583,
|
||||
'maxlng' => 21.0966239,
|
||||
'maxlat' => 60.4807538,
|
||||
);
|
||||
}
|
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
// Azerbaijan
|
||||
|
||||
function location_province_list_az() {
|
||||
return array('AB' => "Ali Bayramli",
|
||||
'ABS' => "Abseron",
|
||||
'AGC' => "AgcabAdi",
|
||||
'AGM' => "Agdam",
|
||||
'AGS' => "Agdas,",
|
||||
'AGA' => "Agstafa",
|
||||
'AGU' => "Agsu",
|
||||
'AST' => "Astara",
|
||||
'BA' => "Baki",
|
||||
'BAB' => "BabAk",
|
||||
'BAL' => "BalakAn",
|
||||
'BAR' => "BArdA",
|
||||
'BEY' => "Beylaqan",
|
||||
'BIL' => "Bilasuvar",
|
||||
'CAB' => "Cabrayil",
|
||||
'CAL' => "Calilabab",
|
||||
'CUL' => "Culfa",
|
||||
'DAS' => "Daskasan",
|
||||
'DAV' => "Davaci",
|
||||
'FUZ' => "Fuzuli",
|
||||
'GA' => "Ganca",
|
||||
'GAD' => "Gadabay",
|
||||
'GOR' => "Goranboy",
|
||||
'GOY' => "Goycay",
|
||||
'HAC' => "Haciqabul",
|
||||
'IMI' => "Imisli",
|
||||
'ISM' => "Ismayilli",
|
||||
'KAL' => "Kalbacar",
|
||||
'KUR' => "Kurdamir",
|
||||
'LA' => "Lankaran",
|
||||
'LAC' => "Lacin",
|
||||
'LAN' => "Lankaran",
|
||||
'LER' => "Lerik",
|
||||
'MAS' => "Masalli",
|
||||
'MI' => "Mingacevir",
|
||||
'NA' => "Naftalan",
|
||||
'NEF' => "Neftcala",
|
||||
'OGU' => "Oguz",
|
||||
'ORD' => "Ordubad",
|
||||
'QAB' => "Qabala",
|
||||
'QAX' => "Qax",
|
||||
'QAZ' => "Qazax",
|
||||
'QOB' => "Qobustan",
|
||||
'QBA' => "Quba",
|
||||
'QBI' => "Qubadli",
|
||||
'QUS' => "Qusar",
|
||||
'SA' => "Saki",
|
||||
'SAT' => "Saatli",
|
||||
'SAB' => "Sabirabad",
|
||||
'SAD' => "Sadarak",
|
||||
'SAH' => "Sahbuz",
|
||||
'SAK' => "Saki",
|
||||
'SAL' => "Salyan",
|
||||
'SM' => "Sumqayit",
|
||||
'SMI' => "Samaxi",
|
||||
'SKR' => "Samkir",
|
||||
'SMX' => "Samux",
|
||||
'SAR' => "Sarur",
|
||||
'SIY' => "Siyazan",
|
||||
'SS' => "Susa",
|
||||
'SUS' => "Susa",
|
||||
'TAR' => "Tartar",
|
||||
'TOV' => "Tovuz",
|
||||
'UCA' => "Ucar",
|
||||
'XA' => "Xankandi",
|
||||
'XAC' => "Xacmaz",
|
||||
'XAN' => "Xanlar",
|
||||
'XIZ' => "Xizi",
|
||||
'XCI' => "Xocali",
|
||||
'XVD' => "Xocavand",
|
||||
'YAR' => "Yardimli",
|
||||
'YEV' => "Yevlax",
|
||||
'ZAN' => "Zangilan",
|
||||
'ZAQ' => "Zaqatala",
|
||||
'ZAR' => "Zardab",
|
||||
'NX' => "Naxcivan");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns minimum and maximum latitude and longitude needed to create a bounding box.
|
||||
*/
|
||||
function location_bounds_az() {
|
||||
return array(
|
||||
'minlng' => 44.7416,
|
||||
'minlat' => 38.4074,
|
||||
'maxlng' => 50.37515,
|
||||
'maxlat' => 41.924867,
|
||||
);
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user