Răsfoiți Sursa

Adding a new option in the configuration file called 'name_order_conventions' in order to overwrite the values of the name_order_conventions.php file see BT#6535

Julio Montoya 11 ani în urmă
părinte
comite
6ad2a9d547

+ 1 - 0
config/configuration.dist.php

@@ -158,3 +158,4 @@ $_configuration['debug']             = false;
 $_configuration['platform_charset']  = 'utf-8';
 // Show a useful toolbar with memory used, loaded time, request, session, logs information.
 $_configuration['show_profiler']     = false;
+$_configuration['name_order_conventions'] = array();

+ 20 - 29
main/inc/global.inc.php

@@ -205,15 +205,25 @@ $app['template.hide_global_chat'] = true;
 $app['template.load_plugins'] = true;
 $app['configuration'] = $_configuration;
 
+// Inclusion of internationalization libraries
+require_once $libPath.'internationalization.lib.php';
+// Functions for internal use behind this API
+require_once $libPath.'internationalization_internal.lib.php';
+
 $_plugins = array();
 if ($alreadyInstalled) {
-
     /** Including service providers */
     require_once 'services.php';
 }
 
 $charset = 'UTF-8';
 
+// Preserving the value of the global variable $charset.
+$charset_initial_value = $charset;
+
+// Section (tabs in the main Chamilo menu)
+$app['this_section'] = SECTION_GLOBAL;
+
 // Manage Chamilo error messages
 $app->error(
     function (\Exception $e, $code) use ($app) {
@@ -262,17 +272,6 @@ $app->error(
     }
 );
 
-// Preserving the value of the global variable $charset.
-$charset_initial_value = $charset;
-
-// Section (tabs in the main Chamilo menu)
-$app['this_section'] = SECTION_GLOBAL;
-
-// Inclusion of internationalization libraries
-require_once $libPath.'internationalization.lib.php';
-// Functions for internal use behind this API
-require_once $libPath.'internationalization_internal.lib.php';
-
 // Checking if we have a valid language. If not we set it to the platform language.
 $cidReset = null;
 
@@ -286,7 +285,6 @@ if ($alreadyInstalled) {
 
     // require $includePath.'/local.inc.php';
 
-
     /**	Loading languages and sublanguages **/
     // @todo improve the language loading
 
@@ -389,12 +387,6 @@ $language_files[] = 'trad4all';
 $language_files[] = 'notification';
 $language_files[] = 'accessibility';
 
-// @todo Added because userportal and index are loaded by a controller should be fixed when a $app['translator'] is configured
-$language_files[] = 'index';
-$language_files[] = 'courses';
-$language_files[] = 'course_home';
-$language_files[] = 'exercice';
-
 if (isset($language_file)) {
     if (!is_array($language_file)) {
         $language_files[] = $language_file;
@@ -443,10 +435,8 @@ if (is_array($language_files)) {
         }
     }
 }*/
-
 // End loading languages
 
-
 /** Silex Middlewares. */
 
 /** A "before" middleware allows you to tweak the Request before the controller is executed. */
@@ -473,13 +463,12 @@ $app->before(
         }
 
         // Check data folder
-
-        if (!is_writable(api_get_path(SYS_DATA_PATH))) {
+        if (!is_writable($app['sys_data_path'])) {
             $app->abort(500, "data folder must be writable.");
         }
 
         // Checks temp folder permissions.
-        if (!is_writable(api_get_path(SYS_ARCHIVE_PATH))) {
+        if (!is_writable($app['sys_temp_path'])) {
             $app->abort(500, "data/temp folder must be writable.");
         }
 
@@ -488,7 +477,10 @@ $app->before(
             $app->abort(500, '$configuration array must be set in the configuration.php file.');
         }
 
-        if (!isset($app['configuration']['root_web'])) {
+        $configuration = $app['configuration'];
+
+        // Check if root_web exists
+        if (!isset($configuration['root_web'])) {
             $app->abort(500, '$configuration[root_web] must be set in the configuration.php file.');
         }
 
@@ -512,19 +504,18 @@ $app->before(
             $filesystem->copyFolders($app['temp.paths']->copyFolders);
         }
 
-
         // Check and modify the date of user in the track.e.online table
         Online::loginCheck(api_get_user_id());
 
-
         // Setting access_url id (multiple url feature)
 
         if (api_get_multiple_access_url()) {
             $_configuration = $app['configuration'];
             $_configuration['access_url'] = 1;
-
             $access_urls = api_get_access_urls();
-            $protocol = ((!empty($_SERVER['HTTPS']) && strtoupper($_SERVER['HTTPS']) != 'OFF') ? 'https' : 'http').'://';
+
+            //$protocol = ((!empty($_SERVER['HTTPS']) && strtoupper($_SERVER['HTTPS']) != 'OFF') ? 'https' : 'http').'://';
+            $protocol = $request->getScheme().'://';
             $request_url1 = $protocol.$_SERVER['SERVER_NAME'].'/';
             $request_url2 = $protocol.$_SERVER['HTTP_HOST'].'/';
 

+ 1 - 6
main/inc/lib/internationalization.lib.php

@@ -124,14 +124,10 @@ $_api_is_translated_call = false;
  */
 function get_lang($variable, $reserved = null, $language = null)
 {
-    // In order to use $app['translator']
     global $app;
-    if ($app['debug']) {
-        //return $variable;
-    }
-
     $translated = $app['translator']->trans($variable);
     if ($translated == $variable) {
+        // Check the langVariable for BC
         $translated = $app['translator']->trans("lang$variable");
         if ($translated == "lang$variable") {
             return $variable;
@@ -139,7 +135,6 @@ function get_lang($variable, $reserved = null, $language = null)
     }
     return $translated;
 
-
     global $app;
     $language_interface = isset($app['language_interface']) ? $app['language_interface'] : api_get_language_interface();
 

+ 2 - 21
main/inc/lib/internationalization_internal.lib.php

@@ -167,9 +167,6 @@ function & _api_compare_n_grams(&$n_grams, $encoding, $max_delta = LANGUAGE_DETE
     return $result;
 }
 
-
-
-
 /**
  * Appendix to "Name order conventions"
  */
@@ -181,26 +178,10 @@ function & _api_compare_n_grams(&$n_grams, $encoding, $max_delta = LANGUAGE_DETE
  * @return mixed			Depending of the requested type, the returned result may be string or boolean; null is returned on error;
  */
 function _api_get_person_name_convention($language, $type) {
-    static $conventions;
+    global $app;
+    $conventions = $app['name_order_conventions'];
     $language = api_purify_language_id($language);
-    if (!isset($conventions)) {
-        $file = dirname(__FILE__).'/internationalization_database/name_order_conventions.php';
 
-        if (file_exists($file)) {
-            $conventions = include $file;
-        } else {
-            $conventions = array('english' => array('format' => 'title first_name last_name', 'sort_by' => 'first_name'));
-        }
-        $search1 = array('FIRST_NAME', 'LAST_NAME', 'TITLE');
-        $replacement1 = array('%F', '%L', '%T');
-        $search2 = array('first_name', 'last_name', 'title');
-        $replacement2 = array('%f', '%l', '%t');
-        foreach (array_keys($conventions) as $key) {
-            $conventions[$key]['format'] = str_replace($search1, $replacement1, $conventions[$key]['format']);
-            $conventions[$key]['format'] = _api_validate_person_name_format(_api_clean_person_name(str_replace('%', ' %', str_ireplace($search2, $replacement2, $conventions[$key]['format']))));
-            $conventions[$key]['sort_by'] = strtolower($conventions[$key]['sort_by']) != 'last_name' ? true : false;
-        }
-    }
     switch ($type) {
         case 'format':
             return is_string($conventions[$language]['format']) ? $conventions[$language]['format'] : '%t %f %l';

+ 25 - 0
main/inc/services.php

@@ -574,8 +574,33 @@ class ChamiloServiceProvider implements ServiceProviderInterface
             $mailGenerator = new ChamiloLMS\Component\Mail\MailGenerator($app['twig'], $app['mailer']);
             return $mailGenerator;
         });
+
+
+        // Setting up name conventions
+        $conventions = require_once $app['sys_root'].'main/inc/lib/internationalization_database/name_order_conventions.php';
+        if (isset($configuration['name_order_conventions']) && !empty($configuration['name_order_conventions'])) {
+            $conventions = array_merge($conventions, $configuration['name_order_conventions']);
+        }
+        $search1 = array('FIRST_NAME', 'LAST_NAME', 'TITLE');
+        $replacement1 = array('%F', '%L', '%T');
+        $search2 = array('first_name', 'last_name', 'title');
+        $replacement2 = array('%f', '%l', '%t');
+        $keyConventions = array_keys($conventions);
+        foreach ($keyConventions as $key) {
+            $conventions[$key]['format'] = str_replace($search1, $replacement1, $conventions[$key]['format']);
+            $conventions[$key]['format'] = _api_validate_person_name_format(
+                _api_clean_person_name(
+                    str_replace('%', ' %', str_ireplace($search2, $replacement2, $conventions[$key]['format']))
+                )
+            );
+            $conventions[$key]['sort_by'] = strtolower($conventions[$key]['sort_by']) != 'last_name' ? true : false;
+        }
+        $app['name_order_conventions'] = $conventions;
     }
 
+    /**
+     * @param Application $app
+     */
     public function boot(Application $app)
     {