You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
4.9 KiB

  1. #!/usr/bin/php
  2. <?php
  3. define('DOCUMENT_ROOT', dirname(__FILE__));
  4. require_once(DOCUMENT_ROOT.'/bootstrap.php');
  5. $bootstrap = new Bootstrap();
  6. $bootstrap->boot();
  7. $argsize = count($argv);
  8. if($argsize == 1) {
  9. echo
  10. colorize("Welcome to Mud - Movim Unified Doer
  11. Here some requests you can do with me :", 'green')."
  12. - ".colorize("getloc", 'yellow')." grab all the translations in Movim and generate a global locale file
  13. - ".colorize("comploc", 'yellow')." compile the current locales to a simple PHP array to boost Movim execution
  14. - ".colorize("comptz", 'yellow')." compile the timezones
  15. - ".colorize("db", 'yellow')." create/update the database
  16. - ".colorize("config", 'yellow')." set the configuration of Movim (separated by commas and colons) eg. info:Test,description:Hop
  17. ";
  18. } elseif($argsize == 2) {
  19. switch ($argv[1]) {
  20. case 'getloc':
  21. getloc();
  22. break;
  23. case 'comploc':
  24. comploc();
  25. break;
  26. case 'comptz':
  27. comptz();
  28. break;
  29. case 'config':
  30. echo colorize("You need to pass an argument", 'red');
  31. break;
  32. case 'db':
  33. $md = Modl\Modl::getInstance();
  34. $infos = $md->check();
  35. if($infos == null) {
  36. echo colorize("Nothing to do\n", 'green');
  37. } else {
  38. foreach($infos as $i) {
  39. echo colorize("The database need to be updated\n", 'green');
  40. echo colorize($i."\n", 'blue');
  41. }
  42. }
  43. break;
  44. }
  45. } elseif($argsize == 3) {
  46. switch ($argv[1]) {
  47. case 'config':
  48. config($argv[2]);
  49. break;
  50. case 'db':
  51. if($argv[2] == 'set') {
  52. $md = Modl\Modl::getInstance();
  53. $md->check(true);
  54. echo colorize("Database updated\n", 'green');
  55. }
  56. break;
  57. }
  58. }
  59. function config($values) {
  60. echo colorize("Movim configuration setter\n", 'green');
  61. $cd = new \Modl\ConfigDAO();
  62. $config = $cd->get();
  63. $values = explode(',', $values);
  64. foreach($values as $value) {
  65. $exp = explode(':', $value);
  66. $key = $exp[0];
  67. array_shift($exp);
  68. $value = implode(':', $exp);
  69. if(property_exists($config, $key)) {
  70. $old = $config->$key;
  71. $config->$key = $value;
  72. $cd->set($config);
  73. echo colorize("The configuration key ", 'yellow').
  74. colorize($key, 'red').
  75. colorize(" has been updated from ", 'yellow').
  76. colorize($old, 'blue').
  77. colorize(" to ", 'yellow').
  78. colorize($value, 'blue')."\n";
  79. }
  80. }
  81. }
  82. function getloc() {
  83. echo colorize("Locales grabber\n", 'green');
  84. // We look for all the ini files
  85. $inifiles = glob(WIDGETS_PATH.'*/*.ini');
  86. array_push($inifiles, LOCALES_PATH . 'locales.ini');
  87. $locales = CACHE_PATH.'locales.php';
  88. $pot = CACHE_PATH.'messages.pot';
  89. // We create the cache file
  90. $out = "<?php\n";
  91. foreach($inifiles as $ini) {
  92. $keys = parse_ini_file($ini);
  93. foreach($keys as $key => $value) {
  94. $out .= "t(\"$value\");\n";
  95. }
  96. }
  97. $fp = fopen($locales, 'w');
  98. fwrite($fp, $out);
  99. fclose($fp);
  100. echo "File $locales created\n";
  101. // And we run gettext on it
  102. exec("xgettext -e --no-wrap -kt -o $pot -L PHP $locales ");
  103. echo "File $pot created\n";
  104. }
  105. function comploc() {
  106. echo colorize("Locales compiler\n", 'green');
  107. $folder = CACHE_PATH.'/locales/';
  108. if(!file_exists($folder)) {
  109. $bool = mkdir($folder);
  110. if(!$bool) {
  111. echo colorize("The locales cache folder can't be created", 'red');
  112. exit;
  113. }
  114. } else
  115. echo colorize("Folder already exist, don't re-create it\n", 'red');
  116. $langs = loadLangArray();
  117. foreach($langs as $key => $value) {
  118. $langarr = parseLangFile(DOCUMENT_ROOT . '/locales/' . $key . '.po');
  119. $out = '<?php global $translations;
  120. $translations = array(';
  121. foreach($langarr as $msgid => $msgstr)
  122. if($msgid != '')
  123. $out .= '"'.$msgid.'" => "'. $msgstr . '",'."\n";
  124. $out .= ');';
  125. $fp = fopen($folder.$key.'.php', 'w');
  126. fwrite($fp, $out);
  127. fclose($fp);
  128. echo "- $key compiled\n";
  129. }
  130. }
  131. function comptz() {
  132. $file = HELPERS_PATH.'TimezoneList.php';
  133. $tz = generateTimezoneList();
  134. $out = '<?php global $timezones;
  135. $timezones = array(';
  136. foreach($tz as $key => $value)
  137. $out .= '"'.$key.'" => "'. $value . '",'."\n";
  138. $out .= ');';
  139. $fp = fopen($file, 'w');
  140. fwrite($fp, $out);
  141. fclose($fp);
  142. echo "- Timezones compiled in $file\n";
  143. }
  144. echo "\n";