Skip to content

Commit

Permalink
Component: Build Public Resources
Browse files Browse the repository at this point in the history
The public-folder was depopulated and the resources that should be served via the web
have been moved to the `resources/` directories of the according components. Files are
be moved to subfolders of `public/assets` according to their type, e.g. `public/assets/css`.
A common top directory for all assets will allow for various improvements regarding
delivery of the assets. Installations could, e.g., define different caching-rules for
assets than for live data delivery from other locations. Splitting up the asset folder
with regard to the type of asset we allow installations to implement effective CSP rules.

This strategy mostly panned out, besides some minor naming collisions. For two components
(COPage and the TinyMCE) the move was not possible due to the complicated structure
of how additional files are loaded from the server. These components put their assets
into specific subfolder in `public` (in components/ILIAS/COPage and node_modules/tinymce).
We expect that further moves will be possible here at some point in the future.
  • Loading branch information
klees committed Apr 22, 2024
1 parent a32d69e commit 17210ea
Show file tree
Hide file tree
Showing 1,092 changed files with 5,063 additions and 3,829 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ jobs:
with:
node-version: ${{ matrix.nodejs }}

- name: Install Node.js packages
run: npm clean-install

- name: Install Composer packages
run: composer install --no-interaction --no-progress

- name: Install Node.js packages
run: cp public/package.json .; cp public/package-lock.json .; npm clean-install

- name: PHP Unit Test
run: scripts/PHPUnit/run_tests.sh
env:
Expand Down
2 changes: 2 additions & 0 deletions components/ILIAS/AccessControl/AccessControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ public function init(
new \ilAccessRBACSetupAgent(
$pull[\ILIAS\Refinery\Factory::class]
);
$contribute[Component\Resource\PublicAsset::class] = fn() =>
new Component\Resource\ComponentJS($this, "ilPermSelect.js");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct(ilPermissionGUI $a_parent_obj, string $a_parent_cmd,
$this->tree_path_ids = $this->tree->getPathId($this->ref_id);

$tpl = $DIC->ui()->mainTemplate();
$tpl->addJavaScript('./components/ILIAS/AccessControl/js/ilPermSelect.js');
$tpl->addJavaScript('assets/js/ilPermSelect.js');

$this->setTitle($this->lng->txt('permission_settings'));
$this->setEnableHeader(true);
Expand Down
File renamed without changes.
5 changes: 4 additions & 1 deletion components/ILIAS/Accordion/Accordion.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public function init(
array | \ArrayAccess &$pull,
array | \ArrayAccess &$internal,
): void {
// ...
$contribute[Component\Resource\PublicAsset::class] = fn() =>
new Component\Resource\ComponentJS($this, "accordion.js");
$contribute[Component\Resource\PublicAsset::class] = fn() =>
new Component\Resource\NodeModule("owl.carousel/dist/owl.carousel.js");
}
}
4 changes: 2 additions & 2 deletions components/ILIAS/Accordion/classes/class.ilAccordionGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ public static function addCss(): void
public static function getLocalJavascriptFiles(): array
{
return array(
"./components/ILIAS/Accordion/js/accordion.js",
self::$owl_path . self::$owl_js_path
"assets/js/accordion.js",
"assets/js" . self::$owl_js_path
);
}

Expand Down
1 change: 0 additions & 1 deletion components/ILIAS/App/tests/RootFolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ final class RootFolderTest extends TestCase
'composer.json',
'composer_new.json',
'composer.lock',
'dependency_resolution.php',
'ilias.ini.php',
'ilias_version.php',
'LICENSE',
Expand Down
6 changes: 5 additions & 1 deletion components/ILIAS/AuthShibboleth/AuthShibboleth.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public function init(
array | \ArrayAccess &$pull,
array | \ArrayAccess &$internal,
): void {
// ...
$contribute[Component\Resource\PublicAsset::class] = fn() =>
new Component\Resource\Endpoint($this, "shib_login.php");

$contribute[Component\Resource\PublicAsset::class] = fn() =>
new Component\Resource\Endpoint($this, "shib_logout.php");
}
}
2 changes: 1 addition & 1 deletion public/shib_login.php → ...S/AuthShibboleth/resources/shib_login.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
// @todo: removed deprecated ilCtrl methods, this needs inspection by a maintainer.
// $DIC->ctrl()->setCmd('doShibbolethAuthentication');
$DIC->ctrl()->callBaseClass(ilStartUpGUI::class);
}
}
2 changes: 1 addition & 1 deletion public/shib_logout.php → .../AuthShibboleth/resources/shib_logout.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,4 @@ function unserializesession($serialized_string)
}

return ($variables);
}
}
5 changes: 5 additions & 0 deletions components/ILIAS/Authentication/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,10 @@ public function init(
new \ilAuthenticationSetupAgent(
$pull[\ILIAS\Refinery\Factory::class]
);

$contribute[Component\Resource\PublicAsset::class] = fn() =>
new Component\Resource\Endpoint($this, "sessioncheck.php");
$contribute[Component\Resource\PublicAsset::class] = fn() =>
new Component\Resource\ComponentJS($this, "session_reminder.js");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function populatePage(): void

iljQueryUtil::initjQuery($this->page);

$this->page->addJavaScript('./components/ILIAS/Authentication/js/session_reminder.js');
$this->page->addJavaScript('assets/js/session_reminder.js');

$url = './sessioncheck.php?client_id=' . CLIENT_ID . '&lang=' . $this->lng->getLangKey();
$devMode = defined('DEVMODE') && DEVMODE ? 1 : 0;
Expand Down
File renamed without changes.
20 changes: 10 additions & 10 deletions public/sessioncheck.php → ...Authentication/resources/sessioncheck.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@
/** @var ILIAS\DI\Container $DIC */
$DIC->http()->saveResponse(
(
new ilSessionReminderCheck(
$DIC->http(),
$DIC->refinery(),
$DIC->language(),
$DIC->database(),
$DIC['ilClientIniFile'],
$DIC->logger()->auth(),
(new DataFactory())->clock()->utc()
)
new ilSessionReminderCheck(
$DIC->http(),
$DIC->refinery(),
$DIC->language(),
$DIC->database(),
$DIC['ilClientIniFile'],
$DIC->logger()->auth(),
(new DataFactory())->clock()->utc()
)
)->handle()
);
$DIC->http()->sendResponse();
$DIC->http()->close();
$DIC->http()->close();
3 changes: 2 additions & 1 deletion components/ILIAS/Awareness/Awareness.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function init(
array | \ArrayAccess &$pull,
array | \ArrayAccess &$internal,
): void {
// ...
$contribute[Component\Resource\PublicAsset::class] = fn() =>
new Component\Resource\ComponentJS($this, "Awareness.js");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function initJS(): void
{
$ilUser = $this->user;
// init js
$this->main_tpl->addJavaScript("./components/ILIAS/Awareness/js/Awareness.js");
$this->main_tpl->addJavaScript("./assets/js/Awareness.js");
$this->ctrl->setParameter($this, "ref_id", $this->ref_id);
$this->main_tpl->addOnLoadCode("il.Awareness.setBaseUrl('" . $this->ctrl->getLinkTarget(
$this,
Expand Down
3 changes: 2 additions & 1 deletion components/ILIAS/BackgroundTasks_/BackgroundTasks_.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function init(
array | \ArrayAccess &$pull,
array | \ArrayAccess &$internal,
): void {
// ...
$contribute[Component\Resource\PublicAsset::class] = fn() =>
new Component\Resource\ComponentJS($this, "background_task_refresh.js");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getNotifications(): array
return [];
}

$this->dic->ui()->mainTemplate()->addJavaScript("./components/ILIAS/BackgroundTasks_/js/background_task_refresh.js");
$this->dic->ui()->mainTemplate()->addJavaScript("assets/js/background_task_refresh.js");
$this->dic->language()->loadLanguageModule('background_tasks');

$id = fn (string $id): IdentificationInterface => $this->if->identifier($id);
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion components/ILIAS/Block/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function init(
array | \ArrayAccess &$pull,
array | \ArrayAccess &$internal,
): void {
// ...
$contribute[Component\Resource\PublicAsset::class] = fn() =>
new Component\Resource\ComponentJS($this, "ilblockcallback.js");
}
}
2 changes: 1 addition & 1 deletion components/ILIAS/Block/classes/class.ilBlockGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function __construct()
$this->ui = $DIC->ui();

ilYuiUtil::initConnection();
$this->main_tpl->addJavaScript("./components/ILIAS/Block/js/ilblockcallback.js");
$this->main_tpl->addJavaScript("./assets/js/ilblockcallback.js");

$this->setLimit((int) $this->user->getPref("hits_per_page"));

Expand Down
3 changes: 3 additions & 0 deletions components/ILIAS/BookingManager/BookingManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ public function init(
new \ILIAS\BookingManager\Setup\Agent(
$pull[\ILIAS\Refinery\Factory::class]
);

$contribute[Component\Resource\PublicAsset::class] = fn() =>
new Component\Resource\ComponentJS($this, "ScheduleInput.js");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public function insert(ilTemplate $a_tpl): void
{
$tpl = $this->tpl;

$tpl->addJavascript("components/ILIAS/BookingManager/js/ScheduleInput.js");
$tpl->addJavascript("assets/js/ScheduleInput.js");

$html = $this->render();

Expand Down
File renamed without changes.
44 changes: 44 additions & 0 deletions components/ILIAS/COPage/COPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,49 @@ public function init(
new \ILIAS\COPage\Setup\Agent(
$pull[\ILIAS\Refinery\Factory::class]
);

// This is included via anonymous classes as a testament to the fact, that
// the js and css of the COPage should be restructured according to the target
// structure in the component directory and the public directory.
$contribute[Component\Resource\PublicAsset::class] = fn() => new class () implements Component\Resource\PublicAsset {
public function getSource(): string
{
return "components/ILIAS/COPage/PC/InteractiveImage/js";
}
public function getTarget(): string
{
return "components/ILIAS/COPage/PC/InteractiveImage/js";
}
};
$contribute[Component\Resource\PublicAsset::class] = fn() => new class () implements Component\Resource\PublicAsset {
public function getSource(): string
{
return "components/ILIAS/COPage/Editor/js";
}
public function getTarget(): string
{
return "components/ILIAS/COPage/Editor/js";
}
};
$contribute[Component\Resource\PublicAsset::class] = fn() => new class () implements Component\Resource\PublicAsset {
public function getSource(): string
{
return "components/ILIAS/COPage/js";
}
public function getTarget(): string
{
return "components/ILIAS/COPage/js";
}
};
$contribute[Component\Resource\PublicAsset::class] = fn() => new class () implements Component\Resource\PublicAsset {
public function getSource(): string
{
return "components/ILIAS/COPage/css";
}
public function getTarget(): string
{
return "components/ILIAS/COPage/css";
}
};
}
}
6 changes: 3 additions & 3 deletions components/ILIAS/COPage/Editor/UI/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ public function initUI(
}

if (DEVMODE == 1) {
$main_tpl->addJavaScript("./node_modules/tinymce/tinymce.js");
$main_tpl->addJavaScript("node_modules/tinymce/tinymce.js");
} else {
$main_tpl->addJavaScript("./node_modules/tinymce/tinymce.min.js");
$main_tpl->addJavaScript("node_modules/tinymce/tinymce.min.js");
}

\ilYuiUtil::initConnection();
$main_tpl->addJavaScript("./components/ILIAS/UIComponent/Explorer/js/ilExplorer.js");
$main_tpl->addJavaScript("assets/js/ilExplorer.js");

// ensure that form.js is loaded which is needed for file input (js that shows file names)
$dummy = new \ilPropertyFormGUI();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public function __construct(
iljQueryUtil::initjQueryUI();
parent::__construct($a_content_obj, $a_page, $request);

$this->main_tpl->addJavaScript("./components/ILIAS/COPage/js/ilCOPagePres.js");
$this->main_tpl->addJavaScript("./components/ILIAS/COPage/js/ilCOPagePCInteractiveImage.js");
$this->main_tpl->addJavaScript("components/ILIAS/COPage/js/ilCOPagePres.js");
$this->main_tpl->addJavaScript("components/ILIAS/COPage/js/ilCOPagePCInteractiveImage.js");

ilAccordionGUI::addJavaScript();
ilAccordionGUI::addCss();
Expand Down
2 changes: 1 addition & 1 deletion components/ILIAS/COPage/PC/Table/class.ilPCTableGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ public function editData(): void
$this->displayValidationError();

$this->initEditor();
$this->tpl->addJavaScript("./components/ILIAS/UIComponent/AdvancedSelectionList/js/AdvancedSelectionList.js");
$this->tpl->addJavaScript("assets/js/AdvancedSelectionList.js");
$this->tpl->addCss(ilObjStyleSheet::getBaseContentStylePath());
$this->tpl->setContent($this->getEditDataTable(true));
}
Expand Down
4 changes: 2 additions & 2 deletions components/ILIAS/COPage/Resources/ResourcesCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ protected function init(\ilPageObject $pg): void
if ($this->output_mode == \ilPageObjectGUI::OFFLINE) {
$this->js_files[] = \iljQueryUtil::getLocaljQueryPath();
$this->js_files[] = \iljQueryUtil::getLocaljQueryUIPath();
$this->js_files[] = './components/ILIAS/JavaScript/js/Basic.js';
$this->js_files[] = 'assets/js/Basic.js';
}

$this->js_files[] = "./components/ILIAS/COPage/js/ilCOPagePres.js";
$this->js_files[] = "components/ILIAS/COPage/js/ilCOPagePres.js";

// for all page components...
$defs = $this->pc_definition->getPCDefinitions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function exportStyles(): void
$this->exp_dir . "/" . ilObjStyleSheet::getBasicImageDir()
);
ilFileUtils::makeDirParents($this->exp_dir . "/components/ILIAS/COPage/css");
copy("components/ILIAS/COPage/css/content.css", $this->exp_dir . "/components/ILIAS/COPage/css/content.css");
copy("components/ILIAS/COPage/resources/content.css", $this->exp_dir . "/components/ILIAS/COPage/css/content.css");
} else {
$style = new ilObjStyleSheet($this->getContentStyleId());
$style->copyImagesToDir($this->exp_dir . "/" . $style->getImagesDirectory());
Expand Down
6 changes: 3 additions & 3 deletions components/ILIAS/COPage/classes/class.ilPageObjectGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ public function showPage(): string
// $this->initSelfAssessmentRendering();
ilObjMediaObjectGUI::includePresentationJS($main_tpl);

$main_tpl->addJavaScript("./components/ILIAS/COPage/js/ilCOPagePres.js");
$main_tpl->addJavaScript("components/ILIAS/COPage/js/ilCOPagePres.js");

// needed for overlays in iim
ilOverlayGUI::initJavascript();
Expand Down Expand Up @@ -2428,7 +2428,7 @@ protected function initEditing(): void
$this->lng->toJS("copg_par_format_selection");
// workaroun: we need this js for the new editor version, e.g. for new section form to work
// @todo: solve this in a smarter way
$this->tpl->addJavaScript("./components/ILIAS/UIComponent/AdvancedSelectionList/js/AdvancedSelectionList.js");
$this->tpl->addJavaScript("assets/js/AdvancedSelectionList.js");
\ilCalendarUtil::initDateTimePicker();
ilModalGUI::initJS();
}
Expand Down Expand Up @@ -2599,7 +2599,7 @@ public function history(): string

$this->setBackToEditTabs();

$this->tpl->addJavaScript("./components/ILIAS/COPage/js/page_history.js");
$this->tpl->addJavaScript("assets/js/page_history.js");

$table_gui = new ilPageHistoryTableGUI($this, "history");
$table_gui->setId("hist_table");
Expand Down
Loading

0 comments on commit 17210ea

Please sign in to comment.