diff options
author | ahriman <ahriman@falte.red> | 2018-12-03 19:22:25 -0500 |
---|---|---|
committer | ahriman <ahriman@falte.red> | 2018-12-03 19:22:25 -0500 |
commit | 0ae8cbf5c0b1a198b963490985b7738392ebcb97 (patch) | |
tree | b2c77ae72c6b717e2b97492065196ac5ffb2d9e2 /wiki/bin/striplangs.php | |
parent | f57f6cc5a2d159f90168d292437dc4bd8cd7f934 (diff) | |
download | site-0ae8cbf5c0b1a198b963490985b7738392ebcb97.tar.gz |
installed dokuwiki, added to navbar, updated news
Diffstat (limited to 'wiki/bin/striplangs.php')
-rwxr-xr-x | wiki/bin/striplangs.php | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/wiki/bin/striplangs.php b/wiki/bin/striplangs.php new file mode 100755 index 0000000..1800971 --- /dev/null +++ b/wiki/bin/striplangs.php @@ -0,0 +1,114 @@ +#!/usr/bin/php +<?php + +use splitbrain\phpcli\CLI; +use splitbrain\phpcli\Options; + +if(!defined('DOKU_INC')) define('DOKU_INC', realpath(dirname(__FILE__) . '/../') . '/'); +define('NOSESSION', 1); +require_once(DOKU_INC . 'inc/init.php'); + +/** + * Remove unwanted languages from a DokuWiki install + */ +class StripLangsCLI extends CLI { + + /** + * Register options and arguments on the given $options object + * + * @param Options $options + * @return void + */ + protected function setup(Options $options) { + + $options->setHelp( + 'Remove all languages from the installation, besides the ones specified. English language ' . + 'is never removed!' + ); + + $options->registerOption( + 'keep', + 'Comma separated list of languages to keep in addition to English.', + 'k', + 'langcodes' + ); + $options->registerOption( + 'english-only', + 'Remove all languages except English', + 'e' + ); + } + + /** + * Your main program + * + * Arguments and options have been parsed when this is run + * + * @param Options $options + * @return void + */ + protected function main(Options $options) { + if($options->getOpt('keep')) { + $keep = explode(',', $options->getOpt('keep')); + if(!in_array('en', $keep)) $keep[] = 'en'; + } elseif($options->getOpt('english-only')) { + $keep = array('en'); + } else { + echo $options->help(); + exit(0); + } + + // Kill all language directories in /inc/lang and /lib/plugins besides those in $langs array + $this->stripDirLangs(realpath(dirname(__FILE__) . '/../inc/lang'), $keep); + $this->processExtensions(realpath(dirname(__FILE__) . '/../lib/plugins'), $keep); + $this->processExtensions(realpath(dirname(__FILE__) . '/../lib/tpl'), $keep); + } + + /** + * Strip languages from extensions + * + * @param string $path path to plugin or template dir + * @param array $keep_langs languages to keep + */ + protected function processExtensions($path, $keep_langs) { + if(is_dir($path)) { + $entries = scandir($path); + + foreach($entries as $entry) { + if($entry != "." && $entry != "..") { + if(is_dir($path . '/' . $entry)) { + + $plugin_langs = $path . '/' . $entry . '/lang'; + + if(is_dir($plugin_langs)) { + $this->stripDirLangs($plugin_langs, $keep_langs); + } + } + } + } + } + } + + /** + * Strip languages from path + * + * @param string $path path to lang dir + * @param array $keep_langs languages to keep + */ + protected function stripDirLangs($path, $keep_langs) { + $dir = dir($path); + + while(($cur_dir = $dir->read()) !== false) { + if($cur_dir != '.' and $cur_dir != '..' and is_dir($path . '/' . $cur_dir)) { + + if(!in_array($cur_dir, $keep_langs, true)) { + io_rmdir($path . '/' . $cur_dir, true); + } + } + } + $dir->close(); + } +} + +$cli = new StripLangsCLI(); +$cli->run(); |