v1.0.0
This commit is contained in:
commit
1ef08bd731
27 changed files with 4854 additions and 0 deletions
674
LICENSE
Normal file
674
LICENSE
Normal file
|
|
@ -0,0 +1,674 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://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 <https://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
|
||||
<https://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
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
153
admin/class-fontdelbosc-transit-admin.php
Normal file
153
admin/class-fontdelbosc-transit-admin.php
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
<?php
|
||||
/**
|
||||
* Admin settings page.
|
||||
*
|
||||
* @package Fontdelbosc_Transit
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Admin UI.
|
||||
*/
|
||||
class Fontdelbosc_Transit_Admin {
|
||||
|
||||
/**
|
||||
* Hook the admin pieces.
|
||||
*/
|
||||
public static function init(): void {
|
||||
add_action( 'admin_menu', array( __CLASS__, 'add_menu' ) );
|
||||
add_action( 'admin_init', array( __CLASS__, 'register_settings' ) );
|
||||
add_action( 'admin_post_fontdelbosc_transit_flush', array( __CLASS__, 'handle_flush' ) );
|
||||
add_action( 'admin_notices', array( __CLASS__, 'notices' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the settings page under Settings.
|
||||
*/
|
||||
public static function add_menu(): void {
|
||||
add_options_page(
|
||||
__( 'Font del Bosc Trànsit', 'fontdelbosc-transit' ),
|
||||
__( 'Font del Bosc Trànsit', 'fontdelbosc-transit' ),
|
||||
'manage_options',
|
||||
'fontdelbosc-transit',
|
||||
array( __CLASS__, 'render_page' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the options entry.
|
||||
*/
|
||||
public static function register_settings(): void {
|
||||
register_setting(
|
||||
'fontdelbosc_transit',
|
||||
Fontdelbosc_Transit_Plugin::option_name(),
|
||||
array(
|
||||
'type' => 'array',
|
||||
'sanitize_callback' => array( __CLASS__, 'sanitize' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize the submitted options.
|
||||
*
|
||||
* @param mixed $input Raw input.
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function sanitize( $input ): array {
|
||||
$current = Fontdelbosc_Transit_Plugin::get_options();
|
||||
$input = is_array( $input ) ? $input : array();
|
||||
|
||||
$clean = array(
|
||||
'incident_cache_ttl' => self::clamp( Fontdelbosc_Transit_Payload::int( $input['incident_cache_ttl'] ?? null ) ?? 300, 60, 86400 ),
|
||||
'zbe_cache_ttl' => self::clamp( Fontdelbosc_Transit_Payload::int( $input['zbe_cache_ttl'] ?? null ) ?? 86400, 3600, 604800 ),
|
||||
'default_view' => 'all' === Fontdelbosc_Transit_Payload::str( $input['default_view'] ?? null ) ? 'all' : 'c15',
|
||||
'max_incidents' => self::clamp( Fontdelbosc_Transit_Payload::int( $input['max_incidents'] ?? null ) ?? 20, 1, 50 ),
|
||||
'show_zbe_2026_notice' => empty( $input['show_zbe_2026_notice'] ) ? false : true,
|
||||
'delete_data_on_uninstall' => empty( $input['delete_data_on_uninstall'] ) ? false : true,
|
||||
);
|
||||
|
||||
$zones = array();
|
||||
if ( isset( $input['zbe_municipalities'] ) && is_array( $input['zbe_municipalities'] ) ) {
|
||||
foreach ( $input['zbe_municipalities'] as $slug ) {
|
||||
$zones[] = Fontdelbosc_Transit_Api_Zbe::sanitize_slug( Fontdelbosc_Transit_Payload::str( $slug ) ?? '' );
|
||||
}
|
||||
}
|
||||
|
||||
$clean['zbe_municipalities'] = array_values( array_unique( array_filter( $zones ) ) );
|
||||
|
||||
if ( array() === $clean['zbe_municipalities'] && isset( $input['zbe_municipalities'] ) ) {
|
||||
$clean['zbe_municipalities'] = (array) $current['zbe_municipalities'];
|
||||
}
|
||||
|
||||
return $clean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clamp an integer between bounds.
|
||||
*
|
||||
* @param int $value Raw value.
|
||||
* @param int $min Minimum.
|
||||
* @param int $max Maximum.
|
||||
* @return int
|
||||
*/
|
||||
private static function clamp( int $value, int $min, int $max ): int {
|
||||
return max( $min, min( $max, $value ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the cache flush action.
|
||||
*/
|
||||
public static function handle_flush(): void {
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_die( esc_html__( 'Insufficient permissions.', 'fontdelbosc-transit' ) );
|
||||
}
|
||||
|
||||
check_admin_referer( 'fontdelbosc_transit_flush' );
|
||||
|
||||
Fontdelbosc_Transit_Data_Manager::flush();
|
||||
|
||||
wp_safe_redirect(
|
||||
add_query_arg(
|
||||
'fontdelbosc_transit_flushed',
|
||||
'1',
|
||||
admin_url( 'options-general.php?page=fontdelbosc-transit' )
|
||||
)
|
||||
);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin notices: activation 2026 info and flush confirmation.
|
||||
*/
|
||||
public static function notices(): void {
|
||||
if ( get_transient( 'fontdelbosc_transit_2026_notice' ) ) {
|
||||
delete_transient( 'fontdelbosc_transit_2026_notice' );
|
||||
echo '<div class="notice notice-info is-dismissible"><p>';
|
||||
echo '<strong>' . esc_html__( 'Font del Bosc — Trànsit', 'fontdelbosc-transit' ) . ':</strong> ';
|
||||
echo esc_html__( 'From 1 January 2026, label B vehicles are banned in Catalan ZBEs when high-pollution protocols are activated.', 'fontdelbosc-transit' );
|
||||
echo '</p></div>';
|
||||
}
|
||||
|
||||
if ( isset( $_GET['fontdelbosc_transit_flushed'] ) && '1' === $_GET['fontdelbosc_transit_flushed'] ) {
|
||||
echo '<div class="notice notice-success is-dismissible"><p>' . esc_html__( 'Cache flushed.', 'fontdelbosc-transit' ) . '</p></div>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the settings page.
|
||||
*/
|
||||
public static function render_page(): void {
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_die( esc_html__( 'Insufficient permissions.', 'fontdelbosc-transit' ) );
|
||||
}
|
||||
|
||||
$view = FONTDELBOSC_TRANSIT_DIR . 'admin/views/settings-page.php';
|
||||
|
||||
if ( file_exists( $view ) ) {
|
||||
include $view;
|
||||
}
|
||||
}
|
||||
}
|
||||
182
admin/views/settings-page.php
Normal file
182
admin/views/settings-page.php
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
<?php
|
||||
/**
|
||||
* Settings page view.
|
||||
*
|
||||
* @package Fontdelbosc_Transit
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Settings-page variables.
|
||||
*
|
||||
* @var array<string, mixed> $fontdelbosc_options
|
||||
*/
|
||||
$fontdelbosc_options = Fontdelbosc_Transit_Plugin::get_options();
|
||||
$fontdelbosc_status = get_option( 'fontdelbosc_transit_status', array() );
|
||||
$fontdelbosc_index = Fontdelbosc_Transit_Data_Manager::get_zbe_index();
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1><?php esc_html_e( 'Font del Bosc Trànsit', 'fontdelbosc-transit' ); ?></h1>
|
||||
|
||||
<form method="post" action="options.php">
|
||||
<?php settings_fields( 'fontdelbosc_transit' ); ?>
|
||||
|
||||
<h2><?php esc_html_e( 'Incidents', 'fontdelbosc-transit' ); ?></h2>
|
||||
<table class="form-table" role="presentation">
|
||||
<tr>
|
||||
<th scope="row"><label for="fontdelbosc-transit-incident-ttl"><?php esc_html_e( 'Cache lifetime (seconds)', 'fontdelbosc-transit' ); ?></label></th>
|
||||
<td>
|
||||
<input type="number" id="fontdelbosc-transit-incident-ttl" name="<?php echo esc_attr( Fontdelbosc_Transit_Plugin::option_name() ); ?>[incident_cache_ttl]" value="<?php echo esc_attr( (string) $fontdelbosc_options['incident_cache_ttl'] ); ?>" min="60" max="86400" step="60" class="small-text" />
|
||||
<p class="description"><?php esc_html_e( 'How long incident data is cached. Default 300 (5 minutes); the source updates in near real time.', 'fontdelbosc-transit' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><label for="fontdelbosc-transit-max"><?php esc_html_e( 'Maximum incidents shown', 'fontdelbosc-transit' ); ?></label></th>
|
||||
<td>
|
||||
<input type="number" id="fontdelbosc-transit-max" name="<?php echo esc_attr( Fontdelbosc_Transit_Plugin::option_name() ); ?>[max_incidents]" value="<?php echo esc_attr( (string) $fontdelbosc_options['max_incidents'] ); ?>" min="1" max="50" class="small-text" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'Default view', 'fontdelbosc-transit' ); ?></th>
|
||||
<td>
|
||||
<label><input type="radio" name="<?php echo esc_attr( Fontdelbosc_Transit_Plugin::option_name() ); ?>[default_view]" value="c15" <?php checked( $fontdelbosc_options['default_view'], 'c15' ); ?> /> <?php esc_html_e( 'Traffic on C-15', 'fontdelbosc-transit' ); ?></label><br />
|
||||
<label><input type="radio" name="<?php echo esc_attr( Fontdelbosc_Transit_Plugin::option_name() ); ?>[default_view]" value="all" <?php checked( $fontdelbosc_options['default_view'], 'all' ); ?> /> <?php esc_html_e( 'All Catalunya traffic', 'fontdelbosc-transit' ); ?></label>
|
||||
<p class="description"><?php esc_html_e( 'What [fontdelbosc_transit] renders when called without a view attribute.', 'fontdelbosc-transit' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2><?php esc_html_e( 'Low Emission Zones (ZBE)', 'fontdelbosc-transit' ); ?></h2>
|
||||
<table class="form-table" role="presentation">
|
||||
<tr>
|
||||
<th scope="row"><label for="fontdelbosc-transit-zbe-ttl"><?php esc_html_e( 'Cache lifetime (seconds)', 'fontdelbosc-transit' ); ?></label></th>
|
||||
<td>
|
||||
<input type="number" id="fontdelbosc-transit-zbe-ttl" name="<?php echo esc_attr( Fontdelbosc_Transit_Plugin::option_name() ); ?>[zbe_cache_ttl]" value="<?php echo esc_attr( (string) $fontdelbosc_options['zbe_cache_ttl'] ); ?>" min="3600" max="604800" step="3600" class="small-text" />
|
||||
<p class="description"><?php esc_html_e( 'ZBE rules change rarely; 86400 (24 hours) is a sensible default.', 'fontdelbosc-transit' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'Zones shown', 'fontdelbosc-transit' ); ?></th>
|
||||
<td>
|
||||
<fieldset>
|
||||
<?php
|
||||
$fontdelbosc_zones = (array) $fontdelbosc_options['zbe_municipalities'];
|
||||
$fontdelbosc_index_list = is_array( $fontdelbosc_index ) ? $fontdelbosc_index : Fontdelbosc_Transit_Api_Zbe::DEFAULT_CATALAN_ZONES;
|
||||
|
||||
foreach ( $fontdelbosc_index_list as $fontdelbosc_slug ) :
|
||||
$fontdelbosc_id = 'fontdelbosc-transit-zone-' . esc_attr( $fontdelbosc_slug );
|
||||
?>
|
||||
<label for="<?php echo esc_attr( $fontdelbosc_id ); ?>">
|
||||
<input type="checkbox" id="<?php echo esc_attr( $fontdelbosc_id ); ?>" name="<?php echo esc_attr( Fontdelbosc_Transit_Plugin::option_name() ); ?>[zbe_municipalities][]" value="<?php echo esc_attr( $fontdelbosc_slug ); ?>" <?php checked( in_array( $fontdelbosc_slug, $fontdelbosc_zones, true ) ); ?> />
|
||||
<?php echo esc_html( preg_replace( '/(?<!^)[A-Z]/', ' $0', $fontdelbosc_slug ) ?? $fontdelbosc_slug ); ?>
|
||||
</label><br />
|
||||
<?php endforeach; ?>
|
||||
<p class="description"><?php esc_html_e( 'Catalan zones are pre-selected. When the DGT publishes new zones they appear here automatically.', 'fontdelbosc-transit' ); ?></p>
|
||||
</fieldset>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( '2026 notice', 'fontdelbosc-transit' ); ?></th>
|
||||
<td>
|
||||
<label for="fontdelbosc-transit-2026"><input type="checkbox" id="fontdelbosc-transit-2026" name="<?php echo esc_attr( Fontdelbosc_Transit_Plugin::option_name() ); ?>[show_zbe_2026_notice]" value="1" <?php checked( $fontdelbosc_options['show_zbe_2026_notice'] ); ?> /> <?php esc_html_e( 'Show the etiqueta B 2026 restriction notice in the ZBE view.', 'fontdelbosc-transit' ); ?></label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'Data on uninstall', 'fontdelbosc-transit' ); ?></th>
|
||||
<td>
|
||||
<label for="fontdelbosc-transit-delete"><input type="checkbox" id="fontdelbosc-transit-delete" name="<?php echo esc_attr( Fontdelbosc_Transit_Plugin::option_name() ); ?>[delete_data_on_uninstall]" value="1" <?php checked( $fontdelbosc_options['delete_data_on_uninstall'] ); ?> /> <?php esc_html_e( 'Delete options and cached data when the plugin is uninstalled.', 'fontdelbosc-transit' ); ?></label>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<?php submit_button(); ?>
|
||||
</form>
|
||||
|
||||
<h2><?php esc_html_e( 'Status', 'fontdelbosc-transit' ); ?></h2>
|
||||
<table class="form-table" role="presentation">
|
||||
<?php if ( isset( $fontdelbosc_status['incidents'] ) ) : ?>
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'Incidents', 'fontdelbosc-transit' ); ?></th>
|
||||
<td>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: 1: date of the last fetch, 2: source, 3: incident count. */
|
||||
esc_html__( 'Last fetch: %1$s (%2$s source, %3$s incidents).', 'fontdelbosc-transit' ),
|
||||
esc_html( Fontdelbosc_Transit_Maps::format_time( gmdate( 'Y-m-d H:i:s', (int) $fontdelbosc_status['incidents']['last_fetch'] ) . ' UTC' ) ),
|
||||
esc_html( (string) $fontdelbosc_status['incidents']['source'] ),
|
||||
esc_html( (string) $fontdelbosc_status['incidents']['count'] )
|
||||
);
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
<?php if ( isset( $fontdelbosc_status['zbe'] ) ) : ?>
|
||||
<tr>
|
||||
<th scope="row"><?php esc_html_e( 'Low Emission Zones (ZBE)', 'fontdelbosc-transit' ); ?></th>
|
||||
<td>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: 1: date of the last fetch, 2: zone count. */
|
||||
esc_html__( 'Last fetch: %1$s (%2$s zones loaded).', 'fontdelbosc-transit' ),
|
||||
esc_html( Fontdelbosc_Transit_Maps::format_time( gmdate( 'Y-m-d H:i:s', (int) $fontdelbosc_status['zbe']['last_fetch'] ) . ' UTC' ) ),
|
||||
esc_html( (string) $fontdelbosc_status['zbe']['zones'] )
|
||||
);
|
||||
?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
</table>
|
||||
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>">
|
||||
<input type="hidden" name="action" value="fontdelbosc_transit_flush" />
|
||||
<?php wp_nonce_field( 'fontdelbosc_transit_flush' ); ?>
|
||||
<?php submit_button( __( 'Flush cache', 'fontdelbosc-transit' ), 'secondary', 'submit', false ); ?>
|
||||
</form>
|
||||
|
||||
<h2><?php esc_html_e( 'Documentation', 'fontdelbosc-transit' ); ?></h2>
|
||||
|
||||
<h3><?php esc_html_e( 'Shortcode', 'fontdelbosc-transit' ); ?></h3>
|
||||
<table class="widefat striped" role="presentation">
|
||||
<thead>
|
||||
<tr><th><?php esc_html_e( 'Attribute', 'fontdelbosc-transit' ); ?></th><th><?php esc_html_e( 'Default', 'fontdelbosc-transit' ); ?></th><th><?php esc_html_e( 'Values', 'fontdelbosc-transit' ); ?></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr><td><code>view</code></td><td><code>c15</code></td><td><code>c15</code>, <code>all</code>, <code>zbe</code></td></tr>
|
||||
<tr><td><code>max</code></td><td><?php esc_html_e( 'Setting above', 'fontdelbosc-transit' ); ?></td><td>1–50</td></tr>
|
||||
<tr><td><code>comarca</code></td><td>—</td><td><code>altpenedes</code>, <code>anoia</code>, <code>baixllobregat</code>, <code>garraf</code> — <?php esc_html_e( 'comma-separated list allowed', 'fontdelbosc-transit' ); ?></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>
|
||||
<code>[fontdelbosc_transit]</code> ·
|
||||
<code>[fontdelbosc_transit view="all" max="10"]</code> ·
|
||||
<code>[fontdelbosc_transit view="all" comarca="anoia"]</code> ·
|
||||
<code>[fontdelbosc_transit view="zbe"]</code>
|
||||
</p>
|
||||
|
||||
<h3><?php esc_html_e( 'Widget', 'fontdelbosc-transit' ); ?></h3>
|
||||
<p><?php esc_html_e( 'A sidebar widget with an editable title shows the five latest C-15 incidents or a summary of the selected Low Emission Zones.', 'fontdelbosc-transit' ); ?></p>
|
||||
|
||||
<h3><?php esc_html_e( 'Data sources', 'fontdelbosc-transit' ); ?></h3>
|
||||
<ul>
|
||||
<li><?php esc_html_e( 'Incidents: Servei Català de Trànsit via the DGT national access point (DATEX2), enriched with the SCT public RSS feed, which provides the incident text and links.', 'fontdelbosc-transit' ); ?></li>
|
||||
<li><?php esc_html_e( 'Low Emission Zones: DGT national access point (DATEX2 v3), with the zone list taken from the live index.', 'fontdelbosc-transit' ); ?></li>
|
||||
<li><?php esc_html_e( 'Attribution is mandatory and cannot be disabled: Incidències — Servei Català de Trànsit (SCT) / CIVICAT; ZBE — DGT / Punt d\'Accés Nacional.', 'fontdelbosc-transit' ); ?></li>
|
||||
</ul>
|
||||
|
||||
<h3><?php esc_html_e( 'Caching', 'fontdelbosc-transit' ); ?></h3>
|
||||
<p><?php esc_html_e( 'Incident data is cached for the lifetime set above (5 minutes by default) and zone rules for 24 hours. When a source fails, the last cached data is served instead (stale-while-error) and the footer shows the age of the data using the source\'s own publication timestamp.', 'fontdelbosc-transit' ); ?></p>
|
||||
<p><?php esc_html_e( 'Use the Flush cache button above to force a fresh fetch of everything.', 'fontdelbosc-transit' ); ?></p>
|
||||
|
||||
<h3><?php esc_html_e( 'Data, privacy and uninstall', 'fontdelbosc-transit' ); ?></h3>
|
||||
<p><?php esc_html_e( 'The plugin stores no personal data and no secrets: only the settings entry, a small fetch-status entry, and transients holding the cached public data. No API keys are needed.', 'fontdelbosc-transit' ); ?></p>
|
||||
<p><?php esc_html_e( 'By default, uninstalling keeps the stored data. With "Delete options and cached data when the plugin is uninstalled" enabled, uninstalling removes the settings, the status entry and every cached transient — nothing is left behind.', 'fontdelbosc-transit' ); ?></p>
|
||||
|
||||
<h3><?php esc_html_e( 'Security', 'fontdelbosc-transit' ); ?></h3>
|
||||
<p><?php esc_html_e( 'No user input reaches the external endpoints: all URLs are hardcoded constants. The only state-changing admin action requires the manage_options capability and a nonce. All output is escaped, and the XML responses are parsed with external entity loading disabled.', 'fontdelbosc-transit' ); ?></p>
|
||||
|
||||
<h3><?php esc_html_e( 'Compatibility', 'fontdelbosc-transit' ); ?></h3>
|
||||
<p><?php esc_html_e( 'WordPress 6.4 – 7.1 and PHP 8.2 – 8.5, single site (Multisite is not supported).', 'fontdelbosc-transit' ); ?></p>
|
||||
|
||||
<h3><?php esc_html_e( 'The 2026 etiqueta B rule', 'fontdelbosc-transit' ); ?></h3>
|
||||
<p><?php esc_html_e( 'From 1 January 2026, label B vehicles are banned in Catalan ZBEs when high-pollution protocols are activated. The persistent notice in the ZBE view can be disabled with the toggle above.', 'fontdelbosc-transit' ); ?></p>
|
||||
</div>
|
||||
36
changelog.txt
Normal file
36
changelog.txt
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
== Changelog ==
|
||||
|
||||
= 1.0.0 =
|
||||
|
||||
_Release date: 2026-10-12_
|
||||
|
||||
**Highlights**
|
||||
|
||||
* Traffic incidents for the C-15 corridor and all Catalunya, plus the 19 Catalan Low Emission Zones, for Font del Bosc residents. No API keys.
|
||||
|
||||
**Added**
|
||||
|
||||
* Shortcode `[fontdelbosc_transit]` with `view` (c15, all, zbe), `max` and `comarca` attributes, rendered as a card grid with C-15 incidents highlighted.
|
||||
* Comarca filter (`altpenedes`, `anoia`, `baixllobregat`, `garraf`, single value or comma-separated list) resolved from the incident towns.
|
||||
* SCT DATEX2 client (structure, coordinates, types) enriched with the SCT RSS feed text, merged by incident reference; RSS also serves as full fallback.
|
||||
* DGT NAP ZBE client: live zone index (HTML directory) with the 19 Catalan zones pre-selected; new zones appear in the admin automatically.
|
||||
* ZBE cards: restricted vehicle labels, operating hours, link to the municipal regulations.
|
||||
* Persistent January 2026 etiqueta B restriction notice (frontend ZBE view and activation admin notice).
|
||||
* Sidebar widget: five latest C-15 incidents or a ZBE summary.
|
||||
* Transient caching (5 minutes incidents, 24 hours ZBE) with stale-while-error fallback and source timestamps.
|
||||
* Admin settings page: incidents, zones, status with cache flush, and documentation sections.
|
||||
* Translations: Spanish (es_ES) and Catalan (ca).
|
||||
|
||||
**Security**
|
||||
|
||||
* Clean-context pre-deploy audit with no critical findings; capability check and nonce on the only state-changing admin action; XML parsed with entity loading disabled and internal error handling; all output escaped.
|
||||
|
||||
**Compatibility**
|
||||
|
||||
* WordPress: 6.4 - 7.1
|
||||
* PHP: 8.2 - 8.5
|
||||
|
||||
**Tests**
|
||||
|
||||
* PHP Coding Standards: 3.13.6
|
||||
* WordPress Coding Standards: 3.4.1
|
||||
41
fontdelbosc-transit.php
Normal file
41
fontdelbosc-transit.php
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
/**
|
||||
* Plugin Name: Font del Bosc — Trànsit
|
||||
* Plugin URI: https://git.robotstxt.es/ROBOTSTXT/fontdelbosc-transit
|
||||
* Description: Traffic incidents (C-15 and all Catalunya) and Low Emission Zones for Font del Bosc residents.
|
||||
* Version: 1.0.0
|
||||
* Requires at least: 6.4
|
||||
* Requires PHP: 8.2
|
||||
* Author: ROBOTSTXT
|
||||
* Author URI: https://www.robotstxt.es
|
||||
* License: GPL-3.0-or-later
|
||||
* License URI: https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
* Text Domain: fontdelbosc-transit
|
||||
* Domain Path: /languages
|
||||
*
|
||||
* @package Fontdelbosc_Transit
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
define( 'FONTDELBOSC_TRANSIT_VERSION', '1.0.0' );
|
||||
define( 'FONTDELBOSC_TRANSIT_DIR', plugin_dir_path( __FILE__ ) );
|
||||
|
||||
require_once FONTDELBOSC_TRANSIT_DIR . 'includes/class-fontdelbosc-transit-payload.php';
|
||||
require_once FONTDELBOSC_TRANSIT_DIR . 'includes/class-fontdelbosc-transit-api-sct.php';
|
||||
require_once FONTDELBOSC_TRANSIT_DIR . 'includes/class-fontdelbosc-transit-api-zbe.php';
|
||||
require_once FONTDELBOSC_TRANSIT_DIR . 'includes/class-fontdelbosc-transit-maps.php';
|
||||
require_once FONTDELBOSC_TRANSIT_DIR . 'includes/class-fontdelbosc-transit-comarques.php';
|
||||
require_once FONTDELBOSC_TRANSIT_DIR . 'includes/class-fontdelbosc-transit-data-manager.php';
|
||||
require_once FONTDELBOSC_TRANSIT_DIR . 'includes/class-fontdelbosc-transit-shortcode.php';
|
||||
require_once FONTDELBOSC_TRANSIT_DIR . 'includes/class-fontdelbosc-transit-widget.php';
|
||||
require_once FONTDELBOSC_TRANSIT_DIR . 'includes/class-fontdelbosc-transit-plugin.php';
|
||||
|
||||
Fontdelbosc_Transit_Plugin::init();
|
||||
|
||||
register_activation_hook(
|
||||
__FILE__,
|
||||
static function (): void {
|
||||
set_transient( 'fontdelbosc_transit_2026_notice', 1, DAY_IN_SECONDS );
|
||||
}
|
||||
);
|
||||
458
includes/class-fontdelbosc-transit-api-sct.php
Normal file
458
includes/class-fontdelbosc-transit-api-sct.php
Normal file
|
|
@ -0,0 +1,458 @@
|
|||
<?php
|
||||
/**
|
||||
* SCT incident fetcher and parser: DATEX2 primary, RSS enricher/fallback.
|
||||
*
|
||||
* @package Fontdelbosc_Transit
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Fetches and parses SCT incidents.
|
||||
*/
|
||||
class Fontdelbosc_Transit_Api_Sct {
|
||||
|
||||
public const DATEX2_URL = 'https://infocar.dgt.es/datex2/sct/SituationPublication/all/content.xml';
|
||||
public const RSS_URL = 'https://www.gencat.cat/transit/opendata/incidenciesRSS.xml';
|
||||
|
||||
private const NS = 'http://datex2.eu/schema/1_0/1_0';
|
||||
|
||||
/**
|
||||
* Fetch and parse incidents: DATEX2 for structure, RSS for text.
|
||||
*
|
||||
* @return array{incidents: array<int, array<string, mixed>>, source: string, publication_time: string}|null
|
||||
*/
|
||||
public static function get_incidents(): ?array {
|
||||
$datex2 = self::fetch_datex2();
|
||||
$rss = self::fetch_rss();
|
||||
|
||||
if ( null === $datex2 ) {
|
||||
if ( null === $rss ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return array(
|
||||
'incidents' => array_values( $rss['items'] ),
|
||||
'source' => 'rss',
|
||||
'publication_time' => $rss['publication_time'],
|
||||
);
|
||||
}
|
||||
|
||||
$by_reference = array();
|
||||
|
||||
if ( null !== $rss ) {
|
||||
foreach ( $rss['items'] as $item ) {
|
||||
$by_reference[ Fontdelbosc_Transit_Payload::str( $item['reference'] ?? null ) ?? '' ] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $datex2['incidents'] as &$incident ) {
|
||||
$match = $by_reference[ Fontdelbosc_Transit_Payload::str( $incident['reference'] ?? null ) ?? '' ] ?? null;
|
||||
if ( null !== $match ) {
|
||||
$incident['title'] = $match['title'];
|
||||
$incident['description'] = $match['description'];
|
||||
$incident['km'] = $match['km'];
|
||||
$incident['link'] = $match['link'];
|
||||
}
|
||||
}
|
||||
unset( $incident );
|
||||
|
||||
return array(
|
||||
'incidents' => array_values( $datex2['incidents'] ),
|
||||
'source' => 'datex2',
|
||||
'publication_time' => $datex2['publication_time'],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch and parse the DATEX2 SituationPublication.
|
||||
*
|
||||
* @return array{incidents: array<int, array<string, mixed>>, publication_time: string}|null
|
||||
*/
|
||||
private static function fetch_datex2(): ?array {
|
||||
$body = self::http_get( self::DATEX2_URL );
|
||||
if ( null === $body ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$xml = self::parse_xml( $body );
|
||||
if ( null === $xml ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- DATEX2 XML tag name.
|
||||
$payload = $xml->payloadPublication;
|
||||
if ( null === $payload ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$incidents = array();
|
||||
$publication_time = '';
|
||||
|
||||
foreach ( $payload->children( self::NS ) as $child ) {
|
||||
if ( 'situation' !== $child->getName() ) {
|
||||
if ( 'publicationTime' === $child->getName() ) {
|
||||
$publication_time = (string) $child;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ( $child->children( self::NS ) as $record ) {
|
||||
if ( 'situationRecord' !== $record->getName() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$incident = self::parse_record( $record );
|
||||
if ( null !== $incident ) {
|
||||
$incidents[] = $incident;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'incidents' => $incidents,
|
||||
'publication_time' => $publication_time,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse one DATEX2 situationRecord into a normalized incident.
|
||||
*
|
||||
* @param SimpleXMLElement $record Situation record element.
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
private static function parse_record( SimpleXMLElement $record ): ?array {
|
||||
$type = self::type_of( $record );
|
||||
$attrs = $record->attributes();
|
||||
|
||||
$incident = array(
|
||||
'id' => isset( $attrs['id'] ) ? (string) $attrs['id'] : '',
|
||||
'reference' => self::child_value( $record, 'situationRecordCreationReference' ),
|
||||
'type' => $type,
|
||||
'status' => '',
|
||||
'start_time' => '',
|
||||
'end_time' => '',
|
||||
'road_name' => '',
|
||||
'town' => '',
|
||||
'direction' => '',
|
||||
'lat' => null,
|
||||
'lon' => null,
|
||||
'impact' => '',
|
||||
'title' => '',
|
||||
'description' => '',
|
||||
'km' => null,
|
||||
'link' => '',
|
||||
);
|
||||
|
||||
$validity = self::child_value_nested( $record, array( 'validity', 'validityStatus' ) );
|
||||
if ( null !== $validity ) {
|
||||
$incident['status'] = $validity;
|
||||
}
|
||||
|
||||
$start = self::child_value_nested( $record, array( 'validity', 'validityTimeSpecification', 'overallStartTime' ) );
|
||||
if ( null !== $start ) {
|
||||
$incident['start_time'] = $start;
|
||||
}
|
||||
|
||||
$end = self::child_value_nested( $record, array( 'validity', 'validityTimeSpecification', 'overallEndTime' ) );
|
||||
if ( null !== $end ) {
|
||||
$incident['end_time'] = $end;
|
||||
}
|
||||
|
||||
$impact = self::child_value_nested( $record, array( 'impact', 'impactOnTraffic' ) );
|
||||
if ( null !== $impact ) {
|
||||
$incident['impact'] = $impact;
|
||||
}
|
||||
|
||||
self::parse_location( $record, $incident );
|
||||
|
||||
if ( '' === $incident['id'] && '' === $incident['road_name'] && '' === $incident['start_time'] ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $incident;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract location data (road, town, direction, coordinates) from the record.
|
||||
*
|
||||
* @param SimpleXMLElement $record Situation record element.
|
||||
* @param array<string, mixed> $incident Incident array, modified by reference.
|
||||
*/
|
||||
private static function parse_location( SimpleXMLElement $record, array &$incident ): void {
|
||||
$tpeg = self::find_child_path(
|
||||
$record,
|
||||
array( 'groupOfLocations', 'locationContainedInGroup', 'tpeglinearLocation' )
|
||||
);
|
||||
|
||||
if ( null === $tpeg ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$direction = self::find_child( $tpeg, 'tpegDirection' );
|
||||
if ( null !== $direction ) {
|
||||
$incident['direction'] = trim( (string) $direction );
|
||||
}
|
||||
|
||||
$from = self::find_child( $tpeg, 'from' );
|
||||
if ( null !== $from ) {
|
||||
self::parse_point( $from, $incident );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a TPEG point (road, town, coordinates).
|
||||
*
|
||||
* @param SimpleXMLElement $point TPEG point element.
|
||||
* @param array<string, mixed> $incident Incident array, modified by reference.
|
||||
*/
|
||||
private static function parse_point( SimpleXMLElement $point, array &$incident ): void {
|
||||
$coords = self::find_child( $point, 'pointCoordinates' );
|
||||
|
||||
if ( null !== $coords ) {
|
||||
$lat = self::find_child( $coords, 'latitude' );
|
||||
$lon = self::find_child( $coords, 'longitude' );
|
||||
if ( null !== $lat && null !== $lon ) {
|
||||
$incident['lat'] = (float) (string) $lat;
|
||||
$incident['lon'] = (float) (string) $lon;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $point->children( self::NS ) as $name ) {
|
||||
if ( 'name' !== $name->getName() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$type = self::find_child( $name, 'tpegDescriptorType' );
|
||||
$value = self::find_child_path( $name, array( 'descriptor', 'value' ) );
|
||||
|
||||
if ( null === $type || null === $value ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$type_value = trim( (string) $type );
|
||||
$name_value = trim( (string) $value );
|
||||
|
||||
if ( 'linkName' === $type_value && '' === $incident['road_name'] ) {
|
||||
$incident['road_name'] = $name_value;
|
||||
} elseif ( 'townName' === $type_value && '' === $incident['town'] ) {
|
||||
$incident['town'] = $name_value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the DATEX2 record type from the xsi:type attribute.
|
||||
*
|
||||
* @param SimpleXMLElement $record Situation record element.
|
||||
* @return string
|
||||
*/
|
||||
private static function type_of( SimpleXMLElement $record ): string {
|
||||
$attrs = $record->attributes( 'http://www.w3.org/2001/XMLSchema-instance' );
|
||||
$type = isset( $attrs['type'] ) ? (string) $attrs['type'] : '';
|
||||
$pos = strrpos( $type, ':' );
|
||||
|
||||
return false === $pos ? $type : substr( $type, $pos + 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch and parse the SCT RSS feed.
|
||||
*
|
||||
* @return array{items: array<int, array<string, mixed>>, publication_time: string}|null
|
||||
*/
|
||||
private static function fetch_rss(): ?array {
|
||||
$body = self::http_get( self::RSS_URL );
|
||||
if ( null === $body ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$xml = self::parse_xml( $body );
|
||||
if ( null === $xml ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$items = array();
|
||||
$channel = $xml->channel;
|
||||
$publication_time = isset( $channel->pubDate ) ? (string) $channel->pubDate : ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- RSS tag name.
|
||||
|
||||
foreach ( $xml->channel->item as $item ) {
|
||||
$guid = (string) $item->guid;
|
||||
$items[] = array(
|
||||
'reference' => '' !== $guid ? self::reference_from_guid( $guid ) : '',
|
||||
'title' => trim( (string) $item->title ),
|
||||
'description' => trim( (string) $item->description ),
|
||||
'town' => self::town_from_description( (string) $item->description ),
|
||||
'km' => self::km_from_description( (string) $item->description ),
|
||||
'link' => (string) $item->link,
|
||||
'pub_time' => (string) $item->pubDate, // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- RSS tag name.
|
||||
);
|
||||
}
|
||||
|
||||
return array(
|
||||
'items' => $items,
|
||||
'publication_time' => $publication_time,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Derive the DATEX2 creation reference from an RSS guid (e.g. 151732601 → 1517326).
|
||||
*
|
||||
* @param string $guid RSS guid.
|
||||
* @return string
|
||||
*/
|
||||
public static function reference_from_guid( string $guid ): string {
|
||||
return '' === $guid ? '' : substr( $guid, 0, -2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the town from an RSS description ("C-15 | CABRERA D' ANOIA | Sentit ...").
|
||||
*
|
||||
* @param string $description RSS item description.
|
||||
* @return string
|
||||
*/
|
||||
public static function town_from_description( string $description ): string {
|
||||
$parts = explode( '|', $description );
|
||||
|
||||
if ( count( $parts ) < 2 ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$town = trim( $parts[1] );
|
||||
|
||||
return '' === $town ? '' : $town;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the kilometre point from an RSS description (e.g. "Punt km. 32.3-32.6").
|
||||
*
|
||||
* @param string $description RSS item description.
|
||||
* @return string
|
||||
*/
|
||||
public static function km_from_description( string $description ): string {
|
||||
if ( 1 === preg_match( '/km\.\s*([0-9]+(?:\.[0-9]+)?)/u', $description, $m ) ) {
|
||||
return $m[1];
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an HTTP GET and return the body, or null on failure.
|
||||
*
|
||||
* @param string $url Endpoint URL.
|
||||
* @return string|null
|
||||
*/
|
||||
private static function http_get( string $url ): ?string {
|
||||
$response = wp_remote_get(
|
||||
$url,
|
||||
array(
|
||||
'timeout' => 15,
|
||||
'headers' => array(
|
||||
'Accept' => 'application/xml, text/xml',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$body = wp_remote_retrieve_body( $response );
|
||||
|
||||
return '' === $body ? null : $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse an XML string with error suppression, or null on failure.
|
||||
*
|
||||
* @param string $body Raw XML body.
|
||||
* @return SimpleXMLElement|null
|
||||
*/
|
||||
private static function parse_xml( string $body ): ?SimpleXMLElement {
|
||||
$previous = libxml_use_internal_errors( true );
|
||||
|
||||
try {
|
||||
$xml = simplexml_load_string( $body );
|
||||
} finally {
|
||||
libxml_clear_errors();
|
||||
libxml_use_internal_errors( $previous );
|
||||
}
|
||||
|
||||
return false === $xml ? null : $xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the string value of a direct namespaced child.
|
||||
*
|
||||
* @param SimpleXMLElement $element Parent element.
|
||||
* @param string $name Child name.
|
||||
* @return string|null
|
||||
*/
|
||||
private static function child_value( SimpleXMLElement $element, string $name ): ?string {
|
||||
$child = self::find_child( $element, $name );
|
||||
if ( null === $child ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$value = trim( (string) $child );
|
||||
|
||||
return '' === $value ? null : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the first namespaced child element by name.
|
||||
*
|
||||
* @param SimpleXMLElement $element Parent element.
|
||||
* @param string $name Child name.
|
||||
* @return SimpleXMLElement|null
|
||||
*/
|
||||
private static function find_child( SimpleXMLElement $element, string $name ): ?SimpleXMLElement {
|
||||
foreach ( $element->children( self::NS ) as $child ) {
|
||||
if ( $name === $child->getName() ) {
|
||||
return $child;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Walk a path of namespaced children and return the last element.
|
||||
*
|
||||
* @param SimpleXMLElement $element Parent element.
|
||||
* @param array<int, string> $path Child names, outermost first.
|
||||
* @return SimpleXMLElement|null
|
||||
*/
|
||||
private static function find_child_path( SimpleXMLElement $element, array $path ): ?SimpleXMLElement {
|
||||
$current = $element;
|
||||
|
||||
foreach ( $path as $name ) {
|
||||
$child = self::find_child( $current, $name );
|
||||
if ( null === $child ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$current = $child;
|
||||
}
|
||||
|
||||
return $current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Walk a path of namespaced children and return the leaf string value.
|
||||
*
|
||||
* @param SimpleXMLElement $element Parent element.
|
||||
* @param array<int, string> $path Child names, outermost first.
|
||||
* @return string|null
|
||||
*/
|
||||
private static function child_value_nested( SimpleXMLElement $element, array $path ): ?string {
|
||||
$leaf = self::find_child_path( $element, $path );
|
||||
if ( null === $leaf ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$value = trim( (string) $leaf );
|
||||
|
||||
return '' === $value ? null : $value;
|
||||
}
|
||||
}
|
||||
446
includes/class-fontdelbosc-transit-api-zbe.php
Normal file
446
includes/class-fontdelbosc-transit-api-zbe.php
Normal file
|
|
@ -0,0 +1,446 @@
|
|||
<?php
|
||||
/**
|
||||
* DGT NAP ZBE fetcher and parser (DATEX2 v3 controlled zones).
|
||||
*
|
||||
* @package Fontdelbosc_Transit
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Fetches and parses Low Emission Zone data.
|
||||
*/
|
||||
class Fontdelbosc_Transit_Api_Zbe {
|
||||
|
||||
public const BASE_URL = 'https://nap.dgt.es/datex2/v3/dgt/zbe/ControledZonePublication/';
|
||||
|
||||
private const NS_CONZ = 'http://levelC/schema/3/controlledZone';
|
||||
private const NS_COM = 'http://levelC/schema/3/common';
|
||||
private const NS_TRA = 'http://levelC/schema/3/trafficRegulation';
|
||||
|
||||
/**
|
||||
* Catalan zones available at the NAP index, pre-selected by default.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
public const DEFAULT_CATALAN_ZONES = array(
|
||||
'Barcelona',
|
||||
'CerdanyolaDelValles',
|
||||
'ElPratDeLlobregat',
|
||||
'Gava',
|
||||
'Girona',
|
||||
'Granollers',
|
||||
'Lleida',
|
||||
'Manlleu',
|
||||
'Mataro',
|
||||
'Reus',
|
||||
'RondasDeBarcelona',
|
||||
'Rubi',
|
||||
'Sabadell',
|
||||
'SantBoiDeLlobregat',
|
||||
'SantCugatDelValles',
|
||||
'SantJoanDespi',
|
||||
'Tarragona',
|
||||
'Terrasa',
|
||||
'Viladecans',
|
||||
);
|
||||
|
||||
/**
|
||||
* Sanitize a zone slug keeping its case (NAP endpoints are case-sensitive).
|
||||
*
|
||||
* @param string $slug Raw slug.
|
||||
* @return string
|
||||
*/
|
||||
public static function sanitize_slug( string $slug ): string {
|
||||
return preg_replace( '/[^A-Za-z0-9\-]/', '', $slug ) ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the zone index (HTML directory listing) and return zone slugs.
|
||||
*
|
||||
* @return array<int, string>|null
|
||||
*/
|
||||
public static function get_index(): ?array {
|
||||
$body = self::http_get( self::BASE_URL );
|
||||
if ( null === $body ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( 0 === preg_match_all( '/href="([A-Za-z0-9\-]+)\.xml"/', $body, $m ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$slugs = array_values( array_unique( $m[1] ) );
|
||||
sort( $slugs );
|
||||
|
||||
return $slugs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch and parse one zone by slug.
|
||||
*
|
||||
* @param string $slug Zone slug (endpoint file name without .xml).
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public static function get_zone( string $slug ): ?array {
|
||||
$body = self::http_get( self::BASE_URL . rawurlencode( $slug ) . '.xml' );
|
||||
if ( null === $body ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$previous = libxml_use_internal_errors( true );
|
||||
|
||||
try {
|
||||
$xml = simplexml_load_string( $body );
|
||||
} finally {
|
||||
libxml_clear_errors();
|
||||
libxml_use_internal_errors( $previous );
|
||||
}
|
||||
|
||||
if ( false === $xml ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$publication_time = '';
|
||||
foreach ( $xml->children( self::NS_COM ) as $child ) {
|
||||
if ( 'publicationTime' === $child->getName() ) {
|
||||
$publication_time = (string) $child;
|
||||
}
|
||||
}
|
||||
|
||||
$table = self::find_child( $xml, 'controlledZoneTable', self::NS_CONZ );
|
||||
if ( null === $table ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$zones = array();
|
||||
foreach ( $table->children( self::NS_CONZ ) as $zone ) {
|
||||
if ( 'controlledZone' !== $zone->getName() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$parsed = self::parse_zone( $zone );
|
||||
if ( null !== $parsed ) {
|
||||
$parsed['publication_time'] = $publication_time;
|
||||
$zones[] = $parsed;
|
||||
}
|
||||
}
|
||||
|
||||
if ( array() === $zones ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$result = $zones[0];
|
||||
if ( count( $zones ) > 1 ) {
|
||||
$result['extra_zones'] = array_slice( $zones, 1 );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse one controlledZone element into a normalized zone array.
|
||||
*
|
||||
* @param SimpleXMLElement $zone Controlled zone element.
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
private static function parse_zone( SimpleXMLElement $zone ): ?array {
|
||||
$result = array(
|
||||
'slug' => '',
|
||||
'name' => '',
|
||||
'description' => '',
|
||||
'url' => '',
|
||||
'status' => '',
|
||||
'restriction_type' => '',
|
||||
'sticker_negate' => false,
|
||||
'stickers' => array(),
|
||||
'periods' => array(),
|
||||
'publication_time' => '',
|
||||
);
|
||||
|
||||
$result['name'] = self::localized_value( $zone, 'name' );
|
||||
|
||||
$description = self::localized_value( $zone, 'controlledZoneDescription' );
|
||||
if ( null !== $description ) {
|
||||
$result['description'] = $description;
|
||||
}
|
||||
|
||||
$url = self::direct_value( $zone, 'urlForFurtherInformation' );
|
||||
if ( null !== $url ) {
|
||||
$result['url'] = $url;
|
||||
}
|
||||
|
||||
$status = self::direct_value( $zone, 'status' );
|
||||
if ( null !== $status ) {
|
||||
$result['status'] = $status;
|
||||
}
|
||||
|
||||
$order = self::find_child( $zone, 'trafficRegulationOrder' );
|
||||
if ( null === $order ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ( $order->children( self::NS_TRA ) as $regulation ) {
|
||||
if ( 'trafficRegulation' !== $regulation->getName() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
self::parse_regulation( $regulation, $result );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract restriction type, sticker conditions and periods from a regulation.
|
||||
*
|
||||
* @param SimpleXMLElement $regulation Traffic regulation element.
|
||||
* @param array<string, mixed> $result Zone array, modified by reference.
|
||||
*/
|
||||
private static function parse_regulation( SimpleXMLElement $regulation, array &$result ): void {
|
||||
$type = self::find_child( $regulation, 'typeOfRegulation', self::NS_TRA );
|
||||
if ( null !== $type ) {
|
||||
$restriction = self::direct_value( $type, 'accessRestrictionType', self::NS_TRA );
|
||||
if ( null !== $restriction && '' === $result['restriction_type'] ) {
|
||||
$result['restriction_type'] = $restriction;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $regulation->children( self::NS_TRA ) as $child ) {
|
||||
if ( 'condition' !== $child->getName() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( 'ConditionSet' === self::type_of( $child ) ) {
|
||||
self::parse_condition_set( $child, $result );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the conditions inside a ConditionSet (stickers and validity periods).
|
||||
*
|
||||
* ConditionSets can nest (outer set with location, sticker set, validity),
|
||||
* so this method recurses into nested sets.
|
||||
*
|
||||
* @param SimpleXMLElement $set Condition set element.
|
||||
* @param array<string, mixed> $result Zone array, modified by reference.
|
||||
*/
|
||||
private static function parse_condition_set( SimpleXMLElement $set, array &$result ): void {
|
||||
$negate = self::direct_value( $set, 'negate', self::NS_TRA );
|
||||
if ( 'true' === $negate ) {
|
||||
$result['sticker_negate'] = true;
|
||||
}
|
||||
|
||||
foreach ( $set->children( self::NS_TRA ) as $child ) {
|
||||
if ( 'conditions' !== $child->getName() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$type_name = self::type_of( $child );
|
||||
|
||||
if ( 'NonCodableCondition' === $type_name ) {
|
||||
$condition = self::find_child( $child, 'condition' );
|
||||
|
||||
if ( null === $condition ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$values = self::find_child_path( $condition, array( 'values', 'value' ), self::NS_COM );
|
||||
|
||||
if ( null !== $values ) {
|
||||
$value = trim( (string) $values );
|
||||
|
||||
if ( '' !== $value ) {
|
||||
$stickers = Fontdelbosc_Transit_Payload::arr( $result['stickers'] ?? null );
|
||||
$stickers[] = $value;
|
||||
|
||||
$result['stickers'] = $stickers;
|
||||
}
|
||||
}
|
||||
} elseif ( 'ConditionSet' === $type_name ) {
|
||||
self::parse_condition_set( $child, $result );
|
||||
} elseif ( 'ValidityCondition' === $type_name ) {
|
||||
self::parse_validity( $child, $result );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse validity periods out of a ValidityCondition.
|
||||
*
|
||||
* @param SimpleXMLElement $element ValidityCondition element.
|
||||
* @param array<string, mixed> $result Zone array, modified by reference.
|
||||
*/
|
||||
private static function parse_validity( SimpleXMLElement $element, array &$result ): void {
|
||||
$implemented = self::find_child( $element, 'implementedValidity', self::NS_TRA );
|
||||
if ( null === $implemented ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$spec = self::find_child( $implemented, 'validityTimeSpecification', self::NS_COM );
|
||||
if ( null === $spec ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $spec->children( self::NS_COM ) as $valid_period ) {
|
||||
if ( 'validPeriod' !== $valid_period->getName() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$days = self::find_child_path( $valid_period, array( 'periodName', 'values', 'value' ), self::NS_COM );
|
||||
$hours = self::find_child( $valid_period, 'recurringTimePeriodOfDay', self::NS_COM );
|
||||
|
||||
if ( null === $days || null === $hours ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$start = self::direct_value( $hours, 'startTimeOfPeriod', self::NS_COM );
|
||||
$end = self::direct_value( $hours, 'endTimeOfPeriod', self::NS_COM );
|
||||
|
||||
$periods = Fontdelbosc_Transit_Payload::arr( $result['periods'] ?? null );
|
||||
$periods[] = array(
|
||||
'days' => trim( (string) $days ),
|
||||
'start' => null !== $start ? self::short_time( $start ) : '',
|
||||
'end' => null !== $end ? self::short_time( $end ) : '',
|
||||
);
|
||||
|
||||
$result['periods'] = $periods;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the local part of the xsi:type attribute.
|
||||
*
|
||||
* @param SimpleXMLElement $element Element with an xsi:type attribute.
|
||||
* @return string
|
||||
*/
|
||||
private static function type_of( SimpleXMLElement $element ): string {
|
||||
$attrs = $element->attributes( 'http://www.w3.org/2001/XMLSchema-instance' );
|
||||
$type = isset( $attrs['type'] ) ? (string) $attrs['type'] : '';
|
||||
$pos = strrpos( $type, ':' );
|
||||
|
||||
return false === $pos ? $type : substr( $type, $pos + 1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorten an xs:time value (07:00:00Z) to HH:MM.
|
||||
*
|
||||
* @param string $time Raw time.
|
||||
* @return string
|
||||
*/
|
||||
private static function short_time( string $time ): string {
|
||||
return strlen( $time ) >= 5 ? substr( $time, 0, 5 ) : $time;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a localized com:value from a conz element (name, description...).
|
||||
*
|
||||
* @param SimpleXMLElement $element Parent element.
|
||||
* @param string $child_name Child name in the conz namespace.
|
||||
* @return string|null
|
||||
*/
|
||||
private static function localized_value( SimpleXMLElement $element, string $child_name ): ?string {
|
||||
$child = self::find_child( $element, $child_name );
|
||||
if ( null === $child ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$values = self::find_child_path( $child, array( 'values', 'value' ), self::NS_COM );
|
||||
if ( null === $values ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$value = trim( (string) $values );
|
||||
|
||||
return '' === $value ? null : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the direct (unprefixed-value) text of a namespaced child.
|
||||
*
|
||||
* @param SimpleXMLElement $element Parent element.
|
||||
* @param string $child_name Child name.
|
||||
* @param string|null $ns Namespace URI, null for the conz namespace.
|
||||
* @return string|null
|
||||
*/
|
||||
private static function direct_value( SimpleXMLElement $element, string $child_name, ?string $ns = null ): ?string {
|
||||
$child = self::find_child( $element, $child_name, $ns ?? self::NS_CONZ );
|
||||
if ( null === $child ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$value = trim( (string) $child );
|
||||
|
||||
return '' === $value ? null : $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the first child element by name within a namespace.
|
||||
*
|
||||
* @param SimpleXMLElement $element Parent element.
|
||||
* @param string $name Child name.
|
||||
* @param string|null $ns Namespace URI, null for the conz namespace.
|
||||
* @return SimpleXMLElement|null
|
||||
*/
|
||||
private static function find_child( SimpleXMLElement $element, string $name, ?string $ns = null ): ?SimpleXMLElement {
|
||||
$uri = $ns ?? self::NS_CONZ;
|
||||
|
||||
foreach ( $element->children( $uri ) as $child ) {
|
||||
if ( $name === $child->getName() ) {
|
||||
return $child;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Walk a path of namespaced children and return the last element.
|
||||
*
|
||||
* @param SimpleXMLElement $element Parent element.
|
||||
* @param array<int, string> $path Child names, outermost first.
|
||||
* @param string|null $ns Namespace URI, null for the conz namespace.
|
||||
* @return SimpleXMLElement|null
|
||||
*/
|
||||
private static function find_child_path( SimpleXMLElement $element, array $path, ?string $ns = null ): ?SimpleXMLElement {
|
||||
$current = $element;
|
||||
|
||||
foreach ( $path as $name ) {
|
||||
$child = self::find_child( $current, $name, $ns );
|
||||
if ( null === $child ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$current = $child;
|
||||
}
|
||||
|
||||
return $current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform an HTTP GET and return the body, or null on failure.
|
||||
*
|
||||
* @param string $url Endpoint URL.
|
||||
* @return string|null
|
||||
*/
|
||||
private static function http_get( string $url ): ?string {
|
||||
$response = wp_remote_get(
|
||||
$url,
|
||||
array(
|
||||
'timeout' => 15,
|
||||
'headers' => array(
|
||||
'Accept' => 'application/xml, text/xml',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$body = wp_remote_retrieve_body( $response );
|
||||
|
||||
return '' === $body ? null : $body;
|
||||
}
|
||||
}
|
||||
199
includes/class-fontdelbosc-transit-comarques.php
Normal file
199
includes/class-fontdelbosc-transit-comarques.php
Normal file
|
|
@ -0,0 +1,199 @@
|
|||
<?php
|
||||
/**
|
||||
* Comarca resolution: maps incident towns to the comarques around Font del Bosc.
|
||||
*
|
||||
* @package Fontdelbosc_Transit
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Town-to-comarca mapping for Alt Penedès, Anoia, Baix Llobregat and Garraf.
|
||||
*/
|
||||
class Fontdelbosc_Transit_Comarques {
|
||||
|
||||
/**
|
||||
* Supported comarca keys and their labels.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public const COMARQUES = array(
|
||||
'altpenedes' => 'Alt Penedès',
|
||||
'anoia' => 'Anoia',
|
||||
'baixllobregat' => 'Baix Llobregat',
|
||||
'garraf' => 'Garraf',
|
||||
);
|
||||
|
||||
/**
|
||||
* Normalized town name to comarca key.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
public const TOWN_COMARCA = array(
|
||||
/* Alt Penedès */
|
||||
'AVINYONETDELPENEDES' => 'altpenedes',
|
||||
'LESCABANES' => 'altpenedes',
|
||||
'CASTELLVIDELAMARCA' => 'altpenedes',
|
||||
'FONTRUBI' => 'altpenedes',
|
||||
'GELIDA' => 'altpenedes',
|
||||
'LAGRANADA' => 'altpenedes',
|
||||
'MEDIONA' => 'altpenedes',
|
||||
'OLERDOLA' => 'altpenedes',
|
||||
'OLESADEBONESVALLS' => 'altpenedes',
|
||||
'PACSDELPENEDES' => 'altpenedes',
|
||||
'PLADELPENEDES' => 'altpenedes',
|
||||
'PONTONS' => 'altpenedes',
|
||||
'PUIGDALBER' => 'altpenedes',
|
||||
'SANTCUGATSESGARRIGUES' => 'altpenedes',
|
||||
'SANTLLORENCDHORTONS' => 'altpenedes',
|
||||
'SANTMARTISARROCA' => 'altpenedes',
|
||||
'SANTPEREDERIUDEBITLLES' => 'altpenedes',
|
||||
'SANTQUINTIDEMEDIONA' => 'altpenedes',
|
||||
'SANTAFEDELPENEDES' => 'altpenedes',
|
||||
'SANTSADURNIDANOIA' => 'altpenedes',
|
||||
'SANTAMARGARIDAILSMONJOS' => 'altpenedes',
|
||||
'SANTAMARGARIDAIELSMONJOS' => 'altpenedes',
|
||||
'SUBIRATS' => 'altpenedes',
|
||||
'TORRELAVIT' => 'altpenedes',
|
||||
'TORRELLESDEFOIX' => 'altpenedes',
|
||||
'VILAFRANCADELPENEDES' => 'altpenedes',
|
||||
'VILOVIDELPENEDES' => 'altpenedes',
|
||||
/* Anoia */
|
||||
'IGUALADA' => 'anoia',
|
||||
'ODENA' => 'anoia',
|
||||
'VILANOVADELCAMI' => 'anoia',
|
||||
'SANTAMARGARIDADEMONTBUI' => 'anoia',
|
||||
'POBLADECLARAMUNT' => 'anoia',
|
||||
'JORBA' => 'anoia',
|
||||
'PIERA' => 'anoia',
|
||||
'CABRERADANOIA' => 'anoia',
|
||||
'CAPELLADES' => 'anoia',
|
||||
'CARME' => 'anoia',
|
||||
'BRUC' => 'anoia',
|
||||
'CASTELLFOLLITDERIUBREGOS' => 'anoia',
|
||||
'CASTELLOLI' => 'anoia',
|
||||
'COPONS' => 'anoia',
|
||||
'ESTARAS' => 'anoia',
|
||||
'RUBIO' => 'anoia',
|
||||
'SANTMARTISESGUEIOLES' => 'anoia',
|
||||
'SANTPERESALLAVINERA' => 'anoia',
|
||||
'PUJALT' => 'anoia',
|
||||
'PRATSDEREI' => 'anoia',
|
||||
'VECIANA' => 'anoia',
|
||||
'MONTMANEU' => 'anoia',
|
||||
'ARGENSOLA' => 'anoia',
|
||||
'BELLPRAT' => 'anoia',
|
||||
/* Baix Llobregat */
|
||||
'CORNELLADELLOBREGAT' => 'baixllobregat',
|
||||
'SANTBOIDELLOBREGAT' => 'baixllobregat',
|
||||
'SANTFEIUDELLOBREGAT' => 'baixllobregat',
|
||||
'SANTJUSTDESVERN' => 'baixllobregat',
|
||||
'ESPLUGUESDELLOBREGAT' => 'baixllobregat',
|
||||
'SANTJOANDESPI' => 'baixllobregat',
|
||||
'SANTVICENSDELSHORTS' => 'baixllobregat',
|
||||
'SANTACOLOMADECERVELLO' => 'baixllobregat',
|
||||
'SANTCLIMENTDELLOBREGAT' => 'baixllobregat',
|
||||
'TORRELLESDELLOBREGAT' => 'baixllobregat',
|
||||
'VILADECANS' => 'baixllobregat',
|
||||
'PRATDELLOBREGAT' => 'baixllobregat',
|
||||
'HOSPITALETDELLOBREGAT' => 'baixllobregat',
|
||||
'CERVELLO' => 'baixllobregat',
|
||||
'CORBERADELLOBREGAT' => 'baixllobregat',
|
||||
'PALMADECERVELLO' => 'baixllobregat',
|
||||
'PALLEJA' => 'baixllobregat',
|
||||
'PAPIOL' => 'baixllobregat',
|
||||
'MOLINSDEREI' => 'baixllobregat',
|
||||
'SANTANDREUDELABARCA' => 'baixllobregat',
|
||||
'CASTELLDEFELS' => 'baixllobregat',
|
||||
'GAVA' => 'baixllobregat',
|
||||
'BEGUES' => 'baixllobregat',
|
||||
'ABRERA' => 'baixllobregat',
|
||||
'MARTORELL' => 'baixllobregat',
|
||||
'SANTESTEVESESROVIRES' => 'baixllobregat',
|
||||
'CASTELLVIDEROSANES' => 'baixllobregat',
|
||||
'COLLBATO' => 'baixllobregat',
|
||||
'ESPARREGUERA' => 'baixllobregat',
|
||||
'OLESADEMONTSERRAT' => 'baixllobregat',
|
||||
'VALLIRANA' => 'baixllobregat',
|
||||
/* Garraf */
|
||||
'VILANOVAILAGELTRU' => 'garraf',
|
||||
'SITGES' => 'garraf',
|
||||
'CUBELLES' => 'garraf',
|
||||
'CANYELLES' => 'garraf',
|
||||
'SANTPEREDERIBES' => 'garraf',
|
||||
'OLIVELLA' => 'garraf',
|
||||
'GARRAF' => 'garraf',
|
||||
);
|
||||
|
||||
/**
|
||||
* Resolve the comarca key of an incident from its town.
|
||||
*
|
||||
* @param array<mixed> $incident Normalized incident.
|
||||
* @return string Comarca key, or '' when unknown.
|
||||
*/
|
||||
public static function comarca_of( array $incident ): string {
|
||||
$town = Fontdelbosc_Transit_Payload::str( $incident['town'] ?? null ) ?? '';
|
||||
|
||||
if ( '' === $town ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return self::TOWN_COMARCA[ self::normalize_town( $town ) ] ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a town name for lookup: uppercase, unaccented, letters only.
|
||||
*
|
||||
* @param string $town Raw town name.
|
||||
* @return string
|
||||
*/
|
||||
public static function normalize_town( string $town ): string {
|
||||
$ascii = iconv( 'UTF-8', 'ASCII//TRANSLIT', $town );
|
||||
|
||||
if ( false === $ascii ) {
|
||||
$ascii = $town;
|
||||
}
|
||||
|
||||
return preg_replace( '/[^A-Z]/', '', strtoupper( $ascii ) ) ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a comma-separated comarca attribute into valid, unique keys.
|
||||
*
|
||||
* @param string $attr Raw attribute value, e.g. "anoia, garraf".
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function keys_from_attr( string $attr ): array {
|
||||
$keys = array();
|
||||
|
||||
foreach ( explode( ',', $attr ) as $part ) {
|
||||
$key = sanitize_key( trim( $part ) );
|
||||
|
||||
if ( '' !== $key && self::is_valid( $key ) && ! in_array( $key, $keys, true ) ) {
|
||||
$keys[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
return $keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a comarca key is supported.
|
||||
*
|
||||
* @param string $key Comarca key.
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_valid( string $key ): bool {
|
||||
return isset( self::COMARQUES[ $key ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Label of a comarca key.
|
||||
*
|
||||
* @param string $key Comarca key.
|
||||
* @return string
|
||||
*/
|
||||
public static function label( string $key ): string {
|
||||
return self::COMARQUES[ $key ] ?? '';
|
||||
}
|
||||
}
|
||||
209
includes/class-fontdelbosc-transit-data-manager.php
Normal file
209
includes/class-fontdelbosc-transit-data-manager.php
Normal file
|
|
@ -0,0 +1,209 @@
|
|||
<?php
|
||||
/**
|
||||
* Orchestration: caching, stale-while-error, fetch status.
|
||||
*
|
||||
* @package Fontdelbosc_Transit
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Coordinates API access with transients.
|
||||
*/
|
||||
class Fontdelbosc_Transit_Data_Manager {
|
||||
|
||||
private const INCIDENTS_TRANSIENT = 'fontdelbosc_transit_incidents';
|
||||
private const INCIDENTS_STALE = 'fontdelbosc_transit_incidents_stale';
|
||||
private const ZBE_INDEX_TRANSIENT = 'fontdelbosc_transit_zbe_index';
|
||||
private const STALE_WINDOW = 6 * HOUR_IN_SECONDS;
|
||||
private const ZBE_STALE_WINDOW = 7 * DAY_IN_SECONDS;
|
||||
|
||||
/**
|
||||
* Get incidents (cached, stale-while-error).
|
||||
*
|
||||
* @return array{incidents: array<int, array<mixed>>, source: string, publication_time: string}|null
|
||||
*/
|
||||
public static function get_incidents(): ?array {
|
||||
$cached = get_transient( self::INCIDENTS_TRANSIENT );
|
||||
|
||||
if ( is_array( $cached ) ) {
|
||||
return self::shape_incidents( $cached );
|
||||
}
|
||||
|
||||
$fresh = Fontdelbosc_Transit_Api_Sct::get_incidents();
|
||||
|
||||
if ( null === $fresh ) {
|
||||
$stale = get_transient( self::INCIDENTS_STALE );
|
||||
|
||||
if ( is_array( $stale ) ) {
|
||||
return self::shape_incidents( $stale );
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$options = Fontdelbosc_Transit_Plugin::get_options();
|
||||
$ttl = max( 60, Fontdelbosc_Transit_Payload::int( $options['incident_cache_ttl'] ?? null ) ?? 300 );
|
||||
|
||||
set_transient( self::INCIDENTS_TRANSIENT, $fresh, $ttl );
|
||||
set_transient( self::INCIDENTS_STALE, $fresh, self::STALE_WINDOW );
|
||||
self::record_status(
|
||||
'incidents',
|
||||
array(
|
||||
'last_fetch' => time(),
|
||||
'source' => $fresh['source'],
|
||||
'publication_time' => $fresh['publication_time'],
|
||||
'count' => count( $fresh['incidents'] ),
|
||||
)
|
||||
);
|
||||
|
||||
return $fresh;
|
||||
}
|
||||
|
||||
/**
|
||||
* Coerce a cached incidents payload back into its typed shape.
|
||||
*
|
||||
* @param array<mixed> $raw Cached value.
|
||||
* @return array{incidents: array<int, array<mixed>>, source: string, publication_time: string}
|
||||
*/
|
||||
private static function shape_incidents( array $raw ): array {
|
||||
$incidents = array();
|
||||
|
||||
foreach ( Fontdelbosc_Transit_Payload::arr( Fontdelbosc_Transit_Payload::get( $raw, 'incidents' ) ) as $incident ) {
|
||||
if ( is_array( $incident ) ) {
|
||||
$incidents[] = $incident;
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'incidents' => $incidents,
|
||||
'source' => Fontdelbosc_Transit_Payload::str( Fontdelbosc_Transit_Payload::get( $raw, 'source' ) ) ?? '',
|
||||
'publication_time' => Fontdelbosc_Transit_Payload::str( Fontdelbosc_Transit_Payload::get( $raw, 'publication_time' ) ) ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the zones selected in the options (cached, stale-while-error).
|
||||
*
|
||||
* @return array<int, array<mixed>>
|
||||
*/
|
||||
public static function get_zbes(): array {
|
||||
$options = Fontdelbosc_Transit_Plugin::get_options();
|
||||
$selected = Fontdelbosc_Transit_Payload::arr( $options['zbe_municipalities'] ?? Fontdelbosc_Transit_Api_Zbe::DEFAULT_CATALAN_ZONES );
|
||||
$ttl = max( HOUR_IN_SECONDS, Fontdelbosc_Transit_Payload::int( $options['zbe_cache_ttl'] ?? null ) ?? DAY_IN_SECONDS );
|
||||
$zones = array();
|
||||
|
||||
foreach ( $selected as $slug ) {
|
||||
$slug = Fontdelbosc_Transit_Api_Zbe::sanitize_slug( Fontdelbosc_Transit_Payload::str( $slug ) ?? '' );
|
||||
|
||||
if ( '' === $slug ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$key = 'fontdelbosc_transit_zbe_' . $slug;
|
||||
$cache = get_transient( $key );
|
||||
|
||||
if ( is_array( $cache ) ) {
|
||||
$cache['slug'] = $slug;
|
||||
$zones[] = $cache;
|
||||
continue;
|
||||
}
|
||||
|
||||
$zone = Fontdelbosc_Transit_Api_Zbe::get_zone( $slug );
|
||||
|
||||
if ( null === $zone ) {
|
||||
$stale = get_transient( $key . '_stale' );
|
||||
|
||||
if ( is_array( $stale ) ) {
|
||||
$stale['slug'] = $slug;
|
||||
$zones[] = $stale;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$zone['slug'] = $slug;
|
||||
set_transient( $key, $zone, $ttl );
|
||||
set_transient( $key . '_stale', $zone, self::ZBE_STALE_WINDOW );
|
||||
$zones[] = $zone;
|
||||
}
|
||||
|
||||
self::record_status(
|
||||
'zbe',
|
||||
array(
|
||||
'last_fetch' => time(),
|
||||
'zones' => count( $zones ),
|
||||
)
|
||||
);
|
||||
|
||||
return $zones;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full zone index for the admin (cached 24 h).
|
||||
*
|
||||
* @return array<int, string>|null
|
||||
*/
|
||||
public static function get_zbe_index(): ?array {
|
||||
$cached = get_transient( self::ZBE_INDEX_TRANSIENT );
|
||||
|
||||
if ( is_array( $cached ) ) {
|
||||
$slugs = array();
|
||||
|
||||
foreach ( $cached as $slug ) {
|
||||
$slug = Fontdelbosc_Transit_Payload::str( $slug );
|
||||
|
||||
if ( null !== $slug ) {
|
||||
$slugs[] = $slug;
|
||||
}
|
||||
}
|
||||
|
||||
return $slugs;
|
||||
}
|
||||
|
||||
$index = Fontdelbosc_Transit_Api_Zbe::get_index();
|
||||
|
||||
if ( null !== $index ) {
|
||||
set_transient( self::ZBE_INDEX_TRANSIENT, $index, DAY_IN_SECONDS );
|
||||
}
|
||||
|
||||
return $index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flush every data transient.
|
||||
*/
|
||||
public static function flush(): void {
|
||||
delete_transient( self::INCIDENTS_TRANSIENT );
|
||||
delete_transient( self::INCIDENTS_STALE );
|
||||
delete_transient( self::ZBE_INDEX_TRANSIENT );
|
||||
|
||||
$options = Fontdelbosc_Transit_Plugin::get_options();
|
||||
$slugs = array_map(
|
||||
static fn( mixed $slug ): string => Fontdelbosc_Transit_Payload::str( $slug ) ?? '',
|
||||
array_merge(
|
||||
Fontdelbosc_Transit_Payload::arr( $options['zbe_municipalities'] ?? array() ),
|
||||
self::get_zbe_index() ?? array()
|
||||
)
|
||||
);
|
||||
|
||||
foreach ( array_unique( $slugs ) as $slug ) {
|
||||
$key = 'fontdelbosc_transit_zbe_' . Fontdelbosc_Transit_Api_Zbe::sanitize_slug( Fontdelbosc_Transit_Payload::str( $slug ) ?? '' );
|
||||
delete_transient( $key );
|
||||
delete_transient( $key . '_stale' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Record a fetch status entry.
|
||||
*
|
||||
* @param string $stream Stream name (incidents, zbe).
|
||||
* @param array<string, mixed> $data Status payload.
|
||||
*/
|
||||
private static function record_status( string $stream, array $data ): void {
|
||||
$status = Fontdelbosc_Transit_Payload::arr( get_option( 'fontdelbosc_transit_status', array() ) );
|
||||
$status[ $stream ] = $data;
|
||||
|
||||
update_option( 'fontdelbosc_transit_status', $status, false );
|
||||
}
|
||||
}
|
||||
263
includes/class-fontdelbosc-transit-maps.php
Normal file
263
includes/class-fontdelbosc-transit-maps.php
Normal file
|
|
@ -0,0 +1,263 @@
|
|||
<?php
|
||||
/**
|
||||
* Label maps and helpers (types, directions, stickers, C-15 detection).
|
||||
*
|
||||
* @package Fontdelbosc_Transit
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Maps raw API values to display labels.
|
||||
*/
|
||||
class Fontdelbosc_Transit_Maps {
|
||||
|
||||
/**
|
||||
* Translate a DATEX2 record type into a display label.
|
||||
*
|
||||
* @param string $type Raw type (local part of xsi:type).
|
||||
* @return string
|
||||
*/
|
||||
public static function type_label( string $type ): string {
|
||||
switch ( $type ) {
|
||||
case 'Accident':
|
||||
return __( 'Accident', 'fontdelbosc-transit' );
|
||||
case 'MaintenanceWorks':
|
||||
case 'RoadWorks':
|
||||
return __( 'Roadworks', 'fontdelbosc-transit' );
|
||||
case 'VehicleObstruction':
|
||||
case 'ObstructionOnRoad':
|
||||
return __( 'Obstruction', 'fontdelbosc-transit' );
|
||||
case 'WeatherRelatedRoadConditions':
|
||||
return __( 'Weather conditions', 'fontdelbosc-transit' );
|
||||
case 'RoadsideAssistance':
|
||||
return __( 'Roadside assistance', 'fontdelbosc-transit' );
|
||||
case 'AbnormalTraffic':
|
||||
case 'TrafficCongestion':
|
||||
return __( 'Congestion', 'fontdelbosc-transit' );
|
||||
case 'NetworkManagement':
|
||||
case 'GeneralNetworkManagement':
|
||||
return __( 'Traffic management', 'fontdelbosc-transit' );
|
||||
case 'Restrictions':
|
||||
return __( 'Restrictions', 'fontdelbosc-transit' );
|
||||
default:
|
||||
return __( 'Incident', 'fontdelbosc-transit' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a TPEG direction code into a display label.
|
||||
*
|
||||
* @param string $direction Raw direction code.
|
||||
* @return string
|
||||
*/
|
||||
public static function direction_label( string $direction ): string {
|
||||
switch ( $direction ) {
|
||||
case 'northBound':
|
||||
return __( 'Northbound', 'fontdelbosc-transit' );
|
||||
case 'southBound':
|
||||
return __( 'Southbound', 'fontdelbosc-transit' );
|
||||
case 'eastBound':
|
||||
return __( 'Eastbound', 'fontdelbosc-transit' );
|
||||
case 'westBound':
|
||||
return __( 'Westbound', 'fontdelbosc-transit' );
|
||||
case 'bothWays':
|
||||
case 'both':
|
||||
return __( 'Both directions', 'fontdelbosc-transit' );
|
||||
default:
|
||||
return $direction;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a DATEX2 impact code into a display label.
|
||||
*
|
||||
* @param string $impact Raw impact code.
|
||||
* @return string
|
||||
*/
|
||||
public static function impact_label( string $impact ): string {
|
||||
switch ( $impact ) {
|
||||
case 'heavy':
|
||||
case 'veryHeavy':
|
||||
return __( 'Heavy impact on traffic', 'fontdelbosc-transit' );
|
||||
case 'medium':
|
||||
return __( 'Medium impact on traffic', 'fontdelbosc-transit' );
|
||||
case 'light':
|
||||
case 'low':
|
||||
return __( 'Light impact on traffic', 'fontdelbosc-transit' );
|
||||
default:
|
||||
return $impact;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a validity status code into a display label.
|
||||
*
|
||||
* @param string $status Raw status code.
|
||||
* @return string
|
||||
*/
|
||||
public static function status_label( string $status ): string {
|
||||
switch ( $status ) {
|
||||
case 'active':
|
||||
return __( 'Active', 'fontdelbosc-transit' );
|
||||
case 'scheduled':
|
||||
return __( 'Scheduled', 'fontdelbosc-transit' );
|
||||
default:
|
||||
return $status;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a DGT sticker value ("Sin distintivo", "B", "C"...) to a label.
|
||||
*
|
||||
* @param string $sticker Raw sticker value.
|
||||
* @return string
|
||||
*/
|
||||
public static function sticker_label( string $sticker ): string {
|
||||
switch ( $sticker ) {
|
||||
case 'Sin distintivo':
|
||||
case 'Sin etiqueta':
|
||||
return __( 'No label (pre-2000 petrol / pre-2006 diesel)', 'fontdelbosc-transit' );
|
||||
case 'B':
|
||||
return __( 'Label B', 'fontdelbosc-transit' );
|
||||
case 'C':
|
||||
return __( 'Label C', 'fontdelbosc-transit' );
|
||||
case 'ECO':
|
||||
return __( 'Label ECO', 'fontdelbosc-transit' );
|
||||
case '0':
|
||||
return __( 'Label 0 emissions', 'fontdelbosc-transit' );
|
||||
default:
|
||||
return $sticker;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a DATEX2 record type to a stable icon/badge key.
|
||||
*
|
||||
* @param string $type Raw type (local part of xsi:type).
|
||||
* @return string
|
||||
*/
|
||||
public static function type_key( string $type ): string {
|
||||
switch ( $type ) {
|
||||
case 'Accident':
|
||||
return 'accident';
|
||||
case 'MaintenanceWorks':
|
||||
case 'RoadWorks':
|
||||
return 'works';
|
||||
case 'VehicleObstruction':
|
||||
case 'ObstructionOnRoad':
|
||||
return 'obstruction';
|
||||
case 'WeatherRelatedRoadConditions':
|
||||
return 'weather';
|
||||
case 'RoadsideAssistance':
|
||||
return 'assistance';
|
||||
case 'AbnormalTraffic':
|
||||
case 'TrafficCongestion':
|
||||
return 'congestion';
|
||||
case 'NetworkManagement':
|
||||
case 'GeneralNetworkManagement':
|
||||
return 'management';
|
||||
case 'Restrictions':
|
||||
return 'restriction';
|
||||
default:
|
||||
return 'incident';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a DGT sticker value to a chip color key (real label colors).
|
||||
*
|
||||
* @param string $sticker Raw sticker value.
|
||||
* @return string
|
||||
*/
|
||||
public static function sticker_class( string $sticker ): string {
|
||||
switch ( $sticker ) {
|
||||
case 'Sin distintivo':
|
||||
case 'Sin etiqueta':
|
||||
return 'none';
|
||||
case 'B':
|
||||
return 'b';
|
||||
case 'C':
|
||||
return 'c';
|
||||
case 'ECO':
|
||||
return 'eco';
|
||||
case '0':
|
||||
return 'zero';
|
||||
default:
|
||||
return 'other';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether an incident belongs to the C-15 corridor (Eix Garraf-Anoia).
|
||||
*
|
||||
* @param array<mixed> $incident Normalized incident.
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_c15( array $incident ): bool {
|
||||
$road = self::normalize_road( Fontdelbosc_Transit_Payload::str( $incident['road_name'] ?? null ) ?? '' );
|
||||
|
||||
if ( 'C15' === $road || 'EIXGARRAF' === substr( $road, 0, 9 ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$title = Fontdelbosc_Transit_Payload::str( $incident['title'] ?? null ) ?? '';
|
||||
$description = Fontdelbosc_Transit_Payload::str( $incident['description'] ?? null ) ?? '';
|
||||
$haystack = $title . ' ' . $description;
|
||||
|
||||
// Word boundary required: C-153 and C-155 are different roads.
|
||||
return 1 === preg_match( '/C-?15\b/i', $haystack ) || false !== stripos( $haystack, 'eix garraf' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a road name for comparison (uppercase, no spaces or hyphens).
|
||||
*
|
||||
* @param string $road Raw road name.
|
||||
* @return string
|
||||
*/
|
||||
private static function normalize_road( string $road ): string {
|
||||
return strtoupper( preg_replace( '/[\s\-]+/u', '', $road ) ?? '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Format an ISO or RSS timestamp as a local date-time string.
|
||||
*
|
||||
* @param string $time Raw timestamp.
|
||||
* @return string Empty when unparseable.
|
||||
*/
|
||||
public static function format_time( string $time ): string {
|
||||
if ( '' === $time ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$ts = strtotime( $time );
|
||||
|
||||
if ( false === $ts ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$formatted = wp_date( 'j M Y H:i', $ts );
|
||||
|
||||
return is_string( $formatted ) ? $formatted : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Human "last updated" line from a raw timestamp.
|
||||
*
|
||||
* @param string $time Raw timestamp.
|
||||
* @return string Empty when unparseable.
|
||||
*/
|
||||
public static function last_updated( string $time ): string {
|
||||
if ( '' === $time ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$ts = strtotime( $time );
|
||||
|
||||
return false === $ts ? '' : sprintf(
|
||||
/* translators: %s: human-readable time difference. */
|
||||
__( 'Last updated: %s ago', 'fontdelbosc-transit' ),
|
||||
human_time_diff( $ts, time() )
|
||||
);
|
||||
}
|
||||
}
|
||||
70
includes/class-fontdelbosc-transit-payload.php
Normal file
70
includes/class-fontdelbosc-transit-payload.php
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
/**
|
||||
* Typed accessors for mixed data (arrays from cache, options, XML).
|
||||
*
|
||||
* @package Fontdelbosc_Transit
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Small typed accessor helpers.
|
||||
*/
|
||||
class Fontdelbosc_Transit_Payload {
|
||||
|
||||
/**
|
||||
* Returns an array value, or the default.
|
||||
*
|
||||
* @param mixed $value Raw value.
|
||||
* @param string $key Key to look up.
|
||||
* @param mixed $default Default when the key is missing.
|
||||
* @return mixed
|
||||
*/
|
||||
public static function get( mixed $value, string $key, mixed $default = null ): mixed {
|
||||
if ( is_array( $value ) && array_key_exists( $key, $value ) ) {
|
||||
return $value[ $key ];
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string value for a possibly missing or mixed key.
|
||||
*
|
||||
* @param mixed $value Raw value.
|
||||
*/
|
||||
public static function str( mixed $value ): ?string {
|
||||
return is_string( $value ) ? trim( $value ) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an int value for a possibly missing or mixed key.
|
||||
*
|
||||
* @param mixed $value Raw value.
|
||||
*/
|
||||
public static function int( mixed $value ): ?int {
|
||||
if ( is_int( $value ) ) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
if ( is_float( $value ) ) {
|
||||
return (int) $value;
|
||||
}
|
||||
|
||||
if ( is_string( $value ) && preg_match( '/^-?\d+$/', trim( $value ) ) ) {
|
||||
return (int) $value;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array value.
|
||||
*
|
||||
* @param mixed $value Raw value.
|
||||
* @return array<int|string, mixed>
|
||||
*/
|
||||
public static function arr( mixed $value ): array {
|
||||
return is_array( $value ) ? $value : array();
|
||||
}
|
||||
}
|
||||
105
includes/class-fontdelbosc-transit-plugin.php
Normal file
105
includes/class-fontdelbosc-transit-plugin.php
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
/**
|
||||
* Plugin bootstrap: hooks, assets, options.
|
||||
*
|
||||
* @package Fontdelbosc_Transit
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Bootstraps the plugin.
|
||||
*/
|
||||
class Fontdelbosc_Transit_Plugin {
|
||||
|
||||
private const OPTION_NAME = 'fontdelbosc_transit_options';
|
||||
|
||||
/**
|
||||
* Default options.
|
||||
*
|
||||
* @var array<string, mixed>
|
||||
*/
|
||||
private static array $defaults = array(
|
||||
'incident_cache_ttl' => 300,
|
||||
'zbe_cache_ttl' => 86400,
|
||||
'default_view' => 'c15',
|
||||
'max_incidents' => 20,
|
||||
'zbe_municipalities' => null,
|
||||
'show_zbe_2026_notice' => true,
|
||||
'delete_data_on_uninstall' => false,
|
||||
);
|
||||
|
||||
/**
|
||||
* Hook everything.
|
||||
*/
|
||||
public static function init(): void {
|
||||
add_action( 'init', array( __CLASS__, 'load_textdomain' ) );
|
||||
add_action( 'wp_enqueue_scripts', array( __CLASS__, 'register_assets' ) );
|
||||
|
||||
Fontdelbosc_Transit_Shortcode::init();
|
||||
add_action( 'widgets_init', array( __CLASS__, 'register_widget' ) );
|
||||
|
||||
if ( is_admin() ) {
|
||||
require_once FONTDELBOSC_TRANSIT_DIR . 'admin/class-fontdelbosc-transit-admin.php';
|
||||
Fontdelbosc_Transit_Admin::init();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load translations.
|
||||
*/
|
||||
public static function load_textdomain(): void {
|
||||
load_plugin_textdomain( 'fontdelbosc-transit', false, dirname( plugin_basename( FONTDELBOSC_TRANSIT_DIR . 'fontdelbosc-transit.php' ) ) . '/languages' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the front-end stylesheet.
|
||||
*/
|
||||
public static function register_assets(): void {
|
||||
$css = FONTDELBOSC_TRANSIT_DIR . 'public/css/fdbt-transit.css';
|
||||
|
||||
wp_register_style(
|
||||
'fdbt-transit',
|
||||
plugins_url( 'public/css/fdbt-transit.css', FONTDELBOSC_TRANSIT_DIR . 'fontdelbosc-transit.php' ),
|
||||
array(),
|
||||
(string) filemtime( $css )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the widget.
|
||||
*/
|
||||
public static function register_widget(): void {
|
||||
register_widget( 'Fontdelbosc_Transit_Widget' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get options merged with defaults.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function get_options(): array {
|
||||
$saved = get_option( self::OPTION_NAME, array() );
|
||||
$saved = is_array( $saved ) ? $saved : array();
|
||||
$options = array();
|
||||
|
||||
foreach ( self::$defaults as $key => $default ) {
|
||||
$options[ $key ] = array_key_exists( $key, $saved ) ? $saved[ $key ] : $default;
|
||||
}
|
||||
|
||||
if ( null === $options['zbe_municipalities'] ) {
|
||||
$options['zbe_municipalities'] = Fontdelbosc_Transit_Api_Zbe::DEFAULT_CATALAN_ZONES;
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Name of the options entry.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function option_name(): string {
|
||||
return self::OPTION_NAME;
|
||||
}
|
||||
}
|
||||
148
includes/class-fontdelbosc-transit-shortcode.php
Normal file
148
includes/class-fontdelbosc-transit-shortcode.php
Normal file
|
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
/**
|
||||
* Shortcode [fontdelbosc_transit] handler.
|
||||
*
|
||||
* @package Fontdelbosc_Transit
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Renders the transit views.
|
||||
*/
|
||||
class Fontdelbosc_Transit_Shortcode {
|
||||
|
||||
/**
|
||||
* Register the shortcode.
|
||||
*/
|
||||
public static function init(): void {
|
||||
add_shortcode( 'fontdelbosc_transit', array( __CLASS__, 'render' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the shortcode.
|
||||
*
|
||||
* @param array<string> $attrs Shortcode attributes.
|
||||
* @return string
|
||||
*/
|
||||
public static function render( $attrs = array() ): string {
|
||||
$options = Fontdelbosc_Transit_Plugin::get_options();
|
||||
$attrs = shortcode_atts(
|
||||
array(
|
||||
'view' => Fontdelbosc_Transit_Payload::str( $options['default_view'] ?? null ) ?? 'c15',
|
||||
'max' => (string) ( Fontdelbosc_Transit_Payload::int( $options['max_incidents'] ?? null ) ?? 20 ),
|
||||
'comarca' => '',
|
||||
),
|
||||
(array) $attrs,
|
||||
'fontdelbosc_transit'
|
||||
);
|
||||
|
||||
$view = sanitize_key( Fontdelbosc_Transit_Payload::str( $attrs['view'] ) ?? '' );
|
||||
$max = min( 50, max( 1, Fontdelbosc_Transit_Payload::int( $attrs['max'] ) ?? 20 ) );
|
||||
$comarcas = Fontdelbosc_Transit_Comarques::keys_from_attr( Fontdelbosc_Transit_Payload::str( $attrs['comarca'] ) ?? '' );
|
||||
|
||||
$comarca_labels = array_map(
|
||||
static fn( string $key ): string => Fontdelbosc_Transit_Comarques::label( $key ),
|
||||
$comarcas
|
||||
);
|
||||
$comarca_label = implode( ', ', $comarca_labels );
|
||||
|
||||
if ( 'zbe' === $view ) {
|
||||
return self::render_view( 'zbe-list', array( 'zones' => Fontdelbosc_Transit_Data_Manager::get_zbes() ) );
|
||||
}
|
||||
|
||||
$data = Fontdelbosc_Transit_Data_Manager::get_incidents();
|
||||
|
||||
if ( null === $data ) {
|
||||
return self::render_view(
|
||||
'c15' === $view ? 'incidents-c15' : 'incidents-all',
|
||||
array(
|
||||
'incidents' => array(),
|
||||
'meta' => array(),
|
||||
'unavailable' => true,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$incidents = $data['incidents'];
|
||||
|
||||
if ( array() !== $comarcas ) {
|
||||
$incidents = array_values(
|
||||
array_filter(
|
||||
$incidents,
|
||||
static fn( array $incident ): bool => in_array( Fontdelbosc_Transit_Comarques::comarca_of( $incident ), $comarcas, true )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( 'c15' === $view ) {
|
||||
$incidents = array_values(
|
||||
array_filter(
|
||||
$incidents,
|
||||
static fn( array $incident ): bool => Fontdelbosc_Transit_Maps::is_c15( $incident )
|
||||
)
|
||||
);
|
||||
} else {
|
||||
usort(
|
||||
$incidents,
|
||||
static function ( array $a, array $b ): int {
|
||||
$a_c15 = Fontdelbosc_Transit_Maps::is_c15( $a ) ? 0 : 1;
|
||||
$b_c15 = Fontdelbosc_Transit_Maps::is_c15( $b ) ? 0 : 1;
|
||||
|
||||
if ( $a_c15 !== $b_c15 ) {
|
||||
return $a_c15 <=> $b_c15;
|
||||
}
|
||||
|
||||
return strcmp( Fontdelbosc_Transit_Payload::str( $b['start_time'] ?? null ) ?? '', Fontdelbosc_Transit_Payload::str( $a['start_time'] ?? null ) ?? '' );
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return self::render_view(
|
||||
'c15' === $view ? 'incidents-c15' : 'incidents-all',
|
||||
array(
|
||||
'incidents' => array_slice( $incidents, 0, $max ),
|
||||
'meta' => array(
|
||||
'source' => $data['source'],
|
||||
'publication_time' => $data['publication_time'],
|
||||
),
|
||||
'comarca_label' => $comarca_label,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a template by name.
|
||||
*
|
||||
* @param string $name Template name (file name without .php).
|
||||
* @param array<string, mixed> $fontdelbosc_data Template data.
|
||||
* @return string
|
||||
*/
|
||||
public static function render_view( string $name, array $fontdelbosc_data ): string {
|
||||
$file = FONTDELBOSC_TRANSIT_DIR . 'templates/' . $name . '.php';
|
||||
|
||||
if ( ! is_file( $file ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
ob_start();
|
||||
include $file;
|
||||
|
||||
return (string) ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the inline SVG markup for an icon key.
|
||||
*
|
||||
* @param string $key Icon key (see templates/icon.php).
|
||||
* @return string Trusted static SVG markup.
|
||||
*/
|
||||
public static function icon( string $key ): string {
|
||||
$fontdelbosc_icon = $key;
|
||||
|
||||
ob_start();
|
||||
include FONTDELBOSC_TRANSIT_DIR . 'templates/icon.php';
|
||||
|
||||
return (string) ob_get_clean();
|
||||
}
|
||||
}
|
||||
205
includes/class-fontdelbosc-transit-widget.php
Normal file
205
includes/class-fontdelbosc-transit-widget.php
Normal file
|
|
@ -0,0 +1,205 @@
|
|||
<?php
|
||||
/**
|
||||
* Sidebar widget: compact incidents or ZBE summary.
|
||||
*
|
||||
* @package Fontdelbosc_Transit
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Transit widget.
|
||||
*/
|
||||
class Fontdelbosc_Transit_Widget extends WP_Widget {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
parent::__construct(
|
||||
'fontdelbosc_transit',
|
||||
__( 'Font del Bosc — Trànsit', 'fontdelbosc-transit' ),
|
||||
array(
|
||||
'classname' => 'fdbt-widget',
|
||||
'description' => __( 'C-15 incidents or a Low Emission Zones summary.', 'fontdelbosc-transit' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the widget.
|
||||
*
|
||||
* @param array<string, mixed> $args Sidebar arguments.
|
||||
* @param array<string, mixed> $instance Widget settings.
|
||||
*/
|
||||
public function widget( $args, $instance ): void {
|
||||
$title = Fontdelbosc_Transit_Payload::str( apply_filters( 'widget_title', Fontdelbosc_Transit_Payload::str( Fontdelbosc_Transit_Payload::get( $instance, 'title' ) ) ?? '' ) ) ?? '';
|
||||
$view = Fontdelbosc_Transit_Payload::str( Fontdelbosc_Transit_Payload::get( $instance, 'view' ) ) ?? 'c15';
|
||||
|
||||
$before_widget = Fontdelbosc_Transit_Payload::str( Fontdelbosc_Transit_Payload::get( $args, 'before_widget' ) ) ?? '';
|
||||
$after_widget = Fontdelbosc_Transit_Payload::str( Fontdelbosc_Transit_Payload::get( $args, 'after_widget' ) ) ?? '';
|
||||
$before_title = Fontdelbosc_Transit_Payload::str( Fontdelbosc_Transit_Payload::get( $args, 'before_title' ) ) ?? '';
|
||||
$after_title = Fontdelbosc_Transit_Payload::str( Fontdelbosc_Transit_Payload::get( $args, 'after_title' ) ) ?? '';
|
||||
|
||||
echo wp_kses_post( $before_widget );
|
||||
|
||||
if ( '' !== $title ) {
|
||||
echo wp_kses_post( $before_title . esc_html( $title ) . $after_title );
|
||||
}
|
||||
|
||||
if ( 'zbe' === $view ) {
|
||||
$this->render_zbe_summary();
|
||||
} else {
|
||||
$this->render_incidents();
|
||||
}
|
||||
|
||||
echo wp_kses_post( $after_widget );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the compact C-15 incident list.
|
||||
*/
|
||||
private function render_incidents(): void {
|
||||
$data = Fontdelbosc_Transit_Data_Manager::get_incidents();
|
||||
|
||||
if ( null === $data ) {
|
||||
echo '<p class="fdbt-widget__empty">' . esc_html__( 'Data unavailable.', 'fontdelbosc-transit' ) . '</p>';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$incidents = array_filter(
|
||||
$data['incidents'],
|
||||
static fn( array $incident ): bool => Fontdelbosc_Transit_Maps::is_c15( $incident )
|
||||
);
|
||||
$incidents = array_slice( array_values( $incidents ), 0, 5 );
|
||||
|
||||
if ( array() === $incidents ) {
|
||||
echo '<p class="fdbt-widget__empty">' . esc_html__( 'No incidents on C-15.', 'fontdelbosc-transit' ) . '</p>';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<ul class="fdbt-widget__list">';
|
||||
foreach ( $incidents as $incident ) {
|
||||
$type_key = Fontdelbosc_Transit_Maps::type_key( Fontdelbosc_Transit_Payload::str( $incident['type'] ?? null ) ?? '' );
|
||||
|
||||
echo '<li class="fdbt-widget__item">';
|
||||
echo '<span class="fdbt-badge fdbt-badge--' . esc_attr( $type_key ) . '">' . esc_html( Fontdelbosc_Transit_Maps::type_label( Fontdelbosc_Transit_Payload::str( $incident['type'] ?? null ) ?? '' ) ) . '</span>';
|
||||
echo '<span class="fdbt-widget__text">' . esc_html( $this->incident_summary( $incident ) ) . '</span>';
|
||||
echo '</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the one-line summary of an incident for the widget.
|
||||
*
|
||||
* @param array<mixed> $incident Normalized incident.
|
||||
* @return string
|
||||
*/
|
||||
private function incident_summary( array $incident ): string {
|
||||
$parts = array();
|
||||
$km = Fontdelbosc_Transit_Payload::str( $incident['km'] ?? null );
|
||||
|
||||
if ( null !== $km && '' !== $km ) {
|
||||
$parts[] = sprintf(
|
||||
/* translators: %s: kilometre point. */
|
||||
__( 'km %s', 'fontdelbosc-transit' ),
|
||||
$km
|
||||
);
|
||||
}
|
||||
|
||||
$town = Fontdelbosc_Transit_Payload::str( $incident['town'] ?? null );
|
||||
|
||||
if ( null !== $town && '' !== $town ) {
|
||||
$parts[] = $town;
|
||||
}
|
||||
|
||||
$title = Fontdelbosc_Transit_Payload::str( $incident['title'] ?? null );
|
||||
|
||||
if ( null !== $title && '' !== $title ) {
|
||||
$parts[] = $title;
|
||||
}
|
||||
|
||||
if ( array() === $parts ) {
|
||||
return Fontdelbosc_Transit_Payload::str( $incident['road_name'] ?? null ) ?? '';
|
||||
}
|
||||
|
||||
return implode( ' — ', $parts );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the compact ZBE summary.
|
||||
*/
|
||||
private function render_zbe_summary(): void {
|
||||
$zones = Fontdelbosc_Transit_Data_Manager::get_zbes();
|
||||
|
||||
if ( array() === $zones ) {
|
||||
echo '<p class="fdbt-widget__empty">' . esc_html__( 'Data unavailable.', 'fontdelbosc-transit' ) . '</p>';
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
echo '<ul class="fdbt-widget__list">';
|
||||
foreach ( $zones as $zone ) {
|
||||
echo '<li class="fdbt-widget__item"><strong>' . esc_html( Fontdelbosc_Transit_Payload::str( $zone['name'] ?? null ) ?? '' ) . '</strong>';
|
||||
|
||||
$periods = Fontdelbosc_Transit_Payload::arr( $zone['periods'] ?? null );
|
||||
$first = $periods[0] ?? null;
|
||||
|
||||
if ( is_array( $first ) ) {
|
||||
$start = Fontdelbosc_Transit_Payload::str( $first['start'] ?? null ) ?? '';
|
||||
$end = Fontdelbosc_Transit_Payload::str( $first['end'] ?? null ) ?? '';
|
||||
$label = $start . '–' . $end;
|
||||
|
||||
if ( '' !== $start && '' !== $end ) {
|
||||
echo '<span class="fdbt-widget__text"> ' . esc_html( $label ) . '</span>';
|
||||
}
|
||||
}
|
||||
|
||||
echo '</li>';
|
||||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Widget settings form.
|
||||
*
|
||||
* @param array<string, mixed> $instance Widget settings.
|
||||
*/
|
||||
public function form( $instance ): ?string {
|
||||
$title = Fontdelbosc_Transit_Payload::str( Fontdelbosc_Transit_Payload::get( $instance, 'title' ) ) ?? __( 'Traffic on C-15', 'fontdelbosc-transit' );
|
||||
$view = Fontdelbosc_Transit_Payload::str( Fontdelbosc_Transit_Payload::get( $instance, 'view' ) ) ?? 'c15';
|
||||
|
||||
echo '<p>';
|
||||
echo '<label for="' . esc_attr( $this->get_field_id( 'title' ) ) . '">' . esc_html__( 'Title:', 'fontdelbosc-transit' ) . ' </label>';
|
||||
echo '<input class="widefat" id="' . esc_attr( $this->get_field_id( 'title' ) ) . '" name="' . esc_attr( $this->get_field_name( 'title' ) ) . '" type="text" value="' . esc_attr( $title ) . '" />';
|
||||
echo '</p>';
|
||||
|
||||
echo '<p>';
|
||||
echo '<label for="' . esc_attr( $this->get_field_id( 'view' ) ) . '">' . esc_html__( 'View:', 'fontdelbosc-transit' ) . ' </label>';
|
||||
echo '<select class="widefat" id="' . esc_attr( $this->get_field_id( 'view' ) ) . '" name="' . esc_attr( $this->get_field_name( 'view' ) ) . '">';
|
||||
echo '<option value="c15"' . selected( $view, 'c15', false ) . '>' . esc_html__( 'Traffic on C-15', 'fontdelbosc-transit' ) . '</option>';
|
||||
echo '<option value="zbe"' . selected( $view, 'zbe', false ) . '>' . esc_html__( 'Low Emission Zones (ZBE)', 'fontdelbosc-transit' ) . '</option>';
|
||||
echo '</select>';
|
||||
echo '</p>';
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save widget settings.
|
||||
*
|
||||
* @param array<string, mixed> $new_instance New settings.
|
||||
* @param array<string, mixed> $old_instance Old settings.
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function update( $new_instance, $old_instance ): array {
|
||||
$instance = $old_instance;
|
||||
$instance['title'] = sanitize_text_field( Fontdelbosc_Transit_Payload::str( Fontdelbosc_Transit_Payload::get( $new_instance, 'title' ) ) ?? '' );
|
||||
$instance['view'] = 'zbe' === Fontdelbosc_Transit_Payload::str( Fontdelbosc_Transit_Payload::get( $new_instance, 'view' ) ) ? 'zbe' : 'c15';
|
||||
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
BIN
languages/fontdelbosc-transit-ca.mo
Normal file
BIN
languages/fontdelbosc-transit-ca.mo
Normal file
Binary file not shown.
368
languages/fontdelbosc-transit-ca.po
Normal file
368
languages/fontdelbosc-transit-ca.po
Normal file
|
|
@ -0,0 +1,368 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Font del Bosc — Trànsit 1.0.0\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"X-Generator: manual\n"
|
||||
"Language: ca\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
|
||||
msgid "Font del Bosc Trànsit"
|
||||
msgstr "Font del Bosc Trànsit"
|
||||
|
||||
msgid "C-15 incidents or a Low Emission Zones summary."
|
||||
msgstr "Incidències de la C-15 o resum de Zones de Baixes Emissions."
|
||||
|
||||
msgid "Title:"
|
||||
msgstr "Títol:"
|
||||
|
||||
msgid "View:"
|
||||
msgstr "Vista:"
|
||||
|
||||
msgid "Traffic on C-15"
|
||||
msgstr "Trànsit a la C-15"
|
||||
|
||||
msgid "All Catalunya traffic"
|
||||
msgstr "Trànsit a Catalunya"
|
||||
|
||||
msgid "Low Emission Zones (ZBE)"
|
||||
msgstr "Zones de Baixes Emissions (ZBE)"
|
||||
|
||||
msgid "No incidents on C-15."
|
||||
msgstr "No hi ha incidències a la C-15."
|
||||
|
||||
msgid "No incidents reported."
|
||||
msgstr "No hi ha incidències registrades."
|
||||
|
||||
msgid "Data unavailable."
|
||||
msgstr "Dades no disponibles."
|
||||
|
||||
msgid "Accident"
|
||||
msgstr "Accident"
|
||||
|
||||
msgid "Roadworks"
|
||||
msgstr "Obres"
|
||||
|
||||
msgid "Obstruction"
|
||||
msgstr "Obstacle"
|
||||
|
||||
msgid "Weather conditions"
|
||||
msgstr "Condicions meteorològiques"
|
||||
|
||||
msgid "Roadside assistance"
|
||||
msgstr "Assistència en carretera"
|
||||
|
||||
msgid "Congestion"
|
||||
msgstr "Retenció"
|
||||
|
||||
msgid "Traffic management"
|
||||
msgstr "Gestió del trànsit"
|
||||
|
||||
msgid "Restrictions"
|
||||
msgstr "Restriccions"
|
||||
|
||||
msgid "Incident"
|
||||
msgstr "Incidència"
|
||||
|
||||
msgid "Northbound"
|
||||
msgstr "Sentit nord"
|
||||
|
||||
msgid "Southbound"
|
||||
msgstr "Sentit sud"
|
||||
|
||||
msgid "Eastbound"
|
||||
msgstr "Sentit est"
|
||||
|
||||
msgid "Westbound"
|
||||
msgstr "Sentit oest"
|
||||
|
||||
msgid "Both directions"
|
||||
msgstr "Tots dos sentits"
|
||||
|
||||
msgid "Heavy impact on traffic"
|
||||
msgstr "Impacte greu en el trànsit"
|
||||
|
||||
msgid "Medium impact on traffic"
|
||||
msgstr "Impacte mitjà en el trànsit"
|
||||
|
||||
msgid "Light impact on traffic"
|
||||
msgstr "Impacte lleu en el trànsit"
|
||||
|
||||
msgid "Active"
|
||||
msgstr "Activa"
|
||||
|
||||
msgid "Scheduled"
|
||||
msgstr "Programada"
|
||||
|
||||
msgid "No label (pre-2000 petrol / pre-2006 diesel)"
|
||||
msgstr "Sense etiqueta (gasolina anterior a 2000 / dièsel anterior a 2006)"
|
||||
|
||||
msgid "Label B"
|
||||
msgstr "Etiqueta B"
|
||||
|
||||
msgid "Label C"
|
||||
msgstr "Etiqueta C"
|
||||
|
||||
msgid "Label ECO"
|
||||
msgstr "Etiqueta ECO"
|
||||
|
||||
msgid "Label 0 emissions"
|
||||
msgstr "Etiqueta 0 emissions"
|
||||
|
||||
msgid ""
|
||||
"From 1 January 2026, label B vehicles are banned in Catalan ZBEs when "
|
||||
"high-pollution protocols are activated."
|
||||
msgstr ""
|
||||
"Des de l'1 de gener de 2026, els vehicles amb etiqueta B no poden circular "
|
||||
"per les ZBE catalanes quan s'activin protocols per alta contaminació."
|
||||
|
||||
msgid "km %s"
|
||||
msgstr "km %s"
|
||||
|
||||
msgid "Last updated: %s ago"
|
||||
msgstr "Darrera actualització: fa %s"
|
||||
|
||||
msgid "Source: %s"
|
||||
msgstr "Font: %s"
|
||||
|
||||
msgid "Servei Català de Trànsit (SCT) / DGT"
|
||||
msgstr "Servei Català de Trànsit (SCT) / DGT"
|
||||
|
||||
msgid "DGT / Punt d'Accés Nacional"
|
||||
msgstr "DGT / Punt d'Accés Nacional"
|
||||
|
||||
msgid "View at the SCT information centre"
|
||||
msgstr "Veure al centre d’informació del SCT"
|
||||
|
||||
msgid "Municipal regulations"
|
||||
msgstr "Normativa municipal"
|
||||
|
||||
|
||||
msgid "Operating hours: %1$s %2$s–%3$s"
|
||||
msgstr "Horari de restricció: %1$s %2$s–%3$s"
|
||||
|
||||
msgid "Start: %s"
|
||||
msgstr "Inici: %s"
|
||||
|
||||
msgid "End: %s"
|
||||
msgstr "Fi prevista: %s"
|
||||
|
||||
msgid "Cache flushed."
|
||||
msgstr "Memòria cau buidada."
|
||||
|
||||
msgid "Insufficient permissions."
|
||||
msgstr "Permisos insuficients."
|
||||
|
||||
msgid "Incidents"
|
||||
msgstr "Incidències"
|
||||
|
||||
msgid "Cache lifetime (seconds)"
|
||||
msgstr "Vida de la memòria cau (segons)"
|
||||
|
||||
msgid ""
|
||||
"How long incident data is cached. Default 300 (5 minutes); the source "
|
||||
"updates in near real time."
|
||||
msgstr ""
|
||||
"Quant de temps es guarden les dades d’incidències. Per defecte 300 (5 "
|
||||
"minuts); la font s’actualitza gairebé en temps real."
|
||||
|
||||
msgid "ZBE rules change rarely; 86400 (24 hours) is a sensible default."
|
||||
msgstr "Les normes ZBE canvien rarament; 86400 (24 hores) és un valor raonable."
|
||||
|
||||
msgid "Maximum incidents shown"
|
||||
msgstr "Màxim d’incidències mostrades"
|
||||
|
||||
msgid "Default view"
|
||||
msgstr "Vista per defecte"
|
||||
|
||||
msgid "What [fontdelbosc_transit] renders when called without a view attribute."
|
||||
msgstr "Què mostra [fontdelbosc_transit] quan s’usa sense l’atribut view."
|
||||
|
||||
msgid "Zones shown"
|
||||
msgstr "Zones mostrades"
|
||||
|
||||
msgid ""
|
||||
"Catalan zones are pre-selected. When the DGT publishes new zones they appear "
|
||||
"here automatically."
|
||||
msgstr ""
|
||||
"Les zones catalanes venen preseleccionades. Quan la DGT publiqui zones noves "
|
||||
"apareixeran aquí automàticament."
|
||||
|
||||
msgid "2026 notice"
|
||||
msgstr "Avís 2026"
|
||||
|
||||
msgid "Show the etiqueta B 2026 restriction notice in the ZBE view."
|
||||
msgstr "Mostrar l’avís de la restricció d’etiqueta B de 2026 a la vista ZBE."
|
||||
|
||||
msgid "Data on uninstall"
|
||||
msgstr "Dades en desinstal·lar"
|
||||
|
||||
msgid "Delete options and cached data when the plugin is uninstalled."
|
||||
msgstr "Esborrar opcions i dades en memòria cau en desinstal·lar el plugin."
|
||||
|
||||
msgid "Status"
|
||||
msgstr "Estat"
|
||||
|
||||
msgid "Last fetch: %1$s (%2$s source, %3$s incidents)."
|
||||
msgstr "Darrera obtenció: %1$s (font %2$s, %3$s incidències)."
|
||||
|
||||
msgid "Last fetch: %1$s (%2$s zones loaded)."
|
||||
msgstr "Darrera obtenció: %1$s (%2$s zones carregades)."
|
||||
|
||||
msgid "Flush cache"
|
||||
msgstr "Buidar la memòria cau"
|
||||
|
||||
msgid "Documentation"
|
||||
msgstr "Documentació"
|
||||
|
||||
msgid "Shortcode"
|
||||
msgstr "Shortcode"
|
||||
|
||||
msgid "Attribute"
|
||||
msgstr "Atribut"
|
||||
|
||||
msgid "Default"
|
||||
msgstr "Per defecte"
|
||||
|
||||
msgid "Values"
|
||||
msgstr "Valors"
|
||||
|
||||
msgid "Setting above"
|
||||
msgstr "Ajust de dalt"
|
||||
|
||||
msgid "Widget"
|
||||
msgstr "Widget"
|
||||
|
||||
msgid ""
|
||||
"A sidebar widget with an editable title shows the five latest C-15 incidents "
|
||||
"or a summary of the selected Low Emission Zones."
|
||||
msgstr ""
|
||||
"Un widget de barra lateral amb títol editable mostra les cinc darreres "
|
||||
"incidències de la C-15 o un resum de les Zones de Baixes Emissions "
|
||||
"seleccionades."
|
||||
|
||||
msgid "Data sources"
|
||||
msgstr "Fonts de dades"
|
||||
|
||||
msgid ""
|
||||
"Incidents: Servei Català de Trànsit via the DGT national access point "
|
||||
"(DATEX2), enriched with the SCT public RSS feed, which provides the incident "
|
||||
"text and links."
|
||||
msgstr ""
|
||||
"Incidències: Servei Català de Trànsit via el punt d’accés nacional de la DGT "
|
||||
"(DATEX2), enriquides amb el canal RSS públic del SCT, que aporta el text i "
|
||||
"els enllaços."
|
||||
|
||||
msgid ""
|
||||
"Low Emission Zones: DGT national access point (DATEX2 v3), with the zone "
|
||||
"list taken from the live index."
|
||||
msgstr ""
|
||||
"Zones de Baixes Emissions: punt d’accés nacional de la DGT (DATEX2 v3), amb "
|
||||
"la llista de zones presa de l’índex en viu."
|
||||
|
||||
msgid ""
|
||||
"Attribution is mandatory and cannot be disabled: Incidències — Servei Català "
|
||||
"de Trànsit (SCT) / CIVICAT; ZBE — DGT / Punt d'Accés Nacional."
|
||||
msgstr ""
|
||||
"L’atribució és obligatòria i no es pot desactivar: Incidències — Servei "
|
||||
"Català de Trànsit (SCT) / CIVICAT; ZBE — DGT / Punt d’Accés Nacional."
|
||||
|
||||
msgid "Caching"
|
||||
msgstr "Memòria cau"
|
||||
|
||||
msgid ""
|
||||
"Incident data is cached for the lifetime set above (5 minutes by default) "
|
||||
"and zone rules for 24 hours. When a source fails, the last cached data is "
|
||||
"served instead (stale-while-error) and the footer shows the age of the data "
|
||||
"using the source's own publication timestamp."
|
||||
msgstr ""
|
||||
"Les dades d’incidències es guarden a la memòria cau durant la vida "
|
||||
"configurada a dalt (5 minuts per defecte) i les normes de les zones durant "
|
||||
"24 hores. Si una font falla, se serveixen les darreres dades en memòria cau "
|
||||
"(stale-while-error) i el peu mostra l’antiguitat de les dades segons la "
|
||||
"marca de temps de la pròpia font."
|
||||
|
||||
msgid "Use the Flush cache button above to force a fresh fetch of everything."
|
||||
msgstr ""
|
||||
"Usa el botó «Buidar la memòria cau» de dalt per forçar una obtenció fresca "
|
||||
"de tot."
|
||||
|
||||
msgid "Data, privacy and uninstall"
|
||||
msgstr "Dades, privacitat i desinstal·lació"
|
||||
|
||||
msgid ""
|
||||
"The plugin stores no personal data and no secrets: only the settings entry, "
|
||||
"a small fetch-status entry, and transients holding the cached public data. "
|
||||
"No API keys are needed."
|
||||
msgstr ""
|
||||
"El plugin no guarda dades personals ni secrets: només l’entrada d’ajustos, "
|
||||
"una petita entrada d’estat d’obtenció, i transients amb les dades públiques "
|
||||
"a la memòria cau. No fan falta claus d’API."
|
||||
|
||||
msgid ""
|
||||
"By default, uninstalling keeps the stored data. With \"Delete options and "
|
||||
"cached data when the plugin is uninstalled\" enabled, uninstalling removes "
|
||||
"the settings, the status entry and every cached transient — nothing is left "
|
||||
"behind."
|
||||
msgstr ""
|
||||
"Per defecte, desinstal·lar conserva les dades guardades. Amb «Esborrar "
|
||||
"opcions i dades en memòria cau en desinstal·lar el plugin» activat, la "
|
||||
"desinstal·lació elimina els ajustos, l’entrada d’estat i tots els transients "
|
||||
"a la memòria cau: no queda res."
|
||||
|
||||
msgid "Security"
|
||||
msgstr "Seguretat"
|
||||
|
||||
msgid ""
|
||||
"No user input reaches the external endpoints: all URLs are hardcoded "
|
||||
"constants. The only state-changing admin action requires the manage_options "
|
||||
"capability and a nonce. All output is escaped, and the XML responses are "
|
||||
"parsed with external entity loading disabled."
|
||||
msgstr ""
|
||||
"Cap entrada de l’usuari arriba als endpoints externs: totes les URL són "
|
||||
"constants fixes. La única acció d’administració que canvia estat requereix "
|
||||
"el permís manage_options i un nonce. Tota la sortida s’escapa i les "
|
||||
"respostes XML s’analitzen amb la càrrega d’entitats externes desactivada."
|
||||
|
||||
msgid "Compatibility"
|
||||
msgstr "Compatibilitat"
|
||||
|
||||
msgid ""
|
||||
"WordPress 6.4 – 7.1 and PHP 8.2 – 8.5, single site (Multisite is not "
|
||||
"supported)."
|
||||
msgstr "WordPress 6.4 – 7.1 i PHP 8.2 – 8.5, lloc únic (Multisite no està suportat)."
|
||||
|
||||
msgid "The 2026 etiqueta B rule"
|
||||
msgstr "La norma d’etiqueta B de 2026"
|
||||
|
||||
msgid ""
|
||||
"From 1 January 2026, label B vehicles are banned in Catalan ZBEs when "
|
||||
"high-pollution protocols are activated. The persistent notice in the ZBE "
|
||||
"view can be disabled with the toggle above."
|
||||
msgstr ""
|
||||
"Des de l’1 de gener de 2026, els vehicles amb etiqueta B no poden circular "
|
||||
"per les ZBE catalanes quan s’activin protocols per alta contaminació. L’avís "
|
||||
"persistent de la vista ZBE es pot desactivar amb l’interruptor de dalt."
|
||||
|
||||
msgid "%s incident"
|
||||
msgid_plural "%s incidents"
|
||||
msgstr[0] "%s incidència"
|
||||
msgstr[1] "%s incidències"
|
||||
|
||||
msgid "%s zone"
|
||||
msgid_plural "%s zones"
|
||||
msgstr[0] "%s zona"
|
||||
msgstr[1] "%s zones"
|
||||
|
||||
msgid "Restricted vehicle types:"
|
||||
msgstr "Vehicles restringits:"
|
||||
|
||||
msgid "Low Emission Zone"
|
||||
msgstr "Zona de Baixes Emissions"
|
||||
|
||||
msgid "comma-separated list allowed"
|
||||
msgstr "s’admet una llista separada per comes"
|
||||
|
||||
msgid "Font del Bosc — Trànsit"
|
||||
msgstr "Font del Bosc — Trànsit"
|
||||
BIN
languages/fontdelbosc-transit-es_ES.mo
Normal file
BIN
languages/fontdelbosc-transit-es_ES.mo
Normal file
Binary file not shown.
372
languages/fontdelbosc-transit-es_ES.po
Normal file
372
languages/fontdelbosc-transit-es_ES.po
Normal file
|
|
@ -0,0 +1,372 @@
|
|||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Font del Bosc — Trànsit 1.0.0\n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"X-Generator: manual\n"
|
||||
"Language: es_ES\n"
|
||||
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||
|
||||
msgid "Font del Bosc Trànsit"
|
||||
msgstr "Font del Bosc Trànsit"
|
||||
|
||||
msgid "C-15 incidents or a Low Emission Zones summary."
|
||||
msgstr "Incidencias de la C-15 o resumen de Zonas de Bajas Emisiones."
|
||||
|
||||
msgid "Title:"
|
||||
msgstr "Título:"
|
||||
|
||||
msgid "View:"
|
||||
msgstr "Vista:"
|
||||
|
||||
msgid "Traffic on C-15"
|
||||
msgstr "Tráfico en la C-15"
|
||||
|
||||
msgid "All Catalunya traffic"
|
||||
msgstr "Tráfico en Cataluña"
|
||||
|
||||
msgid "Low Emission Zones (ZBE)"
|
||||
msgstr "Zonas de Bajas Emisiones (ZBE)"
|
||||
|
||||
msgid "No incidents on C-15."
|
||||
msgstr "No hay incidencias en la C-15."
|
||||
|
||||
msgid "No incidents reported."
|
||||
msgstr "No hay incidencias registradas."
|
||||
|
||||
msgid "Data unavailable."
|
||||
msgstr "Datos no disponibles."
|
||||
|
||||
msgid "Accident"
|
||||
msgstr "Accidente"
|
||||
|
||||
msgid "Roadworks"
|
||||
msgstr "Obras"
|
||||
|
||||
msgid "Obstruction"
|
||||
msgstr "Obstáculo"
|
||||
|
||||
msgid "Weather conditions"
|
||||
msgstr "Condiciones meteorológicas"
|
||||
|
||||
msgid "Roadside assistance"
|
||||
msgstr "Asistencia en carretera"
|
||||
|
||||
msgid "Congestion"
|
||||
msgstr "Retención"
|
||||
|
||||
msgid "Traffic management"
|
||||
msgstr "Gestión del tráfico"
|
||||
|
||||
msgid "Restrictions"
|
||||
msgstr "Restricciones"
|
||||
|
||||
msgid "Incident"
|
||||
msgstr "Incidencia"
|
||||
|
||||
msgid "Northbound"
|
||||
msgstr "Sentido norte"
|
||||
|
||||
msgid "Southbound"
|
||||
msgstr "Sentido sur"
|
||||
|
||||
msgid "Eastbound"
|
||||
msgstr "Sentido este"
|
||||
|
||||
msgid "Westbound"
|
||||
msgstr "Sentido oeste"
|
||||
|
||||
msgid "Both directions"
|
||||
msgstr "Ambos sentidos"
|
||||
|
||||
msgid "Heavy impact on traffic"
|
||||
msgstr "Impacto grave en el tráfico"
|
||||
|
||||
msgid "Medium impact on traffic"
|
||||
msgstr "Impacto medio en el tráfico"
|
||||
|
||||
msgid "Light impact on traffic"
|
||||
msgstr "Impacto ligero en el tráfico"
|
||||
|
||||
msgid "Active"
|
||||
msgstr "Activa"
|
||||
|
||||
msgid "Scheduled"
|
||||
msgstr "Programada"
|
||||
|
||||
msgid "No label (pre-2000 petrol / pre-2006 diesel)"
|
||||
msgstr "Sin etiqueta (gasolina anterior a 2000 / diésel anterior a 2006)"
|
||||
|
||||
msgid "Label B"
|
||||
msgstr "Etiqueta B"
|
||||
|
||||
msgid "Label C"
|
||||
msgstr "Etiqueta C"
|
||||
|
||||
msgid "Label ECO"
|
||||
msgstr "Etiqueta ECO"
|
||||
|
||||
msgid "Label 0 emissions"
|
||||
msgstr "Etiqueta 0 emisiones"
|
||||
|
||||
msgid ""
|
||||
"From 1 January 2026, label B vehicles are banned in Catalan ZBEs when "
|
||||
"high-pollution protocols are activated."
|
||||
msgstr ""
|
||||
"Desde el 1 de enero de 2026, los vehículos con etiqueta B no pueden circular "
|
||||
"por las ZBE catalanas cuando se activen protocolos por alta contaminación."
|
||||
|
||||
msgid "km %s"
|
||||
msgstr "km %s"
|
||||
|
||||
msgid "Last updated: %s ago"
|
||||
msgstr "Última actualización: hace %s"
|
||||
|
||||
msgid "Source: %s"
|
||||
msgstr "Fuente: %s"
|
||||
|
||||
msgid "Servei Català de Trànsit (SCT) / DGT"
|
||||
msgstr "Servei Català de Trànsit (SCT) / DGT"
|
||||
|
||||
msgid "DGT / Punt d'Accés Nacional"
|
||||
msgstr "DGT / Punto de Acceso Nacional"
|
||||
|
||||
msgid "View at the SCT information centre"
|
||||
msgstr "Ver en el centro de información del SCT"
|
||||
|
||||
msgid "Municipal regulations"
|
||||
msgstr "Normativa municipal"
|
||||
|
||||
|
||||
msgid "Operating hours: %1$s %2$s–%3$s"
|
||||
msgstr "Horario de restricción: %1$s %2$s–%3$s"
|
||||
|
||||
msgid "Start: %s"
|
||||
msgstr "Inicio: %s"
|
||||
|
||||
msgid "End: %s"
|
||||
msgstr "Fin previsto: %s"
|
||||
|
||||
msgid "Cache flushed."
|
||||
msgstr "Caché vaciada."
|
||||
|
||||
msgid "Insufficient permissions."
|
||||
msgstr "Permisos insuficientes."
|
||||
|
||||
msgid "Incidents"
|
||||
msgstr "Incidencias"
|
||||
|
||||
msgid "Cache lifetime (seconds)"
|
||||
msgstr "Vida de la caché (segundos)"
|
||||
|
||||
msgid ""
|
||||
"How long incident data is cached. Default 300 (5 minutes); the source "
|
||||
"updates in near real time."
|
||||
msgstr ""
|
||||
"Cuánto tiempo se guardan los datos de incidencias. Por defecto 300 (5 "
|
||||
"minutos); la fuente se actualiza casi en tiempo real."
|
||||
|
||||
msgid "ZBE rules change rarely; 86400 (24 hours) is a sensible default."
|
||||
msgstr "Las normas ZBE cambian raramente; 86400 (24 horas) es un valor razonable."
|
||||
|
||||
msgid "Maximum incidents shown"
|
||||
msgstr "Máximo de incidencias mostradas"
|
||||
|
||||
msgid "Default view"
|
||||
msgstr "Vista por defecto"
|
||||
|
||||
msgid "What [fontdelbosc_transit] renders when called without a view attribute."
|
||||
msgstr "Qué muestra [fontdelbosc_transit] cuando se usa sin el atributo view."
|
||||
|
||||
msgid "Zones shown"
|
||||
msgstr "Zonas mostradas"
|
||||
|
||||
msgid ""
|
||||
"Catalan zones are pre-selected. When the DGT publishes new zones they appear "
|
||||
"here automatically."
|
||||
msgstr ""
|
||||
"Las zonas catalanas vienen preseleccionadas. Cuando la DGT publique zonas "
|
||||
"nuevas aparecerán aquí automáticamente."
|
||||
|
||||
msgid "2026 notice"
|
||||
msgstr "Aviso 2026"
|
||||
|
||||
msgid "Show the etiqueta B 2026 restriction notice in the ZBE view."
|
||||
msgstr "Mostrar el aviso de la restricción de etiqueta B de 2026 en la vista ZBE."
|
||||
|
||||
msgid "Data on uninstall"
|
||||
msgstr "Datos al desinstalar"
|
||||
|
||||
msgid "Delete options and cached data when the plugin is uninstalled."
|
||||
msgstr "Borrar opciones y datos en caché al desinstalar el plugin."
|
||||
|
||||
msgid "Status"
|
||||
msgstr "Estado"
|
||||
|
||||
msgid "Last fetch: %1$s (%2$s source, %3$s incidents)."
|
||||
msgstr "Última obtención: %1$s (fuente %2$s, %3$s incidencias)."
|
||||
|
||||
msgid "Last fetch: %1$s (%2$s zones loaded)."
|
||||
msgstr "Última obtención: %1$s (%2$s zonas cargadas)."
|
||||
|
||||
msgid "Flush cache"
|
||||
msgstr "Vaciar caché"
|
||||
|
||||
msgid "Documentation"
|
||||
msgstr "Documentación"
|
||||
|
||||
msgid "Shortcode"
|
||||
msgstr "Shortcode"
|
||||
|
||||
msgid "Attribute"
|
||||
msgstr "Atributo"
|
||||
|
||||
msgid "Default"
|
||||
msgstr "Por defecto"
|
||||
|
||||
msgid "Values"
|
||||
msgstr "Valores"
|
||||
|
||||
msgid "Setting above"
|
||||
msgstr "Ajuste de arriba"
|
||||
|
||||
msgid "Widget"
|
||||
msgstr "Widget"
|
||||
|
||||
msgid ""
|
||||
"A sidebar widget with an editable title shows the five latest C-15 incidents "
|
||||
"or a summary of the selected Low Emission Zones."
|
||||
msgstr ""
|
||||
"Un widget de barra lateral con título editable muestra las cinco últimas "
|
||||
"incidencias de la C-15 o un resumen de las Zonas de Bajas Emisiones "
|
||||
"seleccionadas."
|
||||
|
||||
msgid "Data sources"
|
||||
msgstr "Fuentes de datos"
|
||||
|
||||
msgid ""
|
||||
"Incidents: Servei Català de Trànsit via the DGT national access point "
|
||||
"(DATEX2), enriched with the SCT public RSS feed, which provides the incident "
|
||||
"text and links."
|
||||
msgstr ""
|
||||
"Incidencias: Servei Català de Trànsit vía el punto de acceso nacional de la "
|
||||
"DGT (DATEX2), enriquecidas con el canal RSS público del SCT, que aporta el "
|
||||
"texto y los enlaces."
|
||||
|
||||
msgid ""
|
||||
"Low Emission Zones: DGT national access point (DATEX2 v3), with the zone "
|
||||
"list taken from the live index."
|
||||
msgstr ""
|
||||
"Zonas de Bajas Emisiones: punto de acceso nacional de la DGT (DATEX2 v3), "
|
||||
"con la lista de zonas tomada del índice en vivo."
|
||||
|
||||
msgid ""
|
||||
"Attribution is mandatory and cannot be disabled: Incidències — Servei Català "
|
||||
"de Trànsit (SCT) / CIVICAT; ZBE — DGT / Punt d'Accés Nacional."
|
||||
msgstr ""
|
||||
"La atribución es obligatoria y no se puede desactivar: Incidències — Servei "
|
||||
"Català de Trànsit (SCT) / CIVICAT; ZBE — DGT / Punto de Acceso Nacional."
|
||||
|
||||
msgid "Caching"
|
||||
msgstr "Caché"
|
||||
|
||||
msgid ""
|
||||
"Incident data is cached for the lifetime set above (5 minutes by default) "
|
||||
"and zone rules for 24 hours. When a source fails, the last cached data is "
|
||||
"served instead (stale-while-error) and the footer shows the age of the data "
|
||||
"using the source's own publication timestamp."
|
||||
msgstr ""
|
||||
"Los datos de incidencias se guardan en caché durante la vida configurada "
|
||||
"arriba (5 minutos por defecto) y las normas de las zonas durante 24 horas. "
|
||||
"Si una fuente falla, se sirven los últimos datos en caché "
|
||||
"(stale-while-error) y el pie muestra la antigüedad de los datos según la "
|
||||
"marca de tiempo de la propia fuente."
|
||||
|
||||
msgid "Use the Flush cache button above to force a fresh fetch of everything."
|
||||
msgstr ""
|
||||
"Usa el botón «Vaciar caché» de arriba para forzar una obtención fresca de "
|
||||
"todo."
|
||||
|
||||
msgid "Data, privacy and uninstall"
|
||||
msgstr "Datos, privacidad y desinstalación"
|
||||
|
||||
msgid ""
|
||||
"The plugin stores no personal data and no secrets: only the settings entry, "
|
||||
"a small fetch-status entry, and transients holding the cached public data. "
|
||||
"No API keys are needed."
|
||||
msgstr ""
|
||||
"El plugin no guarda datos personales ni secretos: solo la entrada de "
|
||||
"ajustes, una pequeña entrada de estado de obtención, y transients con los "
|
||||
"datos públicos en caché. No hacen falta claves de API."
|
||||
|
||||
msgid ""
|
||||
"By default, uninstalling keeps the stored data. With \"Delete options and "
|
||||
"cached data when the plugin is uninstalled\" enabled, uninstalling removes "
|
||||
"the settings, the status entry and every cached transient — nothing is left "
|
||||
"behind."
|
||||
msgstr ""
|
||||
"Por defecto, desinstalar conserva los datos guardados. Con «Borrar opciones "
|
||||
"y datos en caché al desinstalar el plugin» activado, la desinstalación "
|
||||
"elimina los ajustes, la entrada de estado y todos los transients en caché: "
|
||||
"no queda nada."
|
||||
|
||||
msgid "Security"
|
||||
msgstr "Seguridad"
|
||||
|
||||
msgid ""
|
||||
"No user input reaches the external endpoints: all URLs are hardcoded "
|
||||
"constants. The only state-changing admin action requires the manage_options "
|
||||
"capability and a nonce. All output is escaped, and the XML responses are "
|
||||
"parsed with external entity loading disabled."
|
||||
msgstr ""
|
||||
"Ninguna entrada del usuario llega a los endpoints externos: todas las URLs "
|
||||
"son constantes fijas. La única acción de administración que cambia estado "
|
||||
"requiere el permiso manage_options y un nonce. Toda la salida se escapa y "
|
||||
"las respuestas XML se analizan con la carga de entidades externas "
|
||||
"desactivada."
|
||||
|
||||
msgid "Compatibility"
|
||||
msgstr "Compatibilidad"
|
||||
|
||||
msgid ""
|
||||
"WordPress 6.4 – 7.1 and PHP 8.2 – 8.5, single site (Multisite is not "
|
||||
"supported)."
|
||||
msgstr ""
|
||||
"WordPress 6.4 – 7.1 y PHP 8.2 – 8.5, sitio único (Multisite no está "
|
||||
"soportado)."
|
||||
|
||||
msgid "The 2026 etiqueta B rule"
|
||||
msgstr "La norma de etiqueta B de 2026"
|
||||
|
||||
msgid ""
|
||||
"From 1 January 2026, label B vehicles are banned in Catalan ZBEs when "
|
||||
"high-pollution protocols are activated. The persistent notice in the ZBE "
|
||||
"view can be disabled with the toggle above."
|
||||
msgstr ""
|
||||
"Desde el 1 de enero de 2026, los vehículos con etiqueta B no pueden circular "
|
||||
"por las ZBE catalanas cuando se activen protocolos por alta contaminación. "
|
||||
"El aviso persistente de la vista ZBE se puede desactivar con el interruptor "
|
||||
"de arriba."
|
||||
|
||||
msgid "%s incident"
|
||||
msgid_plural "%s incidents"
|
||||
msgstr[0] "%s incidencia"
|
||||
msgstr[1] "%s incidencias"
|
||||
|
||||
msgid "%s zone"
|
||||
msgid_plural "%s zones"
|
||||
msgstr[0] "%s zona"
|
||||
msgstr[1] "%s zonas"
|
||||
|
||||
msgid "Restricted vehicle types:"
|
||||
msgstr "Vehículos restringidos:"
|
||||
|
||||
msgid "Low Emission Zone"
|
||||
msgstr "Zona de Bajas Emisiones"
|
||||
|
||||
msgid "comma-separated list allowed"
|
||||
msgstr "se admite una lista separada por comas"
|
||||
|
||||
msgid "Font del Bosc — Trànsit"
|
||||
msgstr "Font del Bosc — Trànsit"
|
||||
378
public/css/fdbt-transit.css
Normal file
378
public/css/fdbt-transit.css
Normal file
|
|
@ -0,0 +1,378 @@
|
|||
/*
|
||||
* Font del Bosc — Trànsit. Front-end styles (.fdbt- BEM).
|
||||
* Simple bordered cards, generous spacing, quiet hierarchy.
|
||||
*/
|
||||
|
||||
.fdbt {
|
||||
--fdbt-radius: 10px;
|
||||
--fdbt-border: #d8dde3;
|
||||
--fdbt-hairline: #eef1f4;
|
||||
--fdbt-text: #24292f;
|
||||
--fdbt-muted: #57606a;
|
||||
--fdbt-ok: #1a7f37;
|
||||
--fdbt-warn: #9a6700;
|
||||
--fdbt-danger: #cf222e;
|
||||
--fdbt-link: #0969da;
|
||||
|
||||
margin: 1.75rem 0;
|
||||
font-size: 0.95rem;
|
||||
color: var(--fdbt-text);
|
||||
}
|
||||
|
||||
.fdbt :focus-visible {
|
||||
outline: 2px solid var(--fdbt-link);
|
||||
outline-offset: 2px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
/* Section header */
|
||||
|
||||
.fdbt__title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
flex-wrap: wrap;
|
||||
margin: 0 0 1.25rem;
|
||||
font-size: 1.25rem;
|
||||
line-height: 1.25;
|
||||
}
|
||||
|
||||
.fdbt-count {
|
||||
color: var(--fdbt-muted);
|
||||
font-size: 0.85rem;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.fdbt__scope {
|
||||
color: var(--fdbt-muted);
|
||||
font-size: 1.05rem;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* Empty and unavailable states */
|
||||
|
||||
.fdbt__empty {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.6rem;
|
||||
margin: 0;
|
||||
padding: 0.9rem 1.1rem;
|
||||
border: 1px solid #cdebd8;
|
||||
border-radius: var(--fdbt-radius);
|
||||
color: var(--fdbt-ok);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.fdbt__empty--unavailable {
|
||||
border-color: #ecdcab;
|
||||
color: var(--fdbt-warn);
|
||||
}
|
||||
|
||||
.fdbt-empty__icon {
|
||||
display: inline-flex;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
/* Grid: air between cards */
|
||||
|
||||
.fdbt-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
||||
gap: 1.25rem;
|
||||
}
|
||||
|
||||
/* Card */
|
||||
|
||||
.fdbt-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.55rem;
|
||||
padding: 1.15rem 1.25rem 1.05rem;
|
||||
border: 1px solid var(--fdbt-border);
|
||||
border-radius: var(--fdbt-radius);
|
||||
background: #fff;
|
||||
transition: border-color 0.15s ease;
|
||||
}
|
||||
|
||||
.fdbt-card:hover,
|
||||
.fdbt-card:focus-within {
|
||||
border-color: #9ea9b5;
|
||||
}
|
||||
|
||||
.fdbt-card--c15 {
|
||||
border-left: 4px solid #d4a017;
|
||||
}
|
||||
|
||||
.fdbt-card--zbe {
|
||||
border-left: 4px solid #3f9c63;
|
||||
}
|
||||
|
||||
/* Quiet header: type on the left, status on the right */
|
||||
|
||||
.fdbt-card__head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.5rem;
|
||||
min-height: 22px;
|
||||
}
|
||||
|
||||
.fdbt-card__type {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
font-size: 0.85rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.fdbt-type--works { color: #1a56b0; }
|
||||
.fdbt-type--accident { color: #b3261e; }
|
||||
.fdbt-type--congestion { color: #b25e09; }
|
||||
.fdbt-type--obstruction { color: #a04a00; }
|
||||
.fdbt-type--weather { color: #0b6e4f; }
|
||||
.fdbt-type--assistance { color: #6b21a8; }
|
||||
.fdbt-type--management,
|
||||
.fdbt-type--restriction,
|
||||
.fdbt-type--incident { color: #424d57; }
|
||||
.fdbt-type--zbe { color: #2e8b57; }
|
||||
|
||||
.fdbt-icon {
|
||||
display: inline-flex;
|
||||
flex: 0 0 auto;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.fdbt-icon svg {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.fdbt-card__type .fdbt-icon svg {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
}
|
||||
|
||||
.fdbt-card__status {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
color: var(--fdbt-muted);
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.fdbt-dot {
|
||||
width: 6px;
|
||||
height: 6px;
|
||||
border-radius: 50%;
|
||||
background: var(--fdbt-ok);
|
||||
}
|
||||
|
||||
/* Body: title first, place second */
|
||||
|
||||
.fdbt-card__title {
|
||||
margin: 0;
|
||||
font-size: 1.02rem;
|
||||
font-weight: 700;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.fdbt-card__place {
|
||||
margin: 0;
|
||||
color: var(--fdbt-muted);
|
||||
font-size: 0.9rem;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.fdbt-card__place strong {
|
||||
color: var(--fdbt-text);
|
||||
}
|
||||
|
||||
/* Details behind a hairline divider */
|
||||
|
||||
.fdbt-card__meta {
|
||||
margin: 0.35rem 0 0;
|
||||
padding: 0.7rem 0 0;
|
||||
border-top: 1px solid var(--fdbt-hairline);
|
||||
list-style: none;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
|
||||
.fdbt-card__meta-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.45rem;
|
||||
color: var(--fdbt-muted);
|
||||
font-size: 0.85rem;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.fdbt-card__meta-item--impact {
|
||||
color: var(--fdbt-danger);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.fdbt-card__meta-item--hours {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.fdbt-meta__icon {
|
||||
display: inline-flex;
|
||||
flex: 0 0 auto;
|
||||
color: #8b949e;
|
||||
}
|
||||
|
||||
.fdbt-card__link {
|
||||
margin: auto 0 0;
|
||||
padding-top: 0.5rem;
|
||||
font-size: 0.88rem;
|
||||
}
|
||||
|
||||
.fdbt-card__link a {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.35rem;
|
||||
color: var(--fdbt-link);
|
||||
font-weight: 600;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.fdbt-card__link a:hover,
|
||||
.fdbt-card__link a:focus {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.fdbt-link__icon {
|
||||
display: inline-flex;
|
||||
}
|
||||
|
||||
/* ZBE: stickers as chips, hours as meta */
|
||||
|
||||
.fdbt-card__chips {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.4rem;
|
||||
flex-wrap: wrap;
|
||||
margin: 0;
|
||||
font-size: 0.85rem;
|
||||
color: var(--fdbt-muted);
|
||||
}
|
||||
|
||||
.fdbt-chip {
|
||||
display: inline-block;
|
||||
padding: 0.1rem 0.5rem;
|
||||
border-radius: 5px;
|
||||
font-size: 0.78rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.fdbt-chip--none { background: #eceff1; color: #52606d; }
|
||||
.fdbt-chip--b { background: #ffe082; color: #7a5800; }
|
||||
.fdbt-chip--c { background: #c8e6c9; color: #1b5e20; }
|
||||
.fdbt-chip--eco { background: #b2dfdb; color: #004d40; }
|
||||
.fdbt-chip--zero { background: #bbdefb; color: #0d47a1; }
|
||||
.fdbt-chip--other { background: #eceff1; color: #52606d; }
|
||||
|
||||
.fdbt-badge {
|
||||
display: inline-block;
|
||||
padding: 0.1rem 0.5rem;
|
||||
border-radius: 5px;
|
||||
background: #f0f3f6;
|
||||
color: #424d57;
|
||||
font-size: 0.78rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
/* Notice banner */
|
||||
|
||||
.fdbt-notice {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 0.6rem;
|
||||
margin: 0 0 1.25rem;
|
||||
padding: 0.7rem 0.95rem;
|
||||
border-left: 3px solid var(--fdbt-danger);
|
||||
border-radius: 4px;
|
||||
background: #fdf6f5;
|
||||
}
|
||||
|
||||
.fdbt-notice__icon {
|
||||
display: inline-flex;
|
||||
flex: 0 0 auto;
|
||||
color: var(--fdbt-danger);
|
||||
}
|
||||
|
||||
.fdbt-notice p {
|
||||
margin: 0;
|
||||
font-size: 0.9rem;
|
||||
color: #6e2128;
|
||||
}
|
||||
|
||||
/* Footer */
|
||||
|
||||
.fdbt-footer {
|
||||
margin-top: 1.25rem;
|
||||
padding-top: 0.85rem;
|
||||
border-top: 1px solid var(--fdbt-hairline);
|
||||
font-size: 0.8rem;
|
||||
color: var(--fdbt-muted);
|
||||
}
|
||||
|
||||
.fdbt-footer__updated {
|
||||
margin: 0 0 0.2rem;
|
||||
}
|
||||
|
||||
.fdbt-footer__source {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.fdbt-footer a {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
/* Widget */
|
||||
|
||||
.fdbt-widget__list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.fdbt-widget__item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 0.3rem;
|
||||
padding: 0.55rem 0;
|
||||
border-bottom: 1px solid var(--fdbt-hairline);
|
||||
font-size: 0.88rem;
|
||||
}
|
||||
|
||||
.fdbt-widget__item:last-child {
|
||||
border-bottom: 0;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
.fdbt-widget__text {
|
||||
color: var(--fdbt-muted);
|
||||
}
|
||||
|
||||
.fdbt-widget__empty {
|
||||
margin: 0;
|
||||
color: var(--fdbt-ok);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
/* Motion preferences and small screens */
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.fdbt-card {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 480px) {
|
||||
.fdbt-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
95
readme.txt
Normal file
95
readme.txt
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
=== Font del Bosc — Trànsit ===
|
||||
Contributors: javiercasares
|
||||
Tags: traffic, incidents, zbe, low emission zones, mediona
|
||||
Requires at least: 6.4
|
||||
Tested up to: 7.1
|
||||
Stable tag: 1.0.0
|
||||
Requires PHP: 8.2
|
||||
Version: 1.0.0
|
||||
License: GPL-3.0-or-later
|
||||
License URI: https://www.gnu.org/licenses/gpl-3.0.txt
|
||||
|
||||
Traffic incidents (C-15 and all Catalunya) and Low Emission Zones for Font del Bosc residents.
|
||||
|
||||
== Description ==
|
||||
|
||||
Shows current road incidents from the Servei Català de Trànsit and the rules of the Catalan Low Emission Zones (ZBE), for residents of Font del Bosc (Mediona, Alt Penedès) who commute via the C-15 (Eix Garraf-Anoia).
|
||||
|
||||
* Incidents for the whole of Catalunya, with C-15 incidents highlighted (card grid, no map in this version).
|
||||
* Incident text comes from the SCT public RSS feed merged into the DATEX2 structure by reference; coordinates and machine data come from DATEX2.
|
||||
* Low Emission Zone cards: restricted vehicle labels, operating hours and a link to the municipal regulations, from the DGT national access point (DATEX2 v3).
|
||||
* Persistent notice about the January 2026 etiqueta B restriction in Catalan ZBEs.
|
||||
* Cached with short TTLs and a stale-on-error fallback, so a source outage never breaks the page.
|
||||
|
||||
Attribution (mandatory): Incidències: Servei Català de Trànsit (SCT) — CIVICAT. ZBE: DGT / Punt d'Accés Nacional.
|
||||
|
||||
== Using the plugin ==
|
||||
|
||||
= Shortcode =
|
||||
|
||||
`[fontdelbosc_transit]` renders the incidents view. Attributes:
|
||||
|
||||
* `view`: `c15` (default), `all` or `zbe`.
|
||||
* `max`: maximum incidents to show (1-50), overriding the settings.
|
||||
* `comarca`: restrict incidents to the comarques around Font del Bosc: `altpenedes`, `anoia`, `baixllobregat`, `garraf` — one value or a comma-separated list.
|
||||
|
||||
Examples:
|
||||
|
||||
`[fontdelbosc_transit view="c15"]`
|
||||
`[fontdelbosc_transit view="all" max="10"]`
|
||||
`[fontdelbosc_transit view="zbe"]`
|
||||
`[fontdelbosc_transit view="all" comarca="anoia"]`
|
||||
`[fontdelbosc_transit comarca="anoia,garraf"]`
|
||||
|
||||
= Widget =
|
||||
|
||||
A sidebar widget with an editable title offers the five latest C-15 incidents or a ZBE summary.
|
||||
|
||||
= Settings =
|
||||
|
||||
Settings → Font del Bosc Trànsit: cache lifetimes, maximum incidents, default view, zone selection (the 19 Catalan zones are pre-selected and new DGT zones appear automatically), 2026 notice toggle, fetch status, cache flush, and a documentation section.
|
||||
|
||||
== Installation ==
|
||||
|
||||
= Automatic download =
|
||||
|
||||
Visit the plugin section in your WordPress, search for "Font del Bosc — Trànsit"; download and install the plugin.
|
||||
|
||||
= Manual download =
|
||||
|
||||
Extract the contents of the ZIP and upload the contents to the `/wp-content/plugins/fontdelbosc-transit/` directory. Once uploaded, it will appear in your plugin list.
|
||||
|
||||
== Frequently Asked Questions ==
|
||||
|
||||
= Why is there no severity level on the incidents? =
|
||||
|
||||
The SCT DATEX2 and RSS feeds do not publish a severity field. Incidents are classified by type and, when available, by their impact on traffic.
|
||||
|
||||
= How fresh is the data? =
|
||||
|
||||
Incidents are cached for 5 minutes by default; the source updates in near real time. ZBE rules change rarely and are cached for 24 hours.
|
||||
|
||||
== Compatibility ==
|
||||
|
||||
* WordPress: 6.4 - 7.1
|
||||
* PHP: 8.2 - 8.5
|
||||
|
||||
== Changelog ==
|
||||
|
||||
= 1.0.0 =
|
||||
|
||||
* Initial release: C-15 and all-Catalunya incident cards, ZBE cards with the 19 Catalan zones, 2026 etiqueta B notice, widget, stale-while-error caching, es_ES/ca translations.
|
||||
|
||||
= Previous versions =
|
||||
|
||||
If you want to see the full changelog, visit the [changelog.txt](https://git.robotstxt.es/ROBOTSTXT/fontdelbosc-transit/raw/branch/main/changelog.txt) file.
|
||||
|
||||
== Compliance ==
|
||||
|
||||
This plugin adheres to the following security measures and review protocols for each version:
|
||||
|
||||
* [WordPress Plugin Handbook](https://developer.wordpress.org/plugins/)
|
||||
* [WordPress Plugin Security](https://developer.wordpress.org/plugins/wordpress-org/plugin-security/)
|
||||
* [WordPress APIs Security](https://developer.wordpress.org/apis/security/)
|
||||
* [WordPress Coding Standards](https://github.com/WordPress/WordPress-Coding-Standards)
|
||||
* [Plugin Check (PCP)](https://wordpress.org/plugins/plugin-check/)
|
||||
42
templates/icon.php
Normal file
42
templates/icon.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
/**
|
||||
* Inline SVG icons, stroke-based, inherit currentColor.
|
||||
*
|
||||
* @package Fontdelbosc_Transit
|
||||
*
|
||||
* @var string $fontdelbosc_icon Icon key.
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
$fontdelbosc_icon = isset( $fontdelbosc_icon ) ? $fontdelbosc_icon : 'incident';
|
||||
?>
|
||||
<?php if ( 'works' === $fontdelbosc_icon ) : ?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" width="22" height="22" aria-hidden="true" focusable="false"><path d="M12 3 5 20h14L12 3z"/><path d="M8.7 13.5h6.6"/><path d="M10.4 9h1.1"/></svg>
|
||||
<?php elseif ( 'accident' === $fontdelbosc_icon ) : ?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" width="22" height="22" aria-hidden="true" focusable="false"><path d="M7.86 2h8.28L22 7.86v8.28L16.14 22H7.86L2 16.14V7.86L7.86 2z"/><path d="M12 8v4"/><path d="M12 16h.01"/></svg>
|
||||
<?php elseif ( 'congestion' === $fontdelbosc_icon ) : ?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" width="22" height="22" aria-hidden="true" focusable="false"><path d="M4 6h16"/><path d="M4 11h11"/><path d="M4 16h6"/></svg>
|
||||
<?php elseif ( 'obstruction' === $fontdelbosc_icon ) : ?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" width="22" height="22" aria-hidden="true" focusable="false"><path d="M5 21V9"/><path d="M19 21V9"/><rect x="3" y="4" width="18" height="5" rx="1"/><path d="M7 4 5 9"/><path d="M12 4l-2 5"/><path d="M17 4l-2 5"/></svg>
|
||||
<?php elseif ( 'weather' === $fontdelbosc_icon ) : ?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" width="22" height="22" aria-hidden="true" focusable="false"><path d="M18 10h-1.26A8 8 0 1 0 9 20h9a5 5 0 0 0 0-10z"/><path d="M8 20v1.5"/><path d="M12 19v2.5"/><path d="M16 20v1.5"/></svg>
|
||||
<?php elseif ( 'assistance' === $fontdelbosc_icon ) : ?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" width="22" height="22" aria-hidden="true" focusable="false"><path d="M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"/></svg>
|
||||
<?php elseif ( 'management' === $fontdelbosc_icon ) : ?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" width="22" height="22" aria-hidden="true" focusable="false"><rect x="8" y="3" width="8" height="18" rx="3.5"/><path d="M12 6.5v.01"/><path d="M12 11v.01"/><path d="M12 15.5v.01"/></svg>
|
||||
<?php elseif ( 'restriction' === $fontdelbosc_icon ) : ?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" width="22" height="22" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="9"/><path d="M5.64 5.64 18.36 18.36"/></svg>
|
||||
<?php elseif ( 'zbe' === $fontdelbosc_icon ) : ?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" width="22" height="22" aria-hidden="true" focusable="false"><path d="M20 4c0 9-5 13-11 13H5c0-8 6-12 15-13z"/><path d="M4 21c2.5-6.5 6.5-10 12-12.5"/></svg>
|
||||
<?php elseif ( 'clock' === $fontdelbosc_icon ) : ?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="14" height="14" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg>
|
||||
<?php elseif ( 'check' === $fontdelbosc_icon ) : ?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" width="26" height="26" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="9"/><path d="m8.5 12.5 2.5 2.5 5-6"/></svg>
|
||||
<?php elseif ( 'info' === $fontdelbosc_icon ) : ?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" width="26" height="26" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="9"/><path d="M12 11v5"/><path d="M12 8h.01"/></svg>
|
||||
<?php elseif ( 'external' === $fontdelbosc_icon ) : ?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" width="12" height="12" aria-hidden="true" focusable="false"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><path d="M15 3h6v6"/><path d="M10 14 21 3"/></svg>
|
||||
<?php else : ?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" width="22" height="22" aria-hidden="true" focusable="false"><circle cx="12" cy="12" r="9"/><path d="M12 8v4"/><path d="M12 16h.01"/></svg>
|
||||
<?php endif; ?>
|
||||
119
templates/incident-card.php
Normal file
119
templates/incident-card.php
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
/**
|
||||
* Incident card partial.
|
||||
*
|
||||
* @package Fontdelbosc_Transit
|
||||
*
|
||||
* @var array<string, mixed> $fontdelbosc_incident Normalized incident.
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
$fontdelbosc_incident = isset( $fontdelbosc_incident ) ? $fontdelbosc_incident : array();
|
||||
$fontdelbosc_is_c15 = Fontdelbosc_Transit_Maps::is_c15( $fontdelbosc_incident );
|
||||
$fontdelbosc_type = (string) ( $fontdelbosc_incident['type'] ?? '' );
|
||||
$fontdelbosc_key = Fontdelbosc_Transit_Maps::type_key( $fontdelbosc_type );
|
||||
$fontdelbosc_title = (string) ( $fontdelbosc_incident['title'] ?? '' );
|
||||
|
||||
if ( '' === $fontdelbosc_title ) {
|
||||
$fontdelbosc_title = Fontdelbosc_Transit_Maps::type_label( $fontdelbosc_type );
|
||||
}
|
||||
|
||||
// The RSS title ends with the incident type in parentheses; redundant here.
|
||||
$fontdelbosc_title = trim( (string) preg_replace( '/\s*\([^)]*\)$/', '', $fontdelbosc_title ) );
|
||||
|
||||
$fontdelbosc_meta_items = array();
|
||||
|
||||
if ( '' !== (string) ( $fontdelbosc_incident['direction'] ?? '' ) ) {
|
||||
$fontdelbosc_meta_items[] = array(
|
||||
'label' => Fontdelbosc_Transit_Maps::direction_label( (string) $fontdelbosc_incident['direction'] ),
|
||||
'icon' => '',
|
||||
);
|
||||
}
|
||||
|
||||
if ( '' !== (string) ( $fontdelbosc_incident['start_time'] ?? '' ) ) {
|
||||
$fontdelbosc_time = sprintf(
|
||||
/* translators: %s: start date and time. */
|
||||
__( 'Start: %s', 'fontdelbosc-transit' ),
|
||||
Fontdelbosc_Transit_Maps::format_time( (string) $fontdelbosc_incident['start_time'] )
|
||||
);
|
||||
|
||||
if ( '' !== (string) ( $fontdelbosc_incident['end_time'] ?? '' ) ) {
|
||||
$fontdelbosc_time .= sprintf(
|
||||
/* translators: %s: end date and time. */
|
||||
' — ' . __( 'End: %s', 'fontdelbosc-transit' ),
|
||||
Fontdelbosc_Transit_Maps::format_time( (string) $fontdelbosc_incident['end_time'] )
|
||||
);
|
||||
}
|
||||
|
||||
$fontdelbosc_meta_items[] = array(
|
||||
'label' => $fontdelbosc_time,
|
||||
'icon' => 'clock',
|
||||
);
|
||||
}
|
||||
|
||||
if ( '' !== (string) ( $fontdelbosc_incident['impact'] ?? '' ) ) {
|
||||
$fontdelbosc_meta_items[] = array(
|
||||
'label' => Fontdelbosc_Transit_Maps::impact_label( (string) $fontdelbosc_incident['impact'] ),
|
||||
'icon' => '',
|
||||
'impact' => true,
|
||||
);
|
||||
}
|
||||
?>
|
||||
<article class="fdbt-card fdbt-card--<?php echo esc_attr( $fontdelbosc_key ); ?><?php echo $fontdelbosc_is_c15 ? ' fdbt-card--c15' : ''; ?>">
|
||||
<header class="fdbt-card__head">
|
||||
<span class="fdbt-card__type fdbt-type--<?php echo esc_attr( $fontdelbosc_key ); ?>">
|
||||
<span class="fdbt-icon fdbt-icon--<?php echo esc_attr( $fontdelbosc_key ); ?>" aria-hidden="true"><?php echo Fontdelbosc_Transit_Shortcode::icon( $fontdelbosc_key ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- trusted static SVG markup. ?></span>
|
||||
<?php echo esc_html( Fontdelbosc_Transit_Maps::type_label( $fontdelbosc_type ) ); ?>
|
||||
</span>
|
||||
<?php if ( '' !== (string) ( $fontdelbosc_incident['status'] ?? '' ) ) : ?>
|
||||
<span class="fdbt-card__status"><span class="fdbt-dot" aria-hidden="true"></span><?php echo esc_html( Fontdelbosc_Transit_Maps::status_label( (string) $fontdelbosc_incident['status'] ) ); ?></span>
|
||||
<?php endif; ?>
|
||||
</header>
|
||||
|
||||
<p class="fdbt-card__title"><?php echo esc_html( $fontdelbosc_title ); ?></p>
|
||||
|
||||
<?php if ( '' !== (string) ( $fontdelbosc_incident['road_name'] ?? '' ) || '' !== (string) ( $fontdelbosc_incident['town'] ?? '' ) || '' !== (string) ( $fontdelbosc_incident['km'] ?? '' ) ) : ?>
|
||||
<p class="fdbt-card__place">
|
||||
<?php
|
||||
$fontdelbosc_place = array();
|
||||
|
||||
if ( '' !== (string) $fontdelbosc_incident['road_name'] ) {
|
||||
$fontdelbosc_place[] = '<strong>' . esc_html( (string) $fontdelbosc_incident['road_name'] ) . '</strong>';
|
||||
}
|
||||
|
||||
if ( '' !== (string) $fontdelbosc_incident['town'] ) {
|
||||
$fontdelbosc_place[] = esc_html( (string) $fontdelbosc_incident['town'] );
|
||||
}
|
||||
|
||||
if ( '' !== (string) $fontdelbosc_incident['km'] ) {
|
||||
$fontdelbosc_place[] = esc_html( sprintf( /* translators: %s: kilometre point. */ __( 'km %s', 'fontdelbosc-transit' ), (string) $fontdelbosc_incident['km'] ) );
|
||||
}
|
||||
|
||||
echo implode( ' · ', $fontdelbosc_place ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- parts escaped above.
|
||||
?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( array() !== $fontdelbosc_meta_items ) : ?>
|
||||
<ul class="fdbt-card__meta">
|
||||
<?php foreach ( $fontdelbosc_meta_items as $fontdelbosc_meta_item ) : ?>
|
||||
<li class="fdbt-card__meta-item<?php echo ! empty( $fontdelbosc_meta_item['impact'] ) ? ' fdbt-card__meta-item--impact' : ''; ?>">
|
||||
<?php if ( 'clock' === $fontdelbosc_meta_item['icon'] ) : ?>
|
||||
<span class="fdbt-meta__icon" aria-hidden="true"><?php echo Fontdelbosc_Transit_Shortcode::icon( 'clock' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- trusted static SVG markup. ?></span>
|
||||
<?php endif; ?>
|
||||
<?php echo esc_html( $fontdelbosc_meta_item['label'] ); ?>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( '' !== (string) ( $fontdelbosc_incident['link'] ?? '' ) ) : ?>
|
||||
<p class="fdbt-card__link">
|
||||
<a href="<?php echo esc_url( (string) $fontdelbosc_incident['link'] ); ?>" target="_blank" rel="nofollow noopener">
|
||||
<?php esc_html_e( 'View at the SCT information centre', 'fontdelbosc-transit' ); ?>
|
||||
<span class="fdbt-link__icon" aria-hidden="true"><?php echo Fontdelbosc_Transit_Shortcode::icon( 'external' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- trusted static SVG markup. ?></span>
|
||||
</a>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
</article>
|
||||
54
templates/incidents-all.php
Normal file
54
templates/incidents-all.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
/**
|
||||
* All Catalunya incidents view (C-15 first).
|
||||
*
|
||||
* @package Fontdelbosc_Transit
|
||||
*
|
||||
* @var array<string, mixed> $fontdelbosc_data Template data.
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
$fontdelbosc_incidents = $fontdelbosc_data['incidents'] ?? array();
|
||||
$fontdelbosc_meta = $fontdelbosc_data['meta'] ?? array();
|
||||
$fontdelbosc_unavailable = ! empty( $fontdelbosc_data['unavailable'] );
|
||||
$fontdelbosc_scope = Fontdelbosc_Transit_Payload::str( $fontdelbosc_data['comarca_label'] ?? null ) ?? '';
|
||||
?>
|
||||
<section class="fdbt fdbt--all">
|
||||
<h2 class="fdbt__title">
|
||||
<?php esc_html_e( 'All Catalunya traffic', 'fontdelbosc-transit' ); ?>
|
||||
<?php if ( '' !== $fontdelbosc_scope ) : ?>
|
||||
<span class="fdbt__scope">— <?php echo esc_html( $fontdelbosc_scope ); ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if ( ! $fontdelbosc_unavailable && array() !== $fontdelbosc_incidents ) : ?>
|
||||
<span class="fdbt-count">
|
||||
<?php
|
||||
/* translators: %s: number of incidents. */
|
||||
echo esc_html( '(' . sprintf( _n( '%s incident', '%s incidents', count( $fontdelbosc_incidents ), 'fontdelbosc-transit' ), number_format_i18n( count( $fontdelbosc_incidents ) ) ) ) . ')';
|
||||
?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</h2>
|
||||
|
||||
<?php if ( $fontdelbosc_unavailable ) : ?>
|
||||
<p class="fdbt__empty fdbt__empty--unavailable">
|
||||
<span class="fdbt-empty__icon fdbt-empty__icon--muted" aria-hidden="true"><?php echo Fontdelbosc_Transit_Shortcode::icon( 'info' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- trusted static SVG markup. ?></span>
|
||||
<?php esc_html_e( 'Data unavailable.', 'fontdelbosc-transit' ); ?>
|
||||
</p>
|
||||
<?php elseif ( array() === $fontdelbosc_incidents ) : ?>
|
||||
<p class="fdbt__empty">
|
||||
<span class="fdbt-empty__icon fdbt-empty__icon--ok" aria-hidden="true"><?php echo Fontdelbosc_Transit_Shortcode::icon( 'check' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- trusted static SVG markup. ?></span>
|
||||
<?php esc_html_e( 'No incidents reported.', 'fontdelbosc-transit' ); ?>
|
||||
</p>
|
||||
<?php else : ?>
|
||||
<div class="fdbt-grid">
|
||||
<?php
|
||||
foreach ( $fontdelbosc_incidents as $fontdelbosc_incident ) {
|
||||
include FONTDELBOSC_TRANSIT_DIR . 'templates/incident-card.php';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php include FONTDELBOSC_TRANSIT_DIR . 'templates/source-footer.php'; ?>
|
||||
</section>
|
||||
54
templates/incidents-c15.php
Normal file
54
templates/incidents-c15.php
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
/**
|
||||
* C-15 incidents view (highlighted).
|
||||
*
|
||||
* @package Fontdelbosc_Transit
|
||||
*
|
||||
* @var array<string, mixed> $fontdelbosc_data Template data.
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
$fontdelbosc_incidents = $fontdelbosc_data['incidents'] ?? array();
|
||||
$fontdelbosc_meta = $fontdelbosc_data['meta'] ?? array();
|
||||
$fontdelbosc_unavailable = ! empty( $fontdelbosc_data['unavailable'] );
|
||||
$fontdelbosc_scope = Fontdelbosc_Transit_Payload::str( $fontdelbosc_data['comarca_label'] ?? null ) ?? '';
|
||||
?>
|
||||
<section class="fdbt fdbt--c15">
|
||||
<h2 class="fdbt__title">
|
||||
<?php esc_html_e( 'Traffic on C-15', 'fontdelbosc-transit' ); ?>
|
||||
<?php if ( '' !== $fontdelbosc_scope ) : ?>
|
||||
<span class="fdbt__scope">— <?php echo esc_html( $fontdelbosc_scope ); ?></span>
|
||||
<?php endif; ?>
|
||||
<?php if ( ! $fontdelbosc_unavailable && array() !== $fontdelbosc_incidents ) : ?>
|
||||
<span class="fdbt-count">
|
||||
<?php
|
||||
/* translators: %s: number of incidents. */
|
||||
echo esc_html( '(' . sprintf( _n( '%s incident', '%s incidents', count( $fontdelbosc_incidents ), 'fontdelbosc-transit' ), number_format_i18n( count( $fontdelbosc_incidents ) ) ) ) . ')';
|
||||
?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</h2>
|
||||
|
||||
<?php if ( $fontdelbosc_unavailable ) : ?>
|
||||
<p class="fdbt__empty fdbt__empty--unavailable">
|
||||
<span class="fdbt-empty__icon fdbt-empty__icon--muted" aria-hidden="true"><?php echo Fontdelbosc_Transit_Shortcode::icon( 'info' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- trusted static SVG markup. ?></span>
|
||||
<?php esc_html_e( 'Data unavailable.', 'fontdelbosc-transit' ); ?>
|
||||
</p>
|
||||
<?php elseif ( array() === $fontdelbosc_incidents ) : ?>
|
||||
<p class="fdbt__empty">
|
||||
<span class="fdbt-empty__icon fdbt-empty__icon--ok" aria-hidden="true"><?php echo Fontdelbosc_Transit_Shortcode::icon( 'check' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- trusted static SVG markup. ?></span>
|
||||
<?php esc_html_e( 'No incidents on C-15.', 'fontdelbosc-transit' ); ?>
|
||||
</p>
|
||||
<?php else : ?>
|
||||
<div class="fdbt-grid">
|
||||
<?php
|
||||
foreach ( $fontdelbosc_incidents as $fontdelbosc_incident ) {
|
||||
include FONTDELBOSC_TRANSIT_DIR . 'templates/incident-card.php';
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php include FONTDELBOSC_TRANSIT_DIR . 'templates/source-footer.php'; ?>
|
||||
</section>
|
||||
33
templates/source-footer.php
Normal file
33
templates/source-footer.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
/**
|
||||
* Source footer: last updated + mandatory attribution.
|
||||
*
|
||||
* @package Fontdelbosc_Transit
|
||||
*
|
||||
* @var array<string, mixed> $fontdelbosc_meta Source metadata.
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
$fontdelbosc_meta = $fontdelbosc_data['meta'] ?? array();
|
||||
?>
|
||||
<footer class="fdbt-footer">
|
||||
<?php
|
||||
$fontdelbosc_updated = isset( $fontdelbosc_meta['publication_time'] )
|
||||
? Fontdelbosc_Transit_Maps::last_updated( (string) $fontdelbosc_meta['publication_time'] )
|
||||
: '';
|
||||
|
||||
if ( '' !== $fontdelbosc_updated ) :
|
||||
?>
|
||||
<p class="fdbt-footer__updated"><?php echo esc_html( $fontdelbosc_updated ); ?></p>
|
||||
<?php endif; ?>
|
||||
<p class="fdbt-footer__source">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s: source name. */
|
||||
esc_html__( 'Source: %s', 'fontdelbosc-transit' ),
|
||||
'<a href="https://cit.transit.gencat.cat" target="_blank" rel="nofollow noopener">' . esc_html__( 'Servei Català de Trànsit (SCT) / DGT', 'fontdelbosc-transit' ) . '</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</footer>
|
||||
112
templates/zbe-list.php
Normal file
112
templates/zbe-list.php
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
<?php
|
||||
/**
|
||||
* ZBE cards view.
|
||||
*
|
||||
* @package Fontdelbosc_Transit
|
||||
*
|
||||
* @var array<string, mixed> $fontdelbosc_data Template data.
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
$fontdelbosc_zones = $fontdelbosc_data['zones'] ?? array();
|
||||
$fontdelbosc_options = Fontdelbosc_Transit_Plugin::get_options();
|
||||
?>
|
||||
<section class="fdbt fdbt--zbe">
|
||||
<h2 class="fdbt__title">
|
||||
<?php esc_html_e( 'Low Emission Zones (ZBE)', 'fontdelbosc-transit' ); ?>
|
||||
<?php if ( array() !== $fontdelbosc_zones ) : ?>
|
||||
<span class="fdbt-count">
|
||||
<?php
|
||||
/* translators: %s: number of zones. */
|
||||
echo esc_html( '(' . sprintf( _n( '%s zone', '%s zones', count( $fontdelbosc_zones ), 'fontdelbosc-transit' ), number_format_i18n( count( $fontdelbosc_zones ) ) ) . ')' );
|
||||
?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</h2>
|
||||
|
||||
<?php if ( ! empty( $fontdelbosc_options['show_zbe_2026_notice'] ) ) : ?>
|
||||
<div class="fdbt-notice">
|
||||
<span class="fdbt-notice__icon" aria-hidden="true"><?php echo Fontdelbosc_Transit_Shortcode::icon( 'info' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- trusted static SVG markup. ?></span>
|
||||
<p><?php esc_html_e( 'From 1 January 2026, label B vehicles are banned in Catalan ZBEs when high-pollution protocols are activated.', 'fontdelbosc-transit' ); ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( array() === $fontdelbosc_zones ) : ?>
|
||||
<p class="fdbt__empty fdbt__empty--unavailable">
|
||||
<span class="fdbt-empty__icon fdbt-empty__icon--muted" aria-hidden="true"><?php echo Fontdelbosc_Transit_Shortcode::icon( 'info' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- trusted static SVG markup. ?></span>
|
||||
<?php esc_html_e( 'Data unavailable.', 'fontdelbosc-transit' ); ?>
|
||||
</p>
|
||||
<?php else : ?>
|
||||
<div class="fdbt-grid">
|
||||
<?php foreach ( $fontdelbosc_zones as $fontdelbosc_zone ) : ?>
|
||||
<?php $fontdelbosc_stickers = Fontdelbosc_Transit_Payload::arr( $fontdelbosc_zone['stickers'] ?? null ); ?>
|
||||
<article class="fdbt-card fdbt-card--zbe">
|
||||
<header class="fdbt-card__head">
|
||||
<span class="fdbt-card__type fdbt-type--zbe">
|
||||
<span class="fdbt-icon fdbt-icon--zbe" aria-hidden="true"><?php echo Fontdelbosc_Transit_Shortcode::icon( 'zbe' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- trusted static SVG markup. ?></span>
|
||||
<?php esc_html_e( 'Low Emission Zone', 'fontdelbosc-transit' ); ?>
|
||||
</span>
|
||||
<?php if ( 'active' === (string) ( $fontdelbosc_zone['status'] ?? '' ) ) : ?>
|
||||
<span class="fdbt-card__status"><span class="fdbt-dot" aria-hidden="true"></span><?php esc_html_e( 'Active', 'fontdelbosc-transit' ); ?></span>
|
||||
<?php endif; ?>
|
||||
</header>
|
||||
|
||||
<p class="fdbt-card__title"><?php echo esc_html( (string) $fontdelbosc_zone['name'] ); ?></p>
|
||||
|
||||
<?php if ( array() !== $fontdelbosc_stickers ) : ?>
|
||||
<p class="fdbt-card__chips">
|
||||
<?php
|
||||
/* translators: %s: list of restricted vehicle labels. */
|
||||
esc_html_e( 'Restricted vehicle types:', 'fontdelbosc-transit' );
|
||||
?>
|
||||
<?php foreach ( $fontdelbosc_stickers as $fontdelbosc_sticker ) : ?>
|
||||
<span class="fdbt-chip fdbt-chip--<?php echo esc_attr( Fontdelbosc_Transit_Maps::sticker_class( (string) $fontdelbosc_sticker ) ); ?>"><?php echo esc_html( Fontdelbosc_Transit_Maps::sticker_label( (string) $fontdelbosc_sticker ) ); ?></span>
|
||||
<?php endforeach; ?>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php foreach ( Fontdelbosc_Transit_Payload::arr( $fontdelbosc_zone['periods'] ?? null ) as $fontdelbosc_period ) : ?>
|
||||
<?php
|
||||
if ( ! is_array( $fontdelbosc_period ) ) {
|
||||
continue; }
|
||||
?>
|
||||
<p class="fdbt-card__meta-item fdbt-card__meta-item--hours">
|
||||
<span class="fdbt-meta__icon" aria-hidden="true"><?php echo Fontdelbosc_Transit_Shortcode::icon( 'clock' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- trusted static SVG markup. ?></span>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: 1: days, 2: start time, 3: end time. */
|
||||
esc_html__( 'Operating hours: %1$s %2$s–%3$s', 'fontdelbosc-transit' ),
|
||||
esc_html( (string) $fontdelbosc_period['days'] ),
|
||||
esc_html( (string) $fontdelbosc_period['start'] ),
|
||||
esc_html( (string) $fontdelbosc_period['end'] )
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php if ( '' !== (string) ( $fontdelbosc_zone['url'] ?? '' ) ) : ?>
|
||||
<p class="fdbt-card__link">
|
||||
<a href="<?php echo esc_url( (string) $fontdelbosc_zone['url'] ); ?>" target="_blank" rel="nofollow noopener">
|
||||
<?php esc_html_e( 'Municipal regulations', 'fontdelbosc-transit' ); ?>
|
||||
<span class="fdbt-link__icon" aria-hidden="true"><?php echo Fontdelbosc_Transit_Shortcode::icon( 'external' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- trusted static SVG markup. ?></span>
|
||||
</a>
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
</article>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<footer class="fdbt-footer">
|
||||
<p class="fdbt-footer__source">
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s: source name. */
|
||||
esc_html__( 'Source: %s', 'fontdelbosc-transit' ),
|
||||
'<a href="https://nap.dgt.es/dataset/zonas-de-bajas-emisiones" target="_blank" rel="nofollow noopener">' . esc_html__( 'DGT / Punt d\'Accés Nacional', 'fontdelbosc-transit' ) . '</a>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</footer>
|
||||
</section>
|
||||
38
uninstall.php
Normal file
38
uninstall.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* Uninstall cleanup.
|
||||
*
|
||||
* Data is preserved by default; everything is removed only when the
|
||||
* delete_data_on_uninstall flag is set in the options.
|
||||
*
|
||||
* @package Fontdelbosc_Transit
|
||||
*/
|
||||
|
||||
defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
|
||||
|
||||
$fontdelbosc_transit_options = get_option( 'fontdelbosc_transit_options', array() );
|
||||
|
||||
if ( ! is_array( $fontdelbosc_transit_options ) || empty( $fontdelbosc_transit_options['delete_data_on_uninstall'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete_option( 'fontdelbosc_transit_options' );
|
||||
delete_option( 'fontdelbosc_transit_status' );
|
||||
delete_transient( 'fontdelbosc_transit_incidents' );
|
||||
delete_transient( 'fontdelbosc_transit_incidents_stale' );
|
||||
delete_transient( 'fontdelbosc_transit_2026_notice' );
|
||||
|
||||
$fontdelbosc_transit_index = get_transient( 'fontdelbosc_transit_zbe_index' );
|
||||
|
||||
delete_transient( 'fontdelbosc_transit_zbe_index' );
|
||||
|
||||
$fontdelbosc_transit_zones = array_merge(
|
||||
(array) ( $fontdelbosc_transit_options['zbe_municipalities'] ?? array() ),
|
||||
is_array( $fontdelbosc_transit_index ) ? $fontdelbosc_transit_index : array()
|
||||
);
|
||||
|
||||
foreach ( array_unique( $fontdelbosc_transit_zones ) as $fontdelbosc_transit_slug ) {
|
||||
$fontdelbosc_transit_key = 'fontdelbosc_transit_zbe_' . preg_replace( '/[^A-Za-z0-9\-]/', '', (string) $fontdelbosc_transit_slug );
|
||||
delete_transient( $fontdelbosc_transit_key );
|
||||
delete_transient( $fontdelbosc_transit_key . '_stale' );
|
||||
}
|
||||
Loading…
Reference in a new issue