initial commit

This commit is contained in:
boyska 2024-11-09 19:12:24 +01:00
commit ab862b1cee
2 changed files with 299 additions and 0 deletions

134
alberello.php Normal file
View file

@ -0,0 +1,134 @@
<?php
/**
* Plugin Name: Albërellì
* Plugin URI: https://www.your-site.com/
* Description: linktree-like interface for wordpress
* Version: 0.1
* Author: boyska+pinke
* Author URI: https://www.your-site.com/
**/
define('ALB_LINK_URI', 'links');
/* Render {{{ */
function parse_code($text) {
$links = [];
$regexp = '@^(.*)\s+(https?://.*)$@';
foreach(explode("\n", $text) as $line) {
$ret = preg_match($regexp, rtrim($line, "\n\r"), $matches);
if($ret === false || count($matches) < 3) {
continue;
}
$link = [
'text' => rtrim($matches[1]),
'url' => $matches[2]
];
$links[] = $link;
}
return $links;
}
function alb_request() {
$is_front = get_option('alb_option_front');
$uri = $is_front ? '/' : '/' . ALB_LINK_URI;
if($_SERVER["REQUEST_URI"] == $uri ||
$_SERVER["REQUEST_URI"] == '/' . ALB_LINK_URI
) {
$raw = get_option('alb_option_menucode');
$links = parse_code($raw);
// XXX: fai un foglio di stile e una grafica puffosa
echo '<html><head><link href="' . plugins_url('style.css', __FILE__) . '" rel="stylesheet" />';
echo "</head><body><main>\n";
echo "<header><h1>" . get_bloginfo('name') .
"</h1><small class=\"description\">" . get_bloginfo('description') . "</small></header>";
echo "<div class=\"links\">";
foreach($links as $link) {
echo '<a class="link" href="' . esc_html($link['url']) . '">' . esc_html($link['text']) . "</a>";
}
echo "</div>";
echo "</main></body></html>";
exit();
}
}
add_action('init', 'alb_request');
/* Render }}} */
/* Settings page {{{ */
function alb_settings_menu() {
add_options_page('Modifica menu albero', 'Albero dei link', 'activate_plugins', 'alb_settings', 'alb_settings_render', 5);
}
function alb_register_settings() {
register_setting('alb_options', 'alb_option_menucode', 'alb_validate_options');
register_setting('alb_options', 'alb_option_front', 'alb_validate_options');
add_settings_section('alb_menu', 'Menu', 'alb_settings_section_menu', 'alb_settings');
add_settings_field('alb_menucode', 'Versione testuale del menu', 'alb_settings_field_menucode', 'alb_settings', 'alb_menu');
add_settings_field('alb_front', 'Il menu deve sovrascrivere l\'homepage?', 'alb_settings_field_front', 'alb_settings', 'alb_menu');
}
add_action('admin_init', 'alb_register_settings');
function alb_settings() {
}
function alb_settings_render() {
?>
<h2>Albero dei link</h2>
<form action="options.php" method="post">
<?php
settings_fields('alb_options');
do_settings_sections('alb_settings');
?>
<input name="submit" class="button button-primary" type="submit" value="Save" />
</form>
<?php
}
function alb_settings_section_menu() {
$link = get_site_url();
if(!get_option('alb_option_front')) {
$link .= '/' . ALB_LINK_URI;
}
?>
<div>
Il tuo menu è disponibile all'indirizzo <a href="<?php echo $link; ?>"><?php echo esc_html($link); ?></a>
</div>
<?php
}
function alb_settings_field_menucode() {
$value = get_option('alb_option_menucode');
if($value === false) {
$value = "My website " . get_site_url();
}
?>
<textarea style="width: 100%;" id="alb_option_menucode" name="alb_option_menucode" rows="10" wrap="off" type="text" >
<?php
echo esc_html($value);
?>
</textarea>
<div>
<p>Per ogni link che vuoi aggiungere, scrivi il titolo seguito dall'URL.
Vai a capo dopo ogni link.</p>
<p>Esempio:
<pre>
Il mio utente mastodon https://mastodon.bida.im/@noblogs
Il mio sito preferito https://autistici.org/
Un'ottima enciclopedia https://it.wikipedia.org/
</pre></p>
<p>Le righe vuote (o non valide) vengono ignorate</p>
</div>
<?php
}
function alb_settings_field_front() {
$value = get_option('alb_option_front');
?>
<input type="checkbox" <?php echo $value ? 'checked' : '' ?> name="alb_option_front" id="alb_option_front" />
<?php
}
function alb_validate_options( $input ) {
// XXX: protesta quando ci sono linee non vuote che però hanno errori
return $input;
}
add_action('admin_menu', 'alb_settings_menu');
/* Settings page }}} */

165
style.css Normal file
View file

@ -0,0 +1,165 @@
/* Stylesheet for alberello link-tree-style */
@import url(
"https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700;800;900&display=swap");
* {
padding: 0;
margin: 0;
transition: all 0.3s ease-in-out;
}
body {
font-family: "Montserrat", sans-serif;
background-color: #060c21;
}
main {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
a {
text-decoration: none;
font-size: 1.125rem;
font-weight: 600;
}
header { text-align: center;
font-size: 2rem;
font-weight: 700;
margin-bottom: 2rem;
color: white;
padding-top: 10%;
}
.links {
display: flex;
flex-direction: column;
row-gap: 1rem;
}
.link {
height: 3rem;
width: 600px;
display: flex;
align-items: center;
justify-content: center;
color: #000;
margin: 0.5rem 0;
border-radius: 15px;
}
.about {
font-size: 1rem;
font-weight: 500;
margin-bottom: 2rem;
color: white;
}
.link span {
width: 80%;
text-align: center;
}
.link img {
height: 2rem;
aspect-ratio: 1;
}
.linkIcon {
height: 2rem !important;
aspect-ratio: 1;
}
.link:nth-child(1) {
background: #845ec2;
color: white;
}
.link:nth-child(2) {
background: #d65db1;
color: white;
}
.link:nth-child(3) {
background: #ff6f91;
color: white;
}
.link:nth-child(4) {
background: #ff9671;
color: white;
}
.link:nth-child(5) {
background: #ffc75f;
color: white;
}
.link:nth-child(6) {
background: #f9f871;
color: white;
}
.link:nth-child(7) {
background: linear-gradient(90deg,
rgba(241, 241, 241, 0.1) 30%,
rgba(113, 113, 113, 0.3) 100%),
#352e5c;
color: white;
}
.link:nth-child(8) {
background: linear-gradient(90deg,
rgba(241, 241, 241, 0.1) 30%,
rgba(113, 113, 113, 0.3) 100%),
#211d38;
color: white;
}
.link:hover {
filter: drop-shadow(0px 5px 1px rgba(0, 0, 0, 0.2));
transform: scale(1.05);
}
.link>* {
transition: all 0.3s ease-in-out;
transition-delay: 0.1s;
}
.link:hover>* {
transform: scale(1.1);
filter: drop-shadow(0px 5px 1px rgba(0, 0, 0, 0.2));
}
@media (max-width: 600px) {
body {
background-size: 100%;
}
.logo img {
width: 200px;
}
.link span {
width: 70%;
text-align: center;
}
.link {
width: 95vw;
}
.link:hover {
transform: scale(1.01);
}
}