fediverso-box.php
· 2.0 KiB · PHP
Raw
<?php
/*
Plugin Name: Fediverso Box
Description: Mostra un box per seguire l'autore nel Fediverso.
Version: 1.2
File Version: 5
Last Modified: 2025-08-21
Author: Emanuele Gori
Text Domain: fediverso-box
*/
if (!defined('ABSPATH')) exit;
// Carica sempre CSS e JS per compatibilità con chiamata PHP diretta e shortcode
add_action('wp_enqueue_scripts', function() {
wp_enqueue_style('fediverso-box-style', plugin_dir_url(__FILE__) . 'fediverso-style.css');
wp_enqueue_script('fediverso-box-js', plugin_dir_url(__FILE__) . 'fediverso-script.js', array(), null, true);
});
// Funzione richiamabile sia da shortcode che da PHP
if (!function_exists('fediverso_box')) {
function fediverso_box($atts = array()) {
$author_handle = 'emanuelegori@emanuelegori.uno';
ob_start();
?>
<div class="mastodon-box">
<p>
🇮🇹 <?php echo esc_html__('Ricevi i prossimi articoli direttamente nel tuo feed (i Seguiti) del Fediverso.', 'fediverso-box'); ?>
(<a href="https://fediverso.info/" target="_blank"><?php echo esc_html__('Non conosci il Fediverso?', 'fediverso-box'); ?></a>)<br>
<span><?php echo esc_html__('Segui', 'fediverso-box'); ?> <span><?php echo esc_html($author_handle); ?></span></span>
</p>
<form id="fediFollowForm" autocomplete="off">
<input type="text" id="fediUserInput" placeholder="Istanza es. mastodon.uno">
<button type="submit" id="fediFollowBtn">Segui</button>
</form>
<small>
<?php echo esc_html__('Non hai un account?', 'fediverso-box'); ?>
<a href="https://mastodon.uno/auth/sign_up" target="_blank"><?php echo esc_html__('Crea un profilo gratuito', 'fediverso-box'); ?></a>
</small>
</div>
<?php
return ob_get_clean();
}
}
// Shortcode
add_shortcode('fediverso_box', function($atts) {
return fediverso_box($atts);
});
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 | }); |
51 |
fediverso-script.js
· 782 B · JavaScript
Raw
// Fediverso Box JS
// File Version: 4
// Last Modified: 2025-08-01
// Author: Emanuele Gori
document.addEventListener('DOMContentLoaded', function () {
var form = document.getElementById('fediFollowForm');
if (!form) return;
form.onsubmit = function (e) {
e.preventDefault();
var input = document.getElementById('fediUserInput').value.trim().toLowerCase();
// Permetti solo il dominio dell'istanza, es: mastodon.uno
var match = input.match(/^[a-z0-9.-]+\.[a-z]{2,}$/i);
if (!match) {
alert('Inserisci solo il dominio della tua istanza Mastodon (es: mastodon.uno)');
return false;
}
var url = 'https://' + input + '/authorize_interaction?uri=emanuelegori@emanuelegori.uno';
window.open(url, '_blank');
return false;
};
});
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 | }); |
25 |
fediverso-style.css
· 1.5 KiB · CSS
Raw
/* Fediverso Box CSS
File Version: 2
Last Modified: 21-08-2025
Author: Emanuele Gori
*/
.mastodon-box {
width: 100%;
padding: 20px;
margin: 2rem 0;
border: 1px solid #e5e7eb;
border-radius: 16px;
background: linear-gradient(135deg, #f9fafb, #eef2ff);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
font-family: inherit;
transition: all 0.3s ease;
box-sizing: border-box;
}
.mastodon-box p {
margin: 0 0 12px;
color: #444;
font-size: 15px;
line-height: 1.5;
}
.mastodon-box span {
font-size: 1.1em;
font-weight: 600;
}
.mastodon-box span span {
color: #7c3aed;
}
.mastodon-box #fediFollowForm {
display: flex !important;
gap: 10px !important;
flex-wrap: wrap !important;
}
.mastodon-box #fediUserInput {
flex: 1;
padding: 10px 12px;
border: 1px solid #d1d5db;
border-radius: 8px;
font-size: 14px;
transition: border 0.2s ease;
min-width: 200px;
}
.mastodon-box #fediFollowBtn {
background: #7c3aed;
color: #fff;
padding: 10px 18px;
border: none;
border-radius: 8px;
cursor: pointer;
font-weight: 600;
transition: background 0.2s ease;
white-space: nowrap;
}
.mastodon-box #fediFollowBtn:hover {
background: #5b21b6;
}
.mastodon-box small {
font-size: 13px;
color: #666;
margin-top: 10px;
display: block;
}
.mastodon-box a {
color: #7c3aed;
text-decoration: underline;
}
@media (max-width: 768px) {
.mastodon-box #fediFollowForm {
flex-direction: column;
}
.mastodon-box #fediFollowBtn {
width: 100%;
}
}
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 | } |
88 |