/var/www/fossbilling/modules/Theme/Model/Theme.php
* SPDX-License-Identifier: Apache-2.0.
*
* @copyright FOSSBilling (https://www.fossbilling.org)
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
*/
namespace Box\Mod\Theme\Model;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Path;
class Theme
{
private readonly Filesystem $filesystem;
public function __construct(private $name)
{
$this->filesystem = new Filesystem();
if (!$this->filesystem->exists($this->getPath())) {
throw new \FOSSBilling\Exception("Theme ':name' does not exist.", [':name' => $name]);
}
}
public function getName()
{
return $this->name;
}
public function isAdminAreaTheme()
{
return str_contains($this->name, 'admin_');
}
public function isAssetsPathWritable()
{
return is_writable($this->getPathAssets());
}
/**
* @return array<mixed, array<'name'|'url', mixed>>
Arguments
"Theme 'dark' does not exist."
/var/www/fossbilling/modules/Theme/Service.php
private readonly Filesystem $filesystem;
public function setDi(\Pimple\Container $di): void
{
$this->di = $di;
}
public function getDi(): ?\Pimple\Container
{
return $this->di;
}
public function __construct()
{
$this->filesystem = new Filesystem();
}
public function getTheme($name)
{
return new Model\Theme($name);
}
public function getCurrentThemePreset(Model\Theme $theme)
{
$current = $this->di['db']->getCell(
"SELECT meta_value
FROM extension_meta
WHERE 1
AND extension = 'mod_theme'
AND rel_id = 'current'
AND rel_type = 'preset'
AND meta_key = :theme",
[':theme' => $theme->getName()]
);
if (empty($current)) {
$current = $theme->getCurrentPreset();
$this->setCurrentThemePreset($theme, $current);
}
return $current;
/var/www/fossbilling/library/Box/AppClient.php
$template = $this->getTwig()->load(Path::changeExtension($fileName, $ext));
} catch (Twig\Error\LoaderError $e) {
$this->di['logger']->setChannel('routing')->info($e->getMessage());
http_response_code(404);
throw new FOSSBilling\InformationException('Page not found', null, 404);
}
if ("{$fileName}.{$ext}" == 'mod_page_sitemap.xml') {
header('Content-Type: application/xml');
}
return $template->render($variableArray);
}
protected function getTwig(): Twig\Environment
{
$service = $this->di['mod_service']('theme');
$code = $service->getCurrentClientAreaThemeCode();
$theme = $service->getTheme($code);
$settings = $service->getThemeSettings($theme);
$loader = new Box_TwigLoader(
[
'mods' => PATH_MODS,
'theme' => Path::join(PATH_THEMES, $code),
'type' => 'client',
]
);
$twig = $this->di['twig'];
$twig->setLoader($loader);
$twig->addGlobal('current_theme', $code);
$twig->addGlobal('settings', $settings);
if (Environment::isDevelopment()) {
$profile = new Profile();
$twig->addExtension(new ProfilerExtension($profile));
$collector = new NamespacedTwigProfileCollector($profile);
/var/www/fossbilling/library/Box/AppClient.php
} catch (Exception $e) {
if (DEBUG) {
error_log($e->getMessage());
}
}
$e = new FOSSBilling\InformationException('Page :url not found', [':url' => $this->url], 404);
$this->di['logger']->setChannel('routing')->info($e->getMessage());
http_response_code(404);
return $this->render('error', ['exception' => $e]);
}
/**
* @param string $fileName
*/
public function render($fileName, $variableArray = [], $ext = 'html.twig'): string
{
try {
$template = $this->getTwig()->load(Path::changeExtension($fileName, $ext));
} catch (Twig\Error\LoaderError $e) {
$this->di['logger']->setChannel('routing')->info($e->getMessage());
http_response_code(404);
throw new FOSSBilling\InformationException('Page not found', null, 404);
}
if ("{$fileName}.{$ext}" == 'mod_page_sitemap.xml') {
header('Content-Type: application/xml');
}
return $template->render($variableArray);
}
protected function getTwig(): Twig\Environment
{
$service = $this->di['mod_service']('theme');
$code = $service->getCurrentClientAreaThemeCode();
$theme = $service->getTheme($code);
$settings = $service->getThemeSettings($theme);
/var/www/fossbilling/modules/Order/Controller/Client.php
$this->di = $di;
}
public function getDi(): ?\Pimple\Container
{
return $this->di;
}
public function register(\Box_App &$app)
{
$app->get('/order', 'get_products', [], static::class);
$app->get('/order/service', 'get_orders', [], static::class);
$app->get('/order/:id', 'get_configure_product', ['id' => '[0-9]+'], static::class);
$app->get('/order/:slug', 'get_configure_product_by_slug', ['slug' => '[a-z0-9-]+'], static::class);
$app->get('/order/service/manage/:id', 'get_order', ['id' => '[0-9]+'], static::class);
}
public function get_products(\Box_App $app)
{
return $app->render('mod_order_index');
}
public function get_configure_product_by_slug(\Box_App $app, $slug)
{
$api = $this->di['api_guest'];
$product = $api->product_get(['slug' => $slug]);
$tpl = 'mod_service' . $product['type'] . '_order';
if ($api->system_template_exists(['file' => $tpl . '.html.twig'])) {
return $app->render($tpl, ['product' => $product]);
}
return $app->render('mod_order_product', ['product' => $product]);
}
public function get_configure_product(\Box_App $app, $id)
{
$api = $this->di['api_guest'];
$product = $api->product_get(['id' => $id]);
$tpl = 'mod_service' . $product['type'] . '_order';
if ($api->system_template_exists(['file' => $tpl . '.html.twig'])) {
/var/www/fossbilling/library/Box/App.php
{
$this->debugBar['time']->startMeasure('executeShared', 'Reflecting module controller (shared mapping)');
$class = new $classname();
if ($class instanceof InjectionAwareInterface) {
$class->setDi($this->di);
}
$reflection = new ReflectionMethod($class::class, $methodName);
$args = [];
$args[] = $this; // first param always app instance
foreach ($reflection->getParameters() as $param) {
if (isset($params[$param->name])) {
$args[$param->name] = $params[$param->name];
} elseif ($param->isDefaultValueAvailable()) {
$args[$param->name] = $param->getDefaultValue();
}
}
$this->debugBar['time']->stopMeasure('executeShared');
return $reflection->invokeArgs($class, $args);
}
protected function execute($methodName, $params, $classname = null): string
{
$this->debugBar['time']->startMeasure('execute', 'Reflecting module controller');
$reflection = new ReflectionMethod(static::class, $methodName);
$args = [];
foreach ($reflection->getParameters() as $param) {
if (isset($params[$param->name])) {
$args[$param->name] = $params[$param->name];
} elseif ($param->isDefaultValueAvailable()) {
$args[$param->name] = $param->getDefaultValue();
}
}
$this->debugBar['time']->stopMeasure('execute');
return $reflection->invokeArgs($this, $args);
/var/www/fossbilling/library/Box/App.php
$exc = new FOSSBilling\InformationException('The system is undergoing maintenance. Please try again later', [], 503);
$apiController = new Box\Mod\Api\Controller\Client();
$apiController->setDi($this->di);
return $apiController->renderJson(null, $exc);
} else {
return $this->render('mod_system_maintenance');
}
}
}
$this->debugBar['time']->startMeasure('sharedMapping', 'Checking shared mappings');
$sharedCount = count($this->shared);
for ($i = 0; $i < $sharedCount; ++$i) {
$mapping = $this->shared[$i];
$url = new Box_UrlHelper($mapping[0], $mapping[1], $mapping[3], $this->url);
if ($url->match) {
$this->debugBar['time']->stopMeasure('sharedMapping');
return $this->executeShared($mapping[4], $mapping[2], $url->params);
}
}
$this->debugBar['time']->stopMeasure('sharedMapping');
// this class mappings
$this->debugBar['time']->startMeasure('mapping', 'Checking mappings');
$mappingsCount = count($this->mappings);
for ($i = 0; $i < $mappingsCount; ++$i) {
$mapping = $this->mappings[$i];
$url = new Box_UrlHelper($mapping[0], $mapping[1], $mapping[3], $this->url);
if ($url->match) {
$this->debugBar['time']->stopMeasure('mapping');
return $this->execute($mapping[2], $url->params);
}
}
$this->debugBar['time']->stopMeasure('mapping');
$e = new FOSSBilling\InformationException('Page :url not found', [':url' => $this->url], 404);
/var/www/fossbilling/library/Box/App.php
public function delete(string $url, string $methodName, ?array $conditions = [], ?string $class = null): void
{
$this->event('delete', $url, $methodName, $conditions, $class);
}
public function run(): string
{
$this->debugBar['time']->startMeasure('registerModule', 'Registering module routes');
$this->registerModule();
$this->debugBar['time']->stopMeasure('registerModule');
$this->debugBar['time']->startMeasure('init', 'Initializing the app');
$this->init();
$this->debugBar['time']->stopMeasure('init');
$this->debugBar['time']->startMeasure('checkperm', 'Checking access to module');
$this->checkPermission();
$this->debugBar['time']->stopMeasure('checkperm');
return $this->processRequest();
}
/**
* @param string $path
*/
public function redirect($path): never
{
$location = $this->di['url']->link($path);
header("Location: $location");
exit;
}
public function render($fileName, $variableArray = []): string
{
return 'Rendering ' . $fileName;
}
public function sendFile($filename, $contentType, $path): false|int
{
header("Content-type: $contentType");
/home/kawkavbilling/htdocs/billing.kawkav.com/index.php
// If HTTP error code has been passed, handle it.
if (!is_null($http_err_code)) {
switch ($http_err_code) {
case '404':
$e = new FOSSBilling\Exception('Page :url not found', [':url' => $url], 404);
echo $app->show404($e);
break;
default:
$http_err_code = intval($http_err_code);
http_response_code($http_err_code);
$e = new FOSSBilling\Exception('HTTP Error :err_code occurred while attempting to load :url', [':err_code' => $http_err_code, ':url' => $url], $http_err_code);
echo $app->render('error', ['exception' => $e]);
}
exit;
}
// If no HTTP error passed, run the app.
echo $app->run();
exit;