/** Datei: plugins/rest/hooks/generator/controls.php **/ default", function( array $config, string $name, bool $required ) { return array_replace_recursive([ "key" => $name, "label" => ucfirst( $name ), "type" => REST\Generator\Data\Form\Control\Type::Text, "required" => $required ? "Pflichtfeld" : NULL, "validate" => [ "required" => "Bitte füllen Sie dieses Feld aus!", ], ], $config ); }); /* ### CONTROL TYPES ################################################ # */ Hooks::add("rest.generator::control.type->custom", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Custom, ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->tel", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Tel, "validate" => [ "tel" => "Bitte geben Sie eine korrekte Telefonnummer ein!", ], ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->url", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::URL, "validate" => [ "url" => "Bitte geben Sie eine korrekte URL ein!", ], ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->text", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", $config, $name, $required ) ); }); Hooks::add("rest.generator::control.type->date", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Date, ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->datetime", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::DateTime, ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->time", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Time, ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->file", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::File, ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->range", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Range, ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->email", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Email, "validate" => [ "email" => "Bitte geben Sie eine korrekte E-Mail-Adresse ein!", ], ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->radio", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Radio, "options" => [], ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->select", function( array $config, string $name, bool $required, string|bool $choose = FALSE, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Select, "choose" => $choose == TRUE ? "-- Bitte wählen --" : $choose, "options" => [], ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->hidden", function( array $config, string $name, string $value, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "label" => FALSE, "type" => REST\Generator\Data\Form\Control\Type::Hidden, "value" => $value, ], $config ), $name, FALSE ) ); }); Hooks::add("rest.generator::control.type->textarea", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Textarea, ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->checkbox", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Checkbox, "options" => [], // "validate" => [ // "minChecked" => [ // "value" => 1, // "message" => "Mindestens 2 Optionen auswählen!", // ], // "maxChecked" => [ // "value" => 2, // "message" => "Maximal 2 Optionen auswählen!" // ], // ], ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->password", function( array $config, string $name, bool $confirm, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Password, "confirm" => $confirm ? "Password wiederholen" : FALSE, "validate" => [ "confirm" =>$confirm ? "Die Passwörter stimmen nicht überein!" : FALSE, ], ], $config ), $name, TRUE ) ); }); Hooks::add("rest.generator::control.type->number", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Number, ], $config ), $name, $required ) ); }); Hooks::add("rest.generator::control.type->progress", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Progress, ], $config ), $name, $required ) ); }); /* ### SPECIAL CONTROL TYPES ######################################## # */ Hooks::add("rest.generator::control.type->code", function( array $config, string $name, bool $required, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::control.name->{$name}.{$hook}", Hooks::filter("rest.generator::control->default", array_replace_recursive([ "type" => REST\Generator\Data\Form\Control\Type::Code, ], $config ), $name, $required ) ); }); /* ### CONTROL NAMES ################################################ # */ Hooks::add("rest.generator::control.name->email.*", function( array $config ) { return array_replace_recursive( $config, [ "label" => "E-Mail-Adresse", ]); }); Hooks::add("rest.generator::control.name->status.*", function( array $config ) { return array_replace_recursive( $config, [ "options" => Attribute\Status::getAll(), ]); }); /** Datei: plugins/rest/hooks/generator/actions.php **/ *", function( ...$args ) { $matches = array_pop( $args ); $config = array_shift( $args ); $plugin = array_shift( $args ); $route_id = array_shift( $args ) ?? "id"; $config = Hooks::filter("rest.generator::button.{$matches[0]}->{$matches[1]}", $config, $plugin, $route_id ); $config["title"] = $config["label"]; $config["label"] = NULL; return $config; }); /** Datei: plugins/rest/hooks/generator/buttons.php **/ default", function( array $config, ?string $label ) { if( isset( $config["action"] ) ) $config["action"] = preg_replace( '/\/+/', "/", $config["action"] ); return array_replace_recursive([ "label" => $label, "color" => REST\Generator\Config\Color::Primary, "type" => REST\Generator\Components\Button\Type::Button, ], $config ); }); /* ### BUTTON TYPES ################################################# # */ Hooks::add("rest.generator::button.type->submit", function( array $config, ?string $label, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::button.type->submit.{$hook}", Hooks::filter("rest.generator::button->default", array_replace_recursive([ "icon" => "bi bi-send-fill", "type" => REST\Generator\Components\Button\Type::Submit, ], $config ), $label ?? "Absenden" ) ); }); Hooks::add("rest.generator::button.type->delete", function( array $config, ?string $label, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::button.type->delete.{$hook}", Hooks::filter("rest.generator::button->default", array_replace_recursive([ "icon" => "bi bi-trash", "color" => REST\Generator\Config\Color::Danger, "type" => REST\Generator\Components\Button\Type::Submit, ], $config ), $label ?? "Löschen" ) ); }); Hooks::add("rest.generator::button.type->cancel", function( array $config, ?string $label, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::button.type->cancel.{$hook}", Hooks::filter("rest.generator::button->default", array_replace_recursive([ "icon" => "bi bi-x-lg", "color" => REST\Generator\Config\Color::Primary, "type" => REST\Generator\Components\Button\Type::Cancel, ], $config ), $label ?? "Abbrechen" ) ); }); Hooks::add("rest.generator::button.type->sort", function( array $config, ?string $column, string $order = "asc", ?string $label, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::button.type->sort.{$hook}", Hooks::filter("rest.generator::button->default", array_replace_recursive([ "icon" => "bi bi-sort-down-alt", "color" => REST\Generator\Config\Color::Default, "type" => REST\Generator\Components\Button\Type::Button, "title" => $label ?? "Sortieren", "order" => [ "column" => strtolower( $column ), "order" => strtolower( $order ), ], ], $config ), "" ) ); }); /* ### BUTTON NAMES ################################################# # */ Hooks::add("rest.generator::button.name->create", function( array $config, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::button.name->create.{$hook}", Hooks::filter("rest.generator::button->default", array_replace_recursive([ "name" => "create", "label" => "Hinzufügen", "color" => REST\Generator\Config\Color::Primary, "icon" => "bi bi-plus-lg", "action" => "/{$plugin}/create", ], $config ), NULL ) ); }); Hooks::add("rest.generator::button.name->edit", function( array $config, string $plugin, string $route_id = "id" ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::button.name->edit.{$hook}", Hooks::filter("rest.generator::button->default", array_replace_recursive([ "name" => "edit", "label" => "Bearbeiten", "color" => REST\Generator\Config\Color::Primary, "icon" => "bi bi-pencil", "action" => "/{$plugin}/{{$route_id}}", ], $config ), NULL ) ); }); Hooks::add("rest.generator::button.name->list", function( array $config, string $plugin, string $route_id = "id" ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::button.name->list.{$hook}", Hooks::filter("rest.generator::button->default", array_replace_recursive([ "name" => "list", "label" => "Übersicht", "color" => REST\Generator\Config\Color::Secondary, "icon" => "bi bi-list", "action" => "/{$plugin}/{{$route_id}}", ], $config ), NULL ) ); }); Hooks::add("rest.generator::button.name->link", function( array $config, string $plugin, string $route_id = "id" ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::button.name->link.{$hook}", Hooks::filter("rest.generator::button->default", array_replace_recursive([ "name" => "link", "label" => "Öffnen", "color" => REST\Generator\Config\Color::Default, "icon" => REST\Generator\Config\Icon::BoxArrowUpRight, "href" => $config["action"], "target" => "_blank", ], $config ), NULL ) ); }); Hooks::add("rest.generator::button.name->delete", function( array $config, string $plugin, string $route_id = "id" ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::button.name->delete.{$hook}", Hooks::filter("rest.generator::button->default", array_replace_recursive([ "name" => "delete", "label" => "Löschen", "color" => REST\Generator\Config\Color::Danger, "icon" => "bi bi-trash", "action" => "/{$plugin}/{{$route_id}}/delete", ], $config ), NULL ) ); }); /** Datei: plugins/rest/hooks/generator/enum/icon.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * * @hook config::loaded * * @since 1.0.0 File is created */ $pluginDir = realpath( PLUGINS_DIR ); $hashFile = "{$pluginDir}/rest/assets/bootstrap-icons.hash"; $emojiFile = "{$pluginDir}/rest/assets/icon_emoji.json"; $inputFile = "{$pluginDir}/rest/assets/bootstrap-icons.json"; $outputFile = "{$pluginDir}/rest/library/ARUNOX/Plugins/REST/Generator/Config/Icon.php"; if( !file_exists( $emojiFile ) ) return; if( !file_exists( $inputFile ) ) return; $currentHash = implode( ".", [ md5_file( $inputFile ), md5_file( $emojiFile ), ]); $previousHash = file_exists( $hashFile ) ? file_get_contents( $hashFile ) : ""; if( $currentHash === $previousHash ) return; $emojis = file_get_contents( $emojiFile ); $emojis = json_decode( $emojis, TRUE ); $input = file_get_contents( $inputFile ); $input = json_decode( $input, TRUE ); $output = []; if( !is_array( $input ) ) return; function toReadableEnumCase( string $iconName ): string { $parts = explode("-", $iconName ); if( is_numeric( $parts[0] ) ) { $number = array_shift($parts ); $prev = array_shift($parts ); $parts = array_merge( [ $prev, $number ], $parts ); $parts = array_filter( $parts, fn( $item ) => $item !== NULL ); } return implode("", array_map("ucfirst", $parts ) ); } $input = array_map( fn( $key, $code ) => [ "icon" => "bi-{$key}", "name" => toReadableEnumCase( $key ), "code" => sprintf( '\\%04x', $code ), "emoji" => $emojis["bi-{$key}"] ?? NULL, ], array_keys( $input ), array_values( $input ) ); $input = array_filter( $input, fn( $item ) => !is_numeric( $item["name"] ) ); // show( $input ); $output[] = " \"{$icon["code"]}\","; } $output[] = " };"; $output[] = " }"; $output[] = " public function emoji() {"; $output[] = " return match( \$this ) {"; foreach( $input as $icon ) { $output[] = " Icon::{$icon["name"]} => \"{$icon["emoji"]}\","; } $output[] = " };"; $output[] = " }"; $output[] = " }"; $output = implode( "\n", $output ); // show( htmlentities( $output ) ); file_put_contents( $outputFile, $output ); file_put_contents( $hashFile, $currentHash ); /** Datei: plugins/rest/hooks/generator/columns.php **/ default", function( array $config, string $name, bool $sortable, bool $searchable, bool $visible ) { return array_replace_recursive([ "key" => $name, "label" => ucfirst( $name ), "type" => REST\Generator\Data\Table\Column\Type::Text, "visible" => $visible, "sortable" => $sortable, "searchable" => $searchable, "color" => [ "color" => REST\Generator\Config\Color::Default, "target" => "icon" ], ], $config ); }); /* ### COLUMN TYPES ################################################# # */ Hooks::add("rest.generator::column.type->date", function( array $config, string $name, bool $sortable, bool $searchable, bool $visible, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::column.name->{$name}.{$hook}", Hooks::filter("rest.generator::column->default", array_replace_recursive([ "type" => REST\Generator\Data\Table\Column\Type::Date, ], $config ), $name, $sortable, $searchable, $visible ) ); }); Hooks::add("rest.generator::column.type->tel", function( array $config, string $name, bool $sortable, bool $searchable, bool $visible, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::column.name->{$name}.{$hook}", Hooks::filter("rest.generator::column->default", array_replace_recursive([ "type" => REST\Generator\Data\Table\Column\Type::Tel, ], $config ), $name, $sortable, $searchable, $visible ) ); }); Hooks::add("rest.generator::column.type->url", function( array $config, string $name, bool $sortable, bool $searchable, bool $visible, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::column.name->{$name}.{$hook}", Hooks::filter("rest.generator::column->default", array_replace_recursive([ "type" => REST\Generator\Data\Table\Column\Type::URL, ], $config ), $name, $sortable, $searchable, $visible ) ); }); Hooks::add("rest.generator::column.type->text", function( array $config, string $name, bool $sortable, bool $searchable, bool $visible, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::column.name->{$name}.{$hook}", Hooks::filter("rest.generator::column->default", $config, $name, $sortable, $searchable, $visible ) ); }); Hooks::add("rest.generator::column.type->amount", function( array $config, string $name, bool $sortable, bool $searchable, bool $visible, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::column.name->{$name}.{$hook}", Hooks::filter("rest.generator::column->default", array_replace_recursive([ "type" => REST\Generator\Data\Table\Column\Type::Amount, ], $config ), $name, $sortable, $searchable, $visible ) ); }); Hooks::add("rest.generator::column.type->time", function( array $config, string $name, bool $sortable, bool $searchable, bool $visible, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::column.name->{$name}.{$hook}", Hooks::filter("rest.generator::column->default", array_replace_recursive([ "type" => REST\Generator\Data\Table\Column\Type::Time, ], $config ), $name, $sortable, $searchable, $visible ) ); }); Hooks::add("rest.generator::column.type->email", function( array $config, string $name, bool $sortable, bool $searchable, bool $visible, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::column.name->{$name}.{$hook}", Hooks::filter("rest.generator::column->default", array_replace_recursive([ "type" => REST\Generator\Data\Table\Column\Type::Email, ], $config ), $name, $sortable, $searchable, $visible ) ); }); Hooks::add("rest.generator::column.type->actions", function( array $config, array $buttons, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::column.name->actions.{$hook}", Hooks::filter("rest.generator::column->default", array_replace_recursive([ "type" => REST\Generator\Data\Table\Column\Type::Actions, "buttons" => $buttons, ], $config ), "actions", FALSE, FALSE, TRUE ) ); }); Hooks::add("rest.generator::column.type->datetime", function( array $config, string $name, bool $sortable, bool $searchable, bool $visible, string $plugin ) { $hook = Hooks::parseName( $plugin ); return Hooks::filter("rest.generator::column.name->{$name}.{$hook}", Hooks::filter("rest.generator::column->default", array_replace_recursive([ "type" => REST\Generator\Data\Table\Column\Type::DateTime, ], $config ), $name, $sortable, $searchable, $visible ) ); }); Hooks::add("rest.generator::column.type->icon", function( array $config, string $name, array $options, string $plugin ) { $hook = Hooks::parseName( $plugin ); $config = Hooks::filter("rest.generator::column->default", array_replace_recursive([ "icon" => "bi-toggles", "type" => REST\Generator\Data\Table\Column\Type::Icon, "color" => [ "color" => REST\Generator\Config\Color::Default, "target" => "icon" ], "options" => $options, ], $config ), $name, FALSE, FALSE, TRUE ); return Hooks::filter("rest.generator::column.name->{$name}.{$hook}", array_replace_recursive( $config, [ "title" => $config["label"], "label" => NULL, ])); }); Hooks::add("rest.generator::column.type->status", function( array $config, string $name, array $options, string $plugin, string $route_id = "id" ) { return Hooks::filter("rest.generator::column.type->icon", array_replace_recursive([ "type" => REST\Generator\Data\Table\Column\Type::Status, "action" => [ "method" => "PATCH", "route" => "/api/v1/{$plugin}/{{$route_id}}/{$name}", ], ], $config ), $name, $options, $plugin ); }); /* ### COLUMN NAMES ################################################# # */ Hooks::add("rest.generator::column.name->status.*", function( array $config ) { return array_replace_recursive([ "options" => Attribute\Status::getAll(), ], $config ); }); Hooks::add("rest.generator::column.name->email.*", function( array $config ) { return array_replace_recursive( $config, [ "label" => "E-Mail-Adresse", ]); }); Hooks::add("rest.generator::column.name->date_create.*", function( array $config ) { return array_replace_recursive( $config, [ "label" => "Erstellt am", ]); }); Hooks::add("rest.generator::column.name->date_edit.*", function( array $config ) { return array_replace_recursive( $config, [ "label" => "Bearbeitet am", ]); }); Hooks::add("rest.generator::column.name->actions.*", function( array $config ) { return array_replace_recursive( $config, [ "label" => "Aktionen", ]); }); /** Datei: plugins/rest/hooks/theme.php **/ before", function() { ?>before", function() { $hooks = Filesystem::getDir( PLUGINS_DIR . "/rest/assets/js/hooks" ); $hooks = array_map( fn( $file ) => $file->filename, $hooks->files ); $components = Filesystem::getDir( PLUGINS_DIR . "/rest/assets/js/components" ); $components = array_map( fn( $file ) => $file->filename, $components->files ); ?> $item->path, ARUNOX\Core\Plugins::getPreload() ), array_map( fn( $item ) => $item->path, ARUNOX\Core\Plugins::getActive() ), [ "CURRENT THEME" => THEME->dir->path ], ); $dirs = array_values( $dirs ); $dirs = array_unique( $dirs ); $dirs = array_map( fn( $dir ) => realpath( $dir ), $dirs ); $regex = implode( "|", $dirs ); $files = glob_recursive( "{$root}/*/assets/js/arunox/*.js", GLOB_BRACE ); $files = array_filter( $files, fn( $file ) => preg_match( "#^({$regex})#", $file )); $files = array_merge( glob_recursive( "{$root}/assets/js/arunox/*.js", GLOB_BRACE ), $files ); $files = array_map( fn( $file ) => str_replace( $root, "", "{$file}?_=" . filemtime( $file ) ), $files ); $import = array_merge( $import, $files ); // show( $import ); return $import; }); /** Datei: plugins/rest/hooks/public.php **/ template', function( string $template, string $theme ) { return PLUGINS_DIR . "/rest/templates/index.php"; }); Hooks::add('public::api->init', function() { Router::get( "/api/v1/rest/importmap", function() { return [ "list" => Hooks::filter('router::get->api.v1.rest.importmap', [] ) ]; }); Hooks::add('router::resolve->before', function( $route ) { if( !in_array( $route[0], [ "/rest/routes", "/rest/importmap", ])) return $route; Hooks::remove( "LOGIN_REDIRECT" ); return $route; }, 5 ); Hooks::add('router::resolve->before', function( $route ) { if( isset( $_SERVER["HTTP_AUTHORIZATION"] ) ) { $bearer = preg_replace( "/\s*Bearer\s*/", "", $_SERVER["HTTP_AUTHORIZATION"] ?? "" ); if( $bearer != ARUNOX_API_KEY ) return $route; // if( $bearer != "YXJpLmFydW5veC5kZXY" ) return $route; } else return $route; Hooks::remove( "LOGIN_REDIRECT" ); return $route; }, 5 ); }); /** Datei: plugins/rest/hooks/database/attribute/options/get.php **/ * @copyright 2025 ARUNOX * @version 1.0.0 * * @hook database.attribute.options::get * @param array $option Option * * @since 1.0.0 File is created */ if( isset( $option["emoji"] ) && !empty( $option["emoji"] ) ) return $option; if( !defined( "REST_ICON_EMOJIS_MAP" ) ) { $filename = PLUGINS_DIR . "/rest/assets/icon_emoji.json"; $filename = realpath( $filename ); if( file_exists( $filename ) ) { $iconmap = file_get_contents( $filename ); $iconmap = json_decode( $iconmap, TRUE ); if( $iconmap ) { define( "REST_ICON_EMOJIS_MAP", $iconmap ); } } } if( defined( "REST_ICON_EMOJIS_MAP" ) ) { if( isset( $option["icon"] ) ) { if( is_a( $option["icon"], ARUNOX\Plugins\REST\Generator\Config\Icon::class ) ) { $option["emoji"] = $option["icon"]->emoji(); } else if( preg_match('/\b(bi-[a-z0-9-]+)/i', $option["icon"], $matches ) ) { if( key_exists( $matches[1], REST_ICON_EMOJIS_MAP ) ) { $option["emoji"] = REST_ICON_EMOJIS_MAP[ $matches[1] ]; } } } } return $option; /** Datei: plugins/rest/hooks/rest.php **/ api.v1.rest.importmap', function( array $import = [] ) { $root = ROOT_DIR; $root = realpath( $root ); $dirs = array_merge( array_map( fn( $item ) => $item->path, ARUNOX\Core\Plugins::getPreload() ), array_map( fn( $item ) => $item->path, ARUNOX\Core\Plugins::getActive() ), [ "CUTTENT THEME" => THEME->dir->path ], ); foreach( $dirs as $dir ) { $files = glob_recursive( "{$dir}/*.js" ); $files = array_map( fn( $item ) => str_replace( $root, "", $item ), $files ); $names = array_map( fn( $item ) => preg_replace( '#(themes|plugins)/([^/]+)/\2(?:/?.*)#', '$1/$2', preg_replace( '#.*(themes|plugins)/([^/]+)/(.*/js)/(.*)\.js#', '$1/$2/$4', $item ) ), $files ); $import = array_merge( $import, array_combine( $names, $files ) ); } return $import; }); Hooks::add('router::get->api.v1.rest.routes', function( $routes ) { $routes[] = [ "name" => "content", "label" => Users\Model::isSuperadmin() ? "Content" : "Verwaltung", "menu" => "sidebar", ]; return $routes; }, 10 ); Hooks::add('router::get->api.v1.rest.routes', function( $routes ) { $routes[] = [ "name" => "management", "label" => Users\Model::isSuperadmin() ? "Verwaltung" : "Administration", "menu" => "sidebar", ]; return $routes; }, 80 ); Hooks::add('router::get->api.v1.rest.routes', function( $routes ) { $routes[] = [ "name" => "administration", "label" => "Administration", "menu" => "sidebar", ]; return $routes; }, 100 ); Hooks::add( 'rest::response->data', function( $response ) { $request = new ARUNOX\HTTP\Request(); $columns = $request->getQueryParams( "columns" ); $columns = explode( ",", $columns ?? "" ); $columns = array_filter( $columns ); if( empty( $response ) ) return $response; if( is_a( $response, BaseEntity::class ) ) { $response->hashid; if( empty( $columns ) ) return $response; $data = []; foreach( $columns as $column ) { $data[ $column ] = $response->{$column}; } return $data; } if( !is_array( $response ) ) return $response; if( !is_list( $response ) ) return $response; if( !is_a( $response[0], BaseEntity::class ) ) return $response; foreach( $response as &$entity ) { $entity->hashid; if( empty( $columns ) ) continue; $data = []; foreach( $columns as $column ) { $data[ $column ] = $entity->{$column}; } $entity = $data; } // show($columns, $response); return $response; }); Hooks::add( 'response::data', function( $response ) { if( isset( $response["data"] ) ) { $response["data"] = Hooks::filter( 'rest::response->data', $response["data"] ); } return $response; }); Hooks::add( 'router::dispatch->after', function( $response, $route, $data, ...$args ) { return Hooks::filter( 'rest::response->data', $response ); }); Hooks::add( 'router::resolve->before', function( $route ) { [ $uri, $method ] = $route; if( $uri === "/rest" ) { // REST\Response::addWrapper( "overview" ); REST\Response::jsonResponse()->send(); } return $route; }, 200 );