diff --git a/src/library/Box/TwigExtensions.php b/src/library/Box/TwigExtensions.php
index eb8994ed7..ec3db31f9 100644
--- a/src/library/Box/TwigExtensions.php
+++ b/src/library/Box/TwigExtensions.php
@@ -133,6 +133,7 @@ class Box_TwigExtensions extends AbstractExtension implements InjectionAwareInte
public function getFunctions()
{
return [
+ new TwigFunction('render_widgets', $this->twig_render_widgets(...), ['needs_environment' => true, 'is_safe' => ['html']]),
new TwigFunction('svg_sprite', $this->twig_svg_sprite(...), ['needs_environment' => true, 'is_safe' => ['html']]),
// FOSSBilling API functions
@@ -152,6 +153,45 @@ class Box_TwigExtensions extends AbstractExtension implements InjectionAwareInte
return 'bb';
}
+ /**
+ * Part of the Widgets module. Renders the widgets of a specified slot.
+ *
+ * @param \Twig\Environment $env the Twig environment (injected automatically)
+ * @param string $slot name of the slot
+ * @param array $context optional slot context, such as order or client details
+ *
+ * @return string slot content
+ */
+ public function twig_render_widgets(\Twig\Environment $env, string $slot, array $context = []): string
+ {
+ $widgets = $this->di['mod_service']('Widgets')->getSlotWidgets($slot);
+
+ if (empty($widgets)) {
+ return '';
+ }
+
+ $output = '';
+
+ foreach ($widgets as $widget) {
+ try {
+ $templateName = 'widgets/' . $widget['template'] . '.html.twig';
+ $output .= $env->render($templateName, $context);
+ } catch (\Throwable $e) {
+ // Render error widget on failure
+ $output .= $env->render('widgets/mod_widgets_error.html.twig', array_merge($context, [
+ 'widget' => [
+ 'slot' => $slot,
+ 'mod_name' => $widget['module'],
+ 'template' => $widget['template'],
+ ],
+ 'error' => \FOSSBilling\Environment::isDevelopment() ? $e->getMessage() : null,
+ ]));
+ }
+ }
+
+ return $output;
+ }
+
public function twig_ipcountryname_filter($value)
{
if (empty($value)) {
diff --git a/src/library/FOSSBilling/Interfaces/WidgetProviderInterface.php b/src/library/FOSSBilling/Interfaces/WidgetProviderInterface.php
new file mode 100644
index 000000000..5b6874f07
--- /dev/null
+++ b/src/library/FOSSBilling/Interfaces/WidgetProviderInterface.php
@@ -0,0 +1,33 @@
+
+ */
+ public function getWidgets(): array;
+}
diff --git a/src/library/FOSSBilling/Module.php b/src/library/FOSSBilling/Module.php
index 237ac7514..073b4e36e 100644
--- a/src/library/FOSSBilling/Module.php
+++ b/src/library/FOSSBilling/Module.php
@@ -32,7 +32,8 @@ class Module implements InjectionAwareInterface
'page', 'product', 'profile', 'security',
'servicecustom', 'servicedomain', 'servicedownloadable',
'servicehosting', 'servicelicense', 'staff', 'stats',
- 'support', 'system', 'theme', 'orderbutton', 'formbuilder'];
+ 'support', 'system', 'theme', 'orderbutton', 'formbuilder',
+ 'widgets'];
public function setDi(?\Pimple\Container $di): void
{
diff --git a/src/modules/Branding/Service.php b/src/modules/Branding/Service.php
index c2df3241f..70720ef44 100644
--- a/src/modules/Branding/Service.php
+++ b/src/modules/Branding/Service.php
@@ -11,7 +11,10 @@
namespace Box\Mod\Branding;
-class Service implements \FOSSBilling\InjectionAwareInterface
+use \FOSSBilling\InjectionAwareInterface;
+use \FOSSBilling\Interfaces\WidgetProviderInterface;
+
+class Service implements InjectionAwareInterface, WidgetProviderInterface
{
protected ?\Pimple\Container $di = null;
@@ -32,6 +35,16 @@ class Service implements \FOSSBilling\InjectionAwareInterface
];
}
+ public function getWidgets(): array
+ {
+ return [
+ [
+ 'slot' => 'client.theme.footer.end',
+ 'template' => 'mod_branding_footer',
+ ],
+ ];
+ }
+
public function uninstall(): bool
{
return true;
diff --git a/src/modules/Branding/html_client/widgets/mod_branding_footer.html.twig b/src/modules/Branding/html_client/widgets/mod_branding_footer.html.twig
new file mode 100644
index 000000000..e0763bf48
--- /dev/null
+++ b/src/modules/Branding/html_client/widgets/mod_branding_footer.html.twig
@@ -0,0 +1,6 @@
+
+
{{ 'Powered by'|trans }}
+
{{ 'FOSSBilling'|trans }}
+
\ No newline at end of file
diff --git a/src/modules/Cron/Service.php b/src/modules/Cron/Service.php
index 3dde2d93f..e9302e97e 100644
--- a/src/modules/Cron/Service.php
+++ b/src/modules/Cron/Service.php
@@ -39,9 +39,6 @@ class Service
];
}
- /**
- * @todo finish fixing, time to sleep (note: idk what exactly this is referring to. It predates FOSSBilling and is from BoxBilling well before we touched this code)
- */
public function runCrons(): bool
{
$api = $this->di['api_system'];
@@ -80,7 +77,7 @@ class Service
/**
* @param string $method
*/
- protected function _exec($api, $method, $params = null)
+ protected function _exec($api, $method, $params = null): void
{
try {
$api->{$method}($params);
diff --git a/src/modules/Widgets/Api/Admin.php b/src/modules/Widgets/Api/Admin.php
new file mode 100644
index 000000000..793e22d71
--- /dev/null
+++ b/src/modules/Widgets/Api/Admin.php
@@ -0,0 +1,37 @@
+getService()->getWidgetList();
+ }
+
+ /**
+ * Force rebuild of the widget registry cache.
+ * Useful for debugging or after manual changes.
+ */
+ public function rebuild(): bool
+ {
+ $service = $this->getService();
+ $service->invalidateCache();
+ $service->getRegistry(); // Trigger rebuild
+
+ return true;
+ }
+}
diff --git a/src/modules/Widgets/Controller/Admin.php b/src/modules/Widgets/Controller/Admin.php
new file mode 100644
index 000000000..b38312546
--- /dev/null
+++ b/src/modules/Widgets/Controller/Admin.php
@@ -0,0 +1,53 @@
+di = $di;
+ }
+
+ public function getDi(): ?\Pimple\Container
+ {
+ return $this->di;
+ }
+
+ public function fetchNavigation(): array
+ {
+ return [
+ 'subpages' => [
+ [
+ 'location' => 'extensions',
+ 'label' => __trans('Widgets'),
+ 'index' => 500,
+ 'uri' => $this->di['url']->adminLink('widgets'),
+ 'class' => '',
+ ],
+ ],
+ ];
+ }
+
+ public function register(\Box_App &$app): void
+ {
+ $app->get('/widgets', 'get_index', [], static::class);
+ }
+
+ public function get_index(\Box_App $app): string
+ {
+ $this->di['is_admin_logged'];
+
+ return $app->render('mod_widgets_index');
+ }
+}
diff --git a/src/modules/Widgets/Service.php b/src/modules/Widgets/Service.php
new file mode 100644
index 000000000..e03085b49
--- /dev/null
+++ b/src/modules/Widgets/Service.php
@@ -0,0 +1,218 @@
+di = $di;
+ }
+
+ public function getDi(): ?\Pimple\Container
+ {
+ return $this->di;
+ }
+
+ /**
+ * Get the widget registry from cache, rebuild if necessary.
+ *
+ * @return array>
+ */
+ public function getRegistry(): array
+ {
+ return $this->di['cache']->get(self::CACHE_KEY, function (ItemInterface $item) {
+ $item->expiresAfter(null); // No need to expire. We will manually invalidate on module activation/deactivation
+
+ return $this->buildRegistry();
+ });
+ }
+
+ /**
+ * Build the widget registry by scanning all active modules.
+ *
+ * @return array>
+ */
+ public function buildRegistry(): array
+ {
+ $registry = [];
+ $modules = $this->di['mod_service']('Extension')->getCoreAndActiveModules();
+
+ foreach ($modules as $modName) {
+ try {
+ $widgets = $this->getModuleWidgets($modName);
+
+ foreach ($widgets as $widget) {
+ if (!isset($widget['slot']) || !isset($widget['template'])) {
+ continue; // Skip invalid widget definitions
+ }
+
+ $slot = $widget['slot'];
+ $priority = $widget['priority'] ?? self::DEFAULT_PRIORITY;
+
+ if (!is_int($priority) || $priority <= 0) {
+ $priority = self::DEFAULT_PRIORITY;
+ }
+
+ $registry[$slot][] = [
+ 'module' => $modName,
+ 'template' => $widget['template'],
+ 'priority' => $priority,
+ ];
+ }
+ } catch (\Throwable $e) {
+ // Log the error but continue with other modules
+ $this->di['logger']->err("Error loading widgets from module '{$modName}': " . $e->getMessage());
+ }
+ }
+
+ // Sort each slot's widgets by priority (ascending)
+ foreach ($registry as $slot => &$widgets) {
+ usort($widgets, fn ($a, $b) => $a['priority'] <=> $b['priority']);
+ }
+
+ return $registry;
+ }
+
+ /**
+ * Invalidate the widget cache, forcing a rebuild on next access.
+ */
+ public function invalidateCache(): void
+ {
+ $this->di['cache']->delete(self::CACHE_KEY);
+ }
+
+ /**
+ * Get widgets for a specific slot.
+ *
+ * Slot naming convention: {area}.{namespace}.{location}[.{position}]
+ * - area: 'admin' or 'client'
+ * - namespace: 'theme' for layout slots, or module name for module-specific slots
+ * - location: where the slot appears (e.g., 'footer', 'sidebar', 'details')
+ * - position: optional refinement (e.g., 'start', 'end', 'before', 'after')
+ *
+ * Examples:
+ * - 'client.theme.footer.end' - End of footer in client theme layout
+ * - 'admin.theme.sidebar.top' - Top of sidebar in admin theme layout
+ * - 'client.invoice.details.after' - After invoice details in Invoice module
+ *
+ * @param string $slot name of the slot (e.g., 'client.theme.footer.end')
+ *
+ * @return array widgets for the slot
+ */
+ public function getSlotWidgets(string $slot): array
+ {
+ $registry = $this->getRegistry();
+
+ return $registry[$slot] ?? [];
+ }
+
+ /**
+ * Get a module's widget definitions.
+ *
+ * @param string $modName the module name
+ *
+ * @return array list of widget definitions
+ */
+ public function getModuleWidgets(string $modName): array
+ {
+ $mod = $this->di['mod']($modName);
+
+ if ($mod->hasService()) {
+ $service = $mod->getService();
+
+ if ($this->serviceProvidesWidgets($service)) {
+ return $service->getWidgets();
+ }
+ }
+
+ return [];
+ }
+
+ /**
+ * Check if a service class provides widgets.
+ *
+ * @param object $service the service class instance
+ *
+ * @return bool true if the service implements WidgetProviderInterface
+ */
+ private function serviceProvidesWidgets(object $service): bool
+ {
+ return $service instanceof WidgetProviderInterface;
+ }
+
+ /**
+ * Get all widgets grouped by slot (for admin listing).
+ *
+ * @return array list of slots with their widgets
+ */
+ public function getWidgetList(): array
+ {
+ $registry = $this->getRegistry();
+ $result = [];
+
+ foreach ($registry as $slot => $widgets) {
+ $result[] = [
+ 'slot' => $slot,
+ 'widgets' => $widgets,
+ 'count' => count($widgets),
+ ];
+ }
+
+ // Sort by slot name for consistent display
+ usort($result, fn ($a, $b) => strcmp($a['slot'], $b['slot']));
+
+ return $result;
+ }
+
+ /**
+ * Event handler: Invalidate cache when a module is activated.
+ */
+ public static function onAfterAdminActivateExtension(\Box_Event $event): void
+ {
+ $params = $event->getParameters();
+
+ if (isset($params['id'])) {
+ $di = $event->getDi();
+ $ext = $di['db']->load('extension', $params['id']);
+
+ if (is_object($ext) && $ext->type === 'mod') {
+ $di['mod_service']('Widgets')->invalidateCache();
+ }
+ }
+
+ $event->setReturnValue(true);
+ }
+
+ /**
+ * Event handler: Invalidate cache when a module is deactivated.
+ */
+ public static function onAfterAdminDeactivateExtension(\Box_Event $event): void
+ {
+ $params = $event->getParameters();
+
+ if (($params['type'] ?? null) === 'mod') {
+ $di = $event->getDi();
+ $di['mod_service']('Widgets')->invalidateCache();
+ }
+
+ $event->setReturnValue(true);
+ }
+}
diff --git a/src/modules/Widgets/html_admin/mod_widgets_index.html.twig b/src/modules/Widgets/html_admin/mod_widgets_index.html.twig
new file mode 100644
index 000000000..34ea70e28
--- /dev/null
+++ b/src/modules/Widgets/html_admin/mod_widgets_index.html.twig
@@ -0,0 +1,156 @@
+{% extends request.ajax ? 'layout_blank.html.twig' : 'layout_default.html.twig' %}
+
+{% import 'macro_functions.html.twig' as mf %}
+
+{% block meta_title %}{{ 'Widgets'|trans }}{% endblock %}
+
+{% set active_menu = 'extensions' %}
+
+{% block breadcrumbs %}
+
+
+
+
+
+
+
+
+
+ {{ 'Extensions'|trans }}
+
+ {{ 'Widgets'|trans }}
+
+{% endblock %}
+
+{% set slots = admin.widgets_list() %}
+
+{% block content %}
+
+
+
+ {% if slots is empty %}
+
+
+
+
+
+
+
+
{{ 'No widgets registered'|trans }}
+
+ {{ 'Widgets will appear here when modules that provide them are activated.'|trans }}
+ {{ 'Modules register widgets by implementing a getWidgets() method in their Service class.'|trans|raw }}
+
+
+
+
+ {% else %}
+
+
+
+ {{ 'Showing'|trans }}
+ {{ slots|length }}
+ {{ slots|length == 1 ? 'slot'|trans : 'slots'|trans }}
+ {{ 'with'|trans }}
+ {% set total_widgets = 0 %}{% for slot in slots %}{% set total_widgets = total_widgets + slot.count %}{% endfor %}{{ total_widgets }}
+ {{ total_widgets == 1 ? 'widget'|trans : 'widgets'|trans }}
+
+
+
+
+
+
+
+
+ {{ 'Slot'|trans }}
+ {{ 'Widgets'|trans }}
+
+
+
+
+ {% for slot in slots %}
+
+
+
+
+
+
+
+
+
+
{{ slot.slot }}
+
+ {% set slot_parts = slot.slot|split('.') %}
+ {% if slot_parts[0] == 'admin' %}
+ {{ 'Admin'|trans }}
+ {% elseif slot_parts[0] == 'client' %}
+ {{ 'Client'|trans }}
+ {% endif %}
+ {% if slot_parts[1] == 'theme' %}
+ {{ 'Theme layout slot'|trans }}
+ {% else %}
+ {{ 'Module slot'|trans }}
+ {% endif %}
+
+
+
+
+
+
+ {% for widget in slot.widgets %}
+
+ {{ widget.priority }}
+ {{ widget.module|capitalize }}
+ →
+ widgets/{{ widget.template }}.html.twig
+
+ {% endfor %}
+
+
+
+ {{ slot.count }}
+
+
+ {% endfor %}
+
+
+
+
+
+ {% endif %}
+
+{% endblock %}
\ No newline at end of file
diff --git a/src/modules/Widgets/html_admin/widgets/mod_widgets_error.html.twig b/src/modules/Widgets/html_admin/widgets/mod_widgets_error.html.twig
new file mode 100644
index 000000000..25601828d
--- /dev/null
+++ b/src/modules/Widgets/html_admin/widgets/mod_widgets_error.html.twig
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
An error occurred while rendering this widget.
+
+
+
+ Slot:
+ {{ widget.slot|e }}
+
+ Module:
+ {{ widget.mod_name|e }}
+
+ Template:
+ {{ widget.template|e }}.html.twig
+
+
+ {% if error %}
+
{{ error|e }}
+ {% endif %}
+
+
+
diff --git a/src/modules/Widgets/html_client/widgets/mod_widgets_error.html.twig b/src/modules/Widgets/html_client/widgets/mod_widgets_error.html.twig
new file mode 100644
index 000000000..4fc4490c0
--- /dev/null
+++ b/src/modules/Widgets/html_client/widgets/mod_widgets_error.html.twig
@@ -0,0 +1,13 @@
+
+
An error occurred while rendering this widget.
+
+
+ Slot: {{ widget.slot|e }}
+ Module: {{ widget.mod_name|e }}
+ Template: {{ widget.template|e }}.html.twig
+
+
+ {% if error %}
+
{{ error|e }}
+ {% endif %}
+
diff --git a/src/modules/Widgets/icon.svg b/src/modules/Widgets/icon.svg
new file mode 100644
index 000000000..0b40834c8
--- /dev/null
+++ b/src/modules/Widgets/icon.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/src/modules/Widgets/manifest.json b/src/modules/Widgets/manifest.json
new file mode 100644
index 000000000..605561107
--- /dev/null
+++ b/src/modules/Widgets/manifest.json
@@ -0,0 +1,8 @@
+{
+ "id": "widgets",
+ "type": "mod",
+ "name": "Widgets",
+ "description": "Widget system for FOSSBilling. Allows modules to register widgets that can be rendered in designated slots.",
+ "icon_url": "icon.svg",
+ "version": "1.0.0"
+}
diff --git a/src/themes/admin_default/html/layout_default.html.twig b/src/themes/admin_default/html/layout_default.html.twig
index 7de0d67d9..60cf49d5f 100644
--- a/src/themes/admin_default/html/layout_default.html.twig
+++ b/src/themes/admin_default/html/layout_default.html.twig
@@ -209,16 +209,20 @@
{% endblock %}
+ {{ render_widgets('admin.theme.content.before') }}
{% block top_content %}{% endblock %}
{% block content %}{% endblock %}
+ {{ render_widgets('admin.theme.content.after') }}
diff --git a/src/themes/huraga/html/layout_default.html.twig b/src/themes/huraga/html/layout_default.html.twig
index 6940ea4e7..b4a843a11 100644
--- a/src/themes/huraga/html/layout_default.html.twig
+++ b/src/themes/huraga/html/layout_default.html.twig
@@ -167,7 +167,9 @@
{% endblock %}
{% endif %}
+ {{ render_widgets('client.theme.content.before') }}
{% block content %}{% endblock %}
+ {{ render_widgets('client.theme.content.after') }}
{{ include('partial_message.html.twig') }}
@@ -180,6 +182,7 @@
{% if settings.footer_enabled %}
{% endif %}