projects
/
tweeper.git
/ commitdiff
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
a02e732
)
tweeper.php: factor out an is_cli() function
author
Antonio Ospite <ao2@ao2.it>
Mon, 2 Mar 2015 14:05:54 +0000
(15:05 +0100)
committer
Antonio Ospite <ao2@ao2.it>
Mon, 2 Mar 2015 14:05:54 +0000
(15:05 +0100)
tweeper.php
patch
|
blob
|
history
diff --git
a/tweeper.php
b/tweeper.php
index
ed1e1c7
..
37b73f5
100644
(file)
--- 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)
{
function usage($argv)
{
- if (php_sapi_name() != 'cli')
- $usage = htmlentities("{$_SERVER['SCRIPT_NAME']}?src_url=<src_url>&generate_enclosure=<0|1>");
- else
+ if (is_cli()) {
$usage = "{$argv[0]} [-e|-h|--help] <src_url>\n";
$usage = "{$argv[0]} [-e|-h|--help] <src_url>\n";
+ } else {
+ $usage = htmlentities("{$_SERVER['SCRIPT_NAME']}?src_url=<src_url>&generate_enclosure=<0|1>");
+ }
return "usage: $usage";
}
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');
$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'])) {
}
if (!isset($options['src_url'])) {