X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=scripts%2Fcommandline.inc;h=392166a98088dae0ca2f563b0a1709b68ccc7e9b;hb=ab93bb009c8533c8847aafe76ba9774d9d74e7ca;hp=a475e11d01abba19ba7fb9ba8126f00f312388c7;hpb=cae1329f3bca1f5f1fbfdb1d96b38cbb790fbe00;p=quix0rs-gnu-social.git diff --git a/scripts/commandline.inc b/scripts/commandline.inc index a475e11d01..392166a980 100644 --- a/scripts/commandline.inc +++ b/scripts/commandline.inc @@ -26,8 +26,10 @@ if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) { exit(); } -define('STATUSNET', true); -define('LACONICA', true); // compatibility +define('GNUSOCIAL', true); +define('STATUSNET', true); //compatibility + +define('GNUSOCIAL_CLI', true); // to know we're in a CLI environment // Set various flags so we don't time out on long-running processes @@ -35,6 +37,7 @@ ini_set("max_execution_time", "0"); ini_set("max_input_time", "0"); set_time_limit(0); mb_internal_encoding('UTF-8'); +error_reporting(E_ALL & ~E_STRICT & ~E_DEPRECATED); // Add extlib to our path so we can get Console_Getopt @@ -177,3 +180,70 @@ function get_option_value($opt, $alt=null) return null; } + +class NoUserArgumentException extends Exception +{ +} + +function getUser() +{ + $user = null; + + if (have_option('i', 'id')) { + $id = get_option_value('i', 'id'); + $user = User::getKV('id', $id); + if (empty($user)) { + throw new Exception("Can't find user with id '$id'."); + } + } else if (have_option('n', 'nickname')) { + $nickname = get_option_value('n', 'nickname'); + $user = User::getKV('nickname', $nickname); + if (empty($user)) { + throw new Exception("Can't find user with nickname '$nickname'"); + } + } else { + throw new NoUserArgumentException("No user argument specified."); + } + + return $user; +} + +/** "Printf not quiet" */ + +function printfnq() +{ + if (have_option('q', 'quiet')) { + return null; + } + + $cargs = func_num_args(); + + if ($cargs == 0) { + return 0; + } + + $args = func_get_args(); + $format = array_shift($args); + + return vprintf($format, $args); +} + +/** "Print when verbose" */ + +function printfv() +{ + if (!have_option('v', 'verbose')) { + return null; + } + + $cargs = func_num_args(); + + if ($cargs == 0) { + return 0; + } + + $args = func_get_args(); + $format = array_shift($args); + + return vprintf($format, $args); +}