feat AdminLibrary: Document all functions and change a couple things.

This commit is contained in:
prplwtf 2024-04-27 15:08:03 +02:00
parent 6701864476
commit 0858f70ee3

View file

@ -15,73 +15,124 @@ class BlueprintAdminLibrary
) { ) {
} }
/**
/* * Fetch a record from the database.
| Databasing *
| * @param string $table Database table
| dbGet("table", "record"); * @param string $record Database record
| dbSet("table", "record", "value"); * @return mixed Database value
*/ *
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/
public function dbGet($table, $record) { public function dbGet($table, $record) {
return $this->settings->get($table."::".$record); return $this->settings->get($table."::".$record);
} }
/**
* Set a database record.
*
* @param string $table Database table
* @param string $record Database record
* @param string $value Value to store
*
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/
public function dbSet($table, $record, $value) { public function dbSet($table, $record, $value) {
return $this->settings->set($table."::".$record, $value); return $this->settings->set($table."::".$record, $value);
} }
/**
/* * Display a notification on the Pterodactyl admin panel (on next page load).
| Notifications *
| * @param string $text Notification contents
| notify("text"); * @return void Nothing is returned
| notifyAfter(delay, "text"); *
| notifyNow("text"); * [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/ */
public function notify($text) { public function notify($text): void {
$this->dbSet("blueprint", "notification:text", $text); $this->dbSet("blueprint", "notification:text", $text);
return; return;
} }
public function notifyAfter($delay, $text) { /**
* Display a notification on the Pterodactyl admin panel and refresh the page after a certain delay.
*
* @param string $delay Refresh after (in seconds)
* @param string $text Notification contents
* @return void Nothing is returned
*
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/
public function notifyAfter($delay, $text): void {
$this->dbSet("blueprint", "notification:text", $text); $this->dbSet("blueprint", "notification:text", $text);
header("Refresh:$delay"); header("Refresh:$delay");
return; return;
} }
public function notifyNow($text) { /**
* Display a notification on the Pterodactyl admin panel and refresh the page instantly.
* Behaves the same as calling `notifyAfter()` with a delay of zero.
*
* @param string $text Notification contents
* @return void Nothing is returned
*
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/
public function notifyNow($text): void {
$this->dbSet("blueprint", "notification:text", $text); $this->dbSet("blueprint", "notification:text", $text);
header("Refresh:0"); header("Refresh:0");
return; return;
} }
/**
/* * Read and returns the content of a given file.
| Files *
| * @param string $path Path to file
| fileRead("path"); * @return string File contents
| fileMake("path"); * @throws string Errors encountered by `cat` shell utility
| fileWipe("path"); *
*/ * [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/
public function fileRead($path) { public function fileRead($path) {
return shell_exec("cat ".escapeshellarg($path).";"); return shell_exec("cat ".escapeshellarg($path).";");
} }
/**
* Attempts to (non-recursively) create a file.
*
* @param string $path File name/path
* @return string Empty string unless error
* @throws string Errors encountered by `touch` shell utility
*
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/
public function fileMake($path) { public function fileMake($path) {
return shell_exec("touch ".escapeshellarg($path).";"); return shell_exec("touch ".escapeshellarg($path).";");
} }
/**
* Attempts to (recursively) remove a file/folder.
* It's good practice to terminate this function after a certain timeout, to prevent infinite page loads upon input. Blueprint attempts to use `yes` as an input for all questions, but might not succeed.
*
* @param string $path Path to file/folder
* @return string Empty string unless error
* @throws string Errors encountered by `rm` shell utility
*
* [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/
public function fileWipe($path) { public function fileWipe($path) {
return shell_exec("rm ".escapeshellarg($path).";"); return shell_exec("yes | rm -r ".escapeshellarg($path).";");
} }
/**
/* * Check if an extension is installed based on it's identifier.
| Extensions *
| * @param string $identifier Extension identifier
| extension("identifier"); * @return bool Boolean
*/ *
public function extension($identifier) { * [BlueprintExtensionLibrary documentation](https://blueprint.zip/docs/?page=documentation/$blueprint)
*/
public function extension($identifier): bool {
if(str_contains($this->fileRead("::f/.blueprint/extensions/blueprint/private/db/installed_extensions"), $identifier.',')) { if(str_contains($this->fileRead("::f/.blueprint/extensions/blueprint/private/db/installed_extensions"), $identifier.',')) {
return true; return true;
} else { } else {