Zuletzt aktiv 1755967063

Plugin Wordpress che mostra un box per seguire l'utente nel Fediverso

emanuelegori hat die Gist bearbeitet 1755967063. Zu Änderung gehen

3 files changed, 161 insertions

fediverso-box.php(Datei erstellt)

@@ -0,0 +1,50 @@
1 + <?php
2 + /*
3 + Plugin Name: Fediverso Box
4 + Description: Mostra un box per seguire l'autore nel Fediverso.
5 + Version: 1.2
6 + File Version: 5
7 + Last Modified: 2025-08-21
8 + Author: Emanuele Gori
9 + Text Domain: fediverso-box
10 + */
11 +
12 + if (!defined('ABSPATH')) exit;
13 +
14 + // Carica sempre CSS e JS per compatibilità con chiamata PHP diretta e shortcode
15 + add_action('wp_enqueue_scripts', function() {
16 + wp_enqueue_style('fediverso-box-style', plugin_dir_url(__FILE__) . 'fediverso-style.css');
17 + wp_enqueue_script('fediverso-box-js', plugin_dir_url(__FILE__) . 'fediverso-script.js', array(), null, true);
18 + });
19 +
20 + // Funzione richiamabile sia da shortcode che da PHP
21 + if (!function_exists('fediverso_box')) {
22 + function fediverso_box($atts = array()) {
23 + $author_handle = 'emanuelegori@emanuelegori.uno';
24 +
25 + ob_start();
26 + ?>
27 + <div class="mastodon-box">
28 + <p>
29 + 🇮🇹 <?php echo esc_html__('Ricevi i prossimi articoli direttamente nel tuo feed (i Seguiti) del Fediverso.', 'fediverso-box'); ?>
30 + (<a href="https://fediverso.info/" target="_blank"><?php echo esc_html__('Non conosci il Fediverso?', 'fediverso-box'); ?></a>)<br>
31 + <span><?php echo esc_html__('Segui', 'fediverso-box'); ?> <span><?php echo esc_html($author_handle); ?></span></span>
32 + </p>
33 + <form id="fediFollowForm" autocomplete="off">
34 + <input type="text" id="fediUserInput" placeholder="Istanza es. mastodon.uno">
35 + <button type="submit" id="fediFollowBtn">Segui</button>
36 + </form>
37 + <small>
38 + <?php echo esc_html__('Non hai un account?', 'fediverso-box'); ?>
39 + <a href="https://mastodon.uno/auth/sign_up" target="_blank"><?php echo esc_html__('Crea un profilo gratuito', 'fediverso-box'); ?></a>
40 + </small>
41 + </div>
42 + <?php
43 + return ob_get_clean();
44 + }
45 + }
46 +
47 + // Shortcode
48 + add_shortcode('fediverso_box', function($atts) {
49 + return fediverso_box($atts);
50 + });

fediverso-script.js(Datei erstellt)

@@ -0,0 +1,24 @@
1 + // Fediverso Box JS
2 + // File Version: 4
3 + // Last Modified: 2025-08-01
4 + // Author: Emanuele Gori
5 +
6 + document.addEventListener('DOMContentLoaded', function () {
7 + var form = document.getElementById('fediFollowForm');
8 + if (!form) return;
9 + form.onsubmit = function (e) {
10 + e.preventDefault();
11 + var input = document.getElementById('fediUserInput').value.trim().toLowerCase();
12 +
13 + // Permetti solo il dominio dell'istanza, es: mastodon.uno
14 + var match = input.match(/^[a-z0-9.-]+\.[a-z]{2,}$/i);
15 + if (!match) {
16 + alert('Inserisci solo il dominio della tua istanza Mastodon (es: mastodon.uno)');
17 + return false;
18 + }
19 +
20 + var url = 'https://' + input + '/authorize_interaction?uri=emanuelegori@emanuelegori.uno';
21 + window.open(url, '_blank');
22 + return false;
23 + };
24 + });

fediverso-style.css(Datei erstellt)

@@ -0,0 +1,87 @@
1 + /* Fediverso Box CSS
2 + File Version: 2
3 + Last Modified: 21-08-2025
4 + Author: Emanuele Gori
5 + */
6 +
7 + .mastodon-box {
8 + width: 100%;
9 + padding: 20px;
10 + margin: 2rem 0;
11 + border: 1px solid #e5e7eb;
12 + border-radius: 16px;
13 + background: linear-gradient(135deg, #f9fafb, #eef2ff);
14 + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
15 + font-family: inherit;
16 + transition: all 0.3s ease;
17 + box-sizing: border-box;
18 + }
19 +
20 + .mastodon-box p {
21 + margin: 0 0 12px;
22 + color: #444;
23 + font-size: 15px;
24 + line-height: 1.5;
25 + }
26 +
27 + .mastodon-box span {
28 + font-size: 1.1em;
29 + font-weight: 600;
30 + }
31 +
32 + .mastodon-box span span {
33 + color: #7c3aed;
34 + }
35 +
36 + .mastodon-box #fediFollowForm {
37 + display: flex !important;
38 + gap: 10px !important;
39 + flex-wrap: wrap !important;
40 + }
41 +
42 + .mastodon-box #fediUserInput {
43 + flex: 1;
44 + padding: 10px 12px;
45 + border: 1px solid #d1d5db;
46 + border-radius: 8px;
47 + font-size: 14px;
48 + transition: border 0.2s ease;
49 + min-width: 200px;
50 + }
51 +
52 + .mastodon-box #fediFollowBtn {
53 + background: #7c3aed;
54 + color: #fff;
55 + padding: 10px 18px;
56 + border: none;
57 + border-radius: 8px;
58 + cursor: pointer;
59 + font-weight: 600;
60 + transition: background 0.2s ease;
61 + white-space: nowrap;
62 + }
63 +
64 + .mastodon-box #fediFollowBtn:hover {
65 + background: #5b21b6;
66 + }
67 +
68 + .mastodon-box small {
69 + font-size: 13px;
70 + color: #666;
71 + margin-top: 10px;
72 + display: block;
73 + }
74 +
75 + .mastodon-box a {
76 + color: #7c3aed;
77 + text-decoration: underline;
78 + }
79 +
80 + @media (max-width: 768px) {
81 + .mastodon-box #fediFollowForm {
82 + flex-direction: column;
83 + }
84 + .mastodon-box #fediFollowBtn {
85 + width: 100%;
86 + }
87 + }
Neuer Älter