From 7e2ab63062fd91c302fe5b68a9f74e4f732d59aa Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Sat, 3 Sep 2022 17:23:39 +0100
Subject: [PATCH] Add a plugin to show a banner on abandoned blogs (not ready
 yet)

---
 archived-banner.css | 11 +++++++++++
 archived-banner.js  |  8 ++++++++
 archived-banner.php | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+)
 create mode 100644 archived-banner.css
 create mode 100644 archived-banner.js
 create mode 100644 archived-banner.php

diff --git a/archived-banner.css b/archived-banner.css
new file mode 100644
index 0000000..e0a7e06
--- /dev/null
+++ b/archived-banner.css
@@ -0,0 +1,11 @@
+.archived-banner {
+  width: 100%;
+  text-align: center;
+  z-index: 99999;
+  position: relative;
+  display: block;
+}
+.archived-banner .archived-banner-text {
+  font-weight: 700;
+  padding: 10px 20px;
+}
diff --git a/archived-banner.js b/archived-banner.js
new file mode 100644
index 0000000..a28ff90
--- /dev/null
+++ b/archived-banner.js
@@ -0,0 +1,8 @@
+jQuery(document).ready(function() {
+    if (archivedBannerScriptParams.enabled) {
+        $('<div id="archived-banner" class="archived-banner"><div class="archived-banner-text"><span>'
+          + archivedBannerScriptParams.banner_text
+          + '</span></div>' + closeButton + '</div>')
+            .prependTo('body');
+    }
+});
diff --git a/archived-banner.php b/archived-banner.php
new file mode 100644
index 0000000..f087238
--- /dev/null
+++ b/archived-banner.php
@@ -0,0 +1,38 @@
+<?php
+/*
+ * Plugin Name: A/I - Archived Banner
+ * Description: Add a banner to archived blogs
+ * Version: 0.0.1
+ * Author: Autistici/Inventati
+ * Author URI: https://autistici.org
+ */
+
+/*
+ * This plugin adds a banner at the top of the page for
+ * abandoned websites.
+ */
+
+define('ARCHIVED_BANNER_VERSION', '0.0.1');
+
+function is_blog_abandoned() {
+  $last_post_date = date_create_from_format('Y-m-d H:i:s', get_lastpostdate());
+  $five_years = new DateInterval('P5Y');
+  $five_years_ago = new DateTime();
+  $five_years_ago->sub($five_years);
+
+  return ($last_post_date < $five_years_ago);
+}
+
+add_action('wp_enqueue_scripts', 'ai_archived_blog_banner');
+function ai_archived_blog_banner() {
+  $script_params = array(
+    "enabled" => true,
+    "banner_text" => "This blog is abandoned and is kept for archival purposes only."
+  );
+
+  wp_register_style('archived-banner-style', plugin_dir_url(__FILE__) . 'archived-banner.css', '', ARCHIVED_BANNER_VERSION);
+  wp_enqueue_style('archived-banner-style');
+  wp_register_script('archived-banner-script', plugin_dir_url( __FILE__ ) . 'archived-banner.js', array('jquery'), ARCHIVED_BANNER_VERSION);
+  wp_add_inline_script('archived-banner-script', 'const archivedBannerScriptParams = ' . wp_json_encode($script_params), 'before');
+  wp_enqueue_script('archived-banner-script');
+}
-- 
GitLab