/** Datei: plugins/websites/library/ARUNOX/Plugins/Websites/Themes/Files/Model.php **/ $origin, ], $where ); if( $column ) return Model::getAllValue( $where, $column ); return Model::getAll( $where ); } public static function generate( string $hashid ) { if( !$id = static::resolveHashID( $hashid ) ) return FALSE; if( !$file = static::get( $id ) ) return FALSE; return $file->generate(); } /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: plugins/websites/library/ARUNOX/Plugins/Websites/Themes/Files/API/v1/Routes.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Websites\Themes\Files\API\v1; use ARUNOX\Core\Hooks; use ARUNOX\Core\Router; use ARUNOX\Plugins\REST; class Routes { public static function register() : void { /* ### MAIN ROUTES ############################## # */ Router::addAll( Controller::class ); /* ### MENU ROUTES ############################## # */ Hooks::add('router::get->api.v1.rest.routes', function( $routes ) { $routes[] = [ "path" => Controller::getRoute(), "label" => Controller::getPlural(), "icon" => Controller::getIcon(), "menu" => "websites", ]; return $routes; }, 50 ); } } /** Datei: plugins/websites/library/ARUNOX/Plugins/Websites/Themes/Files/API/v1/Controller.php **/ * @copyright 2025 ARUNOX * @version 1.1.0 * * @since 1.0.0 File is created */ namespace ARUNOX\Plugins\Websites\Themes\Files\API\v1; use ARUNOX\HTTP; use ARUNOX\API\PHP; use ARUNOX\Core\Hooks; use ARUNOX\Plugins\Logs; use ARUNOX\Plugins\REST; use ARUNOX\Plugins\Websites; use ARUNOX\API\BaseController; use ARUNOX\Database\BaseEntity; #[PHP\Attributes\Controller\Label( "File", "Files" )] #[PHP\Attributes\Controller\Icon( REST\Generator\Config\Icon::FiletypeCss )] #[PHP\Attributes\Controller\Route( "files", Websites\Themes\API\v1\Controller::class )] #[PHP\Attributes\Database\Definitions\Model( Websites\Themes\Files\Model::class )] class Controller extends BaseController { /* ### PUBLIC GET FUNCTIONS ##################################### # */ /** * @api * @method GET * * @route.path /websites/themes/files * @route.description Listet alle Logeinträge */ public static function getAllPrepared() : array { return parent::getAllPrepared(); } /** * @api * @method GET * * @route.path /websites/themes/{origin}/files * @route.description Listet alle Logeinträge */ public static function getByOriginPrepared( string $origin ) : array { return parent::getByOriginPrepared( $origin ); } /** * @api * @method GET * * @route.path /websites/themes/files/{hashid} * @route.description Gibt einen einzelnen Logeintrag anhand der ID zurück */ public static function getPrepared( string $hashid ) : BaseEntity | HTTP\Response { return parent::getPrepared( $hashid ); } /* ### PUBLIC SAVE FUNCTIONS #################################### # */ /** * @api * @method PUT * * @route.path /websites/themes/files/{hashid} * @route.description Speichert Änderungen an einem bestehenden Termin */ public static function savePrepared( string $hashid, array $data ) : HTTP\Response { return parent::savePrepared( $hashid, $data ); } /** * @api * @method POST * * @route.path /websites/themes/files * @route.description Erstellt einen neuen Kalender */ public static function createPrepared( array $data ) : HTTP\Response { return parent::createPrepared( $data ); } /** * @internal rest * @method GET * * @route.path /websites/themes/{origin}/files/create * @route.description REST-Konfiguration für das Erstellen eines Kalenders (Formular) */ public static function restConfigCreateByOriginPrepared( bool | string $origin = FALSE ) : REST\Generator\Base\BaseGenerator { return parent::restConfigCreateByOriginPrepared( $origin ); } /** * @api * @method DELETE * * @route.path /websites/themes/files/{hashid} * @route.description Löscht ein Logeintrag anhand der ID */ public static function deletePrepared( string $hashid ) : HTTP\Response { return parent::deletePrepared( $hashid ); } /** * @api * @method PATCH * * @route.path /websites/themes/files/{hashid}/status * @route.description Wechselt den Status (aktiv/inaktiv) eines Kalenders */ public static function toggleStatusPrepared( string $hashid ) : HTTP\Response { return parent::toggleStatusPrepared( $hashid ); } /** * @api * @method PATCH * * @route.path /websites/themes/files/{hashid}/generate * @route.description Wechselt den Status (aktiv/inaktiv) eines Kalenders */ public static function generate( string $hashid ) : HTTP\Response { flush_json([ "value" => 0 ]); Websites\Themes\Files\Model::generate( $hashid ); flush_json([ "value" => 100, "label" => "Kompilierung abgeschlossen" ]); exit; } /* ### PUBLIC VALIDATE FUNCTIONS ################################ # */ /* ### PUBLIC REST RESPONSE FUNCTIONS ########################### # */ /** * @internal rest * @method POST * * @route.path /websites/themes/files * @route.description REST-Antwort nach dem Erstellen eines Kalenders */ public static function restResponseCreate( array $data ) : HTTP\Response { $result = static::createPrepared( $data ); if( $result->isStatus( 200 ) ) { REST\Response::closeModals(); REST\Response::refresh( "#files" ); } return static::restResponse( $result ); } /** * @internal rest * @method PUT * * @route.path /websites/themes/files/{hashid} * @route.description REST-Antwort nach dem Speichern eines Termins */ public static function restResponseSavePrepared( string $hashid, array $data ) : HTTP\Response { return parent::restResponseSavePrepared( $hashid, $data ); } /** * @internal rest * @method DELETE * * @route.path /websites/themes/files/{hashid} * @route.description REST-Antwort nach dem Löschen eines Logeintrag */ public static function restResponseDeletePrepared( string $hashid ) : HTTP\Response { return parent::restResponseDeletePrepared( $hashid ); } /** * @internal rest * @method PATCH * * @route.path /websites/themes/files/{hashid}/status * @route.description REST-Antwort zur Status-Umschaltung eines Kalenders */ public static function restResponseToggleStatusPrepared( string $hashid ) : HTTP\Response { return parent::restResponseToggleStatusPrepared( $hashid ); } /* ### PUBLIC REST CONFIG FUNCTIONS ############################# # */ /** * @internal rest * @method GET * * @route.path /websites/themes/files * @route.description REST-Konfiguration für Logbuch-Tabelle */ public static function restConfigOverview() : REST\Generator\Base\BaseGenerator { $tabs = REST\Response::addWrapper( "details", static::getPlural() )->get(); $tabs = $tabs->addTab( "Übersicht", FALSE )->get() ->setIcon( static::getIcon() ) ->addHeadline( static::getPlural(), 2 ) ->addContent( static::restConfigTable() ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "websites/themes/files" )) ) ->parent(); $tabs = $tabs->addTab( Websites\Menus\API\v1\Controller::getPlural(), "categories" )->get() ->setIcon( Websites\Menus\API\v1\Controller::getIcon() ) ->addHeadline( Websites\Menus\API\v1\Controller::getPlural(), 2 ) ->addContent( Websites\Menus\API\v1\Controller::restConfigTable() ) ->parent(); // $tabs = $tabs->addTab( Calendars\Tasks\Templates\API\v1\Controller::getPlural(), "templates" )->get() // ->setIcon( Calendars\Tasks\Templates\API\v1\Controller::getIcon() ) // ->addHeadline( Calendars\Tasks\Templates\API\v1\Controller::getPlural(), 2 ) // ->addContent( // Calendars\Tasks\Templates\API\v1\Controller::restConfigTable() // ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "websites/tasks/templates" )) // ) // ->parent(); // $tabs = $tabs->addTab( Calendars\Entries\API\v1\Controller::getPlural(), "appointments" )->get() // ->setIcon( Calendars\Entries\API\v1\Controller::getIcon() ) // ->addHeadline( Calendars\Entries\API\v1\Controller::getPlural(), 2 ) // ->addContent( Calendars\Entries\API\v1\Controller::restConfigTable() ) // ->parent(); // // $tabs = $tabs->addTab( Calendars\Tasks\API\v1\Controller::getPlural(), "tasks" )->get() // ->setIcon( Calendars\Tasks\API\v1\Controller::getIcon() ) // ->addHeadline( Calendars\Tasks\API\v1\Controller::getPlural(), 2 ) // ->addContent( Calendars\Tasks\API\v1\Controller::restConfigTable() ) // ->parent(); return $tabs; } /** * @internal rest * @method GET * * @route.path /websites/themes/files/{hashid} * @route.description REST-Konfiguration für Detailansicht eines Logeintrags */ public static function restConfigDetails( string $hashid ) : REST\Generator\Base\BaseGenerator { $current = Websites\Themes\Files\Model::get( $hashid ); $origin = $current->origin->hashid; return REST\Response::addWrapper( "details", static::getSingular( "%t bearbeiten" ) ) ->setBacklink( Websites\Themes\API\v1\Controller::getRoute( $origin, "#files" ) ) ->get() ->setApi( static::getRoute( $hashid ) ) ->setAction( static::getRoute( $hashid ), "PUT" ) ->addTab( static::getSingular() )->get() ->addHeadline( static::getSingular(), 2 ) ->addChildren( static::restConfigInputs() ) ->parent() ->addCallable( [ Logs\API\v1\Controller::class, "restConfigTab" ], $hashid ) ->addTab( "Speichern" )->get() ->setColor( REST\Generator\Config\Color::Primary ) ->setIcon( "bi bi-save" ) ->setType( "submit" ); } /** * @internal rest * @method GET * * @route.path /websites/themes/files/create * @route.description REST-Konfiguration für das Erstellen eines Kalenders (Formular) */ public static function restConfigCreatePrepared() : REST\Generator\Base\BaseGenerator { return parent::restConfigCreatePrepared(); } /** * @internal rest * @method GET * * @route.path /websites/themes/{origin}/files/create * @route.description REST-Konfiguration für das Erstellen eines Kalenders (Formular) */ public static function restConfigAddByOriginPrepared( bool | string $origin = FALSE ) : REST\Generator\Base\BaseGenerator { return parent::restConfigAddByOriginPrepared( $origin ); } /** * @internal rest * @method GET * * @route.path /websites/themes/files/{hashid}/delete * @route.description REST-Konfiguration für die Lösch-Bestätigung eines Logeintrags */ public static function restConfigDeletePrepared( string $hashid ) : REST\Generator\Base\BaseGenerator { return parent::restConfigDeletePrepared( $hashid ); } /** * @internal rest * @method GET * * @route.path /websites/themes/files/{hashid}/generate * @route.description REST-Konfiguration für Detailansicht eines Logeintrags */ public static function restConfigCompile( string $hashid ) : REST\Generator\Base\BaseGenerator { return REST\Response::addModal( "details", static::getSingular( "%t kompilieren" ) ) ->get() ->addField(...Hooks::filter( "rest.generator::control.type->progress", [ "api" => [ "route" => static::getRoute( $hashid, "generate" ), "method" => "PATCH", ], ], "domain", TRUE, "websites/domains" )) ; } /* ### PUBLIC REST EXTENSION FUNCTIONS ########################## # */ public static function restConfigTab( REST\Generator\Base\BaseGenerator $rest, null|string $origin = NULL ) : void { $rest->addTab( static::getLabelGroup(), "files" )->get() ->setIcon( static::getIcon() ) ->addContent( static::restConfigTable( $origin ) ) ; } public static function restConfigTable( null|string $origin = NULL ) : REST\Generator\Base\BaseGenerator { $rest = REST\Generator\Data\Table::create() ->setApi( Websites\Themes\API\v1\Controller::getRoute( $origin, "files" ) ) ->setAction( static::getRoute("{hashid}" ) ) ->setOrder( "filename", "asc" ) ->setSearch( TRUE ) ->addButton(...Hooks::filter( "rest.generator::button.name->create", [], "websites/themes/{$origin}/files" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->status", [ "options" => Websites\Themes\Files\Status::getAll(), ], "status", [], "websites/themes/files", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->icon", [ "label" => Websites\Themes\Files\Type::getSingular(), "icon" => Websites\Themes\Files\Type::getIcon(), "options" => Websites\Themes\Files\Type::getAll(), ], "type", [], "websites/themes/files", "hashid" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->text", [], "filename", TRUE, TRUE, TRUE, "websites/themes/files" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->datetime", [], "date_edit", TRUE, FALSE, TRUE, "websites/themes/files" )) ->addColumn(...Hooks::filter( "rest.generator::column.type->actions", [], [], FALSE, "websites/themes/files" ))->get() ->addButton(...Hooks::filter( "rest.generator::action.name->default", [ "label" => Websites\API\v1\Controller::getSingular( "%t kompilieren" ), "action" => static::getRoute( "{hashid}", "generate" ), "icon" => REST\Generator\Config\Icon::Gear, "color" => REST\Generator\Config\Color::Warning, "visibility" => [ "status" => [ Websites\Themes\Files\Status::Compiling ], "type" => [ Websites\Themes\Files\Type::SCSS ], ], ], "websites/themes/files", "hashid" )) ->addButton(...Hooks::filter( "rest.generator::action.name->edit", [], "websites/themes/files", "hashid" )) ->addButton(...Hooks::filter( "rest.generator::action.name->delete", [], "websites/themes/files", "hashid" )) ; return $rest; } public static function restConfigInputs() : array { $rest = REST\Generator\Data\Form::create() ->addField(...Hooks::filter( "rest.generator::control.type->select", [ "options" => Websites\Themes\Files\Type::getAll(), ], "type", TRUE, FALSE, "websites/themes/files" )) ->addField(...Hooks::filter( "rest.generator::control.type->text", [], "filename", TRUE, "websites/themes/files" )) ->addField(...Hooks::filter( "rest.generator::control.type->textarea", [], "content", FALSE, "websites/themes/files" )) ; return $rest->top()->getChildren(); } public static function restConfigOrigin( bool|string $hashid ) : REST\Generator\Base\BaseGenerator { $rest = REST\Generator\Data\Form::create(); if( $hashid === FALSE ) { return $rest->addField(...Hooks::filter( "rest.generator::control.type->select", [ "options" => Websites\Themes\Model::getAsOptions( "title" ), ], "origin_id", TRUE, FALSE, "projects/steps" )); } $origin = Websites\Themes\Model::getValue( $hashid, "id" ); return $rest->addField(...Hooks::filter( "rest.generator::control.type->hidden", [], "origin_id", $origin ?? $hashid, "projects/steps" )); } } /** Datei: plugins/websites/library/ARUNOX/Plugins/Websites/Themes/Files/Type.php **/ origin_id ); } public function generate( ...$args ) : bool|string { if( $this->type->value == Type::Template ) return $this->generateTemplate( ...$args ); if( $this->status->value != Status::Compiling || $this->type->value != Type::SCSS ) return FALSE; if( !$theme = $this->origin ) return FALSE; $rootAssets = realpath( CACHE_DIR ); $rootAssets = "{$rootAssets}/{$theme->hashid}/assets"; @mkdir( $rootAssets, 0755, TRUE ); if( $this->status->value == Status::Active && $this->type->value != Type::SCSS ) { $ext = match ( $this->type->value ) { Type::CSS => "css", }; $filename = "{$rootAssets}/{$ext}/{$this->filename}.{$ext}"; file_put_contents( $filename, $this->content ); return $filename; } $rootSCSS = "{$rootAssets}/scss"; @mkdir( $rootSCSS, 0755, TRUE ); $files = Model::getByOrigin( $theme->hashid, NULL, [ "status__IN" => [ Status::Active ], "type" => Type::SCSS, ]); foreach( $files as $file ) { $filename = $file->filename; $filename = preg_replace( "/(.*\/)?([a-z_-]+)$/", "\$1_\$2", $filename ); $filename = "{$rootSCSS}/{$filename}.scss"; $dirname = dirname( $filename ); @mkdir( $dirname, 0755, TRUE ); file_put_contents( $filename, $file->content ); } $filename = $this->filename; $filename = "{$rootSCSS}/{$filename}.scss"; $dirname = dirname( $filename ); @mkdir( $dirname, 0755, TRUE ); file_put_contents( $filename, $this->content ); $scss_compiler = new SCSS( "{$rootSCSS}/", "{$rootAssets}/css/" . "/", "{$rootSCSS}/", "expanded", "SOURCE_MAP_NONE" ); $scss_compiler->compile( TRUE ); return "{$rootAssets}/css/{$this->filename}.css"; } /* ### PROTECTED FUNCTIONS ###################################### # */ protected function generateTemplate( $page, $files ) : bool|string { if( $this->status->value != Status::Active ) return FALSE; $variables = [ "page" => $page, "files" => $files, ]; $template = $this->content; $template = Templater::render( $template, $variables ); $template = preg_replace( "/\s+/", " ", $template ); return $template; } /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: plugins/websites/library/ARUNOX/Plugins/Websites/Themes/Files/Status.php **/ parent->type->value === Type::SCSS ) { if( $this->value === static::Active ) { $this->value = Status::Compiling; } } return $this->value; } /* ### MAGIC FUNCTIONS ########################################## # */ }