X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=scripts%2Fcommandline.inc;h=296de70529fbc0ad5d92b7d1bfb49c5e4e93a623;hb=b261a77be2a894e3fe4d00c86925bac7fb5d061c;hp=9029bb19db4e7df9879d73fccbb4b792124c8599;hpb=fe1ae3a47edb09e3fd144589f095bfc40637ca2a;p=quix0rs-gnu-social.git diff --git a/scripts/commandline.inc b/scripts/commandline.inc index 9029bb19db..296de70529 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,15 +37,14 @@ 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 - -$_extra_path = array(INSTALLDIR.'/extlib/'); - +// Autoload composer dependencies +require_once INSTALLDIR . '/vendor/autoload.php'; +// Add extlib to our path +$_extra_path = [INSTALLDIR.'/extlib/']; set_include_path(implode(PATH_SEPARATOR, $_extra_path) . PATH_SEPARATOR . get_include_path()); -require_once 'Console/Getopt.php'; - // Note: $shortoptions and $longoptions should be pre-defined! $_default_shortoptions = 'qvhc:s:p:'; @@ -123,6 +124,10 @@ require_once INSTALLDIR . '/lib/common.php'; set_error_handler('common_error_handler'); +// Set up the language infrastructure so we can localize anything that +// needs to be sent out to users, such as mail notifications. +common_init_language(); + function _make_matches($opt, $alt) { $matches = array(); @@ -173,3 +178,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); +}