. /** * Used to convert a bootswatch file from https://bootswatch.com/ to a Moodle preset. * * @package theme_ilb * @subpackage cli * @copyright 2016 Damyon Wiese * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ define('CLI_SCRIPT', true); require(__DIR__.'/../../../config.php'); require_once($CFG->libdir.'/clilib.php'); // Now get cli options. list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help', 'v' => 'variables', 'b' => 'bootswatch', 'p' => 'preset')); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } if (!isset($options['variables'])) { $options['variables'] = '_variables.scss'; } if (!isset($options['bootswatch'])) { $options['bootswatch'] = '_bootswatch.scss'; } if (!isset($options['preset'])) { $options['preset'] = 'preset.scss'; } if ($options['help']) { $help = "Convert a Bootswatch file from Bootstrap 3 to a Moodle preset file compatible with bootstrap 4. This scripts takes the scss files from a Bootstrap 3 Bootswatch and produces a Moodle compatible preset file. Options: -h, --help Print out this help -v, --variables= -b, --bootswatch= -p, --preset= Example: \$import-bootswatch.php -v=_variables.scss -b=_bootswatch.scss -p=preset-paper.scss "; echo $help; die; } cli_heading('Convert a Bootswatch file from Bootstrap 3 to a Moodle preset file compatible with bootstrap 4.'); $variablesfile = $options['variables']; $bootswatchfile = $options['bootswatch']; $presetfile = $options['preset']; $sourcevariables = @file_get_contents($variablesfile); if (!$sourcevariables) { die('Could not read variables file: ' . $variablesfile . "\n"); } $sourcebootswatch = @file_get_contents($bootswatchfile); if (!$sourcebootswatch) { die('Could not read bootswatch file: ' . $bootswatchfile . "\n"); } function str_replace_one($needle, $replace, $haystack) { $pos = strpos($haystack, $needle); if ($pos !== false) { $newstring = substr_replace($haystack, $replace, $pos, strlen($needle)); } return $newstring; } $out = @fopen($presetfile, "w"); if (!$out) { die('Could not open preset file for writing: ' . $presetfile . "\n"); } // Write the license (MIT). $license = <<