Browse Source

Add language filter in course home see BT#15166

Julio Montoya 6 years ago
parent
commit
b730c8e823

+ 3 - 0
main/course_home/course_home.php

@@ -32,6 +32,9 @@ use Fhaculty\Graph\Graph;
 $use_anonymous = true;
 require_once __DIR__.'/../inc/global.inc.php';
 
+$js = '<script>'.api_get_language_translate_html().'</script>';
+$htmlHeadXtra[] = $js;
+
 $htmlHeadXtra[] = '<script>
 /* option show/hide thematic-block */
 $(function() {

+ 0 - 19
main/forum/forumfunction.inc.php

@@ -6938,22 +6938,3 @@ function reportPost($postId, $forumInfo, $threadInfo)
     }
 }
 
-/**
- * @return array
- */
-function getLanguageListForFlag()
-{
-    $table = Database::get_main_table(TABLE_MAIN_LANGUAGE);
-    $sql = "SELECT english_name, isocode FROM $table 
-            ORDER BY original_name ASC";
-    static $languages = [];
-    if (empty($languages)) {
-        $result = Database::query($sql);
-        while ($row = Database::fetch_array($result)) {
-            $languages[$row['english_name']] = $row['isocode'];
-        }
-        $languages['english'] = 'gb';
-    }
-
-    return $languages;
-}

+ 1 - 2
main/forum/index.php

@@ -211,8 +211,7 @@ if (!empty($allCourseForums)) {
 
 $actions = Display::toolbarAction('toolbar-forum', [$actionLeft]);
 
-$languages = getLanguageListForFlag();
-
+$languages = api_get_language_list_for_flag();
 $defaultUserLanguage = ucfirst(api_get_interface_language());
 if (isset($_user['language']) && !empty($_user['language'])) {
     $defaultUserLanguage = ucfirst($_user['language']);

+ 2 - 2
main/forum/viewthread.php

@@ -474,7 +474,7 @@ foreach ($posts as $post) {
             $languageId = api_get_language_id(strtolower($revision));
             $languageInfo = api_get_language_info($languageId);
             if ($languageInfo) {
-                $languages = getLanguageListForFlag();
+                $languages = api_get_language_list_for_flag();
                 $flagRevision = '<span class="flag-icon flag-icon-'.$languages[$languageInfo['english_name']].'"></span> ';
             }
         }
@@ -488,7 +488,7 @@ foreach ($posts as $post) {
                 $languageId = api_get_language_id(strtolower($revision));
                 $languageInfo = api_get_language_info($languageId);
                 if ($languageInfo) {
-                    $languages = getLanguageListForFlag();
+                    $languages = api_get_language_list_for_flag();
                     $flagRevision = '<span class="flag-icon flag-icon-'.$languages[$languageInfo['english_name']].'"></span> ';
                 }
             }

+ 1 - 57
main/inc/ajax/lang.ajax.php

@@ -14,63 +14,7 @@ switch ($action) {
     case 'translate_html':
         header('Content-type: application/x-javascript');
 
-        $translate = api_get_configuration_value('translate_html');
-
-        if (!$translate) {
-            exit;
-        }
-
-        $languageList = api_get_languages();
-        $hideAll = '';
-        foreach ($languageList['all'] as $language) {
-            $hideAll .= '$("span:lang('.$language['isocode'].')").filter(
-            function() {
-                // Ignore ckeditor classes
-                return !this.className.match(/cke(.*)/);
-            }).hide();';
-        }
-
-        $userInfo = api_get_user_info();
-        $languageId = api_get_language_id($userInfo['language']);
-        $languageInfo = api_get_language_info($languageId);
-
-        echo '
-            $(function() {
-                 '.$hideAll.'                 
-                var defaultLanguageFromUser = "'.$languageInfo['isocode'].'";                                
-                $("span:lang('.$languageInfo['isocode'].')").filter(
-                    function() {
-                        // Ignore ckeditor classes
-                        return !this.className.match(/cke(.*)/);
-                }).show();
-                
-                var defaultLanguage = "";
-                var langFromUserFound = false;
-                $(this).find("span").filter(
-                    function() {
-                        // Ignore ckeditor classes
-                        return !this.className.match(/cke(.*)/);
-                }).each(function() {
-                    defaultLanguage = $(this).attr("lang");                            
-                    if (defaultLanguage) {
-                        $(this).before().next("br").remove();                
-                        if (defaultLanguageFromUser == defaultLanguage) {
-                            langFromUserFound = true;
-                        }
-                    }
-                });
-                
-                // Show default language
-                if (langFromUserFound == false && defaultLanguage) {
-                    $("span:lang("+defaultLanguage+")").filter(
-                    function() {
-                            // Ignore ckeditor classes
-                            return !this.className.match(/cke(.*)/);
-                    }).show();
-                }                  
-
-            });
-        ';
+        echo api_get_language_translate_html();
         break;
     default:
         echo '';

+ 1 - 1
main/inc/introductionSection.inc.php

@@ -54,7 +54,7 @@ if (!empty($courseId)) {
 }
 
 $config = [
-    'ToolbarSet' => 'Basic',
+    'ToolbarSet' => 'IntroductionSection',
     'Width' => '100%',
     'Height' => '300',
 ];

+ 88 - 0
main/inc/lib/api.lib.php

@@ -9460,3 +9460,91 @@ function api_find_template($template)
 {
     return Template::findTemplateFilePath($template);
 }
+
+/**
+ * @return array
+ */
+function api_get_language_list_for_flag()
+{
+    $table = Database::get_main_table(TABLE_MAIN_LANGUAGE);
+    $sql = "SELECT english_name, isocode FROM $table 
+            ORDER BY original_name ASC";
+    static $languages = [];
+    if (empty($languages)) {
+        $result = Database::query($sql);
+        while ($row = Database::fetch_array($result)) {
+            $languages[$row['english_name']] = $row['isocode'];
+        }
+        $languages['english'] = 'gb';
+    }
+
+    return $languages;
+}
+
+/**
+ *
+ * @return string
+ *
+ */
+function api_get_language_translate_html()
+{
+    $translate = api_get_configuration_value('translate_html');
+
+    if (!$translate) {
+       return '';
+    }
+
+    $languageList = api_get_languages();
+    $hideAll = '';
+    foreach ($languageList['all'] as $language) {
+        $hideAll .=
+            '$("span:lang('.$language['isocode'].')").filter(
+                function() {
+                    // Ignore ckeditor classes
+                    return !this.className.match(/cke(.*)/);
+            }).hide();';
+    }
+
+    $userInfo = api_get_user_info();
+    $languageId = api_get_language_id($userInfo['language']);
+    $languageInfo = api_get_language_info($languageId);
+
+    return '
+            $(function() {
+                '.$hideAll.'                 
+                var defaultLanguageFromUser = "'.$languageInfo['isocode'].'";   
+                                             
+                $("span:lang('.$languageInfo['isocode'].')").filter(
+                    function() {
+                        // Ignore ckeditor classes
+                        return !this.className.match(/cke(.*)/);
+                }).show();
+                
+                var defaultLanguage = "";
+                var langFromUserFound = false;
+                
+                $(this).find("span").filter(
+                    function() {
+                        // Ignore ckeditor classes
+                        return !this.className.match(/cke(.*)/);
+                }).each(function() {
+                    defaultLanguage = $(this).attr("lang");                            
+                    if (defaultLanguage) {
+                        $(this).before().next("br").remove();                
+                        if (defaultLanguageFromUser == defaultLanguage) {
+                            langFromUserFound = true;
+                        }
+                    }
+                });
+                
+                // Show default language
+                if (langFromUserFound == false && defaultLanguage) {
+                    $("span:lang("+defaultLanguage+")").filter(
+                    function() {
+                            // Ignore ckeditor classes
+                            return !this.className.match(/cke(.*)/);
+                    }).show();
+                }
+            });
+    ';
+}

+ 2 - 2
main/work/work.lib.php

@@ -1005,7 +1005,7 @@ function to_javascript_work()
             $("#work_title").focus();
         }
 
-        $(document).ready(function() {
+        $(function() {
             setFocus();
             var checked = $("#expiry_date").attr("checked");
             if (checked) {
@@ -2101,7 +2101,7 @@ function get_work_user_list(
                     ';
 
                     $correction .= "<script>
-                    $(document).ready(function() {
+                    $(function() {
                         $('.work_correction_file_upload').each(function () {
                             $(this).fileupload({
                                 dropZone: $(this)

+ 135 - 0
src/Chamilo/CoreBundle/Component/Editor/CkEditor/Toolbar/IntroductionSection.php

@@ -0,0 +1,135 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+namespace Chamilo\CoreBundle\Component\Editor\CkEditor\Toolbar;
+
+/**
+ * Documents toolbar configuration.
+ *
+ * @package Chamilo\CoreBundle\Component\Editor\CkEditor\Toolbar
+ */
+class IntroductionSection extends Basic
+{
+    public $plugins = [];
+
+    /**
+     * Get the toolbar config.
+     *
+     * @return array
+     */
+    public function getConfig()
+    {
+        $config = [];
+
+        if (api_get_setting('more_buttons_maximized_mode') !== 'true') {
+            $config['toolbar'] = $this->getNormalToolbar();
+        } else {
+            $config['toolbar_minToolbar'] = $this->getMinimizedToolbar();
+        }
+
+        $config['extraPlugins'] = $this->getPluginsToString();
+        $config['fullPage'] = true;
+
+        return $config;
+    }
+
+    /**
+     * @return array
+     */
+    public function getConditionalPlugins()
+    {
+        $plugins = [];
+
+        if (api_get_setting('show_glossary_in_documents') === 'ismanual') {
+            $plugins[] = 'glossary';
+        }
+
+        return $plugins;
+    }
+
+    /**
+     * Get the default toolbar configuration when the setting more_buttons_maximized_mode is false.
+     *
+     * @return array
+     */
+    protected function getNormalToolbar()
+    {
+        return [
+            ['Maximize', 'PasteFromWord', '-', 'Undo', 'Redo'],
+            ['Link', 'Unlink', 'Anchor', 'inserthtml', 'Glossary'],
+            [
+                'Image',
+                'Video',
+                'Flash',
+                'Oembed',
+                'Youtube',
+                'Audio',
+                'Asciimath',
+                'Asciisvg',
+            ],
+            ['Table', 'SpecialChar'],
+            [
+                'Outdent',
+                'Indent',
+                '-',
+                'TextColor',
+                'BGColor',
+                '-',
+                'NumberedList',
+                'BulletedList',
+                '-',
+                api_get_configuration_value('translate_html') ? 'Language' : '',
+                api_get_setting('allow_spellcheck') === 'true' ? 'Scayt' : '',
+            ],
+            '/',
+            ['Styles', 'Format', 'Font', 'FontSize'],
+            ['Bold', 'Italic', 'Underline'],
+            ['JustifyLeft', 'JustifyCenter', 'JustifyRight'],
+            api_get_setting('enabled_wiris') === 'true' ? ['ckeditor_wiris_formulaEditor', 'ckeditor_wiris_CAS'] : [''],
+            ['Source'],
+        ];
+    }
+
+    /**
+     * Get the toolbar configuration when CKEditor is minimized.
+     *
+     * @return array
+     */
+    protected function getMinimizedToolbar()
+    {
+        return [
+            $this->getNewPageBlock(),
+            ['Undo', 'Redo'],
+            [
+                'Link',
+                'Image',
+                'Video',
+                'Flash',
+                'Youtube',
+                'Audio',
+                'Table',
+                'Asciimath',
+                'Asciisvg',
+            ],
+            ['BulletedList', 'NumberedList', 'HorizontalRule'],
+            ['JustifyLeft', 'JustifyCenter', 'JustifyBlock'],
+            ['Styles',
+                'Format',
+                'Font',
+                'FontSize',
+                'Bold',
+                'Italic',
+                'Underline',
+                'TextColor',
+                'BGColor',
+            ],
+            [
+                'Language',
+                'ShowBlocks',
+                'Source',
+            ],
+            api_get_setting('enabled_wiris') === 'true' ? ['ckeditor_wiris_formulaEditor', 'ckeditor_wiris_CAS'] : [''],
+            ['Toolbarswitch'],
+        ];
+    }
+}