From 6f80eb027678515f0916f1dea7006ecf22cb6a1a Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 26 Sep 2021 12:06:42 -0500 Subject: [PATCH] Learning path: Add script to translate html and bootstrap links - refs BT#19044 --- assets/js/translatehtml.js | 41 ++++++++++++++++--- public/main/lp/lp_controller.php | 3 +- .../Controller/ResourceController.php | 8 +++- .../Settings/CourseSettingsSchema.php | 2 + src/CoreBundle/Settings/SettingsManager.php | 1 + 5 files changed, 47 insertions(+), 8 deletions(-) diff --git a/assets/js/translatehtml.js b/assets/js/translatehtml.js index da55774bc3..a579b42521 100644 --- a/assets/js/translatehtml.js +++ b/assets/js/translatehtml.js @@ -7,17 +7,46 @@ document.addEventListener('DOMContentLoaded', function () { window.config['editor.translate_html'] && 'true' === window.config['editor.translate_html'] ) { - const isoCode = window.user.locale; + var isoCode = window.user.locale; const translateElement = document.querySelector('.mce-translatehtml'); if (translateElement) { document.querySelectorAll('.mce-translatehtml').forEach(function (el) { el.style.display = 'none'; }); const selectedLang = document.querySelectorAll('[lang="' + isoCode + '"]'); - selectedLang.forEach(function (userLang) { - userLang.classList.remove('hidden') - userLang.style.display = 'block'; - }); + if (selectedLang.length > 0) { + selectedLang.forEach(function (userLang) { + userLang.classList.remove('hidden') + userLang.style.display = 'block'; + }); + } + } else { + // it checks content from old version + const langs = document.querySelectorAll('span[lang]'); + if (langs.length > 0) { + // it hides all contents with lang + langs.forEach(function (el) { + el.style.display = 'none'; + }); + + // To show only the content by user language. + if (isoCode == 'pl_PL') { + isoCode = 'pl'; + } + if (isoCode == 'fr_FR') { + isoCode = 'fr'; + } + if (isoCode == 'en_US') { + isoCode = 'en'; + } + const selectedLang = document.querySelectorAll('span[lang="' + isoCode + '"]'); + if (selectedLang.length > 0) { + selectedLang.forEach(function (userLang) { + userLang.classList.remove('hidden') + userLang.style.display = 'block'; + }); + } + } } } -}); \ No newline at end of file +}); diff --git a/public/main/lp/lp_controller.php b/public/main/lp/lp_controller.php index b9c5486b1c..101f80c4de 100644 --- a/public/main/lp/lp_controller.php +++ b/public/main/lp/lp_controller.php @@ -523,6 +523,7 @@ switch ($action) { $audio = $_FILES['mp3']; } + $previous = isset($_POST['previous']) ? $_POST['previous'] : ''; $description = isset($_POST['description']) ? $_POST['description'] : ''; $prerequisites = isset($_POST['prerequisites']) ? $_POST['prerequisites'] : ''; $maxTimeAllowed = isset($_POST['maxTimeAllowed']) ? $_POST['maxTimeAllowed'] : ''; @@ -531,7 +532,7 @@ switch ($action) { $oLP->edit_item( $_REQUEST['id'], $_POST['parent'], - $_POST['previous'], + $previous, $post_title, $description, $prerequisites, diff --git a/src/CoreBundle/Controller/ResourceController.php b/src/CoreBundle/Controller/ResourceController.php index 76b59a5bac..946f9269da 100644 --- a/src/CoreBundle/Controller/ResourceController.php +++ b/src/CoreBundle/Controller/ResourceController.php @@ -521,7 +521,13 @@ class ResourceController extends AbstractResourceController implements CourseCon $content = str_replace('', $js.'', $content); } } - + if ('true' === $this->getSettingsManager()->getSetting('course.enable_bootstrap_in_documents_html')) { + // It adds the bootstrap and awesome css + $links = ''; + $links .= ''; + // Insert inside the head tag. + $content = str_replace('', $links.'', $content); + } $response->setContent($content); /*$contents = $this->renderView('@ChamiloCore/Resource/view_html.twig', [ 'category' => '...', diff --git a/src/CoreBundle/Settings/CourseSettingsSchema.php b/src/CoreBundle/Settings/CourseSettingsSchema.php index 6d95d45304..3f2ad9888b 100644 --- a/src/CoreBundle/Settings/CourseSettingsSchema.php +++ b/src/CoreBundle/Settings/CourseSettingsSchema.php @@ -83,6 +83,7 @@ class CourseSettingsSchema extends AbstractSettingsSchema 'lp_show_reduced_report' => 'false', 'course_creation_splash_screen' => 'true', 'block_registered_users_access_to_open_course_contents' => 'false', + 'enable_bootstrap_in_documents_html' => 'false', // @todo ] ) @@ -222,6 +223,7 @@ class CourseSettingsSchema extends AbstractSettingsSchema ->add('lp_show_reduced_report', YesNoType::class) ->add('course_creation_splash_screen', YesNoType::class) ->add('block_registered_users_access_to_open_course_contents', YesNoType::class) + ->add('enable_bootstrap_in_documents_html', YesNoType::class) ; } } diff --git a/src/CoreBundle/Settings/SettingsManager.php b/src/CoreBundle/Settings/SettingsManager.php index e6bda55983..5eca6862f3 100644 --- a/src/CoreBundle/Settings/SettingsManager.php +++ b/src/CoreBundle/Settings/SettingsManager.php @@ -861,6 +861,7 @@ class SettingsManager implements SettingsManagerInterface 'gradebook_show_percentage_in_reports' => 'gradebook', 'course_creation_splash_screen' => 'Course', 'translate_html' => 'Editor', + 'enable_bootstrap_in_documents_html' => 'Course', ]; }