Merge branch '1.11.x' of github.com:chamilo/chamilo-lms into 1.11.x

pull/2483/head
jmontoyaa 8 years ago
commit 0b2c6030cd
  1. 30
      main/cron/lang/list_undefined_langvars.php
  2. 30
      main/cron/lang/list_unused_langvars.php
  3. 91
      main/cron/lang/switch_files_to_gettext.php
  4. 46
      main/inc/lib/fileManage.lib.php
  5. 2
      main/inc/lib/statistics.lib.php
  6. 3
      main/lang/english/trad4all.inc.php
  7. 3
      main/lang/french/trad4all.inc.php
  8. 7
      main/lang/spanish/trad4all.inc.php
  9. 13
      main/lp/lp_edit.php
  10. 37
      tests/scripts/img/list_unused_img.php
  11. 26
      tests/scripts/img/list_used_img.php

@ -8,7 +8,7 @@
* Includes and declarations.
*/
die();
require_once '../../inc/global.inc.php';
require_once __DIR__.'/../../inc/global.inc.php';
$path = api_get_path(SYS_LANG_PATH).'english';
ini_set('memory_limit', '128M');
/**
@ -29,7 +29,7 @@ $terms = null;
// now get all terms found in all PHP files of Chamilo (this takes some time and memory)
$undefined_terms = [];
$l = strlen(api_get_path(SYS_PATH));
$files = get_all_php_files(api_get_path(SYS_PATH));
$files = getAllPhpFiles(api_get_path(SYS_PATH));
foreach ($files as $file) {
//echo 'Analyzing '.$file."<br />";
$shortfile = substr($file, $l);
@ -73,29 +73,3 @@ foreach ($undefined_terms as $term => $file) {
}
echo "</table>\n";
function get_all_php_files($base_path)
{
$list = scandir($base_path);
$files = [];
foreach ($list as $item) {
if (substr($item, 0, 1) == '.') {
continue;
}
$special_dirs = [api_get_path(SYS_TEST_PATH), api_get_path(SYS_COURSE_PATH), api_get_path(SYS_LANG_PATH), api_get_path(SYS_ARCHIVE_PATH)];
if (in_array($base_path.$item.'/', $special_dirs)) {
continue;
}
if (is_dir($base_path.$item)) {
$files = array_merge($files, get_all_php_files($base_path.$item.'/'));
} else {
//only analyse php files
$sub = substr($item, -4);
if ($sub == '.php' or $sub == '.tpl') {
$files[] = $base_path.$item;
}
}
}
$list = null;
return $files;
}

@ -8,7 +8,7 @@
* Includes and declarations.
*/
die();
require_once '../../inc/global.inc.php';
require_once __DIR__.'/../../inc/global.inc.php';
$path = api_get_path(SYS_LANG_PATH).'english';
ini_set('memory_limit', '128M');
/**
@ -31,7 +31,7 @@ echo count($defined_terms)." terms were found in language files<br />";
// time and memory)
$usedTerms = [];
$l = strlen(api_get_path(SYS_PATH));
$files = get_all_php_files(api_get_path(SYS_PATH));
$files = getAllPhpFiles(api_get_path(SYS_PATH));
// Browse files
foreach ($files as $file) {
//echo 'Analyzing '.$file."<br />";
@ -86,29 +86,3 @@ foreach ($defined_terms as $term => $file) {
}
echo "</table>\n";
function get_all_php_files($base_path)
{
$list = scandir($base_path);
$files = [];
foreach ($list as $item) {
if (substr($item, 0, 1) == '.') {
continue;
}
$special_dirs = [api_get_path(SYS_TEST_PATH), api_get_path(SYS_COURSE_PATH), api_get_path(SYS_LANG_PATH), api_get_path(SYS_ARCHIVE_PATH)];
if (in_array($base_path.$item.'/', $special_dirs)) {
continue;
}
if (is_dir($base_path.$item)) {
$files = array_merge($files, get_all_php_files($base_path.$item.'/'));
} else {
//only analyse php files
$sub = substr($item, -4);
if ($sub == '.php' or $sub == '.tpl') {
$files[] = $base_path.$item;
}
}
}
$list = null;
return $files;
}

@ -0,0 +1,91 @@
<?php /* For licensing terms, see /license.txt */
/**
* Script to switch all PHP files in Chamilo to a more Gettext-like syntax
*
* @package chamilo.cron.lang
*/
/**
* Includes and declarations.
*/
die();
require_once __DIR__.'/../../inc/global.inc.php';
$path = api_get_path(SYS_LANG_PATH).'english';
ini_set('memory_limit', '128M');
/**
* Main code.
*/
$terms = [];
$list = SubLanguageManager::get_lang_folder_files_list($path);
foreach ($list as $entry) {
$file = $path.'/'.$entry;
if (is_file($file)) {
$terms = array_merge($terms, SubLanguageManager::get_all_language_variable_in_file($file, true));
}
}
foreach ($terms as $index => $translation) {
$terms[$index] = trim(rtrim($translation, ';'), '"');
}
// get only the array keys (the language variables defined in language files)
$defined_terms = array_flip(array_keys($terms));
echo count($defined_terms)." terms were found in language files".PHP_EOL;
// now get all terms found in all PHP files of Chamilo (this takes some
// time and memory)
$usedTerms = [];
$l = strlen(api_get_path(SYS_PATH));
$files = getAllPhpFiles(api_get_path(SYS_PATH));
$rootLength = strlen(api_get_path(SYS_PATH));
$countFiles = 0;
$countReplaces = 0;
// Browse files
foreach ($files as $file) {
if (substr($file, $rootLength, 6) === 'vendor' || substr($file, $rootLength, 3) === 'web') {
continue;
}
//echo 'Analyzing '.$file.PHP_EOL;
$shortFile = substr($file, $l);
//echo 'Analyzing '.$shortFile.PHP_EOL;
$lines = file($file);
// Browse lines inside file $file
foreach ($lines as $line) {
$myTerms = [];
$res = preg_match_all('/get_lang\(([\'"](\\w*)[\'"])\)/m', $line, $myTerms);
if ($res > 0) {
foreach ($myTerms[2] as $term) {
echo "Found term $term - ".print_r($myTerms, 1).PHP_EOL;
if (substr($term, 0, 4) == 'lang') {
$term = substr($term, 4);
}
if (!empty($terms[$term])) {
$translation = $terms[$term];
$quotedTerm = $myTerms[1][0];
//echo "Would do sed -i \"s#$quotedTerm#'$translation'#g\" $file here\n";
system("sed -i \"s#$term#'$translation'#g\" $file");
$countReplaces++;
}
}
} else {
$res = 0;
$res = preg_match_all('/\{\s*([\'"](\\w*)[\'"])\s*\|get_lang\}/m', $line, $myTerms);
if ($res > 0) {
foreach ($myTerms[2] as $term) {
echo "Found term $term".PHP_EOL;
if (substr($term, 0, 4) == 'lang') {
$term = substr($term, 4);
}
if (!empty($terms[$term])) {
$translation = $terms[$term];
$quotedTerm = $myTerms[1][0];
//echo "Would do sed -i \"s#$quotedTerm#'$translation'#g\" $file here\n";
system("sed -i \"s#$term#'$translation'#g\" $file");
$countReplaces++;
}
}
}
}
}
$countFiles++;
flush();
}
echo "Done analyzing $countFiles files, with $countReplaces replacements!\n";

@ -63,9 +63,8 @@ function my_delete($file)
return true;
}
} else {
return false; // no file or directory to delete
}
return false; // no file or directory to delete
}
/**
@ -258,9 +257,8 @@ function move($source, $target, $forceMove = true, $moveContent = false)
return true;
}
} else {
return false;
}
return false;
}
/**
@ -270,6 +268,7 @@ function move($source, $target, $forceMove = true, $moveContent = false)
*
* @param string $source the path of the directory to move
* @param string $destination the path of the new area
* @param bool $move Whether we want to remove the source at the end
*
* @return bool false on error
*/
@ -344,3 +343,42 @@ function getextension($filename)
return [array_pop($bouts), implode('.', $bouts)];
}
/**
* Get a list of all PHP (.php) files in a given directory. Includes .tpl files
* @param string $base_path The base path in which to find the corresponding files
* @param bool $includeStatic Include static .html, .htm and .css files
* @return array
*/
function getAllPhpFiles($base_path, $includeStatic = false)
{
$list = scandir($base_path);
$files = [];
$extensionsArray = ['.php', '.tpl'];
if ($includeStatic) {
$extensionsArray[] = 'html';
$extensionsArray[] = '.htm';
$extensionsArray[] = '.css';
}
foreach ($list as $item) {
if (substr($item, 0, 1) == '.') {
continue;
}
$special_dirs = [api_get_path(SYS_TEST_PATH), api_get_path(SYS_COURSE_PATH), api_get_path(SYS_LANG_PATH), api_get_path(SYS_ARCHIVE_PATH)];
if (in_array($base_path.$item.'/', $special_dirs)) {
continue;
}
if (is_dir($base_path.$item)) {
$files = array_merge($files, getAllPhpFiles($base_path.$item.'/', $includeStatic));
} else {
//only analyse php files
$sub = substr($item, -4);
if (in_array($sub, $extensionsArray)) {
$files[] = $base_path.$item;
}
}
}
$list = null;
return $files;
}

@ -300,7 +300,7 @@ class Statistics
WHERE track_default.default_user_id = user.user_id ";
}
if (isset($_GET['keyword'])) {
if (!empty($_GET['keyword'])) {
$keyword = Database::escape_string(trim($_GET['keyword']));
$sql .= " AND (user.username LIKE '%".$keyword."%' OR
default_event_type LIKE '%".$keyword."%' OR

@ -8121,4 +8121,7 @@ $HottestSessions = "Most popular sessions";
$LPItemCanBeAccessed = "Item can be viewed - Prerequisites completed";
$ItemXBlocksThisElement = "Item %s blocks this step";
$YourResultAtXBlocksThisElement = "Your result at %s blocks this step";
$RegistrationRoleWhatDoYouWantToDo = "What do you want to do?";
$RegistrationRoleFollowCourses = "Follow courses";
$RegistrationRoleTeachCourses = "Teach courses";
?>

@ -8058,4 +8058,7 @@ $HottestSessions = "Sessions les plus populaires";
$LPItemCanBeAccessed = "Etape accessible";
$ItemXBlocksThisElement = "L'absence de consultation de l'étape \"%s\" ne vous permet pas d'accéder à celle-ci";
$YourResultAtXBlocksThisElement = "Votre score à l'étape \"%s\" ne vous permet d'accéder à celle-ci";
$RegistrationRoleWhatDoYouWantToDo = "Que souhaitez-vous faire?";
$RegistrationRoleFollowCourses = "Suivre des cours";
$RegistrationRoleTeachCourses = "Enseigner";
?>

@ -3019,7 +3019,7 @@ $Archive = "archivo";
$CourseCode = "Código del curso";
$NoDescription = "Sin descripción";
$OfficialCode = "Código oficial";
$FirstName = "Nombre";
$FirstName = "Nombres";
$LastName = "Apellidos";
$Status = "Estado";
$Email = "Correo electrónico";
@ -7000,7 +7000,7 @@ $Configure = "Configurar";
$Regions = "Regiones";
$CourseList = "Lista de cursos";
$NumberAbbreviation = "N°";
$FirstnameAndLastname = "Nombre y apellidos";
$FirstnameAndLastname = "Nombres y apellidos";
$LastnameAndFirstname = "Apellidos y nombre";
$Plugins = "Plugins";
$Detailed = "Detallado";
@ -8145,4 +8145,7 @@ $HottestSessions = "Sesiones más populares";
$LPItemCanBeAccessed = "Item accesible - prerequisitos completados.";
$ItemXBlocksThisElement = "El item \"%s\" bloquea este paso";
$YourResultAtXBlocksThisElement = "El resultado en el item \"%s\" bloquea esta etapa.";
$RegistrationRoleWhatDoYouWantToDo = "¿Qué deseas hacer?";
$RegistrationRoleFollowCourses = "Seguir cursos";
$RegistrationRoleTeachCourses = "Dictar cursos";
?>

@ -8,7 +8,7 @@ use ChamiloSession as Session;
*
* @package chamilo.learnpath
*
* @author Yannick Warnier <ywarnier@beeznest.org>
* @author Yannick Warnier <ywarnier@beeznest.org>
*/
require_once api_get_path(LIBRARY_PATH).'specific_fields_manager.lib.php';
@ -106,7 +106,8 @@ $form->applyFilter('lp_author', 'html_filter');
// LP image
if (strlen($learnPath->get_preview_image()) > 0) {
$show_preview_image = '<img src='.api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/learning_path/images/'.$learnPath->get_preview_image().'>';
$show_preview_image = '<img src='.api_get_path(WEB_COURSE_PATH).api_get_course_path()
.'/upload/learning_path/images/'.$learnPath->get_preview_image().'>';
$form->addElement('label', get_lang('ImagePreview'), $show_preview_image);
$form->addElement('checkbox', 'remove_picture', null, get_lang('DelImage'));
}
@ -241,8 +242,12 @@ if ($enableLpExtraFields) {
</script>';
}
$defaults['publicated_on'] = !empty($publicated_on) && $publicated_on !== '0000-00-00 00:00:00' ? api_get_local_time($publicated_on) : null;
$defaults['expired_on'] = (!empty($expired_on)) ? api_get_local_time($expired_on) : date('Y-m-d 12:00:00', time() + 84600);
$defaults['publicated_on'] = !empty($publicated_on) && $publicated_on !== '0000-00-00 00:00:00'
? api_get_local_time($publicated_on)
: null;
$defaults['expired_on'] = (!empty($expired_on))
? api_get_local_time($expired_on)
: date('Y-m-d 12:00:00', time() + 84600);
$defaults['subscribe_users'] = $learnPath->getSubscribeUsers();
$defaults['skills'] = array_keys($skillList);
$form->setDefaults($defaults);

@ -9,7 +9,7 @@
if (PHP_SAPI!='cli') {
die('Run this script through the command line or comment this line in the code');
}
require_once '../../inc/global.inc.php';
require_once __DIR__.'/../../../main/inc/global.inc.php';
$path = api_get_path(SYS_CODE_PATH).'img/';
ini_set('memory_limit', '128M');
ini_set('max_execution_time', '240');
@ -64,41 +64,6 @@ foreach ($unused as $term => $path) {
}
echo "</table>\n";
/**
* @param $base_path
* @return array
*/
function get_all_php_files($base_path)
{
$list = scandir($base_path);
$files = array();
foreach ($list as $item) {
if (substr($item, 0, 1)=='.') {
continue;
}
$special_dirs = array(
api_get_path(SYS_TEST_PATH),
api_get_path(SYS_COURSE_PATH),
api_get_path(SYS_LANG_PATH),
api_get_path(SYS_ARCHIVE_PATH)
);
if (in_array($base_path.$item.'/', $special_dirs)) {
continue;
}
if (is_dir($base_path.$item)) {
$files = array_merge($files, get_all_php_files($base_path.$item.'/'));
} else {
//only analyse php files
$ext = substr($item, -4);
if (in_array($ext, array('.php', 'html', '.htm', '.css'))) {
$files[] = $base_path.$item;
}
}
}
$list = null;
return $files;
}
/**
* Get the list of available images
* @param string $path The path to start the scan from

@ -7,7 +7,7 @@
* Includes and declarations
*/
if (PHP_SAPI!='cli') { die('Run this script through the command line or comment this line in the code'); }
require_once '../../inc/global.inc.php';
require_once __DIR__.'/../../../main/inc/global.inc.php';
$path = api_get_path(SYS_CODE_PATH).'img/';
ini_set('memory_limit','128M');
ini_set('max_execution_time','240');
@ -19,8 +19,9 @@ $found_img = get_img_files($path);
// now get all terms found in all PHP files of Chamilo (this takes some time and memory)
$unexisting_img = array();
$l = strlen(api_get_path(SYS_PATH));
$files = get_all_php_files(api_get_path(SYS_PATH));
$files = getAllPhpFiles(api_get_path(SYS_PATH), true);
$counter = 0;
$used_icons = [];
foreach ($files as $file) {
$shortfile = substr($file,$l);
$lines = file($file);
@ -77,27 +78,6 @@ echo "</table>\n";
echo "Analysed files:<br />\n";
print_r($files);
function get_all_php_files($base_path) {
$list = scandir($base_path);
$files = array();
foreach ($list as $item) {
if (substr($item,0,1)=='.') {continue;}
$special_dirs = array(api_get_path(SYS_TEST_PATH),api_get_path(SYS_COURSE_PATH),api_get_path(SYS_LANG_PATH),api_get_path(SYS_ARCHIVE_PATH));
if (in_array($base_path.$item.'/',$special_dirs)) {continue;}
if (is_dir($base_path.$item)) {
$files = array_merge($files,get_all_php_files($base_path.$item.'/'));
} else {
//only analyse php files
$ext = substr($item,-4);
if (in_array($ext,array('.php','html','.htm','.css'))) {
$files[] = $base_path.$item;
}
}
}
$list = null;
return $files;
}
function get_img_files($path) {
$files = array();
//We know there are max 3 levels

Loading…
Cancel
Save