diff options
-rw-r--r-- | README | 3 | ||||
-rw-r--r-- | actions/all.php | 11 | ||||
-rw-r--r-- | actions/api.php | 4 | ||||
-rw-r--r-- | actions/block.php | 2 | ||||
-rw-r--r-- | actions/favorited.php | 11 | ||||
-rw-r--r-- | actions/groupmembers.php | 11 | ||||
-rw-r--r-- | actions/groups.php | 11 | ||||
-rw-r--r-- | actions/inbox.php | 21 | ||||
-rw-r--r-- | actions/outbox.php | 13 | ||||
-rw-r--r-- | actions/public.php | 11 | ||||
-rw-r--r-- | actions/replies.php | 11 | ||||
-rw-r--r-- | actions/showfavorites.php | 12 | ||||
-rw-r--r-- | actions/showgroup.php | 11 | ||||
-rw-r--r-- | actions/shownotice.php | 2 | ||||
-rw-r--r-- | actions/showstream.php | 19 | ||||
-rw-r--r-- | actions/tag.php | 12 | ||||
-rw-r--r-- | actions/unblock.php | 2 | ||||
-rw-r--r-- | classes/Notice.php | 7 | ||||
-rw-r--r-- | js/util.js | 9 | ||||
-rw-r--r-- | lib/Shorturl_api.php | 2 | ||||
-rw-r--r-- | lib/action.php | 46 | ||||
-rw-r--r-- | lib/common.php | 1 | ||||
-rw-r--r-- | lib/mail.php | 1 | ||||
-rw-r--r-- | lib/router.php | 2 | ||||
-rw-r--r-- | lib/twitterapi.php | 22 | ||||
-rw-r--r-- | scripts/fixup_utf8.php | 358 | ||||
-rwxr-xr-x | scripts/maildaemon.php | 14 |
27 files changed, 356 insertions, 273 deletions
@@ -901,6 +901,9 @@ sslserver: use an alternate server name for SSL URLs, like parameters correctly so that both the SSL server and the "normal" server can access the session cookie and preferably other cookies as well. +shorturllength: Length of URL at which URLs in a message exceeding 140 + characters will be sent to the user's chosen + shortening service. db -- diff --git a/actions/all.php b/actions/all.php index a53bbea07..03179a246 100644 --- a/actions/all.php +++ b/actions/all.php @@ -69,17 +69,6 @@ class AllAction extends ProfileAction sprintf(_('Feed for friends of %s (Atom)'), $this->user->nickname))); } - /** - * Output document relationship links - * - * @return void - */ - function showRelationshipLinks() - { - $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME - $this->page, 'all', array('nickname' => $this->user->nickname)); - } - function showLocalNav() { $nav = new PersonalGroupNav($this); diff --git a/actions/api.php b/actions/api.php index b25ba99f3..b8da852b5 100644 --- a/actions/api.php +++ b/actions/api.php @@ -144,8 +144,8 @@ class ApiAction extends Action } if (in_array($fullname, $bareauth)) { - # bareauth: only needs auth if without an argument - if ($this->api_arg) { + # bareauth: only needs auth if without an argument or query param specifying user + if ($this->api_arg || $this->arg('id') || is_numeric($this->arg('user_id')) || $this->arg('screen_name')) { return false; } else { return true; diff --git a/actions/block.php b/actions/block.php index 34f991dc6..0efee5932 100644 --- a/actions/block.php +++ b/actions/block.php @@ -180,7 +180,7 @@ class BlockAction extends Action if ($action) { common_redirect(common_local_url($action, $args), 303); } else { - common_redirect(common_local_url('subscriptions', + common_redirect(common_local_url('subscribers', array('nickname' => $cur->nickname)), 303); } diff --git a/actions/favorited.php b/actions/favorited.php index 7e31303e3..c902d80f5 100644 --- a/actions/favorited.php +++ b/actions/favorited.php @@ -221,15 +221,4 @@ class FavoritedAction extends Action $this->pagination($this->page > 1, $cnt > NOTICES_PER_PAGE, $this->page, 'favorited'); } - - /** - * Output document relationship links - * - * @return void - */ - function showRelationshipLinks() - { - $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME - $this->page, 'favorited'); - } } diff --git a/actions/groupmembers.php b/actions/groupmembers.php index 909935bec..21e5ebbaa 100644 --- a/actions/groupmembers.php +++ b/actions/groupmembers.php @@ -137,15 +137,4 @@ class GroupmembersAction extends Action $this->page, 'groupmembers', array('nickname' => $this->group->nickname)); } - - /** - * Output document relationship links - * - * @return void - */ - function showRelationshipLinks() - { - $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME - $this->page, 'groupmembers', array('nickname' => $this->group->nickname)); - } } diff --git a/actions/groups.php b/actions/groups.php index e20acce70..26b52a5fc 100644 --- a/actions/groups.php +++ b/actions/groups.php @@ -129,15 +129,4 @@ class GroupsAction extends Action $gbm = new GroupsByMembersSection($this); $gbm->show(); } - - /** - * Output document relationship links - * - * @return void - */ - function showRelationshipLinks() - { - $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME - $this->page, 'groups', array('nickname' => $this->group->nickname)); - } } diff --git a/actions/inbox.php b/actions/inbox.php index 7b5cf2d20..f14ba631f 100644 --- a/actions/inbox.php +++ b/actions/inbox.php @@ -46,15 +46,15 @@ require_once INSTALLDIR.'/lib/mailbox.php'; class InboxAction extends MailboxAction { - + /** * Title of the page * * @return string page title */ - + function title() - { + { if ($this->page > 1) { return sprintf(_("Inbox for %s - page %d"), $this->user->nickname, $this->page); @@ -64,21 +64,10 @@ class InboxAction extends MailboxAction } /** - * Output document relationship links - * - * @return void - */ - function showRelationshipLinks() - { - $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME - $this->page, 'inbox', array('nickname' => $this->user->nickname)); - } - - /** * Retrieve the messages for this user and this page * * Does a query for the right messages - * + * * @return Message data object with stream for messages * * @see MailboxAction::getMessages() @@ -95,7 +84,7 @@ class InboxAction extends MailboxAction if ($message->find()) { return $message; - } else { + } else { return null; } } diff --git a/actions/outbox.php b/actions/outbox.php index deef1cc87..a875e9ad9 100644 --- a/actions/outbox.php +++ b/actions/outbox.php @@ -63,21 +63,10 @@ class OutboxAction extends MailboxAction } /** - * Output document relationship links - * - * @return void - */ - function showRelationshipLinks() - { - $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME - $this->page, 'outbox', array('nickname' => $this->user->nickname)); - } - - /** * retrieve the messages for this user and this page * * Does a query for the right messages - * + * * @return Message data object with stream for messages * * @see MailboxAction::getMessages() diff --git a/actions/public.php b/actions/public.php index d2f9da646..27153f131 100644 --- a/actions/public.php +++ b/actions/public.php @@ -136,17 +136,6 @@ class PublicAction extends Action } /** - * Output document relationship links - * - * @return void - */ - function showRelationshipLinks() - { - $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME - $this->page, 'public'); - } - - /** * Extra head elements * * We include a <meta> element linking to the publicxrds page, for OpenID diff --git a/actions/replies.php b/actions/replies.php index dfb520d64..eac4d0a3a 100644 --- a/actions/replies.php +++ b/actions/replies.php @@ -139,17 +139,6 @@ class RepliesAction extends Action } /** - * Output document relationship links - * - * @return void - */ - function showRelationshipLinks() - { - $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME - $this->page, 'replies', array('nickname' => $this->user->nickname)); - } - - /** * show the personal group nav * * @return void diff --git a/actions/showfavorites.php b/actions/showfavorites.php index eed62a2ab..865045337 100644 --- a/actions/showfavorites.php +++ b/actions/showfavorites.php @@ -151,18 +151,6 @@ class ShowfavoritesAction extends Action } /** - * Output document relationship links - * - * @return void - */ - function showRelationshipLinks() - { - $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME - $this->page, 'showfavorites', array('nickname' => $this->user->nickname)); - } - - - /** * show the personal group nav * * @return void diff --git a/actions/showgroup.php b/actions/showgroup.php index a7df39727..29b6fa1e6 100644 --- a/actions/showgroup.php +++ b/actions/showgroup.php @@ -312,17 +312,6 @@ class ShowgroupAction extends Action } /** - * Output document relationship links - * - * @return void - */ - function showRelationshipLinks() - { - $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME - $this->page, 'showgroup', array('nickname' => $this->group->nickname)); - } - - /** * Fill in the sidebar. * * @return void diff --git a/actions/shownotice.php b/actions/shownotice.php index 2c469c9de..1be1e2414 100644 --- a/actions/shownotice.php +++ b/actions/shownotice.php @@ -122,7 +122,7 @@ class ShownoticeAction extends Action function lastModified() { - return max(strtotime($this->notice->created), + return max(strtotime($this->notice->modified), strtotime($this->profile->modified), ($this->avatar) ? strtotime($this->avatar->modified) : 0); } diff --git a/actions/showstream.php b/actions/showstream.php index 82665e5b8..641228bc7 100644 --- a/actions/showstream.php +++ b/actions/showstream.php @@ -135,17 +135,6 @@ class ShowstreamAction extends ProfileAction sprintf(_('FOAF for %s'), $this->user->nickname))); } - /** - * Output document relationship links - * - * @return void - */ - function showRelationshipLinks() - { - $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME - $this->page, 'showstream', array('nickname' => $this->user->nickname)); - } - function extraHead() { // for remote subscriptions etc. @@ -319,10 +308,14 @@ class ShowstreamAction extends ProfileAction $blocked = $cur->hasBlocked($this->profile); $this->elementStart('li', 'entity_block'); if ($blocked) { - $ubf = new UnblockForm($this, $this->profile); + $ubf = new UnblockForm($this, $this->profile, + array('action' => 'showstream', + 'nickname' => $this->profile->nickname)); $ubf->show(); } else { - $bf = new BlockForm($this, $this->profile); + $bf = new BlockForm($this, $this->profile, + array('action' => 'showstream', + 'nickname' => $this->profile->nickname)); $bf->show(); } $this->elementEnd('li'); diff --git a/actions/tag.php b/actions/tag.php index 02f3e3522..f5ca06f05 100644 --- a/actions/tag.php +++ b/actions/tag.php @@ -51,7 +51,6 @@ class TagAction extends Action $pop->show(); } - function title() { if ($this->page == 1) { @@ -77,17 +76,6 @@ class TagAction extends Action sprintf(_('Feed for tag %s'), $this->tag))); } - /** - * Output document relationship links - * - * @return void - */ - function showRelationshipLinks() - { - $this->sequenceRelationships($this->page > 1, $this->count > NOTICES_PER_PAGE, // FIXME - $this->page, 'tag', array('tag' => $this->tag)); - } - function showPageNotice() { return sprintf(_('Messages tagged "%s", most recent first'), $this->tag); diff --git a/actions/unblock.php b/actions/unblock.php index 8573b2a87..6e671c9dd 100644 --- a/actions/unblock.php +++ b/actions/unblock.php @@ -118,7 +118,7 @@ class UnblockAction extends Action if ($action) { common_redirect(common_local_url($action, $args), 303); } else { - common_redirect(common_local_url('subscriptions', + common_redirect(common_local_url('subscribers', array('nickname' => $cur->nickname)), 303); } diff --git a/classes/Notice.php b/classes/Notice.php index b4c86ebeb..bca4b22c4 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -123,7 +123,12 @@ class Notice extends Memcached_DataObject $profile = Profile::staticGet($profile_id); - $final = common_shorten_links($content); + $final = common_shorten_links($content); + + if (mb_strlen($final) > 140) { + common_log(LOG_INFO, 'Rejecting notice that is too long.'); + return _('Problem saving notice. Too long.'); + } if (!$profile) { common_log(LOG_ERR, 'Problem saving notice. Unknown user.'); diff --git a/js/util.js b/js/util.js index 3f14bc61c..23abba6c2 100644 --- a/js/util.js +++ b/js/util.js @@ -178,7 +178,14 @@ $(document).ready(function(){ $('#form_notice').append(document._importNode($(".error", xhr.responseXML).get(0), true)); } else { - alert("Sorry! We had trouble sending your notice ("+xhr.status+" "+xhr.statusText+"). Please report the problem to the site administrator if this happens again."); + var HTTP20x30x = [200, 201, 202, 203, 204, 205, 206, 300, 301, 302, 303, 304, 305, 306, 307]; + if(jQuery.inArray(parseInt(xhr.status), HTTP20x30x) < 0) { + alert("Sorry! We had trouble sending your notice ("+xhr.status+" "+xhr.statusText+"). Please report the problem to the site administrator if this happens again."); + } + else { + $("#notice_data-text").val(""); + counter(); + } } } }, diff --git a/lib/Shorturl_api.php b/lib/Shorturl_api.php index fe106cb83..d1fc5eb6d 100644 --- a/lib/Shorturl_api.php +++ b/lib/Shorturl_api.php @@ -39,7 +39,7 @@ class ShortUrlApi } private function is_long($url) { - return strlen($url) >= 30; + return strlen($url) >= common_config('site', 'shorturllength'); } protected function http_post($data) { diff --git a/lib/action.php b/lib/action.php index 6b130b6d5..7c7c52c2c 100644 --- a/lib/action.php +++ b/lib/action.php @@ -124,7 +124,6 @@ class Action extends HTMLOutputter // lawsuit $this->showShortcutIcon(); $this->showStylesheets(); $this->showScripts(); - $this->showRelationshipLinks(); $this->showOpenSearch(); $this->showFeeds(); $this->showDescription(); @@ -262,19 +261,6 @@ class Action extends HTMLOutputter // lawsuit } /** - * Show document relationship links - * - * SHOULD overload - * - * @return nothing - */ - function showRelationshipLinks() - { - // output <link> elements with appropriate HTML4.01 link types: - // http://www.w3.org/TR/html401/types.html#type-links - } - - /** * Show OpenSearch headers * * @return nothing @@ -1055,36 +1041,4 @@ class Action extends HTMLOutputter // lawsuit { return null; } - - /** - * Generate document metadata for sequential navigation - * - * @param boolean $have_before is there something before? - * @param boolean $have_after is there something after? - * @param integer $page current page - * @param string $action current action - * @param array $args rest of query arguments - * - * @return nothing - */ - function sequenceRelationships($have_next, $have_previous, $page, $action, $args=null) - { - // Outputs machine-readable pagination in <link> elements. - // Pattern taken from $this->pagination() method. - - // "next" is equivalent to "after" - if ($have_next) { - $pargs = array('page' => $page-1); - $this->element('link', array('rel' => 'next', - 'href' => common_local_url($action, $args, $pargs), - 'title' => _('Next'))); - } - // "previous" is equivalent to "before" - if ($have_previous=true) { // FIXME - $pargs = array('page' => $page+1); - $this->element('link', array('rel' => 'prev', - 'href' => common_local_url($action, $args, $pargs), - 'title' => _('Previous'))); - } - } } diff --git a/lib/common.php b/lib/common.php index 01d2c78ea..151b31d80 100644 --- a/lib/common.php +++ b/lib/common.php @@ -89,6 +89,7 @@ $config = 'private' => false, 'ssl' => 'never', 'sslserver' => null, + 'shorturllength' => 30, 'dupelimit' => 60), # default for same person saying the same thing 'syslog' => array('appname' => 'laconica', # for syslog diff --git a/lib/mail.php b/lib/mail.php index 27a1d99dc..4e1f1dbb1 100644 --- a/lib/mail.php +++ b/lib/mail.php @@ -335,6 +335,7 @@ function mail_broadcast_notice_sms($notice) "FROM $UT JOIN subscription " . "ON $UT.id = subscription.subscriber " . 'WHERE subscription.subscribed = ' . $notice->profile_id . ' ' . + 'AND subscription.subscribed != subscription.subscriber ' . "AND $UT.smsemail IS NOT null " . "AND $UT.smsnotify = 1 " . 'AND subscription.sms = 1 '); diff --git a/lib/router.php b/lib/router.php index 12590b790..748966567 100644 --- a/lib/router.php +++ b/lib/router.php @@ -101,7 +101,7 @@ class Router $main = array('login', 'logout', 'register', 'subscribe', 'unsubscribe', 'confirmaddress', 'recoverpassword', 'invite', 'favor', 'disfavor', 'sup', - 'block', 'subedit'); + 'block', 'unblock', 'subedit'); foreach ($main as $a) { $m->connect('main/'.$a, array('action' => $a)); diff --git a/lib/twitterapi.php b/lib/twitterapi.php index 1d527b935..ca8b03cdc 100644 --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@ -673,7 +673,27 @@ class TwitterapiAction extends Action function get_user($id, $apidata=null) { if (!$id) { - return $apidata['user']; + + // Twitter supports these other ways of passing the user ID + if (is_numeric($this->arg('id'))) { + return User::staticGet($this->arg('id')); + } else if ($this->arg('id')) { + $nickname = common_canonical_nickname($this->arg('id')); + return User::staticGet('nickname', $nickname); + } else if ($this->arg('user_id')) { + // This is to ensure that a non-numeric user_id still + // overrides screen_name even if it doesn't get used + if (is_numeric($this->arg('user_id'))) { + return User::staticGet('id', $this->arg('user_id')); + } + } else if ($this->arg('screen_name')) { + $nickname = common_canonical_nickname($this->arg('screen_name')); + return User::staticGet('nickname', $nickname); + } else { + // Fall back to trying the currently authenticated user + return $apidata['user']; + } + } else if (is_numeric($id)) { return User::staticGet($id); } else { diff --git a/scripts/fixup_utf8.php b/scripts/fixup_utf8.php index 925da2484..169376091 100644 --- a/scripts/fixup_utf8.php +++ b/scripts/fixup_utf8.php @@ -35,116 +35,334 @@ define('LACONICA', true); require_once(INSTALLDIR . '/lib/common.php'); require_once('DB.php'); -function fixup_utf8($max_id, $min_id) { +class UTF8FixerUpper +{ + var $dbl = null; + var $dbu = null; + var $args = array(); + + function __construct($args) + { + $this->args = $args; + + if (array_key_exists('max_date', $args)) { + $this->max_date = strftime('%Y-%m-%d %H:%M:%S', strtotime($args['max_date'])); + } else { + $this->max_date = strftime('%Y-%m-%d %H:%M:%S', time()); + } - $dbl = doConnect('latin1'); + $this->dbl = $this->doConnect('latin1'); - if (empty($dbl)) { - return; - } + if (empty($this->dbl)) { + return; + } - $dbu = doConnect('utf8'); + $this->dbu = $this->doConnect('utf8'); - if (empty($dbu)) { - return; + if (empty($this->dbu)) { + return; + } } - // Do a separate DB connection + function doConnect($charset) + { + $db = DB::connect(common_config('db', 'database'), + array('persistent' => false)); - $sth = $dbu->prepare("UPDATE notice SET content = UNHEX(?), rendered = UNHEX(?) WHERE id = ?"); + if (PEAR::isError($db)) { + echo "ERROR: " . $db->getMessage() . "\n"; + return NULL; + } - if (PEAR::isError($sth)) { - echo "ERROR: " . $sth->getMessage() . "\n"; - return; - } + $conn = $db->connection; - $sql = 'SELECT id, content, rendered FROM notice ' . - 'WHERE LENGTH(content) != CHAR_LENGTH(content)'; + $succ = mysqli_set_charset($conn, $charset); - if (!empty($max_id)) { - $sql .= ' AND id <= ' . $max_id; - } + if (!$succ) { + echo "ERROR: couldn't set charset\n"; + $db->disconnect(); + return NULL; + } - if (!empty($min_id)) { - $sql .= ' AND id >= ' . $min_id; - } + $result = $db->autoCommit(true); - $sql .= ' ORDER BY id DESC'; + if (PEAR::isError($result)) { + echo "ERROR: " . $result->getMessage() . "\n"; + $db->disconnect(); + return NULL; + } - $rn = $dbl->query($sql); + return $db; + } - if (PEAR::isError($rn)) { - echo "ERROR: " . $rn->getMessage() . "\n"; - return; + function fixup() + { + $this->fixupNotices($this->args['max_notice'], + $this->args['min_notice']); + $this->fixupProfiles(); + $this->fixupGroups(); + $this->fixupMessages(); } - echo "Number of rows: " . $rn->numRows() . "\n"; + function fixupNotices($max_id, $min_id) { - $notice = array(); + // Do a separate DB connection - while (DB_OK == $rn->fetchInto($notice)) { + $sth = $this->dbu->prepare("UPDATE notice SET content = UNHEX(?), rendered = UNHEX(?) WHERE id = ?"); - $id = ($notice[0])+0; - $content = bin2hex($notice[1]); - $rendered = bin2hex($notice[2]); + if (PEAR::isError($sth)) { + echo "ERROR: " . $sth->getMessage() . "\n"; + return; + } - echo "$id..."; + $sql = 'SELECT id, content, rendered FROM notice ' . + 'WHERE LENGTH(content) != CHAR_LENGTH(content) '. + 'AND modified < "'.$this->max_date.'" '; - $result =& $dbu->execute($sth, array($content, $rendered, $id)); + if (!empty($max_id)) { + $sql .= ' AND id <= ' . $max_id; + } - if (PEAR::isError($result)) { - echo "ERROR: " . $result->getMessage() . "\n"; - continue; + if (!empty($min_id)) { + $sql .= ' AND id >= ' . $min_id; } - $cnt = $dbu->affectedRows(); + $sql .= ' ORDER BY id DESC'; + + $rn = $this->dbl->query($sql); - if ($cnt != 1) { - echo "ERROR: 0 rows affected\n"; - continue; + if (PEAR::isError($rn)) { + echo "ERROR: " . $rn->getMessage() . "\n"; + return; } - $notice = Notice::staticGet('id', $id); - $notice->decache(); + echo "Number of rows: " . $rn->numRows() . "\n"; - echo "OK\n"; - } -} + $notice = array(); -function doConnect($charset) -{ - $db = DB::connect(common_config('db', 'database'), - array('persistent' => false)); + while (DB_OK == $rn->fetchInto($notice)) { - if (PEAR::isError($db)) { - echo "ERROR: " . $db->getMessage() . "\n"; - return NULL; + $id = ($notice[0])+0; + $content = bin2hex($notice[1]); + $rendered = bin2hex($notice[2]); + + echo "$id..."; + + $result =& $this->dbu->execute($sth, array($content, $rendered, $id)); + + if (PEAR::isError($result)) { + echo "ERROR: " . $result->getMessage() . "\n"; + continue; + } + + $cnt = $this->dbu->affectedRows(); + + if ($cnt != 1) { + echo "ERROR: 0 rows affected\n"; + continue; + } + + $notice = Notice::staticGet('id', $id); + $notice->decache(); + $notice->free(); + + echo "OK\n"; + } } -// $result = $db->query("SET NAMES $charset"); + function fixupProfiles() + { + // Do a separate DB connection + + $sth = $this->dbu->prepare("UPDATE profile SET ". + "fullname = UNHEX(?),". + "location = UNHEX(?), ". + "bio = UNHEX(?) ". + "WHERE id = ?"); + + if (PEAR::isError($sth)) { + echo "ERROR: " . $sth->getMessage() . "\n"; + return; + } + + $sql = 'SELECT id, fullname, location, bio FROM profile ' . + 'WHERE (LENGTH(fullname) != CHAR_LENGTH(fullname) '. + 'OR LENGTH(location) != CHAR_LENGTH(location) '. + 'OR LENGTH(bio) != CHAR_LENGTH(bio)) '. + 'AND modified < "'.$this->max_date.'" '. + ' ORDER BY modified DESC'; + + $rn = $this->dbl->query($sql); + + if (PEAR::isError($rn)) { + echo "ERROR: " . $rn->getMessage() . "\n"; + return; + } + + echo "Number of rows: " . $rn->numRows() . "\n"; + + $profile = array(); + + while (DB_OK == $rn->fetchInto($profile)) { + + $id = ($profile[0])+0; + $fullname = bin2hex($profile[1]); + $location = bin2hex($profile[2]); + $bio = bin2hex($profile[3]); + + echo "$id..."; + + $result =& $this->dbu->execute($sth, array($fullname, $location, $bio, $id)); + + if (PEAR::isError($result)) { + echo "ERROR: " . $result->getMessage() . "\n"; + continue; + } - $conn = $db->connection; + $cnt = $this->dbu->affectedRows(); - $succ = mysqli_set_charset($conn, $charset); + if ($cnt != 1) { + echo "ERROR: 0 rows affected\n"; + continue; + } - if (!$succ) { - echo "ERROR: couldn't set charset\n"; - $db->disconnect(); - return NULL; + $profile = Profile::staticGet('id', $id); + $profile->decache(); + $profile->free(); + + echo "OK\n"; + } } - $result = $db->autoCommit(true); + function fixupGroups() + { + // Do a separate DB connection + + $sth = $this->dbu->prepare("UPDATE user_group SET ". + "fullname = UNHEX(?),". + "location = UNHEX(?), ". + "description = UNHEX(?) ". + "WHERE id = ?"); + + if (PEAR::isError($sth)) { + echo "ERROR: " . $sth->getMessage() . "\n"; + return; + } + + $sql = 'SELECT id, fullname, location, description FROM user_group ' . + 'WHERE LENGTH(fullname) != CHAR_LENGTH(fullname) '. + 'OR LENGTH(location) != CHAR_LENGTH(location) '. + 'OR LENGTH(description) != CHAR_LENGTH(description) '; + 'AND modified < "'.$this->max_date.'" '. + 'ORDER BY modified DESC'; + + $rn = $this->dbl->query($sql); + + if (PEAR::isError($rn)) { + echo "ERROR: " . $rn->getMessage() . "\n"; + return; + } + + echo "Number of rows: " . $rn->numRows() . "\n"; + + $user_group = array(); - if (PEAR::isError($result)) { - echo "ERROR: " . $result->getMessage() . "\n"; - $db->disconnect(); - return NULL; + while (DB_OK == $rn->fetchInto($user_group)) { + + $id = ($user_group[0])+0; + $fullname = bin2hex($user_group[1]); + $location = bin2hex($user_group[2]); + $description = bin2hex($user_group[3]); + + echo "$id..."; + + $result =& $this->dbu->execute($sth, array($fullname, $location, $description, $id)); + + if (PEAR::isError($result)) { + echo "ERROR: " . $result->getMessage() . "\n"; + continue; + } + + $cnt = $this->dbu->affectedRows(); + + if ($cnt != 1) { + echo "ERROR: 0 rows affected\n"; + continue; + } + + $user_group = User_group::staticGet('id', $id); + $user_group->decache(); + $user_group->free(); + + echo "OK\n"; + } } - return $db; + function fixupMessages() { + + // Do a separate DB connection + + $sth = $this->dbu->prepare("UPDATE message SET content = UNHEX(?), rendered = UNHEX(?) WHERE id = ?"); + + if (PEAR::isError($sth)) { + echo "ERROR: " . $sth->getMessage() . "\n"; + return; + } + + $sql = 'SELECT id, content, rendered FROM message ' . + 'WHERE LENGTH(content) != CHAR_LENGTH(content) '. + 'AND modified < "'.$this->max_date.'" '. + 'ORDER BY id DESC'; + + $rn = $this->dbl->query($sql); + + if (PEAR::isError($rn)) { + echo "ERROR: " . $rn->getMessage() . "\n"; + return; + } + + echo "Number of rows: " . $rn->numRows() . "\n"; + + $message = array(); + + while (DB_OK == $rn->fetchInto($message)) { + + $id = ($message[0])+0; + $content = bin2hex($message[1]); + $rendered = bin2hex($message[2]); + + echo "$id..."; + + $result =& $this->dbu->execute($sth, array($content, $rendered, $id)); + + if (PEAR::isError($result)) { + echo "ERROR: " . $result->getMessage() . "\n"; + continue; + } + + $cnt = $this->dbu->affectedRows(); + + if ($cnt != 1) { + echo "ERROR: 0 rows affected\n"; + continue; + } + + $message = Message::staticGet('id', $id); + $message->decache(); + $message->free(); + + echo "OK\n"; + } + } } -$max_id = ($argc > 1) ? $argv[1] : null; -$min_id = ($argc > 2) ? $argv[2] : null; +$max_date = ($argc > 1) ? $argv[1] : null; +$max_id = ($argc > 2) ? $argv[2] : null; +$min_id = ($argc > 3) ? $argv[3] : null; + +$fixer = new UTF8FixerUpper(array('max_date' => $max_date, + 'max_notice' => $max_id, + 'min_notice' => $min_id)); + +$fixer->fixup(); -fixup_utf8($max_id, $min_id); diff --git a/scripts/maildaemon.php b/scripts/maildaemon.php index b9facec1a..9dd647bf4 100755 --- a/scripts/maildaemon.php +++ b/scripts/maildaemon.php @@ -66,7 +66,13 @@ class MailerDaemon return true; } $msg = $this->cleanup_msg($msg); - $this->add_notice($user, $msg); + $err = $this->add_notice($user, $msg); + if (is_string($err)) { + $this->error($from, $err); + return false; + } else { + return true; + } } function error($from, $msg) @@ -130,17 +136,15 @@ class MailerDaemon 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; + return $notice; } common_broadcast_notice($notice); $this->log(LOG_INFO, 'Added notice ' . $notice->id . ' from user ' . $user->nickname); + return true; } function parse_message($fname) |