<?php
/*
- * Laconica - a distributed open-source microblogging tool
- * Copyright (C) 2008, 2009, Control Yourself, Inc.
+ * StatusNet - a distributed open-source microblogging tool
+ * Copyright (C) 2008, 2009, StatusNet, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
exit();
}
-define('LACONICA', true);
+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
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
set_error_handler('common_error_handler');
-function have_option($opt, $alt=null)
-{
- global $options;
+// 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();
if (strlen($opt) > 1 && 0 != strncmp($opt, '--', 2)) {
}
}
+ return $matches;
+}
+
+function have_option($opt, $alt=null)
+{
+ global $options;
+
+ $matches = _make_matches($opt, $alt);
+
foreach ($options as $option) {
if (in_array($option[0], $matches)) {
return true;
return false;
}
-function get_option_value($str, $alt=null)
+function get_option_value($opt, $alt=null)
{
global $options;
- $matches = array();
-
- if (strlen($opt) > 1 && 0 != strncmp($opt, '--', 2)) {
- $matches[] = '--'.$opt;
- } else {
- $matches[] = $opt;
- }
-
- if (!empty($alt)) {
- if (strlen($alt) > 1 && 0 != strncmp($alt, '--', 2)) {
- $matches[] = '--'.$alt;
- } else {
- $matches[] = $alt;
- }
- }
+ $matches = _make_matches($opt, $alt);
foreach ($options as $option) {
if (in_array($option[0], $matches)) {
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);
+}