summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2009-12-22 16:44:19 -0800
committerEvan Prodromou <evan@status.net>2009-12-22 16:44:19 -0800
commitf6bf9529805cd58fdd1671dd9b133bde05e8ae87 (patch)
treecf272bd1105da48f016b635db4d9c34810adcbda /scripts
parentf987273f118a12d443b6789c2ab59d7a4b01f678 (diff)
parent30c2e2ce83282f0bc268153d7ec465fbb5cf00ca (diff)
Merge branch 'testing'
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/console.php21
-rwxr-xr-xscripts/fixup_utf8.php8
-rwxr-xr-xscripts/setup_status_network.sh4
-rwxr-xr-xscripts/update_po_templates.php211
-rwxr-xr-xscripts/update_pot.sh13
-rw-r--r--scripts/updateavatarurl.php8
-rwxr-xr-xscripts/xmppdaemon.php20
7 files changed, 237 insertions, 48 deletions
diff --git a/scripts/console.php b/scripts/console.php
index 210d2b6b2..329caf472 100755
--- a/scripts/console.php
+++ b/scripts/console.php
@@ -73,7 +73,7 @@ function read_input_line($prompt)
*/
function readline_emulation($prompt)
{
- if(file_exists(trim(shell_exec('which bash')))) {
+ if(CONSOLE_INTERACTIVE && file_exists(trim(shell_exec('which bash')))) {
$encPrompt = escapeshellarg($prompt);
$command = "read -er -p $encPrompt && echo \"\$REPLY\"";
$encCommand = escapeshellarg($command);
@@ -103,7 +103,9 @@ function readline_emulation($prompt)
if (feof(STDIN)) {
return false;
}
- print $prompt;
+ if (CONSOLE_INTERACTIVE) {
+ print $prompt;
+ }
return fgets(STDIN);
}
@@ -123,13 +125,16 @@ function console_help()
print "Type ctrl+D or enter 'exit' to exit.\n";
}
-
-print "StatusNet interactive PHP console... type ctrl+D or enter 'exit' to exit.\n";
-$prompt = common_config('site', 'name') . '> ';
+if (CONSOLE_INTERACTIVE) {
+ print "StatusNet interactive PHP console... type ctrl+D or enter 'exit' to exit.\n";
+ $prompt = common_config('site', 'name') . '> ';
+}
while (!feof(STDIN)) {
$line = read_input_line($prompt);
if ($line === false) {
- print "\n";
+ if (CONSOLE_INTERACTIVE) {
+ print "\n";
+ }
break;
} elseif ($line !== '') {
try {
@@ -154,5 +159,7 @@ while (!feof(STDIN)) {
print get_class($e) . ": " . $e->getMessage() . "\n";
}
}
- print "\n";
+ if (CONSOLE_INTERACTIVE) {
+ print "\n";
+ }
}
diff --git a/scripts/fixup_utf8.php b/scripts/fixup_utf8.php
index 5a9fba7c3..30befadfd 100755
--- a/scripts/fixup_utf8.php
+++ b/scripts/fixup_utf8.php
@@ -145,7 +145,7 @@ class UTF8FixerUpper
echo "$id...";
- $result =& $this->dbu->execute($sth, array($content, $rendered, $id));
+ $result = $this->dbu->execute($sth, array($content, $rendered, $id));
if (PEAR::isError($result)) {
echo "ERROR: " . $result->getMessage() . "\n";
@@ -209,7 +209,7 @@ class UTF8FixerUpper
echo "$id...";
- $result =& $this->dbu->execute($sth, array($fullname, $location, $bio, $id));
+ $result = $this->dbu->execute($sth, array($fullname, $location, $bio, $id));
if (PEAR::isError($result)) {
echo "ERROR: " . $result->getMessage() . "\n";
@@ -273,7 +273,7 @@ class UTF8FixerUpper
echo "$id...";
- $result =& $this->dbu->execute($sth, array($fullname, $location, $description, $id));
+ $result = $this->dbu->execute($sth, array($fullname, $location, $description, $id));
if (PEAR::isError($result)) {
echo "ERROR: " . $result->getMessage() . "\n";
@@ -330,7 +330,7 @@ class UTF8FixerUpper
echo "$id...";
- $result =& $this->dbu->execute($sth, array($content, $rendered, $id));
+ $result = $this->dbu->execute($sth, array($content, $rendered, $id));
if (PEAR::isError($result)) {
echo "ERROR: " . $result->getMessage() . "\n";
diff --git a/scripts/setup_status_network.sh b/scripts/setup_status_network.sh
index d40d4724f..777711fb5 100755
--- a/scripts/setup_status_network.sh
+++ b/scripts/setup_status_network.sh
@@ -19,8 +19,8 @@ done
mysql -h $DBHOST -u $ADMIN --password=$ADMINPASS $SITEDB << ENDOFCOMMANDS
-GRANT INSERT,SELECT,UPDATE,DELETE ON $database.* TO '$username'@'localhost' IDENTIFIED BY '$password';
-GRANT INSERT,SELECT,UPDATE,DELETE ON $database.* TO '$username'@'%' IDENTIFIED BY '$password';
+GRANT ALL ON $database.* TO '$username'@'localhost' IDENTIFIED BY '$password';
+GRANT ALL ON $database.* TO '$username'@'%' IDENTIFIED BY '$password';
INSERT INTO status_network (nickname, dbhost, dbuser, dbpass, dbname, sitename, created)
VALUES ('$nickname', '$DBHOSTNAME', '$username', '$password', '$database', '$sitename', now());
diff --git a/scripts/update_po_templates.php b/scripts/update_po_templates.php
new file mode 100755
index 000000000..83bff6d80
--- /dev/null
+++ b/scripts/update_po_templates.php
@@ -0,0 +1,211 @@
+#!/usr/bin/env php
+<?php
+/*
+ * StatusNet - the 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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Abort if called from a web server
+if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
+ print "This script must be run from the command line\n";
+ exit();
+}
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
+
+function update_core($dir, $domain)
+{
+ $old = getcwd();
+ chdir($dir);
+ passthru(<<<END
+xgettext \
+ --from-code=UTF-8 \
+ --default-domain=$domain \
+ --output=locale/$domain.po \
+ --language=PHP \
+ --keyword="_m:1" \
+ --keyword="pgettext:1c,2" \
+ --keyword="npgettext:1c,2,3" \
+ actions/*.php \
+ classes/*.php \
+ lib/*.php \
+ scripts/*.php
+END
+);
+ chdir($old);
+}
+
+function do_update_plugin($dir, $domain)
+{
+ $old = getcwd();
+ chdir($dir);
+ if (!file_exists('locale')) {
+ mkdir('locale');
+ }
+ $files = get_plugin_sources(".");
+ $cmd = <<<END
+xgettext \
+ --from-code=UTF-8 \
+ --default-domain=$domain \
+ --output=locale/$domain.po \
+ --language=PHP \
+ --keyword='' \
+ --keyword="_m:1" \
+
+END;
+ foreach ($files as $file) {
+ $cmd .= ' ' . escapeshellarg($file);
+ }
+ passthru($cmd);
+ chdir($old);
+}
+
+function do_translatewiki_plugin($basedir, $plugin)
+{
+ $yamldir = "$basedir/locale/TranslateWiki";
+ if (!file_exists($yamldir)) {
+ mkdir($yamldir);
+ }
+ $outfile = "$yamldir/StatusNet-{$plugin}.yml";
+ $data = <<<END
+---
+BASIC:
+ id: out-statusnet-{$plugin}
+ label: StatusNet - {$plugin}
+ description: "{{int:bw-desc-statusnet-plugin-{$plugin}}}"
+ namespace: NS_STATUSNET
+ display: out/statusnet/{$plugin}
+ class: GettextMessageGroup
+
+FILES:
+ class: GettextFFS
+ sourcePattern: %GROUPROOT%/plugins/{$plugin}/locale/%CODE%/LC_MESSAGES/{$plugin}.po
+ targetPattern: {$plugin}.po
+ codeMap:
+ en-gb: en_GB
+ no: nb
+ pt-br: pt_BR
+ zh-hans: zh_CN
+ zh-hant: zh_TW
+
+MANGLER
+ class: StringMatcher
+ prefix: {$plugin}-
+ patterns:
+ - "*"
+
+END;
+ file_put_contents($outfile, $data);
+}
+
+function get_plugins($dir)
+{
+ $plugins = array();
+ $dirs = new DirectoryIterator("$dir/plugins");
+ foreach ($dirs as $item) {
+ if ($item->isDir() && !$item->isDot()) {
+ $name = $item->getBasename();
+ if (file_exists("$dir/plugins/$name/{$name}Plugin.php")) {
+ $plugins[] = $name;
+ }
+ }
+ }
+ return $plugins;
+}
+
+function get_plugin_sources($dir)
+{
+ $files = array();
+
+ $dirs = new RecursiveDirectoryIterator($dir);
+ $iter = new RecursiveIteratorIterator($dirs);
+ foreach ($iter as $pathname => $item) {
+ if ($item->isFile() && preg_match('/\.php$/', $item->getBaseName())) {
+ $files[] = $pathname;
+ }
+ }
+ return $files;
+}
+
+function plugin_using_gettext($dir)
+{
+ $files = get_plugin_sources($dir);
+ foreach ($files as $pathname) {
+ // Check if the file is using our _m gettext wrapper
+ $code = file_get_contents($pathname);
+ if (preg_match('/\b_m\(/', $code)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+function update_plugin($basedir, $name)
+{
+ $dir = "$basedir/plugins/$name";
+ if (plugin_using_gettext($dir)) {
+ do_update_plugin($dir, $name);
+ do_translatewiki_plugin($basedir, $name);
+ return true;
+ } else {
+ return false;
+ }
+}
+
+$args = $_SERVER['argv'];
+array_shift($args);
+
+$all = false;
+$core = false;
+$allplugins = false;
+$plugins = array();
+if (count($args) == 0) {
+ $all = true;
+}
+foreach ($args as $arg) {
+ if ($arg == '--all') {
+ $all = true;
+ } elseif ($arg == "--core") {
+ $core = true;
+ } elseif ($arg == "--plugins") {
+ $allplugins = true;
+ } elseif (substr($arg, 0, 9) == "--plugin=") {
+ $plugins[] = substr($arg, 9);
+ }
+}
+
+
+
+if ($all || $core) {
+ echo "core...";
+ update_core(INSTALLDIR, 'statusnet');
+ echo " ok\n";
+}
+if ($all || $allplugins) {
+ $plugins = get_plugins(INSTALLDIR);
+}
+if ($plugins) {
+ foreach ($plugins as $plugin) {
+ echo "$plugin...";
+ if (update_plugin(INSTALLDIR, $plugin)) {
+ echo " ok\n";
+ } else {
+ echo " not localized\n";
+ }
+ }
+}
+
diff --git a/scripts/update_pot.sh b/scripts/update_pot.sh
deleted file mode 100755
index de53fe7c9..000000000
--- a/scripts/update_pot.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-cd `dirname $0`
-cd ..
-xgettext \
- --from-code=UTF-8 \
- --default-domain=statusnet \
- --output=locale/statusnet.po \
- --language=PHP \
- --keyword="pgettext:1c,2" \
- --keyword="npgettext:1c,2,3" \
- actions/*.php \
- classes/*.php \
- lib/*.php \
- scripts/*.php
diff --git a/scripts/updateavatarurl.php b/scripts/updateavatarurl.php
index dfcfc118c..617c2e24c 100644
--- a/scripts/updateavatarurl.php
+++ b/scripts/updateavatarurl.php
@@ -60,7 +60,8 @@ try {
}
}
} else {
- throw new Exception("You have to provide an ID or nickname or 'all'.");
+ show_help();
+ exit(1);
}
} catch (Exception $e) {
print $e->getMessage()."\n";
@@ -123,6 +124,9 @@ function updateAvatars($user)
}
if (have_option('v', 'verbose')) {
- print "DONE.\n";
+ print "DONE.";
+ }
+ if (!have_option('q', 'quiet') || have_option('v', 'verbose')) {
+ print "\n";
}
}
diff --git a/scripts/xmppdaemon.php b/scripts/xmppdaemon.php
index e52e2a6af..20105b602 100755
--- a/scripts/xmppdaemon.php
+++ b/scripts/xmppdaemon.php
@@ -195,17 +195,6 @@ class XMPPDaemon extends Daemon
} else if ($this->is_otr($pl['body'])) {
$this->log(LOG_INFO, 'Ignoring OTR from ' . $from);
return;
- } else if ($this->is_direct($pl['body'])) {
- $this->log(LOG_INFO, 'Got a direct message ' . $from);
-
- preg_match_all('/d[\ ]*([a-z0-9]{1,64})/', $pl['body'], $to);
-
- $to = preg_replace('/^d([\ ])*/', '', $to[0][0]);
- $body = preg_replace('/d[\ ]*('. $to .')[\ ]*/', '', $pl['body']);
-
- $this->log(LOG_INFO, 'Direct message from '. $user->nickname . ' to ' . $to);
-
- $this->add_direct($user, $body, $to, $from);
} else {
$this->log(LOG_INFO, 'Posting a notice from ' . $user->nickname);
@@ -284,15 +273,6 @@ class XMPPDaemon extends Daemon
}
}
- function is_direct($txt)
- {
- if (strtolower(substr($txt, 0, 2))=='d ') {
- return true;
- } else {
- return false;
- }
- }
-
function from_site($address, $msg)
{
$text = '['.common_config('site', 'name') . '] ' . $msg;