echo <<<USAGE CodeIgniterMU CLI Author: sskaje Usage: {$_SERVER['argv'][0]} -h|--host HOSTNAME PATH [PARAM1 [PARAM2 [...]]] USAGE; if ($msg) { echo "Error: {$msg}\n\n"; } exit; } if (isset($_SERVER['argv'][1])) { if ($_SERVER['argv'][1] == '-H' || $_SERVER['argv'][1] == '--help') { cli_usage(); } if ($_SERVER['argv'][1] == '-h' || $_SERVER['argv'][1] == '--host') { if (!isset($_SERVER['argv'][2])) { cli_usage("Missing hostname"); } if (!preg_match('#^([a-z0-9]+\\.)+[a-z0-9]+$#i', $_SERVER['argv'][2])) { cli_usage("Invalid hostname"); } $_SERVER['HTTP_HOST'] = $_SERVER['argv'][2]; unset($_SERVER['argv'][1], $_SERVER['argv'][2]); } } require __DIR__ . '/index.php'; # EOF
return; } } $readme_file = null; } lookup_readme_file(); function cli_usage() { global $argv; echo "Usage: preview_github_readme [README.md file]\n"; exit(1); die; } if (!$readme_file) { if ('cli' === php_sapi_name()) { cli_usage(); } trigger_error("No README.md file found!", E_USER_ERROR); } $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents($readme_file)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/plain')); curl_setopt($ch, CURLOPT_USERAGENT, sprintf('%s v%s %s', APP_NAME, APP_VERSION, APP_URL)); $response = curl_exec($ch); curl_close($ch); ob_start(function ($buffer) { global $template, $response, $readme_file, $stylesheet; $tpl = file_get_contents($readme_file); $buffer = str_replace("%stylesheet%", "<style>{$stylesheet}</style>", $buffer);