DarkSleeky/user/plugins/ds-backend/plugin.php

80 lines
1.8 KiB
PHP

<?php
/*
Plugin Name: DarkSleeky Backend
Plugin URI: https://sophia.wtf
Description: UI overhaul of the YOURLS backend
Version: 2.4.1
Author: Sophia Atkinson
Author URI: https://sophia.wtf
*/
// No direct call
if( !defined( 'YOURLS_ABSPATH' ) ) die();
// Plugin location URL
$url = yourls_plugin_url( __DIR__ );
yourls_add_action( 'html_head', 'init' );
function init()
{
echo <<<HEAD
<style>body {background: unset;}</style>
HEAD;
}
// Inject Sleeky files
yourls_add_action( 'html_head', 'sleeky_head_scripts' );
function sleeky_head_scripts() {
// This is so the user doesn't have to reload page twice in settings screen
if (isset( $_POST['theme_choice'] )) {
// User has just changed theme
if ($_POST['theme_choice'] == "light") {
setTheme("light");
} else {
setTheme("dark");
}
} else {
// User has not just changed theme
if (yourls_get_option( 'theme_choice' ) == "light") {
setTheme("light");
} else {
setTheme("dark");
}
}
}
// Inject Sleeky files
function setTheme($theme) {
$url = yourls_plugin_url( __DIR__ );
if ($theme == "light") {
echo <<<HEAD
<link rel="stylesheet" href="$url/assets/css/light.css">
<link rel="stylesheet" href="$url/assets/css/animate.min.css">
<script src="$url/assets/js/theme.js"></script>
<meta name="sleeky_theme" content="light">
HEAD;
} else if ($theme == "dark") {
echo <<<HEAD
<link rel="stylesheet" href="$url/assets/css/dark.css">
<link rel="stylesheet" href="$url/assets/css/animate.min.css">
<script src="$url/assets/js/theme.js"></script>
<meta name="sleeky_theme" content="dark">
HEAD;
}
}
// Inject information and options into the frontend
yourls_add_action( 'html_head', 'addOptions' );
function addOptions()
{
$url = yourls_plugin_url( __DIR__ );
echo <<<HEAD
<meta name="pluginURL" content="$url">
HEAD;
}