From: Antonio Ospite Date: Mon, 2 Mar 2015 14:05:54 +0000 (+0100) Subject: tweeper.php: factor out an is_cli() function X-Git-Tag: v0.4~29 X-Git-Url: https://git.ao2.it/tweeper.git/commitdiff_plain/4c4771f61019b68bdf3d6896995fe9fb24b5fd45 tweeper.php: factor out an is_cli() function --- diff --git a/tweeper.php b/tweeper.php index ed1e1c7..37b73f5 100644 --- a/tweeper.php +++ b/tweeper.php @@ -261,12 +261,18 @@ class Tweeper { } } +function is_cli() +{ + return (substr(php_sapi_name(), 0, 3) == 'cli'); +} + function usage($argv) { - if (php_sapi_name() != 'cli') - $usage = htmlentities("{$_SERVER['SCRIPT_NAME']}?src_url=&generate_enclosure=<0|1>"); - else + if (is_cli()) { $usage = "{$argv[0]} [-e|-h|--help] \n"; + } else { + $usage = htmlentities("{$_SERVER['SCRIPT_NAME']}?src_url=&generate_enclosure=<0|1>"); + } return "usage: $usage"; } @@ -317,12 +323,12 @@ function parse_options_query_string() } -if (php_sapi_name() != 'cli') { - $options = parse_options_query_string(); - $ERROR_STREAM = fopen('php://output', 'w'); -} else { +if (is_cli()) { $options = parse_options_cli($argv, $argc); $ERROR_STREAM = fopen('php://stderr', 'w'); +} else { + $options = parse_options_query_string(); + $ERROR_STREAM = fopen('php://output', 'w'); } if (!isset($options['src_url'])) {