langstats.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script prints a list of most used language terms. The registration of
  5. * frequency for language variables is a very heavy operation.
  6. * To enable, add "$_configuration['language_measure_frequency' ] = 1;" at the
  7. * end of main/inc/conf/configuration.php. Remove when done.
  8. * Add ?output=1 to the URL to generate languag files in /tmp/lang/ with just
  9. * the number of terms you want.
  10. */
  11. /**
  12. * Requires
  13. */
  14. die();
  15. require_once '../../inc/global.inc.php';
  16. require_once 'langstats.class.php';
  17. /**
  18. * Init
  19. */
  20. $terms_limit = 10000 + 50;
  21. $x_most_popular = 2000;
  22. $output = false;
  23. $ls = new langstats();
  24. if ($ls === false) {
  25. exit($ls->error);
  26. }
  27. $list = $ls->get_popular_terms($x_most_popular);
  28. if ($_GET['output'] == 1) {
  29. $output = true;
  30. $variables_origin = $ls->get_variables_origin();
  31. }
  32. /**
  33. * Display
  34. */
  35. if (count($list) == 0) { echo 'No terms loaded so far'; }
  36. if (count($list) > 0) {
  37. $i = 1;
  38. $j = 1;
  39. $k = 0;
  40. $files = array();
  41. $trans = array();
  42. echo 'Number of records: '.count($list).'<br />';
  43. echo '<table><tr><th>Index</th><th>Registration order</th><th>Term</th>'.($output == 1 ? '<th>Origin</th>' : '').'<th>Count</th></tr>';
  44. foreach ($list as $elem) {
  45. if ($k > $terms_limit) { break; }
  46. $fixed_elem = $elem;
  47. if ($output) {
  48. if (empty($variables_origin[$elem['term_name']]) && !empty($variables_origin['lang'.$elem['term_name']])) {
  49. $fixed_elem = array('id' => $elem['id'], 'term_name' => 'lang'.$elem['term_name'], 'term_count' => $elem['term_count']);
  50. }
  51. if (empty($variables_origin[$fixed_elem['term_name']])) {
  52. continue;
  53. }
  54. $files[$variables_origin[$fixed_elem['term_name']]][] = $fixed_elem['term_name'];
  55. $translation = get_lang($fixed_elem['term_name']);
  56. $k += str_word_count($translation);
  57. $trans[$fixed_elem['term_name']] = $translation;
  58. $j++;
  59. }
  60. echo '<tr><td>', $i,
  61. '</td><td>', $fixed_elem['id'],
  62. '</td><td>', $fixed_elem['term_name'];
  63. if ($output) {
  64. echo '</td><td>'.$variables_origin[$fixed_elem['term_name']];
  65. }
  66. echo '</td><td>', $fixed_elem['term_count'], '</td></tr>';
  67. $i++;
  68. }
  69. echo '</table>';
  70. if ($output) {
  71. @mkdir('/tmp/lang');
  72. foreach ($files as $file => $terms) {
  73. @touch('/tmp/lang/'.$file);
  74. file_put_contents('/tmp/lang/'.$file, "<?php".PHP_EOL);
  75. foreach ($terms as $term) {
  76. file_put_contents('/tmp/lang/'.$file, '$'.$term.' = "'.str_replace('"', '\"', $trans[$term]).'";'.PHP_EOL, FILE_APPEND);
  77. }
  78. }
  79. }
  80. }