parent
e852e9a2b1
commit
f199ca4a58
@ -1,359 +0,0 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
use Chamilo\CoreBundle\Framework\Container; |
||||
|
||||
/** |
||||
* This script displays a form for registering new users. |
||||
*/ |
||||
$cidReset = true; |
||||
require_once __DIR__.'/../inc/global.inc.php'; |
||||
|
||||
api_protect_admin_script(); |
||||
|
||||
// Load terms & conditions from the current lang |
||||
if ('true' === api_get_setting('allow_terms_conditions')) { |
||||
$get = array_keys($_GET); |
||||
if (isset($get)) { |
||||
if (isset($get[0]) && 'legal' == $get[0]) { |
||||
$language = api_get_language_isocode(); |
||||
$language = api_get_language_id($language); |
||||
$term_preview = LegalManager::get_last_condition($language); |
||||
if (!$term_preview) { |
||||
//look for the default language |
||||
$language = api_get_setting('platformLanguage'); |
||||
$language = api_get_language_id($language); |
||||
$term_preview = LegalManager::get_last_condition($language); |
||||
} |
||||
$tool_name = get_lang('Terms and Conditions'); |
||||
Display :: display_header(''); |
||||
echo '<div class="actions-title">'; |
||||
echo $tool_name; |
||||
echo '</div>'; |
||||
if (!empty($term_preview['content'])) { |
||||
echo $term_preview['content']; |
||||
} else { |
||||
echo get_lang('Coming soon...'); |
||||
} |
||||
Display :: display_footer(); |
||||
exit; |
||||
} |
||||
} |
||||
} |
||||
|
||||
$action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null; |
||||
|
||||
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Administration')]; |
||||
$tool_name = get_lang('Setting the registration page'); |
||||
if (!empty($action)) { |
||||
$interbreadcrumb[] = ['url' => 'configure_inscription.php', 'name' => get_lang('Setting the registration page')]; |
||||
switch ($action) { |
||||
case 'edit_top': |
||||
$tool_name = get_lang('Edit Note'); |
||||
|
||||
break; |
||||
} |
||||
} |
||||
|
||||
$lang = ''; //el for "Edit Language" |
||||
if (!empty($_SESSION['user_language_choice'])) { |
||||
$lang = $_SESSION['user_language_choice']; |
||||
} elseif (!empty($_SESSION['_user']['language'])) { |
||||
$lang = $_SESSION['_user']['language']; |
||||
} else { |
||||
$lang = api_get_setting('platformLanguage'); |
||||
} |
||||
|
||||
// ----- Ensuring availability of main files in the corresponding language ----- |
||||
/*if (api_is_multiple_url_enabled()) { |
||||
$access_url_id = api_get_current_access_url_id(); |
||||
if ($access_url_id != -1) { |
||||
$url_info = api_get_access_url($access_url_id); |
||||
$url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url'])); |
||||
|
||||
$clean_url = api_replace_dangerous_char($url); |
||||
$clean_url = str_replace('/', '-', $clean_url); |
||||
$clean_url .= '/'; |
||||
|
||||
$homep = api_get_path(SYS_APP_PATH).'home/'; //homep for Home Path |
||||
$homep_new = api_get_path(SYS_APP_PATH).'home/'.$clean_url; //homep for Home Path added the url |
||||
$new_url_dir = api_get_path(SYS_APP_PATH).'home/'.$clean_url; |
||||
//we create the new dir for the new sites |
||||
if (!is_dir($new_url_dir)) { |
||||
mkdir($new_url_dir, api_get_permissions_for_new_directories()); |
||||
} |
||||
} |
||||
} else { |
||||
$homep_new = ''; |
||||
$homep = api_get_path(SYS_APP_PATH).'home/'; //homep for Home Path |
||||
} |
||||
|
||||
$topf = 'register_top'; //topf for Top File |
||||
$ext = '.html'; //ext for HTML Extension - when used frequently, variables are |
||||
$homef = [$topf]; |
||||
|
||||
// If language-specific file does not exist, create it by copying default file |
||||
foreach ($homef as $my_file) { |
||||
if (api_is_multiple_url_enabled()) { |
||||
if (!file_exists($homep_new.$my_file.'_'.$lang.$ext)) { |
||||
copy($homep.$my_file.$ext, $homep_new.$my_file.'_'.$lang.$ext); |
||||
} |
||||
} else { |
||||
if (!file_exists($homep.$my_file.'_'.$lang.$ext)) { |
||||
copy($homep.$my_file.$ext, $homep.$my_file.'_'.$lang.$ext); |
||||
} |
||||
} |
||||
} |
||||
|
||||
if (!empty($homep_new)) { |
||||
$homep = $homep_new; |
||||
} |
||||
|
||||
if (!empty($action)) { |
||||
if (isset($_POST['formSent'])) { |
||||
switch ($action) { |
||||
case 'edit_top': |
||||
// Filter |
||||
$home_top = trim(stripslashes($_POST['register_top'])); |
||||
// Write |
||||
if (file_exists($homep.$topf.'_'.$lang.$ext)) { |
||||
if (is_writable($homep.$topf.'_'.$lang.$ext)) { |
||||
$fp = fopen($homep.$topf.'_'.$lang.$ext, 'w'); |
||||
fputs($fp, $home_top); |
||||
fclose($fp); |
||||
} else { |
||||
$errorMsg = get_lang('Homepage-files are not writable!'); |
||||
} |
||||
} else { |
||||
//File does not exist |
||||
$fp = fopen($homep.$topf.'_'.$lang.$ext, 'w'); |
||||
fputs($fp, $home_top); |
||||
fclose($fp); |
||||
} |
||||
break; |
||||
} |
||||
if (empty($errorMsg)) { |
||||
header('Location: '.api_get_self()); |
||||
exit(); |
||||
} |
||||
} else { |
||||
switch ($action) { |
||||
case 'edit_top': |
||||
// This request is only the preparation for the update of the home_top |
||||
$home_top = ''; |
||||
if (is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) { |
||||
$home_top = @(string) file_get_contents($homep.$topf.'_'.$lang.$ext); |
||||
} elseif (is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) { |
||||
$home_top = @(string) file_get_contents($homep.$topf.$lang.$ext); |
||||
} else { |
||||
$errorMsg = get_lang('Homepage files are not readable'); |
||||
} |
||||
$home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top))); |
||||
break; |
||||
} |
||||
} |
||||
}*/ |
||||
|
||||
$form = new FormValidator('registration'); |
||||
if ('true' === api_get_setting('allow_terms_conditions')) { |
||||
$display_all_form = !isset($_SESSION['update_term_and_condition']['user_id']); |
||||
} else { |
||||
$display_all_form = true; |
||||
} |
||||
|
||||
if ($display_all_form) { |
||||
if (api_is_western_name_order()) { |
||||
// FIRST NAME and LAST NAME |
||||
$form->addElement('text', 'firstname', get_lang('First name'), ['size' => 40, 'disabled' => 'disabled']); |
||||
$form->addElement('text', 'lastname', get_lang('Last name'), ['size' => 40, 'disabled' => 'disabled']); |
||||
} else { |
||||
// LAST NAME and FIRST NAME |
||||
$form->addElement('text', 'lastname', get_lang('Last name'), ['size' => 40, 'disabled' => 'disabled']); |
||||
$form->addElement('text', 'firstname', get_lang('First name'), ['size' => 40, 'disabled' => 'disabled']); |
||||
} |
||||
$form->applyFilter('firstname', 'trim'); |
||||
$form->applyFilter('lastname', 'trim'); |
||||
$form->addRule('lastname', get_lang('Required field'), 'required'); |
||||
$form->addRule('firstname', get_lang('Required field'), 'required'); |
||||
|
||||
// EMAIL |
||||
$form->addElement('text', 'email', get_lang('e-mail'), ['size' => 40, 'disabled' => 'disabled']); |
||||
if ('true' == api_get_setting('registration', 'email')) { |
||||
$form->addRule('email', get_lang('Required field'), 'required'); |
||||
} |
||||
$form->addEmailRule('email'); |
||||
|
||||
// USERNAME |
||||
$form->addElement('text', 'username', get_lang('Username'), ['size' => \Chamilo\CoreBundle\Entity\User::USERNAME_MAX_LENGTH, 'disabled' => 'disabled']); |
||||
$form->addRule('username', get_lang('Required field'), 'required'); |
||||
$form->addRule('username', get_lang('Your login can only contain letters, numbers and _.-'), 'username'); |
||||
$form->addRule('username', get_lang('This login is already in use'), 'username_available'); |
||||
$form->addRule('username', sprintf(get_lang('The login needs to be maximum %s characters long'), (string) \Chamilo\CoreBundle\Entity\User::USERNAME_MAX_LENGTH), 'maxlength', \Chamilo\CoreBundle\Entity\User::USERNAME_MAX_LENGTH); |
||||
|
||||
// PASSWORD |
||||
$form->addElement('password', 'pass1', get_lang('Pass'), ['size' => 40, 'disabled' => 'disabled']); |
||||
$form->addElement('password', 'pass2', get_lang('Confirm password'), ['size' => 40, 'disabled' => 'disabled']); |
||||
$form->addRule('pass1', get_lang('Required field'), 'required'); |
||||
$form->addRule('pass2', get_lang('Required field'), 'required'); |
||||
$form->addRule(['pass1', 'pass2'], get_lang('You have typed two different passwords'), 'compare'); |
||||
$form->addPasswordRule('pass1'); |
||||
|
||||
// PHONE |
||||
$form->addElement('text', 'phone', get_lang('Phone'), ['size' => 40, 'disabled' => 'disabled']); |
||||
if ('true' == api_get_setting('registration', 'phone')) { |
||||
$form->addRule('phone', get_lang('Required field'), 'required'); |
||||
} |
||||
|
||||
// LANGUAGE |
||||
if ('true' == api_get_setting('registration', 'language')) { |
||||
$form->addSelectLanguage( |
||||
'language', |
||||
get_lang('Language'), |
||||
'', |
||||
['disabled' => 'disabled'] |
||||
); |
||||
} |
||||
|
||||
// STUDENT/TEACHER |
||||
if ('false' != api_get_setting('allow_registration_as_teacher')) { |
||||
$form->addElement('radio', 'status', get_lang('Status'), get_lang('Student (follows courses)'), STUDENT, ['disabled' => 'disabled']); |
||||
$form->addElement('radio', 'status', null, get_lang('Teacher (creates courses)'), COURSEMANAGER, ['disabled' => 'disabled']); |
||||
} |
||||
|
||||
// EXTENDED FIELDS |
||||
if ('true' == api_get_setting('extended_profile') && |
||||
'true' == api_get_setting('extendedprofile_registration', 'mycomptetences') |
||||
) { |
||||
$form->addHtmlEditor('competences', get_lang('My competences'), false, false, ['ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130']); |
||||
} |
||||
|
||||
if ('true' == api_get_setting('extended_profile') && |
||||
'true' == api_get_setting('extendedprofile_registration', 'mydiplomas') |
||||
) { |
||||
$form->addHtmlEditor('diplomas', get_lang('My diplomas'), false, false, ['ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130']); |
||||
} |
||||
|
||||
if ('true' == api_get_setting('extended_profile') && |
||||
'true' == api_get_setting('extendedprofile_registration', 'myteach') |
||||
) { |
||||
$form->addHtmlEditor('teach', get_lang('What I am able to teach'), false, false, ['ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130']); |
||||
} |
||||
|
||||
if ('true' == api_get_setting('extended_profile') && |
||||
'true' == api_get_setting('extendedprofile_registration', 'mypersonalopenarea') |
||||
) { |
||||
$form->addHtmlEditor('openarea', get_lang('My personal open area'), false, false, ['ToolbarSet' => 'Profile', 'Width' => '100%', 'Height' => '130']); |
||||
} |
||||
|
||||
if ('true' == api_get_setting('extended_profile')) { |
||||
if ('true' == api_get_setting('extendedprofile_registrationrequired', 'mycomptetences')) { |
||||
$form->addRule('competences', get_lang('Required field'), 'required'); |
||||
} |
||||
if ('true' == api_get_setting('extendedprofile_registrationrequired', 'mydiplomas')) { |
||||
$form->addRule('diplomas', get_lang('Required field'), 'required'); |
||||
} |
||||
if ('true' == api_get_setting('extendedprofile_registrationrequired', 'myteach')) { |
||||
$form->addRule('teach', get_lang('Required field'), 'required'); |
||||
} |
||||
if ('true' == api_get_setting('extendedprofile_registrationrequired', 'mypersonalopenarea')) { |
||||
$form->addRule('openarea', get_lang('Required field'), 'required'); |
||||
} |
||||
} |
||||
|
||||
$extraField = new ExtraField('user'); |
||||
$extraField->addElements($form); |
||||
} |
||||
|
||||
// Terms and conditions |
||||
if ('true' == api_get_setting('allow_terms_conditions')) { |
||||
$language = api_get_language_isocode(); |
||||
$language = api_get_language_id($language); |
||||
$term_preview = LegalManager::get_last_condition($language); |
||||
|
||||
if (!$term_preview) { |
||||
//we load from the platform |
||||
$language = api_get_setting('platformLanguage'); |
||||
$language = api_get_language_id($language); |
||||
$term_preview = LegalManager::get_last_condition($language); |
||||
//if is false we load from english |
||||
if (!$term_preview) { |
||||
$language = api_get_language_id('english'); //this must work |
||||
$term_preview = LegalManager::get_last_condition($language); |
||||
} |
||||
} |
||||
|
||||
// Version and language //password |
||||
$form->addElement('hidden', 'legal_accept_type', $term_preview['version'].':'.$term_preview['language_id']); |
||||
$form->addElement('hidden', 'legal_info', $term_preview['id'].':'.$term_preview['language_id']); |
||||
|
||||
if (1 == $term_preview['type']) { |
||||
$form->addElement( |
||||
'checkbox', |
||||
'legal_accept', |
||||
null, |
||||
get_lang('I have read and agree to the').' <a href="inscription.php?legal" target="_blank">'.get_lang('Terms and Conditions').'</a>' |
||||
); |
||||
$form->addRule('legal_accept', get_lang('Required field'), 'required'); |
||||
} else { |
||||
if (!empty($term_preview['content'])) { |
||||
$preview = LegalManager::show_last_condition($term_preview); |
||||
$form->addElement('label', get_lang('Terms and Conditions'), $preview); |
||||
} |
||||
} |
||||
} |
||||
|
||||
$form->addButtonSave(get_lang('Register')); |
||||
|
||||
$defaults['status'] = STUDENT; |
||||
|
||||
if (isset($_SESSION['user_language_choice']) && '' != $_SESSION['user_language_choice']) { |
||||
$defaults['language'] = $_SESSION['user_language_choice']; |
||||
} else { |
||||
$defaults['language'] = api_get_setting('platformLanguage'); |
||||
} |
||||
|
||||
if (!empty($_GET['username'])) { |
||||
$defaults['username'] = Security::remove_XSS($_GET['username']); |
||||
} |
||||
|
||||
if (!empty($_GET['email'])) { |
||||
$defaults['email'] = Security::remove_XSS($_GET['email']); |
||||
} |
||||
|
||||
if (!empty($_GET['phone'])) { |
||||
$defaults['phone'] = Security::remove_XSS($_GET['phone']); |
||||
} |
||||
|
||||
$form->setDefaults($defaults); |
||||
|
||||
$tpl = new Template(); |
||||
|
||||
$content = Display::page_header($tool_name); |
||||
|
||||
// The following security condition has been removed, because it makes no sense here. See Bug #1846. |
||||
//// Forbidden to self-register |
||||
//if (api_get_setting('allow_registration') == 'false') { |
||||
// api_not_allowed(); |
||||
//} |
||||
|
||||
//Display::page_subheader2($tool_name); |
||||
if ('approval' == api_get_setting('allow_registration')) { |
||||
$content .= Display::return_message(get_lang('Your account has to be approved'), 'normal'); |
||||
} |
||||
|
||||
$url = api_get_path(WEB_PUBLIC_PATH).'internal_page/edit/inscription'; |
||||
//Form of language |
||||
//$content .= api_display_language_form(); |
||||
$content .= ' <a href="'.api_get_self().'?action=edit_top">'. |
||||
Display::return_icon('edit.gif', get_lang('Edit')).'</a> |
||||
<a href="'.$url.'">'.get_lang('Edit notice').'</a>'; |
||||
|
||||
$content .= $form->returnForm(); |
||||
|
||||
//$page = Container::getPage('inscription'); |
||||
//$tpl->assign('page', $page); |
||||
$tpl->assign('form', $content); |
||||
|
||||
$templateName = $tpl->get_template('auth/inscription_edit.html.twig'); |
||||
$tpl->display($templateName); |
||||
@ -1,41 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* Script to check that no language file has parse errors. |
||||
*/ |
||||
/** |
||||
* Includes and declarations. |
||||
*/ |
||||
//die(); |
||||
require_once '../../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); |
||||
$langs = scandir(api_get_path(SYS_LANG_PATH)); |
||||
foreach ($langs as $lang) { |
||||
$dir = api_get_path(SYS_LANG_PATH).$lang; |
||||
if (is_dir($dir) && '.' != substr($lang, 0, 1) && !empty($lang)) { |
||||
echo "$lang..."; |
||||
$ok = true; |
||||
foreach ($list as $entry) { |
||||
$file = $dir.'/'.$entry; |
||||
$out = []; |
||||
if (is_file($file)) { |
||||
//$terms = array_merge($terms,SubLanguageManager::get_all_language_variable_in_file($file,true)); |
||||
@exec('php -l '.$file, $out); |
||||
if ('No' != substr($out[0], 0, 2)) { |
||||
echo $out[0]."\n"; |
||||
$ok = false; |
||||
} |
||||
} |
||||
} |
||||
if ($ok) { |
||||
echo "OK\n"; |
||||
} |
||||
} |
||||
} |
||||
echo "Done\n"; |
||||
@ -1,215 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* This class takes the creation and querying of an SQLite DB in charge. The |
||||
* goal of this DB is to get stats on the usage of language vars for a common |
||||
* user. |
||||
*/ |
||||
|
||||
/** |
||||
* This class takes the creation and querying of an SQLite DB in charge. The |
||||
* goal of this DB is to get stats on the usage of language vars for a common |
||||
* user. This class requires the SQLite extension of PHP to be installed. The |
||||
* check for the availability of sqlite_open() should be made before calling |
||||
* the constructor (preferably). |
||||
*/ |
||||
class langstats |
||||
{ |
||||
public $db; //database connector |
||||
public $error; //stored errors |
||||
public $db_type = 'sqlite'; |
||||
|
||||
public function __construct($file = '') |
||||
{ |
||||
switch ($this->db_type) { |
||||
case 'sqlite': |
||||
if (!class_exists('SQLite3')) { |
||||
$this->error = 'SQLiteNotAvailable'; |
||||
|
||||
return false; //cannot use if sqlite not installed |
||||
} |
||||
if (empty($file)) { |
||||
$file = api_get_path(SYS_ARCHIVE_PATH).'/langstasdb'; |
||||
} |
||||
if (is_file($file) && is_writeable($file)) { |
||||
$this->db = new SQLite3($file, SQLITE3_OPEN_READWRITE); |
||||
} else { |
||||
try { |
||||
$this->db = new SQLite3($file); |
||||
} catch (Exception $e) { |
||||
$this->error = 'DatabaseCreateError'; |
||||
error_log('Exception: '.$e->getMessage()); |
||||
|
||||
return false; |
||||
} |
||||
$err = $this->db->exec( |
||||
'CREATE TABLE lang_freq (' |
||||
.' id integer PRIMARY KEY AUTOINCREMENT, ' //autoincrement in SQLITE |
||||
.' term_name text, term_file text, term_count integer default 0)' |
||||
); |
||||
if (false === $err) { |
||||
$this->error = 'CouldNotCreateTable'; |
||||
|
||||
return false; |
||||
} |
||||
$err = $this->db->exec( |
||||
'CREATE INDEX lang_freq_terms_idx ON lang_freq(term_name, term_file)' |
||||
); |
||||
if (false === $err) { |
||||
$this->error = 'CouldNotCreateIndex'; |
||||
|
||||
return false; |
||||
} |
||||
// Table and index created, move on. |
||||
} |
||||
break; |
||||
case 'mysql': //implementation not finished |
||||
if (!function_exists('mysql_connect')) { |
||||
$this->error = 'SQLiteNotAvailable'; |
||||
|
||||
return false; //cannot use if sqlite not installed |
||||
} |
||||
$err = Database::query('SELECT * FROM lang_freq'); |
||||
if (false === $err) { //the database probably does not exist, create it |
||||
$err = Database::query( |
||||
'CREATE TABLE lang_freq (' |
||||
.' id int PRIMARY KEY AUTO_INCREMENT, ' |
||||
.' term_name text, term_file text default \'\', term_count int default 0)' |
||||
); |
||||
if (false === $err) { |
||||
$this->error = 'CouldNotCreateTable'; |
||||
|
||||
return false; |
||||
} |
||||
} // if no error, we assume the table exists |
||||
break; |
||||
} |
||||
|
||||
return $this->db; |
||||
} |
||||
|
||||
/** |
||||
* Add a count for a specific term. |
||||
* |
||||
* @param string The language term used |
||||
* @param string The file from which the language term came from |
||||
* |
||||
* @return mixed |
||||
*/ |
||||
public function add_use($term, $term_file = '') |
||||
{ |
||||
$term = $this->db->escapeString($term); |
||||
$term_file = $this->db->escapeString($term_file); |
||||
$sql = "SELECT id, term_name, term_file, term_count FROM lang_freq WHERE term_name='$term' and term_file='$term_file'"; |
||||
$ress = $this->db->query($sql); |
||||
if (false === $ress) { |
||||
$this->error = 'CouldNotQueryTermFromTable'; |
||||
|
||||
return false; |
||||
} |
||||
$i = 0; |
||||
while ($row = $ress->fetchArray(SQLITE3_BOTH)) { |
||||
$num = $row[3]; |
||||
$num++; |
||||
$i++; |
||||
$res = $this->db->query( |
||||
'UPDATE lang_freq SET term_count = '.$num.' WHERE id = '.$row[0] |
||||
); |
||||
if (false === $res) { |
||||
$this->error = 'CouldNotUpdateTerm'; |
||||
|
||||
return false; |
||||
} else { |
||||
return $row[0]; |
||||
} |
||||
} |
||||
if (0 == $i) { |
||||
//No term found in the table, register as new term |
||||
$resi = $this->db->query( |
||||
"INSERT INTO lang_freq(term_name, term_file, term_count) VALUES ('$term', '$term_file', 1)" |
||||
); |
||||
if (false === $resi) { |
||||
$this->error = 'CouldNotInsertRow'; |
||||
|
||||
return false; |
||||
} else { |
||||
return $this->db->lastInsertRowID(); |
||||
} |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
/** |
||||
* Function to get a list of the X most-requested terms. |
||||
* |
||||
* @param int Limit of terms to show |
||||
* |
||||
* @return array List of most requested terms |
||||
*/ |
||||
public function get_popular_terms($num = 1000) |
||||
{ |
||||
$num = (int) $num; |
||||
$res = $this->db->query( |
||||
'SELECT * FROM lang_freq |
||||
ORDER BY term_count DESC LIMIT '.$num |
||||
); |
||||
$list = []; |
||||
while ($row = $res->fetchArray()) { |
||||
$list[] = $row; |
||||
} |
||||
|
||||
return $list; |
||||
} |
||||
|
||||
/** |
||||
* Clear all records in lang_freq. |
||||
* |
||||
* @return resource true |
||||
*/ |
||||
public function clear_all() |
||||
{ |
||||
$res = sqlite_query($this->db, 'DELETE FROM lang_freq WHERE 1=1'); |
||||
|
||||
return $res; |
||||
} |
||||
|
||||
/** |
||||
* Returns an array of all the language variables with their corresponding |
||||
* file of origin. This function tolerates a certain rate of error due to |
||||
* the duplication of variables in language files. |
||||
* |
||||
* @return array variable => origin file |
||||
*/ |
||||
public function get_variables_origin() |
||||
{ |
||||
$path = api_get_path(SYS_LANG_PATH).'english/'; |
||||
$vars = []; |
||||
$priority = ['trad4all']; |
||||
foreach ($priority as $file) { |
||||
$list = SubLanguageManager::get_all_language_variable_in_file( |
||||
$path.$file.'.inc.php', |
||||
true |
||||
); |
||||
foreach ($list as $var => $trad) { |
||||
$vars[$var] = $file.'.inc.php'; |
||||
} |
||||
} |
||||
$files = scandir($path); |
||||
foreach ($files as $file) { |
||||
if ('.' == substr($file, 0, 1) or in_array($file, $priority)) { |
||||
continue; |
||||
} |
||||
$list = SubLanguageManager::get_all_language_variable_in_file( |
||||
$path.$file, |
||||
true |
||||
); |
||||
foreach ($list as $var => $trad) { |
||||
$vars[$var] = $file; |
||||
} |
||||
} |
||||
|
||||
return $vars; |
||||
} |
||||
} |
||||
@ -1,84 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* This script prints a list of most used language terms. The registration of |
||||
* frequency for language variables is a very heavy operation. |
||||
* To enable, add "$_configuration['language_measure_frequency' ] = 1;" at the |
||||
* end of main/inc/conf/configuration.php. Remove when done. |
||||
* Add ?output=1 to the URL to generate languag files in /tmp/lang/ with just |
||||
* the number of terms you want. |
||||
*/ |
||||
/** |
||||
* Requires. |
||||
*/ |
||||
exit(); |
||||
require_once '../../inc/global.inc.php'; |
||||
require_once 'langstats.class.php'; |
||||
/** |
||||
* Init. |
||||
*/ |
||||
$terms_limit = 10000 + 50; |
||||
$x_most_popular = 2000; |
||||
$output = false; |
||||
$ls = new langstats(); |
||||
if (false === $ls) { |
||||
exit($ls->error); |
||||
} |
||||
$list = $ls->get_popular_terms($x_most_popular); |
||||
if (1 == $_GET['output']) { |
||||
$output = true; |
||||
$variables_origin = $ls->get_variables_origin(); |
||||
} |
||||
/** |
||||
* Display. |
||||
*/ |
||||
if (0 == count($list)) { |
||||
echo 'No terms loaded so far'; |
||||
} |
||||
if (count($list) > 0) { |
||||
$i = 1; |
||||
$j = 1; |
||||
$k = 0; |
||||
$files = []; |
||||
$trans = []; |
||||
echo 'Number of records: '.count($list).'<br />'; |
||||
echo '<table><tr><th>Index</th><th>Registration order</th><th>Term</th>'.(1 == $output ? '<th>Origin</th>' : '').'<th>Count</th></tr>'; |
||||
foreach ($list as $elem) { |
||||
if ($k > $terms_limit) { |
||||
break; |
||||
} |
||||
$fixed_elem = $elem; |
||||
if ($output) { |
||||
if (empty($variables_origin[$elem['term_name']]) && !empty($variables_origin['lang'.$elem['term_name']])) { |
||||
$fixed_elem = ['id' => $elem['id'], 'term_name' => 'lang'.$elem['term_name'], 'term_count' => $elem['term_count']]; |
||||
} |
||||
if (empty($variables_origin[$fixed_elem['term_name']])) { |
||||
continue; |
||||
} |
||||
$files[$variables_origin[$fixed_elem['term_name']]][] = $fixed_elem['term_name']; |
||||
$translation = get_lang($fixed_elem['term_name']); |
||||
$k += str_word_count($translation); |
||||
$trans[$fixed_elem['term_name']] = $translation; |
||||
$j++; |
||||
} |
||||
echo '<tr><td>', $i, |
||||
'</td><td>', $fixed_elem['id'], |
||||
'</td><td>', $fixed_elem['term_name']; |
||||
if ($output) { |
||||
echo '</td><td>'.$variables_origin[$fixed_elem['term_name']]; |
||||
} |
||||
echo '</td><td>', $fixed_elem['term_count'], '</td></tr>'; |
||||
$i++; |
||||
} |
||||
echo '</table>'; |
||||
if ($output) { |
||||
@mkdir('/tmp/lang'); |
||||
foreach ($files as $file => $terms) { |
||||
@touch('/tmp/lang/'.$file); |
||||
file_put_contents('/tmp/lang/'.$file, "<?php".PHP_EOL);
|
||||
foreach ($terms as $term) { |
||||
file_put_contents('/tmp/lang/'.$file, '$'.$term.' = "'.str_replace('"', '\"', $trans[$term]).'";'.PHP_EOL, FILE_APPEND); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -1,104 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
/** |
||||
* This script generates a directory based on the English language variables |
||||
* but only composed of the 10,000 (can be configured) most frequent words |
||||
* used in Chamilo. This implies first using the langstats.php script, which |
||||
* in turn implies configuring an additional variable in configuration.php |
||||
* (see langstats.php for more info). |
||||
* When running the language_builder, please make sure this parameter is |
||||
* set to 0 in the configuration.php file, otherwise it will take *ages*. |
||||
*/ |
||||
require_once '../../inc/global.inc.php'; |
||||
require_once 'langstats.class.php'; |
||||
global $_configuration; |
||||
$_configuration['language_measure_frequency'] = 0; |
||||
$langstats = new langstats(); |
||||
$orig_lang = 'english'; |
||||
/** |
||||
* Init. |
||||
*/ |
||||
$words_limit = 10000; //change this if you want more words |
||||
$terms_limit = 3000; //change this if you think you'll need more terms |
||||
$terms = $langstats->get_popular_terms($terms_limit); |
||||
$words_counter = 0; |
||||
$i = 0; |
||||
$terms_in_limit = []; |
||||
$lang_dir = api_get_path(SYS_LANG_PATH); |
||||
$arch_dir = api_get_path(SYS_ARCHIVE_PATH); |
||||
/** |
||||
* Code run. |
||||
*/ |
||||
foreach ($terms as $row) { |
||||
if ($words_counter > 10000) { |
||||
break; |
||||
} |
||||
$words = str_word_count(get_lang($row['term_name'], null, $orig_lang)); |
||||
$words_counter += $words; |
||||
$terms_in_limit[$row['term_name']] = $i; |
||||
//echo "Term <b>".$row['term_name']."</b> is <b>'".get_lang($row['term_name'],null,$orig_lang)."'</b> which means $words words<br /><br />\n"; |
||||
//if ($words_counter%1000 >= 0) { |
||||
//echo "Reached $words_counter words at term $i (".$row['term_name']." used ".$row['term_count']." times)...<br />\n"; |
||||
//} |
||||
$i++; |
||||
} |
||||
//echo $words_counter.'<br />'; |
||||
|
||||
echo "Reached ".count($terms_in_limit)." terms for the $words_counter most-used words<br /><br />\n"; |
||||
|
||||
echo "Scanning English files, trying to find these terms...<br />\n"; |
||||
if (!is_dir($arch_dir.'/langstats')) { |
||||
mkdir($arch_dir.'/langstats'); |
||||
mkdir($arch_dir.'/langstats/'.$orig_lang); |
||||
} |
||||
$list_files = scandir($lang_dir.'/'.$orig_lang); |
||||
$j = 1; |
||||
$terms_found = []; |
||||
$words_found = 0; |
||||
$global_var = []; //keep the combination of all vars |
||||
$terms_in_limit = array_flip($terms_in_limit); |
||||
foreach ($list_files as $file) { |
||||
if ('.' == substr($file, 0, 1)) { |
||||
continue; |
||||
} |
||||
//echo "'".substr($file,0,-8)."',<br />"; //print in a PHP array format |
||||
$vars = file($lang_dir.'/'.$orig_lang.'/'.$file); |
||||
$local_var = []; |
||||
$file_string = '<?php'."\n"; |
||||
foreach ($vars as $line) { |
||||
$var = []; |
||||
$res = preg_match('/^(\$\w*)/', $line, $var); |
||||
if ($res > 0) { |
||||
//echo $var[1]."<br />"; |
||||
|
||||
if (in_array(substr($var[1], 1), $terms_in_limit)) { |
||||
//echo "Var ".$var[1]." was in the limit<br />"; |
||||
$local_var[$var[1]] = $line; |
||||
$file_string .= $line; |
||||
$terms_found[] = substr($var[1], 1); //e.g. store Tools |
||||
$words_found += str_word_count(get_lang($var[1], null, $orig_lang)); |
||||
} elseif (in_array(substr($var[1], 5), $terms_in_limit)) { |
||||
//echo "Var ".$var[1]." was in the limit<br />"; |
||||
$local_var[$var[1]] = $line; |
||||
$file_string .= $line; |
||||
$terms_found[] = substr($var[1], 5); //e.g. store langTools |
||||
$words_found += str_word_count(get_lang(substr($var[1], 5), null, $orig_lang)); |
||||
} //else do not care |
||||
} |
||||
} |
||||
echo "Writing ".$arch_dir.'/langstats/'.$orig_lang.'/'.$file."<br />\n"; |
||||
file_put_contents($arch_dir.'/langstats/'.$orig_lang.'/'.$file, $file_string); |
||||
$global_var += $local_var; |
||||
} |
||||
$terms_diff = count($global_var) - count($terms_in_limit); |
||||
echo count( |
||||
$global_var |
||||
)." terms found in English files (summing up to $words_found words). Some terms ($terms_diff in this case) might have appeared in two different files<br />"; |
||||
/** |
||||
* Display results. |
||||
*/ |
||||
echo "Difference between filtered and found in English:<br />"; |
||||
//print_r($terms_found); |
||||
echo "<pre>".print_r(array_diff($terms_in_limit, $terms_found), 1)."</pre>"; |
||||
echo "#"; |
||||
@ -1,81 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* Cron script to list used, but undefined, language variables. |
||||
*/ |
||||
/** |
||||
* Includes and declarations. |
||||
*/ |
||||
exit(); |
||||
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)); |
||||
} |
||||
} |
||||
// get only the array keys (the language variables defined in language files) |
||||
$defined_terms = array_flip(array_keys($terms)); |
||||
$terms = null; |
||||
$hidePlugins = !empty($_GET['hidePlugins']); |
||||
|
||||
// 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 = getAllPhpFiles(api_get_path(SYS_PATH)); |
||||
foreach ($files as $file) { |
||||
$isPlugin = preg_match('#/plugin/#', $file); |
||||
if ($isPlugin && $hidePlugins) { |
||||
continue; |
||||
} |
||||
//echo 'Analyzing '.$file."<br />"; |
||||
$shortfile = substr($file, $l); |
||||
$lines = file($file); |
||||
foreach ($lines as $line) { |
||||
$myterms = []; |
||||
$res = preg_match_all('/get_lang\(\'(\\w*)\'\)/', $line, $myterms); |
||||
if ($res > 0) { |
||||
foreach ($myterms[1] as $term) { |
||||
if (!isset($defined_terms[$term]) && !isset($defined_terms['lang'.$term])) { |
||||
$undefined_terms[$term] = $shortfile; |
||||
//echo "Undefined: $term<br />"; |
||||
} |
||||
} |
||||
} |
||||
$res = 0; |
||||
$res = preg_match_all('/\{[\'"](\\w*)[\'"]\|get_lang\}/', $line, $myterms); |
||||
if ($res > 0) { |
||||
foreach ($myterms[1] as $term) { |
||||
if (!isset($defined_terms[$term]) && !isset($defined_terms['lang'.$term])) { |
||||
$undefined_terms[$term] = $shortfile; |
||||
//echo "Undefined: $term<br />"; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
flush(); |
||||
} |
||||
//$undefined_terms = array_flip($undefined_terms); |
||||
if (count($undefined_terms) < 1) { |
||||
exit("No missing terms<br />\n"); |
||||
} else { |
||||
echo "The following terms were nowhere to be found: <br />\n<table>"; |
||||
} |
||||
$i = 1; |
||||
foreach ($undefined_terms as $term => $file) { |
||||
$isPlugin = 'plugin/' == substr($file, 0, 7); |
||||
echo "<tr><td>$i</td><td>$term</td><td>in $file"; |
||||
if ($isPlugin) { |
||||
echo " <span style=\"color: #00ff00;\">(this one should be taken care of by the plugin's language files)</span>"; |
||||
} |
||||
echo "</td></tr>\n"; |
||||
$i++; |
||||
} |
||||
echo "</table>\n"; |
||||
@ -1,127 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* Cron script to list unused, but defined, language variables. |
||||
*/ |
||||
/** |
||||
* Includes and declarations. |
||||
*/ |
||||
exit(); |
||||
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)); |
||||
} |
||||
} |
||||
// get only the array keys (the language variables defined in language files) |
||||
$defined_terms = array_flip(array_keys($terms)); |
||||
$terms = null; |
||||
echo count($defined_terms)." terms were found in language files<br />"; |
||||
|
||||
// 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)); |
||||
$files[] = api_get_path(SYS_PATH).'main/install/data.sql'; |
||||
// Browse files |
||||
foreach ($files as $file) { |
||||
//echo 'Analyzing '.$file."<br />"; |
||||
$shortFile = substr($file, $l); |
||||
//echo 'Analyzing '.$shortFile."<br />"; |
||||
$lines = file($file); |
||||
$isDataSQL = false; |
||||
if ('main/install/data.sql' === substr($file, -21)) { |
||||
$isDataSQL = true; |
||||
} |
||||
// Browse lines inside file $file |
||||
foreach ($lines as $line) { |
||||
if ($isDataSQL) { |
||||
// Check main/install/data.sql |
||||
// Should recognize stuff like |
||||
// INSERT INTO settings_current (variable, type, category, selected_value, title, comment) VALUES ('enable_profile_user_address_geolocalization', 'radio', 'User', 'false', 'EnableProfileUsersAddressGeolocalizationTitle', 'EnableProfileUsersAddressGeolocalizationComment'); |
||||
// INSERT INTO settings_options (variable, value, display_text) VALUES ('enable_profile_user_address_geolocalization', 'true', 'Yes'); |
||||
// ('show_teacher_data',NULL,'radio','Platform','true','ShowTeacherDataTitle','ShowTeacherDataComment',NULL,NULL, 1), |
||||
$res = 0; |
||||
$myTerms = []; |
||||
$res = preg_match_all('/\'(\w*)\',/', $line, $myTerms); |
||||
if ($res > 0) { |
||||
foreach ($myTerms[1] as $term) { |
||||
if ('lang' == substr($term, 0, 4)) { |
||||
$term = substr($term, 4); |
||||
} |
||||
$usedTerms[$term] = $shortFile; |
||||
} |
||||
} |
||||
} else { |
||||
$myTerms = []; |
||||
$res = preg_match_all('/get_lang\(\'(\\w*)\'\)/', $line, $myTerms); |
||||
if ($res > 0) { |
||||
foreach ($myTerms[1] as $term) { |
||||
if ('lang' == substr($term, 0, 4)) { |
||||
$term = substr($term, 4); |
||||
} |
||||
$usedTerms[$term] = $shortFile; |
||||
} |
||||
} else { |
||||
$res = 0; |
||||
$myTerms = []; |
||||
// Should catch: |
||||
// {{ 'CopyTextToClipboard' | get_lang }} |
||||
// {{ "HelloX" | get_lang | format(show_user_info.user_info.complete_name) }} |
||||
// {{ "StudentCourseProgressX" | get_lang | format(item.student_info.progress) }} |
||||
$res = preg_match_all('/\{\s*[\'"](\w*)[\'"]\s*\|\s*get_lang\s*(\|\s*\w*(\s*\([\w_\.,\s]*\))?\s*)?\}/', $line, $myTerms); |
||||
if ($res > 0) { |
||||
foreach ($myTerms[1] as $term) { |
||||
if ('lang' == substr($term, 0, 4)) { |
||||
$term = substr($term, 4); |
||||
} |
||||
$usedTerms[$term] = $shortFile; |
||||
} |
||||
} |
||||
// {{ display.panel('PersonalDataResponsibleOrganizationTitle' | get_lang , personal_data.responsible ) }} |
||||
// {{ display.panel('PersonalDataIntroductionTitle' | get_lang , 'PersonalDataIntroductionText' | get_lang) }} |
||||
$myTerms = []; |
||||
$res = preg_match_all('/\{\s*[\w\.]*\([\'"](\w*)[\'"]\s*\|\s*get_lang\s*(,\s*[\w_\.,\s\|\'"]*\s*)?\)\s*\}/', $line, $myTerms); |
||||
if ($res > 0) { |
||||
foreach ($myTerms[1] as $term) { |
||||
if ('lang' == substr($term, 0, 4)) { |
||||
$term = substr($term, 4); |
||||
} |
||||
$usedTerms[$term] = $shortFile; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
flush(); |
||||
} |
||||
|
||||
// Compare defined terms VS used terms. Used terms should be smaller than |
||||
// defined terms, and this should prove the concept that there are much |
||||
// more variables than what we really use |
||||
if (count($usedTerms) < 1) { |
||||
exit("No used terms<br />\n"); |
||||
} else { |
||||
echo "The following terms were defined but never used: <br />\n<table>"; |
||||
} |
||||
$i = 1; |
||||
foreach ($defined_terms as $term => $file) { |
||||
// remove "lang" prefix just in case |
||||
if ('lang' == substr($term, 0, 4)) { |
||||
$term = substr($term, 4); |
||||
} |
||||
if (!isset($usedTerms[$term])) { |
||||
echo "<tr><td>$i</td><td>$term</td></tr>\n"; |
||||
$i++; |
||||
} |
||||
} |
||||
echo "</table>\n"; |
||||
@ -1,90 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
* Script to switch all PHP files in Chamilo to a more Gettext-like syntax. |
||||
*/ |
||||
/** |
||||
* Includes and declarations. |
||||
*/ |
||||
exit(); |
||||
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 ('vendor' === substr($file, $rootLength, 6) || 'web' === substr($file, $rootLength, 3)) { |
||||
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 ('lang' == substr($term, 0, 4)) { |
||||
$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 ('lang' == substr($term, 0, 4)) { |
||||
$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"; |
||||
@ -1,8 +0,0 @@ |
||||
<html> |
||||
<head> |
||||
|
||||
<meta http-equiv="refresh" content="0; url=../"> |
||||
</head> |
||||
<body> |
||||
</body> |
||||
</html> |
||||
Loading…
Reference in new issue