Explorar o código

allow customizing HestiaCP with js/php (#2747)

* allow customizing HestiaCP with js/php

make a folder where everything that loads init.js will load additional .js/.php files, allowing people to customize their HestiaCP control panels.

I must admit, I have not studied the HestiaCP plugin system, and if it turns out that the plugin system is superior to this folder, please tell me about it :) I couldn't really find documentation on the plugin system

* code-breaking typos

* make CI run again (CI is bugging out)

* simplify code

i think the only thing htmlentities did was to encode "+" characters, which isn't required when using RAWurlencode, and im not even sure it was actually required with normal urlencode.

* DirectoryIterator isn't static-callable

ick

* make CI run again (i think it's bugging out?)
divinity76 %!s(int64=3) %!d(string=hai) anos
pai
achega
cfe36df591

+ 9 - 0
web/js/custom_scripts/README.txt

@@ -0,0 +1,9 @@
+.js and .php files placed in this directory will automatically be included in scripts loading init.js.
+
+subfolders will be ignored (recursive file loading is not supported. you're free to create sub-folders, but they will not be invoked automatically.)
+
+These custom files will perist across HestiaCP upgrades.
+
+This directory is not meant for HestiaCP development, but meant for people wantng to customize their own HestiaCP control panel.
+
+Warning: modifications to this README.txt may be lost during HestiaCP upgrades.

+ 7 - 1
web/templates/includes/end_js.html

@@ -7,6 +7,13 @@
 <script src="/js/init.js?<?=JS_LATEST_UPDATE?>"></script>
 <script src="/js/i18n.js.php?<?=JS_LATEST_UPDATE?>"></script>
 <script src="/js/templates.js?<?=JS_LATEST_UPDATE?>"></script>
+<?php foreach(new DirectoryIterator($_SERVER['HESTIA'].'/web/js/custom_scripts') as $customScript){ 
+	if($customScript->getExtension() === 'js'){
+		echo '<script src="/js/custom_scripts/'.rawurlencode($customScript->getBasename()).'"></script>';
+	} elseif($customScript->getExtension() === "php"){
+		require_once($customScript->getPathname());
+	}
+ } ?>
 <script>
 	$(function() {
 		hover_menu();
@@ -43,4 +50,3 @@
 <?php
 	unset($_SESSION['error_msg']);
 	endif;
-?>

+ 7 - 0
web/templates/pages/list_server_info.html

@@ -15,6 +15,13 @@
 	<script src="/js/init.js?<?=JS_LATEST_UPDATE?>"></script>
 	<script src="/js/i18n.js.php?<?=JS_LATEST_UPDATE?>"></script>
 	<script src="/js/templates.js?<?=JS_LATEST_UPDATE?>"></script>
+	<?php foreach(new DirectoryIterator($_SERVER['HESTIA'].'/web/js/custom_scripts') as $customScript){ 
+		if($customScript->getExtension() === 'js'){
+			echo '<script src="/js/custom_scripts/'.rawurlencode($customScript->getBasename()).'"></script>';
+		} elseif($customScript->getExtension() === "php"){
+			require_once($customScript->getPathname());
+		}
+	 } ?>
 </head>
 
 <body>

+ 7 - 0
web/templates/pages/list_weblog.html

@@ -15,6 +15,13 @@
 	<script src="/js/init.js?<?=JS_LATEST_UPDATE?>"></script>
 	<script src="/js/i18n.js.php?<?=JS_LATEST_UPDATE?>"></script>
 	<script src="/js/templates.js?<?=JS_LATEST_UPDATE?>"></script>
+	<?php foreach(new DirectoryIterator($_SERVER['HESTIA'].'/web/js/custom_scripts') as $customScript){ 
+		if($customScript->getExtension() === 'js'){
+			echo '<script src="/js/custom_scripts/'.rawurlencode($customScript->getBasename()).'"></script>';
+		} elseif($customScript->getExtension() === "php"){
+			require_once($customScript->getPathname());
+		}
+	 } ?>
 </head>
 
 <body>