summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorEvan Prodromou <evan@prodromou.name>2008-12-23 14:33:23 -0500
committerEvan Prodromou <evan@prodromou.name>2008-12-23 14:33:23 -0500
commit04ef1ba8eee7a9e2a565d7b4b747ef607665d562 (patch)
treed56ac33bd6bfb8f8641cc9f63b0f6af52b6edfb9 /scripts
parenteb2f9c98ac115ce67e9a740b200c832153ffa05c (diff)
change function headers to K&R style
Another huge change, for PEAR code standards compliance. Function headers have to be in K&R style (opening brace on its own line), instead of having the opening brace on the same line as the function and parameters. So, a little perl magic found all the function definitions and move the opening brace to the next line (properly indented... usually). darcs-hash:20081223193323-84dde-a28e36ecc66672c783c2842d12fc11043c13ab28.gz
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/enjitqueuehandler.php9
-rwxr-xr-xscripts/jabberqueuehandler.php6
-rwxr-xr-xscripts/maildaemon.php36
-rwxr-xr-xscripts/ombqueuehandler.php15
-rwxr-xr-xscripts/publicqueuehandler.php6
-rw-r--r--scripts/sitemap.php39
-rwxr-xr-xscripts/smsqueuehandler.php12
-rwxr-xr-xscripts/xmppconfirmhandler.php12
-rwxr-xr-xscripts/xmppdaemon.php54
9 files changed, 126 insertions, 63 deletions
diff --git a/scripts/enjitqueuehandler.php b/scripts/enjitqueuehandler.php
index 1c033603f..55d73e08c 100755
--- a/scripts/enjitqueuehandler.php
+++ b/scripts/enjitqueuehandler.php
@@ -35,17 +35,20 @@ set_error_handler('common_error_handler');
class EnjitQueueHandler extends QueueHandler {
- function transport() {
+ function transport()
+ {
return 'enjit';
}
- function start() {
+ function start()
+ {
$this->log(LOG_INFO, "Starting EnjitQueueHandler");
$this->log(LOG_INFO, "Broadcasting to ".common_config('enjit', 'apiurl'));
return true;
}
- function handle_notice($notice) {
+ function handle_notice($notice)
+ {
$profile = Profile::staticGet($notice->profile_id);
diff --git a/scripts/jabberqueuehandler.php b/scripts/jabberqueuehandler.php
index 271aab22b..ea26aaf79 100755
--- a/scripts/jabberqueuehandler.php
+++ b/scripts/jabberqueuehandler.php
@@ -37,11 +37,13 @@ class JabberQueueHandler extends XmppQueueHandler {
var $conn = null;
- function transport() {
+ function transport()
+ {
return 'jabber';
}
- function handle_notice($notice) {
+ function handle_notice($notice)
+ {
try {
return jabber_broadcast_notice($notice);
} catch (XMPPHP_Exception $e) {
diff --git a/scripts/maildaemon.php b/scripts/maildaemon.php
index 886e72ba7..6100cd21b 100755
--- a/scripts/maildaemon.php
+++ b/scripts/maildaemon.php
@@ -36,10 +36,12 @@ require_once('Mail/mimeDecode.php');
class MailerDaemon {
- function __construct() {
+ function __construct()
+ {
}
- function handle_message($fname='php://stdin') {
+ function handle_message($fname='php://stdin')
+ {
list($from, $to, $msg) = $this->parse_message($fname);
if (!$from || !$to || !$msg) {
$this->error(null, _('Could not parse message.'));
@@ -66,12 +68,14 @@ class MailerDaemon {
$this->add_notice($user, $msg);
}
- function error($from, $msg) {
+ function error($from, $msg)
+ {
file_put_contents("php://stderr", $msg . "\n");
exit(1);
}
- function user_from($from_hdr) {
+ function user_from($from_hdr)
+ {
$froms = mailparse_rfc822_parse_addresses($from_hdr);
if (!$froms) {
return null;
@@ -85,7 +89,8 @@ class MailerDaemon {
return $user;
}
- function user_match_to($user, $to_hdr) {
+ function user_match_to($user, $to_hdr)
+ {
$incoming = $user->incomingemail;
$tos = mailparse_rfc822_parse_addresses($to_hdr);
foreach ($tos as $to) {
@@ -96,7 +101,8 @@ class MailerDaemon {
return false;
}
- function handle_command($user, $from, $msg) {
+ function handle_command($user, $from, $msg)
+ {
$inter = new CommandInterpreter();
$cmd = $inter->handle_command($user, $msg);
if ($cmd) {
@@ -106,7 +112,8 @@ class MailerDaemon {
return false;
}
- function respond($from, $to, $response) {
+ function respond($from, $to, $response)
+ {
$headers['From'] = $to;
$headers['To'] = $from;
@@ -115,11 +122,13 @@ class MailerDaemon {
return mail_send(array($from), $headers, $response);
}
- function log($level, $msg) {
+ function log($level, $msg)
+ {
common_log($level, 'MailDaemon: '.$msg);
}
- function add_notice($user, $msg) {
+ function add_notice($user, $msg)
+ {
// should test
// $msg_shortened = common_shorten_links($msg);
// if (mb_strlen($msg_shortened) > 140) ERROR and STOP
@@ -133,7 +142,8 @@ class MailerDaemon {
'Added notice ' . $notice->id . ' from user ' . $user->nickname);
}
- function parse_message($fname) {
+ function parse_message($fname)
+ {
$contents = file_get_contents($fname);
$parsed = Mail_mimeDecode::decode(array('input' => $contents,
'include_bodies' => true,
@@ -166,11 +176,13 @@ class MailerDaemon {
return array($from, $to, $msg);
}
- function unsupported_type($type) {
+ function unsupported_type($type)
+ {
$this->error(null, "Unsupported message type: " . $type);
}
- function cleanup_msg($msg) {
+ function cleanup_msg($msg)
+ {
$lines = explode("\n", $msg);
$output = '';
diff --git a/scripts/ombqueuehandler.php b/scripts/ombqueuehandler.php
index 43c0980b6..299381ace 100755
--- a/scripts/ombqueuehandler.php
+++ b/scripts/ombqueuehandler.php
@@ -35,16 +35,19 @@ set_error_handler('common_error_handler');
class OmbQueueHandler extends QueueHandler {
- function transport() {
+ function transport()
+ {
return 'omb';
}
- function start() {
+ function start()
+ {
$this->log(LOG_INFO, "INITIALIZE");
return true;
}
- function handle_notice($notice) {
+ function handle_notice($notice)
+ {
if ($this->is_remote($notice)) {
$this->log(LOG_DEBUG, 'Ignoring remote notice ' . $notice->id);
return true;
@@ -53,10 +56,12 @@ class OmbQueueHandler extends QueueHandler {
}
}
- function finish() {
+ function finish()
+ {
}
- function is_remote($notice) {
+ function is_remote($notice)
+ {
$user = User::staticGet($notice->profile_id);
return is_null($user);
}
diff --git a/scripts/publicqueuehandler.php b/scripts/publicqueuehandler.php
index 2168aade2..b3542e5c5 100755
--- a/scripts/publicqueuehandler.php
+++ b/scripts/publicqueuehandler.php
@@ -35,11 +35,13 @@ set_error_handler('common_error_handler');
class PublicQueueHandler extends XmppQueueHandler {
- function transport() {
+ function transport()
+ {
return 'public';
}
- function handle_notice($notice) {
+ function handle_notice($notice)
+ {
try {
return jabber_public_notice($notice);
} catch (XMPPHP_Exception $e) {
diff --git a/scripts/sitemap.php b/scripts/sitemap.php
index b49bfe2a5..504783e88 100644
--- a/scripts/sitemap.php
+++ b/scripts/sitemap.php
@@ -18,7 +18,8 @@ index_map();
# ------------------------------------------------------------------------------
# Generate index sitemap of all other sitemaps.
-function index_map() {
+function index_map()
+{
global $output_paths;
$output_dir = $output_paths['output_dir'];
$output_url = $output_paths['output_url'];
@@ -40,7 +41,8 @@ function index_map() {
}
# Generate sitemap of standard site elements.
-function standard_map() {
+function standard_map()
+{
global $output_paths;
$standard_map_urls .= url(
@@ -77,7 +79,8 @@ function standard_map() {
}
# Generate sitemaps of all notices.
-function notices_map() {
+function notices_map()
+{
global $output_paths;
$notices = DB_DataObject::factory('notice');
@@ -115,7 +118,8 @@ function notices_map() {
}
# Generate sitemaps of all users.
-function user_map() {
+function user_map()
+{
global $output_paths;
$users = DB_DataObject::factory('user');
@@ -208,7 +212,8 @@ function user_map() {
# ------------------------------------------------------------------------------
# Generate a <url></url> element.
-function url($url_args) {
+function url($url_args)
+{
$url = preg_replace('/&/', '&amp;', $url_args['url']); # escape ampersands for XML
$lastmod = $url_args['lastmod'];
$changefreq = $url_args['changefreq'];
@@ -238,7 +243,8 @@ function url($url_args) {
return $url_out;
}
-function sitemap($sitemap_args) {
+function sitemap($sitemap_args)
+{
$url = preg_replace('/&/', '&amp;', $sitemap_args['url']); # escape ampersands for XML
$lastmod = $sitemap_args['lastmod'];
@@ -259,7 +265,8 @@ function sitemap($sitemap_args) {
}
# Generate a <urlset></urlset> element.
-function urlset($urlset_text) {
+function urlset($urlset_text)
+{
$urlset = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n" .
$urlset_text .
@@ -269,7 +276,8 @@ function urlset($urlset_text) {
}
# Generate a <urlset></urlset> element.
-function sitemapindex($sitemapindex_text) {
+function sitemapindex($sitemapindex_text)
+{
$sitemapindex = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" .
'<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n" .
$sitemapindex_text .
@@ -279,7 +287,8 @@ function sitemapindex($sitemapindex_text) {
}
# Generate a sitemap from an array containing <url></url> elements and write it to a file.
-function array_to_map($url_list, $filename_prefix) {
+function array_to_map($url_list, $filename_prefix)
+{
global $output_paths;
if ($url_list) {
@@ -297,7 +306,8 @@ function array_to_map($url_list, $filename_prefix) {
# ------------------------------------------------------------------------------
# Parse command line arguments.
-function parse_args() {
+function parse_args()
+{
$args = getopt('f:d:u:');
if (is_null($args[f]) && is_null($args[d]) && is_null($args[u])) {
@@ -338,7 +348,8 @@ function parse_args() {
}
# Ensure paths end with a "/".
-function trailing_slash($path) {
+function trailing_slash($path)
+{
if (preg_match('/\/$/', $path) == 0) {
$path .= '/';
}
@@ -347,7 +358,8 @@ function trailing_slash($path) {
}
# Write data to disk.
-function write_file($path, $data) {
+function write_file($path, $data)
+{
if (is_null($path)) {
error('No path specified for writing to.');
} elseif (is_null($data)) {
@@ -364,7 +376,8 @@ function write_file($path, $data) {
}
# Display an error message and exit.
-function error ($error_msg) {
+function error ($error_msg)
+{
if (is_null($error_msg)) {
$error_msg = 'error() was called without any explanation!';
}
diff --git a/scripts/smsqueuehandler.php b/scripts/smsqueuehandler.php
index f8b2e9d53..c962ad095 100755
--- a/scripts/smsqueuehandler.php
+++ b/scripts/smsqueuehandler.php
@@ -35,20 +35,24 @@ set_error_handler('common_error_handler');
class SmsQueueHandler extends QueueHandler {
- function transport() {
+ function transport()
+ {
return 'sms';
}
- function start() {
+ function start()
+ {
$this->log(LOG_INFO, "INITIALIZE");
return true;
}
- function handle_notice($notice) {
+ function handle_notice($notice)
+ {
return mail_broadcast_notice_sms($notice);
}
- function finish() {
+ function finish()
+ {
}
}
diff --git a/scripts/xmppconfirmhandler.php b/scripts/xmppconfirmhandler.php
index 9e177b3fa..b059149bc 100755
--- a/scripts/xmppconfirmhandler.php
+++ b/scripts/xmppconfirmhandler.php
@@ -39,11 +39,13 @@ class XmppConfirmHandler extends XmppQueueHandler {
var $_id = 'confirm';
- function class_name() {
+ function class_name()
+ {
return 'XmppConfirmHandler';
}
- function run() {
+ function run()
+ {
if (!$this->start()) {
return false;
}
@@ -99,7 +101,8 @@ class XmppConfirmHandler extends XmppQueueHandler {
return true;
}
- function next_confirm() {
+ function next_confirm()
+ {
$confirm = new Confirm_address();
$confirm->whereAdd('claimed IS null');
$confirm->whereAdd('sent IS null');
@@ -125,7 +128,8 @@ class XmppConfirmHandler extends XmppQueueHandler {
return null;
}
- function clear_old_confirm_claims() {
+ function clear_old_confirm_claims()
+ {
$confirm = new Confirm();
$confirm->claimed = null;
$confirm->whereAdd('now() - claimed > '.CLAIM_TIMEOUT);
diff --git a/scripts/xmppdaemon.php b/scripts/xmppdaemon.php
index ead842928..28ac64725 100755
--- a/scripts/xmppdaemon.php
+++ b/scripts/xmppdaemon.php
@@ -39,7 +39,8 @@ set_error_handler('common_error_handler');
class XMPPDaemon extends Daemon {
- function XMPPDaemon($resource=null) {
+ function XMPPDaemon($resource=null)
+ {
static $attrs = array('server', 'port', 'user', 'password', 'host');
foreach ($attrs as $attr)
@@ -56,7 +57,8 @@ class XMPPDaemon extends Daemon {
$this->log(LOG_INFO, "INITIALIZE XMPPDaemon {$this->user}@{$this->server}/{$this->resource}");
}
- function connect() {
+ function connect()
+ {
$connect_to = ($this->host) ? $this->host : $this->server;
@@ -75,11 +77,13 @@ class XMPPDaemon extends Daemon {
return !$this->conn->isDisconnected();
}
- function name() {
+ function name()
+ {
return strtolower('xmppdaemon.'.$this->resource);
}
- function run() {
+ function run()
+ {
if ($this->connect()) {
$this->conn->addEventHandler('message', 'handle_message', $this);
@@ -90,17 +94,20 @@ class XMPPDaemon extends Daemon {
}
}
- function handle_reconnect(&$pl) {
+ function handle_reconnect(&$pl)
+ {
$this->conn->processUntil('session_start');
$this->conn->presence('Send me a message to post a notice', 'available', null, 'available', 100);
}
- function get_user($from) {
+ function get_user($from)
+ {
$user = User::staticGet('jabber', jabber_normalize_jid($from));
return $user;
}
- function handle_message(&$pl) {
+ function handle_message(&$pl)
+ {
if ($pl['type'] != 'chat') {
return;
}
@@ -156,11 +163,13 @@ class XMPPDaemon extends Daemon {
unset($user);
}
- function is_self($from) {
+ function is_self($from)
+ {
return preg_match('/^'.strtolower(jabber_daemon_address()).'/', strtolower($from));
}
- function get_ofrom($pl) {
+ function get_ofrom($pl)
+ {
$xml = $pl['xml'];
$addresses = $xml->sub('addresses');
if (!$addresses) {
@@ -194,7 +203,8 @@ class XMPPDaemon extends Daemon {
return $jid;
}
- function is_autoreply($txt) {
+ function is_autoreply($txt)
+ {
if (preg_match('/[\[\(]?[Aa]uto[-\s]?[Rr]e(ply|sponse)[\]\)]/', $txt)) {
return true;
} else {
@@ -202,7 +212,8 @@ class XMPPDaemon extends Daemon {
}
}
- function is_otr($txt) {
+ function is_otr($txt)
+ {
if (preg_match('/^\?OTR/', $txt)) {
return true;
} else {
@@ -210,7 +221,8 @@ class XMPPDaemon extends Daemon {
}
}
- function is_direct($txt) {
+ function is_direct($txt)
+ {
if (strtolower(substr($txt, 0, 2))=='d ') {
return true;
} else {
@@ -218,12 +230,14 @@ class XMPPDaemon extends Daemon {
}
}
- function from_site($address, $msg) {
+ function from_site($address, $msg)
+ {
$text = '['.common_config('site', 'name') . '] ' . $msg;
jabber_send_message($address, $text);
}
- function handle_command($user, $body) {
+ function handle_command($user, $body)
+ {
$inter = new CommandInterpreter();
$cmd = $inter->handle_command($user, $body);
if ($cmd) {
@@ -235,7 +249,8 @@ class XMPPDaemon extends Daemon {
}
}
- function add_notice(&$user, &$pl) {
+ function add_notice(&$user, &$pl)
+ {
$body = trim($pl['body']);
$content_shortened = common_shorten_link($body);
if (mb_strlen($content_shortened) > 140) {
@@ -257,7 +272,8 @@ class XMPPDaemon extends Daemon {
unset($notice);
}
- function handle_presence(&$pl) {
+ function handle_presence(&$pl)
+ {
$from = jabber_normalize_jid($pl['from']);
switch ($pl['type']) {
case 'subscribe':
@@ -291,11 +307,13 @@ class XMPPDaemon extends Daemon {
}
}
- function log($level, $msg) {
+ function log($level, $msg)
+ {
common_log($level, 'XMPPDaemon('.$this->resource.'): '.$msg);
}
- function subscribed($to) {
+ function subscribed($to)
+ {
jabber_special_presence('subscribed', $to);
}
}