From dcfe5b24f6047aa830f107628aa3c10b9d292951 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 28 Jun 2010 15:20:50 -0400 Subject: Fix regression in 92ded7c6cb56056a89bc8b3caabd08049104898e: spewed PHP notices when checking for enclosures due to uninitialized variables. --- classes/File.php | 1 + 1 file changed, 1 insertion(+) (limited to 'classes') diff --git a/classes/File.php b/classes/File.php index 0cd31075d..0f230a6ee 100644 --- a/classes/File.php +++ b/classes/File.php @@ -302,6 +302,7 @@ class File extends Memcached_DataObject if(! isset($this->filename)){ $notEnclosureMimeTypes = array(null,'text/html','application/xhtml+xml'); + $mimetype = $this->mimetype; if($mimetype != null){ $mimetype = strtolower($this->mimetype); } -- cgit v1.2.3-54-g00ecf From 4c5098cd32599a2c376beaadb43cd9d471477c90 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 8 Jul 2010 21:17:10 +0000 Subject: Handle the case where a screen name has shifted from one Twitter ID to another --- classes/Foreign_user.php | 16 ++++++++++++++++ plugins/TwitterBridge/twitter.php | 21 +++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) (limited to 'classes') diff --git a/classes/Foreign_user.php b/classes/Foreign_user.php index 0dd94ffb9..e98a16064 100644 --- a/classes/Foreign_user.php +++ b/classes/Foreign_user.php @@ -39,6 +39,22 @@ class Foreign_user extends Memcached_DataObject return null; } + static function getByNickname($nickname, $service) + { + if (empty($nickname) || empty($service)) { + return null; + } else { + $fuser = new Foreign_user(); + $fuser->service = $service; + $fuser->nickname = $nickname; + $fuser->limit(1); + + $result = $fuser->find(true); + + return empty($result) ? null : $fuser; + } + } + function updateKeys(&$orig) { $this->_connect(); diff --git a/plugins/TwitterBridge/twitter.php b/plugins/TwitterBridge/twitter.php index 896eee2da..306ba2442 100644 --- a/plugins/TwitterBridge/twitter.php +++ b/plugins/TwitterBridge/twitter.php @@ -75,8 +75,6 @@ function save_twitter_user($twitter_id, $screen_name) if (!empty($fuser)) { - $result = true; - // Delete old record if Twitter user changed screen name if ($fuser->nickname != $screen_name) { @@ -88,6 +86,25 @@ function save_twitter_user($twitter_id, $screen_name) $screen_name, $oldname)); } + + } else { + + // Kill any old, invalid records for this screen name + + $fuser = Foreign_user::getByNickname($screen_name, TWITTER_SERVICE); + + if (!empty($fuser)) { + $fuser->delete(); + common_log( + LOG_INFO, + sprintf( + 'Twitter bridge - deteted old record for Twitter ' . + 'screen name "%s" belonging to Twitter ID %d.', + $screen_name, + $fuser->id + ) + ); + } } return add_twitter_user($twitter_id, $screen_name); -- cgit v1.2.3-54-g00ecf From dfd65a4290c7c2f6137d5508597189c4202bfaee Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 13 Jul 2010 10:51:25 -0400 Subject: push exception on missing profile down to Notice::getProfile() --- classes/Notice.php | 8 +++++++- lib/apiaction.php | 8 ++------ 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index 482bc550b..ae7e2e540 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -90,7 +90,13 @@ class Notice extends Memcached_DataObject function getProfile() { - return Profile::staticGet('id', $this->profile_id); + $profile = Profile::staticGet('id', $this->profile_id); + + if (empty($profile)) { + throw new ServerException(sprintf(_('No such profile (%d) for notice (%d)'), $this->profile_id, $this->id)); + } + + return $profile; } function delete() diff --git a/lib/apiaction.php b/lib/apiaction.php index 16dd87814..01985f0db 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -462,10 +462,6 @@ class ApiAction extends Action { $profile = $notice->getProfile(); - if (empty($profile)) { - throw new ServerException(sprintf(_('No such profile: %d'), $notice->profile_id)); - } - $entry = array(); // We trim() to avoid extraneous whitespace in the output @@ -798,7 +794,7 @@ class ApiAction extends Action $entry = $this->twitterRssEntryArray($n); $this->showTwitterRssItem($entry); } catch (Exception $e) { - common_log(LOG_ERR, "Error with notice {$n->id}: " . $e->getMessage()); + common_log(LOG_ERR, $e->getMessage()); // continue on exceptions } } @@ -808,7 +804,7 @@ class ApiAction extends Action $entry = $this->twitterRssEntryArray($notice); $this->showTwitterRssItem($entry); } catch (Exception $e) { - common_log(LOG_ERR, "Error with notice {$n->id}: " . $e->getMessage()); + common_log(LOG_ERR, $e->getMessage()); // continue on exceptions } } -- cgit v1.2.3-54-g00ecf From d73feb82d89d66593fd81f8bb5d10b1873fc9458 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 14 Jul 2010 10:38:34 -0400 Subject: cache sitemap notice and user counts for 4h --- classes/Memcached_DataObject.php | 4 ++-- plugins/Sitemap/Sitemap_notice_count.php | 4 +++- plugins/Sitemap/Sitemap_user_count.php | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) (limited to 'classes') diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index 4579f64df..a7fec365e 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -593,7 +593,7 @@ class Memcached_DataObject extends Safe_DataObject return $c->get($cacheKey); } - static function cacheSet($keyPart, $value) + static function cacheSet($keyPart, $value, $flag=null, $expiry=null) { $c = self::memcache(); @@ -603,7 +603,7 @@ class Memcached_DataObject extends Safe_DataObject $cacheKey = common_cache_key($keyPart); - return $c->set($cacheKey, $value); + return $c->set($cacheKey, $value, $flag, $expiry); } static function valueString($v) diff --git a/plugins/Sitemap/Sitemap_notice_count.php b/plugins/Sitemap/Sitemap_notice_count.php index 2a375b3e4..6e0061e97 100644 --- a/plugins/Sitemap/Sitemap_notice_count.php +++ b/plugins/Sitemap/Sitemap_notice_count.php @@ -153,7 +153,9 @@ class Sitemap_notice_count extends Memcached_DataObject $noticeCounts[$snc->notice_date] = $snc->notice_count; } - self::cacheSet('sitemap:notice:counts', $noticeCounts); + // Cache notice counts for 4 hours. + + self::cacheSet('sitemap:notice:counts', $noticeCounts, null, time() + 4 * 60 * 60); } return $noticeCounts; diff --git a/plugins/Sitemap/Sitemap_user_count.php b/plugins/Sitemap/Sitemap_user_count.php index 64b4c3442..98dd05bfe 100644 --- a/plugins/Sitemap/Sitemap_user_count.php +++ b/plugins/Sitemap/Sitemap_user_count.php @@ -154,7 +154,9 @@ class Sitemap_user_count extends Memcached_DataObject $userCounts[$suc->registration_date] = $suc->user_count; } - self::cacheSet('sitemap:user:counts', $userCounts); + // Cache user counts for 4 hours. + + self::cacheSet('sitemap:user:counts', $userCounts, null, time() + 4 * 60 * 60); } return $userCounts; -- cgit v1.2.3-54-g00ecf From d51820adc52aef962542ecc6da0607ce0118fefc Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 19 Jul 2010 13:43:17 -0700 Subject: Change the cache window on notices from 61 to 200, the max number of notices available at one time through the API. Note: this will require a memcache restart. --- classes/Notice.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index ae7e2e540..8552248ba 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -42,10 +42,10 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { */ require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; -/* We keep the first three 20-notice pages, plus one for pagination check, +/* We keep 200 notices, the max number of notices available per API request, * in the memcached cache. */ -define('NOTICE_CACHE_WINDOW', 61); +define('NOTICE_CACHE_WINDOW', 200); define('MAX_BOXCARS', 128); -- cgit v1.2.3-54-g00ecf From a65b3f171c4d23af8ca844439ad08959eb760b86 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 19 Jul 2010 17:38:11 -0700 Subject: Revert "Change the cache window on notices from 61 to 200, the max number" This reverts commit d51820adc52aef962542ecc6da0607ce0118fefc. --- classes/Notice.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index 8552248ba..ae7e2e540 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -42,10 +42,10 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { */ require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; -/* We keep 200 notices, the max number of notices available per API request, +/* We keep the first three 20-notice pages, plus one for pagination check, * in the memcached cache. */ -define('NOTICE_CACHE_WINDOW', 200); +define('NOTICE_CACHE_WINDOW', 61); define('MAX_BOXCARS', 128); -- cgit v1.2.3-54-g00ecf From 9b899eea750fd54c75fbb58e48526a5cab169f6c Mon Sep 17 00:00:00 2001 From: Eric Helgeson Date: Mon, 19 Jul 2010 21:09:09 -0500 Subject: Make some messages gender neutral. --- actions/all.php | 4 ++-- actions/favor.php | 2 +- actions/finishremotesubscribe.php | 2 +- actions/nudge.php | 2 +- actions/replies.php | 6 +++--- actions/showfavorites.php | 6 +++--- actions/showstream.php | 4 ++-- classes/User.php | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) (limited to 'classes') diff --git a/actions/all.php b/actions/all.php index 9c01b6393..ac4e321d0 100644 --- a/actions/all.php +++ b/actions/all.php @@ -143,10 +143,10 @@ class AllAction extends ProfileAction $message .= _('Try subscribing to more people, [join a group](%%action.groups%%) or post something yourself.'); } else { // TRANS: %1$s is user nickname, %2$s is user nickname, %2$s is user nickname prefixed with "@" - $message .= sprintf(_('You can try to [nudge %1$s](../%2$s) from his profile or [post something to his or her attention](%%%%action.newnotice%%%%?status_textarea=%3$s).'), $this->user->nickname, $this->user->nickname, '@' . $this->user->nickname); + $message .= sprintf(_('You can try to [nudge %1$s](../%2$s) from their profile or [post something to their attention](%%%%action.newnotice%%%%?status_textarea=%3$s).'), $this->user->nickname, $this->user->nickname, '@' . $this->user->nickname); } } else { - $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to his or her attention.'), $this->user->nickname); + $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to their attention.'), $this->user->nickname); } $this->elementStart('div', 'guide'); diff --git a/actions/favor.php b/actions/favor.php index 475912fd0..01976a38f 100644 --- a/actions/favor.php +++ b/actions/favor.php @@ -104,7 +104,7 @@ class FavorAction extends Action } /** - * Notifies a user when his notice is favorited. + * Notifies a user when their notice is favorited. * * @param class $notice favorited notice * @param class $user user declaring a favorite diff --git a/actions/finishremotesubscribe.php b/actions/finishremotesubscribe.php index ac51ddec3..0325f6adb 100644 --- a/actions/finishremotesubscribe.php +++ b/actions/finishremotesubscribe.php @@ -37,7 +37,7 @@ require_once INSTALLDIR.'/lib/omb.php'; * Handler for remote subscription finish callback * * When a remote user subscribes a local user, a redirect to this action is - * issued after the remote user authorized his service to subscribe. + * issued after the remote user authorized their service to subscribe. * * @category Action * @package Laconica diff --git a/actions/nudge.php b/actions/nudge.php index cf5f773e7..32ae8587c 100644 --- a/actions/nudge.php +++ b/actions/nudge.php @@ -82,7 +82,7 @@ class NudgeAction extends Action } if (!$other->email || !$other->emailnotifynudge) { - $this->clientError(_('This user doesn\'t allow nudges or hasn\'t confirmed or set his email yet.')); + $this->clientError(_('This user doesn\'t allow nudges or hasn\'t confirmed or set their email yet.')); return; } diff --git a/actions/replies.php b/actions/replies.php index 608f71d6e..0474a6de0 100644 --- a/actions/replies.php +++ b/actions/replies.php @@ -196,18 +196,18 @@ class RepliesAction extends OwnerDesignAction function showEmptyListMessage() { - $message = sprintf(_('This is the timeline showing replies to %1$s but %2$s hasn\'t received a notice to his attention yet.'), $this->user->nickname, $this->user->nickname) . ' '; + $message = sprintf(_('This is the timeline showing replies to %1$s but %2$s hasn\'t received a notice to their attention yet.'), $this->user->nickname, $this->user->nickname) . ' '; if (common_logged_in()) { $current_user = common_current_user(); if ($this->user->id === $current_user->id) { $message .= _('You can engage other users in a conversation, subscribe to more people or [join groups](%%action.groups%%).'); } else { - $message .= sprintf(_('You can try to [nudge %1$s](../%2$s) or [post something to his or her attention](%%%%action.newnotice%%%%?status_textarea=%3$s).'), $this->user->nickname, $this->user->nickname, '@' . $this->user->nickname); + $message .= sprintf(_('You can try to [nudge %1$s](../%2$s) or [post something to their attention](%%%%action.newnotice%%%%?status_textarea=%3$s).'), $this->user->nickname, $this->user->nickname, '@' . $this->user->nickname); } } else { - $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to his or her attention.'), $this->user->nickname); + $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to their attention.'), $this->user->nickname); } $this->elementStart('div', 'guide'); diff --git a/actions/showfavorites.php b/actions/showfavorites.php index 7f3c77ee2..d8042e91c 100644 --- a/actions/showfavorites.php +++ b/actions/showfavorites.php @@ -119,7 +119,7 @@ class ShowfavoritesAction extends OwnerDesignAction if (!empty($cur) && $cur->id == $this->user->id) { // Show imported/gateway notices as well as local if - // the user is looking at his own favorites + // the user is looking at their own favorites $this->notice = $this->user->favoriteNotices(true, ($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); @@ -205,11 +205,11 @@ class ShowfavoritesAction extends OwnerDesignAction if ($this->user->id === $current_user->id) { $message = _('You haven\'t chosen any favorite notices yet. Click the fave button on notices you like to bookmark them for later or shed a spotlight on them.'); } else { - $message = sprintf(_('%s hasn\'t added any notices to his favorites yet. Post something interesting they would add to their favorites :)'), $this->user->nickname); + $message = sprintf(_('%s hasn\'t added any favorite notices yet. Post something interesting they would add to their favorites :)'), $this->user->nickname); } } else { - $message = sprintf(_('%s hasn\'t added any notices to his favorites yet. Why not [register an account](%%%%action.register%%%%) and then post something interesting they would add to their favorites :)'), $this->user->nickname); + $message = sprintf(_('%s hasn\'t added any favorite notices yet. Why not [register an account](%%%%action.register%%%%) and then post something interesting they would add to their favorites :)'), $this->user->nickname); } $this->elementStart('div', 'guide'); diff --git a/actions/showstream.php b/actions/showstream.php index f9407e35a..956c05741 100644 --- a/actions/showstream.php +++ b/actions/showstream.php @@ -204,11 +204,11 @@ class ShowstreamAction extends ProfileAction if ($this->user->id === $current_user->id) { $message .= _('Seen anything interesting recently? You haven\'t posted any notices yet, now would be a good time to start :)'); } else { - $message .= sprintf(_('You can try to nudge %1$s or [post something to his or her attention](%%%%action.newnotice%%%%?status_textarea=%2$s).'), $this->user->nickname, '@' . $this->user->nickname); + $message .= sprintf(_('You can try to nudge %1$s or [post something to their attention](%%%%action.newnotice%%%%?status_textarea=%2$s).'), $this->user->nickname, '@' . $this->user->nickname); } } else { - $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to his or her attention.'), $this->user->nickname); + $message .= sprintf(_('Why not [register an account](%%%%action.register%%%%) and then nudge %s or post a notice to their attention.'), $this->user->nickname); } $this->elementStart('div', 'guide'); diff --git a/classes/User.php b/classes/User.php index 2abb7eeb6..cf8d4527b 100644 --- a/classes/User.php +++ b/classes/User.php @@ -524,7 +524,7 @@ class User extends Memcached_DataObject if ($this->id == $other->id) { common_log(LOG_WARNING, sprintf( - "Profile ID %d (%s) tried to block his or herself.", + "Profile ID %d (%s) tried to block themself.", $this->id, $this->nickname ) -- cgit v1.2.3-54-g00ecf From 7065450f03078fb1ac2105b75f9c7a4e052bca9c Mon Sep 17 00:00:00 2001 From: James Walker Date: Tue, 20 Jul 2010 17:34:58 -0700 Subject: normalizing tags for status_network --- classes/Status_network.php | 52 +++++++++++++++++++++++++++++-- classes/Status_network_tag.php | 69 +++++++++++++++++++++++++++++++++++++++++ classes/status_network.ini | 15 +++++++-- db/site.sql | 16 +++++++--- scripts/settag.php | 12 ++----- scripts/setup_status_network.sh | 6 ++-- 6 files changed, 150 insertions(+), 20 deletions(-) create mode 100644 classes/Status_network_tag.php (limited to 'classes') diff --git a/classes/Status_network.php b/classes/Status_network.php index 64016dd79..d1ca454e2 100644 --- a/classes/Status_network.php +++ b/classes/Status_network.php @@ -27,7 +27,8 @@ class Status_network extends Safe_DataObject /* the code below is auto generated do not remove the above tag */ public $__table = 'status_network'; // table name - public $nickname; // varchar(64) primary_key not_null + public $site_id; // int(4) primary_key not_null + public $nickname; // varchar(64) unique_key not_null public $hostname; // varchar(255) unique_key public $pathname; // varchar(255) unique_key public $dbhost; // varchar(255) @@ -39,7 +40,6 @@ class Status_network extends Safe_DataObject public $logo; // varchar(255) public $created; // datetime() not_null public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP - public $tags; // text /* Static get */ function staticGet($k,$v=NULL) { @@ -308,9 +308,55 @@ class Status_network extends Safe_DataObject */ function getTags() { - return array_filter(explode("|", strval($this->tags))); + $result = array(); + + $tags = new Status_network_tag(); + $tags->site_id = $this->site_id; + if ($tags->find()) { + while ($tags->fetch()) { + $result[] = $tags->tag; + } + } + + return $result; } + /** + * Save a given set of tags + * @param array tags + */ + function setTags($tags) + { + $this->clearTags(); + foreach ($tags as $tag) { + $snt = new Status_network_tag(); + $snt->site_id = $this->site_id; + $snt->tag = $tag; + $snt->created = common_sql_now(); + + $id = $snt->insert(); + if (!$id) { + throw new Exception(_("Unable to save tag.")); + } + } + + return true; + } + + function clearTags() + { + $tag = new Status_network_tag(); + $tag->site_id = $this->site_id; + + if ($tag->find()) { + while($tag->fetch()) { + $tag->delete(); + } + } + + $tag->free(); + } + /** * Check if this site record has a particular meta-info tag attached. * @param string $tag diff --git a/classes/Status_network_tag.php b/classes/Status_network_tag.php new file mode 100644 index 000000000..18c508bc8 --- /dev/null +++ b/classes/Status_network_tag.php @@ -0,0 +1,69 @@ +. + */ + +if (!defined('STATUSNET')) { exit(1); } + +class Status_network_tag extends Safe_DataObject +{ + ###START_AUTOCODE + /* the code below is auto generated do not remove the above tag */ + + public $__table = 'status_network_tag'; // table name + public $site_id; // int(4) primary_key not_null + public $tag; // varchar(64) primary_key not_null + public $created; // datetime() not_null + + + function __construct() + { + global $config; + global $_DB_DATAOBJECT; + + $sn = new Status_network(); + $sn->_connect(); + + $config['db']['table_'. $this->__table] = $sn->_database; + + $this->_connect(); + } + + + /* Static get */ + function staticGet($k,$v=null) + { + $i = DB_DataObject::staticGet('Status_network_tag',$k,$v); + + // Don't use local process cache; if we're fetching multiple + // times it's because we're reloading it in a long-running + // process; we need a fresh copy! + global $_DB_DATAOBJECT; + unset($_DB_DATAOBJECT['CACHE']['status_network_tag']); + return $i; + } + + /* the code above is auto generated do not remove the tag below */ + ###END_AUTOCODE + + + + function pkeyGet($kv) + { + return Memcached_DataObject::pkeyGet('Status_network_tag', $kv); + } +} diff --git a/classes/status_network.ini b/classes/status_network.ini index adb71cba7..83226e915 100644 --- a/classes/status_network.ini +++ b/classes/status_network.ini @@ -1,4 +1,5 @@ [status_network] +side_id = 129 nickname = 130 hostname = 2 pathname = 2 @@ -11,9 +12,19 @@ theme = 2 logo = 2 created = 142 modified = 384 -tags = 34 [status_network__keys] -nickname = K +site_id = K +nickname = U hostname = U pathname = U + +[status_network_tag] +site_id = 129 +tag = 130 +created = 142 + +[status_network_tag__keys] +site_id = K +tag = K + diff --git a/db/site.sql b/db/site.sql index 791303bd5..bc425841d 100644 --- a/db/site.sql +++ b/db/site.sql @@ -1,8 +1,9 @@ /* For managing multiple sites */ create table status_network ( - - nickname varchar(64) primary key comment 'nickname', + + site_id integer auto_increment primary key comment 'unique id', + nickname varchar(64) unique key comment 'nickname', hostname varchar(255) unique key comment 'alternate hostname if any', pathname varchar(255) unique key comment 'alternate pathname if any', @@ -15,9 +16,16 @@ create table status_network ( theme varchar(255) comment 'theme name', logo varchar(255) comment 'site logo', - tags text comment 'site meta-info tags (pipe-separated)', - created datetime not null comment 'date this record was created', modified timestamp comment 'date this record was modified' ) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci; + +create table status_network_tag ( + site_id integer comment 'unique id', + tag varchar(64) comment 'tag name', + created datetime not null comment 'date the record was created', + + constraint primary key (site_id, tag) +) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci; + diff --git a/scripts/settag.php b/scripts/settag.php index d1b06ff10..ca260f7bf 100644 --- a/scripts/settag.php +++ b/scripts/settag.php @@ -39,11 +39,10 @@ if (count($args) < 1) { } $nickname = $args[0]; - $sn = Status_network::memGet('nickname', $nickname); if (empty($sn)) { - print "No such site.\n"; + print "No such site ($nickname).\n"; exit(-1); } @@ -54,16 +53,13 @@ if (count($args) == 1) { exit(0); } $tag = $args[1]; - $i = array_search($tag, $tags); if ($i !== false) { if (have_option('d', 'delete')) { // Delete unset($tags[$i]); - $orig = clone($sn); - $sn->tags = implode('|', $tags); - $result = $sn->update($orig); + $result = $sn->setTags($tags); if (!$result) { print "Couldn't update.\n"; exit(-1); @@ -78,9 +74,7 @@ if ($i !== false) { exit(-1); } else { $tags[] = $tag; - $orig = clone($sn); - $sn->tags = implode('|', $tags); - $result = $sn->update($orig); + $result = $sn->setTags($tags); if (!$result) { print "Couldn't update.\n"; exit(-1); diff --git a/scripts/setup_status_network.sh b/scripts/setup_status_network.sh index 4ebb696c7..3dd739030 100755 --- a/scripts/setup_status_network.sh +++ b/scripts/setup_status_network.sh @@ -44,8 +44,8 @@ mysql -h $DBHOST -u $ADMIN --password=$ADMINPASS $SITEDB << ENDOFCOMMANDS GRANT ALL ON $database.* TO '$username'@'localhost' IDENTIFIED BY '$password'; GRANT ALL ON $database.* TO '$username'@'%' IDENTIFIED BY '$password'; -INSERT INTO status_network (nickname, dbhost, dbuser, dbpass, dbname, sitename, created, tags) -VALUES ('$nickname', '$DBHOSTNAME', '$username', '$password', '$database', '$sitename', now(), '$tags'); +INSERT INTO status_network (nickname, dbhost, dbuser, dbpass, dbname, sitename, created) +VALUES ('$nickname', '$DBHOSTNAME', '$username', '$password', '$database', '$sitename', now()); ENDOFCOMMANDS @@ -56,6 +56,8 @@ done php $PHPBASE/scripts/checkschema.php -s"$server" +php $PHPBASE/scripts/settag.php -s"$server" "$nickname" "$tags" + php $PHPBASE/scripts/registeruser.php \ -s"$server" \ -n"$nickname" \ -- cgit v1.2.3-54-g00ecf From 25e963769c866d6847064fd88172483a9c6b1964 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Wed, 21 Jul 2010 12:29:47 -0700 Subject: Revert "Revert "Change the cache window on notices from 61 to 200, the max number"" This reverts commit a65b3f171c4d23af8ca844439ad08959eb760b86. --- classes/Notice.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index ae7e2e540..8552248ba 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -42,10 +42,10 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { */ require_once INSTALLDIR.'/classes/Memcached_DataObject.php'; -/* We keep the first three 20-notice pages, plus one for pagination check, +/* We keep 200 notices, the max number of notices available per API request, * in the memcached cache. */ -define('NOTICE_CACHE_WINDOW', 61); +define('NOTICE_CACHE_WINDOW', 200); define('MAX_BOXCARS', 128); -- cgit v1.2.3-54-g00ecf From 29b8a6a18f67de74fb6adb9e91c10e7d1577c067 Mon Sep 17 00:00:00 2001 From: James Walker Date: Wed, 28 Jul 2010 11:57:54 -0400 Subject: don't try to save empty tags --- classes/Status_network.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'classes') diff --git a/classes/Status_network.php b/classes/Status_network.php index d1ca454e2..339f4c813 100644 --- a/classes/Status_network.php +++ b/classes/Status_network.php @@ -329,14 +329,16 @@ class Status_network extends Safe_DataObject { $this->clearTags(); foreach ($tags as $tag) { - $snt = new Status_network_tag(); - $snt->site_id = $this->site_id; - $snt->tag = $tag; - $snt->created = common_sql_now(); - - $id = $snt->insert(); - if (!$id) { - throw new Exception(_("Unable to save tag.")); + if (!empty($tag)) { + $snt = new Status_network_tag(); + $snt->site_id = $this->site_id; + $snt->tag = $tag; + $snt->created = common_sql_now(); + + $id = $snt->insert(); + if (!$id) { + throw new Exception(_("Unable to save tag.")); + } } } -- cgit v1.2.3-54-g00ecf From 5688c635a62ea109a9aa9565e40e994ea984cd95 Mon Sep 17 00:00:00 2001 From: James Walker Date: Wed, 28 Jul 2010 12:13:53 -0400 Subject: backwards compatibility for old tags format in hasTag --- classes/Status_network.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'classes') diff --git a/classes/Status_network.php b/classes/Status_network.php index 339f4c813..a0f3ba5f7 100644 --- a/classes/Status_network.php +++ b/classes/Status_network.php @@ -318,6 +318,11 @@ class Status_network extends Safe_DataObject } } + // XXX : for backwards compatibility + if (empty($result)) { + return explode('|', $this->tags); + } + return $result; } -- cgit v1.2.3-54-g00ecf From e694da24a9b6ec242fd49b5ce6e012d0a2a28679 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Wed, 28 Jul 2010 22:17:54 +0200 Subject: Number parameters --- classes/File.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'classes') diff --git a/classes/File.php b/classes/File.php index 0f230a6ee..ba8cea9d9 100644 --- a/classes/File.php +++ b/classes/File.php @@ -182,8 +182,8 @@ class File extends Memcached_DataObject function isRespectsQuota($user,$fileSize) { if ($fileSize > common_config('attachments', 'file_quota')) { - return sprintf(_('No file may be larger than %d bytes ' . - 'and the file you sent was %d bytes. Try to upload a smaller version.'), + return sprintf(_('No file may be larger than %1$d bytes ' . + 'and the file you sent was %2$d bytes. Try to upload a smaller version.'), common_config('attachments', 'file_quota'), $fileSize); } -- cgit v1.2.3-54-g00ecf From f241cdcbb3485c353bee8d5ee106ebc48e69ed01 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Thu, 29 Jul 2010 11:34:58 +0200 Subject: * mark two untranslatable server exceptions as translatable * number parameters when multiple are user in a message * update translator documentation --- classes/Notice.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index 8552248ba..606803b6f 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -93,7 +93,9 @@ class Notice extends Memcached_DataObject $profile = Profile::staticGet('id', $this->profile_id); if (empty($profile)) { - throw new ServerException(sprintf(_('No such profile (%d) for notice (%d)'), $this->profile_id, $this->id)); + // TRANS: Server exception thrown when a user profile for a notice cannot be found. + // TRANS: %1$d is a profile ID (number), %2$d is a notice ID (number). + throw new ServerException(sprintf(_('No such profile (%1$d) for notice (%2$d).'), $this->profile_id, $this->id)); } return $profile; @@ -254,27 +256,32 @@ class Notice extends Memcached_DataObject $final = common_shorten_links($content); if (Notice::contentTooLong($final)) { + // TRANS: Client exception thrown if a notice contains too many characters. throw new ClientException(_('Problem saving notice. Too long.')); } if (empty($profile)) { + // TRANS: Client exception thrown when trying to save a notice for an unknown user. throw new ClientException(_('Problem saving notice. Unknown user.')); } if (common_config('throttle', 'enabled') && !Notice::checkEditThrottle($profile_id)) { common_log(LOG_WARNING, 'Excessive posting by profile #' . $profile_id . '; throttled.'); + // TRANS: Client exception thrown when a user tries to post too many notices in a given time frame. throw new ClientException(_('Too many notices too fast; take a breather '. 'and post again in a few minutes.')); } if (common_config('site', 'dupelimit') > 0 && !Notice::checkDupes($profile_id, $final)) { common_log(LOG_WARNING, 'Dupe posting by profile #' . $profile_id . '; throttled.'); + // TRANS: Client exception thrown when a user tries to post too many duplicate notices in a given time frame. throw new ClientException(_('Too many duplicate messages too quickly;'. ' take a breather and post again in a few minutes.')); } if (!$profile->hasRight(Right::NEWNOTICE)) { common_log(LOG_WARNING, "Attempted post from user disallowed to post: " . $profile->nickname); + // TRANS: Client exception thrown when a user tries to post while being banned. throw new ClientException(_('You are banned from posting notices on this site.')); } @@ -341,6 +348,7 @@ class Notice extends Memcached_DataObject if (!$id) { common_log_db_error($notice, 'INSERT', __FILE__); + // TRANS: Server exception thrown when a notice cannot be saved. throw new ServerException(_('Problem saving notice.')); } @@ -367,6 +375,7 @@ class Notice extends Memcached_DataObject if ($changed) { if (!$notice->update($orig)) { common_log_db_error($notice, 'UPDATE', __FILE__); + // TRANS: Server exception thrown when a notice cannot be updated. throw new ServerException(_('Problem saving notice.')); } } @@ -878,7 +887,8 @@ class Notice extends Memcached_DataObject function saveKnownGroups($group_ids) { if (!is_array($group_ids)) { - throw new ServerException("Bad type provided to saveKnownGroups"); + // TRANS: Server exception thrown when no array is provided to the method saveKnownGroups(). + throw new ServerException(_("Bad type provided to saveKnownGroups")); } $groups = array(); @@ -976,6 +986,7 @@ class Notice extends Memcached_DataObject if (!$result) { common_log_db_error($gi, 'INSERT', __FILE__); + // TRANS: Server exception thrown when an update for a group inbox fails. throw new ServerException(_('Problem saving group inbox.')); } @@ -1081,7 +1092,9 @@ class Notice extends Memcached_DataObject if (!$id) { common_log_db_error($reply, 'INSERT', __FILE__); - throw new ServerException("Couldn't save reply for {$this->id}, {$mentioned->id}"); + // TRANS: Server exception thrown when a reply cannot be saved. + // TRANS: First arg is a notice ID, second ID is the ID of the mentioned user. + throw new ServerException(_("Couldn't save reply for {$this->id}, {$mentioned->id}")); } else { $replied[$mentioned->id] = 1; self::blow('reply:stream:%d', $mentioned->id); -- cgit v1.2.3-54-g00ecf From e7acb45b5733e97ab9504aff5e4255a17fe5c6de Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Thu, 29 Jul 2010 12:58:48 +0200 Subject: * add string for translation with translator documentation * add FIXMEs for strings that may need i18n, but leaving decision to other dev(s) --- classes/Memcached_DataObject.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'classes') diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index a7fec365e..04cd6c120 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -235,6 +235,7 @@ class Memcached_DataObject extends Safe_DataObject $pkey[] = $key; $pval[] = self::valueString($this->$key); } else { + // FIXME: i18n? throw new Exception("Unknown key type $key => $type for " . $this->tableName()); } } @@ -282,6 +283,7 @@ class Memcached_DataObject extends Safe_DataObject } else if ($type == 'fulltext') { $search_engine = new MySQLSearch($this, $table); } else { + // FIXME: i18n? throw new ServerException('Unknown search type: ' . $type); } } else { @@ -527,7 +529,8 @@ class Memcached_DataObject extends Safe_DataObject } if (!$dsn) { - throw new Exception("No database name / dsn found anywhere"); + // TRANS: Exception thrown when database name or Data Source Name could not be found. + throw new Exception(_("No database name / DSN found anywhere")); } return $dsn; @@ -577,6 +580,7 @@ class Memcached_DataObject extends Safe_DataObject if ($message instanceof PEAR_Error) { $message = $message->getMessage(); } + // FIXME: i18n? throw new ServerException("[$id] DB_DataObject error [$type]: $message"); } @@ -619,9 +623,11 @@ class Memcached_DataObject extends Safe_DataObject case 'sql': case 'datetime': case 'time': + // FIXME: i18n? throw new ServerException("Unhandled DB_DataObject_Cast type passed as cacheKey value: '$v->type'"); break; default: + // FIXME: i18n? throw new ServerException("Unknown DB_DataObject_Cast type passed as cacheKey value: '$v->type'"); break; } -- cgit v1.2.3-54-g00ecf From 5813ecada276147d120d42ce2a92343313cf0029 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Thu, 29 Jul 2010 13:01:04 +0200 Subject: * add translator documentation * mark strings for translation * add FIXME for unclear/confusing message --- classes/File.php | 20 +++++++++++++++----- classes/Group_member.php | 3 +++ classes/Local_group.php | 1 + classes/Login_token.php | 2 ++ 4 files changed, 21 insertions(+), 5 deletions(-) (limited to 'classes') diff --git a/classes/File.php b/classes/File.php index ba8cea9d9..18ad82892 100644 --- a/classes/File.php +++ b/classes/File.php @@ -139,7 +139,8 @@ class File extends Memcached_DataObject $redir_url = $redir_data; $redir_data = array(); } else { - throw new ServerException("Can't process url '$given_url'"); + // TRANS: Server exception thrown when a URL cannot be processed. + throw new ServerException(_("Cannot process URL '$given_url'")); } // TODO: max field length if ($redir_url === $given_url || strlen($redir_url) > 255 || !$followRedirects) { @@ -169,7 +170,9 @@ class File extends Memcached_DataObject if (empty($x)) { $x = File::staticGet($file_id); if (empty($x)) { - throw new ServerException("Robin thinks something is impossible."); + // FIXME: This could possibly be a clearer message :) + // TRANS: Server exception thrown when... Robin thinks something is impossible! + throw new ServerException(_("Robin thinks something is impossible.")); } } @@ -182,6 +185,8 @@ class File extends Memcached_DataObject function isRespectsQuota($user,$fileSize) { if ($fileSize > common_config('attachments', 'file_quota')) { + // TRANS: Message given if an upload is larger than the configured maximum. + // TRANS: %1$d is the byte limit for uploads, %2$d is the byte count for the uploaded file. return sprintf(_('No file may be larger than %1$d bytes ' . 'and the file you sent was %2$d bytes. Try to upload a smaller version.'), common_config('attachments', 'file_quota'), $fileSize); @@ -192,6 +197,8 @@ class File extends Memcached_DataObject $this->fetch(); $total = $this->total + $fileSize; if ($total > common_config('attachments', 'user_quota')) { + // TRANS: Message given if an upload would exceed user quota. + // TRANS: %d (number) is the user quota in bytes. return sprintf(_('A file this large would exceed your user quota of %d bytes.'), common_config('attachments', 'user_quota')); } $query .= ' AND EXTRACT(month FROM file.modified) = EXTRACT(month FROM now()) and EXTRACT(year FROM file.modified) = EXTRACT(year FROM now())'; @@ -199,6 +206,8 @@ class File extends Memcached_DataObject $this->fetch(); $total = $this->total + $fileSize; if ($total > common_config('attachments', 'monthly_quota')) { + // TRANS: Message given id an upload would exceed a user's monthly quota. + // TRANS: $d (number) is the monthly user quota in bytes. return sprintf(_('A file this large would exceed your monthly quota of %d bytes.'), common_config('attachments', 'monthly_quota')); } return true; @@ -235,7 +244,8 @@ class File extends Memcached_DataObject static function path($filename) { if (!self::validFilename($filename)) { - throw new ClientException("Invalid filename"); + // TRANS: Client exception thrown if a file upload does not have a valid name. + throw new ClientException(_("Invalid filename.")); } $dir = common_config('attachments', 'dir'); @@ -249,7 +259,8 @@ class File extends Memcached_DataObject static function url($filename) { if (!self::validFilename($filename)) { - throw new ClientException("Invalid filename"); + // TRANS: Client exception thrown if a file upload does not have a valid name. + throw new ClientException(_("Invalid filename.")); } if(common_config('site','private')) { @@ -342,4 +353,3 @@ class File extends Memcached_DataObject return !empty($enclosure); } } - diff --git a/classes/Group_member.php b/classes/Group_member.php index 7b1760f76..2239461be 100644 --- a/classes/Group_member.php +++ b/classes/Group_member.php @@ -38,6 +38,7 @@ class Group_member extends Memcached_DataObject if (!$result) { common_log_db_error($member, 'INSERT', __FILE__); + // TRANS: Exception thrown when joining a group fails. throw new Exception(_("Group join failed.")); } @@ -50,6 +51,7 @@ class Group_member extends Memcached_DataObject 'profile_id' => $profile_id)); if (empty($member)) { + // TRANS: Exception thrown when trying to leave a group the user is not a member of. throw new Exception(_("Not part of group.")); } @@ -57,6 +59,7 @@ class Group_member extends Memcached_DataObject if (!$result) { common_log_db_error($member, 'INSERT', __FILE__); + // TRANS: Exception thrown when trying to leave a group fails. throw new Exception(_("Group leave failed.")); } diff --git a/classes/Local_group.php b/classes/Local_group.php index 42312ec63..ccd0125cf 100644 --- a/classes/Local_group.php +++ b/classes/Local_group.php @@ -38,6 +38,7 @@ class Local_group extends Memcached_DataObject $this->encache(); } else { common_log_db_error($local, 'UPDATE', __FILE__); + // TRANS: Server exception thrown when updating a local group fails. throw new ServerException(_('Could not update local group.')); } diff --git a/classes/Login_token.php b/classes/Login_token.php index 51dc61262..20d5d9dbc 100644 --- a/classes/Login_token.php +++ b/classes/Login_token.php @@ -73,6 +73,8 @@ class Login_token extends Memcached_DataObject if (!$result) { common_log_db_error($login_token, 'INSERT', __FILE__); + // TRANS: Exception thrown when trying creating a login token failed. + // TRANS: %s is the user nickname for which token creation failed. throw new Exception(sprintf(_('Could not create login token for %s'), $user->nickname)); } -- cgit v1.2.3-54-g00ecf From 312c6b68654a6bc5239526c61f23636833e5b502 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Thu, 29 Jul 2010 13:18:41 +0200 Subject: * add FIXME for messages that may need i18n. * trailing whitespace removed. --- classes/Safe_DataObject.php | 71 ++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 37 deletions(-) (limited to 'classes') diff --git a/classes/Safe_DataObject.php b/classes/Safe_DataObject.php index e926cb0d5..16d7165d6 100644 --- a/classes/Safe_DataObject.php +++ b/classes/Safe_DataObject.php @@ -116,6 +116,7 @@ class Safe_DataObject extends DB_DataObject if ($this->_call($method, $params, $return)) { return $return; } else { + // FIXME: i18n? throw new Exception('Call to undefined method ' . get_class($this) . '::' . $method); } @@ -125,7 +126,7 @@ class Safe_DataObject extends DB_DataObject * Work around memory-leak bugs... * Had to copy-paste the whole function in order to patch a couple lines of it. * Would be nice if this code was better factored. - * + * * @param optional string name of database to assign / read * @param optional array structure of database, and keys * @param optional array table links @@ -136,108 +137,103 @@ class Safe_DataObject extends DB_DataObject */ function databaseStructure() { - global $_DB_DATAOBJECT; - - // Assignment code - + + // Assignment code + if ($args = func_get_args()) { - + if (count($args) == 1) { - + // this returns all the tables and their structure.. if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) { $this->debug("Loading Generator as databaseStructure called with args",1); } - + $x = new DB_DataObject; $x->_database = $args[0]; $this->_connect(); $DB = &$_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5]; - + $tables = $DB->getListOf('tables'); - class_exists('DB_DataObject_Generator') ? '' : + class_exists('DB_DataObject_Generator') ? '' : require_once 'DB/DataObject/Generator.php'; - + foreach($tables as $table) { $y = new DB_DataObject_Generator; $y->fillTableSchema($x->_database,$table); } - return $_DB_DATAOBJECT['INI'][$x->_database]; + return $_DB_DATAOBJECT['INI'][$x->_database]; } else { - + $_DB_DATAOBJECT['INI'][$args[0]] = isset($_DB_DATAOBJECT['INI'][$args[0]]) ? $_DB_DATAOBJECT['INI'][$args[0]] + $args[1] : $args[1]; - + if (isset($args[1])) { $_DB_DATAOBJECT['LINKS'][$args[0]] = isset($_DB_DATAOBJECT['LINKS'][$args[0]]) ? $_DB_DATAOBJECT['LINKS'][$args[0]] + $args[2] : $args[2]; } return true; } - + } - - - + if (!$this->_database) { $this->_connect(); } - + // loaded already? if (!empty($_DB_DATAOBJECT['INI'][$this->_database])) { - + // database loaded - but this is table is not available.. if ( - empty($_DB_DATAOBJECT['INI'][$this->_database][$this->__table]) + empty($_DB_DATAOBJECT['INI'][$this->_database][$this->__table]) && !empty($_DB_DATAOBJECT['CONFIG']['proxy']) ) { if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) { $this->debug("Loading Generator to fetch Schema",1); } - class_exists('DB_DataObject_Generator') ? '' : + class_exists('DB_DataObject_Generator') ? '' : require_once 'DB/DataObject/Generator.php'; - - + + $x = new DB_DataObject_Generator; $x->fillTableSchema($this->_database,$this->__table); } return true; } - - + if (empty($_DB_DATAOBJECT['CONFIG'])) { DB_DataObject::_loadConfig(); } - + // if you supply this with arguments, then it will take those // as the database and links array... - + $schemas = isset($_DB_DATAOBJECT['CONFIG']['schema_location']) ? array("{$_DB_DATAOBJECT['CONFIG']['schema_location']}/{$this->_database}.ini") : array() ; - + if (isset($_DB_DATAOBJECT['CONFIG']["ini_{$this->_database}"])) { $schemas = is_array($_DB_DATAOBJECT['CONFIG']["ini_{$this->_database}"]) ? $_DB_DATAOBJECT['CONFIG']["ini_{$this->_database}"] : explode(PATH_SEPARATOR,$_DB_DATAOBJECT['CONFIG']["ini_{$this->_database}"]); } - - + /* BEGIN CHANGED FROM UPSTREAM */ $_DB_DATAOBJECT['INI'][$this->_database] = $this->parseIniFiles($schemas); /* END CHANGED FROM UPSTREAM */ - // now have we loaded the structure.. - + // now have we loaded the structure.. + if (!empty($_DB_DATAOBJECT['INI'][$this->_database][$this->__table])) { return true; } // - if not try building it.. if (!empty($_DB_DATAOBJECT['CONFIG']['proxy'])) { - class_exists('DB_DataObject_Generator') ? '' : + class_exists('DB_DataObject_Generator') ? '' : require_once 'DB/DataObject/Generator.php'; - + $x = new DB_DataObject_Generator; $x->fillTableSchema($this->_database,$this->__table); // should this fail!!!??? @@ -245,7 +241,8 @@ class Safe_DataObject extends DB_DataObject } $this->debug("Cant find database schema: {$this->_database}/{$this->__table} \n". "in links file data: " . print_r($_DB_DATAOBJECT['INI'],true),"databaseStructure",5); - // we have to die here!! - it causes chaos if we dont (including looping forever!) + // we have to die here!! - it causes chaos if we don't (including looping forever!) + // FIXME: i18n? $this->raiseError( "Unable to load schema for database and table (turn debugging up to 5 for full error message)", DB_DATAOBJECT_ERROR_INVALIDARGS, PEAR_ERROR_DIE); return false; } @@ -271,7 +268,7 @@ class Safe_DataObject extends DB_DataObject if (file_exists($ini) && is_file($ini)) { $data = array_merge($data, parse_ini_file($ini, true)); - if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) { + if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) { if (!is_readable ($ini)) { $this->debug("ini file is not readable: $ini","databaseStructure",1); } else { -- cgit v1.2.3-54-g00ecf From 125ff142e871d4cde780335d6a4f16d5f59bca83 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Thu, 29 Jul 2010 13:36:08 +0200 Subject: * mark a few message for translation * add translator documentation --- classes/Message.php | 3 +++ classes/Profile.php | 8 ++++++-- classes/Remote_profile.php | 3 ++- classes/Status_network.php | 1 + classes/Subscription.php | 15 +++++++++++---- classes/User.php | 4 ++-- classes/User_group.php | 5 +++++ 7 files changed, 30 insertions(+), 9 deletions(-) (limited to 'classes') diff --git a/classes/Message.php b/classes/Message.php index 16d0c60b3..fa0c5b318 100644 --- a/classes/Message.php +++ b/classes/Message.php @@ -42,6 +42,7 @@ class Message extends Memcached_DataObject $sender = Profile::staticGet('id', $from); if (!$sender->hasRight(Right::NEWMESSAGE)) { + // TRANS: Client exception thrown when a user tries to send a direct message while being banned from sending them. throw new ClientException(_('You are banned from sending direct messages.')); } @@ -58,6 +59,7 @@ class Message extends Memcached_DataObject if (!$result) { common_log_db_error($msg, 'INSERT', __FILE__); + // TRANS: Message given when a message could not be stored on the server. return _('Could not insert message.'); } @@ -68,6 +70,7 @@ class Message extends Memcached_DataObject if (!$result) { common_log_db_error($msg, 'UPDATE', __FILE__); + // TRANS: Message given when a message could not be updated on the server. return _('Could not update message with new URI.'); } diff --git a/classes/Profile.php b/classes/Profile.php index a303469e9..ae6a37602 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -735,14 +735,18 @@ class Profile extends Memcached_DataObject 'role' => $name)); if (empty($role)) { - throw new Exception('Cannot revoke role "'.$name.'" for user #'.$this->id.'; does not exist.'); + // TRANS: Exception thrown when trying to revoke an existing role for a user that does not exist. + // TRANS: %1$s is the role name, %2$s is the user ID. + throw new Exception(sprintf(_('Cannot revoke role "%s" for user #%2$s; does not exist.'),$name, $this->id)); } $result = $role->delete(); if (!$result) { common_log_db_error($role, 'DELETE', __FILE__); - throw new Exception('Cannot revoke role "'.$name.'" for user #'.$this->id.'; database error.'); + // TRANS: Exception thrown when trying to revoke a role for a user with a failing database query. + // TRANS: %1$s is the role name, %2$s is the user ID. + throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$s; database error.'),$name, $this->id)); } return true; diff --git a/classes/Remote_profile.php b/classes/Remote_profile.php index 0a1676a6a..77bfbcd99 100644 --- a/classes/Remote_profile.php +++ b/classes/Remote_profile.php @@ -50,7 +50,8 @@ class Remote_profile extends Memcached_DataObject if ($profile) { return $profile->hasright($right); } else { - throw new Exception("Missing profile"); + // TRANS: Exception thrown when a right for a non-existing user profile is checked. + throw new Exception(_("Missing profile.")); } } } diff --git a/classes/Status_network.php b/classes/Status_network.php index a0f3ba5f7..5680c1458 100644 --- a/classes/Status_network.php +++ b/classes/Status_network.php @@ -342,6 +342,7 @@ class Status_network extends Safe_DataObject $id = $snt->insert(); if (!$id) { + // TRANS: Exception thrown when a tag cannot be saved. throw new Exception(_("Unable to save tag.")); } } diff --git a/classes/Subscription.php b/classes/Subscription.php index 0679c0925..0225ed4df 100644 --- a/classes/Subscription.php +++ b/classes/Subscription.php @@ -71,14 +71,17 @@ class Subscription extends Memcached_DataObject } if (!$subscriber->hasRight(Right::SUBSCRIBE)) { + // TRANS: Exception thrown when trying to subscribe while being banned from subscribing. throw new Exception(_('You have been banned from subscribing.')); } if (self::exists($subscriber, $other)) { + // TRANS: Exception thrown when trying to subscribe while already subscribed. throw new Exception(_('Already subscribed!')); } if ($other->hasBlocked($subscriber)) { + // TRANS: Exception thrown when trying to subscribe to a user who has blocked the subscribing user. throw new Exception(_('User has blocked you.')); } @@ -129,6 +132,7 @@ class Subscription extends Memcached_DataObject if (!$result) { common_log_db_error($sub, 'INSERT', __FILE__); + // TRANS: Exception thrown when a subscription could not be stored on the server. throw new Exception(_('Could not save subscription.')); } @@ -160,17 +164,18 @@ class Subscription extends Memcached_DataObject * Cancel a subscription * */ - function cancel($subscriber, $other) { if (!self::exists($subscriber, $other)) { + // TRANS: Exception thrown when trying to unsibscribe without a subscription. throw new Exception(_('Not subscribed!')); } // Don't allow deleting self subs if ($subscriber->id == $other->id) { - throw new Exception(_('Couldn\'t delete self-subscription.')); + // TRANS: Exception thrown when trying to unsubscribe a user from themselves. + throw new Exception(_('Could not delete self-subscription.')); } if (Event::handle('StartUnsubscribe', array($subscriber, $other))) { @@ -197,7 +202,8 @@ class Subscription extends Memcached_DataObject if (!$result) { common_log_db_error($token, 'DELETE', __FILE__); - throw new Exception(_('Couldn\'t delete subscription OMB token.')); + // TRANS: Exception thrown when the OMB token for a subscription could not deleted on the server. + throw new Exception(_('Could not delete subscription OMB token.')); } } else { common_log(LOG_ERR, "Couldn't find credentials with token {$token->tok}"); @@ -208,7 +214,8 @@ class Subscription extends Memcached_DataObject if (!$result) { common_log_db_error($sub, 'DELETE', __FILE__); - throw new Exception(_('Couldn\'t delete subscription.')); + // TRANS: Exception thrown when a subscription could not be deleted on the server. + throw new Exception(_('Could not delete subscription.')); } self::blow('user:notices_with_friends:%d', $subscriber->id); diff --git a/classes/User.php b/classes/User.php index cf8d4527b..8033229c4 100644 --- a/classes/User.php +++ b/classes/User.php @@ -360,11 +360,12 @@ class User extends Memcached_DataObject __FILE__); } else { $notice = Notice::saveNew($welcomeuser->id, + // TRANS: Notice given on user registration. + // TRANS: %1$s is the sitename, $2$s is the registering user's nickname. sprintf(_('Welcome to %1$s, @%2$s!'), common_config('site', 'name'), $user->nickname), 'system'); - } } @@ -375,7 +376,6 @@ class User extends Memcached_DataObject } // Things we do when the email changes - function emailChanged() { diff --git a/classes/User_group.php b/classes/User_group.php index e04c46626..0b83cfd47 100644 --- a/classes/User_group.php +++ b/classes/User_group.php @@ -492,6 +492,7 @@ class User_group extends Memcached_DataObject if (!$result) { common_log_db_error($group, 'INSERT', __FILE__); + // TRANS: Server exception thrown when creating a group failed. throw new ServerException(_('Could not create group.')); } @@ -501,6 +502,7 @@ class User_group extends Memcached_DataObject $result = $group->update($orig); if (!$result) { common_log_db_error($group, 'UPDATE', __FILE__); + // TRANS: Server exception thrown when updating a group URI failed. throw new ServerException(_('Could not set group URI.')); } } @@ -508,6 +510,7 @@ class User_group extends Memcached_DataObject $result = $group->setAliases($aliases); if (!$result) { + // TRANS: Server exception thrown when creating group aliases failed. throw new ServerException(_('Could not create aliases.')); } @@ -522,6 +525,7 @@ class User_group extends Memcached_DataObject if (!$result) { common_log_db_error($member, 'INSERT', __FILE__); + // TRANS: Server exception thrown when setting group membership failed. throw new ServerException(_('Could not set group membership.')); } @@ -536,6 +540,7 @@ class User_group extends Memcached_DataObject if (!$result) { common_log_db_error($local_group, 'INSERT', __FILE__); + // TRANS: Server exception thrown when saving local group information failed. throw new ServerException(_('Could not save local group info.')); } } -- cgit v1.2.3-54-g00ecf From 4e8e77f6b091e024f58241c2807c61e0b7930e5c Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Thu, 29 Jul 2010 18:47:28 +0000 Subject: Return HTTP 403 instead of 400 when silenced users try to post via API --- actions/apistatusesupdate.php | 2 +- classes/Notice.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'classes') diff --git a/actions/apistatusesupdate.php b/actions/apistatusesupdate.php index d65a068f5..9be16b2c5 100644 --- a/actions/apistatusesupdate.php +++ b/actions/apistatusesupdate.php @@ -332,7 +332,7 @@ class ApiStatusesUpdateAction extends ApiAuthAction $options ); } catch (Exception $e) { - $this->clientError($e->getMessage()); + $this->clientError($e->getMessage(), $e->getCode()); return; } diff --git a/classes/Notice.php b/classes/Notice.php index 8552248ba..36943be84 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -275,7 +275,7 @@ class Notice extends Memcached_DataObject if (!$profile->hasRight(Right::NEWNOTICE)) { common_log(LOG_WARNING, "Attempted post from user disallowed to post: " . $profile->nickname); - throw new ClientException(_('You are banned from posting notices on this site.')); + throw new ClientException(_('You are banned from posting notices on this site.'), 403); } $notice = new Notice(); -- cgit v1.2.3-54-g00ecf From 3fa76463edf5487bdfb26dd492d4356a0637e393 Mon Sep 17 00:00:00 2001 From: James Walker Date: Wed, 28 Jul 2010 23:59:46 -0400 Subject: oops. really embarassing typo (that explains some weird behaviour) --- classes/status_network.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'classes') diff --git a/classes/status_network.ini b/classes/status_network.ini index 83226e915..b298daae4 100644 --- a/classes/status_network.ini +++ b/classes/status_network.ini @@ -1,5 +1,5 @@ [status_network] -side_id = 129 +site_id = 129 nickname = 130 hostname = 2 pathname = 2 -- cgit v1.2.3-54-g00ecf From e7534224802f3de009d5d29563070392c376f100 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Fri, 30 Jul 2010 19:15:07 +0200 Subject: * Address i18n related FIXMEs after talk with Brion. * Tweak message --- classes/Memcached_DataObject.php | 12 ++++++------ classes/Safe_DataObject.php | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'classes') diff --git a/classes/Memcached_DataObject.php b/classes/Memcached_DataObject.php index 04cd6c120..7768fe757 100644 --- a/classes/Memcached_DataObject.php +++ b/classes/Memcached_DataObject.php @@ -235,7 +235,7 @@ class Memcached_DataObject extends Safe_DataObject $pkey[] = $key; $pval[] = self::valueString($this->$key); } else { - // FIXME: i18n? + // Low level exception. No need for i18n as discussed with Brion. throw new Exception("Unknown key type $key => $type for " . $this->tableName()); } } @@ -283,7 +283,7 @@ class Memcached_DataObject extends Safe_DataObject } else if ($type == 'fulltext') { $search_engine = new MySQLSearch($this, $table); } else { - // FIXME: i18n? + // Low level exception. No need for i18n as discussed with Brion. throw new ServerException('Unknown search type: ' . $type); } } else { @@ -530,7 +530,7 @@ class Memcached_DataObject extends Safe_DataObject if (!$dsn) { // TRANS: Exception thrown when database name or Data Source Name could not be found. - throw new Exception(_("No database name / DSN found anywhere")); + throw new Exception(_("No database name or DSN found anywhere.")); } return $dsn; @@ -580,7 +580,7 @@ class Memcached_DataObject extends Safe_DataObject if ($message instanceof PEAR_Error) { $message = $message->getMessage(); } - // FIXME: i18n? + // Low level exception. No need for i18n as discussed with Brion. throw new ServerException("[$id] DB_DataObject error [$type]: $message"); } @@ -623,11 +623,11 @@ class Memcached_DataObject extends Safe_DataObject case 'sql': case 'datetime': case 'time': - // FIXME: i18n? + // Low level exception. No need for i18n as discussed with Brion. throw new ServerException("Unhandled DB_DataObject_Cast type passed as cacheKey value: '$v->type'"); break; default: - // FIXME: i18n? + // Low level exception. No need for i18n as discussed with Brion. throw new ServerException("Unknown DB_DataObject_Cast type passed as cacheKey value: '$v->type'"); break; } diff --git a/classes/Safe_DataObject.php b/classes/Safe_DataObject.php index 16d7165d6..f0ea6b136 100644 --- a/classes/Safe_DataObject.php +++ b/classes/Safe_DataObject.php @@ -116,7 +116,7 @@ class Safe_DataObject extends DB_DataObject if ($this->_call($method, $params, $return)) { return $return; } else { - // FIXME: i18n? + // Low level exception. No need for i18n as discussed with Brion. throw new Exception('Call to undefined method ' . get_class($this) . '::' . $method); } @@ -242,7 +242,7 @@ class Safe_DataObject extends DB_DataObject $this->debug("Cant find database schema: {$this->_database}/{$this->__table} \n". "in links file data: " . print_r($_DB_DATAOBJECT['INI'],true),"databaseStructure",5); // we have to die here!! - it causes chaos if we don't (including looping forever!) - // FIXME: i18n? + // Low level exception. No need for i18n as discussed with Brion. $this->raiseError( "Unable to load schema for database and table (turn debugging up to 5 for full error message)", DB_DATAOBJECT_ERROR_INVALIDARGS, PEAR_ERROR_DIE); return false; } -- cgit v1.2.3-54-g00ecf From 8f8588026b9e0a2ab9b6d7b06b485379f02310bc Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Fri, 30 Jul 2010 19:25:55 +0200 Subject: Fixes for messages after review by Brion. --- classes/File.php | 2 +- classes/Notice.php | 4 ++-- classes/Profile.php | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'classes') diff --git a/classes/File.php b/classes/File.php index 18ad82892..407fd3211 100644 --- a/classes/File.php +++ b/classes/File.php @@ -140,7 +140,7 @@ class File extends Memcached_DataObject $redir_data = array(); } else { // TRANS: Server exception thrown when a URL cannot be processed. - throw new ServerException(_("Cannot process URL '$given_url'")); + throw new ServerException(sprintf(_("Cannot process URL '%s'"), $given_url)); } // TODO: max field length if ($redir_url === $given_url || strlen($redir_url) > 255 || !$followRedirects) { diff --git a/classes/Notice.php b/classes/Notice.php index 12467c850..3297c7a59 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1094,8 +1094,8 @@ class Notice extends Memcached_DataObject if (!$id) { common_log_db_error($reply, 'INSERT', __FILE__); // TRANS: Server exception thrown when a reply cannot be saved. - // TRANS: First arg is a notice ID, second ID is the ID of the mentioned user. - throw new ServerException(_("Couldn't save reply for {$this->id}, {$mentioned->id}")); + // TRANS: %1$d is a notice ID, %2$d is the ID of the mentioned user. + throw new ServerException(sprintf(_("Could not save reply for %1$d, %2$d."), $this->id, $mentioned->id)); } else { $replied[$mentioned->id] = 1; self::blow('reply:stream:%d', $mentioned->id); diff --git a/classes/Profile.php b/classes/Profile.php index ae6a37602..3b1e54c4d 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -736,8 +736,8 @@ class Profile extends Memcached_DataObject if (empty($role)) { // TRANS: Exception thrown when trying to revoke an existing role for a user that does not exist. - // TRANS: %1$s is the role name, %2$s is the user ID. - throw new Exception(sprintf(_('Cannot revoke role "%s" for user #%2$s; does not exist.'),$name, $this->id)); + // TRANS: %1$s is the role name, %2$s is the user ID (number). + throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; does not exist.'),$name, $this->id)); } $result = $role->delete(); @@ -745,8 +745,8 @@ class Profile extends Memcached_DataObject if (!$result) { common_log_db_error($role, 'DELETE', __FILE__); // TRANS: Exception thrown when trying to revoke a role for a user with a failing database query. - // TRANS: %1$s is the role name, %2$s is the user ID. - throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$s; database error.'),$name, $this->id)); + // TRANS: %1$s is the role name, %2$s is the user ID (number). + throw new Exception(sprintf(_('Cannot revoke role "%1$s" for user #%2$d; database error.'),$name, $this->id)); } return true; -- cgit v1.2.3-54-g00ecf From e603632f13e87aa2671bd5ff732c4858ce44ef6e Mon Sep 17 00:00:00 2001 From: James Walker Date: Mon, 2 Aug 2010 14:06:14 -0400 Subject: add support for Salmon's new "mentioned" rel value --- classes/Notice.php | 14 ++++++++++++++ lib/activitycontext.php | 5 +++++ 2 files changed, 19 insertions(+) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index 3297c7a59..399879e79 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1330,24 +1330,38 @@ class Notice extends Memcached_DataObject foreach ($reply_ids as $id) { $profile = Profile::staticGet('id', $id); if (!empty($profile)) { + // XXX: Deprecate this for 'mentioned' $xs->element( 'link', array( 'rel' => 'ostatus:attention', 'href' => $profile->getUri() ) ); + $xs->element( + 'link', array( + 'rel' => 'mentioned', + 'href' => $profile->getUri() + ) + ); } } $groups = $this->getGroups(); foreach ($groups as $group) { + // XXX: Deprecate this for 'mentioned' $xs->element( 'link', array( 'rel' => 'ostatus:attention', 'href' => $group->permalink() ) ); + $xs->element( + 'link', array( + 'rel' => 'mentioned', + 'href' => $group->permalink() + ) + ); } if (!empty($this->repeat_of)) { diff --git a/lib/activitycontext.php b/lib/activitycontext.php index 2df7613f7..4e97b2ab9 100644 --- a/lib/activitycontext.php +++ b/lib/activitycontext.php @@ -51,6 +51,7 @@ class ActivityContext const POINT = 'point'; const ATTENTION = 'ostatus:attention'; + const MENTIONED = 'mentioned'; const CONVERSATION = 'ostatus:conversation'; function __construct($element) @@ -76,8 +77,12 @@ class ActivityContext $linkRel = $link->getAttribute(ActivityUtils::REL); + // XXX: Deprecate this in favour of "mentioned" from Salmon spec + // http://salmon-protocol.googlecode.com/svn/trunk/draft-panzer-salmon-00.html#SALR if ($linkRel == self::ATTENTION) { $this->attention[] = $link->getAttribute(self::HREF); + } else if ($linkRel == self:MENTIONED) { + $this->attention[] = $link->getAttribute(self::HREF); } } } -- cgit v1.2.3-54-g00ecf From fe2b4fdf1c16eb2ecbbe1cd5e7f0fc1f477799ad Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 2 Aug 2010 17:16:04 -0700 Subject: add some activity hooks --- classes/Notice.php | 338 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 238 insertions(+), 100 deletions(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index 8552248ba..592e2f384 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1184,6 +1184,9 @@ class Notice extends Memcached_DataObject return $groups; } + // This has gotten way too long. Needs to be sliced up into functional bits + // or ideally exported to a utility class. + function asAtomEntry($namespace=false, $source=false, $author=true, $cur=null) { $profile = $this->getProfile(); @@ -1203,74 +1206,160 @@ class Notice extends Memcached_DataObject $attrs = array(); } - $xs->elementStart('entry', $attrs); + if (Event::handle('StartActivityStart', array(&$this, &$xs, &$attrs))) { + $xs->elementStart('entry', $attrs); + Event::handle('EndActivityStart', array(&$this, &$xs, &$attrs)); + } - if ($source) { - $xs->elementStart('source'); - $xs->element('id', null, $profile->profileurl); - $xs->element('title', null, $profile->nickname . " - " . common_config('site', 'name')); - $xs->element('link', array('href' => $profile->profileurl)); - $user = User::staticGet('id', $profile->id); - if (!empty($user)) { - $atom_feed = common_local_url('ApiTimelineUser', - array('format' => 'atom', - 'id' => $profile->nickname)); - $xs->element('link', array('rel' => 'self', - 'type' => 'application/atom+xml', - 'href' => $profile->profileurl)); - $xs->element('link', array('rel' => 'license', - 'href' => common_config('license', 'url'))); + if (Event::handle('StartActivitySource', array(&$this, &$xs))) { + + if ($source) { + + $xs->elementStart('source'); + + $xs->element('id', null, $profile->profileurl); + $xs->element('title', null, $profile->nickname . " - " . common_config('site', 'name')); + $xs->element('link', array('href' => $profile->profileurl)); + + $user = User::staticGet('id', $profile->id); + + if (!empty($user)) { + $atom_feed = common_local_url('ApiTimelineUser', + array('format' => 'atom', + 'id' => $profile->nickname)); + $xs->element('link', array('rel' => 'self', + 'type' => 'application/atom+xml', + 'href' => $profile->profileurl)); + $xs->element('link', array('rel' => 'license', + 'href' => common_config('license', 'url'))); + } + + $xs->element('icon', null, $profile->avatarUrl(AVATAR_PROFILE_SIZE)); + $xs->element('updated', null, common_date_w3dtf($this->created)); // FIXME: not true! + + $xs->elementEnd('source'); } + Event::handle('EndActivitySource', array(&$this, &$xs)); + } - $xs->element('icon', null, $profile->avatarUrl(AVATAR_PROFILE_SIZE)); - $xs->element('updated', null, common_date_w3dtf($this->created)); + $title = common_xml_safe_str($this->content); + + if (Event::handle('StartActivityTitle', array(&$this, &$xs, &$title))) { + $xs->element('title', null, $title); + Event::handle('EndActivityTitle', array($this, &$xs, $title)); + } + + $atomAuthor = ''; + + if ($author) { + $atomAuthor = $profile->asAtomAuthor($cur); } - if ($source) { - $xs->elementEnd('source'); + if (Event::handle('StartActivityAuthor', array(&$this, &$xs, &$atomAuthor))) { + if (!empty($atomAuthor)) { + $xs->raw($atomAuthor); + Event::handle('EndActivityAuthor', array(&$this, &$xs, &$atomAuthor)); + } } - $xs->element('title', null, common_xml_safe_str($this->content)); + $actor = ''; if ($author) { - $xs->raw($profile->asAtomAuthor($cur)); - $xs->raw($profile->asActivityActor()); + $actor = $profile->asActivityActor(); } - $xs->element('link', array('rel' => 'alternate', - 'type' => 'text/html', - 'href' => $this->bestUrl())); + if (Event::handle('StartActivityActor', array(&$this, &$xs, &$actor))) { + if (!empty($actor)) { + $xs->raw($actor); + Event::handle('EndActivityActor', array(&$this, &$xs, &$actor)); + } + } - $xs->element('id', null, $this->uri); + $url = $this->bestUrl(); - $xs->element('published', null, common_date_w3dtf($this->created)); - $xs->element('updated', null, common_date_w3dtf($this->created)); + if (Event::handle('StartActivityLink', array(&$this, &$xs, &$url))) { + $xs->element('link', array('rel' => 'alternate', + 'type' => 'text/html', + 'href' => $url)); + Event::handle('EndActivityLink', array(&$this, &$xs, $url)); + } - $source = null; + $id = $this->uri; - $ns = $this->getSource(); + if (Event::handle('StartActivityId', array(&$this, &$xs, &$id))) { + $xs->element('id', null, $id); + Event::handle('EndActivityId', array(&$this, &$xs, $id)); + } - if ($ns) { - if (!empty($ns->name) && !empty($ns->url)) { - $source = '' - . htmlspecialchars($ns->name) - . ''; - } else { - $source = $ns->code; + $published = common_date_w3dtf($this->created); + + if (Event::handle('StartActivityPublished', array(&$this, &$xs, &$published))) { + $xs->element('published', null, $published); + Event::handle('EndActivityPublished', array(&$this, &$xs, $published)); + } + + $updated = $published; // XXX: notices are usually immutable + + if (Event::handle('StartActivityUpdated', array(&$this, &$xs, &$updated))) { + $xs->element('updated', null, $updated); + Event::handle('EndActivityUpdated', array(&$this, &$xs, $updated)); + } + + $content = common_xml_safe_str($this->rendered); + + if (Event::handle('StartActivityContent', array(&$this, &$xs, &$content))) { + $xs->element('content', array('type' => 'html'), $content); + Event::handle('EndActivityContent', array(&$this, &$xs, $content)); + } + + // Most of our notices represent POSTing a NOTE. This is the default verb + // for activity streams, so we normally just leave it out. + + $verb = ActivityVerb::POST; + + if (Event::handle('StartActivityVerb', array(&$this, &$xs, &$verb))) { + $xs->element('activity:verb', null, $verb); + Event::handle('EndActivityVerb', array(&$this, &$xs, $verb)); + } + + // We use the default behavior for activity streams: if there's no activity:object, + // then treat the entry itself as the object. Here, you can set the type of that object, + // which is normally a NOTE. + + $type = ActivityObject::NOTE; + + if (Event::handle('StartActivityDefaultObjectType', array(&$this, &$xs, &$type))) { + $xs->element('activity:object-type', null, $type); + Event::handle('EndActivityDefaultObjectType', array(&$this, &$xs, $type)); + } + + // Since we usually use the entry itself as an object, we don't have an explicit + // object. Some extensions may want to add them (for photo, event, music, etc.). + + $objects = array(); + + if (Event::handle('StartActivityObjects', array(&$this, &$xs, &$objects))) { + foreach ($objects as $object) { + $xs->raw($object->asString()); } + Event::handle('EndActivityObjects', array(&$this, &$xs, $objects)); } - $noticeInfoAttr = array( - 'local_id' => $this->id, // local notice ID (useful to clients for ordering) - 'source' => $source, // the client name (source attribution) - ); + $noticeInfoAttr = array('local_id' => $this->id); // local notice ID (useful to clients for ordering) $ns = $this->getSource(); - if ($ns) { + + if (!empty($ns)) { + $noticeInfoAttr['source'] = $ns->code; if (!empty($ns->url)) { $noticeInfoAttr['source_link'] = $ns->url; + if (!empty($ns->name)) { + $noticeInfoAttr['source'] = '' + . htmlspecialchars($ns->name) + . ''; + } } } @@ -1284,103 +1373,139 @@ class Notice extends Memcached_DataObject $noticeInfoAttr['repeat_of'] = $this->repeat_of; } - $xs->element('statusnet:notice_info', $noticeInfoAttr, null); + if (Event::handle('StartActivityNoticeInfo', array(&$this, &$xs, &$noticeInfoAttr))) { + $xs->element('statusnet:notice_info', $noticeInfoAttr, null); + Event::handle('EndActivityNoticeInfo', array(&$this, &$xs, $noticeInfoAttr)); + } + + $replyNotice = null; if ($this->reply_to) { - $reply_notice = Notice::staticGet('id', $this->reply_to); - if (!empty($reply_notice)) { + $replyNotice = Notice::staticGet('id', $this->reply_to); + } + + if (Event::handle('StartActivityInReplyTo', array(&$this, &$xs, &$replyNotice))) { + if (!empty($replyNotice)) { $xs->element('link', array('rel' => 'related', - 'href' => $reply_notice->bestUrl())); + 'href' => $replyNotice->bestUrl())); $xs->element('thr:in-reply-to', - array('ref' => $reply_notice->uri, - 'href' => $reply_notice->bestUrl())); + array('ref' => $replyNotice->uri, + 'href' => $replyNotice->bestUrl())); + Event::handle('EndActivityInReplyTo', array(&$this, &$xs, $replyUri, $replyUrl)); } } - if (!empty($this->conversation)) { + $conv = null; + if (!empty($this->conversation)) { $conv = Conversation::staticGet('id', $this->conversation); + } + if (Event::handle('StartActivityConversation', array(&$this, &$xs, &$conv))) { if (!empty($conv)) { - $xs->element( - 'link', array( - 'rel' => 'ostatus:conversation', - 'href' => $conv->uri - ) - ); + $xs->element('link', array('rel' => 'ostatus:conversation', + 'href' => $conv->uri)); } + Event::handle('EndActivityConversation', array(&$this, &$xs, $conv)); } + $replyProfiles = array(); + $reply_ids = $this->getReplies(); foreach ($reply_ids as $id) { $profile = Profile::staticGet('id', $id); - if (!empty($profile)) { - $xs->element( - 'link', array( - 'rel' => 'ostatus:attention', - 'href' => $profile->getUri() - ) - ); + if (!empty($profile)) { + $replyProfiles[] = $profile; + } + } + + if (Event::handle('StartActivityAttentionProfiles', array(&$this, &$xs, &$replyProfiles))) { + foreach ($replyProfiles as $profile) { + $xs->element('link', array('rel' => 'ostatus:attention', + 'href' => $profile->getUri())); } + Event::handle('EndActivityAttentionProfiles', array(&$this, &$xs, $replyProfiles)); } $groups = $this->getGroups(); - foreach ($groups as $group) { - $xs->element( - 'link', array( - 'rel' => 'ostatus:attention', - 'href' => $group->permalink() - ) - ); + if (Event::handle('StartActivityAttentionGroups', array(&$this, &$xs, &$groups))) { + foreach ($groups as $group) { + $xs->element('link', array('rel' => 'ostatus:attention', + 'href' => $group->permalink())); + } + Event::handle('EndActivityAttentionGroups', array(&$this, &$xs, $groups)); } + $repeat = null; + if (!empty($this->repeat_of)) { $repeat = Notice::staticGet('id', $this->repeat_of); + } + + if (Event::handle('StartActivityForward', array(&$this, &$xs, &$repeat))) { if (!empty($repeat)) { - $xs->element( - 'ostatus:forward', - array('ref' => $repeat->uri, 'href' => $repeat->bestUrl()) - ); + $xs->element('ostatus:forward', + array('ref' => $repeat->uri, + 'href' => $repeat->bestUrl())); } + + Event::handle('EndActivityForward', array(&$this, &$xs, $repeat)); } - $xs->element( - 'content', - array('type' => 'html'), - common_xml_safe_str($this->rendered) - ); + $tags = $this->getTags(); - $tag = new Notice_tag(); - $tag->notice_id = $this->id; - if ($tag->find()) { - while ($tag->fetch()) { - $xs->element('category', array('term' => $tag->tag)); + if (Event::handle('StartActivityCategories', array(&$this, &$xs, &$tags))) { + foreach ($tags as $tag) { + $xs->element('category', array('term' => $tag)); } + Event::handle('EndActivityCategories', array(&$this, &$xs, $tags)); } - $tag->free(); - # Enclosures + // Enclosures + + $enclosures = array(); + $attachments = $this->attachments(); - if($attachments){ - foreach($attachments as $attachment){ - $enclosure=$attachment->getEnclosure(); - if ($enclosure) { - $attributes = array('rel'=>'enclosure','href'=>$enclosure->url,'type'=>$enclosure->mimetype,'length'=>$enclosure->size); - if($enclosure->title){ - $attributes['title']=$enclosure->title; - } - $xs->element('link', $attributes, null); + + foreach ($attachments as $attachment) { + $enclosure = $attachment->getEnclosure(); + if ($enclosure) { + $enclosures[] = $enclosure; + } + } + + if (Event::handle('StartActivityEnclosures', array(&$this, &$xs, &$enclosures))) { + foreach ($enclosures as $enclosure) { + $attributes = array('rel' => 'enclosure', + 'href' => $enclosure->url, + 'type' => $enclosure->mimetype, + 'length' => $enclosure->size); + + if ($enclosure->title) { + $attributes['title'] = $enclosure->title; } + + $xs->element('link', $attributes, null); } + Event::handle('EndActivityEnclosures', array(&$this, &$xs, $enclosures)); } - if (!empty($this->lat) && !empty($this->lon)) { - $xs->element('georss:point', null, $this->lat . ' ' . $this->lon); + $lat = $this->lat; + $lon = $this->lon; + + if (Event::handle('StartActivityGeo', array(&$this, &$xs, &$lat, &$lon))) { + if (!empty($lat) && !empty($lon)) { + $xs->element('georss:point', null, $lat . ' ' . $lon); + } + Event::handle('EndActivityGeo', array(&$this, &$xs, $lat, $lon)); } - $xs->elementEnd('entry'); + if (Event::handle('StartActivityEnd', array(&$this, &$xs))) { + $xs->elementEnd('entry'); + Event::handle('EndActivityEnd', array(&$this, &$xs)); + } return $xs->getString(); } @@ -1901,4 +2026,17 @@ class Notice extends Memcached_DataObject $this->is_local == Notice::LOCAL_NONPUBLIC); } + public function getTags() + { + $tags = array(); + $tag = new Notice_tag(); + $tag->notice_id = $this->id; + if ($tag->find()) { + while ($tag->fetch()) { + $tags[] = $tag->tag; + } + } + $tag->free(); + return $tags; + } } -- cgit v1.2.3-54-g00ecf From f12cafb275ea16903d5d5edeb3b9e46b9f7b2667 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 2 Aug 2010 17:56:44 -0700 Subject: correct output for EndActivityInReplyTo event --- classes/Notice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index 592e2f384..f6e9eb585 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1391,7 +1391,7 @@ class Notice extends Memcached_DataObject $xs->element('thr:in-reply-to', array('ref' => $replyNotice->uri, 'href' => $replyNotice->bestUrl())); - Event::handle('EndActivityInReplyTo', array(&$this, &$xs, $replyUri, $replyUrl)); + Event::handle('EndActivityInReplyTo', array(&$this, &$xs, $replyNotice)); } } -- cgit v1.2.3-54-g00ecf From f83171824f835ff9cd24bf0aea26f13c62b806cf Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 3 Aug 2010 15:50:21 -0700 Subject: correctly show for atom feeds --- classes/Notice.php | 48 ++++++++++++++++++++++++++------------- classes/Profile.php | 29 +++++++++++++++++------ plugins/OStatus/OStatusPlugin.php | 12 ++++++++++ 3 files changed, 66 insertions(+), 23 deletions(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index f6e9eb585..61844d487 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1215,29 +1215,45 @@ class Notice extends Memcached_DataObject if ($source) { - $xs->elementStart('source'); + $atom_feed = $profile->getAtomFeed(); - $xs->element('id', null, $profile->profileurl); - $xs->element('title', null, $profile->nickname . " - " . common_config('site', 'name')); - $xs->element('link', array('href' => $profile->profileurl)); + if (!empty($atom_feed)) { - $user = User::staticGet('id', $profile->id); + $xs->elementStart('source'); + + // XXX: we should store the actual feed ID + + $xs->element('id', null, $atom_feed); + + // XXX: we should store the actual feed title + + $xs->element('title', null, $profile->getBestName()); + + $xs->element('link', array('rel' => 'alternate', + 'type' => 'text/html', + 'href' => $profile->profileurl)); - if (!empty($user)) { - $atom_feed = common_local_url('ApiTimelineUser', - array('format' => 'atom', - 'id' => $profile->nickname)); $xs->element('link', array('rel' => 'self', 'type' => 'application/atom+xml', - 'href' => $profile->profileurl)); - $xs->element('link', array('rel' => 'license', - 'href' => common_config('license', 'url'))); - } + 'href' => $atom_feed)); - $xs->element('icon', null, $profile->avatarUrl(AVATAR_PROFILE_SIZE)); - $xs->element('updated', null, common_date_w3dtf($this->created)); // FIXME: not true! + $xs->element('icon', null, $profile->avatarUrl(AVATAR_PROFILE_SIZE)); - $xs->elementEnd('source'); + $notice = $profile->getCurrentNotice(); + + if (!empty($notice)) { + $xs->element('updated', null, common_date_w3dtf($notice->created)); + } + + $user = User::staticGet('id', $profile->id); + + if (!empty($user)) { + $xs->element('link', array('rel' => 'license', + 'href' => common_config('license', 'url'))); + } + + $xs->elementEnd('source'); + } } Event::handle('EndActivitySource', array(&$this, &$xs)); } diff --git a/classes/Profile.php b/classes/Profile.php index a303469e9..abd6eb031 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -152,17 +152,16 @@ class Profile extends Memcached_DataObject * * @return mixed Notice or null */ + function getCurrentNotice() { - $notice = new Notice(); - $notice->profile_id = $this->id; - // @fixme change this to sort on notice.id only when indexes are updated - $notice->orderBy('created DESC, notice.id DESC'); - $notice->limit(1); - if ($notice->find(true)) { + $notice = $this->getNotices(0, 1); + + if ($notice->fetch()) { return $notice; + } else { + return null; } - return null; } function getTaggedNotices($tag, $offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0) @@ -943,4 +942,20 @@ class Profile extends Memcached_DataObject return $result; } + + function getAtomFeed() + { + $feed = null; + + if (Event::handle('StartProfileGetAtomFeed', array($this, &$feed))) { + $user = User::staticGet('id', $this->id); + if (!empty($user)) { + $feed = common_local_url('ApiTimelineUser', array('id' => $user->id, + 'format' => 'atom')); + } + Event::handle('EndProfileGetAtomFeed', array($this, $feed)); + } + + return $feed; + } } diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php index c61e2cc5f..4fc9d4108 100644 --- a/plugins/OStatus/OStatusPlugin.php +++ b/plugins/OStatus/OStatusPlugin.php @@ -953,4 +953,16 @@ class OStatusPlugin extends Plugin } return false; } + + public function onStartProfileGetAtomFeed($profile, &$feed) + { + $oprofile = Ostatus_profile::staticGet('profile_id', $profile->id); + + if (empty($oprofile)) { + return true; + } + + $feed = $oprofile->feeduri; + return false; + } } -- cgit v1.2.3-54-g00ecf From cc71f1ae826cc7c186f38ac902d963dc8f65caeb Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 3 Aug 2010 15:55:40 -0700 Subject: output Atom dates in UTC --- classes/Notice.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index 61844d487..b849225fd 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1242,7 +1242,7 @@ class Notice extends Memcached_DataObject $notice = $profile->getCurrentNotice(); if (!empty($notice)) { - $xs->element('updated', null, common_date_w3dtf($notice->created)); + $xs->element('updated', null, self::utcDate($notice->created)); } $user = User::staticGet('id', $profile->id); @@ -1307,7 +1307,7 @@ class Notice extends Memcached_DataObject Event::handle('EndActivityId', array(&$this, &$xs, $id)); } - $published = common_date_w3dtf($this->created); + $published = self::utcDate($this->created); if (Event::handle('StartActivityPublished', array(&$this, &$xs, &$published))) { $xs->element('published', null, $published); @@ -2055,4 +2055,11 @@ class Notice extends Memcached_DataObject $tag->free(); return $tags; } + + static private function utcDate($dt) + { + $dateStr = date('d F Y H:i:s', strtotime($dt)); + $d = new DateTime($dateStr, new DateTimeZone('UTC')); + return $d->format(DATE_W3C); + } } -- cgit v1.2.3-54-g00ecf From e2c90576c0e50ccaa2b70c4d72ad06f320842f73 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 3 Aug 2010 16:01:50 -0700 Subject: re-add mentioned link lost in last merge --- classes/Notice.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index 20c9c9518..4646fc6ab 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1454,6 +1454,8 @@ class Notice extends Memcached_DataObject foreach ($replyProfiles as $profile) { $xs->element('link', array('rel' => 'ostatus:attention', 'href' => $profile->getUri())); + $xs->element('link', array('rel' => 'mentioned', + 'href' => $profile->getUri())); } Event::handle('EndActivityAttentionProfiles', array(&$this, &$xs, $replyProfiles)); } @@ -1464,6 +1466,8 @@ class Notice extends Memcached_DataObject foreach ($groups as $group) { $xs->element('link', array('rel' => 'ostatus:attention', 'href' => $group->permalink())); + $xs->element('link', array('rel' => 'mentioned', + 'href' => $group->permalink())); } Event::handle('EndActivityAttentionGroups', array(&$this, &$xs, $groups)); } -- cgit v1.2.3-54-g00ecf