feat: prima versione del plugin, blocco e shortcode con iframe stampato lato server
This commit is contained in:
commit
5c73bbc2b8
20 changed files with 1562 additions and 0 deletions
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
dist/
|
||||||
|
.DS_Store
|
||||||
|
node_modules/
|
||||||
|
vendor/
|
||||||
338
LICENSE
Normal file
338
LICENSE
Normal file
|
|
@ -0,0 +1,338 @@
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 2, June 1991
|
||||||
|
|
||||||
|
Copyright (C) 1989, 1991 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 licenses for most software are designed to take away your
|
||||||
|
freedom to share and change it. By contrast, the GNU General Public
|
||||||
|
License is intended to guarantee your freedom to share and change free
|
||||||
|
software--to make sure the software is free for all its users. This
|
||||||
|
General Public License applies to most of the Free Software
|
||||||
|
Foundation's software and to any other program whose authors commit to
|
||||||
|
using it. (Some other Free Software Foundation software is covered by
|
||||||
|
the GNU Lesser General Public License instead.) You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
this service if you wish), that you receive source code or can get it
|
||||||
|
if you want it, that you can change the software or use pieces of it
|
||||||
|
in new free programs; and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to make restrictions that forbid
|
||||||
|
anyone to deny you these rights or to ask you to surrender the rights.
|
||||||
|
These restrictions translate to certain responsibilities for you if you
|
||||||
|
distribute copies of the software, or if you modify it.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must give the recipients all the rights that
|
||||||
|
you have. You must make sure that they, too, receive or can get the
|
||||||
|
source code. And you must show them these terms so they know their
|
||||||
|
rights.
|
||||||
|
|
||||||
|
We protect your rights with two steps: (1) copyright the software, and
|
||||||
|
(2) offer you this license which gives you legal permission to copy,
|
||||||
|
distribute and/or modify the software.
|
||||||
|
|
||||||
|
Also, for each author's protection and ours, we want to make certain
|
||||||
|
that everyone understands that there is no warranty for this free
|
||||||
|
software. If the software is modified by someone else and passed on, we
|
||||||
|
want its recipients to know that what they have is not the original, so
|
||||||
|
that any problems introduced by others will not reflect on the original
|
||||||
|
authors' reputations.
|
||||||
|
|
||||||
|
Finally, any free program is threatened constantly by software
|
||||||
|
patents. We wish to avoid the danger that redistributors of a free
|
||||||
|
program will individually obtain patent licenses, in effect making the
|
||||||
|
program proprietary. To prevent this, we have made it clear that any
|
||||||
|
patent must be licensed for everyone's free use or not licensed at all.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. This License applies to any program or other work which contains
|
||||||
|
a notice placed by the copyright holder saying it may be distributed
|
||||||
|
under the terms of this General Public License. The "Program", below,
|
||||||
|
refers to any such program or work, and a "work based on the Program"
|
||||||
|
means either the Program or any derivative work under copyright law:
|
||||||
|
that is to say, a work containing the Program or a portion of it,
|
||||||
|
either verbatim or with modifications and/or translated into another
|
||||||
|
language. (Hereinafter, translation is included without limitation in
|
||||||
|
the term "modification".) Each licensee is addressed as "you".
|
||||||
|
|
||||||
|
Activities other than copying, distribution and modification are not
|
||||||
|
covered by this License; they are outside its scope. The act of
|
||||||
|
running the Program is not restricted, and the output from the Program
|
||||||
|
is covered only if its contents constitute a work based on the
|
||||||
|
Program (independent of having been made by running the Program).
|
||||||
|
Whether that is true depends on what the Program does.
|
||||||
|
|
||||||
|
1. You may copy and distribute verbatim copies of the Program's
|
||||||
|
source code as you receive it, in any medium, provided that you
|
||||||
|
conspicuously and appropriately publish on each copy an appropriate
|
||||||
|
copyright notice and disclaimer of warranty; keep intact all the
|
||||||
|
notices that refer to this License and to the absence of any warranty;
|
||||||
|
and give any other recipients of the Program a copy of this License
|
||||||
|
along with the Program.
|
||||||
|
|
||||||
|
You may charge a fee for the physical act of transferring a copy, and
|
||||||
|
you may at your option offer warranty protection in exchange for a fee.
|
||||||
|
|
||||||
|
2. You may modify your copy or copies of the Program or any portion
|
||||||
|
of it, thus forming a work based on the Program, and copy and
|
||||||
|
distribute such modifications or work under the terms of Section 1
|
||||||
|
above, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) You must cause the modified files to carry prominent notices
|
||||||
|
stating that you changed the files and the date of any change.
|
||||||
|
|
||||||
|
b) You must cause any work that you distribute or publish, that in
|
||||||
|
whole or in part contains or is derived from the Program or any
|
||||||
|
part thereof, to be licensed as a whole at no charge to all third
|
||||||
|
parties under the terms of this License.
|
||||||
|
|
||||||
|
c) If the modified program normally reads commands interactively
|
||||||
|
when run, you must cause it, when started running for such
|
||||||
|
interactive use in the most ordinary way, to print or display an
|
||||||
|
announcement including an appropriate copyright notice and a
|
||||||
|
notice that there is no warranty (or else, saying that you provide
|
||||||
|
a warranty) and that users may redistribute the program under
|
||||||
|
these conditions, and telling the user how to view a copy of this
|
||||||
|
License. (Exception: if the Program itself is interactive but
|
||||||
|
does not normally print such an announcement, your work based on
|
||||||
|
the Program is not required to print an announcement.)
|
||||||
|
|
||||||
|
These requirements apply to the modified work as a whole. If
|
||||||
|
identifiable sections of that work are not derived from the Program,
|
||||||
|
and can be reasonably considered independent and separate works in
|
||||||
|
themselves, then this License, and its terms, do not apply to those
|
||||||
|
sections when you distribute them as separate works. But when you
|
||||||
|
distribute the same sections as part of a whole which is a work based
|
||||||
|
on the Program, the distribution of the whole must be on the terms of
|
||||||
|
this License, whose permissions for other licensees extend to the
|
||||||
|
entire whole, and thus to each and every part regardless of who wrote it.
|
||||||
|
|
||||||
|
Thus, it is not the intent of this section to claim rights or contest
|
||||||
|
your rights to work written entirely by you; rather, the intent is to
|
||||||
|
exercise the right to control the distribution of derivative or
|
||||||
|
collective works based on the Program.
|
||||||
|
|
||||||
|
In addition, mere aggregation of another work not based on the Program
|
||||||
|
with the Program (or with a work based on the Program) on a volume of
|
||||||
|
a storage or distribution medium does not bring the other work under
|
||||||
|
the scope of this License.
|
||||||
|
|
||||||
|
3. You may copy and distribute the Program (or a work based on it,
|
||||||
|
under Section 2) in object code or executable form under the terms of
|
||||||
|
Sections 1 and 2 above provided that you also do one of the following:
|
||||||
|
|
||||||
|
a) Accompany it with the complete corresponding machine-readable
|
||||||
|
source code, which must be distributed under the terms of Sections
|
||||||
|
1 and 2 above on a medium customarily used for software interchange; or,
|
||||||
|
|
||||||
|
b) Accompany it with a written offer, valid for at least three
|
||||||
|
years, to give any third party, for a charge no more than your
|
||||||
|
cost of physically performing source distribution, a complete
|
||||||
|
machine-readable copy of the corresponding source code, to be
|
||||||
|
distributed under the terms of Sections 1 and 2 above on a medium
|
||||||
|
customarily used for software interchange; or,
|
||||||
|
|
||||||
|
c) Accompany it with the information you received as to the offer
|
||||||
|
to distribute corresponding source code. (This alternative is
|
||||||
|
allowed only for noncommercial distribution and only if you
|
||||||
|
received the program in object code or executable form with such
|
||||||
|
an offer, in accord with Subsection b above.)
|
||||||
|
|
||||||
|
The source code for a work means the preferred form of the work for
|
||||||
|
making modifications to it. For an executable work, complete source
|
||||||
|
code means all the source code for all modules it contains, plus any
|
||||||
|
associated interface definition files, plus the scripts used to
|
||||||
|
control compilation and installation of the executable. However, as a
|
||||||
|
special exception, the source code distributed need not include
|
||||||
|
anything that is normally distributed (in either source or binary
|
||||||
|
form) with the major components (compiler, kernel, and so on) of the
|
||||||
|
operating system on which the executable runs, unless that component
|
||||||
|
itself accompanies the executable.
|
||||||
|
|
||||||
|
If distribution of executable or object code is made by offering
|
||||||
|
access to copy from a designated place, then offering equivalent
|
||||||
|
access to copy the source code from the same place counts as
|
||||||
|
distribution of the source code, even though third parties are not
|
||||||
|
compelled to copy the source along with the object code.
|
||||||
|
|
||||||
|
4. You may not copy, modify, sublicense, or distribute the Program
|
||||||
|
except as expressly provided under this License. Any attempt
|
||||||
|
otherwise to copy, modify, sublicense or distribute the Program is
|
||||||
|
void, and will automatically terminate your rights under this License.
|
||||||
|
However, parties who have received copies, or rights, from you under
|
||||||
|
this License will not have their licenses terminated so long as such
|
||||||
|
parties remain in full compliance.
|
||||||
|
|
||||||
|
5. You are not required to accept this License, since you have not
|
||||||
|
signed it. However, nothing else grants you permission to modify or
|
||||||
|
distribute the Program or its derivative works. These actions are
|
||||||
|
prohibited by law if you do not accept this License. Therefore, by
|
||||||
|
modifying or distributing the Program (or any work based on the
|
||||||
|
Program), you indicate your acceptance of this License to do so, and
|
||||||
|
all its terms and conditions for copying, distributing or modifying
|
||||||
|
the Program or works based on it.
|
||||||
|
|
||||||
|
6. Each time you redistribute the Program (or any work based on the
|
||||||
|
Program), the recipient automatically receives a license from the
|
||||||
|
original licensor to copy, distribute or modify the Program subject to
|
||||||
|
these terms and conditions. You may not impose any further
|
||||||
|
restrictions on the recipients' exercise of the rights granted herein.
|
||||||
|
You are not responsible for enforcing compliance by third parties to
|
||||||
|
this License.
|
||||||
|
|
||||||
|
7. If, as a consequence of a court judgment or allegation of patent
|
||||||
|
infringement or for any other reason (not limited to patent issues),
|
||||||
|
conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot
|
||||||
|
distribute so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you
|
||||||
|
may not distribute the Program at all. For example, if a patent
|
||||||
|
license would not permit royalty-free redistribution of the Program by
|
||||||
|
all those who receive copies directly or indirectly through you, then
|
||||||
|
the only way you could satisfy both it and this License would be to
|
||||||
|
refrain entirely from distribution of the Program.
|
||||||
|
|
||||||
|
If any portion of this section is held invalid or unenforceable under
|
||||||
|
any particular circumstance, the balance of the section is intended to
|
||||||
|
apply and the section as a whole is intended to apply in other
|
||||||
|
circumstances.
|
||||||
|
|
||||||
|
It is not the purpose of this section to induce you to infringe any
|
||||||
|
patents or other property right claims or to contest validity of any
|
||||||
|
such claims; this section has the sole purpose of protecting the
|
||||||
|
integrity of the free software distribution system, which is
|
||||||
|
implemented by public license practices. Many people have made
|
||||||
|
generous contributions to the wide range of software distributed
|
||||||
|
through that system in reliance on consistent application of that
|
||||||
|
system; it is up to the author/donor to decide if he or she is willing
|
||||||
|
to distribute software through any other system and a licensee cannot
|
||||||
|
impose that choice.
|
||||||
|
|
||||||
|
This section is intended to make thoroughly clear what is believed to
|
||||||
|
be a consequence of the rest of this License.
|
||||||
|
|
||||||
|
8. If the distribution and/or use of the Program is restricted in
|
||||||
|
certain countries either by patents or by copyrighted interfaces, the
|
||||||
|
original copyright holder who places the Program under this License
|
||||||
|
may add an explicit geographical distribution limitation excluding
|
||||||
|
those countries, so that distribution is permitted only in or among
|
||||||
|
countries not thus excluded. In such case, this License incorporates
|
||||||
|
the limitation as if written in the body of this License.
|
||||||
|
|
||||||
|
9. The Free Software Foundation may publish revised and/or new versions
|
||||||
|
of the General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the Program
|
||||||
|
specifies a version number of this License which applies to it and "any
|
||||||
|
later version", you have the option of following the terms and conditions
|
||||||
|
either of that version or of any later version published by the Free
|
||||||
|
Software Foundation. If the Program does not specify a version number of
|
||||||
|
this License, you may choose any version ever published by the Free Software
|
||||||
|
Foundation.
|
||||||
|
|
||||||
|
10. If you wish to incorporate parts of the Program into other free
|
||||||
|
programs whose distribution conditions are different, write to the author
|
||||||
|
to ask for permission. For software which is copyrighted by the Free
|
||||||
|
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||||
|
make exceptions for this. Our decision will be guided by the two goals
|
||||||
|
of preserving the free status of all derivatives of our free software and
|
||||||
|
of promoting the sharing and reuse of software generally.
|
||||||
|
|
||||||
|
NO WARRANTY
|
||||||
|
|
||||||
|
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||||
|
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||||
|
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||||
|
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||||
|
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||||
|
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||||
|
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||||
|
REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||||
|
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||||
|
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||||
|
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||||
|
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||||
|
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||||
|
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||||
|
POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
convey the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with this program; if not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program is interactive, make it output a short notice like this
|
||||||
|
when it starts in an interactive mode:
|
||||||
|
|
||||||
|
Gnomovision version 69, Copyright (C) year name of author
|
||||||
|
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, the commands you use may
|
||||||
|
be called something other than `show w' and `show c'; they could even be
|
||||||
|
mouse-clicks or menu items--whatever suits your program.
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or your
|
||||||
|
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||||
|
necessary. Here is a sample; alter the names:
|
||||||
|
|
||||||
|
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||||
|
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||||
|
|
||||||
|
<signature of Moe Ghoul>, 1 April 1989
|
||||||
|
Moe Ghoul, President of Vice
|
||||||
|
|
||||||
|
This General Public License does not permit incorporating your program into
|
||||||
|
proprietary programs. If your program is a subroutine library, you may
|
||||||
|
consider it more useful to permit linking proprietary applications with the
|
||||||
|
library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License.
|
||||||
50
README.md
Normal file
50
README.md
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
# Piazza in Festa, plugin WordPress
|
||||||
|
|
||||||
|
Il calendario degli eventi dei comuni italiani dentro un sito WordPress: un blocco, uno shortcode, si aggiorna da solo.
|
||||||
|
|
||||||
|
E' il terzo modo di consumare il widget di [piazzainfesta.it](https://piazzainfesta.it/widget), dopo lo snippet `<script>` e l'iframe a mano. Esiste perche' WordPress filtra i tag `<script>` e `<iframe>` in base ai permessi: passano solo per gli amministratori di installazioni self-hosted, mentre il redattore che nella pratica incolla le cose se li vede sparire senza spiegazioni. Il plugin stampa l'iframe lato server, quindi non c'e' niente da filtrare e funziona per chiunque possa scrivere un articolo.
|
||||||
|
|
||||||
|
## Come e' fatto
|
||||||
|
|
||||||
|
| File | Cosa fa |
|
||||||
|
|---|---|
|
||||||
|
| `piazza-in-festa.php` | header del plugin, costanti, registrazione degli asset |
|
||||||
|
| `includes/render.php` | costruisce l'URL del widget e stampa l'iframe. Unico posto dove si sanifica e unico posto che produce markup |
|
||||||
|
| `includes/shortcode.php` | `[piazza-in-festa comuni="alba,barolo" limite="5"]` |
|
||||||
|
| `includes/block.php` | blocco dinamico: il markup lo fa PHP a ogni caricamento, quindi gli eventi sono sempre quelli di oggi |
|
||||||
|
| `includes/settings.php` | Impostazioni > Piazza in Festa, un campo solo: la chiave per la versione senza marchio |
|
||||||
|
| `blocks/eventi/index.js` | pannello dell'editor, `wp.element.createElement` senza JSX e senza build step: quello che leggi e' quello che gira |
|
||||||
|
| `assets/js/resize.js` | ascolta l'altezza che arriva da dentro l'iframe e adatta il riquadro |
|
||||||
|
|
||||||
|
Niente build: non c'e' `npm`, non c'e' webpack, non c'e' codice minificato. E' una richiesta esplicita delle linee guida di WordPress.org (niente sorgenti nascoste) ed e' anche comodo per noi.
|
||||||
|
|
||||||
|
## Vincoli da non rompere
|
||||||
|
|
||||||
|
Sono le regole che decidono se il plugin resta nella directory:
|
||||||
|
|
||||||
|
- **Niente limitazioni artificiali** (linee guida 5 e 6). Ogni funzione del plugin funziona senza chiave. La chiave e' un'opzione del *servizio*: la inoltra e basta, non abilita niente nel codice.
|
||||||
|
- **Niente codice eseguibile scaricato da fuori** (linea guida 8). Il JS di resize e' locale, non e' il nostro `/widget.js` remoto. Se un domani serve altro JS, va nel plugin, non caricato dal nostro dominio.
|
||||||
|
- **Servizio esterno dichiarato**. La sezione `== External services ==` del `readme.txt` dice cosa parte dal browser del visitatore e verso dove. Se cambiano i parametri inviati, si aggiorna quella sezione.
|
||||||
|
- **Tutto sanificato e tutto in escape**, prefisso `pinfesta_` su ogni funzione e opzione.
|
||||||
|
|
||||||
|
## Build
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./build.sh # -> dist/piazza-in-festa.zip
|
||||||
|
```
|
||||||
|
|
||||||
|
Lo zip contiene una sola cartella `piazza-in-festa/`, ed e' quello che si carica sia su WordPress.org sia in "Aggiungi plugin > Carica plugin".
|
||||||
|
|
||||||
|
## Traduzioni
|
||||||
|
|
||||||
|
Le stringhe sorgente sono in inglese (e' la lingua della directory), l'italiano e' in `languages/`. Le stringhe PHP stanno nel `.mo`, quelle dell'editor in un `.json` a parte perche' vivono in JavaScript. Dopo aver toccato le stringhe:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
msgfmt languages/piazza-in-festa-it_IT.po -o languages/piazza-in-festa-it_IT.mo
|
||||||
|
```
|
||||||
|
|
||||||
|
e rigenera i due `.json` (stesso contenuto, due nomi: WordPress cerca prima per handle dello script, poi per md5 del percorso).
|
||||||
|
|
||||||
|
## Pubblicazione su WordPress.org
|
||||||
|
|
||||||
|
Lo slug lo decide il campo `Plugin Name` alla prima revisione e **non si cambia piu'** dopo l'approvazione. Dopo il via libera si lavora su SVN: `trunk/` piu' un tag per versione, e `.wordpress-org/` per icona e banner.
|
||||||
17
assets/css/widget.css
Normal file
17
assets/css/widget.css
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
/* The widget is an iframe: it only needs to be as wide as its column and to
|
||||||
|
have no border of its own. Everything else lives inside the frame. */
|
||||||
|
.pinfesta-embed {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
border: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pinfesta-empty {
|
||||||
|
margin: 0;
|
||||||
|
padding: 12px 14px;
|
||||||
|
border: 1px dashed currentColor;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-size: 0.9em;
|
||||||
|
opacity: 0.75;
|
||||||
|
}
|
||||||
44
assets/js/resize.js
Normal file
44
assets/js/resize.js
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
/**
|
||||||
|
* Keeps the widget as tall as its content.
|
||||||
|
*
|
||||||
|
* The framed page posts its height whenever it changes; we accept the message
|
||||||
|
* only when it comes from the Piazza in Festa origin and from a window that is
|
||||||
|
* one of our own iframes, then set the height. Nothing else leaves or enters
|
||||||
|
* the page.
|
||||||
|
*/
|
||||||
|
(function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var cfg = window.pinfestaCfg || {};
|
||||||
|
var origin = cfg.origin || '';
|
||||||
|
|
||||||
|
if (!origin) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('message', function (event) {
|
||||||
|
if (event.origin !== origin) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var data = event.data;
|
||||||
|
|
||||||
|
if (!data || data.tipo !== 'piazzainfesta:altezza') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var altezza = parseInt(data.altezza, 10);
|
||||||
|
|
||||||
|
if (!altezza || altezza < 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var frames = document.querySelectorAll('iframe.pinfesta-embed');
|
||||||
|
|
||||||
|
for (var i = 0; i < frames.length; i++) {
|
||||||
|
if (frames[i].contentWindow === event.source) {
|
||||||
|
frames[i].style.height = altezza + 2 + 'px';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})();
|
||||||
27
blocks/eventi/block.json
Normal file
27
blocks/eventi/block.json
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://schemas.wp.org/trunk/block.json",
|
||||||
|
"apiVersion": 3,
|
||||||
|
"name": "piazza-in-festa/eventi",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"title": "Piazza in Festa",
|
||||||
|
"category": "widgets",
|
||||||
|
"icon": "calendar-alt",
|
||||||
|
"description": "Upcoming local events of the towns you follow.",
|
||||||
|
"keywords": ["eventi", "events", "sagre", "calendar", "agenda"],
|
||||||
|
"textdomain": "piazza-in-festa",
|
||||||
|
"supports": {
|
||||||
|
"html": false,
|
||||||
|
"align": ["wide", "full"]
|
||||||
|
},
|
||||||
|
"attributes": {
|
||||||
|
"comuni": { "type": "string", "default": "" },
|
||||||
|
"regione": { "type": "string", "default": "" },
|
||||||
|
"categoria": { "type": "string", "default": "" },
|
||||||
|
"limite": { "type": "string", "default": "5" },
|
||||||
|
"tema": { "type": "string", "default": "chiaro" },
|
||||||
|
"colore": { "type": "string", "default": "" },
|
||||||
|
"titolo": { "type": "string", "default": "" },
|
||||||
|
"altezza": { "type": "string", "default": "320" }
|
||||||
|
},
|
||||||
|
"editorScript": "file:./index.js"
|
||||||
|
}
|
||||||
22
blocks/eventi/index.asset.php
Normal file
22
blocks/eventi/index.asset.php
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Dependencies of the editor script.
|
||||||
|
*
|
||||||
|
* Normally this file is generated by @wordpress/scripts. There is no build
|
||||||
|
* step here (index.js is plain, readable JavaScript), so the list is written
|
||||||
|
* by hand: it is what index.js reads off the wp.* globals, nothing more.
|
||||||
|
*
|
||||||
|
* @package PiazzaInFesta
|
||||||
|
*/
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'dependencies' => array(
|
||||||
|
'wp-blocks',
|
||||||
|
'wp-block-editor',
|
||||||
|
'wp-components',
|
||||||
|
'wp-element',
|
||||||
|
'wp-i18n',
|
||||||
|
'wp-server-side-render',
|
||||||
|
),
|
||||||
|
'version' => '1.0.0',
|
||||||
|
);
|
||||||
151
blocks/eventi/index.js
Normal file
151
blocks/eventi/index.js
Normal file
|
|
@ -0,0 +1,151 @@
|
||||||
|
/**
|
||||||
|
* Editor script for the Piazza in Festa block.
|
||||||
|
*
|
||||||
|
* Written against the wp.* globals with createElement instead of JSX: no build
|
||||||
|
* step, so what ships in the plugin is exactly the source you are reading.
|
||||||
|
* The preview is rendered by PHP (ServerSideRender), so the editor shows the
|
||||||
|
* same events the visitors will see.
|
||||||
|
*/
|
||||||
|
(function (blocks, element, blockEditor, components, i18n, serverSideRender) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var el = element.createElement;
|
||||||
|
var __ = i18n.__;
|
||||||
|
var InspectorControls = blockEditor.InspectorControls;
|
||||||
|
var useBlockProps = blockEditor.useBlockProps;
|
||||||
|
var PanelBody = components.PanelBody;
|
||||||
|
var TextControl = components.TextControl;
|
||||||
|
var SelectControl = components.SelectControl;
|
||||||
|
var ServerSideRender = serverSideRender;
|
||||||
|
|
||||||
|
var CATEGORIE = [
|
||||||
|
{ label: __('All categories', 'piazza-in-festa'), value: '' },
|
||||||
|
{ label: 'Sagre e enogastronomia', value: 'sagra_enogastronomica' },
|
||||||
|
{ label: 'Musica e concerti', value: 'musica_concerto' },
|
||||||
|
{ label: 'Cultura e mostre', value: 'culturale_mostra' },
|
||||||
|
{ label: 'Religioso e patronali', value: 'religioso' },
|
||||||
|
{ label: 'Fiere e mercati', value: 'fiera_mercato' },
|
||||||
|
{ label: 'Mercatini', value: 'mercatini' },
|
||||||
|
{ label: 'Spettacoli e intrattenimento', value: 'spettacolo' },
|
||||||
|
{ label: 'Teatro', value: 'teatro' },
|
||||||
|
{ label: 'Cinema', value: 'cinema' },
|
||||||
|
{ label: 'Sport', value: 'sportivo' },
|
||||||
|
{ label: 'Natura ed escursioni', value: 'natura_escursione' },
|
||||||
|
{ label: 'Bambini e famiglie', value: 'bambini_famiglie' },
|
||||||
|
{ label: 'Incontri e conferenze', value: 'incontro_conferenza' },
|
||||||
|
{ label: 'Istituzionale', value: 'istituzionale' },
|
||||||
|
{ label: 'Altro', value: 'altro' }
|
||||||
|
];
|
||||||
|
|
||||||
|
var REGIONI = [
|
||||||
|
'', 'Abruzzo', 'Basilicata', 'Calabria', 'Campania', 'Emilia-Romagna',
|
||||||
|
'Friuli-Venezia Giulia', 'Lazio', 'Liguria', 'Lombardia', 'Marche',
|
||||||
|
'Molise', 'Piemonte', 'Puglia', 'Sardegna', 'Sicilia', 'Toscana',
|
||||||
|
'Trentino-Alto Adige/Südtirol', 'Umbria', "Valle d'Aosta/Vallée d'Aoste",
|
||||||
|
'Veneto'
|
||||||
|
].map(function (nome) {
|
||||||
|
return { label: nome === '' ? __('No region', 'piazza-in-festa') : nome, value: nome };
|
||||||
|
});
|
||||||
|
|
||||||
|
blocks.registerBlockType('piazza-in-festa/eventi', {
|
||||||
|
edit: function (props) {
|
||||||
|
var a = props.attributes;
|
||||||
|
var set = props.setAttributes;
|
||||||
|
|
||||||
|
function campo(chiave, etichetta, aiuto) {
|
||||||
|
return el(TextControl, {
|
||||||
|
label: etichetta,
|
||||||
|
help: aiuto,
|
||||||
|
value: a[chiave],
|
||||||
|
__next40pxDefaultSize: true,
|
||||||
|
__nextHasNoMarginBottom: true,
|
||||||
|
onChange: function (v) {
|
||||||
|
var patch = {};
|
||||||
|
patch[chiave] = v;
|
||||||
|
set(patch);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var pannello = el(
|
||||||
|
InspectorControls,
|
||||||
|
null,
|
||||||
|
el(
|
||||||
|
PanelBody,
|
||||||
|
{ title: __('Events to show', 'piazza-in-festa'), initialOpen: true },
|
||||||
|
campo(
|
||||||
|
'comuni',
|
||||||
|
__('Towns', 'piazza-in-festa'),
|
||||||
|
__('Comma separated identifiers, for instance: alba, barolo, la-morra', 'piazza-in-festa')
|
||||||
|
),
|
||||||
|
el(SelectControl, {
|
||||||
|
label: __('Or a whole region', 'piazza-in-festa'),
|
||||||
|
value: a.regione,
|
||||||
|
options: REGIONI,
|
||||||
|
disabled: a.comuni !== '',
|
||||||
|
__next40pxDefaultSize: true,
|
||||||
|
__nextHasNoMarginBottom: true,
|
||||||
|
onChange: function (v) {
|
||||||
|
set({ regione: v });
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
el(SelectControl, {
|
||||||
|
label: __('Category', 'piazza-in-festa'),
|
||||||
|
value: a.categoria,
|
||||||
|
options: CATEGORIE,
|
||||||
|
__next40pxDefaultSize: true,
|
||||||
|
__nextHasNoMarginBottom: true,
|
||||||
|
onChange: function (v) {
|
||||||
|
set({ categoria: v });
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
campo('limite', __('How many events', 'piazza-in-festa'), __('From 1 to 20.', 'piazza-in-festa'))
|
||||||
|
),
|
||||||
|
el(
|
||||||
|
PanelBody,
|
||||||
|
{ title: __('Look', 'piazza-in-festa'), initialOpen: false },
|
||||||
|
el(SelectControl, {
|
||||||
|
label: __('Theme', 'piazza-in-festa'),
|
||||||
|
value: a.tema,
|
||||||
|
options: [
|
||||||
|
{ label: __('Light', 'piazza-in-festa'), value: 'chiaro' },
|
||||||
|
{ label: __('Dark', 'piazza-in-festa'), value: 'scuro' }
|
||||||
|
],
|
||||||
|
__next40pxDefaultSize: true,
|
||||||
|
__nextHasNoMarginBottom: true,
|
||||||
|
onChange: function (v) {
|
||||||
|
set({ tema: v });
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
campo('colore', __('Accent colour', 'piazza-in-festa'), __('Hex code, for instance #b4315a.', 'piazza-in-festa')),
|
||||||
|
campo('titolo', __('Heading', 'piazza-in-festa'), __('Leave it empty for no heading.', 'piazza-in-festa')),
|
||||||
|
campo('altezza', __('Starting height (px)', 'piazza-in-festa'), __('It adapts by itself once loaded.', 'piazza-in-festa'))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
var anteprima =
|
||||||
|
a.comuni === '' && a.regione === ''
|
||||||
|
? el(
|
||||||
|
'p',
|
||||||
|
{ className: 'pinfesta-empty' },
|
||||||
|
__('Piazza in Festa: set at least one town or a region in the block settings.', 'piazza-in-festa')
|
||||||
|
)
|
||||||
|
: el(ServerSideRender, {
|
||||||
|
block: 'piazza-in-festa/eventi',
|
||||||
|
attributes: a
|
||||||
|
});
|
||||||
|
|
||||||
|
return el('div', useBlockProps(), pannello, anteprima);
|
||||||
|
},
|
||||||
|
save: function () {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(
|
||||||
|
window.wp.blocks,
|
||||||
|
window.wp.element,
|
||||||
|
window.wp.blockEditor,
|
||||||
|
window.wp.components,
|
||||||
|
window.wp.i18n,
|
||||||
|
window.wp.serverSideRender
|
||||||
|
);
|
||||||
33
build.sh
Executable file
33
build.sh
Executable file
|
|
@ -0,0 +1,33 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
# Costruisce lo zip da caricare su WordPress.org e da mettere in download sul
|
||||||
|
# sito. Dentro c'e' una sola cartella `piazza-in-festa/`, come si aspetta chi
|
||||||
|
# installa da "Aggiungi plugin > Carica plugin".
|
||||||
|
#
|
||||||
|
# ./build.sh -> dist/piazza-in-festa.zip
|
||||||
|
#
|
||||||
|
# Nello zip finisce SOLO quello che serve a far girare il plugin: niente .git,
|
||||||
|
# niente sorgenti di sviluppo, niente questo script.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
|
||||||
|
SLUG="piazza-in-festa"
|
||||||
|
VERSIONE=$(grep -m1 "^ \* Version:" piazza-in-festa.php | awk '{print $3}')
|
||||||
|
DIST="dist"
|
||||||
|
STAGE="$DIST/$SLUG"
|
||||||
|
|
||||||
|
rm -rf "$DIST"
|
||||||
|
mkdir -p "$STAGE"
|
||||||
|
|
||||||
|
# Elenco esplicito invece di una lista di esclusioni: se domani si aggiunge un
|
||||||
|
# file di sviluppo, non finisce nello zip per distrazione.
|
||||||
|
cp piazza-in-festa.php uninstall.php readme.txt LICENSE "$STAGE/"
|
||||||
|
cp -R includes blocks assets languages "$STAGE/"
|
||||||
|
|
||||||
|
# Le traduzioni sorgente (.po) non servono a chi installa, il .mo si'.
|
||||||
|
rm -f "$STAGE/languages/"*.po
|
||||||
|
|
||||||
|
( cd "$DIST" && zip -qr "$SLUG.zip" "$SLUG" )
|
||||||
|
rm -rf "$STAGE"
|
||||||
|
|
||||||
|
echo "$DIST/$SLUG.zip (versione $VERSIONE, $(du -h "$DIST/$SLUG.zip" | cut -f1))"
|
||||||
52
includes/block.php
Normal file
52
includes/block.php
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* The editor block. Dynamic: the markup is produced by PHP at render time, so
|
||||||
|
* the events are always the ones of today and never a copy frozen in the post
|
||||||
|
* content.
|
||||||
|
*
|
||||||
|
* @package PiazzaInFesta
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers the block from its block.json.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function pinfesta_register_block() {
|
||||||
|
$type = register_block_type(
|
||||||
|
PINFESTA_DIR . 'blocks/eventi',
|
||||||
|
array( 'render_callback' => 'pinfesta_render_block' )
|
||||||
|
);
|
||||||
|
|
||||||
|
// The editor strings live in JavaScript, so they need their own JSON
|
||||||
|
// catalogue. The handle is read back from the registered block instead of
|
||||||
|
// being guessed: WordPress builds it from block.json and it can change.
|
||||||
|
if ( $type && ! empty( $type->editor_script_handles ) ) {
|
||||||
|
foreach ( $type->editor_script_handles as $handle ) {
|
||||||
|
wp_set_script_translations( $handle, 'piazza-in-festa', PINFESTA_DIR . 'languages' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action( 'init', 'pinfesta_register_block' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the block on the front end and in the editor preview.
|
||||||
|
*
|
||||||
|
* @param array $attributes Block attributes.
|
||||||
|
* @return string HTML.
|
||||||
|
*/
|
||||||
|
function pinfesta_render_block( $attributes ) {
|
||||||
|
$args = wp_parse_args( (array) $attributes, pinfesta_defaults() );
|
||||||
|
|
||||||
|
$html = pinfesta_render_iframe( $args );
|
||||||
|
|
||||||
|
if ( '' === $html ) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$wrapper = get_block_wrapper_attributes();
|
||||||
|
|
||||||
|
return '<div' . ( '' === $wrapper ? '' : ' ' . $wrapper ) . '>' . $html . '</div>';
|
||||||
|
}
|
||||||
172
includes/render.php
Normal file
172
includes/render.php
Normal file
|
|
@ -0,0 +1,172 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Builds the widget URL and renders the iframe. Shared by the shortcode and
|
||||||
|
* the block: both end up here, so there is a single place where parameters are
|
||||||
|
* sanitised and a single place where markup is produced.
|
||||||
|
*
|
||||||
|
* @package PiazzaInFesta
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default values for every supported parameter.
|
||||||
|
*
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
function pinfesta_defaults() {
|
||||||
|
return array(
|
||||||
|
'comuni' => '',
|
||||||
|
'regione' => '',
|
||||||
|
'categoria' => '',
|
||||||
|
'limite' => '5',
|
||||||
|
'tema' => 'chiaro',
|
||||||
|
'colore' => '',
|
||||||
|
'titolo' => '',
|
||||||
|
'altezza' => '320',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Categories accepted by the service. Anything else is dropped instead of
|
||||||
|
* being forwarded, so a typo shows every event rather than none.
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
function pinfesta_categorie() {
|
||||||
|
return array(
|
||||||
|
'religioso',
|
||||||
|
'sagra_enogastronomica',
|
||||||
|
'musica_concerto',
|
||||||
|
'culturale_mostra',
|
||||||
|
'incontro_conferenza',
|
||||||
|
'fiera_mercato',
|
||||||
|
'mercatini',
|
||||||
|
'sportivo',
|
||||||
|
'natura_escursione',
|
||||||
|
'spettacolo',
|
||||||
|
'teatro',
|
||||||
|
'cinema',
|
||||||
|
'bambini_famiglie',
|
||||||
|
'istituzionale',
|
||||||
|
'altro',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cleans a comma separated list of town identifiers (the slug you see in the
|
||||||
|
* address of a town page, for instance "la-morra"). Twelve at most, which is
|
||||||
|
* what the service accepts.
|
||||||
|
*
|
||||||
|
* @param string $raw Raw attribute value.
|
||||||
|
* @return string Normalised list, empty when nothing survives.
|
||||||
|
*/
|
||||||
|
function pinfesta_clean_comuni( $raw ) {
|
||||||
|
$out = array();
|
||||||
|
|
||||||
|
foreach ( explode( ',', (string) $raw ) as $item ) {
|
||||||
|
$slug = sanitize_title( trim( $item ) );
|
||||||
|
|
||||||
|
if ( '' !== $slug ) {
|
||||||
|
$out[] = $slug;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return implode( ',', array_slice( array_unique( $out ), 0, 12 ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turns the parameters into the URL of the widget page on the service.
|
||||||
|
*
|
||||||
|
* @param array $args Parameters, already merged with the defaults.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function pinfesta_build_url( $args ) {
|
||||||
|
$query = array();
|
||||||
|
|
||||||
|
$comuni = pinfesta_clean_comuni( $args['comuni'] );
|
||||||
|
|
||||||
|
if ( '' !== $comuni ) {
|
||||||
|
$query['comune'] = $comuni;
|
||||||
|
} elseif ( '' !== $args['regione'] ) {
|
||||||
|
$query['regione'] = sanitize_text_field( $args['regione'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( in_array( $args['categoria'], pinfesta_categorie(), true ) ) {
|
||||||
|
$query['categoria'] = $args['categoria'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$limite = absint( $args['limite'] );
|
||||||
|
|
||||||
|
if ( $limite > 0 ) {
|
||||||
|
$query['limite'] = min( $limite, 20 );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( 'scuro' === $args['tema'] ) {
|
||||||
|
$query['tema'] = 'scuro';
|
||||||
|
}
|
||||||
|
|
||||||
|
$colore = sanitize_hex_color( $args['colore'] );
|
||||||
|
|
||||||
|
if ( $colore ) {
|
||||||
|
// Without the hash: add_query_arg() leaves "#" as it is, and a bare "#"
|
||||||
|
// in a URL opens the fragment, which would swallow this parameter and
|
||||||
|
// every parameter after it. The service accepts the six digits alone.
|
||||||
|
$query['accent'] = ltrim( $colore, '#' );
|
||||||
|
}
|
||||||
|
|
||||||
|
$titolo = sanitize_text_field( $args['titolo'] );
|
||||||
|
|
||||||
|
if ( '' !== $titolo ) {
|
||||||
|
$query['titolo'] = $titolo;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Service key: optional. It only tells the service that this site may ask
|
||||||
|
// for the version without the Piazza in Festa credit line; every feature of
|
||||||
|
// this plugin works exactly the same with or without it.
|
||||||
|
$chiave = pinfesta_get_option( 'chiave' );
|
||||||
|
|
||||||
|
if ( '' !== $chiave ) {
|
||||||
|
$query['chiave'] = $chiave;
|
||||||
|
$query['marchio'] = '0';
|
||||||
|
}
|
||||||
|
|
||||||
|
return add_query_arg( $query, pinfesta_base_url() . '/embed' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the widget.
|
||||||
|
*
|
||||||
|
* An iframe, on purpose: the CSS of the host site cannot break the widget and
|
||||||
|
* the widget cannot break the host site. The height arrives from the framed
|
||||||
|
* page via postMessage (assets/js/resize.js), so nobody has to guess it; the
|
||||||
|
* `altezza` parameter is only the starting height, and what visitors see when
|
||||||
|
* JavaScript is off.
|
||||||
|
*
|
||||||
|
* @param array $args Parameters, already merged with the defaults.
|
||||||
|
* @return string HTML.
|
||||||
|
*/
|
||||||
|
function pinfesta_render_iframe( $args ) {
|
||||||
|
$args = wp_parse_args( $args, pinfesta_defaults() );
|
||||||
|
|
||||||
|
if ( '' === pinfesta_clean_comuni( $args['comuni'] ) && '' === trim( (string) $args['regione'] ) ) {
|
||||||
|
if ( ! current_user_can( 'edit_posts' ) ) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return '<p class="pinfesta-empty">' . esc_html__( 'Piazza in Festa: set at least one town or a region.', 'piazza-in-festa' ) . '</p>';
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_enqueue_style( 'pinfesta-widget' );
|
||||||
|
wp_enqueue_script( 'pinfesta-resize' );
|
||||||
|
|
||||||
|
$altezza = absint( $args['altezza'] );
|
||||||
|
$altezza = ( $altezza >= 120 && $altezza <= 4000 ) ? $altezza : 320;
|
||||||
|
|
||||||
|
return sprintf(
|
||||||
|
'<iframe class="pinfesta-embed" src="%1$s" title="%2$s" height="%3$d" loading="lazy" scrolling="no" referrerpolicy="no-referrer-when-downgrade"></iframe>',
|
||||||
|
esc_url( pinfesta_build_url( $args ) ),
|
||||||
|
esc_attr__( 'Upcoming local events', 'piazza-in-festa' ),
|
||||||
|
$altezza
|
||||||
|
);
|
||||||
|
}
|
||||||
148
includes/settings.php
Normal file
148
includes/settings.php
Normal file
|
|
@ -0,0 +1,148 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Settings screen (Settings > Piazza in Festa).
|
||||||
|
*
|
||||||
|
* One field only: the optional service key. The plugin does everything it can
|
||||||
|
* do without it; the key just lets the service serve the widget without the
|
||||||
|
* small Piazza in Festa credit line at the bottom.
|
||||||
|
*
|
||||||
|
* @package PiazzaInFesta
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads one saved option.
|
||||||
|
*
|
||||||
|
* @param string $key Option key.
|
||||||
|
* @return string Empty string when unset.
|
||||||
|
*/
|
||||||
|
function pinfesta_get_option( $key ) {
|
||||||
|
$options = get_option( 'pinfesta_options', array() );
|
||||||
|
|
||||||
|
if ( ! is_array( $options ) || ! isset( $options[ $key ] ) ) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return (string) $options[ $key ];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers the setting and its field.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function pinfesta_register_settings() {
|
||||||
|
register_setting(
|
||||||
|
'pinfesta_settings',
|
||||||
|
'pinfesta_options',
|
||||||
|
array(
|
||||||
|
'type' => 'array',
|
||||||
|
'sanitize_callback' => 'pinfesta_sanitize_options',
|
||||||
|
'default' => array(),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
add_settings_section(
|
||||||
|
'pinfesta_section',
|
||||||
|
'',
|
||||||
|
'__return_false',
|
||||||
|
'piazza-in-festa'
|
||||||
|
);
|
||||||
|
|
||||||
|
add_settings_field(
|
||||||
|
'pinfesta_chiave',
|
||||||
|
esc_html__( 'Service key', 'piazza-in-festa' ),
|
||||||
|
'pinfesta_field_chiave',
|
||||||
|
'piazza-in-festa',
|
||||||
|
'pinfesta_section'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
add_action( 'admin_init', 'pinfesta_register_settings' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sanitises the saved options.
|
||||||
|
*
|
||||||
|
* @param mixed $input Raw value coming from the form.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function pinfesta_sanitize_options( $input ) {
|
||||||
|
$out = array();
|
||||||
|
|
||||||
|
if ( is_array( $input ) && isset( $input['chiave'] ) ) {
|
||||||
|
// Keys are hexadecimal strings; anything else is not a key.
|
||||||
|
$chiave = preg_replace( '/[^a-zA-Z0-9]/', '', (string) $input['chiave'] );
|
||||||
|
|
||||||
|
$out['chiave'] = substr( (string) $chiave, 0, 128 );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints the key field.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function pinfesta_field_chiave() {
|
||||||
|
printf(
|
||||||
|
'<input type="text" class="regular-text" name="pinfesta_options[chiave]" value="%s" autocomplete="off" />',
|
||||||
|
esc_attr( pinfesta_get_option( 'chiave' ) )
|
||||||
|
);
|
||||||
|
|
||||||
|
echo '<p class="description">' . esc_html__( 'Optional. Leave it empty and the widget works anyway, with a small credit line at the bottom.', 'piazza-in-festa' ) . '</p>';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the menu entry.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function pinfesta_admin_menu() {
|
||||||
|
add_options_page(
|
||||||
|
esc_html__( 'Piazza in Festa', 'piazza-in-festa' ),
|
||||||
|
esc_html__( 'Piazza in Festa', 'piazza-in-festa' ),
|
||||||
|
'manage_options',
|
||||||
|
'piazza-in-festa',
|
||||||
|
'pinfesta_settings_page'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
add_action( 'admin_menu', 'pinfesta_admin_menu' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints the settings page.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function pinfesta_settings_page() {
|
||||||
|
if ( ! current_user_can( 'manage_options' ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<div class="wrap">
|
||||||
|
<h1><?php echo esc_html__( 'Piazza in Festa', 'piazza-in-festa' ); ?></h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<?php echo esc_html__( 'Add the events with the block called Piazza in Festa, or with this shortcode:', 'piazza-in-festa' ); ?>
|
||||||
|
<code>[piazza-in-festa comuni="alba,barolo,la-morra" limite="5"]</code>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<?php
|
||||||
|
printf(
|
||||||
|
/* translators: %s: link to the online configurator. */
|
||||||
|
esc_html__( 'Not sure about the identifiers of your towns? Build the widget here and copy the values: %s', 'piazza-in-festa' ),
|
||||||
|
'<a href="' . esc_url( pinfesta_base_url() . '/widget' ) . '" target="_blank" rel="noopener noreferrer">' . esc_html( pinfesta_base_url() . '/widget' ) . '</a>'
|
||||||
|
);
|
||||||
|
?>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<form action="options.php" method="post">
|
||||||
|
<?php
|
||||||
|
settings_fields( 'pinfesta_settings' );
|
||||||
|
do_settings_sections( 'piazza-in-festa' );
|
||||||
|
submit_button();
|
||||||
|
?>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
28
includes/shortcode.php
Normal file
28
includes/shortcode.php
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* The [piazza-in-festa] shortcode.
|
||||||
|
*
|
||||||
|
* Attribute names are Italian because the data is Italian: they match the town
|
||||||
|
* identifiers and the parameters documented on piazzainfesta.it, so what you
|
||||||
|
* read there is what you write here.
|
||||||
|
*
|
||||||
|
* [piazza-in-festa comuni="alba,barolo,la-morra" limite="5"]
|
||||||
|
* [piazza-in-festa regione="Piemonte" categoria="sagra_enogastronomica"]
|
||||||
|
*
|
||||||
|
* @package PiazzaInFesta
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the shortcode.
|
||||||
|
*
|
||||||
|
* @param array|string $atts Shortcode attributes.
|
||||||
|
* @return string HTML.
|
||||||
|
*/
|
||||||
|
function pinfesta_shortcode( $atts ) {
|
||||||
|
$args = shortcode_atts( pinfesta_defaults(), $atts, 'piazza-in-festa' );
|
||||||
|
|
||||||
|
return pinfesta_render_iframe( $args );
|
||||||
|
}
|
||||||
|
add_shortcode( 'piazza-in-festa', 'pinfesta_shortcode' );
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
{
|
||||||
|
"translation-revision-date": "2026-09-04 12:00+0000",
|
||||||
|
"generator": "manuale (nessun build step)",
|
||||||
|
"domain": "messages",
|
||||||
|
"locale_data": {
|
||||||
|
"messages": {
|
||||||
|
"": {
|
||||||
|
"domain": "messages",
|
||||||
|
"lang": "it_IT",
|
||||||
|
"plural-forms": "nplurals=2; plural=(n != 1);"
|
||||||
|
},
|
||||||
|
"All categories": [
|
||||||
|
"Tutte le categorie"
|
||||||
|
],
|
||||||
|
"No region": [
|
||||||
|
"Nessuna regione"
|
||||||
|
],
|
||||||
|
"Events to show": [
|
||||||
|
"Quali eventi mostrare"
|
||||||
|
],
|
||||||
|
"Towns": [
|
||||||
|
"Comuni"
|
||||||
|
],
|
||||||
|
"Comma separated identifiers, for instance: alba, barolo, la-morra": [
|
||||||
|
"Identificativi separati da virgola, per esempio: alba, barolo, la-morra"
|
||||||
|
],
|
||||||
|
"Or a whole region": [
|
||||||
|
"Oppure una regione intera"
|
||||||
|
],
|
||||||
|
"Category": [
|
||||||
|
"Categoria"
|
||||||
|
],
|
||||||
|
"How many events": [
|
||||||
|
"Quanti eventi"
|
||||||
|
],
|
||||||
|
"From 1 to 20.": [
|
||||||
|
"Da 1 a 20."
|
||||||
|
],
|
||||||
|
"Look": [
|
||||||
|
"Aspetto"
|
||||||
|
],
|
||||||
|
"Theme": [
|
||||||
|
"Tema"
|
||||||
|
],
|
||||||
|
"Light": [
|
||||||
|
"Chiaro"
|
||||||
|
],
|
||||||
|
"Dark": [
|
||||||
|
"Scuro"
|
||||||
|
],
|
||||||
|
"Accent colour": [
|
||||||
|
"Colore d'accento"
|
||||||
|
],
|
||||||
|
"Hex code, for instance #b4315a.": [
|
||||||
|
"Codice esadecimale, per esempio #b4315a."
|
||||||
|
],
|
||||||
|
"Heading": [
|
||||||
|
"Titolo"
|
||||||
|
],
|
||||||
|
"Leave it empty for no heading.": [
|
||||||
|
"Lascialo vuoto per non avere titolo."
|
||||||
|
],
|
||||||
|
"Starting height (px)": [
|
||||||
|
"Altezza iniziale (px)"
|
||||||
|
],
|
||||||
|
"It adapts by itself once loaded.": [
|
||||||
|
"Si adatta da sola appena carica."
|
||||||
|
],
|
||||||
|
"Piazza in Festa: set at least one town or a region in the block settings.": [
|
||||||
|
"Piazza in Festa: indica almeno un comune o una regione nelle impostazioni del blocco."
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
{
|
||||||
|
"translation-revision-date": "2026-09-04 12:00+0000",
|
||||||
|
"generator": "manuale (nessun build step)",
|
||||||
|
"domain": "messages",
|
||||||
|
"locale_data": {
|
||||||
|
"messages": {
|
||||||
|
"": {
|
||||||
|
"domain": "messages",
|
||||||
|
"lang": "it_IT",
|
||||||
|
"plural-forms": "nplurals=2; plural=(n != 1);"
|
||||||
|
},
|
||||||
|
"All categories": [
|
||||||
|
"Tutte le categorie"
|
||||||
|
],
|
||||||
|
"No region": [
|
||||||
|
"Nessuna regione"
|
||||||
|
],
|
||||||
|
"Events to show": [
|
||||||
|
"Quali eventi mostrare"
|
||||||
|
],
|
||||||
|
"Towns": [
|
||||||
|
"Comuni"
|
||||||
|
],
|
||||||
|
"Comma separated identifiers, for instance: alba, barolo, la-morra": [
|
||||||
|
"Identificativi separati da virgola, per esempio: alba, barolo, la-morra"
|
||||||
|
],
|
||||||
|
"Or a whole region": [
|
||||||
|
"Oppure una regione intera"
|
||||||
|
],
|
||||||
|
"Category": [
|
||||||
|
"Categoria"
|
||||||
|
],
|
||||||
|
"How many events": [
|
||||||
|
"Quanti eventi"
|
||||||
|
],
|
||||||
|
"From 1 to 20.": [
|
||||||
|
"Da 1 a 20."
|
||||||
|
],
|
||||||
|
"Look": [
|
||||||
|
"Aspetto"
|
||||||
|
],
|
||||||
|
"Theme": [
|
||||||
|
"Tema"
|
||||||
|
],
|
||||||
|
"Light": [
|
||||||
|
"Chiaro"
|
||||||
|
],
|
||||||
|
"Dark": [
|
||||||
|
"Scuro"
|
||||||
|
],
|
||||||
|
"Accent colour": [
|
||||||
|
"Colore d'accento"
|
||||||
|
],
|
||||||
|
"Hex code, for instance #b4315a.": [
|
||||||
|
"Codice esadecimale, per esempio #b4315a."
|
||||||
|
],
|
||||||
|
"Heading": [
|
||||||
|
"Titolo"
|
||||||
|
],
|
||||||
|
"Leave it empty for no heading.": [
|
||||||
|
"Lascialo vuoto per non avere titolo."
|
||||||
|
],
|
||||||
|
"Starting height (px)": [
|
||||||
|
"Altezza iniziale (px)"
|
||||||
|
],
|
||||||
|
"It adapts by itself once loaded.": [
|
||||||
|
"Si adatta da sola appena carica."
|
||||||
|
],
|
||||||
|
"Piazza in Festa: set at least one town or a region in the block settings.": [
|
||||||
|
"Piazza in Festa: indica almeno un comune o una regione nelle impostazioni del blocco."
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
languages/piazza-in-festa-it_IT.mo
Normal file
BIN
languages/piazza-in-festa-it_IT.mo
Normal file
Binary file not shown.
122
languages/piazza-in-festa-it_IT.po
Normal file
122
languages/piazza-in-festa-it_IT.po
Normal file
|
|
@ -0,0 +1,122 @@
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: Piazza in Festa 1.0.0\n"
|
||||||
|
"Report-Msgid-Bugs-To: https://piazzainfesta.it/contatti\n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
"Language: it_IT\n"
|
||||||
|
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
|
||||||
|
"X-Domain: piazza-in-festa\n"
|
||||||
|
|
||||||
|
#: piazza-in-festa.php
|
||||||
|
msgid "Settings"
|
||||||
|
msgstr "Impostazioni"
|
||||||
|
|
||||||
|
#: includes/render.php
|
||||||
|
msgid "Piazza in Festa: set at least one town or a region."
|
||||||
|
msgstr "Piazza in Festa: indica almeno un comune o una regione."
|
||||||
|
|
||||||
|
#: includes/render.php
|
||||||
|
msgid "Upcoming local events"
|
||||||
|
msgstr "Eventi in arrivo in zona"
|
||||||
|
|
||||||
|
#: includes/settings.php
|
||||||
|
msgid "Service key"
|
||||||
|
msgstr "Chiave del servizio"
|
||||||
|
|
||||||
|
#: includes/settings.php
|
||||||
|
msgid "Optional. Leave it empty and the widget works anyway, with a small credit line at the bottom."
|
||||||
|
msgstr "Facoltativa. Lasciala vuota e il widget funziona lo stesso, con una riga piccola in fondo che dice da dove arrivano gli eventi."
|
||||||
|
|
||||||
|
#: includes/settings.php
|
||||||
|
msgid "Piazza in Festa"
|
||||||
|
msgstr "Piazza in Festa"
|
||||||
|
|
||||||
|
#: includes/settings.php
|
||||||
|
msgid "Add the events with the block called Piazza in Festa, or with this shortcode:"
|
||||||
|
msgstr "Metti gli eventi con il blocco Piazza in Festa, oppure con questo shortcode:"
|
||||||
|
|
||||||
|
#: includes/settings.php
|
||||||
|
msgid "Not sure about the identifiers of your towns? Build the widget here and copy the values: %s"
|
||||||
|
msgstr "Non sai come si scrivono i tuoi comuni? Costruisci il widget qui e copia i valori: %s"
|
||||||
|
|
||||||
|
#: blocks/eventi/index.js
|
||||||
|
msgid "All categories"
|
||||||
|
msgstr "Tutte le categorie"
|
||||||
|
|
||||||
|
#: blocks/eventi/index.js
|
||||||
|
msgid "No region"
|
||||||
|
msgstr "Nessuna regione"
|
||||||
|
|
||||||
|
#: blocks/eventi/index.js
|
||||||
|
msgid "Events to show"
|
||||||
|
msgstr "Quali eventi mostrare"
|
||||||
|
|
||||||
|
#: blocks/eventi/index.js
|
||||||
|
msgid "Towns"
|
||||||
|
msgstr "Comuni"
|
||||||
|
|
||||||
|
#: blocks/eventi/index.js
|
||||||
|
msgid "Comma separated identifiers, for instance: alba, barolo, la-morra"
|
||||||
|
msgstr "Identificativi separati da virgola, per esempio: alba, barolo, la-morra"
|
||||||
|
|
||||||
|
#: blocks/eventi/index.js
|
||||||
|
msgid "Or a whole region"
|
||||||
|
msgstr "Oppure una regione intera"
|
||||||
|
|
||||||
|
#: blocks/eventi/index.js
|
||||||
|
msgid "Category"
|
||||||
|
msgstr "Categoria"
|
||||||
|
|
||||||
|
#: blocks/eventi/index.js
|
||||||
|
msgid "How many events"
|
||||||
|
msgstr "Quanti eventi"
|
||||||
|
|
||||||
|
#: blocks/eventi/index.js
|
||||||
|
msgid "From 1 to 20."
|
||||||
|
msgstr "Da 1 a 20."
|
||||||
|
|
||||||
|
#: blocks/eventi/index.js
|
||||||
|
msgid "Look"
|
||||||
|
msgstr "Aspetto"
|
||||||
|
|
||||||
|
#: blocks/eventi/index.js
|
||||||
|
msgid "Theme"
|
||||||
|
msgstr "Tema"
|
||||||
|
|
||||||
|
#: blocks/eventi/index.js
|
||||||
|
msgid "Light"
|
||||||
|
msgstr "Chiaro"
|
||||||
|
|
||||||
|
#: blocks/eventi/index.js
|
||||||
|
msgid "Dark"
|
||||||
|
msgstr "Scuro"
|
||||||
|
|
||||||
|
#: blocks/eventi/index.js
|
||||||
|
msgid "Accent colour"
|
||||||
|
msgstr "Colore d'accento"
|
||||||
|
|
||||||
|
#: blocks/eventi/index.js
|
||||||
|
msgid "Hex code, for instance #b4315a."
|
||||||
|
msgstr "Codice esadecimale, per esempio #b4315a."
|
||||||
|
|
||||||
|
#: blocks/eventi/index.js
|
||||||
|
msgid "Heading"
|
||||||
|
msgstr "Titolo"
|
||||||
|
|
||||||
|
#: blocks/eventi/index.js
|
||||||
|
msgid "Leave it empty for no heading."
|
||||||
|
msgstr "Lascialo vuoto per non avere titolo."
|
||||||
|
|
||||||
|
#: blocks/eventi/index.js
|
||||||
|
msgid "Starting height (px)"
|
||||||
|
msgstr "Altezza iniziale (px)"
|
||||||
|
|
||||||
|
#: blocks/eventi/index.js
|
||||||
|
msgid "It adapts by itself once loaded."
|
||||||
|
msgstr "Si adatta da sola appena carica."
|
||||||
|
|
||||||
|
#: blocks/eventi/index.js
|
||||||
|
msgid "Piazza in Festa: set at least one town or a region in the block settings."
|
||||||
|
msgstr "Piazza in Festa: indica almeno un comune o una regione nelle impostazioni del blocco."
|
||||||
105
piazza-in-festa.php
Normal file
105
piazza-in-festa.php
Normal file
|
|
@ -0,0 +1,105 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Plugin Name: Piazza in Festa
|
||||||
|
* Plugin URI: https://piazzainfesta.it/widget
|
||||||
|
* Description: Show the upcoming local events of the Italian towns you follow: village feasts, concerts, fairs, exhibitions. Shortcode and block, updated daily.
|
||||||
|
* Version: 1.0.0
|
||||||
|
* Requires at least: 6.5
|
||||||
|
* Requires PHP: 7.4
|
||||||
|
* Author: Piazza in Festa
|
||||||
|
* Author URI: https://piazzainfesta.it
|
||||||
|
* License: GPL-2.0-or-later
|
||||||
|
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
* Text Domain: piazza-in-festa
|
||||||
|
* Domain Path: /languages
|
||||||
|
*
|
||||||
|
* @package PiazzaInFesta
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
define( 'PINFESTA_VERSION', '1.0.0' );
|
||||||
|
define( 'PINFESTA_FILE', __FILE__ );
|
||||||
|
define( 'PINFESTA_DIR', plugin_dir_path( __FILE__ ) );
|
||||||
|
define( 'PINFESTA_URL', plugin_dir_url( __FILE__ ) );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base URL of the service that serves the widget.
|
||||||
|
*
|
||||||
|
* Kept in a filter so a site can point the plugin at a staging instance
|
||||||
|
* without editing the plugin files.
|
||||||
|
*
|
||||||
|
* @return string Base URL, without trailing slash.
|
||||||
|
*/
|
||||||
|
function pinfesta_base_url() {
|
||||||
|
/**
|
||||||
|
* Filters the base URL of the Piazza in Festa service.
|
||||||
|
*
|
||||||
|
* @param string $url Base URL, without trailing slash.
|
||||||
|
*/
|
||||||
|
$url = apply_filters( 'pinfesta_base_url', 'https://piazzainfesta.it' );
|
||||||
|
|
||||||
|
return untrailingslashit( esc_url_raw( $url ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once PINFESTA_DIR . 'includes/render.php';
|
||||||
|
require_once PINFESTA_DIR . 'includes/shortcode.php';
|
||||||
|
require_once PINFESTA_DIR . 'includes/block.php';
|
||||||
|
require_once PINFESTA_DIR . 'includes/settings.php';
|
||||||
|
|
||||||
|
// Translations are not loaded by hand: WordPress finds them on its own, both
|
||||||
|
// the ones from translate.wordpress.org and the bundled ones in /languages
|
||||||
|
// (Domain Path in the header above). Verified on WordPress 7.1 with an it_IT
|
||||||
|
// site: calling load_plugin_textdomain() changes nothing and Plugin Check
|
||||||
|
// flags it as discouraged since 4.6.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers the front end assets.
|
||||||
|
*
|
||||||
|
* They are only enqueued when a widget is actually rendered (see
|
||||||
|
* pinfesta_render_iframe), so a page without the block or the shortcode does
|
||||||
|
* not load anything.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function pinfesta_register_assets() {
|
||||||
|
wp_register_style(
|
||||||
|
'pinfesta-widget',
|
||||||
|
PINFESTA_URL . 'assets/css/widget.css',
|
||||||
|
array(),
|
||||||
|
PINFESTA_VERSION
|
||||||
|
);
|
||||||
|
|
||||||
|
wp_register_script(
|
||||||
|
'pinfesta-resize',
|
||||||
|
PINFESTA_URL . 'assets/js/resize.js',
|
||||||
|
array(),
|
||||||
|
PINFESTA_VERSION,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
wp_localize_script(
|
||||||
|
'pinfesta-resize',
|
||||||
|
'pinfestaCfg',
|
||||||
|
array( 'origin' => pinfesta_base_url() )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
add_action( 'init', 'pinfesta_register_assets' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a settings link on the plugins list, next to Deactivate.
|
||||||
|
*
|
||||||
|
* @param array $links Existing action links.
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function pinfesta_action_links( $links ) {
|
||||||
|
$url = admin_url( 'options-general.php?page=piazza-in-festa' );
|
||||||
|
|
||||||
|
array_unshift(
|
||||||
|
$links,
|
||||||
|
'<a href="' . esc_url( $url ) . '">' . esc_html__( 'Settings', 'piazza-in-festa' ) . '</a>'
|
||||||
|
);
|
||||||
|
|
||||||
|
return $links;
|
||||||
|
}
|
||||||
|
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'pinfesta_action_links' );
|
||||||
88
readme.txt
Normal file
88
readme.txt
Normal file
|
|
@ -0,0 +1,88 @@
|
||||||
|
=== Piazza in Festa ===
|
||||||
|
Contributors: thisloke
|
||||||
|
Tags: events, calendar, agenda, italy, local
|
||||||
|
Requires at least: 6.5
|
||||||
|
Tested up to: 7.1
|
||||||
|
Requires PHP: 7.4
|
||||||
|
Stable tag: 1.0.0
|
||||||
|
License: GPLv2 or later
|
||||||
|
License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
|
|
||||||
|
Show the upcoming local events of the Italian towns you follow: village feasts, concerts, fairs, exhibitions. A block, a shortcode, updated daily.
|
||||||
|
|
||||||
|
== Description ==
|
||||||
|
|
||||||
|
Piazza in Festa collects the events of Italian towns from the notices that town halls and other public bodies are required to publish (the *albo pretorio*), and turns them into a readable calendar. This plugin puts that calendar on your site.
|
||||||
|
|
||||||
|
You pick the towns you care about, or a whole region. The list updates by itself every day: nobody on your side has to type events in, and nothing is copied into your database.
|
||||||
|
|
||||||
|
= What you get =
|
||||||
|
|
||||||
|
* A **block** called Piazza in Festa, with a live preview while you edit.
|
||||||
|
* A **shortcode**, `[piazza-in-festa comuni="alba,barolo,la-morra" limite="5"]`, for classic editor, widgets and page builders.
|
||||||
|
* Filters by town, region and category, from village feasts to concerts, markets, exhibitions and sport.
|
||||||
|
* Light and dark theme, your own accent colour, your own heading.
|
||||||
|
* Nothing to maintain: no cron job, no cache to purge, no import.
|
||||||
|
|
||||||
|
= Where the events come from =
|
||||||
|
|
||||||
|
Every event is reconstructed from a public document: an ordinance closing a street for the procession, a resolution granting patronage to the fair, an authorisation for the concert. Small towns included, the ones no manual calendar ever reaches. Titles and descriptions are written by AI systems reading those documents, so they can contain mistakes; each event links back to the town page where the original source is shown.
|
||||||
|
|
||||||
|
= Free, and what is not =
|
||||||
|
|
||||||
|
The plugin is free and complete: every option described here works, with or without an account. The widget shows a small credit line at the bottom pointing back to Piazza in Festa. Site owners who prefer it without that line can ask the service for a key and paste it in the settings; that is an option of the service, not a feature locked inside this plugin.
|
||||||
|
|
||||||
|
== External services ==
|
||||||
|
|
||||||
|
This plugin displays events served by **Piazza in Festa**, an external service run by the plugin author.
|
||||||
|
|
||||||
|
When a visitor opens a page that contains the block or the shortcode, their browser loads a page from `https://piazzainfesta.it/embed` with the parameters you configured: the towns or the region, the category, how many events to show, and the appearance options (theme, colour, heading). If you saved a service key in the settings, the key is part of that address as well.
|
||||||
|
|
||||||
|
As with any embedded content, that request reaches the service with the visitor's IP address and browser user agent. The plugin sends nothing from your server, stores nothing about your visitors, and sets no cookies of its own.
|
||||||
|
|
||||||
|
* Service: [Piazza in Festa](https://piazzainfesta.it)
|
||||||
|
* Terms and conditions: [piazzainfesta.it/termini-e-condizioni](https://piazzainfesta.it/termini-e-condizioni)
|
||||||
|
* Privacy policy: [piazzainfesta.it/privacy-policy](https://piazzainfesta.it/privacy-policy)
|
||||||
|
|
||||||
|
== Installation ==
|
||||||
|
|
||||||
|
1. Install and activate the plugin.
|
||||||
|
2. Edit a page and add the block named **Piazza in Festa**, or write the shortcode `[piazza-in-festa comuni="alba,barolo"]`.
|
||||||
|
3. In the block settings, type the identifiers of the towns you follow, separated by commas.
|
||||||
|
|
||||||
|
The identifier of a town is the one you see in the address of its page on piazzainfesta.it: for La Morra it is `la-morra`. If you are not sure, build the widget at [piazzainfesta.it/widget](https://piazzainfesta.it/widget) and copy the values.
|
||||||
|
|
||||||
|
== Frequently Asked Questions ==
|
||||||
|
|
||||||
|
= Do I need an account? =
|
||||||
|
|
||||||
|
No. The plugin works right away, without registering anything.
|
||||||
|
|
||||||
|
= Which towns are covered? =
|
||||||
|
|
||||||
|
All Italian towns, in every region. How many events a town has depends on how much it publishes: some publish a lot, some very little.
|
||||||
|
|
||||||
|
= How many towns can one widget show? =
|
||||||
|
|
||||||
|
Up to twelve. For a wider area use `regione` instead, or place more than one widget.
|
||||||
|
|
||||||
|
= The events are not the ones I expected =
|
||||||
|
|
||||||
|
Each event comes from a public document of a town, so the widget shows what has been published, not everything that happens. If you find a wrong or missing event, the page of the event on piazzainfesta.it has a link to report it.
|
||||||
|
|
||||||
|
= Does it slow my site down? =
|
||||||
|
|
||||||
|
No. The widget is an iframe loaded lazily by the browser: your pages are built and cached exactly as before, and your server never talks to ours.
|
||||||
|
|
||||||
|
= Can I remove the credit line? =
|
||||||
|
|
||||||
|
Yes, with a service key from Piazza in Festa, pasted in Settings > Piazza in Festa. Everything else in the plugin behaves the same either way.
|
||||||
|
|
||||||
|
= Can I style it like my site? =
|
||||||
|
|
||||||
|
You can set the theme (light or dark), the accent colour and the heading. The rest lives inside the frame, on purpose: that way your CSS cannot break the widget and the widget cannot break your layout.
|
||||||
|
|
||||||
|
== Changelog ==
|
||||||
|
|
||||||
|
= 1.0.0 =
|
||||||
|
* First release: block, shortcode, filters by town, region and category, light and dark theme, accent colour, automatic height.
|
||||||
13
uninstall.php
Normal file
13
uninstall.php
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Removes what the plugin saved, when the plugin is deleted.
|
||||||
|
*
|
||||||
|
* One option, nothing else: the events are not copied into the site, they are
|
||||||
|
* fetched live, so there is no leftover content to clean up.
|
||||||
|
*
|
||||||
|
* @package PiazzaInFesta
|
||||||
|
*/
|
||||||
|
|
||||||
|
defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
|
||||||
|
|
||||||
|
delete_option( 'pinfesta_options' );
|
||||||
Loading…
Add table
Add a link
Reference in a new issue