136c0b2b4SAndreas Gohr#!/usr/bin/env php 236c0b2b4SAndreas Gohr<?php 336c0b2b4SAndreas Gohr 436c0b2b4SAndreas Gohruse dokuwiki\Extension\CLIPlugin; 536c0b2b4SAndreas Gohruse dokuwiki\Extension\PluginController; 65586e97bSAndreas Gohruse dokuwiki\plugin\dev\LangProcessor; 770316b84SAndreas Gohruse dokuwiki\plugin\dev\Skeletor; 81a23d1dbSAndreas Gohruse dokuwiki\plugin\dev\SVGIcon; 936c0b2b4SAndreas Gohruse splitbrain\phpcli\Exception as CliException; 1036c0b2b4SAndreas Gohruse splitbrain\phpcli\Options; 1136c0b2b4SAndreas Gohr 1236c0b2b4SAndreas Gohr/** 1336c0b2b4SAndreas Gohr * @license GPL2 1436c0b2b4SAndreas Gohr * @author Andreas Gohr <andi@splitbrain.org> 1536c0b2b4SAndreas Gohr */ 1636c0b2b4SAndreas Gohrclass cli_plugin_dev extends CLIPlugin 1736c0b2b4SAndreas Gohr{ 1836c0b2b4SAndreas Gohr /** 1936c0b2b4SAndreas Gohr * Register options and arguments on the given $options object 2036c0b2b4SAndreas Gohr * 2136c0b2b4SAndreas Gohr * @param Options $options 2236c0b2b4SAndreas Gohr * @return void 2336c0b2b4SAndreas Gohr */ 2436c0b2b4SAndreas Gohr protected function setup(Options $options) 2536c0b2b4SAndreas Gohr { 26f2576912SAndreas Gohr $options->useCompactHelp(); 2736c0b2b4SAndreas Gohr $options->setHelp( 28f2576912SAndreas Gohr "CLI to help with DokuWiki plugin and template development.\n\n" . 2936c0b2b4SAndreas Gohr "Run this script from within the extension's directory." 3036c0b2b4SAndreas Gohr ); 3136c0b2b4SAndreas Gohr 32fcb8165bSAndreas Gohr $options->registerCommand('init', 'Initialize a new plugin or template in the current directory.'); 33f2576912SAndreas Gohr $options->registerCommand('addTest', 'Add the testing framework files and a test. (_test/)'); 34f2576912SAndreas Gohr $options->registerArgument('test', 'Optional name of the new test. Defaults to the general test.', false, 35f2576912SAndreas Gohr 'addTest'); 36f2576912SAndreas Gohr $options->registerCommand('addConf', 'Add the configuration files. (conf/)'); 37f2576912SAndreas Gohr $options->registerCommand('addLang', 'Add the language files. (lang/)'); 3836c0b2b4SAndreas Gohr 39f2576912SAndreas Gohr $types = PluginController::PLUGIN_TYPES; 40f2576912SAndreas Gohr array_walk( 41f2576912SAndreas Gohr $types, 42f2576912SAndreas Gohr function (&$item) { 43f2576912SAndreas Gohr $item = $this->colors->wrap($item, $this->colors::C_BROWN); 44f2576912SAndreas Gohr } 4536c0b2b4SAndreas Gohr ); 4636c0b2b4SAndreas Gohr 47f2576912SAndreas Gohr $options->registerCommand('addComponent', 'Add a new plugin component.'); 48f2576912SAndreas Gohr $options->registerArgument('type', 'Type of the component. Needs to be one of ' . join(', ', $types), true, 49f2576912SAndreas Gohr 'addComponent'); 50f2576912SAndreas Gohr $options->registerArgument('name', 'Optional name of the component. Defaults to a base component.', false, 51f2576912SAndreas Gohr 'addComponent'); 52f2576912SAndreas Gohr 53f2576912SAndreas Gohr $options->registerCommand('deletedFiles', 'Create the list of deleted files based on the git history.'); 54f2576912SAndreas Gohr $options->registerCommand('rmObsolete', 'Delete obsolete files.'); 551a23d1dbSAndreas Gohr 561a23d1dbSAndreas Gohr $prefixes = array_keys(SVGIcon::SOURCES); 571a23d1dbSAndreas Gohr array_walk( 581a23d1dbSAndreas Gohr $prefixes, 591a23d1dbSAndreas Gohr function (&$item) { 601a23d1dbSAndreas Gohr $item = $this->colors->wrap($item, $this->colors::C_BROWN); 611a23d1dbSAndreas Gohr } 621a23d1dbSAndreas Gohr ); 631a23d1dbSAndreas Gohr 641a23d1dbSAndreas Gohr $options->registerCommand('downloadSvg', 'Download an SVG file from a known icon repository.'); 651a23d1dbSAndreas Gohr $options->registerArgument('prefix:name', 661a23d1dbSAndreas Gohr 'Colon-prefixed name of the icon. Available prefixes: ' . join(', ', $prefixes), true, 'downloadSvg'); 671a23d1dbSAndreas Gohr $options->registerArgument('output', 'File to save, defaults to <name>.svg in current dir', false, 681a23d1dbSAndreas Gohr 'downloadSvg'); 6992738407SAndreas Gohr $options->registerOption('keep-ns', 'Keep the SVG namespace. Use when the file is not inlined into HTML.', 'k', 7092738407SAndreas Gohr false, 'downloadSvg'); 711a23d1dbSAndreas Gohr 728f82d673SAndreas Gohr $options->registerCommand('cleanSvg', 'Clean a existing SVG files to reduce their file size.'); 738f82d673SAndreas Gohr $options->registerArgument('files...', 'The files to clean (will be overwritten)', true, 'cleanSvg'); 7492738407SAndreas Gohr $options->registerOption('keep-ns', 'Keep the SVG namespace. Use when the file is not inlined into HTML.', 'k', 7592738407SAndreas Gohr false, 'cleanSvg'); 765586e97bSAndreas Gohr 775586e97bSAndreas Gohr $options->registerCommand('cleanLang', 785586e97bSAndreas Gohr 'Clean language files from unused language strings. Detecting which strings are truly in use may ' . 795586e97bSAndreas Gohr 'not always correctly work. Use with caution.'); 8036c0b2b4SAndreas Gohr } 8136c0b2b4SAndreas Gohr 8236c0b2b4SAndreas Gohr /** @inheritDoc */ 8336c0b2b4SAndreas Gohr protected function main(Options $options) 8436c0b2b4SAndreas Gohr { 851a23d1dbSAndreas Gohr $args = $options->getArgs(); 861a23d1dbSAndreas Gohr 8736c0b2b4SAndreas Gohr switch ($options->getCmd()) { 8836c0b2b4SAndreas Gohr case 'init': 8936c0b2b4SAndreas Gohr return $this->cmdInit(); 9036c0b2b4SAndreas Gohr case 'addTest': 9136c0b2b4SAndreas Gohr $test = array_shift($args); 9236c0b2b4SAndreas Gohr return $this->cmdAddTest($test); 9336c0b2b4SAndreas Gohr case 'addConf': 9436c0b2b4SAndreas Gohr return $this->cmdAddConf(); 9536c0b2b4SAndreas Gohr case 'addLang': 9636c0b2b4SAndreas Gohr return $this->cmdAddLang(); 9736c0b2b4SAndreas Gohr case 'addComponent': 9836c0b2b4SAndreas Gohr $type = array_shift($args); 9936c0b2b4SAndreas Gohr $component = array_shift($args); 10036c0b2b4SAndreas Gohr return $this->cmdAddComponent($type, $component); 10136c0b2b4SAndreas Gohr case 'deletedFiles': 10236c0b2b4SAndreas Gohr return $this->cmdDeletedFiles(); 103c5c85a97SAndreas Gohr case 'rmObsolete': 1041a23d1dbSAndreas Gohr return $this->cmdRmObsolete(); 1051a23d1dbSAndreas Gohr case 'downloadSvg': 1061a23d1dbSAndreas Gohr $ident = array_shift($args); 1071a23d1dbSAndreas Gohr $save = array_shift($args); 10870316b84SAndreas Gohr $keep = $options->getOpt('keep-ns'); 10992738407SAndreas Gohr return $this->cmdDownloadSVG($ident, $save, $keep); 1101a23d1dbSAndreas Gohr case 'cleanSvg': 11170316b84SAndreas Gohr $keep = $options->getOpt('keep-ns'); 1128f82d673SAndreas Gohr return $this->cmdCleanSVG($args, $keep); 1135586e97bSAndreas Gohr case 'cleanLang': 1145586e97bSAndreas Gohr return $this->cmdCleanLang(); 11536c0b2b4SAndreas Gohr default: 1161a23d1dbSAndreas Gohr $this->error('Unknown command'); 11736c0b2b4SAndreas Gohr echo $options->help(); 11836c0b2b4SAndreas Gohr return 0; 11936c0b2b4SAndreas Gohr } 12036c0b2b4SAndreas Gohr } 12136c0b2b4SAndreas Gohr 12236c0b2b4SAndreas Gohr /** 12336c0b2b4SAndreas Gohr * Get the extension name from the current working directory 12436c0b2b4SAndreas Gohr * 12536c0b2b4SAndreas Gohr * @throws CliException if something's wrong 12636c0b2b4SAndreas Gohr * @param string $dir 12736c0b2b4SAndreas Gohr * @return string[] name, type 12836c0b2b4SAndreas Gohr */ 12936c0b2b4SAndreas Gohr protected function getTypedNameFromDir($dir) 13036c0b2b4SAndreas Gohr { 13136c0b2b4SAndreas Gohr $pdir = fullpath(DOKU_PLUGIN); 13236c0b2b4SAndreas Gohr $tdir = fullpath(tpl_incdir() . '../'); 13336c0b2b4SAndreas Gohr 13436c0b2b4SAndreas Gohr if (strpos($dir, $pdir) === 0) { 13536c0b2b4SAndreas Gohr $ldir = substr($dir, strlen($pdir)); 13636c0b2b4SAndreas Gohr $type = 'plugin'; 13736c0b2b4SAndreas Gohr } elseif (strpos($dir, $tdir) === 0) { 13836c0b2b4SAndreas Gohr $ldir = substr($dir, strlen($tdir)); 13936c0b2b4SAndreas Gohr $type = 'template'; 14036c0b2b4SAndreas Gohr } else { 14136c0b2b4SAndreas Gohr throw new CliException('Current directory needs to be in plugin or template directory'); 14236c0b2b4SAndreas Gohr } 14336c0b2b4SAndreas Gohr 14436c0b2b4SAndreas Gohr $ldir = trim($ldir, '/'); 14536c0b2b4SAndreas Gohr 14636c0b2b4SAndreas Gohr if (strpos($ldir, '/') !== false) { 14736c0b2b4SAndreas Gohr throw new CliException('Current directory has to be main extension directory'); 14836c0b2b4SAndreas Gohr } 14936c0b2b4SAndreas Gohr 15036c0b2b4SAndreas Gohr return [$ldir, $type]; 15136c0b2b4SAndreas Gohr } 15236c0b2b4SAndreas Gohr 15336c0b2b4SAndreas Gohr /** 15436c0b2b4SAndreas Gohr * Interactively ask for a value from the user 15536c0b2b4SAndreas Gohr * 15636c0b2b4SAndreas Gohr * @param string $prompt 15736c0b2b4SAndreas Gohr * @param bool $cache cache given value for next time? 15836c0b2b4SAndreas Gohr * @return string 15936c0b2b4SAndreas Gohr */ 16036c0b2b4SAndreas Gohr protected function readLine($prompt, $cache = false) 16136c0b2b4SAndreas Gohr { 16236c0b2b4SAndreas Gohr $value = ''; 16336c0b2b4SAndreas Gohr $default = ''; 16436c0b2b4SAndreas Gohr $cachename = getCacheName($prompt, '.readline'); 16536c0b2b4SAndreas Gohr if ($cache && file_exists($cachename)) { 16636c0b2b4SAndreas Gohr $default = file_get_contents($cachename); 16736c0b2b4SAndreas Gohr } 16836c0b2b4SAndreas Gohr 16936c0b2b4SAndreas Gohr while ($value === '') { 17036c0b2b4SAndreas Gohr echo $prompt; 17136c0b2b4SAndreas Gohr if ($default) echo ' [' . $default . ']'; 17236c0b2b4SAndreas Gohr echo ': '; 17336c0b2b4SAndreas Gohr 17436c0b2b4SAndreas Gohr $fh = fopen('php://stdin', 'r'); 17536c0b2b4SAndreas Gohr $value = trim(fgets($fh)); 17636c0b2b4SAndreas Gohr fclose($fh); 17736c0b2b4SAndreas Gohr 17836c0b2b4SAndreas Gohr if ($value === '') $value = $default; 17936c0b2b4SAndreas Gohr } 18036c0b2b4SAndreas Gohr 18136c0b2b4SAndreas Gohr if ($cache) { 18236c0b2b4SAndreas Gohr file_put_contents($cachename, $value); 18336c0b2b4SAndreas Gohr } 18436c0b2b4SAndreas Gohr 18536c0b2b4SAndreas Gohr return $value; 18636c0b2b4SAndreas Gohr } 18736c0b2b4SAndreas Gohr 18836c0b2b4SAndreas Gohr /** 18970316b84SAndreas Gohr * Create the given files with their given content 19036c0b2b4SAndreas Gohr * 19170316b84SAndreas Gohr * Ignores all files that already exist 19270316b84SAndreas Gohr * 19370316b84SAndreas Gohr * @param array $files A File array as created by Skeletor::getFiles() 19436c0b2b4SAndreas Gohr */ 195fcb8165bSAndreas Gohr protected function createFiles($files) 196fcb8165bSAndreas Gohr { 19770316b84SAndreas Gohr foreach ($files as $path => $content) { 19870316b84SAndreas Gohr if (file_exists($path)) { 19970316b84SAndreas Gohr $this->error($path . ' already exists'); 20070316b84SAndreas Gohr continue; 20136c0b2b4SAndreas Gohr } 20236c0b2b4SAndreas Gohr 20370316b84SAndreas Gohr io_makeFileDir($path); 20470316b84SAndreas Gohr file_put_contents($path, $content); 20570316b84SAndreas Gohr $this->success($path . ' created'); 20636c0b2b4SAndreas Gohr } 20736c0b2b4SAndreas Gohr } 20836c0b2b4SAndreas Gohr 20936c0b2b4SAndreas Gohr /** 210c5c85a97SAndreas Gohr * Delete the given file if it exists 211c5c85a97SAndreas Gohr * 212c5c85a97SAndreas Gohr * @param string $file 213c5c85a97SAndreas Gohr */ 214c5c85a97SAndreas Gohr protected function deleteFile($file) 215c5c85a97SAndreas Gohr { 216c5c85a97SAndreas Gohr if (!file_exists($file)) return; 217c5c85a97SAndreas Gohr if (@unlink($file)) { 218c5c85a97SAndreas Gohr $this->success('Delete ' . $file); 219c5c85a97SAndreas Gohr } 220c5c85a97SAndreas Gohr } 221c5c85a97SAndreas Gohr 222c5c85a97SAndreas Gohr /** 223c5c85a97SAndreas Gohr * Run git with the given arguments and return the output 224c5c85a97SAndreas Gohr * 225c5c85a97SAndreas Gohr * @throws CliException when the command can't be run 226c5c85a97SAndreas Gohr * @param string ...$args 227c5c85a97SAndreas Gohr * @return string[] 228c5c85a97SAndreas Gohr */ 229c5c85a97SAndreas Gohr protected function git(...$args) 230c5c85a97SAndreas Gohr { 231c5c85a97SAndreas Gohr $args = array_map('escapeshellarg', $args); 232c5c85a97SAndreas Gohr $cmd = 'git ' . join(' ', $args); 233c5c85a97SAndreas Gohr $output = []; 234c5c85a97SAndreas Gohr $result = 0; 235c5c85a97SAndreas Gohr 236c5c85a97SAndreas Gohr $this->info($cmd); 237c5c85a97SAndreas Gohr $last = exec($cmd, $output, $result); 238c5c85a97SAndreas Gohr if ($last === false || $result !== 0) { 239c5c85a97SAndreas Gohr throw new CliException('Running git failed'); 240c5c85a97SAndreas Gohr } 241c5c85a97SAndreas Gohr 242c5c85a97SAndreas Gohr return $output; 243c5c85a97SAndreas Gohr } 244c5c85a97SAndreas Gohr 245c5c85a97SAndreas Gohr // region Commands 246c5c85a97SAndreas Gohr 247c5c85a97SAndreas Gohr /** 24836c0b2b4SAndreas Gohr * Intialize the current directory as a plugin or template 24936c0b2b4SAndreas Gohr * 25036c0b2b4SAndreas Gohr * @return int 25136c0b2b4SAndreas Gohr */ 25236c0b2b4SAndreas Gohr protected function cmdInit() 25336c0b2b4SAndreas Gohr { 25436c0b2b4SAndreas Gohr $dir = fullpath(getcwd()); 25536c0b2b4SAndreas Gohr if ((new FilesystemIterator($dir))->valid()) { 256fcb8165bSAndreas Gohr // existing directory, initialize from info file 257fcb8165bSAndreas Gohr $skeletor = Skeletor::fromDir($dir); 258fcb8165bSAndreas Gohr } else { 259fcb8165bSAndreas Gohr // new directory, ask for info 26070316b84SAndreas Gohr [$base, $type] = $this->getTypedNameFromDir($dir); 26136c0b2b4SAndreas Gohr $user = $this->readLine('Your Name', true); 26236c0b2b4SAndreas Gohr $mail = $this->readLine('Your E-Mail', true); 26336c0b2b4SAndreas Gohr $desc = $this->readLine('Short description'); 26470316b84SAndreas Gohr $skeletor = new Skeletor($type, $base, $desc, $user, $mail); 265fcb8165bSAndreas Gohr } 26670316b84SAndreas Gohr $skeletor->addBasics(); 26770316b84SAndreas Gohr $this->createFiles($skeletor->getFiles()); 26836c0b2b4SAndreas Gohr 269fcb8165bSAndreas Gohr if (!is_dir("$dir/.git")) { 2708b06c9ddSAndreas Gohr try { 2718b06c9ddSAndreas Gohr $this->git('init'); 2728b06c9ddSAndreas Gohr } catch (CliException $e) { 2738b06c9ddSAndreas Gohr $this->error($e->getMessage()); 2748b06c9ddSAndreas Gohr } 275fcb8165bSAndreas Gohr } 2768b06c9ddSAndreas Gohr 27736c0b2b4SAndreas Gohr return 0; 27836c0b2b4SAndreas Gohr } 27936c0b2b4SAndreas Gohr 28036c0b2b4SAndreas Gohr /** 28136c0b2b4SAndreas Gohr * Add test framework 28236c0b2b4SAndreas Gohr * 28336c0b2b4SAndreas Gohr * @param string $test Name of the Test to add 28436c0b2b4SAndreas Gohr * @return int 28536c0b2b4SAndreas Gohr */ 28636c0b2b4SAndreas Gohr protected function cmdAddTest($test = '') 28736c0b2b4SAndreas Gohr { 28870316b84SAndreas Gohr $skeletor = Skeletor::fromDir(getcwd()); 28970316b84SAndreas Gohr $skeletor->addTest($test); 29070316b84SAndreas Gohr $this->createFiles($skeletor->getFiles()); 29136c0b2b4SAndreas Gohr return 0; 29236c0b2b4SAndreas Gohr } 29336c0b2b4SAndreas Gohr 29436c0b2b4SAndreas Gohr /** 29536c0b2b4SAndreas Gohr * Add configuration 29636c0b2b4SAndreas Gohr * 29736c0b2b4SAndreas Gohr * @return int 29836c0b2b4SAndreas Gohr */ 29936c0b2b4SAndreas Gohr protected function cmdAddConf() 30036c0b2b4SAndreas Gohr { 30170316b84SAndreas Gohr $skeletor = Skeletor::fromDir(getcwd()); 30270316b84SAndreas Gohr $skeletor->addConf(is_dir('lang')); 30370316b84SAndreas Gohr $this->createFiles($skeletor->getFiles()); 30436c0b2b4SAndreas Gohr return 0; 30536c0b2b4SAndreas Gohr } 30636c0b2b4SAndreas Gohr 30736c0b2b4SAndreas Gohr /** 30836c0b2b4SAndreas Gohr * Add language 30936c0b2b4SAndreas Gohr * 31036c0b2b4SAndreas Gohr * @return int 31136c0b2b4SAndreas Gohr */ 31236c0b2b4SAndreas Gohr protected function cmdAddLang() 31336c0b2b4SAndreas Gohr { 31470316b84SAndreas Gohr $skeletor = Skeletor::fromDir(getcwd()); 31570316b84SAndreas Gohr $skeletor->addLang(is_dir('conf')); 31670316b84SAndreas Gohr $this->createFiles($skeletor->getFiles()); 31736c0b2b4SAndreas Gohr return 0; 31836c0b2b4SAndreas Gohr } 31936c0b2b4SAndreas Gohr 32036c0b2b4SAndreas Gohr /** 32136c0b2b4SAndreas Gohr * Add another component to the plugin 32236c0b2b4SAndreas Gohr * 32336c0b2b4SAndreas Gohr * @param string $type 32436c0b2b4SAndreas Gohr * @param string $component 32536c0b2b4SAndreas Gohr */ 32636c0b2b4SAndreas Gohr protected function cmdAddComponent($type, $component = '') 32736c0b2b4SAndreas Gohr { 32870316b84SAndreas Gohr $skeletor = Skeletor::fromDir(getcwd()); 32970316b84SAndreas Gohr $skeletor->addComponent($type, $component); 33070316b84SAndreas Gohr $this->createFiles($skeletor->getFiles()); 33136c0b2b4SAndreas Gohr return 0; 33236c0b2b4SAndreas Gohr } 33336c0b2b4SAndreas Gohr 33436c0b2b4SAndreas Gohr /** 33536c0b2b4SAndreas Gohr * Generate a list of deleted files from git 33636c0b2b4SAndreas Gohr * 33736c0b2b4SAndreas Gohr * @link https://stackoverflow.com/a/6018049/172068 33836c0b2b4SAndreas Gohr */ 33936c0b2b4SAndreas Gohr protected function cmdDeletedFiles() 34036c0b2b4SAndreas Gohr { 3418b06c9ddSAndreas Gohr if (!is_dir('.git')) throw new CliException('This extension seems not to be managed by git'); 34236c0b2b4SAndreas Gohr 3438b06c9ddSAndreas Gohr $output = $this->git('log', '--no-renames', '--pretty=format:', '--name-only', '--diff-filter=D'); 34436c0b2b4SAndreas Gohr $output = array_map('trim', $output); 34536c0b2b4SAndreas Gohr $output = array_filter($output); 34636c0b2b4SAndreas Gohr $output = array_unique($output); 34736c0b2b4SAndreas Gohr $output = array_filter($output, function ($item) { 34836c0b2b4SAndreas Gohr return !file_exists($item); 34936c0b2b4SAndreas Gohr }); 35036c0b2b4SAndreas Gohr sort($output); 35136c0b2b4SAndreas Gohr 35236c0b2b4SAndreas Gohr if (!count($output)) { 35336c0b2b4SAndreas Gohr $this->info('No deleted files found'); 35436c0b2b4SAndreas Gohr return 0; 35536c0b2b4SAndreas Gohr } 35636c0b2b4SAndreas Gohr 35736c0b2b4SAndreas Gohr $content = "# This is a list of files that were present in previous releases\n" . 35836c0b2b4SAndreas Gohr "# but were removed later. They should not exist in your installation.\n" . 35936c0b2b4SAndreas Gohr join("\n", $output) . "\n"; 36036c0b2b4SAndreas Gohr 36136c0b2b4SAndreas Gohr file_put_contents('deleted.files', $content); 36236c0b2b4SAndreas Gohr $this->success('written deleted.files'); 36336c0b2b4SAndreas Gohr return 0; 36436c0b2b4SAndreas Gohr } 3658b06c9ddSAndreas Gohr 3668b06c9ddSAndreas Gohr /** 367c5c85a97SAndreas Gohr * Remove files that shouldn't be here anymore 3688b06c9ddSAndreas Gohr */ 3691a23d1dbSAndreas Gohr protected function cmdRmObsolete() 3708b06c9ddSAndreas Gohr { 371c5c85a97SAndreas Gohr $this->deleteFile('_test/general.test.php'); 372c5c85a97SAndreas Gohr $this->deleteFile('.travis.yml'); 373*53bec4caSAndreas Gohr $this->deleteFile('.github/workflows/phpTestLinux.yml'); 3748b06c9ddSAndreas Gohr 375c5c85a97SAndreas Gohr return 0; 3768b06c9ddSAndreas Gohr } 3778b06c9ddSAndreas Gohr 3781a23d1dbSAndreas Gohr /** 3791a23d1dbSAndreas Gohr * Download a remote icon 3801a23d1dbSAndreas Gohr * 3811a23d1dbSAndreas Gohr * @param string $ident 3821a23d1dbSAndreas Gohr * @param string $save 38392738407SAndreas Gohr * @param bool $keep 3841a23d1dbSAndreas Gohr * @return int 3851a23d1dbSAndreas Gohr * @throws Exception 3861a23d1dbSAndreas Gohr */ 38792738407SAndreas Gohr protected function cmdDownloadSVG($ident, $save = '', $keep = false) 3881a23d1dbSAndreas Gohr { 3891a23d1dbSAndreas Gohr $svg = new SVGIcon($this); 39092738407SAndreas Gohr $svg->keepNamespace($keep); 3911a23d1dbSAndreas Gohr return (int)$svg->downloadRemoteIcon($ident, $save); 3921a23d1dbSAndreas Gohr } 3931a23d1dbSAndreas Gohr 3941a23d1dbSAndreas Gohr /** 3958f82d673SAndreas Gohr * @param string[] $files 39692738407SAndreas Gohr * @param bool $keep 3971a23d1dbSAndreas Gohr * @return int 3981a23d1dbSAndreas Gohr * @throws Exception 3991a23d1dbSAndreas Gohr */ 4008f82d673SAndreas Gohr protected function cmdCleanSVG($files, $keep = false) 4011a23d1dbSAndreas Gohr { 4021a23d1dbSAndreas Gohr $svg = new SVGIcon($this); 40392738407SAndreas Gohr $svg->keepNamespace($keep); 4048f82d673SAndreas Gohr 4058f82d673SAndreas Gohr $ok = true; 4068f82d673SAndreas Gohr foreach ($files as $file) { 4078f82d673SAndreas Gohr $ok = $ok && $svg->cleanSVGFile($file); 4088f82d673SAndreas Gohr } 4098f82d673SAndreas Gohr return (int)$ok; 4101a23d1dbSAndreas Gohr } 4111a23d1dbSAndreas Gohr 4125586e97bSAndreas Gohr /** 4135586e97bSAndreas Gohr * @return int 4145586e97bSAndreas Gohr */ 4155586e97bSAndreas Gohr protected function cmdCleanLang() 4165586e97bSAndreas Gohr { 4175586e97bSAndreas Gohr $lp = new LangProcessor($this); 4185586e97bSAndreas Gohr 4195586e97bSAndreas Gohr $files = glob('./lang/*/lang.php'); 4205b2e8f12SAndreas Gohr foreach ($files as $file) { 4215b2e8f12SAndreas Gohr $lp->processLangFile($file); 4225b2e8f12SAndreas Gohr } 4235b2e8f12SAndreas Gohr 4245b2e8f12SAndreas Gohr $files = glob('./lang/*/settings.php'); 4255586e97bSAndreas Gohr foreach ($files as $file) { 426f4f76afdSAndreas Gohr $lp->processSettingsFile($file); 4275586e97bSAndreas Gohr } 4285586e97bSAndreas Gohr 4295586e97bSAndreas Gohr return 0; 4305586e97bSAndreas Gohr } 4315586e97bSAndreas Gohr 432c5c85a97SAndreas Gohr //endregion 43336c0b2b4SAndreas Gohr} 434