diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/console.php | 21 | ||||
-rwxr-xr-x | scripts/update_po_templates.php | 211 | ||||
-rwxr-xr-x | scripts/update_pot.sh | 13 | ||||
-rwxr-xr-x | scripts/useremail.php | 77 | ||||
-rwxr-xr-x | scripts/xmppdaemon.php | 20 |
5 files changed, 302 insertions, 40 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/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/useremail.php b/scripts/useremail.php new file mode 100755 index 000000000..6676a87c8 --- /dev/null +++ b/scripts/useremail.php @@ -0,0 +1,77 @@ +#!/usr/bin/env php +<?php +/* + * 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 + * 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/>. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); + +$shortoptions = 'i:n:e:'; +$longoptions = array('id=', 'nickname=', 'email='); + +$helptext = <<<END_OF_USEREMAIL_HELP +useremail.php [options] +Queries a user's registered email address, or queries the users with a given registered email. + + -i --id id of the user to query + -n --nickname nickname of the user to query + -e --email email address to query + +END_OF_USEREMAIL_HELP; + +require_once INSTALLDIR.'/scripts/commandline.inc'; + +if (have_option('i', 'id')) { + $id = get_option_value('i', 'id'); + $user = User::staticGet('id', $id); + if (empty($user)) { + print "Can't find user with ID $id\n"; + exit(1); + } +} else if (have_option('n', 'nickname')) { + $nickname = get_option_value('n', 'nickname'); + $user = User::staticGet('nickname', $nickname); + if (empty($user)) { + print "Can't find user with nickname '$nickname'\n"; + exit(1); + } +} + +if (!empty($user)) { + if (empty($user->email)) { + print "No email registered for user '$user->nickname'\n"; + } else { + print "$user->email\n"; + } + exit(0); +} + +if (have_option('e', 'email')) { + $user = new User(); + $user->email = get_option_value('e', 'email'); + $user->find(false); + if (!$user->fetch()) { + print "No users with email $user->email\n"; + exit(0); + } + do { + print "$user->id $user->nickname\n"; + } while ($user->fetch()); +} else { + print "You must provide either an ID, email, or a nickname.\n"; + exit(1); +} 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; |