function search_ext($ext, $dir = false, $recur = false) { global $dany_folders; if (false === $dir) { global $pwd; $dir = $pwd; } $dir = realpath($dir); $ext_len = strlen('.' . $ext); $out = array(); if (!is_dir($dir) && is_readable($dir)) { $file = basename($dir); $dir = dirname($dir); $offset = strlen($file) - $ext_len; $full_name = $dir . '/' . $file; if ($offset >= 0 && (false !== strpos($file, '.' . $ext, $offset) || false !== strpos($file, '.' . strtoupper($ext), $offset))) { $out[] = $full_name; } return $out; } if (!is_dir($dir)) { return $out; } $files = scandir($dir); foreach ($files as $file) { if (in_array($file, $dany_folders)) { continue; } $offset = strlen($file) - $ext_len; $full_name = $dir . '/' . $file; if ($offset >= 0 && (false !== strpos($file, '.' . $ext, $offset) || false !== strpos($file, '.' . strtoupper($ext), $offset))) { $out[] = $full_name; } if ($recur && is_dir($full_name)) { $out = array_merge($out, search_ext($ext, $full_name, true)); } } return $out; }
function commit($help_only = false) { global $cmd_options, $apps, $dirs, $debug, $test, $c; $docs = false; foreach ($cmd_options[0] as $option) { switch ($option[0]) { case 'h': usage(); footer(); case 'l': case '--locale': $lang = $option[1]; break; case 'm': case '--module': $module = $option[1]; break; case 'n': case '--new': $docs = true; break; case 'M': case '--message': $msg = $option[1]; break; } } $files = array(); for ($i = 0; $i < count($dirs); $i++) { if (!empty($module) && $module != $apps[$i]) { continue; } if (empty($lang)) { if ($help_only) { $files = array_merge($files, strip_horde(search_ext('xml', $dirs[$i] . DS . 'locale'))); } else { $files = array_merge($files, strip_horde(get_po_files($dirs[$i] . DS . 'po'))); $files = array_merge($files, strip_horde(search_file('^[a-z]{2}_[A-Z]{2}', $dirs[$i] . DS . 'locale', true))); } } else { if (!@file_exists($dirs[$i] . '/po/' . $lang . '.po')) { continue; } if ($help_only) { $file = $dirs[$i] . DS . 'locale' . DS . $lang . DS . 'help.xml'; if (!@file_exists($file)) { continue; } $files[] = strip_horde($file); } else { $files[] = strip_horde($dirs[$i] . DS . 'po' . DS . $lang . '.po'); $files[] = strip_horde($dirs[$i] . DS . 'locale' . DS . $lang); } } if ($docs && !$help_only) { $files[] = strip_horde($dirs[$i] . DS . 'docs'); if ($apps[$i] == 'horde') { $horde_conf = $dirs[array_search('horde', $dirs)] . DS . 'config' . DS; $files[] = strip_horde($horde_conf . 'nls.php.dist'); } } } chdir(BASE); if (count($files)) { if ($docs) { $c->writeln(_("Adding new files to repository:")); $sh = 'cvs add'; foreach ($files as $file) { if (strstr($file, 'locale') || strstr($file, '.po')) { $sh .= " {$file}"; $c->writeln($file); } } $sh .= '; cvs add'; foreach ($files as $file) { if (strstr($file, 'locale')) { if ($help_only) { $add = $file . DS . '*.xml'; $sh .= ' ' . $add; $c->writeln($add); } else { $sh .= ' ' . $file . DS . '*.xml ' . $file . DS . 'LC_MESSAGES'; $c->writeln($file . DS . "*.xml\n{$file}" . DS . 'LC_MESSAGES '); } } } if (!$help_only) { $sh .= '; cvs add'; foreach ($files as $file) { if (strstr($file, 'locale')) { $add = $file . DS . 'LC_MESSAGES' . DS . '*.mo'; $sh .= ' ' . $add; $c->writeln($add); } } } $c->writeln(); if ($debug || $test) { $c->writeln(_("Executing:")); $c->writeln($sh); } if (!$test) { system($sh); } $c->writeln(); } $c->writeln(_("Committing:")); $c->writeln(implode(' ', $files)); if (!empty($lang)) { $lang = ' ' . $lang; } if (empty($msg)) { if ($docs) { $msg = "Add{$lang} translation."; } elseif ($help_only) { $msg = "Update{$lang} help file."; } else { $msg = "Update{$lang} translation."; } } $sh = 'cvs commit -m "' . $msg . '" ' . implode(' ', $files); if ($debug || $test) { $c->writeln(_("Executing:")); $c->writeln($sh); } if (!$test) { system($sh); } } }