From 4c4771f61019b68bdf3d6896995fe9fb24b5fd45 Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Mon, 2 Mar 2015 15:05:54 +0100 Subject: [PATCH] tweeper.php: factor out an is_cli() function --- tweeper.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) 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'])) { -- 2.1.4