Initial commit

This commit is contained in:
root
2026-01-19 17:44:46 +01:00
commit 823af8b11d
8721 changed files with 1130846 additions and 0 deletions

View File

@@ -0,0 +1,106 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Utils\Client;
use Espo\Core\Api\Response;
use Espo\Core\Utils\Client\ActionRenderer\Params;
use Espo\Core\Utils\Json;
use Espo\Core\Utils\ClientManager;
/**
* Renders a front-end page that executes a controller action. Utilized by entry points.
*/
class ActionRenderer
{
public function __construct(private ClientManager $clientManager)
{}
/**
* Writes to a body.
*/
public function write(Response $response, Params $params): void
{
$body = $this->render(
controller: $params->getController(),
action: $params->getAction(),
data: $params->getData(),
initAuth: $params->initAuth(),
scripts: $params->getScripts(),
pageTitle: $params->getPageTitle(),
theme: $params->getTheme(),
);
$securityParams = new SecurityParams(
frameAncestors: $params->getFrameAncestors(),
);
$this->clientManager->writeHeaders($response, $securityParams);
$response->writeBody($body);
}
/**
* @param ?array<string, mixed> $data
* @param Script[] $scripts
*/
private function render(
string $controller,
string $action,
?array $data,
bool $initAuth,
array $scripts,
?string $pageTitle,
?string $theme,
): string {
$encodedData = Json::encode($data);
$initAuthPart = $initAuth ? "app.initAuth();" : '';
$script =
"
{$initAuthPart}
app.doAction({
controllerClassName: '$controller',
action: '$action',
options: $encodedData,
});
";
$params = new RenderParams(
runScript: $script,
scripts: $scripts,
pageTitle: $pageTitle,
theme: $theme,
);
return $this->clientManager->render($params);
}
}

View File

@@ -0,0 +1,189 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Utils\Client\ActionRenderer;
use Espo\Core\Utils\Client\Script;
/**
* Immutable.
*/
class Params
{
/** @var ?array<string, mixed> */
private ?array $data;
private bool $initAuth = false;
/** @var string[] */
private array $frameAncestors = [];
/** @var Script[] */
private array $scripts = [];
private ?string $pageTitle = null;
private ?string $theme = null;
/**
* @param ?array<string, mixed> $data
*/
public function __construct(
private string $controller,
private string $action,
?array $data = null
) {
$this->data = $data;
}
/**
* @param ?array<string, mixed> $data
*/
public static function create(string $controller, string $action, ?array $data = null): self
{
return new self($controller, $action, $data);
}
/**
* @param array<string, mixed> $data
*/
public function withData(array $data): self
{
$obj = clone $this;
$obj->data = $data;
return $obj;
}
public function withInitAuth(bool $initAuth = true): self
{
$obj = clone $this;
$obj->initAuth = $initAuth;
return $obj;
}
/**
* @param string[] $frameAncestors
* @since 9.0.0
*/
public function withFrameAncestors(array $frameAncestors): self
{
$obj = clone $this;
$obj->frameAncestors = $frameAncestors;
return $obj;
}
/**
* @param Script[] $scripts
* @since 9.0.0
*/
public function withScripts(array $scripts): self
{
$obj = clone $this;
$obj->scripts = $scripts;
return $obj;
}
/**
* @since 9.1.0
*/
public function withPageTitle(?string $pageTitle): self
{
$obj = clone $this;
$obj->pageTitle = $pageTitle;
return $obj;
}
/**
* @since 9.1.0
*/
public function withTheme(?string $theme): self
{
$obj = clone $this;
$obj->theme = $theme;
return $obj;
}
public function getController(): string
{
return $this->controller;
}
public function getAction(): string
{
return $this->action;
}
/**
* @return ?array<string, mixed>
*/
public function getData(): ?array
{
return $this->data;
}
public function initAuth(): bool
{
return $this->initAuth;
}
/**
* @return string[]
* @since 9.0.0
*/
public function getFrameAncestors(): array
{
return $this->frameAncestors;
}
/**
* @return Script[]
* @since 9.0.0
*/
public function getScripts(): array
{
return $this->scripts;
}
/**
* @since 9.1.0
*/
public function getPageTitle(): ?string
{
return $this->pageTitle;
}
/**
* @since 9.1.0
*/
public function getTheme(): ?string
{
return $this->theme;
}
}

View File

@@ -0,0 +1,91 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Utils\Client;
use Espo\Core\Utils\Config;
use Espo\Core\Utils\File\Manager as FileManager;
use Espo\Core\Utils\Module;
use Espo\Core\Utils\Util;
/**
* Allows bundled extensions to work when the system is in the developer mode.
*/
class DevModeExtensionInitJsFileListProvider
{
public function __construct(
private Module $module,
private FileManager $fileManager,
private Config $config,
) {}
/**
* @return string[]
*/
public function get(): array
{
$developedModule = $this->config->get('developedModule');
if (!$developedModule) {
return [];
}
$output = [];
foreach ($this->getBundledModuleList() as $module) {
if ($module === $developedModule) {
continue;
}
$file = "client/custom/modules/$module/lib/init.js";
if ($this->fileManager->exists($file)) {
$output[] = $file;
}
}
return $output;
}
/**
* @return string[]
*/
private function getBundledModuleList(): array
{
$modules = array_values(array_filter(
$this->module->getList(),
fn ($item) => $this->module->get([$item, 'bundled'])
));
return array_map(
fn ($item) => Util::fromCamelCase($item, '-'),
$modules
);
}
}

View File

@@ -0,0 +1,109 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Utils\Client;
use Espo\Core\Utils\File\Manager as FileManager;
use RuntimeException;
/**
* @internal Also used by the installer w/o DI.
*/
class DevModeJsFileListProvider
{
private const LIBS_FILE = 'frontend/libs.json';
public function __construct(private FileManager $fileManager)
{}
/**
* @return string[]
*/
public function get(): array
{
$list = [];
$items = json_decode($this->fileManager->getContents(self::LIBS_FILE));
foreach ($items as $item) {
if (!($item->bundle ?? false)) {
continue;
}
$files = $item->files ?? null;
if ($files !== null) {
$list = array_merge(
$list,
array_map(
fn ($item) => self::prepareBundleLibFilePath($item),
$files
)
);
continue;
}
if (!isset($item->src)) {
continue;
}
$list[] = self::prepareBundleLibFilePath($item);
}
return $list;
}
private function prepareBundleLibFilePath(object $item): string
{
$amdId = $item->amdId ?? null;
if ($amdId) {
$file = $amdId;
if (str_starts_with($amdId, '@')) {
$file = substr($amdId, 1);
$file = str_replace('/', '-', $file);
}
return 'client/lib/original/' . $file . '.js';
}
$src = $item->src ?? null;
if (!$src) {
throw new RuntimeException("Missing 'src' in bundled lib definition.");
}
$arr = explode('/', $src);
return 'client/lib/original/' . array_slice($arr, -1)[0];
}
}

View File

@@ -0,0 +1,67 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Utils\Client;
use Espo\Core\Utils\Metadata;
class LoaderParamsProvider
{
public function __construct(
private Metadata $metadata
) {}
public function getLibsConfig(): object
{
return (object) $this->metadata->get(['app', 'jsLibs'], []);
}
public function getAliasMap(): object
{
$map = (object) [];
/** @var array<string, array<string, mixed>> $libs */
$libs = $this->metadata->get(['app', 'jsLibs'], []);
foreach ($libs as $name => $item) {
/** @var ?string[] $aliases */
$aliases = $item['aliases'] ?? null;
$map->$name = 'lib!' . $name;
if ($aliases) {
foreach ($aliases as $alias) {
$map->$alias = 'lib!' . $name;
}
}
}
return $map;
}
}

View File

@@ -0,0 +1,46 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Utils\Client;
readonly class RenderParams
{
/**
* @param ?string $runScript A JS run-script.
* @param Script[] $scripts Scripts to include on the page.
* @param ?string $pageTitle A page title. Since 9.1.0.
* @param ?string $theme A page theme name.
*/
public function __construct(
public ?string $runScript = null,
public array $scripts = [],
public ?string $pageTitle = null,
public ?string $theme = null,
) {}
}

View File

@@ -0,0 +1,40 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Utils\Client;
class Script
{
public function __construct(
readonly public string $source,
readonly public bool $cacheBusting = false,
readonly public bool $async = false,
readonly public bool $defer = false,
) {}
}

View File

@@ -0,0 +1,40 @@
<?php
/************************************************************************
* This file is part of EspoCRM.
*
* EspoCRM Open Source CRM application.
* Copyright (C) 2014-2025 EspoCRM, Inc.
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
namespace Espo\Core\Utils\Client;
class SecurityParams
{
/**
* @param string[] $frameAncestors
*/
public function __construct(
readonly public array $frameAncestors = [],
) {}
}