first commit
This commit is contained in:
@@ -0,0 +1,178 @@
|
||||
== Old Changelog ==
|
||||
|
||||
= 2.8.2 =
|
||||
* Maxmind vendor code was updated to the current version (2.7.0).
|
||||
* FIX: There was a fatal error when using PHP 7.2 (thx jj-dev)
|
||||
* FIX: The automatic update of Maxmind Geoip2 Lite City database was fixed.
|
||||
* FIX: Always try to fill in more information into the country information from the GeoNames-DB.
|
||||
|
||||
= 2.8.1 =
|
||||
|
||||
(Was not released on wordpress.org)
|
||||
|
||||
= 2.8.0 =
|
||||
|
||||
* FIX: Localhost now always is a trusted proxy (for standard reverse proxy configurations, however the checkbox "uses a reverse proxy" still needs to be activated.)
|
||||
* FIX: Timezone was overwritten by country data even though the maxmind data had already detected a timezone.
|
||||
* ADD: If the manual datasource is used, the file will continue to be found if the site is moved to another host
|
||||
* Maxmind vendor code was updated to the current version (2.6.0).
|
||||
* PHP 5.4 is now required (due to the maxmind library).
|
||||
|
||||
= 2.7.0 =
|
||||
|
||||
* ADD: The options array of `geoip_detect2_get_info_from_ip` now has a new parameter for overriding the current source for a single lookup. See [API usage examples](https://github.com/yellowtree/wp-geoip-detect/wiki/API-Usage-Examples)
|
||||
* ADD: New filter `geoip_detect2_shortcode_country_select_countries` for the country list of `[geoip_detect2_countries]`
|
||||
* ADD: New constant `GEOIP_DETECT_IP_EMPTY_CACHE_TIME` that can be used to specify a shorter cache time in case temporarily no external IP was found.
|
||||
* FIX: Compatibility with CF 4.6 (remove deprecated function call)
|
||||
* Maxmind vendor code was updated to the current version (2.4.5).
|
||||
|
||||
= 2.6.0 =
|
||||
|
||||
* ADD: New datasources for Cloudflare & Amazon AWS CloudFront (countries for current IP only).
|
||||
* ADD: Country information (names, lat/lon, continent, localized in the different languages) are now filled in for sources that only detect the country code (Cloudflare, Amazon, hostip.info)
|
||||
* ADD: 2 shortcodes for [Contact Form 7](https://wordpress.org/plugins/contact-form-7/) (a select with all countries `[geoip_detect2_countries mycountry]`, and tracking information for the email text `[geoip_detect2_user_info]`) - see [Documentation](https://github.com/yellowtree/wp-geoip-detect/wiki/API-Documentation#wp-contactform7-shortcodes)
|
||||
* FIX: Cron scheduling is checked every time you visit the plugin page.
|
||||
* FIX: Timezones of US & Canada are now detected more often (if country+state is known)
|
||||
* FIX: Shortcode didn't use current sitelang as default, but always english
|
||||
* Maxmind vendor code was updated to the current version (2.4.2).
|
||||
|
||||
= 2.5.7 =
|
||||
* ADD: Shortcodes can now optionally specifiy the IP: `[geoip_detect2 property="country.isoCode" ip="(ipv4 or ipv6)"]`
|
||||
* ADD: Plugin is now translated into German.
|
||||
* FIX: `geoip_detect2_get_info_from_current_ip()` now also handles the case when REMOTE_ADDR contains multiple IP adresses
|
||||
|
||||
= 2.5.6 =
|
||||
* FIX: Removed noticed concerning open_basedir.
|
||||
|
||||
= 2.5.5 =
|
||||
|
||||
* Clean-up changes to prepare plugin translation.
|
||||
* FIX: Only show the "no database installed" admin notice to admins (props @meitar)
|
||||
|
||||
= 2.5.4 =
|
||||
|
||||
* FIX: Manual datasource filepath handling corrected.
|
||||
* FIX: Potential incompability with BuddyPress removed.
|
||||
|
||||
= 2.5.3 =
|
||||
|
||||
* FIX: (Security) Add nonces to backend to avoid CSRF (thanks to Gerard Arall).
|
||||
* FIX: Do not use PHP shortcode tags (<?=) as some servers do not support it with PHP 5.3
|
||||
* Maxmind vendor code was updated to the current version (2.3.3).
|
||||
|
||||
= 2.5.2 =
|
||||
* FIX: Also disallow proxy caching via HTTP header, if possible.
|
||||
* NEW: Shortcodes for the other API functions: `[geoip_detect2_get_current_source_description]`, `[geoip_detect2_get_client_ip]`, and `[geoip_detect2_get_external_ip_adress]`
|
||||
* FIX: geoip_detect2_get_external_ip_adress() : do not filter if $unfiltered is true.
|
||||
|
||||
= 2.5.1 =
|
||||
* FIX: Upgrade script did change the source.
|
||||
* FIX: Page caching is only disabled on upgrade when `set_css_country` is disabled.
|
||||
|
||||
= 2.5.0 =
|
||||
* CHANGE: The parameter $skipCache is now $options['skipCache']. Using $skipCache is deprecated, but still works.
|
||||
* NEW: $options['timeout'] for Web-API lookups can now be specified.
|
||||
* FIX: Hostip.info did not set traits->ipAddress
|
||||
* FIX: Hostip.info does not include data for IPv6. Add a lookup error message.
|
||||
* NEW: Disable page caching if geoip-API was called (this is configurable in the options). (Supported plugins: WP Super Cache, W3 Total Cache, ZenCache, and possibly others)
|
||||
* Maxmind vendor code was updated to the current version (2.3.1).
|
||||
|
||||
= 2.4.3 =
|
||||
* FIX: Options Page: The checkboxes didn't show (even though the option was saved) since 2.4.0
|
||||
* NEW: A fixed external IP can now be specified on the options page. (Useful in development scenarios without internet, or mixed internet/intranet cases. You can also use this to speed up things on the production server if you know the IP will not change.)
|
||||
* NEW: Hidden feature/side-effect: Clicking on save in the General Options section also empties the external IP cache.
|
||||
|
||||
= 2.4.2 =
|
||||
* FIX: Trim whitespace of IP adress.
|
||||
* FIX: some PHP notices.
|
||||
* FIX: The Installation message "No database installed" failed to install the Maxmind database since 2.4.0
|
||||
* NEW: Show IPv6-not-supported notice.
|
||||
* FIX: Add empty fallback functions in case the plugin requirements are not met. (To avoid fatal errors.)
|
||||
|
||||
= 2.4.1 =
|
||||
* FIX: Revert IPv6 check. (Sorry for this. I thought PHP compiled without IPv6 would be esoteric.)
|
||||
|
||||
= 2.4.0 =
|
||||
This is a major refactor in order to support multiple sources properly. The Lookup and the Options were seperated into 2 screens (accessible in the menu under `Tools` and `Options`, respectively.)
|
||||
|
||||
* NEW: Add a Cache for Web-API-Requests. Consequently, the function geoip_detect2_get_info_from_ip() received a new parameter "$skipCache" to skip this cache if not needed. You can check if the result is coming from the cache by checking $result->extra->cached (it is 0 when not cached, UNIX timestamp of cache event otherwise).
|
||||
* This also applies to the shortcode API (`[geoip_detect2 property="extra.cached" skip_cache="true"]`)
|
||||
* NEW: Error messages during lookup are now in `$record->extra->error`.
|
||||
* NEW: Experimental support for the Maxmind Precision API.
|
||||
* NEW: Shortcodes now also support fallback languages. (`[geoip_detect2 property="country" lang="fr,de"]`)
|
||||
* FIX: Check for IPv6 support for PHP.
|
||||
* FIX: Country data now also get timezones.
|
||||
|
||||
= 2.3.1 =
|
||||
* NEW: API function geoip_detect2_get_current_source_description() (as there are different sources to choose from now)
|
||||
* FIX: Show error message if PHP < 5.3 (instead of fatal error)
|
||||
|
||||
= 2.3.0 =
|
||||
* NEW: Add HostIP.info-Support
|
||||
|
||||
= 2.2.0 =
|
||||
* FIX: Update Maxmind Reader to 1.0.3 (fixing issues when the PHP extension mbstring was not installed)
|
||||
* NEW: Commercial databases are now supported. You can specify a file path in the options.
|
||||
* NEW: A country database (lite or commercial) database now works as well.
|
||||
* NEW:
|
||||
License is now displayed before install.
|
||||
|
||||
= 2.1.2 =
|
||||
* FIX: Show error message if PHP < 5.3 (instead of fatal error)
|
||||
* FIX: Support multiple proxies (but currently only one reverse proxy)
|
||||
|
||||
= 2.1.1 =
|
||||
* FIX: Notice "Database missing" should not show during/right after database update.
|
||||
|
||||
= 2.1.0 =
|
||||
* NEW: A nagging admin notice shows up on every wp-admin page when no database is installed (yet).
|
||||
|
||||
= 2.0.1 =
|
||||
* NEW: Using v2 version of the API.
|
||||
See Migration Guide at [Github](https://github.com/yellowtree/wp-geoip-detect/wiki/How-to-migrate-from-v1-to-v2)
|
||||
|
||||
Other changes:
|
||||
|
||||
* NEW: The v2-functions now support location names in other locales. By default, they return the current site language if possible.
|
||||
* NEW: The new shortcode [geoip_detect2 ...] also supports a "lang"-Attribute.
|
||||
* NEW: IPv6 addresses are now supported as well.
|
||||
* Legacy function names and shortcode should work in most cases. For details check the guide above.
|
||||
|
||||
= 2.0.0 =
|
||||
|
||||
(Was not released on wordpress.org to make sure that development releases get this update as well.)
|
||||
|
||||
= 1.8 =
|
||||
* NEW: Support reverse proxies (you have to enable it in the plugin options.)
|
||||
* NEW: Shortcode now has a default value when no information for this IP found.
|
||||
|
||||
= 1.7.1 =
|
||||
* FIX: Fatal error on cron run
|
||||
|
||||
= 1.7 =
|
||||
* FIX: Schedule Database update to do in background immediately after plugin installation/re-activation.
|
||||
* FIX: Longitude can be smaller than -90
|
||||
|
||||
= 1.6 =
|
||||
* NEW: Can add a country- and continent-specific class on the body tag. You need to activate this in the options.
|
||||
* FIX: Automatic weekly update. (Didn't work on all installations).
|
||||
* FIX: Do not include Maxmind Libraries again if already included by another plugin/theme
|
||||
|
||||
= 1.5 =
|
||||
* FIX: Automatic weekly update. Go to the plugin page (Tools menu) to verify that an update is planned.
|
||||
|
||||
= 1.4 =
|
||||
* Feature: Add shortcode [geoip_detect property="(property name)"] for direct use in posts/pages
|
||||
|
||||
= 1.3 =
|
||||
* FIX: Manual install works again (was broken since 1.2)
|
||||
|
||||
= 1.2 =
|
||||
* FIX: property region_name is now filled again (was broken since 1.1)
|
||||
|
||||
= 1.1 =
|
||||
* Add function `geoip_detect_get_external_ip_adress()`: Ask a webservice to tell me the external IP of the webserver.
|
||||
* New filter: When developing locally, the external IP is used to determine the geographic location.
|
||||
|
||||
= 1.0 =
|
||||
* First working release.
|
||||
@@ -0,0 +1,675 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. 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
|
||||
them 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 prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. 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.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey 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;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If 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 convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU 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 that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
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.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
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.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
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
|
||||
state 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program 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, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU 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. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
|
||||
@@ -0,0 +1,675 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. 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
|
||||
them 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 prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. 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.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey 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;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If 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 convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU 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 that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
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.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
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.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
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
|
||||
state 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program 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, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU 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. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
||||
|
||||
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright 2013-2019 Yellow Tree, Siegen, Germany
|
||||
Author: Benjamin Pick (wp-geoip-detect| |posteo.de)
|
||||
|
||||
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 3 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
use YellowTree\GeoipDetect\DataSources\DataSourceRegistry;
|
||||
|
||||
function geoip_detect_menu() {
|
||||
require_once ABSPATH . '/wp-admin/admin.php';
|
||||
add_submenu_page('tools.php', __('GeoIP Detection Lookup', 'geoip-detect'), __('GeoIP Lookup', 'geoip-detect'), 'activate_plugins', GEOIP_PLUGIN_BASENAME, 'geoip_detect_lookup_page');
|
||||
add_options_page(__('GeoIP Detection', 'geoip-detect'), __('GeoIP Detection', 'geoip-detect'), 'manage_options', GEOIP_PLUGIN_BASENAME, 'geoip_detect_option_page');
|
||||
}
|
||||
add_action('admin_menu', 'geoip_detect_menu');
|
||||
|
||||
function geoip_detect_add_settings_link( $links ) {
|
||||
$link = '<a href="tools.php?page=' . GEOIP_PLUGIN_BASENAME . '">' . __('Lookup', 'geoip-detect') . '</a>';
|
||||
array_push( $links, $link );
|
||||
|
||||
$link = '<a href="options-general.php?page=' . GEOIP_PLUGIN_BASENAME . '">' . __('Options', 'geoip-detect') . '</a>';
|
||||
array_push( $links, $link );
|
||||
|
||||
return $links;
|
||||
}
|
||||
add_filter( "plugin_action_links_" . GEOIP_PLUGIN_BASENAME, 'geoip_detect_add_settings_link' );
|
||||
|
||||
|
||||
// ------------- Admin GUI --------------------
|
||||
|
||||
function geoip_detect_verify_nonce($action) {
|
||||
$nonce = isset($_POST['_wpnonce']) ? $_POST['_wpnonce'] : '';
|
||||
return wp_verify_nonce( $nonce, 'geoip_detect_' . $action );
|
||||
}
|
||||
|
||||
function geoip_detect_lookup_page()
|
||||
{
|
||||
if (!is_admin())
|
||||
return;
|
||||
|
||||
$ip_lookup_result = false;
|
||||
$message = '';
|
||||
$action = isset($_POST['action']) ? $_POST['action'] : '';
|
||||
|
||||
if (geoip_detect_verify_nonce($action)) {
|
||||
switch($action) {
|
||||
case 'lookup':
|
||||
if (isset($_POST['ip']))
|
||||
{
|
||||
$request_ip = $_POST['ip'];
|
||||
$request_skipCache = !empty($_POST['skip_cache']);
|
||||
$options = array('skipCache' => $request_skipCache);
|
||||
|
||||
$request_locales = null;
|
||||
if (!empty($_POST['locales']))
|
||||
$request_locales = explode(',', $_POST['locales']);
|
||||
|
||||
$start = microtime(true);
|
||||
$ip_lookup_result = geoip_detect2_get_info_from_ip($request_ip, $request_locales, $options);
|
||||
$end = microtime(true);
|
||||
$ip_lookup_duration = $end - $start;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
include_once(GEOIP_PLUGIN_DIR . '/views/lookup.php');
|
||||
}
|
||||
|
||||
function geoip_detect_option_page() {
|
||||
if (!is_admin() || !current_user_can('manage_options'))
|
||||
return;
|
||||
|
||||
if (isset($_GET['geoip_detect_part'])) {
|
||||
switch ($_GET['geoip_detect_part']) {
|
||||
case 'client-ip':
|
||||
return geoip_detect_option_client_ip_page();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$registry = DataSourceRegistry::getInstance();
|
||||
$sources = $registry->getAllSources();
|
||||
|
||||
$message = '';
|
||||
|
||||
$numeric_options = array('set_css_country', 'has_reverse_proxy', 'disable_pagecache', 'ajax_enabled', 'ajax_enqueue_js');
|
||||
$text_options = array('external_ip', 'trusted_proxy_ips');
|
||||
$option_names = array_merge($numeric_options, $text_options);
|
||||
|
||||
$action = isset($_POST['action']) ? $_POST['action'] : '';
|
||||
|
||||
if (geoip_detect_verify_nonce($action)) {
|
||||
switch($action)
|
||||
{
|
||||
case 'update':
|
||||
$registry->setCurrentSource('auto');
|
||||
|
||||
$s = new \YellowTree\GeoipDetect\DataSources\Auto\AutoDataSource();
|
||||
$ret = $s->maxmindUpdate();
|
||||
|
||||
if ($ret === true)
|
||||
$message .= __('Updated successfully.', 'geoip-detect');
|
||||
else
|
||||
$message .= __('File was not updated', 'geoip-detect') .': '. $ret;
|
||||
|
||||
break;
|
||||
|
||||
case 'choose':
|
||||
$registry->setCurrentSource($_POST['options']['source']);
|
||||
break;
|
||||
|
||||
|
||||
case 'options-source':
|
||||
$messages = array();
|
||||
foreach ($sources as $s) {
|
||||
$ret = $s->saveParameters($_POST);
|
||||
if (is_string($ret) && $ret) {
|
||||
$messages[] = $ret;
|
||||
}
|
||||
}
|
||||
if ($messages)
|
||||
$message .= implode('<br />', $messages);
|
||||
|
||||
break;
|
||||
|
||||
case 'options':
|
||||
// Empty IP Cache
|
||||
delete_transient('geoip_detect_external_ip');
|
||||
|
||||
if (!empty($_POST['options']['external_ip'])) {
|
||||
if (!geoip_detect_is_ip($_POST['options']['external_ip'])) {
|
||||
$message .= 'The external IP "' . esc_html($_POST['options']['external_ip']) . '" is not a valid IP.';
|
||||
unset($_POST['options']['external_ip']);
|
||||
} else if (!geoip_detect_is_public_ip($_POST['options']['external_ip'])) {
|
||||
$message .= 'Warning: The external IP "' . esc_html($_POST['options']['external_ip']) . '" is not a public internet IP, so it will probably not work.';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ($option_names as $opt_name) {
|
||||
if (in_array($opt_name, $numeric_options))
|
||||
$opt_value = isset($_POST['options'][$opt_name]) ? (int) $_POST['options'][$opt_name] : 0;
|
||||
else
|
||||
$opt_value = isset($_POST['options'][$opt_name]) ? $_POST['options'][$opt_name] : '';
|
||||
update_option('geoip-detect-' . $opt_name, $opt_value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$currentSource = $registry->getCurrentSource();
|
||||
|
||||
$wp_options = array();
|
||||
foreach ($option_names as $opt_name) {
|
||||
$wp_options[$opt_name] = get_option('geoip-detect-'. $opt_name);
|
||||
}
|
||||
|
||||
$ipv6_supported = GEOIP_DETECT_IPV6_SUPPORTED;
|
||||
|
||||
include_once(GEOIP_PLUGIN_DIR . '/views/options.php');
|
||||
}
|
||||
|
||||
function geoip_detect_option_client_ip_page() {
|
||||
include_once(GEOIP_PLUGIN_DIR . '/views/client-ip.php');
|
||||
}
|
||||
|
||||
function _geoip_detect_improve_data_for_lookup($data, $shorten_attributes = false) {
|
||||
if ($shorten_attributes) {
|
||||
$short = [
|
||||
'city',
|
||||
'subdivisions',
|
||||
'country',
|
||||
'location'
|
||||
];
|
||||
$short = array_combine($short, $short);
|
||||
$data = array_intersect_key($data, $short);
|
||||
|
||||
unset($data['city']['geoname_id']);
|
||||
unset($data['country']['geoname_id']);
|
||||
unset($data['country']['is_in_european_union']);
|
||||
unset($data['location']['accuracy_radius']);
|
||||
if (!empty($data['subdivisions'])) {
|
||||
foreach ($data['subdivisions'] as $i => $s) {
|
||||
unset($data['subdivisions'][$i]['geoname_id']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Logical order
|
||||
$order = [
|
||||
'is_empty',
|
||||
'city',
|
||||
'most_specific_subdivision',
|
||||
'subdivisions',
|
||||
'postal',
|
||||
'country',
|
||||
'registered_country',
|
||||
'represented_country',
|
||||
'continent',
|
||||
'location',
|
||||
'traits',
|
||||
'maxmind',
|
||||
'extra'
|
||||
];
|
||||
|
||||
uksort($data, function($a, $b) use ($order) {
|
||||
$a_found = array_search($a, $order);
|
||||
$b_found = array_search($b, $order);
|
||||
|
||||
if ($a_found === false) $a_found = 1000;
|
||||
if ($b_found === false) $b_found = 1000;
|
||||
return $a_found > $b_found;
|
||||
});
|
||||
|
||||
return $data;
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Copyright 2013-2019 Yellow Tree, Siegen, Germany
|
||||
Author: Benjamin Pick (wp-geoip-detect| |posteo.de)
|
||||
|
||||
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 3 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* Calling the API via AJAX
|
||||
* ========================
|
||||
*
|
||||
* These function make it possible to query the geo-data corresponding to the current visitor via AJAX.
|
||||
* This can be useful for Site Cache: If the variable content/behavior is injected via JS only, the HTML still can be cached.
|
||||
*
|
||||
* WARNING: We cannot completely prevent others from using this functionality, though, as JS requests can be faked.
|
||||
* To make this harder, we check the referer (so simply embeding the JS in another site won't work).
|
||||
*/
|
||||
|
||||
function geoip_detect_ajax_get_info_from_current_ip() {
|
||||
// Do not cache this response!
|
||||
if (!headers_sent()) {
|
||||
header('Cache-Control: no-cache, no-store, must-revalidate');
|
||||
header('Pragma: no-cache');
|
||||
header('Expires: 0');
|
||||
header('Content-Type: application/json');
|
||||
}
|
||||
|
||||
// Enabled in preferences? If not, do as if the plugin doesn't even exist.
|
||||
if (!get_option('geoip-detect-ajax_enabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!defined( 'DOING_AJAX' ))
|
||||
_geoip_detect_ajax_error('This method is for AJAX only.');
|
||||
|
||||
// Referer check
|
||||
|
||||
$referer = _geoip_detect_get_domain_name($_SERVER['HTTP_REFERER']);
|
||||
if (!$referer) {
|
||||
_geoip_detect_ajax_error('This AJAX call does not work when called directly. Do an AJAX call via JS instead.');
|
||||
}
|
||||
$allowed_domains = [ _geoip_detect_get_domain_name(get_site_url()) ];
|
||||
$allowed_domains = apply_filters('geoip_detect2_ajax_allowed_domains', $allowed_domains);
|
||||
if (!in_array($referer, $allowed_domains)) {
|
||||
_geoip_detect_ajax_error('Incorrect referer.'); // Ajax only works if coming from the same site. No CORS even if headers are enabled.
|
||||
}
|
||||
|
||||
$options = apply_filters('geoip_detect2_ajax_options', []);
|
||||
|
||||
// Do the API call:
|
||||
$data = _geoip_detect_ajax_get_data($options);
|
||||
|
||||
$data = apply_filters('geoip_detect2_ajax_record_data', $data, isset($data['traits']['ip_address']) ? $data['traits']['ip_address'] : '' ) ;
|
||||
|
||||
if ($data['extra']['error'])
|
||||
http_response_code(500);
|
||||
|
||||
echo json_encode($data);
|
||||
exit;
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_geoip_detect2_get_info_from_current_ip', 'geoip_detect_ajax_get_info_from_current_ip' );
|
||||
add_action( 'wp_ajax_nopriv_geoip_detect2_get_info_from_current_ip', 'geoip_detect_ajax_get_info_from_current_ip' );
|
||||
|
||||
|
||||
function _geoip_detect_get_domain_name($url) {
|
||||
$result = parse_url($url);
|
||||
return $result['host'];
|
||||
}
|
||||
|
||||
function _geoip_detect_ajax_error($error) {
|
||||
http_response_code(412);
|
||||
|
||||
$data = array('extra' => array('error' => $error));
|
||||
$data['is_empty'] = true;
|
||||
echo json_encode($data);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
function _geoip_detect_ajax_get_data($options = array()) {
|
||||
$info = geoip_detect2_get_info_from_current_ip(['en'], $options);
|
||||
$data = $info->jsonSerialize();
|
||||
|
||||
// For privacy reasons, do not emit the nb of credits left (Maxmind Precision)
|
||||
unset($data['maxmind']);
|
||||
|
||||
if (is_array($data['subdivisions'])) {
|
||||
$data['most_specific_subdivision'] = end($data['subdivisions']);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call this function if you want to register the JS script only for specific pages
|
||||
*/
|
||||
function geoip_detect2_enqueue_javascript() {
|
||||
wp_enqueue_script('geoip-detect-js');
|
||||
}
|
||||
|
||||
function _geoip_detect_parcel_get_dist_js($handle) {
|
||||
$urlFile = GEOIP_PLUGIN_DIR . '/js/dist/parcel.json';
|
||||
if (!is_readable($urlFile)) return false;
|
||||
|
||||
$json = file_get_contents($urlFile);
|
||||
$urls = json_decode($json, true);
|
||||
|
||||
if (isset($urls[$handle]))
|
||||
return '/js/dist' .$urls[$handle];
|
||||
return false;
|
||||
}
|
||||
|
||||
function _geoip_detect_register_javascript() {
|
||||
// What about CORS usage?
|
||||
// if (!get_option('geoip-detect-ajax_enabled')) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (!get_option('geoip-detect-ajax_enabled')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$file_uri = _geoip_detect_parcel_get_dist_js('frontendJS');
|
||||
if (!$file_uri) {
|
||||
if (WP_DEBUG) {
|
||||
trigger_error('Warning by the geoip-detect-Plugin: the file frontend.js could not be found, JS API will not work.', E_USER_NOTICE);
|
||||
die();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
wp_register_script('geoip-detect-js', GEOIP_DETECT_PLUGIN_URI . $file_uri, array('jquery'), GEOIP_DETECT_VERSION, true);
|
||||
$data = [
|
||||
'ajaxurl' => admin_url('/admin-ajax.php'),
|
||||
'default_locales' => apply_filters('geoip_detect2_locales', null),
|
||||
'do_body_classes' => (bool) get_option('geoip-detect-set_css_country'),
|
||||
'cookie_name' => 'geoip-detect-result', /* If you don't want to use the cookie cache, empty this value via the filter */
|
||||
'cookie_duration_in_days' => 1, /* If you set this to 0, then the cookie will expire when the window closes. */
|
||||
];
|
||||
$data = apply_filters('geoip_detect2_ajax_localize_script_data', $data);
|
||||
wp_localize_script('geoip-detect-js', 'geoip_detect', [ 'options' => $data ] );
|
||||
|
||||
if ((get_option('geoip-detect-ajax_enqueue_js') || get_option('geoip-detect-set_css_country')) && !is_admin()) {
|
||||
geoip_detect2_enqueue_javascript();
|
||||
}
|
||||
}
|
||||
|
||||
add_action('wp_enqueue_scripts', '_geoip_detect_register_javascript');
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
// This file contains dummy method in case the requirements are not met.
|
||||
// Those functions don't do anything but at least there is no Fatal Error or so.
|
||||
|
||||
function geoip_detect2_get_info_from_ip($ip, $locales = null, $options = array()) { return new stdClass; }
|
||||
function geoip_detect2_get_info_from_current_ip($locales = null, $options = array()) { return geoip_detect2_get_info_from_ip(''); }
|
||||
function geoip_detect2_get_reader($locales = null, $options = array()) { return NULL; }
|
||||
function geoip_detect2_get_current_source_description($source = null) { return ''; }
|
||||
function geoip_detect2_get_client_ip() { return ''; }
|
||||
function geoip_detect2_get_external_ip_adress($unfiltered = false) { return ''; }
|
||||
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright 2013-2019 Yellow Tree, Siegen, Germany
|
||||
Author: Benjamin Pick (wp-geoip-detect| |posteo.de)
|
||||
|
||||
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 3 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
use YellowTree\GeoipDetect\DataSources\DataSourceRegistry;
|
||||
use YellowTree\GeoipDetect\Lib\GetClientIp;
|
||||
|
||||
/**
|
||||
* Get Geo-Information for a specific IP
|
||||
* @param string $ip IP-Adress (IPv4 or IPv6). 'me' is the current IP of the server.
|
||||
* @param array(string) $locales List of locale codes to use in name property
|
||||
* from most preferred to least preferred. (Default: Site language, en)
|
||||
* @param array $options Property names with options.
|
||||
* @param boolean $skipCache TRUE: Do not use cache for this request. (Default: FALSE)
|
||||
* @param string $source Change the source for this request only. (Valid values: 'auto', 'manual', 'precision', 'header', 'hostinfo')
|
||||
* @param float $timeout Total transaction timeout in seconds (Precision+HostIP.info API only)
|
||||
* @param int $connectTimeout Initial connection timeout in seconds (Precision API only)
|
||||
* @return YellowTree\GeoipDetect\DataSources\City GeoInformation. (Actually, this is a subclass of \GeoIp2\Model\City)
|
||||
*
|
||||
* @see https://github.com/maxmind/GeoIP2-php API Usage
|
||||
* @see http://dev.maxmind.com/geoip/geoip2/web-services/ API Documentation
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @since 2.4.0 New parameter $skipCache
|
||||
* @since 2.5.0 Parameter $skipCache has been renamed to $options with 'skipCache' property
|
||||
* @since 2.7.0 Parameter $options['source'] has been introduced
|
||||
*/
|
||||
function geoip_detect2_get_info_from_ip($ip, $locales = null, $options = array()) {
|
||||
_geoip_maybe_disable_pagecache();
|
||||
// 1) Processing the parameters.
|
||||
|
||||
$options = _geoip_detect2_process_options($options);
|
||||
|
||||
/**
|
||||
* Filter: geoip_detect2_locales
|
||||
*
|
||||
* @param array $locales The locales that were passed to the function
|
||||
*/
|
||||
$locales = apply_filters('geoip_detect2_locales', $locales);
|
||||
|
||||
|
||||
// 2) Doing the Lookup
|
||||
$data = array();
|
||||
|
||||
// Have a look at the cache first
|
||||
if (!$options['skipCache']) {
|
||||
$data = _geoip_detect2_get_data_from_cache($ip, $options['source']);
|
||||
}
|
||||
|
||||
if (!$data) {
|
||||
|
||||
$reader = _geoip_detect2_get_reader(array('en') /* will be replaced anyway */, true, $outSourceId, $options);
|
||||
|
||||
$lookupError = '';
|
||||
$record = _geoip_detect2_get_record_from_reader($reader, $ip, $lookupError);
|
||||
|
||||
$data = _geoip_detect2_record_enrich_data($record, $ip, $outSourceId, $lookupError);
|
||||
|
||||
if (WP_DEBUG && !GEOIP_DETECT_DOING_UNIT_TESTS && $lookupError) {
|
||||
trigger_error($lookupError, E_USER_NOTICE);
|
||||
}
|
||||
|
||||
// Save result to cache, but no "IP not found in database" or similar errors
|
||||
if (!$lookupError)
|
||||
_geoip_detect2_add_data_to_cache($data, $ip);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter: geoip_detect2_record_data_after_cache
|
||||
* After loading the information from the GeoIP-Database AND after the cache, you can add information to it.
|
||||
*
|
||||
* @param array $data Information found.
|
||||
* @param string $orig_ip IP that originally passed to the function.
|
||||
* @return array
|
||||
*/
|
||||
$data = apply_filters('geoip_detect2_record_data_after_cache', $data, $ip);
|
||||
|
||||
// 3) Returning the data
|
||||
|
||||
// Always return a city record for API compatability. City attributes etc. return empty values.
|
||||
$record = new \YellowTree\GeoipDetect\DataSources\City($data, $locales);
|
||||
|
||||
/**
|
||||
* Filter: geoip_detect2_record_information
|
||||
* Use geoip_detect2_record_data_after_cache instead if you want to modify the data.
|
||||
*
|
||||
* @return \YellowTree\GeoipDetect\DataSources\City
|
||||
*/
|
||||
$record = apply_filters('geoip_detect2_record_information', $record, $ip, $locales);
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Geo-Information for the current IP
|
||||
*
|
||||
* @param array(string) $locales List of locale codes to use in name property
|
||||
* from most preferred to least preferred. (Default: Site language, en)
|
||||
* @param array Property names with options.
|
||||
* @param boolean $skipCache TRUE: Do not use cache for this request. (Default: FALSE)
|
||||
* @param string $source Change the source for this request only. (Valid values: 'auto', 'manual', 'precision', 'header', 'hostinfo')
|
||||
* @param float $timeout Total transaction timeout in seconds (Precision+HostIP.info API only)
|
||||
* @param int $connectTimeout Initial connection timeout in seconds (Precision API only)
|
||||
* @return YellowTree\GeoipDetect\DataSources\City GeoInformation.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @since 2.4.0 New parameter $skipCache
|
||||
* @since 2.5.0 Parameter $skipCache has been renamed to $options with 'skipCache' property
|
||||
* @since 2.7.0 Parameter $options['source'] has been introduced
|
||||
*/
|
||||
function geoip_detect2_get_info_from_current_ip($locales = null, $options = array()) {
|
||||
return geoip_detect2_get_info_from_ip(geoip_detect2_get_client_ip(), $locales, $options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the Reader class of the currently chosen source.
|
||||
* (Use this if you want to use other methods than "city" or otherwise customize behavior.)
|
||||
*
|
||||
* @param array(string) $locales List of locale codes to use in name property
|
||||
* from most preferred to least preferred. (Default: Site language, en)
|
||||
* @param array $options Property names with options.
|
||||
* @param string $source Change the source for this request only. (Valid values: 'auto', 'manual', 'precision', 'header', 'hostinfo')
|
||||
* @param float $timeout Total transaction timeout in seconds (Precision+HostIP.info API only)
|
||||
* @param int $connectTimeout Initial connection timeout in seconds (Precision API only)
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @since 2.5.0 new parameter $options
|
||||
* @since 2.7.0 Parameter $options['source'] has been introduced
|
||||
*/
|
||||
function geoip_detect2_get_reader($locales = null, $options = array()) {
|
||||
_geoip_maybe_disable_pagecache();
|
||||
$options = _geoip_detect2_process_options($options);
|
||||
|
||||
return _geoip_detect2_get_reader($locales, false, $sourceIdOut, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a human-readable label of the currently chosen source.
|
||||
* @param string|\YellowTree\GeoipDetect\DataSources\City $source Id of the source or the returned record
|
||||
* @return string The label.
|
||||
*
|
||||
* @since 2.3.1
|
||||
* @since 2.4.0 new parameter $source
|
||||
*/
|
||||
function geoip_detect2_get_current_source_description($source = null) {
|
||||
if (is_object($source) && $source instanceof \YellowTree\GeoipDetect\DataSources\City) {
|
||||
$source = $source->extra->source;
|
||||
}
|
||||
$registry = DataSourceRegistry::getInstance();
|
||||
if (is_null($source)) {
|
||||
$source = $registry->getCurrentSource();
|
||||
} else {
|
||||
$source = $registry->getSource($source);
|
||||
}
|
||||
|
||||
if ($source) {
|
||||
return $source->getShortLabel();
|
||||
}
|
||||
return 'Unknown';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get client IP (even if it is behind a reverse proxy)
|
||||
* For security reasons, the reverse proxy usage has to be enabled on the settings page.
|
||||
*
|
||||
* @return string Client Ip (IPv4 or IPv6)
|
||||
*
|
||||
* @since 2.0.0
|
||||
*/
|
||||
function geoip_detect2_get_client_ip() {
|
||||
_geoip_maybe_disable_pagecache();
|
||||
|
||||
static $helper = null;
|
||||
if (is_null($helper) || defined('GEOIP_DETECT_DOING_UNIT_TESTS')) {
|
||||
$helper = new GetClientIp();
|
||||
|
||||
// TODO: Expose option to UI. comma-seperated list of IPv4 and v6 adresses.
|
||||
$trusted_proxies = explode(',', (string) get_option('geoip-detect-trusted_proxy_ips', ''));
|
||||
$helper->addProxiesToWhitelist($trusted_proxies);
|
||||
}
|
||||
$useReverseProxy = get_option('geoip-detect-has_reverse_proxy', 0);
|
||||
return $helper->getIp( $useReverseProxy );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sometimes we can only see an local IP adress (local development environment.)
|
||||
* In this case we need to ask an internet server which IP adress our internet connection has.
|
||||
*
|
||||
* @param boolean $unfiltered If true, do not check the options for an external adress. (Default: false)
|
||||
* @return string The detected IPv4 Adress. If none is found, '0.0.0.0' is returned instead.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @since 2.4.3 Reading option 'external_ip' first.
|
||||
* @since 2.5.2 New param $unfiltered that can bypass the option.
|
||||
*/
|
||||
function geoip_detect2_get_external_ip_adress($unfiltered = false) {
|
||||
$ip_cache = '';
|
||||
|
||||
if (!$unfiltered)
|
||||
$ip_cache = get_option('geoip-detect-external_ip');
|
||||
|
||||
if (!$ip_cache)
|
||||
$ip_cache = get_transient('geoip_detect_external_ip');
|
||||
|
||||
if (!$ip_cache) {
|
||||
$ip_cache = _geoip_detect_get_external_ip_adress_without_cache();
|
||||
|
||||
$expiryTime = GEOIP_DETECT_IP_CACHE_TIME;
|
||||
if (empty($ip_cache) || $ip_cache === '0.0.0.0')
|
||||
$expiryTime = GEOIP_DETECT_IP_EMPTY_CACHE_TIME;
|
||||
|
||||
set_transient('geoip_detect_external_ip', $ip_cache, $expiryTime);
|
||||
}
|
||||
|
||||
$ip_cache = apply_filters('geoip_detect_get_external_ip_adress', $ip_cache);
|
||||
|
||||
return $ip_cache;
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
== Old Changelog ==
|
||||
|
||||
= 2.8.2 =
|
||||
* Maxmind vendor code was updated to the current version (2.7.0).
|
||||
* FIX: There was a fatal error when using PHP 7.2 (thx jj-dev)
|
||||
* FIX: The automatic update of Maxmind Geoip2 Lite City database was fixed.
|
||||
* FIX: Always try to fill in more information into the country information from the GeoNames-DB.
|
||||
|
||||
= 2.8.1 =
|
||||
|
||||
(Was not released on wordpress.org)
|
||||
|
||||
= 2.8.0 =
|
||||
|
||||
* FIX: Localhost now always is a trusted proxy (for standard reverse proxy configurations, however the checkbox "uses a reverse proxy" still needs to be activated.)
|
||||
* FIX: Timezone was overwritten by country data even though the maxmind data had already detected a timezone.
|
||||
* ADD: If the manual datasource is used, the file will continue to be found if the site is moved to another host
|
||||
* Maxmind vendor code was updated to the current version (2.6.0).
|
||||
* PHP 5.4 is now required (due to the maxmind library).
|
||||
|
||||
= 2.7.0 =
|
||||
|
||||
* ADD: The options array of `geoip_detect2_get_info_from_ip` now has a new parameter for overriding the current source for a single lookup. See [API usage examples](https://github.com/yellowtree/wp-geoip-detect/wiki/API-Usage-Examples)
|
||||
* ADD: New filter `geoip_detect2_shortcode_country_select_countries` for the country list of `[geoip_detect2_countries]`
|
||||
* ADD: New constant `GEOIP_DETECT_IP_EMPTY_CACHE_TIME` that can be used to specify a shorter cache time in case temporarily no external IP was found.
|
||||
* FIX: Compatibility with CF 4.6 (remove deprecated function call)
|
||||
* Maxmind vendor code was updated to the current version (2.4.5).
|
||||
|
||||
= 2.6.0 =
|
||||
|
||||
* ADD: New datasources for Cloudflare & Amazon AWS CloudFront (countries for current IP only).
|
||||
* ADD: Country information (names, lat/lon, continent, localized in the different languages) are now filled in for sources that only detect the country code (Cloudflare, Amazon, hostip.info)
|
||||
* ADD: 2 shortcodes for [Contact Form 7](https://wordpress.org/plugins/contact-form-7/) (a select with all countries `[geoip_detect2_countries mycountry]`, and tracking information for the email text `[geoip_detect2_user_info]`) - see [Documentation](https://github.com/yellowtree/wp-geoip-detect/wiki/API-Documentation#wp-contactform7-shortcodes)
|
||||
* FIX: Cron scheduling is checked every time you visit the plugin page.
|
||||
* FIX: Timezones of US & Canada are now detected more often (if country+state is known)
|
||||
* FIX: Shortcode didn't use current sitelang as default, but always english
|
||||
* Maxmind vendor code was updated to the current version (2.4.2).
|
||||
|
||||
= 2.5.7 =
|
||||
* ADD: Shortcodes can now optionally specifiy the IP: `[geoip_detect2 property="country.isoCode" ip="(ipv4 or ipv6)"]`
|
||||
* ADD: Plugin is now translated into German.
|
||||
* FIX: `geoip_detect2_get_info_from_current_ip()` now also handles the case when REMOTE_ADDR contains multiple IP adresses
|
||||
|
||||
= 2.5.6 =
|
||||
* FIX: Removed noticed concerning open_basedir.
|
||||
|
||||
= 2.5.5 =
|
||||
|
||||
* Clean-up changes to prepare plugin translation.
|
||||
* FIX: Only show the "no database installed" admin notice to admins (props @meitar)
|
||||
|
||||
= 2.5.4 =
|
||||
|
||||
* FIX: Manual datasource filepath handling corrected.
|
||||
* FIX: Potential incompability with BuddyPress removed.
|
||||
|
||||
= 2.5.3 =
|
||||
|
||||
* FIX: (Security) Add nonces to backend to avoid CSRF (thanks to Gerard Arall).
|
||||
* FIX: Do not use PHP shortcode tags (<?=) as some servers do not support it with PHP 5.3
|
||||
* Maxmind vendor code was updated to the current version (2.3.3).
|
||||
|
||||
= 2.5.2 =
|
||||
* FIX: Also disallow proxy caching via HTTP header, if possible.
|
||||
* NEW: Shortcodes for the other API functions: `[geoip_detect2_get_current_source_description]`, `[geoip_detect2_get_client_ip]`, and `[geoip_detect2_get_external_ip_adress]`
|
||||
* FIX: geoip_detect2_get_external_ip_adress() : do not filter if $unfiltered is true.
|
||||
|
||||
= 2.5.1 =
|
||||
* FIX: Upgrade script did change the source.
|
||||
* FIX: Page caching is only disabled on upgrade when `set_css_country` is disabled.
|
||||
|
||||
= 2.5.0 =
|
||||
* CHANGE: The parameter $skipCache is now $options['skipCache']. Using $skipCache is deprecated, but still works.
|
||||
* NEW: $options['timeout'] for Web-API lookups can now be specified.
|
||||
* FIX: Hostip.info did not set traits->ipAddress
|
||||
* FIX: Hostip.info does not include data for IPv6. Add a lookup error message.
|
||||
* NEW: Disable page caching if geoip-API was called (this is configurable in the options). (Supported plugins: WP Super Cache, W3 Total Cache, ZenCache, and possibly others)
|
||||
* Maxmind vendor code was updated to the current version (2.3.1).
|
||||
|
||||
= 2.4.3 =
|
||||
* FIX: Options Page: The checkboxes didn't show (even though the option was saved) since 2.4.0
|
||||
* NEW: A fixed external IP can now be specified on the options page. (Useful in development scenarios without internet, or mixed internet/intranet cases. You can also use this to speed up things on the production server if you know the IP will not change.)
|
||||
* NEW: Hidden feature/side-effect: Clicking on save in the General Options section also empties the external IP cache.
|
||||
|
||||
= 2.4.2 =
|
||||
* FIX: Trim whitespace of IP adress.
|
||||
* FIX: some PHP notices.
|
||||
* FIX: The Installation message "No database installed" failed to install the Maxmind database since 2.4.0
|
||||
* NEW: Show IPv6-not-supported notice.
|
||||
* FIX: Add empty fallback functions in case the plugin requirements are not met. (To avoid fatal errors.)
|
||||
|
||||
= 2.4.1 =
|
||||
* FIX: Revert IPv6 check. (Sorry for this. I thought PHP compiled without IPv6 would be esoteric.)
|
||||
|
||||
= 2.4.0 =
|
||||
This is a major refactor in order to support multiple sources properly. The Lookup and the Options were seperated into 2 screens (accessible in the menu under `Tools` and `Options`, respectively.)
|
||||
|
||||
* NEW: Add a Cache for Web-API-Requests. Consequently, the function geoip_detect2_get_info_from_ip() received a new parameter "$skipCache" to skip this cache if not needed. You can check if the result is coming from the cache by checking $result->extra->cached (it is 0 when not cached, UNIX timestamp of cache event otherwise).
|
||||
* This also applies to the shortcode API (`[geoip_detect2 property="extra.cached" skip_cache="true"]`)
|
||||
* NEW: Error messages during lookup are now in `$record->extra->error`.
|
||||
* NEW: Experimental support for the Maxmind Precision API.
|
||||
* NEW: Shortcodes now also support fallback languages. (`[geoip_detect2 property="country" lang="fr,de"]`)
|
||||
* FIX: Check for IPv6 support for PHP.
|
||||
* FIX: Country data now also get timezones.
|
||||
|
||||
= 2.3.1 =
|
||||
* NEW: API function geoip_detect2_get_current_source_description() (as there are different sources to choose from now)
|
||||
* FIX: Show error message if PHP < 5.3 (instead of fatal error)
|
||||
|
||||
= 2.3.0 =
|
||||
* NEW: Add HostIP.info-Support
|
||||
|
||||
= 2.2.0 =
|
||||
* FIX: Update Maxmind Reader to 1.0.3 (fixing issues when the PHP extension mbstring was not installed)
|
||||
* NEW: Commercial databases are now supported. You can specify a file path in the options.
|
||||
* NEW: A country database (lite or commercial) database now works as well.
|
||||
* NEW: License is now displayed before install.
|
||||
|
||||
= 2.1.2 =
|
||||
* FIX: Show error message if PHP < 5.3 (instead of fatal error)
|
||||
* FIX: Support multiple proxies (but currently only one reverse proxy)
|
||||
|
||||
= 2.1.1 =
|
||||
* FIX: Notice "Database missing" should not show during/right after database update.
|
||||
|
||||
= 2.1.0 =
|
||||
* NEW: A nagging admin notice shows up on every wp-admin page when no database is installed (yet).
|
||||
|
||||
= 2.0.1 =
|
||||
* NEW: Using v2 version of the API.
|
||||
See Migration Guide at [Github](https://github.com/yellowtree/wp-geoip-detect/wiki/How-to-migrate-from-v1-to-v2)
|
||||
|
||||
Other changes:
|
||||
|
||||
* NEW: The v2-functions now support location names in other locales. By default, they return the current site language if possible.
|
||||
* NEW: The new shortcode [geoip_detect2 ...] also supports a "lang"-Attribute.
|
||||
* NEW: IPv6 addresses are now supported as well.
|
||||
* Legacy function names and shortcode should work in most cases. For details check the guide above.
|
||||
|
||||
= 2.0.0 =
|
||||
|
||||
(Was not released on wordpress.org to make sure that development releases get this update as well.)
|
||||
|
||||
= 1.8 =
|
||||
* NEW: Support reverse proxies (you have to enable it in the plugin options.)
|
||||
* NEW: Shortcode now has a default value when no information for this IP found.
|
||||
|
||||
= 1.7.1 =
|
||||
* FIX: Fatal error on cron run
|
||||
|
||||
= 1.7 =
|
||||
* FIX: Schedule Database update to do in background immediately after plugin installation/re-activation.
|
||||
* FIX: Longitude can be smaller than -90
|
||||
|
||||
= 1.6 =
|
||||
* NEW: Can add a country- and continent-specific class on the body tag. You need to activate this in the options.
|
||||
* FIX: Automatic weekly update. (Didn't work on all installations).
|
||||
* FIX: Do not include Maxmind Libraries again if already included by another plugin/theme
|
||||
|
||||
= 1.5 =
|
||||
* FIX: Automatic weekly update. Go to the plugin page (Tools menu) to verify that an update is planned.
|
||||
|
||||
= 1.4 =
|
||||
* Feature: Add shortcode [geoip_detect property="(property name)"] for direct use in posts/pages
|
||||
|
||||
= 1.3 =
|
||||
* FIX: Manual install works again (was broken since 1.2)
|
||||
|
||||
= 1.2 =
|
||||
* FIX: property region_name is now filled again (was broken since 1.1)
|
||||
|
||||
= 1.1 =
|
||||
* Add function `geoip_detect_get_external_ip_adress()`: Ask a webservice to tell me the external IP of the webserver.
|
||||
* New filter: When developing locally, the external IP is used to determine the geographic location.
|
||||
|
||||
= 1.0 =
|
||||
* First working release.
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright 2013-2019 Yellow Tree, Siegen, Germany
|
||||
Author: Benjamin Pick (wp-geoip-detect| |posteo.de)
|
||||
|
||||
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 3 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
function geoip_detect_version_check() {
|
||||
if (empty($GLOBALS['wp_version']))
|
||||
require(ABSPATH . '/wp-includes/version.php');
|
||||
else
|
||||
$wp_version = $GLOBALS['wp_version'];
|
||||
|
||||
|
||||
if (version_compare ( PHP_VERSION, GEOIP_REQUIRED_PHP_VERSION, '<' )) {
|
||||
$flag = 'PHP';
|
||||
$min = GEOIP_REQUIRED_PHP_VERSION;
|
||||
$yours = PHP_VERSION;
|
||||
|
||||
$message = 'Plugin GeoIP Detection is disabled. Requires ' . $flag . ' ' .$min ." (you're using " . $flag . " " . $yours . ") ";
|
||||
} elseif (version_compare ( $wp_version, GEOIP_REQUIRED_WP_VERSION, '<' )) {
|
||||
$flag = 'WordPress';
|
||||
$min = GEOIP_REQUIRED_WP_VERSION;
|
||||
$yours = $wp_version;
|
||||
|
||||
$message = 'Plugin GeoIP Detection is disabled. Requires ' . $flag . ' ' .$min ." (you're using " . $flag . " " . $yours . ") ";
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (WP_DEBUG)
|
||||
trigger_error($message);
|
||||
|
||||
add_action ( 'all_admin_notices', 'geoip_detect_version_minimum_requirements_notice' );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function geoip_detect_version_minimum_requirements_notice() {
|
||||
if (empty($GLOBALS['wp_version']))
|
||||
require(ABSPATH . '/wp-includes/version.php');
|
||||
else
|
||||
$wp_version = $GLOBALS['wp_version'];
|
||||
?>
|
||||
<div class="error">
|
||||
<h3><?php _e( 'GeoIP Detection: Minimum requirements not met.', 'geoip-detect' ); ?></h3>
|
||||
<p>
|
||||
The plugin <strong>GeoIP Detection</strong> plugin requires PHP <?php echo GEOIP_REQUIRED_PHP_VERSION; ?> (you're using PHP <?php echo PHP_VERSION; ?>) and WordPress version <?php echo GEOIP_REQUIRED_WP_VERSION; ?> (you're using: <?php echo $wp_version; ?>) and therefore does exactly nothing.</p>
|
||||
<p>
|
||||
You can update, or install an <a href="https://github.com/yellowtree/wp-geoip-detect/releases">1.x legacy version</a> of this plugin instead.
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "yellowtree/geoip-detect",
|
||||
"description": "Wordpress Plugin GeoIP Detection: Retrieving Geo-Information using the Maxmind GeoIP2 (Lite) Database.",
|
||||
"type": "wordpress-plugin",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Benjamin Pick",
|
||||
"email": "b.pick@yellowtree.de"
|
||||
}
|
||||
],
|
||||
"keywords": [],
|
||||
"homepage": "http://www.yellowtree.de",
|
||||
"license": [
|
||||
"GPL-3.0+"
|
||||
],
|
||||
"require": {
|
||||
"geoip2/geoip2": "~2.0",
|
||||
"php": ">=5.4"
|
||||
}
|
||||
}
|
||||
+231
@@ -0,0 +1,231 @@
|
||||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "1469024a23af7d9facb99a4208b34160",
|
||||
"packages": [
|
||||
{
|
||||
"name": "composer/ca-bundle",
|
||||
"version": "1.2.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/composer/ca-bundle.git",
|
||||
"reference": "10bb96592168a0f8e8f6dcde3532d9fa50b0b527"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/composer/ca-bundle/zipball/10bb96592168a0f8e8f6dcde3532d9fa50b0b527",
|
||||
"reference": "10bb96592168a0f8e8f6dcde3532d9fa50b0b527",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-openssl": "*",
|
||||
"ext-pcre": "*",
|
||||
"php": "^5.3.2 || ^7.0 || ^8.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^4.8.35 || ^5.7 || 6.5 - 8",
|
||||
"psr/log": "^1.0",
|
||||
"symfony/process": "^2.5 || ^3.0 || ^4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Composer\\CaBundle\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Jordi Boggiano",
|
||||
"email": "j.boggiano@seld.be",
|
||||
"homepage": "http://seld.be"
|
||||
}
|
||||
],
|
||||
"description": "Lets you find a path to the system CA bundle, and includes a fallback to the Mozilla CA bundle.",
|
||||
"keywords": [
|
||||
"cabundle",
|
||||
"cacert",
|
||||
"certificate",
|
||||
"ssl",
|
||||
"tls"
|
||||
],
|
||||
"time": "2019-08-30T08:44:50+00:00"
|
||||
},
|
||||
{
|
||||
"name": "geoip2/geoip2",
|
||||
"version": "v2.9.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/maxmind/GeoIP2-php.git",
|
||||
"reference": "a807fbf65212eef5d8d2db1a1b31082b53633d77"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/maxmind/GeoIP2-php/zipball/a807fbf65212eef5d8d2db1a1b31082b53633d77",
|
||||
"reference": "a807fbf65212eef5d8d2db1a1b31082b53633d77",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"maxmind-db/reader": "~1.0",
|
||||
"maxmind/web-service-common": "~0.5",
|
||||
"php": ">=5.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": "2.*",
|
||||
"phpunit/phpunit": "4.*",
|
||||
"squizlabs/php_codesniffer": "3.*"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GeoIp2\\": "src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"Apache-2.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Gregory J. Oschwald",
|
||||
"email": "goschwald@maxmind.com",
|
||||
"homepage": "http://www.maxmind.com/"
|
||||
}
|
||||
],
|
||||
"description": "MaxMind GeoIP2 PHP API",
|
||||
"homepage": "https://github.com/maxmind/GeoIP2-php",
|
||||
"keywords": [
|
||||
"IP",
|
||||
"geoip",
|
||||
"geoip2",
|
||||
"geolocation",
|
||||
"maxmind"
|
||||
],
|
||||
"time": "2018-04-10T15:32:59+00:00"
|
||||
},
|
||||
{
|
||||
"name": "maxmind-db/reader",
|
||||
"version": "v1.5.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/maxmind/MaxMind-DB-Reader-php.git",
|
||||
"reference": "bd436094fc0a9b0558a899fb80b0ae34fe1808a0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/maxmind/MaxMind-DB-Reader-php/zipball/bd436094fc0a9b0558a899fb80b0ae34fe1808a0",
|
||||
"reference": "bd436094fc0a9b0558a899fb80b0ae34fe1808a0",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.6"
|
||||
},
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": "2.*",
|
||||
"php-coveralls/php-coveralls": "^2.1",
|
||||
"phpunit/phpcov": "^3.0",
|
||||
"phpunit/phpunit": "5.*",
|
||||
"squizlabs/php_codesniffer": "3.*"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-bcmath": "bcmath or gmp is required for decoding larger integers with the pure PHP decoder",
|
||||
"ext-gmp": "bcmath or gmp is required for decoding larger integers with the pure PHP decoder",
|
||||
"ext-maxminddb": "A C-based database decoder that provides significantly faster lookups"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"MaxMind\\Db\\": "src/MaxMind/Db"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"Apache-2.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Gregory J. Oschwald",
|
||||
"email": "goschwald@maxmind.com",
|
||||
"homepage": "https://www.maxmind.com/"
|
||||
}
|
||||
],
|
||||
"description": "MaxMind DB Reader API",
|
||||
"homepage": "https://github.com/maxmind/MaxMind-DB-Reader-php",
|
||||
"keywords": [
|
||||
"database",
|
||||
"geoip",
|
||||
"geoip2",
|
||||
"geolocation",
|
||||
"maxmind"
|
||||
],
|
||||
"time": "2019-09-30T22:56:38+00:00"
|
||||
},
|
||||
{
|
||||
"name": "maxmind/web-service-common",
|
||||
"version": "v0.5.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/maxmind/web-service-common-php.git",
|
||||
"reference": "61a9836fa3bb1743ab89752bae5005d71e78c73b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/maxmind/web-service-common-php/zipball/61a9836fa3bb1743ab89752bae5005d71e78c73b",
|
||||
"reference": "61a9836fa3bb1743ab89752bae5005d71e78c73b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"composer/ca-bundle": "^1.0.3",
|
||||
"ext-curl": "*",
|
||||
"ext-json": "*",
|
||||
"php": ">=5.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": "2.*",
|
||||
"phpunit/phpunit": "4.*",
|
||||
"squizlabs/php_codesniffer": "3.*"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"MaxMind\\Exception\\": "src/Exception",
|
||||
"MaxMind\\WebService\\": "src/WebService"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"Apache-2.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Gregory Oschwald",
|
||||
"email": "goschwald@maxmind.com"
|
||||
}
|
||||
],
|
||||
"description": "Internal MaxMind Web Service API",
|
||||
"homepage": "https://github.com/maxmind/web-service-common-php",
|
||||
"time": "2018-02-12T22:31:54+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": {
|
||||
"php": ">=5.4"
|
||||
},
|
||||
"platform-dev": []
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
/**
|
||||
Each datasource has:
|
||||
- An id, name & description
|
||||
- A reader that can generate Maxmind GeoIP records.
|
||||
- (optional) Configuration options
|
||||
- (optional) Data Source Information (only shown for
|
||||
- activate / deactivate when activated / deactivated by the user
|
||||
|
||||
For future compatibility:
|
||||
Each data source may not rely on the fact that it is the "currently chosen" source. There may be several sources that are "activated" and then used in a fallback manner.
|
||||
In practise this means that wordpress filters should be used only in conjunction of checks like
|
||||
|
||||
if ($record->extra->source == $this->getId()) { ...
|
||||
|
||||
*/
|
||||
|
||||
namespace YellowTree\GeoipDetect\DataSources {
|
||||
|
||||
abstract class AbstractDataSource {
|
||||
public function __construct() {}
|
||||
|
||||
abstract public function getId();
|
||||
public function getLabel() { return ''; }
|
||||
|
||||
public function getDescriptionHTML() { return ''; }
|
||||
public function getStatusInformationHTML() { return ''; }
|
||||
public function getParameterHTML() { return ''; }
|
||||
public function saveParameters($post) { }
|
||||
public function getShortLabel() { return $this->getLabel(); }
|
||||
|
||||
public function activate() { }
|
||||
public function deactivate() { }
|
||||
public function uninstall() {}
|
||||
|
||||
public function getReader($locales = array('en'), $options = array()) { return null; }
|
||||
|
||||
public function isWorking() { return false; }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This Class extends the Maxmind City with more attributes.
|
||||
*
|
||||
* @property bool $isEmpty (Wordpress Plugin) If the record is empty or contains any data.
|
||||
*
|
||||
* @property \YellowTree\GeoipDetect\DataSources\ExtraInformation $extra (Wordpress Plugin) Extra Information added by the GeoIP Detect plugin
|
||||
*/
|
||||
class City extends \GeoIp2\Model\Insights {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
protected $extra;
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
public function __construct($raw, $locales) {
|
||||
parent::__construct($raw, $locales);
|
||||
|
||||
$this->extra = new ExtraInformation($this->get('extra'));
|
||||
}
|
||||
|
||||
public function __get($attr) {
|
||||
if ($attr == 'isEmpty')
|
||||
return $this->raw['is_empty'];
|
||||
else
|
||||
return parent::__get($attr);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @property string $source Id of the source that this record is originating from.
|
||||
*
|
||||
* @property int $cached 0 if not cached, else Unix Timestamp when it was written to the cache.
|
||||
*
|
||||
* @property string $error Error message if one occured during lookup. If multiple errors, they are seperated by \n
|
||||
*/
|
||||
|
||||
class ExtraInformation extends \GeoIp2\Record\AbstractRecord {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
protected $validAttributes = array('source', 'cached', 'error', 'original', 'flag', 'tel');
|
||||
}
|
||||
|
||||
interface ReaderInterface extends \GeoIp2\ProviderInterface {
|
||||
/**
|
||||
* Closes the database and returns the resources to the system.
|
||||
*/
|
||||
public function close();
|
||||
}
|
||||
|
||||
abstract class AbstractReader implements \YellowTree\GeoipDetect\DataSources\ReaderInterface {
|
||||
protected $options;
|
||||
|
||||
public function __construct($options = array()) {
|
||||
$this->options = $options;
|
||||
}
|
||||
|
||||
public function city($ip) {
|
||||
throw new \BadMethodCallException('This datasource does not provide data for city()');
|
||||
}
|
||||
|
||||
public function country($ip) {
|
||||
throw new \BadMethodCallException('This datasource does not provide data for country()');
|
||||
}
|
||||
|
||||
public function close() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // end namespace
|
||||
|
||||
namespace { // global namespace
|
||||
function geoip_detect2_register_source($source) {
|
||||
$registry = \YellowTree\GeoipDetect\DataSources\DataSourceRegistry::getInstance();
|
||||
$registry->register($source);
|
||||
}
|
||||
|
||||
function geoip_detect2_is_source_active($sourceId) {
|
||||
$registry = \YellowTree\GeoipDetect\DataSources\DataSourceRegistry::getInstance();
|
||||
return $sourceId == $registry->getCurrentSource();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright 2013-2019 Yellow Tree, Siegen, Germany
|
||||
Author: Benjamin Pick (wp-geoip-detect| |posteo.de)
|
||||
|
||||
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 3 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
namespace YellowTree\GeoipDetect\DataSources\Auto;
|
||||
|
||||
use YellowTree\GeoipDetect\DataSources\Manual\ManualDataSource;
|
||||
|
||||
define('GEOIP_DETECT_DATA_UPDATE_FILENAME', 'GeoLite2-City.mmdb');
|
||||
|
||||
class AutoDataSource extends ManualDataSource
|
||||
{
|
||||
public function getId() { return 'auto'; }
|
||||
public function getLabel() { return __('Automatic download & update of Maxmind GeoIP Lite City', 'geoip-detect'); }
|
||||
public function getShortLabel() { return sprintf(__('%s (updated monthly)', 'geoip-detect'), parent::getShortLabel()); }
|
||||
public function getDescriptionHTML() { return __('(License: Creative Commons Attribution-ShareAlike 3.0 Unported. See <a href="https://github.com/yellowtree/wp-geoip-detect/wiki/FAQ#the-maxmind-lite-databases-are-licensed-creative-commons-sharealike-attribution-when-do-i-need-to-give-attribution" target="_blank">Licensing FAQ</a> for more details.)', 'geoip-detect'); }
|
||||
|
||||
public function getStatusInformationHTML() {
|
||||
$html = parent::getStatusInformationHTML();
|
||||
$date_format = get_option('date_format') . ' ' . get_option('time_format');
|
||||
|
||||
$rescheduled = '';
|
||||
$next_cron_update = wp_next_scheduled( 'geoipdetectupdate' );
|
||||
if ($next_cron_update === false) {
|
||||
$rescheduled = ' ' . __('(Was rescheduled just now)', 'geoip-detect');
|
||||
$this->set_cron_schedule();
|
||||
$next_cron_update = wp_next_scheduled( 'geoipdetectupdate' );
|
||||
}
|
||||
$html .= '<br />' . sprintf(__('Next update: %s', 'geoip-detect'), $next_cron_update !== false ? date_i18n($date_format, $next_cron_update) : __('Never', 'geoip-detect'));
|
||||
$html .= $rescheduled;
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function getParameterHTML() {
|
||||
$text_update = __('Update now', 'geoip-detect');
|
||||
$nonce_field = wp_nonce_field( 'geoip_detect_update' );
|
||||
$html = <<<HTML
|
||||
<form method="post" action="#">
|
||||
$nonce_field
|
||||
<input type="hidden" name="action" value="update" />
|
||||
<input type="submit" class="button button-secondary" value="$text_update" />
|
||||
</form>
|
||||
HTML;
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function saveParameters($post) {}
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
add_action('geoipdetectupdate', array($this, 'hook_cron'), 10, 1);
|
||||
add_action('plugins_loaded', array($this, 'on_plugins_loaded'));
|
||||
}
|
||||
|
||||
public function on_plugins_loaded() {
|
||||
if (!defined('GEOIP_DETECT_AUTO_UPDATE_DEACTIVATED'))
|
||||
define('GEOIP_DETECT_AUTO_UPDATE_DEACTIVATED', false);
|
||||
}
|
||||
|
||||
public function maxmindGetFilename() {
|
||||
$data_filename = $this->maxmindGetUploadFilename();
|
||||
if (!is_readable($data_filename))
|
||||
$data_filename = '';
|
||||
|
||||
$data_filename = apply_filters('geoip_detect_get_abs_db_filename', $data_filename);
|
||||
return $data_filename;
|
||||
}
|
||||
|
||||
protected function maxmindGetUploadFilename() {
|
||||
$upload_dir = wp_upload_dir();
|
||||
$dir = $upload_dir['basedir'];
|
||||
|
||||
$filename = $dir . '/' . GEOIP_DETECT_DATA_UPDATE_FILENAME;
|
||||
return $filename;
|
||||
}
|
||||
|
||||
protected function download_url($url, $modified = 0) {
|
||||
// Similar to wordpress download_url, but with custom UA
|
||||
$url_filename = basename( parse_url( $url, PHP_URL_PATH ) );
|
||||
|
||||
$tmpfname = wp_tempnam( $url_filename );
|
||||
if ( ! $tmpfname )
|
||||
return new \WP_Error('http_no_file', __('Could not create temporary file.', 'geoip-detect'));
|
||||
|
||||
$headers = array();
|
||||
$headers['User-Agent'] = GEOIP_DETECT_USER_AGENT;
|
||||
if ($modified) {
|
||||
$headers['If-Modified-Since'] = date('r', $modified);
|
||||
}
|
||||
|
||||
$response = wp_safe_remote_get( $url, array('timeout' => 300, 'stream' => true, 'filename' => $tmpfname, 'headers' => $headers ) );
|
||||
$http_response_code = wp_remote_retrieve_response_code( $response );
|
||||
if (304 === $http_response_code) {
|
||||
return new \WP_Error( 'http_304', __('It has not changed since the last update.', 'geoip-detect') );
|
||||
}
|
||||
if (is_wp_error( $response ) || 200 != $http_response_code) {
|
||||
unlink($tmpfname);
|
||||
$body = wp_remote_retrieve_body($response);
|
||||
return new \WP_Error( 'http_404', $http_response_code . ': ' . trim( wp_remote_retrieve_response_message( $response ) ) . ' ' . $body );
|
||||
}
|
||||
|
||||
return $tmpfname;
|
||||
}
|
||||
|
||||
public function maxmindUpdate()
|
||||
{
|
||||
require_once(ABSPATH.'/wp-admin/includes/file.php');
|
||||
|
||||
$download_url = 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz';
|
||||
//$download_url = 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz';
|
||||
$download_url = apply_filters('geoip_detect2_download_url', $download_url);
|
||||
|
||||
$outFile = $this->maxmindGetUploadFilename();
|
||||
$modified = 0;
|
||||
if (\is_readable($outFile)) {
|
||||
$modified = filemtime($outFile);
|
||||
}
|
||||
|
||||
// Check if existing download should be resumed
|
||||
$tmpFile = get_option('geoip-detect-auto_downloaded_file');
|
||||
if (!$tmpFile || !file_exists($tmpFile)) {
|
||||
// Download file
|
||||
$tmpFile = $this->download_url($download_url, $modified);
|
||||
}
|
||||
|
||||
if (is_wp_error($tmpFile)) {
|
||||
return $tmpFile->get_error_message();
|
||||
}
|
||||
update_option('geoip-detect-auto_downloaded_file', $tmpFile);
|
||||
|
||||
// Unpack tar.gz
|
||||
$ret = $this->unpackArchive($tmpFile, $outFile);
|
||||
if (is_string($ret)) {
|
||||
return $ret;
|
||||
}
|
||||
|
||||
if (!is_readable($outFile)) {
|
||||
return 'Something went wrong: the unpacked file cannot be found.';
|
||||
}
|
||||
|
||||
update_option('geoip-detect-auto_downloaded_file', '');
|
||||
unlink($tmpFile);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Ungzip File
|
||||
protected function unpackArchive($downloadedFilename, $outFile) {
|
||||
if (!is_readable($downloadedFilename))
|
||||
return __('Downloaded file could not be opened for reading.', 'geoip-detect');
|
||||
if (!\is_writable(dirname($outFile)))
|
||||
return sprintf(__('Database could not be written (%s).', 'geoip-detect'), $outFile);
|
||||
|
||||
$phar = new \PharData( $downloadedFilename );
|
||||
|
||||
$outDir = get_temp_dir() . 'geoip-detect/';
|
||||
|
||||
global $wp_filesystem;
|
||||
if (!$wp_filesystem) {
|
||||
\WP_Filesystem(false, get_temp_dir());
|
||||
}
|
||||
if (\is_dir($outDir)) {
|
||||
$wp_filesystem->rmdir($outDir, true);
|
||||
}
|
||||
|
||||
mkdir($outDir);
|
||||
$phar->extractTo($outDir, null, true);
|
||||
|
||||
$files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($outDir));
|
||||
|
||||
$inFile = '';
|
||||
foreach($files as $file) {
|
||||
if (!$file->isDir() && mb_substr($file->getFilename(), -5) == '.mmdb') {
|
||||
$inFile = $file->getPathname();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!\is_readable($inFile))
|
||||
return __('Downloaded file could not be opened for reading.', 'geoip-detect');
|
||||
|
||||
$ret = copy($inFile, $outFile);
|
||||
if (!$ret)
|
||||
return sprintf(__('Downloaded file could not write or overwrite %s.', 'geoip-detect'), $outFile);
|
||||
|
||||
$wp_filesystem->rmdir($outDir, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function hook_cron() {
|
||||
/**
|
||||
* Filter:
|
||||
* Cron has fired.
|
||||
* Find out if file should be updated now.
|
||||
*
|
||||
* @param $do_it False if deactivated by define
|
||||
* @param $immediately_after_activation True if this is fired because the plugin was recently activated (deprecated, will now always be false)
|
||||
*/
|
||||
$do_it = apply_filters('geoip_detect_cron_do_update', !GEOIP_DETECT_AUTO_UPDATE_DEACTIVATED, false);
|
||||
|
||||
$this->schedule_next_cron_run();
|
||||
|
||||
if ($do_it)
|
||||
$this->maxmindUpdate();
|
||||
}
|
||||
|
||||
public function set_cron_schedule()
|
||||
{
|
||||
$next = wp_next_scheduled( 'geoipdetectupdate' );
|
||||
if ( $next === false ) {
|
||||
$this->schedule_next_cron_run();
|
||||
}
|
||||
}
|
||||
|
||||
public function schedule_next_cron_run() {
|
||||
// Try to update every 1-2 weeks
|
||||
$next = time() + WEEK_IN_SECONDS;
|
||||
$next += mt_rand(1, WEEK_IN_SECONDS);
|
||||
wp_schedule_single_event($next, 'geoipdetectupdate');
|
||||
}
|
||||
|
||||
public function activate() {
|
||||
$this->set_cron_schedule();
|
||||
}
|
||||
|
||||
public function deactivate()
|
||||
{
|
||||
wp_clear_scheduled_hook('geoipdetectupdate');
|
||||
}
|
||||
|
||||
public function uninstall() {
|
||||
// Delete the automatically downloaded file, if it exists
|
||||
$filename = $this->maxmindGetFilename();
|
||||
if ($filename) {
|
||||
unlink($filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
geoip_detect2_register_source(new AutoDataSource());
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright 2013-2019 Yellow Tree, Siegen, Germany
|
||||
Author: Benjamin Pick (wp-geoip-detect| |posteo.de)
|
||||
|
||||
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 3 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
namespace YellowTree\GeoipDetect\DataSources\Header;
|
||||
|
||||
use YellowTree\GeoipDetect\DataSources\AbstractDataSource;
|
||||
|
||||
class HeaderReader extends \YellowTree\GeoipDetect\DataSources\AbstractReader {
|
||||
|
||||
protected $providers = array(
|
||||
'aws' => 'Amazon AWS CloudFront',
|
||||
'cloudflare' => 'Cloudflare',
|
||||
);
|
||||
|
||||
public function country($ip) {
|
||||
|
||||
$r = array();
|
||||
|
||||
$isoCode = '';
|
||||
switch ($this->options['provider']) {
|
||||
case 'aws':
|
||||
if (isset($_SERVER['CloudFront-Viewer-Country'])) {
|
||||
$isoCode = $_SERVER['CloudFront-Viewer-Country'];
|
||||
}
|
||||
break;
|
||||
|
||||
case 'cloudflare';
|
||||
if (isset($_SERVER["HTTP_CF_IPCOUNTRY"])) {
|
||||
$isoCode = $_SERVER["HTTP_CF_IPCOUNTRY"];
|
||||
if ($isoCode == 'xx' /* not a country / unknown */)
|
||||
$isoCode = '';
|
||||
}
|
||||
break;
|
||||
}
|
||||
$country = '';
|
||||
if (!$isoCode) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$r['country']['iso_code'] = strtoupper($isoCode);
|
||||
|
||||
$r['traits']['ip_address'] = $ip;
|
||||
|
||||
$record = new \GeoIp2\Model\City($r, array('en'));
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
||||
|
||||
class HeaderDataSource extends AbstractDataSource {
|
||||
|
||||
public function getId() { return 'header'; }
|
||||
public function getLabel() { return __('Special Hosting Providers (Cloudflare, Amazon AWS CloudFront)', 'geoip-detect'); }
|
||||
|
||||
public function getDescriptionHTML() { return __('These servers already do geodetection, but only of the visitor\'s country.', 'geoip-detect'); }
|
||||
|
||||
public function getStatusInformationHTML() {
|
||||
$provider = get_option('geoip-detect-header-provider');
|
||||
|
||||
$html = '';
|
||||
$link = '';
|
||||
if ($provider == 'cloudflare') {
|
||||
$link = 'https://support.cloudflare.com/hc/en-us/articles/200168236-What-does-CloudFlare-IP-Geolocation-do-';
|
||||
} elseif ($provider == 'aws') {
|
||||
$link = 'https://aws.amazon.com/blogs/aws/enhanced-cloudfront-customization/';
|
||||
}
|
||||
if ($link)
|
||||
$html = sprintf(__('This needs to be enabled in the admin panel: see <a href="%s">Help</a>.', 'geoip-detect'), $link);
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function getParameterHTML() {
|
||||
$provider = get_option('geoip-detect-header-provider');
|
||||
$checked_cloudflare = $provider == 'cloudflare' ? 'checked' : '';
|
||||
$checked_aws = $provider == 'aws' ? 'checked' : '';
|
||||
|
||||
$label = __('Which Hosting Provider:', 'geoip-detect');
|
||||
$html = <<<HTML
|
||||
<p>$label<br>
|
||||
<label><input type="radio" name="options_header[provider]" value="cloudflare" $checked_cloudflare /> Cloudflare</label>
|
||||
<label><input type="radio" name="options_header[provider]" value="aws" $checked_aws /> Amazon AWS CloudFront</label>
|
||||
</p>
|
||||
<br />
|
||||
HTML;
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function saveParameters($post) {
|
||||
$message = '';
|
||||
|
||||
$value = isset($post['options_header']['provider']) ? $post['options_header']['provider'] : '';
|
||||
if (!empty($value)) {
|
||||
update_option('geoip-detect-header-provider', $value);
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function getShortLabel() {
|
||||
$provider = get_option('geoip-detect-header-provider');
|
||||
$labels = array(
|
||||
'' => __('None', 'geoip-detect'),
|
||||
'aws' => 'Amazon AWS CloudFront',
|
||||
'cloudflare' => 'Cloudflare',
|
||||
);
|
||||
if (!isset($labels[$provider]))
|
||||
$provider = '';
|
||||
|
||||
$html = __('Hosting Provider:', 'geoip-detect') . ' ' . $labels[$provider];
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function getReader($locales = array('en'), $options = array()) {
|
||||
$reader = null;
|
||||
|
||||
$provider = get_option('geoip-detect-header-provider');
|
||||
if ($provider) {
|
||||
try {
|
||||
$reader = new HeaderReader( array(
|
||||
'provider' => $provider,
|
||||
) );
|
||||
} catch ( \Exception $e ) {
|
||||
if (WP_DEBUG)
|
||||
echo printf(__('Error while creating reader for "%s": %s', 'geoip-detect'), $filename, $e->getMessage ());
|
||||
}
|
||||
}
|
||||
|
||||
return $reader;
|
||||
}
|
||||
|
||||
public function isWorking() {
|
||||
$working = (bool) get_option('geoip-detect-header-provider');
|
||||
|
||||
return $working;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
geoip_detect2_register_source(new HeaderDataSource());
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace YellowTree\GeoipDetect\DataSources\HostInfo;
|
||||
|
||||
use YellowTree\GeoipDetect\DataSources\AbstractDataSource;
|
||||
use YellowTree\GeoipDetect\DataSources\DataSourceRegistry;
|
||||
|
||||
class Reader implements \YellowTree\GeoipDetect\DataSources\ReaderInterface {
|
||||
|
||||
const URL = 'http://api.hostip.info/get_json.php?ip=';
|
||||
protected $options;
|
||||
|
||||
function __construct($options) {
|
||||
$default_options = array(
|
||||
'timeout' => 1,
|
||||
);
|
||||
$this->options = $options + $default_options;
|
||||
}
|
||||
|
||||
public function city($ip) {
|
||||
if (!geoip_detect_is_ip($ip, true))
|
||||
throw new \Exception('The Hostip.info-Database only contains IPv4 adresses.');
|
||||
|
||||
$data = $this->api_call($ip);
|
||||
|
||||
if (!$data)
|
||||
return null;
|
||||
|
||||
$r = array();
|
||||
|
||||
$r['traits']['original'] = $data;
|
||||
|
||||
if ($data['country_name'])
|
||||
$r['country']['names'] = array('en' => $data['country_name']);
|
||||
if ($data['country_code'])
|
||||
$r['country']['iso_code'] = strtoupper($data['country_code']);
|
||||
|
||||
if ($data['city']) {
|
||||
$r['city']['names'] = array('en' => $data['city']);
|
||||
}
|
||||
|
||||
$r['traits']['ip_address'] = $ip;
|
||||
|
||||
$record = new \GeoIp2\Model\City($r, array('en'));
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
public function country($ip) {
|
||||
return $this->city($ip); // too much info shouldn't hurt ...
|
||||
}
|
||||
|
||||
public function close() {
|
||||
|
||||
}
|
||||
|
||||
private function api_call($ip) {
|
||||
try {
|
||||
// Setting timeout limit to speed up sites
|
||||
$context = stream_context_create(
|
||||
array(
|
||||
'http' => array(
|
||||
'timeout' => $this->options['timeout'],
|
||||
),
|
||||
)
|
||||
);
|
||||
// Using @file... to supress errors
|
||||
// Example output: {"country_name":"UNITED STATES","country_code":"US","city":"Aurora, TX","ip":"12.215.42.19"}
|
||||
$body = @file_get_contents(self::URL . $ip, false, $context);
|
||||
$data = json_decode($body);
|
||||
|
||||
$hasInfo = false;
|
||||
if ($data) {
|
||||
$data = get_object_vars($data);
|
||||
foreach ($data as $key => &$value) {
|
||||
if (stripos($value, '(unknown') !== false)
|
||||
$value = '';
|
||||
if (stripos($value, '(private') !== false)
|
||||
$value = '';
|
||||
if ($key == 'country_code' && $value == 'XX')
|
||||
$value = '';
|
||||
}
|
||||
$hasInfo = $data['country_name'] || $data['country_code'] || $data['city'];
|
||||
}
|
||||
|
||||
if ($hasInfo)
|
||||
return $data;
|
||||
return null;
|
||||
} catch (\Exception $e) {
|
||||
// If the API isn't available, we have to do this
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class HostInfoDataSource extends AbstractDataSource {
|
||||
public function getId() { return 'hostinfo'; }
|
||||
public function getLabel() { return __('HostIP.info Web-API', 'geoip-detect'); }
|
||||
|
||||
public function getDescriptionHTML() { return __('Free (Licence: GPL)<br />(only English names, does only have the following fields: country name, country ID and city name)', 'geoip-detect'); }
|
||||
public function getStatusInformationHTML() { return __('You can choose a Maxmind database below.', 'geoip-detect'); }
|
||||
public function getParameterHTML() { return ''; }
|
||||
|
||||
public function getReader($locales = array('en'), $options = array()) { return new Reader($options); }
|
||||
|
||||
public function isWorking() { return true; }
|
||||
|
||||
}
|
||||
|
||||
geoip_detect2_register_source(new HostInfoDataSource());
|
||||
@@ -0,0 +1,242 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright 2013-2019 Yellow Tree, Siegen, Germany
|
||||
Author: Benjamin Pick (wp-geoip-detect| |posteo.de)
|
||||
|
||||
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 3 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
namespace YellowTree\GeoipDetect\DataSources\Ipstack;
|
||||
|
||||
use YellowTree\GeoipDetect\DataSources\AbstractDataSource;
|
||||
|
||||
class Reader implements \YellowTree\GeoipDetect\DataSources\ReaderInterface {
|
||||
|
||||
const URL = 'api.ipstack.com/';
|
||||
protected $options = array();
|
||||
protected $params = array();
|
||||
|
||||
function __construct($params, $locales, $options) {
|
||||
$this->params= $params;
|
||||
$this->params['language'] = reset($locales);
|
||||
if (empty($this->params['language'])) {
|
||||
$this->params['language'] = 'en';
|
||||
}
|
||||
|
||||
$default_options = array(
|
||||
'timeout' => 1,
|
||||
);
|
||||
$this->options = $options + $default_options;
|
||||
}
|
||||
|
||||
protected function locales($locale, $value) {
|
||||
$locales = array('en' => $value);
|
||||
if ($locale != 'en') {
|
||||
$locales[$locale] = $value;
|
||||
}
|
||||
return $locales;
|
||||
}
|
||||
|
||||
public function city($ip) {
|
||||
$data = $this->api_call($ip);
|
||||
|
||||
if (!$data)
|
||||
return null;
|
||||
|
||||
$r = array();
|
||||
|
||||
$r['extra']['original'] = $data;
|
||||
|
||||
if (isset($data['success']) && $data['success'] === false) {
|
||||
throw new \RuntimeException($data['error']['info']);
|
||||
// Example error:
|
||||
/* @see https://ipstack.com/documentation#errors
|
||||
{
|
||||
"success": false,
|
||||
"error": {
|
||||
"code": 104,
|
||||
"type": "monthly_limit_reached",
|
||||
"info": "Your monthly API request volume has been reached. Please upgrade your plan."
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
$locale = $this->params['language'];
|
||||
if (!empty($data['continent_name']))
|
||||
$r['continent']['names'] = $this->locales($locale, $data['continent_name']);
|
||||
if (!empty($data['continent_code']))
|
||||
$r['continent']['code'] = strtoupper($data['continent_code']);
|
||||
if (!empty($data['country_name']))
|
||||
$r['country']['names'] = $this->locales($locale, $data['country_name']);
|
||||
if (!empty($data['country_code']))
|
||||
$r['country']['iso_code'] = strtoupper($data['country_code']);
|
||||
|
||||
if (!empty($data['region_code'])) {
|
||||
$r['subdivisions'][0] = array(
|
||||
'iso_code' => $data['region_code'],
|
||||
'names' => $this->locales($locale, $data['region_name']),
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($data['city']))
|
||||
$r['city']['names'] = $this->locales($locale, $data['city']);
|
||||
if (!empty($data['latitude']))
|
||||
$r['location']['latitude'] = $data['latitude'];
|
||||
if (!empty($data['longitude']))
|
||||
$r['location']['longitude'] = $data['longitude'];
|
||||
|
||||
if (isset($data['is_eu']))
|
||||
$r['country']['is_in_european_union'] = $data['is_eu'];
|
||||
if (isset($data['timezone']['id']))
|
||||
$r['location']['time_zone'] = $data['timezone']['id'];
|
||||
|
||||
if (isset($data['connection']['asn']))
|
||||
$r['traits']['autonomous_system_number'] = $data['connection']['asn'];
|
||||
if (isset($data['connection']['isp']))
|
||||
$r['traits']['isp'] = $data['connection']['isp'];
|
||||
if (isset($data['security']['is_proxy']))
|
||||
$r['traits']['is_anonymous_vpn'] = $data['security']['is_proxy'] && $data['security']['proxy_type'] == 'vpn';
|
||||
if (isset($data['security']['is_tor']))
|
||||
$r['traits']['is_tor_exit_node'] = $data['security']['is_tor'];
|
||||
|
||||
if (!empty($data['location']['country_flag_emoji']))
|
||||
$r['extra']['flag'] = strtoupper($data['location']['country_flag_emoji']);
|
||||
|
||||
|
||||
$r['traits']['ip_address'] = $ip;
|
||||
|
||||
$record = new \GeoIp2\Model\City($r, array('en'));
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
public function country($ip) {
|
||||
return $this->city($ip); // too much info shouldn't hurt ...
|
||||
}
|
||||
|
||||
public function close() {
|
||||
|
||||
}
|
||||
|
||||
private function build_url($ip) {
|
||||
$url = $this->params['ssl'] ? 'https' : 'http';
|
||||
$url .= '://' . self::URL . $ip;
|
||||
|
||||
$params = [
|
||||
'access_key' => $this->params['key'],
|
||||
'language' => $this->params['language'],
|
||||
];
|
||||
return $url . '?' . \http_build_query($params);
|
||||
}
|
||||
|
||||
private function api_call($ip) {
|
||||
|
||||
try {
|
||||
// Setting timeout limit to speed up sites
|
||||
$context = stream_context_create(
|
||||
array(
|
||||
'http' => array(
|
||||
'timeout' => $this->options['timeout'],
|
||||
),
|
||||
)
|
||||
);
|
||||
// Using @file... to supress errors
|
||||
// Example output: {"country_name":"UNITED STATES","country_code":"US","city":"Aurora, TX","ip":"12.215.42.19"}
|
||||
|
||||
$body = @file_get_contents($this->build_url($ip), false, $context);
|
||||
$data = json_decode($body, true);
|
||||
|
||||
return $data;
|
||||
} catch (\Exception $e) {
|
||||
// If the API isn't available, we have to do this
|
||||
throw $e;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class IpstackSource extends AbstractDataSource {
|
||||
protected $params = array();
|
||||
|
||||
public function __construct() {
|
||||
$this->params['key'] = get_option('geoip-detect-ipstack_key', '');
|
||||
$this->params['ssl'] = get_option('geoip-detect-ipstack_ssl', 0);
|
||||
}
|
||||
|
||||
public function getId() { return 'ipstack'; }
|
||||
public function getLabel() { return __('Ipstack Web-API', 'geoip-detect'); }
|
||||
|
||||
public function getDescriptionHTML() { return __('<a href="https://ipstack.com/">Ipstack</a>', 'geoip-detect'); }
|
||||
public function getStatusInformationHTML() {
|
||||
$html = '';
|
||||
|
||||
$html .= \sprintf(__('SSL: %s', 'geoip-detect'), $this->params['ssl'] ? __('Enabled', 'geoip-detect') : __('Disabled', 'geoip-detect')) . '<br />';
|
||||
|
||||
|
||||
if (!$this->isWorking())
|
||||
$html .= '<div class="geoip_detect_error">' . __('Ipstack only works with an API key.', 'geoip-detect') . '</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function getParameterHTML() {
|
||||
$label_key = __('API Access Key:', 'geoip-detect');
|
||||
$label_ssl = __('Access the API via SSL:', 'geoip-detect');
|
||||
|
||||
$key = esc_attr($this->params['key']);
|
||||
|
||||
$html = <<<HTML
|
||||
$label_key <input type="text" autocomplete="off" size="20" name="options_ipstack[key]" value="$key" /><br />
|
||||
$label_ssl <select name="options_ipstack[ssl]">
|
||||
HTML;
|
||||
$html .= '<option value="0" ' . (!$this->params['ssl'] ? ' selected="selected"' : '') . '">' . __('HTTP (without encryption, not GDPR-compatible)', 'geoip-detect') . '</option>';
|
||||
$html .= '<option value="1" ' . ($this->params['ssl'] ? ' selected="selected"' : '') . '">' . __('HTTPS (with encryption - paid plans only)', 'geoip-detect') . '</option>';
|
||||
$html .= '</select>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function saveParameters($post) {
|
||||
$message = '';
|
||||
|
||||
if (isset($post['options_ipstack']['key'])) {
|
||||
update_option('geoip-detect-ipstack_key', $post['options_ipstack']['key']);
|
||||
$this->params['key']= $post['options_ipstack']['key'];
|
||||
}
|
||||
|
||||
if (isset($post['options_ipstack']['ssl'])) {
|
||||
$ssl = (int) $post['options_ipstack']['ssl'];
|
||||
update_option('geoip-detect-ipstack_ssl', $ssl);
|
||||
$this->params['ssl'] = $post['options_ipstack']['ssl'];
|
||||
}
|
||||
|
||||
if (geoip_detect2_is_source_active('ipstack') && !$this->isWorking())
|
||||
$message .= __('Ipstack only works with an API key.', 'geoip-detect');
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function getReader($locales = array('en'), $options = array()) {
|
||||
return new Reader($this->params, $locales, $options);
|
||||
}
|
||||
|
||||
public function isWorking() {
|
||||
return !empty($this->params['key']);
|
||||
}
|
||||
|
||||
}
|
||||
geoip_detect2_register_source(new IpstackSource());
|
||||
@@ -0,0 +1,180 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright 2013-2019 Yellow Tree, Siegen, Germany
|
||||
Author: Benjamin Pick (wp-geoip-detect| |posteo.de)
|
||||
|
||||
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 3 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
namespace YellowTree\GeoipDetect\DataSources\Manual;
|
||||
|
||||
use YellowTree\GeoipDetect\DataSources\AbstractDataSource;
|
||||
|
||||
define('GEOIP_DETECT_DATA_FILENAME', 'GeoLite2-City.mmdb');
|
||||
|
||||
class ManualDataSource extends AbstractDataSource {
|
||||
|
||||
public function getId() { return 'manual'; }
|
||||
public function getLabel() { return __('Manual download & update of a Maxmind City or Country database', 'geoip-detect'); }
|
||||
|
||||
public function getDescriptionHTML() { return __('<a href="http://dev.maxmind.com/geoip/geoip2/geolite2/" target="_blank">Free version</a> - <a href="https://www.maxmind.com/en/geoip2-country-database" target="_blank">Commercial Version</a>', 'geoip-detect'); }
|
||||
public function getStatusInformationHTML() {
|
||||
$built = $last_update = 0;
|
||||
$html = array();
|
||||
|
||||
$date_format = get_option('date_format') . ' ' . get_option('time_format');
|
||||
$file = $this->maxmindGetFilename();
|
||||
|
||||
if (!$file)
|
||||
return '<b>' . __('No Maxmind database found.', 'geoip-detect') . '</b>';
|
||||
|
||||
$relative_file = geoip_detect_get_relative_path(ABSPATH, $file);
|
||||
|
||||
$html[] = sprintf(__('Database file: %s', 'geoip-detect'), $relative_file);
|
||||
|
||||
$reader = $this->getReader();
|
||||
if ($reader) {
|
||||
$metadata = $reader->metadata();
|
||||
$built = $metadata->buildEpoch;
|
||||
$last_update = is_readable($file) ? filemtime($file) : '';
|
||||
$html[] = sprintf(__('Last updated: %s', 'geoip-detect'), $last_update ? date_i18n($date_format, $last_update) : __('Never', 'geoip-detect'));
|
||||
$html[] = sprintf(__('Database data from: %s', 'geoip-detect'), date_i18n($date_format, $built) );
|
||||
}
|
||||
|
||||
|
||||
return implode('<br>', $html);
|
||||
}
|
||||
|
||||
public function getParameterHTML() {
|
||||
$manual_file = esc_attr(get_option('geoip-detect-manual_file'));
|
||||
$current_value = '';
|
||||
|
||||
if ( get_option('geoip-detect-manual_file_validated') &&
|
||||
get_option('geoip-detect-manual_file') != get_option('geoip-detect-manual_file_validated') &&
|
||||
ABSPATH . get_option('geoip-detect-manual_file') != get_option('geoip-detect-manual_file_validated')
|
||||
) {
|
||||
$current_value = '<br >' . sprintf(__('Current value: %s', 'geoip-detect'), get_option('geoip-detect-manual_file_validated'));
|
||||
}
|
||||
|
||||
$label = __('Filepath to mmdb-file:', 'geoip-detect');
|
||||
$desc = __('e.g. wp-content/uploads/GeoLite2-Country.mmdb or absolute filepath', 'geoip-detect');
|
||||
$html = <<<HTML
|
||||
<p>$label <input type="text" size="40" name="options_manual[manual_file]" value="$manual_file" /></p>
|
||||
<span class="detail-box">$desc $current_value</span>
|
||||
<br />
|
||||
HTML;
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function saveParameters($post) {
|
||||
$message = '';
|
||||
|
||||
$file = isset($post['options_manual']['manual_file']) ? $post['options_manual']['manual_file'] : '';
|
||||
if (!empty($file)) {
|
||||
update_option('geoip-detect-manual_file', $file);
|
||||
|
||||
$validated_filename = self::maxmindValidateFilename($file);
|
||||
if (empty($validated_filename)) {
|
||||
$message .= __('The manual datafile has not been found or is not a mmdb-File. ', 'geoip-detect');
|
||||
} else {
|
||||
update_option('geoip-detect-manual_file_validated', $validated_filename);
|
||||
}
|
||||
}
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function getShortLabel() { return $this->maxmindGetFileDescription(); }
|
||||
|
||||
public function getReader($locales = array('en'), $options = array()) {
|
||||
$reader = null;
|
||||
|
||||
$data_file = $this->maxmindGetFilename();
|
||||
if ($data_file) {
|
||||
try {
|
||||
$reader = new \GeoIp2\Database\Reader ( $data_file, $locales );
|
||||
} catch ( \Exception $e ) {
|
||||
if (WP_DEBUG)
|
||||
printf(__('Error while creating reader for "%s": %s', 'geoip-detect'), $data_file, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return $reader;
|
||||
}
|
||||
|
||||
public function isWorking() {
|
||||
$filename = $this->maxmindGetFilename();
|
||||
if (!is_readable($filename))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function maxmindGetFilename() {
|
||||
$data_filename = get_option('geoip-detect-manual_file_validated');
|
||||
|
||||
// Allow placing the file in the plugin folder for backwards compat
|
||||
if (!$data_filename || !file_exists($data_filename)) {
|
||||
$data_filename = GEOIP_PLUGIN_DIR . '/' . GEOIP_DETECT_DATA_FILENAME;
|
||||
}
|
||||
|
||||
if (!file_exists($data_filename)) {
|
||||
// Maybe site root changed?
|
||||
$data_filename = $this->maxmindValidateFilename(get_option('geoip-detect-manual_file'));
|
||||
}
|
||||
|
||||
$data_filename = apply_filters('geoip_detect_get_abs_db_filename', $data_filename);
|
||||
|
||||
return $data_filename;
|
||||
}
|
||||
|
||||
public static function maxmindValidateFilename($filename) {
|
||||
// Maybe make path absolute
|
||||
if (file_exists(ABSPATH . $filename))
|
||||
$filename = ABSPATH . $filename;
|
||||
|
||||
if (!is_readable($filename))
|
||||
return '';
|
||||
|
||||
try {
|
||||
$reader = new \GeoIp2\Database\Reader($filename);
|
||||
$reader->metadata(); /* Try to read from it ... the result doesn't actually interest me. */
|
||||
$reader->close();
|
||||
} catch ( \Exception $e ) {
|
||||
// Not readable, so do not accept this filename
|
||||
return '';
|
||||
}
|
||||
|
||||
return $filename;
|
||||
}
|
||||
|
||||
protected function maxmindGetFileDescription() {
|
||||
$reader = $this->getReader();
|
||||
|
||||
if (!method_exists($reader, 'metadata'))
|
||||
return __('Maxmind File Database (file does not exist or is not readable)', 'geoip-detect');
|
||||
|
||||
try {
|
||||
$metadata = $reader->metadata();
|
||||
$desc = $metadata->description;
|
||||
return $desc['en'];
|
||||
} catch (\Exception $e) {
|
||||
return __('Maxmind File Database (file does not exist or is not readable)', 'geoip-detect');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
geoip_detect2_register_source(new ManualDataSource());
|
||||
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright 2013-2019 Yellow Tree, Siegen, Germany
|
||||
Author: Benjamin Pick (wp-geoip-detect| |posteo.de)
|
||||
|
||||
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 3 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* maybe TODO:
|
||||
* - warn email when counter is low ?
|
||||
* - change to hostinfo or maxmind if credit is zero?
|
||||
* - exclude spiders?
|
||||
* - error logging
|
||||
*/
|
||||
|
||||
namespace YellowTree\GeoipDetect\DataSources\Precision;
|
||||
|
||||
use YellowTree\GeoipDetect\DataSources\AbstractDataSource;
|
||||
use YellowTree\GeoipDetect\DataSources\DataSourceRegistry;
|
||||
|
||||
class PrecisionReader extends \GeoIp2\WebService\Client implements \YellowTree\GeoipDetect\DataSources\ReaderInterface
|
||||
{
|
||||
public function __construct($userId, $licenseKey, $options) {
|
||||
parent::__construct($userId, $licenseKey, array('en'), $options);
|
||||
}
|
||||
|
||||
public function city($ip = 'me') {
|
||||
$method = get_option('geoip-detect-precision_api_type', 'city');
|
||||
|
||||
$ret = null;
|
||||
|
||||
$callback = array($this, $method);
|
||||
if (!is_callable($callback)) {
|
||||
throw new \RuntimeException('Precision API: Unsupported method ' . $method);
|
||||
}
|
||||
|
||||
if ($method == 'city')
|
||||
$ret = parent::city($ip);
|
||||
else
|
||||
$ret = call_user_func_array($callback, array($ip));
|
||||
|
||||
/* Web-API-specific exceptions:
|
||||
} catch (AuthenticationException $e) {
|
||||
} catch (OutOfQueriesException $e) {
|
||||
}
|
||||
*/
|
||||
|
||||
if ($ret) {
|
||||
$credits = $ret->maxmind->queriesRemaining; // This seems to be approximate.
|
||||
update_option('geoip-detect-precision-remaining_credits', $credits);
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public function close() { }
|
||||
}
|
||||
|
||||
class PrecisionDataSource extends AbstractDataSource {
|
||||
|
||||
protected $known_api_types = array(
|
||||
'country' => array('label' => 'Country'),
|
||||
'city' => array('label' => 'City'),
|
||||
'insights' => array('label' => 'Insights'));
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getId() { return 'precision'; }
|
||||
public function getLabel() { return __('Maxmind Precision Web-API', 'geoip-detect'); }
|
||||
|
||||
public function getDescriptionHTML() { return __('<a href="https://www.maxmind.com/en/geoip2-precision-services">Maxmind Precision Services</a>', 'geoip-detect'); }
|
||||
public function getStatusInformationHTML() {
|
||||
$html = '';
|
||||
$html .= sprintf(__('API Type: %s', 'geoip-detect'), ucfirst(get_option('geoip-detect-precision_api_type', 'city'))) . '<br />';
|
||||
|
||||
$remaining = get_option('geoip-detect-precision-remaining_credits');
|
||||
if ($remaining !== false) {
|
||||
$html .= sprintf(__('Remaining Credits: ca. %s', 'geoip-detect'), $remaining) . '<br />';
|
||||
}
|
||||
|
||||
if (!$this->isWorking())
|
||||
$html .= '<div class="geoip_detect_error">' . __('Maxmind Precision only works with a given user id and secret.', 'geoip-detect') . '</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function getParameterHTML() {
|
||||
$user_id = (int) get_option('geoip-detect-precision-user_id');
|
||||
$user_secret = esc_attr(get_option('geoip-detect-precision-user_secret'));
|
||||
$current_api_type = get_option('geoip-detect-precision_api_type');
|
||||
|
||||
$label_user_id = __('User ID:', 'geoip-detect');
|
||||
$label_user_secret = __('License key:', 'geoip-detect');
|
||||
$label_api_type = __('API Type:', 'geoip-detect');
|
||||
|
||||
$html = <<<HTML
|
||||
$label_user_id <input type="text" size="10" name="options_precision[user_id]" value="$user_id" /><br />
|
||||
$label_user_secret <input type="text" autocomplete="off" size="20" name="options_precision[user_secret]" value="$user_secret" /><br />
|
||||
$label_api_type <select name="options_precision[api_type]">
|
||||
HTML;
|
||||
|
||||
foreach ($this->known_api_types as $name => $api_type) {
|
||||
$html .= '<option ';
|
||||
if ($name == $current_api_type)
|
||||
$html .= 'selected="selected" ';
|
||||
$html .= 'value="' . $name . '">' . $api_type['label'] . '</option>';
|
||||
}
|
||||
$html .= '</select>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function saveParameters($post) {
|
||||
$message = '';
|
||||
|
||||
if (isset($post['options_precision']['user_id'])) {
|
||||
$user_id = (int) $post['options_precision']['user_id'];
|
||||
update_option('geoip-detect-precision-user_id', $user_id);
|
||||
}
|
||||
if (isset($post['options_precision']['user_secret'])) {
|
||||
$user_secret = trim($post['options_precision']['user_secret']);
|
||||
update_option('geoip-detect-precision-user_secret', $user_secret);
|
||||
}
|
||||
if (isset($post['options_precision']['api_type'])) {
|
||||
if (isset($this->known_api_types[$post['options_precision']['api_type']]))
|
||||
update_option('geoip-detect-precision_api_type', $post['options_precision']['api_type']);
|
||||
}
|
||||
|
||||
if (geoip_detect2_is_source_active('precision') && !$this->isWorking())
|
||||
$message .= __('Maxmind Precision only works with a given user id and secret.', 'geoip-detect');
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function getReader($locales = array('en'), $options = array()) {
|
||||
if (!$this->isWorking())
|
||||
return null;
|
||||
|
||||
$user_id = get_option('geoip-detect-precision-user_id');
|
||||
$user_secret = get_option('geoip-detect-precision-user_secret');
|
||||
|
||||
$client = new PrecisionReader($user_id, $user_secret, $options);
|
||||
|
||||
return $client;
|
||||
}
|
||||
|
||||
public function isWorking() {
|
||||
$user_id = get_option('geoip-detect-precision-user_id');
|
||||
$user_secret = get_option('geoip-detect-precision-user_secret');
|
||||
|
||||
return ! (empty($user_id) || empty($user_secret));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
geoip_detect2_register_source(new PrecisionDataSource());
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright 2013-2019 Yellow Tree, Siegen, Germany
|
||||
Author: Benjamin Pick (wp-geoip-detect| |posteo.de)
|
||||
|
||||
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 3 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
namespace YellowTree\GeoipDetect\DataSources;
|
||||
|
||||
class DataSourceRegistry {
|
||||
|
||||
private static $instance;
|
||||
/* singleton */
|
||||
private function __construct() {
|
||||
$this->sources = array();
|
||||
}
|
||||
public static function getInstance() {
|
||||
if (!self::$instance) {
|
||||
self::$instance = new static();
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
|
||||
protected $sources;
|
||||
|
||||
/**
|
||||
* Register a Data source
|
||||
* @param \YellowTree\GeoipDetect\DataSources\AbstractDataSource $source
|
||||
*/
|
||||
public function register($source) {
|
||||
$id = $source->getId();
|
||||
$this->sources[$id] = $source;
|
||||
}
|
||||
|
||||
|
||||
const DEFAULT_SOURCE = 'hostinfo';
|
||||
|
||||
public function getCurrentSourceId() {
|
||||
return get_option('geoip-detect-source', self::DEFAULT_SOURCE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the currently chosen source.
|
||||
* @deprecated Use getSource() instead
|
||||
* @return \YellowTree\GeoipDetect\DataSources\AbstractDataSource
|
||||
*/
|
||||
public function getCurrentSource() {
|
||||
return $this->getSource($this->getCurrentSourceId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the source known by this id.
|
||||
* @param string $id Source id
|
||||
* @return \YellowTree\GeoipDetect\DataSources\AbstractDataSource
|
||||
*/
|
||||
public function getSource($id) {
|
||||
if (isset($this->sources[$id]))
|
||||
return $this->sources[$id];
|
||||
|
||||
if (WP_DEBUG)
|
||||
trigger_error('The source with id "' . $id . '" was requested, but no such source was found. Using default source instead.', E_USER_NOTICE);
|
||||
|
||||
if (isset($this->sources[self::DEFAULT_SOURCE]))
|
||||
return $this->sources[self::DEFAULT_SOURCE];
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a source named $id exists.
|
||||
* @param string $id
|
||||
* @return boolean
|
||||
*/
|
||||
public function sourceExists($id) {
|
||||
return isset($this->sources[$id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Choose a new source as "current source".
|
||||
* @param string $id
|
||||
*/
|
||||
public function setCurrentSource($id) {
|
||||
$oldSource = $this->getCurrentSource();
|
||||
$newSource = $this->getSource($id);
|
||||
|
||||
if ($oldSource->getId() != $newSource->getId()) {
|
||||
$oldSource->deactivate();
|
||||
update_option('geoip-detect-source', $newSource->getId());
|
||||
$newSource->activate();
|
||||
}
|
||||
|
||||
update_option('geoip-detect-ui-has-chosen-source', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all registered sources.
|
||||
*
|
||||
* @return array(\YellowTree\GeoipDetect\DataSources\AbstractDataSource)
|
||||
*/
|
||||
public function getAllSources() {
|
||||
return $this->sources;
|
||||
}
|
||||
|
||||
public function isSourceCachable($source) {
|
||||
// Don't cache for file access based sources (not worth the effort/time)
|
||||
$sources_not_cachable = apply_filters('geoip2_detect_sources_not_cachable', array('auto', 'manual', 'header'));
|
||||
return !in_array($source, $sources_not_cachable);
|
||||
}
|
||||
|
||||
public function isCachingUsed() {
|
||||
return $this->isSourceCachable($this->getCurrentSourceId());
|
||||
}
|
||||
|
||||
public function uninstall() {
|
||||
foreach($this->sources as $source) {
|
||||
$source->deactivate();
|
||||
$source->uninstall();
|
||||
}
|
||||
|
||||
// Delete all options from this plugin
|
||||
foreach ( wp_load_alloptions() as $option => $value ) {
|
||||
if ( strpos( $option, 'geoip-detect-' ) === 0 ) {
|
||||
delete_option( $option );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
/**
|
||||
* @deprecated If you really need to do that manually, use the AutoDataSource-Class instead.
|
||||
*/
|
||||
function geoip_detect_update() {
|
||||
_doing_it_wrong('GeoIP Detection: geoip_detect_update', ' If you really need to do that manually, use the AutoDataSource-Class instead.', '2.4.0');
|
||||
$s = new \YellowTree\GeoipDetect\DataSources\Auto\AutoDataSource();
|
||||
return $s->maxmindUpdate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 2.4.0
|
||||
* @return string
|
||||
*/
|
||||
function geoip_detect_get_abs_db_filename()
|
||||
{
|
||||
_doing_it_wrong('GeoIP Detection: geoip_detect_get_abs_db_filename', 'geoip_detect_get_abs_db_filename should not be called directly', '2.4.0');
|
||||
|
||||
$source = \YellowTree\GeoipDetect\DataSources\DataSourceRegistry::getInstance()->getCurrentSource();
|
||||
if (method_exists($source, 'maxmindGetFilename'))
|
||||
return $source->maxmindGetFilename();
|
||||
return '';
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright 2013-2019 Yellow Tree, Siegen, Germany
|
||||
Author: Benjamin Pick (wp-geoip-detect| |posteo.de)
|
||||
|
||||
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 3 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
function geoip_detect2_add_body_classes_if_needed($classes) {
|
||||
if (!get_option('geoip-detect-set_css_country') || get_option('geoip-detect-ajax_enabled'))
|
||||
return $classes;
|
||||
|
||||
return array_merge($classes, geoip_detect2_get_body_classes());
|
||||
}
|
||||
add_filter('body_class', 'geoip_detect2_add_body_classes_if_needed');
|
||||
|
||||
function geoip_detect2_get_body_classes() {
|
||||
$info = geoip_detect2_get_info_from_current_ip();
|
||||
$classes = array();
|
||||
|
||||
if ($info->continent->code)
|
||||
$classes[] = 'geoip-continent-' . $info->continent->code;
|
||||
|
||||
if ($info->country->isoCode)
|
||||
$classes[] = 'geoip-country-' . $info->country->isoCode;
|
||||
|
||||
if ($info->country->isInEuropeanUnion)
|
||||
$classes[] = 'geoip-country-is-in-european-union';
|
||||
|
||||
if ($info->mostSpecificSubdivision->isoCode)
|
||||
$classes[] = 'geoip-province-' . $info->mostSpecificSubdivision->isoCode;
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function geoip_detect2_convert_locale_format($locales) {
|
||||
if (is_string($locales)) {
|
||||
$locales = explode(',', $locales);
|
||||
$locales = array_map('trim', $locales);
|
||||
$locales = array_unique($locales);
|
||||
}
|
||||
|
||||
return $locales;
|
||||
}
|
||||
add_filter('geoip_detect2_locales', 'geoip_detect2_convert_locale_format', 7);
|
||||
|
||||
function geoip_detect2_add_default_locales($locales) {
|
||||
if (is_null($locales) || $locales === false) {
|
||||
$locales = array();
|
||||
|
||||
/* Needed? should be in get_locale()
|
||||
if (defined('ICL_LANGUAGE_CODE'))
|
||||
$locales[] = ICL_LANGUAGE_CODE;
|
||||
*/
|
||||
|
||||
$site_locale = get_locale();
|
||||
if ($site_locale) {
|
||||
$translate = array(
|
||||
'pt_BR' => 'pt-BR',
|
||||
'zh_CN' => 'zh-CN',
|
||||
);
|
||||
if (isset($translate[$site_locale]))
|
||||
$site_locale = $translate[$site_locale];
|
||||
else
|
||||
$site_locale = substr($site_locale, 0, 2);
|
||||
|
||||
$locales[] = $site_locale;
|
||||
}
|
||||
$locales[] = 'en';
|
||||
}
|
||||
return $locales;
|
||||
}
|
||||
add_filter('geoip_detect2_locales', 'geoip_detect2_add_default_locales');
|
||||
@@ -0,0 +1,473 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright 2013-2019 Yellow Tree, Siegen, Germany
|
||||
Author: Benjamin Pick (wp-geoip-detect| |posteo.de)
|
||||
|
||||
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 3 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// This file contains function that are necessary for the plugin, but not deemed as API.
|
||||
// Their name / parameter may change without warning.
|
||||
|
||||
use YellowTree\GeoipDetect\DataSources\DataSourceRegistry;
|
||||
|
||||
// This file is outside composer root in order to not distribute all the other symfony files
|
||||
require_once(__DIR__ . '/lib/vendor/symfony/http-foundation/IpUtils.php');
|
||||
use Symfony\Component\HttpFoundation\IpUtils;
|
||||
|
||||
/**
|
||||
* Take the parameter options and add the default values.
|
||||
* @param array $options
|
||||
* return $options
|
||||
*/
|
||||
|
||||
function _geoip_detect2_process_options($options) {
|
||||
|
||||
// For backwards compat 2.4.0-2.5.0
|
||||
if (is_bool($options)) {
|
||||
_doing_it_wrong('GeoIP Detection Plugin: geoip_detect2_get_info_from_ip()', '$skipCache has been renamed to $options. Instead of TRUE, now use "[\'skipCache\' => TRUE]".', '2.5.0');
|
||||
$value = $options;
|
||||
$options = array();
|
||||
$options['skipCache'] = $value;
|
||||
}
|
||||
|
||||
// Check if source exists
|
||||
if (isset($options['source'])) {
|
||||
$registry = DataSourceRegistry::getInstance();
|
||||
if (!$registry->sourceExists($options['source']))
|
||||
unset($options['source']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter: geoip_detect2_options
|
||||
* You can programmatically change the defaults etc.
|
||||
*
|
||||
* @param array $options The options array
|
||||
*/
|
||||
$options = apply_filters('geoip_detect2_options', $options);
|
||||
|
||||
|
||||
$defaultOptions = array(
|
||||
'skipCache' => false,
|
||||
'source' => get_option('geoip-detect-source', DataSourceRegistry::DEFAULT_SOURCE),
|
||||
);
|
||||
$options = $options + $defaultOptions;
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the Maxmind Reader
|
||||
* (Use this if you want to use other methods than "city" or otherwise customize behavior.)
|
||||
*
|
||||
* @param array(string) List of locale codes to use in name property
|
||||
* from most preferred to least preferred. (Default: Site language, en)
|
||||
* @param boolean If locale filter should be skipped (default: No)
|
||||
* @return GeoIp2\Database\Reader The reader, ready to do its work. Don't forget to `close()` it afterwards. NULL if file not found (or other problems).
|
||||
* NULL if initialization went wrong (e.g., File not found.)
|
||||
*/
|
||||
function _geoip_detect2_get_reader($locales = null, $skipLocaleFilter = false, &$sourceId = '', $options = array()) {
|
||||
if (! $skipLocaleFilter) {
|
||||
/**
|
||||
* Filter: geoip_detect2_locales
|
||||
*
|
||||
* @param array(string) $locales
|
||||
* Current locales.
|
||||
*/
|
||||
$locales = apply_filters ( 'geoip_detect2_locales', $locales );
|
||||
}
|
||||
|
||||
$reader = null;
|
||||
$source = DataSourceRegistry::getInstance()->getSource($options['source']);
|
||||
if ($source) {
|
||||
$reader = $source->getReader($locales, $options);
|
||||
$sourceId = $source->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter: geoip_detect2_reader
|
||||
* You can customize your reader here.
|
||||
* This filter will be called for every IP request.
|
||||
*
|
||||
* @param
|
||||
* GeoIp2\Database\ProviderInterface Reader (by default: GeoLite City)
|
||||
* @param
|
||||
* array(string) Locale precedence
|
||||
*/
|
||||
$reader = apply_filters('geoip_detect2_reader', $reader, $locales );
|
||||
|
||||
return $reader;
|
||||
}
|
||||
|
||||
function _ip_to_s($ip) {
|
||||
$binary = '';
|
||||
try {
|
||||
$binary = @inet_pton($ip);
|
||||
} catch (\Throwable $e) { }
|
||||
if (empty($binary))
|
||||
return '';
|
||||
return base64_encode($binary);
|
||||
}
|
||||
|
||||
function _geoip_detect2_get_data_from_cache($ip, $source) {
|
||||
if (!DataSourceRegistry::getInstance()->isSourceCachable($source)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$ip_s = _ip_to_s($ip);
|
||||
if (!$ip_s) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = get_transient('geoip_detect_c_' . $source . '_' . $ip_s);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
function _geoip_detect2_add_data_to_cache($data, $ip) {
|
||||
$source = $data['extra']['source'];
|
||||
if (!DataSourceRegistry::getInstance()->isSourceCachable($source)) {
|
||||
return null;
|
||||
}
|
||||
if (GEOIP_DETECT_READER_CACHE_TIME === 0) {
|
||||
// Caching is disabled
|
||||
return null;
|
||||
}
|
||||
|
||||
$data['extra']['cached'] = time();
|
||||
unset($data['maxmind']['queries_remaining']);
|
||||
|
||||
$ip_s = _ip_to_s($ip);
|
||||
// Do not cache invalid IPs
|
||||
if (!$ip_s) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Do not cache error lookups (they might be temporary)
|
||||
if (!empty($data['extra']['error'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
set_transient('geoip_detect_c_' . $source . '_' . $ip_s, $data, GEOIP_DETECT_READER_CACHE_TIME);
|
||||
}
|
||||
|
||||
function _geoip_detect2_get_record_from_reader($reader, $ip, &$error) {
|
||||
$record = null;
|
||||
|
||||
$ip = trim($ip);
|
||||
|
||||
if ($reader) {
|
||||
// When plugin installed on development boxes:
|
||||
// If the client IP is not a public IP, use the public IP of the server instead.
|
||||
// Of course this only works if the internet can be accessed.
|
||||
if ($ip == 'me' || (geoip_detect_is_ip($ip) && !geoip_detect_is_public_ip($ip))) {
|
||||
$ip = geoip_detect2_get_external_ip_adress();
|
||||
}
|
||||
|
||||
try {
|
||||
try {
|
||||
$record = $reader->city($ip);
|
||||
} catch (\BadMethodCallException $e) {
|
||||
$record = $reader->country($ip);
|
||||
}
|
||||
} catch(\Exception $e) {
|
||||
$error = 'Lookup Error: ' . $e->getMessage();
|
||||
}
|
||||
|
||||
$reader->close();
|
||||
} else {
|
||||
$error = 'No reader was found. Check if the configuration is complete and correct.';
|
||||
}
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
function _geoip_detect2_record_enrich_data($record, $ip, $sourceId, $error) {
|
||||
$data = array('traits' => array('ip_address' => $ip), 'is_empty' => true);
|
||||
if (is_object($record) && method_exists($record, 'jsonSerialize')) {
|
||||
$data = $record->jsonSerialize();
|
||||
$data['is_empty'] = false;
|
||||
}
|
||||
$data['extra']['source'] = $sourceId;
|
||||
$data['extra']['cached'] = 0;
|
||||
|
||||
if ($error || !isset($data['extra']['error'])) {
|
||||
$data['extra']['error'] = $error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter: geoip_detect2_record_data
|
||||
* After loading the information from the GeoIP-Database, you can add information to it.
|
||||
*
|
||||
* @param array $data Information found.
|
||||
* @param string $orig_ip IP that originally passed to the function.
|
||||
* @return array
|
||||
*/
|
||||
$data = apply_filters('geoip_detect2_record_data', $data, $ip);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* GeoIPv2 doesn't always include a timezone when v1 did.
|
||||
* Region ids have changed, so countries with several time zones are out of luck.
|
||||
*
|
||||
* @param array $record
|
||||
*/
|
||||
function _geoip_detect2_try_to_fix_timezone($data) {
|
||||
if (!empty($data['location']['time_zone']))
|
||||
return $data;
|
||||
|
||||
if (!function_exists('_geoip_detect_get_time_zone')) {
|
||||
require_once(GEOIP_PLUGIN_DIR . '/vendor/timezone.php');
|
||||
}
|
||||
|
||||
if (!empty($data['country']['iso_code'])) {
|
||||
$data['location']['time_zone'] = _geoip_detect_get_time_zone($data['country']['iso_code'], isset($data['subdivisions'][0]['iso_code']) ? $data['subdivisions'][0]['iso_code'] : null);
|
||||
} else {
|
||||
$data['location']['time_zone'] = null;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
add_filter('geoip_detect2_record_data', '_geoip_detect2_try_to_fix_timezone');
|
||||
|
||||
/**
|
||||
* Add country name, if not known yet
|
||||
*/
|
||||
function _geoip_detect2_add_geonames_data($data) {
|
||||
static $countryInfo = null;
|
||||
if (is_null($countryInfo))
|
||||
$countryInfo = new \YellowTree\GeoipDetect\Geonames\CountryInformation;
|
||||
|
||||
if (!empty($data['country']['iso_code'])) {
|
||||
$geonamesData = $countryInfo->getInformationAboutCountry($data['country']['iso_code']);
|
||||
$data = array_replace_recursive($geonamesData, $data);
|
||||
|
||||
$emoji = $countryInfo->getFlagEmoji($data['country']['iso_code']);
|
||||
if ($emoji && empty($data['extra']['flag'])) {
|
||||
$data['extra']['flag'] = $emoji;
|
||||
}
|
||||
$tel = $countryInfo->getTelephonePrefix($data['country']['iso_code']);
|
||||
if ($tel && empty($data['extra']['tel'])) {
|
||||
$data['extra']['tel'] = $tel;
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
add_filter('geoip_detect2_record_data', '_geoip_detect2_add_geonames_data');
|
||||
|
||||
|
||||
/**
|
||||
* IPv6-Adresses can be written in different formats. Make sure they are standardized.
|
||||
* For IPv4-Adresses, spaces are removed.
|
||||
*/
|
||||
function geoip_detect_normalize_ip($ip) {
|
||||
$ip = trim($ip);
|
||||
$binary = '';
|
||||
try {
|
||||
$binary = @inet_pton($ip);
|
||||
} catch (\Throwable $e) { }
|
||||
if (empty($binary))
|
||||
return $ip; // Probably an IPv6 adress & IPv6 is not supported. Or not a valid IP.
|
||||
|
||||
$ip = inet_ntop($binary);
|
||||
return $ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the expected IP left matches the actual IP
|
||||
* @param string $actual IP
|
||||
* @param string|array $expected IP (can include subnet)
|
||||
* @return boolean
|
||||
*/
|
||||
function geoip_detect_is_ip_equal($actual, $expected) {
|
||||
try {
|
||||
return IpUtils::checkIp($actual, $expected);
|
||||
} catch(Exception $e) {
|
||||
if (WP_DEBUG) {
|
||||
throw $e;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function geoip_detect_is_ip($ip, $noIpv6 = false) {
|
||||
$flags = FILTER_FLAG_IPV4;
|
||||
|
||||
if (GEOIP_DETECT_IPV6_SUPPORTED && !$noIpv6)
|
||||
$flags = $flags | FILTER_FLAG_IPV6;
|
||||
|
||||
return filter_var($ip, FILTER_VALIDATE_IP, $flags) !== false;
|
||||
}
|
||||
|
||||
function geoip_detect_is_ip_in_range($ip, $range_start, $range_end) {
|
||||
$long_ip = ip2long($ip);
|
||||
if ($long_ip === false) // Not IPv4
|
||||
return false;
|
||||
if($long_ip >= ip2long($range_start) && $long_ip <= ip2long($range_end))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if IP is not in RFC private IP range
|
||||
* (for local development)
|
||||
* @param string $ip IP (IPv4 or IPv6)
|
||||
* @return boolean TRUE if private
|
||||
*/
|
||||
function geoip_detect_is_public_ip($ip) {
|
||||
// filver_var only detects 127.0.0.1 as local ...
|
||||
if (geoip_detect_is_ip_equal($ip, '127.0.0.0/8'))
|
||||
return false;
|
||||
if (trim($ip) === '0.0.0.0')
|
||||
return false;
|
||||
|
||||
$flags = FILTER_FLAG_IPV4 // IP can be v4 or v6
|
||||
| FILTER_FLAG_NO_PRIV_RANGE // It may not be in the RFC private range
|
||||
| FILTER_FLAG_NO_RES_RANGE; // It may not be in the RFC reserved range
|
||||
|
||||
if (GEOIP_DETECT_IPV6_SUPPORTED)
|
||||
$flags = $flags | FILTER_FLAG_IPV6;
|
||||
|
||||
$is_public = filter_var($ip, FILTER_VALIDATE_IP, $flags) !== false;
|
||||
|
||||
return $is_public;
|
||||
}
|
||||
|
||||
function _geoip_detect2_get_external_ip_services($nb = 3, $needsCORS = false) {
|
||||
$ipservicesThatAllowCORS = array(
|
||||
'http://ipv4.icanhazip.com',
|
||||
'http://v4.ident.me',
|
||||
);
|
||||
$ipservicesWithoutCORS = array(
|
||||
'http://ipecho.net/plain',
|
||||
'http://bot.whatismyipaddress.com',
|
||||
);
|
||||
|
||||
$ipservices = $ipservicesThatAllowCORS;
|
||||
if (!$needsCORS) {
|
||||
$ipservices = array_merge($ipservices, $ipservicesWithoutCORS);
|
||||
}
|
||||
|
||||
// Randomizing to avoid querying the same service each time
|
||||
shuffle($ipservices);
|
||||
$ipservices = apply_filters('geiop_detect_ipservices', $ipservices);
|
||||
$ipservices = array_slice($ipservices, 0, $nb);
|
||||
return $ipservices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sometimes we can only see an local IP adress (local development environment.)
|
||||
* In this case we need to ask an internet server which IP adress our internet connection has.
|
||||
* (This function is not cached. Some providers may throttle our requests, that's why caching is enabled by default.)
|
||||
*
|
||||
* @return string The detected IPv4 Adress. If none is found, '0.0.0.0' is returned instead.
|
||||
*/
|
||||
function _geoip_detect_get_external_ip_adress_without_cache()
|
||||
{
|
||||
$ipservices = _geoip_detect2_get_external_ip_services();
|
||||
|
||||
foreach ($ipservices as $url)
|
||||
{
|
||||
$ret = wp_remote_get($url, array('timeout' => defined('WP_TESTS_TITLE') ? 3 : 1));
|
||||
|
||||
if (is_wp_error($ret)) {
|
||||
if (WP_DEBUG || defined('WP_TESTS_TITLE')) {
|
||||
trigger_error('_geoip_detect_get_external_ip_adress_without_cache(): Curl error (' . $url . '): ' . $ret->get_error_message(), E_USER_NOTICE);
|
||||
}
|
||||
} else if (isset($ret['response']['code']) && $ret['response']['code'] != 200) {
|
||||
if (WP_DEBUG || defined('WP_TESTS_TITLE')) {
|
||||
trigger_error('_geoip_detect_get_external_ip_adress_without_cache(): HTTP error (' . $url . '): Returned code ' . $ret['response']['code'], E_USER_NOTICE);
|
||||
}
|
||||
} else {
|
||||
if (isset($ret['body'])) {
|
||||
$ip = trim($ret['body']);
|
||||
if (geoip_detect_is_ip($ip))
|
||||
return $ip;
|
||||
}
|
||||
if (WP_DEBUG || defined('WP_TESTS_TITLE')) {
|
||||
trigger_error('_geoip_detect_get_external_ip_adress_without_cache(): HTTP error (' . $url . '): Did not return an IP: ' . $ret['body'], E_USER_NOTICE);
|
||||
}
|
||||
}
|
||||
}
|
||||
return '0.0.0.0';
|
||||
}
|
||||
|
||||
// @see https://stackoverflow.com/questions/2637945/getting-relative-path-from-absolute-path-in-php
|
||||
function geoip_detect_get_relative_path($from, $to)
|
||||
{
|
||||
// some compatibility fixes for Windows paths
|
||||
$from = is_dir($from) ? rtrim($from, '\/') . '/' : $from;
|
||||
$to = is_dir($to) ? rtrim($to, '\/') . '/' : $to;
|
||||
$from = str_replace('\\', '/', $from);
|
||||
$to = str_replace('\\', '/', $to);
|
||||
|
||||
$from = explode('/', $from);
|
||||
$to = explode('/', $to);
|
||||
$relPath = $to;
|
||||
|
||||
foreach($from as $depth => $dir) {
|
||||
// find first non-matching dir
|
||||
if($dir === $to[$depth]) {
|
||||
// ignore this directory
|
||||
array_shift($relPath);
|
||||
} else {
|
||||
// get number of remaining dirs to $from
|
||||
$remaining = count($from) - $depth;
|
||||
if($remaining > 1) {
|
||||
// add traversals up to first matching dir
|
||||
$padLength = (count($relPath) + $remaining - 1) * -1;
|
||||
$relPath = array_pad($relPath, $padLength, '..');
|
||||
break;
|
||||
} else {
|
||||
$relPath[0] = $relPath[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
return implode('/', $relPath);
|
||||
}
|
||||
|
||||
function _geoip_maybe_disable_pagecache() {
|
||||
if (!get_option('geoip-detect-disable_pagecache'))
|
||||
return false;
|
||||
|
||||
// WP Super Cache, W3 Total Cache
|
||||
if (!defined('DONOTCACHEPAGE'))
|
||||
define('DONOTCACHEPAGE', true);
|
||||
|
||||
if (!defined('DONOTCACHEOBJECT'))
|
||||
define('DONOTCACHEOBJECT', true);
|
||||
|
||||
if (!defined('DONOTCACHEDB'))
|
||||
define('DONOTCACHEDB', true);
|
||||
|
||||
if (!headers_sent()) {
|
||||
header('Cache-Control: private, proxy-revalidate, s-maxage=0');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function _geoip_dashes_to_camel_case($string, $capitalizeFirstCharacter = false) {
|
||||
$str = str_replace(' ', '', ucwords(str_replace('_', ' ', $string)));
|
||||
|
||||
if (!$capitalizeFirstCharacter) {
|
||||
$str = lcfirst($str);
|
||||
}
|
||||
|
||||
return $str;
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: GeoIP Detection
|
||||
Plugin URI: http://www.yellowtree.de
|
||||
Description: Retrieving Geo-Information using the Maxmind GeoIP (Lite) Database.
|
||||
Author: Yellow Tree (Benjamin Pick)
|
||||
Author URI: http://www.yellowtree.de
|
||||
Version: 2.13.0
|
||||
License: GPLv3 or later
|
||||
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
||||
Text Domain: geoip-detect
|
||||
Domain Path: /languages
|
||||
GitHub Plugin URI: https://github.com/yellowtree/geoip-detect
|
||||
GitHub Branch: master
|
||||
Requires WP: 4.0
|
||||
Requires PHP: 5.6
|
||||
*/
|
||||
|
||||
define('GEOIP_DETECT_VERSION', '2.13.0');
|
||||
|
||||
/*
|
||||
Copyright 2013-2019 Yellow Tree, Siegen, Germany
|
||||
Author: Benjamin Pick (wp-geoip-detect| |posteo.de)
|
||||
|
||||
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 3 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
define('GEOIP_REQUIRED_PHP_VERSION', '5.6');
|
||||
|
||||
// In theory, it should still run in 3.5 . But officially supported is only WP 4.0 and above.
|
||||
define('GEOIP_REQUIRED_WP_VERSION', '3.5');
|
||||
|
||||
define('GEOIP_PLUGIN_FILE', __FILE__);
|
||||
define('GEOIP_PLUGIN_DIR', dirname(GEOIP_PLUGIN_FILE));
|
||||
define('GEOIP_PLUGIN_BASENAME', plugin_basename(GEOIP_PLUGIN_FILE));
|
||||
define('GEOIP_DETECT_PLUGIN_URI', plugin_dir_url(GEOIP_PLUGIN_FILE));
|
||||
|
||||
|
||||
// Do PHP & WP Version check
|
||||
require_once(GEOIP_PLUGIN_DIR . '/check_requirements.php');
|
||||
if (!geoip_detect_version_check()) {
|
||||
require_once(GEOIP_PLUGIN_DIR . '/api-stubs.php');
|
||||
return; // Do nothing except emitting the admin notice
|
||||
}
|
||||
|
||||
require_once(GEOIP_PLUGIN_DIR . '/vendor/autoload.php');
|
||||
require_once(GEOIP_PLUGIN_DIR . '/init.php');
|
||||
|
||||
require_once(GEOIP_PLUGIN_DIR . '/geoip-detect-lib.php');
|
||||
require_once(GEOIP_PLUGIN_DIR . '/lib/geonames/geonames-country-info.php');
|
||||
require_once(GEOIP_PLUGIN_DIR . '/lib/get-client-ip.php');
|
||||
|
||||
require_once(GEOIP_PLUGIN_DIR . '/upgrade-plugin.php');
|
||||
require_once(GEOIP_PLUGIN_DIR . '/api.php');
|
||||
require_once(GEOIP_PLUGIN_DIR . '/legacy-api.php');
|
||||
require_once(GEOIP_PLUGIN_DIR . '/deprecated.php');
|
||||
require_once(GEOIP_PLUGIN_DIR . '/filter.php');
|
||||
require_once(GEOIP_PLUGIN_DIR . '/shortcode.php');
|
||||
require_once(GEOIP_PLUGIN_DIR . '/ajax.php');
|
||||
|
||||
require_once(GEOIP_PLUGIN_DIR . '/data-sources/registry.php');
|
||||
require_once(GEOIP_PLUGIN_DIR . '/data-sources/abstract.php');
|
||||
|
||||
// These data-source files are optional
|
||||
include_once(GEOIP_PLUGIN_DIR . '/data-sources/hostinfo.php');
|
||||
include_once(GEOIP_PLUGIN_DIR . '/data-sources/manual.php');
|
||||
include_once(GEOIP_PLUGIN_DIR . '/data-sources/auto.php');
|
||||
include_once(GEOIP_PLUGIN_DIR . '/data-sources/precision.php');
|
||||
include_once(GEOIP_PLUGIN_DIR . '/data-sources/header.php');
|
||||
include_once(GEOIP_PLUGIN_DIR . '/data-sources/ipstack.php');
|
||||
|
||||
// You can define these constants in your theme/plugin if you like.
|
||||
|
||||
/**
|
||||
* Set to TRUE if the plugin should never auto-update the Maxmind City Lite database.
|
||||
*/
|
||||
//define('GEOIP_DETECT_AUTO_UPDATE_DEACTIVATED', true);
|
||||
|
||||
/**
|
||||
* How long the external IP of the server is cached.
|
||||
* This is probably only used in dev cases, so per default relatively low.
|
||||
*/
|
||||
//define('GEOIP_DETECT_IP_CACHE_TIME', 2 * HOUR_IN_SECONDS);
|
||||
|
||||
/**
|
||||
* How long the external IP of the server is cached, if no IP was found.
|
||||
* Default: the same as GEOIP_DETECT_IP_CACHE_TIME
|
||||
*/
|
||||
//define('GEOIP_DETECT_IP_EMPTY_CACHE_TIME', 2 * HOUR_IN_SECONDS);
|
||||
|
||||
/**
|
||||
* How long the data of the IP is cached. This applies to the Web-APIs (Maxmind Precision and HostIP.info)
|
||||
* Only successful lookups will be cached.
|
||||
*/
|
||||
//define('GEOIP_DETECT_READER_CACHE_TIME', 7 * DAY_IN_SECONDS);
|
||||
|
||||
|
||||
|
||||
require_once(GEOIP_PLUGIN_DIR . '/admin-ui.php');
|
||||
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
use YellowTree\GeoipDetect\DataSources\DataSourceRegistry;
|
||||
|
||||
function geoip_detect_defines() {
|
||||
if (!defined('GEOIP_DETECT_IP_CACHE_TIME'))
|
||||
define('GEOIP_DETECT_IP_CACHE_TIME', 2 * HOUR_IN_SECONDS);
|
||||
if (!defined('GEOIP_DETECT_IP_EMPTY_CACHE_TIME'))
|
||||
define('GEOIP_DETECT_IP_EMPTY_CACHE_TIME', GEOIP_DETECT_IP_CACHE_TIME);
|
||||
|
||||
|
||||
if (!defined('GEOIP_DETECT_READER_CACHE_TIME'))
|
||||
define('GEOIP_DETECT_READER_CACHE_TIME', 7 * DAY_IN_SECONDS);
|
||||
if (!defined('GEOIP_DETECT_DOING_UNIT_TESTS'))
|
||||
define('GEOIP_DETECT_DOING_UNIT_TESTS', false);
|
||||
|
||||
|
||||
if (!defined('GEOIP_DETECT_IPV6_SUPPORTED'))
|
||||
define('GEOIP_DETECT_IPV6_SUPPORTED', geoip_detect_check_ipv6_support());
|
||||
|
||||
if (!defined('GEOIP_DETECT_USER_AGENT'))
|
||||
define('GEOIP_DETECT_USER_AGENT', 'GeoIP Detect ' . GEOIP_DETECT_VERSION);
|
||||
}
|
||||
add_action('plugins_loaded', 'geoip_detect_defines');
|
||||
|
||||
|
||||
function geoip_detect_check_ipv6_support() {
|
||||
if (defined('AF_INET6')) {
|
||||
return true;
|
||||
}
|
||||
return @inet_pton('::1') !== false;
|
||||
}
|
||||
|
||||
// Load Locales
|
||||
function geoip_detect_load_textdomain() {
|
||||
load_plugin_textdomain( 'geoip-detect', false, GEOIP_PLUGIN_DIR . '/languages' );
|
||||
}
|
||||
add_action( 'plugins_loaded', 'geoip_detect_load_textdomain' );
|
||||
|
||||
|
||||
function geoip_detect_enqueue_admin_notices() {
|
||||
// Nobody would see them anyway.
|
||||
if (!is_admin() ||
|
||||
!is_user_logged_in() ||
|
||||
(defined('DOING_CRON') && DOING_CRON) ||
|
||||
(defined('DOING_AJAX') && DOING_AJAX) )
|
||||
return;
|
||||
|
||||
global $plugin_page;
|
||||
|
||||
if (get_option('geoip-detect-source') == 'hostinfo' && get_option('geoip-detect-ui-has-chosen-source', false) == false) {
|
||||
if ($plugin_page == GEOIP_PLUGIN_BASENAME && isset($_POST['action']) && $_POST['action'] == 'update') {
|
||||
// Skip because maybe he is currently updating the database
|
||||
} else {
|
||||
add_action( 'all_admin_notices', 'geoip_detect_admin_notice_database_missing' );
|
||||
}
|
||||
}
|
||||
}
|
||||
add_action('admin_init', 'geoip_detect_enqueue_admin_notices');
|
||||
|
||||
function geoip_detect_admin_notice_database_missing() {
|
||||
$ignored_notices = (array) get_user_meta(get_current_user_id(), 'geoip_detect_dismissed_notices', true);
|
||||
if (in_array('hostinfo_used', $ignored_notices) || !current_user_can('manage_options'))
|
||||
return;
|
||||
|
||||
$url = '<a href="tools.php?page=' . GEOIP_PLUGIN_BASENAME . '">GeoIP Detection</a>';
|
||||
?>
|
||||
<div class="error notice is-dismissible">
|
||||
<p style="float: right">
|
||||
<a href="tools.php?page=<?php echo GEOIP_PLUGIN_BASENAME ?>&geoip_detect_dismiss_notice=hostinfo_used"><?php _e('Dismiss notice', 'geoip-detect'); ?></a>
|
||||
|
||||
|
||||
<h3><?php _e( 'GeoIP Detection: No database installed', 'geoip-detect' ); ?></h3>
|
||||
<p><?php printf(__('The Plugin %s is currently using the Webservice <a href="http://hostip.info" target="_blank">hostip.info</a> as data source. <br />You can click on the button below to download and install Maxmind GeoIPv2 Lite City now.', 'geoip-detect' ), $url); ?></p>
|
||||
<p><?php printf(__('This database is licenced <a href="http://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA</a>. See <a href="http://dev.maxmind.com/geoip/geoip2/geolite2/#License">License</a> for details.', 'geoip-detect')); ?>
|
||||
|
||||
|
||||
|
||||
<form action="options-general.php?page=<?php echo GEOIP_PLUGIN_BASENAME; ?>" method="post">
|
||||
<?php wp_nonce_field( 'geoip_detect_update' ); ?>
|
||||
<input type="hidden" name="source" value="auto" />
|
||||
<input type="hidden" name="action" value="update" />
|
||||
<p>
|
||||
<input type="submit" value="<?php esc_attr_e('Install now', 'geoip-detect');?>" class="button button-primary" />
|
||||
<a href="?geoip_detect_dismiss_notice=hostinfo_used"><?php _e('Keep using hostip.info', 'geoip-detect'); ?></a>
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
function geoip_detect_dismiss_message() {
|
||||
if (!is_admin() || !is_user_logged_in())
|
||||
return;
|
||||
|
||||
if (!isset($_GET['geoip_detect_dismiss_notice']))
|
||||
return;
|
||||
|
||||
$dismiss = $_GET['geoip_detect_dismiss_notice'];
|
||||
if ($dismiss) {
|
||||
$ignored_notices = (array) get_user_meta(get_current_user_id(), 'geoip_detect_dismissed_notices', true);
|
||||
|
||||
if ($dismiss == '-1') { // Undocumented feature: reset dismissed messages
|
||||
$ignored_notices = array();
|
||||
} else if (!in_array($dismiss, $ignored_notices)) {
|
||||
$ignored_notices[] = $dismiss;
|
||||
}
|
||||
|
||||
update_user_meta(get_current_user_id(), 'geoip_detect_dismissed_notices', $ignored_notices);
|
||||
}
|
||||
}
|
||||
add_action('admin_init', 'geoip_detect_dismiss_message');
|
||||
|
||||
// --------------------------------------- Privacy (GDPR) -------------------------------
|
||||
|
||||
|
||||
function geoip_detect_add_privacy_policy_content() {
|
||||
if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$registry = DataSourceRegistry::getInstance();
|
||||
|
||||
$caching = '';
|
||||
if (GEOIP_DETECT_READER_CACHE_TIME > 0 && !$registry->isCachingUsed()) {
|
||||
$caching = sprintf(__('This site is saving the IP of the visitors of the last %s for performance reasons.', 'geoip-detect'), human_time_diff(0, GEOIP_DETECT_READER_CACHE_TIME));
|
||||
}
|
||||
if ($registry->isCachingUsed()) {
|
||||
$caching = __('This site is sending the visitor\'s IP to (add Provider name) in order to receive the geographic information. (You will need to have a data-processing contract with this provider.)', 'geoip-detect');
|
||||
}
|
||||
$source = geoip_detect2_get_current_source_description();
|
||||
$content = '<p>' . sprintf(__( 'This site is using %s to identify the geographic location of your IP adress. %s (Add here: how this information is used, how long it is retained. Be especially careful when using this information to change prices or selling options, as this might not be legal.)', 'geoip-detect' ),
|
||||
$source, $caching) . '</p>';
|
||||
|
||||
if (get_option('geoip-detect-ajax_enabled') ) {
|
||||
if ((get_option('geoip-detect-ajax_enqueue_js') || get_option('geoip-detect-set_css_country'))) {
|
||||
$content .= '<p>' . __('In order to increase the performance of this site, it is setting a cookie called "geoip-detect-result" containing the geographic information of the current user. (Explain how the information stored in this cookie will be used, e.g.: This information is not used for tracking purposes, but ...) The cookie will automatically deleted after 1 day by your browser.', 'geoip-detect') . '</p>';
|
||||
}
|
||||
}
|
||||
|
||||
wp_add_privacy_policy_content(
|
||||
'GeoIP Detection',
|
||||
wp_kses_post( wpautop( $content, false ) )
|
||||
);
|
||||
}
|
||||
add_action( 'admin_init', 'geoip_detect_add_privacy_policy_content' );
|
||||
|
||||
|
||||
/**
|
||||
* This function is called when the user clicks on "Remove" in the wp-admin
|
||||
*/
|
||||
function on_uninstall() {
|
||||
$registry = DataSourceRegistry::getInstance();
|
||||
$registry->uninstall();
|
||||
}
|
||||
register_uninstall_hook(GEOIP_PLUGIN_FILE, __NAMESPACE__ . '\\on_uninstall');
|
||||
|
||||
// For Debugging purposes ...
|
||||
if (WP_DEBUG && isset($_GET['uninstall']) && $_GET['uninstall'] == 'asdf') {
|
||||
|
||||
add_action('plugins_loaded', function() {
|
||||
on_uninstall();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/**
|
||||
* Get a jQuery Promise that will delive the AJAX data.
|
||||
* @param locales Locales to fill in the 'name' field (optional)
|
||||
* @returns promise
|
||||
*/
|
||||
|
||||
function geoip_detect_ajax_promise(locales) {
|
||||
locales = locales || '';
|
||||
|
||||
var promise = jQuery.ajax(geoip_detect.ajaxurl, {
|
||||
dataType: 'json',
|
||||
type: 'GET',
|
||||
data: {
|
||||
action: 'geoip_detect2_get_info_from_current_ip',
|
||||
locales: locales
|
||||
}
|
||||
});
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get property value from data
|
||||
*
|
||||
* @param data
|
||||
* @param property_name
|
||||
* @param options
|
||||
*/
|
||||
function geoip_detect_get_property_value(data, property_name, options) {
|
||||
var _get_name = function(names, locales) {
|
||||
if (typeof(locales) === 'string') {
|
||||
locales = locales.split(',');
|
||||
}
|
||||
|
||||
for (var l in locales) {
|
||||
//l = l.trim();
|
||||
if (typeof(names[l]) != 'undefined' && names[l])
|
||||
return names[l];
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
var $ = jQuery;
|
||||
var default_options = {
|
||||
'locales' : 'en',
|
||||
'default' : '',
|
||||
};
|
||||
options = $.extend(options, default_options);
|
||||
|
||||
var properties = property_name.split('.');
|
||||
var next_property = properties.shift();
|
||||
if (next_property == 'name' || !next_property) {
|
||||
if (typeof(data['names']) == 'object') {
|
||||
return _get_name(data['names'], options.locales);
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
if (typeof(data[next_property]) == 'undefined')
|
||||
return options['default'];
|
||||
if (typeof(data[next_property]) == 'string')
|
||||
return data[next_property];
|
||||
return geoip_detect_get_property_value(data[next_property], properties.join('.'), options);
|
||||
}
|
||||
|
||||
function geoip_detect_fill_data_attributes(el) {
|
||||
var $ = jQuery;
|
||||
el = $(el);
|
||||
// Fill in the shortcodes into the HTML
|
||||
var shortcodes = el.find('[data-geoip]');
|
||||
if (!shortcodes.length)
|
||||
return;
|
||||
|
||||
var promise = geoip_detect_ajax_promise('en');
|
||||
|
||||
promise.done(function(data) {
|
||||
shortcodes.each(function() {
|
||||
var options = $(this).data('geoip');
|
||||
var value = geoip_detect_get_property_value(data, options.property, options);
|
||||
|
||||
if ($(this).data('geoip-method') == 'class')
|
||||
$(this).addClass('geoip-' + value);
|
||||
else
|
||||
$(this).text(value);
|
||||
$(this).trigger('geoip_detect.value.success');
|
||||
});
|
||||
}).fail(function(data) {
|
||||
if (typeof(console) != 'undefined' && typeof(console.log) != 'undefined')
|
||||
console.log('Error: ' + data.error);
|
||||
shortcodes.trigger('geoip_detect.value.failure');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
jQuery(document).ready(function($) {
|
||||
geoip_detect_fill_data_attributes('html');
|
||||
});
|
||||
@@ -0,0 +1,102 @@
|
||||
import Record from './models/record';
|
||||
import Cookies from 'js-cookie';
|
||||
|
||||
if (!window.jQuery) {
|
||||
console.error('Geoip-detect: window.jQuery is missing!');
|
||||
}
|
||||
const $ = window.jQuery;
|
||||
|
||||
|
||||
if (!window.geoip_detect) {
|
||||
console.error('Geoip-detect: window.geoip_detect')
|
||||
}
|
||||
const options = window.geoip_detect.options || {};
|
||||
|
||||
let ajaxPromise = null;
|
||||
|
||||
function get_info_raw() {
|
||||
if (!ajaxPromise) {
|
||||
// Do Ajax Request only once per page load
|
||||
ajaxPromise = $.ajax(options.ajaxurl, {
|
||||
dataType: 'json',
|
||||
type: 'GET',
|
||||
data: {
|
||||
action: 'geoip_detect2_get_info_from_current_ip'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return ajaxPromise;
|
||||
}
|
||||
|
||||
async function get_info_cached() {
|
||||
let response = false;
|
||||
|
||||
// 1) Load Info from cookie cache, if possible
|
||||
if (options.cookie_name) {
|
||||
response = Cookies.getJSON(options.cookie_name)
|
||||
}
|
||||
|
||||
// 2) Get response
|
||||
try {
|
||||
response = await get_info_raw();
|
||||
} catch(err) {
|
||||
response = err.responseJSON || err;
|
||||
}
|
||||
|
||||
// 3) Save info to cookie cache
|
||||
if (options.cookie_name) {
|
||||
let cookie_options = { path: '/' };
|
||||
if (options.cookie_duration_in_days) {
|
||||
cookie_options.expires = options.cookie_duration_in_days;
|
||||
}
|
||||
Cookies.set(options.cookie_name, JSON.stringify(response), cookie_options);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
export async function get_info() {
|
||||
let response = await get_info_cached();
|
||||
|
||||
if (typeof(response) !== 'object') {
|
||||
console.error('Geoip-detect: Record should be an object, not a ' + typeof(response), response);
|
||||
response = { 'extra': { 'error': response || 'Network error, look at the original server response ...' }};
|
||||
}
|
||||
|
||||
const record = new Record(response, options.default_locales);
|
||||
return record;
|
||||
}
|
||||
|
||||
async function add_body_classes() {
|
||||
const record = await get_info();
|
||||
|
||||
if (record.error()) {
|
||||
console.error('Geodata Error (could not add CSS-classes to body): ' + record.error());
|
||||
}
|
||||
|
||||
const css_classes = {
|
||||
country: record.get('country.iso_code'),
|
||||
'country-is-in-european-union': record.get('country.is_in_european_union'),
|
||||
continent: record.get('continent.code'),
|
||||
province: record.get('most_specific_subdivision.iso_code'),
|
||||
};
|
||||
|
||||
for(let key of Object.keys(css_classes)) {
|
||||
const value = css_classes[key];
|
||||
if (value) {
|
||||
if (typeof(value) == 'string') {
|
||||
$('body').addClass(`geoip-${key}-${value}`);
|
||||
} else {
|
||||
$('body').addClass(`geoip-${key}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (options.do_body_classes) {
|
||||
add_body_classes();
|
||||
}
|
||||
|
||||
// Extend window object
|
||||
window.geoip_detect.get_info = get_info;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* @license
|
||||
* Lodash (Custom Build) lodash.com/license | Underscore.js 1.8.3 underscorejs.org/LICENSE
|
||||
* Build: `lodash include="get" -o js/lodash.custom.js`
|
||||
*/
|
||||
;(function(){function t(){}function e(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function n(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function r(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function o(t,e){for(var n=t.length;n--;)if(f(t[n][0],e))return n;return-1}function i(t){if(null==t)t=t===b?"[object Undefined]":"[object Null]";else if(I&&I in Object(t)){var e=T.call(t,I),n=t[I];
|
||||
try{t[I]=b;var r=true}catch(t){}var o=P.call(t);r&&(e?t[I]=n:delete t[I]),t=o}else t=P.call(t);return t}function a(t){if(typeof t=="string")return t;if(M(t)){for(var e=-1,n=null==t?0:t.length,r=Array(n);++e<n;)r[e]=a(t[e]);return r+""}return y(t)?G?G.call(t):"":(e=t+"","0"==e&&1/t==-g?"-0":e)}function c(t,e){var n=t.__data__,r=typeof e;return("string"==r||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==e:null===e)?n[typeof e=="string"?"string":"hash"]:n.map}function u(t,e){var n=null==t?b:t[e];
|
||||
return(!h(n)||C&&C in n?0:(p(n)?k:z).test(s(n)))?n:b}function s(t){if(null!=t){try{return E.call(t)}catch(t){}return t+""}return""}function l(t,e){function n(){var r=arguments,o=e?e.apply(this,r):r[0],i=n.cache;return i.has(o)?i.get(o):(r=t.apply(this,r),n.cache=i.set(o,r)||i,r)}if(typeof t!="function"||null!=e&&typeof e!="function")throw new TypeError("Expected a function");return n.cache=new(l.Cache||r),n}function f(t,e){return t===e||t!==t&&e!==e}function p(t){return!!h(t)&&(t=i(t),"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t);
|
||||
}function h(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function _(t){return null!=t&&typeof t=="object"}function y(t){return typeof t=="symbol"||_(t)&&"[object Symbol]"==i(t)}function d(t){return null==t?"":a(t)}var b,g=1/0,v=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,j=/^\w*$/,m=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,O=/\\(\\)?/g,z=/^\[object .+?Constructor\]$/,S=typeof self=="object"&&self&&self.Object===Object&&self,S=typeof global=="object"&&global&&global.Object===Object&&global||S||Function("return this")(),w=typeof exports=="object"&&exports&&!exports.nodeType&&exports,x=w&&typeof module=="object"&&module&&!module.nodeType&&module,$=Array.prototype,A=Object.prototype,F=S["__core-js_shared__"],E=Function.prototype.toString,T=A.hasOwnProperty,C=function(){
|
||||
var t=/[^.]+$/.exec(F&&F.keys&&F.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),P=A.toString,k=RegExp("^"+E.call(T).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),A=S.Symbol,R=$.splice,I=A?A.toStringTag:b,N=u(S,"Map"),q=u(Object,"create"),G=($=A?A.prototype:b)?$.toString:b;e.prototype.clear=function(){this.__data__=q?q(null):{},this.size=0},e.prototype.delete=function(t){return t=this.has(t)&&delete this.__data__[t],this.size-=t?1:0,
|
||||
t},e.prototype.get=function(t){var e=this.__data__;return q?(t=e[t],"__lodash_hash_undefined__"===t?b:t):T.call(e,t)?e[t]:b},e.prototype.has=function(t){var e=this.__data__;return q?e[t]!==b:T.call(e,t)},e.prototype.set=function(t,e){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=q&&e===b?"__lodash_hash_undefined__":e,this},n.prototype.clear=function(){this.__data__=[],this.size=0},n.prototype.delete=function(t){var e=this.__data__;return t=o(e,t),!(0>t)&&(t==e.length-1?e.pop():R.call(e,t,1),
|
||||
--this.size,true)},n.prototype.get=function(t){var e=this.__data__;return t=o(e,t),0>t?b:e[t][1]},n.prototype.has=function(t){return-1<o(this.__data__,t)},n.prototype.set=function(t,e){var n=this.__data__,r=o(n,t);return 0>r?(++this.size,n.push([t,e])):n[r][1]=e,this},r.prototype.clear=function(){this.size=0,this.__data__={hash:new e,map:new(N||n),string:new e}},r.prototype.delete=function(t){return t=c(this,t).delete(t),this.size-=t?1:0,t},r.prototype.get=function(t){return c(this,t).get(t)},r.prototype.has=function(t){
|
||||
return c(this,t).has(t)},r.prototype.set=function(t,e){var n=c(this,t),r=n.size;return n.set(t,e),this.size+=n.size==r?0:1,this};var L=function(t){t=l(t,function(t){return 500===e.size&&e.clear(),t});var e=t.cache;return t}(function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(m,function(t,n,r,o){e.push(r?o.replace(O,"$1"):n||t)}),e});l.Cache=r;var M=Array.isArray;t.memoize=l,t.eq=f,t.get=function(t,e,n){if(null==t)t=b;else{var r=t;if(!M(e)){if(M(e))r=false;else var o=typeof e,r=!("number"!=o&&"symbol"!=o&&"boolean"!=o&&null!=e&&!y(e))||(j.test(e)||!v.test(e)||null!=r&&e in Object(r));
|
||||
e=r?[e]:L(d(e))}for(r=0,o=e.length;null!=t&&r<o;){var i;if(i=e[r++],typeof i!="string"&&!y(i)){var a=i+"";i="0"==a&&1/i==-g?"-0":a}t=t[i]}t=r&&r==o?t:b}return t===b?n:t},t.isArray=M,t.isFunction=p,t.isObject=h,t.isObjectLike=_,t.isSymbol=y,t.toString=d,t.VERSION="4.17.5",typeof define=="function"&&typeof define.amd=="object"&&define.amd?(S._=t, define(function(){return t})):x?((x.exports=t)._=t,w._=t):S._=t}).call(this);
|
||||
@@ -0,0 +1,58 @@
|
||||
|
||||
import _ from '../lodash.custom';
|
||||
|
||||
|
||||
const _get_localized = function(ret, locales) {
|
||||
if (typeof(ret) == 'object' && typeof(ret.names) == 'object') {
|
||||
for (let locale of locales) {
|
||||
if (ret.names[locale]) {
|
||||
return ret.names[locale];
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
class Record {
|
||||
data = {};
|
||||
default_locales = [];
|
||||
|
||||
constructor(data, default_locales) {
|
||||
this.data = data || {};
|
||||
this.default_locales = default_locales || ['en'];
|
||||
}
|
||||
|
||||
get(prop, default_value) {
|
||||
return this.get_with_locales(prop, this.default_locales, default_value);
|
||||
}
|
||||
|
||||
|
||||
get_with_locales(prop, locales, default_value) {
|
||||
// Treat pseudo-property 'name' as if it never existed
|
||||
if (prop.substr(-5) === '.name') {
|
||||
prop = prop.substr(0, prop.length - 5);
|
||||
}
|
||||
|
||||
// TODO handle most_specific_subdivision (here or in PHP)?
|
||||
|
||||
let ret = _.get(this.data, prop, default_value);
|
||||
|
||||
// Localize property, if possible
|
||||
ret = _get_localized(ret, locales);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get error message, if any
|
||||
* @return string Error Message
|
||||
*/
|
||||
error() {
|
||||
return _.get(this.data, 'extra.error', '');
|
||||
}
|
||||
}
|
||||
|
||||
export default Record;
|
||||
@@ -0,0 +1,371 @@
|
||||
# Copyright (C) 2016 GeoIP Detection
|
||||
# This file is distributed under the same license as the package.
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: GeoIP Detection 2.5.4\n"
|
||||
"Report-Msgid-Bugs-To: http://wordpress.org/tag/geoip-detect\n"
|
||||
"POT-Creation-Date: 2016-01-06 01:34:25+00:00\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"PO-Revision-Date: 2016-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
||||
#: admin-ui.php:7
|
||||
msgid "GeoIP Detection Lookup"
|
||||
msgstr ""
|
||||
|
||||
#: admin-ui.php:7
|
||||
msgid "GeoIP Lookup"
|
||||
msgstr ""
|
||||
|
||||
#: admin-ui.php:8 views/lookup.php:19 views/options.php:6
|
||||
msgid "GeoIP Detection"
|
||||
msgstr ""
|
||||
|
||||
#: admin-ui.php:13 views/lookup.php:45
|
||||
msgid "Lookup"
|
||||
msgstr ""
|
||||
|
||||
#: admin-ui.php:16
|
||||
msgid "Options"
|
||||
msgstr ""
|
||||
|
||||
#: admin-ui.php:85
|
||||
msgid "Updated successfully."
|
||||
msgstr ""
|
||||
|
||||
#: admin-ui.php:87
|
||||
msgid "Update failed."
|
||||
msgstr ""
|
||||
|
||||
#: check_requirements.php:40
|
||||
msgid "GeoIP Detection: Minimum requirements not met."
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/auto.php:12
|
||||
msgid "Automatic download & update of Maxmind GeoIP Lite City"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/auto.php:13
|
||||
msgid "%s (updated monthly)"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/auto.php:14
|
||||
msgid ""
|
||||
"(License: Creative Commons Attribution-ShareAlike 3.0 Unported. See <a href="
|
||||
"\"https://github.com/yellowtree/wp-geoip-detect/wiki/FAQ#the-maxmind-lite-"
|
||||
"databases-are-licensed-creative-commons-sharealike-attribution-when-do-i-"
|
||||
"need-to-give-attribution\" target=\"_blank\">Licensing FAQ</a> for more "
|
||||
"details.)"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/auto.php:21
|
||||
msgid "Next update: %s"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/auto.php:21 data-sources/manual.php:36
|
||||
msgid "Never"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/auto.php:27
|
||||
msgid "Update now"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/auto.php:88
|
||||
msgid "Downloaded file could not be opened for reading."
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/auto.php:90
|
||||
msgid "Database could not be written (%s)."
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/hostinfo.php:96
|
||||
msgid "HostIP.info Web-API"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/hostinfo.php:98
|
||||
msgid ""
|
||||
"Free (Licence: GPL)<br />(only English names, does only have the following "
|
||||
"fields: country name, country ID and city name)"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/hostinfo.php:99
|
||||
msgid "You can choose a Maxmind database below."
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/manual.php:12
|
||||
msgid "Manual download & update of a Maxmind City or Country database"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/manual.php:14
|
||||
msgid ""
|
||||
"<a href=\"http://dev.maxmind.com/geoip/geoip2/geolite2/\" target=\"_blank"
|
||||
"\">Free version</a> - <a href=\"https://www.maxmind.com/en/geoip2-country-"
|
||||
"database\" target=\"_blank\">Commercial Version</a>"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/manual.php:21
|
||||
msgid "No Maxmind database found."
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/manual.php:25
|
||||
msgid "Database file: %s"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/manual.php:36
|
||||
msgid "Last updated: %s"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/manual.php:37
|
||||
msgid "Database data from: %s"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/manual.php:50
|
||||
msgid "Current value: %s"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/manual.php:71
|
||||
msgid "The manual datafile has not been found or is not a mmdb-File. "
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/manual.php:91 data-sources/manual.php:137
|
||||
msgid "Error while creating reader for \"%s\": %s"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/manual.php:148 data-sources/manual.php:155
|
||||
msgid "Maxmind File Database (file does not exist or is not readable)"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/precision.php:64
|
||||
msgid "Maxmind Precision Web-API"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/precision.php:66
|
||||
msgid ""
|
||||
"<a href=\"https://www.maxmind.com/en/geoip2-precision-services\">Maxmind "
|
||||
"Precision Services</a>"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/precision.php:69
|
||||
msgid "API Type: %s"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/precision.php:73
|
||||
msgid "Remaining Credits: ca. %s"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/precision.php:77 data-sources/precision.php:124
|
||||
msgid "Maxmind Precision only works with a given user id and secret."
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/precision.php:87
|
||||
msgid "User ID:"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/precision.php:88
|
||||
msgid "User Secret:"
|
||||
msgstr ""
|
||||
|
||||
#: data-sources/precision.php:89
|
||||
msgid "API Type:"
|
||||
msgstr ""
|
||||
|
||||
#: init.php:48
|
||||
msgid "Dismiss notice"
|
||||
msgstr ""
|
||||
|
||||
#: init.php:51
|
||||
msgid "GeoIP Detection: No database installed"
|
||||
msgstr ""
|
||||
|
||||
#: init.php:52
|
||||
msgid ""
|
||||
"The Plugin %s is currently using the Webservice <a href=\"http://hostip.info"
|
||||
"\" target=\"_blank\">hostip.info</a> as data source. <br />You can click on "
|
||||
"the button below to download and install Maxmind GeoIPv2 Lite City now."
|
||||
msgstr ""
|
||||
|
||||
#: init.php:53
|
||||
msgid ""
|
||||
"This database is licenced <a href=\"http://creativecommons.org/licenses/by-"
|
||||
"sa/3.0/\">CC BY-SA</a>. See <a href=\"http://dev.maxmind.com/geoip/geoip2/"
|
||||
"geolite2/#License\">License</a> for details."
|
||||
msgstr ""
|
||||
|
||||
#: init.php:62
|
||||
msgid "Install now"
|
||||
msgstr ""
|
||||
|
||||
#: init.php:63
|
||||
msgid "Keep using hostip.info"
|
||||
msgstr ""
|
||||
|
||||
#: views/footer.php:4
|
||||
msgid ""
|
||||
"This extension is \"charity-ware\". You can use it for free but if you want "
|
||||
"to do me a favor, please <a href=\"%s\" target=\"_blank\">donate</a> to <a "
|
||||
"href=\"%s\" target=\"_blank\">this charity</a>. (See <a href=\"%s\" target="
|
||||
"\"_blank\">FAQ</a> for more infos.)"
|
||||
msgstr ""
|
||||
|
||||
#: views/footer.php:10
|
||||
msgid ""
|
||||
"This product includes GeoLite2 data created by MaxMind, available from <a "
|
||||
"href=\"http://www.maxmind.com/\">http://www.maxmind.com</a>."
|
||||
msgstr ""
|
||||
|
||||
#: views/lookup.php:23 views/options.php:15
|
||||
msgid "<b>Selected data source:</b> %s"
|
||||
msgstr ""
|
||||
|
||||
#: views/lookup.php:36
|
||||
msgid "IP"
|
||||
msgstr ""
|
||||
|
||||
#: views/lookup.php:36
|
||||
msgid "Enter an IP (v4 or v6)"
|
||||
msgstr ""
|
||||
|
||||
#: views/lookup.php:37
|
||||
msgid "Use these locales:"
|
||||
msgstr ""
|
||||
|
||||
#: views/lookup.php:39
|
||||
msgid "Default (Current site language, English otherwise)"
|
||||
msgstr ""
|
||||
|
||||
#: views/lookup.php:40
|
||||
msgid "English only"
|
||||
msgstr ""
|
||||
|
||||
#: views/lookup.php:41
|
||||
msgid "French, English otherwise"
|
||||
msgstr ""
|
||||
|
||||
#: views/lookup.php:43
|
||||
msgid "Skip cache"
|
||||
msgstr ""
|
||||
|
||||
#: views/lookup.php:53
|
||||
msgid "The function %s returns an object:"
|
||||
msgstr ""
|
||||
|
||||
#: views/lookup.php:54
|
||||
msgid "Lookup duration: %.5f s"
|
||||
msgstr ""
|
||||
|
||||
#: views/lookup.php:56
|
||||
msgid "(Served from cache. Was cached %s ago)"
|
||||
msgstr ""
|
||||
|
||||
#: views/lookup.php:68
|
||||
msgid "Key"
|
||||
msgstr ""
|
||||
|
||||
#: views/lookup.php:69
|
||||
msgid "Value"
|
||||
msgstr ""
|
||||
|
||||
#: views/lookup.php:70
|
||||
msgid "Shortcode equivalent"
|
||||
msgstr ""
|
||||
|
||||
#: views/lookup.php:123
|
||||
msgid "No information found about this IP."
|
||||
msgstr ""
|
||||
|
||||
#: views/lookup.php:128
|
||||
msgid "See %s for more documentation."
|
||||
msgstr ""
|
||||
|
||||
#: views/options.php:7
|
||||
msgid "Test IP Detection Lookup"
|
||||
msgstr ""
|
||||
|
||||
#: views/options.php:21
|
||||
msgid "Options for this data source"
|
||||
msgstr ""
|
||||
|
||||
#: views/options.php:28 views/options.php:48 views/options.php:89
|
||||
msgid "Save"
|
||||
msgstr ""
|
||||
|
||||
#: views/options.php:39
|
||||
msgid "Choose data source:"
|
||||
msgstr ""
|
||||
|
||||
#: views/options.php:53
|
||||
msgid "General Options"
|
||||
msgstr ""
|
||||
|
||||
#: views/options.php:55
|
||||
msgid "Add a country-specific CSS class to the <body>-Tag."
|
||||
msgstr ""
|
||||
|
||||
#: views/options.php:58
|
||||
msgid ""
|
||||
"Disable caching a page that contains a shortcode or API call to geo-"
|
||||
"dependent functions."
|
||||
msgstr ""
|
||||
|
||||
#: views/options.php:60
|
||||
msgid "At least WP SuperCache, W3TotalCache and ZenCache are supported."
|
||||
msgstr ""
|
||||
|
||||
#: views/options.php:63
|
||||
msgid ""
|
||||
"Warning: As the CSS option above is active, this means that all pages are "
|
||||
"not cached."
|
||||
msgstr ""
|
||||
|
||||
#: views/options.php:68
|
||||
msgid "The server is behind a reverse proxy"
|
||||
msgstr ""
|
||||
|
||||
#: views/options.php:71
|
||||
msgid ""
|
||||
"(With Proxy: %s - Without Proxy: %s - Client IP with current configuration: "
|
||||
"%s)"
|
||||
msgstr ""
|
||||
|
||||
#: views/options.php:73
|
||||
msgid "(This doesn't seem to be the case.)"
|
||||
msgstr ""
|
||||
|
||||
#: views/options.php:79
|
||||
msgid "External IP of this server:"
|
||||
msgstr ""
|
||||
|
||||
#: views/options.php:79
|
||||
msgid "detect automatically"
|
||||
msgstr ""
|
||||
|
||||
#: views/options.php:81
|
||||
msgid "Current value:"
|
||||
msgstr ""
|
||||
|
||||
#: views/options.php:82
|
||||
msgid ""
|
||||
"If empty: Try to use an ip service to detect it (Internet connection is "
|
||||
"necessary). If this is not possible, 0.0.0.0 will be returned."
|
||||
msgstr ""
|
||||
|
||||
#: views/options.php:83
|
||||
msgid ""
|
||||
"(This external adress will be used when the request IP adress is not a "
|
||||
"public IP, e.g. 127.0.0.1)"
|
||||
msgstr ""
|
||||
|
||||
#: views/options.php:94
|
||||
msgid "IPv6 not supported"
|
||||
msgstr ""
|
||||
|
||||
#: views/options.php:96
|
||||
msgid ""
|
||||
"Your version of PHP is compiled without IPv6-support, so it is not possible "
|
||||
"to lookup adresses like \"2001:4860:4801:5::91\". For more information see "
|
||||
"<a href=\"https://php.net/manual/en/function.inet-pton.php\">PHP "
|
||||
"documentation & user comments</a>."
|
||||
msgstr ""
|
||||
@@ -0,0 +1,365 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright 2013-2019 Yellow Tree, Siegen, Germany
|
||||
Author: Benjamin Pick (wp-geoip-detect| |posteo.de)
|
||||
|
||||
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 3 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
if (!class_exists('geoiprecord')) {
|
||||
class geoiprecord
|
||||
{
|
||||
public $country_code;
|
||||
public $country_code3;
|
||||
public $country_name;
|
||||
public $region;
|
||||
public $city;
|
||||
public $postal_code;
|
||||
public $latitude;
|
||||
public $longitude;
|
||||
public $area_code;
|
||||
public $dma_code;
|
||||
public $metro_code;
|
||||
public $continent_code;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Geo-Information for a specific IP
|
||||
* @param string $ip IP-Adress (currently only IPv4)
|
||||
* @return geoiprecord GeoInformation. (0 or NULL: no infos found.)
|
||||
* @deprecated since v2.0
|
||||
*/
|
||||
function geoip_detect_get_info_from_ip($ip)
|
||||
{
|
||||
$ret = geoip_detect2_get_info_from_ip($ip);
|
||||
if ($ret == null || !$ret->country->name) // Better way to detect "empty?"
|
||||
$ret = geoip_detect2_get_info_from_ip('me');
|
||||
|
||||
$record = null;
|
||||
|
||||
if (is_object($ret)) {
|
||||
$mapping = _geoip_detect_get_country_code_mapping();
|
||||
|
||||
$record = new geoiprecord();
|
||||
|
||||
$record->country_code = $ret->country->isoCode;
|
||||
$record->country_code3 = $mapping[$record->country_code];
|
||||
$record->country_name = $ret->country->name;
|
||||
$record->region = $ret->mostSpecificSubdivision->isoCode;
|
||||
$record->region_name = $ret->mostSpecificSubdivision->name;
|
||||
$record->city = $ret->city->name;
|
||||
$record->postal_code = $ret->postal->code;
|
||||
$record->latitude = $ret->location->latitude;
|
||||
$record->longitude = $ret->location->longitude;
|
||||
$record->continent_code = $ret->continent->code;
|
||||
$record->metro_code = $ret->location->metroCode;
|
||||
$record->timezone = $ret->location->timeZone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter: geoip_detect_record_information
|
||||
* After loading the information from the GeoIP-Database, you can add or remove information from it.
|
||||
* @param geoiprecord $record Information found.
|
||||
* @param string $ip IP that was looked up
|
||||
* @return geoiprecord
|
||||
* @deprecated since v2.0
|
||||
*/
|
||||
$record = apply_filters('geoip_detect_record_information', $record, $ip);
|
||||
|
||||
return $record;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Geo-Information for the current IP
|
||||
* @param string $ip (IPv4)
|
||||
* @return geoiprecord GeoInformation. (0 / NULL: no infos found.)
|
||||
* @deprecated since v2.0
|
||||
*/
|
||||
function geoip_detect_get_info_from_current_ip()
|
||||
{
|
||||
return geoip_detect_get_info_from_ip(geoip_detect2_get_client_ip());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get client IP (even if it is behind a reverse proxy)
|
||||
* @deprecated since v2.0
|
||||
*/
|
||||
function geoip_detect_get_client_ip() {
|
||||
return geoip_detect2_get_client_ip();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sometimes we can only see an local IP adress (local development environment.)
|
||||
* In this case we need to ask an internet server which IP adress our internet connection has.
|
||||
*
|
||||
* @deprecated since v2.0
|
||||
* @return string The detected IP Adress. If none is found, '0.0.0.0' is returned instead.
|
||||
*/
|
||||
function geoip_detect_get_external_ip_adress()
|
||||
{
|
||||
return geoip_detect2_get_external_ip_adress();
|
||||
}
|
||||
|
||||
function _geoip_detect_get_country_code_mapping() {
|
||||
return array (
|
||||
'' => '',
|
||||
'A1' => 'A1',
|
||||
'A2' => 'A2',
|
||||
'AD' => 'AND',
|
||||
'AE' => 'ARE',
|
||||
'AF' => 'AFG',
|
||||
'AG' => 'ATG',
|
||||
'AI' => 'AIA',
|
||||
'AL' => 'ALB',
|
||||
'AM' => 'ARM',
|
||||
'AO' => 'AGO',
|
||||
'AP' => 'AP',
|
||||
'AQ' => 'ATA',
|
||||
'AR' => 'ARG',
|
||||
'AS' => 'ASM',
|
||||
'AT' => 'AUT',
|
||||
'AU' => 'AUS',
|
||||
'AW' => 'ABW',
|
||||
'AX' => 'ALA',
|
||||
'AZ' => 'AZE',
|
||||
'BA' => 'BIH',
|
||||
'BB' => 'BRB',
|
||||
'BD' => 'BGD',
|
||||
'BE' => 'BEL',
|
||||
'BF' => 'BFA',
|
||||
'BG' => 'BGR',
|
||||
'BH' => 'BHR',
|
||||
'BI' => 'BDI',
|
||||
'BJ' => 'BEN',
|
||||
'BL' => 'BLM',
|
||||
'BM' => 'BMU',
|
||||
'BN' => 'BRN',
|
||||
'BO' => 'BOL',
|
||||
'BQ' => 'BES',
|
||||
'BR' => 'BRA',
|
||||
'BS' => 'BHS',
|
||||
'BT' => 'BTN',
|
||||
'BV' => 'BVT',
|
||||
'BW' => 'BWA',
|
||||
'BY' => 'BLR',
|
||||
'BZ' => 'BLZ',
|
||||
'CA' => 'CAN',
|
||||
'CC' => 'CCK',
|
||||
'CD' => 'COD',
|
||||
'CF' => 'CAF',
|
||||
'CG' => 'COG',
|
||||
'CH' => 'CHE',
|
||||
'CI' => 'CIV',
|
||||
'CK' => 'COK',
|
||||
'CL' => 'CHL',
|
||||
'CM' => 'CMR',
|
||||
'CN' => 'CHN',
|
||||
'CO' => 'COL',
|
||||
'CR' => 'CRI',
|
||||
'CU' => 'CUB',
|
||||
'CV' => 'CPV',
|
||||
'CW' => 'CUW',
|
||||
'CX' => 'CXR',
|
||||
'CY' => 'CYP',
|
||||
'CZ' => 'CZE',
|
||||
'DE' => 'DEU',
|
||||
'DJ' => 'DJI',
|
||||
'DK' => 'DNK',
|
||||
'DM' => 'DMA',
|
||||
'DO' => 'DOM',
|
||||
'DZ' => 'DZA',
|
||||
'EC' => 'ECU',
|
||||
'EE' => 'EST',
|
||||
'EG' => 'EGY',
|
||||
'EH' => 'ESH',
|
||||
'ER' => 'ERI',
|
||||
'ES' => 'ESP',
|
||||
'ET' => 'ETH',
|
||||
'EU' => 'EU',
|
||||
'FI' => 'FIN',
|
||||
'FJ' => 'FJI',
|
||||
'FK' => 'FLK',
|
||||
'FM' => 'FSM',
|
||||
'FO' => 'FRO',
|
||||
'FR' => 'FRA',
|
||||
'GA' => 'GAB',
|
||||
'GB' => 'GBR',
|
||||
'GD' => 'GRD',
|
||||
'GE' => 'GEO',
|
||||
'GF' => 'GUF',
|
||||
'GG' => 'GGY',
|
||||
'GH' => 'GHA',
|
||||
'GI' => 'GIB',
|
||||
'GL' => 'GRL',
|
||||
'GM' => 'GMB',
|
||||
'GN' => 'GIN',
|
||||
'GP' => 'GLP',
|
||||
'GQ' => 'GNQ',
|
||||
'GR' => 'GRC',
|
||||
'GS' => 'SGS',
|
||||
'GT' => 'GTM',
|
||||
'GU' => 'GUM',
|
||||
'GW' => 'GNB',
|
||||
'GY' => 'GUY',
|
||||
'HK' => 'HKG',
|
||||
'HM' => 'HMD',
|
||||
'HN' => 'HND',
|
||||
'HR' => 'HRV',
|
||||
'HT' => 'HTI',
|
||||
'HU' => 'HUN',
|
||||
'ID' => 'IDN',
|
||||
'IE' => 'IRL',
|
||||
'IL' => 'ISR',
|
||||
'IM' => 'IMN',
|
||||
'IN' => 'IND',
|
||||
'IO' => 'IOT',
|
||||
'IQ' => 'IRQ',
|
||||
'IR' => 'IRN',
|
||||
'IS' => 'ISL',
|
||||
'IT' => 'ITA',
|
||||
'JE' => 'JEY',
|
||||
'JM' => 'JAM',
|
||||
'JO' => 'JOR',
|
||||
'JP' => 'JPN',
|
||||
'KE' => 'KEN',
|
||||
'KG' => 'KGZ',
|
||||
'KH' => 'KHM',
|
||||
'KI' => 'KIR',
|
||||
'KM' => 'COM',
|
||||
'KN' => 'KNA',
|
||||
'KP' => 'PRK',
|
||||
'KR' => 'KOR',
|
||||
'KW' => 'KWT',
|
||||
'KY' => 'CYM',
|
||||
'KZ' => 'KAZ',
|
||||
'LA' => 'LAO',
|
||||
'LB' => 'LBN',
|
||||
'LC' => 'LCA',
|
||||
'LI' => 'LIE',
|
||||
'LK' => 'LKA',
|
||||
'LR' => 'LBR',
|
||||
'LS' => 'LSO',
|
||||
'LT' => 'LTU',
|
||||
'LU' => 'LUX',
|
||||
'LV' => 'LVA',
|
||||
'LY' => 'LBY',
|
||||
'MA' => 'MAR',
|
||||
'MC' => 'MCO',
|
||||
'MD' => 'MDA',
|
||||
'ME' => 'MNE',
|
||||
'MF' => 'MAF',
|
||||
'MG' => 'MDG',
|
||||
'MH' => 'MHL',
|
||||
'MK' => 'MKD',
|
||||
'ML' => 'MLI',
|
||||
'MM' => 'MMR',
|
||||
'MN' => 'MNG',
|
||||
'MO' => 'MAC',
|
||||
'MP' => 'MNP',
|
||||
'MQ' => 'MTQ',
|
||||
'MR' => 'MRT',
|
||||
'MS' => 'MSR',
|
||||
'MT' => 'MLT',
|
||||
'MU' => 'MUS',
|
||||
'MV' => 'MDV',
|
||||
'MW' => 'MWI',
|
||||
'MX' => 'MEX',
|
||||
'MY' => 'MYS',
|
||||
'MZ' => 'MOZ',
|
||||
'NA' => 'NAM',
|
||||
'NC' => 'NCL',
|
||||
'NE' => 'NER',
|
||||
'NF' => 'NFK',
|
||||
'NG' => 'NGA',
|
||||
'NI' => 'NIC',
|
||||
'NL' => 'NLD',
|
||||
'NO' => 'NOR',
|
||||
'NP' => 'NPL',
|
||||
'NR' => 'NRU',
|
||||
'NU' => 'NIU',
|
||||
'NZ' => 'NZL',
|
||||
'O1' => 'O1',
|
||||
'OM' => 'OMN',
|
||||
'PA' => 'PAN',
|
||||
'PE' => 'PER',
|
||||
'PF' => 'PYF',
|
||||
'PG' => 'PNG',
|
||||
'PH' => 'PHL',
|
||||
'PK' => 'PAK',
|
||||
'PL' => 'POL',
|
||||
'RO' => 'ROU',
|
||||
'RS' => 'SRB',
|
||||
'RU' => 'RUS',
|
||||
'RW' => 'RWA',
|
||||
'SA' => 'SAU',
|
||||
'SB' => 'SLB',
|
||||
'SC' => 'SYC',
|
||||
'SD' => 'SDN',
|
||||
'SE' => 'SWE',
|
||||
'SG' => 'SGP',
|
||||
'SH' => 'SHN',
|
||||
'SI' => 'SVN',
|
||||
'SJ' => 'SJM',
|
||||
'SK' => 'SVK',
|
||||
'SL' => 'SLE',
|
||||
'SM' => 'SMR',
|
||||
'SN' => 'SEN',
|
||||
'SO' => 'SOM',
|
||||
'SR' => 'SUR',
|
||||
'SS' => 'SSD',
|
||||
'ST' => 'STP',
|
||||
'SV' => 'SLV',
|
||||
'SX' => 'SXM',
|
||||
'SY' => 'SYR',
|
||||
'SZ' => 'SWZ',
|
||||
'TC' => 'TCA',
|
||||
'TD' => 'TCD',
|
||||
'TF' => 'ATF',
|
||||
'TG' => 'TGO',
|
||||
'TH' => 'THA',
|
||||
'TJ' => 'TJK',
|
||||
'TK' => 'TKL',
|
||||
'TL' => 'TLS',
|
||||
'TM' => 'TKM',
|
||||
'TN' => 'TUN',
|
||||
'TO' => 'TON',
|
||||
'TR' => 'TUR',
|
||||
'TT' => 'TTO',
|
||||
'TV' => 'TUV',
|
||||
'TW' => 'TWN',
|
||||
'TZ' => 'TZA',
|
||||
'UA' => 'UKR',
|
||||
'UG' => 'UGA',
|
||||
'UM' => 'UMI',
|
||||
'US' => 'USA',
|
||||
'UY' => 'URY',
|
||||
'UZ' => 'UZB',
|
||||
'VA' => 'VAT',
|
||||
'VC' => 'VCT',
|
||||
'VE' => 'VEN',
|
||||
'VG' => 'VGB',
|
||||
'VI' => 'VIR',
|
||||
'VN' => 'VNM',
|
||||
'VU' => 'VUT',
|
||||
'WF' => 'WLF',
|
||||
'WS' => 'WSM',
|
||||
'YE' => 'YEM',
|
||||
'YT' => 'MYT',
|
||||
'ZA' => 'ZAF',
|
||||
'ZM' => 'ZMB',
|
||||
'ZW' => 'ZWE',
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "yellowtree/geoip-detect-lib",
|
||||
"type": "library",
|
||||
"require": {
|
||||
"symfony/http-foundation": "^4.2"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Benjamin Pick",
|
||||
"email": "benjaminpick@github.com"
|
||||
}
|
||||
]
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
{
|
||||
"_readme": [
|
||||
"This file locks the dependencies of your project to a known state",
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "689f4cbd126b0807e8268f1cfd775a98",
|
||||
"packages": [
|
||||
{
|
||||
"name": "symfony/http-foundation",
|
||||
"version": "v4.2.3",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/http-foundation.git",
|
||||
"reference": "8d2318b73e0a1bc75baa699d00ebe2ae8b595a39"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/http-foundation/zipball/8d2318b73e0a1bc75baa699d00ebe2ae8b595a39",
|
||||
"reference": "8d2318b73e0a1bc75baa699d00ebe2ae8b595a39",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": "^7.1.3",
|
||||
"symfony/polyfill-mbstring": "~1.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"predis/predis": "~1.0",
|
||||
"symfony/expression-language": "~3.4|~4.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.2-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Component\\HttpFoundation\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony HttpFoundation Component",
|
||||
"homepage": "https://symfony.com",
|
||||
"time": "2019-01-29T09:49:29+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/polyfill-mbstring",
|
||||
"version": "v1.10.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/polyfill-mbstring.git",
|
||||
"reference": "c79c051f5b3a46be09205c73b80b346e4153e494"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/c79c051f5b3a46be09205c73b80b346e4153e494",
|
||||
"reference": "c79c051f5b3a46be09205c73b80b346e4153e494",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-mbstring": "For best performance"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.9-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Polyfill\\Mbstring\\": ""
|
||||
},
|
||||
"files": [
|
||||
"bootstrap.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Grekas",
|
||||
"email": "p@tchwork.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony polyfill for the Mbstring extension",
|
||||
"homepage": "https://symfony.com",
|
||||
"keywords": [
|
||||
"compatibility",
|
||||
"mbstring",
|
||||
"polyfill",
|
||||
"portable",
|
||||
"shim"
|
||||
],
|
||||
"time": "2018-09-21T13:07:52+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
"aliases": [],
|
||||
"minimum-stability": "stable",
|
||||
"stability-flags": [],
|
||||
"prefer-stable": false,
|
||||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": []
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright 2013-2019 Yellow Tree, Siegen, Germany
|
||||
Author: Benjamin Pick (wp-geoip-detect| |posteo.de)
|
||||
|
||||
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 3 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
namespace YellowTree\GeoipDetect\Geonames;
|
||||
define ('GEOIP_DETECT_GEONAMES_COUNTRY_INFO', GEOIP_PLUGIN_DIR . '/lib/geonames/data/country-info.php');
|
||||
define ('GEOIP_DETECT_GEONAMES_COUNTRY_NAMES', GEOIP_PLUGIN_DIR . '/lib/geonames/data/country-names.php');
|
||||
define ('GEOIP_DETECT_GEONAMES_COUNTRY_FLAGS', GEOIP_PLUGIN_DIR . '/lib/geonames/data/country-flags.php');
|
||||
|
||||
class CountryInformation {
|
||||
|
||||
protected $data = array();
|
||||
|
||||
protected function lazyLoadInformation($filename) {
|
||||
if (!isset($this->data[$filename])) {
|
||||
$this->data[$filename] = require($filename);
|
||||
}
|
||||
return $this->data[$filename];
|
||||
}
|
||||
/**
|
||||
* Get all geonames Information that is known about the country with this ISO code.
|
||||
*
|
||||
* @param string $iso 2-letter ISO-Code of the country (e.g. 'DE')
|
||||
* @return array Information in record format
|
||||
*/
|
||||
public function getInformationAboutCountry($iso) {
|
||||
$data = $this->lazyLoadInformation(GEOIP_DETECT_GEONAMES_COUNTRY_INFO);
|
||||
|
||||
if ($iso == 'keys')
|
||||
return array_keys($data['countries']);
|
||||
|
||||
if (!isset($data['countries'][$iso]))
|
||||
return array();
|
||||
|
||||
$country = $data['countries'][$iso];
|
||||
if (isset($country['continent']) && is_string($country['continent']))
|
||||
$country['continent'] = $data['continents'][$country['continent']];
|
||||
return $country;
|
||||
}
|
||||
|
||||
/**
|
||||
* The Emoji representing the flag
|
||||
*
|
||||
* @param string $iso 2-letter ISO-Code of the country(e.g. 'DE')
|
||||
* @return string the emoji char
|
||||
*/
|
||||
public function getFlagEmoji($iso) {
|
||||
$data = $this->lazyLoadInformation(GEOIP_DETECT_GEONAMES_COUNTRY_FLAGS);
|
||||
|
||||
if ($iso == 'keys')
|
||||
return array_keys($data);
|
||||
|
||||
if (!isset($data[$iso]['emoji'])) return '';
|
||||
|
||||
return $data[$iso]['emoji'];
|
||||
}
|
||||
|
||||
/**
|
||||
* The tel code of a country
|
||||
*
|
||||
* @param string $iso 2-letter ISO-Code of the country(e.g. 'DE')
|
||||
* @return string the emoji char
|
||||
*/
|
||||
public function getTelephonePrefix($iso) {
|
||||
$data = $this->lazyLoadInformation(GEOIP_DETECT_GEONAMES_COUNTRY_FLAGS);
|
||||
|
||||
if ($iso == 'keys')
|
||||
return array_keys($data);
|
||||
|
||||
if (!isset($data[$iso]['tel'])) return '';
|
||||
|
||||
return $data[$iso]['tel'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get all country names
|
||||
* @param string/array $locales Locale of the label (if array: use the first locale available)
|
||||
* @return array ISO Codes => Label Pairs
|
||||
*/
|
||||
public function getAllCountries($locales = 'en') {
|
||||
$data = $this->lazyLoadInformation(GEOIP_DETECT_GEONAMES_COUNTRY_NAMES);
|
||||
|
||||
if ($locales === 'keys')
|
||||
return array_keys($data);
|
||||
|
||||
foreach ((array) $locales as $locale) {
|
||||
if (isset($data[$locale]))
|
||||
return $data[$locale];
|
||||
}
|
||||
return $data['en'];
|
||||
}
|
||||
}
|
||||
|
||||
// List of country names, iso, continent id.
|
||||
// List of continents
|
||||
|
||||
// List of timezones
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Copyright 2013-2019 Yellow Tree, Siegen, Germany
|
||||
Author: Benjamin Pick (wp-geoip-detect| |posteo.de)
|
||||
|
||||
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 3 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
namespace YellowTree\GeoipDetect\Lib;
|
||||
|
||||
class GetClientIp {
|
||||
protected $proxyWhitelist = [];
|
||||
protected $useProxyWhitelist = false;
|
||||
|
||||
public function __construct() {
|
||||
$this->proxyWhitelist[] = '::1';
|
||||
$this->proxyWhitelist[] = '127.0.0.1';
|
||||
}
|
||||
|
||||
public function addProxiesToWhitelist($trusted_proxies) {
|
||||
foreach ($trusted_proxies as $proxy) {
|
||||
$proxy = geoip_detect_normalize_ip($proxy);
|
||||
if ($proxy) {
|
||||
$this->proxyWhitelist[] = $proxy;
|
||||
$this->useProxyWhitelist = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getIpsFromRemoteAddr() {
|
||||
if (!isset($_SERVER['REMOTE_ADDR']))
|
||||
return ['::1'];
|
||||
|
||||
// REMOTE_ADDR may contain multiple adresses
|
||||
$ip_list = explode(',', $_SERVER['REMOTE_ADDR']);
|
||||
|
||||
return $ip_list;
|
||||
}
|
||||
|
||||
protected function getIpsFromForwardedFor($currentIpList) {
|
||||
$ip_list_reverse = explode(',', isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : '');
|
||||
|
||||
if ($this->useProxyWhitelist) {
|
||||
// Add the REMOTE_ADDR to the available IP pool
|
||||
$ip_list_reverse = array_merge($ip_list_reverse, $currentIpList);
|
||||
|
||||
$ip_list_reverse = array_filter($ip_list_reverse, function($value) {
|
||||
$value = trim($value);
|
||||
if (!$value) return false;
|
||||
return false === geoip_detect_is_ip_equal($value, $this->proxyWhitelist);
|
||||
});
|
||||
}
|
||||
|
||||
return $ip_list_reverse;
|
||||
}
|
||||
|
||||
public function getIp($useReverseProxy = false) {
|
||||
$ip_list = $this->getIpsFromRemoteAddr();
|
||||
|
||||
if ($useReverseProxy)
|
||||
{
|
||||
$ip_list = $this->getIpsFromForwardedFor($ip_list);
|
||||
}
|
||||
|
||||
// Each Proxy server append their information at the end, so the last IP is most trustworthy.
|
||||
$ip = end($ip_list);
|
||||
$ip = geoip_detect_normalize_ip($ip);
|
||||
|
||||
if (!geoip_detect_is_ip($ip))
|
||||
$ip = '::1'; // By default, use localhost
|
||||
|
||||
// this is the correct one!
|
||||
$ip = apply_filters('geoip_detect2_client_ip', $ip, $ip_list);
|
||||
|
||||
return $ip;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "geoip-detect",
|
||||
"version": "2.11.0",
|
||||
"description": "Geoip Detection - Wordpress Plugin (JS)",
|
||||
"main": "index.js",
|
||||
"repository": "git@github.com:yellowtree/geoip-detect.git",
|
||||
"author": "Benjamin Pick <benjaminpick@github.com>",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"scripts": {
|
||||
"clean": "rm -rf .cache",
|
||||
"build-lodash": "lodash include=get -o js/lodash.custom.js",
|
||||
"start": "rm -rf js/dist && parcel parcel.urls --out-dir js/dist",
|
||||
"build": "rm -rf js/dist && parcel build parcel.urls --out-dir js/dist"
|
||||
},
|
||||
"private": false,
|
||||
"dependencies": {
|
||||
"@babel/runtime": ">=7.7.2",
|
||||
"babel-plugin-transform-class-properties": ">=6.24.1",
|
||||
"emoji-flags": "matiassingers/emoji-flags#master",
|
||||
"js-cookie": "^2.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": ">=7.7.2",
|
||||
"@babel/plugin-transform-runtime": ">=7.6.2",
|
||||
"babel-plugin-transform-runtime": ">=6.23.0",
|
||||
"eslint": "^6.6.0",
|
||||
"lodash-cli": "^4.17.5",
|
||||
"parcel-bundler": ">=1.12.4",
|
||||
"parcel-plugin-assets-list": ">=1.7.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
frontendJS: js/frontend.js
|
||||
backendJS: js/backend.js
|
||||
@@ -0,0 +1,191 @@
|
||||
=== GeoIP Detection ===
|
||||
Contributors: benjaminpick
|
||||
Tags: geoip, maxmind, geolocation, locator
|
||||
Requires at least: 4.0
|
||||
Tested up to: 5.3
|
||||
Requires PHP: 5.6
|
||||
Stable tag: trunk
|
||||
License: GPLv3 or later
|
||||
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
||||
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BSYUZHS8FH3CL
|
||||
|
||||
Retrieving Geo-Information using one the Maxmind GeoIP2 databases.
|
||||
|
||||
== Description ==
|
||||
|
||||
Provides geographic information detected by an IP adress. This can be used in themes or other plugins,
|
||||
as a shortcode, or via CSS body classes. The city & country names are translated in different languages ([supported languages](https://dev.maxmind.com/geoip/geoip2/web-services/#Languages-8)).
|
||||
|
||||
= Features: =
|
||||
|
||||
* Provides these 5 functions (see [API Documentation](https://github.com/yellowtree/geoip-detect/wiki/API:-PHP)):
|
||||
* `geoip_detect2_get_info_from_ip($ip, $locales = array('en'), $options = array())`: Lookup Geo-Information of the specified IP
|
||||
* `geoip_detect2_get_info_from_current_ip($locales = array('en'), $options = array())`: Lookup Geo-Information of the current website user
|
||||
* `geoip_detect2_get_current_source_description(...)`: Return a human-readable label of the currently chosen source.
|
||||
* `geoip_detect2_get_external_ip_adress()`: Fetch the internet adress of the webserver
|
||||
* `geoip_detect2_get_client_ip()`: Get client IP (even if it is behind a reverse proxy)
|
||||
* You can use one of these data sources (see [comparison](https://github.com/yellowtree/geoip-detect/wiki/FAQ#which-data-source-should-i-choose)):
|
||||
* Free: [Maxmind GeoIP2 Lite City](http://dev.maxmind.com/geoip/geoip2/geolite2/), automatically updated every month (licensed CC BY-SA. See [FAQ](https://github.com/yellowtree/geoip-detect/wiki/FAQ).)
|
||||
* Commercial: [Maxmind GeoIP2 City](https://www.maxmind.com/en/geoip2-country-database) or [Maxmind GeoIP2 Country](https://www.maxmind.com/en/geoip2-city)
|
||||
* Commercial Web-API: [Maxmind GeoIP2 Precision](https://www.maxmind.com/en/geoip2-precision-services) (City, Country or Insights)
|
||||
* Free (default source): [HostIP.info](http://www.hostip.info/) (IPv4 only)
|
||||
* Hosting-Provider dependent: [Cloudflare](https://support.cloudflare.com/hc/en-us/articles/200168236-What-does-CloudFlare-IP-Geolocation-do-) or [Amazon AWS CloudFront](https://aws.amazon.com/blogs/aws/enhanced-cloudfront-customization/) (Country)
|
||||
* Free or Commercial Web-API: [Ipstack](https://ipstack.com)
|
||||
* For the property names, see the results of a specific IP in the wordpress backend (under *Tools > GeoIP Detection*).
|
||||
* You can include these properties into your posts and pages by using the shortcode `[geoip_detect2 property="country.name" default="(country could not be detected)" lang="en"]` (where 'country.name' can be one of the other property names as well, and 'default' and 'lang' are optional).
|
||||
* You can show or hide content by using a shortcode `[geoip_detect2_show_if country="FR, DE" not_city="Berlin"]TEXT[/geoip_detect2_show_if]`. See [Shortcode Documentation](https://github.com/yellowtree/geoip-detect/wiki/API:-Shortcodes#show-or-hide-content-depending-on-the-location).
|
||||
* When enabled on the options page, it adds CSS classes to the body tag such as `geoip-province-HE`, `geoip-country-DE` and `geoip-continent-EU`.
|
||||
* When enabled on the options page, the client IP respects a reverse proxy of the server.
|
||||
* If you are using [Contact Form 7](https://wordpress.org/plugins/contact-form-7/), you can use these shortcodes:
|
||||
* A select input with all countries, the detected country being selected by default: `[geoip_detect2_countries mycountry]`
|
||||
* A text input that is pre-filled with the detected city (or other property): `[geoip_detect2_text_input city property:city lang:fr id:id class:class default:Paris]`
|
||||
* GeoIP information for the email text: `[geoip_detect2_user_info]`
|
||||
|
||||
See [Documentation](https://github.com/yellowtree/geoip-detect/wiki) for more info.
|
||||
|
||||
= How can I use these functions? =
|
||||
|
||||
* You could choose the currency of the store based on the country name
|
||||
* You could suggest an timezone to use when displaying dates
|
||||
* You could show the store nearest to your customer
|
||||
* You show or hide content specific to a geographic target group
|
||||
* Etc. ... You tell me! I'm rather curious what you'll do with this plugin!
|
||||
* Be careful to comply to the applicable laws. For example Regulation (EU) 2018/302 (going into effect 03 Dec 2018)...
|
||||
|
||||
**System Requirements**: You will need at least PHP 5.4.
|
||||
|
||||
*GDPR: See [Is this plugin GDPR-compliant?](https://github.com/yellowtree/geoip-detect/wiki/FAQ#is-this-plugin-gdpr-compliant)*
|
||||
|
||||
*This extension is "charity-ware". If you are happy with it, please [leave a tip](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BSYUZHS8FH3CL) for the benefit of [this charity](http://www.jmem-hainichen.de/homepage). (See [FAQ](https://github.com/yellowtree/geoip-detect/wiki/FAQ#what-you-mean-by-this-plugin-is-charity-ware) for more infos.)*
|
||||
|
||||
*This product can provide GeoLite2 data created by MaxMind, available from http://www.maxmind.com.*
|
||||
|
||||
== Installation ==
|
||||
|
||||
* Install the plugin
|
||||
* Go to the plugin's option page and choose a data source.
|
||||
* Test it by clicking on "Lookup" on the lookup page.
|
||||
|
||||
=== Troubleshooting ===
|
||||
|
||||
Does `geoip_detect2_get_info_from_current_ip()` return the same country, regardless of where you are visiting the site from? Maybe your server has a reverse proxy configured. You can check this: Go to the options page and look for "reverse proxy". Are there 2 IPs listed there? If so, which one corresponds to your [public IP](https://www.whatismyip.com/)?
|
||||
|
||||
== Frequently Asked Questions ==
|
||||
|
||||
[Technically speaking, how could I verify if my visitor comes from Germany?](https://github.com/yellowtree/geoip-detect/wiki/FAQ#technically-speaking-how-could-i-verify-if-my-visitor-comes-from-germany)
|
||||
|
||||
[How can I show text only if the visitor is coming from Germany?](https://github.com/yellowtree/geoip-detect/wiki/FAQ#how-can-i-show-text-only-if-the-visitor-is-coming-from-germany)
|
||||
|
||||
[How can I add the current country name as text in my page?](https://github.com/yellowtree/geoip-detect/wiki/FAQ#how-can-i-add-the-current-country-name-as-text-in-my-page)
|
||||
|
||||
[Which data source should I choose?](https://github.com/yellowtree/geoip-detect/wiki/FAQ#which-data-source-should-i-choose)
|
||||
|
||||
[Can I change the time period how long the data is cached?](https://github.com/yellowtree/geoip-detect/wiki/FAQ#can-i-change-the-time-period-how-long-the-data-is-cached)
|
||||
|
||||
[The Maxmind Lite databases are licensed Creative Commons ShareAlike-Attribution. When do I need to give attribution?](https://github.com/yellowtree/geoip-detect/wiki/FAQ#the-maxmind-lite-databases-are-licensed-creative-commons-sharealike-attribution-when-do-i-need-to-give-attribution)
|
||||
|
||||
[Does this plugin work in a MultiSite-Network environment?](https://github.com/yellowtree/geoip-detect/wiki/FAQ#does-this-plugin-work-in-a-multisite-network-environment)
|
||||
|
||||
[What do you mean by "This plugin is charity-ware"?](https://github.com/yellowtree/geoip-detect/wiki/FAQ#what-do-you-mean-by-this-plugin-is-charity-ware)
|
||||
|
||||
**Further documentation**
|
||||
|
||||
[PHP Functions](https://github.com/yellowtree/geoip-detect/wiki/API:-PHP)
|
||||
|
||||
[JS Functions for AJAX mode](https://github.com/yellowtree/geoip-detect/wiki/API%3A-AJAX)
|
||||
|
||||
[Shortcodes](https://github.com/yellowtree/geoip-detect/wiki/API:-Shortcodes)
|
||||
|
||||
[Shortcodes for Contact Form 7](https://github.com/yellowtree/geoip-detect/wiki/API:-Shortcodes-for-Contact-Form-7)
|
||||
|
||||
[Record Properties](https://github.com/yellowtree/geoip-detect/wiki/Record-Properties)
|
||||
|
||||
[API usage examples](https://github.com/yellowtree/geoip-detect/wiki/API-Usage-Examples)
|
||||
|
||||
== Screenshots ==
|
||||
|
||||
1. Lookup page (under Tools > GeoIP Lookup)
|
||||
2. Options page (under Preferences > GeoIP Detection)
|
||||
|
||||
== Upgrade Notice ==
|
||||
|
||||
= 2.13.0 =
|
||||
|
||||
PHP 5.6 is required now. If you are using the AJAX mode, this version will drastically reduce the number of requests as it will store the visitor's geo-information in a cookie.
|
||||
|
||||
= 2.12.0 =
|
||||
|
||||
New: Ipstack.com can be used as data source
|
||||
|
||||
= 2.11.0 =
|
||||
|
||||
The Download code of the automatically updated Maxmind file was rewritten for better performance. Also, AJAX support is now in beta (see documentation).
|
||||
|
||||
= 2.9.2 =
|
||||
|
||||
Hotfix: In 2.9.1, this plugin was incompatible with other Contact Form 7-Special Mailtags (https://contactform7.com/special-mail-tags/).
|
||||
|
||||
= 2.9.1 =
|
||||
|
||||
Online Shops: Be careful to comply to (EU) 2018/302 (going into effect 03 Dec 2018) in how you use this plugin !
|
||||
|
||||
= 2.9.0 =
|
||||
|
||||
There have been changes to the reverse proxy logic. If you have enabled a reverse proxy, check if the detected IP is correct.
|
||||
New: Shortcode for showing/hiding content!
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 2.13 =
|
||||
* NEW: JS/AJAX mode now caches the response as a cookie so that every user only needs to call the AJAX requests once
|
||||
* NEW: If you install the plugin [SVG Flags](https://wordpress.org/plugins/svg-flags-lite/), you can use this shortcode to show the flag of the current country: `[geoip_detect2_current_flag]`. See [Documentation](https://github.com/yellowtree/geoip-detect/wiki/API:-Shortcodes#add-a-flag-of-the-visitors-country) for more infos.
|
||||
* FIX: Example PHP code on Lookup page now displays nicer array syntax (and fixing a deprecation warning)
|
||||
* Updated Maxmind vendor code - PHP 5.6 is required now
|
||||
|
||||
= 2.12.1 =
|
||||
* NEW: With the new Wordpress filter `geoip_detect2_record_data_after_cache` you can change the record data for testing purposes (see https://github.com/yellowtree/geoip-detect/wiki/API-Usage-Examples#change-record-data-eg-for-testing-purposes)
|
||||
* NEW: All datasources now also have the properties `extra->flag` (containing the flag as Unicode Emoji) and `extra->tel` (containing the country dial code)
|
||||
* Some cleanup in ipstack & showing all properties in backend.
|
||||
|
||||
= 2.12.0 =
|
||||
* NEW: It is now possible to use ipstack.com as a data source.
|
||||
* The Backend Lookup UI now can show all properties and you can choose if you want to see the PHP, Shortcode or JS syntax.
|
||||
|
||||
= 2.11.2 =
|
||||
* The auto-updater of the Maxmind City Lite source now updates more often (every 1-2weeks) in order to get more accurate data.
|
||||
|
||||
= 2.11.1 =
|
||||
* FIX: When activating the plugin on Wordpress MultiSite, an error was thrown before
|
||||
* NEW: Add body class "geoip-country-is-in-european-union" if the detected country is inside of the European Union
|
||||
* JS/AJAX support for cached pages (Public BETA now. See https://github.com/yellowtree/geoip-detect/wiki/API%3A-AJAX)
|
||||
* NEW: If AJAX and body classes are enabled, body classes are added via AJAX.
|
||||
|
||||
= 2.11.0 =
|
||||
* NEW: JS/AJAX support for cached pages (This is in **BETA**. Read https://github.com/yellowtree/geoip-detect/wiki/API%3A-AJAX on how to activate it)
|
||||
* FIX: Improve performance of unpacking the Maxmind file (Source: Automatic download) - important for hosts with a low max_execution_time
|
||||
* NEW: On removal (in the Backend), the plugin will delete its options from the database and the downloaded Maxmind file
|
||||
|
||||
= 2.10.0 =
|
||||
* NEW: The whitelisted proxies can now be subnets such as `11.11.11.0/24`
|
||||
* NEW: Add a ContactForm7-Tag `geoip_detect2_text_input` (see https://github.com/yellowtree/geoip-detect/wiki/API:-Shortcodes-for-Contact-Form-7#create-a-text-input-that-is-prefilled-with-a-geodetected-property)
|
||||
* NEW: A new wordpress filter allows overriding of the detected geo-information inside the `geoip_detect2_shortcode_show_if`-Shortcode. Use the already-existing filter `geoip_detect2_record_information` instead if you want to override this information for all shortcodes and API calls.
|
||||
* Updated Maxmind vendor code
|
||||
* Increased WP minimum version to 4.0
|
||||
|
||||
= 2.9.2 =
|
||||
* FIX: ContactForm7-Mailtag disabled mailtags from other plugins.
|
||||
|
||||
= 2.9.1 =
|
||||
* NEW: Add ContactForm7-Mailtags so that the user information formatting can be customized: `geoip_detect2_get_client_ip`, `geoip_detect2_get_current_source_description`, `geoip_detect2_property_country`, `geoip_detect2_property_state`, `geoip_detect2_property_city`. Of course you can still use `geoip_detect2_user_info` as shortcode for all these informations.
|
||||
* FIX: On some server, the plugin had wrongly assumed that PHP was compiled without IPv6-support.
|
||||
|
||||
= 2.9.0 =
|
||||
* Add default Privacy text for GDPR compliance.
|
||||
* The reverse proxy logic was heavily changed. If you run into configuration errors, try the debug panel (see link after the reverse proxy option).
|
||||
* NEW: Reverse proxies can now be whitelisted - all non-whitelisted proxies are treated as user IP.
|
||||
* NEW: Shortcode to show/hide content dynamically. (`[geoip_detect2_show_if country="US" not_state="Texas"]TEXT[/geoip_detect2_show_if]`) (Thanks to @DynAggelos!)
|
||||
* NEW: All shortcodes now support multiple subdivisions (`[geoip_detect2 property="subdivisions.0.isoCode"]`)
|
||||
* NEW: The CSS classes that are added to the body-tag (if enabled in the options) now also include the most specific subdivision (`geoip-province-HE`).
|
||||
* Maxmind vendor code was updated to the current version (2.9.0).
|
||||
|
||||
[Older changelog](https://github.com/yellowtree/geoip-detect/blob/master/CHANGELOG.md)
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 27 KiB |
@@ -0,0 +1,732 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright 2013-2019 Yellow Tree, Siegen, Germany
|
||||
Author: Benjamin Pick (wp-geoip-detect| |posteo.de)
|
||||
|
||||
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 3 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
function geoip_detect_shortcode($attr)
|
||||
{
|
||||
$userInfo = geoip_detect_get_info_from_current_ip();
|
||||
|
||||
$defaultValue = isset($attr['default']) ? $attr['default'] : '';
|
||||
|
||||
if (!is_object($userInfo))
|
||||
return $defaultValue . '<!-- GeoIP Detect: No info found for this IP. -->';
|
||||
|
||||
$propertyName = $attr['property'];
|
||||
|
||||
|
||||
if (property_exists($userInfo, $propertyName)) {
|
||||
if ($userInfo->$propertyName)
|
||||
return $userInfo->$propertyName;
|
||||
else
|
||||
return $defaultValue;
|
||||
}
|
||||
|
||||
return $defaultValue . '<!-- GeoIP Detect: Invalid property name. -->';
|
||||
}
|
||||
add_shortcode('geoip_detect', 'geoip_detect_shortcode');
|
||||
|
||||
/**
|
||||
* Short Code
|
||||
*
|
||||
* Examples:
|
||||
* `[geoip_detect2 property="country"]` -> Germany
|
||||
* `[geoip_detect2 property="country.isoCode"]` -> DE
|
||||
* `[geoip_detect2 property="country.isoCode" ip="8.8.8.8"]` -> US
|
||||
*
|
||||
* `[geoip_detect2 property="country" lang="de"]` -> Deutschland
|
||||
* `[geoip_detect2 property="country" lang="fr,de"]` -> Allemagne
|
||||
* `[geoip_detect2 property="country.confidence" skip_cache="true" default="default value"]` -> default value
|
||||
*
|
||||
* @param string $property Property to read. For a list of all possible property names, see https://github.com/yellowtree/geoip-detect/wiki/Record-Properties#list-of-all-property-names
|
||||
* @param string $lang Language(s) (optional. If not set, current site language is used.)
|
||||
* @param string $default Default Value that will be shown if value not set (optional)
|
||||
* @param string $skip_cache if 'true': Do not cache value
|
||||
*
|
||||
* @since 2.5.7 New attribute `ip`
|
||||
*/
|
||||
function geoip_detect2_shortcode($attr, $content = '', $shortcodeName = 'geoip_detect2')
|
||||
{
|
||||
$attr = shortcode_atts(array(
|
||||
'skip_cache' => 'false',
|
||||
'lang' => null,
|
||||
'default' => '',
|
||||
'property' => '',
|
||||
'ip' => null,
|
||||
'add_error' => true,
|
||||
), $attr, $shortcodeName);
|
||||
|
||||
$skipCache = filter_var($attr['skip_cache'], FILTER_VALIDATE_BOOLEAN );
|
||||
|
||||
$locales = isset($attr['lang']) ? $attr['lang'] . ',en' : null;
|
||||
$locales = apply_filters('geoip_detect2_locales', $locales);
|
||||
|
||||
$defaultValue = $attr['default'];
|
||||
|
||||
$options = array('skipCache' => $skipCache);
|
||||
|
||||
$ip = $attr['ip'] ?: geoip_detect2_get_client_ip();
|
||||
|
||||
$userInfo = geoip_detect2_get_info_from_ip($ip, $locales, $options);
|
||||
|
||||
if ($userInfo->isEmpty)
|
||||
return $defaultValue . ($attr['add_error'] ? '<!-- GeoIP Detect: No information found for this IP (' . geoip_detect2_get_client_ip() . ') -->' : '');
|
||||
|
||||
try {
|
||||
$return = geoip_detect2_shortcode_get_property($userInfo, $attr['property']);
|
||||
} catch (\RuntimeException $e) {
|
||||
return $defaultValue . ($attr['add_error'] ? '<!-- GeoIP Detect: Invalid property name. -->' : '');
|
||||
}
|
||||
|
||||
if (is_object($return) && $return instanceof \GeoIp2\Record\AbstractPlaceRecord) {
|
||||
$return = $return->name;
|
||||
}
|
||||
|
||||
if (is_object($return) || is_array($return)) {
|
||||
return $defaultValue . ($attr['add_error'] ? '<!-- GeoIP Detect: Invalid property name (sub-property missing). -->' : '');
|
||||
}
|
||||
|
||||
if ($return)
|
||||
return (string) $return;
|
||||
else
|
||||
return $defaultValue;
|
||||
|
||||
}
|
||||
add_shortcode('geoip_detect2', 'geoip_detect2_shortcode');
|
||||
|
||||
/**
|
||||
* Get property from object by string
|
||||
* @param YellowTree\GeoipDetect\DataSources\City $userInfo GeoIP information object
|
||||
* @param string $propertyName property name, e.g. "city.isoCode"
|
||||
* @return string|\GeoIp2\Record\AbstractRecord Property Value
|
||||
* @throws \RuntimeException (if Property name invalid)
|
||||
*/
|
||||
function geoip_detect2_shortcode_get_property($userInfo, $propertyName) {
|
||||
$return = '';
|
||||
$properties = explode('.', $propertyName);
|
||||
if (count($properties) == 1) {
|
||||
$return = $userInfo->{$properties[0]};
|
||||
} else if ($properties[0] == 'subdivisions' && (count($properties) == 2 || count($properties) == 3)) {
|
||||
$return = $userInfo->{$properties[0]};
|
||||
if (!is_array($return))
|
||||
throw new \RuntimeException('Invalid property name.');
|
||||
if (!is_numeric($properties[1]))
|
||||
throw new \RuntimeException('Invalid property name (must be numeric, e.g. "subdivisions.0").');
|
||||
$return = $return[(int) $properties[1]];
|
||||
|
||||
if (isset($properties[2])) {
|
||||
if (!is_object($return))
|
||||
throw new \RuntimeException('Invalid property name.');
|
||||
$return = $return->{$properties[2]};
|
||||
}
|
||||
} else if (count($properties) == 2) {
|
||||
$return = $userInfo->{$properties[0]};
|
||||
if (!is_object($return))
|
||||
throw new \RuntimeException('Invalid property name.');
|
||||
$return = $return->{$properties[1]};
|
||||
} else {
|
||||
throw new \RuntimeException('Only 1 dot supported. Please send a bug report to show me the shortcode you used if you need it ...');
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
||||
function geoip_detect2_shortcode_client_ip() {
|
||||
$client_ip = geoip_detect2_get_client_ip();
|
||||
$client_ip = geoip_detect_normalize_ip($client_ip);
|
||||
|
||||
return $client_ip;
|
||||
}
|
||||
add_shortcode('geoip_detect2_get_client_ip', 'geoip_detect2_shortcode_client_ip');
|
||||
|
||||
function geoip_detect2_shortcode_get_external_ip_adress($attr) {
|
||||
$external_ip = geoip_detect2_get_external_ip_adress();
|
||||
$external_ip = geoip_detect_normalize_ip($external_ip);
|
||||
|
||||
return $external_ip;
|
||||
}
|
||||
add_shortcode('geoip_detect2_get_external_ip_adress', 'geoip_detect2_shortcode_get_external_ip_adress');
|
||||
|
||||
function geoip_detect2_shortcode_get_current_source_description() {
|
||||
$return = geoip_detect2_get_current_source_description();
|
||||
|
||||
return $return;
|
||||
}
|
||||
add_shortcode('geoip_detect2_get_current_source_description', 'geoip_detect2_shortcode_get_current_source_description');
|
||||
|
||||
/**
|
||||
* Create a <select>-Input element with all countries.
|
||||
*
|
||||
* Examples:
|
||||
* `[geoip_detect2_countries_select name="mycountry" lang="fr"]`
|
||||
* A list of all country names in French, the visitor's country is preselected.
|
||||
*
|
||||
* `[geoip_detect2_countries_select id="id" class="class" name="mycountry" lang="fr"]`
|
||||
* As above, with CSS id "#id" and class ".class"
|
||||
*
|
||||
* `[geoip_detect2_countries_select name="mycountry" include_blank="true"]`
|
||||
* Country names are in the current site language. User can also choose '---' for no country at all.
|
||||
*
|
||||
* `[geoip_detect2_countries_select name="mycountry" selected="US"]`
|
||||
* "United States" is preselected, there is no visitor IP detection going on here
|
||||
*
|
||||
* `[geoip_detect2_countries_select name="mycountry" default="US"]`
|
||||
* Visitor's country is preselected, but in case the country is unknown, use "United States"
|
||||
*
|
||||
* $attr is an array that can have these properties:
|
||||
* @param string $name Name of the form element
|
||||
* @param string $id CSS Id of element
|
||||
* @param bool $required If the field is required or not
|
||||
* @param string $class CSS Class of element
|
||||
* @param string $lang Language(s) (optional. If not set, current site language is used.)
|
||||
* @param string $selected Which country to select by default (2-letter ISO code.) (optional. If not set, the country will be detected by client ip.)
|
||||
* @param string $default Default Value that will be used if country cannot be detected (optional)
|
||||
* @param string $include_blank If this value contains 'true', a empty value will be prepended ('---', i.e. no country) (optional)
|
||||
*
|
||||
* @return string The generated HTML
|
||||
*/
|
||||
function geoip_detect2_shortcode_country_select($attr) {
|
||||
$selected = '';
|
||||
if (!empty($attr['selected'])) {
|
||||
$selected = $attr['selected'];
|
||||
} else {
|
||||
$record = geoip_detect2_get_info_from_current_ip();
|
||||
$selected = $record->country->isoCode;
|
||||
}
|
||||
if (empty($selected)) {
|
||||
if (isset($attr['default']))
|
||||
$selected = $attr['default'];
|
||||
}
|
||||
|
||||
$locales = !empty($attr['lang']) ? $attr['lang'] : null;
|
||||
$locales = apply_filters('geoip_detect2_locales', $locales);
|
||||
|
||||
$select_attrs = array(
|
||||
'name' => !empty($attr['name']) ? $attr['name'] : 'geoip-countries',
|
||||
'id' => !empty($attr['id']) ? $attr['id'] : '',
|
||||
'class' => !empty($attr['class']) ? $attr['class'] : 'geoip_detect2_countries',
|
||||
'aria-required' => !empty($attr['required']) ? 'required' : '',
|
||||
'aria-invalid' => !empty($attr['invalid']) ? $attr['invalid'] : '',
|
||||
);
|
||||
|
||||
$countryInfo = new YellowTree\GeoipDetect\Geonames\CountryInformation();
|
||||
$countries = $countryInfo->getAllCountries($locales);
|
||||
|
||||
/**
|
||||
* Filter: geoip_detect2_shortcode_country_select_countries
|
||||
* Change the list of countries that should show up in the select box.
|
||||
* You can add, remove, reorder countries at will.
|
||||
* If you want to add a blank value (for seperators or so), use a key name that starts with 'blank_'
|
||||
* and then something at will in case you need several of them.
|
||||
*
|
||||
* @param array $countries List of localized country names
|
||||
* @param array $attr Parameters that were passed to the shortcode
|
||||
* @return array
|
||||
*/
|
||||
$countries = apply_filters('geoip_detect2_shortcode_country_select_countries', $countries, $attr);
|
||||
|
||||
$html = '<select ' . _geoip_detect_flatten_html_attr($select_attrs) . '>';
|
||||
if (!empty($attr['include_blank']) && $attr['include_blank'] !== 'false')
|
||||
$html .= '<option value="">---</option>';
|
||||
foreach ($countries as $code => $label) {
|
||||
if (substr($code, 0, 6) == 'blank_')
|
||||
{
|
||||
$html .= '<option value="">' . esc_html($label) . '</option>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$html .= '<option' . ($code == $selected ? ' selected="selected"' : '') . '>' . esc_html($label) . '</option>';
|
||||
}
|
||||
}
|
||||
$html .= '</select>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
add_shortcode('geoip_detect2_countries_select', 'geoip_detect2_shortcode_country_select');
|
||||
add_shortcode('geoip_detect2_countries', 'geoip_detect2_shortcode_country_select');
|
||||
|
||||
function _geoip_detect_flatten_html_attr($attr) {
|
||||
$html = '';
|
||||
foreach ($attr as $key => $value) {
|
||||
if ($value)
|
||||
$html .= $key . '="' . esc_attr($value) . '" ';
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generating a country select field that has the geoip value as default
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* `[geoip_detect2_countries mycountry id:id class:class lang:fr]`
|
||||
* A list of all country names in French (with CSS id "#id" and class ".class"), the visitor's country is preselected.
|
||||
*
|
||||
* `[geoip_detect2_countries mycountry include_blank]`
|
||||
* Country names are in the current site language. User can also choose '---' for no country at all.
|
||||
*
|
||||
* `[geoip_detect2_countries mycountry "US"]`
|
||||
* "United States" is preselected, there is no visitor IP detection going on here
|
||||
*
|
||||
* `[geoip_detect2_countries mycountry default:US]`
|
||||
* Visitor's country is preselected, but in case the country is unknown, use "United States"
|
||||
*
|
||||
*/
|
||||
function geoip_detect2_shortcode_country_select_wpcf7($tag) {
|
||||
$tag = new WPCF7_FormTag( $tag );
|
||||
|
||||
$default = (string) reset( $tag->values );
|
||||
$default = $tag->get_default_option($default, array('multiple' => false));
|
||||
$default = wpcf7_get_hangover( $tag->name, $default ); // Get from $_POST if available
|
||||
|
||||
$class = wpcf7_form_controls_class( $tag->type );
|
||||
$validation_error = wpcf7_get_validation_error( $tag->name );
|
||||
if ($validation_error)
|
||||
$class .= ' wpcf7-not-valid';
|
||||
|
||||
$attr = array(
|
||||
'name' => $tag->name,
|
||||
'include_blank' => $tag->has_option( 'include_blank' ),
|
||||
'required' => substr($tag->type, -1) == '*',
|
||||
'invalid' => $validation_error ? 'true' : 'false',
|
||||
'id' => $tag->get_id_option(),
|
||||
'class' => $tag->get_class_option( $class ),
|
||||
'lang' => $tag->get_option('lang', '', true),
|
||||
'selected' => $default,
|
||||
'default' => $tag->get_option('default', '', true),
|
||||
);
|
||||
$html = geoip_detect2_shortcode_country_select($attr);
|
||||
|
||||
$html = sprintf(
|
||||
'<span class="wpcf7-form-control-wrap %1$s">%2$s %3$s</span>',
|
||||
sanitize_html_class( $tag->name ), $html, $validation_error );
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generating a <input />-field that has a geoip value as default
|
||||
*
|
||||
* Property can be: continent, country, city, postal.code or any other property understood by `geoip_detect2_get_info_from_ip`
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* `[geoip_detect2_text_input name="city" property="city" lang="fr" id="id" class="class"]`
|
||||
* A text input that has the detetected city as default (with CSS id "#id" and class ".class")
|
||||
*
|
||||
* `[geoip_detect2_text_input name="city" property="city" lang="fr" id="id" class="class" default="Paris"]`
|
||||
* As above, but in case the city is unknown, use "Paris"
|
||||
*
|
||||
* $attr is an array that can have these properties:
|
||||
* @param string $property Maxmind property string (e.g. "city" or "postal.code")
|
||||
* @param string $name Name of the form element
|
||||
* @param bool $required If the field is required or not
|
||||
* @param string $id CSS Id of element
|
||||
* @param string $class CSS Class of element
|
||||
* @param string $lang Language(s) (optional. If not set, current site language is used.)
|
||||
* @param string $default Default Value that will be used if country cannot be detected (optional)
|
||||
* @param bool $skip_cache
|
||||
* @param string $ip
|
||||
* @param string $placeholder
|
||||
*
|
||||
* @return string The generated HTML
|
||||
*/
|
||||
function geoip_detect2_shortcode_text_input($attr) {
|
||||
$value = geoip_detect2_shortcode($attr + array('add_error' => false));
|
||||
|
||||
$html_attrs = array(
|
||||
'type' => 'text',
|
||||
'name' => !empty($attr['name']) ? $attr['name'] : 'geoip-text-input',
|
||||
'id' => !empty($attr['id']) ? $attr['id'] : '',
|
||||
'class' => !empty($attr['class']) ? $attr['class'] : 'geoip-text-input',
|
||||
'aria-required' => !empty($attr['required']) ? 'required' : '',
|
||||
'aria-invalid' => !empty($attr['invalid']) ? $attr['invalid'] : '',
|
||||
'value' => $value,
|
||||
'placeholder' => !empty($attr['placeholder']) ? $attr['placeholder'] : '',
|
||||
);
|
||||
|
||||
$html = '<input ' . _geoip_detect_flatten_html_attr($html_attrs) . '/>';
|
||||
return $html;
|
||||
}
|
||||
add_shortcode('geoip_detect2_text_input', 'geoip_detect2_shortcode_text_input');
|
||||
add_shortcode('geoip_detect2_input', 'geoip_detect2_shortcode_text_input');
|
||||
|
||||
/**
|
||||
* Generating a text field that has a geoip value as default
|
||||
*
|
||||
* Property can be: continent, country, city, postal.code or any other property understood by `geoip_detect2_get_info_from_ip`
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* `[geoip_detect2_text_input city property:city lang:fr id:id class:class]`
|
||||
* A text input that has the detetected city as default (with CSS id "#id" and class ".class")
|
||||
*
|
||||
* `[geoip_detect2_text_input city property:city lang:fr id:id class:class default:Paris]`
|
||||
* As above, but in case the city is unknown, use "Paris"
|
||||
*
|
||||
*/
|
||||
function geoip_detect2_shortcode_text_input_wpcf7($tag) {
|
||||
$tag = new WPCF7_FormTag( $tag );
|
||||
|
||||
$default = (string) reset( $tag->values );
|
||||
$default = $tag->get_default_option($default, array('multiple' => false));
|
||||
$default = wpcf7_get_hangover( $tag->name, $default ); // Get from $_POST if available
|
||||
|
||||
$class = wpcf7_form_controls_class( $tag->type );
|
||||
$validation_error = wpcf7_get_validation_error( $tag->name );
|
||||
if ($validation_error)
|
||||
$class .= ' wpcf7-not-valid';
|
||||
|
||||
$attr = array(
|
||||
'name' => $tag->name,
|
||||
'required' => substr($tag->type, -1) == '*',
|
||||
'invalid' => $validation_error ? 'true' : 'false',
|
||||
'id' => $tag->get_id_option(),
|
||||
'class' => $tag->get_class_option( $class ),
|
||||
'lang' => $tag->get_option('lang', '', true),
|
||||
'property' => $tag->get_option('property', '', true),
|
||||
'default' => $tag->get_option('default', '', true),
|
||||
);
|
||||
$html = geoip_detect2_shortcode_text_input($attr);
|
||||
|
||||
$html = sprintf(
|
||||
'<span class="wpcf7-form-control-wrap %1$s">%2$s %3$s</span>',
|
||||
sanitize_html_class( $tag->name ), $html, $validation_error );
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
add_action( 'wpcf7_init', 'geoip_detect2_add_wpcf7_shortcodes' );
|
||||
function geoip_detect2_add_wpcf7_shortcodes() {
|
||||
if (function_exists('wpcf7_add_form_tag')) {
|
||||
// >=CF 4.6
|
||||
wpcf7_add_form_tag(array('geoip_detect2_countries', 'geoip_detect2_countries*'), 'geoip_detect2_shortcode_country_select_wpcf7', true);
|
||||
wpcf7_add_form_tag(array('geoip_detect2_text_input', 'geoip_detect2_text_input*'), 'geoip_detect2_shortcode_text_input_wpcf7', true);
|
||||
} else if (function_exists('wpcf7_add_shortcode')) {
|
||||
// < CF 4.6
|
||||
wpcf7_add_shortcode(array('geoip_detect2_countries', 'geoip_detect2_countries*'), 'geoip_detect2_shortcode_country_select_wpcf7', true);
|
||||
wpcf7_add_shortcode(array('geoip_detect2_text_input', 'geoip_detect2_text_input*'), 'geoip_detect2_shortcode_text_input_wpcf7', true);
|
||||
}
|
||||
}
|
||||
|
||||
function geoip_detect2_shortcode_user_info_wpcf7($output, $name, $isHtml) {
|
||||
$lines = array();
|
||||
|
||||
switch($name) {
|
||||
case 'geoip_detect2_get_client_ip':
|
||||
$lines[] = geoip_detect2_get_client_ip();
|
||||
break;
|
||||
case 'geoip_detect2_get_current_source_description':
|
||||
$lines[] = geoip_detect2_get_current_source_description();
|
||||
break;
|
||||
case 'geoip_detect2_property_country':
|
||||
$info = geoip_detect2_get_info_from_current_ip();
|
||||
$lines[] = $info->country->name;
|
||||
break;
|
||||
case 'geoip_detect2_property_most_specific_subdivision':
|
||||
case 'geoip_detect2_property_state':
|
||||
case 'geoip_detect2_property_region':
|
||||
$name = 'geoip_detect2_property_most_specific_subdivision';
|
||||
$info = geoip_detect2_get_info_from_current_ip();
|
||||
$lines[] = $info->mostSpecificSubdivision->name;
|
||||
break;
|
||||
case 'geoip_detect2_property_city':
|
||||
$info = geoip_detect2_get_info_from_current_ip();
|
||||
$lines[] = $info->city->name;
|
||||
break;
|
||||
|
||||
case 'geoip_detect2_user_info':
|
||||
$lines[] = sprintf(__('IP of the user: %s', 'geoip-detect'), geoip_detect2_get_client_ip());
|
||||
|
||||
$info = geoip_detect2_get_info_from_current_ip();
|
||||
if ($info->country->name)
|
||||
$lines[] = sprintf(__('Country: %s', 'geoip-detect'), $info->country->name);
|
||||
if ($info->mostSpecificSubdivision->name)
|
||||
$lines[] = sprintf(__('State or region: %s', 'geoip-detect'), $info->mostSpecificSubdivision->name);
|
||||
if ($info->city->name)
|
||||
$lines[] = sprintf(__('City: %s', 'geoip-detect'), $info->city->name);
|
||||
|
||||
$lines[] = '';
|
||||
$lines[] = sprintf(__('Data from: %s', 'geoip-detect'), geoip_detect2_get_current_source_description());
|
||||
break;
|
||||
|
||||
default:
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter: geoip2_detect_wpcf7_special_mail_tags
|
||||
* This filter is called if a GeoIP-detection-tag was used.
|
||||
*
|
||||
* @param array $lines - Output lines
|
||||
* @param string $name - Name of the WPCF 7 Tag that was used
|
||||
* @param bool $isHtml - Whether HTML or Plain Text output should be used
|
||||
* @return array Output lines
|
||||
*/
|
||||
$lines = apply_filters('geoip2_detect_wpcf7_special_mail_tags', $lines, $name, $isHtml);
|
||||
|
||||
$lineBreak = $isHtml ? "<br>" : "\n";
|
||||
return implode($lineBreak, $lines);
|
||||
}
|
||||
add_filter( 'wpcf7_special_mail_tags', 'geoip_detect2_shortcode_user_info_wpcf7', 18, 3 );
|
||||
|
||||
function geoip_detect_shortcode_user_info() {
|
||||
return geoip_detect2_shortcode_user_info_wpcf7('', 'geoip_detect2_user_info', true);
|
||||
}
|
||||
add_shortcode('geoip_detect2_user_info', 'geoip_detect_shortcode_user_info');
|
||||
|
||||
/**
|
||||
*
|
||||
* Geo-Dependent Content Hiding
|
||||
*
|
||||
* Uses an enclosing shortcode to selectively show or hide content. Use either
|
||||
* [geoip_detect2_show_if][/geoip_detect2_show_if] or [geoip_detect2_hide_if][/geoip_detect2_hide_if] at your
|
||||
* discretion, as they can both be used to accomplish the same thing.
|
||||
*
|
||||
* Shortcode attributes can be as follows:
|
||||
*
|
||||
* Inclusive Attributes (note that `hide_if` makes them exclusive):
|
||||
* "continent", "country", "most_specific_subdivision"/"region"/"state"*, "city"
|
||||
*
|
||||
* * most_specific_subdivision, region, and state are aliases (use the one that makes the most sense to you)
|
||||
*
|
||||
* Exclusive Attributes (note that `hide_if` makes them inclusive):
|
||||
* "not_country", "not_most_specific_subdivision"/"not_region"/"not_state"*, "not_city"
|
||||
*
|
||||
* * most_specific_subdivision, region, and state are aliases (use the one that makes the most sense to you)
|
||||
*
|
||||
* Each attribute may only appear once in a shortcode!
|
||||
* The location attributes can take each take full names, ISO abbreviations (e.g., US), or the GeonamesId.
|
||||
* All attributes may take multiple values seperated by comma (,).
|
||||
*
|
||||
* You can use custom property names with the attribute "property" and "property_value" / "not_property_value".
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* Display TEXT if the visitor is in the US and in Texas.
|
||||
* `[geoip_detect2_show_if country="US" state="TX"]TEXT[/geoip_detect2_show_if]`
|
||||
* - OR -
|
||||
* `[geoip_detect2_show_if country="US" region="TX"]TEXT[/geoip_detect2_show_if]`
|
||||
* - OR -
|
||||
* `[geoip_detect2_show_if country="US" region="Texas"]TEXT[/geoip_detect2_show_if]`
|
||||
* - OR -
|
||||
* `[geoip_detect2_show_if country="US" most_specific_subdivision="TX"]TEXT[/geoip_detect2_show_if]`
|
||||
*
|
||||
* Display TEXT if the visitor is in the US, and in either Texas or Louisiana, but hide this content
|
||||
* from visitors with IP addresses from cities named Houston.
|
||||
* `[geoip_detect2_show_if country="US" state="TX, LA" not_city="Houston"]TEXT[/geoip_detect2_show_if]`
|
||||
*
|
||||
* Display TEXT if the visitor is from North America.
|
||||
* `[geoip_detect2_show_if continent="North America"]TEXT[/geoip_detect2_show_if]`
|
||||
* - OR -
|
||||
* `[geoip_detect2_hide_if not_continent="North America"]TEXT[/geoip_detect2_hide_if]`
|
||||
*
|
||||
* Hide TEXT if the visitor is from the US.
|
||||
* `[geoip_detect2_hide_if country="US"]TEXT[/geoip_detect2_hide_if]`
|
||||
* - OR -
|
||||
* `[geoip_detect2_show_if not_country="US"]TEXT[/geoip_detect2_show_if]`
|
||||
*
|
||||
* Show TEXT if the visitor is within the timezone Europe/Berlin
|
||||
* `[geoip_detect2_show_if property="location.timeZone" property_value="Europe/Berlin"]TEXT[/geoip_detect2_show_if]`
|
||||
*
|
||||
* LIMITATIONS:
|
||||
* - You cannot nest several of these shortcodes within one another. Instead, seperate them into several blocks of shortcodes.
|
||||
* - City names can be ambigous. For example, [geoip_detect2_show_if country="US,FR" not_city="Paris"] will exclude both Paris in France and Paris in Texas, US. Instead, you can find out the geoname_id or seperate the shortcode to make it more specific.
|
||||
*
|
||||
*/
|
||||
function geoip_detect2_shortcode_show_if($attr, $content = null, $shortcodeName = '') {
|
||||
$showContentIfMatch = ($shortcodeName == 'geoip_detect2_show_if') ? true : false;
|
||||
|
||||
/* Attribute Conditions. Order is not important, as they are combined with an transitive AND condition */
|
||||
$attributeNames = array(
|
||||
'continent' => 'continent',
|
||||
'not_continent' => 'continent',
|
||||
'country' => 'country',
|
||||
'not_country' => 'country',
|
||||
'most_specific_subdivision' => 'mostSpecificSubdivision',
|
||||
'region' => 'mostSpecificSubdivision',
|
||||
'state' => 'mostSpecificSubdivision',
|
||||
'not_most_specific_subdivision' => 'mostSpecificSubdivision',
|
||||
'not_region' => 'mostSpecificSubdivision',
|
||||
'not_state' => 'mostSpecificSubdivision',
|
||||
'city' => 'city',
|
||||
'not_city' => 'city',
|
||||
);
|
||||
|
||||
$attrDefaults = array(
|
||||
'lang' => null,
|
||||
'skip_cache' => 'false',
|
||||
'property' => null,
|
||||
'property_value' => null,
|
||||
'not_property_value' => null,
|
||||
);
|
||||
$attrDefaults = array_merge($attrDefaults, array_fill_keys(array_keys($attributeNames), null));
|
||||
|
||||
$attr = shortcode_atts($attrDefaults, $attr, $shortcodeName);
|
||||
|
||||
$skipCache = filter_var($attr['skip_cache'], FILTER_VALIDATE_BOOLEAN );
|
||||
|
||||
$locales = isset($attr['lang']) ? $attr['lang'] . ',en' : null;
|
||||
$locales = apply_filters('geoip_detect2_locales', $locales);
|
||||
|
||||
$options = array('skipCache' => $skipCache);
|
||||
|
||||
$info = geoip_detect2_get_info_from_current_ip($locales, $options);
|
||||
|
||||
/**
|
||||
* You can override the detected location information here.
|
||||
* E.g. "Show if in Paris, but if the user has given an adress in his profile, use that city instead"
|
||||
* @param YellowTree\GeoipDetect\DataSources\City $info
|
||||
* @param array $attr Shortcode attributes given to the function.
|
||||
* @param bool $showContentIfMatch Should the content be shown (TRUE) or hidden (FALSE) if the conditions are true?
|
||||
*/
|
||||
$info = apply_filters('geoip_detect2_shortcode_show_if_ip_info_override', $info, $attr, $showContentIfMatch);
|
||||
|
||||
$isConditionMatching = true;
|
||||
|
||||
foreach ($attributeNames as $shortcodeParamName => $maxmindName) {
|
||||
if (!empty($attr[$shortcodeParamName])) {
|
||||
// Determine Actual MaxMind Value(s) for Attribute
|
||||
$actualValues = array();
|
||||
$alternativePropertyNames = array(
|
||||
'name',
|
||||
'isoCode',
|
||||
'code',
|
||||
'geonameId',
|
||||
);
|
||||
foreach ($alternativePropertyNames as $p) {
|
||||
if (isset($info->{$maxmindName}->{$p})) {
|
||||
$actualValues[] = $info->{$maxmindName}->{$p};
|
||||
}
|
||||
}
|
||||
|
||||
$subConditionMatching = geoip_detect2_shortcode_check_subcondition($attr[$shortcodeParamName], $actualValues);
|
||||
|
||||
if (substr($shortcodeParamName, 0, 4) == 'not_') {
|
||||
$subConditionMatching = !$subConditionMatching;
|
||||
}
|
||||
$isConditionMatching = $isConditionMatching && $subConditionMatching;
|
||||
}
|
||||
}
|
||||
|
||||
// Custom property
|
||||
if (!empty($attr['property']) && (!empty($attr['property_value']) || !empty($attr['not_property_value'])) ) {
|
||||
$subConditionMatching = false;
|
||||
try {
|
||||
$actualValue = geoip_detect2_shortcode_get_property($info, $attr['property']);
|
||||
|
||||
if (!empty($attr['property_value'])) {
|
||||
$subConditionMatching = geoip_detect2_shortcode_check_subcondition($attr['property_value'], $actualValue);
|
||||
}
|
||||
if (!empty($attr['not_property_value'])) {
|
||||
$subConditionMatching = ! geoip_detect2_shortcode_check_subcondition($attr['not_property_value'], $actualValue);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
// Invalid Property or so... ignore.
|
||||
}
|
||||
|
||||
$isConditionMatching = $isConditionMatching && $subConditionMatching;
|
||||
}
|
||||
|
||||
// All Criteria Passed?
|
||||
if ($isConditionMatching === $showContentIfMatch) {
|
||||
return do_shortcode($content);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
add_shortcode('geoip_detect2_show_if', 'geoip_detect2_shortcode_show_if');
|
||||
add_shortcode('geoip_detect2_hide_if', 'geoip_detect2_shortcode_show_if');
|
||||
|
||||
function geoip_detect2_shortcode_check_subcondition($expectedValuesRaw, $actualValues) {
|
||||
// Parse User Input Values of Attribute
|
||||
$attributeValuesArray = explode(',', $expectedValuesRaw);
|
||||
$attributeValuesArray = array_map('trim', $attributeValuesArray);
|
||||
|
||||
$actualValues = (array) $actualValues;
|
||||
|
||||
// Compare case-insensitively
|
||||
$attributeValuesArray = array_map('mb_strtolower', $attributeValuesArray);
|
||||
$actualValues = array_map('mb_strtolower', $actualValues);
|
||||
|
||||
return count(array_intersect($actualValues, $attributeValuesArray)) > 0;
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------- Flags - This needs the Plugin "SVG Flags" to work ---------------------
|
||||
|
||||
/**
|
||||
* @param int|string width CSS Width of the flag `<span>`-Element (in Pixels or CSS including unit)
|
||||
* @param int|string height CSS Height of the flag `<span>`-Element (in Pixels or CSS including unit)
|
||||
* @param int squared Instead of being 4:3, the flag should be 1:1 in ratio
|
||||
* @param string $class Extra CSS Class of element. All flags will have the class `flag-icon` anyway.
|
||||
* @param string $default Default Country in case the visitor's country cannot be determined
|
||||
*/
|
||||
function geoip_detect2_shortcode_current_flag($attr, $content = '', $shortcodeName = 'geoip_detect2_current_flag') {
|
||||
if (!wp_style_is('svg-flags-css')) {
|
||||
return '<!-- There should be a flag here. However, the Plugin "SVG Flags" is missing.';
|
||||
}
|
||||
|
||||
$attr = shortcode_atts(array(
|
||||
'width' => '',
|
||||
'height' => '',
|
||||
'squared' => '',
|
||||
'square' => '',
|
||||
'class' => '',
|
||||
'default' => '',
|
||||
'skip_cache' => false,
|
||||
), $attr, $shortcodeName);
|
||||
|
||||
$skipCache = filter_var($attr['skip_cache'], FILTER_VALIDATE_BOOLEAN );
|
||||
$options = array('skipCache' => $skipCache);
|
||||
|
||||
$style = '';
|
||||
$processCssProperty = function($name, $value) {
|
||||
$value = strtr($value, [' ' => '', ':' => '', ';' => '']);
|
||||
if (!$value) {
|
||||
return '';
|
||||
}
|
||||
if (is_numeric($value)) {
|
||||
$value .= 'px';
|
||||
}
|
||||
return $name . ':' . $value . ';';
|
||||
};
|
||||
$style .= $processCssProperty('height', $attr['height']);
|
||||
$style .= $processCssProperty('width', $attr['width']);
|
||||
|
||||
if ($attr['squared'] || $attr['square']) {
|
||||
$attr['class'] .= ' flag-icon-squared';
|
||||
}
|
||||
|
||||
$record = geoip_detect2_get_info_from_current_ip(null, $options);
|
||||
$country = $attr['default'];
|
||||
if ($record->country->isoCode) {
|
||||
$country = $record->country->isoCode;
|
||||
}
|
||||
if (!$country) {
|
||||
return '<!-- There should be a flag here, but no country could be detected and the parameter "default" was not set. -->';
|
||||
}
|
||||
$country = mb_substr($country, 0, 2);
|
||||
$country = mb_strtolower($country);
|
||||
|
||||
$html = '<span style="'. esc_attr($style) . '" class="' . esc_attr($attr['class']) . ' flag-icon ' . esc_attr('flag-icon-' . $country) . '"></span>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
add_shortcode('geoip_detect2_current_flag', 'geoip_detect2_shortcode_current_flag');
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
// You can use this in your theme/plugin to deactivate the auto-update
|
||||
//define('GEOIP_DETECT_AUTO_UPDATE_DEACTIVATED', true);
|
||||
|
||||
define('GEOIP_DETECT_UPDATER_INCLUDED', true);
|
||||
|
||||
// Needed for WP File functions. Cron doesn't work without it.
|
||||
require_once(ABSPATH.'/wp-admin/includes/file.php');
|
||||
|
||||
function geoip_detect_update()
|
||||
{
|
||||
// TODO: Currently cron is scheduled but not executed. Remove scheduling.
|
||||
if (get_option('geoip-detect-source') != 'auto')
|
||||
return;
|
||||
|
||||
$download_url = 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz';
|
||||
$download_url = apply_filters('geoip_detect2_download_url', $download_url);
|
||||
|
||||
$outFile = geoip_detect_get_database_upload_filename();
|
||||
|
||||
// Download
|
||||
$tmpFile = download_url($download_url);
|
||||
if (is_wp_error($tmpFile))
|
||||
return $tmpFile->get_error_message();
|
||||
|
||||
// Ungzip File
|
||||
$zh = gzopen($tmpFile, 'r');
|
||||
$h = fopen($outFile, 'w');
|
||||
|
||||
if (!$zh)
|
||||
return __('Downloaded file could not be opened for reading.', 'geoip-detect');
|
||||
if (!$h)
|
||||
return sprintf(__('Database could not be written (%s).', 'geoip-detect'), $outFile);
|
||||
|
||||
while ( ($string = gzread($zh, 4096)) != false )
|
||||
fwrite($h, $string, strlen($string));
|
||||
|
||||
gzclose($zh);
|
||||
fclose($h);
|
||||
|
||||
unlink($tmpFile);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ------------------ CRON Hooks --------------------------
|
||||
|
||||
function geoip_detect_update_cron($immediately_after_activation = false) {
|
||||
/**
|
||||
* Filter:
|
||||
* Cron has fired.
|
||||
* Find out if file should be updated now.
|
||||
*
|
||||
* @param $do_it False if deactivated by define
|
||||
* @param $immediately_after_activation True if this is fired because the plugin was recently activated
|
||||
*/
|
||||
$do_it = apply_filters('geoip_detect_cron_do_update', !GEOIP_DETECT_AUTO_UPDATE_DEACTIVATED, $immediately_after_activation);
|
||||
|
||||
if ($do_it)
|
||||
geoip_detect_update();
|
||||
|
||||
geoip_detect_schedule_next_cron_run();
|
||||
}
|
||||
add_action('geoipdetectupdate', 'geoip_detect_update_cron', 10, 1);
|
||||
|
||||
function geoip_detect_set_cron_schedule($now = false)
|
||||
{
|
||||
$next = wp_next_scheduled( 'geoipdetectupdate' );
|
||||
if ( !$next ) {
|
||||
geoip_detect_schedule_next_cron_run();
|
||||
}
|
||||
|
||||
if ($now)
|
||||
wp_schedule_single_event(time(), 'geoipdetectupdate', array(true));
|
||||
}
|
||||
|
||||
function geoip_detect_schedule_next_cron_run() {
|
||||
// The Lite databases are updated on the first tuesday of each month. Maybe not at midnight, so we schedule it for the night afterwards.
|
||||
$next = strtotime('first tuesday of next month + 1 day');
|
||||
wp_schedule_single_event($next, 'geoipdetectupdate');
|
||||
}
|
||||
|
||||
|
||||
function geoip_detect_deactivate()
|
||||
{
|
||||
wp_clear_scheduled_hook('geoipdetectupdate');
|
||||
wp_clear_scheduled_hook('geoipdetectupdate', array(true));
|
||||
}
|
||||
register_deactivation_hook(GEOIP_PLUGIN_FILE, 'geoip_detect_deactivate');
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/*
|
||||
Copyright 2013-2019 Yellow Tree, Siegen, Germany
|
||||
Author: Benjamin Pick (wp-geoip-detect| |posteo.de)
|
||||
|
||||
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 3 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 St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
/**
|
||||
* This function is executed each time a new version is installed.
|
||||
* Note that downgrading versions is not supported. (Shouldn't lead to problems, though, normally.)
|
||||
*
|
||||
* These updates are executed ONCE if the old version is smaller than ...
|
||||
*
|
||||
* @param string $old_version
|
||||
*/
|
||||
function geoip_detect_do_upgrade($old_version) {
|
||||
|
||||
// v2.3.0 Always set default source to hostinfo
|
||||
if (version_compare('2.3.0', $old_version, '>')) {
|
||||
if (!get_option('geoip-detect-source'))
|
||||
update_option('geoip-detect-source', 'hostinfo');
|
||||
}
|
||||
|
||||
// v2.5.0 Set "DONOTCACHEPAGE"
|
||||
if (version_compare('2.5.0', $old_version, '>')) {
|
||||
if (get_option('geoip-detect-disable_pagecache') === false) {
|
||||
if (get_option('geoip-detect-set_css_country'))
|
||||
update_option('geoip-detect-disable_pagecache', '0');
|
||||
else
|
||||
update_option('geoip-detect-disable_pagecache', '1');
|
||||
}
|
||||
}
|
||||
|
||||
// v.2.5.1 - Upgrade to 2.5.0 contained a bug. Make sure info is consistent again.
|
||||
if (version_compare('2.5.0', $old_version, '=')) {
|
||||
if (get_option('geoip-detect-source') === '1') {
|
||||
update_option('geoip-detect-source', 'hostinfo');
|
||||
}
|
||||
}
|
||||
|
||||
// v 2.8.2 Fix auto update hook (re-schedule if necessary)
|
||||
if (version_compare('2.8.2', $old_version, '>')) {
|
||||
if (wp_next_scheduled( 'geoipdetectupdate' ) === false) {
|
||||
$source = new \YellowTree\GeoipDetect\DataSources\Auto\AutoDataSource;
|
||||
$source->deactivate();
|
||||
if (get_option('geoip-detect-source') == 'auto') {
|
||||
$source->activate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// v2.11.1 Create beta option in database
|
||||
if (version_compare('2.11.1', $old_version, '>')) {
|
||||
delete_option('geoip-detect-ajax_beta');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a routine to be called when a plugin has been updated
|
||||
*
|
||||
* It works by comparing the current version with the version previously stored in the database.
|
||||
*
|
||||
* @since 2.3.0
|
||||
*
|
||||
* @param string $file A reference to the main plugin file
|
||||
* @param callback $callback The function to run when the hook is called.
|
||||
* @param string $version The version to which the plugin is updating.
|
||||
*/
|
||||
function geoip_detect_maybe_upgrade_version( ) {
|
||||
if (!is_admin())
|
||||
return;
|
||||
|
||||
$version = GEOIP_DETECT_VERSION;
|
||||
$current_vers = get_option( 'geoip-detect-plugin_version' );
|
||||
|
||||
if ( version_compare( $version, $current_vers, '>' ) ) {
|
||||
|
||||
geoip_detect_do_upgrade($current_vers);
|
||||
|
||||
$current_vers = $version;
|
||||
}
|
||||
|
||||
update_option('geoip-detect-plugin_version', $current_vers );
|
||||
}
|
||||
add_action('plugins_loaded', 'geoip_detect_maybe_upgrade_version');
|
||||
@@ -0,0 +1,58 @@
|
||||
<div class="wrap geoip-detect-wrap">
|
||||
<!-- This page cannot be translated yet, as I am not sure how it will look like in the long-term.
|
||||
The goal is to have wizard helping to set all the relevant options semi-automatically. -->
|
||||
<h1><?php _e('GeoIP Detection', 'geoip-detect');?> - Client IP Debug Panel</h1>
|
||||
<p>
|
||||
<a href="tools.php?page=<?php echo GEOIP_PLUGIN_BASENAME ?>"><?php _e('Test IP Detection Lookup', 'geoip-detect')?></a>
|
||||
|
|
||||
<a href="options-general.php?page=<?php echo GEOIP_PLUGIN_BASENAME ?>"><?php _e('Options', 'geoip-detect');?></a>
|
||||
</p>
|
||||
<pre>This debug panel is listing all relevant informations to debug when the detected client ip is wrong (in case of reverse proxies etc.)
|
||||
Sometimes, there are proxies between your user and the wordpress server application (e.g. a <abbr title="Content Delivery Network: Amazon, Cloudflare, etc.">CDN</abbr>, reverse proxies).
|
||||
This needs to be known to the plugin to choose the correct IP adress.
|
||||
</pre>
|
||||
<h2>Current IP informations (as detected by the plugin)</h2>
|
||||
<p>
|
||||
Detected client IP: <b><?php echo geoip_detect2_get_client_ip(); ?></b><br>
|
||||
<span class="detail-box">This IP is used for detecting the geo-information of the user. It should be the same as the real client IP below.</span>
|
||||
Real client IP (detected without the plugin): <b><span id="ajax_get_client_ip"><i>Detecting ...</i></span></b>
|
||||
<span class="detail-box">This IP is detected within the browser, so reverse proxies of the server are not affected.<br></span>
|
||||
External Server IP: <b><?php echo geoip_detect2_get_external_ip_adress(); ?></b><br>
|
||||
<span class="detail-box">In some cases, the server is in the same network as the client (e.g. testing server). As the connection does not use Internet, this plugin uses the IP adress of the server as seen from the internet.<br>
|
||||
For performance reasons, this IP is cached for <?php echo human_time_diff(0, GEOIP_DETECT_IP_CACHE_TIME); ?>.<br>
|
||||
Also, for servers without internet access, this IP can be set in the options.
|
||||
</span>
|
||||
</p>
|
||||
<p>
|
||||
REMOTE_ADDR: <b><?php echo $_SERVER['REMOTE_ADDR']; ?></b><br>
|
||||
<span class="detail-box">In server configurations without reverse proxy, this will equal to the "detected client IP". Otherwise, this is the IP of the reverse proxy.</span>
|
||||
HTTP_X_FORWARDED_FOR: <b><?php echo isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : __('(unset)', 'geoip-detect'); ?></b><br>
|
||||
<span class="detail-box">Reverse proxies usually add this header to indicate the original IP. If several IPs are given here (seperated by a comma), the correct user IP usually is the leftmost one.</span>
|
||||
<?php if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]) && !get_option('geoip-detect-has_reverse_proxy')): ?>
|
||||
<i>(Probably you should enable the reverse proxy option.)</i>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
<h3>Settings of the plugin</h3>
|
||||
<ul>
|
||||
<li>Use reverse proxy: <b><?php echo get_option('geoip-detect-has_reverse_proxy', 0) ? 'yes' : 'no' ?></b>
|
||||
<span class="detail-box">Enable this option if REMOTE_ADDR is not the correct client IP.</span>
|
||||
</li>
|
||||
|
||||
<li>Whitelist for known reverse proxies (optional if only one): <b><?php echo get_option('geoip-detect-trusted_proxy_ips') ?: '(none)'; ?></b>
|
||||
<span class="detail-box">All IPs in HTTP_X_FORWARDED_FOR that are not the correct client IP are probably known reverse proxies.<br>(For security reasons, this is not assumed by default: maybe the reverse proxy is not of the server, but a Man-In-The-Middle-Attack ... not very probable but possible.)</span>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<script>
|
||||
jQuery.ajax(<?php echo json_encode(_geoip_detect2_get_external_ip_services(1, true)[0]); ?>, {
|
||||
type: 'GET',
|
||||
dataType: 'text',
|
||||
}).done(function(ret) {
|
||||
jQuery('#ajax_get_client_ip').text(ret);
|
||||
}).fail(function(xhr, status, ret) {
|
||||
jQuery('#ajax_get_client_ip').text('Failed: ' + status + ret);
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php require(GEOIP_PLUGIN_DIR . '/views/footer.php'); ?>
|
||||
</div>
|
||||
@@ -0,0 +1,45 @@
|
||||
<br><br>
|
||||
<p class="legal_notices">
|
||||
<br />
|
||||
<?php printf(__('This extension is "charity-ware". You can use it for free but if you want to do me a favor, please <a href="%s" target="_blank">donate</a> to <a href="%s" target="_blank">this charity</a>. (See <a href="%s" target="_blank">FAQ</a> for more infos.)', 'geoip-detect'),
|
||||
'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=BSYUZHS8FH3CL',
|
||||
__('http://www.jmem-hainichen.de/homepage', 'geoip-detect'),
|
||||
'https://github.com/yellowtree/wp-geoip-detect/wiki/FAQ#what-you-mean-by-this-plugin-is-charity-ware'); ?>
|
||||
</p>
|
||||
<p class="legal_notices">
|
||||
<?php _e('This product includes GeoLite2 data created by MaxMind, available from <a href="http://www.maxmind.com/">http://www.maxmind.com</a>.', 'geoip-detect'); ?>
|
||||
</p>
|
||||
|
||||
<style>
|
||||
.legal_notices {
|
||||
font-size: 80%;
|
||||
font-style: italic;
|
||||
}
|
||||
.geoip_detect_error {
|
||||
display:block;
|
||||
clear: both;
|
||||
background-color: rgb(255, 255, 255);
|
||||
border-left: rgb(255, 0, 0) solid 4px;
|
||||
box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1);
|
||||
display: inline-block;
|
||||
font-size: 14px;
|
||||
line-height: 19px;
|
||||
margin-bottom: 0;
|
||||
margin-left: 2px;
|
||||
margin-right: 20px;
|
||||
margin-top: 25px;
|
||||
padding-bottom: 11px;
|
||||
padding-left: 15px;
|
||||
padding-right: 15px;
|
||||
padding-top: 11px;
|
||||
text-align: left;
|
||||
}
|
||||
.detail-box {
|
||||
display: block;
|
||||
margin-left: 50px;
|
||||
color: #777;
|
||||
}
|
||||
.geoip-detect-wrap select {
|
||||
max-width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,230 @@
|
||||
<?php
|
||||
use YellowTree\GeoipDetect\DataSources\DataSourceRegistry;
|
||||
$date_format = get_option('date_format') . ' ' . get_option('time_format');
|
||||
|
||||
$current_source = DataSourceRegistry::getInstance()->getCurrentSource();
|
||||
|
||||
$is_ajax_enabled = !!get_option('geoip-detect-ajax_enabled');
|
||||
|
||||
// @see https://stackoverflow.com/a/35207172
|
||||
function var_export_short($data, $return=true)
|
||||
{
|
||||
$dump = var_export($data, true);
|
||||
|
||||
$dump = preg_replace('#(?:\A|\n)([ ]*)array \(#i', '[', $dump); // Starts
|
||||
$dump = preg_replace('#\n([ ]*)\),#', "\n$1],", $dump); // Ends
|
||||
$dump = preg_replace('#=> \[\n\s+\],\n#', "=> [],\n", $dump); // Empties
|
||||
|
||||
if (gettype($data) == 'object') { // Deal with object states
|
||||
$dump = str_replace('__set_state(array(', '__set_state([', $dump);
|
||||
$dump = preg_replace('#\)\)$#', "])", $dump);
|
||||
} else {
|
||||
$dump = preg_replace('#\)$#', "]", $dump);
|
||||
}
|
||||
|
||||
$dump = preg_replace('#,[\n\s]*]#m', "\n]", $dump);
|
||||
|
||||
if ($return===true) {
|
||||
return $dump;
|
||||
} else {
|
||||
echo $dump;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="wrap geoip-detect-wrap">
|
||||
<h1><?php _e('GeoIP Detection', 'geoip-detect');?></h1>
|
||||
<p>
|
||||
<a href="options-general.php?page=<?php echo GEOIP_PLUGIN_BASENAME ?>"><?php _e('Options', 'geoip-detect');?></a>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<?php printf(__('<b>Selected data source:</b> %s', 'geoip-detect'), geoip_detect2_get_current_source_description() ); ?>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<?php echo $current_source->getStatusInformationHTML(); ?>
|
||||
<br />
|
||||
<br />
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<b><?php _e('Your current IP:', 'geoip-detect');?></b> <?php echo geoip_detect2_get_client_ip(); ?>
|
||||
<a href="options-general.php?page=<?php echo GEOIP_PLUGIN_BASENAME ?>&geoip_detect_part=client-ip">(<?php _e('Not correct?', 'geoip-detect');?>)</a>
|
||||
</p>
|
||||
|
||||
<h2><?php _e('Test IP Detection Lookup ', 'geoip-detect');?></h2>
|
||||
<form method="post" action="#">
|
||||
<?php wp_nonce_field( 'geoip_detect_lookup' ); ?>
|
||||
<input type="hidden" name="action" value="lookup" />
|
||||
<?php _e('IP', 'geoip-detect')?>: <input type="text" placeholder="<?php _e('Enter an IP (v4 or v6)', 'geoip-detect')?>" name="ip" value="<?php echo isset($_REQUEST['ip']) ? esc_attr($_REQUEST['ip']) : esc_attr(geoip_detect2_get_client_ip()); ?>" /><br />
|
||||
<label><?php _e('Use these locales:', 'geoip-detect'); ?>
|
||||
<select name="locales">
|
||||
<option value="" <?php if (empty($_POST['locales'])) echo 'selected="selected"'?>><?php _e('Default (Current site language, English otherwise)', 'geoip-detect')?></option>
|
||||
<option value="en" <?php if (!empty($_POST['locales']) && $_POST['locales'] == 'en') echo 'selected="selected"'?>><?php _e('English only', 'geoip-detect')?></option>
|
||||
<option value="fr,en" <?php if (!empty($_POST['locales']) && $_POST['locales'] == 'fr,en') echo 'selected="selected"'?>><?php _e('French, English otherwise', 'geoip-detect')?></option>
|
||||
</select>
|
||||
</label><br />
|
||||
<label><?php _e('Which syntax:', 'geoip-detect'); ?>
|
||||
<select name="syntax">
|
||||
<option value="php" <?php if (empty($_POST['syntax']) || $_POST['syntax'] === 'php') echo 'selected="selected"'?>><?= __('PHP Syntax') ?></option>
|
||||
<option value="shortcode" <?php if (!empty($_POST['syntax']) && $_POST['syntax'] === 'shortcode') echo 'selected="selected"'?>><?= __('Shortcode Syntax') ?></option>
|
||||
<option value="js" <?php if (!empty($_POST['syntax']) && $_POST['syntax'] === 'js') echo 'selected="selected"'?>><?= __('JS Syntax') ?></option>
|
||||
</select>
|
||||
</label><br>
|
||||
<label><input type="checkbox" name="skip_cache" value="1" <?php if (!empty($_POST['skip_cache'])) echo 'checked="checked"'?>/><?php _e('Skip cache', 'geoip-detect')?></label><br />
|
||||
<br />
|
||||
<input type="submit" class="button button-primary" value="<?php _e('Lookup', 'geoip-detect'); ?>" />
|
||||
</form>
|
||||
<?php if ($ip_lookup_result !== false) :
|
||||
if (is_object($ip_lookup_result)) :
|
||||
$record = $ip_lookup_result;
|
||||
$data = _geoip_detect_improve_data_for_lookup($record->jsonSerialize());
|
||||
$data_short = _geoip_detect_improve_data_for_lookup($record->jsonSerialize(), true);
|
||||
|
||||
?>
|
||||
<h3><?php _e('Lookup Result', 'geoip-detect'); ?></h3>
|
||||
<p>
|
||||
<?php if ($_POST['syntax'] == 'php') : ?>
|
||||
<?php printf(__('The function %s returns an object:', 'geoip-detect'), "<code>\$record = geoip_detect2_get_info_from_ip('" . esc_html($request_ip) . "', " . var_export_short($request_locales, true) . ($request_skipCache ? ', [ \'skipCache\' => TRUE ]' : '') .");</code>"); ?><br />
|
||||
<?= sprintf(__('See %s for more information.', 'geoip-detect'), '<a href="https://github.com/yellowtree/geoip-detect/wiki/API:-PHP">API: PHP</a>'); ?>
|
||||
<?php elseif ($_POST['syntax'] == 'shortcode') : ?>
|
||||
<?= sprintf(__('You can use the following shortcodes.', 'geoip-detect')); ?><br />
|
||||
<?= sprintf(__('See %s for more information.', 'geoip-detect'), '<a href="https://github.com/yellowtree/geoip-detect/wiki/API:-Shortcodes">API: Shortcodes</a>'); ?>
|
||||
<?php elseif ($_POST['syntax'] == 'js') : ?>
|
||||
<?= sprintf(__('AJAX and JS must be enabled in the preferences!', 'geoip-detect')); ?><br />
|
||||
<?= sprintf(__('See %s for more information.', 'geoip-detect'), '<a href="https://github.com/yellowtree/geoip-detect/wiki/API:-AJAX">API: AJAX</a>'); ?>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
<p>
|
||||
<?php printf(__('Lookup duration: %.5f s', 'geoip-detect'), $ip_lookup_duration); ?>
|
||||
<?php if ($record->extra->cached) : ?>
|
||||
<br /><?php printf(__('(Served from cache. Was cached %s ago)', 'geoip-detect'), human_time_diff($record->extra->cached));?>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
|
||||
<?php if ($record->extra->error) : ?>
|
||||
<p class="geoip_detect_error">
|
||||
<?php echo nl2br(esc_html($record->extra->error)); ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th style="text-align: left"><?php _e('Value', 'geoip-detect'); ?></th>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
function show_row($record, $key_1, $key_2, $value = null, $class = '') {
|
||||
if (is_array($value)) {
|
||||
if ($key_2 === 'names') {
|
||||
show_row($record, $key_1, 'name', null, $class);
|
||||
return;
|
||||
}
|
||||
if ($key_1 === 'subdivisions') {
|
||||
foreach ($value as $key_3 => $v) {
|
||||
show_row($record, 'most_specific_subdivision', $key_3, $v, $class);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
$camel_key_1 = _geoip_dashes_to_camel_case($key_1);
|
||||
$camel_key_2 = _geoip_dashes_to_camel_case($key_2);
|
||||
|
||||
try {
|
||||
if (is_object($record) ) {
|
||||
$value = $record->$camel_key_1;
|
||||
if (is_object($value)) {
|
||||
$value = $value->$camel_key_2;
|
||||
}
|
||||
}
|
||||
} catch(\RuntimeException $e) {
|
||||
return; // Access did not work.
|
||||
}
|
||||
if (!is_string($value)) {
|
||||
$value = var_export_short($value, true);
|
||||
}
|
||||
|
||||
switch($_POST['syntax']) {
|
||||
case 'shortcode':
|
||||
$extra = '';
|
||||
if (!empty($_POST['locales']) && $key_2 === 'name') {
|
||||
$extra .= ' lang="' . $_POST['locales'] . '"';
|
||||
}
|
||||
if (!empty($_POST['skip_cache'])) {
|
||||
$extra .= ' skip_cache="true"';
|
||||
}
|
||||
|
||||
$access = '[geoip_detect2 property="' . $camel_key_1 . '.' . $camel_key_2 . '"' . $extra . ']';
|
||||
break;
|
||||
|
||||
case 'js':
|
||||
$prop = '"' . $key_1 . '.' . $key_2 . '"';
|
||||
if (!empty($_POST['locales']) && $key_2 === 'name') {
|
||||
$access = 'record.get_with_locales(' . $prop . ', ' . json_encode(explode(',', $_POST['locales'])) . ')';
|
||||
} else {
|
||||
$access = 'record.get(' . $prop . ')';
|
||||
}
|
||||
break;
|
||||
|
||||
case 'php':
|
||||
default:
|
||||
$access = '$record->' . $camel_key_1 . '->' . $camel_key_2;
|
||||
break;
|
||||
}
|
||||
?>
|
||||
<tr class="<?= $class ?>">
|
||||
<td><code><?= esc_html($access) ?></code></td>
|
||||
<td><?= esc_html($value);?></td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
foreach($data as $key_1 => $value_1) {
|
||||
if (is_array($value_1)) {
|
||||
foreach($value_1 as $key_2 => $value_2) {
|
||||
show_row($record, $key_1, $key_2, $value_2, 'all');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach($data_short as $key_1 => $value_1) {
|
||||
if (is_array($value_1)) {
|
||||
foreach($value_1 as $key_2 => $value_2) {
|
||||
show_row($record, $key_1, $key_2, $value_2, 'short');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
</table>
|
||||
|
||||
<p class="all"><a href="#" onclick="geoip_properties_toggle('short', 'all'); return false;"><?= __('Show only the most common properties', 'geoip-detect') ?></a></p>
|
||||
<p class="short"><a href="#" onclick="geoip_properties_toggle('all', 'short'); return false;"><?= __('Show all available properties', 'geoip-detect') ?></a></p>
|
||||
<p><?= __('(More properties might be available for other IPs and with other data sources.)', 'geoip-detect'); ?></p>
|
||||
|
||||
<?php if (WP_DEBUG) { var_Dump($data); } ?>
|
||||
<?php elseif ($ip_lookup_result === 0 || is_null($ip_lookup_result)) : ?>
|
||||
<p>
|
||||
<?php _e('No information found about this IP.', 'geoip-detect')?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<p>
|
||||
<?php printf(__('See %s for more documentation.', 'geoip-detect'), '<a href="http://dev.maxmind.com/geoip/geoip2/web-services/" target="_blank">http://dev.maxmind.com/geoip/geoip2/web-services/</a>');?>
|
||||
</p>
|
||||
<?php require(GEOIP_PLUGIN_DIR . '/views/footer.php'); ?>
|
||||
</div>
|
||||
<script>
|
||||
function geoip_properties_toggle(show, hide) {
|
||||
jQuery('.' + show).show();
|
||||
jQuery('.' + hide).hide();
|
||||
}
|
||||
jQuery('document').ready(function() {
|
||||
jQuery('.all').hide();
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
$options = $currentSource->getParameterHTML();
|
||||
$currentSourceId = $currentSource->getId();
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
<h1><?php _e('GeoIP Detection', 'geoip-detect');?></h1>
|
||||
<p><a href="tools.php?page=<?php echo GEOIP_PLUGIN_BASENAME ?>"><?php _e('Test IP Detection Lookup', 'geoip-detect')?></a></p>
|
||||
<?php if (!empty($message)): ?>
|
||||
<p class="geoip_detect_error">
|
||||
<?php echo $message; ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<p>
|
||||
<?php printf(__('<b>Selected data source:</b> %s', 'geoip-detect'), geoip_detect2_get_current_source_description() ); ?>
|
||||
</p>
|
||||
<p>
|
||||
<?php echo $currentSource->getStatusInformationHTML(); ?>
|
||||
</p>
|
||||
<?php if ($options) : ?>
|
||||
<h2><?php _e('Options for this data source', 'geoip-detect'); ?></h2>
|
||||
<p>
|
||||
<form method="post" action="#">
|
||||
<input type="hidden" name="action" value="options-source" />
|
||||
<?php wp_nonce_field( 'geoip_detect_options-source' ); ?>
|
||||
<p><?php echo $options; ?></p>
|
||||
<p>
|
||||
<input type="submit" class="button button-primary" value="<?php _e('Save', 'geoip-detect'); ?>" />
|
||||
</p>
|
||||
</form>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<br/>
|
||||
|
||||
<br /><br />
|
||||
<form method="post" action="#">
|
||||
<input type="hidden" name="action" value="choose" />
|
||||
<?php wp_nonce_field( 'geoip_detect_choose' ); ?>
|
||||
<h2><?php _e('Choose data source:', 'geoip-detect'); ?></h2>
|
||||
<a href="https://github.com/yellowtree/wp-geoip-detect/wiki/FAQ#which-data-source-should-i-choose"><?php _e('Help', 'geoip-detect'); ?></a>
|
||||
<?php foreach ($sources as $s) : $id = $s->getId();?>
|
||||
<p><label><input type="radio" name="options[source]" value="<?php echo $id ?>" <?php if ($currentSourceId == $id) { echo 'checked="checked"'; } ?> /><?php echo $s->getLabel(); ?></label></p>
|
||||
<span class="detail-box">
|
||||
<?php echo $s->getDescriptionHTML(); ?>
|
||||
</span>
|
||||
<?php endforeach; ?>
|
||||
<br />
|
||||
<input type="submit" class="button button-primary" value="<?php _e('Save', 'geoip-detect'); ?>" />
|
||||
</form>
|
||||
<form method="post" action="#">
|
||||
<input type="hidden" name="action" value="options" />
|
||||
<?php wp_nonce_field( 'geoip_detect_options' ); ?>
|
||||
<h3><?php _e('General Options', 'geoip-detect'); ?></h3>
|
||||
<p>
|
||||
<label><input type="checkbox" name="options[set_css_country]" value="1" <?php if (!empty($wp_options['set_css_country'])) { echo 'checked="checked"'; } ?>> <?php _e('Add a country-specific CSS class to the <body>-Tag.', 'geoip-detect'); ?></label><br />
|
||||
</p>
|
||||
<p>
|
||||
<label><input type="checkbox" name="options[disable_pagecache]" value="1" <?php if (!empty($wp_options['disable_pagecache'])) { echo 'checked="checked"'; } ?>> <?php _e('Disable caching a page that contains a shortcode or API call to geo-dependent functions.', 'geoip-detect'); ?></label><br />
|
||||
<span class="detail-box">
|
||||
<?php _e('At least WP SuperCache, W3TotalCache and ZenCache are supported.', 'geoip-detect'); ?>
|
||||
</span>
|
||||
<?php if (!empty($wp_options['set_css_country']) && !empty($wp_options['disable_pagecache']) && empty($wp_options['ajax_enabled'])): ?>
|
||||
<span class="geoip_detect_error"><?php _e('Warning: As the CSS option above is active, this means that all pages are not cached.', 'geoip-detect'); ?></span>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label><input type="checkbox" name="options[ajax_enabled]" value="1" <?php if (!empty($wp_options['ajax_enabled'])) { echo 'checked="checked"'; } ?>>BETA: <?php _e('Enable AJAX endpoint to get the information for the current IP even on cached pages.', 'geoip-detect'); ?></label>
|
||||
</p>
|
||||
<?php if (in_array($currentSourceId, array('precision', 'ipstack')) && !empty($wp_options['ajax_enabled'])): ?>
|
||||
<span class="geoip_detect_error" style="margin-top: 0;"><?php printf(__('Warning: In theory, other websites could use your API credits over AJAX, this cannot be prevented completely (see <a href="%s" target="_blank">documentation</a> for more infos). You should use a different data source or disable AJAX.', 'geoip-detect'), 'https://github.com/yellowtree/geoip-detect/wiki/JS-API-Documentation'); ?></span>
|
||||
<?php endif; ?>
|
||||
<p style="margin-left: 20px;">
|
||||
<label><input type="checkbox" name="options[ajax_enqueue_js]" value="1" <?php if (!empty($wp_options['ajax_enqueue_js'])) { echo 'checked="checked"'; } ?>>BETA: <?php _e('Add JS to make the access to the AJAX endpoint easier.', 'geoip-detect'); ?></label>
|
||||
<span class="detail-box">
|
||||
<?php _e('You will need to code JS (see <a href="https://github.com/yellowtree/geoip-detect/wiki/API%3A-AJAX">documentation</a>) in order to make this work. Shortcodes are not automatically converted to their AJAX equivalent.', 'geoip-detect'); ?>
|
||||
</span>
|
||||
</p>
|
||||
<p>
|
||||
|
||||
<label><input type="checkbox" name="options[has_reverse_proxy]" value="1" <?php if (!empty($wp_options['has_reverse_proxy'])) { echo 'checked="checked"'; } ?>> <?php _e('The server is behind a reverse proxy', 'geoip-detect')?></label>
|
||||
<a href="options-general.php?page=<?php echo GEOIP_PLUGIN_BASENAME ?>&geoip_detect_part=client-ip">(<?php _e('Client IP debug panel', 'geoip-detect');?>)</a>
|
||||
<span class="detail-box">
|
||||
<?php if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) : ?>
|
||||
<?php printf(__('(With Proxy: %s - Without Proxy: %s - Client IP with current configuration: %s)', 'geoip-detect'), $_SERVER['HTTP_X_FORWARDED_FOR'], $_SERVER['REMOTE_ADDR'], geoip_detect2_get_client_ip()); ?><br />
|
||||
<?php else: ?>
|
||||
<?php echo __("(This doesn't seem to be the case.)", 'geoip-detect'); ?>
|
||||
<?php endif; ?>
|
||||
</span>
|
||||
</p>
|
||||
<p>
|
||||
<label><?php _e('IPs of trusted proxies:', 'geoip-detect'); ?><input type="text" name="options[trusted_proxy_ips]" <?php echo esc_attr($wp_options['trusted_proxy_ips']); ?>" placeholder="1.1.1.1, 1234::1, 2.2.2.2/24" />
|
||||
<span class="detail-box">
|
||||
<?php _e('If specified, only IPs in this list will be treated as proxy.', 'geoip-detect'); ?><br>
|
||||
<?php _e('Make sure to add both IPv4 and IPv6 adresses of the proxy!', 'geoip-detect'); ?>
|
||||
</span>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<label><?php _e('External IP of this server:', 'geoip-detect'); ?> <input type="text" name="options[external_ip]" value="<?php echo esc_attr($wp_options['external_ip']); ?>" placeholder="<?php _e('detect automatically', 'geoip-detect'); ?>" /></label>
|
||||
<span class="detail-box">
|
||||
<?php _e('Current value:', 'geoip-detect'); ?> <?php echo geoip_detect2_get_external_ip_adress(); ?><br />
|
||||
<?php _e('If empty: Try to use an ip service to detect it (Internet connection is necessary). If this is not possible, 0.0.0.0 will be returned.', 'geoip-detect'); ?><br />
|
||||
<?php _e('(This external adress will be used when the request IP adress is not a public IP, e.g. 127.0.0.1)', 'geoip-detect'); ?>
|
||||
</span>
|
||||
</p>
|
||||
|
||||
|
||||
<p>
|
||||
<input type="submit" class="button button-primary" value="<?php _e('Save', 'geoip-detect'); ?>" />
|
||||
</p>
|
||||
</form>
|
||||
<?php if (!$ipv6_supported) : ?>
|
||||
<div class="geoip_detect_error">
|
||||
<h3><?php _e('IPv6 not supported', 'geoip-detect'); ?></h3>
|
||||
<p>
|
||||
<?php _e('Your version of PHP is compiled without IPv6-support, so it is not possible to lookup adresses like "2001:4860:4801:5::91". For more information see <a href="https://php.net/manual/en/function.inet-pton.php">PHP documentation & user comments</a>.', 'geoip-detect'); ?>
|
||||
</p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php require(GEOIP_PLUGIN_DIR . '/views/footer.php'); ?>
|
||||
</div>
|
||||
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
$date_format = get_option('date_format') . ' ' . get_option('time_format')
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h2><?php _e('GeoIP Detection', 'geoip-detect');?></h2>
|
||||
|
||||
<?php if (!empty($message)): ?>
|
||||
<p class="geoip_detect_error">
|
||||
<?php echo $message; ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<p>
|
||||
<?php printf(__('Selected data source: %s', 'geoip-detect'), geoip_detect2_get_current_source_description() ); ?>
|
||||
</p>
|
||||
<?php if ($last_update_db) : ?>
|
||||
<p>
|
||||
<?php printf(__('Database data from: %s', 'geoip-detect'), date_i18n($date_format, $last_update_db) ); ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($options['source'] == 'hostinfo') : ?>
|
||||
<p>
|
||||
You can choose a Maxmind database below.
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php if ($options['source'] == 'auto') : ?>
|
||||
<p>
|
||||
<?php printf(__('Last updated: %s', 'geoip-detect'), $last_update ? date_i18n($date_format, $last_update) : __('Never', 'geoip-detect')); ?>
|
||||
|
||||
<?php if (GEOIP_DETECT_UPDATER_INCLUDED && (!defined('GEOIP_DETECT_AUTO_UPDATE_DEACTIVATED') || !GEOIP_DETECT_AUTO_UPDATE_DEACTIVATED)) : ?>
|
||||
<br />
|
||||
<?php printf(__('Next update: %s', 'geoip-detect'), $next_cron_update ? date_i18n($date_format, $next_cron_update) : __('Never', 'geoip-detect')); ?><br />
|
||||
<em><?php _e('(The file is updated automatically once a month.)', 'geoip-detect'); ?></em>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
<?php if (GEOIP_DETECT_UPDATER_INCLUDED) : ?>
|
||||
<form method="post" action="#">
|
||||
<input type="hidden" name="action" value="update" />
|
||||
<input type="submit" class="button button-primary" value="<?php _e('Update now'); ?>" />
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
|
||||
<br/>
|
||||
<h3>Test GeoIP Lookup manually</h3>
|
||||
<form method="post" action="#">
|
||||
<input type="hidden" name="action" value="lookup" />
|
||||
<input type="text" placeholder="Enter an IP (v4 or v6)" name="ip" value="<?php echo isset($_REQUEST['ip']) ? esc_attr($_REQUEST['ip']) : esc_attr(geoip_detect2_get_client_ip()); ?>" />
|
||||
<input type="submit" class="button button-secondary" value="<?php _e('Lookup', 'geoip-detect'); ?>" />
|
||||
</form>
|
||||
<?php if ($ip_lookup_result !== false) :
|
||||
if (is_object($ip_lookup_result)) : $record = $ip_lookup_result; ?>
|
||||
<p>
|
||||
<?php printf(__('The function %s returns an object:', 'geoip-detect'), "<code>\$record = geoip_detect2_get_info_from_ip('" . esc_html($_POST['ip']) . "')</code>"); ?>
|
||||
</p>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<th><?php _e('Key', 'geoip-detect'); ?></th>
|
||||
<th><?php _e('Value', 'geoip-detect'); ?></th>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td><code>$record->city->name</code></td>
|
||||
<td><?php echo esc_html($record->city->name);?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>$record->mostSpecificSubdivision->isoCode</code></td>
|
||||
<td><?php echo esc_html($record->mostSpecificSubdivision->name);?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>$record->mostSpecificSubdivision->name</code></td>
|
||||
<td><?php echo esc_html($record->mostSpecificSubdivision->name);?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>$record->country->isoCode</code></td>
|
||||
<td><?php echo esc_html($record->country->isoCode);?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>$record->country->name</code></td>
|
||||
<td><?php echo esc_html($record->country->name);?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>$record->location->latitude</code></td>
|
||||
<td><?php echo esc_html($record->location->latitude);?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>$record->location->longitude</code></td>
|
||||
<td><?php echo esc_html($record->location->longitude);?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>$record->continent->code</code></td>
|
||||
<td><?php echo esc_html($record->continent->code);?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><code>$record->location->timeZone</code></td>
|
||||
<td><?php echo esc_html($record->location->timeZone);?></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
<?php elseif ($ip_lookup_result === 0 || is_null($ip_lookup_result)) : ?>
|
||||
<p>
|
||||
<?php _e('No information found about this IP.', 'geoip-detect')?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<p>
|
||||
<?php printf(__('See %s for more documentation.', 'geoip-detect'), '<a href="http://dev.maxmind.com/geoip/geoip2/web-services/" target="_blank">http://dev.maxmind.com/geoip/geoip2/web-services/</a>');?>
|
||||
</p>
|
||||
|
||||
|
||||
<br /><br />
|
||||
<h3>Options</h3>
|
||||
<form method="post" action="#">
|
||||
<input type="hidden" name="action" value="options" />
|
||||
|
||||
<p>
|
||||
<input type="checkbox" name="options[set_css_country]" value="1" <?php if ($options['set_css_country']) { echo 'checked="checked"'; } ?>> <?php _e('Add a country-specific CSS class to the <body>-Tag.', 'geoip-detect'); ?><br />
|
||||
</p>
|
||||
<p>
|
||||
<input type="checkbox" name="options[has_reverse_proxy]" value="1" <?php if ($options['has_reverse_proxy']) { echo 'checked="checked"'; } ?>> The server is behind a reverse proxy<em>
|
||||
<span class="detail-box">
|
||||
<?php if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) : ?>
|
||||
<?php printf(__('(With Proxy: %s - Without Proxy: %s)', 'geoip-detect'), $_SERVER['HTTP_X_FORWARDED_FOR'], $_SERVER['REMOTE_ADDR']); ?><br />
|
||||
<?php else: ?>
|
||||
<?php echo "(This doesn't seem to be the case.)"; ?>
|
||||
<?php endif; ?>
|
||||
</em>
|
||||
</span>
|
||||
</p>
|
||||
|
||||
<h4>Data source: </h4>
|
||||
<?php if (GEOIP_DETECT_UPDATER_INCLUDED) : ?>
|
||||
<p><input type="radio" name="options[source]" value="auto" <?php if ($options['source'] == 'auto') { echo 'checked="checked"'; } ?> />Automatic download & update of Maxmind GeoIP Lite City</p>
|
||||
<span class="detail-box">
|
||||
(License: Creative Commons Attribution-ShareAlike 3.0 Unported. See <a href="https://github.com/yellowtree/wp-geoip-detect/wiki/FAQ#the-maxmind-lite-databases-are-licensed-creative-commons-sharealike-attribution-when-do-i-need-to-give-attribution" target="_blank">Licensing FAQ</a> for more details.)
|
||||
</span>
|
||||
<?php else : ?>
|
||||
<p><input type="radio" name="options[source]" value="auto" disabled="disabled"/>Automatic download & update <em>(only available in Github version)</em></p>
|
||||
<?php endif; ?>
|
||||
<p><input type="radio" name="options[source]" value="manual" <?php if ($options['source'] == 'manual') { echo 'checked="checked"'; } ?> />Manual download & update of a Maxmind City or Country database<br />
|
||||
<span class="detail-box">
|
||||
Filepath to mmdb-file: <input type="text" size="40" name="options[manual_file]" value="<?php echo esc_attr($options['manual_file']); ?>" /><br />
|
||||
<a href="http://dev.maxmind.com/geoip/geoip2/geolite2/" target="_blank">Free version</a> - <a href="https://www.maxmind.com/en/geoip2-country-database" target="_blank">Commercial Version</a>
|
||||
</span>
|
||||
<p><input type="radio" name="options[source]" value="hostinfo" <?php if ($options['source'] == 'hostinfo') { echo 'checked="checked"'; } ?> />HostIp.info<br />
|
||||
<span class="detail-box">
|
||||
(only English names, only country, country ID and city are populated)
|
||||
</span>
|
||||
</p>
|
||||
<p>
|
||||
<input type="submit" class="button button-primary" value="<?php _e('Save', 'geoip-detect'); ?>" />
|
||||
</p>
|
||||
</form>
|
||||
<p>
|
||||
<br />
|
||||
<small><em>This product includes GeoLite2 data created by MaxMind, available from <a href="http://www.maxmind.com/">http://www.maxmind.com</a>.</em></small>
|
||||
</p>
|
||||
</div>
|
||||
<style>
|
||||
.geoip_detect_error {
|
||||
background-color: rgb(255, 255, 255);
|
||||
border-left: rgb(255, 0, 0) solid 4px;
|
||||
box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.1);
|
||||
display: inline-block;
|
||||
font-size: 14px;
|
||||
line-height: 19px;
|
||||
margin-bottom: 0;
|
||||
margin-left: 2px;
|
||||
margin-right: 20px;
|
||||
margin-top: 25px;
|
||||
padding-bottom: 11px;
|
||||
padding-left: 15px;
|
||||
padding-right: 15px;
|
||||
padding-top: 11px;
|
||||
text-align: left;
|
||||
}
|
||||
.detail-box {
|
||||
display: block;
|
||||
margin-left: 50px;
|
||||
color: #777;
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user