Cheetah
lang_file.php
Go to the documentation of this file.
1 <?php
2 
8 define ('CH_SECURITY_EXCEPTIONS', true);
10 for ($i=1; $i<255 ; ++$i) {
11  $aChSecurityExceptions[] = 'POST.string_for_'.$i;
12  $aChSecurityExceptions[] = 'REQUEST.string_for_'.$i;
13 }
14 
15 require_once( '../inc/header.inc.php' );
16 require_once( CH_DIRECTORY_PATH_INC . 'profiles.inc.php' );
17 require_once( CH_DIRECTORY_PATH_INC . 'design.inc.php' );
18 require_once( CH_DIRECTORY_PATH_INC . 'admin_design.inc.php' );
19 require_once( CH_DIRECTORY_PATH_INC . 'utils.inc.php' );
20 ch_import('ChTemplSearchResult');
21 
22 $logged['admin'] = member_auth( 1, true, true );
23 
24 ch_import('ChWsbAdminSettings');
26 
27 //--- Process submit ---//
28 $aResults = array();
29 
30 //--- Change settings ---//
31 if (isset($_POST['save']) && isset($_POST['cat'])) {
32  $aResults['settings'] = $oSettingsLanguage->saveChanges($_POST);
33 }
34 
35 if (isset($_POST['create_key_batch'])) {
36  $iLangId = (int) $_POST['lang'];
37  $iCategoryId = (int) $_POST['category'];
38  $sKeyList = trim($_POST['keylist']);
39  $iUpdateDup = (int) $_POST['updatedup'];
40 
41  if ($sKeyList) {
42  $sTmpFile = CH_DIRECTORY_PATH_TMP . md5(microtime()) . '.txt';
43  file_put_contents($sTmpFile, $sKeyList);
44  $bMode1 = $bMode2 = $bMode3 = true;
45  $bProcess = false;
46  $sSep = '';
47  // Pass one. See what format the file is in.
48  $file = fopen($sTmpFile, "r");
49  while (!feof($file)) {
50  $line = fgets($file);
51  $line = trim($line);
52  if ($line) {
53  $line = rtrim($line, ',');
54  if (strpos($line, ',') === false)
55  $bMode1 = false;
56  if (strpos($line, '=>') === false)
57  $bMode2 = false;
58  if (strpos($line, '=') === false)
59  $bMode3 = false;
60  }
61  }
62  fclose($file);
63  if ($bMode2)
64  $bMode3 = false;
65  if ($bMode1 && !$bMode2 && !$bMode3) {
66  $sSep = ',';
67  $bProcess = true;
68  }
69  if ($bMode2 && !$bMode1 && !$bMode3) {
70  $sSep = '=>';
71  $bProcess = true;
72  }
73  if ($bMode3 && !$bMode1 && !$bMode2) {
74  $sSep = '=';
75  $bProcess = true;
76  }
77  if (!$bMode1 && !$bMode2 && !$bMode3) {
78  // Unknown list format
79  $sSep = '';
80  $bProcess = false;
81  }
82 
83  if ($bProcess) {
84  // Pass two. Process the keys.
85  // Set the case in which to return column_names.
86  $iKeyAddedCount = 0;
87  $iKeyCount = 0;
88  $iDupCount = 0;
89  $file = fopen($sTmpFile, "r");
90  while (!feof($file)) {
91  $line = fgets($file);
92  $line = trim($line);
93  if ($line) {
94  $iKeyCount++;
95  $line = rtrim($line, ','); // Remove trailing comma if exists.
96  $aLine = explode($sSep, $line, 2);
97  $sLangKey = trim($aLine[0], " \t\n\r\0\x0B\x27\x22"); // Trim the language key of unwanted characters.
98  $sLangString = trim($aLine[1], " \t\n\r\0\x0B\x27\x22"); // Trim the language string of unwanted characters.
99  $GLOBALS['MySQL']->query("INSERT IGNORE INTO `sys_localization_keys`(`IDCategory`, `Key`) VALUES('$iCategoryId', '$sLangKey')");
100  $iKeyId = (int) $GLOBALS['MySQL']->lastId();
101  // If the ID of the last inserted row is 0, then a duplicate key error most likely occured.
102  // So if $iKeyId is not > 0, do not try to insert the string.
103  if ($iKeyId) {
104  $iKeyAddedCount++;
105  $sLangString = process_db_input($sLangString);
106  $GLOBALS['MySQL']->query("INSERT IGNORE INTO `sys_localization_strings`(`IDKey`, `IDLanguage`, `String`) VALUES('$iKeyId', '$iLangId', '$sLangString')");
107  } else {
108  if($iUpdateDup) {
109  // Update the key if the option to update duplicates is on.
110  $iKeyId = (int)$GLOBALS['MySQL']->getOne("SELECT `ID` FROM `sys_localization_keys` WHERE `IDCategory` = '$iCategoryId' AND `Key` = '$sLangKey'");
111  if($iKeyId) {
112  $GLOBALS['MySQL']->query("UPDATE `sys_localization_strings` SET `String` = '$sLangString' WHERE `IDKey` = '$iKeyId' AND `IDLanguage` = '$iLangId'");
113  }
114  }
115  $iDupCount++;
116  }
117  }
118  }
119  fclose($file);
120  unlink($sTmpFile);
121  compileLanguage($iLangId);
122  if ($iDupCount) {
123  if($iUpdateDup) {
124  $aResults['keys-add-batch'] = 'Out of ' . $iKeyCount . ' keys, ' . $iKeyAddedCount . ' Keys were added, and ' . $iDupCount . ' duplicate keys were updated.';
125  } else {
126  $aResults['keys-add-batch'] = 'Out of ' . $iKeyCount . ' keys, ' . $iKeyAddedCount . ' Keys were added, and ' . $iDupCount . ' duplicate keys were ignored.';
127  }
128  } else {
129  $aResults['keys-add-batch'] = $iKeyAddedCount . ' keys were added';
130  }
131  } else {
132  $aResults['keys-add-batch'] = 'Unknown list format. Could not process keys.';
133  }
134  } else {
135  $aResults['keys-add-batch'] = 'Keys To Add was empty. No keys were added.';
136  }
137 }
138 
139 //--- Create/Edit/Delete/Recompile/Export/Import Languages ---//
140 if(isset($_POST['create_language'])) {
141  $aResults[(isset($_POST['id']) && (int)$_POST['id'] != 0 ? 'langs' : 'langs-add')] = createLanguage($_POST);
142 } else if(isset($_POST['import_language'])) {
143  $aResults['langs-import'] = importLanguage($_POST, $_FILES);
144 } else if(isset($_POST['adm-lang-compile']) && !empty($_POST['langs'])) {
145  foreach($_POST['langs'] as $iLangId)
146  if(!compileLanguage((int)$iLangId)) {
147  $aResults['langs'] = '_adm_txt_langs_cannot_compile';
148  break;
149  }
150  if(empty($aResults['langs']))
151  $aResults['langs'] = '_adm_txt_langs_success_compile';
152 } else if(isset($_POST['adm-lang-delete']) && !empty($_POST['langs'])) {
153  $sNameDefault = getParam('lang_default');
154  foreach($_POST['langs'] as $iLangId) {
155  $sName = getLanguageName($iLangId);
156  if($sName == $sNameDefault) {
157  $aResults['langs'] = '_adm_txt_langs_cannot_delete_default';
158  break;
159  }
160 
161  if(!deleteLanguage((int)$iLangId)){
162  $aResults['langs'] = '_adm_txt_langs_cannot_delete';
163  break;
164  }
165  }
166 
167  if(empty($aResults['langs']))
168  $aResults['langs'] = '_adm_txt_langs_success_delete';
169 } else if(isset($_GET['action']) && $_GET['action'] == 'export' && isset($_GET['id'])) {
170  $aLanguage = $GLOBALS['MySQL']->getRow("SELECT `Name`, `Flag`, `Title`, `Direction`, `LanguageCountry` FROM `sys_localization_languages` WHERE `ID`= ? LIMIT 1", [$_GET['id']]);
171 
172  $aContent = array();
173  $aItems = $GLOBALS['MySQL']->getAll("SELECT `tlk`.`Key` AS `key`, `tls`.`String` AS `string` FROM `sys_localization_keys` AS `tlk`
174  LEFT JOIN `sys_localization_strings` AS `tls` ON `tlk`.`ID`=`tls`.`IDKey` WHERE `tls`.`IDLanguage`= ? ", [$_GET['id']]);
175  foreach($aItems as $aItem)
176  $aContent[$aItem['key']] = $aItem['string'];
177 
178  ksort($aContent);
179 
180  $sName = 'lang_' . $aLanguage['Name'] . '.php';
181  $sContent = "<?php\n\$aLangInfo=" . var_export($aLanguage, true) . ";\n\$aLangContent=" . var_export($aContent, true) . ";\n?>";
182 
183  header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
184  header ("Content-type: application/octet-stream");
185  header ("Content-Length: " . strlen($sContent));
186  header ("Content-Disposition: attachment; filename=" . $sName);
187  echo $sContent;
188  exit;
189 } else if(isset($_POST['action']) && $_POST['action'] == 'get_edit_form_language') {
190  echo json_encode(array('code' => PopupBox('adm-langs-wnd-edit', _t('_adm_box_cpt_lang_edit_language'), _getLanguageCreateForm(true))));
191  exit;
192 }
193 
194 //--- Create/Delete/Edit Language Key ---//
195 if(isset($_POST['action']) && $_POST['action'] == 'get_edit_form_key') {
196  echo json_encode(array('code' => PageCodeKeyEdit((int)$_POST['id'])));
197  exit;
198 }
199 if(isset($_POST['create_key'])) {
200  $sName = process_db_input($_POST['name']);
201  $iCategoryId = (int)$_POST['category'];
202 
203  $mixedResult = $GLOBALS['MySQL']->query("INSERT INTO `sys_localization_keys`(`IDCategory`, `Key`) VALUES('" . $iCategoryId . "', '" . $sName . "')", false);
204  if($mixedResult !== false) {
205  $bCompiled = true;
206  $iKeyId = (int)$GLOBALS['MySQL']->lastId();
207  $aLanguages = $GLOBALS['MySQL']->getAll("SELECT `ID` AS `id`, `Title` AS `title` FROM `sys_localization_languages`");
208  foreach($aLanguages as $aLanguage)
209  if(isset($_POST['string_for_' . $aLanguage['id']])) {
210  $GLOBALS['MySQL']->query("INSERT INTO `sys_localization_strings`(`IDKey`, `IDLanguage`, `String`) VALUES('" . $iKeyId . "', '" . $aLanguage['id'] . "', '" . process_db_input($_POST['string_for_' . $aLanguage['id']]) . "')");
211 
212  $bCompiled = $bCompiled && compileLanguage((int)$aLanguage['id']);
213  }
214 
215  $aResult = $bCompiled ? array('code' => 0, 'message' => '_adm_txt_langs_success_key_save') : array('code' => 1, 'message' => '_adm_txt_langs_cannot_compile');
216  } else
217  $aResult = array('code' => 2, 'message' => '_adm_txt_langs_already_exists');
218 
219  $aResult['message'] = MsgBox(_t($aResult['message']));
220 
221  echo "<script>parent.onResult('add', " . json_encode($aResult) . ");</script>";
222  exit;
223 } else if(isset($_POST['edit_key'])) {
224  $iId = (int)$_POST['id'];
225 
226  $bCompiled = true;
227  $aLanguages = $GLOBALS['MySQL']->getAll("SELECT `ID` AS `id`, `Title` AS `title` FROM `sys_localization_languages`");
228  foreach($aLanguages as $aLanguage)
229  if(isset($_POST['string_for_' . $aLanguage['id']])) {
230  $GLOBALS['MySQL']->query("REPLACE INTO `sys_localization_strings`(`IDKey`, `IDLanguage`, `String`) VALUES('" . $iId . "', '" . $aLanguage['id'] . "', '" . process_db_input($_POST['string_for_' . $aLanguage['id']]) . "')");
231 
232  $bCompiled = $bCompiled && compileLanguage((int)$aLanguage['id']);
233  }
234  $aResult = $bCompiled ? array('code' => 0, 'message' => '_adm_txt_langs_success_key_save') : array('code' => 1, 'message' => '_adm_txt_langs_cannot_compile');
235  $aResult['message'] = MsgBox(_t($aResult['message']));
236 
237  echo "<script>parent.onResult('edit', " . json_encode($aResult) . ");</script>";
238  exit;
239 }
240 
241 if(isset($_POST['adm-lang-key-delete']) && is_array($_POST['keys'])) {
242  foreach($_POST['keys'] as $iKeyId)
243  $GLOBALS['MySQL']->query("DELETE FROM `sys_localization_keys`, `sys_localization_strings` USING `sys_localization_keys`, `sys_localization_strings` WHERE `sys_localization_keys`.`ID`=`sys_localization_strings`.`IDKey` AND `sys_localization_keys`.`ID`='" . $iKeyId . "'");
244 }
246 $_page = array(
247  'name_index' => $iNameIndex,
248  'css_name' => array('forms_adv.css', 'lang_file.css'),
249  'js_name' => array('lang_file.js'),
250  'header' => _t('_adm_page_cpt_lang_file'),
251 );
252 
253 $sLangRssFeed = 'on' == getParam('feeds_enable') ? DesignBoxAdmin (_t('_adm_box_cpt_lang_files'), '<div class="RSSAggrCont" rssid="cheetah_market_lang_files" rssnum="5" member="0">' . $GLOBALS['oFunctions']->loadingBoxInline() . '</div>') : '';
254 
256  'page_result_code' => '',
257  'page_code_main' => PageCodeMain($aResults),
258  'page_code_key' => PageCodeKeyCreate() . $sLangRssFeed,
259 );
260 
261 PageCodeAdmin();
262 
264 {
265  $aTopItems = array(
266  'adm-langs-btn-keys' => array('href' => 'javascript:void(0)', 'onclick' => 'javascript:onChangeType(this)', 'title' => _t('_adm_txt_langs_keys'), 'active' => empty($aResults) ? 1 : 0),
267  'adm-langs-btn-keys-add' => array('href' => 'javascript:void(0)', 'onclick' => 'javascript:onCreate()', 'title' => _t('_adm_txt_langs_add_key'), 'active' => 0),
268  'adm-langs-btn-keys-add-batch' => array('href' => 'javascript:void(0)', 'onclick' => 'javascript:onChangeType(this)', 'title' => _t('_adm_txt_langs_add_key_batch'), 'active' => isset($aResults['keys-add-batch']) ? 1 : 0),
269  'adm-langs-btn-langs' => array('href' => 'javascript:void(0)', 'onclick' => 'javascript:onChangeType(this)', 'title' => _t('_adm_txt_langs_languages'), 'active' => isset($aResults['langs']) ? 1 : 0),
270  'adm-langs-btn-langs-add' => array('href' => 'javascript:void(0)', 'onclick' => 'javascript:onChangeType(this)', 'title' => _t('_adm_txt_langs_languages_add'), 'active' => isset($aResults['langs-add']) ? 1 : 0),
271  'adm-langs-btn-langs-import' => array('href' => 'javascript:void(0)', 'onclick' => 'javascript:onChangeType(this)', 'title' => _t('_adm_txt_langs_languages_import'), 'active' => isset($aResults['langs-import']) ? 1 : 0),
272  'adm-langs-btn-settings' => array('href' => 'javascript:void(0)', 'onclick' => 'javascript:onChangeType(this)', 'title' => _t('_adm_txt_langs_settings'), 'active' => isset($aResults['settings']) ? 1 : 0),
273  'adm-langs-btn-help' => array('href' => 'https://www.cheetahwsb.com/m/cheetah_docs/chapter/using-language-keys', 'target' => '_blank', 'title' => _t('_help'))
274  );
275 
276  $sResult = $GLOBALS['oAdmTemplate']->parseHtmlByName('langs.html', array(
277  'content_keys' => _getKeysList(isset($aResults['keys']) ? $aResults['keys'] : true, empty($aResults)),
278  'content_keys_batch' => _getKeysBatch(isset($aResults['keys-add-batch']) ? $aResults['keys-add-batch'] : true),
279  'content_files' => _getLanguagesList(isset($aResults['langs']) ? $aResults['langs'] : true),
280  'content_create' => _getLanguageCreateForm(isset($aResults['langs-add']) ? $aResults['langs-add'] : true),
281  'content_import' => _getLanguageImportForm(isset($aResults['langs-import']) ? $aResults['langs-import'] : true),
282  'content_settings' => _getLanguageSettingsForm(isset($aResults['settings']) ? $aResults['settings'] : true),
283  ));
284 
285  return DesignBoxAdmin(_t('_adm_box_cpt_lang_available'), $sResult, $aTopItems);
286 }
287 
289 {
290  return $GLOBALS['MySQL']->fromCache('sys_localization_languages', 'getAllWithKey',
291  "SELECT `ID` AS `id`, `Name` AS `name`, `Title` AS `title`, `Flag` AS `flag` FROM `sys_localization_languages` ORDER BY `Name`", 'name');
292 }
293 
294 function _checkLangUnique($sLangName)
295 {
296  $aLangs = _getLanguagesArray();
297  return array_key_exists($sLangName, $aLangs);
298 }
299 
300 function _getKeysList($mixedResult, $bActive = false)
301 {
302  $sFilterName = 'filter';
303  $sFilter = '';
304  $aItems = array();
305  if(isset($_GET[$sFilterName])) {
306  $sFilter = process_db_input($_GET[$sFilterName], CH_TAGS_STRIP);
307 
308  $aKeys = $GLOBALS['MySQL']->getAll("SELECT `tk`.`ID` AS `id`, `tk`.`Key` AS `key`, `tc`.`Name` AS `category` FROM `sys_localization_keys` AS `tk`
309  LEFT JOIN `sys_localization_strings` AS `ts` ON `tk`.`ID`=`ts`.`IDKey` LEFT JOIN `sys_localization_categories` AS `tc` ON `tk`.`IDCategory`=`tc`.`ID`
310  WHERE `tk`.`Key` LIKE ? OR `ts`.`String` LIKE ? GROUP BY `tk`.`ID`", ["%{$sFilter}%", "%{$sFilter}%"]);
311  foreach($aKeys as $aKey)
312  $aItems[] = array(
313  'id' => $aKey['id'],
314  'key' => $aKey['key'],
315  'category' => $aKey['category'],
316  'admin_url' => $GLOBALS['site']['url_admin']
317  );
318  }
319 
320  //--- Get Controls ---//
321  $aButtons = array(
322  'adm-lang-key-delete' => _t('_adm_txt_langs_delete')
323  );
324  $sControls = ChTemplSearchResult::showAdminActionsPanel('adm-keys-form', $aButtons, 'keys');
325 
326  $sFilter = ChTemplSearchResult::showAdminFilterPanel(false !== ch_get($sFilterName) ? ch_get($sFilterName) : '', 'adm-langs-look-for', 'adm-langs-apply', $sFilterName);
327 
328  if($mixedResult !== true && !empty($mixedResult))
329  $sFilter .= MsgBox(_t($mixedResult), 3);
330 
331  return $GLOBALS['oAdmTemplate']->parseHtmlByName('langs_keys.html', array(
332  'display' => $bActive ? 'block' : 'none',
333  'filter_panel' => $sFilter,
334  'ch_repeat:items' => !empty($aItems) ? $aItems : MsgBox(_t('_Empty')),
335  'control' => $sControls,
336  'url_admin' => $GLOBALS['site']['url_admin']
337  ));
338 }
339 
340 function _getKeysBatch($mixedResult, $bActive = false)
341 {
342  $sResult = '';
343  if ($mixedResult !== true && !empty($mixedResult)) {
344  $bActive = true;
345  //$sResult = MsgBox(_t($mixedResult), 10);
346  $aOptions = array(
347  'timer' => 10,
348  'showclosebtn' => true,
349  'class' => 'MsgBoxInfo ch-def-font-large',
350  'titleclass' => 'MsgBoxTitleInfo ch-def-font-large'
351  );
352  $sResult = advMsgBox(_t($mixedResult), $aOptions);
353  }
354 
355  $aLanguages = $GLOBALS['MySQL']->getAll("SELECT `ID`, `Title` FROM `sys_localization_languages`");
356  $sLangOptions = '';
357  foreach ($aLanguages as $aLanguage) {
358  $sLangOptions .= '<option value="' . $aLanguage['ID'] . '">' . $aLanguage['Title'] . '</option>' . "\r\n";
359  }
360 
361  $aCategories = $GLOBALS['MySQL']->getAll("SELECT `ID`, `Name` FROM `sys_localization_categories`");
362  $sCatOptions = '';
363  foreach ($aCategories as $aCategory) {
364  $sCatOptions .= '<option value="' . $aCategory['ID'] . '">' . $aCategory['Name'] . '</option>' . "\r\n";
365  }
366 
367  return $GLOBALS['oAdmTemplate']->parseHtmlByName('langs_keys_batch.html', array(
368  'display' => $bActive ? 'block' : 'none',
369  'results' => $sResult,
370  'cat_options' => $sCatOptions,
371  'lang_options' => $sLangOptions
372  ));
373 }
374 
375 function _getLanguagesList($mixedResult, $bActive = false)
376 {
377  $sResult = '';
378  if($mixedResult !== true && !empty($mixedResult)) {
379  $bActive = true;
380  $sResult = MsgBox(_t($mixedResult), 3);
381  }
382 
383  //--- Get Items ---//
384  $aItems = array();
385  $sNameDefault = getParam('lang_default');
386 
387  $aLangs = $GLOBALS['MySQL']->getAll("SELECT `ID` AS `id`, `Name` AS `name`, `Title` AS `title`, `Flag` AS `flag` FROM `sys_localization_languages` ORDER BY `Name`");
388  foreach($aLangs as $aLang)
389  $aItems[] = array(
390  'name' => $aLang['name'],
391  'value' => $aLang['id'],
392  'title' => $aLang['title'],
393  'icon' => $GLOBALS['site']['flags'] . $aLang['flag'] . '.gif',
394  'default' => $aLang['name'] == $sNameDefault ? '(' . _t('_adm_txt_langs_default') . ')' : '',
395  'edit_link' => $GLOBALS['site']['url_admin'] . 'lang_file.php?action=edit&id=' . $aLang['id'],
396  'export_link' => $GLOBALS['site']['url_admin'] . 'lang_file.php?action=export&id=' . $aLang['id']
397  );
398 
399  //--- Get Controls ---//
400  $aButtons = array(
401  'adm-lang-compile' => _t('_adm_txt_langs_compile'),
402  'adm-lang-delete' => _t('_adm_txt_langs_delete')
403  );
404  $sControls = ChTemplSearchResult::showAdminActionsPanel('adm-langs-form', $aButtons, 'langs');
405 
406  return $GLOBALS['oAdmTemplate']->parseHtmlByName('langs_files.html', array(
407  'display' => $bActive ? 'block' : 'none',
408  'results' => $sResult,
409  'ch_repeat:items' => $aItems,
410  'controls' => $sControls
411  ));
412 }
413 function _getLanguageCreateForm($mixedResult, $bActive = false)
414 {
415  if (isset($_POST['action']) && $_POST['action'] == 'get_edit_form_language' && isset($_POST['id'])) {
416  $aLanguage = $GLOBALS['MySQL']->getRow("SELECT `ID` AS `id`, `Name` AS `name`, `Flag` AS `flag`, `Title` AS `title`, `Direction` AS `direction`, `LanguageCountry` AS `lang_country`
417  FROM `sys_localization_languages` WHERE `ID`= ? LIMIT 1", [$_POST['id']]);
418  }
419 
420  //--- Create language form ---//
421  $aFormCreate = array(
422  'form_attrs' => array(
423  'id' => 'adm-settings-form-files',
424  'name' => 'adm-settings-form-files',
425  'action' => $GLOBALS['site']['url_admin'] . 'lang_file.php',
426  'method' => 'post',
427  'enctype' => 'multipart/form-data'
428  ),
429  'inputs' => array(
430  'CopyLanguage_Title' => array(
431  'type' => 'text',
432  'name' => 'CopyLanguage_Title',
433  'caption' => _t('_adm_txt_langs_title'),
434  'value' => isset($aLanguage['title']) ? $aLanguage['title'] : '',
435  ),
436  'CopyLanguage_Name' => array(
437  'type' => 'text',
438  'name' => 'CopyLanguage_Name',
439  'caption' => _t('_adm_txt_langs_code'),
440  'value' => isset($aLanguage['name']) ? $aLanguage['name'] : '',
441  ),
442  'LanguageCountry' => array(
443  'type' => 'text',
444  'name' => 'LanguageCountry',
445  'caption' => _t('_adm_txt_langs_country_code'),
446  'value' => isset($aLanguage['lang_country']) ? $aLanguage['lang_country'] : '',
447  ),
448  'Direction' => array(
449  'type' => 'select',
450  'name' => 'Direction',
451  'caption' => _t('_adm_txt_langs_direction'),
452  'values' => array('LTR' => 'LTR', 'RTL' => 'RTL'),
453  'value' => isset($aLanguage['direction']) ? $aLanguage['direction'] : 'LTR',
454  ),
455  'Flag' => array(
456  'type' => 'select',
457  'name' => 'Flag',
458  'caption' => _t('_adm_txt_langs_flag'),
459  'values' => array(),
460  'value' => isset($aLanguage['flag']) ? $aLanguage['flag'] : strtolower(getParam('default_country')),
461  ),
462  'CopyLanguage_SourceLangID' => array(
463  'type' => 'select',
464  'name' => 'CopyLanguage_SourceLangID',
465  'caption' => _t('_adm_txt_langs_copy_from'),
466  'values' => array()
467  ),
468  'create_language' => array(
469  'type' => 'submit',
470  'name' => 'create_language',
471  'value' => _t("_adm_btn_lang_save"),
472  )
473  )
474  );
475  //--- Copy from ---//
476  $aLangs = getLangsArr(false, true);
477  foreach($aLangs as $iId => $sName)
478  $aFormCreate['inputs']['CopyLanguage_SourceLangID']['values'][] = array('key' => $iId, 'value' => htmlspecialchars_adv( $sName ));
479 
480  //--- Flags ---//
481  $aCountries = $GLOBALS['MySQL']->getAll("SELECT `ISO2` AS `code`, `Country` AS `title` FROM `sys_countries` ORDER BY `Country`");
482  foreach($aCountries AS $aCountry) {
483  $sCode = strtolower($aCountry['code']);
484  $aFormCreate['inputs']['Flag']['values'][] = array('key' => $sCode, 'value' => $aCountry['title']);
485  }
486 
487  $bLanguage = !empty($aLanguage);
488  if($bLanguage) {
489  unset($aFormCreate['inputs']['CopyLanguage_SourceLangID']);
490  $aFormCreate['inputs']['id'] = array(
491  'type' => 'hidden',
492  'name' => 'id',
493  'value' => $aLanguage['id']
494  );
495  }
496  $oForm = new ChTemplFormView($aFormCreate);
497 
498  $sResult = $oForm->getCode();
499  if($mixedResult !== true && !empty($mixedResult)) {
500  $bActive = true;
501  $sResult = MsgBox(_t($mixedResult), 3) . $sResult;
502  }
503 
504  return $GLOBALS['oAdmTemplate']->parseHtmlByName('langs_form_create.html', array(
505  'display' => $bActive || $bLanguage ? 'block' : 'none',
506  'form' => $sResult
507  ));
508 }
509 function _getLanguageImportForm($mixedResult, $bActive = false)
510 {
511  $aFormImport = array(
512  'form_attrs' => array(
513  'id' => 'adm-settings-form-import',
514  'name' => 'adm-settings-form-import',
515  'action' => $GLOBALS['site']['url_admin'] . 'lang_file.php',
516  'method' => 'post',
517  'enctype' => 'multipart/form-data'
518  ),
519  'inputs' => array(
520  'ImportLanguage_File' => array(
521  'type' => 'file',
522  'name' => 'ImportLanguage_File',
523  'caption' => _t('_adm_txt_langs_file'),
524  ),
525  'import_language' => array(
526  'type' => 'submit',
527  'name' => 'import_language',
528  'value' => _t('_adm_btn_lang_import'),
529  )
530  )
531  );
532  $oForm = new ChTemplFormView($aFormImport);
533 
534  $sResult = $oForm->getCode();
535  if($mixedResult !== true && !empty($mixedResult)) {
536  $bActive = true;
537  $sResult = MsgBox(_t($mixedResult), 3) . $sResult;
538  }
539 
540  return $GLOBALS['oAdmTemplate']->parseHtmlByName('langs_form_import.html', array(
541  'display' => $bActive ? 'block' : 'none',
542  'form' => $sResult
543  ));
544 }
545 function _getLanguageSettingsForm($mixedResult, $bActive = false)
546 {
548 
549  $oForm = $oSettingsLanguage->getFormObject();
550 
551  // re-format 'default language' form field
552  foreach ($oForm->aInputs as $k => $r) {
553  if ('lang_default' != $r['name'])
554  continue;
555  $oForm->aInputs[$k] = array(
556  'type' => 'select',
557  'name' => 'lang_default',
558  'caption' => _t('_adm_txt_langs_def_lang'),
559  'values' => array(),
560  'value' => getParam('lang_default'),
561  );
562  $aLangs = getLangsArr();
563  foreach ($aLangs as $sName => $sTitle)
564  $oForm->aInputs[$k]['values'][] = array('key' => $sName, 'value' => htmlspecialchars_adv($sTitle));
565  }
566 
567  // get form code
568  $oForm->initChecker();
569  $sResult = $oForm->getCode();
570 
571  // add operation result
572  if ($mixedResult !== true && !empty($mixedResult)) {
573  $bActive = true;
574  $sResult = $mixedResult . $sResult;
575  }
576 
577  // display
578  return $GLOBALS['oAdmTemplate']->parseHtmlByName('langs_form_settings.html', array(
579  'display' => $bActive ? 'block' : 'none',
580  'form' => $sResult
581  ));
582 }
583 
585 {
586  $aForm = array(
587  'form_attrs' => array(
588  'id' => 'adm-langs-add-key-form',
589  'name' => 'adm-langs-add-key-form',
590  'action' => $GLOBALS['site']['url_admin'] . 'lang_file.php',
591  'method' => 'post',
592  'enctype' => 'multipart/form-data',
593  'target' => 'adm-langs-add-key-iframe'
594  ),
595  'params' => array(),
596  'inputs' => array(
597  'name' => array(
598  'type' => 'text',
599  'name' => 'name',
600  'caption' => _t('_adm_txt_keys_name'),
601  'value' => '',
602  ),
603  'category' => array(
604  'type' => 'select',
605  'name' => 'category',
606  'caption' => _t('_adm_txt_keys_category'),
607  'value' => '',
608  'values' => array()
609  ),
610  )
611  );
612 
613  $aCategories = $GLOBALS['MySQL']->getAll("SELECT `ID` AS `id`, `Name` AS `title` FROM `sys_localization_categories`");
614  foreach($aCategories as $aCategory)
615  $aForm['inputs']['category']['values'][] = array('key' => $aCategory['id'], 'value' => $aCategory['title']);
616 
617  $aLanguages = $GLOBALS['MySQL']->getAll("SELECT `ID` AS `id`, `Title` AS `title` FROM `sys_localization_languages`");
618  foreach($aLanguages as $aLanguage)
619  $aForm['inputs']['string_for_' . $aLanguage['id']] = array(
620  'type' => 'textarea',
621  'name' => 'string_for_' . $aLanguage['id'],
622  'caption' => _t('_adm_txt_keys_string_for', $aLanguage['title']),
623  'value' => '',
624  );
625 
626  $aForm['inputs']['create_key'] = array(
627  'type' => 'submit',
628  'name' => 'create_key',
629  'value' => _t("_adm_btn_lang_save"),
630  );
631 
633  $sContent = $GLOBALS['oAdmTemplate']->parseHtmlByName('langs_key.html', array('type' => 'add', 'content' => $oForm->getCode()));
634  return $GLOBALS['oFunctions']->popupBox('adm-langs-add-key', _t('_adm_box_cpt_lang_key'), $sContent);
635 }
637 {
638  $aForm = array(
639  'form_attrs' => array(
640  'id' => 'adm-langs-edit-key-form',
641  'name' => 'adm-langs-edit-key-form',
642  'action' => $GLOBALS['site']['url_admin'] . 'lang_file.php',
643  'method' => 'post',
644  'enctype' => 'multipart/form-data',
645  'target' => 'adm-langs-edit-key-iframe'
646  ),
647  'params' => array(),
648  'inputs' => array(
649  'id' => array(
650  'type' => 'hidden',
651  'name' => 'id',
652  'value' => $iId
653  ),
654  'name' => array(
655  'type' => 'text',
656  'name' => 'name',
657  'caption' => _t('_adm_txt_keys_name'),
658  'value' => $GLOBALS['MySQL']->getOne("SELECT `Key` FROM `sys_localization_keys` WHERE `ID`='" . $iId . "' LIMIT 1"),
659  'attrs' => array(
660  'disabled' => 'disabled'
661  )
662  ),
663  )
664  );
665 
666  $aStrings = $GLOBALS['MySQL']->getAllWithKey("SELECT CONCAT('string_for_', `IDLanguage`) AS `key`, `String` AS `value` FROM `sys_localization_strings` WHERE `IDKey`= ?", "key", [$iId]);
667  $aLanguages = $GLOBALS['MySQL']->getAll("SELECT `ID` AS `id`, `Title` AS `title` FROM `sys_localization_languages`");
668  foreach($aLanguages as $aLanguage) {
669  $sKey = 'string_for_' . $aLanguage['id'];
670 
671  $aForm['inputs'][$sKey] = array(
672  'type' => 'textarea',
673  'name' => 'string_for_' . $aLanguage['id'],
674  'caption' => _t('_adm_txt_keys_string_for', $aLanguage['title']),
675  'value' => $aStrings[$sKey]['value'],
676  );
677  }
678  $aForm['inputs']['edit_key'] = array(
679  'type' => 'submit',
680  'name' => 'edit_key',
681  'value' => _t("_adm_btn_lang_save"),
682  );
683 
685  $sContent = $GLOBALS['oAdmTemplate']->parseHtmlByName('langs_key.html', array('type' => 'edit', 'content' => $oForm->getCode()));
686  return $GLOBALS['oFunctions']->popupBox('adm-langs-edit-key', _t('_adm_box_cpt_lang_key'), $sContent);
687 }
688 function createLanguage(&$aData)
689 {
690  global $MySQL;
691 
692  $sTitle = process_db_input($aData['CopyLanguage_Title']);
693  $sName = mb_strtolower( process_db_input($aData['CopyLanguage_Name']) );
694  $sFlag = process_db_input($aData['Flag']);
695  $sDir = process_db_input($aData['Direction']);
696  $sLangCountry = process_db_input($aData['LanguageCountry']);
697  $iSourceId = isset($aData['CopyLanguage_SourceLangID']) ? (int)$aData['CopyLanguage_SourceLangID'] : 0;
698 
699  if(strlen($sTitle) <= 0)
700  return '_adm_txt_langs_empty_title';
701  if(strlen($sName) <= 0)
702  return '_adm_txt_langs_empty_name';
703 
704  if(isset($aData['id']) && (int)$aData['id'] != 0) {
705  $MySQL->query("UPDATE `sys_localization_languages` SET `Name`='" . $sName . "', `Flag`='" . $sFlag . "', `Title`='" . $sTitle . "', `Direction`='" . $sDir . "', `LanguageCountry`='" . $sLangCountry . "' WHERE `ID`='" . (int)$aData['id'] . "'");
706 
707  return '_adm_txt_langs_success_updated';
708  }
709 
710  if (_checkLangUnique($sName) === true)
711  return '_adm_txt_langs_cannot_create';
712 
713  $mixedResult = $MySQL->query("INSERT INTO `sys_localization_languages` (`Name`, `Flag`, `Title`, `Direction`, `LanguageCountry`) VALUES ('{$sName}', '{$sFlag}', '{$sTitle}', '{$sDir}', '{$sLangCountry}')");
714  if($mixedResult === false)
715  return '_adm_txt_langs_cannot_create';
716  $iId = (int)$MySQL->lastId();
717 
718  $MySQL->cleanCache('sys_localization_languages');
719 
720  $aStrings = $MySQL->getAll("SELECT `IDKey`, `String` FROM `sys_localization_strings` WHERE `IDLanguage` = ?", [$iSourceId]);
721 
722  foreach($aStrings as $aString){
723  $aString['String'] = addslashes($aString['String']);
724  $count = $MySQL->query("INSERT INTO `sys_localization_strings`(`IDKey`, `IDLanguage`, `String`) VALUES ('{$aString['IDKey']}', $iId, '{$aString['String']}')");
725 
726  if( !$count )
727  return '_adm_txt_langs_cannot_add_string';
728  }
729 
730  return '_adm_txt_langs_success_create';
731 }
732 function importLanguage(&$aData, &$aFiles)
733 {
734  global $MySQL;
735 
736  $sTmpPath = $GLOBALS['dir']['tmp'] . time() . ".php";
737  if(!file_exists($aFiles['ImportLanguage_File']['tmp_name']) || !move_uploaded_file($aFiles['ImportLanguage_File']['tmp_name'], $sTmpPath))
738  return '_adm_txt_langs_cannot_upload_file';
739 
740  require_once($sTmpPath);
741 
742  $aLangInfo = isset($aLangInfo) ? $aLangInfo : $LANG_INFO;
744  if (empty($aLangInfo) || empty($aLangContent)) {
745  return '_adm_txt_langs_cannot_create';
746  }
747  if (_checkLangUnique($aLangInfo['Name']) === true)
748  return '_adm_txt_langs_cannot_create';
749 
750  $mixedResult = $MySQL->query("INSERT INTO `sys_localization_languages` (`Name`, `Flag`, `Title`, `Direction`, `LanguageCountry`)
751  VALUES (?, ?, ?, ?, ?)", [
752  $aLangInfo['Name'],
753  $aLangInfo['Flag'],
754  $aLangInfo['Title'],
755  $aLangInfo['Direction'],
756  $aLangInfo['LanguageCountry']
757  ]
758  );
759  if($mixedResult === false) {
760  @unlink($sTmpPath);
761  return '_adm_txt_langs_cannot_create';
762  }
763  $iId = (int)$MySQL->lastId();
764 
765  $MySQL->cleanCache('sys_localization_languages');
766 
767  $aKeys = $MySQL->getAllWithKey("SELECT `ID` AS `id`, `Key` AS `key` FROM `sys_localization_keys`", "key");
768  foreach($aLangContent as $sKey => $sString) {
769  if(!isset($aKeys[$sKey]))
770  continue;
771 
772  $MySQL->query("INSERT INTO `sys_localization_strings`(`IDKey`, `IDLanguage`, `String`) VALUES ('" . $aKeys[$sKey]['id'] . "', " . $iId . ", '" . addslashes($sString) . "')");
773  }
774 
776 
777  @unlink($sTmpPath);
778  return '_adm_txt_langs_success_import';
779 }
781 {
782  return $GLOBALS['MySQL']->getOne("SELECT `Name` FROM `sys_localization_languages` WHERE `ID`='" . (int)$iId . "' LIMIT 1");
783 }
process_db_input
process_db_input($sText, $iStripTags=0)
Definition: utils.inc.php:256
header
</code > Be careful enabling this directive if you have a redirector script that does not use the< code > Location</code > HTTP header
Definition: URI.MungeResources.txt:10
getLanguageName
getLanguageName($iId)
Definition: lang_file.php:780
importLanguage
importLanguage(&$aData, &$aFiles)
Definition: lang_file.php:732
ChTemplFormView
Definition: ChTemplFormView.php:11
_getLanguagesArray
_getLanguagesArray()
Definition: lang_file.php:288
MsgBox
MsgBox($sText, $iTimer=0)
Definition: design.inc.php:175
compileLanguage
compileLanguage($langID=0)
Definition: languages.inc.php:301
_getKeysList
_getKeysList($mixedResult, $bActive=false)
Definition: lang_file.php:300
$sCode
$sCode
Definition: explanation.php:19
$sResult
$sResult
Definition: advanced_settings.php:26
$_page
$_page
Definition: lang_file.php:246
$aLangContent
$aLangContent
Definition: en.php:8
ch_import
ch_import($sClassName, $aModule=array())
Definition: utils.inc.php:1218
$aResult
$aResult
Definition: index.php:19
PageCodeKeyEdit
PageCodeKeyEdit($iId)
Definition: lang_file.php:636
ch_get
ch_get($sName)
Definition: utils.inc.php:1664
$aResults
$aResults
Definition: lang_file.php:28
php
$_page_cont
$_page_cont[$iNameIndex]
Definition: lang_file.php:255
$iId
$iId
Definition: license.php:15
ChBaseSearchResult\showAdminFilterPanel
static showAdminFilterPanel($sFilterValue, $sInputId='filter_input_id', $sCheckboxId='filter_checkbox_id', $sFilterName='filter', $sOnApply='')
Definition: ChBaseSearchResult.php:124
_getLanguageSettingsForm
_getLanguageSettingsForm($mixedResult, $bActive=false)
Definition: lang_file.php:545
$oSettingsLanguage
$oSettingsLanguage
Definition: lang_file.php:25
$iNameIndex
if(isset($_POST['save']) &&isset($_POST['cat'])) if(isset($_POST['create_key_batch'])) if(isset($_POST['create_language'])) else if(isset($_POST['import_language'])) else if(isset($_POST['adm-lang-compile']) &&!empty($_POST['langs'])) else if(isset($_POST['adm-lang-delete']) &&!empty($_POST['langs'])) else if(isset($_GET['action']) && $_GET['action']=='export' &&isset($_GET['id'])) else if(isset($_POST['action']) && $_POST['action']=='get_edit_form_language') if(isset($_POST['action']) && $_POST['action']=='get_edit_form_key') if(isset($_POST['create_key'])) else if(isset($_POST['edit_key'])) if(isset($_POST['adm-lang-key-delete']) &&is_array($_POST['keys'])) $iNameIndex
Definition: lang_file.php:245
_getKeysBatch
_getKeysBatch($mixedResult, $bActive=false)
Definition: lang_file.php:340
$oForm
$oForm
Definition: host_tools.php:42
DesignBoxAdmin
DesignBoxAdmin($sTitle, $sContent, $mixedTopItems='', $sBottomItems='', $iIndex=1)
Definition: admin_design.inc.php:50
exit
exit
Definition: cart.php:21
$aTopItems
$aTopItems
Definition: antispam.php:366
$_GET
$_GET['debug']
Definition: index.php:67
getParam
getParam($sParamName, $bUseCache=true)
Definition: db.inc.php:130
_getLanguagesList
_getLanguagesList($mixedResult, $bActive=false)
Definition: lang_file.php:375
$sTitle
$sTitle
Definition: actions.inc.php:13
_checkLangUnique
_checkLangUnique($sLangName)
Definition: lang_file.php:294
htmlspecialchars_adv
htmlspecialchars_adv($string)
Definition: utils.inc.php:302
PageCodeMain
PageCodeMain($aResults)
Definition: lang_file.php:263
getLangsArr
getLangsArr( $bAddFlag=false, $bRetIDs=false)
Definition: languages.inc.php:155
createLanguage
createLanguage(&$aData)
Definition: lang_file.php:688
global
if(!defined("GLOBAL_MODULE")) define("GLOBAL_MODULE" global
Definition: header.inc.php:25
_getLanguageImportForm
_getLanguageImportForm($mixedResult, $bActive=false)
Definition: lang_file.php:509
PageCodeAdmin
PageCodeAdmin($oTemplate=null)
Definition: admin_design.inc.php:45
$sContent
$sContent
Definition: bottom_menu_compose.php:169
_t
_t($key, $arg0="", $arg1="", $arg2="")
Definition: languages.inc.php:509
time
that in the case of a Adaptation or at a minimum such credit will if a credit for all contributing authors of the Adaptation or Collection then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors For the avoidance of You may only use the credit required by this Section for the purpose of attribution in the manner set out above by exercising Your rights under this You may not implicitly or explicitly assert or imply any connection sponsorship or endorsement by the Original Licensor and or Attribution as of You or Your use of the without the express prior written permission of the Original Licensor and or Attribution Parties Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable if You Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or You must not modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author s honor or reputation Licensor agrees that in those in which any exercise of the right granted in modification or other derogatory action prejudicial to the Original Author s honor and the Licensor will waive or not as this to the fullest extent permitted by the applicable national to enable You to reasonably exercise Your right under Warranties and Disclaimer UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN LICENSOR OFFERS THE WORK AS IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE STATUTORY OR WITHOUT WARRANTIES OF FITNESS FOR A PARTICULAR OR THE ABSENCE OF LATENT OR OTHER OR THE PRESENCE OF ABSENCE OF WHETHER OR NOT DISCOVERABLE SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED SO SUCH EXCLUSION MAY NOT APPLY TO YOU Limitation on Liability EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES Termination This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License Individuals or entities who have received Adaptations or Collections from You under this will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses and will survive any termination of this License Subject to the above terms and the license granted here is Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time
Definition: license.txt:56
member_auth
member_auth($member=0, $error_handle=true, $bAjx=false)
Definition: admin.inc.php:262
$logged
$logged['admin']
Definition: lang_file.php:22
ChWsbAdminSettings
Definition: ChWsbAdminSettings.php:35
CH_TAGS_STRIP
const CH_TAGS_STRIP
Definition: utils.inc.php:22
deleteLanguage
deleteLanguage($langID=0)
Definition: languages.inc.php:173
PopupBox
PopupBox($sName, $sTitle, $sContent, $aActions=array())
Definition: design.inc.php:189
$LANG_INFO
$LANG_INFO
Definition: lang-en.php:8
$aForm
$aForm
Definition: forgot.php:43
ChBaseSearchResult\showAdminActionsPanel
static showAdminActionsPanel($sWrapperId, $aButtons, $sCheckboxName='entry', $bSelectAll=true, $bSelectAllChecked=false, $sCustomHtml='')
Definition: ChBaseSearchResult.php:81
empty
Attr AllowedRel this is empty
Definition: Attr.AllowedRel.txt:7
$aChSecurityExceptions
$aChSecurityExceptions
Definition: lang_file.php:9
_getLanguageCreateForm
_getLanguageCreateForm($mixedResult, $bActive=false)
Definition: lang_file.php:413
$sLangRssFeed
$sLangRssFeed
Definition: lang_file.php:253
PageCodeKeyCreate
PageCodeKeyCreate()
Definition: lang_file.php:584
as
as
Definition: Filter.ExtractStyleBlocks.Escaping.txt:10
$sName
$sName
Definition: ChWsbAdminTools.php:853
$GLOBALS
$GLOBALS['iAdminPage']
Definition: advanced_settings.php:10
$LANG
$LANG
Definition: lang-en.php:12