diff options
author | Evan Prodromou <evan@prodromou.name> | 2008-12-23 14:19:07 -0500 |
---|---|---|
committer | Evan Prodromou <evan@prodromou.name> | 2008-12-23 14:19:07 -0500 |
commit | edbc0c665cc65875b4d14b79939233b1c9c06bb6 (patch) | |
tree | 4daaacb5bb4c52db9131624b4339bd9a60b205dd /scripts | |
parent | 17ece0777b22b15c60b27b32f0f7e24ecc447661 (diff) |
replace all tabs with four spaces
The PEAR coding standards decree: no tabs, but indent by four spaces.
I've done a global search-and-replace on all tabs, replacing them by
four spaces. This is a huge change, but it will go a long way to
getting us towards phpcs-compliance. And that means better code
readability, and that means more participation.
darcs-hash:20081223191907-84dde-21e8efe210e6d5d54e935a22d0cee5c7bbfc007d.gz
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/enjitqueuehandler.php | 86 | ||||
-rwxr-xr-x | scripts/fixup_hashtags.php | 12 | ||||
-rwxr-xr-x | scripts/fixup_inboxes.php | 58 | ||||
-rwxr-xr-x | scripts/fixup_notices_rendered.php | 20 | ||||
-rwxr-xr-x | scripts/getpiddir.php | 4 | ||||
-rwxr-xr-x | scripts/inbox_users.php | 122 | ||||
-rwxr-xr-x | scripts/jabberqueuehandler.php | 28 | ||||
-rwxr-xr-x | scripts/maildaemon.php | 344 | ||||
-rwxr-xr-x | scripts/ombqueuehandler.php | 52 | ||||
-rwxr-xr-x | scripts/publicqueuehandler.php | 30 | ||||
-rw-r--r-- | scripts/sitemap.php | 538 | ||||
-rwxr-xr-x | scripts/smsqueuehandler.php | 32 | ||||
-rwxr-xr-x | scripts/synctwitterfriends.php | 28 | ||||
-rw-r--r-- | scripts/update_translations.php | 98 | ||||
-rwxr-xr-x | scripts/xmppconfirmhandler.php | 192 | ||||
-rwxr-xr-x | scripts/xmppdaemon.php | 504 |
16 files changed, 1074 insertions, 1074 deletions
diff --git a/scripts/enjitqueuehandler.php b/scripts/enjitqueuehandler.php index 8538ae09a..cfb253753 100755 --- a/scripts/enjitqueuehandler.php +++ b/scripts/enjitqueuehandler.php @@ -20,8 +20,8 @@ # 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(); + print "This script must be run from the command line\n"; + exit(); } define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); @@ -34,20 +34,20 @@ require_once(INSTALLDIR . '/lib/queuehandler.php'); set_error_handler('common_error_handler'); class EnjitQueueHandler extends QueueHandler { - - function transport() { - return 'enjit'; - } + + 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; - } + return true; + } - function handle_notice($notice) { + function handle_notice($notice) { - $profile = Profile::staticGet($notice->profile_id); + $profile = Profile::staticGet($notice->profile_id); $this->log(LOG_INFO, "Posting Notice ".$notice->id." from ".$profile->nickname); @@ -60,25 +60,25 @@ class EnjitQueueHandler extends QueueHandler { # # Build an Atom message from the notice # - $noticeurl = common_local_url('shownotice', array('notice' => $notice->id)); - $msg = $profile->nickname . ': ' . $notice->content; - - $atom = "<entry xmlns='http://www.w3.org/2005/Atom'>\n"; - $atom .= "<apisource>".common_config('enjit','source')."</apisource>\n"; - $atom .= "<source>\n"; - $atom .= "<title>" . $profile->nickname . " - " . common_config('site', 'name') . "</title>\n"; - $atom .= "<link href='" . $profile->profileurl . "'/>\n"; - $atom .= "<link rel='self' type='application/rss+xml' href='" . common_local_url('userrss', array('nickname' => $profile->nickname)) . "'/>\n"; - $atom .= "<author><name>" . $profile->nickname . "</name></author>\n"; - $atom .= "<icon>" . common_profile_avatar_url($profile, AVATAR_PROFILE_SIZE) . "</icon>\n"; - $atom .= "</source>\n"; - $atom .= "<title>" . htmlspecialchars($msg) . "</title>\n"; - $atom .= "<summary>" . htmlspecialchars($msg) . "</summary>\n"; - $atom .= "<link rel='alternate' href='" . $noticeurl . "' />\n"; - $atom .= "<id>". $notice->uri . "</id>\n"; - $atom .= "<published>".common_date_w3dtf($notice->created)."</published>\n"; - $atom .= "<updated>".common_date_w3dtf($notice->modified)."</updated>\n"; - $atom .= "</entry>\n"; + $noticeurl = common_local_url('shownotice', array('notice' => $notice->id)); + $msg = $profile->nickname . ': ' . $notice->content; + + $atom = "<entry xmlns='http://www.w3.org/2005/Atom'>\n"; + $atom .= "<apisource>".common_config('enjit','source')."</apisource>\n"; + $atom .= "<source>\n"; + $atom .= "<title>" . $profile->nickname . " - " . common_config('site', 'name') . "</title>\n"; + $atom .= "<link href='" . $profile->profileurl . "'/>\n"; + $atom .= "<link rel='self' type='application/rss+xml' href='" . common_local_url('userrss', array('nickname' => $profile->nickname)) . "'/>\n"; + $atom .= "<author><name>" . $profile->nickname . "</name></author>\n"; + $atom .= "<icon>" . common_profile_avatar_url($profile, AVATAR_PROFILE_SIZE) . "</icon>\n"; + $atom .= "</source>\n"; + $atom .= "<title>" . htmlspecialchars($msg) . "</title>\n"; + $atom .= "<summary>" . htmlspecialchars($msg) . "</summary>\n"; + $atom .= "<link rel='alternate' href='" . $noticeurl . "' />\n"; + $atom .= "<id>". $notice->uri . "</id>\n"; + $atom .= "<published>".common_date_w3dtf($notice->created)."</published>\n"; + $atom .= "<updated>".common_date_w3dtf($notice->modified)."</updated>\n"; + $atom .= "</entry>\n"; $url = common_config('enjit', 'apiurl') . "/submit/". common_config('enjit','apikey'); $data = "msg=$atom"; @@ -86,32 +86,32 @@ class EnjitQueueHandler extends QueueHandler { # # POST the message to $config['enjit']['apiurl'] # - $ch = curl_init(); + $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 1); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($ch, CURLOPT_POST, 1) ; - curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_POST, 1) ; + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); # SSL and Debugging options # - # curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); - # curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); + # curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); + # curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); # curl_setopt($ch, CURLOPT_VERBOSE, 1); - $result = curl_exec($ch); + $result = curl_exec($ch); - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE ); + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE ); $this->log(LOG_INFO, "Response Code: $code"); - curl_close($ch); + curl_close($ch); return $code; - } - + } + } @@ -122,7 +122,7 @@ $id = ($argc > 1) ? $argv[1] : NULL; $handler = new EnjitQueueHandler($id); if ($handler->start()) { - $handler->handle_queue(); + $handler->handle_queue(); } $handler->finish(); diff --git a/scripts/fixup_hashtags.php b/scripts/fixup_hashtags.php index 88f385798..6f65c78a1 100755 --- a/scripts/fixup_hashtags.php +++ b/scripts/fixup_hashtags.php @@ -37,10 +37,10 @@ $cnt = $notice->find(); while ($notice->fetch()) { common_log(LOG_INFO, 'Getting tags for notice #' . $notice->id); $notice->saveTags(); - $original = clone($notice); - $notice->rendered = common_render_content($notice->content, $notice); - $result = $notice->update($original); - if (!$result) { - common_log_db_error($notice, 'UPDATE', __FILE__); - } + $original = clone($notice); + $notice->rendered = common_render_content($notice->content, $notice); + $result = $notice->update($original); + if (!$result) { + common_log_db_error($notice, 'UPDATE', __FILE__); + } } diff --git a/scripts/fixup_inboxes.php b/scripts/fixup_inboxes.php index 1715b0bc1..e631a80ed 100755 --- a/scripts/fixup_inboxes.php +++ b/scripts/fixup_inboxes.php @@ -41,7 +41,7 @@ common_log(LOG_INFO, 'Updating user inboxes.'); $user = new User(); if ($start_at) { - $user->whereAdd('id >= ' . $start_at); + $user->whereAdd('id >= ' . $start_at); } $cnt = $user->find(); @@ -49,32 +49,32 @@ $cache = common_memcache(); while ($user->fetch()) { common_log(LOG_INFO, 'Updating inbox for user ' . $user->id); - $user->query('BEGIN'); - $inbox = new Notice_inbox(); - $result = $inbox->query('INSERT LOW_PRIORITY INTO notice_inbox (user_id, notice_id, created) ' . - 'SELECT ' . $user->id . ', notice.id, notice.created ' . - 'FROM subscription JOIN notice ON subscription.subscribed = notice.profile_id ' . - 'WHERE subscription.subscriber = ' . $user->id . ' ' . - 'AND notice.created >= subscription.created ' . - 'AND NOT EXISTS (SELECT user_id, notice_id ' . - 'FROM notice_inbox ' . - 'WHERE user_id = ' . $user->id . ' ' . - 'AND notice_id = notice.id)'); - if (is_null($result) || $result === false) { - common_log_db_error($inbox, 'INSERT', __FILE__); - continue; - } - $orig = clone($user); - $user->inboxed = 1; - $result = $user->update($orig); - if (!$result) { - common_log_db_error($user, 'UPDATE', __FILE__); - continue; - } - $user->query('COMMIT'); - $inbox->free(); - unset($inbox); - if ($cache) { - $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id)); - } + $user->query('BEGIN'); + $inbox = new Notice_inbox(); + $result = $inbox->query('INSERT LOW_PRIORITY INTO notice_inbox (user_id, notice_id, created) ' . + 'SELECT ' . $user->id . ', notice.id, notice.created ' . + 'FROM subscription JOIN notice ON subscription.subscribed = notice.profile_id ' . + 'WHERE subscription.subscriber = ' . $user->id . ' ' . + 'AND notice.created >= subscription.created ' . + 'AND NOT EXISTS (SELECT user_id, notice_id ' . + 'FROM notice_inbox ' . + 'WHERE user_id = ' . $user->id . ' ' . + 'AND notice_id = notice.id)'); + if (is_null($result) || $result === false) { + common_log_db_error($inbox, 'INSERT', __FILE__); + continue; + } + $orig = clone($user); + $user->inboxed = 1; + $result = $user->update($orig); + if (!$result) { + common_log_db_error($user, 'UPDATE', __FILE__); + continue; + } + $user->query('COMMIT'); + $inbox->free(); + unset($inbox); + if ($cache) { + $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id)); + } } diff --git a/scripts/fixup_notices_rendered.php b/scripts/fixup_notices_rendered.php index c6c925729..1fa9f394e 100755 --- a/scripts/fixup_notices_rendered.php +++ b/scripts/fixup_notices_rendered.php @@ -20,8 +20,8 @@ # 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(); + print "This script must be run from the command line\n"; + exit(); } define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); @@ -35,16 +35,16 @@ $start_at = ($argc > 1) ? $argv[1] : NULL; $notice = new Notice(); if ($start_at) { - $notice->whereAdd('id >= ' . $start_at); + $notice->whereAdd('id >= ' . $start_at); } $cnt = $notice->find(); while ($notice->fetch()) { - common_log(LOG_INFO, 'Pre-rendering notice #' . $notice->id); - $original = clone($notice); - $notice->rendered = common_render_content($notice->content, $notice); - $result = $notice->update($original); - if (!$result) { - common_log_db_error($notice, 'UPDATE', __FILE__); - } + common_log(LOG_INFO, 'Pre-rendering notice #' . $notice->id); + $original = clone($notice); + $notice->rendered = common_render_content($notice->content, $notice); + $result = $notice->update($original); + if (!$result) { + common_log_db_error($notice, 'UPDATE', __FILE__); + } } diff --git a/scripts/getpiddir.php b/scripts/getpiddir.php index b4dda2254..4f5704249 100755 --- a/scripts/getpiddir.php +++ b/scripts/getpiddir.php @@ -20,8 +20,8 @@ # 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(); + print "This script must be run from the command line\n"; + exit(); } define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); diff --git a/scripts/inbox_users.php b/scripts/inbox_users.php index 0543abb2a..f907e1584 100755 --- a/scripts/inbox_users.php +++ b/scripts/inbox_users.php @@ -42,68 +42,68 @@ common_log(LOG_INFO, 'Updating user inboxes.'); $ids = file($id_file); foreach ($ids as $id) { - - $user = User::staticGet('id', $id); + + $user = User::staticGet('id', $id); - if (!$user) { - common_log(LOG_WARNING, 'No such user: ' . $id); - continue; - } - - if ($user->inboxed) { - common_log(LOG_WARNING, 'Already inboxed: ' . $id); - continue; - } - + if (!$user) { + common_log(LOG_WARNING, 'No such user: ' . $id); + continue; + } + + if ($user->inboxed) { + common_log(LOG_WARNING, 'Already inboxed: ' . $id); + continue; + } + common_log(LOG_INFO, 'Updating inbox for user ' . $user->id); - - $user->query('BEGIN'); - - $old_inbox = new Notice_inbox(); - $old_inbox->user_id = $user->id; - - $result = $old_inbox->delete(); - - if (is_null($result) || $result === false) { - common_log_db_error($old_inbox, 'DELETE', __FILE__); - continue; - } + + $user->query('BEGIN'); + + $old_inbox = new Notice_inbox(); + $old_inbox->user_id = $user->id; + + $result = $old_inbox->delete(); + + if (is_null($result) || $result === false) { + common_log_db_error($old_inbox, 'DELETE', __FILE__); + continue; + } - $old_inbox->free(); - - $inbox = new Notice_inbox(); - - $result = $inbox->query('INSERT INTO notice_inbox (user_id, notice_id, created) ' . - 'SELECT ' . $user->id . ', notice.id, notice.created ' . - 'FROM subscription JOIN notice ON subscription.subscribed = notice.profile_id ' . - 'WHERE subscription.subscriber = ' . $user->id . ' ' . - 'AND notice.created >= subscription.created ' . - 'AND now() - notice.created < ' . (7 * 24 * 3600) . ' ' . - 'AND NOT EXISTS (SELECT user_id, notice_id ' . - 'FROM notice_inbox ' . - 'WHERE user_id = ' . $user->id . ' ' . - 'AND notice_id = notice.id)'); - - if (is_null($result) || $result === false) { - common_log_db_error($inbox, 'INSERT', __FILE__); - continue; - } - - $orig = clone($user); - $user->inboxed = 1; - $result = $user->update($orig); - - if (!$result) { - common_log_db_error($user, 'UPDATE', __FILE__); - continue; - } - - $user->query('COMMIT'); - - $inbox->free(); - unset($inbox); - - if ($cache) { - $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id)); - } + $old_inbox->free(); + + $inbox = new Notice_inbox(); + + $result = $inbox->query('INSERT INTO notice_inbox (user_id, notice_id, created) ' . + 'SELECT ' . $user->id . ', notice.id, notice.created ' . + 'FROM subscription JOIN notice ON subscription.subscribed = notice.profile_id ' . + 'WHERE subscription.subscriber = ' . $user->id . ' ' . + 'AND notice.created >= subscription.created ' . + 'AND now() - notice.created < ' . (7 * 24 * 3600) . ' ' . + 'AND NOT EXISTS (SELECT user_id, notice_id ' . + 'FROM notice_inbox ' . + 'WHERE user_id = ' . $user->id . ' ' . + 'AND notice_id = notice.id)'); + + if (is_null($result) || $result === false) { + common_log_db_error($inbox, 'INSERT', __FILE__); + continue; + } + + $orig = clone($user); + $user->inboxed = 1; + $result = $user->update($orig); + + if (!$result) { + common_log_db_error($user, 'UPDATE', __FILE__); + continue; + } + + $user->query('COMMIT'); + + $inbox->free(); + unset($inbox); + + if ($cache) { + $cache->delete(common_cache_key('user:notices_with_friends:' . $user->id)); + } } diff --git a/scripts/jabberqueuehandler.php b/scripts/jabberqueuehandler.php index 59cdb94ad..8e33cfaf0 100755 --- a/scripts/jabberqueuehandler.php +++ b/scripts/jabberqueuehandler.php @@ -20,8 +20,8 @@ # 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(); + print "This script must be run from the command line\n"; + exit(); } define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); @@ -35,20 +35,20 @@ set_error_handler('common_error_handler'); class JabberQueueHandler extends XmppQueueHandler { - var $conn = NULL; + var $conn = NULL; - function transport() { - return 'jabber'; - } + function transport() { + return 'jabber'; + } - function handle_notice($notice) { - try { - return jabber_broadcast_notice($notice); - } catch (XMPPHP_Exception $e) { - $this->log(LOG_ERR, "Got an XMPPHP_Exception: " . $e->getMessage()); - exit(1); - } - } + function handle_notice($notice) { + try { + return jabber_broadcast_notice($notice); + } catch (XMPPHP_Exception $e) { + $this->log(LOG_ERR, "Got an XMPPHP_Exception: " . $e->getMessage()); + exit(1); + } + } } ini_set("max_execution_time", "0"); diff --git a/scripts/maildaemon.php b/scripts/maildaemon.php index 8b809f646..6d8507514 100755 --- a/scripts/maildaemon.php +++ b/scripts/maildaemon.php @@ -20,8 +20,8 @@ # 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(); + print "This script must be run from the command line\n"; + exit(); } define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); @@ -36,179 +36,179 @@ require_once('Mail/mimeDecode.php'); class MailerDaemon { - function __construct() { - } - - 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.')); - } - common_log(LOG_INFO, "Mail from $from to $to: " .substr($msg, 0, 20)); - $user = $this->user_from($from); - if (!$user) { - $this->error($from, _('Not a registered user.')); - return false; - } - if (!$this->user_match_to($user, $to)) { - $this->error($from, _('Sorry, that is not your incoming email address.')); - return false; - } - if (!$user->emailpost) { - $this->error($from, _('Sorry, no incoming email allowed.')); - return false; - } - $response = $this->handle_command($user, $from, $msg); - if ($response) { - return true; - } - $msg = $this->cleanup_msg($msg); - $this->add_notice($user, $msg); - } - - function error($from, $msg) { - file_put_contents("php://stderr", $msg . "\n"); - exit(1); - } - - function user_from($from_hdr) { - $froms = mailparse_rfc822_parse_addresses($from_hdr); - if (!$froms) { - return NULL; - } - $from = $froms[0]; - $addr = common_canonical_email($from['address']); - $user = User::staticGet('email', $addr); - if (!$user) { - $user = User::staticGet('smsemail', $addr); - } - return $user; - } - - function user_match_to($user, $to_hdr) { - $incoming = $user->incomingemail; - $tos = mailparse_rfc822_parse_addresses($to_hdr); - foreach ($tos as $to) { - if (strcasecmp($incoming, $to['address']) == 0) { - return true; - } - } - return false; - } - - function handle_command($user, $from, $msg) { - $inter = new CommandInterpreter(); - $cmd = $inter->handle_command($user, $msg); - if ($cmd) { - $cmd->execute(new MailChannel($from)); - return true; - } - return false; - } - - function respond($from, $to, $response) { - - $headers['From'] = $to; - $headers['To'] = $from; - $headers['Subject'] = "Command complete"; - - return mail_send(array($from), $headers, $response); - } - - function log($level, $msg) { - common_log($level, 'MailDaemon: '.$msg); - } - - function add_notice($user, $msg) { + function __construct() { + } + + 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.')); + } + common_log(LOG_INFO, "Mail from $from to $to: " .substr($msg, 0, 20)); + $user = $this->user_from($from); + if (!$user) { + $this->error($from, _('Not a registered user.')); + return false; + } + if (!$this->user_match_to($user, $to)) { + $this->error($from, _('Sorry, that is not your incoming email address.')); + return false; + } + if (!$user->emailpost) { + $this->error($from, _('Sorry, no incoming email allowed.')); + return false; + } + $response = $this->handle_command($user, $from, $msg); + if ($response) { + return true; + } + $msg = $this->cleanup_msg($msg); + $this->add_notice($user, $msg); + } + + function error($from, $msg) { + file_put_contents("php://stderr", $msg . "\n"); + exit(1); + } + + function user_from($from_hdr) { + $froms = mailparse_rfc822_parse_addresses($from_hdr); + if (!$froms) { + return NULL; + } + $from = $froms[0]; + $addr = common_canonical_email($from['address']); + $user = User::staticGet('email', $addr); + if (!$user) { + $user = User::staticGet('smsemail', $addr); + } + return $user; + } + + function user_match_to($user, $to_hdr) { + $incoming = $user->incomingemail; + $tos = mailparse_rfc822_parse_addresses($to_hdr); + foreach ($tos as $to) { + if (strcasecmp($incoming, $to['address']) == 0) { + return true; + } + } + return false; + } + + function handle_command($user, $from, $msg) { + $inter = new CommandInterpreter(); + $cmd = $inter->handle_command($user, $msg); + if ($cmd) { + $cmd->execute(new MailChannel($from)); + return true; + } + return false; + } + + function respond($from, $to, $response) { + + $headers['From'] = $to; + $headers['To'] = $from; + $headers['Subject'] = "Command complete"; + + return mail_send(array($from), $headers, $response); + } + + function log($level, $msg) { + common_log($level, 'MailDaemon: '.$msg); + } + + function add_notice($user, $msg) { // should test // $msg_shortened = common_shorten_links($msg); // if (mb_strlen($msg_shortened) > 140) ERROR and STOP - $notice = Notice::saveNew($user->id, $msg, 'mail'); - if (is_string($notice)) { - $this->log(LOG_ERR, $notice); - return; - } - common_broadcast_notice($notice); - $this->log(LOG_INFO, - 'Added notice ' . $notice->id . ' from user ' . $user->nickname); - } - - function parse_message($fname) { - $contents = file_get_contents($fname); - $parsed = Mail_mimeDecode::decode(array('input' => $contents, - 'include_bodies' => true, - 'decode_headers' => true, - 'decode_bodies' => true)); - if (!$parsed) { - return NULL; - } - - $from = $parsed->headers['from']; - - $to = $parsed->headers['to']; - - $type = $parsed->ctype_primary . '/' . $parsed->ctype_secondary; - - if ($parsed->ctype_primary == 'multipart') { - foreach ($parsed->parts as $part) { - if ($part->ctype_primary == 'text' && - $part->ctype_secondary == 'plain') { - $msg = $part->body; - break; - } - } - } else if ($type == 'text/plain') { - $msg = $parsed->body; - } else { - $this->unsupported_type($type); - } - - return array($from, $to, $msg); - } - - function unsupported_type($type) { - $this->error(NULL, "Unsupported message type: " . $type); - } - - function cleanup_msg($msg) { - $lines = explode("\n", $msg); - - $output = ''; - - foreach ($lines as $line) { - // skip quotes - if (preg_match('/^\s*>.*$/', $line)) { - continue; - } - // skip start of quote - if (preg_match('/^\s*On.*wrote:\s*$/', $line)) { - continue; - } - // probably interesting to someone, not us - if (preg_match('/^\s*Sent via/', $line)) { - continue; - } - // skip everything after a sig - if (preg_match('/^\s*--+\s*$/', $line) || - preg_match('/^\s*__+\s*$/', $line)) - { - break; - } - // skip everything after Outlook quote - if (preg_match('/^\s*-+\s*Original Message\s*-+\s*$/', $line)) { - break; - } - // skip everything after weird forward - if (preg_match('/^\s*Begin\s+forward/', $line)) { - break; - } - - $output .= ' ' . $line; - } - - preg_replace('/\s+/', ' ', $output); - return trim($output); - } + $notice = Notice::saveNew($user->id, $msg, 'mail'); + if (is_string($notice)) { + $this->log(LOG_ERR, $notice); + return; + } + common_broadcast_notice($notice); + $this->log(LOG_INFO, + 'Added notice ' . $notice->id . ' from user ' . $user->nickname); + } + + function parse_message($fname) { + $contents = file_get_contents($fname); + $parsed = Mail_mimeDecode::decode(array('input' => $contents, + 'include_bodies' => true, + 'decode_headers' => true, + 'decode_bodies' => true)); + if (!$parsed) { + return NULL; + } + + $from = $parsed->headers['from']; + + $to = $parsed->headers['to']; + + $type = $parsed->ctype_primary . '/' . $parsed->ctype_secondary; + + if ($parsed->ctype_primary == 'multipart') { + foreach ($parsed->parts as $part) { + if ($part->ctype_primary == 'text' && + $part->ctype_secondary == 'plain') { + $msg = $part->body; + break; + } + } + } else if ($type == 'text/plain') { + $msg = $parsed->body; + } else { + $this->unsupported_type($type); + } + + return array($from, $to, $msg); + } + + function unsupported_type($type) { + $this->error(NULL, "Unsupported message type: " . $type); + } + + function cleanup_msg($msg) { + $lines = explode("\n", $msg); + + $output = ''; + + foreach ($lines as $line) { + // skip quotes + if (preg_match('/^\s*>.*$/', $line)) { + continue; + } + // skip start of quote + if (preg_match('/^\s*On.*wrote:\s*$/', $line)) { + continue; + } + // probably interesting to someone, not us + if (preg_match('/^\s*Sent via/', $line)) { + continue; + } + // skip everything after a sig + if (preg_match('/^\s*--+\s*$/', $line) || + preg_match('/^\s*__+\s*$/', $line)) + { + break; + } + // skip everything after Outlook quote + if (preg_match('/^\s*-+\s*Original Message\s*-+\s*$/', $line)) { + break; + } + // skip everything after weird forward + if (preg_match('/^\s*Begin\s+forward/', $line)) { + break; + } + + $output .= ' ' . $line; + } + + preg_replace('/\s+/', ' ', $output); + return trim($output); + } } $md = new MailerDaemon(); diff --git a/scripts/ombqueuehandler.php b/scripts/ombqueuehandler.php index 1df816d14..31ae20f00 100755 --- a/scripts/ombqueuehandler.php +++ b/scripts/ombqueuehandler.php @@ -20,8 +20,8 @@ # 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(); + print "This script must be run from the command line\n"; + exit(); } define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); @@ -34,32 +34,32 @@ require_once(INSTALLDIR . '/lib/queuehandler.php'); set_error_handler('common_error_handler'); class OmbQueueHandler extends QueueHandler { - - function transport() { - return 'omb'; - } - - function start() { - $this->log(LOG_INFO, "INITIALIZE"); - return true; - } + + function transport() { + return 'omb'; + } + + function start() { + $this->log(LOG_INFO, "INITIALIZE"); + return true; + } - function handle_notice($notice) { - if ($this->is_remote($notice)) { - $this->log(LOG_DEBUG, 'Ignoring remote notice ' . $notice->id); - return true; - } else { - return omb_broadcast_remote_subscribers($notice); - } - } - - function finish() { - } + function handle_notice($notice) { + if ($this->is_remote($notice)) { + $this->log(LOG_DEBUG, 'Ignoring remote notice ' . $notice->id); + return true; + } else { + return omb_broadcast_remote_subscribers($notice); + } + } + + function finish() { + } - function is_remote($notice) { - $user = User::staticGet($notice->profile_id); - return is_null($user); - } + function is_remote($notice) { + $user = User::staticGet($notice->profile_id); + return is_null($user); + } } ini_set("max_execution_time", "0"); diff --git a/scripts/publicqueuehandler.php b/scripts/publicqueuehandler.php index b1ae1d581..2168aade2 100755 --- a/scripts/publicqueuehandler.php +++ b/scripts/publicqueuehandler.php @@ -20,8 +20,8 @@ # 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(); + print "This script must be run from the command line\n"; + exit(); } define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); @@ -34,19 +34,19 @@ require_once(INSTALLDIR . '/lib/xmppqueuehandler.php'); set_error_handler('common_error_handler'); class PublicQueueHandler extends XmppQueueHandler { - - function transport() { - return 'public'; - } - - function handle_notice($notice) { - try { - return jabber_public_notice($notice); - } catch (XMPPHP_Exception $e) { - $this->log(LOG_ERR, "Got an XMPPHP_Exception: " . $e->getMessage()); - die($e->getMessage()); - } - } + + function transport() { + return 'public'; + } + + function handle_notice($notice) { + try { + return jabber_public_notice($notice); + } catch (XMPPHP_Exception $e) { + $this->log(LOG_ERR, "Got an XMPPHP_Exception: " . $e->getMessage()); + die($e->getMessage()); + } + } } ini_set("max_execution_time", "0"); diff --git a/scripts/sitemap.php b/scripts/sitemap.php index 6b845beae..b49bfe2a5 100644 --- a/scripts/sitemap.php +++ b/scripts/sitemap.php @@ -19,188 +19,188 @@ index_map(); # Generate index sitemap of all other sitemaps. function index_map() { - global $output_paths; - $output_dir = $output_paths['output_dir']; - $output_url = $output_paths['output_url']; + global $output_paths; + $output_dir = $output_paths['output_dir']; + $output_url = $output_paths['output_url']; - foreach (glob("$output_dir*.xml") as $file_name) { + foreach (glob("$output_dir*.xml") as $file_name) { - # Just the file name please. - $file_name = preg_replace("|$output_dir|", '', $file_name); + # Just the file name please. + $file_name = preg_replace("|$output_dir|", '', $file_name); - $index_urls .= sitemap( - array( - 'url' => $output_url . $file_name, - 'changefreq' => 'daily' - ) - ); - } + $index_urls .= sitemap( + array( + 'url' => $output_url . $file_name, + 'changefreq' => 'daily' + ) + ); + } - write_file($output_paths['index_file'], sitemapindex($index_urls)); + write_file($output_paths['index_file'], sitemapindex($index_urls)); } # Generate sitemap of standard site elements. function standard_map() { - global $output_paths; - - $standard_map_urls .= url( - array( - 'url' => common_local_url('public'), - 'changefreq' => 'daily', - 'priority' => '1', - ) - ); - - $standard_map_urls .= url( - array( - 'url' => common_local_url('publicrss'), - 'changefreq' => 'daily', - 'priority' => '0.3', - ) - ); - - $docs = array('about', 'faq', 'contact', 'im', 'openid', 'openmublog', 'privacy', 'source'); - - foreach($docs as $title) { - $standard_map_urls .= url( - array( - 'url' => common_local_url('doc', array('title' => $title)), - 'changefreq' => 'monthly', - 'priority' => '0.2', - ) - ); - } - - $urlset_path = $output_paths['output_dir'] . 'standard.xml'; - - write_file($urlset_path, urlset($standard_map_urls)); + global $output_paths; + + $standard_map_urls .= url( + array( + 'url' => common_local_url('public'), + 'changefreq' => 'daily', + 'priority' => '1', + ) + ); + + $standard_map_urls .= url( + array( + 'url' => common_local_url('publicrss'), + 'changefreq' => 'daily', + 'priority' => '0.3', + ) + ); + + $docs = array('about', 'faq', 'contact', 'im', 'openid', 'openmublog', 'privacy', 'source'); + + foreach($docs as $title) { + $standard_map_urls .= url( + array( + 'url' => common_local_url('doc', array('title' => $title)), + 'changefreq' => 'monthly', + 'priority' => '0.2', + ) + ); + } + + $urlset_path = $output_paths['output_dir'] . 'standard.xml'; + + write_file($urlset_path, urlset($standard_map_urls)); } # Generate sitemaps of all notices. function notices_map() { - global $output_paths; + global $output_paths; - $notices = DB_DataObject::factory('notice'); + $notices = DB_DataObject::factory('notice'); - $notices->query('SELECT id, uri, url, modified FROM notice where is_local = 1'); + $notices->query('SELECT id, uri, url, modified FROM notice where is_local = 1'); - $notice_count = 0; - $map_count = 1; + $notice_count = 0; + $map_count = 1; - while ($notices->fetch()) { + while ($notices->fetch()) { - # Maximum 50,000 URLs per sitemap file. - if ($notice_count == 50000) { - $notice_count = 0; - $map_count++; - } + # Maximum 50,000 URLs per sitemap file. + if ($notice_count == 50000) { + $notice_count = 0; + $map_count++; + } - # remote notices have an URL - - if (!$notices->url && $notices->uri) { - $notice = array( - 'url' => ($notices->uri) ? $notices->uri : common_local_url('shownotice', array('notice' => $notices->id)), - 'lastmod' => common_date_w3dtf($notices->modified), - 'changefreq' => 'never', - 'priority' => '1', - ); + # remote notices have an URL + + if (!$notices->url && $notices->uri) { + $notice = array( + 'url' => ($notices->uri) ? $notices->uri : common_local_url('shownotice', array('notice' => $notices->id)), + 'lastmod' => common_date_w3dtf($notices->modified), + 'changefreq' => 'never', + 'priority' => '1', + ); - $notice_list[$map_count] .= url($notice); - $notice_count++; - } - } + $notice_list[$map_count] .= url($notice); + $notice_count++; + } + } - # Make full sitemaps from the lists and save them. - array_to_map($notice_list, 'notice'); + # Make full sitemaps from the lists and save them. + array_to_map($notice_list, 'notice'); } # Generate sitemaps of all users. function user_map() { - global $output_paths; - - $users = DB_DataObject::factory('user'); - - $users->query('SELECT id, nickname FROM user'); - - $user_count = 0; - $map_count = 1; - - while ($users->fetch()) { - - # Maximum 50,000 URLs per sitemap file. - if ($user_count == 50000) { - $user_count = 0; - $map_count++; - } - - $user_args = array('nickname' => $users->nickname); - - # Define parameters for generating <url></url> elements. - $user = array( - 'url' => common_local_url('showstream', $user_args), - 'changefreq' => 'daily', - 'priority' => '1', - ); - - $user_rss = array( - 'url' => common_local_url('userrss', $user_args), - 'changefreq' => 'daily', - 'priority' => '0.3', - ); - - $all = array( - 'url' => common_local_url('all', $user_args), - 'changefreq' => 'daily', - 'priority' => '1', - ); - - $all_rss = array( - 'url' => common_local_url('allrss', $user_args), - 'changefreq' => 'daily', - 'priority' => '0.3', - ); - - $replies = array( - 'url' => common_local_url('replies', $user_args), - 'changefreq' => 'daily', - 'priority' => '1', - ); - - $replies_rss = array( - 'url' => common_local_url('repliesrss', $user_args), - 'changefreq' => 'daily', - 'priority' => '0.3', - ); - - $foaf = array( - 'url' => common_local_url('foaf', $user_args), - 'changefreq' => 'weekly', - 'priority' => '0.5', - ); - - # Construct a <url></url> element for each user facet and add it - # to our existing list of those. - $user_list[$map_count] .= url($user); - $user_rss_list[$map_count] .= url($user_rss); - $all_list[$map_count] .= url($all); - $all_rss_list[$map_count] .= url($all_rss); - $replies_list[$map_count] .= url($replies); - $replies_rss_list[$map_count] .= url($replies_rss); - $foaf_list[$map_count] .= url($foaf); - - $user_count++; - } - - # Make full sitemaps from the lists and save them. - # Possible factoring: put all the lists into a master array, thus allowing - # calling with single argument (i.e., array_to_map('user')). - array_to_map($user_list, 'user'); - array_to_map($user_rss_list, 'user_rss'); - array_to_map($all_list, 'all'); - array_to_map($all_rss_list, 'all_rss'); - array_to_map($replies_list, 'replies'); - array_to_map($replies_rss_list, 'replies_rss'); - array_to_map($foaf_list, 'foaf'); + global $output_paths; + + $users = DB_DataObject::factory('user'); + + $users->query('SELECT id, nickname FROM user'); + + $user_count = 0; + $map_count = 1; + + while ($users->fetch()) { + + # Maximum 50,000 URLs per sitemap file. + if ($user_count == 50000) { + $user_count = 0; + $map_count++; + } + + $user_args = array('nickname' => $users->nickname); + + # Define parameters for generating <url></url> elements. + $user = array( + 'url' => common_local_url('showstream', $user_args), + 'changefreq' => 'daily', + 'priority' => '1', + ); + + $user_rss = array( + 'url' => common_local_url('userrss', $user_args), + 'changefreq' => 'daily', + 'priority' => '0.3', + ); + + $all = array( + 'url' => common_local_url('all', $user_args), + 'changefreq' => 'daily', + 'priority' => '1', + ); + + $all_rss = array( + 'url' => common_local_url('allrss', $user_args), + 'changefreq' => 'daily', + 'priority' => '0.3', + ); + + $replies = array( + 'url' => common_local_url('replies', $user_args), + 'changefreq' => 'daily', + 'priority' => '1', + ); + + $replies_rss = array( + 'url' => common_local_url('repliesrss', $user_args), + 'changefreq' => 'daily', + 'priority' => '0.3', + ); + + $foaf = array( + 'url' => common_local_url('foaf', $user_args), + 'changefreq' => 'weekly', + 'priority' => '0.5', + ); + + # Construct a <url></url> element for each user facet and add it + # to our existing list of those. + $user_list[$map_count] .= url($user); + $user_rss_list[$map_count] .= url($user_rss); + $all_list[$map_count] .= url($all); + $all_rss_list[$map_count] .= url($all_rss); + $replies_list[$map_count] .= url($replies); + $replies_rss_list[$map_count] .= url($replies_rss); + $foaf_list[$map_count] .= url($foaf); + + $user_count++; + } + + # Make full sitemaps from the lists and save them. + # Possible factoring: put all the lists into a master array, thus allowing + # calling with single argument (i.e., array_to_map('user')). + array_to_map($user_list, 'user'); + array_to_map($user_rss_list, 'user_rss'); + array_to_map($all_list, 'all'); + array_to_map($all_rss_list, 'all_rss'); + array_to_map($replies_list, 'replies'); + array_to_map($replies_rss_list, 'replies_rss'); + array_to_map($foaf_list, 'foaf'); } # ------------------------------------------------------------------------------ @@ -209,87 +209,87 @@ function user_map() { # Generate a <url></url> element. function url($url_args) { - $url = preg_replace('/&/', '&', $url_args['url']); # escape ampersands for XML - $lastmod = $url_args['lastmod']; - $changefreq = $url_args['changefreq']; - $priority = $url_args['priority']; + $url = preg_replace('/&/', '&', $url_args['url']); # escape ampersands for XML + $lastmod = $url_args['lastmod']; + $changefreq = $url_args['changefreq']; + $priority = $url_args['priority']; - if (is_null($url)) { - error("url() arguments require 'url' value."); - } + if (is_null($url)) { + error("url() arguments require 'url' value."); + } - $url_out = "\t<url>\n"; - $url_out .= "\t\t<loc>$url</loc>\n"; + $url_out = "\t<url>\n"; + $url_out .= "\t\t<loc>$url</loc>\n"; - if ($changefreq) { - $url_out .= "\t\t<changefreq>$changefreq</changefreq>\n"; - } + if ($changefreq) { + $url_out .= "\t\t<changefreq>$changefreq</changefreq>\n"; + } - if ($lastmod) { - $url_out .= "\t\t<lastmod>$lastmod</lastmod>\n"; - } + if ($lastmod) { + $url_out .= "\t\t<lastmod>$lastmod</lastmod>\n"; + } - if ($priority) { - $url_out .= "\t\t<priority>$priority</priority>\n"; - } + if ($priority) { + $url_out .= "\t\t<priority>$priority</priority>\n"; + } - $url_out .= "\t</url>\n"; + $url_out .= "\t</url>\n"; - return $url_out; + return $url_out; } function sitemap($sitemap_args) { - $url = preg_replace('/&/', '&', $sitemap_args['url']); # escape ampersands for XML - $lastmod = $sitemap_args['lastmod']; + $url = preg_replace('/&/', '&', $sitemap_args['url']); # escape ampersands for XML + $lastmod = $sitemap_args['lastmod']; - if (is_null($url)) { - error("url() arguments require 'url' value."); - } + if (is_null($url)) { + error("url() arguments require 'url' value."); + } - $sitemap_out = "\t<sitemap>\n"; - $sitemap_out .= "\t\t<loc>$url</loc>\n"; + $sitemap_out = "\t<sitemap>\n"; + $sitemap_out .= "\t\t<loc>$url</loc>\n"; - if ($lastmod) { - $sitemap_out .= "\t\t<lastmod>$lastmod</lastmod>\n"; - } + if ($lastmod) { + $sitemap_out .= "\t\t<lastmod>$lastmod</lastmod>\n"; + } - $sitemap_out .= "\t</sitemap>\n"; + $sitemap_out .= "\t</sitemap>\n"; - return $sitemap_out; + return $sitemap_out; } # Generate a <urlset></urlset> element. 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 . - '</urlset>'; + $urlset = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . + '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n" . + $urlset_text . + '</urlset>'; - return $urlset; + return $urlset; } # Generate a <urlset></urlset> element. 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 . - '</sitemapindex>'; + $sitemapindex = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . + '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . "\n" . + $sitemapindex_text . + '</sitemapindex>'; - return $sitemapindex; + return $sitemapindex; } # Generate a sitemap from an array containing <url></url> elements and write it to a file. function array_to_map($url_list, $filename_prefix) { - global $output_paths; - - if ($url_list) { - # $map_urls is a long string containing concatenated <url></url> elements. - while (list($map_idx, $map_urls) = each($url_list)) { - $urlset_path = $output_paths['output_dir'] . "$filename_prefix-$map_idx.xml"; - - write_file($urlset_path, urlset($map_urls)); - } - } + global $output_paths; + + if ($url_list) { + # $map_urls is a long string containing concatenated <url></url> elements. + while (list($map_idx, $map_urls) = each($url_list)) { + $urlset_path = $output_paths['output_dir'] . "$filename_prefix-$map_idx.xml"; + + write_file($urlset_path, urlset($map_urls)); + } + } } # ------------------------------------------------------------------------------ @@ -298,79 +298,79 @@ function array_to_map($url_list, $filename_prefix) { # Parse command line arguments. function parse_args() { - $args = getopt('f:d:u:'); - - if (is_null($args[f]) && is_null($args[d]) && is_null($args[u])) { - error('Mandatory arguments: -f <index file path> -d <output directory path> -u <URL of sitemaps directory>'); - } - - if (is_null($args[f])) { - error('You must specify an index file name with the -f option.'); - } - - if (is_null($args[d])) { - error('You must specify a directory for the output file with the -d option.'); - } - - if (is_null($args[u])) { - error('You must specify a URL for the directory where the sitemaps will be kept with the -u option.'); - } - - $index_file = $args[f]; - $output_dir = $args[d]; - $output_url = $args[u]; - - if (file_exists($output_dir)) { - if (is_writable($output_dir) === FALSE) { - error("$output_dir is not writable."); - } - } else { - error("output directory $output_dir does not exist."); - } - - $paths = array( - 'index_file' => $index_file, - 'output_dir' => trailing_slash($output_dir), - 'output_url' => trailing_slash($output_url), - ); - - return $paths; + $args = getopt('f:d:u:'); + + if (is_null($args[f]) && is_null($args[d]) && is_null($args[u])) { + error('Mandatory arguments: -f <index file path> -d <output directory path> -u <URL of sitemaps directory>'); + } + + if (is_null($args[f])) { + error('You must specify an index file name with the -f option.'); + } + + if (is_null($args[d])) { + error('You must specify a directory for the output file with the -d option.'); + } + + if (is_null($args[u])) { + error('You must specify a URL for the directory where the sitemaps will be kept with the -u option.'); + } + + $index_file = $args[f]; + $output_dir = $args[d]; + $output_url = $args[u]; + + if (file_exists($output_dir)) { + if (is_writable($output_dir) === FALSE) { + error("$output_dir is not writable."); + } + } else { + error("output directory $output_dir does not exist."); + } + + $paths = array( + 'index_file' => $index_file, + 'output_dir' => trailing_slash($output_dir), + 'output_url' => trailing_slash($output_url), + ); + + return $paths; } # Ensure paths end with a "/". function trailing_slash($path) { - if (preg_match('/\/$/', $path) == 0) { - $path .= '/'; - } + if (preg_match('/\/$/', $path) == 0) { + $path .= '/'; + } - return $path; + return $path; } # Write data to disk. function write_file($path, $data) { - if (is_null($path)) { - error('No path specified for writing to.'); - } elseif (is_null($data)) { - error('No data specified for writing.'); - } - - if (($fh_out = fopen($path,'w')) === FALSE) { - error("couldn't open $path for writing."); - } - - if (fwrite($fh_out, $data) === FALSE) { - error("couldn't write to $path."); - } + if (is_null($path)) { + error('No path specified for writing to.'); + } elseif (is_null($data)) { + error('No data specified for writing.'); + } + + if (($fh_out = fopen($path,'w')) === FALSE) { + error("couldn't open $path for writing."); + } + + if (fwrite($fh_out, $data) === FALSE) { + error("couldn't write to $path."); + } } # Display an error message and exit. function error ($error_msg) { - if (is_null($error_msg)) { - $error_msg = 'error() was called without any explanation!'; - } + if (is_null($error_msg)) { + $error_msg = 'error() was called without any explanation!'; + } - echo "Error: $error_msg\n"; - exit(1); + echo "Error: $error_msg\n"; + exit(1); } ?>
\ No newline at end of file diff --git a/scripts/smsqueuehandler.php b/scripts/smsqueuehandler.php index 8f0d02d9b..f17429d96 100755 --- a/scripts/smsqueuehandler.php +++ b/scripts/smsqueuehandler.php @@ -20,8 +20,8 @@ # 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(); + print "This script must be run from the command line\n"; + exit(); } define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); @@ -34,22 +34,22 @@ require_once(INSTALLDIR . '/lib/queuehandler.php'); set_error_handler('common_error_handler'); class SmsQueueHandler extends QueueHandler { - - function transport() { - return 'sms'; - } + + function transport() { + return 'sms'; + } - function start() { - $this->log(LOG_INFO, "INITIALIZE"); - return true; - } + function start() { + $this->log(LOG_INFO, "INITIALIZE"); + return true; + } - function handle_notice($notice) { - return mail_broadcast_notice_sms($notice); - } - - function finish() { - } + function handle_notice($notice) { + return mail_broadcast_notice_sms($notice); + } + + function finish() { + } } ini_set("max_execution_time", "0"); diff --git a/scripts/synctwitterfriends.php b/scripts/synctwitterfriends.php index 070eb9bbb..0ce34c2ae 100755 --- a/scripts/synctwitterfriends.php +++ b/scripts/synctwitterfriends.php @@ -11,17 +11,17 @@ * * 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 + * 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/>. + * 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(); + print "This script must be run from the command line\n"; + exit(); } define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); @@ -35,21 +35,21 @@ $flink->find(); while ($flink->fetch()) { - if (($flink->friendsync & FOREIGN_FRIEND_RECV) == FOREIGN_FRIEND_RECV) { + if (($flink->friendsync & FOREIGN_FRIEND_RECV) == FOREIGN_FRIEND_RECV) { - $user = User::staticGet($flink->user_id); + $user = User::staticGet($flink->user_id); - print "Updating Twitter friends for user $user->nickname ($user->id)\n"; + print "Updating Twitter friends for user $user->nickname ($user->id)\n"; - $fuser = $flink->getForeignUser(); + $fuser = $flink->getForeignUser(); - $result = save_twitter_friends($user, $fuser->id, $fuser->nickname, $flink->credentials); + $result = save_twitter_friends($user, $fuser->id, $fuser->nickname, $flink->credentials); - if ($result == false) { - print "Problems updating Twitter friends! Check the log.\n"; - exit(1); - } - } + if ($result == false) { + print "Problems updating Twitter friends! Check the log.\n"; + exit(1); + } + } } diff --git a/scripts/update_translations.php b/scripts/update_translations.php index 3eb7b3401..8ad07ccca 100644 --- a/scripts/update_translations.php +++ b/scripts/update_translations.php @@ -5,62 +5,62 @@ chdir(dirname(__FILE__) . '/..'); /* Languages to pull */ $languages = array( - 'da_DK' => 'http://laconi.ca/translate/download.php?file_id=23', - 'nl_NL' => 'http://laconi.ca/translate/download.php?file_id=39', - 'en_NZ' => 'http://laconi.ca/translate/download.php?file_id=15', - 'eo' => 'http://laconi.ca/translate/download.php?file_id=10', - 'fr_FR' => 'http://laconi.ca/translate/download.php?file_id=19', - 'de_DE' => 'http://laconi.ca/translate/download.php?file_id=18', - 'it_IT' => 'http://laconi.ca/translate/download.php?file_id=21', - 'ko' => 'http://laconi.ca/translate/download.php?file_id=33', - 'no_NB' => 'http://laconi.ca/translate/download.php?file_id=31', - 'pt' => 'http://laconi.ca/translate/download.php?file_id=8', - 'pt_BR' => 'http://laconi.ca/translate/download.php?file_id=72', - 'ru_RU' => 'http://laconi.ca/translate/download.php?file_id=26', - 'es' => 'http://laconi.ca/translate/download.php?file_id=9', - 'tr_TR' => 'http://laconi.ca/translate/download.php?file_id=37', - 'uk_UA' => 'http://laconi.ca/translate/download.php?file_id=44', - 'he_IL' => 'http://laconi.ca/translate/download.php?file_id=71', - 'mk_MK' => 'http://laconi.ca/translate/download.php?file_id=67', - 'ja_JP' => 'http://laconi.ca/translate/download.php?file_id=43', - 'cs_CZ' => 'http://laconi.ca/translate/download.php?file_id=63', - 'ca_ES' => 'http://laconi.ca/translate/download.php?file_id=49', - 'pl_PL' => 'http://laconi.ca/translate/download.php?file_id=51', - 'sv_SE' => 'http://laconi.ca/translate/download.php?file_id=55' + 'da_DK' => 'http://laconi.ca/translate/download.php?file_id=23', + 'nl_NL' => 'http://laconi.ca/translate/download.php?file_id=39', + 'en_NZ' => 'http://laconi.ca/translate/download.php?file_id=15', + 'eo' => 'http://laconi.ca/translate/download.php?file_id=10', + 'fr_FR' => 'http://laconi.ca/translate/download.php?file_id=19', + 'de_DE' => 'http://laconi.ca/translate/download.php?file_id=18', + 'it_IT' => 'http://laconi.ca/translate/download.php?file_id=21', + 'ko' => 'http://laconi.ca/translate/download.php?file_id=33', + 'no_NB' => 'http://laconi.ca/translate/download.php?file_id=31', + 'pt' => 'http://laconi.ca/translate/download.php?file_id=8', + 'pt_BR' => 'http://laconi.ca/translate/download.php?file_id=72', + 'ru_RU' => 'http://laconi.ca/translate/download.php?file_id=26', + 'es' => 'http://laconi.ca/translate/download.php?file_id=9', + 'tr_TR' => 'http://laconi.ca/translate/download.php?file_id=37', + 'uk_UA' => 'http://laconi.ca/translate/download.php?file_id=44', + 'he_IL' => 'http://laconi.ca/translate/download.php?file_id=71', + 'mk_MK' => 'http://laconi.ca/translate/download.php?file_id=67', + 'ja_JP' => 'http://laconi.ca/translate/download.php?file_id=43', + 'cs_CZ' => 'http://laconi.ca/translate/download.php?file_id=63', + 'ca_ES' => 'http://laconi.ca/translate/download.php?file_id=49', + 'pl_PL' => 'http://laconi.ca/translate/download.php?file_id=51', + 'sv_SE' => 'http://laconi.ca/translate/download.php?file_id=55' ); /* Update the languages */ foreach ($languages as $code => $file) { - $lcdir='locale/'.$code; - $msgdir=$lcdir.'/LC_MESSAGES'; - $pofile=$msgdir.'/laconica.po'; - $mofile=$msgdir.'/laconica.mo'; + $lcdir='locale/'.$code; + $msgdir=$lcdir.'/LC_MESSAGES'; + $pofile=$msgdir.'/laconica.po'; + $mofile=$msgdir.'/laconica.mo'; - /* Check for an existing */ - if (!is_dir($msgdir)) { - mkdir($lcdir); - mkdir($msgdir); - $existingSHA1 = ''; - } else { - $existingSHA1 = file_exists($pofile) ? sha1_file($pofile) : ''; - } + /* Check for an existing */ + if (!is_dir($msgdir)) { + mkdir($lcdir); + mkdir($msgdir); + $existingSHA1 = ''; + } else { + $existingSHA1 = file_exists($pofile) ? sha1_file($pofile) : ''; + } - /* Get the remote one */ - $newFile = file_get_contents($file); + /* Get the remote one */ + $newFile = file_get_contents($file); - // Update if the local .po file is different to the one downloaded, or - // if the .mo file is not present. - if(sha1($newFile)!=$existingSHA1 || !file_exists($mofile)) { - echo "Updating ".$code."\n"; - file_put_contents($pofile, $newFile); - $prevdir = getcwd(); - chdir($msgdir); - system('msgmerge -U laconica.po ../../laconica.pot'); - system('msgfmt -f -o laconica.mo laconica.po'); - chdir($prevdir); - } else { - echo "Unchanged - ".$code."\n"; - } + // Update if the local .po file is different to the one downloaded, or + // if the .mo file is not present. + if(sha1($newFile)!=$existingSHA1 || !file_exists($mofile)) { + echo "Updating ".$code."\n"; + file_put_contents($pofile, $newFile); + $prevdir = getcwd(); + chdir($msgdir); + system('msgmerge -U laconica.po ../../laconica.pot'); + system('msgfmt -f -o laconica.mo laconica.po'); + chdir($prevdir); + } else { + echo "Unchanged - ".$code."\n"; + } } echo "Finished\n"; diff --git a/scripts/xmppconfirmhandler.php b/scripts/xmppconfirmhandler.php index 8961b0b6e..454616ca0 100755 --- a/scripts/xmppconfirmhandler.php +++ b/scripts/xmppconfirmhandler.php @@ -20,8 +20,8 @@ # 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(); + print "This script must be run from the command line\n"; + exit(); } define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); @@ -37,102 +37,102 @@ define('CLAIM_TIMEOUT', 1200); class XmppConfirmHandler extends XmppQueueHandler { - var $_id = 'confirm'; - - function class_name() { - return 'XmppConfirmHandler'; - } - - function run() { - if (!$this->start()) { - return false; - } - $this->log(LOG_INFO, 'checking for queued confirmations'); - do { - $confirm = $this->next_confirm(); - if ($confirm) { - $this->log(LOG_INFO, 'Sending confirmation for ' . $confirm->address); - $user = User::staticGet($confirm->user_id); - if (!$user) { - $this->log(LOG_WARNING, 'Confirmation for unknown user ' . $confirm->user_id); - continue; - } - $success = jabber_confirm_address($confirm->code, - $user->nickname, - $confirm->address); - if (!$success) { - $this->log(LOG_ERR, 'Confirmation failed for ' . $confirm->address); - # Just let the claim age out; hopefully things work then - continue; - } else { - $this->log(LOG_INFO, 'Confirmation sent for ' . $confirm->address); - # Mark confirmation sent; need a dupe so we don't have the WHERE clause - $dupe = Confirm_address::staticGet('code', $confirm->code); - if (!$dupe) { - common_log(LOG_WARNING, 'Could not refetch confirm', __FILE__); - continue; - } - $orig = clone($dupe); - $dupe->sent = $dupe->claimed; - $result = $dupe->update($orig); - if (!$result) { - common_log_db_error($dupe, 'UPDATE', __FILE__); - # Just let the claim age out; hopefully things work then - continue; - } - $dupe->free(); - unset($dupe); - } - $user->free(); - unset($user); - $confirm->free(); - unset($confirm); - $this->idle(0); - } else { -# $this->clear_old_confirm_claims(); - $this->idle(10); - } - } while (true); - if (!$this->finish()) { - return false; - } - return true; - } + var $_id = 'confirm'; + + function class_name() { + return 'XmppConfirmHandler'; + } + + function run() { + if (!$this->start()) { + return false; + } + $this->log(LOG_INFO, 'checking for queued confirmations'); + do { + $confirm = $this->next_confirm(); + if ($confirm) { + $this->log(LOG_INFO, 'Sending confirmation for ' . $confirm->address); + $user = User::staticGet($confirm->user_id); + if (!$user) { + $this->log(LOG_WARNING, 'Confirmation for unknown user ' . $confirm->user_id); + continue; + } + $success = jabber_confirm_address($confirm->code, + $user->nickname, + $confirm->address); + if (!$success) { + $this->log(LOG_ERR, 'Confirmation failed for ' . $confirm->address); + # Just let the claim age out; hopefully things work then + continue; + } else { + $this->log(LOG_INFO, 'Confirmation sent for ' . $confirm->address); + # Mark confirmation sent; need a dupe so we don't have the WHERE clause + $dupe = Confirm_address::staticGet('code', $confirm->code); + if (!$dupe) { + common_log(LOG_WARNING, 'Could not refetch confirm', __FILE__); + continue; + } + $orig = clone($dupe); + $dupe->sent = $dupe->claimed; + $result = $dupe->update($orig); + if (!$result) { + common_log_db_error($dupe, 'UPDATE', __FILE__); + # Just let the claim age out; hopefully things work then + continue; + } + $dupe->free(); + unset($dupe); + } + $user->free(); + unset($user); + $confirm->free(); + unset($confirm); + $this->idle(0); + } else { +# $this->clear_old_confirm_claims(); + $this->idle(10); + } + } while (true); + if (!$this->finish()) { + return false; + } + return true; + } - function next_confirm() { - $confirm = new Confirm_address(); - $confirm->whereAdd('claimed IS NULL'); - $confirm->whereAdd('sent IS NULL'); - # XXX: eventually we could do other confirmations in the queue, too - $confirm->address_type = 'jabber'; - $confirm->orderBy('modified DESC'); - $confirm->limit(1); - if ($confirm->find(TRUE)) { - $this->log(LOG_INFO, 'Claiming confirmation for ' . $confirm->address); - # working around some weird DB_DataObject behaviour - $confirm->whereAdd(''); # clears where stuff - $original = clone($confirm); - $confirm->claimed = common_sql_now(); - $result = $confirm->update($original); - if ($result) { - $this->log(LOG_INFO, 'Succeeded in claim! '. $result); - return $confirm; - } else { - $this->log(LOG_INFO, 'Failed in claim!'); - return false; - } - } - return NULL; - } + function next_confirm() { + $confirm = new Confirm_address(); + $confirm->whereAdd('claimed IS NULL'); + $confirm->whereAdd('sent IS NULL'); + # XXX: eventually we could do other confirmations in the queue, too + $confirm->address_type = 'jabber'; + $confirm->orderBy('modified DESC'); + $confirm->limit(1); + if ($confirm->find(TRUE)) { + $this->log(LOG_INFO, 'Claiming confirmation for ' . $confirm->address); + # working around some weird DB_DataObject behaviour + $confirm->whereAdd(''); # clears where stuff + $original = clone($confirm); + $confirm->claimed = common_sql_now(); + $result = $confirm->update($original); + if ($result) { + $this->log(LOG_INFO, 'Succeeded in claim! '. $result); + return $confirm; + } else { + $this->log(LOG_INFO, 'Failed in claim!'); + return false; + } + } + return NULL; + } - function clear_old_confirm_claims() { - $confirm = new Confirm(); - $confirm->claimed = NULL; - $confirm->whereAdd('now() - claimed > '.CLAIM_TIMEOUT); - $confirm->update(DB_DATAOBJECT_WHEREADD_ONLY); - $confirm->free(); - unset($confirm); - } + function clear_old_confirm_claims() { + $confirm = new Confirm(); + $confirm->claimed = NULL; + $confirm->whereAdd('now() - claimed > '.CLAIM_TIMEOUT); + $confirm->update(DB_DATAOBJECT_WHEREADD_ONLY); + $confirm->free(); + unset($confirm); + } } ini_set("max_execution_time", "0"); diff --git a/scripts/xmppdaemon.php b/scripts/xmppdaemon.php index 9a60970a6..cd27a2c14 100755 --- a/scripts/xmppdaemon.php +++ b/scripts/xmppdaemon.php @@ -20,8 +20,8 @@ # 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(); + print "This script must be run from the command line\n"; + exit(); } define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); @@ -39,203 +39,203 @@ set_error_handler('common_error_handler'); class XMPPDaemon extends Daemon { - function XMPPDaemon($resource=NULL) { - static $attrs = array('server', 'port', 'user', 'password', 'host'); - - foreach ($attrs as $attr) - { - $this->$attr = common_config('xmpp', $attr); - } - - if ($resource) { - $this->resource = $resource; - } else { - $this->resource = common_config('xmpp', 'resource') . 'daemon'; - } - - $this->log(LOG_INFO, "INITIALIZE XMPPDaemon {$this->user}@{$this->server}/{$this->resource}"); - } - - function connect() { - - $connect_to = ($this->host) ? $this->host : $this->server; - - $this->log(LOG_INFO, "Connecting to $connect_to on port $this->port"); - - $this->conn = jabber_connect($this->resource); - - if (!$this->conn) { - return false; - } - - $this->conn->setReconnectTimeout(600); - - jabber_send_presence("Send me a message to post a notice", 'available', - NULL, 'available', 100); - return !$this->conn->isDisconnected(); - } - - function name() { - return strtolower('xmppdaemon.'.$this->resource); - } - - function run() { - if ($this->connect()) { - - $this->conn->addEventHandler('message', 'handle_message', $this); - $this->conn->addEventHandler('presence', 'handle_presence', $this); - $this->conn->addEventHandler('reconnect', 'handle_reconnect', $this); - - $this->conn->process(); - } - } - - 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) { - $user = User::staticGet('jabber', jabber_normalize_jid($from)); - return $user; - } - - function handle_message(&$pl) { - if ($pl['type'] != 'chat') { - return; - } - if (mb_strlen($pl['body']) == 0) { - return; - } - - $from = jabber_normalize_jid($pl['from']); - - # Forwarded from another daemon (probably a broadcaster) for - # us to handle - - if ($this->is_self($from)) { - $from = $this->get_ofrom($pl); - if (is_null($from) || $this->is_self($from)) { - return; - } - } - - $user = $this->get_user($from); - - if (!$user) { - $this->from_site($from, 'Unknown user; go to ' . - common_local_url('imsettings') . - ' to add your address to your account'); - $this->log(LOG_WARNING, 'Message from unknown user ' . $from); - return; - } - if ($this->handle_command($user, $pl['body'])) { - return; - } else if ($this->is_autoreply($pl['body'])) { - $this->log(LOG_INFO, 'Ignoring auto reply from ' . $from); - return; - } else if ($this->is_otr($pl['body'])) { - $this->log(LOG_INFO, 'Ignoring OTR from ' . $from); - return; - } else if ($this->is_direct($pl['body'])) { - 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->add_direct($user, $body, $to, $from); - } else { - $len = mb_strlen($pl['body']); - if($len > 140) { - $this->from_site($from, 'Message too long - maximum is 140 characters, you sent ' . $len); - return; - } - $this->add_notice($user, $pl); - } - - $user->free(); - unset($user); - } - - function is_self($from) { - return preg_match('/^'.strtolower(jabber_daemon_address()).'/', strtolower($from)); - } - - function get_ofrom($pl) { - $xml = $pl['xml']; - $addresses = $xml->sub('addresses'); - if (!$addresses) { - $this->log(LOG_WARNING, 'Forwarded message without addresses'); - return NULL; - } - $address = $addresses->sub('address'); - if (!$address) { - $this->log(LOG_WARNING, 'Forwarded message without address'); - return NULL; - } - if (!array_key_exists('type', $address->attrs)) { - $this->log(LOG_WARNING, 'No type for forwarded message'); - return NULL; - } - $type = $address->attrs['type']; - if ($type != 'ofrom') { - $this->log(LOG_WARNING, 'Type of forwarded message is not ofrom'); - return NULL; - } - if (!array_key_exists('jid', $address->attrs)) { - $this->log(LOG_WARNING, 'No jid for forwarded message'); - return NULL; - } - $jid = $address->attrs['jid']; - if (!$jid) { - $this->log(LOG_WARNING, 'Could not get jid from address'); - return NULL; - } - $this->log(LOG_DEBUG, 'Got message forwarded from jid ' . $jid); - return $jid; - } - - function is_autoreply($txt) { - if (preg_match('/[\[\(]?[Aa]uto[-\s]?[Rr]e(ply|sponse)[\]\)]/', $txt)) { - return true; - } else { - return false; - } - } - - function is_otr($txt) { - if (preg_match('/^\?OTR/', $txt)) { - return true; - } else { - return false; - } - } - - 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; - jabber_send_message($address, $text); - } - - function handle_command($user, $body) { - $inter = new CommandInterpreter(); - $cmd = $inter->handle_command($user, $body); - if ($cmd) { - $chan = new XMPPChannel($this->conn); - $cmd->execute($chan); - return true; - } else { - return false; - } - } - - function add_notice(&$user, &$pl) { + function XMPPDaemon($resource=NULL) { + static $attrs = array('server', 'port', 'user', 'password', 'host'); + + foreach ($attrs as $attr) + { + $this->$attr = common_config('xmpp', $attr); + } + + if ($resource) { + $this->resource = $resource; + } else { + $this->resource = common_config('xmpp', 'resource') . 'daemon'; + } + + $this->log(LOG_INFO, "INITIALIZE XMPPDaemon {$this->user}@{$this->server}/{$this->resource}"); + } + + function connect() { + + $connect_to = ($this->host) ? $this->host : $this->server; + + $this->log(LOG_INFO, "Connecting to $connect_to on port $this->port"); + + $this->conn = jabber_connect($this->resource); + + if (!$this->conn) { + return false; + } + + $this->conn->setReconnectTimeout(600); + + jabber_send_presence("Send me a message to post a notice", 'available', + NULL, 'available', 100); + return !$this->conn->isDisconnected(); + } + + function name() { + return strtolower('xmppdaemon.'.$this->resource); + } + + function run() { + if ($this->connect()) { + + $this->conn->addEventHandler('message', 'handle_message', $this); + $this->conn->addEventHandler('presence', 'handle_presence', $this); + $this->conn->addEventHandler('reconnect', 'handle_reconnect', $this); + + $this->conn->process(); + } + } + + 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) { + $user = User::staticGet('jabber', jabber_normalize_jid($from)); + return $user; + } + + function handle_message(&$pl) { + if ($pl['type'] != 'chat') { + return; + } + if (mb_strlen($pl['body']) == 0) { + return; + } + + $from = jabber_normalize_jid($pl['from']); + + # Forwarded from another daemon (probably a broadcaster) for + # us to handle + + if ($this->is_self($from)) { + $from = $this->get_ofrom($pl); + if (is_null($from) || $this->is_self($from)) { + return; + } + } + + $user = $this->get_user($from); + + if (!$user) { + $this->from_site($from, 'Unknown user; go to ' . + common_local_url('imsettings') . + ' to add your address to your account'); + $this->log(LOG_WARNING, 'Message from unknown user ' . $from); + return; + } + if ($this->handle_command($user, $pl['body'])) { + return; + } else if ($this->is_autoreply($pl['body'])) { + $this->log(LOG_INFO, 'Ignoring auto reply from ' . $from); + return; + } else if ($this->is_otr($pl['body'])) { + $this->log(LOG_INFO, 'Ignoring OTR from ' . $from); + return; + } else if ($this->is_direct($pl['body'])) { + 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->add_direct($user, $body, $to, $from); + } else { + $len = mb_strlen($pl['body']); + if($len > 140) { + $this->from_site($from, 'Message too long - maximum is 140 characters, you sent ' . $len); + return; + } + $this->add_notice($user, $pl); + } + + $user->free(); + unset($user); + } + + function is_self($from) { + return preg_match('/^'.strtolower(jabber_daemon_address()).'/', strtolower($from)); + } + + function get_ofrom($pl) { + $xml = $pl['xml']; + $addresses = $xml->sub('addresses'); + if (!$addresses) { + $this->log(LOG_WARNING, 'Forwarded message without addresses'); + return NULL; + } + $address = $addresses->sub('address'); + if (!$address) { + $this->log(LOG_WARNING, 'Forwarded message without address'); + return NULL; + } + if (!array_key_exists('type', $address->attrs)) { + $this->log(LOG_WARNING, 'No type for forwarded message'); + return NULL; + } + $type = $address->attrs['type']; + if ($type != 'ofrom') { + $this->log(LOG_WARNING, 'Type of forwarded message is not ofrom'); + return NULL; + } + if (!array_key_exists('jid', $address->attrs)) { + $this->log(LOG_WARNING, 'No jid for forwarded message'); + return NULL; + } + $jid = $address->attrs['jid']; + if (!$jid) { + $this->log(LOG_WARNING, 'Could not get jid from address'); + return NULL; + } + $this->log(LOG_DEBUG, 'Got message forwarded from jid ' . $jid); + return $jid; + } + + function is_autoreply($txt) { + if (preg_match('/[\[\(]?[Aa]uto[-\s]?[Rr]e(ply|sponse)[\]\)]/', $txt)) { + return true; + } else { + return false; + } + } + + function is_otr($txt) { + if (preg_match('/^\?OTR/', $txt)) { + return true; + } else { + return false; + } + } + + 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; + jabber_send_message($address, $text); + } + + function handle_command($user, $body) { + $inter = new CommandInterpreter(); + $cmd = $inter->handle_command($user, $body); + if ($cmd) { + $chan = new XMPPChannel($this->conn); + $cmd->execute($chan); + return true; + } else { + return false; + } + } + + function add_notice(&$user, &$pl) { $body = trim($pl['body']); $content_shortened = common_shorten_link($body); if (mb_strlen($content_shortened) > 140) { @@ -245,59 +245,59 @@ class XMPPDaemon extends Daemon { else { $content = $body; } - $notice = Notice::saveNew($user->id, $content, 'xmpp'); - if (is_string($notice)) { - $this->log(LOG_ERR, $notice); - return; - } - common_broadcast_notice($notice); - $this->log(LOG_INFO, - 'Added notice ' . $notice->id . ' from user ' . $user->nickname); - $notice->free(); - unset($notice); - } - - function handle_presence(&$pl) { - $from = jabber_normalize_jid($pl['from']); - switch ($pl['type']) { - case 'subscribe': - # We let anyone subscribe - $this->subscribed($from); - $this->log(LOG_INFO, - 'Accepted subscription from ' . $from); - break; - case 'subscribed': - case 'unsubscribed': - case 'unsubscribe': - $this->log(LOG_INFO, - 'Ignoring "' . $pl['type'] . '" from ' . $from); - break; - default: - if (!$pl['type']) { - $user = User::staticGet('jabber', $from); - if (!$user) { - $this->log(LOG_WARNING, 'Presence from unknown user ' . $from); - return; - } - if ($user->updatefrompresence) { - $this->log(LOG_INFO, 'Updating ' . $user->nickname . - ' status from presence.'); - $this->add_notice($user, $pl); - } - $user->free(); - unset($user); - } - break; - } - } - - function log($level, $msg) { - common_log($level, 'XMPPDaemon('.$this->resource.'): '.$msg); - } - - function subscribed($to) { - jabber_special_presence('subscribed', $to); - } + $notice = Notice::saveNew($user->id, $content, 'xmpp'); + if (is_string($notice)) { + $this->log(LOG_ERR, $notice); + return; + } + common_broadcast_notice($notice); + $this->log(LOG_INFO, + 'Added notice ' . $notice->id . ' from user ' . $user->nickname); + $notice->free(); + unset($notice); + } + + function handle_presence(&$pl) { + $from = jabber_normalize_jid($pl['from']); + switch ($pl['type']) { + case 'subscribe': + # We let anyone subscribe + $this->subscribed($from); + $this->log(LOG_INFO, + 'Accepted subscription from ' . $from); + break; + case 'subscribed': + case 'unsubscribed': + case 'unsubscribe': + $this->log(LOG_INFO, + 'Ignoring "' . $pl['type'] . '" from ' . $from); + break; + default: + if (!$pl['type']) { + $user = User::staticGet('jabber', $from); + if (!$user) { + $this->log(LOG_WARNING, 'Presence from unknown user ' . $from); + return; + } + if ($user->updatefrompresence) { + $this->log(LOG_INFO, 'Updating ' . $user->nickname . + ' status from presence.'); + $this->add_notice($user, $pl); + } + $user->free(); + unset($user); + } + break; + } + } + + function log($level, $msg) { + common_log($level, 'XMPPDaemon('.$this->resource.'): '.$msg); + } + + function subscribed($to) { + jabber_special_presence('subscribed', $to); + } } ini_set("max_execution_time", "0"); |