]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - scripts/commandline.inc
Merge branch '1.0.x' into schema-x
[quix0rs-gnu-social.git] / scripts / commandline.inc
index 1573b569db604cc0ad491ee4089bad43f07fbdbd..9390890ef33c0f7379c38d58fee4325aefdd935e 100644 (file)
@@ -27,6 +27,7 @@ if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
 }
 
 define('STATUSNET', true);
+define('LACONICA', true); // compatibility
 
 // Set various flags so we don't time out on long-running processes
 
@@ -122,6 +123,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();
@@ -172,3 +177,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::staticGet('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::staticGet('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);
+}
\ No newline at end of file