From 14dbb82afb3829ede099041203085913e6d5b05f Mon Sep 17 00:00:00 2001
From: Julio Montoya <gugli100@gmail.com>
Date: Thu, 18 Oct 2018 11:07:51 +0200
Subject: [PATCH] Fix asset url in order to work with legacy and new code

---
 .../layout/welcome_to_course.html.twig        | 17 ------------
 src/CoreBundle/Resources/config/routing.yml   |  3 +++
 .../views/Layout/base-layout.html.twig        |  2 +-
 .../Resources/views/Layout/head.html.twig     | 10 +++----
 .../views/Layout/legacy_js.html.twig          |  4 +--
 .../views/Layout/no_layout.html.twig          |  2 +-
 .../Resources/views/Layout/topbar.html.twig   |  2 +-
 .../views/Layout/welcome_to_course.html.twig  | 24 +++++++++++++++++
 .../layout/welcome_to_course.html.twig        | 26 -------------------
 9 files changed, 37 insertions(+), 53 deletions(-)
 delete mode 100644 main/template/default/layout/welcome_to_course.html.twig
 create mode 100644 src/ThemeBundle/Resources/views/Layout/welcome_to_course.html.twig
 delete mode 100644 src/ThemeBundle/Resources/views/default/layout/welcome_to_course.html.twig

diff --git a/main/template/default/layout/welcome_to_course.html.twig b/main/template/default/layout/welcome_to_course.html.twig
deleted file mode 100644
index babae3eac5..0000000000
--- a/main/template/default/layout/welcome_to_course.html.twig
+++ /dev/null
@@ -1,17 +0,0 @@
-<div class="normal-message">
-  {{ "HelloXAsYouCanSeeYourCourseListIsEmpty"|get_lang | format(_u.complete_name) }}
-
-{% if count_courses  == 0 %}
-    {{ "PleaseAllowUsALittleTimeToSubscribeYouToOneOfOurCourses"|get_lang }}
-{% else %}
-
-    {% if "allow_students_to_browse_courses"|api_get_setting  == 'true' %}
-        {{ "GoAheadAndBrowseOurCourseCatalogXOnceRegisteredYouWillSeeTheCourseHereX"|get_lang|format(course_catalog_link, course_list_link) }}
-        <a class="btn btn-primary btn-large" href="{{ course_catalog_url }}">
-            {{ "CourseCatalog"|get_lang }}
-        </a>
-    {% else %}
-        {{ "PleaseAllowUsALittleTimeToSubscribeYouToOneOfOurCourses"|get_lang }}
-    {% endif %}
-{% endif %}
-</div>
\ No newline at end of file
diff --git a/src/CoreBundle/Resources/config/routing.yml b/src/CoreBundle/Resources/config/routing.yml
index 8eedeb266d..d67aa261a7 100644
--- a/src/CoreBundle/Resources/config/routing.yml
+++ b/src/CoreBundle/Resources/config/routing.yml
@@ -1,4 +1,7 @@
 # Legacy routes
+legacy_public:
+    path: ../public/
+
 legacy_index:
     path: ../
 
diff --git a/src/ThemeBundle/Resources/views/Layout/base-layout.html.twig b/src/ThemeBundle/Resources/views/Layout/base-layout.html.twig
index 016af367ab..068f1109b4 100644
--- a/src/ThemeBundle/Resources/views/Layout/base-layout.html.twig
+++ b/src/ThemeBundle/Resources/views/Layout/base-layout.html.twig
@@ -52,7 +52,7 @@
                             <div class="peers ai-c fxw-nw">
                                 <div class="peer">
                                     <div class="logo">
-                                        <img src="{{ asset('build/css/themes/'~ theme ~'/images/logo_chamilo.svg') }}"/>
+                                        <img src="{{ url('legacy_public') ~ 'build/css/themes/'~ theme ~'/images/logo_chamilo.svg' }}"/>
                                     </div>
                                 </div>
                             </div>
diff --git a/src/ThemeBundle/Resources/views/Layout/head.html.twig b/src/ThemeBundle/Resources/views/Layout/head.html.twig
index d8602536e6..2c816cdc39 100644
--- a/src/ThemeBundle/Resources/views/Layout/head.html.twig
+++ b/src/ThemeBundle/Resources/views/Layout/head.html.twig
@@ -4,7 +4,7 @@
 <link href="https://chamilo.org/chamilo-lms/" rel="help"/>
 <link href="https://chamilo.org/the-association/" rel="author"/>
 <link href="https://chamilo.org/the-association/" rel="copyright"/>
-<link rel="apple-touch-icon" href="{{ asset('apple-touch-icon.png') }}"/>
+<link rel="apple-touch-icon" href="{{ url('legacy_public') ~ 'apple-touch-icon.png' }}"/>
 {% autoescape false %}
     {{ favico }}
 {% endautoescape %}
@@ -28,13 +28,13 @@
 {% set message_link = '' %}
 
 {# Files app.css is generated from "assets/css/app.scss" file using the file webpack.config.js #}
-<link rel="stylesheet" href="{{ asset('build/css/app.css') }}"/>
-<link rel="stylesheet" href="{{ asset('build/css/themes/'~ theme ~'/default.css') }}"/>
-<link rel="stylesheet" media="print" href="{{ asset('build/css/print.css') }}"/>
+<link rel="stylesheet" href="{{ url('legacy_public') ~ 'build/css/app.css' }}"/>
+<link rel="stylesheet" href="{{ url('legacy_public') ~ 'build/css/themes/'~ theme ~'/default.css' }}"/>
+<link rel="stylesheet" media="print" href="{{ url('legacy_public') ~ 'build/css/print.css' }}"/>
 {# Add third party js libraries that can't be loaded using webpack #}
 {% include "@ChamiloTheme/Layout/legacy_js.html.twig" %}
 {# app.js is generated using the file webpack.config.js and using yarn read /assets/README.md for more info #}
-<script src="{{ asset('build/app.js') }}"></script>
+<script src="{{ url('legacy_public') ~ 'build/app.js' }}"></script>
 
 {# Check chamilo_js key in assetic.yml #}
 {% block javascripts %}
diff --git a/src/ThemeBundle/Resources/views/Layout/legacy_js.html.twig b/src/ThemeBundle/Resources/views/Layout/legacy_js.html.twig
index 7020802199..9d579ce28a 100644
--- a/src/ThemeBundle/Resources/views/Layout/legacy_js.html.twig
+++ b/src/ThemeBundle/Resources/views/Layout/legacy_js.html.twig
@@ -1,6 +1,6 @@
 {# Files that can't be loaded using webpack #}
 
-<script src="{{ asset('libs/ckeditor/ckeditor.js') }}"></script>
+<script src="{{ url('legacy_public') ~ 'libs/ckeditor/ckeditor.js' }}"></script>
 {#<script src="{{ asset('libs/readmore-js/readmore.js') }}"></script>#}
-<script src="{{ asset('libs/js-cookie/src/js.cookie.js') }}"></script>
+<script src="{{ url('legacy_public') ~ 'libs/js-cookie/src/js.cookie.js' }}"></script>
 
diff --git a/src/ThemeBundle/Resources/views/Layout/no_layout.html.twig b/src/ThemeBundle/Resources/views/Layout/no_layout.html.twig
index 08d8ac7474..442d11e135 100644
--- a/src/ThemeBundle/Resources/views/Layout/no_layout.html.twig
+++ b/src/ThemeBundle/Resources/views/Layout/no_layout.html.twig
@@ -2,7 +2,7 @@
 {# overrides everything inside body no-footer no-header #}
 {% block chamilo_wrap %}
     {% autoescape false %}
-        <link rel="stylesheet" href="{{ asset('build/css/scorm.css') }}"/>
+        <link rel="stylesheet" href="{{ url('legacy_public') ~ 'build/css/scorm.css' }}"/>
         <section id="content-scorm">
         {{ content }}
         </section>
diff --git a/src/ThemeBundle/Resources/views/Layout/topbar.html.twig b/src/ThemeBundle/Resources/views/Layout/topbar.html.twig
index 77600c48c9..f06062d563 100644
--- a/src/ThemeBundle/Resources/views/Layout/topbar.html.twig
+++ b/src/ThemeBundle/Resources/views/Layout/topbar.html.twig
@@ -70,7 +70,7 @@
             });
 
             /**
-             * Wait untill sidebar fully toggled (animated in/out)
+             * Wait until sidebar fully toggled (animated in/out)
              * then trigger window resize event in order to recalculate
              * masonry layout widths and gutters.
              */
diff --git a/src/ThemeBundle/Resources/views/Layout/welcome_to_course.html.twig b/src/ThemeBundle/Resources/views/Layout/welcome_to_course.html.twig
new file mode 100644
index 0000000000..5c36865a2f
--- /dev/null
+++ b/src/ThemeBundle/Resources/views/Layout/welcome_to_course.html.twig
@@ -0,0 +1,24 @@
+{% autoescape false %}
+    {{ "HelloXAsYouCanSeeYourCourseListIsEmpty" | trans | format(app.user.completeName) }}
+
+    {% if count_courses == 0 %}
+        {{ "PleaseAllowUsALittleTimeToSubscribeYouToOneOfOurCourses"|trans }}
+    {% else %}
+
+        {% if chamilo_settings_get("display.allow_students_to_browse_courses")  == 'true' %}
+            {{
+            "GoAheadAndBrowseOurCourseCatalogXOnceRegisteredYouWillSeeTheCourseHereX" | trans |
+            format(
+                '<a href="' ~ url('main', {'name': 'auth/courses.php'}) ~ '"/> '~ "here" | trans ~'</a>',
+                '<a href="' ~ url('userportal') ~ '"/> '~ "here" | trans ~'</a>'
+            )
+            }}
+
+                <a class="btn btn-primary btn-large" href="{{ url('main', {'name': 'auth/courses.php'}) }}">
+                    {{ "CourseCatalog"|trans }}
+                </a>
+        {% else %}
+            {{ "PleaseAllowUsALittleTimeToSubscribeYouToOneOfOurCourses"|trans }}
+        {% endif %}
+    {% endif %}
+{% endautoescape %}
diff --git a/src/ThemeBundle/Resources/views/default/layout/welcome_to_course.html.twig b/src/ThemeBundle/Resources/views/default/layout/welcome_to_course.html.twig
deleted file mode 100644
index b1065ed103..0000000000
--- a/src/ThemeBundle/Resources/views/default/layout/welcome_to_course.html.twig
+++ /dev/null
@@ -1,26 +0,0 @@
-{% autoescape false %}
-
-{{ "HelloXAsYouCanSeeYourCourseListIsEmpty" | trans | format(app.user.completeName) }}
-
-{% if count_courses == 0 %}
-    {{ "PleaseAllowUsALittleTimeToSubscribeYouToOneOfOurCourses"|trans }}
-{% else %}
-
-    {% if chamilo_settings_get("display.allow_students_to_browse_courses")  == 'true' %}
-        {{
-            "GoAheadAndBrowseOurCourseCatalogXOnceRegisteredYouWillSeeTheCourseHereX" | trans |
-            format(
-                '<a href="' ~ url('main', {'name': 'auth/courses.php'}) ~ '"/> '~ "here" | trans ~'</a>',
-                '<a href="' ~ url('userportal') ~ '"/> '~ "here" | trans ~'</a>'
-            )
-        }}
-
-        <a class="btn btn-primary btn-large" href="{{ url('main', {'name': 'auth/courses.php'}) }}">
-            {{ "CourseCatalog"|trans }}
-        </a>
-    {% else %}
-        {{ "PleaseAllowUsALittleTimeToSubscribeYouToOneOfOurCourses"|trans }}
-    {% endif %}
-{% endif %}
-
-{% endautoescape %}